Helper to do common string operations, such as word wrap and censoring.

package XenForo_Helper

 Methods

Automatically links URLs/email in the given string of BB code.

autoLinkBbCode(string $string) : string

Output will be original BB code input with [url] or [email] tags inserted where ncessary.

Parameters

$string

string

BB code string

Returns

string

Auto-links URLs in plain text.

autoLinkPlainText(string $string, boolean $htmlEncoded) : string

This text should generally already be HTML escaped, because it can't be done after the linking.

Parameters

$string

string

$htmlEncoded

boolean

Denotes whether the text is already encoded; if false, the URL will be encoded before being put into the link

Returns

stringText with links added

Strips BB code from a string

bbCodeStrip(string $string, boolean $stripQuote) : string

Parameters

$string

string

$stripQuote

boolean

If true, contents from within quote tags are stripped

Returns

string

Builds the censorship array.

buildCensorArray(array $words, string $censorString) : array

Parameters

$words

array

List of words (from option format)

$censorString

string

String to replace each character with if no replacement map

Returns

arrayPossible keys: exact, any with key-value search/replace pairs

Censors the given string.

censorString(string $string, array $words, string | null $censorString) : string

Parameters

$string

string

$words

arraynull

Words to censor. Null to use option value.

$censorString

stringnull

String to censor each character with. Null to use option value.

Returns

string

Helper to allow templates to pass the censor string to self::censorString()

censorStringTemplateHelper(string $string, string $censorString) : string

Parameters

$string

string

$censorString

string

Returns

string

Gets the class and target to apply to a specified link URL.

getLinkClassTarget(string $url) : array

Parameters

$url

string

Returns

array[class, target, type (internal/external)]

Returns an HTML string with instances a search term highlighted with <em class="$emClass">.

highlightSearchTerm(string $string, string $term, string $emClass) : string

..

Parameters

$string

string

Haystack

$term

string

Needle

$emClass

string

Class with which to style the wrapping

Returns

stringHTML

Given a text that appears to be a URL, extracts the components from it, possibly moving characters after the link or adding http://.

prepareAutoLinkedUrl(string $url) : array

Parameters

$url

string

URL that may have trailing characters or missing scheme

Returns

arrayKeys: url, linkText, suffixText

Strips out quoted text from the specified string, allowing for quoted text up to a specified depth.

stripQuotes(string $string, integer $allowedDepth, boolean $censorResults) : string

Parameters

$string

string

$allowedDepth

integer

-1 for unlimited depth

$censorResults

boolean

Returns

stringQuotes stripped

Returns a string that is snipped to $maxLength characters at the nearest space, Appends an elipsis if the string is snipped.

wholeWordTrim($string, integer $maxLength, integer $offset, string $elipses) : string

Parameters

$string

string

$maxLength

integer

Max length of returned string, excluding elipsis

$offset

integer

Offset from string start - will add leading elipsis

$elipses

string

Elipses string (default: '...')

Returns

string

Creates a snippet of $length maximum characters around a search term.

wholeWordTrimAroundSearchTerm($string, $maxLength, $term) : string

If the term is not found, the snippet is taken from the string start.

Parameters

$string

$maxLength

$term

Returns

string

Adds spaces to the given string after the given amount of contiguous, non-whitespace characters.

wordWrapString(string $string, integer $breakLength) : string

Parameters

$string

string

$breakLength

integer

Number of characters before break; if null, use option

Returns

string

Internal handler for auto-linking regex.

_autoLinkPlainTextCallback(array $match) : string

Parameters

$match

array

Returns

string

Private constructor.

__construct() 

Use statically.

 Properties

 

Internal value of html encoded variable for auto-linking.

$_alptHtmlEncoded : boolean

Only used to pass to callback.

 

Censor cache for default words/censor string option.

$_censorCache : array | null