class BBCodeMonkey

Constants

REGEXP

Expression that matches a regexp such as /foo/i

Properties

array $allowedFilters
protected Configurator $configurator
array $tokenRegexp
array $unfilteredTokens

Methods

__construct(Configurator $configurator)

Constructor

array
create(string $usage, string|Template $template)

Create a BBCode and its underlying tag and template(s) based on its reference usage

array
parse(string $usage)

Create a BBCode based on its reference usage

array
addAttributes(array $definitions, BBCode $bbcode, Tag $tag)

Parse a string of attribute definitions and add the attributes/options to the tag/BBCode

bool|string
convertValue(string $value)

Convert a human-readable value to a typed PHP value

array
parseTokens(string $definition)

Parse and return all the tokens contained in a definition

generateAttribute(array $token)

Generate an attribute based on a token

void
appendFilters(Attribute $attribute, string $filters)

Append a list of filters to an attribute's filterChain

bool
isFilter(string $tokenId)

Test whether a token's name is the name of a filter

array
parseOptionString(string $string)

Parse the option string into an associative array

Details

at line 94
__construct(Configurator $configurator)

Constructor

Parameters

Configurator $configurator

Instance of Configurator

at line 107
array create(string $usage, string|Template $template)

Create a BBCode and its underlying tag and template(s) based on its reference usage

Parameters

string $usage

BBCode usage, e.g. [B]{TEXT}[/b]

string|Template $template

BBCode's template

Return Value

array

An array containing three elements: 'bbcode', 'bbcodeName' and 'tag'

at line 175
protected array parse(string $usage)

Create a BBCode based on its reference usage

Parameters

string $usage

BBCode usage, e.g. [B]{TEXT}[/b]

Return Value

array

at line 346
protected array addAttributes(array $definitions, BBCode $bbcode, Tag $tag)

Parse a string of attribute definitions and add the attributes/options to the tag/BBCode

Attributes come in two forms. Most commonly, in the form of a single token, e.g. [a href={URL} title={TEXT}]

Sometimes, however, we need to parse more than one single token. For instance, the phpBB [FLASH] BBCode uses two tokens separated by a comma: [flash={NUMBER},{NUMBER}]{URL}[/flash]

In addition, some custom BBCodes circulating for phpBB use a combination of token and static text such as: [youtube]http://www.youtube.com/watch?v={SIMPLETEXT}[/youtube]

Any attribute that is not a single token is implemented as an attribute preprocessor, with each token generating a matching attribute. Tentatively, those of those attributes are created by taking the attribute preprocessor's name and appending a unique number counting the number of created attributes. In the [FLASH] example above, an attribute preprocessor named "flash" would be created as well as two attributes named "flash0" and "flash1" respectively.

Parameters

array $definitions

List of attributes definitions as [[name, definition]*]

BBCode $bbcode

Owner BBCode

Tag $tag

Owner tag

Return Value

array

Array of [token id => attribute name] where FALSE in place of the name indicates that the token is ambiguous (e.g. used multiple times)

at line 551
protected bool|string convertValue(string $value)

Convert a human-readable value to a typed PHP value

Parameters

string $value

Original value

Return Value

bool|string

Converted value

at line 572
protected array parseTokens(string $definition)

Parse and return all the tokens contained in a definition

Parameters

string $definition

Return Value

array

at line 664
protected Attribute generateAttribute(array $token)

Generate an attribute based on a token

Parameters

array $token

Token this attribute is based on

Return Value

Attribute

at line 771
protected void appendFilters(Attribute $attribute, string $filters)

Append a list of filters to an attribute's filterChain

Parameters

Attribute $attribute
string $filters

List of filters, separated with commas

Return Value

void

at line 792
protected bool isFilter(string $tokenId)

Test whether a token's name is the name of a filter

Parameters

string $tokenId

Token ID, e.g. "TEXT1"

Return Value

bool

at line 823
protected array parseOptionString(string $string)

Parse the option string into an associative array

Parameters

string $string

Serialized options

Return Value

array

Associative array of options