mirror of
https://github.com/smarty-php/smarty.git
synced 2026-04-21 00:48:47 +02:00
- add concept unique_resource to combat potentially ambiguous template_resource values when custom resource handlers are used (Forum Topic 2012)
http://www.smarty.net/forums/viewtopic.php?t=2012 thereby DRYed and optimized the resource handler identification method.
This commit is contained in:
@@ -37,24 +37,45 @@ class Smarty_Internal_Resource_String extends Smarty_Resource {
|
||||
/**
|
||||
* Load template's source from $resource_name into current template object
|
||||
*
|
||||
* {@internal if source begins with "base64:" or "urlencode:", the source is decoded accordingly}}
|
||||
*
|
||||
* @uses decode() to decode base64 and urlencoded template_resources
|
||||
* @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)
|
||||
{
|
||||
return $this->decode($source->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode base64 and urlencode
|
||||
*
|
||||
* @param string $string template_resource to decode
|
||||
* @return string decoded template_resource
|
||||
*/
|
||||
protected function decode($string)
|
||||
{
|
||||
// decode if specified
|
||||
if (($pos = strpos($source->name, ':')) !== false) {
|
||||
if (!strncmp($source->name, 'base64', 6)) {
|
||||
return base64_decode(substr($source->name, 7));
|
||||
} elseif (!strncmp($source->name, 'urlencode', 9)) {
|
||||
return urldecode(substr($source->name, 10));
|
||||
if (($pos = strpos($string, ':')) !== false) {
|
||||
if (!strncmp($string, 'base64', 6)) {
|
||||
return base64_decode(substr($string, 7));
|
||||
} elseif (!strncmp($string, 'urlencode', 9)) {
|
||||
return urldecode(substr($string, 10));
|
||||
}
|
||||
}
|
||||
|
||||
return $source->name;
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @return string unique resource name
|
||||
*/
|
||||
protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
|
||||
{
|
||||
return get_class($this) . '#' .$this->decode($resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user