PHP Class PKPTemplateManager, pkp-lib

Inheritance: extends Smarty
Mostra file Open project: pkp/pkp-lib Class Usage Examples

Public Methods

Method Description
__construct ( $request ) Constructor.
_smarty_include ( $params ) Override the Smarty {include .
addHeader ( $name, $header, $args = [] ) Add a page-specific item to the .
addJavaScript ( $name, $script, $args = [] ) Register a script with the script handler
addStyleSheet ( $name, $style, $args = [] ) Register a stylesheet with the style handler
cacheLess ( $path, $styles ) : boolean Save LESS styles to a cached file
clearCssCache ( ) Clear all compiled CSS files
clearTemplateCache ( ) Clear template compile and cache directories.
compileLess ( $name, $lessFile, $args = [] ) : string Compile a LESS stylesheet
display ( $template, $sendContentType = null, $hookName = null, $display = true ) Display the template.
fetch ( $resource_name, $cache_id = null, $compile_id = null, $display = false )
fetchAjax ( $id, $url, $element = 'div' ) : JSONMessage Fetch content via AJAX and add it to the DOM, wrapped in a container element.
fetchJson ( $template, $status = true ) : JSONMessage Returns the template results as a JSON message.
flush ( )
getCachedLessFilePath ( $name ) Retrieve the file path for a cached LESS file
getCompileId ( $resourceName ) : string Calculate a compile ID for a resource.
getFBV ( ) : TemplateManager Return an instance of the Form Builder Vocabulary class.
getManager ( $request = null ) : TemplateManager Return an instance of the template manager.
getResourcesByContext ( $resources, $context ) : array Get resources assigned to a context
initialize ( ) Initialize the template manager.
registerJSLibrary ( ) Register all files required by the core JavaScript library
registerJSLibraryData ( ) Register JavaScript data used by the core JS library
setCacheability ( $cacheability = CACHEABILITY_PUBLIC ) Flag the page as cacheable (or not).
smartyAssign ( $value, $varName, $passThru = false ) Assign a value to a template variable.
smartyCSRF ( $params, $smarty ) : string Smarty usage: {csrf}
smartyCallHook ( $params, $smarty ) Call hooks from a template.
smartyCompare ( $a, $b, $strict = false, $invert = false ) Concatenate the parameters and return the result.
smartyConcat ( ) Concatenate the parameters and return the result.
smartyExplode ( $string, $separator ) Split the supplied string by the supplied separator.
smartyFlush ( $params, $smarty ) Flush the output buffer. This is useful in cases where Smarty templates are calling functions that take a while to execute so that they can display a progress indicator or a message stating that the operation may take a while.
smartyHelp ( $params, $smarty ) : string Smarty usage: {help file="someFile.md" section="someSection" textKey="some.text.key"}
smartyHtmlOptionsTranslate ( $params, $smarty ) Smarty usage: {html_options_translate .
smartyIterate ( $params, $content, $smarty, &$repeat ) Iterator function for looping through objects extending the ItemIterator class.
smartyLoadHeader ( $params, $smarty ) : string Smarty usage: {load_header context="frontent" headers=$headers}
smartyLoadScript ( $params, $smarty ) : string Smarty usage: {load_script context="backend" scripts=$scripts}
smartyLoadStylesheet ( $params, $smarty ) : string Smarty usage: {load_stylesheet context="frontend" stylesheets=$stylesheets}
smartyLoadUrlInDiv ( $params, $smarty ) : string Smarty usage: {load_url_in_div id="someHtmlId" url="http://the.url.to.be.loaded.into.the.grid"}
smartyLoadUrlInEl ( $params, $smarty ) : string Smarty usage: {load_url_in_el el="htmlElement" id="someHtmlId" url="http://the.url.to.be.loaded.into.the.grid"}
smartyNullLinkAction ( $params, $smarty ) : string Smarty usage: {null_link_action id="linkId" key="localization.key.name" image="imageClassName"}
smartyPageInfo ( $params, $smarty ) Display page information for a listing of items that has been divided onto multiple pages.
smartyPageLinks ( $params, $smarty ) Display page links for a listing of items that has been divided onto multiple pages.
smartyPluckFiles ( $params, $smarty ) : array Smarty usage: {pluck_files files=$availableFiles by="chapter" value=$chapterId}
smartyStrtotime ( $string ) Convert a string to a numeric time.
smartyToArray ( ) Convert the parameters of a function to an array.
smartyTranslate ( $params, $smarty ) : string Smarty usage: {translate key="localization.key.name" [paramName="paramValue" .
smartyUrl ( $parameters, $smarty ) Generate a URL into a PKPApp.

Method Details

__construct() public method

Initialize template engine and assign basic template variables.
public __construct ( $request )
$request PKPRequest

_smarty_include() public method

..} function to allow hooks to be called.
public _smarty_include ( $params )

addHeader() public method

Add a page-specific item to the .
public addHeader ( $name, $header, $args = [] )
$name string Unique name for the header
$header string The header to be included.
$args array Key/value array defining display details `priority` int The order in which to print this header. Default: STYLE_SEQUENCE_NORMAL `contexts` string|array Where the header should be loaded. Default: array('frontend')

addJavaScript() public method

Register a script with the script handler
public addJavaScript ( $name, $script, $args = [] )
$name string Unique name for the script
$script string The script to be included. Should be a URL or, if the `inline` argument is included, script data to be output.
$args array Key/value array defining display details `priority` int The order in which to print this script. Default: STYLE_SEQUENCE_NORMAL `contexts` string|array Where the script should be loaded. Default: array('frontend') `inline` bool Whether the $script value should be output directly as script data. Used to pass backend data to the scripts.

addStyleSheet() public method

Register a stylesheet with the style handler
public addStyleSheet ( $name, $style, $args = [] )
$name string Unique name for the stylesheet
$style string The stylesheet to be included. Should be a URL or, if the `inline` argument is included, stylesheet data to be output.
$args array Key/value array defining display details `priority` int The order in which to print this stylesheet. Default: STYLE_SEQUENCE_NORMAL `contexts` string|array Where the stylesheet should be loaded. Default: array('frontend') `inline` bool Whether the $stylesheet value should be output directly as stylesheet data. Used to pass backend data to the scripts.

cacheLess() public method

Save LESS styles to a cached file
public cacheLess ( $path, $styles ) : boolean
$path string File path to save the compiled styles
return boolean success/failure

clearCssCache() public method

Clear all compiled CSS files
public clearCssCache ( )

clearTemplateCache() public method

Clear template compile and cache directories.
public clearTemplateCache ( )

compileLess() public method

Compile a LESS stylesheet
public compileLess ( $name, $lessFile, $args = [] ) : string
$name string Unique name for this LESS stylesheet
$lessFile string Path to the LESS file to compile
$args array Optional arguments. SUpports: 'baseUrl': Base URL to use when rewriting URLs in the LESS file. 'addLess': Array of additional LESS files to parse before compiling
return string Compiled CSS styles

display() public method

Display the template.
public display ( $template, $sendContentType = null, $hookName = null, $display = true )

fetch() public method

See also: Smarty::fetch()
public fetch ( $resource_name, $cache_id = null, $compile_id = null, $display = false )

fetchAjax() public method

Fetch content via AJAX and add it to the DOM, wrapped in a container element.
public fetchAjax ( $id, $url, $element = 'div' ) : JSONMessage
$id string ID to use for the generated container element.
$url string URL to fetch the contents from.
$element string Element to use for container.
return JSONMessage The JSON-encoded result.

fetchJson() public method

Returns the template results as a JSON message.
public fetchJson ( $template, $status = true ) : JSONMessage
$template string
$status boolean
return JSONMessage JSON object

flush() public method

public flush ( )

getCachedLessFilePath() public method

Retrieve the file path for a cached LESS file
public getCachedLessFilePath ( $name )
$name string Unique name for the LESS file

getCompileId() public method

Calculate a compile ID for a resource.
public getCompileId ( $resourceName ) : string
$resourceName string Resource name.
return string

getFBV() public method

Return an instance of the Form Builder Vocabulary class.
public getFBV ( ) : TemplateManager
return TemplateManager the template manager object

getManager() static public method

Return an instance of the template manager.
static public getManager ( $request = null ) : TemplateManager
$request PKPRequest
return TemplateManager the template manager object

getResourcesByContext() public method

A helper function which retrieves script, style and header assets assigned to a particular context.
public getResourcesByContext ( $resources, $context ) : array
$resources array Requested resources
$context string Requested context
return array Resources assigned to these contexts

initialize() public method

Initialize the template manager.
public initialize ( )

registerJSLibrary() public method

Register all files required by the core JavaScript library
public registerJSLibrary ( )

registerJSLibraryData() public method

This function registers script data that is required by the core JS library. This data is queued after jQuery but before the pkp-lib framework, allowing dynamic data to be passed to the framework. It is intended to be used for passing constants and locale strings, but plugins may also take advantage of a hook to include data required by their own scripts, when integrating with the pkp-lib framework.

setCacheability() public method

Flag the page as cacheable (or not).
public setCacheability ( $cacheability = CACHEABILITY_PUBLIC )
$cacheability boolean optional

smartyAssign() public method

Assign a value to a template variable.
public smartyAssign ( $value, $varName, $passThru = false )

smartyCSRF() public method

Custom Smarty function for inserting a CSRF token.
public smartyCSRF ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML

smartyCallHook() public method

Call hooks from a template.
public smartyCallHook ( $params, $smarty )

smartyCompare() public method

Concatenate the parameters and return the result.
public smartyCompare ( $a, $b, $strict = false, $invert = false )
$a mixed Parameter A
$strict boolean True iff a strict (===) compare should be used
$invert booelan True iff the output should be inverted

smartyConcat() public method

Concatenate the parameters and return the result.
public smartyConcat ( )

smartyExplode() public method

Split the supplied string by the supplied separator.
public smartyExplode ( $string, $separator )

smartyFlush() public method

Flush the output buffer. This is useful in cases where Smarty templates are calling functions that take a while to execute so that they can display a progress indicator or a message stating that the operation may take a while.
public smartyFlush ( $params, $smarty )

smartyHelp() public method

Custom Smarty function for displaying a context-sensitive help link.
public smartyHelp ( $params, $smarty ) : string
$smarty Smarty
return string the HTML for the generated link action

smartyHtmlOptionsTranslate() public method

..} For parameter usage, see http://smarty.php.net/manual/en/language.function.html.options.php Identical to Smarty's "html_options" function except option values are translated from i18n keys.
public smartyHtmlOptionsTranslate ( $params, $smarty )
$params array
$smarty Smarty

smartyIterate() public method

Parameters: - from: Name of template variable containing iterator - item: Name of template variable to receive each item - key: (optional) Name of variable to receive index of current item
public smartyIterate ( $params, $content, $smarty, &$repeat )

smartyLoadHeader() public method

Custom Smarty function for printing scripts attached to a context.
public smartyLoadHeader ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML/Javascript

smartyLoadScript() public method

Custom Smarty function for printing scripts attached to a context.
public smartyLoadScript ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML/Javascript

smartyLoadStylesheet() public method

Custom Smarty function for printing stylesheets attached to a context.
public smartyLoadStylesheet ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML/Javascript

smartyLoadUrlInDiv() public method

Custom Smarty function for loading a URL via AJAX into a DIV. Convenience wrapper for smartyLoadUrlInEl.
public smartyLoadUrlInDiv ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML/Javascript

smartyLoadUrlInEl() public method

Custom Smarty function for loading a URL via AJAX into any HTML element
public smartyLoadUrlInEl ( $params, $smarty ) : string
$params array associative array
$smarty Smarty
return string of HTML/Javascript

smartyNullLinkAction() public method

Custom Smarty function for displaying a null link action; these will typically be attached and handled in Javascript.
public smartyNullLinkAction ( $params, $smarty ) : string
$smarty Smarty
return string the HTML for the generated link action

smartyPageInfo() public method

Usage: {page_info from=$myIterator}
public smartyPageInfo ( $params, $smarty )

smartyPluckFiles() public method

Custom Smarty function for plucking files from the array of $availableFiles related to a submission. Intended to be used on the frontend
public smartyPluckFiles ( $params, $smarty ) : array
$params array associative array
$smarty Smarty
return array of SubmissionFile objects

smartyStrtotime() public method

Convert a string to a numeric time.
public smartyStrtotime ( $string )

smartyToArray() public method

Convert the parameters of a function to an array.
public smartyToArray ( )

smartyTranslate() public method

..]} Custom Smarty function for translating localization keys. Substitution works by replacing tokens like "{$foo}" with the value of the parameter named "foo" (if supplied).
public smartyTranslate ( $params, $smarty ) : string
$params array associative array, must contain "key" parameter for string to translate plus zero or more named parameters for substitution. Translation variables can be specified also as an optional associative array named "params".
$smarty Smarty
return string the localized string, including any parameter substitutions

smartyUrl() public method

Generate a URL into a PKPApp.
public smartyUrl ( $parameters, $smarty )
$smarty object Available parameters: - router: which router to use - context - page - component - op - path (array) - anchor - escape (default to true unless otherwise specified) - params: parameters to include in the URL if available as an array