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_template_resource_base.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Smarty Template Resource Base Object
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Rodney Rehm
  8. */
  9. abstract class Smarty_Template_Resource_Base
  10. {
  11. /**
  12. * Compiled Filepath
  13. *
  14. * @var string
  15. */
  16. public $filepath = null;
  17. /**
  18. * Compiled Timestamp
  19. *
  20. * @var integer|bool
  21. */
  22. public $timestamp = false;
  23. /**
  24. * Compiled Existence
  25. *
  26. * @var boolean
  27. */
  28. public $exists = false;
  29. /**
  30. * Template Compile Id (Smarty_Internal_Template::$compile_id)
  31. *
  32. * @var string
  33. */
  34. public $compile_id = null;
  35. /**
  36. * Compiled Content Loaded
  37. *
  38. * @var boolean
  39. */
  40. public $processed = false;
  41. /**
  42. * unique function name for compiled template code
  43. *
  44. * @var string
  45. */
  46. public $unifunc = '';
  47. /**
  48. * flag if template does contain nocache code sections
  49. *
  50. * @var bool
  51. */
  52. public $has_nocache_code = false;
  53. /**
  54. * resource file dependency
  55. *
  56. * @var array
  57. */
  58. public $file_dependency = array();
  59. /**
  60. * Content buffer
  61. *
  62. * @var string
  63. */
  64. public $content = null;
  65. /**
  66. * Included sub templates
  67. * - index name
  68. * - value use count
  69. *
  70. * @var int[]
  71. */
  72. public $includes = array();
  73. /**
  74. * Flag if this is a cache resource
  75. *
  76. * @var bool
  77. */
  78. public $isCache = false;
  79. /**
  80. * Process resource
  81. *
  82. * @param Smarty_Internal_Template $_template template object
  83. */
  84. abstract public function process(Smarty_Internal_Template $_template);
  85. /**
  86. * get rendered template content by calling compiled or cached template code
  87. *
  88. * @param \Smarty_Internal_Template $_template
  89. * @param string $unifunc function with template code
  90. *
  91. * @throws \Exception
  92. */
  93. public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
  94. {
  95. $smarty = &$_template->smarty;
  96. $_template->isRenderingCache = $this->isCache;
  97. $level = ob_get_level();
  98. try {
  99. if (!isset($unifunc)) {
  100. $unifunc = $this->unifunc;
  101. }
  102. if (empty($unifunc) || !function_exists($unifunc)) {
  103. throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
  104. }
  105. if ($_template->startRenderCallbacks) {
  106. foreach ($_template->startRenderCallbacks as $callback) {
  107. call_user_func($callback, $_template);
  108. }
  109. }
  110. $unifunc($_template);
  111. foreach ($_template->endRenderCallbacks as $callback) {
  112. call_user_func($callback, $_template);
  113. }
  114. $_template->isRenderingCache = false;
  115. }
  116. catch (Exception $e) {
  117. $_template->isRenderingCache = false;
  118. while (ob_get_level() > $level) {
  119. ob_end_clean();
  120. }
  121. if (isset($smarty->security_policy)) {
  122. $smarty->security_policy->endTemplate();
  123. }
  124. throw $e;
  125. }
  126. }
  127. /**
  128. * Get compiled time stamp
  129. *
  130. * @return int
  131. */
  132. public function getTimeStamp()
  133. {
  134. if ($this->exists && !$this->timestamp) {
  135. $this->timestamp = filemtime($this->filepath);
  136. }
  137. return $this->timestamp;
  138. }
  139. }