Added registry connection plugs to the modules
[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 * Framework registry object
54 * @var object
55 */
56 var $registry = null;
57
58 /**
59 * The path, from the path of the application, where templates are stored
60 * @var string
61 */
62 var $templatedir = '';
63
64 /**
65 * The extension all the template files have
66 * @var string
67 */
68 var $extension = 'tpl';
69
70 /**
71 * Constructor
72 */
73 function FS_Template($registry)
74 {
75 $this->registry = $registry;
76 }
77
78 /**
79 * Takes an array of template names, loads them, and then stores
80 * a parsed version for optimum speed.
81 *
82 * @param array List of template names to be cached
83 */
84 function cache($namearray)
85 {
86 if (sizeof($this->cache) > 0)
87 {
88 trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING);
89 }
90 else
91 {
92 foreach ($namearray AS $name)
93 {
94 $template = $this->_load($name);
95 $template = $this->_parse($template);
96 $this->cache["$name"] = $template;
97 $this->usage["$name"] = 0;
98 }
99 }
100 }
101
102 /**
103 * Loads a template from the file system from the specified $templatedir
104 * with the file extension $extension
105 *
106 * @param string The name of the template call
107 */
108 function _load($name)
109 {
110 global $_isso;
111
112 $path = $_isso->apppath . $this->templatedir . $name . '.' . $this->extension;
113 if (is_file($path))
114 {
115 if (($template = @file_get_contents($path)) !== false)
116 {
117 return $template;
118 }
119 else
120 {
121 trigger_error("Could not load the template '$path'", E_USER_ERROR);
122 exit;
123 }
124 }
125 else
126 {
127 trigger_error("Could not load the template '$path'", E_USER_ERROR);
128 exit;
129 }
130 }
131 }
132
133 /*=====================================================================*\
134 || ###################################################################
135 || # $HeadURL$
136 || # $Id$
137 || ###################################################################
138 \*=====================================================================*/
139 ?>