BB code to BB code formatter that can strip quotes or all BB codes.

This serves as a basis for other formatters that want to make BB code translations and return the result as BB code.

package XenForo_BbCode

 Methods

Constructor.

__construct() 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::__construct()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::__construct()

Adds to the list of acceptable media sites.

addMediaSites(array $sites) 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::addMediaSites()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::addMediaSites()

Parameters

$sites

array

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

addSmilies(array $smilies) 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::addSmilies()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::addSmilies()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::create()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::create()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::filterFinalOutput()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::filterFinalOutput()

Parameters

$output

string

Returns

string

Default, empty string filterer.

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

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

see \global\XenForo_BbCode_Formatter_Base::filterString()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::filterString()

Parameters

$string

string

$rendererStates

array

List of states the renderer may be in

Returns

stringFiltered/escaped string

Gets the list of valid BB code tags.

getTags() : array
Inherited

This removes most behaviors.

see \global\XenForo_BbCode_Formatter_Base::getTags()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::getTags()

Returns

array

Gets the effective text size to use.

getTextSize(string $inputSize) : string | false
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::getTextSize()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::getTextSize()

Parameters

$inputSize

string

Returns

stringfalse

handleListTag()

handleListTag(array $tag, array $rendererStates) 

Parameters

$tag

$rendererStates

Deals with stripping nested quote tags.

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

Parameters

$tag

array

$rendererStates

array

Returns

string

General purpose tag handler.

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

Parameters

$tag

array

$rendererStates

array

Returns

string

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

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

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

inherited_from \XenForo_BbCode_Formatter_Base::parseValidatePlainIfNoOption()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::parseValidatePlainIfNoOption()

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
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::parseValidateTagCode()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::parseValidateTagCode()

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() 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::preLoadData()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::preLoadData()

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

preLoadTemplates(\XenForo_View $view) 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::preLoadTemplates()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::preLoadTemplates()

Parameters

Renders an invalid tag.

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

This tag is simply displayed in its original form.

inherited_from \XenForo_BbCode_Formatter_Base::renderInvalidTag()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderInvalidTag()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderString()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderString()

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
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::renderSubTree()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderSubTree()

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
Inherited

This tag may be valid or invalid.

inherited_from \XenForo_BbCode_Formatter_Base::renderTag()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTag()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagAlign()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagAlign()

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) 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagAttach()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagAttach()

Parameters

$tag

$rendererStates

Renders a code tag.

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

inherited_from \XenForo_BbCode_Formatter_Base::renderTagCode()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagCode()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagEmail()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagEmail()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagHtml()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagHtml()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagImage()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagImage()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagIndent()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagIndent()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagList()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagList()

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
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::renderTagMedia()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagMedia()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagPhp()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagPhp()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagQuote()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagQuote()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagSize()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagSize()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagUnparsed()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagUnparsed()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTagUrl()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTagUrl()

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
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::renderTree()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTree()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderTreeElement()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderTreeElement()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::renderValidTag()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::renderValidTag()

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
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::replaceSmiliesInText()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::replaceSmiliesInText()

Parameters

$text

string

Text to replace in

$escapeCallback

mixed

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

Returns

string

Controls whether or not the string is censored.

setCensoring(string $value) 
Inherited

inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::setCensoring()

Parameters

$value

string

Sets the maximum quote depth.

setMaxQuoteDepth(integer $max) : \$this

Parameters

$max

integer

Returns

\$thisFluent interface

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

setView(\XenForo_View $view) : \unknown_type
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::setView()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::setView()

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
Inherited

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

Note that this output is not escaped in anyway!

inherited_from \XenForo_BbCode_Formatter_Base::stringifyTree()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::stringifyTree()

Parameters

$tree

array

Tree or sub-tree to stringify

Returns

stringTree as a string (like the original input)

Sets the value for stripping non-quote tags.

stripAllBbCode(boolean $value, integer | null $maxQuoteDepth) : \$this

Parameters

$value

boolean

$maxQuoteDepth

integernull

Returns

\$thisFluent interface

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

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

inherited_from \XenForo_BbCode_Formatter_Base::trimLeadingLines()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::trimLeadingLines()

Parameters

$string

string

$amount

integer

Returns

string

Appends a list element if it is not empty.

_appendListElement(array $elements, string $appendString) 
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_appendListElement()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_appendListElement()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_getMediaSiteHtmlFromCallback()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_getMediaSiteHtmlFromCallback()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_getTagRule()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_getTagRule()

Parameters

$tagName

string

Returns

arrayfalse

Gets a valid, full URL if possible.

_getValidUrl(string $url) : string | false
Inherited

False is returned if not possible.

inherited_from \XenForo_BbCode_Formatter_Base::_getValidUrl()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_getValidUrl()

Parameters

$url

string

URL to validate

Returns

stringfalse

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

_prepareSmilieUrl(string $smilieUrl) : string
Inherited

Fetches the result from cache if possible.

inherited_from \XenForo_BbCode_Formatter_Base::_prepareSmilieUrl()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_prepareSmilieUrl()

Parameters

$smilieUrl

string

Returns

string

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

_prepareSmilieUrlInternal(string $smilieUrl) : string
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_prepareSmilieUrlInternal()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_prepareSmilieUrlInternal()

Parameters

$smilieUrl

string

Returns

string

Populates the sprite smilie template with data

_processSmilieSpriteTemplate(array $smilie) : string
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_processSmilieSpriteTemplate()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_processSmilieSpriteTemplate()

Parameters

$smilie

array

Returns

string

Populates the image smilie template with data

_processSmilieTemplate(array $smilie) : string
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_processSmilieTemplate()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_processSmilieTemplate()

Parameters

$smilie

array

Returns

string

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

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

inherited_from \XenForo_BbCode_Formatter_Base::_renderListOutput()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_renderListOutput()

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
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::_renderTagQuoteFallback()
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::_renderTagQuoteFallback()

Parameters

$name

string

Name of quoted user

$content

string

Quoted text

Returns

string

 Properties

 

Controls whether text is censored before returning.

$_censorString : boolean
Inherited

inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_censorString
 

Callback that can be overriden in children.

$_generalTagCallback : callback | null

If specified, all tags will callback to this function.

 

List of ignored users, for quoted content mostly.

$_ignoredUsers : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_ignoredUsers
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_ignoredUsers
 

String used for outputting [IMG] tags.

$_imageTemplate : string
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::$$_imageTemplate
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_imageTemplate
 

The maximum quote depth allowed.

$_maxQuoteDepth : integer

-1 means unlimited.

 

List of media sites that are known.

$_mediaSites : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_mediaSites
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_mediaSites
 

If specified, callbacks that override the named tag.

$_overrideCallbacks : array

 

$_skipTags

$_skipTags 

 

Array to store smilie paths for [IMG] lookup

$_smiliePaths : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_smiliePaths
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smiliePaths
 

Essentially the reverse of the above lookup, this one translates a smilie ID to the actual "rich" replacement (for HTML, an image tag).

$_smilieReverse : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_smilieReverse
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smilieReverse
 

String used for outputting smilies as sprites.

$_smilieSpriteTemplate : string
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::$$_smilieSpriteTemplate
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smilieSpriteTemplate
 

String used for outputting smilies.

$_smilieTemplate : string
Inherited

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

inherited_from \XenForo_BbCode_Formatter_Base::$$_smilieTemplate
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smilieTemplate
 

Lookup array that translates a smilie replacement text to an untypeable sentinel value (\0-id-\0).

$_smilieTranslate : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_smilieTranslate
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smilieTranslate
 

Cache to store processed smilie URLs, to avoid having to process them for every single smilie.

$_smilieUrlCache : array
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_smilieUrlCache
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_smilieUrlCache
 

Controls whether all tags will be stripped.

$_stripAllBbCode : boolean

 

List of tags this formatter knows about.

$_tags : array | null
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_tags
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_tags
 

Direction of the text on the page by default.

$_textDirection : string
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_textDirection
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_textDirection
 

View for rendering tags that require templates.

$_view : \XenForo_View | null
Inherited

inherited_from \XenForo_BbCode_Formatter_Base::$$_view
inherited_from \XenForo_BbCode_Formatter_BbCode_Abstract::$$_view