BBcode ideas

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The next feature release of phpBB 3 will be 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.2.x. If you need support for phpBB 3.2.x please visit the 3.2.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
simpleton
Registered User
Posts: 4
Joined: Sun Apr 18, 2010 11:38 pm

BBcode ideas

Post by simpleton »

Dynamic BBcode modules: The ability to create custom BBcodes in the ACP is great, but still a little limited in power if there need to be any special processing. I'm not sure how the BBcode works in phpBB. In the past I coded my own BBcode parser for a Python notes-like application once that would parse a string a lot like an HTML parser, and break it down into nodes, text nodes, BBcode nodes with possible child nodes, etc. This made adding some new BBcodes really easy, for instance by just dropping the py file under a directory that is dynamically loaded.

Forum/topic/post link BBcodes: A post may contain links to other forums, topics, or posts in the same board, often with the url BBcode. But, if the forum domain or path changes, the links may need to be updates. A custom bbcode to link to a specific forum, topic, or post could eliminate this:

You can find more information in the [ forum=37]Projects[ /forum] forum
The bug report is [ topic=878]here[ /topic]
The files are attached to [ post=98432]this post[ /post]

Quote: Quoting could link to the specific post quoted as well:

[ quote="bob"]Bob is quoted[ /quote]
[ quote=6523]The user who posted the post 6523 is quoted and would appear with a link to the post as well[ /quote]

User avatar
ameeck
Registered User
Posts: 86
Joined: Sun Nov 13, 2005 6:43 pm
Location: Prague, Czech Republic
Contact:

Re: [RFC] BBcode ideas

Post by ameeck »

Your forum/topic/attachment BBCodes can be easily created with the current system.

A RFC should contain a finished concept proposing a feature, it's pros, con, comparison to the current system, technological implementation etc..This really should go into discussion first.
Please think before you post.

simpleton
Registered User
Posts: 4
Joined: Sun Apr 18, 2010 11:38 pm

Re: BBcode ideas

Post by simpleton »

Okay, here is a little bit more thinking about it. Current custom BBcodes only have two settings, code and HTML replacement. A lot of BBcodes use styles and also scripts, sometimes entire script sections (< script > ... </ script >) that would get duplicated with each usage. I've seen also seem some that do a 'window.onload = ', which may be bad if two different BBcodes do this, replacing one onload with another so it does not get executed, and also because window.onload gets executed after everything else, even large images, get loaded.

An idea would be to include two extra fields in the BBcode editor: Custom CSS and Custom Scripts. During rendering of a page, phpBB would determine which codes are used and at the top output the correct style and script sections in the head element after any other style or script sections. It would be recommended that style names and script functions be prefixed to avoid any name conflicts:

Custom CSS (To be inserted in a <style type="text/css"> in the page <head> element)
.bbcode_spoiler ...
{
}

Custom Script (To be inserted in a <script type="text/javascript"> in the page <head> element after any other phpBB scripts):
var bbcode_spoiler_toggle = function(e)
{
...
};

HTML replacement
<div class=".bbcode_spoiler">
...
</div>


This way instead of sending styles or < script > elements multiple times, they can be consolidated at the top and used when needed in the HTML replacement. Also, for BBcodes that use window.onload, some type of ready mechanism can be provided similar to jQuery.ready

Custom Script:
phpbb_ready(function()
{
// Prepare something when DOM is fully loaded
});

FeyFre
Registered User
Posts: 29
Joined: Wed Mar 17, 2010 9:49 pm

Re: BBcode ideas

Post by FeyFre »

I fully agreed with simpleton. phpBB should extend BBCodes system. And not only by CSS and JavaScript injections.
Spoiler BBCode is classical example(as for me). But spoiler is simple BBCode. More handy BBCodes need more powered engine.
For example, I dream for such bbcodes:
UID:

Code: Select all

[UID]{NUMBER}[/UID], where {NUMBER} is id of some user in board, will be substituted by
<a href='{user_profile_link}'>{username}</a>

where:
{user_profile_link} - link to user profile i.e memberlist.php?mode=viewprofile&u={NUMBER}
{username} - real user name by fetched from users table using given user_id={NUMBER} 
PID:

Code: Select all

[PID]{NUMBER}[/PID], where {NUMBER} is id of post in board, will be substituted by
<a href='{direct_link_to_post}'>{post_subject}({post_caster})</a>

where:
{direct_link_to_post} - link to post i.e viewtopic.php?p={NUMBER}#p{NUMBER}
{post_subject} - real subject of post fetched from posts table using given post_id={NUMBER}
{post_caster} - user who created post
etc
Of course, if post is inaccessible - substitution must be like empty, or at least language string like "You do not have access to this post" or something similar.
TID:

Code: Select all

[TID]{NUMBER}[/TID], where {NUMBER} is id of topic in board, will be substituted by
<a href='{direct_link_to_head_post_in_topic}'>{topic_subject}({topic_caster})</a>

where:
{direct_link_to_head_post_in_topic} - link to head post of topic i.e viewtopic.php?t={NUMBER}
{topic_subject} - real subject of topic fetched from DB using given topic_id={NUMBER}
{topic_caster} - topic caster
Of course, if topic is inaccessible - substitution must be like empty, or at least language string like "You do not have access to this topic" or something similar.
FID:

Code: Select all

[FID]{NUMBER}[/FID], where {NUMBER} is id of forum(or category) in board, will be substituted by
<a href='{direct_link_to_forum_or_category}'>{forum_name}</a>

where:
{direct_link_to_forum_or_category} - link to forum or category i.e viewforum.php?f={NUMBER}
{forum_name} - real forum name fetched from DB using given forum_id={NUMBER}
Of course, if forum is inaccessible - substitution must be like empty, or at least language string like "You do not have access to this forum" or something similar.
I think you catch my idea.
As we can see, existing parser system unable to implement such BBCodes. We need to do some work in PHP also(read write MODX, what was done by community users for SPOILER and other custom bbcodes. IPB for example does it for each BBcode)

So I suggest to extend not only by including JavaScript and CSS injections into BB-code definitions, but also provide simple interface to access data stored in DB and use it in BB-substitution.

JavaScript and CSS injection are quite simple. bbcode parser should collect information about used bbcodes and assign them to special template block variable. For example

Code: Select all

//! In bbcode.php
class bcode
{
....
....
	//! Save bbocode usage stats
	var $injection_stats=array();
...
	//! In function bbcode_second_pass in foreach ($bbcodes_set as $bbcode_id) loop
	//! In pseudo language
	IF bbcode_is_used_in_this text AND NOT bbcode_injection_not_printed(check $this->injection_stats[$bbcode_id]) THEN
		global $template;
		$template->assign_block_vars('bbcode_css',array('DATA'=>$this->bbcode_css_cache[$bbcode_id];
		$template->assign_block_vars('bbcode_js',array('DATA'=>$this->bbcode_js_cache[$bbcode_id];
		$this->injection_stats[$bbcode_id] = true;	//! Mark injections as printed
	ENDIF
}
And in template(overall_header) in HTML`s head node should be

Code: Select all

<!-- IF .bbcode_css -->
	<style type="text/css">
	<!-- BEGIN bbcode_css -->
		{bbcode_css.DATA}
	<!-- END bbcode_css -->
	</style>
<!-- ENDIF -->
<!-- IF .bbcode_js -->
	<script type="text/javascript">
	<!-- BEGIN bbcode_js -->
		{bbcode_js.DATA}
	<!-- END bbcode_js -->
	</script>
<!-- ENDIF -->
Second way is to collect all CSS and JS injections in separate two files(.css and .js) and link to them in page header. Of course files must be updated when some bbcode edited in ACP. This solution is more effective than first one(another proof of proverb "Second thoughts are best.")

About access data stored in DB. There is more work, and it is more difficult.
I suggest to crate web-interface which will utilise abilities such power method of phpBB's Data Base Abstraction Layer as sql_build_query($query,$array). AFAIK this method intended to build complex queries having image of structure of query($array argument of method). So why we can't allow BBCode creator to setup this structure via web-interface in ACP? (Yes, Admin should know at least something about SQL and phpBB. But if he(she) want have such complex BBcodes, he(she) must pay for it. :) ) Web-interface should provide BBCode creator list of available tables(not a question, we have it always), list of fields in selected tables(have it also), and some other options like: Grouping, Ordering and of course Caching results of queries. Some or all data fetched by query must be accessible in substitution. BBcode parser should check, if bbcode definition is marked as "must acquire data from DB" and then do data acquisition using given SQL.
Of course, security side and performance of such feature must be carefully worked out.

User avatar
A_Jelly_Doughnut
Registered User
Posts: 1780
Joined: Wed Jun 04, 2003 4:23 pm

Re: BBcode ideas

Post by A_Jelly_Doughnut »

FeyFre wrote:I fully agreed with simpleton. phpBB should extend BBCodes system. And not only by CSS and JavaScript injections.
Spoiler BBCode is classical example(as for me). But spoiler is simple BBCode. More handy BBCodes need more powered engine.
For example, I dream for such bbcodes:
[snipped]
As we can see, existing parser system unable to implement such BBCodes. We need to do some work in PHP also(read write MODX, what was done by community users for SPOILER and other custom bbcodes. IPB for example does it for each BBcode)
Is there something I'm missing which required by these examples and is not provided in the current BBCode implementation other than "If the linked post/topic/forum is not available, do not convert the link"? If so, I'm not seeing the benefit.
So I suggest to extend not only by including JavaScript and CSS injections into BB-code definitions, but also provide simple interface to access data stored in DB and use it in BB-substitution.
[snip]
It would probably be possible, maybe even reasonable, to provide some gathering place for the javascript used by BBCodes, for examples like the spoiler, which requires a nontrivial amount of javascript. However, I don't see any need to have the "dice MOD" be implemented via the custom BBCode system. That doesn't seem too globally useful to me.

(Of course, that's what this forum is about - if its useful to you, pipe up)
A_Jelly_Doughnut

Nelsaidi
Registered User
Posts: 122
Joined: Tue Nov 11, 2008 5:44 pm

Re: BBcode ideas

Post by Nelsaidi »

Also it means CSS/JS will be global and not style based which may cause issues. If you have it style based for BBCode then thats overcomplicating hings. IF you need full on BBCodes use PHP for them as mods

User avatar
Kellanved
Former Team Member
Posts: 407
Joined: Sun Jul 30, 2006 4:59 pm
Location: Berlin

Re: BBcode ideas

Post by Kellanved »

Frankly, I don't see the benefit at all. Injecting javascript and CSS is something for the upcoming hooks system, not the bbcode system. It might be an idea to provide a hook for bbcodes requiring server-side actions, but that's as far as it goes.

Bottom line: wait for the hook placement call for RFCs and propose hooks for the features you deem necessary.
No support via PM.
Trust me, I'm a doctor.

poppertom69
Registered User
Posts: 8
Joined: Mon Jan 07, 2008 12:32 pm

Re: BBcode ideas

Post by poppertom69 »

The only thing I think that would be useful for the custom bbcode system is being able to assign template variables, this would be very useful when only wanting bbcodes to be viewed by logged in users. The other thing I would suggest which I started on a while ago is to have permissions who can use what custom bbcode that you add. This would be a very useful feature.

leviatan21
Registered User
Posts: 18
Joined: Tue May 05, 2009 5:51 pm

Re: BBcode ideas

Post by leviatan21 »

poppertom69 wrote:The only thing I think that would be useful for the custom bbcode system is being able to assign template variables, this would be very useful when only wanting bbcodes to be viewed by logged in users. The other thing I would suggest which I started on a while ago is to have permissions who can use what custom bbcode that you add. This would be a very useful feature.
++
QA Team Member - I don't support by PM,
Customize forums, install Skins/Mods ! Sendme a PM | Don't forget to visit my other mods
Excuse me for my poor English, I speak Spanish. | Image phpBB en Español

bar10dr
Registered User
Posts: 1
Joined: Wed Mar 17, 2010 8:29 pm

Re: BBcode ideas

Post by bar10dr »

What I really miss is the ability to specify access to different BBCodes.

For instance if I only wanted the mods to be able to use a specific BBCode it would be great if you could do something like this in the header to specify what groups the BBCode would work for.
[Allowed=<groupname1>,<groupname2>,...]
...

That BBCode button would then not show up for people who are not in those groups, and if they tried using it anyway it would not insert any code.

Post Reply