You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_resource_string.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource String
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource String
  12. * Implements the strings as resource for Smarty template
  13. * {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
  14. *
  15. * @package Smarty
  16. * @subpackage TemplateResources
  17. */
  18. class Smarty_Internal_Resource_String extends Smarty_Resource
  19. {
  20. /**
  21. * populate Source Object with meta data from Resource
  22. *
  23. * @param Smarty_Template_Source $source source object
  24. * @param Smarty_Internal_Template $_template template object
  25. *
  26. * @return void
  27. */
  28. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
  29. {
  30. $source->uid = $source->filepath = sha1($source->name);
  31. $source->timestamp = 0;
  32. $source->exists = true;
  33. }
  34. /**
  35. * Load template's source from $resource_name into current template object
  36. *
  37. * @uses decode() to decode base64 and urlencoded template_resources
  38. *
  39. * @param Smarty_Template_Source $source source object
  40. *
  41. * @return string template source
  42. */
  43. public function getContent(Smarty_Template_Source $source)
  44. {
  45. return $this->decode($source->name);
  46. }
  47. /**
  48. * decode base64 and urlencode
  49. *
  50. * @param string $string template_resource to decode
  51. *
  52. * @return string decoded template_resource
  53. */
  54. protected function decode($string)
  55. {
  56. // decode if specified
  57. if (($pos = strpos($string, ':')) !== false) {
  58. if (!strncmp($string, 'base64', 6)) {
  59. return base64_decode(substr($string, 7));
  60. } elseif (!strncmp($string, 'urlencode', 9)) {
  61. return urldecode(substr($string, 10));
  62. }
  63. }
  64. return $string;
  65. }
  66. /**
  67. * modify resource_name according to resource handlers specifications
  68. *
  69. * @param Smarty $smarty Smarty instance
  70. * @param string $resource_name resource_name to make unique
  71. * @param boolean $isConfig flag for config resource
  72. *
  73. * @return string unique resource name
  74. */
  75. public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
  76. {
  77. return get_class($this) . '#' . $this->decode($resource_name);
  78. }
  79. /**
  80. * Determine basename for compiled filename
  81. * Always returns an empty string.
  82. *
  83. * @param Smarty_Template_Source $source source object
  84. *
  85. * @return string resource's basename
  86. */
  87. public function getBasename(Smarty_Template_Source $source)
  88. {
  89. return '';
  90. }
  91. }