Add tempalte config for alternate stylesheets
[squirrelmail.git] / class / template / Smarty_Template.class.php
CommitLineData
de4d58cb 1<?php
2
3/**
4 * Smarty_Template.class.php
5 *
6 * This file contains a Template subclass intended as a bridge between
7 * SquirrelMail and Smarty. All abstract methods from the Template class
8 * are implemented here.
9 *
10 * @copyright &copy; 2003-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @version $Id$
13 * @package squirrelmail
14 * @subpackage Template
15 * @since 1.5.2
16 *
17 */
18
19/**
20 * The SquirrelMail Smarty Template class. Extends the base
21 * Template class for use with Smarty template pages.
22 *
23 * @author Paul Lesniewski
24 * @package squirrelmail
25 *
26 */
27class Smarty_Template extends Template
28{
29
30 /**
31 * The Smarty template object
32 *
33 * @var object
34 *
35 */
36 var $smarty_template = null;
37
38
39 /**
40 * Constructor
41 *
42 * Please do not call directly. Use Template::construct_template().
43 *
44 * @param string $template_id the template ID
45 *
46 */
47 function Smarty_Template($template_id) {
48//FIXME: find a way to test that this is ONLY ever called
49// from parent's construct_template() method (I doubt it
50// is worth the trouble to parse the current stack trace)
51// if (???)
52// trigger_error('Please do not use default Smarty_Template() constructor. Instead, use Template::construct_template().', E_USER_ERROR);
53
54 parent::Template($template_id);
55
56
57 // pull in the tempalte config file and load smarty settings
58 //
59 $template_config_file = SM_PATH . $this->get_template_file_directory()
60 . 'config.php';
61 if (!file_exists($template_config_file)) {
62
63 trigger_error('No template configuration file was found where expected: ("'
64 . $template_config_file . '")', E_USER_ERROR);
65
66 } else {
67
68 require($template_config_file);
69
70
71 // instantiate and set up Smarty object
72 //
73//LEFT OFF HERE - check for this as empty or not
74 require($smarty_path);
75 $this->smarty_template = new Smarty();
76//LEFT OFF HERE - check for these as empty or not.... I think we at least need compile dir?
77 $this->smarty_template->compile_dir = $smarty_compile_dir;
78 $this->smarty_template->cache_dir = $smarty_cache_dir;
79 $this->smarty_template->config_dir = $smarty_config_dir;
80
81 // note that we do not use Smarty's template_dir
82 // because SquirrelMail has its own method of
83 // determining template file paths
84 //
85 //$this->smarty_template->template_dir =
86
87 }
88
89 }
90
91 /**
92 * Assigns values to template variables
93 *
94 * @param array|string $tpl_var the template variable name(s)
95 * @param mixed $value the value to assign
96FIXME: Proposed idea to add a parameter here that turns variable
97 encoding on, so that we can make sure output is always
98 run through something like htmlspecialchars() (maybe even nl2br()?)
99 *
100 */
101 function assign($tpl_var, $value = NULL) {
102
103 $this->smarty_template->assign($tpl_var, $value);
104
105 }
106
107 /**
108 * Assigns values to template variables by reference
109 *
110 * @param string $tpl_var the template variable name
111 * @param mixed $value the referenced value to assign
112FIXME: Proposed idea to add a parameter here that turns variable
113 encoding on, so that we can make sure output is always
114 run through something like htmlspecialchars() (maybe even nl2br()?)
115 *
116 */
117 function assign_by_ref($tpl_var, &$value) {
118
119 $this->smarty_template->assign_by_ref($tpl_var, $value);
120
121 }
122
123 /**
124 * Appends values to template variables
125 *
126 * @param array|string $tpl_var the template variable name(s)
127 * @param mixed $value the value to append
128 * @param boolean $merge when $value is given as an array,
129 * this indicates whether or not that
130 * array itself should be appended as
131 * a new template variable value or if
132 * that array's values should be merged
133 * into the existing array of template
134 * variable values
135FIXME: Proposed idea to add a parameter here that turns variable
136 encoding on, so that we can make sure output is always
137 run through something like htmlspecialchars() (maybe even nl2br()?)
138 *
139 */
140 function append($tpl_var, $value = NULL, $merge = FALSE) {
141
142 $this->smarty_template->append($tpl_var, $value, $merge);
143
144 }
145
146 /**
147 * Appends values to template variables by reference
148 *
149 * @param string $tpl_var the template variable name
150 * @param mixed $value the referenced value to append
151 * @param boolean $merge when $value is given as an array,
152 * this indicates whether or not that
153 * array itself should be appended as
154 * a new template variable value or if
155 * that array's values should be merged
156 * into the existing array of template
157 * variable values
158FIXME: Proposed idea to add a parameter here that turns variable
159 encoding on, so that we can make sure output is always
160 run through something like htmlspecialchars() (maybe even nl2br()?)
161 *
162 */
163 function append_by_ref($tpl_var, &$value, $merge = FALSE) {
164
165 $this->smarty_template->append_by_ref($tpl_var, $value, $merge);
166
167 }
168
169 /**
170 * Applys the template and generates final output destined
171 * for the user's browser
172 *
173 * @param string $filepath The full file path to the template to be applied
174 *
175 * @return string The output for the given template
176 *
177 */
178 function apply_template($filepath) {
179
180 // if being passed a raw .css or .js file, default
181 // Smarty delimiters will cause errors
182 //
183 if (strrpos($filepath, '.css') === (strlen($filepath) - 4)
184 || strrpos($filepath, '.js') === (strlen($filepath) - 3)) {
185 $this->smarty_template->left_delimiter = '{=';
186 $this->smarty_template->right_delimiter = '=}';
187 }
188
189 // Smarty wants absolute paths
190 //
191 if (strpos($filepath, '/') === 0)
192 return $this->smarty_template->fetch('file:' . $filepath);
193 else
194 return $this->smarty_template->fetch('file:' . getcwd() . '/' . $filepath);
195
196 }
197
198}
199