/[cvs]/nfo/php/libs/org.netfrag.flib/Site/Template.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.flib/Site/Template.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Dec 19 10:33:49 2002 UTC (21 years, 8 months ago) by joko
Branch: MAIN
Changes since 1.1: +192 -196 lines
+ debugging and bugfixing

1 <?
2 // -------------------------------------------------------------------------
3 // $Id: Template.php,v 1.1 2002/12/19 06:20:39 joko Exp $
4 // -------------------------------------------------------------------------
5 // $Log: Template.php,v $
6 // Revision 1.1 2002/12/19 06:20:39 joko
7 // + initial check-in
8 //
9 // -------------------------------------------------------------------------
10
11 class Site_Template {
12
13 var $meta;
14
15 function start() {
16 //print "START<br>";
17 }
18
19 function _register_langtext_safe() {
20 if (!$this->meta[registered][lt]) {
21 $this->meta[registered][lt] = 1;
22 $this->_register_langtext();
23 }
24 }
25
26 function _register_langtext() {
27 //print "REGISTER<br>";
28 // register 'lt' (LangText) template provider
29 $this->site->smarty->register_resource(
30 "lt",
31 array(
32 "db_get_template",
33 "db_get_timestamp"
34 )
35 );
36 /*
37 array(
38 "db_get_template",
39 "db_get_timestamp",
40 "db_get_secure",
41 "db_get_trusted"
42 )
43 */
44 }
45
46 function display($identifier, $options) {
47 //print "DISPLAY<br>";
48 $this->_build($identifier, $options);
49 }
50
51 function get($identifier, $interpolate = array()) {
52 //print "GET<br>";
53 // TODO: review... what about the cache-key here? use volatile by default or not?
54 // for now: per default to be _very_ safe.... ;)
55 $options = array(
56 'interpolate' => $interpolate,
57 'return' => 1,
58 'cache_key' => 'volatile'
59 );
60 // 'cache_key' => 'volatile'
61 return $this->_build($identifier, $options);
62 }
63
64 function _build($identifier, $options) {
65
66 //print "BUILD identifier $identifier<br>";
67 //print "options:<br>" . Dumper($options) . "<br>";
68
69 $this->_register_langtext_safe();
70
71 // TODO: just do '$this->site->smarty->assign($arguments[vars]);' ???
72 /*
73 foreach ($arguments[vars] as $name => $value) {
74 $this->site->smarty->assign($name, $value);
75 }
76 */
77
78 // template variable interpolation
79 if ($options['interpolate']) {
80 $this->site->smarty->assign($options['interpolate']);
81 }
82
83 //print "cached: " . $this->site->smarty->is_cached($identifier) . "<br>";
84
85 // TODO: refactor this!
86 // $smarty_method = 'fetch|display'
87 // $cache_key???
88 if ($options['return']) {
89
90 //print "RETURN<br>";
91
92 // return template
93 // use of cache-key per template
94 if ($cache_key = $options['cache_key']) {
95 //print "1: $cache_key<br>";
96 if ($cache_key == 'volatile') {
97 //$this->site->smarty->clear_cache($identifier, $cache_key);
98 //$this->site->smarty->clear_cache('referer.php');
99 }
100 $result = $this->site->smarty->fetch($identifier, $cache_key);
101 } else {
102 //print "2<br>";
103 $result = $this->site->smarty->fetch($identifier);
104 }
105 //print "result: $result<br>";
106
107 } else {
108
109 // display template
110 // use of cache-key per template
111 if ($cache_key = $options['cache_key']) {
112 $result = $this->site->smarty->display($identifier, $cache_key);
113 } else {
114 $result = $this->site->smarty->display($identifier);
115 }
116
117 }
118
119 return $result;
120
121 }
122
123 }
124
125
126 function db_get_template($tpl_name, &$tpl_source, &$smarty_obj)
127 {
128 //print "db_get_template: '$tpl_name', '$tpl_source', '$smarty_obj'<br>";
129 //return $this->site->lt->getlt($tpl_name);
130 global $site;
131 if ($template = $site->lt->getlt($tpl_name, array(), 1)) {
132 //print "template: '$template'<br>";
133 $tpl_source = $template;
134 return true;
135 }
136 }
137
138 function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
139 {
140 $tpl_timestamp = time();
141 return true;
142 }
143
144
145 /*
146
147 // ----------------------------------------------------------------------------------
148 // from: http://smarty.php.net/manual/en/templates.from.elsewhere.html
149 // ----------------------------------------------------------------------------------
150
151
152 // from PHP script
153
154 // put these function somewhere in your application
155 function db_get_template ($tpl_name, &tpl_source, &$smarty_obj)
156 {
157 // do database call here to fetch your template,
158 // populating $tpl_source
159 $sql = new SQL;
160 $sql->query("select tpl_source
161 from my_table
162 where tpl_name='$tpl_name'");
163 if ($sql->num_rows) {
164 $tpl_source = $sql->record['tpl_source'];
165 return true;
166 } else {
167 return false;
168 }
169 }
170
171 function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
172 {
173 // do database call here to populate $tpl_timestamp.
174 $sql = new SQL;
175 $sql->query("select tpl_timestamp
176 from my_table
177 where tpl_name='$tpl_name'");
178 if ($sql->num_rows) {
179 $tpl_timestamp = $sql->record['tpl_timestamp'];
180 return true;
181 } else {
182 return false;
183 }
184 }
185
186 function db_get_secure($tpl_name, &$smarty_obj)
187 {
188 // assume all templates are secure
189 return true;
190 }
191
192 function db_get_trusted($tpl_name, &$smarty_obj)
193 {
194 // not used for templates
195 }
196
197 // register the resource name "db"
198 $smarty->register_resource("db", array("db_get_template",
199 "db_get_timestamp",
200 "db_get_secure",
201 "db_get_trusted"));
202
203 // using resource from php script
204 $smarty->display("db:index.tpl");
205
206 {* using resource from within Smarty template *}
207 {include file="db:/extras/navigation.tpl"}
208
209 // ----------------------------------------------------------------------------------
210
211 */
212
213
214 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed