Documentation

SmileyParser extends Parser
in package

Converts smiley codes to HTML img tags.

Table of Contents

Constants

INPUT_BBC  = 0b1
INPUT_MARKDOWN  = 0b10
INPUT_SMILEYS  = 0b100
OUTPUT_BBC  = 2
OUTPUT_HTML  = 0
OUTPUT_TEXT  = 1

Properties

$custom_smileys_enabled  : bool
$defalt_options  : array<string|int, mixed>
$disabled  : array<string|int, mixed>
$enable_bbc  : bool
$enable_markdown  : bool
$enable_post_html  : bool
$encoding  : string
$for_print  : bool
$locale  : string
$parse_tags  : array<string|int, mixed>
$smiley_set  : string
$smileys_url  : string
$time_format  : string
$time_offset  : int
$smiley_preg_replacements  : array<string|int, mixed>
$smiley_preg_search  : string
$data  : array<string|int, mixed>
$parser  : self
$results  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructor.
getBBCodes()  : array<string|int, mixed>
Get the list of supported BBCodes, including any added by modifications.
getBBCodeTagsRegex()  : string
Gets a regular expression to match all known BBC tags.
getSigTags()  : array<string|int, mixed>
Returns an array of BBCodes tags that are allowed in signatures.
highlightPhpCode()  : string
Highlight any code.
load()  : object
Returns a reusable instance of this class.
loadData()  : array<string|int, mixed>
Loads data for the requested smiley set from the database.
parse()  : string
Parse smileys in the passed string.
transform()  : string
Transforms one type of markup into another.
unparse()  : string
Converts HTML img tags for smileys back into smiley text.
disableCode()  : array<string|int, mixed>
Adjusts a BBCode definition so that it outputs its disabled version.
getCacheKey()  : string
Generates a unique cache key for the combination of string, parameters, settings, etc., that apply to this particular call to self::transform().
highLoadAverage()  : bool
Checks whether the server's load average is too high to parse BBCode.
setDisabled()  : void
Sets $this->disabled.
setOptions()  : array<string|int, mixed>
Fills in any missing elements of $options with the default values.
setStaticVars()  : void
Sets the values of this class's static variables.
toBBC()  : string
Transforms the input string into BBCode.
toHTML()  : string
Transforms the input string into HTML.
toText()  : string
Transforms the input string into plain text (i.e. removes all markup).

Constants

INPUT_BBC

public int INPUT_BBC = 0b1

Indicates that BBCode should be parsed in the input string.

INPUT_MARKDOWN

public int INPUT_MARKDOWN = 0b10

Indicates that Markdown should be parsed in the input string.

INPUT_SMILEYS

public int INPUT_SMILEYS = 0b100

Indicates that smileys should be parsed in the input string.

When the output type is HTML, this controls whether smiley text will be transformed into tags pointing to smiley images.

When the output type is plain text, this controls whether tags for smiley images will be transformed into smiley text or removed.

When the output type is BBCode, this controls whether tags for smiley images will be transformed into smiley text or [img] BBCodes.

OUTPUT_BBC

public int OUTPUT_BBC = 2

Used to set the output to BBCode.

When this is used, HTML and Markdown in the input will be transformed into the equivalent BBCode. Unsupported HTML tags will be removed.

OUTPUT_HTML

public int OUTPUT_HTML = 0

Used to set the output to HTML.

This is the default output type.

OUTPUT_TEXT

public int OUTPUT_TEXT = 1

Used to set the output to plain text.

When this is used, the input will be parsed into HTML and then the HTML tags will be stripped.

Properties

$custom_smileys_enabled

public static bool $custom_smileys_enabled

Whether custom smileys are enabled.

$defalt_options

public static array<string|int, mixed> $defalt_options = ['cache_id' => '', 'parse_tags' => [], 'for_print' => false, 'hard_breaks' => null, 'no_paragraphs' => false, 'str_replace' => [], 'preg_replace' => []]

Default options for the various parsers.

  • cache_id: ID string to identify the string for caching purposes. If empty, an ID will be generated automatically. Default: ''

  • parse_tags: A list of specific BBC tags to parse. If empty, all BBC are parsed. Default: []

  • for_print: Whether the output is intended for a non-interactive medium, such as being printed on paper. Default: false

  • hard_breaks: Controls how line breaks are handled by MarkdownParser. For more info, see the documentation for MarkdownParser::__construct(). Default: null

  • str_replace: String replacements to apply when converting to plain text. Keys are the strings to find, and values are the replacements. These replacements are applied after the input has been transformed into HTML and before the HTML tags are stripped out. Default: []

  • preg_replace: Similar to str_replace, except that the keys are regular expressions. Default: []

Mods implementing custom parsers can add values to this array using the integrate_parser_options hook.

$disabled

public array<string|int, mixed> $disabled = []

List of disabled BBCode tags.

$enable_bbc

public static bool $enable_bbc

Whether BBCode should be parsed.

$enable_markdown

public static bool $enable_markdown

Whether Markdown should be parsed.

$enable_post_html

public static bool $enable_post_html

Whether to allow certain basic HTML tags in the input.

$encoding

public static string $encoding

The character encoding of the strings to be parsed.

$for_print

public bool $for_print = false

Enables special handling if output is meant for paper printing.

$locale

public static string $locale

Language locale to use.

$parse_tags

public array<string|int, mixed> $parse_tags = []

If not empty, only these BBCode tags will be parsed.

$smiley_set

public static string $smiley_set

The smiley set to use when parsing smileys.

$smileys_url

public static string $smileys_url

URL of the base smileys directory.

$time_format

public static string $time_format

User's time format string.

$time_offset

public static int $time_offset

User's time offset from UTC.

$smiley_preg_replacements

protected array<string|int, mixed> $smiley_preg_replacements

Replacement values for smileys.

protected string $smiley_preg_search

Regular expression to match smileys.

$data

private static array<string|int, mixed> $data

Smiley data retrieved from the database.

$parser

private static self $parser

A reference to an existing, reusable instance of this class.

$results

private static array<string|int, mixed> $results = []

Holds parsed messages.

Methods

getBBCodes()

Get the list of supported BBCodes, including any added by modifications.

public static getBBCodes() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of supported BBCodes.

getBBCodeTagsRegex()

Gets a regular expression to match all known BBC tags.

public static getBBCodeTagsRegex() : string
Return values
string

Regular expression to match all BBCode tags.

getSigTags()

Returns an array of BBCodes tags that are allowed in signatures.

public static getSigTags() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array containing allowed tags for signatures, or an empty array if all tags are allowed.

highlightPhpCode()

Highlight any code.

public static highlightPhpCode(string $code) : string

Uses PHP's highlight_string() to highlight PHP syntax. Does special handling to keep the tabs in the code available. Used to parse PHP code from inside [code] and [php] tags.

Parameters
$code : string

The code.

Return values
string

The code with highlighted HTML.

load()

Returns a reusable instance of this class.

public static load() : object

Using this method to get a SmileyParser instance saves memory by avoiding creating redundant instances.

Return values
object

An instance of this class.

loadData()

Loads data for the requested smiley set from the database.

public static loadData(string $set) : array<string|int, mixed>
Parameters
$set : string

The name of the smiley set.

Return values
array<string|int, mixed>

Data for all the smileys in the specified set.

parse()

Parse smileys in the passed string.

public parse(string $string) : string

The smiley parsing function which makes pretty faces appear :). If custom smiley sets are turned off by smiley_enable, the default set of smileys will be used. These are specifically not parsed in code tags [url=mailto:Dad@blah.com] Caches the smileys from the database or array in memory.

Parameters
$string : string

The string to parse smileys in.

Return values
string

The string with smiley images inserted.

transform()

Transforms one type of markup into another.

public static transform(string $string[, int $input_types = self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS ][, int $output_type = self::OUTPUT_HTML ][, array<string|int, mixed> $options = [] ]) : string

Supported input markup types are BBCode, Markdown, and smileys. Supported output markup types are HTML, BBCode, and plain text.

Parameters
$string : string

The string in which to transform markup.

$input_types : int = self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS

Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string. Default: self::INPUT_BBC | self::INPUT_MARKDOWN | self::INPUT_SMILEYS

$output_type : int = self::OUTPUT_HTML

One of this class's INPUT_* constants. Default: self::OUTPUT_HTML

$options : array<string|int, mixed> = []

Various parser options. See self::$default_options.

Return values
string

The transformed string.

unparse()

Converts HTML img tags for smileys back into smiley text.

public unparse(string $string) : string
Parameters
$string : string

Text containing HTML.

Return values
string

The string with smiley images converted to text.

disableCode()

Adjusts a BBCode definition so that it outputs its disabled version.

protected disableCode(array<string|int, mixed> $code) : array<string|int, mixed>
Parameters
$code : array<string|int, mixed>

A BBCode definition.

Return values
array<string|int, mixed>

The disabled version of the BBCode definition.

getCacheKey()

Generates a unique cache key for the combination of string, parameters, settings, etc., that apply to this particular call to self::transform().

protected static getCacheKey(string $string, int $input_types, int $output_type, array<string|int, mixed> $options) : string
Parameters
$string : string

The string in which to transform markup.

$input_types : int

Bitmask of this class's INPUT_* constants.

$output_type : int

One of this class's INPUT_* constants.

$options : array<string|int, mixed>

An array of parser options.

Return values
string

A unique cache key.

highLoadAverage()

Checks whether the server's load average is too high to parse BBCode.

protected highLoadAverage() : bool
Return values
bool

Whether the load average is too high.

setDisabled()

Sets $this->disabled.

protected setDisabled() : void

setOptions()

Fills in any missing elements of $options with the default values.

protected static setOptions(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

An array of parser options.

Return values
array<string|int, mixed>

An updated copy of $options.

setStaticVars()

Sets the values of this class's static variables.

protected static setStaticVars() : void

If a variable already has a value, the existing value is not changed. This ensures that custom values set by external code are respected.

toBBC()

Transforms the input string into BBCode.

protected static toBBC(string $string, int $input_types, array<string|int, mixed> $options) : string
  • Markdown is transformed to the equivalent BBCode.
  • HTML img tags for smileys are transformed to smiley text.
  • Other HTML is transformed to the equivalent BBCode where possible.
  • HTML tags that cannot be transformed are removed.
Parameters
$string : string

The string in which to remove markup.

$input_types : int

Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.

$options : array<string|int, mixed>

An array of parser options.

Return values
string

The transformed string.

toHTML()

Transforms the input string into HTML.

protected static toHTML(string $string, int $input_types, array<string|int, mixed> $options) : string
Parameters
$string : string

The string in which to transform markup.

$input_types : int

Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.

$options : array<string|int, mixed>

An array of parser options.

Return values
string

The transformed string.

toText()

Transforms the input string into plain text (i.e. removes all markup).

protected static toText(string $string, int $input_types, array<string|int, mixed> $options) : string
Parameters
$string : string

The string in which to remove markup.

$input_types : int

Bitmask of this class's INPUT_* constants. Only the indicated types of markup will be parsed in the input string.

$options : array<string|int, mixed>

An array of parser options.

Return values
string

The transformed string.


        
On this page

Search results