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_registered.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Registered
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource Registered
  12. * Implements the registered resource for Smarty template
  13. *
  14. * @package Smarty
  15. * @subpackage TemplateResources
  16. * @deprecated
  17. */
  18. class Smarty_Internal_Resource_Registered 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->filepath = $source->type . ':' . $source->name;
  31. $source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir);
  32. $source->timestamp = $this->getTemplateTimestamp($source);
  33. $source->exists = !!$source->timestamp;
  34. }
  35. /**
  36. * populate Source Object with timestamp and exists from Resource
  37. *
  38. * @param Smarty_Template_Source $source source object
  39. *
  40. * @return void
  41. */
  42. public function populateTimestamp(Smarty_Template_Source $source)
  43. {
  44. $source->timestamp = $this->getTemplateTimestamp($source);
  45. $source->exists = !!$source->timestamp;
  46. }
  47. /**
  48. * Get timestamp (epoch) the template source was modified
  49. *
  50. * @param Smarty_Template_Source $source source object
  51. *
  52. * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
  53. */
  54. public function getTemplateTimestamp(Smarty_Template_Source $source)
  55. {
  56. // return timestamp
  57. $time_stamp = false;
  58. call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ],
  59. array($source->name, &$time_stamp, $source->smarty));
  60. return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp;
  61. }
  62. /**
  63. * Load template's source by invoking the registered callback into current template object
  64. *
  65. * @param Smarty_Template_Source $source source object
  66. *
  67. * @return string template source
  68. * @throws SmartyException if source cannot be loaded
  69. */
  70. public function getContent(Smarty_Template_Source $source)
  71. {
  72. // return template string
  73. $content = null;
  74. $t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ],
  75. array($source->name, &$content, $source->smarty));
  76. if (is_bool($t) && !$t) {
  77. throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
  78. }
  79. return $content;
  80. }
  81. /**
  82. * Determine basename for compiled filename
  83. *
  84. * @param Smarty_Template_Source $source source object
  85. *
  86. * @return string resource's basename
  87. */
  88. public function getBasename(Smarty_Template_Source $source)
  89. {
  90. return basename($source->name);
  91. }
  92. }