--- nfo/php/libs/org.netfrag.flib/Site/Template.php 2002/12/19 06:20:39 1.1
+++ nfo/php/libs/org.netfrag.flib/Site/Template.php 2002/12/19 10:33:49 1.2
@@ -1,221 +1,217 @@
// -------------------------------------------------------------------------
-// $Id: Template.php,v 1.1 2002/12/19 06:20:39 joko Exp $
+// $Id: Template.php,v 1.2 2002/12/19 10:33:49 joko Exp $
// -------------------------------------------------------------------------
// $Log: Template.php,v $
+// Revision 1.2 2002/12/19 10:33:49 joko
+// + debugging and bugfixing
+//
// Revision 1.1 2002/12/19 06:20:39 joko
// + initial check-in
//
// -------------------------------------------------------------------------
-
-class Site_Template {
-
- var $meta;
-
- function start() {
-//print "START
";
- }
-
- function _register_langtext_safe() {
- if (!$this->meta[registered][lt]) {
- $this->meta[registered][lt] = 1;
- $this->_register_langtext();
- }
- }
-
- function _register_langtext() {
-//print "REGISTER
";
- // register 'lt' (LangText) template provider
- $this->site->smarty->register_resource(
- "lt",
- array(
- "db_get_template",
- "db_get_timestamp"
- )
- );
-/*
- array(
- "db_get_template",
- "db_get_timestamp",
- "db_get_secure",
- "db_get_trusted"
- )
-*/
- }
-
- function display($identifier, $options) {
-//print "DISPLAY
";
- $this->_build($identifier, $options);
- }
-
- function get($identifier, $interpolate = array()) {
-//print "GET
";
- // TODO: review... what about the cache-key here? use volatile by default or not?
- // for now: per default to be _very_ safe.... ;)
- $options = array(
- 'interpolate' => $interpolate,
- 'return' => 1,
- 'cache_key' => 'volatile'
- );
-// 'cache_key' => 'volatile'
- return $this->_build($identifier, $options);
- }
-
- function _build($identifier, $options) {
-
-//print "BUILD identifier $identifier
";
-//print "options:
" . Dumper($options) . "
";
-
- $this->_register_langtext_safe();
-
+
+class Site_Template {
+
+ var $meta;
+
+ function start() {
+//print "START
";
+ }
+
+ function _register_langtext_safe() {
+ if (!$this->meta[registered][lt]) {
+ $this->meta[registered][lt] = 1;
+ $this->_register_langtext();
+ }
+ }
+
+ function _register_langtext() {
+//print "REGISTER
";
+ // register 'lt' (LangText) template provider
+ $this->site->smarty->register_resource(
+ "lt",
+ array(
+ "db_get_template",
+ "db_get_timestamp"
+ )
+ );
+/*
+ array(
+ "db_get_template",
+ "db_get_timestamp",
+ "db_get_secure",
+ "db_get_trusted"
+ )
+*/
+ }
+
+ function display($identifier, $options) {
+//print "DISPLAY
";
+ $this->_build($identifier, $options);
+ }
+
+ function get($identifier, $interpolate = array()) {
+//print "GET
";
+ // TODO: review... what about the cache-key here? use volatile by default or not?
+ // for now: per default to be _very_ safe.... ;)
+ $options = array(
+ 'interpolate' => $interpolate,
+ 'return' => 1,
+ 'cache_key' => 'volatile'
+ );
+// 'cache_key' => 'volatile'
+ return $this->_build($identifier, $options);
+ }
+
+ function _build($identifier, $options) {
+
+//print "BUILD identifier $identifier
";
+//print "options:
" . Dumper($options) . "
";
+
+ $this->_register_langtext_safe();
+
// TODO: just do '$this->site->smarty->assign($arguments[vars]);' ???
- /*
+ /*
foreach ($arguments[vars] as $name => $value) {
$this->site->smarty->assign($name, $value);
- }
- */
-
- // template variable interpolation
- if ($options['interpolate']) {
- //print Dumper($options['interpolate']);
- $this->site->smarty->assign($options['interpolate']);
- /*
- foreach ($options['interpolate'] as $key => $val) {
- print "key: $key - val $val
";
- $this->site->smarty->assign($key, $val);
- }
- */
- }
-
+ }
+ */
+
+ // template variable interpolation
+ if ($options['interpolate']) {
+ $this->site->smarty->assign($options['interpolate']);
+ }
+
//print "cached: " . $this->site->smarty->is_cached($identifier) . "
";
-
- // TODO: refactor this!
- // $smarty_method = 'fetch|display'
- // $cache_key???
- if ($options['return']) {
-
-//print "RETURN
";
-
- // return template
+
+ // TODO: refactor this!
+ // $smarty_method = 'fetch|display'
+ // $cache_key???
+ if ($options['return']) {
+
+//print "RETURN
";
+
+ // return template
// use of cache-key per template
if ($cache_key = $options['cache_key']) {
-//print "1: $cache_key
";
- if ($cache_key == 'volatile') {
- //$this->site->smarty->clear_cache($identifier, $cache_key);
- //$this->site->smarty->clear_cache('referer.php');
- }
+//print "1: $cache_key
";
+ if ($cache_key == 'volatile') {
+ //$this->site->smarty->clear_cache($identifier, $cache_key);
+ //$this->site->smarty->clear_cache('referer.php');
+ }
$result = $this->site->smarty->fetch($identifier, $cache_key);
} else {
-//print "2
";
+//print "2
";
$result = $this->site->smarty->fetch($identifier);
- }
-//print "result: $result
";
-
+ }
+//print "result: $result
";
+
} else {
- // display template
+ // display template
// use of cache-key per template
if ($cache_key = $options['cache_key']) {
$result = $this->site->smarty->display($identifier, $cache_key);
} else {
$result = $this->site->smarty->display($identifier);
- }
-
- }
-
+ }
+
+ }
+
return $result;
-
- }
-
-}
-
-
-function db_get_template($tpl_name, &$tpl_source, &$smarty_obj)
-{
- //print "db_get_template: '$tpl_name', '$tpl_source', '$smarty_obj'
";
- //return $this->site->lt->getlt($tpl_name);
- global $site;
- if ($template = $site->lt->getlt($tpl_name)) {
-//print "template: '$template'
";
- $tpl_source = $template;
- return true;
- }
-}
-
-function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
-{
- $tpl_timestamp = time();
- return true;
-}
-
-
-/*
-
-// ----------------------------------------------------------------------------------
-// from: http://smarty.php.net/manual/en/templates.from.elsewhere.html
-// ----------------------------------------------------------------------------------
-
-
-// from PHP script
-
-// put these function somewhere in your application
-function db_get_template ($tpl_name, &tpl_source, &$smarty_obj)
-{
- // do database call here to fetch your template,
- // populating $tpl_source
- $sql = new SQL;
- $sql->query("select tpl_source
- from my_table
- where tpl_name='$tpl_name'");
- if ($sql->num_rows) {
- $tpl_source = $sql->record['tpl_source'];
- return true;
- } else {
- return false;
- }
-}
-
-function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
-{
- // do database call here to populate $tpl_timestamp.
- $sql = new SQL;
- $sql->query("select tpl_timestamp
- from my_table
- where tpl_name='$tpl_name'");
- if ($sql->num_rows) {
- $tpl_timestamp = $sql->record['tpl_timestamp'];
- return true;
- } else {
- return false;
- }
-}
-
-function db_get_secure($tpl_name, &$smarty_obj)
-{
- // assume all templates are secure
- return true;
-}
-
-function db_get_trusted($tpl_name, &$smarty_obj)
-{
- // not used for templates
-}
-
-// register the resource name "db"
-$smarty->register_resource("db", array("db_get_template",
- "db_get_timestamp",
- "db_get_secure",
- "db_get_trusted"));
-
-// using resource from php script
-$smarty->display("db:index.tpl");
-
-{* using resource from within Smarty template *}
-{include file="db:/extras/navigation.tpl"}
-
-// ----------------------------------------------------------------------------------
-
-*/
-
-
+
+ }
+
+}
+
+
+function db_get_template($tpl_name, &$tpl_source, &$smarty_obj)
+{
+ //print "db_get_template: '$tpl_name', '$tpl_source', '$smarty_obj'
";
+ //return $this->site->lt->getlt($tpl_name);
+ global $site;
+ if ($template = $site->lt->getlt($tpl_name, array(), 1)) {
+//print "template: '$template'
";
+ $tpl_source = $template;
+ return true;
+ }
+}
+
+function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
+{
+ $tpl_timestamp = time();
+ return true;
+}
+
+
+/*
+
+// ----------------------------------------------------------------------------------
+// from: http://smarty.php.net/manual/en/templates.from.elsewhere.html
+// ----------------------------------------------------------------------------------
+
+
+// from PHP script
+
+// put these function somewhere in your application
+function db_get_template ($tpl_name, &tpl_source, &$smarty_obj)
+{
+ // do database call here to fetch your template,
+ // populating $tpl_source
+ $sql = new SQL;
+ $sql->query("select tpl_source
+ from my_table
+ where tpl_name='$tpl_name'");
+ if ($sql->num_rows) {
+ $tpl_source = $sql->record['tpl_source'];
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
+{
+ // do database call here to populate $tpl_timestamp.
+ $sql = new SQL;
+ $sql->query("select tpl_timestamp
+ from my_table
+ where tpl_name='$tpl_name'");
+ if ($sql->num_rows) {
+ $tpl_timestamp = $sql->record['tpl_timestamp'];
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function db_get_secure($tpl_name, &$smarty_obj)
+{
+ // assume all templates are secure
+ return true;
+}
+
+function db_get_trusted($tpl_name, &$smarty_obj)
+{
+ // not used for templates
+}
+
+// register the resource name "db"
+$smarty->register_resource("db", array("db_get_template",
+ "db_get_timestamp",
+ "db_get_secure",
+ "db_get_trusted"));
+
+// using resource from php script
+$smarty->display("db:index.tpl");
+
+{* using resource from within Smarty template *}
+{include file="db:/extras/navigation.tpl"}
+
+// ----------------------------------------------------------------------------------
+
+*/
+
+
?>
\ No newline at end of file