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_security.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @package Smarty
  6. * @subpackage Security
  7. * @author Uwe Tews
  8. */
  9. /*
  10. * FIXME: Smarty_Security API
  11. * - getter and setter instead of public properties would allow cultivating an internal cache properly
  12. * - current implementation of isTrustedResourceDir() assumes that Smarty::$template_dir and Smarty::$config_dir are immutable
  13. * the cache is killed every time either of the variables change. That means that two distinct Smarty objects with differing
  14. * $template_dir or $config_dir should NOT share the same Smarty_Security instance,
  15. * as this would lead to (severe) performance penalty! how should this be handled?
  16. */
  17. /**
  18. * This class does contain the security settings
  19. */
  20. class Smarty_Security
  21. {
  22. /**
  23. * This determines how Smarty handles "<?php ... ?>" tags in templates.
  24. * possible values:
  25. * <ul>
  26. * <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li>
  27. * <li>Smarty::PHP_QUOTE -> escape tags as entities</li>
  28. * <li>Smarty::PHP_REMOVE -> remove php tags</li>
  29. * <li>Smarty::PHP_ALLOW -> execute php tags</li>
  30. * </ul>
  31. *
  32. * @var integer
  33. */
  34. public $php_handling = Smarty::PHP_PASSTHRU;
  35. /**
  36. * This is the list of template directories that are considered secure.
  37. * $template_dir is in this list implicitly.
  38. *
  39. * @var array
  40. */
  41. public $secure_dir = array();
  42. /**
  43. * This is an array of directories where trusted php scripts reside.
  44. * {@link $security} is disabled during their inclusion/execution.
  45. *
  46. * @var array
  47. */
  48. public $trusted_dir = array();
  49. /**
  50. * List of regular expressions (PCRE) that include trusted URIs
  51. *
  52. * @var array
  53. */
  54. public $trusted_uri = array();
  55. /**
  56. * List of trusted constants names
  57. *
  58. * @var array
  59. */
  60. public $trusted_constants = array();
  61. /**
  62. * This is an array of trusted static classes.
  63. * If empty access to all static classes is allowed.
  64. * If set to 'none' none is allowed.
  65. *
  66. * @var array
  67. */
  68. public $static_classes = array();
  69. /**
  70. * This is an nested array of trusted classes and static methods.
  71. * If empty access to all static classes and methods is allowed.
  72. * Format:
  73. * array (
  74. * 'class_1' => array('method_1', 'method_2'), // allowed methods listed
  75. * 'class_2' => array(), // all methods of class allowed
  76. * )
  77. * If set to null none is allowed.
  78. *
  79. * @var array
  80. */
  81. public $trusted_static_methods = array();
  82. /**
  83. * This is an array of trusted static properties.
  84. * If empty access to all static classes and properties is allowed.
  85. * Format:
  86. * array (
  87. * 'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
  88. * 'class_2' => array(), // all properties of class allowed
  89. * )
  90. * If set to null none is allowed.
  91. *
  92. * @var array
  93. */
  94. public $trusted_static_properties = array();
  95. /**
  96. * This is an array of trusted PHP functions.
  97. * If empty all functions are allowed.
  98. * To disable all PHP functions set $php_functions = null.
  99. *
  100. * @var array
  101. */
  102. public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',);
  103. /**
  104. * This is an array of trusted PHP modifiers.
  105. * If empty all modifiers are allowed.
  106. * To disable all modifier set $php_modifiers = null.
  107. *
  108. * @var array
  109. */
  110. public $php_modifiers = array('escape', 'count', 'nl2br',);
  111. /**
  112. * This is an array of allowed tags.
  113. * If empty no restriction by allowed_tags.
  114. *
  115. * @var array
  116. */
  117. public $allowed_tags = array();
  118. /**
  119. * This is an array of disabled tags.
  120. * If empty no restriction by disabled_tags.
  121. *
  122. * @var array
  123. */
  124. public $disabled_tags = array();
  125. /**
  126. * This is an array of allowed modifier plugins.
  127. * If empty no restriction by allowed_modifiers.
  128. *
  129. * @var array
  130. */
  131. public $allowed_modifiers = array();
  132. /**
  133. * This is an array of disabled modifier plugins.
  134. * If empty no restriction by disabled_modifiers.
  135. *
  136. * @var array
  137. */
  138. public $disabled_modifiers = array();
  139. /**
  140. * This is an array of disabled special $smarty variables.
  141. *
  142. * @var array
  143. */
  144. public $disabled_special_smarty_vars = array();
  145. /**
  146. * This is an array of trusted streams.
  147. * If empty all streams are allowed.
  148. * To disable all streams set $streams = null.
  149. *
  150. * @var array
  151. */
  152. public $streams = array('file');
  153. /**
  154. * + flag if constants can be accessed from template
  155. *
  156. * @var boolean
  157. */
  158. public $allow_constants = true;
  159. /**
  160. * + flag if super globals can be accessed from template
  161. *
  162. * @var boolean
  163. */
  164. public $allow_super_globals = true;
  165. /**
  166. * max template nesting level
  167. *
  168. * @var int
  169. */
  170. public $max_template_nesting = 0;
  171. /**
  172. * current template nesting level
  173. *
  174. * @var int
  175. */
  176. private $_current_template_nesting = 0;
  177. /**
  178. * Cache for $resource_dir lookup
  179. *
  180. * @var array
  181. */
  182. protected $_resource_dir = array();
  183. /**
  184. * Cache for $template_dir lookup
  185. *
  186. * @var array
  187. */
  188. protected $_template_dir = array();
  189. /**
  190. * Cache for $config_dir lookup
  191. *
  192. * @var array
  193. */
  194. protected $_config_dir = array();
  195. /**
  196. * Cache for $secure_dir lookup
  197. *
  198. * @var array
  199. */
  200. protected $_secure_dir = array();
  201. /**
  202. * Cache for $php_resource_dir lookup
  203. *
  204. * @var array
  205. */
  206. protected $_php_resource_dir = null;
  207. /**
  208. * Cache for $trusted_dir lookup
  209. *
  210. * @var array
  211. */
  212. protected $_trusted_dir = null;
  213. /**
  214. * Cache for include path status
  215. *
  216. * @var bool
  217. */
  218. protected $_include_path_status = false;
  219. /**
  220. * Cache for $_include_array lookup
  221. *
  222. * @var array
  223. */
  224. protected $_include_dir = array();
  225. /**
  226. * @param Smarty $smarty
  227. */
  228. public function __construct($smarty)
  229. {
  230. $this->smarty = $smarty;
  231. $this->smarty->_cache[ 'template_dir_new' ] = true;
  232. $this->smarty->_cache[ 'config_dir_new' ] = true;
  233. }
  234. /**
  235. * Check if PHP function is trusted.
  236. *
  237. * @param string $function_name
  238. * @param object $compiler compiler object
  239. *
  240. * @return boolean true if function is trusted
  241. * @throws SmartyCompilerException if php function is not trusted
  242. */
  243. public function isTrustedPhpFunction($function_name, $compiler)
  244. {
  245. if (isset($this->php_functions) &&
  246. (empty($this->php_functions) || in_array($function_name, $this->php_functions))
  247. ) {
  248. return true;
  249. }
  250. $compiler->trigger_template_error("PHP function '{$function_name}' not allowed by security setting");
  251. return false; // should not, but who knows what happens to the compiler in the future?
  252. }
  253. /**
  254. * Check if static class is trusted.
  255. *
  256. * @param string $class_name
  257. * @param object $compiler compiler object
  258. *
  259. * @return boolean true if class is trusted
  260. * @throws SmartyCompilerException if static class is not trusted
  261. */
  262. public function isTrustedStaticClass($class_name, $compiler)
  263. {
  264. if (isset($this->static_classes) &&
  265. (empty($this->static_classes) || in_array($class_name, $this->static_classes))
  266. ) {
  267. return true;
  268. }
  269. $compiler->trigger_template_error("access to static class '{$class_name}' not allowed by security setting");
  270. return false; // should not, but who knows what happens to the compiler in the future?
  271. }
  272. /**
  273. * Check if static class method/property is trusted.
  274. *
  275. * @param string $class_name
  276. * @param string $params
  277. * @param object $compiler compiler object
  278. *
  279. * @return boolean true if class method is trusted
  280. * @throws SmartyCompilerException if static class method is not trusted
  281. */
  282. public function isTrustedStaticClassAccess($class_name, $params, $compiler)
  283. {
  284. if (!isset($params[ 2 ])) {
  285. // fall back
  286. return $this->isTrustedStaticClass($class_name, $compiler);
  287. }
  288. if ($params[ 2 ] === 'method') {
  289. $allowed = $this->trusted_static_methods;
  290. $name = substr($params[ 0 ], 0, strpos($params[ 0 ], '('));
  291. } else {
  292. $allowed = $this->trusted_static_properties;
  293. // strip '$'
  294. $name = substr($params[ 0 ], 1);
  295. }
  296. if (isset($allowed)) {
  297. if (empty($allowed)) {
  298. // fall back
  299. return $this->isTrustedStaticClass($class_name, $compiler);
  300. }
  301. if (isset($allowed[ $class_name ]) &&
  302. (empty($allowed[ $class_name ]) || in_array($name, $allowed[ $class_name ]))
  303. ) {
  304. return true;
  305. }
  306. }
  307. $compiler->trigger_template_error("access to static class '{$class_name}' {$params[2]} '{$name}' not allowed by security setting");
  308. return false; // should not, but who knows what happens to the compiler in the future?
  309. }
  310. /**
  311. * Check if PHP modifier is trusted.
  312. *
  313. * @param string $modifier_name
  314. * @param object $compiler compiler object
  315. *
  316. * @return boolean true if modifier is trusted
  317. * @throws SmartyCompilerException if modifier is not trusted
  318. */
  319. public function isTrustedPhpModifier($modifier_name, $compiler)
  320. {
  321. if (isset($this->php_modifiers) &&
  322. (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))
  323. ) {
  324. return true;
  325. }
  326. $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting");
  327. return false; // should not, but who knows what happens to the compiler in the future?
  328. }
  329. /**
  330. * Check if tag is trusted.
  331. *
  332. * @param string $tag_name
  333. * @param object $compiler compiler object
  334. *
  335. * @return boolean true if tag is trusted
  336. * @throws SmartyCompilerException if modifier is not trusted
  337. */
  338. public function isTrustedTag($tag_name, $compiler)
  339. {
  340. // check for internal always required tags
  341. if (in_array($tag_name,
  342. array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin',
  343. 'private_object_block_function', 'private_object_function', 'private_registered_function',
  344. 'private_registered_block', 'private_special_variable', 'private_print_expression',
  345. 'private_modifier'))) {
  346. return true;
  347. }
  348. // check security settings
  349. if (empty($this->allowed_tags)) {
  350. if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
  351. return true;
  352. } else {
  353. $compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
  354. }
  355. } elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
  356. return true;
  357. } else {
  358. $compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
  359. }
  360. return false; // should not, but who knows what happens to the compiler in the future?
  361. }
  362. /**
  363. * Check if special $smarty variable is trusted.
  364. *
  365. * @param string $var_name
  366. * @param object $compiler compiler object
  367. *
  368. * @return boolean true if tag is trusted
  369. * @throws SmartyCompilerException if modifier is not trusted
  370. */
  371. public function isTrustedSpecialSmartyVar($var_name, $compiler)
  372. {
  373. if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
  374. return true;
  375. } else {
  376. $compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting",
  377. null, true);
  378. }
  379. return false; // should not, but who knows what happens to the compiler in the future?
  380. }
  381. /**
  382. * Check if modifier plugin is trusted.
  383. *
  384. * @param string $modifier_name
  385. * @param object $compiler compiler object
  386. *
  387. * @return boolean true if tag is trusted
  388. * @throws SmartyCompilerException if modifier is not trusted
  389. */
  390. public function isTrustedModifier($modifier_name, $compiler)
  391. {
  392. // check for internal always allowed modifier
  393. if (in_array($modifier_name, array('default'))) {
  394. return true;
  395. }
  396. // check security settings
  397. if (empty($this->allowed_modifiers)) {
  398. if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
  399. return true;
  400. } else {
  401. $compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null,
  402. true);
  403. }
  404. } elseif (in_array($modifier_name, $this->allowed_modifiers) &&
  405. !in_array($modifier_name, $this->disabled_modifiers)
  406. ) {
  407. return true;
  408. } else {
  409. $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null,
  410. true);
  411. }
  412. return false; // should not, but who knows what happens to the compiler in the future?
  413. }
  414. /**
  415. * Check if constants are enabled or trusted
  416. *
  417. * @param string $const constant name
  418. * @param object $compiler compiler object
  419. *
  420. * @return bool
  421. */
  422. public function isTrustedConstant($const, $compiler)
  423. {
  424. if (in_array($const, array('true', 'false', 'null'))) {
  425. return true;
  426. }
  427. if (!empty($this->trusted_constants)) {
  428. if (!in_array(strtolower($const), $this->trusted_constants)) {
  429. $compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
  430. return false;
  431. }
  432. return true;
  433. }
  434. if ($this->allow_constants) {
  435. return true;
  436. }
  437. $compiler->trigger_template_error("Security: access to constants not permitted");
  438. return false;
  439. }
  440. /**
  441. * Check if stream is trusted.
  442. *
  443. * @param string $stream_name
  444. *
  445. * @return boolean true if stream is trusted
  446. * @throws SmartyException if stream is not trusted
  447. */
  448. public function isTrustedStream($stream_name)
  449. {
  450. if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) {
  451. return true;
  452. }
  453. throw new SmartyException("stream '{$stream_name}' not allowed by security setting");
  454. }
  455. /**
  456. * Check if directory of file resource is trusted.
  457. *
  458. * @param string $filepath
  459. * @param null|bool $isConfig
  460. *
  461. * @return bool true if directory is trusted
  462. * @throws \SmartyException if directory is not trusted
  463. */
  464. public function isTrustedResourceDir($filepath, $isConfig = null)
  465. {
  466. if ($this->_include_path_status !== $this->smarty->use_include_path) {
  467. $_dir = $this->smarty->use_include_path ? $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty) : array();
  468. if ($this->_include_dir !== $_dir) {
  469. $this->_updateResourceDir($this->_include_dir, $_dir);
  470. $this->_include_dir = $_dir;
  471. }
  472. $this->_include_path_status = $this->smarty->use_include_path;
  473. }
  474. if ($isConfig !== true) {
  475. $_dir = $this->smarty->getTemplateDir();
  476. if ($this->_template_dir !== $_dir) {
  477. $this->_updateResourceDir($this->_template_dir, $_dir);
  478. $this->_template_dir = $_dir;
  479. }
  480. }
  481. if ($isConfig !== false) {
  482. $_dir = $this->smarty->getConfigDir();
  483. if ($this->_config_dir !== $_dir) {
  484. $this->_updateResourceDir($this->_config_dir, $_dir);
  485. $this->_config_dir = $_dir;
  486. }
  487. }
  488. if ($this->_secure_dir !== $this->secure_dir) {
  489. $this->secure_dir = (array)$this->secure_dir;
  490. foreach($this->secure_dir as $k => $d) {
  491. $this->secure_dir[$k] = $this->smarty->_realpath($d.DIRECTORY_SEPARATOR,true);
  492. }
  493. $this->_updateResourceDir($this->_secure_dir, $this->secure_dir);
  494. $this->_secure_dir = $this->secure_dir;
  495. }
  496. $addPath = $this->_checkDir($filepath, $this->_resource_dir);
  497. if ($addPath !== false) {
  498. $this->_resource_dir = array_merge($this->_resource_dir, $addPath);
  499. }
  500. return true;
  501. }
  502. /**
  503. * Check if URI (e.g. {fetch} or {html_image}) is trusted
  504. * To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}".
  505. * So "http://username:password@hello.world.example.org:8080/some-path?some=query-string"
  506. * is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}.
  507. *
  508. * @param string $uri
  509. *
  510. * @return boolean true if URI is trusted
  511. * @throws SmartyException if URI is not trusted
  512. * @uses $trusted_uri for list of patterns to match against $uri
  513. */
  514. public function isTrustedUri($uri)
  515. {
  516. $_uri = parse_url($uri);
  517. if (!empty($_uri[ 'scheme' ]) && !empty($_uri[ 'host' ])) {
  518. $_uri = $_uri[ 'scheme' ] . '://' . $_uri[ 'host' ];
  519. foreach ($this->trusted_uri as $pattern) {
  520. if (preg_match($pattern, $_uri)) {
  521. return true;
  522. }
  523. }
  524. }
  525. throw new SmartyException("URI '{$uri}' not allowed by security setting");
  526. }
  527. /**
  528. * Check if directory of file resource is trusted.
  529. *
  530. * @param string $filepath
  531. *
  532. * @return boolean true if directory is trusted
  533. * @throws SmartyException if PHP directory is not trusted
  534. */
  535. public function isTrustedPHPDir($filepath)
  536. {
  537. if (empty($this->trusted_dir)) {
  538. throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
  539. }
  540. // check if index is outdated
  541. if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
  542. $this->_php_resource_dir = array();
  543. $this->_trusted_dir = $this->trusted_dir;
  544. foreach ((array) $this->trusted_dir as $directory) {
  545. $directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
  546. $this->_php_resource_dir[ $directory ] = true;
  547. }
  548. }
  549. $addPath = $this->_checkDir($filepath, $this->_php_resource_dir);
  550. if ($addPath !== false) {
  551. $this->_php_resource_dir = array_merge($this->_php_resource_dir, $addPath);
  552. }
  553. return true;
  554. }
  555. /**
  556. * Remove old directories and its sub folders, add new directories
  557. *
  558. * @param array $oldDir
  559. * @param array $newDir
  560. */
  561. private function _updateResourceDir($oldDir, $newDir) {
  562. foreach ($oldDir as $directory) {
  563. $directory = $this->smarty->_realpath($directory, true);
  564. $length = strlen($directory);
  565. foreach ($this->_resource_dir as $dir) {
  566. if (substr($dir, 0,$length) === $directory) {
  567. unset($this->_resource_dir[ $dir ]);
  568. }
  569. }
  570. }
  571. foreach ($newDir as $directory) {
  572. $directory = $this->smarty->_realpath($directory, true);
  573. $this->_resource_dir[ $directory ] = true;
  574. }
  575. }
  576. /**
  577. * Check if file is inside a valid directory
  578. *
  579. * @param string $filepath
  580. * @param array $dirs valid directories
  581. *
  582. * @return array|bool
  583. * @throws \SmartyException
  584. */
  585. private function _checkDir($filepath, $dirs)
  586. {
  587. $directory = dirname($filepath) . DIRECTORY_SEPARATOR;
  588. if (isset($dirs[ $directory ])) {
  589. return false;
  590. }
  591. $filepath = $this->smarty->_realpath($filepath, true);
  592. $directory = dirname($filepath) . DIRECTORY_SEPARATOR;
  593. $_directory = array();
  594. while (true) {
  595. // test if the directory is trusted
  596. if (isset($dirs[ $directory ])) {
  597. return $_directory;
  598. }
  599. // abort if we've reached root
  600. if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
  601. break;
  602. }
  603. // remember the directory to add it to _resource_dir in case we're successful
  604. $_directory[ $directory ] = true;
  605. // bubble up one level
  606. $directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory);
  607. }
  608. // give up
  609. throw new SmartyException("directory '{$filepath}' not allowed by security setting");
  610. }
  611. /**
  612. * Loads security class and enables security
  613. *
  614. * @param \Smarty $smarty
  615. * @param string|Smarty_Security $security_class if a string is used, it must be class-name
  616. *
  617. * @return \Smarty current Smarty instance for chaining
  618. * @throws \SmartyException when an invalid class name is provided
  619. */
  620. public static function enableSecurity(Smarty $smarty, $security_class)
  621. {
  622. if ($security_class instanceof Smarty_Security) {
  623. $smarty->security_policy = $security_class;
  624. return $smarty;
  625. } elseif (is_object($security_class)) {
  626. throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
  627. }
  628. if ($security_class === null) {
  629. $security_class = $smarty->security_class;
  630. }
  631. if (!class_exists($security_class)) {
  632. throw new SmartyException("Security class '$security_class' is not defined");
  633. } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
  634. throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
  635. } else {
  636. $smarty->security_policy = new $security_class($smarty);
  637. }
  638. return $smarty;
  639. }
  640. /**
  641. * Start template processing
  642. *
  643. * @param $template
  644. *
  645. * @throws SmartyException
  646. */
  647. public function startTemplate($template)
  648. {
  649. if ($this->max_template_nesting > 0 && $this->_current_template_nesting ++ >= $this->max_template_nesting) {
  650. throw new SmartyException("maximum template nesting level of '{$this->max_template_nesting}' exceeded when calling '{$template->template_resource}'");
  651. }
  652. }
  653. /**
  654. * Exit template processing
  655. *
  656. */
  657. public function endTemplate()
  658. {
  659. if ($this->max_template_nesting > 0) {
  660. $this->_current_template_nesting --;
  661. }
  662. }
  663. /**
  664. * Register callback functions call at start/end of template rendering
  665. *
  666. * @param \Smarty_Internal_Template $template
  667. */
  668. public function registerCallBacks(Smarty_Internal_Template $template)
  669. {
  670. $template->startRenderCallbacks[] = array($this, 'startTemplate');
  671. $template->endRenderCallbacks[] = array($this, 'endTemplate');
  672. }
  673. }