Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

smarty_template_resource_base.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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
  21. */
  22. public $timestamp = null;
  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. * required plugins
  67. *
  68. * @var array
  69. */
  70. public $required_plugins = array();
  71. /**
  72. * Included subtemplates
  73. *
  74. * @var array
  75. */
  76. public $includes = array();
  77. /**
  78. * Process resource
  79. *
  80. * @param Smarty_Internal_Template $_template template object
  81. */
  82. abstract public function process(Smarty_Internal_Template $_template);
  83. /**
  84. * get rendered template content by calling compiled or cached template code
  85. *
  86. * @param string $unifunc function with template code
  87. *
  88. * @return string
  89. * @throws \Exception
  90. */
  91. public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
  92. {
  93. $unifunc = isset($unifunc) ? $unifunc : $this->unifunc;
  94. $level = ob_get_level();
  95. try {
  96. if (empty($unifunc) || !is_callable($unifunc)) {
  97. throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
  98. }
  99. if (isset($_template->smarty->security_policy)) {
  100. $_template->smarty->security_policy->startTemplate($_template);
  101. }
  102. //
  103. // render compiled or saved template code
  104. //
  105. if (!isset($_template->_cache['capture_stack'])) {
  106. $_template->_cache['capture_stack'] = array();
  107. }
  108. $_saved_capture_level = count($_template->_cache['capture_stack']);
  109. $unifunc($_template);
  110. // any unclosed {capture} tags ?
  111. if ($_saved_capture_level != count($_template->_cache['capture_stack'])) {
  112. $_template->capture_error();
  113. }
  114. if (isset($_template->smarty->security_policy)) {
  115. $_template->smarty->security_policy->exitTemplate();
  116. }
  117. return null;
  118. }
  119. catch (Exception $e) {
  120. while (ob_get_level() > $level) {
  121. ob_end_clean();
  122. }
  123. if (isset($_template->smarty->security_policy)) {
  124. $_template->smarty->security_policy->exitTemplate();
  125. }
  126. throw $e;
  127. }
  128. }
  129. /**
  130. * Get compiled time stamp
  131. *
  132. * @return int
  133. */
  134. public function getTimeStamp()
  135. {
  136. if ($this->exists && !isset($this->timestamp)) {
  137. $this->timestamp = @filemtime($this->filepath);
  138. }
  139. return $this->timestamp;
  140. }
  141. }