[3.2][3.3][ALPHA] BBCode Permissions

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Scam Warning
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
Post Reply
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4579
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

[3.2][3.3][ALPHA] BBCode Permissions

Post by kasimi »

BBCode Permissions


Description

This extension adds various permissions for using and viewing BBCodes. The permissions allow you to not only prevent users from using them, but also to hide or replace BBCode contents in posts (forum-based local permissions), private messages (global user permissions) and mChat messages (global user permissions). Other content can be added upon request.

Screenshots

01_permissions.png
02_messages.png
03_edit.png


Requirements
  • phpBB 3.2.10 or 3.3.1 or later (3.3.0 is not supported)
  • PHP 7.2.0 or later
Important Notes
  • When enabling the extension, default permissions for the user role ROLE_USER_STANDARD and the forum role ROLE_FORUM_STANDARD are set up automatically. It is assumed that all your users have these roles assigned. If you have deleted either of the roles or if you are using different roles, your users won't be able to see nor use any BBCodes until you have correctly configured the extension's permissions.
Latest Version
  • 1.0.0-a3
Download
igorbond
Registered User
Posts: 119
Joined: Sun Mar 24, 2013 5:54 pm

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by igorbond »

Coool :!: :!: :!:
Image
User avatar
Dark❶
Registered User
Posts: 247
Joined: Mon Jan 15, 2018 1:22 pm
Location: D@rK V0id
Name: Dark❶ [dark1]
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by Dark❶ »

Nice :heart_eyes:

I'll wait when phpBB 3.2.10/3.3.1 are released to test it... :smiley:

Best regards :+1:
Dark❶ [dark1]
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4579
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by kasimi »

1.0.0-a2 released.
TWEagle
Registered User
Posts: 304
Joined: Sat Dec 10, 2005 2:50 pm
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by TWEagle »

Is this only to view

or also to use?

otherwise to use would also be cool
Image
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4579
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by kasimi »

There are permissions for both, see the two tabs in the first screenshot.
TWEagle
Registered User
Posts: 304
Joined: Sat Dec 10, 2005 2:50 pm
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by TWEagle »

Thnx

I am following it
Image
User avatar
ViolaF
Registered User
Posts: 1540
Joined: Tue Aug 14, 2012 11:52 pm

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by ViolaF »

Finally its transformed and no bbcodebox/-ultra/-special/-extra is needed anymore,
thanks for that :D :geek:
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4579
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by kasimi »

1.0.0-a3 is now available. BBCode permissions in private messages and mChat messages are now supported. Minimum requirements are PHP 7.2.0 or later and phpBB 3.2.10 or 3.3.1 or later (phpBB 3.3.0 is not supported).
User avatar
JoshyPHP
Code Contributor
Posts: 1167
Joined: Mon Jul 11, 2011 12:28 am

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by JoshyPHP »

Hey,

I'm looking through some of the code on GitHub, as I'm interested in how people use the library so to better inform my decisions in developing the API. So I'm mostly interested in text_helper.

I have a suggestion and a question about process_xml(). The first is to replace this:

Code: Select all

substr($xml, 0, 3) === '<r>'
With this:

Code: Select all

substr($xml, 0, 3) !== '<t>'
The reason is that the root node may contain namespace declarations and future versions may even store some metadata in the root node or maybe introduce other types of root nodes. So matching <t> is better and if you really want to future proof, you can test the XML against a (^<t[ />]) regexp.

The other thing is I think you may be able to simplify the way non-authorized BBCodes are displayed. Instead of modifying the XML to replace it, you could reconfigure their template instead, probably via the core.text_formatter_s9e_configure_after event. For example, the [color] BBCode uses something like that by default:

Code: Select all

<span style="color:{@color}"><xsl:apply-templates/></span>
You could replace it with something like that:

Code: Select all

<xsl:choose>
	<xsl:when test="$SHOW_BBCODE_COLOR">
		<span style="color:{@color}"><xsl:apply-templates/></span>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="$L_YOU_CANNOT_VIEW_BBCODE"/>
	</xsl:otherwise>
</xsl:choose>
Then you would use the core.text_formatter_s9e_renderer_setup event to set SHOW_BBCODE_COLOR to non-empty value to enable it, or leave it disabled by default. I think that's an idea worth digging. I'm subscribed to the topic so let me know if you have any questions.

Edit: changing the template can have side-effects though. For example, if the xsl:otherwise is fundamentally different from the other branch, it may change the behaviour of the BBCode, such as how to resolve misnested tags.
I wrote the thing that does BBCodes in 3.2+.
User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 4579
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by kasimi »

Thanks for your feedback. Here's the updated XML check: https://github.com/kasimi/phpbb-ext-bbc ... 9c2fa3fbac Maybe it makes sense to add a helper method for this to the TextFormatter?
JoshyPHP wrote:
Wed Aug 19, 2020 1:36 pm
you may be able to simplify the way non-authorized BBCodes are displayed
This sounds like a lot of work. The extension would have to re-create the templates for all BBCodes. How would this work for custom BBCodes? I understand it would improve performance a lot, but I'm not sure it's worth the effort.
User avatar
JoshyPHP
Code Contributor
Posts: 1167
Joined: Mon Jul 11, 2011 12:28 am

Re: [3.2][3.3][ALPHA] BBCode Permissions

Post by JoshyPHP »

I wouldn't add a method that just tests whether the XML is rich or plain, but I'm thinking about different kinds of markup manipulation, that's why I'm proactively looking at extensions such as yours. But I haven't got very far and I still don't know what the API would look like.

There's a different kind of check on the XML that you could use to avoid loading the whole thing into a DOMDocument. Just test whether the XML contains any of the disallowed tags, e.g.

Code: Select all

$regexp = '((?<=<)(?:' . implode('|', $disallowed_bbcodes) . ')[ />])';
if (!preg_match($xml, $regexp))
{
	return $xml;
}
If the XML doesn't contain <FOO you know it doesn't have any FOO tags. Assuming that most posts don't contain any disallowed BBCodes, you end up skipping the whole DOM loading/saving most of the time. In the regexp above, I use the lookbehind assertion (?<=<) instead of < for performance. It changes the way PCRE2 looks for potential matches and it's more efficient on average because an XML file has a lot of < and not that many F.
kasimi wrote:
Sat Aug 22, 2020 10:29 am
The extension would have to re-create the templates for all BBCodes.
You'd listen for the core.text_formatter_s9e_configure_after event with a non-zero priority so it gets dispatched after regular listeners, then you'd just iterate through the BBCodes that are disallowable. Something like this:

Code: Select all

foreach ($disallowable_bbcodes as $name)
{
	if (!isset($configurator->tags[$name]))
	{
		continue;
	}

	$tag = $configurator->tags[$name];
	$tag->template =
		'<xsl:choose>
			<xsl:when test="$SHOW_BBCODE_' . strtoupper($name) . '">
				' . $tag->template . '
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$L_YOU_CANNOT_VIEW_BBCODE"/>
			</xsl:otherwise>
		</xsl:choose>';
}
I haven't thought a lot about it though, so it's possible it's not worth implementing. I guess you can wait for some feedback on whether your current solution works well enough for your needs.

The alternative would be to create a new event or use a service decorator on the *.data_access service to replace the BBCodes' templates when they are loaded.
I wrote the thing that does BBCodes in 3.2+.
Post Reply

Return to “Extensions in Development”