Converting to GPL
[isso.git] / template_fs.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 if (!$this->is_loaded('template'))
30 {
31 $this->locate('template');
32 }
33
34 $OBJECT = 'File-Based Template System';
35 $CLASS = 'FS_Template';
36 $OBJ = 'template';
37
38 /**
39 * File System Template System
40 *
41 * This framework merely replaces the template loading functions with
42 * file-system based ones.
43 *
44 * @author Iris Studios, Inc.
45 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
46 * @version $Revision$
47 * @package ISSO
48 *
49 */
50 class FS_Template extends DB_Template
51 {
52 /**
53 * The path, from the path of the application, where templates are stored
54 * @var str
55 * @see Shared_Object_Framework::$apppath, _load()
56 */
57 var $templatedir = '';
58
59 /**
60 * The extension all the template files have
61 * @var str
62 * @see _load()
63 */
64 var $extension = 'tpl';
65
66 /**
67 * Takes an array of template names, loads them, and then stores
68 * a parsed version for optimum speed.
69 *
70 * @param array List of template names to be cached
71 */
72 function cache($namearray)
73 {
74 if (sizeof($this->cache) > 0)
75 {
76 trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING);
77 }
78 else
79 {
80 foreach ($namearray AS $name)
81 {
82 $template = $this->_load($name);
83 $template = $this->_parse($template);
84 $this->cache["$name"] = $template;
85 $this->usage["$name"] = 0;
86 }
87 }
88 }
89
90 /**
91 * Loads a template from the file system from the specified $templatedir
92 * with the file extension $extension
93 *
94 * @param str The name of the template call
95 */
96 function _load($name)
97 {
98 global $_isso;
99
100 $path = $_isso->apppath . $this->templatedir . $name . '.' . $this->extension;
101 if (is_file($path))
102 {
103 if (($template = @file_get_contents($path)) !== false)
104 {
105 return $template;
106 }
107 else
108 {
109 trigger_error("Could not load the template '$path'", E_USER_ERROR);
110 exit;
111 }
112 }
113 else
114 {
115 trigger_error("Could not load the template '$path'", E_USER_ERROR);
116 exit;
117 }
118 }
119 }
120
121 /*=====================================================================*\
122 || ###################################################################
123 || # $HeadURL$
124 || # $Id$
125 || ###################################################################
126 \*=====================================================================*/
127 ?>