Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2013-09-05 17:20:55

AracornRed
Member
Registered: 2008-12-25
Posts: 44
Website

How to add custom bbcode?

Is there anywhere on the site or forums that explains how to add custom bbcode?  I searched and came up with a few mentions but nothing that really spells it out.

In this case I'm wanting to add a [spoiler] tag that converts to <span class="spoiler">.

Don't want to install any full-fledged mods, would just like to know the simplest way to go about adding new bbcode. smile

Last edited by AracornRed (2013-09-06 14:26:25)

Offline

#2 2013-09-05 23:41:48

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,730
Website

Re: How to add custom bbcode?

Two steps.

First, add your spoiler tag to the relevant arrays in the preparse_tags() function.

Also, you need to add the tag regex and the HTML that should replace it in the do_bbcode() function.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2013-09-06 15:03:22

AracornRed
Member
Registered: 2008-12-25
Posts: 44
Website

Re: How to add custom bbcode?

Thanks Franz!

I'm planning a very simple css and jQuery implementation, if it goes well I'll post it later. smile

Offline

#4 2013-09-11 15:55:27

AracornRed
Member
Registered: 2008-12-25
Posts: 44
Website

Re: How to add custom bbcode?

I got my [spoiler] tag mod working nicely except for one thing.  I'm trying to prevent the color and colour tags from being nested inside it, so for example where [spoiler]this[/spoiler] isn't allowed.  In parser.php I've made these changes for that specific purpose but they don't seem to be working:

	// Tags we limit bbcode in
	$tags_limit_bbcode = array(
		'*' 	=> array('spoiler', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'code', 'topic', 'post', 'forum', 'user'),
		'spoiler'	=> array('color', 'colour'),

Am I misunderstanding the way this section works?

Offline

#5 2013-09-11 16:12:49

Otomatic
FluxBB Donor
From: Paris - France
Registered: 2010-01-26
Posts: 456
Website

Re: How to add custom bbcode?

Hi,

I think it does not work like you write.

First, you must add the tag spoiler in the list of all tags :

	// List of all the tags
	$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h', 'topic', 'post', 'forum', 'user', 'spoiler');

Second, in // Tags we limit bbcode in you write the tags that are allowed inside the tag spoiler, not the tags that are forbidden.


Ce n'est pas parce que l'erreur se propage qu'elle devient vérité. Ghandi
An error does not become truth by reason of multiplied propagation. Ghandi

Offline

#6 2013-09-22 22:01:28

omibb
Member
Registered: 2011-07-06
Posts: 23

Re: How to add custom bbcode?

Hi OP,

If you figure a way to keep the spoiler from being revealed in any of the feeds, could you post it?

Offline

#7 2013-10-01 17:37:54

AracornRed
Member
Registered: 2008-12-25
Posts: 44
Website

Re: How to add custom bbcode?

You mean as in RSS and Atom feeds and what not?  I haven't bothered with those but I do have the spoiler code for forum topics themselves working.  Once I get nesting working properly as Otomatic has helpfully described I can post the code here.

Offline

#8 2014-01-30 05:48:48

Different55
Member
Registered: 2011-11-18
Posts: 147

Re: How to add custom bbcode?

I've added two tags to the arrays mentioned:

	// List of all the tags
	$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h', 'topic', 'post', 'forum', 'user', 'center', 'alpha');
	$pattern[] = '%\[center\](.*?)\[/center\]%ms';
	$pattern[] = '%\[alpha=(0|1|0\.[0-9])\](.*?)\[/alpha\]%ms';
	$pattern[] = '%\[alpha\](.*?)\[/alpha\]%ms';
...
	$replace[] = '<center>$1</center>';
	$replace[] = '<span style="opacity: $1;">$2</span>';
	$replace[] = '<span style="opacity: 0.5;">$1</span>';

But, while the center tag works as expected, the alpha tag doesn't work at all. I'm not sure what the problem is.

EDIT: As always, I've found my own solution. This time, I happened to be editing the wrong parser.php for the forum I wanted the tags on. Not sure how [center] worked if I hadn't added it. I'm probably forgetting something else. I am not a clever person.

Last edited by Different55 (2014-01-30 06:22:16)

Offline

Board footer

Powered by FluxBB 1.5.6