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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

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