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

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

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

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

Parameters

$attribute

mixed

Returns

boolean

Calls a general helper as listed in the helper callbacks.

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

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

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

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

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

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

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

Parameters

$user

array

Returns

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

Gets the default language.

getDefaultLanguage() : array | null

Returns

arraynull

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

getHiddenInputs(array $params) : string

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

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

see \global\$_invalidStylePropertyAccess

Returns

array

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

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

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) 

Parameters

$user

array

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

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

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

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

Parameters

$text

string

Returns

string

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

helperBodyText(string $string) : string

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

Parameters

$timestamp

integer

$attributes

array

Returns

string

helperDump()

helperDump($data) 

Parameters

$data

Returns a hyperlink to follow or unfollow a user.

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

Designed to work with the XenForo.FollowLink javascript.

Parameters

$user

array

$attributes

array

$wrapTag

string

Returns

string

helperIgnoredCss()

helperIgnoredCss(array $ignoredUsers) 

Parameters

$ignoredUsers

helperImplode()

helperImplode($data, $glue) 

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

Parameters

$user

integerstring

$ignoredNames

Returns

boolean

helperIsMemberOf()

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

Parameters

$user

$userGroupId

$multipleIds

helperJavaScriptUrl()

helperJavaScriptUrl($scriptUrl) 

Parameters

$scriptUrl

Encodes the incoming data as JSON

helperJson(mixed $data) : string

Parameters

$data

mixed

Returns

stringJSON

Returns an HTML string declaring who likes something

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

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

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

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

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

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

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

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

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

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) 

Parameters

$prefixGroupId

helperTwitterLanguage()

helperTwitterLanguage($locale) 

Parameters

$locale

helperType()

helperType($data) 

Parameters

$data

helperUniqueId()

helperUniqueId() 

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

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

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

Parameters

$fieldId

Returns

Helper to fetch the HTML value of a custom user field

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

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) 

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

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

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) 

Parameters

$string

string

$trimLength

integer

Wraps and HTML escapes the given string.

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

Parameters

$string

string

$breakLength

integernull

Escape a string for use within JavaScript.

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

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

Behaves like PHP's number_format.

Parameters

$number

mixed

$decimals

integer

Returns

string

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

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

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() 

Sets the default language for language-specific calls.

setDefaultLanguage(array $language) 

This should be unset after the specific context is complete.

Parameters

$language

arraynull

Sets the display styles.

setDisplayStyles(array $displayStyles) 

Parameters

$displayStyles

array

Helper to set the available style properties.

setStyleProperties(array $properties, boolean $merge) 

Parameters

$properties

array

Style properties

$merge

boolean

True to merge with existing set

Sets the thread prefixes.

setThreadPrefixes(array $prefixes) 

Parameters

$prefixes

array

[prefix id] => class name

Sets the user titles in the ladder.

setUserTitles(array $userTitles) 

Parameters

$userTitles

array

Performs string manipulation functions.

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

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

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

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

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

Parameters

$user

array

$size

string

(s,m,l)

Returns

string

Returns the default gender-specific avatar URL

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

Parameters

$user

$size

string

(s,m,l)

Returns

string

Returns a Gravatar URL for the user

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

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

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

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

Parameters

$phraseName

string

Returns

string

Private constructor.

__construct() 

Don't instantiate this object. Use it statically.

 Properties

 

List of callbacks for the "helper" template tag.

$helperCallbacks : array

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

Data received by this callback is not escaped!

 

List of callbacks for the "string" template tag.

$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!

 

List of display styles for user title/name markup.

$_displayStyles : array

 

A list of invalid property accesses.

$_invalidStylePropertyAccess : array

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

 

Default language to send to functions that vary per language.

$_language : array | null

Null uses the visitor's language.

 

Array to cache model objects

$_modelCache : array

 

Holds data about style properties available to the templates.

$_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.

 

List of thread prefixes for marking up threads.

$_threadPrefixes : array

 

$_uniqueId

$_uniqueId 

 

Array to cache user custom field info

$_userFieldsInfo : array

 

Array to cache user custom field values

$_userFieldsValues : array

 

List of user titles in ladder.

$_userTitles : array