Making everything properly documented so that we don't produce warnings when running...
[isso.git] / template_fs.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 /**
14 * File System Template System
15 * template_fs.php
16 *
17 * @package ISSO
18 */
19
20 if (!$this->is_loaded('template'))
21 {
22 $this->locate('template');
23 }
24
25 $OBJECT = 'File-Based Template System';
26 $CLASS = 'FS_Template';
27 $OBJ = 'template';
28
29 /**
30 * File System Template System
31 *
32 * This framework merely replaces the template loading functions with
33 * file-system based ones.
34 *
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 class FS_Template extends DB_Template
42 {
43 /**
44 * The path, from the path of the application, where templates are stored
45 * @var str
46 * @see Shared_Object_Framework::$apppath, _load()
47 */
48 var $templatedir = '';
49
50 /**
51 * The extension all the template files have
52 * @var str
53 * @see _load()
54 */
55 var $extension = 'tpl';
56
57 /**
58 * Takes an array of template names, loads them, and then stores
59 * a parsed version for optimum speed.
60 *
61 * @param array List of template names to be cached
62 */
63 function cache($namearray)
64 {
65 if (sizeof($this->cache) > 0)
66 {
67 trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING);
68 }
69 else
70 {
71 foreach ($namearray AS $name)
72 {
73 $template = $this->_load($name);
74 $template = $this->_parse($template);
75 $this->cache["$name"] = $template;
76 $this->usage["$name"] = 0;
77 }
78 }
79 }
80
81 /**
82 * Loads a template from the file system from the specified $templatedir
83 * with the file extension $extension
84 *
85 * @param str The name of the template call
86 */
87 function _load($name)
88 {
89 global $_isso;
90
91 $path = $_isso->apppath . $this->templatedir . $name . '.' . $this->extension;
92 if (is_file($path))
93 {
94 if (($template = @file_get_contents($path)) !== false)
95 {
96 return $template;
97 }
98 else
99 {
100 trigger_error("Could not load the template '$path'", E_USER_ERROR);
101 exit;
102 }
103 }
104 else
105 {
106 trigger_error("Could not load the template '$path'", E_USER_ERROR);
107 exit;
108 }
109 }
110 }
111
112 /*=====================================================================*\
113 || ###################################################################
114 || # $HeadURL$
115 || # $Id$
116 || ###################################################################
117 \*=====================================================================*/
118 ?>