BBCodes



BBCodes are a special way of formatting posts, similar to HTML. phpBB 3.0 allows you to create your own BBCodes very easily. On this page, you can see the custom BBCodes that currently exist.

Adding a BBCode is very easy. If done right, allowing users to use your new BBCode may be safer than allowing them to use HTML code. To add a BBCode, click Add a new BBCode to begin. There are four main things to consider when adding a BBCode: how you want your users to use the BBCode, what HTML code the BBcode will actually use (the users will not see this), what short info message you want for the BBCode, and whether or not you want a button for the new BBCode to be displayed on the posting screen. Once you are done configuring all of the custom BBCode settings, click Submit to add your new BBCode.

Figure 3.5. Creating BBCodes

Creating BBCodes

Creating a new BBCode. In this example, we are creating a new [font] BBCode that will allow users to specify the font face of the specified text.

In the BBCode Usage form, you can define how you want your users to use the BBCode. Let's say you want to create a new font BBCode that will let your users pick a font to use for their text. An example of what to put under BBCode Usage would be [font={SIMPLETEXT}]{TEXT}[/font] This would make a new [font] BBCode, and will allow the user to pick what font face they want for the text. The user's text is represented by TEXT, while SIMPLETEXT represents whatever font name the user types in.

In the HTML Replacement form, you can define what HTML code your new BBCode will use to actually format the text. In the case of making a new [font] BBCode, try <span style="font-family: {SIMPLETEXT}">{TEXT}<span> This HTML code will be used to actually format the user's text.

The third option to consider when adding a custom BBCode is what sort of help message you want to display to your users if they choose to use the new BBCode. Ideally, the helpline message is a short note or tip for the user using the BBCode. This message will be displayed below the BBCode row on the posting screens.

Note

If the next option described, Display on posting, isn't enabled, the helpline message will not be displayed.

Lastly, when adding a new BBCode, you can decide whether or not you want an actual BBCode button for your new BBCode to be displayed on the posting screens. If you want this, then check the Display on posting checkbox.

It is important to choose appropriate tokens when creating your custom BBCodes. The tokens limit the type of input that they will accept. If you want to only allow URLs, use the URL token. If you only want to allow numbers, use the NUMBER token.

BBCode Tokens

{TEXT}

Any text, including foreign characters, numbers, etc. You should NOT use this token in HTML element attributes (e.g. <a href="{TEXT}">). Always use the most restrictive token possible.

{SIMPLETEXT}

Characters from the latin alphabet (A-Z), numbers, spaces, commas, dots, minus, plus, hyphen, and underscore. Does not include apostrophes or quotation marks.

{INTTEXT}

Unicode letter characters, numbers, spaces, commas, dots, minus, plus, hyphen, underscore, and whitespaces. Does not include apostrophes or quotation marks.

{IDENTIFIER}

Characters from the latin alphabet (A-Z), numbers, hyphen, and underscore. Does not include most punctuation marks.

{NUMBER}

Any series of digits.

{EMAIL}

A valid email address.

{URL}

A valid URL using any protocol (http, ftp, etc. cannot be used for javascript exploits). If none is given, "http://" is prefixed to the string.

{LOCAL_URL}

A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol, as links are prefixed with "http://yourdomain/forum/".

{RELATIVE_URL}

A relative URL. You can use this to match parts of a URL, but be careful: a full URL is a valid relative URL. When you want to use relative URLs of your board, use the LOCAL_URL token.

{COLOR}

A HTML colour, can be either in the numeric form #FF1234 or a CSS colour keyword such as fuchsia or InactiveBorder.

If you need to use the same type of token more than once, you can differentiate between them by adding a number as the last character between the braces, e.g. {TEXT1}, {TEXT2}.