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

Jon Daley plogworld at jon.limedaley.com
Fri Apr 4 13:50:57 EDT 2008


 	Nice.

On Sat, 5 Apr 2008, Mark Wu wrote:

> It works great.
>
> I test it to cache the $plugins and $post inside the nocache block, it works
> great without any problem.
>
> Mark
>
>> -----Original Message-----
>> From: plog-svn-bounces at devel.lifetype.net
>> [mailto:plog-svn-bounces at devel.lifetype.net] On Behalf Of
>> mark at devel.lifetype.net
>> Sent: Saturday, April 05, 2008 1:23 AM
>> To: plog-svn at devel.lifetype.net
>> Subject: [pLog-svn] r6293 - plog/trunk/class/template
>>
>> 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'][$cou
>> nter[$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' );
>>
>> _______________________________________________
>> pLog-svn mailing list
>> pLog-svn at devel.lifetype.net
>> http://limedaley.com/mailman/listinfo/plog-svn
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com/

When you starve with a tiger, the tiger starves last.
-- Griffin's Thought


More information about the pLog-svn mailing list