]> src.bluestatic.org Git - isso.git/blob - TemplateFs.php
mkstrings is obsolete compared to makepo.sh.php
[isso.git] / TemplateFs.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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 (TemplateFs.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Template.php');
29 require_once('ISSO/Functions.php');
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 BSTemplateFs extends BSTemplate
44 {
45 /**
46 * The path, from the path of the application, where templates are stored
47 * @var string
48 */
49 private $templateDir = '';
50
51 /**
52 * The extension all the template files have
53 * @var string
54 */
55 private $extension = 'tpl';
56
57 // ###################################################################
58 /**
59 * Constructor (overriding so we don't require the Db module)
60 */
61 public function __construct() {}
62
63 // ###################################################################
64 /**
65 * Sets the template directory name
66 *
67 * @param string Template directory name
68 */
69 public function setTemplateDirectory($dir)
70 {
71 $this->templateDir = BSFunctions::FetchSourcePath($dir);
72 }
73
74 // ###################################################################
75 /**
76 * Sets the file extension for the templates
77 *
78 * @param string File extension
79 */
80 public function setExtension($ext)
81 {
82 $this->extension = $ext;
83 }
84
85 // ###################################################################
86 /**
87 * Takes an array of template names, loads them, and then stores a
88 * parsed version for optimum speed.
89 *
90 * @param array List of template names to be cached
91 */
92 public function cache($namearray)
93 {
94 if (sizeof($this->cache) > 0)
95 {
96 trigger_error('You cannot cache templates more than once per initialization');
97 }
98 else
99 {
100 foreach ($namearray AS $name)
101 {
102 $template = $this->_loadTemplate($name);
103 $template = $this->_parseTemplate($template);
104 $this->cache["$name"] = $template;
105 $this->usage["$name"] = 0;
106 }
107 }
108 }
109
110 // ###################################################################
111 /**
112 * Loads a template from the file system from the specified
113 * $templatedir with the file extension $extension
114 *
115 * @param string The name of the template call
116 */
117 protected function _loadTemplate($name)
118 {
119 $path = BSRegister::GetAppPath() . $this->templateDir . $name . '.' . $this->extension;
120 if (is_file($path))
121 {
122 if (($template = @file_get_contents($path)) !== false)
123 {
124 return $template;
125 }
126 else
127 {
128 trigger_error("Could not load the template '$path'");
129 exit;
130 }
131 }
132 else
133 {
134 trigger_error("Could not load the template '$path'");
135 exit;
136 }
137 }
138 }
139
140 /*=====================================================================*\
141 || ###################################################################
142 || # $HeadURL$
143 || # $Id$
144 || ###################################################################
145 \*=====================================================================*/
146 ?>