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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 . $source->smarty->_joined_template_dir);
  31. $source->timestamp = $source->exists = true;
  32. }
  33. /**
  34. * Load template's source from $resource_name into current template object
  35. *
  36. * @uses decode() to decode base64 and urlencoded template_resources
  37. *
  38. * @param Smarty_Template_Source $source source object
  39. *
  40. * @return string template source
  41. */
  42. public function getContent(Smarty_Template_Source $source)
  43. {
  44. return $this->decode($source->name);
  45. }
  46. /**
  47. * decode base64 and urlencode
  48. *
  49. * @param string $string template_resource to decode
  50. *
  51. * @return string decoded template_resource
  52. */
  53. protected function decode($string)
  54. {
  55. // decode if specified
  56. if (($pos = strpos($string, ':')) !== false) {
  57. if (!strncmp($string, 'base64', 6)) {
  58. return base64_decode(substr($string, 7));
  59. } elseif (!strncmp($string, 'urlencode', 9)) {
  60. return urldecode(substr($string, 10));
  61. }
  62. }
  63. return $string;
  64. }
  65. /**
  66. * modify resource_name according to resource handlers specifications
  67. *
  68. * @param Smarty $smarty Smarty instance
  69. * @param string $resource_name resource_name to make unique
  70. * @param boolean $isConfig flag for config resource
  71. *
  72. * @return string unique resource name
  73. */
  74. public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
  75. {
  76. return get_class($this) . '#' . $this->decode($resource_name);
  77. }
  78. /**
  79. * Determine basename for compiled filename
  80. * Always returns an empty string.
  81. *
  82. * @param Smarty_Template_Source $source source object
  83. *
  84. * @return string resource's basename
  85. */
  86. public function getBasename(Smarty_Template_Source $source)
  87. {
  88. return '';
  89. }
  90. /*
  91. * Disable timestamp checks for string resource.
  92. *
  93. * @return bool
  94. */
  95. /**
  96. * @return bool
  97. */
  98. public function checkTimestamps()
  99. {
  100. return false;
  101. }
  102. }