Helper methods for the core template functions/tags.

package XenForo_Template

 Methods

Adds a CSS class to a class list if it's not already there

addClass(string $class, string $classList) : string
Static

Parameters

$class

string

Class to add / remove

$classList

string

Existing class defininition

Returns

string

Gets the page navigation for an admin page.

adminPageNav(integer $perPage, integer $totalItems, integer $page, string $linkType, mixed $linkData, array $linkParams, array $options) : string | \XenForo_Template_Public
Static

Parameters

$perPage

integer

Items to display per page

$totalItems

integer

Total number of items

$page

integer

Current page number

$linkType

string

Type of link to create

$linkData

mixed

Data for the link

$linkParams

array

List of key value params for the link; page will be set as needed

$options

array

Options to control the building

Returns

Appends bread crumb entries to the existing list of bread crumbs.

appendBreadCrumbs(array $existing, array $new) : array
Static

Parameters

$existing

array

Existing entries

$new

array

New entries; if this is invalid, nothing will be appended

Returns

arrayExisting entries with new entries appended

Helper to determine if an attribute value should be treated as true

attributeTrue(mixed $attribute) : boolean
Static

Parameters

$attribute

mixed

Returns

boolean

Calls a general helper as listed in the helper callbacks.

callHelper(string $helper, array $args) : string
Static

Parameters

$helper

string

Name of helper

$args

array

All arguments passed to the helper.

Returns

string

Converts a URL that may have a route/action and named params to a form action (script name, things before query string) and named params.

convertUrlToActionAndNamedParams(string $url) : array
Static

A route in the query string is converted to a named param "_".

Parameters

$url

string

Returns

arrayFormat: [action] => form action, [params] => key-value param pairs

Date formatting.

date(integer $timestamp, string $format) : string
Static

Format represents a string name of a format.

Parameters

$timestamp

integer

Unix timestamp to format

$format

string

Named format (name options TBD)

Returns

string

Date and time formatting.

dateTime(integer $timestamp, string $format) : string
Static

Format represents a string name of a format.

Parameters

$timestamp

integer

Unix timestamp to format

$format

string

Named format (name options TBD)

Returns

string

Builds a string of attributes for insertion into an HTML tag.

getAttributes(array $attributes) : string
Static

Parameters

$attributes

array

Returns

string' attr1="abc" attr2="def" attr3="ghi"'

Returns the URL to the appropriate avatar type for the given user

getAvatarUrl(array $user, string $size, string $forceType) : string
Static

Parameters

$user

array

$size

string

(s,m,l)

$forceType

string

Force 'default' or 'custom' type

Returns

string

Returns an array containing the URLs for each avatar size available for the given user

getAvatarUrls(array $user) : array
Static

Parameters

$user

array

Returns

array[$sizeCode => $url, $sizeCode => $url...]

Gets the default language.

getDefaultLanguage() : array | null
Static

Returns

arraynull

Gets hidden inputs from a list of key-value params.

getHiddenInputs(array $params) : string
Static

Parameters

$params

array

Returns

string

Converts a URL into hidden inputs, for use in a GET form when the action may have a query string.

getHiddenInputsFromUrl(string $url) : string
Static

Note that the non-query string part of the URL will not be output in any way.

Parameters

$url

string

Returns

stringString of hidden form inputs

Returns a list of invalid style property accesses.

getInvalidStylePropertyAccessList() : array
Static
see \$_invalidStylePropertyAccess

Returns

array

Constructs ' href="link-to-user"' if appropriate

getUserHref(array $user, array $attributes) : string
Static

Parameters

$user

array

$attributes

array

Returns

string' href="members/example-user.234"' or empty

Helper to fetch the CSS rules to crop a user's avatar to their chosen square aspect

helperAvatarCropCss(array $user) 
Static

Parameters

$user

array

Returns an <a> tag for use as a user avatar

helperAvatarHtml(array $user, boolean $img, array $attributes, string $content) 
Static

Parameters

$user

array

$img

boolean

If true, use an tag, otherwise use a block with the avatar as a background image

$attributes

array

Extra tag attributes

$content

string

Additional tag contents (inserted after image element)

Helper to fetch the URL of a user's avatar.

helperAvatarUrl(array $user, string $size, boolean $forceType, boolean $canonical) : string
Static

Parameters

$user

array

User info

$size

string

Size code

$forceType

boolean

Serve the default gender avatar, even if the user has a custom avatar

$canonical

boolean

Serve the full canonical URL

Returns

stringPath to avatar

Helper to render the specified text as BB code.

helperBbCode(\XenForo_BbCode_Parser $parser, string $text) : string
Static

Parameters

$text

string

Returns

string

Prepares simple body text with word wrap, censoring, and nl2br.

helperBodyText(string $string) : string
Static

HTML/BB code is not parsed within string.

Parameters

$string

string

Returns

string

Returns an <abbr> tag with a date suitable for Javascript refreshing

helperDateTimeHtml(integer $timestamp, array $attributes) : string
Static

Parameters

$timestamp

integer

$attributes

array

Returns

string

helperDump()

helperDump($data) 
Static

Parameters

$data

Returns a hyperlink to follow or unfollow a user.

helperFollowHtml(array $user, array $attributes, string $wrapTag) : string
Static

Designed to work with the XenForo.FollowLink javascript.

Parameters

$user

array

$attributes

array

$wrapTag

string

Returns

string

helperIgnoredCss()

helperIgnoredCss(array $ignoredUsers) 
Static

Parameters

$ignoredUsers

helperImplode()

helperImplode($data, $glue) 
Static

Parameters

$data

$glue

Determines whether or not the given user ID / username is being ignored by the visiting user

helperIsIgnored(integer | string $user, array $ignoredNames) : boolean
Static

Parameters

$user

integerstring

$ignoredNames

Returns

boolean

helperIsMemberOf()

helperIsMemberOf(array $user, $userGroupId, $multipleIds) 
Static

Parameters

$user

$userGroupId

$multipleIds

helperJavaScriptUrl()

helperJavaScriptUrl($scriptUrl) 
Static

Parameters

$scriptUrl

Encodes the incoming data as JSON

helperJson(mixed $data) : string
Static

Parameters

$data

mixed

Returns

stringJSON

Returns an HTML string declaring who likes something

helperLikesHtml(integer $number, string $likesLink, integer $likeDate, array $users) : string
Static

Parameters

$number

integer

Total number of likes

$likesLink

string

Link to page showing all users who liked this content

$likeDate

integer

Timestamp at which the visitor liked this content

$users

array

Array of up to 3 users who liked this content - user_id, username required.

Returns

string

Returns a string of CSS class names, identifying the current node and all its ancestors.

helperNodeClasses(array $nodeBreadCrumbs, array $currentNode) : string
Static

Parameters

$nodeBreadCrumbs

array

$currentNode

array

Returns

string'node5 node3 node1'

Wrapper function for handling pagenav template tags (not functions).

helperPageNavHtml(string $callType, integer $perPage, integer $totalItems, integer $page, string $linkType, mixed $linkData, array $linkParams, string | false $unreadLink, array $options) : string
Static

This simply ensures that some of the data is of the expected type.

Parameters

$callType

string

Type of page to render: admin or public

$perPage

integer

Items to display per page

$totalItems

integer

Total number of items

$page

integer

Current page number

$linkType

string

Type of link to create

$linkData

mixed

Data for the link

$linkParams

array

List of key value params for the link; page will be set as needed

$unreadLink

stringfalse

URL for to jump to the first unread

$options

array

Options to control the building

Returns

string

Returns the string ' | Page $page' if $page is greater than one.

helperPageNumber(integer $page) : string
Static

Parameters

$page

integer

Returns

string

Outputs the necessary HTML for a rich username (includes the display style markup class).

helperRichUserName(array $user, string $usernameHtml) : string
Static

Parameters

$user

array

$usernameHtml

string

Alternative username HTML

Returns

string

Strips BB Code from a string and word-trims it to a given max length around an optional search term

helperSnippet(string $string, integer $maxLength, array $options) : string
Static

Parameters

$string

string

Input text (bb code)

$maxLength

integer

$options

array

Key-value options

Returns

stringHTML

Helper to print out the sort arrow.

helperSortArrow(string $order, string $direction, string $fieldName, string $descOutput, string $ascOutput) : string
Static

Parameters

$order

string

Name of the current ordering field

$direction

string

Direction (asc, desc)

$fieldName

string

Name of the field we're looking at

$descOutput

string

HTML to output for descending

$ascOutput

string

HTML to output for ascending

Returns

string

Strips HTML from the text and then HTML escapes it without double encoding.

helperStripHtml(string $string, string $allowedTags) : string
Static

Parameters

$string

string

$allowedTags

string

List of allowed tags for strip_tags

Returns

stringString with HTML removed or escaped if not removed.

Helper to display a thread prefix for the specified prefix ID/thread.

helperThreadPrefix(integer | array $prefixId, string $outputType, string | null $append) : string
Static

Can take an array.

Parameters

$prefixId

integerarray

Prefix ID or array with key of prefix_id

$outputType

string

Type of output; options are html (marked up), plain (plain text), escaped (plain text escaped)

$append

stringnull

Value to append if there is a prefix (eg, a space); if null, defaults to space (html) or dash (plain)

Returns

string

helperThreadPrefixGroup()

helperThreadPrefixGroup($prefixGroupId) 
Static

Parameters

$prefixGroupId

helperTwitterLanguage()

helperTwitterLanguage($locale) 
Static

Parameters

$locale

helperType()

helperType($data) 
Static

Parameters

$data

helperUniqueId()

helperUniqueId() 
Static

Helper, for the user blurb "Title, gender, age, from location".

helperUserBlurb(array $user, boolean $includeUserTitle) : string
Static

Parameters

$user

array

$includeUserTitle

boolean

Include user title in blurb

Returns

string

Helper to fetch the title of a custom user field from its ID

helperUserFieldTitle($fieldId) : \XenForo_Phrase
Static

Parameters

$fieldId

Returns

Helper to fetch the HTML value of a custom user field

helperUserFieldValue(array | string $field, array $user, mixed $fieldValue) : string | boolean
Static

Parameters

$field

arraystring

Either the field info array for a field, or just its field_id

$user

array

User to whom the field belongs

$fieldValue

mixed

Value of the field for $user

Returns

stringboolean

helperUserName()

helperUserName(array $user, $class, $rich) 
Static

Parameters

$user

$class

$rich

Produces a <a href="members/username.123" class="username">Username</a> snippet

helperUserNameHtml(array $user, string $username, boolean $rich, array $attributes) : string
Static

Parameters

$user

array

$username

string

Used to override the username from $user

$rich

boolean

Render rich username markup

$attributes

array

Attributes for the tag

Returns

string

Helper to get the user title for the specified user.

helperUserTitle(array $user, boolean $allowCustomTitle) : string
Static

Parameters

$user

array

$allowCustomTitle

boolean

Allows the user title to come from the custom title

Returns

string

Word trims and HTML escapes the given string.

helperWordTrim(string $string, integer $trimLength) 
Static

Parameters

$string

string

$trimLength

integer

Wraps and HTML escapes the given string.

helperWrap(string $string, integer | null $breakLength) 
Static

Parameters

$string

string

$breakLength

integernull

Escape a string for use within JavaScript.

jsEscape(string $string, string $context) : string
Static

The context represents whether it is within a double- or single-quoted string. This function does not support outputs in other contexts!

Parameters

$string

string

String to escape

$context

string

Context (double or single)

Returns

string

Formats a number based on current user's language.

numberFormat(mixed $number, integer $decimals) : string
Static

Behaves like PHP's number_format.

Parameters

$number

mixed

$decimals

integer

Returns

string

Gets the page navigation for a public page.

pageNav(integer $perPage, integer $totalItems, integer $page, string $linkType, mixed $linkData, array $linkParams, array $options) : string | \XenForo_Template_Public
Static

Parameters

$perPage

integer

Items to display per page

$totalItems

integer

Total number of items

$page

integer

Current page number

$linkType

string

Type of link to create

$linkData

mixed

Data for the link

$linkParams

array

List of key value params for the link; page will be set as needed

$options

array

Options to control the building

Returns

Returns the content in its raw format only if it meets the specified condition.

rawCondition(mixed $data, string $condition) : mixed
Static

Parameters

$data

mixed

$condition

string

"Object" to return any object raw, otherwise a class name

Returns

mixedData escaped if needed

Resets invalid style property accesses.

resetInvalidStylePropertyAccessList() 
Static

Sets the default language for language-specific calls.

setDefaultLanguage(array $language) 
Static

This should be unset after the specific context is complete.

Parameters

$language

arraynull

Sets the display styles.

setDisplayStyles(array $displayStyles) 
Static

Parameters

$displayStyles

array

Helper to set the available style properties.

setStyleProperties(array $properties, boolean $merge) 
Static

Parameters

$properties

array

Style properties

$merge

boolean

True to merge with existing set

Sets the thread prefixes.

setThreadPrefixes(array $prefixes) 
Static

Parameters

$prefixes

array

[prefix id] => class name

Sets the user titles in the ladder.

setUserTitles(array $userTitles) 
Static

Parameters

$userTitles

array

Performs string manipulation functions.

string(string $functionList, array $args) : string
Static

Function list is a string that may be delimited by " " (eg, 'nl2br trim'). Chained functions will be run from left to right. Chaining can only work when a single argument is provided. Functions requiring multiple args need separate calls.

Parameters

$functionList

string

$args

array

Returns

string

Outputs a style property or a group of style properties.

styleProperty(string $propertyName) : string
Static

See $_styleProperties for more information on the format. The property name may be in format "group" or "group.rule". Scalar properties cannot have a rule.

If no rule is specified, an entire group will be outputted, including rule names. If a rule is specified, only the value will be output.

Parameters

$propertyName

string

Returns

string

Time formatting.

time(integer $timestamp, string $format) : string
Static

Format represents a string name of a format.

Parameters

$timestamp

integer

Unix timestamp to format

$format

string

Named format (name options TBD)

Returns

string

Adds a CSS class to a class list if it is not already there, otherwise removes it

toggleClass(string $class, string $classList) : string
Static

Parameters

$class

string

Class to add / remove

$classList

string

Existing class defininition

Returns

string

Returns the URL to a user's custom avatar

_getCustomAvatarUrl(array $user, string $size) : string
Static

Parameters

$user

array

$size

string

(s,m,l)

Returns

string

Returns the default gender-specific avatar URL

_getDefaultAvatarUrl(array $user, string $size) : string
Static

Parameters

$user

$size

string

(s,m,l)

Returns

string

Returns a Gravatar URL for the user

_getGravatarUrl(array $user, string | integer $size, string $default) 
Static

Parameters

$user

array

$size

stringinteger

(s,m,l)

$default

string

Override default (useful to use '404')

Fetches a model object from the local cache

_getModelFromCache(string $modelName) : \XenForo_Model
Static

Parameters

$modelName

string

Returns

Helper to get page navigation (all pages, for scrolling pagenav version).

_getPageNav(string $templateClass, string $linkFunction, integer $perPage, integer $totalItems, integer $currentPage, string $linkType, mixed $linkData, array $linkParams, array $options) : string | \XenForo_Template_Abstract
Static

Parameters

$templateClass

string

Name of the template class to instantiate

$linkFunction

string

Name of the linking function to call (in this class)

$perPage

integer

Items to display per page

$totalItems

integer

Total number of items

$currentPage

integer

Current page number

$linkType

string

Type of link to create

$linkData

mixed

Data for the link

$linkParams

array

List of key value params for the link; page will be set as needed

$options

array

Options to control the building

Returns

Fetches the text of the specified phrase

_getPhraseText(string $phraseName) : string
Static

Parameters

$phraseName

string

Returns

string

Private constructor.

__construct() 

Don't instantiate this object. Use it statically.

 Properties

 

$helperCallbacks : array

Maps the helper name (key) to a callback (value).

Data received by this callback is not escaped!

 

$stringCallbacks : array

To support chaining, the called function should tag the string as the first argument and only require one argument. If neither constraint is true, the function must be called on its own.

Data received by this call back may be escaped!

 

$_displayStyles : array
 

$_invalidStylePropertyAccess : array

If an invalid group is accessed: [group] => true; if an invalid property in a valid group is accessed: [group][property] => true.

 

$_language : array | null

Null uses the visitor's language.

 

$_modelCache : array
 

$_styleProperties : array

The first dimension is a group of properties; the second represents the actual rules. Rules should be keyed by the CSS property name so they can be output directly. Prefix non-direct CSS vars with an underscore.

 

$_threadPrefixes : array
 

$_uniqueId 
 

$_userFieldsInfo : array
 

$_userFieldsValues : array
 

$_userTitles : array