smarty_internal_resource_eval.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Eval
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource Eval
  12. *
  13. * Implements the strings as resource for Smarty template
  14. *
  15. * {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}}
  16. *
  17. * @package Smarty
  18. * @subpackage TemplateResources
  19. */
  20. class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled {
  21. /**
  22. * populate Source Object with meta data from Resource
  23. *
  24. * @param Smarty_Template_Source $source source object
  25. * @param Smarty_Internal_Template $_template template object
  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 = false;
  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. * @param Smarty_Template_Source $source source object
  39. * @return string template source
  40. */
  41. public function getContent(Smarty_Template_Source $source)
  42. {
  43. return $this->decode($source->name);
  44. }
  45. /**
  46. * decode base64 and urlencode
  47. *
  48. * @param string $string template_resource to decode
  49. * @return string decoded template_resource
  50. */
  51. protected function decode($string)
  52. {
  53. // decode if specified
  54. if (($pos = strpos($string, ':')) !== false) {
  55. if (!strncmp($string, 'base64', 6)) {
  56. return base64_decode(substr($string, 7));
  57. } elseif (!strncmp($string, 'urlencode', 9)) {
  58. return urldecode(substr($string, 10));
  59. }
  60. }
  61. return $string;
  62. }
  63. /**
  64. * modify resource_name according to resource handlers specifications
  65. *
  66. * @param Smarty $smarty Smarty instance
  67. * @param string $resource_name resource_name to make unique
  68. * @return string unique resource name
  69. */
  70. protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
  71. {
  72. return get_class($this) . '#' .$this->decode($resource_name);
  73. }
  74. /**
  75. * Determine basename for compiled filename
  76. *
  77. * @param Smarty_Template_Source $source source object
  78. * @return string resource's basename
  79. */
  80. protected function getBasename(Smarty_Template_Source $source)
  81. {
  82. return '';
  83. }
  84. }
  85. ?>