[pLog-svn] r6293 - plog/trunk/class/template

mark at devel.lifetype.net mark at devel.lifetype.net
Fri Apr 4 13:22:55 EDT 2008


Author: mark
Date: 2008-04-04 13:22:55 -0400 (Fri, 04 Apr 2008)
New Revision: 6293

Modified:
   plog/trunk/class/template/template.class.php
Log:
Remove the {dynamic} filter, and replace it with an enhanced {nocache} filter. (It also compatible with the dynamic filter)

Now, we can cache the "variable" in no cached block. The usage looks like:

{nocache name="<unique blockname>" <varname1>=$<value1> [...]}...{/nocache} 

For more information, please see the following url

Modified: plog/trunk/class/template/template.class.php
===================================================================
--- plog/trunk/class/template/template.class.php	2008-04-04 17:09:55 UTC (rev 6292)
+++ plog/trunk/class/template/template.class.php	2008-04-04 17:22:55 UTC (rev 6293)
@@ -27,11 +27,50 @@
 	// name of the folder where the default template is stored
 	define( "DEFAULT_TEMPLATE_FOLDER", "default" );
 	
-	// Smarty dynamic block function
-	function smarty_block_dynamic($param, $content, &$smarty) {
-    	return $content;
-	}	
+	/* block nocache
+	 *
+	 * usage
+	 *
+	 * {nocache}...{/nocache}
+	 *
+	 * OR
+	 *
+	 * {nocache name="<unique blockname>" <varname1>=$<value1> [...]}...{/nocache}
+	 */
+	function smarty_block_nocache($param, $content, &$smarty, &$repeat)
+	{
+		static $counter = array();
+	
+		if ($repeat)
+		{
+			if (!isset($param['name']))
+				return $content;
 
+			$name = $param['name'];
+	    	unset($param['name']);
+
+			if (!isset($counter[$name]))
+				$counter[$name] = 0;
+			$counter[$name]++;
+	
+			if ($smarty->_cache_including)
+			{
+				$param = isset($smarty->_cache_info['cached_vars'][$name]['items'][$counter[$name]]) ? $smarty->_cache_info['cached_vars'][$name]['items'][$counter[$name]] : array();
+			}
+			else
+			{
+				$smarty->_cache_info['cached_vars'][$name]['items'][$counter[$name]] = $param;
+			}
+	
+			foreach ($param AS $k => $v)
+			{
+				$smarty->_tpl_vars[$k] = $v;
+			}
+		}
+	
+		return $content;
+	} 
+
     /**
      * \ingroup Template
      * 
@@ -100,8 +139,8 @@
             // this helps if php is running in 'safe_mode'
             $this->use_sub_dirs = false;
 
-			// register dynamic block for every template instance
-			$this->register_block('dynamic', 'smarty_block_dynamic', false);
+			// register nocache block for every template instance
+			$this->register_block('nocache', 'smarty_block_nocache', false);
 			
 			if( $config->getValue( 'trim_whitespace_output' ))
 				$this->load_filter( 'output', 'trimwhitespace' );



More information about the pLog-svn mailing list