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>.
10 * The SquirrelMail (Foowd) template implementation.
11 * Derived from the foowd template implementation and adapted
14 * @package SquirrelMail
18 * The SquirrelMail (Foowd) template class.
20 * Basic template class for capturing values and pluging them into a template.
21 * This class uses a similar API to Smarty.
24 * @author Monte Ohrt <monte@ispi.net>
25 * @author Andrei Zmievski <andrei@php.net>
26 * @package squirrelmail
31 * The templates values array
35 var $values = array();
38 * The template directory to use
42 var $template_dir = 'templates\default';
47 * @param string $sTplDir where the template set is located
49 function Template($sTplDir = 'templates\default') {
50 $this->template_dir
= $sTplDir;
55 * Assigns values to template variables
57 * @param array|string $tpl_var the template variable name(s)
58 * @param mixed $value the value to assign
60 function assign($tpl_var, $value = NULL) {
61 if (is_array($tpl_var))
63 foreach ($tpl_var as $key => $val)
66 $this->values
[$key] = $val;
72 $this->values
[$tpl_var] = $value;
77 * Assigns values to template variables by reference
79 * @param string $tpl_var the template variable name
80 * @param mixed $value the referenced value to assign
82 function assign_by_ref($tpl_var, &$value)
85 $this->values
[$tpl_var] = &$value;
89 * Appends values to template variables
91 * @param array|string $tpl_var the template variable name(s)
92 * @param mixed $value the value to append
94 function append($tpl_var, $value = NULL, $merge = FALSE)
96 if (is_array($tpl_var))
98 foreach ($tpl_var as $_key => $_val)
102 if(isset($this->values
[$_key]) && !is_array($this->values
[$_key]))
103 settype($this->values
[$_key],'array');
105 if($merge && is_array($_val))
107 foreach($_val as $_mkey => $_mval)
108 $this->values
[$_key][$_mkey] = $_mval;
111 $this->values
[$_key][] = $_val;
117 if ($tpl_var != '' && isset($value))
119 if(isset($this->values
[$tpl_var]) && !is_array($this->values
[$tpl_var]))
120 settype($this->values
[$tpl_var],'array');
122 if($merge && is_array($value))
124 foreach($value as $_mkey => $_mval)
125 $this->values
[$tpl_var][$_mkey] = $_mval;
128 $this->values
[$tpl_var][] = $value;
134 * Appends values to template variables by reference
136 * @param string $tpl_var the template variable name
137 * @param mixed $value the referenced value to append
139 function append_by_ref($tpl_var, &$value, $merge = FALSE)
141 if ($tpl_var != '' && isset($value))
143 if(!@is_array
($this->values
[$tpl_var]))
144 settype($this->values
[$tpl_var],'array');
146 if ($merge && is_array($value))
148 foreach($value as $_key => $_val)
149 $this->values
[$tpl_var][$_key] = &$value[$_key];
152 $this->values
[$tpl_var][] = &$value;
157 * Display the template
159 * @param string $file The template file to use
161 function display($file)
163 $t = &$this->values
; // place values array directly in scope
165 include($this->template_dir
.$file);
170 * Return the results of applying a template.
172 * @param string $file The template file to use
173 * @return string A string of the results
175 function fetch($file)
178 $t = &$this->values
; // place values array directly in scope
179 include($this->template_dir
.$file);
180 $contents = ob_get_contents();