7bc8ad62dd7ec097da254d025fea39a6581aad2e
4 * Copyright 2003, Paul James
6 * This file contains some methods from the Smarty templating engine version
7 * 2.5.0 by Monte Ohrt <monte@ispi.net> and Andrei Zmievski <andrei@php.net>.
9 * The SquirrelMail (Foowd) template implementation.
10 * Derived from the foowd template implementation and adapted
12 * @copyright © 2005-2006 The SquirrelMail Project Team
13 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @package squirrelmail
20 * The SquirrelMail PHP Template class. Extends the base
21 * Template class for use with PHP template pages.
24 * @author Monte Ohrt <monte at ispi.net>
25 * @author Andrei Zmievski <andrei at php.net>
26 * @author Paul Lesniewski
27 * @package squirrelmail
30 class PHP_Template
extends Template
34 * The templates values array
39 var $values = array();
45 * Please do not call directly. Use Template::construct_template().
47 * @param string $template_id the template ID
50 function PHP_Template($template_id) {
51 //FIXME: find a way to test that this is ONLY ever called
52 // from parent's construct_template() method (I doubt it
53 // is worth the trouble to parse the current stack trace)
55 // trigger_error('Please do not use default PHP_Template() constructor. Instead, use Template::construct_template().', E_USER_ERROR);
57 parent
::Template($template_id);
62 * Assigns values to template variables
64 * @param array|string $tpl_var the template variable name(s)
65 * @param mixed $value the value to assign
66 FIXME: Proposed idea to add a parameter here that turns variable
67 encoding on, so that we can make sure output is always
68 run through something like htmlspecialchars() (maybe even nl2br()?)
71 function assign($tpl_var, $value = NULL) {
73 if (is_array($tpl_var))
75 foreach ($tpl_var as $key => $val)
78 $this->values
[$key] = $val;
84 $this->values
[$tpl_var] = $value;
90 * Assigns values to template variables by reference
92 * @param string $tpl_var the template variable name
93 * @param mixed $value the referenced value to assign
94 FIXME: Proposed idea to add a parameter here that turns variable
95 encoding on, so that we can make sure output is always
96 run through something like htmlspecialchars() (maybe even nl2br()?)
99 function assign_by_ref($tpl_var, &$value) {
102 $this->values
[$tpl_var] = &$value;
107 * Appends values to template variables
109 * @param array|string $tpl_var the template variable name(s)
110 * @param mixed $value the value to append
111 * @param boolean $merge when $value is given as an array,
112 * this indicates whether or not that
113 * array itself should be appended as
114 * a new template variable value or if
115 * that array's values should be merged
116 * into the existing array of template
118 FIXME: Proposed idea to add a parameter here that turns variable
119 encoding on, so that we can make sure output is always
120 run through something like htmlspecialchars() (maybe even nl2br()?)
123 function append($tpl_var, $value = NULL, $merge = FALSE)
125 if (is_array($tpl_var))
127 foreach ($tpl_var as $_key => $_val)
131 if(isset($this->values
[$_key]) && !is_array($this->values
[$_key]))
132 settype($this->values
[$_key],'array');
134 if($merge && is_array($_val))
136 // FIXME: Tentative testing seems to indicate that
137 // this does not mirror Smarty behavior; Smarty
138 // seems to append the full array as a new element
139 // instead of merging, so this behavior is technically
140 // more "correct", but Smarty seems to differ
141 foreach($_val as $_mkey => $_mval)
142 $this->values
[$_key][$_mkey] = $_mval;
145 $this->values
[$_key][] = $_val;
151 if ($tpl_var != '' && isset($value))
153 if(isset($this->values
[$tpl_var]) && !is_array($this->values
[$tpl_var]))
154 settype($this->values
[$tpl_var],'array');
156 if($merge && is_array($value))
158 foreach($value as $_mkey => $_mval)
159 $this->values
[$tpl_var][$_mkey] = $_mval;
162 $this->values
[$tpl_var][] = $value;
168 * Appends values to template variables by reference
170 * @param string $tpl_var the template variable name
171 * @param mixed $value the referenced value to append
172 * @param boolean $merge when $value is given as an array,
173 * this indicates whether or not that
174 * array itself should be appended as
175 * a new template variable value or if
176 * that array's values should be merged
177 * into the existing array of template
179 FIXME: Proposed idea to add a parameter here that turns variable
180 encoding on, so that we can make sure output is always
181 run through something like htmlspecialchars() (maybe even nl2br()?)
184 function append_by_ref($tpl_var, &$value, $merge = FALSE)
186 if ($tpl_var != '' && isset($value))
188 if(!@is_array
($this->values
[$tpl_var]))
189 settype($this->values
[$tpl_var],'array');
191 if ($merge && is_array($value))
193 foreach($value as $_key => $_val)
194 $this->values
[$tpl_var][$_key] = &$value[$_key];
197 $this->values
[$tpl_var][] = &$value;
202 * Applys the template and generates final output destined
203 * for the user's browser
205 * @param string $filepath The full file path to the template to be applied
207 * @return string The output for the given template
210 function apply_template($filepath) {
212 // place values array directly in scope
213 // ($t? let's try to be more verbose please :-) )
219 $contents = ob_get_contents();