3 * Copyright 2003, Paul James
4 * Copyright (c) 2005 The SquirrelMail Project Team
5 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 * This file contains some methods from the Smarty templating engine version
8 * 2.5.0 by Monte Ohrt <monte@ispi.net> and Andrei Zmievski <andrei@php.net>.
14 * The SquirrelMail (Foowd) template implementation.
15 * Derived from the foowd template implementation and adapted
17 * @package SquirrelMail
21 * The SquirrelMail (Foowd) template class.
23 * Basic template class for capturing values and pluging them into a template.
24 * This class uses a similar API to Smarty.
27 * @author Monte Ohrt <monte@ispi.net>
28 * @author Andrei Zmievski <andrei@php.net>
29 * @package SquirrelMail
34 * The templates values array
38 var $values = array();
41 * The template directory to use
45 var $template_dir = 'templates\default';
50 * @param string $sTplDir where the template set is located
52 function Template($sTplDir = 'templates\default') {
53 $this->template_dir
= $sTplDir;
58 * Assigns values to template variables
60 * @param array|string $tpl_var the template variable name(s)
61 * @param mixed $value the value to assign
63 function assign($tpl_var, $value = NULL) {
64 if (is_array($tpl_var))
66 foreach ($tpl_var as $key => $val)
69 $this->values
[$key] = $val;
75 $this->values
[$tpl_var] = $value;
80 * Assigns values to template variables by reference
82 * @param string $tpl_var the template variable name
83 * @param mixed $value the referenced value to assign
85 function assign_by_ref($tpl_var, &$value)
88 $this->values
[$tpl_var] = &$value;
92 * Appends values to template variables
94 * @param array|string $tpl_var the template variable name(s)
95 * @param mixed $value the value to append
97 function append($tpl_var, $value = NULL, $merge = FALSE)
99 if (is_array($tpl_var))
101 foreach ($tpl_var as $_key => $_val)
105 if(isset($this->values
[$_key]) && !is_array($this->values
[$_key]))
106 settype($this->values
[$_key],'array');
108 if($merge && is_array($_val))
110 foreach($_val as $_mkey => $_mval)
111 $this->values
[$_key][$_mkey] = $_mval;
114 $this->values
[$_key][] = $_val;
120 if ($tpl_var != '' && isset($value))
122 if(isset($this->values
[$tpl_var]) && !is_array($this->values
[$tpl_var]))
123 settype($this->values
[$tpl_var],'array');
125 if($merge && is_array($value))
127 foreach($value as $_mkey => $_mval)
128 $this->values
[$tpl_var][$_mkey] = $_mval;
131 $this->values
[$tpl_var][] = $value;
137 * Appends values to template variables by reference
139 * @param string $tpl_var the template variable name
140 * @param mixed $value the referenced value to append
142 function append_by_ref($tpl_var, &$value, $merge = FALSE)
144 if ($tpl_var != '' && isset($value))
146 if(!@is_array
($this->values
[$tpl_var]))
147 settype($this->values
[$tpl_var],'array');
149 if ($merge && is_array($value))
151 foreach($value as $_key => $_val)
152 $this->values
[$tpl_var][$_key] = &$value[$_key];
155 $this->values
[$tpl_var][] = &$value;
160 * Display the template
162 * @param string $file The template file to use
164 function display($file)
166 $t = &$this->values
; // place values array directly in scope
168 include($this->template_dir
.$file);
173 * Return the results of applying a template.
175 * @param string $file The template file to use
176 * @return string A string of the results
178 function fetch($file)
181 $t = &$this->values
; // place values array directly in scope
182 include($this->template_dir
.$file);
183 $contents = ob_get_contents();