Model for templates

Models don't share that much, so most implementations will be adding methods onto this class. This class simply provides helper methods for common actions.

package XenForo_Templates

 Methods

Constructor.

__construct() 
Inherited

Use create() statically unless you know what you're doing.

inherited_from \XenForo_Model::__construct()

Adds a join to the set of fetch options.

addFetchOptionJoin(array $fetchOptions, integer $join) 
Inherited

Join should be one of the constants.

inherited_from \XenForo_Model::addFetchOptionJoin()

Parameters

$fetchOptions

array

$join

integer

Adds the equivalent of a limit clause using position-based limits.

addPositionLimit(string $table, integer $limit, integer $offset, string $column) : string
Inherited

It no limit value is specified, nothing will be returned.

This must be added within a WHERE clause. If a clause is required, it will begin with "AND", so ensure there is a condition before it.

inherited_from \XenForo_Model::addPositionLimit()

Parameters

$table

string

Name of the table alias to prefix. May be blank for no table reference.

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

$column

string

Name of the column that is storing the position

Returns

stringPosition limit clause if needed

Appends the add-on template XML to a given DOM element.

appendTemplatesAddOnXml(\DOMElement $rootNode, string $addOnId) 

Parameters

$rootNode

\DOMElement

Node to append all elements to

$addOnId

string

Add-on ID to be exported

Appends the template XML for templates in the specified style.

appendTemplatesStyleXml(\DOMElement $rootNode, integer $styleId) 

Parameters

$rootNode

\DOMElement

$styleId

integer

Ensures that a valid cut-off operator is passed.

assertValidCutOffOperator(string $operator) 
Inherited

inherited_from \XenForo_Model::assertValidCutOffOperator()

Parameters

$operator

string

Builds (and inserts) the template map for a specified template, from the root of the style tree.

buildTemplateMap(string $title, array $data) 

Parameters

$title

string

Title of the template being build

$data

array

Injectable data. Supports styleTree and styleTemplateMap.

Builds the full template map data for an entire style sub-tree.

buildTemplateMapForStyleTree(integer $styleId) : array

Parameters

$styleId

integer

Starting style. This style and all children will be built.

Returns

arrayFormat: [style id][title] => template id

Checks that the templates directory has been configured and exists

canImportTemplatesFromDevelopment() : boolean

Returns

boolean

Determines if the visiting user can modify a template in the specified style.

canModifyTemplateInStyle(integer $styleId) : boolean

If debug mode is not enabled, users can't modify templates in the master style.

Parameters

$styleId

integer

Returns

boolean

Recompiles all templates.

compileAllTemplates(integer $maxExecution, integer $startStyle, integer $startTemplate) : boolean | array

Parameters

$maxExecution

integer

The approx maximum length of time this function will run for

$startStyle

integer

The ID of the style to start with

$startTemplate

integer

The number of the template to start with in that style (not ID, just counter)

Returns

booleanarrayTrue if completed successfull, otherwise array of where to restart (values start style ID, start template counter)

Compiles and inserts the specified effective templates.

compileAndInsertEffectiveTemplates(array $templates) 

Parameters

$templates

array

Array of effective template info

Compiles the specified parsed template and updates the compiled table and included templates list.

compileAndInsertParsedTemplate(integer $templateMapId, string | array $parsedTemplate, string $title, integer $compileStyleId) 

Parameters

$templateMapId

integer

The map ID of the template being compiled (for includes)

$parsedTemplate

stringarray

Parsed form of the template

$title

string

Title of the template

$compileStyleId

integer

Style ID of the template

Compiles the list of template map IDs and any child templates that are using the same core template.

compileMappedTemplatesInStyleTree(integer | array $templateMapIds) : array

Parameters

$templateMapIds

integerarray

One map ID as a scalar or many as an array

Returns

arrayA list of template map IDs that were compiled

Compiles the named template in the style tree.

compileNamedTemplateInStyleTree(string $title, integer $styleId) : array

Any child templates that use this template will be recompiled as well.

Parameters

$title

string

$styleId

integer

Returns

arrayA list of template map IDs that were compiled

Compiles the specified template data in the style tree.

compileTemplateInStyleTree(array $parsedRecord) : array

This compiles this template in any style that is actually using this template.

Parameters

$parsedRecord

array

Full template information

Returns

arrayList of template map IDs that were compiled

Recompiles all templates that include the named phrase.

compileTemplatesThatIncludePhrase(string $phraseTitle) : array

Parameters

$phraseTitle

string

Returns

arrayList of template map IDs that were compiled

Factory method to get the named model.

create(string $class) : \XenForo_Model
Inherited

The class must exist or be autoloadable or an exception will be thrown.

inherited_from \XenForo_Model::create()

Parameters

$class

string

Class to load

Returns

Deletes the file versions of all templates

deleteTemplateFiles() 

Deletes the templates that belong to the specified add-on.

deleteTemplatesForAddOn(string $addOnId) 

Parameters

$addOnId

string

deleteTemplatesInStyle()

deleteTemplatesInStyle($styleId) 

Parameters

$styleId

Fetches results from the database with each row keyed according to preference.

fetchAllKeyed(string $sql, string $key, mixed $bind, string $nullPrefix) : array
Inherited

The 'key' parameter provides the column name with which to key the result. For example, calling fetchAllKeyed('SELECT item_id, title, date FROM table', 'item_id') would result in an array keyed by item_id: [$itemId] => array('item_id' => $itemId, 'title' => $title, 'date' => $date)

Note that the specified key must exist in the query result, or it will be ignored.

inherited_from \XenForo_Model::fetchAllKeyed()

Parameters

$sql

string

SQL to execute

$key

string

Column with which to key the results array

$bind

mixed

Parameters for the SQL

$nullPrefix

string

If the key is null, prefix the counter with this

Returns

array

Finds the necessary template map updates for the specified template within the sub-tree.

findTemplateMapUpdates(integer $parentId, array $styleTree, array $styleTemplateMap, integer $defaultTemplateId) : array

If {$defaultTemplateId} is non-0, a return entry will be inserted for {$parentId}.

Parameters

$parentId

integer

Parent of the style sub-tree to search.

$styleTree

array

Tree of styles

$styleTemplateMap

array

List of styleId => templateId pairs for the places where this template has been customized.

$defaultTemplateId

integer

The default template ID that non-customized template in the sub-tree should get.

Returns

arrayFormat: [style id] => [effective template id]

Gets all effective templates in a style.

getAllEffectiveTemplatesInStyle(integer $styleId) : array

"Effective" means a merged/flattened system where every valid template has a record.

Parameters

$styleId

integer

Returns

arrayFormat: [] => (array) effective template info

Returns all templates customized in a style in alphabetical title order

getAllTemplatesInStyle(integer $styleId, boolean $basicData) : array

Parameters

$styleId

integer

Style ID

$basicData

boolean

If true, gets basic data only

Returns

arrayFormat: [] => (array) template

Gets a list of SQL conditions in the format for a clause.

getConditionsForClause(array $sqlConditions) : string
Inherited

This always returns a value that can be used in a clause such as WHERE.

inherited_from \XenForo_Model::getConditionsForClause()

Parameters

$sqlConditions

array

Returns

string

Gets the specified field from a content type, if specified for that type.

getContentTypeField(string $contentType, string $fieldName) : string | false
Inherited

inherited_from \XenForo_Model::getContentTypeField()

Parameters

$contentType

string

$fieldName

string

Returns

stringfalse

Gets the value of the specified field for each content type that has that field.

getContentTypesWithField(string $fieldName) : array
Inherited

inherited_from \XenForo_Model::getContentTypesWithField()

Parameters

$fieldName

string

Returns

arrayFormat: [content type] => field value

Gets the effective template based on a known map idea.

getEffectiveTemplateByMapId(integer $templateMapId) : array | false

Returns all template information and the map ID.

Parameters

$templateMapId

integer

Returns

arrayfalseEffective template info.

Gets the effective template in a style by its title.

getEffectiveTemplateByTitle(string $title, integer $styleId) : array | false

This includes all template information and the map ID.

Parameters

$title

string

$styleId

integer

Returns

arrayfalseEffective template info.

Get the effective template list for a style.

getEffectiveTemplateListForStyle(integer $styleId, array $conditions, $fetchOptions) : array

"Effective" means a merged/flattened system where every valid template has a record.

This only returns data appropriate for a list view (map id, template id, title). Template_state is also calculated based on whether this template has been customized. State options: default, custom, inherited.

Parameters

$styleId

integer

$conditions

$fetchOptions

Returns

arrayFormat: [] => (array) template list info

Gets multiple effective templates based on 1 or more map IDs.

getEffectiveTemplatesByMapIds(\integery | array $templateMapIds) : array

Returns all template information and the map ID.

Parameters

$templateMapIds

\integeryarray

Either one map ID as a scalar or any array of map IDs

Returns

arrayFormat: [] => (array) effective template info

Gets effective templates in a style by their titles

getEffectiveTemplatesByTitles(array $titles, integer $styleId) : array | false

Parameters

$titles

array

$styleId

integer

Returns

arrayfalseEffective template info

Gets the template map IDs of any templates that include the source map IDs.

getIncludingTemplateMapIds(integer | array $mapIds) : array

For example, this would pass in the map ID of _header and get the map ID of the PAGE_CONTAINER.

Parameters

$mapIds

integerarray

One map ID as a scalar or an array of many.

Returns

arrayArray of map IDs

Gets the template map information for all templates that are mapped to the specified template ID.

getMappedTemplatesByTemplateId(integer $templateId) : array

Parameters

$templateId

integer

Returns

arrayFormat: [] => (array) template map info

Returns all the templates that belong to the specified add-on.

getMasterTemplatesInAddOn(string $addOnId) : array

Parameters

$addOnId

string

Returns

arrayFormat: [title] => info

Gets the specified model object from the cache.

getModelFromCache(string $class) : \XenForo_Model
Inherited

If it does not exist, it will be instantiated.

inherited_from \XenForo_Model::getModelFromCache()

Parameters

$class

string

Name of the class to load

Returns

Gets the order by clause for an SQL query.

getOrderByClause(array $choices, array $fetchOptions, string $defaultOrderSql) : string
Inherited

inherited_from \XenForo_Model::getOrderByClause()

Parameters

$choices

array

$fetchOptions

array

$defaultOrderSql

string

Returns

stringOrder by clause or empty string

Gets all templates that are outdated (master version edited more recently).

getOutdatedTemplates() : array

Does not include contents of template.

Returns

array[template id] => template info, including master_version_string

Gets mapped template information from the parent style of the named template.

getParentMappedTemplateByTitle(string $title, integer $styleId) : array | false

If the named style is 0 (or invalid), returns false.

Parameters

$title

string

$styleId

integer

Returns

arrayfalse

Returns the template specified by template_id

getTemplateById(integer $templateId) : array | false

Parameters

$templateId

integer

Template ID

Returns

arrayfalseTemplate

Returns the path to the template development directory, if it has been configured and exists

getTemplateDevelopmentDirectory() : string

Returns

stringPath to templates directory

Gets style ID/template ID pairs for all styles where the named template is modified.

getTemplateIdInStylesByTitle(string $templateTitle) : array

Parameters

$templateTitle

string

Returns

arrayFormat: [style_id] => template_id

Fetches a template from a particular style based on its title.

getTemplateInStyleByTitle(string $title, integer $styleId) : array

Note that if a version of the requested template does not exist in the specified style, nothing will be returned.

Parameters

$title

string

Title

$styleId

integer

Style ID (defaults to master style)

Returns

array

Gets the list of all template map IDs that include the named phrase.

getTemplateMapIdsThatIncludePhrase(string $phraseTitle) : array

Parameters

$phraseTitle

string

Returns

arrayList of template map IDs

Returns the templates specified by template IDs

getTemplatesByIds(array $templateIds) : array

Parameters

$templateIds

array

Returns

array

Gets the templates development XML.

getTemplatesDevelopmentXml() : \DOMDocument

Returns

Fetches templates from a particular style based on their titles.

getTemplatesInStyleByTitles(array $titles, integer $styleId) : array

Note that if a version of the requested template does not exist in the specified style, nothing will be returned for it.

Parameters

$titles

array

List of titles

$styleId

integer

Style ID (defaults to master style)

Returns

arrayFormat: [title] => info

Imports the add-on templates XML.

importTemplatesAddOnXml(\SimpleXMLElement $xml, string $addOnId, integer $maxExecution, integer $offset) : boolean | integer

Parameters

$xml

\SimpleXMLElement

XML element pointing to the root of the data

$addOnId

string

Add-on to import for

$maxExecution

integer

Maximum run time in seconds

$offset

integer

Number of elements to skip

Returns

booleanintegerTrue on completion; false if the XML isn't correct; integer otherwise with new offset value

Imports all templates from the templates directory into the database

importTemplatesFromDevelopment() 

Imports templates into a given style.

importTemplatesStyleXml(\SimpleXMLElement $xml, integer $styleId) 

Note that this assumes the style is already empty. It does not check for conflicts.

Parameters

$styleId

integer

Inserts the template map records for all elements of various styles.

insertTemplateMapForStyles(array $styleMapList, \bolean $truncate) 

Parameters

$styleMapList

array

Format: [style id][title] => template id

$truncate

\bolean

If true, all map data is truncated (quicker that way)

Applies a limit clause to the provided query if a limit value is specified.

limitQueryResults(string $query, integer $limit, integer $offset) : string
Inherited

If the limit value is 0 or less, no clause is applied.

inherited_from \XenForo_Model::limitQueryResults()

Parameters

$query

string

SQL query to run

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

Returns

stringQuery with limit applied if necessary

Prepares the limit-related fetching options that can be applied to various queries.

prepareLimitFetchOptions(array $fetchOptions) : array
Inherited

Includes: limit, offset, page, and perPage.

inherited_from \XenForo_Model::prepareLimitFetchOptions()

Parameters

$fetchOptions

array

Unprepared options

Returns

arrayLimit options; keys: limit, offset

Prepares state related fetch limits, based on the list of conditions.

prepareStateLimitFromConditions(array $fetchOptions, string $table, string $stateField, string $userField) : string
Inherited

Looks for keys "deleted" and "moderated".

inherited_from \XenForo_Model::prepareStateLimitFromConditions()

Parameters

$fetchOptions

array

$table

string

Name of the table to prefix the state and user fields with

$stateField

string

Name of the field that holds the state

$userField

string

Name of the field that holds the user ID

Returns

stringSQL condition to limit state

Prepares conditions for searching templates.

prepareTemplateConditions(array $conditions, array $fetchOptions) : string

Often, this search will be done on an effective template set (using the map). Some conditions may require this.

Parameters

$conditions

array

$fetchOptions

array

Returns

stringSQL conditions

Replaces <xen:require/include/edithint with <link rel="xenforo_x" for the purposes of easy WebDAV editing.

replaceIncludesWithLinkRel(string $templateText) : string

Parameters

$templateText

string

Returns

string

Replaces <link rel="xenforo_x" with <xen:require/include/edithint for the purposes of easy WebDAV editing.

replaceLinkRelWithIncludes(string $templateText) : string

Parameters

$templateText

string

Returns

string

Reset an entry or the entire local cache.

resetLocalCacheData($name) 
Inherited

This can be used if you know when some cached data has expired.

inherited_from \XenForo_Model::resetLocalCacheData()

Parameters

$name

Sets whether we're allowed to read values from the cache on a model-level.

setAllowCachedRead($allowCachedRead) 
Inherited

This may be controllable on an individual level basis, if the implementation allows it.

inherited_from \XenForo_Model::setAllowCachedRead()

Parameters

$allowCachedRead

boolean

Injects a local cache value.

setLocalCacheData(string $name, $value) 
Inherited

This should only be used if you know what you're doing or for testing purposes!

Note that you cannot get the existing data via the public interface. If you think you need the set data, use a new object. It defaults to empty. :)

inherited_from \XenForo_Model::setLocalCacheData()

Parameters

$name

string

$value

Standardizes a set of node permissions and a user ID to always have appropriate data.

standardizeNodePermissionsAndUserId(integer $nodeId, array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizeNodePermissionsAndUserId()

Parameters

$nodeId

integer

Node permissions are for

$permissions

arraynull

Permissions for node or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a permission combination and user ID to always have appropriate data.

standardizePermissionCombinationIdAndUserId(integer | null $permissionCombinationId, integer | null $userId) 
Inherited

If null, users current visitor's values.

inherited_from \XenForo_Model::standardizePermissionCombinationIdAndUserId()

Parameters

$permissionCombinationId

integernull

Permission combination ID or null to use current visitor

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a set of permissions and a user ID to always have appropriate data.

standardizePermissionsAndUserId(array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizePermissionsAndUserId()

Parameters

$permissions

arraynull

Global pPermissions or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a viewing user reference array.

standardizeViewingUserReference(array $viewingUser) 
Inherited

This array must contain all basic user info (preferably all user info) and include global permissions in a "permissions" key. If not an array or missing a user_id, the visitor's values will be used.

inherited_from \XenForo_Model::standardizeViewingUserReference()

Parameters

$viewingUser

arraynull

Standardizes the viewing user reference for the specific node.

standardizeViewingUserReferenceForNode(integer $nodeId, array $viewingUser, array $nodePermissions) 
Inherited

inherited_from \XenForo_Model::standardizeViewingUserReferenceForNode()

Parameters

$nodeId

integer

$viewingUser

arraynull

Viewing user; if null, use visitor

$nodePermissions

arraynull

Permissions for this node; if null, use visitor's

Helper to unserialize permissions in a list of items.

unserializePermissionsInList(array $items, string $serializedKey, string $targetKey) : array
Inherited

inherited_from \XenForo_Model::unserializePermissionsInList()

Parameters

$items

array

List of items

$serializedKey

string

Key where serialized permissions are

$targetKey

string

Key where unserialized permissions will go

Returns

arrayList of items with permissions unserialized

Writes out the complete set of template files to the file system

writeTemplateFiles(boolean $enable, boolean $handleOptions) 

Parameters

$enable

boolean

Enable the templateFiles option after completion.

$handleOptions

boolean

Manipulate the option values to ensure failsafe operation.

Internal handler to build the template map data for a style sub-tree.

_buildTemplateMapForStyleTree(integer $styleId, array $map, array $styles, array $styleTree) : array

Calls itself recursively.

Parameters

$styleId

integer

Style to build (builds children automatically)

$map

array

Base template map data. Format: [title] => template id

$styles

array

List of styles

$styleTree

array

Style tree

Returns

arrayFormat: [style id][title] => template id

Helper method to get the cache object.

_getCache(boolean $forceCachedRead) : \Zend_Cache_Core | \Zend_Cache_Frontend | false
Inherited

If cache reads are disabled, this will return false.

inherited_from \XenForo_Model::_getCache()

Parameters

$forceCachedRead

boolean

If true, the global "allow cached read" value is ignored

Returns

\Zend_Cache_Core\Zend_Cache_Frontendfalse

Gets the data registry model.

_getDataRegistryModel() : \XenForo_Model_DataRegistry
Inherited

inherited_from \XenForo_Model::_getDataRegistryModel()

Returns

Helper method to get the database object.

_getDb() : \Zend_Db_Adapter_Abstract
Inherited

inherited_from \XenForo_Model::_getDb()

Returns

\Zend_Db_Adapter_Abstract

Gets the named entry from the local cache.

_getLocalCacheData(string $name) : mixed
Inherited

inherited_from \XenForo_Model::_getLocalCacheData()

Parameters

$name

string

Returns

mixed

 Properties

 

Controls whether a cached read is allowed.

$_allowCachedRead : boolean
Inherited

If not, it should be retrieved from the source.

inherited_from \XenForo_Model::$$_allowCachedRead
 

Cache object

$_cache : \Zend_Cache_Core | \Zend_Cache_Frontend
Inherited

inherited_from \XenForo_Model::$$_cache
 

Database object

$_db : \Zend_Db_Adapter_Abstract
Inherited

inherited_from \XenForo_Model::$$_db
 

Stores local, instance-specific cached data for each model.

$_localCacheData : array
Inherited

This data is generally treated as canonical, even if {$_allowCachedRead} is false.

inherited_from \XenForo_Model::$$_localCacheData
 

Standard approach to caching other model objects for the lifetime of the model.

$_modelCache : array
Inherited

inherited_from \XenForo_Model::$$_modelCache