Source for file PHP_Template.class.php
Documentation is available at PHP_Template.class.php
* Copyright 2003, Paul James
* This file contains some methods from the Smarty templating engine version
* The SquirrelMail (Foowd) template implementation.
* Derived from the foowd template implementation and adapted
* @copyright © 2005-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: PHP_Template.class.php,v 1.2 2006/10/02 09:38:49 pdontthink Exp $
* The SquirrelMail PHP Template class. Extends the base
* Template class for use with PHP template pages.
* @author Monte Ohrt <monte at ispi.net>
* @author Andrei Zmievski <andrei at php.net>
* @author Paul Lesniewski
* The templates values array
* Please do not call directly. Use Template::construct_template().
* @param string $template_id the template ID
//FIXME: find a way to test that this is ONLY ever called
// from parent's construct_template() method (I doubt it
// is worth the trouble to parse the current stack trace)
// trigger_error('Please do not use default PHP_Template() constructor. Instead, use Template::construct_template().', E_USER_ERROR);
* Assigns values to template variables
* @param array|string$tpl_var the template variable name(s)
* @param mixed $value the value to assign
FIXME: Proposed idea to add a parameter here that turns variable
encoding on, so that we can make sure output is always
run through something like htmlspecialchars() (maybe even nl2br()?)
function assign($tpl_var, $value =
NULL) {
foreach ($tpl_var as $key =>
$val)
$this->values[$tpl_var] =
$value;
* Assigns values to template variables by reference
* @param string $tpl_var the template variable name
* @param mixed $value the referenced value to assign
FIXME: Proposed idea to add a parameter here that turns variable
encoding on, so that we can make sure output is always
run through something like htmlspecialchars() (maybe even nl2br()?)
$this->values[$tpl_var] =
&$value;
* Clears the values of all assigned varaiables.
* Returns assigned variable value(s).
* @param string $varname If given, the value of that variable
* is returned, assuming it has been
* previously assigned. If not specified
* an array of all assigned variables is
* @return mixed Desired single variable value or list of all
* assigned variable values.
// just looking for one value
if (!empty($this->values[$varname]))
return $this->values[$varname];
// FIXME: this OK? What does Smarty do?
// return all variable values
* Appends values to template variables
* @param array|string$tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge when $value is given as an array,
* this indicates whether or not that
* array itself should be appended as
* a new template variable value or if
* that array's values should be merged
* into the existing array of template
FIXME: Proposed idea to add a parameter here that turns variable
encoding on, so that we can make sure output is always
run through something like htmlspecialchars() (maybe even nl2br()?)
function append($tpl_var, $value =
NULL, $merge =
FALSE)
foreach ($tpl_var as $_key =>
$_val)
// FIXME: Tentative testing seems to indicate that
// this does not mirror Smarty behavior; Smarty
// seems to append the full array as a new element
// instead of merging, so this behavior is technically
// more "correct", but Smarty seems to differ
foreach($_val as $_mkey =>
$_mval)
$this->values[$_key][$_mkey] =
$_mval;
$this->values[$_key][] =
$_val;
if ($tpl_var !=
'' && isset
($value))
foreach($value as $_mkey =>
$_mval)
$this->values[$tpl_var][$_mkey] =
$_mval;
$this->values[$tpl_var][] =
$value;
* Appends values to template variables by reference
* @param string $tpl_var the template variable name
* @param mixed $value the referenced value to append
* @param boolean $merge when $value is given as an array,
* this indicates whether or not that
* array itself should be appended as
* a new template variable value or if
* that array's values should be merged
* into the existing array of template
FIXME: Proposed idea to add a parameter here that turns variable
encoding on, so that we can make sure output is always
run through something like htmlspecialchars() (maybe even nl2br()?)
if ($tpl_var !=
'' && isset
($value))
foreach($value as $_key =>
$_val)
$this->values[$tpl_var][$_key] =
&$value[$_key];
$this->values[$tpl_var][] =
&$value;
* Applys the template and generates final output destined
* @param string $filepath The full file path to the template to be applied
* @return string The output for the given template
// place values array directly in scope
// ($t? let's try to be more verbose please :-) )
Documentation generated on Sat, 07 Oct 2006 16:13:02 +0300 by phpDocumentor 1.3.0RC6