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