Base class for defining the formatting used by the BB code parser.

This class implements HTML formatting.

package XenForo_BbCode

 Methods

Constructor.

__construct() 

Adds to the list of acceptable media sites.

addMediaSites(array $sites) 

Parameters

$sites

array

Add the specified list of smilies to the list that will be processed.

addSmilies(array $smilies) 

Parameters

$smilies

array

List of smilies with data from the DB (smilie_id, smilieText [array], image_url)

Create the specified BB code formatter.

create(string $class, array | false $options) : \XenForo_BbCode_Formatter_Base
Static

Parameters

$class

string

Name of the class. If empty, uses this class; if doesn't contain an underscore, assumes a partial name

$options

arrayfalse

Set of options to configure formatter; defaults to pulling as necessary; if false, doesn't look in registry etc

Returns

Filters the final string output.

filterFinalOutput(string $output) : string

Parameters

$output

string

Returns

string

Filter a string for the current output format.

filterString(string $string, array $rendererStates) : string

A string is simply the text between tags. This function is responsible for things like word wrap and smilies and output escaping.

Parameters

$string

string

$rendererStates

array

List of states the renderer may be in

Returns

stringFiltered/escaped string

Get the list of parsable tags and their parsing rules.

getTags() : array

Returns

array

Gets the effective text size to use.

getTextSize(string $inputSize) : string | false

Parameters

$inputSize

string

Returns

stringfalse

Disables parsing of child tags if this tag does not have an option.

parseValidatePlainIfNoOption(array $tagInfo, string | null $tagOption) : array | boolean

Useful for tags like url/email, where the address may be in the body of the tag.

Parameters

$tagInfo

array

Info about the tag we're parsing.

$tagOption

stringnull

Any option passed into the tag

Returns

arraybooleanTrue if tag is ok as is, array to change states, false to reject tag

Modifies the parsing options for a code tag.

parseValidateTagCode(array $tagInfo, string | null $tagOption) : array | boolean

Users must explicitly opt in to allow BB codes to be used within.

Parameters

$tagInfo

array

Info about the tag we're parsing.

$tagOption

stringnull

Any option passed into the tag

Returns

arraybooleanTrue if tag is ok as is, array to change states, false to reject tag

Pre-loads any required data, such as templates or phrases that may be be used.

preLoadData() 

Tells the view to pre-load the templates that are required.

preLoadTemplates(\XenForo_View $view) 

Parameters

Renders an invalid tag.

renderInvalidTag(array $tag, array $rendererStates) : string

This tag is simply displayed in its original form.

Parameters

$tag

array

Tag data from tree

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

Returns

stringRendered version

Renders a string tree element.

renderString(string $string, array $rendererStates, integer $trimLeadingLines) : string

Parameters

$string

string

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

$trimLeadingLines

integer

By reference. Number of leading lines to strip off next element.

Returns

stringRendered string

Renders a parsed BB code tree to the required output format.

renderSubTree(array $tree, array $rendererStates) : string

This does not reset the rendering states, meaning it is ok for recursive calls.

Parameters

$tree

array

Tree from {@link parse()}

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

Returns

stringOutput text

Renders a tag.

renderTag(array $element, array $rendererStates, integer $trimLeadingLines) : string

This tag may be valid or invalid.

Parameters

$element

array

Tag element.

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

$trimLeadingLines

integer

By reference. Number of leading lines to strip from next element. May be modified by tag.

Returns

stringRendered tag.

Renders an alignment (left, center, right) tag.

renderTagAlign(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

renderTagAttach()

renderTagAttach(array $tag, array $rendererStates) 

Parameters

$tag

$rendererStates

Renders a code tag.

renderTagCode(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders an email tag.

renderTagEmail(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders an HTML tag.

renderTagHtml(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a img tag.

renderTagImage(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders an indent tag.

renderTagIndent(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a list tag.

renderTagList(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a media tag.

renderTagMedia(array $tag, array $rendererStates) : string

Media tags embed rich media (usually videos). To embed a video, the source must be known.

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a PHP tag.

renderTagPhp(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a quote tag.

renderTagQuote(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a size tag.

renderTagSize(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Renders a tag as if it's unparsed (in its original form).

renderTagUnparsed(array $tag, array $rendererStates) : string

Parameters

$tag

array

Tag data from tree

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

Returns

stringRendered version

Renders a URL tag.

renderTagUrl(array $tag, array $rendererStates) : string

Parameters

$tag

array

Information about the tag reference; keys: tag, option, children

$rendererStates

array

Renderer states to push down

Returns

stringRendered tag

Resets rendering state and renders a parsed BB code tree to the required output format.

renderTree(array $tree, array $extraStates) : string

Note that this initializes the default states, so it is likely not the correct function to call for child tags.

Parameters

$tree

array

Tree from {@link parse()}.

$extraStates

array

A list of extra states to push into the formatter

Returns

stringOutput text

Renders a tree element, that be a tag (valid or not) or a string.

renderTreeElement(array | string $element, array $rendererStates, integer $trimLeadingLines) : string

Parameters

$element

arraystring

Tree element

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

$trimLeadingLines

integer

By reference. Number of leading lines to strip off next element.

Returns

stringRendered element.

Renders a tag.

renderValidTag(array $tagInfo, array $tag, array $rendererStates) : string

Parameters

$tagInfo

array

Information about how to parse the tag

$tag

array

Tag data from tree

$rendererStates

array

Renderer states to push down. Except in specific cases, cannot be pushed up.

Returns

stringRendered version

Replaces smilie strings in text with the appropriate "rich" markup.

replaceSmiliesInText(string $text, mixed $escapeCallback) : string

This method also escapes the output before the smilies are ultimately replaced. This is necessary to prevent the rich output from being escaped.

Parameters

$text

string

Text to replace in

$escapeCallback

mixed

Callback for escaping. If empty, no escaping is done.

Returns

string

Sets the view that is used to render tags requiring templates.

setView(\XenForo_View $view) : \unknown_type

Parameters

Returns

\unknown_type

Similar to rendering the tree, but this function renders all tags to plain text (as if they weren't special tags).

stringifyTree(array $tree) : string

This can be useful for functions that can only take plain text children.

Note that this output is not escaped in anyway!

Parameters

$tree

array

Tree or sub-tree to stringify

Returns

stringTree as a string (like the original input)

Trims the given number of leading blank lines off of the given string.

trimLeadingLines(string $string, integer $amount) : string

Parameters

$string

string

$amount

integer

Returns

string

Appends a list element if it is not empty.

_appendListElement(array $elements, string $appendString) 

Parameters

$elements

array

By reference. List of existing elements.

$appendString

string

String to append (if not empty)

Attempts to fetch media tag embed HTML using the callback method defined for a media site, if one is specified.

_getMediaSiteHtmlFromCallback(string $mediaKey, array $site) : string | boolean

Parameters

$mediaKey

string

$site

array

Information about the site to render this media

Returns

stringbooleanReturns false if callback is invalid

Gets information about the specified tag.

_getTagRule(string $tagName) : array | false

Parameters

$tagName

string

Returns

arrayfalse

Gets a valid, full URL if possible.

_getValidUrl(string $url) : string | false

False is returned if not possible.

Parameters

$url

string

URL to validate

Returns

stringfalse

Prepares a smilie URL for use in an <img /> tag.

_prepareSmilieUrl(string $smilieUrl) : string

Fetches the result from cache if possible.

Parameters

$smilieUrl

string

Returns

string

Prepares a smilie URL for use in an <img /> tag.

_prepareSmilieUrlInternal(string $smilieUrl) : string

Parameters

$smilieUrl

string

Returns

string

Populates the sprite smilie template with data

_processSmilieSpriteTemplate(array $smilie) : string

Parameters

$smilie

array

Returns

string

Populates the image smilie template with data

_processSmilieTemplate(array $smilie) : string

Parameters

$smilie

array

Returns

string

Given already parsed list elements, gets the output for the list.

_renderListOutput(string $listType, array $elements) : string

Parameters

$listType

string

Type of list (ol or ul)

$elements

array

List of elements in the list. These are already rendered.

Returns

string

Returns HTML output for a quote tag when the view is not available

_renderTagQuoteFallback(string $name, string $content) : string

Parameters

$name

string

Name of quoted user

$content

string

Quoted text

Returns

string

 Properties

 

$_ignoredUsers : array
 

$_imageTemplate : string

Will be passed the following params: 1 URL 2 Additional CSS classes

 

$_mediaSites : array
 

$_smiliePaths : array
 

$_smilieReverse : array
 

$_smilieSpriteTemplate : string

Will be passed the following params: 1 Smilie ID 2 Smilie text 3 Smilie title

 

$_smilieTemplate : string

Will be passed the following params: 1 Image URL 2 Smilie text 3 Smilie title

 

$_smilieTranslate : array
 

$_smilieUrlCache : array
 

$_tags : array | null
 

$_textDirection : string
 

$_view : \XenForo_View | null