class utils implements utils_interface

Text manipulation utilities

In this implementation, "plain text" refers to regular text as it would be inputted by a user. "Parsed text" is XML suitable to be reinserted into the database.

Methods

string
clean_formatting(string $xml)

Replace BBCodes and other formatting elements with whitespace

string
format_attribute_value(string $str)

Format given string to be used as an attribute value

string
generate_quote(string $text, array $attributes = array())

Create a quote block for given text

string[]
get_outermost_quote_authors(string $xml)

Get a list of quote authors, limited to the outermost quotes

string
remove_bbcode(string $xml, string $bbcode_name, int $depth = 0)

Remove given BBCode and its content, at given nesting depth

string
unparse(string $xml)

Return a parsed text to its original form

bool
is_empty(string $text)

Return whether or not a parsed text represent an empty text.

Details

at line 32
string clean_formatting(string $xml)

Replace BBCodes and other formatting elements with whitespace

NOTE: preserves smilies as text

Parameters

string $xml

Parsed text

Return Value

string

Plain text

at line 50
protected string format_attribute_value(string $str)

Format given string to be used as an attribute value

Will return the string as-is if it can be used in a BBCode without quotes. Otherwise, it will use either single- or double- quotes depending on whichever requires less escaping. Quotes and backslashes are escaped with backslashes where necessary

Parameters

string $str

Original string

Return Value

string

Same string if possible, escaped string within quotes otherwise

at line 66
string generate_quote(string $text, array $attributes = array())

Create a quote block for given text

Possible attributes:

  • author: author's name (usually a username)
  • post_id: post_id of the post being quoted
  • user_id: user_id of the user being quoted
  • time: timestamp of the original message

Parameters

string $text

Quote's text

array $attributes

Quote's attributes

Return Value

string

Quote block to be used in a new post/text

at line 100
string[] get_outermost_quote_authors(string $xml)

Get a list of quote authors, limited to the outermost quotes

Parameters

string $xml

Parsed text

Return Value

string[]

List of authors

at line 127
string remove_bbcode(string $xml, string $bbcode_name, int $depth = 0)

Remove given BBCode and its content, at given nesting depth

Parameters

string $xml

Parsed text

string $bbcode_name

BBCode's name

int $depth

Minimum nesting depth (number of parents of the same name)

Return Value

string

Parsed text

at line 138
string unparse(string $xml)

Return a parsed text to its original form

Parameters

string $xml

Parsed text

Return Value

string

Original plain text

at line 146
bool is_empty(string $text)

Return whether or not a parsed text represent an empty text.

Parameters

string $text

Parsed text

Return Value

bool

True if the original text is empty