Revision: 4094
Author: rodneyrehm
Date: Mon May 23 06:16:34 2011
Log: added base64: and urlencode: arguments to eval and string
resource types
both resource handlers now translate
»string:urlencode:%7B%22foobar%22%7Cescape%7D« and
»string:base64:eyJmb29iYXIifGVzY2FwZX0=« to
»string:{"foobar"|escape}«.
This measure was taken so eval and string resource types may me used with
extends resource type without breaking the | (pipe) delimiter used by
extends as well as a modifier activation within an eval or string resource
http://code.google.com/p/smarty-php/source/detail?r=4094
Modified:
/branches/rodneyrehm/development/PHPunit/EvalResourceTests.php
/branches/rodneyrehm/development/PHPunit/StringResourceTests.php
/branches/rodneyrehm/distribution/change_log.txt
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_eval.php
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_string.php
=======================================
--- /branches/rodneyrehm/development/PHPunit/EvalResourceTests.php Mon May
23 06:00:49 2011
+++ /branches/rodneyrehm/development/PHPunit/EvalResourceTests.php Mon May
23 06:16:34 2011
@@ -163,6 +163,18 @@
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertFalse($this->smarty->isCached($tpl));
}
+
+ public function testUrlencodeTemplate()
+ {
+ $tpl =
$this->smarty->createTemplate('eval:urlencode:%7B%22foobar%22%7Cescape%7D');
+ $this->assertEquals('foobar', $tpl->fetch());
+ }
+
+ public function testBase64Template()
+ {
+ $tpl =
$this->smarty->createTemplate('eval:base64:eyJmb29iYXIifGVzY2FwZX0=');
+ $this->assertEquals('foobar', $tpl->fetch());
+ }
}
?>
=======================================
--- /branches/rodneyrehm/development/PHPunit/StringResourceTests.php Mon
May 23 06:00:49 2011
+++ /branches/rodneyrehm/development/PHPunit/StringResourceTests.php Mon
May 23 06:16:34 2011
@@ -169,7 +169,19 @@
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertTrue($this->smarty->isCached($tpl));
- }
+ }
+
+ public function testUrlencodeTemplate()
+ {
+ $tpl =
$this->smarty->createTemplate('string:urlencode:%7B%22foobar%22%7Cescape%7D');
+ $this->assertEquals('foobar', $tpl->fetch());
+ }
+
+ public function testBase64Template()
+ {
+ $tpl =
$this->smarty->createTemplate('string:base64:eyJmb29iYXIifGVzY2FwZX0=');
+ $this->assertEquals('foobar', $tpl->fetch());
+ }
}
?>
=======================================
--- /branches/rodneyrehm/distribution/change_log.txt Sun May 22 04:30:16
2011
+++ /branches/rodneyrehm/distribution/change_log.txt Mon May 23 06:16:34
2011
@@ -1,4 +1,7 @@
===== SVN branch rodneyrehm =====
+23/05/2011
+- added base64: and urlencode: arguments to eval and string resource types
+
22/05/2011
- made time-attribute of {html_select_date} and {html_select_time} accept
arrays as defined by attributes prefix and field_array
=======================================
---
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_eval.php
Mon May 23 06:00:49 2011
+++
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_eval.php
Mon May 23 06:16:34 2011
@@ -30,13 +30,22 @@
/**
* Load template's source from $resource_name into current template
object
*
+ * @note if source begins with "base64:" or "urlencode:", the source
is decoded accordingly
* @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 template 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));
+ }
+ }
+
return $source->name;
}
=======================================
---
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_string.php
Mon May 23 06:00:49 2011
+++
/branches/rodneyrehm/distribution/libs/sysplugins/smarty_internal_resource_string.php
Mon May 23 06:16:34 2011
@@ -30,12 +30,22 @@
/**
* Load template's source from $resource_name into current template
object
*
+ * @note if source begins with "base64:" or "urlencode:", the source
is decoded accordingly
* @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)
- {
+ {
+ // 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));
+ }
+ }
+
return $source->name;
}