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
19 * The SquirrelMail (Foowd) template class.
21 * Basic template class for capturing values and pluging them into a template.
22 * This class uses a similar API to Smarty.
25 * @author Monte Ohrt <monte at ispi.net>
26 * @author Andrei Zmievski <andrei at php.net>
27 * @package squirrelmail
32 * The templates values array
36 var $values = array();
39 * The template directory to use
43 var $template_dir = '';
48 * @param string $sTplDir where the template set is located
50 function Template($sTplDir) {
51 $this->template_dir
= $sTplDir;
56 * Assigns values to template variables
58 * @param array|string $tpl_var the template variable name(s)
59 * @param mixed $value the value to assign
61 function assign($tpl_var, $value = NULL) {
62 if (is_array($tpl_var))
64 foreach ($tpl_var as $key => $val)
67 $this->values
[$key] = $val;
73 $this->values
[$tpl_var] = $value;
78 * Assigns values to template variables by reference
80 * @param string $tpl_var the template variable name
81 * @param mixed $value the referenced value to assign
83 function assign_by_ref($tpl_var, &$value)
86 $this->values
[$tpl_var] = &$value;
90 * Appends values to template variables
92 * @param array|string $tpl_var the template variable name(s)
93 * @param mixed $value the value to append
95 function append($tpl_var, $value = NULL, $merge = FALSE)
97 if (is_array($tpl_var))
99 foreach ($tpl_var as $_key => $_val)
103 if(isset($this->values
[$_key]) && !is_array($this->values
[$_key]))
104 settype($this->values
[$_key],'array');
106 if($merge && is_array($_val))
108 foreach($_val as $_mkey => $_mval)
109 $this->values
[$_key][$_mkey] = $_mval;
112 $this->values
[$_key][] = $_val;
118 if ($tpl_var != '' && isset($value))
120 if(isset($this->values
[$tpl_var]) && !is_array($this->values
[$tpl_var]))
121 settype($this->values
[$tpl_var],'array');
123 if($merge && is_array($value))
125 foreach($value as $_mkey => $_mval)
126 $this->values
[$tpl_var][$_mkey] = $_mval;
129 $this->values
[$tpl_var][] = $value;
135 * Appends values to template variables by reference
137 * @param string $tpl_var the template variable name
138 * @param mixed $value the referenced value to append
140 function append_by_ref($tpl_var, &$value, $merge = FALSE)
142 if ($tpl_var != '' && isset($value))
144 if(!@is_array
($this->values
[$tpl_var]))
145 settype($this->values
[$tpl_var],'array');
147 if ($merge && is_array($value))
149 foreach($value as $_key => $_val)
150 $this->values
[$tpl_var][$_key] = &$value[$_key];
153 $this->values
[$tpl_var][] = &$value;
158 * Display the template
160 * @param string $file The template file to use
162 function display($file)
164 $t = &$this->values
; // place values array directly in scope
166 include($this->template_dir
.$file);
171 * Return the results of applying a template.
173 * @param string $file The template file to use
174 * @return string A string of the results
176 function fetch($file)
179 $t = &$this->values
; // place values array directly in scope
180 include($this->template_dir
.$file);
181 $contents = ob_get_contents();