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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Thu May 13 19:16:45 2004 UTC (20 years, 2 months ago) by jonen
Branch: MAIN
Changes since 1.2: +9 -3 lines
+ bugfix related to wrong interpretation of double qoutes at $site->lt->getlt()

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

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