Redbean + Smarty update

This commit is contained in:
Robin Kloppe 2014-10-13 11:24:53 +02:00
parent c1b8226466
commit eb0835ff74
122 changed files with 12653 additions and 11637 deletions

View file

@ -1,75 +1,82 @@
<?php
/**
* Smarty Internal Plugin
*
* @package Smarty
* @subpackage Cacher
*/
* Smarty Internal Plugin
*
* @package Smarty
* @subpackage Cacher
*/
/**
* Cache Handler API
*
* @package Smarty
* @subpackage Cacher
* @author Rodney Rehm
*/
* Cache Handler API
*
* @package Smarty
* @subpackage Cacher
* @author Rodney Rehm
*/
abstract class Smarty_CacheResource
{
/**
* cache for Smarty_CacheResource instances
* @var array
*/
* cache for Smarty_CacheResource instances
*
* @var array
*/
public static $resources = array();
/**
* resource types provided by the core
* @var array
*/
* resource types provided by the core
*
* @var array
*/
protected static $sysplugins = array(
'file' => true,
);
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @return void
*/
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $source cached object
* @return void
*/
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached
*
* @return void
*/
abstract public function populateTimestamp(Smarty_Template_Cached $cached);
/**
* Read the cached template and process header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null);
* Read the cached template and process header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null);
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @return boolean success
*/
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
abstract public function writeCachedContent(Smarty_Internal_Template $_template, $content);
/**
* Return cached content
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content of cache
*/
* Return cached content
*
* @param Smarty_Internal_Template $_template template object
*
* @return null|string
*/
public function getCachedContent(Smarty_Internal_Template $_template)
{
if ($_template->cached->handler->process($_template)) {
@ -83,26 +90,34 @@ abstract class Smarty_CacheResource
}
/**
* Empty cache
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
abstract public function clearAll(Smarty $smarty, $exp_time=null);
* Empty cache
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
abstract public function clearAll(Smarty $smarty, $exp_time = null);
/**
* Empty cache for a specific template
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
* Empty cache for a specific template
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
abstract public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time);
/**
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
*
* @return bool|null
*/
public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
{
// theoretically locking_timeout should be checked against time_limit (max_execution_time)
@ -120,18 +135,42 @@ abstract class Smarty_CacheResource
return $hadLock;
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
*
* @return bool
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
// check if lock exists
return false;
}
/**
* Lock cache for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
*
* @return bool
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
// create lock
return true;
}
/**
* Unlock cache for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
*
* @return bool
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
// release lock
@ -139,12 +178,14 @@ abstract class Smarty_CacheResource
}
/**
* Load Cache Resource Handler
*
* @param Smarty $smarty Smarty object
* @param string $type name of the cache resource
* @return Smarty_CacheResource Cache Resource Handler
*/
* Load Cache Resource Handler
*
* @param Smarty $smarty Smarty object
* @param string $type name of the cache resource
*
* @throws SmartyException
* @return Smarty_CacheResource Cache Resource Handler
*/
public static function load(Smarty $smarty, $type = null)
{
if (!isset($type)) {
@ -184,10 +225,10 @@ abstract class Smarty_CacheResource
}
/**
* Invalid Loaded Cache Files
*
* @param Smarty $smarty Smarty object
*/
* Invalid Loaded Cache Files
*
* @param Smarty $smarty Smarty object
*/
public static function invalidLoadedCache(Smarty $smarty)
{
foreach ($smarty->template_objects as $tpl) {
@ -200,93 +241,104 @@ abstract class Smarty_CacheResource
}
/**
* Smarty Resource Data Object
*
* Cache Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
* Smarty Resource Data Object
* Cache Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Smarty_Template_Cached
{
/**
* Source Filepath
* @var string
*/
* Source Filepath
*
* @var string
*/
public $filepath = false;
/**
* Source Content
* @var string
*/
* Source Content
*
* @var string
*/
public $content = null;
/**
* Source Timestamp
* @var integer
*/
* Source Timestamp
*
* @var integer
*/
public $timestamp = false;
/**
* Source Existence
* @var boolean
*/
* Source Existence
*
* @var boolean
*/
public $exists = false;
/**
* Cache Is Valid
* @var boolean
*/
* Cache Is Valid
*
* @var boolean
*/
public $valid = false;
/**
* Cache was processed
* @var boolean
*/
* Cache was processed
*
* @var boolean
*/
public $processed = false;
/**
* CacheResource Handler
* @var Smarty_CacheResource
*/
* CacheResource Handler
*
* @var Smarty_CacheResource
*/
public $handler = null;
/**
* Template Compile Id (Smarty_Internal_Template::$compile_id)
* @var string
*/
* Template Compile Id (Smarty_Internal_Template::$compile_id)
*
* @var string
*/
public $compile_id = null;
/**
* Template Cache Id (Smarty_Internal_Template::$cache_id)
* @var string
*/
* Template Cache Id (Smarty_Internal_Template::$cache_id)
*
* @var string
*/
public $cache_id = null;
/**
* Id for cache locking
* @var string
*/
* Id for cache locking
*
* @var string
*/
public $lock_id = null;
/**
* flag that cache is locked by this instance
* @var bool
*/
* flag that cache is locked by this instance
*
* @var bool
*/
public $is_locked = false;
/**
* Source Object
* @var Smarty_Template_Source
*/
* Source Object
*
* @var Smarty_Template_Source
*/
public $source = null;
/**
* create Cached Object container
*
* @param Smarty_Internal_Template $_template template object
*/
* create Cached Object container
*
* @param Smarty_Internal_Template $_template template object
*/
public function __construct(Smarty_Internal_Template $_template)
{
$this->compile_id = $_template->compile_id;
@ -362,16 +414,18 @@ class Smarty_Template_Cached
}
/**
* Write this cache object to handler
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @return boolean success
*/
* Write this cache object to handler
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function write(Smarty_Internal_Template $_template, $content)
{
if (!$_template->source->recompiled) {
if ($this->handler->writeCachedContent($_template, $content)) {
$this->content = null;
$this->timestamp = time();
$this->exists = true;
$this->valid = true;
@ -385,5 +439,4 @@ class Smarty_Template_Cached
return false;
}
}

View file

@ -2,16 +2,16 @@
/**
* Smarty Internal Plugin
*
* @package Smarty
* @package Smarty
* @subpackage Cacher
*/
/**
* Cache Handler API
*
* @package Smarty
* @package Smarty
* @subpackage Cacher
* @author Rodney Rehm
* @author Rodney Rehm
*/
abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{
@ -24,20 +24,21 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
*
* @return void
*/
abstract protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime);
/**
* Fetch cached content's modification timestamp from data source
*
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
@ -54,6 +55,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $content content to cache
*
* @return boolean success
*/
abstract protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content);
@ -65,6 +67,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
*
* @return integer number of deleted caches
*/
abstract protected function delete($name, $cache_id, $compile_id, $exp_time);
@ -74,6 +77,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
@ -88,7 +92,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $source cached object
* @param Smarty_Template_Cached $cached
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
@ -111,9 +116,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if the cached content does not exist
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
{
if (!$cached) {
$cached = $_template->cached;
@ -131,6 +137,9 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
);
}
if (isset($content)) {
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $_template;
eval("?>" . $content);
@ -145,6 +154,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
@ -164,9 +174,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
public function clearAll(Smarty $smarty, $exp_time=null)
public function clearAll(Smarty $smarty, $exp_time = null)
{
$this->cache = array();
@ -181,13 +192,40 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$this->cache = array();
$cache_name = null;
return $this->delete($resource_name, $cache_id, $compile_id, $exp_time);
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
if ($tpl->source->exists) {
$cache_name = $tpl->source->name;
} else {
return 0;
}
// remove from template cache
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
// template object no longer needed
unset($tpl);
}
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
}
/**
@ -195,7 +233,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if cache is locked
*
* @return boolean true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
@ -215,6 +254,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
@ -230,6 +271,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{

View file

@ -2,44 +2,43 @@
/**
* Smarty Internal Plugin
*
* @package Smarty
* @package Smarty
* @subpackage Cacher
*/
/**
* Smarty Cache Handler Base for Key/Value Storage Implementations
*
* This class implements the functionality required to use simple key/value stores
* for hierarchical cache groups. key/value stores like memcache or APC do not support
* wildcards in keys, therefore a cache group cannot be cleared like "a|*" - which
* is no problem to filesystem and RDBMS implementations.
*
* This implementation is based on the concept of invalidation. While one specific cache
* can be identified and cleared, any range of caches cannot be identified. For this reason
* each level of the cache group hierarchy can have its own value in the store. These values
* are nothing but microtimes, telling us when a particular cache group was cleared for the
* last time. These keys are evaluated for every cache read to determine if the cache has
* been invalidated since it was created and should hence be treated as inexistent.
*
* Although deep hierarchies are possible, they are not recommended. Try to keep your
* cache groups as shallow as possible. Anything up 3-5 parents should be ok. So
* »a|b| is a good depth where »a|b|c|d|e|f|g|h|i|j| isn't. Try to join correlating
* cache groups: if your cache groups look somewhat like »a|b|$page|$items|$whatever«
* consider using »a|b|c|$page-$items-$whatever« instead.
*
* @package Smarty
* @package Smarty
* @subpackage Cacher
* @author Rodney Rehm
* @author Rodney Rehm
*/
abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
/**
* cache for contents
*
* @var array
*/
protected $contents = array();
/**
* cache for timestamps
*
* @var array
*/
protected $timestamps = array();
@ -49,14 +48,15 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$cached->filepath = $_template->source->uid
. '#' . $this->sanitize($cached->source->name)
. '#' . $this->sanitize($cached->cache_id)
. '#' . $this->sanitize($cached->compile_id);
. '#' . $this->sanitize($cached->source->resource)
. '#' . $this->sanitize($cached->cache_id)
. '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached);
}
@ -65,6 +65,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
@ -82,9 +83,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if the cached content does not exist
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
{
if (!$cached) {
$cached = $_template->cached;
@ -97,6 +99,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
}
}
if (isset($content)) {
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $_template;
eval("?>" . $content);
@ -111,6 +116,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
@ -122,27 +128,26 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Empty cache
*
* {@internal the $exp_time argument is ignored altogether }}
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
* @uses purge() to clear the whole store
* @uses invalidate() to mark everything outdated if purge() is inapplicable
*/
public function clearAll(Smarty $smarty, $exp_time=null)
public function clearAll(Smarty $smarty, $exp_time = null)
{
if (!$this->purge()) {
$this->invalidate(null);
}
return -1;
return - 1;
}
/**
* Empty cache for a specific template
*
* {@internal the $exp_time argument is ignored altogether}}
*
* @param Smarty $smarty Smarty object
@ -150,6 +155,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
@ -162,8 +168,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$this->delete(array($cid));
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
return -1;
return - 1;
}
/**
* Get template's unique ID
*
@ -171,6 +178,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return string filepath of cache file
*/
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
@ -201,6 +209,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Sanitize CacheID components
*
* @param string $string CacheID component to sanitize
*
* @return string sanitized CacheID component
*/
protected function sanitize($string)
@ -224,6 +233,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
* @param string $resource_uid resource's uid
*
* @return boolean success
*/
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
@ -245,7 +255,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Add current microtime to the beginning of $cache_content
*
* {@internal the header uses 8 Bytes, the first 4 Bytes are the seconds, the second 4 Bytes are the microseconds}}
*
* @param string &$content the content to be cached
@ -261,6 +270,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Extract the timestamp the $content was cached
*
* @param string &$content the cached content
*
* @return float the microtime the content was cached
*/
protected function getMetaTimestamp(&$content)
@ -280,6 +290,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's uid
*
* @return void
*/
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
@ -289,22 +300,24 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
// invalidate everything
if (!$resource_name && !$cache_id && !$compile_id) {
$key = 'IVK#ALL';
}
// invalidate all caches by template
else if ($resource_name && !$cache_id && !$compile_id) {
$key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
}
// invalidate all caches by cache group
else if (!$resource_name && $cache_id && !$compile_id) {
$key = 'IVK#CACHE#' . $this->sanitize($cache_id);
}
// invalidate all caches by compile id
else if (!$resource_name && !$cache_id && $compile_id) {
$key = 'IVK#COMPILE#' . $this->sanitize($compile_id);
}
// invalidate by combination
} // invalidate all caches by template
else {
$key = 'IVK#CID#' . $cid;
if ($resource_name && !$cache_id && !$compile_id) {
$key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
} // invalidate all caches by cache group
else {
if (!$resource_name && $cache_id && !$compile_id) {
$key = 'IVK#CACHE#' . $this->sanitize($cache_id);
} // invalidate all caches by compile id
else {
if (!$resource_name && !$cache_id && $compile_id) {
$key = 'IVK#COMPILE#' . $this->sanitize($compile_id);
} // invalidate by combination
else {
$key = 'IVK#CID#' . $cid;
}
}
}
}
$this->write(array($key => $now));
}
@ -317,6 +330,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return float the microtime the CacheID was invalidated
*/
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
@ -342,7 +356,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Translate a CacheID into the list of applicable InvalidationKeys.
*
* Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
*
* @param string $cid CacheID to translate
@ -350,6 +363,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/
@ -387,7 +401,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$t[] = 'IVK#CACHE#' . $part;
$t[] = 'IVK#CID' . $_name . $part . $_compile;
// skip past delimiter position
$i++;
$i ++;
}
return $t;
@ -398,7 +412,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if cache is locked
*
* @return boolean true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
@ -413,6 +428,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
@ -426,6 +443,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
@ -438,6 +457,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
*/
abstract protected function read(array $keys);
@ -445,16 +465,18 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
abstract protected function write(array $keys, $expire=null);
abstract protected function write(array $keys, $expire = null);
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/
abstract protected function delete(array $keys);
@ -468,5 +490,4 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
return false;
}
}

View file

@ -2,19 +2,17 @@
/**
* Smarty Internal Plugin
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
/**
* Smarty Resource Data Object
*
* Meta Data Container for Config Files
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*
* @author Rodney Rehm
* @property string $content
* @property int $timestamp
* @property bool $exists
@ -50,8 +48,9 @@ class Smarty_Config_Source extends Smarty_Template_Source
/**
* <<magic>> Generic setter.
*
* @param string $property_name valid: content, timestamp, exists
* @param mixed $value newly assigned value (not check for correct type)
* @param string $property_name valid: content, timestamp, exists
* @param mixed $value newly assigned value (not check for correct type)
*
* @throws SmartyException when the given property name is not valid
*/
public function __set($property_name, $value)
@ -71,7 +70,9 @@ class Smarty_Config_Source extends Smarty_Template_Source
/**
* <<magic>> Generic getter.
*
* @param string $property_name valid: content, timestamp, exists
* @param string $property_name valid: content, timestamp, exists
*
* @return mixed|void
* @throws SmartyException when the given property name is not valid
*/
public function __get($property_name)
@ -90,5 +91,4 @@ class Smarty_Config_Source extends Smarty_Template_Source
throw new SmartyException("config property '$property_name' does not exist.");
}
}
}

View file

@ -1,277 +1,297 @@
<?php
/**
* Smarty Internal Plugin CacheResource File
*
* @package Smarty
* @subpackage Cacher
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin CacheResource File
*
* @package Smarty
* @subpackage Cacher
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* This class does contain all necessary methods for the HTML cache on file system
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
*
* @package Smarty
* @subpackage Cacher
*/
class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
{
/**
* This class does contain all necessary methods for the HTML cache on file system
*
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
*
* @package Smarty
* @subpackage Cacher
*/
class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
$_filepath = $_template->source->uid;
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
$_filepath = $_template->source->uid;
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
} else {
$_cache_id = '';
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
}
$_cache_dir = $_template->smarty->getCacheDir();
if ($_template->smarty->cache_locking) {
// create locking file name
// relative file name?
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
$_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
} else {
$_cache_id = '';
$_lock_dir = $_cache_dir;
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
}
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
}
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
}
/**
* Read the cached template and process its header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
*
* @return booleantrue or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
{
/** @var Smarty_Internal_Template $_smarty_tpl
* used in included file
*/
$_smarty_tpl = $_template;
return @include $_template->cached->filepath;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
$_template->cached->timestamp = @filemtime($_template->cached->filepath);
$_template->cached->exists = !!$_template->cached->timestamp;
if ($_template->cached->exists) {
return true;
}
$_cache_dir = $_template->smarty->getCacheDir();
if ($_template->smarty->cache_locking) {
// create locking file name
// relative file name?
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
$_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
} else {
$_lock_dir = $_cache_dir;
}
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
}
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
}
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
return false;
}
/**
* Empty cache
*
* @param Smarty $smarty
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
return $this->clear($smarty, null, null, null, $exp_time);
}
/**
* Empty cache for a specific template
*
* @param Smarty $smarty
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
if (($_dir = realpath($smarty->getCacheDir())) === false) {
return 0;
}
/**
* Read the cached template and process its header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
{
$_smarty_tpl = $_template;
return @include $_template->cached->filepath;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
$_template->cached->timestamp = @filemtime($_template->cached->filepath);
$_template->cached->exists = !!$_template->cached->timestamp;
if ($_template->cached->exists) {
return true;
$_dir .= '/';
$_dir_length = strlen($_dir);
if (isset($_cache_id)) {
$_cache_id_parts = explode('|', $_cache_id);
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
}
}
return false;
}
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
/**
* Empty cache
*
* @param Smarty_Internal_Template $_template template object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
return $this->clear($smarty, null, null, null, $exp_time);
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
} else {
return 0;
}
}
/**
* Empty cache for a specific template
*
* @param Smarty $_template template object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
$_dir = $smarty->getCacheDir();
$_dir_length = strlen($_dir);
if (isset($_cache_id)) {
$_cache_id_parts = explode('|', $_cache_id);
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
$_count = 0;
$_time = time();
if (file_exists($_dir)) {
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_cache as $_file) {
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
// directory ?
if ($_file->isDir()) {
if (!$_cache->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
}
}
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
} else {
return 0;
}
}
$_count = 0;
$_time = time();
if (file_exists($_dir)) {
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_cache as $_file) {
if (substr(basename($_file->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
// directory ?
if ($_file->isDir()) {
if (!$_cache->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
} else {
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
$_parts_count = count($_parts);
// check name
if (isset($resource_name)) {
if ($_parts[$_parts_count-1] != $_resourcename_parts) {
continue;
}
}
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) {
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
$_parts_count = count($_parts);
// check name
if (isset($resource_name)) {
if ($_parts[$_parts_count - 1] != $_resourcename_parts) {
continue;
}
// check cache id
if (isset($_cache_id)) {
// count of cache id parts
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
if ($_parts_count < $_cache_id_parts_count) {
}
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
continue;
}
// check cache id
if (isset($_cache_id)) {
// count of cache id parts
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
if ($_parts_count < $_cache_id_parts_count) {
continue;
}
for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
if ($_parts[$i] != $_cache_id_parts[$i]) {
continue 2;
}
}
}
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[1])) {
continue;
}
for ($i = 0; $i < $_cache_id_parts_count; $i++) {
if ($_parts[$i] != $_cache_id_parts[$i]) continue 2;
} else {
if ($_time - @filemtime($_file) < $exp_time) {
continue;
}
}
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[1])) {
continue;
}
} else {
if ($_time - @filemtime($_file) < $exp_time) {
continue;
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
}
$_count += @unlink((string) $_file) ? 1 : 0;
}
}
return $_count;
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
clearstatcache(true, $cached->lock_id);
} else {
clearstatcache();
}
$t = @filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
}
/**
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = true;
touch($cached->lock_id);
}
/**
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = false;
@unlink($cached->lock_id);
}
return $_count;
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
clearstatcache(true, $cached->lock_id);
} else {
clearstatcache();
}
$t = @filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
}
/**
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = true;
touch($cached->lock_id);
}
/**
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return bool|void
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = false;
@unlink($cached->lock_id);
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Append
*
* Compiles the {append} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Append Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
@ -23,6 +22,7 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -47,5 +47,4 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
// call compile assign
return parent::compile($_new_attr, $compiler, $_params);
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Assign
*
* Compiles the {assign} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Assign Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
@ -23,6 +22,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -83,5 +83,4 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
return $output;
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Compile Block
*
* Compiles the {block}{/block} tags
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Block Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
@ -68,8 +67,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
/**
* Compiles code for the {block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return boolean true
*/
public function compile($args, $compiler)
@ -78,13 +78,18 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
$_name = trim($_attr['name'], "\"'");
// existing child must override parent settings
if (isset($compiler->template->block_data[$_name]) && $compiler->template->block_data[$_name]['mode'] == 'replace') {
$_attr['append'] = false;
$_attr['prepend'] = false;
}
// check if we process an inheritance child template
if ($compiler->inheritance_child) {
array_unshift(self::$nested_block_names, $_name);
$this->template->block_data[$_name]['source'] = '';
// build {block} for child block
self::$block_data[$_name]['source'] =
"{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}'" .
"{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" .
" uid='{$compiler->template->source->uid}' line={$compiler->lex->line}";
if ($_attr['nocache']) {
self::$block_data[$_name]['source'] .= ' nocache';
@ -114,12 +119,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
return true;
}
/**
* Compile saved child block source
*
* @param object $compiler compiler object
* @param string $_name optional name of child block
* @param object $compiler compiler object
* @param string $_name optional name of child block
*
* @return string compiled code of child block
*/
static function compileChildBlock($compiler, $_name = null)
@ -156,7 +161,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
// flag that child is already compile by {$smarty.block.child} inclusion
$compiler->template->block_data[$_name]['compiled'] = true;
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
if ($compiler->smarty->debugging) {
Smarty_Internal_Debug::ignore($_tpl);
}
@ -206,9 +211,10 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
/**
* Compile $smarty.block.parent
*
* @param object $compiler compiler object
* @param string $_name optional name of child block
* @return string compiled code of schild block
* @param object $compiler compiler object
* @param string $_name optional name of child block
*
* @return string compiled code of child block
*/
static function compileParentBlock($compiler, $_name = null)
{
@ -237,21 +243,20 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
/**
* Process block source
*
* @param string $source source text
* @return ''
* @param $compiler
* @param string $source source text
*
*/
static function blockSource($compiler, $source)
{
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= $source;
}
}
/**
* Smarty Internal Plugin Compile BlockClose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
@ -259,8 +264,9 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -276,7 +282,6 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
if ($compiler->inheritance_child) {
$name1 = Smarty_Internal_Compile_Block::$nested_block_names[0];
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= "{$compiler->smarty->left_delimiter}/private_child_block{$compiler->smarty->right_delimiter}";
$level = count(Smarty_Internal_Compile_Block::$nested_block_names);
array_shift(Smarty_Internal_Compile_Block::$nested_block_names);
if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
$name2 = Smarty_Internal_Compile_Block::$nested_block_names[0];
@ -349,7 +354,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
/**
* Smarty Internal Plugin Compile Child Block Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_CompileBase
@ -361,14 +366,14 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
* @var array
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name', 'file', 'uid', 'line');
public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource');
/**
* Compiles code for the {private_child_block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return boolean true
*/
public function compile($args, $compiler)
@ -376,6 +381,16 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// update template with original template resource of {block}
if (trim($_attr['type'], "'") == 'file') {
$compiler->template->template_resource = 'file:' . realpath(trim($_attr['file'], "'"));
} else {
$compiler->template->template_resource = trim($_attr['resource'], "'");
}
// source object
unset ($compiler->template->source);
$exists = $compiler->template->source->exists;
// must merge includes
if ($_attr['nocache'] == true) {
$compiler->tag_nocache = true;
@ -397,18 +412,18 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
/**
* Smarty Internal Plugin Compile Child Block Close Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Child_Blockclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/private_child_block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return boolean true
*/
public function compile($args, $compiler)

View file

@ -1,17 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Break
*
* Compiles the {break} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Break Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
@ -37,6 +37,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -61,9 +62,9 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
$stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
$level_count--;
$level_count --;
}
$stack_count--;
$stack_count --;
}
if ($level_count != 0) {
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
@ -71,5 +72,4 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
return "<?php break {$_levels}?>";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Function_Call
*
* Compiles the calls of user defined tags defined by {function}
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Function_Call Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
@ -42,9 +41,9 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
/**
* Compiles the calls of user defined tags defined by {function}
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -53,7 +52,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
}
$_name = $_attr['name'];
@ -96,7 +95,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
}
}
}
//varibale name?
//variable name?
if (!(strpos($_name, '$') === false)) {
$call_cache = $_name;
$call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
@ -125,5 +124,4 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
return $_output;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Capture
*
* Compiles the {capture} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Capture Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
@ -37,6 +36,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -55,13 +55,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
return $_output;
}
}
/**
* Smarty Internal Plugin Compile Captureclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
@ -71,6 +70,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -93,5 +93,4 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
return $_output;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Config Load
*
* Compiles the {config load} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Config Load Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
@ -30,7 +29,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file','section');
public $shorttag_order = array('file', 'section');
/**
* Attribute definition: Overwrites base class.
*
@ -44,11 +43,12 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
{
static $_is_legal_scope = array('local' => true,'parent' => true,'root' => true,'global' => true);
static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -56,7 +56,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
}
// save posible attributes
// save possible attributes
$conf_file = $_attr['file'];
if (isset($_attr['section'])) {
$section = $_attr['section'];
@ -69,9 +69,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
$_attr['scope'] = trim($_attr['scope'], "'\"");
if (isset($_is_legal_scope[$_attr['scope']])) {
$scope = $_attr['scope'];
} else {
} else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
}
}
}
// create config object
$_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
@ -79,5 +79,4 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
return $_output;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Continue
*
* Compiles the {continue} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Continue Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
@ -38,6 +37,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -62,9 +62,9 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
$stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
$level_count--;
$level_count --;
}
$stack_count--;
$stack_count --;
}
if ($level_count != 0) {
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
@ -72,5 +72,4 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
return "<?php continue {$_levels}?>";
}
}

View file

@ -1,19 +1,18 @@
<?php
/**
* Smarty Internal Plugin Compile Debug
*
* Compiles the {debug} tag.
* It opens a window the the Smarty Debugging Console.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Debug Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
@ -23,6 +22,7 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -38,5 +38,4 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
return $_output;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Eval
*
* Compiles the {eval} tag.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Eval Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
@ -37,13 +36,14 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('var','assign');
public $shorttag_order = array('var', 'assign');
/**
* Compiles code for the {eval} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -53,12 +53,12 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
}
// create template object
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.".$_attr['var'].", \$_smarty_tpl->smarty, \$_smarty_tpl);";
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
//was there an assign attribute?
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
@ -68,5 +68,4 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
return "<?php $_output ?>";
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Compile extend
*
* Compiles the {extends} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile extend Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
@ -36,8 +35,9 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
/**
* Compiles code for the {extends} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -52,6 +52,9 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
}
$name = $_attr['file'];
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
eval("\$tpl_name = $name;");
// create template object
@ -59,7 +62,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
// check for recursion
$uid = $_template->source->uid;
if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $this->lex->line - 1);
$compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
}
$compiler->extends_uid[$uid] = true;
if (empty($_template->source->components)) {
@ -69,7 +72,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
array_unshift($compiler->sources, $source);
$uid = $source->uid;
if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"{$sorce->filepath}\"", $this->lex->line - 1);
$compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
}
$compiler->extends_uid[$uid] = true;
}

View file

@ -1,39 +1,35 @@
<?php
/**
* Smarty Internal Plugin Compile For
*
* Compiles the {for} {forelse} {/for} tags
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile For Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {for} tag
*
* Smarty 3 does implement two different sytaxes:
*
* Smarty 3 does implement two different syntax's:
* - {for $var in $array}
* For looping over arrays or iterators
*
* - {for $x=0; $x<$y; $x++}
* For general loops
*
* The parser is gereration different sets of attribute by which this compiler can
* determin which syntax is used.
* The parser is generating different sets of attribute by which this compiler can
* determine which syntax is used.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -81,13 +77,12 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
// return compiled code
return $output;
}
}
/**
* Smarty Internal Plugin Compile Forelse Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
@ -98,25 +93,25 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
$this->openTag($compiler, 'forelse', array('forelse', $nocache));
return "<?php }} else { ?>";
}
}
/**
* Smarty Internal Plugin Compile Forclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
@ -127,6 +122,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -146,5 +142,4 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
return "<?php }} ?>";
}
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Foreach
*
* Compiles the {foreach} {foreachelse} {/foreach} tags
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Foreach Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
@ -37,7 +36,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('from','item','key','name');
public $shorttag_order = array('from', 'item', 'key', 'name');
/**
* Compiles code for the {foreach} tag
@ -45,11 +44,11 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
$tpl = $compiler->template;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -80,12 +79,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
$ItemVarName = '$' . trim($item, '\'"') . '@';
// evaluates which Smarty variables and properties have to be computed
if ($has_name) {
$usesSmartyFirst = strpos($tpl->source->content, $SmartyVarName . 'first') !== false;
$usesSmartyLast = strpos($tpl->source->content, $SmartyVarName . 'last') !== false;
$usesSmartyIndex = strpos($tpl->source->content, $SmartyVarName . 'index') !== false;
$usesSmartyIteration = strpos($tpl->source->content, $SmartyVarName . 'iteration') !== false;
$usesSmartyShow = strpos($tpl->source->content, $SmartyVarName . 'show') !== false;
$usesSmartyTotal = strpos($tpl->source->content, $SmartyVarName . 'total') !== false;
$usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false;
$usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false;
$usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false;
$usesSmartyIteration = strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false;
$usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false;
$usesSmartyTotal = strpos($compiler->lex->data, $SmartyVarName . 'total') !== false;
} else {
$usesSmartyFirst = false;
$usesSmartyLast = false;
@ -93,12 +92,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
$usesSmartyShow = false;
}
$usesPropFirst = $usesSmartyFirst || strpos($tpl->source->content, $ItemVarName . 'first') !== false;
$usesPropLast = $usesSmartyLast || strpos($tpl->source->content, $ItemVarName . 'last') !== false;
$usesPropIndex = $usesPropFirst || strpos($tpl->source->content, $ItemVarName . 'index') !== false;
$usesPropIteration = $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'iteration') !== false;
$usesPropShow = strpos($tpl->source->content, $ItemVarName . 'show') !== false;
$usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'total') !== false;
$usesPropFirst = $usesSmartyFirst || strpos($compiler->lex->data, $ItemVarName . 'first') !== false;
$usesPropLast = $usesSmartyLast || strpos($compiler->lex->data, $ItemVarName . 'last') !== false;
$usesPropIndex = $usesPropFirst || strpos($compiler->lex->data, $ItemVarName . 'index') !== false;
$usesPropIteration = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false;
$usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false;
$usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false;
// generate output code
$output = "<?php ";
$output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n";
@ -171,7 +170,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
/**
* Smarty Internal Plugin Compile Foreachelse Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
@ -182,6 +181,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -194,13 +194,12 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
}
}
/**
* Smarty Internal Plugin Compile Foreachclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
@ -211,6 +210,7 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -226,5 +226,4 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
return "<?php } ?>";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Function
*
* Compiles the {function} {/function} tags
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Function Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
@ -42,9 +41,10 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return boolean true
*/
public function compile($args, $compiler, $parameter)
@ -57,16 +57,19 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
}
unset($_attr['nocache']);
$save = array($_attr, $compiler->parser->current_buffer,
$compiler->template->has_nocache_code, $compiler->template->required_plugins);
$compiler->template->has_nocache_code, $compiler->template->required_plugins);
$this->openTag($compiler, 'function', $save);
$_name = trim($_attr['name'], "'\"");
unset($_attr['name']);
// set flag that we are compiling a template function
$compiler->compiles_template_function = true;
$compiler->template->properties['function'][$_name]['parameter'] = array();
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
foreach ($_attr as $_key => $_data) {
eval ('$tmp='.$_data.';');
eval ('$tmp=' . $_data . ';');
$compiler->template->properties['function'][$_name]['parameter'][$_key] = $tmp;
}
$compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter'];
@ -79,7 +82,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
}
// Init temporay context
// Init temporary context
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
@ -88,13 +91,12 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
$compiler->template->properties['function'][$_name]['compiled'] = '';
return true;
}
}
/**
* Smarty Internal Plugin Compile Functionclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
@ -102,9 +104,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/function} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return boolean true
*/
public function compile($args, $compiler, $parameter)
@ -132,15 +135,15 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
}
$plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n";
}
// remove last line break from function definition
$last = count($compiler->parser->current_buffer->subtrees) - 1;
if ($compiler->parser->current_buffer->subtrees[$last] instanceof _smarty_linebreak) {
unset($compiler->parser->current_buffer->subtrees[$last]);
}
// remove last line break from function definition
$last = count($compiler->parser->current_buffer->subtrees) - 1;
if ($compiler->parser->current_buffer->subtrees[$last] instanceof _smarty_linebreak) {
unset($compiler->parser->current_buffer->subtrees[$last]);
}
// if caching save template function for possible nocache call
if ($compiler->template->caching) {
$compiler->template->properties['function'][$_name]['compiled'] .= $plugins_string
. $compiler->parser->current_buffer->to_smarty_php();
. $compiler->parser->current_buffer->to_smarty_php();
$compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code;
$compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions;
@ -161,5 +164,4 @@ foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl-
return $output;
}
}

View file

@ -1,30 +1,30 @@
<?php
/**
* Smarty Internal Plugin Compile If
*
* Compiles the {if} {else} {elseif} {/if} tags
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
* Smarty Internal Plugin Compile If
* Compiles the {if} {else} {elseif} {/if} tags
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile If Class
*
* @package Smarty
* @subpackage Compiler
*/
* Smarty Internal Plugin Compile If Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
* Compiles code for the {if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// check and get attributes
@ -33,7 +33,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
// must whole block be nocache ?
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!array_key_exists("if condition",$parameter)) {
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno);
}
@ -50,11 +50,11 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$_nocache = '';
}
if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value'].") {?>";
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
} else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value'].") {?>";
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
}
return $_output;
@ -62,25 +62,25 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
return "<?php if ({$parameter['if condition']}) {?>";
}
}
}
/**
* Smarty Internal Plugin Compile Else Class
*
* @package Smarty
* @subpackage Compiler
*/
* Smarty Internal Plugin Compile Else Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {else} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
* Compiles code for the {else} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
@ -88,25 +88,25 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
return "<?php } else { ?>";
}
}
/**
* Smarty Internal Plugin Compile ElseIf Class
*
* @package Smarty
* @subpackage Compiler
*/
* Smarty Internal Plugin Compile ElseIf Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {elseif} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
* Compiles code for the {elseif} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// check and get attributes
@ -114,7 +114,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!array_key_exists("if condition",$parameter)) {
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno);
}
@ -154,8 +154,9 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
}
} else {
$tmp = '';
foreach ($compiler->prefix_code as $code)
$tmp .= $code;
foreach ($compiler->prefix_code as $code) {
$tmp .= $code;
}
$compiler->prefix_code = array();
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) {
@ -173,25 +174,25 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
}
}
}
}
/**
* Smarty Internal Plugin Compile Ifclose Class
*
* @package Smarty
* @subpackage Compiler
*/
* Smarty Internal Plugin Compile Ifclose Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
* Compiles code for the {/if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// must endblock be nocache?
@ -200,11 +201,10 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
}
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
$tmp = '';
for ($i = 0; $i < $nesting; $i++) {
for ($i = 0; $i < $nesting; $i ++) {
$tmp .= '}';
}
return "<?php {$tmp}?>";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Include
*
* Compiles the {include} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Include Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
@ -53,20 +52,21 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save posible attributes
// save possible attributes
$include_file = $_attr['file'];
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
}
@ -81,15 +81,15 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_parent_scope = Smarty::SCOPE_GLOBAL;
}
}
$_caching = Smarty::CACHING_OFF;
// flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes ||($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes)|| $_attr['inline'] === true) && !$compiler->template->source->recompiled;
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled;
// set default when in nocache mode
// if ($compiler->template->caching && ($compiler->nocache || $compiler->tag_nocache || $compiler->forceNocache == 2)) {
if ($compiler->template->caching && ((!$compiler->inheritance && !$compiler->nocache && !$compiler->tag_nocache) || ($compiler->inheritance && ($compiler->nocache ||$compiler->tag_nocache)))) {
// if ($compiler->template->caching && ($compiler->nocache || $compiler->tag_nocache || $compiler->forceNocache == 2)) {
if ($compiler->template->caching && ((!$compiler->inheritance && !$compiler->nocache && !$compiler->tag_nocache) || ($compiler->inheritance && ($compiler->nocache || $compiler->tag_nocache)))) {
$_caching = self::CACHING_NOCACHE_CODE;
}
/*
@ -122,9 +122,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($_attr['nocache'] === true) {
$compiler->tag_nocache = true;
if ($merge_compiled_includes) {
$_caching = self::CACHING_NOCACHE_CODE;
$_caching = self::CACHING_NOCACHE_CODE;
} else {
$_caching = Smarty::CACHING_OFF;
$_caching = Smarty::CACHING_OFF;
}
}
@ -164,12 +164,15 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$uid = sha1($_compile_id);
$tpl_name = null;
$nocache = false;
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
eval("\$tpl_name = $include_file;");
if (!isset($compiler->smarty->merged_templates_func[$tpl_name][$uid]) || $compiler->inheritance) {
if (!isset($compiler->smarty->merged_templates_func[$tpl_name][$uid])) {
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id);
// save unique function name
$compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true));
$compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
// use current nocache hash for inlined code
$compiler->smarty->merged_templates_func[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
if ($compiler->template->caching && $_caching == self::CACHING_NOCACHE_CODE) {
@ -183,7 +186,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->mustCompile = true;
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
// get compiled code
$compiled_code = $tpl->compiler->compileTemplate($tpl, $nocache);
// release compiler object to free memory
@ -214,17 +216,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if (!empty($_attr)) {
if ($_parent_scope == Smarty::SCOPE_LOCAL) {
// create variables
$nccode = '';
foreach ($_attr as $key => $value) {
$_pairs[] = "'$key'=>$value";
$nccode .= "\$_smarty_tpl->tpl_vars['$key'] = new Smarty_variable($value);\n";
}
$_vars = 'array(' . join(',', $_pairs) . ')';
$_has_vars = true;
} else {
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno);
}
} else {
$_vars = 'array()';
$_has_vars = false;
}
if ($has_compiled_template) {
// never call inline templates in nocache mode
@ -232,6 +234,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_hash = $compiler->smarty->merged_templates_func[$tpl_name][$uid]['nocache_hash'];
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
$_output .= "\$_tpl_stack[] = \$_smarty_tpl;\n";
if (!empty($nccode) && $_caching == 9999 && $_smarty_tpl->caching) {
$compiler->suppressNocacheProcessing = false;
$_output .= substr($compiler->processNocacheCode('<?php ' .$nccode . "?>\n", true), 6, -3);
$compiler->suppressNocacheProcessing = true;
}
$_output .= " \$_smarty_tpl = \$_smarty_tpl->setupInlineSubTemplate($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, '$_hash');\n";
if (isset($_assign)) {
$_output .= 'ob_start(); ';

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Include PHP
*
* Compiles the {include_php} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
@ -44,6 +43,8 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @throws SmartyException
* @return string compiled code
*/
public function compile($args, $compiler)
@ -54,8 +55,9 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$_output = '<?php ';
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
$_filepath = false;
eval('$_file = ' . $_attr['file'] . ';');
@ -71,7 +73,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
foreach ((array) $_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . DS;
if (file_exists($_script_dir . $_file)) {
$_filepath = $_script_dir . $_file;
$_filepath = $_script_dir . $_file;
break;
}
}
@ -102,5 +104,4 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
return "<?php include{$_once} ('{$_filepath}');?>\n";
}
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Compile Insert
*
* Compiles the {insert} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
@ -45,6 +44,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -59,12 +59,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_script = null;
$_output = '<?php ';
// save posible attributes
// save possible attributes
eval('$_name = ' . $_attr['name'] . ';');
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
// create variable to make shure that the compiler knows about its nocache status
// create variable to make sure that the compiler knows about its nocache status
$compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true);
}
if (isset($_attr['script'])) {
@ -137,5 +137,4 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
return $_output;
}
}

View file

@ -1,28 +1,28 @@
<?php
/**
* Smarty Internal Plugin Compile Ldelim
*
* Compiles the {ldelim} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Ldelim Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {ldelim} tag
*
* This tag does output the left delimiter
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -36,5 +36,4 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
return $compiler->smarty->left_delimiter;
}
}

View file

@ -1,29 +1,28 @@
<?php
/**
* Smarty Internal Plugin Compile Nocache
*
* Compiles the {nocache} {/nocache} tags.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Nocache Classv
* Smarty Internal Plugin Compile Nocache Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {nocache} tag
*
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return bool
*/
public function compile($args, $compiler)
@ -32,47 +31,40 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
}
if ($compiler->template->caching) {
// enter nocache mode
$this->openTag($compiler, 'nocache', $compiler->nocache);
$compiler->nocache = true;
}
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
/**
* Smarty Internal Plugin Compile Nocacheclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/nocache} tag
*
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return bool
*/
public function compile($args, $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
if ($compiler->template->caching) {
// restore old nocache mode
$compiler->nocache = $this->closeTag($compiler, 'nocache');
}
// leave nocache mode
$compiler->nocache = false;
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Block Plugin
*
* Compiles code for the execution of block plugin
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Block Plugin Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase
@ -33,18 +32,19 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $function)
{
if (!isset($tag[5]) || substr($tag, -5) != 'close') {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->tag_nocache = true;
}
unset($_attr['nocache']);
unset($_attr['nocache']);
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
@ -67,20 +67,19 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$compiler->tag_nocache = true;
}
// closing tag of block plugin, restore nocache
list($_params, $compiler->nocache) = $this->closeTag($compiler, substr($tag, 0, -5));
list($_params, $compiler->nocache) = $this->closeTag($compiler, substr($tag, 0, - 5));
// This tag does create output
$compiler->has_output = true;
// compile code
if (!isset($parameter['modifier_list'])) {
$mod_pre = $mod_post ='';
$mod_pre = $mod_post = '';
} else {
$mod_pre = ' ob_start(); ';
$mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
}
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
}
return $output . "\n";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Function Plugin
*
* Compiles code for the execution of function plugin
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Function Plugin Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase
@ -40,6 +39,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $function)
@ -68,5 +68,4 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
return $output;
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Compile Modifier
*
* Compiles code for modifier execution
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Modifier Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase
@ -24,6 +23,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -136,5 +136,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
return $output;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Object Block Function
*
* Compiles code for registered objects as block function
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Object Block Function Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase
@ -33,11 +32,12 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
* @param array $parameter array with compilation parameter
* @param string $tag name of block object
* @param string $method name of method to call
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $method)
{
if (!isset($tag[5]) || substr($tag, -5) != 'close') {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -62,7 +62,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
// compile code
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else {
$base_tag = substr($tag, 0, -5);
$base_tag = substr($tag, 0, - 5);
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
@ -83,5 +83,4 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
return $output . "\n";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Object Funtion
*
* Smarty Internal Plugin Compile Object Function
* Compiles code for registered objects as function
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Object Function Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase
@ -28,11 +27,12 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $method)
@ -81,5 +81,4 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
return $output;
}
}

View file

@ -1,45 +1,46 @@
<?php
/**
* Smarty Internal Plugin Compile Print Expression
*
* Compiles any tag which will output an expression or variable
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
* Smarty Internal Plugin Compile Print Expression
* Compiles any tag which will output an expression or variable
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Print Expression Class
*
* @package Smarty
* @subpackage Compiler
*/
* Smarty Internal Plugin Compile Print Expression Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('assign');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'nofilter');
/**
* Compiles code for gererting output from any expression
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
* Compiles code for generating output from any expression
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @throws SmartyException
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
// check and get attributes
@ -48,12 +49,6 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if ($_attr['nocache'] === true) {
$compiler->tag_nocache = true;
}
// filter handling
if ($_attr['nofilter'] === true) {
$_filter = 'false';
} else {
$_filter = 'true';
}
if (isset($_attr['assign'])) {
// assign output to variable
$output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
@ -71,13 +66,13 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$modifierlist = array();
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, $mod_array);
for ($i = 0, $count = count($mod_array[0]);$i < $count;$i++) {
for ($i = 0, $count = count($mod_array[0]); $i < $count; $i ++) {
if ($mod_array[0][$i] != ':') {
$modifierlist[$key][] = $mod_array[0][$i];
}
}
}
$compiler->default_modifier_list = $modifierlist;
$compiler->default_modifier_list = $modifierlist;
}
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output));
}
@ -85,7 +80,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if ($compiler->template->smarty->escape_html) {
$output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
}
// loop over registerd filters
// loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) {
if (!is_array($function)) {
@ -128,11 +123,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
/**
* @param object $compiler compiler object
* @param string $name name of variable filter
* @param type $output embedded output
* @return string
*/
* @param object $compiler compiler object
* @param string $name name of variable filter
* @param string $output embedded output
*
* @return string
*/
private function compile_output_filter($compiler, $name, $output)
{
$plugin_name = "smarty_variablefilter_{$name}";
@ -152,5 +148,4 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
return "{$plugin_name}({$output},\$_smarty_tpl)";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Registered Block
*
* Compiles code for the execution of a registered block function
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Registered Block Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase
@ -32,30 +31,31 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block function
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag)
{
if (!isset($tag[5]) || substr($tag,-5) != 'close') {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache']) {
$compiler->tag_nocache = true;
}
unset($_attr['nocache']);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
} else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
}
unset($_attr['nocache']);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
} else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
}
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) {
$_value = str_replace("'","^#^",$_value);
} elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) {
$_value = str_replace("'", "^#^", $_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else {
$_paramsArray[] = "'$_key'=>$_value";
@ -80,33 +80,32 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
$base_tag = substr($tag, 0, -5);
$base_tag = substr($tag, 0, - 5);
// closing tag of block plugin, restore nocache
list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag);
// This tag does create output
$compiler->has_output = true;
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
} else {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
}
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
} else {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
}
// compile code
if (!isset($parameter['modifier_list'])) {
$mod_pre = $mod_post ='';
$mod_pre = $mod_post = '';
} else {
$mod_pre = ' ob_start(); ';
$mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
}
if (!is_array($function)) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} elseif (is_object($function[0])) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} else {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
}
}
return $output . "\n";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Registered Function
*
* Compiles code for the execution of a registered function
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Registered Function Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase
@ -32,6 +31,7 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag)
@ -44,20 +44,20 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
$compiler->tag_nocache = true;
}
unset($_attr['nocache']);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
} else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
}
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
} else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
}
// not cachable?
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) {
$_value = str_replace("'","^#^",$_value);
} elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) {
$_value = str_replace("'", "^#^", $_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else {
$_paramsArray[] = "'$_key'=>$_value";
@ -76,5 +76,4 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
return $output;
}
}

View file

@ -1,32 +1,33 @@
<?php
/**
* Smarty Internal Plugin Compile Special Smarty Variable
*
* Compiles the special $smarty variables
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile special Smarty Variable Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the speical $smarty variables
* Compiles code for the special $smarty variables
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param $parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
$_index = preg_split("/\]\[/",substr($parameter, 1, strlen($parameter)-2));
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$compiled_ref = ' ';
$variable = trim($_index[0], "'");
switch ($variable) {
@ -56,7 +57,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
$compiled_ref = '$_'.strtoupper($variable);
$compiled_ref = '$_' . strtoupper($variable);
break;
case 'template':
@ -110,5 +111,4 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return $compiled_ref;
}
}

View file

@ -1,28 +1,28 @@
<?php
/**
* Smarty Internal Plugin Compile Rdelim
*
* Compiles the {rdelim} tag
* @package Smarty
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Rdelim Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {rdelim} tag
*
* This tag does output the right delimiter.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -36,5 +36,4 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
return $compiler->smarty->right_delimiter;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Section
*
* Compiles the {section} {sectionelse} {/section} tags
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Section Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
@ -44,6 +43,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -69,10 +69,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
break;
case 'show':
if (is_bool($attr_value))
if (is_bool($attr_value)) {
$show_attr_value = $attr_value ? 'true' : 'false';
else
} else {
$show_attr_value = "(bool) $attr_value";
}
$output .= "{$section_props}['show'] = $show_attr_value;\n";
break;
@ -91,23 +92,27 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
}
}
if (!isset($_attr['show']))
if (!isset($_attr['show'])) {
$output .= "{$section_props}['show'] = true;\n";
}
if (!isset($_attr['loop']))
if (!isset($_attr['loop'])) {
$output .= "{$section_props}['loop'] = 1;\n";
}
if (!isset($_attr['max']))
if (!isset($_attr['max'])) {
$output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
else
} else {
$output .= "if ({$section_props}['max'] < 0)\n" . " {$section_props}['max'] = {$section_props}['loop'];\n";
}
if (!isset($_attr['step']))
if (!isset($_attr['step'])) {
$output .= "{$section_props}['step'] = 1;\n";
}
if (!isset($_attr['start']))
if (!isset($_attr['start'])) {
$output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
else {
} else {
$output .= "if ({$section_props}['start'] < 0)\n" . " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
}
@ -134,13 +139,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
return $output;
}
}
/**
* Smarty Internal Plugin Compile Sectionelse Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
@ -150,6 +154,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -162,13 +167,12 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
return "<?php endfor; else: ?>";
}
}
/**
* Smarty Internal Plugin Compile Sectionclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
@ -178,6 +182,7 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -198,5 +203,4 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
return "<?php endfor; endif; ?>";
}
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile Setfilter
*
* Compiles code for setfilter tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Setfilter Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
@ -23,6 +22,7 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -34,24 +34,23 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
return true;
}
}
/**
* Smarty Internal Plugin Compile Setfilterclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/setfilter} tag
*
* This tag does not generate compiled output. It resets variable filter.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -68,5 +67,4 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
return true;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Compile While
*
* Compiles the {while} tag
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile While Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
@ -23,6 +22,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
@ -31,7 +31,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache);
if (!array_key_exists("if condition",$parameter)) {
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno);
}
@ -62,13 +62,12 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
return "<?php while ({$parameter['if condition']}) {?>";
}
}
}
/**
* Smarty Internal Plugin Compile Whileclose Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
@ -78,6 +77,7 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
@ -90,5 +90,4 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
return "<?php }?>";
}
}

View file

@ -2,15 +2,15 @@
/**
* Smarty Internal Plugin CompileBase
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* This class does extend all internal compile plugins
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
abstract class Smarty_Internal_CompileBase
@ -43,7 +43,6 @@ abstract class Smarty_Internal_CompileBase
/**
* This function checks if the attributes passed are valid
*
* The attributes passed for the tag to compile are checked against the list of required and
* optional attributes. Required attributes must be present. Optional attributes are check against
* the corresponding list. The keyword '_any' specifies that any attribute will be accepted
@ -51,6 +50,7 @@ abstract class Smarty_Internal_CompileBase
*
* @param object $compiler compiler object
* @param array $attributes attributes applied to the tag
*
* @return array of mapped attributes for further processing
*/
public function getAttributes($compiler, $attributes)
@ -105,7 +105,7 @@ abstract class Smarty_Internal_CompileBase
$compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno);
}
}
// check for unallowed attributes
// check for not allowed attributes
if ($this->optional_attributes != array('_any')) {
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
foreach ($_indexed_attr as $key => $dummy) {
@ -126,7 +126,6 @@ abstract class Smarty_Internal_CompileBase
/**
* Push opening tag name on stack
*
* Optionally additional data can be saved on stack
*
* @param object $compiler compiler object
@ -140,11 +139,11 @@ abstract class Smarty_Internal_CompileBase
/**
* Pop closing tag
*
* Raise an error if this stack-top doesn't match with expected opening tags
*
* @param object $compiler compiler object
* @param array|string $expectedTag the expected opening tag names
*
* @return mixed any type the opening tag's name or saved data
*/
public function closeTag($compiler, $expectedTag)
@ -172,5 +171,4 @@ abstract class Smarty_Internal_CompileBase
return;
}
}

View file

@ -2,27 +2,23 @@
/**
* Smarty Internal Plugin Config
*
* @package Smarty
* @package Smarty
* @subpackage Config
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Config
*
* Main class for config variables
*
* @package Smarty
* @package Smarty
* @subpackage Config
*
* @property Smarty_Config_Source $source
* @property Smarty_Config_Compiled $compiled
* @ignore
*/
class Smarty_Internal_Config
{
/**
* Samrty instance
* Smarty instance
*
* @var Smarty object
*/
@ -35,6 +31,7 @@ class Smarty_Internal_Config
public $data = null;
/**
* Config resource
*
* @var string
*/
public $config_resource = null;
@ -58,6 +55,7 @@ class Smarty_Internal_Config
public $compiled_timestamp = null;
/**
* flag if compiled config file is invalid and must be (re)compiled
*
* @var bool
*/
public $mustCompile = null;
@ -90,8 +88,8 @@ class Smarty_Internal_Config
public function getCompiledFilepath()
{
return $this->compiled_filepath === null ?
($this->compiled_filepath = $this->buildCompiledFilepath()) :
$this->compiled_filepath;
($this->compiled_filepath = $this->buildCompiledFilepath()) :
$this->compiled_filepath;
}
/**
@ -103,14 +101,14 @@ class Smarty_Internal_Config
{
$_compile_id = isset($this->smarty->compile_id) ? preg_replace('![^\w\|]+!', '_', $this->smarty->compile_id) : null;
$_flag = (int) $this->smarty->config_read_hidden + (int) $this->smarty->config_booleanize * 2
+ (int) $this->smarty->config_overwrite * 4;
$_filepath = sha1($this->source->filepath . $_flag);
+ (int) $this->smarty->config_overwrite * 4;
$_filepath = sha1(realpath($this->source->filepath) . $_flag);
// if use_sub_dirs, break file into directories
if ($this->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
}
$_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
@ -122,7 +120,7 @@ class Smarty_Internal_Config
}
/**
* Returns the timpestamp of the compiled file
* Returns the timestamp of the compiled file
*
* @return integer the file timestamp
*/
@ -135,7 +133,6 @@ class Smarty_Internal_Config
/**
* Returns if the current config file must be compiled
*
* It does compare the timestamps of config source and the compiled config and checks the force compile configuration
*
* @return boolean true if the file must be compiled
@ -143,13 +140,12 @@ class Smarty_Internal_Config
public function mustCompile()
{
return $this->mustCompile === null ?
$this->mustCompile = ($this->smarty->force_compile || $this->getCompiledTimestamp () === false || $this->smarty->compile_check && $this->getCompiledTimestamp () < $this->source->timestamp):
$this->mustCompile = ($this->smarty->force_compile || $this->getCompiledTimestamp() === false || $this->smarty->compile_check && $this->getCompiledTimestamp() < $this->source->timestamp) :
$this->mustCompile;
}
/**
* Returns the compiled config file
*
* It checks if the config file must be compiled or just read the compiled version
*
* @return string the compiled config file
@ -189,14 +185,15 @@ class Smarty_Internal_Config
// call compiler
try {
$this->compiler_object->compileSource($this);
} catch (Exception $e) {
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && $saved_timestamp) {
touch($this->getCompiledFilepath(), $saved_timestamp);
}
throw $e;
}
// compiling succeded
// compiling succeeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
}
@ -204,8 +201,10 @@ class Smarty_Internal_Config
/**
* load config variables
*
* @param mixed $sections array of section names, single section or null
* @param object $scope global,parent or local
* @param mixed $sections array of section names, single section or null
* @param string $scope global,parent or local
*
* @throws Exception
*/
public function loadConfigVars($sections = null, $scope = 'local')
{
@ -259,8 +258,9 @@ class Smarty_Internal_Config
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException if $property_name is not valid
*/
public function __set($property_name, $value)
@ -279,7 +279,9 @@ class Smarty_Internal_Config
/**
* get Smarty property in template context
*
* @param string $property_name property name
* @param string $property_name property name
*
* @return \Smarty_Config_Source|\Smarty_Template_Compiled
* @throws SmartyException if $property_name is not valid
*/
public function __get($property_name)
@ -301,5 +303,4 @@ class Smarty_Internal_Config
throw new SmartyException("config attribute '$property_name' does not exist.");
}
}

View file

@ -1,19 +1,18 @@
<?php
/**
* Smarty Internal Plugin Config File Compiler
*
* This is the config file compiler class. It calls the lexer and parser to
* perform the compiling.
*
* @package Smarty
* @package Smarty
* @subpackage Config
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Main config file compiler class
*
* @package Smarty
* @package Smarty
* @subpackage Config
*/
class Smarty_Internal_Config_File_Compiler
@ -69,6 +68,7 @@ class Smarty_Internal_Config_File_Compiler
* Method to compile a Smarty template.
*
* @param Smarty_Internal_Config $config config object
*
* @return bool true if compiling succeeded, false if it failed
*/
public function compileSource(Smarty_Internal_Config $config)
@ -84,28 +84,46 @@ class Smarty_Internal_Config_File_Compiler
return true;
}
// init the lexer/parser to compile the config file
$lex = new Smarty_Internal_Configfilelexer($_content, $this->smarty);
$lex = new Smarty_Internal_Configfilelexer($_content, $this);
$parser = new Smarty_Internal_Configfileparser($lex, $this);
if ($this->smarty->_parserdebug) $parser->PrintTrace();
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
} else {
$mbEncoding = null;
}
if ($this->smarty->_parserdebug) {
$parser->PrintTrace();
}
// get tokens from lexer and parse them
while ($lex->yylex()) {
if ($this->smarty->_parserdebug) echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
if ($this->smarty->_parserdebug) {
echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
}
$parser->doParse($lex->token, $lex->value);
}
// finish parsing process
$parser->doParse(0, 0);
if ($mbEncoding) {
mb_internal_encoding($mbEncoding);
}
$config->compiled_config = '<?php $_config_vars = ' . var_export($this->config_data, true) . '; ?>';
}
/**
* display compiler error messages without dying
*
* If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about exspected tokens.
*
* In this case the parser is called to obtain information about expected tokens.
* If parameter $args contains a string this is used as error message
*
* @param string $args individual error message or null
*
* @throws SmartyCompilerException
*/
public function trigger_config_file_error($args = null)
{
@ -117,12 +135,12 @@ class Smarty_Internal_Config_File_Compiler
// $line--;
}
$match = preg_split("/\n/", $this->lex->data);
$error_text = "Syntax error in config file '{$this->config->source->filepath}' on line {$line} '{$match[$line-1]}' ";
$error_text = "Syntax error in config file '{$this->config->source->filepath}' on line {$line} '{$match[$line - 1]}' ";
if (isset($args)) {
// individual error message
$error_text .= $args;
} else {
// exspected token from parser
// expected token from parser
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$token];
if (isset($this->lex->smarty_token_names[$exp_token])) {
@ -138,5 +156,4 @@ class Smarty_Internal_Config_File_Compiler
}
throw new SmartyCompilerException($error_text);
}
}

View file

@ -1,15 +1,16 @@
<?php
/**
* Smarty Internal Plugin Configfilelexer
*
* This is the lexer to break the config file source into tokens
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
* Smarty Internal Plugin Configfilelexer
* This is the lexer to break the config file source into tokens
*
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Configfilelexer
*/
* Smarty Internal Plugin Configfilelexer
*/
class Smarty_Internal_Configfilelexer
{
@ -22,36 +23,39 @@ class Smarty_Internal_Configfilelexer
private $state = 1;
public $yyTraceFILE;
public $yyTracePrompt;
public $state_name = array (1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE');
public $smarty_token_names = array ( // Text for parser error messages
);
function __construct($data, $smarty)
public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE');
public $smarty_token_names = array( // Text for parser error messages
);
function __construct($data, $compiler)
{
// set instance object
self::instance($this);
self::instance($this);
$this->data = $data . "\n"; //now all lines are \n-terminated
$this->counter = 0;
if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
$this->counter += strlen($match[0]);
}
$this->line = 1;
$this->smarty = $smarty;
$this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
$this->compiler = $compiler;
$this->smarty = $compiler->smarty;
}
public static function &instance($new_instance = null)
{
static $instance = null;
if (isset($new_instance) && is_object($new_instance))
if (isset($new_instance) && is_object($new_instance)) {
$instance = $new_instance;
}
return $instance;
}
}
public function PrintTrace()
{
$this->yyTraceFILE = fopen('php://output', 'w');
$this->yyTracePrompt = '<br>';
}
private $_yy_state = 1;
private $_yy_stack = array();
@ -63,77 +67,73 @@ class Smarty_Internal_Configfilelexer
public function yypushstate($state)
{
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state;
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
}
public function yypopstate()
{
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
$this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
$this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
}
public function yybegin($state)
{
$this->_yy_state = $state;
$this->_yy_state = $state;
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
}
}
public function yylex1()
{
$tokenMap = array (
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state START');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state START');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r1_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -142,110 +142,115 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const START = 1;
function yy_r1_1($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
$this->yypushstate(self::COMMENT);
$this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
$this->yypushstate(self::COMMENT);
}
function yy_r1_2($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
$this->yypushstate(self::SECTION);
$this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
$this->yypushstate(self::SECTION);
}
function yy_r1_3($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
$this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
}
function yy_r1_4($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
$this->yypushstate(self::VALUE);
$this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
$this->yypushstate(self::VALUE);
}
function yy_r1_5($yy_subpatterns)
{
return false;
return false;
}
function yy_r1_6($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
}
function yy_r1_7($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_ID;
$this->token = Smarty_Internal_Configfileparser::TPC_ID;
}
function yy_r1_8($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
$this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
}
public function yylex2()
{
$tokenMap = array (
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state VALUE');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state VALUE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r2_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -254,119 +259,125 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const VALUE = 2;
function yy_r2_1($yy_subpatterns)
{
return false;
return false;
}
function yy_r2_2($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
$this->yypopstate();
}
function yy_r2_3($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_INT;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_INT;
$this->yypopstate();
}
function yy_r2_4($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
$this->yypushstate(self::TRIPPLE);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
$this->yypushstate(self::TRIPPLE);
}
function yy_r2_5($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
$this->yypopstate();
}
function yy_r2_6($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
$this->yypopstate();
}
function yy_r2_7($yy_subpatterns)
{
if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
$this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state
} else {
$this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
$this->yypopstate();
}
if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no"))) {
$this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state
} else {
$this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
$this->yypopstate();
}
}
function yy_r2_8($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}
function yy_r2_9($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = "";
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = "";
$this->yypopstate();
}
public function yylex3()
{
$tokenMap = array (
1 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G([^\n]+?(?=[ \t\r]*\n))/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state NAKED_STRING_VALUE');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state NAKED_STRING_VALUE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r3_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -375,67 +386,65 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const NAKED_STRING_VALUE = 3;
function yy_r3_1($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}
public function yylex4()
{
$tokenMap = array (
1 => 0,
2 => 0,
3 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
2 => 0,
3 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state COMMENT');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state COMMENT');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r4_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -444,76 +453,76 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const COMMENT = 4;
function yy_r4_1($yy_subpatterns)
{
return false;
return false;
}
function yy_r4_2($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
}
function yy_r4_3($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->yypopstate();
}
public function yylex5()
{
$tokenMap = array (
1 => 0,
2 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
2 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state SECTION');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state SECTION');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r5_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -522,70 +531,70 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const SECTION = 5;
function yy_r5_1($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_DOT;
$this->token = Smarty_Internal_Configfileparser::TPC_DOT;
}
function yy_r5_2($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
$this->yypopstate();
$this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
$this->yypopstate();
}
public function yylex6()
{
$tokenMap = array (
1 => 0,
2 => 0,
);
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
$tokenMap = array(
1 => 0,
2 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/iS";
do {
if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state TRIPPLE');
' an empty string. Input "' . substr($this->data,
$this->counter, 5) . '... state TRIPPLE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
if ($tokenMap[$this->token]) {
// extract sub-patterns for passing to lex function
$yysubmatches = array_slice($yysubmatches, $this->token + 1,
$tokenMap[$this->token]);
$tokenMap[$this->token]);
} else {
$yysubmatches = array();
}
$this->value = current($yymatches); // token value
$r = $this->{'yy_r6_' . $this->token}($yysubmatches);
if ($r === null) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
@ -594,53 +603,44 @@ class Smarty_Internal_Configfilelexer
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
$this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
// skip this token
continue;
} } else {
}
} else {
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[$this->counter]);
': ' . $this->data[$this->counter]);
}
break;
} while (true);
} // end function
const TRIPPLE = 6;
function yy_r6_1($yy_subpatterns)
{
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
$this->yypopstate();
$this->yypushstate(self::START);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
$this->yypopstate();
$this->yypushstate(self::START);
}
function yy_r6_2($yy_subpatterns)
{
if ($this->mbstring_overload) {
$to = mb_strlen($this->data,'latin1');
} else {
$to = strlen($this->data);
}
preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
$this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
}
if ($this->mbstring_overload) {
$this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
} else {
$this->value = substr($this->data,$this->counter,$to-$this->counter);
}
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
$to = strlen($this->data);
preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
$this->compiler->trigger_template_error("missing or misspelled literal closing tag");
}
$this->value = substr($this->data, $this->counter, $to - $this->counter);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Data
* This file contains the basic classes and methods for template and variable creation
*
* This file contains the basic classes and methodes for template and variable creation
*
* @package Smarty
* @package Smarty
* @subpackage Template
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Base class with template and variable methodes
* Base class with template and variable methods
*
* @package Smarty
* @package Smarty
* @subpackage Template
*/
class Smarty_Internal_Data
@ -45,10 +44,10 @@ class Smarty_Internal_Data
/**
* assigns a Smarty variable
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param boolean $scope the scope the variable will have (local,parent or root)
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function assign($tpl_var, $value = null, $nocache = false)
@ -71,9 +70,10 @@ class Smarty_Internal_Data
/**
* assigns a global Smarty variable
*
* @param string $varname the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param string $varname the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function assignGlobal($varname, $value = null, $nocache = false)
@ -89,19 +89,21 @@ class Smarty_Internal_Data
return $this;
}
/**
* assigns values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param string $tpl_var the template variable name
* @param $value
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function assignByRef($tpl_var, &$value, $nocache = false)
{
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
$this->tpl_vars[$tpl_var]->value = &$value;
$this->tpl_vars[$tpl_var]->value = & $value;
}
return $this;
@ -110,10 +112,11 @@ class Smarty_Internal_Data
/**
* appends values to template variables
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged
* @param boolean $nocache if true any output of this variable will be not cached
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function append($tpl_var, $value = null, $merge = false, $nocache = false)
@ -171,9 +174,10 @@ class Smarty_Internal_Data
/**
* appends values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function appendByRef($tpl_var, &$value, $merge = false)
@ -187,10 +191,10 @@ class Smarty_Internal_Data
}
if ($merge && is_array($value)) {
foreach ($value as $_key => $_val) {
$this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
$this->tpl_vars[$tpl_var]->value[$_key] = & $value[$_key];
}
} else {
$this->tpl_vars[$tpl_var]->value[] = &$value;
$this->tpl_vars[$tpl_var]->value[] = & $value;
}
}
@ -201,8 +205,9 @@ class Smarty_Internal_Data
* Returns a single or all template variables
*
* @param string $varname variable name or null
* @param string $_ptr optional pointer to data object
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents include parent templates?
*
* @return string variable value or or array of variables
*/
public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
@ -218,7 +223,8 @@ class Smarty_Internal_Data
$_result = array();
if ($_ptr === null) {
$_ptr = $this;
} while ($_ptr !== null) {
}
while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
@ -246,7 +252,8 @@ class Smarty_Internal_Data
/**
* clear the given assigned template variable.
*
* @param string|array $tpl_var the template variable(s) to clear
* @param string|array $tpl_var the template variable(s) to clear
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearAssign($tpl_var)
@ -264,6 +271,7 @@ class Smarty_Internal_Data
/**
* clear all the assigned template variables.
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearAllAssign()
@ -276,8 +284,9 @@ class Smarty_Internal_Data
/**
* load a config file, optionally load just selected sections
*
* @param string $config_file filename
* @param mixed $sections array of section names, single section or null
* @param string $config_file filename
* @param mixed $sections array of section names, single section or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function configLoad($config_file, $sections = null)
@ -295,13 +304,16 @@ class Smarty_Internal_Data
* @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data
* @param bool $error_enable
*
* @return object the object of the variable
*/
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
{
if ($_ptr === null) {
$_ptr = $this;
} while ($_ptr !== null) {
}
while ($_ptr !== null) {
if (isset($_ptr->tpl_vars[$variable])) {
// found it, return it
return $_ptr->tpl_vars[$variable];
@ -329,6 +341,8 @@ class Smarty_Internal_Data
* gets a config variable
*
* @param string $variable the name of the config variable
* @param bool $error_enable
*
* @return mixed the value of the config variable
*/
public function getConfigVariable($variable, $error_enable = true)
@ -354,6 +368,8 @@ class Smarty_Internal_Data
* gets a stream variable
*
* @param string $variable the stream of the variable
*
* @throws SmartyException
* @return mixed the value of the stream variable
*/
public function getStreamVariable($variable)
@ -361,7 +377,7 @@ class Smarty_Internal_Data
$_result = '';
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
@ -380,6 +396,8 @@ class Smarty_Internal_Data
* Returns a single or all config variables
*
* @param string $varname variable name or null
* @param bool $search_parents
*
* @return string variable value or or array of variables
*/
public function getConfigVars($varname = null, $search_parents = true)
@ -394,7 +412,7 @@ class Smarty_Internal_Data
} else {
$var_array = array_merge($_ptr->config_vars, $var_array);
}
// not found, try at parent
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
@ -411,7 +429,8 @@ class Smarty_Internal_Data
/**
* Deassigns a single or all config variables
*
* @param string $varname variable name or null
* @param string $varname variable name or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearConfig($varname = null)
@ -424,15 +443,13 @@ class Smarty_Internal_Data
return $this;
}
}
/**
* class for the Smarty data object
*
* The Smarty data object will hold Smarty variables in the current scope
*
* @package Smarty
* @package Smarty
* @subpackage Template
*/
class Smarty_Data extends Smarty_Internal_Data
@ -448,9 +465,11 @@ class Smarty_Data extends Smarty_Internal_Data
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty $smarty global smarty instance
* @param Smarty|Smarty_Internal_Template $smarty global smarty instance
*
* @throws SmartyException
*/
public function __construct ($_parent = null, $smarty = null)
public function __construct($_parent = null, $smarty = null)
{
$this->smarty = $smarty;
if (is_object($_parent)) {
@ -465,15 +484,13 @@ class Smarty_Data extends Smarty_Internal_Data
throw new SmartyException("Wrong type for template variables");
}
}
}
/**
* class for the Smarty variable object
*
* This class defines the Smarty variable object
*
* @package Smarty
* @package Smarty
* @subpackage Template
*/
class Smarty_Variable
@ -520,15 +537,13 @@ class Smarty_Variable
{
return (string) $this->value;
}
}
/**
* class for undefined variable object
*
* This class defines an object for undefined variable handling
*
* @package Smarty
* @package Smarty
* @subpackage Template
*/
class Undefined_Smarty_Variable
@ -537,6 +552,7 @@ class Undefined_Smarty_Variable
* Returns FALSE for 'nocache' and NULL otherwise.
*
* @param string $name
*
* @return bool
*/
public function __get($name)
@ -557,5 +573,4 @@ class Undefined_Smarty_Variable
{
return "";
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Debug
*
* Class to collect data for the Smarty Debugging Consol
*
* @package Smarty
* @package Smarty
* @subpackage Debug
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Debug Class
*
* @package Smarty
* @package Smarty
* @subpackage Debug
*/
class Smarty_Internal_Debug extends Smarty_Internal_Data
@ -187,6 +186,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
* Recursively gets variables from all template/data scopes
*
* @param Smarty_Internal_Template|Smarty_Data $obj object to debug
*
* @return StdClass
*/
public static function get_debug_vars($obj)
@ -218,13 +218,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
}
}
return (object)array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
}
/**
* Return key into $template_data for template
*
* @param object $template template object
*
* @return string key into $template_data
*/
private static function get_key($template)
@ -250,5 +251,4 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
return $key;
}
}
}

View file

@ -1,25 +1,23 @@
<?php
/**
* Smarty Internal Plugin Filter Handler
*
* Smarty filter handler class
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Class for filter processing
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Filter_Handler
{
/**
* Run filters over content
*
* The filters will be lazy loaded if required
* class name format: Smarty_FilterType_FilterName
* plugin filename format: filtertype.filtername.php
@ -28,6 +26,8 @@ class Smarty_Internal_Filter_Handler
* @param string $type the type of filter ('pre','post','output') which shall run
* @param string $content the content which shall be processed by the filters
* @param Smarty_Internal_Template $template template object
*
* @throws SmartyException
* @return string the filtered content
*/
public static function runFilter($type, $content, Smarty_Internal_Template $template)
@ -64,5 +64,4 @@ class Smarty_Internal_Filter_Handler
// return filtered output
return $output;
}
}

View file

@ -2,15 +2,15 @@
/**
* Smarty Internal Plugin Function Call Handler
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* This class does call function defined with the {function} tag
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Function_Call_Handler
@ -39,7 +39,7 @@ class Smarty_Internal_Function_Call_Handler
foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
if ($_nocache) {
$_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
"!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
"!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
$_template->smarty->template_functions[$_name]['called_nocache'] = true;
} else {
$_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
@ -49,5 +49,4 @@ class Smarty_Internal_Function_Call_Handler
}
$_function($_template, $_params);
}
}

View file

@ -2,15 +2,15 @@
/**
* Smarty read include path plugin
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
* @author Monte Ohrt
* @author Monte Ohrt
*/
/**
* Smarty Internal Read Include Path Class
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Get_Include_Path
@ -18,7 +18,8 @@ class Smarty_Internal_Get_Include_Path
/**
* Return full file path from PHP include_path
*
* @param string $filepath filepath
* @param string $filepath filepath
*
* @return string|boolean full filepath or false
*/
public static function getIncludePath($filepath)
@ -42,5 +43,4 @@ class Smarty_Internal_Get_Include_Path
return false;
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Nocache Insert
*
* Compiles the {insert} tag into the cache file
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Nocache_Insert
@ -25,6 +24,7 @@ class Smarty_Internal_Nocache_Insert
* @param Smarty_Internal_Template $_template template object
* @param string $_script script name to load or 'null'
* @param string $_assign optional variable name
*
* @return string compiled code
*/
public static function compile($_function, $_attr, $_template, $_script, $_assign = null)
@ -48,5 +48,4 @@ class Smarty_Internal_Nocache_Insert
return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/";
}
}

View file

@ -1,17 +1,16 @@
<?php
/**
* Smarty Internal Plugin Templateparser Parsetrees
*
* These are classes to build parsetrees in the template parser
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Thue Kristensen
* @author Uwe Tews
* @author Thue Kristensen
* @author Uwe Tews
*/
/**
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -19,28 +18,36 @@ abstract class _smarty_parsetree
{
/**
* Parser object
*
* @var object
*/
public $parser;
/**
* Buffer content
*
* @var mixed
*/
public $data;
/**
* Subtree array
*
* @var array
*/
public $subtrees = array();
/**
* Return buffer
*
* @return string buffer content
*/
abstract public function to_smarty_php();
}
/**
* A complete smarty tag.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -48,6 +55,7 @@ class _smarty_tag extends _smarty_parsetree
{
/**
* Saved block nesting level
*
* @var int
*/
public $saved_block_nesting;
@ -76,7 +84,7 @@ class _smarty_tag extends _smarty_parsetree
}
/**
* Return complied code that loads the evaluated outout of buffer content into a temporary variable
* Return complied code that loads the evaluated output of buffer content into a temporary variable
*
* @return string template code
*/
@ -87,13 +95,12 @@ class _smarty_tag extends _smarty_parsetree
return $var;
}
}
/**
* Code fragment inside a tag.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -120,13 +127,12 @@ class _smarty_code extends _smarty_parsetree
{
return sprintf("(%s)", $this->data);
}
}
/**
* Double quoted string inside a tag.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -198,13 +204,12 @@ class _smarty_doublequoted extends _smarty_parsetree
return $code;
}
}
/**
* Raw chars as part of a double quoted string.
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -231,13 +236,12 @@ class _smarty_dq_content extends _smarty_parsetree
{
return '"' . $this->data . '"';
}
}
/**
* Template element
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -278,18 +282,18 @@ class _smarty_template_buffer extends _smarty_parsetree
public function to_smarty_php()
{
$code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
if ($key + 2 < $cnt) {
if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) {
$key = $key + 1;
continue;
}
if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') {
if (substr($this->subtrees[$key]->data, - 1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, - 1) == '?') {
$key = $key + 2;
continue;
}
}
if (substr($code, -1) == '<') {
if (substr($code, - 1) == '<') {
$subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '?') {
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>?' . substr($subtree, 1);
@ -300,7 +304,7 @@ class _smarty_template_buffer extends _smarty_parsetree
}
continue;
}
if ($this->parser->asp_tags && substr($code, -1) == '%') {
if ($this->parser->asp_tags && substr($code, - 1) == '%') {
$subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '>') {
$code = substr($code, 0, strlen($code) - 1) . '%<?php ?>>' . substr($subtree, 1);
@ -309,7 +313,7 @@ class _smarty_template_buffer extends _smarty_parsetree
}
continue;
}
if (substr($code, -1) == '?') {
if (substr($code, - 1) == '?') {
$subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '>') {
$code = substr($code, 0, strlen($code) - 1) . '?<?php ?>>' . substr($subtree, 1);
@ -323,13 +327,12 @@ class _smarty_template_buffer extends _smarty_parsetree
return $code;
}
}
/**
* template text
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -356,13 +359,12 @@ class _smarty_text extends _smarty_parsetree
{
return $this->data;
}
}
/**
* template linebreaks
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @ignore
*/
@ -389,5 +391,4 @@ class _smarty_linebreak extends _smarty_parsetree
{
return $this->data;
}
}

View file

@ -2,20 +2,18 @@
/**
* Smarty Internal Plugin Resource Eval
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource Eval
*
* Implements the strings as resource for Smarty template
*
* {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}}
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
@ -25,9 +23,10 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name);
$source->timestamp = false;
@ -38,7 +37,9 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
* Load template's source from $resource_name into current template object
*
* @uses decode() to decode base64 and urlencoded template_resources
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
*/
public function getContent(Smarty_Template_Source $source)
@ -50,6 +51,7 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
* decode base64 and urlencode
*
* @param string $string template_resource to decode
*
* @return string decoded template_resource
*/
protected function decode($string)
@ -69,25 +71,26 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
*
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
{
return get_class($this) . '#' .$this->decode($resource_name);
return get_class($this) . '#' . $this->decode($resource_name);
}
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
{
return '';
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Resource Extends
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource Extends
*
* Implements the file system as resource for Smarty which {extend}s a chain of template files templates
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Resource_Extends extends Smarty_Resource
@ -28,8 +27,10 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @throws SmartyException
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
@ -43,7 +44,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
}
$sources[$s->uid] = $s;
$uid .= $s->filepath;
$uid .= realpath($s->filepath);
if ($_template && $_template->smarty->compile_check) {
$exists = $exists && $s->exists;
}
@ -77,6 +78,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
* Load template's source from files into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -100,11 +102,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source)
{
return str_replace(':', '.', basename($source->filepath));
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Resource File
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource File
*
* Implements the file system as resource for Smarty templates
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Resource_File extends Smarty_Resource
@ -24,7 +23,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $this->buildFilepath($source, $_template);
@ -33,7 +32,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
$source->smarty->security_policy->isTrustedResourceDir($source->filepath);
}
$source->uid = sha1($source->filepath);
$source->uid = sha1(realpath($source->filepath));
if ($source->smarty->compile_check && !isset($source->timestamp)) {
$source->timestamp = @filemtime($source->filepath);
$source->exists = !!$source->timestamp;
@ -56,6 +55,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -74,6 +74,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source)
@ -85,5 +86,4 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
return basename($_file);
}
}

View file

@ -2,29 +2,29 @@
/**
* Smarty Internal Plugin Resource PHP
*
* Implements the file system as resource for PHP templates
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
{
/**
* container for short_open_tag directive's value before executing PHP templates
*
* @var string
*/
protected $short_open_tag;
/**
* Create a new PHP Resource
*
*/
public function __construct()
{
$this->short_open_tag = ini_get( 'short_open_tag' );
$this->short_open_tag = ini_get('short_open_tag');
}
/**
@ -32,9 +32,10 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $this->buildFilepath($source, $_template);
@ -55,6 +56,7 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
* populate Source Object with timestamp and exists from Resource
*
* @param Smarty_Template_Source $source source object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Source $source)
@ -67,6 +69,7 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -83,13 +86,12 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
*/
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
{
$_smarty_template = $_template;
if (!$source->smarty->allow_php_templates) {
throw new SmartyException("PHP templates are disabled");
}
@ -106,8 +108,12 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled
extract($_template->getTemplateVars());
// include PHP template with short open tags enabled
ini_set( 'short_open_tag', '1' );
ini_set('short_open_tag', '1');
/** @var Smarty_Internal_Template $_smarty_template
* used in included file
*/
$_smarty_template = $_template;
include($source->filepath);
ini_set( 'short_open_tag', $this->short_open_tag );
ini_set('short_open_tag', $this->short_open_tag);
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Resource Registered
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource Registered
*
* Implements the registered resource for Smarty template
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @deprecated
*/
@ -24,9 +23,10 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $source->type . ':' . $source->name;
$source->uid = sha1($source->filepath);
@ -40,6 +40,7 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
* populate Source Object with timestamp and exists from Resource
*
* @param Smarty_Template_Source $source source object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Source $source)
@ -52,6 +53,7 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
* Get timestamp (epoch) the template source was modified
*
* @param Smarty_Template_Source $source source object
*
* @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
*/
public function getTemplateTimestamp(Smarty_Template_Source $source)
@ -67,6 +69,7 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
* Load template's source by invoking the registered callback into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -85,11 +88,11 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
{
return basename($source->name);
}
}

View file

@ -1,34 +1,33 @@
<?php
/**
* Smarty Internal Plugin Resource Stream
*
* Implements the streams as resource for Smarty template
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
*/
* Smarty Internal Plugin Resource Stream
* Implements the streams as resource for Smarty template
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource Stream
*
* Implements the streams as resource for Smarty template
*
* @link http://php.net/streams
* @package Smarty
* @subpackage TemplateResources
*/
* Smarty Internal Plugin Resource Stream
* Implements the streams as resource for Smarty template
*
* @link http://php.net/streams
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
{
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
if (strpos($source->resource, '://') !== false) {
$source->filepath = $source->resource;
@ -42,12 +41,13 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
}
/**
* Load template's source from stream into current template object
*
* @param Smarty_Template_Source $source source object
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
* Load template's source from stream into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source)
{
$t = '';
@ -66,13 +66,14 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
* @return string unique resource name
*/
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
*
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
{
return get_class($this) . '#' . $resource_name;

View file

@ -2,20 +2,18 @@
/**
* Smarty Internal Plugin Resource String
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource String
*
* Implements the strings as resource for Smarty template
*
* {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Resource_String extends Smarty_Resource
@ -25,9 +23,10 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name);
$source->timestamp = 0;
@ -38,7 +37,9 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
* Load template's source from $resource_name into current template object
*
* @uses decode() to decode base64 and urlencoded template_resources
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
*/
public function getContent(Smarty_Template_Source $source)
@ -50,6 +51,7 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
* decode base64 and urlencode
*
* @param string $string template_resource to decode
*
* @return string decoded template_resource
*/
protected function decode($string)
@ -69,27 +71,27 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
*
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
{
return get_class($this) . '#' .$this->decode($resource_name);
return get_class($this) . '#' . $this->decode($resource_name);
}
/**
* Determine basename for compiled filename
*
* Always returns an empty string.
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
{
return '';
}
}

View file

@ -1,12 +1,11 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Compiler Base
* This file contains the basic classes and methods for compiling Smarty templates with lexer/parser
*
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
@ -17,7 +16,7 @@ include 'smarty_internal_parsetree.php';
/**
* Class SmartyTemplateCompiler
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase
@ -81,9 +80,10 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
}
/**
* Methode to compile a Smarty template
* method to compile a Smarty template
*
* @param mixed $_content template source
*
* @return bool true if compiling succeeded, false if it failed
*/
protected function doCompile($_content)
@ -98,6 +98,13 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
// start state on child templates
$this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
} else {
$mbEncoding = null;
}
if ($this->smarty->_parserdebug) {
$this->parser->PrintTrace();
$this->lex->PrintTrace();
@ -117,6 +124,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
}
// finish parsing process
$this->parser->doParse(0, 0);
if ($mbEncoding) {
mb_internal_encoding($mbEncoding);
}
// check for unclosed tags
if (count($this->_tag_stack) > 0) {
// get stacked info
@ -127,5 +137,4 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
// return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
return $this->parser->retvalue;
}
}

View file

@ -1,20 +1,18 @@
<?php
/**
* Smarty Internal Plugin Template
*
* This file contains the Smarty template engine
*
* @package Smarty
* @package Smarty
* @subpackage Template
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Main class with template data structures and methods
*
* @package Smarty
* @package Smarty
* @subpackage Template
*
* @property Smarty_Template_Source $source
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
@ -23,6 +21,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{
/**
* cache_id
*
* @var string
*/
public $cache_id = null;
@ -33,75 +32,87 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public $compile_id = null;
/**
* caching enabled
*
* @var boolean
*/
public $caching = null;
/**
* cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = null;
/**
* Template resource
*
* @var string
*/
public $template_resource = null;
/**
* flag if compiled template is invalid and must be (re)compiled
*
* @var bool
*/
public $mustCompile = null;
/**
* flag if template does contain nocache code sections
*
* @var bool
*/
public $has_nocache_code = false;
/**
* special compiled and cached template properties
*
* @var array
*/
public $properties = array('file_dependency' => array(),
'nocache_hash' => '',
'function' => array());
'nocache_hash' => '',
'function' => array());
/**
* required plugins
*
* @var array
*/
public $required_plugins = array('compiled' => array(), 'nocache' => array());
/**
* Global smarty instance
*
* @var Smarty
*/
public $smarty = null;
/**
* blocks for template inheritance
*
* @var array
*/
public $block_data = array();
/**
* variable filters
*
* @var array
*/
public $variable_filters = array();
/**
* optional log of tag/attributes
*
* @var array
*/
public $used_tags = array();
/**
* internal flag to allow relative path in child template blocks
*
* @var bool
*/
public $allow_relative_path = false;
/**
* internal capture runtime stack
*
* @var array
*/
public $_capture_stack = array(0 => array());
/**
* Create template data object
*
* Some of the global Smarty settings copied to template scope
* It load the required template resources and cacher plugins
*
@ -115,13 +126,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
{
$this->smarty = &$smarty;
$this->smarty = & $smarty;
// Smarty parameter
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
$this->caching = $_caching === null ? $this->smarty->caching : $_caching;
if ($this->caching === true)
if ($this->caching === true) {
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
}
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
$this->parent = $_parent;
// Template resource
@ -134,9 +146,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* Returns if the current template must be compiled by the Smarty compiler
*
* It does compare the timestamps of template source and the compiled templates and checks the force compile configuration
*
* @throws SmartyException
* @return boolean true if the template must be compiled
*/
public function mustCompile()
@ -159,7 +171,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* Compiles the template
*
* If the template is not evaluated the compiled template is saved on disk
*/
public function compileTemplateSource()
@ -184,7 +195,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// call compiler
try {
$code = $this->compiler->compileTemplate($this);
} catch (Exception $e) {
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
touch($this->compiled->filepath, $saved_timestamp);
@ -195,8 +207,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
// write compiled template
$_filepath = $this->compiled->filepath;
if ($_filepath === false)
if ($_filepath === false) {
throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
}
Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
$this->compiled->exists = true;
$this->compiled->isCompiled = true;
@ -208,6 +221,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* Writes the cached template output
*
* @param string $content
*
* @return bool
*/
public function writeCachedContent($content)
@ -217,8 +232,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
return false;
}
$this->properties['cache_lifetime'] = $this->cache_lifetime;
$this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true));
$this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
$content = $this->createTemplateCodeFrame($content, true);
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $this;
eval("?>" . $content);
$this->cached->valid = true;
@ -235,8 +253,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* @param mixed $compile_id compile id to be used with this template
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $vars optional variables to assign
* @param $data
* @param int $parent_scope scope in which {include} should execute
*
* @returns string template content
*/
public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
@ -265,13 +284,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$tpl->tpl_vars = $this->tpl_vars;
$tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty'];
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
$tpl->tpl_vars = &$this->tpl_vars;
$tpl->tpl_vars = & $this->tpl_vars;
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
$tpl->tpl_vars = & Smarty::$global_tpl_vars;
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
$tpl->tpl_vars = &$this->tpl_vars;
$tpl->tpl_vars = & $this->tpl_vars;
} else {
$tpl->tpl_vars = &$scope_ptr->tpl_vars;
$tpl->tpl_vars = & $scope_ptr->tpl_vars;
}
$tpl->config_vars = $this->config_vars;
if (!empty($data)) {
@ -292,27 +311,28 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* @param mixed $compile_id compile id to be used with this template
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $vars optional variables to assign
* @param $data
* @param int $parent_scope scope in which {include} should execute
* @param string $hash nocache hash code
*
* @returns string template content
*/
public function setupInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash)
{
$tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime);
$tpl->properties['nocache_hash'] = $hash;
$tpl->properties['nocache_hash'] = $hash;
// get variables from calling scope
if ($parent_scope == Smarty::SCOPE_LOCAL) {
$tpl->tpl_vars = $this->tpl_vars;
$tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty'];
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
$tpl->tpl_vars = &$this->tpl_vars;
$tpl->tpl_vars = & $this->tpl_vars;
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
$tpl->tpl_vars = & Smarty::$global_tpl_vars;
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
$tpl->tpl_vars = &$this->tpl_vars;
$tpl->tpl_vars = & $this->tpl_vars;
} else {
$tpl->tpl_vars = &$scope_ptr->tpl_vars;
$tpl->tpl_vars = & $scope_ptr->tpl_vars;
}
$tpl->config_vars = $this->config_vars;
if (!empty($data)) {
@ -325,12 +345,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
return $tpl;
}
/**
* Create code frame for compiled and cached templates
*
* @param string $content optional template content
* @param bool $cache flag for cache file
*
* @return string
*/
public function createTemplateCodeFrame($content = '', $cache = false)
@ -389,7 +409,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
}
}
foreach ($this->smarty->template_functions as $name => $function_data) {
foreach ($this->smarty->template_functions as $name => $function_data) {
if (isset($function_data['called_nocache'])) {
unset($function_data['called_nocache'], $function_data['called_functions'], $this->smarty->template_functions[$name]['called_nocache']);
$this->properties['function'][$name] = $function_data;
@ -399,7 +419,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
$this->properties['version'] = Smarty::SMARTY_VERSION;
if (!isset($this->properties['unifunc'])) {
$this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true));
$this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
}
if (!$this->source->recompiled) {
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($this->properties, true) . ',' . ($cache ? 'true' : 'false') . "); /*/%%SmartyHeaderCode%%*/?>\n";
@ -416,12 +436,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* This function is executed automatically when a compiled or cached template file is included
*
* - Decode saved properties from compiled template and cache files
* - Check if compiled or cache file is valid
*
* @param array $properties special template properties
* @param bool $cache flag if called from cache file
*
* @return bool flag if compiled or cache file is valid
*/
public function decodeProperties($properties, $cache = false)
@ -470,12 +490,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED &&
$this->properties['cache_lifetime'] >= 0 &&
(time() > ($this->cached->timestamp + $this->properties['cache_lifetime']))) {
(time() > ($this->cached->timestamp + $this->properties['cache_lifetime']))
) {
$is_valid = false;
}
$this->cached->valid = $is_valid;
} else {
$this->mustCompile = !$is_valid; }
$this->mustCompile = !$is_valid;
}
// store data in reusable Smarty_Template_Compiled
if (!$cache) {
$this->compiled->_properties = $properties;
@ -509,7 +531,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* Template code runtime function to get pointer to template variable array of requested scope
*
* @param int $scope requested variable scope
* @param int $scope requested variable scope
*
* @return array array of template variables
*/
public function &getScope($scope)
@ -534,7 +557,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* Get parent or root of template parent chain
*
* @param int $scope pqrent or root scope
* @param int $scope pqrent or root scope
*
* @return mixed object
*/
public function getScopePointer($scope)
@ -557,6 +581,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* [util function] counts an array, arrayaccess/traversable or PDOStatement object
*
* @param mixed $value
*
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 for empty elements
*/
public function _count($value)
@ -586,7 +611,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* runtime error not matching capture tags
*
*/
public function capture_error()
{
@ -594,23 +619,26 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
/**
* Empty cache for this template
*
* @param integer $exp_time expiration time
* @return integer number of cache files deleted
*/
public function clearCache($exp_time=null)
* Empty cache for this template
*
* @param integer $exp_time expiration time
*
* @return integer number of cache files deleted
*/
public function clearCache($exp_time = null)
{
Smarty_CacheResource::invalidLoadedCache($this->smarty);
return $this->cached->handler->clear($this->smarty, $this->template_name, $this->cache_id, $this->compile_id, $exp_time);
}
/**
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
@ -639,6 +667,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* get Smarty property in template context
*
* @param string $property_name property name
*
* @throws SmartyException
*/
public function __get($property_name)
{
@ -695,8 +725,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
/**
* Template data object destrutor
*
* Template data object destructor
*/
public function __destruct()
{
@ -704,5 +734,4 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->cached->handler->releaseLock($this->smarty, $this->cached);
}
}
}

View file

@ -1,18 +1,17 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Base
* This file contains the basic shared methods for template handling
*
* This file contains the basic shared methodes for template handling
*
* @package Smarty
* @package Smarty
* @subpackage Template
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Class with shared template methodes
* Class with shared template methods
*
* @package Smarty
* @package Smarty
* @subpackage Template
*/
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
@ -27,6 +26,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @param bool $display true: display, false: fetch
* @param bool $merge_tpl_vars if true parent template variables merged in to local scope
* @param bool $no_output_filter if true do not run output filter
*
* @throws Exception
* @throws SmartyException
* @return string rendered template output
*/
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
@ -34,7 +36,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
if ($template === null && $this instanceof $this->template_class) {
$template = $this;
}
if (!empty($cache_id) && is_object($cache_id)) {
if ($cache_id !== null && is_object($cache_id)) {
$parent = $cache_id;
$cache_id = null;
}
@ -43,8 +45,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
// create template object if necessary
$_template = ($template instanceof $this->template_class)
? $template
: $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
? $template
: $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
// if called by Smarty object make sure we use current caching status
if ($this instanceof Smarty) {
$_template->caching = $this->caching;
@ -130,6 +132,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {
// render template (not loaded and not in cache)
if (!$_template->source->uncompiled) {
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $_template;
if ($_template->source->recompiled) {
$code = $_template->compiler->compileTemplate($_template);
@ -140,7 +145,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
ob_start();
eval("?>" . $code);
unset($code);
} catch (Exception $e) {
}
catch (Exception $e) {
ob_get_clean();
throw $e;
}
@ -175,7 +181,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
}
array_unshift($_template->_capture_stack,array());
array_unshift($_template->_capture_stack, array());
//
// render compiled template
//
@ -185,7 +191,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
$_template->capture_error();
}
array_shift($_template->_capture_stack);
} catch (Exception $e) {
}
catch (Exception $e) {
ob_get_clean();
throw $e;
}
@ -198,7 +205,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
try {
ob_start();
$_template->source->renderUncompiled($_template);
} catch (Exception $e) {
}
catch (Exception $e) {
ob_get_clean();
throw $e;
}
@ -248,12 +256,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
}
// rendering (must be done before writing cache file because of {function} nocache handling)
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $_template;
try {
ob_start();
eval("?>" . $output);
$_output = ob_get_clean();
} catch (Exception $e) {
}
catch (Exception $e) {
ob_get_clean();
throw $e;
}
@ -276,7 +288,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
try {
ob_start();
array_unshift($_template->_capture_stack,array());
array_unshift($_template->_capture_stack, array());
//
// render cached template
//
@ -287,7 +299,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
array_shift($_template->_capture_stack);
$_output = ob_get_clean();
} catch (Exception $e) {
}
catch (Exception $e) {
ob_get_clean();
throw $e;
}
@ -308,33 +321,37 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
$_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified');
break;
case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified');
break;
case 'cli':
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
}
break;
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
}
break;
default:
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
break;
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
break;
}
} else {
switch (PHP_SAPI) {
case 'cli':
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
}
break;
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
}
break;
default:
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
break;
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
break;
}
echo $_output;
}
@ -343,12 +360,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
// debug output
if ($this->smarty->debugging) {
Smarty_Internal_Debug::display_debug($this);
Smarty_Internal_Debug::display_debug($_template);
}
if ($merge_tpl_vars) {
// restore local variables
$_template->tpl_vars = $save_tpl_vars;
$_template->config_vars = $save_config_vars;
$_template->config_vars = $save_config_vars;
}
return;
@ -356,7 +373,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
if ($merge_tpl_vars) {
// restore local variables
$_template->tpl_vars = $save_tpl_vars;
$_template->config_vars = $save_config_vars;
$_template->config_vars = $save_config_vars;
}
// return fetched content
return $_output;
@ -384,6 +401,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return boolean cache status
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
@ -405,6 +423,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* creates a data object
*
* @param object $parent next higher level of Smarty variables
*
* @returns Smarty_Data data object
*/
public function createData($parent = null)
@ -415,11 +434,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this fuction is cachable
* @param array $cache_attr caching attributes if any
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this fuction is cachable
* @param array $cache_attr caching attributes if any
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException when the plugin tag is invalid
*/
@ -439,8 +459,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Unregister Plugin
*
* @param string $type of plugin
* @param string $tag name of plugin
* @param string $type of plugin
* @param string $tag name of plugin
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterPlugin($type, $tag)
@ -455,8 +476,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a resource to fetch a template
*
* @param string $type name of resource type
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
* @param string $type name of resource type
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function registerResource($type, $callback)
@ -469,7 +491,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Unregisters a resource
*
* @param string $type name of resource type
* @param string $type name of resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterResource($type)
@ -484,8 +507,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a cache resource to cache a template's output
*
* @param string $type name of cache resource type
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
* @param string $type name of cache resource type
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function registerCacheResource($type, Smarty_CacheResource $callback)
@ -498,7 +522,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Unregisters a cache resource
*
* @param string $type name of cache resource type
* @param string $type name of cache resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterCacheResource($type)
@ -513,18 +538,18 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers object to be used in templates
*
* @param string $object name of template object
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
* @param array $block_functs list of methods that are block format
* @param $object_name
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException if any of the methods in $allowed or $block_methods are invalid
*/
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
{
// test if allowed methodes callable
// test if allowed methods callable
if (!empty($allowed)) {
foreach ((array) $allowed as $method) {
if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
@ -532,7 +557,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
}
}
// test if block methodes callable
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array) $block_methods as $method) {
if (!is_callable(array($object_impl, $method))) {
@ -542,7 +567,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
// register the object
$this->smarty->registered_objects[$object_name] =
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
return $this;
}
@ -550,7 +575,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* return a reference to a registered object
*
* @param string $name object name
* @param string $name object name
*
* @return object
* @throws SmartyException if no such object is found
*/
@ -569,7 +595,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* unregister an object
*
* @param string $name object name
* @param string $name object name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterObject($name)
@ -584,10 +611,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers static classes to be used in templates
*
* @param string $class name of template class
* @param string $class_impl the referenced PHP class to register
* @param $class_name
* @param string $class_impl the referenced PHP class to register
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $class_impl does not refer to an existing class
*/
public function registerClass($class_name, $class_impl)
{
@ -604,7 +632,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
@ -622,7 +651,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a default template handler
*
* @param callable $callback class/method name
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
@ -640,7 +670,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a default template handler
*
* @param callable $callback class/method name
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
@ -658,8 +689,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Registers a filter function
*
* @param string $type filter type
* @param callback $callback
* @param string $type filter type
* @param callback $callback
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function registerFilter($type, $callback)
@ -672,8 +704,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback $callback
* @param string $type filter type
* @param callback $callback
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterFilter($type, $callback)
@ -690,13 +723,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
public function _get_filter_name($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ?
get_class($function_name[0]) : $function_name[0]);
get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} else {
@ -707,8 +741,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
* @param string $type filter type
* @param string $name filter name
*
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter($type, $name)
@ -731,8 +766,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
/**
* unload a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
* @param string $type filter type
* @param string $name filter name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unloadFilter($type, $name)
@ -749,6 +785,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* preg_replace callback to convert camelcase getter/setter to underscore property names
*
* @param string $match match string
*
* @return string replacemant
*/
private function replaceCamelcase($match)
@ -761,6 +798,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @throws SmartyException
*/
public function __call($name, $args)
{
@ -782,7 +821,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
// lcfirst() not available < PHP 5.3.0, so improvise
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// convert camel case to underscored name
$property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name);
$property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name);
$_resolved_property_name[$name] = $property_name;
}
if (isset($_resolved_property_source[$property_name])) {
@ -797,20 +836,20 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
$_resolved_property_source[$property_name] = $_is_this;
}
if ($_is_this) {
if ($first3 == 'get')
return $this->$property_name;
else
return $this->$property_name = $args[0];
if ($first3 == 'get') {
return $this->$property_name;
} else {
return $this->$property_name = $args[0];
}
} elseif ($_is_this === false) {
if ($first3 == 'get')
return $this->smarty->$property_name;
else
return $this->smarty->$property_name = $args[0];
if ($first3 == 'get') {
return $this->smarty->$property_name;
} else {
return $this->smarty->$property_name = $args[0];
}
} else {
throw new SmartyException("property '$property_name' does not exist.");
return false;
}
}
}
if ($name == 'Smarty') {
throw new SmartyException("PHP5 requires you to call __construct() instead of Smarty()");
@ -818,5 +857,4 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
// must be unknown
throw new SmartyException("Call of unknown method '$name'.");
}
}

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Smarty Template Compiler Base
* This file contains the basic classes and methods for compiling Smarty templates with lexer/parser
*
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Main abstract compiler class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
abstract class Smarty_Internal_TemplateCompilerBase
@ -138,62 +137,72 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* force compilation of complete template as nocache
*
* @var boolean
*/
public $forceNocache = false;
/**
* suppress Smarty header code in compiled template
*
* @var bool
*/
public $suppressHeader = false;
/**
* suppress template property header code in compiled template
*
* @var bool
*/
public $suppressTemplatePropertyHeader = false;
/**
* suppress pre and post filter
*
* @var bool
*/
public $suppressFilter = false;
/**
* flag if compiled template file shall we written
*
* @var bool
*/
public $write_compiled_code = true;
/**
* flag if currently a template function is compiled
*
* @var bool
*/
public $compiles_template_function = false;
/**
* called subfuntions from template function
*
* @var array
*/
public $called_functions = array();
/**
* flags for used modifier plugins
*
* @var array
*/
public $modifier_plugins = array();
/**
* type of already compiled modifier
*
* @var array
*/
public $known_modifier_type = array();
/**
* Methode to compile a Smarty template
* method to compile a Smarty template
*
* @param mixed $_content template source
*
* @return bool true if compiling succeeded, false if it failed
*/
abstract protected function doCompile($_content);
@ -203,14 +212,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function __construct()
{
$this->nocache_hash = str_replace('.', '-', uniqid(rand(), true));
$this->nocache_hash = str_replace(array('.', ','), '-', uniqid(rand(), true));
}
/**
* Method to compile a Smarty template
*
* @param Smarty_Internal_Template $template template object to compile
* @param bool $nocache true is shall be compiled in nocache mode
* @param bool $nocache true is shall be compiled in nocache mode
*
* @return bool true if compiling succeeded, false if it failed
*/
public function compileTemplate(Smarty_Internal_Template $template, $nocache = false)
@ -252,7 +262,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($loop || $no_sources) {
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
}
$loop++;
$loop ++;
if ($no_sources) {
$this->inheritance_child = true;
} else {
@ -308,13 +318,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Compile Tag
*
* This is a call back from the lexer/parser
* It executes the required compile plugin for the Smarty tag
*
* @param string $tag tag name
* @param array $args array with tag attributes
* @param array $parameter array with compilation parameter
* @param array $args array with tag attributes
* @param array $parameter array with compilation parameter
*
* @throws SmartyCompilerException
* @throws SmartyException
* @return string compiled code
*/
public function compileTag($tag, $args, $parameter = array())
@ -365,18 +377,19 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
}
// not an internal compiler tag
if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
if (strlen($tag) < 6 || substr($tag, - 5) != 'close') {
// check if tag is a registered object
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))
) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
} else {
return $this->trigger_template_error('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
// throw exception
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . $tag . '"', $this->lex->taglineno);
}
}
// check if tag is registered
@ -482,14 +495,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
} else {
// compile closing tag of block function
$base_tag = substr($tag, 0, -5);
$base_tag = substr($tag, 0, - 5);
// check if closing tag is a registered object
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
} else {
return $this->trigger_template_error('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
// throw exception
$this->trigger_template_error('not allowed closing tag method "' . $method . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
}
}
// registered block tag ?
@ -535,17 +549,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
/**
* lazy loads internal compile plugin for tag and calls the compile methode
*
* lazy loads internal compile plugin for tag and calls the compile method
* compile objects cached for reuse.
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_Tagname.php
*
* @param string $tag tag name
* @param array $args list of tag attributes
* @param mixed $param1 optional parameter
* @param mixed $param2 optional parameter
* @param mixed $param3 optional parameter
* @param array $args list of tag attributes
* @param mixed $param1 optional parameter
* @param mixed $param2 optional parameter
* @param mixed $param3 optional parameter
*
* @return string compiled code
*/
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
@ -573,8 +587,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Check for plugins and return function name
*
* @param string $pugin_name name of plugin or function
* @param $plugin_name
* @param string $plugin_type type of plugin
*
* @return string call name of function
*/
public function getPlugin($plugin_name, $plugin_type)
@ -633,6 +648,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*
* @param string $tag name of tag
* @param string $plugin_type type of plugin
*
* @return boolean true if found
*/
public function getPluginFromDefaultHandler($tag, $plugin_type)
@ -676,13 +692,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Inject inline code for nocache template sections
*
* This method gets the content of each template element from the parser.
* If the content is compiled code and it should be not cached the code is injected
* into the rendered output.
*
* @param string $content content of template element
* @param string $content content of template element
* @param boolean $is_code true if content is compiled code
*
* @return string content
*/
public function processNocacheCode($content, $is_code)
@ -719,10 +735,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* push current file and line offset on stack for tracing {block} source lines
*
* @param string $file new filename
* @param string $uid uid of file
* @param string $debug false debug end_compile shall not be called
* @param int $line line offset to source
* @param string $file new filename
* @param string $uid uid of file
* @param int $line line offset to source
* @param bool $debug false debug end_compile shall not be called
*/
public function pushTrace($file, $uid, $line, $debug = true)
{
@ -732,7 +748,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset));
$this->trace_filepath = $this->smarty->_current_file = $file;
$this->trace_uid = $uid;
$this->trace_line_offset = $line ;
$this->trace_line_offset = $line;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
@ -740,7 +756,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* restore file and line offset
*
*/
public function popTrace()
{
@ -759,14 +775,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* display compiler error messages without dying
*
* If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about expected tokens.
*
* If parameter $args contains a string this is used as error message
*
* @param string $args individual error message or null
* @param string $line line-number
*
* @throws SmartyCompilerException when an unexpected token is found
*/
public function trigger_template_error($args = null, $line = null)
@ -775,9 +790,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!isset($line)) {
$line = $this->lex->line;
}
// $line += $this->trace_line_offset;
// $line += $this->trace_line_offset;
$match = preg_split("/\n/", $this->lex->data);
$error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
$error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
if (isset($args)) {
// individual error message
$error_text .= $args;
@ -805,5 +820,4 @@ abstract class Smarty_Internal_TemplateCompilerBase
$e->template = $this->template->source->filepath;
throw $e;
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,38 +3,34 @@
* Project: Smarty: the PHP compiling template engine
* File: smarty_internal_utility.php
* SVN: $Id: $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @package Smarty
* @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @package Smarty
* @subpackage PluginsInternal
* @version 3-SVN$Rev: 3286 $
* @version 3-SVN$Rev: 3286 $
*/
/**
* Utility class
*
* @package Smarty
* @package Smarty
* @subpackage Security
*/
class Smarty_Internal_Utility
@ -50,11 +46,12 @@ class Smarty_Internal_Utility
/**
* Compile all template files
*
* @param string $extension template file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
* @param string $extension template file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
*
* @return integer number of template files compiled
*/
public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
@ -72,30 +69,35 @@ class Smarty_Internal_Utility
$_compile = new RecursiveIteratorIterator($_compileDirs);
foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue;
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
$_template_file = $_file;
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
continue;
}
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
$_template_file = $_file;
} else {
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
}
echo '<br>', $_dir, '---', $_template_file;
flush();
$_start_time = microtime(true);
try {
$_tpl = $smarty->createTemplate($_template_file,null,null,null,false);
$_tpl = $smarty->createTemplate($_template_file, null, null, null, false);
if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource();
$_count++;
$_count ++;
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
} catch (Exception $e) {
}
catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count++;
$_error_count ++;
}
// free memory
$smarty->template_objects = array();
@ -114,11 +116,12 @@ class Smarty_Internal_Utility
/**
* Compile all config files
*
* @param string $extension config file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
* @param string $extension config file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
*
* @return integer number of config files compiled
*/
public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
@ -136,9 +139,13 @@ class Smarty_Internal_Utility
$_compile = new RecursiveIteratorIterator($_compileDirs);
foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue;
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
continue;
}
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
$_config_file = $_file;
} else {
$_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
@ -150,16 +157,17 @@ class Smarty_Internal_Utility
$_config = new Smarty_Internal_Config($_config_file, $smarty);
if ($_config->mustCompile()) {
$_config->compileConfigSource();
$_count++;
$_count ++;
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
} catch (Exception $e) {
}
catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count++;
$_error_count ++;
}
if ($max_errors !== null && $_error_count == $max_errors) {
echo '<br><br>too many errors';
@ -178,13 +186,14 @@ class Smarty_Internal_Utility
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param Smarty $smarty Smarty instance
*
* @return integer number of template files deleted
*/
public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)
{
$_compile_dir = $smarty->getCompileDir();
$_compile_dir = realpath($smarty->getCompileDir()) . '/';
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? DS : '^';
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = false;
@ -204,13 +213,13 @@ class Smarty_Internal_Utility
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
$_resource_part_1_length = strlen($_resource_part_1);
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
$_resource_part_1_length = strlen($_resource_part_1);
} else {
return 0;
}
$_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);
$_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1);
$_resource_part_2_length = strlen($_resource_part_2);
}
$_dir = $_compile_dir;
@ -218,22 +227,24 @@ class Smarty_Internal_Utility
$_dir .= $_compile_id . $_dir_sep;
}
if (isset($_compile_id)) {
$_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep;
$_compile_id_part = str_replace('\\', '/', $_compile_dir . $_compile_id . $_dir_sep);
$_compile_id_part_length = strlen($_compile_id_part);
}
$_count = 0;
try {
$_compileDirs = new RecursiveDirectoryIterator($_dir);
// NOTE: UnexpectedValueException thrown for PHP >= 5.3
} catch (Exception $e) {
// NOTE: UnexpectedValueException thrown for PHP >= 5.3
}
catch (Exception $e) {
return 0;
}
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_compile as $_file) {
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false)
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
$_filepath = (string) $_file;
$_filepath = str_replace('\\', '/', (string) $_file);
if ($_file->isDir()) {
if (!$_compile->isDot()) {
@ -242,12 +253,13 @@ class Smarty_Internal_Utility
}
} else {
$unlink = false;
if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length)))
if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && $a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length)))
&& (!isset($resource_name)
|| (isset($_filepath[$_resource_part_1_length])
&& substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0)
&& substr_compare($_filepath, $_resource_part_1, - $_resource_part_1_length, $_resource_part_1_length) == 0)
|| (isset($_filepath[$_resource_part_2_length])
&& substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) {
&& substr_compare($_filepath, $_resource_part_2, - $_resource_part_2_length, $_resource_part_2_length) == 0))
) {
if (isset($exp_time)) {
if (time() - @filemtime($_filepath) >= $exp_time) {
$unlink = true;
@ -258,7 +270,7 @@ class Smarty_Internal_Utility
}
if ($unlink && @unlink($_filepath)) {
$_count++;
$_count ++;
}
}
}
@ -272,7 +284,10 @@ class Smarty_Internal_Utility
/**
* Return array of tag/attributes of all tags used by an template
*
* @param Smarty_Internal_Template $templae template object
* @param Smarty_Internal_Template $template
*
* @throws Exception
* @throws SmartyException
* @return array of tag/attributes
*/
public static function getTags(Smarty_Internal_Template $template)
@ -285,14 +300,14 @@ class Smarty_Internal_Utility
/**
* diagnose Smarty setup
*
* If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
*
* @param Smarty $smarty Smarty instance to test
* @param array $errors array to push results into rather than outputting them
*
* @return bool status, true if everything is fine, false else
*/
public static function testInstall(Smarty $smarty, &$errors=null)
public static function testInstall(Smarty $smarty, &$errors = null)
{
$status = true;
@ -422,7 +437,7 @@ class Smarty_Internal_Utility
// test if all registered plugins_dir are accessible
// and if core plugins directory is still registered
$_core_plugins_dir = realpath(dirname(__FILE__) .'/../plugins');
$_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins');
$_core_plugins_available = false;
foreach ($smarty->getPluginsDir() as $plugin_dir) {
$_plugin_dir = $plugin_dir;
@ -627,75 +642,75 @@ class Smarty_Internal_Utility
$source = SMARTY_SYSPLUGINS_DIR;
if (is_dir($source)) {
$expected = array(
"smarty_cacheresource.php" => true,
"smarty_cacheresource_custom.php" => true,
"smarty_cacheresource_keyvaluestore.php" => true,
"smarty_config_source.php" => true,
"smarty_internal_cacheresource_file.php" => true,
"smarty_internal_compile_append.php" => true,
"smarty_internal_compile_assign.php" => true,
"smarty_internal_compile_block.php" => true,
"smarty_internal_compile_break.php" => true,
"smarty_internal_compile_call.php" => true,
"smarty_internal_compile_capture.php" => true,
"smarty_internal_compile_config_load.php" => true,
"smarty_internal_compile_continue.php" => true,
"smarty_internal_compile_debug.php" => true,
"smarty_internal_compile_eval.php" => true,
"smarty_internal_compile_extends.php" => true,
"smarty_internal_compile_for.php" => true,
"smarty_internal_compile_foreach.php" => true,
"smarty_internal_compile_function.php" => true,
"smarty_internal_compile_if.php" => true,
"smarty_internal_compile_include.php" => true,
"smarty_internal_compile_include_php.php" => true,
"smarty_internal_compile_insert.php" => true,
"smarty_internal_compile_ldelim.php" => true,
"smarty_internal_compile_nocache.php" => true,
"smarty_internal_compile_private_block_plugin.php" => true,
"smarty_internal_compile_private_function_plugin.php" => true,
"smarty_internal_compile_private_modifier.php" => true,
"smarty_cacheresource.php" => true,
"smarty_cacheresource_custom.php" => true,
"smarty_cacheresource_keyvaluestore.php" => true,
"smarty_config_source.php" => true,
"smarty_internal_cacheresource_file.php" => true,
"smarty_internal_compile_append.php" => true,
"smarty_internal_compile_assign.php" => true,
"smarty_internal_compile_block.php" => true,
"smarty_internal_compile_break.php" => true,
"smarty_internal_compile_call.php" => true,
"smarty_internal_compile_capture.php" => true,
"smarty_internal_compile_config_load.php" => true,
"smarty_internal_compile_continue.php" => true,
"smarty_internal_compile_debug.php" => true,
"smarty_internal_compile_eval.php" => true,
"smarty_internal_compile_extends.php" => true,
"smarty_internal_compile_for.php" => true,
"smarty_internal_compile_foreach.php" => true,
"smarty_internal_compile_function.php" => true,
"smarty_internal_compile_if.php" => true,
"smarty_internal_compile_include.php" => true,
"smarty_internal_compile_include_php.php" => true,
"smarty_internal_compile_insert.php" => true,
"smarty_internal_compile_ldelim.php" => true,
"smarty_internal_compile_nocache.php" => true,
"smarty_internal_compile_private_block_plugin.php" => true,
"smarty_internal_compile_private_function_plugin.php" => true,
"smarty_internal_compile_private_modifier.php" => true,
"smarty_internal_compile_private_object_block_function.php" => true,
"smarty_internal_compile_private_object_function.php" => true,
"smarty_internal_compile_private_print_expression.php" => true,
"smarty_internal_compile_private_registered_block.php" => true,
"smarty_internal_compile_private_registered_function.php" => true,
"smarty_internal_compile_private_special_variable.php" => true,
"smarty_internal_compile_rdelim.php" => true,
"smarty_internal_compile_section.php" => true,
"smarty_internal_compile_setfilter.php" => true,
"smarty_internal_compile_while.php" => true,
"smarty_internal_compilebase.php" => true,
"smarty_internal_config.php" => true,
"smarty_internal_config_file_compiler.php" => true,
"smarty_internal_configfilelexer.php" => true,
"smarty_internal_configfileparser.php" => true,
"smarty_internal_data.php" => true,
"smarty_internal_debug.php" => true,
"smarty_internal_filter_handler.php" => true,
"smarty_internal_function_call_handler.php" => true,
"smarty_internal_get_include_path.php" => true,
"smarty_internal_nocache_insert.php" => true,
"smarty_internal_parsetree.php" => true,
"smarty_internal_resource_eval.php" => true,
"smarty_internal_resource_extends.php" => true,
"smarty_internal_resource_file.php" => true,
"smarty_internal_resource_registered.php" => true,
"smarty_internal_resource_stream.php" => true,
"smarty_internal_resource_string.php" => true,
"smarty_internal_smartytemplatecompiler.php" => true,
"smarty_internal_template.php" => true,
"smarty_internal_templatebase.php" => true,
"smarty_internal_templatecompilerbase.php" => true,
"smarty_internal_templatelexer.php" => true,
"smarty_internal_templateparser.php" => true,
"smarty_internal_utility.php" => true,
"smarty_internal_write_file.php" => true,
"smarty_resource.php" => true,
"smarty_resource_custom.php" => true,
"smarty_resource_recompiled.php" => true,
"smarty_resource_uncompiled.php" => true,
"smarty_security.php" => true,
"smarty_internal_compile_private_object_function.php" => true,
"smarty_internal_compile_private_print_expression.php" => true,
"smarty_internal_compile_private_registered_block.php" => true,
"smarty_internal_compile_private_registered_function.php" => true,
"smarty_internal_compile_private_special_variable.php" => true,
"smarty_internal_compile_rdelim.php" => true,
"smarty_internal_compile_section.php" => true,
"smarty_internal_compile_setfilter.php" => true,
"smarty_internal_compile_while.php" => true,
"smarty_internal_compilebase.php" => true,
"smarty_internal_config.php" => true,
"smarty_internal_config_file_compiler.php" => true,
"smarty_internal_configfilelexer.php" => true,
"smarty_internal_configfileparser.php" => true,
"smarty_internal_data.php" => true,
"smarty_internal_debug.php" => true,
"smarty_internal_filter_handler.php" => true,
"smarty_internal_function_call_handler.php" => true,
"smarty_internal_get_include_path.php" => true,
"smarty_internal_nocache_insert.php" => true,
"smarty_internal_parsetree.php" => true,
"smarty_internal_resource_eval.php" => true,
"smarty_internal_resource_extends.php" => true,
"smarty_internal_resource_file.php" => true,
"smarty_internal_resource_registered.php" => true,
"smarty_internal_resource_stream.php" => true,
"smarty_internal_resource_string.php" => true,
"smarty_internal_smartytemplatecompiler.php" => true,
"smarty_internal_template.php" => true,
"smarty_internal_templatebase.php" => true,
"smarty_internal_templatecompilerbase.php" => true,
"smarty_internal_templatelexer.php" => true,
"smarty_internal_templateparser.php" => true,
"smarty_internal_utility.php" => true,
"smarty_internal_write_file.php" => true,
"smarty_resource.php" => true,
"smarty_resource_custom.php" => true,
"smarty_resource_recompiled.php" => true,
"smarty_resource_uncompiled.php" => true,
"smarty_security.php" => true,
);
$iterator = new DirectoryIterator($source);
foreach ($iterator as $file) {
@ -708,7 +723,7 @@ class Smarty_Internal_Utility
}
if ($expected) {
$status = false;
$message = "FAILED: files missing from libs/sysplugins: ". join(', ', array_keys($expected));
$message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected));
if ($errors === null) {
echo $message . ".\n";
} else {
@ -719,7 +734,7 @@ class Smarty_Internal_Utility
}
} else {
$status = false;
$message = "FAILED: ". SMARTY_SYSPLUGINS_DIR .' is not a directory';
$message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory';
if ($errors === null) {
echo $message . ".\n";
} else {
@ -734,53 +749,53 @@ class Smarty_Internal_Utility
$source = SMARTY_PLUGINS_DIR;
if (is_dir($source)) {
$expected = array(
"block.textformat.php" => true,
"function.counter.php" => true,
"function.cycle.php" => true,
"function.fetch.php" => true,
"function.html_checkboxes.php" => true,
"function.html_image.php" => true,
"function.html_options.php" => true,
"function.html_radios.php" => true,
"function.html_select_date.php" => true,
"function.html_select_time.php" => true,
"function.html_table.php" => true,
"function.mailto.php" => true,
"function.math.php" => true,
"modifier.capitalize.php" => true,
"modifier.date_format.php" => true,
"modifier.debug_print_var.php" => true,
"modifier.escape.php" => true,
"modifier.regex_replace.php" => true,
"modifier.replace.php" => true,
"modifier.spacify.php" => true,
"modifier.truncate.php" => true,
"modifiercompiler.cat.php" => true,
"block.textformat.php" => true,
"function.counter.php" => true,
"function.cycle.php" => true,
"function.fetch.php" => true,
"function.html_checkboxes.php" => true,
"function.html_image.php" => true,
"function.html_options.php" => true,
"function.html_radios.php" => true,
"function.html_select_date.php" => true,
"function.html_select_time.php" => true,
"function.html_table.php" => true,
"function.mailto.php" => true,
"function.math.php" => true,
"modifier.capitalize.php" => true,
"modifier.date_format.php" => true,
"modifier.debug_print_var.php" => true,
"modifier.escape.php" => true,
"modifier.regex_replace.php" => true,
"modifier.replace.php" => true,
"modifier.spacify.php" => true,
"modifier.truncate.php" => true,
"modifiercompiler.cat.php" => true,
"modifiercompiler.count_characters.php" => true,
"modifiercompiler.count_paragraphs.php" => true,
"modifiercompiler.count_sentences.php" => true,
"modifiercompiler.count_words.php" => true,
"modifiercompiler.default.php" => true,
"modifiercompiler.escape.php" => true,
"modifiercompiler.from_charset.php" => true,
"modifiercompiler.indent.php" => true,
"modifiercompiler.lower.php" => true,
"modifiercompiler.noprint.php" => true,
"modifiercompiler.string_format.php" => true,
"modifiercompiler.strip.php" => true,
"modifiercompiler.strip_tags.php" => true,
"modifiercompiler.to_charset.php" => true,
"modifiercompiler.unescape.php" => true,
"modifiercompiler.upper.php" => true,
"modifiercompiler.wordwrap.php" => true,
"outputfilter.trimwhitespace.php" => true,
"shared.escape_special_chars.php" => true,
"shared.literal_compiler_param.php" => true,
"shared.make_timestamp.php" => true,
"shared.mb_str_replace.php" => true,
"shared.mb_unicode.php" => true,
"shared.mb_wordwrap.php" => true,
"variablefilter.htmlspecialchars.php" => true,
"modifiercompiler.count_sentences.php" => true,
"modifiercompiler.count_words.php" => true,
"modifiercompiler.default.php" => true,
"modifiercompiler.escape.php" => true,
"modifiercompiler.from_charset.php" => true,
"modifiercompiler.indent.php" => true,
"modifiercompiler.lower.php" => true,
"modifiercompiler.noprint.php" => true,
"modifiercompiler.string_format.php" => true,
"modifiercompiler.strip.php" => true,
"modifiercompiler.strip_tags.php" => true,
"modifiercompiler.to_charset.php" => true,
"modifiercompiler.unescape.php" => true,
"modifiercompiler.upper.php" => true,
"modifiercompiler.wordwrap.php" => true,
"outputfilter.trimwhitespace.php" => true,
"shared.escape_special_chars.php" => true,
"shared.literal_compiler_param.php" => true,
"shared.make_timestamp.php" => true,
"shared.mb_str_replace.php" => true,
"shared.mb_unicode.php" => true,
"shared.mb_wordwrap.php" => true,
"variablefilter.htmlspecialchars.php" => true,
);
$iterator = new DirectoryIterator($source);
foreach ($iterator as $file) {
@ -793,7 +808,7 @@ class Smarty_Internal_Utility
}
if ($expected) {
$status = false;
$message = "FAILED: files missing from libs/plugins: ". join(', ', array_keys($expected));
$message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected));
if ($errors === null) {
echo $message . ".\n";
} else {
@ -804,7 +819,7 @@ class Smarty_Internal_Utility
}
} else {
$status = false;
$message = "FAILED: ". SMARTY_PLUGINS_DIR .' is not a directory';
$message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory';
if ($errors === null) {
echo $message . ".\n";
} else {
@ -819,5 +834,4 @@ class Smarty_Internal_Utility
return $status;
}
}

View file

@ -2,15 +2,15 @@
/**
* Smarty write file plugin
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
* @author Monte Ohrt
* @author Monte Ohrt
*/
/**
* Smarty Internal Write File Class
*
* @package Smarty
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Write_File
@ -18,9 +18,11 @@ class Smarty_Internal_Write_File
/**
* Writes file in a safe way to disk
*
* @param string $_filepath complete filepath
* @param string $_contents file content
* @param Smarty $smarty smarty instance
* @param string $_filepath complete filepath
* @param string $_contents file content
* @param Smarty $smarty smarty instance
*
* @throws SmartyException
* @return boolean true
*/
public static function writeFile($_filepath, $_contents, Smarty $smarty)
@ -38,13 +40,11 @@ class Smarty_Internal_Write_File
}
// write to tmp file, then move to overt file lock race condition
$_tmp_file = $_dirpath . DS . uniqid('wrt', true);
$_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true));
if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_tmp_file}");
return false;
}
}
/*
* Windows' rename() fails if the destination exists,
@ -72,8 +72,6 @@ class Smarty_Internal_Write_File
if (!$success) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_filepath}");
return false;
}
if ($smarty->_file_perms !== null) {
@ -85,5 +83,4 @@ class Smarty_Internal_Write_File
return true;
}
}

View file

@ -2,73 +2,79 @@
/**
* Smarty Resource Plugin
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @author Rodney Rehm
*/
/**
* Smarty Resource Plugin
*
* Base implementation for resource plugins
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource
{
/**
* cache for Smarty_Template_Source instances
*
* @var array
*/
public static $sources = array();
/**
* cache for Smarty_Template_Compiled instances
*
* @var array
*/
public static $compileds = array();
/**
* cache for Smarty_Resource instances
*
* @var array
*/
public static $resources = array();
/**
* resource types provided by the core
*
* @var array
*/
protected static $sysplugins = array(
'file' => true,
'string' => true,
'file' => true,
'string' => true,
'extends' => true,
'stream' => true,
'eval' => true,
'php' => true
'stream' => true,
'eval' => true,
'php' => true
);
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Load template's source into current template object
*
* {@internal The loaded source is assigned to $_template->source->content directly.}}
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -80,7 +86,7 @@ abstract class Smarty_Resource
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null);
abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
/**
* populate Source Object with timestamp and exists from Resource
@ -95,9 +101,10 @@ abstract class Smarty_Resource
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
*
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
@ -122,9 +129,9 @@ abstract class Smarty_Resource
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
@ -140,7 +147,7 @@ abstract class Smarty_Resource
// set basename if not specified
$_basename = $this->getBasename($compiled->source);
if ($_basename === null) {
$_basename = basename( preg_replace('![^\w\/]+!', '_', $compiled->source->name) );
$_basename = basename(preg_replace('![^\w\/]+!', '_', $compiled->source->name));
}
// separate (optional) basename by dot
if ($_basename) {
@ -155,9 +162,10 @@ abstract class Smarty_Resource
*
* @param string $_path path to normalize
* @param boolean $ds respect windows directory separator
*
* @return string normalized path
*/
protected function normalizePath($_path, $ds=true)
protected function normalizePath($_path, $ds = true)
{
if ($ds) {
// don't we all just love windows?
@ -200,10 +208,11 @@ abstract class Smarty_Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return string fully qualified filepath
* @throws SmartyException if default template handler is registered but not callable
*/
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$file = $source->name;
if ($source instanceof Smarty_Config_Source) {
@ -232,7 +241,6 @@ abstract class Smarty_Resource
// resolve relative path
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
// don't we all just love windows?
$_path = str_replace('\\', '/', $file);
$_path = DS . trim($file, '/');
$_was_relative = true;
} else {
@ -325,7 +333,7 @@ abstract class Smarty_Resource
}
}
$_return = call_user_func_array($_default_handler,
array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
if (is_string($_return)) {
$source->timestamp = @filemtime($_return);
$source->exists = !!$source->timestamp;
@ -349,6 +357,7 @@ abstract class Smarty_Resource
*
* @param Smarty_Template_Source $source source object
* @param string $file file name
*
* @return bool true if file exists
*/
protected function fileExists(Smarty_Template_Source $source, $file)
@ -356,13 +365,13 @@ abstract class Smarty_Resource
$source->timestamp = is_file($file) ? @filemtime($file) : false;
return $source->exists = !!$source->timestamp;
}
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
@ -373,8 +382,10 @@ abstract class Smarty_Resource
/**
* Load Resource Handler
*
* @param Smarty $smarty smarty object
* @param string $type name of the resource
* @param Smarty $smarty smarty object
* @param string $type name of the resource
*
* @throws SmartyException
* @return Smarty_Resource Resource Handler
*/
public static function load(Smarty $smarty, $type)
@ -453,17 +464,18 @@ abstract class Smarty_Resource
// TODO: try default_(template|config)_handler
// give up
throw new SmartyException("Unkown resource type '{$type}'");
throw new SmartyException("Unknown resource type '{$type}'");
}
/**
* extract resource_type and resource_name from template_resource and config_resource
*
* @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
*
* @param string $resource_name template_resource or config_resource to parse
* @param string $default_resource the default resource_type defined in $smarty
* @param string &$name the parsed resource name
* @param string &$type the parsed resource type
*
* @return void
*/
protected static function parseResourceName($resource_name, $default_resource, &$name, &$type)
@ -485,14 +497,16 @@ abstract class Smarty_Resource
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
*
* @return string unique resource name
*/
/**
* modify template_resource according to resource handlers specifications
*
* @param Smarty_Internal_template $template Smarty instance
* @param string $template_resource template_resource to extracate resource handler and name of
* @param Smarty_Internal_template $template Smarty instance
* @param string $template_resource template_resource to extract resource handler and name of
*
* @return string unique resource name
*/
public static function getUniqueTemplateName($template, $template_resource)
@ -510,15 +524,15 @@ abstract class Smarty_Resource
/**
* initialize Source Object for given resource
*
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Source Source Object
*/
public static function source(Smarty_Internal_Template $_template=null, Smarty $smarty=null, $template_resource=null)
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
{
if ($_template) {
$smarty = $_template->smarty;
@ -540,7 +554,7 @@ abstract class Smarty_Resource
// check runtime cache
$_cache_key = 'template|' . $unique_resource_name;
if ($smarty->compile_id) {
$_cache_key .= '|'.$smarty->compile_id;
$_cache_key .= '|' . $smarty->compile_id;
}
if (isset(self::$sources[$_cache_key])) {
return self::$sources[$_cache_key];
@ -560,6 +574,8 @@ abstract class Smarty_Resource
* initialize Config Source Object for given resource
*
* @param Smarty_Internal_Config $_config config object
*
* @throws SmartyException
* @return Smarty_Config_Source Source Object
*/
public static function config(Smarty_Internal_Config $_config)
@ -595,18 +611,15 @@ abstract class Smarty_Resource
return $source;
}
}
/**
* Smarty Resource Data Object
*
* Meta Data Container for Template Files
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*
* @author Rodney Rehm
* @property integer $timestamp Source Timestamp
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
@ -616,84 +629,98 @@ class Smarty_Template_Source
{
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = null;
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = null;
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = null;
/**
* Unique Template ID
*
* @var string
*/
public $uid = null;
/**
* Template Resource (Smarty_Internal_Template::$template_resource)
*
* @var string
*/
public $resource = null;
/**
* Resource Type
*
* @var string
*/
public $type = null;
/**
* Resource Name
*
* @var string
*/
public $name = null;
/**
* Unique Resource Name
*
* @var string
*/
public $unique_resource = null;
/**
* Source Filepath
*
* @var string
*/
public $filepath = null;
/**
* Source is bypassing compiler
*
* @var boolean
*/
public $uncompiled = null;
/**
* Source must be recompiled on every occasion
*
* @var boolean
*/
public $recompiled = null;
/**
* The Components an extended template is made of
*
* @var array
*/
public $components = null;
/**
* Resource Handler
*
* @var Smarty_Resource
*/
public $handler = null;
/**
* Smarty instance
*
* @var Smarty
*/
public $smarty = null;
@ -706,7 +733,7 @@ class Smarty_Template_Source
* @param string $resource full template_resource
* @param string $type type of resource
* @param string $name resource name
* @param string $unique_resource unqiue resource name
* @param string $unique_resource unique resource name
*/
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
{
@ -728,10 +755,11 @@ class Smarty_Template_Source
/**
* get a Compiled Object of this source
*
* @param Smarty_Internal_Template $_template template objet
* @param Smarty_Internal_Template|Smarty_Internal_Config $_template template object
*
* @return Smarty_Template_Compiled compiled object
*/
public function getCompiled(Smarty_Internal_Template $_template)
public function getCompiled($_template)
{
// check runtime cache
$_cache_key = $this->unique_resource . '#' . $_template->compile_id;
@ -763,8 +791,9 @@ class Smarty_Template_Source
/**
* <<magic>> Generic Setter.
*
* @param string $property_name valid: timestamp, exists, content, template
* @param mixed $value new value (is not checked)
* @param string $property_name valid: timestamp, exists, content, template
* @param mixed $value new value (is not checked)
*
* @throws SmartyException if $property_name is not valid
*/
public function __set($property_name, $value)
@ -774,7 +803,7 @@ class Smarty_Template_Source
case 'timestamp':
case 'exists':
case 'content':
// required for extends: only
// required for extends: only
case 'template':
$this->$property_name = $value;
break;
@ -787,7 +816,8 @@ class Smarty_Template_Source
/**
* <<magic>> Generic getter.
*
* @param string $property_name valid: timestamp, exists, content
* @param string $property_name valid: timestamp, exists, content
*
* @return mixed
* @throws SmartyException if $property_name is not valid
*/
@ -807,62 +837,65 @@ class Smarty_Template_Source
throw new SmartyException("source property '$property_name' does not exist.");
}
}
}
/**
* Smarty Resource Data Object
*
* Meta Data Container for Template Files
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*
* @author Rodney Rehm
* @property string $content compiled content
*/
class Smarty_Template_Compiled
{
/**
* Compiled Filepath
*
* @var string
*/
public $filepath = null;
/**
* Compiled Timestamp
*
* @var integer
*/
public $timestamp = null;
/**
* Compiled Existence
*
* @var boolean
*/
public $exists = false;
/**
* Compiled Content Loaded
*
* @var boolean
*/
public $loaded = false;
/**
* Template was compiled
*
* @var boolean
*/
public $isCompiled = false;
/**
* Source Object
*
* @var Smarty_Template_Source
*/
public $source = null;
/**
* Metadata properties
*
* populated by Smarty_Internal_Template::decodeProperties()
*
* @var array
*/
public $_properties = null;
@ -876,5 +909,4 @@ class Smarty_Template_Compiled
{
$this->source = $source;
}
}

View file

@ -2,17 +2,16 @@
/**
* Smarty Resource Plugin
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @author Rodney Rehm
*/
/**
* Smarty Resource Plugin
*
* Wrapper Implementation for custom resource plugins
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource_Custom extends Smarty_Resource
@ -28,11 +27,11 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
/**
* Fetch template's modification timestamp from data source
*
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete template source.}}
*
* @param string $name template name
* @param string $name template name
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
protected function fetchTimestamp($name)
@ -46,9 +45,9 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = strtolower($source->type . ':' . $source->name);
$source->filepath = $source->type . ':' . $source->name;
$source->uid = sha1($source->type . ':' . $source->name);
$mtime = $this->fetchTimestamp($source->name);
@ -57,8 +56,9 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
} else {
$this->fetch($source->name, $content, $timestamp);
$source->timestamp = isset($timestamp) ? $timestamp : false;
if( isset($content) )
if (isset($content)) {
$source->content = $content;
}
}
$source->exists = !!$source->timestamp;
}
@ -67,6 +67,7 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
* Load template's source into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
@ -84,11 +85,11 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
{
return basename($source->name);
}
}

View file

@ -2,17 +2,16 @@
/**
* Smarty Resource Plugin
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @author Rodney Rehm
*/
/**
* Smarty Resource Plugin
*
* Base implementation for resource plugins that don't compile cache
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource_Recompiled extends Smarty_Resource
@ -22,6 +21,7 @@ abstract class Smarty_Resource_Recompiled extends Smarty_Resource
*
* @param Smarty_Template_Compiled $compiled compiled object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
@ -30,5 +30,4 @@ abstract class Smarty_Resource_Recompiled extends Smarty_Resource
$compiled->timestamp = false;
$compiled->exists = false;
}
}

View file

@ -2,17 +2,16 @@
/**
* Smarty Resource Plugin
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @author Rodney Rehm
*/
/**
* Smarty Resource Plugin
*
* Base implementation for resource plugins that don't use the compiler
*
* @package Smarty
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
@ -22,6 +21,7 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @throws SmartyException on failure
*/
abstract public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template);
@ -38,5 +38,4 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
$compiled->timestamp = false;
$compiled->exists = false;
}
}

View file

@ -2,9 +2,9 @@
/**
* Smarty plugin
*
* @package Smarty
* @package Smarty
* @subpackage Security
* @author Uwe Tews
* @author Uwe Tews
*/
/*
@ -56,17 +56,17 @@ class Smarty_Security
public $trusted_uri = array();
/**
* This is an array of trusted static classes.
*
* If empty access to all static classes is allowed.
* If set to 'none' none is allowed.
*
* @var array
*/
public $static_classes = array();
/**
* This is an array of trusted PHP functions.
*
* If empty all functions are allowed.
* To disable all PHP functions set $php_functions = null.
*
* @var array
*/
public $php_functions = array(
@ -78,9 +78,9 @@ class Smarty_Security
);
/**
* This is an array of trusted PHP modifiers.
*
* If empty all modifiers are allowed.
* To disable all modifier set $modifiers = null.
* To disable all modifier set $php_modifiers = null.
*
* @var array
*/
public $php_modifiers = array(
@ -89,78 +89,86 @@ class Smarty_Security
);
/**
* This is an array of allowed tags.
*
* If empty no restriction by allowed_tags.
*
* @var array
*/
public $allowed_tags = array();
/**
* This is an array of disabled tags.
*
* If empty no restriction by disabled_tags.
*
* @var array
*/
public $disabled_tags = array();
/**
* This is an array of allowed modifier plugins.
*
* If empty no restriction by allowed_modifiers.
*
* @var array
*/
public $allowed_modifiers = array();
/**
* This is an array of disabled modifier plugins.
*
* If empty no restriction by disabled_modifiers.
*
* @var array
*/
public $disabled_modifiers = array();
/**
* This is an array of trusted streams.
*
* If empty all streams are allowed.
* To disable all streams set $streams = null.
*
* @var array
*/
public $streams = array('file');
/**
* + flag if constants can be accessed from template
*
* @var boolean
*/
public $allow_constants = true;
/**
* + flag if super globals can be accessed from template
*
* @var boolean
*/
public $allow_super_globals = true;
/**
* Cache for $resource_dir lookups
* Cache for $resource_dir lookup
*
* @var array
*/
protected $_resource_dir = null;
/**
* Cache for $template_dir lookups
* Cache for $template_dir lookup
*
* @var array
*/
protected $_template_dir = null;
/**
* Cache for $config_dir lookups
* Cache for $config_dir lookup
*
* @var array
*/
protected $_config_dir = null;
/**
* Cache for $secure_dir lookups
* Cache for $secure_dir lookup
*
* @var array
*/
protected $_secure_dir = null;
/**
* Cache for $php_resource_dir lookups
* Cache for $php_resource_dir lookup
*
* @var array
*/
protected $_php_resource_dir = null;
/**
* Cache for $trusted_dir lookups
* Cache for $trusted_dir lookup
*
* @var array
*/
protected $_trusted_dir = null;
@ -176,8 +184,9 @@ class Smarty_Security
/**
* Check if PHP function is trusted.
*
* @param string $function_name
* @param object $compiler compiler object
* @param string $function_name
* @param object $compiler compiler object
*
* @return boolean true if function is trusted
* @throws SmartyCompilerException if php function is not trusted
*/
@ -195,8 +204,9 @@ class Smarty_Security
/**
* Check if static class is trusted.
*
* @param string $class_name
* @param object $compiler compiler object
* @param string $class_name
* @param object $compiler compiler object
*
* @return boolean true if class is trusted
* @throws SmartyCompilerException if static class is not trusted
*/
@ -214,8 +224,9 @@ class Smarty_Security
/**
* Check if PHP modifier is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
* @param string $modifier_name
* @param object $compiler compiler object
*
* @return boolean true if modifier is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/
@ -233,8 +244,9 @@ class Smarty_Security
/**
* Check if tag is trusted.
*
* @param string $tag_name
* @param object $compiler compiler object
* @param string $tag_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/
@ -242,7 +254,8 @@ class Smarty_Security
{
// check for internal always required tags
if (in_array($tag_name, array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin', 'private_object_block_function',
'private_object_function', 'private_registered_function', 'private_registered_block', 'private_special_variable', 'private_print_expression', 'private_modifier'))) {
'private_object_function', 'private_registered_function', 'private_registered_block', 'private_special_variable', 'private_print_expression', 'private_modifier'))
) {
return true;
}
// check security settings
@ -264,8 +277,9 @@ class Smarty_Security
/**
* Check if modifier plugin is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
* @param string $modifier_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/
@ -294,7 +308,8 @@ class Smarty_Security
/**
* Check if stream is trusted.
*
* @param string $stream_name
* @param string $stream_name
*
* @return boolean true if stream is trusted
* @throws SmartyException if stream is not trusted
*/
@ -310,7 +325,8 @@ class Smarty_Security
/**
* Check if directory of file resource is trusted.
*
* @param string $filepath
* @param string $filepath
*
* @return boolean true if directory is trusted
* @throws SmartyException if directory is not trusted
*/
@ -325,8 +341,8 @@ class Smarty_Security
// check if index is outdated
if ((!$this->_template_dir || $this->_template_dir !== $_template_dir)
|| (!$this->_config_dir || $this->_config_dir !== $_config_dir)
|| (!empty($this->secure_dir) && (!$this->_secure_dir || $this->_secure_dir !== $this->secure_dir))
|| (!$this->_config_dir || $this->_config_dir !== $_config_dir)
|| (!empty($this->secure_dir) && (!$this->_secure_dir || $this->_secure_dir !== $this->secure_dir))
) {
$this->_resource_dir = array();
$_template = true;
@ -369,7 +385,7 @@ class Smarty_Security
$_directory[$directory] = true;
// test if the directory is trusted
if (isset($this->_resource_dir[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookups
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$this->_resource_dir = array_merge($this->_resource_dir, $_directory);
return true;
@ -388,11 +404,12 @@ class Smarty_Security
/**
* Check if URI (e.g. {fetch} or {html_image}) is trusted
*
* To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}".
* So "http://username:password@hello.world.example.org:8080/some-path?some=query-string"
* is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}.
* @param string $uri
*
* @param string $uri
*
* @return boolean true if URI is trusted
* @throws SmartyException if URI is not trusted
* @uses $trusted_uri for list of patterns to match against $uri
@ -415,7 +432,8 @@ class Smarty_Security
/**
* Check if directory of file resource is trusted.
*
* @param string $filepath
* @param string $filepath
*
* @return boolean true if directory is trusted
* @throws SmartyException if PHP directory is not trusted
*/
@ -444,7 +462,7 @@ class Smarty_Security
$_directory[] = $directory;
// test if the directory is trusted
if (isset($this->_php_resource_dir[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookups
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory);
return true;
@ -459,5 +477,4 @@ class Smarty_Security
throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
}
}