2012-07-04 07:23:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Resource String
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage TemplateResources
|
2014-09-07 13:38:28 +02:00
|
|
|
* @author Uwe Tews
|
|
|
|
* @author Rodney Rehm
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}}
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage TemplateResources
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
class Smarty_Internal_Resource_String extends Smarty_Resource
|
|
|
|
{
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* populate Source Object with meta data from Resource
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param Smarty_Template_Source $source source object
|
|
|
|
* @param Smarty_Internal_Template $_template template object
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
2012-07-04 07:23:08 +02:00
|
|
|
{
|
|
|
|
$source->uid = $source->filepath = sha1($source->name);
|
|
|
|
$source->timestamp = 0;
|
|
|
|
$source->exists = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load template's source from $resource_name into current template object
|
|
|
|
*
|
|
|
|
* @uses decode() to decode base64 and urlencoded template_resources
|
2014-09-07 13:38:28 +02:00
|
|
|
*
|
|
|
|
* @param Smarty_Template_Source $source source object
|
|
|
|
*
|
|
|
|
* @return string template source
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
public function getContent(Smarty_Template_Source $source)
|
|
|
|
{
|
|
|
|
return $this->decode($source->name);
|
|
|
|
}
|
2014-09-07 13:38:28 +02:00
|
|
|
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* decode base64 and urlencode
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param string $string template_resource to decode
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @return string decoded template_resource
|
|
|
|
*/
|
|
|
|
protected function decode($string)
|
|
|
|
{
|
|
|
|
// decode if specified
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 13:38:28 +02:00
|
|
|
|
2012-07-04 07:23:08 +02:00
|
|
|
return $string;
|
|
|
|
}
|
2014-09-07 13:38:28 +02:00
|
|
|
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* modify resource_name according to resource handlers specifications
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param Smarty $smarty Smarty instance
|
|
|
|
* @param string $resource_name resource_name to make unique
|
|
|
|
* @param boolean $is_config flag for config resource
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @return string unique resource name
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
|
2012-07-04 07:23:08 +02:00
|
|
|
{
|
2014-09-07 13:38:28 +02:00
|
|
|
return get_class($this) . '#' . $this->decode($resource_name);
|
2012-07-04 07:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine basename for compiled filename
|
|
|
|
* Always returns an empty string.
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param Smarty_Template_Source $source source object
|
|
|
|
*
|
|
|
|
* @return string resource's basename
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
protected function getBasename(Smarty_Template_Source $source)
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|