Geeklog
[ class tree: Geeklog ] [ index: Geeklog ] [ all elements ]

Class: Template

Source Location: /system/classes/template.class.php

Class Overview


The template class allows you to keep your HTML code in some external files which are completely free of PHP code, but contain replacement fields.


Variables

Methods



Class Details

[line 83]
The template class allows you to keep your HTML code in some external files which are completely free of PHP code, but contain replacement fields.

The class provides you with functions which can fill in the replacement fields with arbitrary strings. These strings can become very large, e.g. entire tables.

Note: If you think that this is like FastTemplates, read carefully. It isn't.




[ Top ]


Class Variables

$classname =  'Template'

[line 90]

Serialization helper, the name of this class.



Tags:

access:  public

Type:   string


[ Top ]

$debug =  0

[line 106]

Determines how much debugging output Template will produce.

This is a bitwise mask of available debug levels:

  1. = no debugging
  2. = debug variable assignments
  3. = debug calls to get variable
4 = debug internals (outputs all function calls with parameters). 8 = debug caching (incomplete)

Note: setting $this->debug = true will enable debugging of variable assignments only which is the same behaviour as versions up to release 7.2d.




Tags:

access:  public

Type:   int


[ Top ]

$halt_on_error =  'yes'

[line 214]

Determines how Template handles error conditions.

"yes" = the error is reported, then execution is halted "report" = the error is reported, then execution continues by returning "false" "no" = errors are silently ignored, and execution resumes reporting "false" "log" = writes errors to Error log and returns false.




Tags:

see:  halt
access:  public

Type:   string


[ Top ]

$last_error =  ''

[line 222]

The last error message is retained in this variable.



Tags:

see:  halt
access:  public

Type:   string


[ Top ]

$postprocess_fn =  ''

[line 238]

The name of a function is retained in this variable and is used to do any post processing work.



Tags:

see:  _postprocess
access:  public

Type:   string


[ Top ]

$preprocess_fn =  ''

[line 230]

The name of a function is retained in this variable and is used to do any pre processing work.



Tags:

see:  _preprocess
access:  public

Type:   string


[ Top ]

$templateCode = array()

[line 145]

The in memory template



Tags:

see:  Template::set_file()
access:  public

Type:   array


[ Top ]



Class Methods


constructor __construct [line 290]

Template __construct( [array|string $root = array('.')], [string $unknowns = 'remove'])

**************************************************************************** Class constructor. May be called with two optional parameters.

The first parameter sets the template directory the second parameter sets the policy regarding handling of unknown variables.

usage: Template([string $root = array()], [string $unknowns = "remove"])




Tags:

see:  Template::set_root()
see:  Template::set_unknowns()
access:  public


Parameters:

array|string   $root   path to template directory
string   $unknowns   what to do with undefined variables

[ Top ]

method block_echo [line 1382]

void block_echo( $block)



Parameters:

   $block  

[ Top ]

method check_instance [line 1940]

boolean check_instance( string $iid, string $fileVar)

**************************************************************************** Checks for an instance of the current template. This check is based solely on the $iid. The $fileVar is replaces with the cached file if it exists.

The $iid parameter must be globally unique. The recommended format is $plugin_$primaryKey or $plugin_$page_$uid

The $fileVar parameter is supposed to match one of the varNames passed set_file.

usage: $T->set_file('main', 'main.thtml'); $iid = 'mainfile_'.$primaryKey; if (!$T->check_instance($iid, 'main')) { $T->set_var(...); //... $T->create_instance($iid, 'main'); } $T->set_var('hits', $hit_count, false, true); $T->parse('output', 'main');




Tags:

return:  true if the instance file exists
see:  Template::create_instance()
access:  public


Parameters:

string   $iid   A globally unique instance identifier.
string   $fileVar   This is the varName passed to $T->set_file.

[ Top ]

method clear_var [line 639]

void clear_var( string|array $varName)

**************************************************************************** This functions clears the value of a variable.

It may be called with either a varName as a string or an array with the values being the varNames to be cleared.

The function sets the value of the variable in the $varKeys and $varVals hashes to "". It is not necessary for a variable to exist in these hashes before calling this function.

usage: clear_var(string $varName) or usage: clear_var(array $varName = (string $varName))




Tags:

access:  public


Parameters:

string|array   $varName   either a string containing a varName or an array of varNames.

[ Top ]

method create_instance [line 1890]

string create_instance( string $iid, string $fileVar)

**************************************************************************** Creates an instance of the current template. Variables in the nocache array are untranslated by returning the original PHP back. Conceptually, this function is equivalent to the parse function.

The $iid parameter must be globally unique. The recommended format is $plugin_$primaryKey or $plugin_$page_$uid

The $fileVar parameter is supposed to match one of the varNames passed to set_file.

usage: create_instance(string $iid, string $fileVar)




Tags:

return:  The full path of the cached file.
see:  Template::check_instance()
access:  public


Parameters:

string   $iid   A globally unique instance identifier.
string   $fileVar   This is the varName passed to $T->set_file.

[ Top ]

method dec_echo [line 1414]

void dec_echo( $var)



Parameters:

   $var  

[ Top ]

method finish [line 1078]

string finish( string $str)

**************************************************************************** Returns: Unknown processing use to take place here. Now it happens directly in the cache file. This function is still necessary for being able to hook the final output from the library.

usage: finish(string $str)




Tags:

access:  public


Parameters:

string   $str   a string to return

[ Top ]

method get [line 1123]

string get( string $varName)

**************************************************************************** This function returns the finished version of the value of the variable named by $varName. That is, the policy regarding unresolved variable names will be applied to the variable $varName and the result returned.

usage: get(string $varName)




Tags:

return:  a finished string derived from the variable $varName
see:  Template::set_unknowns()
see:  Template::finish()
access:  public


Parameters:

string   $varName   a string containing the name of the variable to finish

[ Top ]

method get_undefined [line 1033]

array get_undefined( string $varName)

**************************************************************************** DEPRECATED: This function doesn't really work any more. Processing in val_echo could be done to gather unknowns. But coding that seems like a waste of time and would only cause 99.99% of the normal use of this class to be slower.

This function returns a hash of unresolved variable names in $varName, keyed by their names (that is, the hash has the form $a[$name] = $name).

Returns: a hash of varName/varName pairs or false on error.

usage: get_undefined(string $varName)




Tags:

access:  public


Parameters:

string   $varName   a string containing the name the name of the variable to scan for unresolved variables

[ Top ]

method get_var [line 987]

string|array get_var( string|array $varName)

**************************************************************************** This function returns the value of the variable named by $varName.

If $varName references a file and that file has not been loaded yet, the variable will be reported as empty.

When called with an array of variable names this function will return a a hash of variable values keyed by their names.

Returns: a string or an array containing the value of $varName.

usage: get_var(string $varName) or usage: get_var(array $varName)




Tags:

access:  public


Parameters:

string|array   $varName   if a string, the name the name of the variable to get the value of, or if an array a list of variables to return the value of

[ Top ]

method get_vars [line 955]

array get_vars( )

**************************************************************************** This function returns an associative array of all defined variables with the name as the key and the value of the variable as the value.

This is mostly useful for debugging. Also note that $this->debug can be used to echo all variable assignments as they occur and to trace execution.

usage: get_vars()




Tags:

return:  a hash of all defined variable values keyed by their names
see:  Template::$debug
access:  public


[ Top ]

method haltmsg [line 1271]

void haltmsg( string $msg)

**************************************************************************** This function prints an error message.

It can be overridden by your subclass of Template. It will be called with an error message to display.

usage: haltmsg(string $msg)




Tags:

see:  halt
access:  public


Parameters:

string   $msg   a string containing the error message to display

[ Top ]

method inc_echo [line 1406]

void inc_echo( $var)



Parameters:

   $var  

[ Top ]

method lang_echo [line 1353]

void lang_echo( $val)



Parameters:

   $val  

[ Top ]

method loop [line 1390]

void loop( $var)



Parameters:

   $var  

[ Top ]

method mod_echo [line 1317]

void mod_echo( $val, [ $modifier = ''])



Parameters:

   $val  
   $modifier  

[ Top ]

method p [line 1106]

void p( string $varName)

**************************************************************************** This function prints the finished version of the value of the variable named by $varName. That is, the policy regarding unresolved variable names will be applied to the variable $varName then it will be printed.

usage: p(string $varName)




Tags:

see:  Template::set_unknowns()
see:  Template::finish()
access:  public


Parameters:

string   $varName   a string containing the name of the variable to finish and print

[ Top ]

method parse [line 875]

string parse( string $target, string $varName, [boolean $append = false])

**************************************************************************** The function substitutes the values of all defined variables in the variable named $varName and stores or appends the result in the variable named $target.

It may be called with either a target and a varName as two strings or a target as a string and an array of variable names in varName.

The function inserts the new value of the variable into the $varKeys and $varVals hashes. It is not necessary for a variable to exist in these hashes before calling this function.

An optional third parameter allows the value for each varName to be appended to the existing target variable instead of replacing it. The default is to replace.

If $target and $varName are both strings, the substituted value of the variable $varName is inserted into or appended to $target.

If $handle is an array of variable names the variables named by $handle are sequentially substituted and the result of each substitution step is inserted into or appended to in $target. The resulting substitution is available in the variable named by $target, as is each intermediate step for the next $varName in sequence. Note that while it is possible, it is only rarely desirable to call this function with an array of varNames and with $append = true. This append feature was introduced after the 7.2d release.

usage: parse(string $target, string $varName, [boolean $append]) or usage: parse(string $target, array $varName = (string $varName), [boolean $append])




Tags:

return:  the last value assigned to $target
see:  Template::subst()
access:  public


Parameters:

string   $target   a string containing the name of the variable into which substituted $varnames are to be stored
string   $varName   if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted
boolean   $append   if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced

[ Top ]

method parse_extended_callback [line 1544]

void parse_extended_callback( $matches)



Parameters:

   $matches  

[ Top ]

method parse_lang_callback [line 1494]

void parse_lang_callback( $matches)



Parameters:

   $matches  

[ Top ]

method parse_quoted_lang_callback [line 1499]

void parse_quoted_lang_callback( $matches)



Parameters:

   $matches  

[ Top ]

method pparse [line 933]

false pparse( string $target, string|array $varName, [boolean $append = false])

**************************************************************************** This is shorthand for print $this->parse(...) and is functionally identical.

See parse for further details.

usage: pparse(string $target, string $varName, [boolean $append]) or usage: pparse(string $target, array $varName = (string $varName), [boolean $append])




Tags:

return:  (always)
see:  Template::parse()
access:  public


Parameters:

string   $target   a string containing the name of the variable into which substituted $varnames are to be stored
string|array   $varName   if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted
boolean   $append   if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced

[ Top ]

method psubst [line 824]

false psubst( string $varName)

**************************************************************************** This is shorthand for print $this->subst($varName). See subst for further details.

usage: psubst(string $varName)




Tags:

return:  (always)
see:  Template::subst()
access:  public


Parameters:

string   $varName   the name of the variable within which variables are to be substituted

[ Top ]

method replace_extended [line 1504]

void replace_extended( $tmplt)



Parameters:

   $tmplt  

[ Top ]

method replace_lang [line 1461]

void replace_lang( $tmplt, [ $in_php = false])



Parameters:

   $tmplt  
   $in_php  

[ Top ]

method set_block [line 501]

boolean set_block( string $parent, string $varName, [string $name = ''])

**************************************************************************** A variable $parent may contain a variable block defined by: <!-- BEGIN $varName --> content <!-- END $varName -->. This function removes that block from $parent and replaces it with a variable reference named $name.

The block is inserted into the varKeys and varVals hashes. If $name is omitted, it is assumed to be the same as $varName.

Blocks may be nested but care must be taken to extract the blocks in order from the innermost block to the outermost block.

Returns true on success, false on error.

usage: set_block(string $parent, string $varName, [string $name = ""])




Tags:

access:  public


Parameters:

string   $parent   a string containing the name of the parent variable
string   $varName   a string containing the name of the block to be extracted
string   $name   the name of the variable in which to store the block

[ Top ]

method set_file [line 437]

boolean set_file( string|array $varName, [string $filename = ''])

**************************************************************************** Defines a filename for the initial value of a variable.

It may be passed either a var name and a file name as two strings or a hash of strings with the key being the var name and the value being the file name.

The new mappings are stored in the array $this->file. The files are not loaded yet, but only when needed.

Returns true on success, false on error.

usage: set_file(array $fileList = (string $varName => string $filename)) or usage: set_file(string $varName, string $filename)




Tags:

access:  public


Parameters:

string|array   $varName   either a string containing a var name or a hash of var name/file name pairs.
string   $filename   if var name is a string this is the filename otherwise filename is not required

[ Top ]

method set_root [line 329]

boolean set_root( string|array $root)

**************************************************************************** Checks that $root is a valid directory and if so sets this directory as the base directory from which templates are loaded by storing the value in $this->root. Relative file names are prepended with the path in $this->root.

Returns true on success, false on error.

usage: set_root(string $root)




Tags:

see:  root
access:  public


Parameters:

string|array   $root   string|array containing new template directory

[ Top ]

method set_unknowns [line 395]

void set_unknowns( [string $unknowns = ''])

**************************************************************************** Sets the policy for dealing with unresolved variable names.

unknowns defines what to do with undefined template variables "remove" = remove undefined variables "comment" = replace undefined variables with comments "keep" = keep undefined variables

Note: "comment" can cause unexpected results when the variable tag is embedded inside an HTML tag, for example a tag which is expected to be replaced with a URL.

usage: set_unknowns(string $unknowns)




Tags:

see:  unknowns
access:  public


Parameters:

string   $unknowns   new value for unknowns

[ Top ]

method set_var [line 569]

void set_var( string|array $varName, [string $value = ''], [boolean $append = false], [boolean $nocache = false])

**************************************************************************** This functions sets the value of a variable.

It may be called with either a varName and a value as two strings or an an associative array with the key being the varName and the value being the new variable value.

The function inserts the new value of the variable into the $varKeys and $varVals hashes. It is not necessary for a variable to exist in these hashes before calling this function.

An optional third parameter allows the value for each varName to be appended to the existing variable instead of replacing it. The default is to replace. This feature was introduced after the 7.2d release.

usage: set_var(string $varName, [string $value = ""], [boolean $append = false]) or usage: set_var(array $varName = (string $varName => string $value), [mixed $dummy_var], [boolean $append = false])




Tags:

access:  public


Parameters:

string|array   $varName   either a string containing a varName or a hash of varName/value pairs.
string   $value   if $varName is a string this contains the new value for the variable otherwise this parameter is ignored
boolean   $append   if true, the value is appended to the variable's existing value
boolean   $nocache   if true, the variable is added to the list of variable that are not instance cached.

[ Top ]

method slow_subst [line 790]

string slow_subst( string $varName)

****************************************************************************

This function fills in all the variables contained within the variable named $varName. The resulting value is returned as the function result and the original value of the variable varName is not changed. The resulting string is not "finished", that is, the unresolved variable name policy has not been applied yet.

This is the old version of subst.

Returns: the value of the variable $varName with all variables substituted.

usage: subst(string $varName)




Tags:

access:  public


Parameters:

string   $varName   the name of the variable within which variables are to be substituted

[ Top ]

method subst [line 716]

string subst( string $varName)

****************************************************************************

This function fills in all the variables contained within the variable named $varName. The resulting value is returned as the function result and the original value of the variable varName is not changed. The resulting string is not "finished", that is, the unresolved variable name policy has not been applied yet.

Returns: the value of the variable $varName with all variables substituted.

usage: subst(string $varName)




Tags:

access:  public


Parameters:

string   $varName   the name of the variable within which variables are to be substituted

[ Top ]

method uncached_var [line 1860]

void uncached_var( string|array $vars)

**************************************************************************** Prevents certain variables from being cached in the instance cache.



Tags:



Parameters:

string|array   $vars   A string varName or array of varNames

[ Top ]

method unset_var [line 678]

void unset_var( string|array $varName)

**************************************************************************** This functions unsets a variable completely.

It may be called with either a varName as a string or an array with the values being the varNames to be cleared.

The function removes the variable from the $varKeys and $varVals hashes. It is not necessary for a variable to exist in these hashes before calling this function.

usage: unset_var(string $varName) or usage: unset_var(array $varName = (string $varName))




Tags:

access:  public


Parameters:

string|array   $varName   either a string containing a varName or an array of varNames.

[ Top ]

method var_notempty [line 1309]

void var_notempty( $val)

*

Used in {!if var}. Avoid duplicating a large string when all we care about is if the string is non-zero length




Parameters:

   $val  

[ Top ]

method _modifyTemplateLocation [line 525]

string _modifyTemplateLocation( string $location)

Modifies template location to prevent non-Root users from seeing it



Tags:

return:  If the current user is in the Root group, $location is unchanged. Otherwise, $location is changed into a path relative to $_CONF['path_layout'].
access:  protected


Parameters:

string   $location  

[ Top ]


Documentation generated on Sun, 02 Oct 2016 07:56:09 +0000 by phpDocumentor 1.4.3