Version: current

# Class SSHTMLBBCodeParser

### Direct known subclasses

`SSHTMLBBCodeParser_Filter`

### Indirect known subclasses

`SSHTMLBBCodeParser_Filter_Basic`, `SSHTMLBBCodeParser_Filter_EmailLinks`, `SSHTMLBBCodeParser_Filter_Extended`, `SSHTMLBBCodeParser_Filter_Images`, `SSHTMLBBCodeParser_Filter_Links`, `SSHTMLBBCodeParser_Filter_Lists`

Package: sapphire\misc
Author: Stijn de Reede <sjr@gmx.co.uk> , SilverStripe This is a parser to replace UBB style tags with their html equivalents. It does not simply do some regex calls, but is complete stack based parse engine. This ensures that all tags are properly nested, if not, extra tags are added to maintain the nesting. This parser should only produce xhtml 1.0 compliant code. All tags are validated and so are all their attributes. It should be easy to extend this parser with your own tags, see the _definedTags format description below. Usage: $parser = new SSHTMLBBCodeParser(); $parser->setText('normal [b]bold[/b] and normal again'); $parser->parse(); echo $parser->getParsed(); or: $parser = new SSHTMLBBCodeParser(); echo $parser->qparse('normal [b]bold[/b] and normal again'); or: echo SSHTMLBBCodeParser::staticQparse('normal [b]bold[/b] and normal again'); Setting the options from the ini file: $config = parse_ini_file('BBCodeParser.ini', true); $options = &PEAR::getStaticProperty('SSHTMLBBCodeParser', '_options'); $options = $config['SSHTMLBBCodeParser']; unset($options);
Located at sapphire/parsers/HTML/HTMLBBCodeParser.php

## Methods summary

`public none` | # `SSHTMLBBCodeParser( array $options = array() )` Constructor, initialises the options and filters Constructor, initialises the options and filters Sets the private variable _options with base options defined with &PEAR::getStaticProperty(), overwriting them with (if present) the argument to this method. Then it sets the extra options to properly escape the tag characters in preg_replace() etc. The set options are then stored back with &PEAR::getStaticProperty(), so that the filter classes can use them. All the filters in the options are initialised and their defined tags are copied into the private variable _definedTags. #### Parameters $options array options to use, can be left out #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk>
`public &` | # `getStaticProperty( mixed $class, mixed $var )`
`public` | # `setOption( string $name, mixed $value )` Option setter Option setter #### Parameters $name string option name $value mixed option value #### Author Lorenzo Alberton <l.alberton@quipo.it>
`public` | # `addFilter( string $filter )` Add a new filter Add a new filter #### Parameters $filter string filter #### Author Lorenzo Alberton <l.alberton@quipo.it>
`public` | # `removeFilter( string $filter )` Remove an existing filter Remove an existing filter #### Parameters $filter string $filter #### Author Lorenzo Alberton <l.alberton@quipo.it>
`public boolean` | # `addFilters( mixed $filters )` Add new filters Add new filters #### Parameters $filters mixed (array or string) #### Returns `boolean` true if all ok, false if not. #### Author Lorenzo Alberton <l.alberton@quipo.it>
`public none` | # `_preparse( )` Executes statements before the actual array building starts Executes statements before the actual array building starts This method should be overwritten in a filter if you want to do something before the parsing process starts. This can be useful to allow certain short alternative tags which then can be converted into proper tags with preg_replace() calls. The main class walks through all the filters and and calls this method. The filters should modify their private $_preparsed variable, with input from $_text. #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See `mixed`
`public none` | # `_buildTagArray( )` Builds the tag array from the input string $_text Builds the tag array from the input string $_text An array consisting of tag and text elements is contructed from the $_preparsed variable. The method uses _buildTag() to check if a tag is valid and to build the actual tag to be added to the tag array. #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::_buildTag()`` `mixed` `mixed`
`public array` | # `_buildTag( string $str )` Builds a tag from the input string Builds a tag from the input string This method builds a tag array based on the string it got as an argument. If the tag is invalid, <false> is returned. The tag attributes are extracted from the string and stored in the tag array as an associative array. #### Parameters $str string string to build tag from #### Returns `array` tag in array format #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::_buildTagArray()``
`public none` | # `_validateTagArray( )` Validates the tag array, regarding the allowed tags Validates the tag array, regarding the allowed tags While looping through the tag array, two following text tags are joined, and it is checked that the tag is allowed inside the last opened tag. By remembering what tags have been opened it is checked that there is correct (xml compliant) nesting. In the end all still opened tags are closed. #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk>, Seth Price <seth@pricepages.org> #### See ``SSHTMLBBCodeParser::_isAllowed()`` `mixed`
`public boolean` | # `_parentNeeded( array $out, array $in )` Checks to see if a parent is needed Checks to see if a parent is needed Checks to see if the current $in tag has an appropriate parent. If it does, then it returns false. If a parent is needed, then it returns the first tag in the list to add to the stack. #### Parameters $out array tag that is on the outside $in array tag that is on the inside #### Returns `boolean` false if not needed, tag if needed, true if out of our minds #### Author Seth Price <seth@pricepages.org> #### See ``SSHTMLBBCodeParser::_validateTagArray()``
`public boolean` | # `_childNeeded( array $out, array $in )` Checks to see if a child is needed Checks to see if a child is needed Checks to see if the current $out tag has an appropriate child. If it does, then it returns false. If a child is needed, then it returns the first tag in the list to add to the stack. #### Parameters $out array tag that is on the outside $in array tag that is on the inside #### Returns `boolean` false if not needed, tag if needed, true if out of our minds #### Author Seth Price <seth@pricepages.org> #### See ``SSHTMLBBCodeParser::_validateTagArray()``
`public boolean` | # `_isAllowed( array $out, array $in )` Checks to see if a tag is allowed inside another tag Checks to see if a tag is allowed inside another tag The allowed tags are extracted from the private _definedTags array. #### Parameters $out array tag that is on the outside $in array tag that is on the inside #### Returns `boolean` return true if the tag is allowed, false otherwise #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::_validateTagArray()``
`public none` | # `_buildParsedString( )` Builds a parsed string based on the tag array Builds a parsed string based on the tag array The correct html and attribute values are extracted from the private _definedTags array. #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See `mixed` `mixed`
`public none` | # `setText( string $str )` Sets text in the object to be parsed Sets text in the object to be parsed #### Parameters $str string the text to set in the object #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::getText()`` `mixed`
`public string` | # `getText( )` Gets the unparsed text from the object Gets the unparsed text from the object #### Returns `string` the text set in the object #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::setText()`` `mixed`
`public string` | # `getPreparsed( )` Gets the preparsed text from the object Gets the preparsed text from the object #### Returns `string` the text set in the object #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::_preparse()`` `mixed`
`public string` | # `getParsed( )` Gets the parsed text from the object Gets the parsed text from the object #### Returns `string` the parsed text set in the object #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::parse()`` `mixed`
`public none` | # `parse( )` Parses the text set in the object Parses the text set in the object #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::_preparse()`` ``SSHTMLBBCodeParser::_buildTagArray()`` ``SSHTMLBBCodeParser::_validateTagArray()`` ``SSHTMLBBCodeParser::_buildParsedString()``
`public none` | # `qparse( mixed $str )` Quick method to do setText(), parse() and getParsed at once Quick method to do setText(), parse() and getParsed at once #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::parse()`` `mixed`
`public none` | # `staticQparse( mixed $str )` Quick static method to do setText(), parse() and getParsed at once Quick static method to do setText(), parse() and getParsed at once #### Returns `none` none #### Author Stijn de Reede <sjr@gmx.co.uk> #### See ``SSHTMLBBCodeParser::parse()`` `mixed`

### Magic methods summary

## Properties summary

`public array` | $_definedTags | # An array of tags parsed by the engine, should be overwritten by filters An array of tags parsed by the engine, should be overwritten by filters
`public string` | $_text | # A string containing the input A string containing the input
`public string` | $_preparsed | # A string containing the preparsed input A string containing the preparsed input
`public array` | $_tagArray | # An array tags and texts build from the input text An array tags and texts build from the input text
`public string` | $_parsed | # A string containing the parsed version of the text A string containing the parsed version of the text
`public array` | $_options | # An array of options, filled by an ini file or through the contructor An array of options, filled by an ini file or through the contructor
`public array` | $_filters | # An array of filters used for parsing An array of filters used for parsing

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -