Woops. That is supposed to be setAppVersion()
[isso.git] / template_fs.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * File System Template System
24 * template_fs.php
25 *
26 * @package ISSO
27 */
28
29 $this->load('template', null);
30
31 /**
32 * File System Template System
33 *
34 * This framework merely replaces the template loading functions with
35 * file-system based ones.
36 *
37 * @author Blue Static
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class Template_FS extends Template
44 {
45 /**
46 * The path, from the path of the application, where templates are stored
47 * @var string
48 * @access private
49 */
50 var $templatedir = '';
51
52 /**
53 * The extension all the template files have
54 * @var string
55 * @access private
56 */
57 var $extension = 'tpl';
58
59 // ###################################################################
60 /**
61 * Constructor
62 */
63 function __construct(&$registry)
64 {
65 $this->registry =& $registry;
66 }
67
68 // ###################################################################
69 /**
70 * (PHP 4) Constructor
71 */
72 function Template_FS(&$registry)
73 {
74 $this->__construct($registry);
75 }
76
77 // ###################################################################
78 /**
79 * Sets the template directory
80 *
81 * @access public
82 *
83 * @param string The template directory
84 */
85 function setTemplateDir($path)
86 {
87 $this->templatedir = $this->registry->fetch_sourcepath($path);
88 }
89
90 // ###################################################################
91 /**
92 * Sets the file extension
93 *
94 * @access public
95 *
96 * @param string File extension
97 */
98 function setExtension($ext)
99 {
100 $this->extension = $ext;
101 }
102
103 // ###################################################################
104 /**
105 * Takes an array of template names, loads them, and then stores a
106 * parsed version for optimum speed.
107 *
108 * @access public
109 *
110 * @param array List of template names to be cached
111 */
112 function cache($namearray)
113 {
114 if (sizeof($this->cache) > 0)
115 {
116 trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING);
117 }
118 else
119 {
120 foreach ($namearray AS $name)
121 {
122 $template = $this->_load($name);
123 $template = $this->_parse($template);
124 $this->cache["$name"] = $template;
125 $this->usage["$name"] = 0;
126 }
127 }
128 }
129
130 // ###################################################################
131 /**
132 * Loads a template from the file system from the specified
133 * $templatedir with the file extension $extension
134 *
135 * @access private
136 *
137 * @param string The name of the template call
138 */
139 function _load($name)
140 {
141 $this->registry->check_isso_fields(get_class($this));
142
143 $path = $this->registry->apppath . $this->templatedir . $name . '.' . $this->extension;
144 if (is_file($path))
145 {
146 if (($template = @file_get_contents($path)) !== false)
147 {
148 return $template;
149 }
150 else
151 {
152 trigger_error("Could not load the template '$path'", E_USER_ERROR);
153 exit;
154 }
155 }
156 else
157 {
158 trigger_error("Could not load the template '$path'", E_USER_ERROR);
159 exit;
160 }
161 }
162 }
163
164 /*=====================================================================*\
165 || ###################################################################
166 || # $HeadURL$
167 || # $Id$
168 || ###################################################################
169 \*=====================================================================*/
170 ?>