PageRenderTime 44ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/include/Smarty/Smarty.class.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 1940 lines | 1036 code | 178 blank | 726 comment | 136 complexity | 44dbf7377bba64c38900cc56d6b0b5b7 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: Smarty.class.php
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * For questions, help, comments, discussion, etc., please join the
  21. * Smarty mailing list. Send a blank e-mail to
  22. * smarty-general-subscribe@lists.php.net
  23. *
  24. * @link http://smarty.php.net/
  25. * @copyright 2001-2005 New Digital Group, Inc.
  26. * @author Monte Ohrt <monte at ohrt dot com>
  27. * @author Andrei Zmievski <andrei@php.net>
  28. * @package Smarty
  29. * @version 2.6.11
  30. */
  31. /**
  32. * DIR_SEP isn't used anymore, but third party apps might
  33. */
  34. if(!defined('DIR_SEP')) {
  35. define('DIR_SEP', DIRECTORY_SEPARATOR);
  36. }
  37. /**
  38. * set SMARTY_DIR to absolute path to Smarty library files.
  39. * if not defined, include_path will be used. Sets SMARTY_DIR only if user
  40. * application has not already defined it.
  41. */
  42. if (!defined('SMARTY_DIR')) {
  43. define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  44. }
  45. if (!defined('SMARTY_CORE_DIR')) {
  46. define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
  47. }
  48. define('SMARTY_PHP_PASSTHRU', 0);
  49. define('SMARTY_PHP_QUOTE', 1);
  50. define('SMARTY_PHP_REMOVE', 2);
  51. define('SMARTY_PHP_ALLOW', 3);
  52. /**
  53. * @package Smarty
  54. */
  55. class Smarty
  56. {
  57. /**#@+
  58. * Smarty Configuration Section
  59. */
  60. /**
  61. * The name of the directory where templates are located.
  62. *
  63. * @var string
  64. */
  65. var $template_dir = 'templates';
  66. /**
  67. * The directory where compiled templates are located.
  68. *
  69. * @var string
  70. */
  71. var $compile_dir = 'templates_c';
  72. /**
  73. * The directory where config files are located.
  74. *
  75. * @var string
  76. */
  77. var $config_dir = 'configs';
  78. /**
  79. * An array of directories searched for plugins.
  80. *
  81. * @var array
  82. */
  83. var $plugins_dir = array('plugins');
  84. /**
  85. * If debugging is enabled, a debug console window will display
  86. * when the page loads (make sure your browser allows unrequested
  87. * popup windows)
  88. *
  89. * @var boolean
  90. */
  91. var $debugging = false;
  92. /**
  93. * When set, smarty does uses this value as error_reporting-level.
  94. *
  95. * @var boolean
  96. */
  97. var $error_reporting = null;
  98. /**
  99. * This is the path to the debug console template. If not set,
  100. * the default one will be used.
  101. *
  102. * @var string
  103. */
  104. var $debug_tpl = '';
  105. /**
  106. * This determines if debugging is enable-able from the browser.
  107. * <ul>
  108. * <li>NONE => no debugging control allowed</li>
  109. * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  110. * </ul>
  111. * @link http://www.foo.dom/index.php?SMARTY_DEBUG
  112. * @var string
  113. */
  114. var $debugging_ctrl = 'NONE';
  115. /**
  116. * This tells Smarty whether to check for recompiling or not. Recompiling
  117. * does not need to happen unless a template or config file is changed.
  118. * Typically you enable this during development, and disable for
  119. * production.
  120. *
  121. * @var boolean
  122. */
  123. var $compile_check = true;
  124. /**
  125. * This forces templates to compile every time. Useful for development
  126. * or debugging.
  127. *
  128. * @var boolean
  129. */
  130. var $force_compile = false;
  131. /**
  132. * This enables template caching.
  133. * <ul>
  134. * <li>0 = no caching</li>
  135. * <li>1 = use class cache_lifetime value</li>
  136. * <li>2 = use cache_lifetime in cache file</li>
  137. * </ul>
  138. * @var integer
  139. */
  140. var $caching = 0;
  141. /**
  142. * The name of the directory for cache files.
  143. *
  144. * @var string
  145. */
  146. var $cache_dir = 'cache';
  147. /**
  148. * This is the number of seconds cached content will persist.
  149. * <ul>
  150. * <li>0 = always regenerate cache</li>
  151. * <li>-1 = never expires</li>
  152. * </ul>
  153. *
  154. * @var integer
  155. */
  156. var $cache_lifetime = 3600;
  157. /**
  158. * Only used when $caching is enabled. If true, then If-Modified-Since headers
  159. * are respected with cached content, and appropriate HTTP headers are sent.
  160. * This way repeated hits to a cached page do not send the entire page to the
  161. * client every time.
  162. *
  163. * @var boolean
  164. */
  165. var $cache_modified_check = false;
  166. /**
  167. * This determines how Smarty handles "<?php ... ?>" tags in templates.
  168. * possible values:
  169. * <ul>
  170. * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
  171. * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
  172. * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
  173. * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
  174. * </ul>
  175. *
  176. * @var integer
  177. */
  178. var $php_handling = SMARTY_PHP_PASSTHRU;
  179. /**
  180. * This enables template security. When enabled, many things are restricted
  181. * in the templates that normally would go unchecked. This is useful when
  182. * untrusted parties are editing templates and you want a reasonable level
  183. * of security. (no direct execution of PHP in templates for example)
  184. *
  185. * @var boolean
  186. */
  187. var $security = false;
  188. /**
  189. * This is the list of template directories that are considered secure. This
  190. * is used only if {@link $security} is enabled. One directory per array
  191. * element. {@link $template_dir} is in this list implicitly.
  192. *
  193. * @var array
  194. */
  195. var $secure_dir = array();
  196. /**
  197. * These are the security settings for Smarty. They are used only when
  198. * {@link $security} is enabled.
  199. *
  200. * @var array
  201. */
  202. var $security_settings = array(
  203. 'PHP_HANDLING' => false,
  204. 'IF_FUNCS' => array('array', 'list',
  205. 'isset', 'empty',
  206. 'count', 'sizeof',
  207. 'in_array', 'is_array',
  208. 'true', 'false', 'null'),
  209. 'INCLUDE_ANY' => false,
  210. 'PHP_TAGS' => false,
  211. 'MODIFIER_FUNCS' => array('count'),
  212. 'ALLOW_CONSTANTS' => false
  213. );
  214. /**
  215. * This is an array of directories where trusted php scripts reside.
  216. * {@link $security} is disabled during their inclusion/execution.
  217. *
  218. * @var array
  219. */
  220. var $trusted_dir = array();
  221. /**
  222. * The left delimiter used for the template tags.
  223. *
  224. * @var string
  225. */
  226. var $left_delimiter = '{';
  227. /**
  228. * The right delimiter used for the template tags.
  229. *
  230. * @var string
  231. */
  232. var $right_delimiter = '}';
  233. /**
  234. * The order in which request variables are registered, similar to
  235. * variables_order in php.ini E = Environment, G = GET, P = POST,
  236. * C = Cookies, S = Server
  237. *
  238. * @var string
  239. */
  240. var $request_vars_order = 'EGPCS';
  241. /**
  242. * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
  243. * are uses as request-vars or $_*[]-vars. note: if
  244. * request_use_auto_globals is true, then $request_vars_order has
  245. * no effect, but the php-ini-value "gpc_order"
  246. *
  247. * @var boolean
  248. */
  249. var $request_use_auto_globals = true;
  250. /**
  251. * Set this if you want different sets of compiled files for the same
  252. * templates. This is useful for things like different languages.
  253. * Instead of creating separate sets of templates per language, you
  254. * set different compile_ids like 'en' and 'de'.
  255. *
  256. * @var string
  257. */
  258. var $compile_id = null;
  259. /**
  260. * This tells Smarty whether or not to use sub dirs in the cache/ and
  261. * templates_c/ directories. sub directories better organized, but
  262. * may not work well with PHP safe mode enabled.
  263. *
  264. * @var boolean
  265. *
  266. */
  267. var $use_sub_dirs = false;
  268. /**
  269. * This is a list of the modifiers to apply to all template variables.
  270. * Put each modifier in a separate array element in the order you want
  271. * them applied. example: <code>array('escape:"htmlall"');</code>
  272. *
  273. * @var array
  274. */
  275. var $default_modifiers = array();
  276. /**
  277. * This is the resource type to be used when not specified
  278. * at the beginning of the resource path. examples:
  279. * $smarty->display('file:index.tpl');
  280. * $smarty->display('db:index.tpl');
  281. * $smarty->display('index.tpl'); // will use default resource type
  282. * {include file="file:index.tpl"}
  283. * {include file="db:index.tpl"}
  284. * {include file="index.tpl"} {* will use default resource type *}
  285. *
  286. * @var array
  287. */
  288. var $default_resource_type = 'file';
  289. /**
  290. * The function used for cache file handling. If not set, built-in caching is used.
  291. *
  292. * @var null|string function name
  293. */
  294. var $cache_handler_func = null;
  295. /**
  296. * This indicates which filters are automatically loaded into Smarty.
  297. *
  298. * @var array array of filter names
  299. */
  300. var $autoload_filters = array();
  301. /**#@+
  302. * @var boolean
  303. */
  304. /**
  305. * This tells if config file vars of the same name overwrite each other or not.
  306. * if disabled, same name variables are accumulated in an array.
  307. */
  308. var $config_overwrite = true;
  309. /**
  310. * This tells whether or not to automatically booleanize config file variables.
  311. * If enabled, then the strings "on", "true", and "yes" are treated as boolean
  312. * true, and "off", "false" and "no" are treated as boolean false.
  313. */
  314. var $config_booleanize = true;
  315. /**
  316. * This tells whether hidden sections [.foobar] are readable from the
  317. * tempalates or not. Normally you would never allow this since that is
  318. * the point behind hidden sections: the application can access them, but
  319. * the templates cannot.
  320. */
  321. var $config_read_hidden = false;
  322. /**
  323. * This tells whether or not automatically fix newlines in config files.
  324. * It basically converts \r (mac) or \r\n (dos) to \n
  325. */
  326. var $config_fix_newlines = true;
  327. /**#@-*/
  328. /**
  329. * If a template cannot be found, this PHP function will be executed.
  330. * Useful for creating templates on-the-fly or other special action.
  331. *
  332. * @var string function name
  333. */
  334. var $default_template_handler_func = '';
  335. /**
  336. * The file that contains the compiler class. This can a full
  337. * pathname, or relative to the php_include path.
  338. *
  339. * @var string
  340. */
  341. var $compiler_file = 'Smarty_Compiler.class.php';
  342. /**
  343. * The class used for compiling templates.
  344. *
  345. * @var string
  346. */
  347. var $compiler_class = 'Smarty_Compiler';
  348. /**
  349. * The class used to load config vars.
  350. *
  351. * @var string
  352. */
  353. var $config_class = 'Config_File';
  354. /**#@+
  355. * END Smarty Configuration Section
  356. * There should be no need to touch anything below this line.
  357. * @access private
  358. */
  359. /**
  360. * where assigned template vars are kept
  361. *
  362. * @var array
  363. */
  364. var $_tpl_vars = array();
  365. /**
  366. * stores run-time $smarty.* vars
  367. *
  368. * @var null|array
  369. */
  370. var $_smarty_vars = null;
  371. /**
  372. * keeps track of sections
  373. *
  374. * @var array
  375. */
  376. var $_sections = array();
  377. /**
  378. * keeps track of foreach blocks
  379. *
  380. * @var array
  381. */
  382. var $_foreach = array();
  383. /**
  384. * keeps track of tag hierarchy
  385. *
  386. * @var array
  387. */
  388. var $_tag_stack = array();
  389. /**
  390. * configuration object
  391. *
  392. * @var Config_file
  393. */
  394. var $_conf_obj = null;
  395. /**
  396. * loaded configuration settings
  397. *
  398. * @var array
  399. */
  400. var $_config = array(array('vars' => array(), 'files' => array()));
  401. /**
  402. * md5 checksum of the string 'Smarty'
  403. *
  404. * @var string
  405. */
  406. var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f';
  407. /**
  408. * Smarty version number
  409. *
  410. * @var string
  411. */
  412. var $_version = '2.6.11';
  413. /**
  414. * current template inclusion depth
  415. *
  416. * @var integer
  417. */
  418. var $_inclusion_depth = 0;
  419. /**
  420. * for different compiled templates
  421. *
  422. * @var string
  423. */
  424. var $_compile_id = null;
  425. /**
  426. * text in URL to enable debug mode
  427. *
  428. * @var string
  429. */
  430. var $_smarty_debug_id = 'SMARTY_DEBUG';
  431. /**
  432. * debugging information for debug console
  433. *
  434. * @var array
  435. */
  436. var $_smarty_debug_info = array();
  437. /**
  438. * info that makes up a cache file
  439. *
  440. * @var array
  441. */
  442. var $_cache_info = array();
  443. /**
  444. * default file permissions
  445. *
  446. * @var integer
  447. */
  448. var $_file_perms = 0644;
  449. /**
  450. * default dir permissions
  451. *
  452. * @var integer
  453. */
  454. var $_dir_perms = 0771;
  455. /**
  456. * registered objects
  457. *
  458. * @var array
  459. */
  460. var $_reg_objects = array();
  461. /**
  462. * table keeping track of plugins
  463. *
  464. * @var array
  465. */
  466. var $_plugins = array(
  467. 'modifier' => array(),
  468. 'function' => array(),
  469. 'block' => array(),
  470. 'compiler' => array(),
  471. 'prefilter' => array(),
  472. 'postfilter' => array(),
  473. 'outputfilter' => array(),
  474. 'resource' => array(),
  475. 'insert' => array());
  476. /**
  477. * cache serials
  478. *
  479. * @var array
  480. */
  481. var $_cache_serials = array();
  482. /**
  483. * name of optional cache include file
  484. *
  485. * @var string
  486. */
  487. var $_cache_include = null;
  488. /**
  489. * indicate if the current code is used in a compiled
  490. * include
  491. *
  492. * @var string
  493. */
  494. var $_cache_including = false;
  495. /**#@-*/
  496. /**
  497. * The class constructor.
  498. */
  499. function Smarty()
  500. {
  501. $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
  502. : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
  503. }
  504. /**
  505. * assigns values to template variables
  506. *
  507. * @param array|string $tpl_var the template variable name(s)
  508. * @param mixed $value the value to assign
  509. */
  510. function assign($tpl_var, $value = null)
  511. {
  512. if (is_array($tpl_var)){
  513. foreach ($tpl_var as $key => $val) {
  514. if ($key != '') {
  515. $this->_tpl_vars[$key] = $val;
  516. }
  517. }
  518. } else {
  519. if ($tpl_var != '')
  520. $this->_tpl_vars[$tpl_var] = $value;
  521. }
  522. }
  523. /**
  524. * assigns values to template variables by reference
  525. *
  526. * @param string $tpl_var the template variable name
  527. * @param mixed $value the referenced value to assign
  528. */
  529. function assign_by_ref($tpl_var, &$value)
  530. {
  531. if ($tpl_var != '')
  532. $this->_tpl_vars[$tpl_var] = &$value;
  533. }
  534. /**
  535. * appends values to template variables
  536. *
  537. * @param array|string $tpl_var the template variable name(s)
  538. * @param mixed $value the value to append
  539. */
  540. function append($tpl_var, $value=null, $merge=false)
  541. {
  542. if (is_array($tpl_var)) {
  543. // $tpl_var is an array, ignore $value
  544. foreach ($tpl_var as $_key => $_val) {
  545. if ($_key != '') {
  546. if(!@is_array($this->_tpl_vars[$_key])) {
  547. settype($this->_tpl_vars[$_key],'array');
  548. }
  549. if($merge && is_array($_val)) {
  550. foreach($_val as $_mkey => $_mval) {
  551. $this->_tpl_vars[$_key][$_mkey] = $_mval;
  552. }
  553. } else {
  554. $this->_tpl_vars[$_key][] = $_val;
  555. }
  556. }
  557. }
  558. } else {
  559. if ($tpl_var != '' && isset($value)) {
  560. if(!@is_array($this->_tpl_vars[$tpl_var])) {
  561. settype($this->_tpl_vars[$tpl_var],'array');
  562. }
  563. if($merge && is_array($value)) {
  564. foreach($value as $_mkey => $_mval) {
  565. $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
  566. }
  567. } else {
  568. $this->_tpl_vars[$tpl_var][] = $value;
  569. }
  570. }
  571. }
  572. }
  573. /**
  574. * appends values to template variables by reference
  575. *
  576. * @param string $tpl_var the template variable name
  577. * @param mixed $value the referenced value to append
  578. */
  579. function append_by_ref($tpl_var, &$value, $merge=false)
  580. {
  581. if ($tpl_var != '' && isset($value)) {
  582. if(!@is_array($this->_tpl_vars[$tpl_var])) {
  583. settype($this->_tpl_vars[$tpl_var],'array');
  584. }
  585. if ($merge && is_array($value)) {
  586. foreach($value as $_key => $_val) {
  587. $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
  588. }
  589. } else {
  590. $this->_tpl_vars[$tpl_var][] = &$value;
  591. }
  592. }
  593. }
  594. /**
  595. * clear the given assigned template variable.
  596. *
  597. * @param string $tpl_var the template variable to clear
  598. */
  599. function clear_assign($tpl_var)
  600. {
  601. if (is_array($tpl_var))
  602. foreach ($tpl_var as $curr_var)
  603. unset($this->_tpl_vars[$curr_var]);
  604. else
  605. unset($this->_tpl_vars[$tpl_var]);
  606. }
  607. /**
  608. * Registers custom function to be used in templates
  609. *
  610. * @param string $function the name of the template function
  611. * @param string $function_impl the name of the PHP function to register
  612. */
  613. function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
  614. {
  615. $this->_plugins['function'][$function] =
  616. array($function_impl, null, null, false, $cacheable, $cache_attrs);
  617. }
  618. /**
  619. * Unregisters custom function
  620. *
  621. * @param string $function name of template function
  622. */
  623. function unregister_function($function)
  624. {
  625. unset($this->_plugins['function'][$function]);
  626. }
  627. /**
  628. * Registers object to be used in templates
  629. *
  630. * @param string $object name of template object
  631. * @param object &$object_impl the referenced PHP object to register
  632. * @param null|array $allowed list of allowed methods (empty = all)
  633. * @param boolean $smarty_args smarty argument format, else traditional
  634. * @param null|array $block_functs list of methods that are block format
  635. */
  636. function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
  637. {
  638. settype($allowed, 'array');
  639. settype($smarty_args, 'boolean');
  640. $this->_reg_objects[$object] =
  641. array(&$object_impl, $allowed, $smarty_args, $block_methods);
  642. }
  643. /**
  644. * Unregisters object
  645. *
  646. * @param string $object name of template object
  647. */
  648. function unregister_object($object)
  649. {
  650. unset($this->_reg_objects[$object]);
  651. }
  652. /**
  653. * Registers block function to be used in templates
  654. *
  655. * @param string $block name of template block
  656. * @param string $block_impl PHP function to register
  657. */
  658. function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
  659. {
  660. $this->_plugins['block'][$block] =
  661. array($block_impl, null, null, false, $cacheable, $cache_attrs);
  662. }
  663. /**
  664. * Unregisters block function
  665. *
  666. * @param string $block name of template function
  667. */
  668. function unregister_block($block)
  669. {
  670. unset($this->_plugins['block'][$block]);
  671. }
  672. /**
  673. * Registers compiler function
  674. *
  675. * @param string $function name of template function
  676. * @param string $function_impl name of PHP function to register
  677. */
  678. function register_compiler_function($function, $function_impl, $cacheable=true)
  679. {
  680. $this->_plugins['compiler'][$function] =
  681. array($function_impl, null, null, false, $cacheable);
  682. }
  683. /**
  684. * Unregisters compiler function
  685. *
  686. * @param string $function name of template function
  687. */
  688. function unregister_compiler_function($function)
  689. {
  690. unset($this->_plugins['compiler'][$function]);
  691. }
  692. /**
  693. * Registers modifier to be used in templates
  694. *
  695. * @param string $modifier name of template modifier
  696. * @param string $modifier_impl name of PHP function to register
  697. */
  698. function register_modifier($modifier, $modifier_impl)
  699. {
  700. $this->_plugins['modifier'][$modifier] =
  701. array($modifier_impl, null, null, false);
  702. }
  703. /**
  704. * Unregisters modifier
  705. *
  706. * @param string $modifier name of template modifier
  707. */
  708. function unregister_modifier($modifier)
  709. {
  710. unset($this->_plugins['modifier'][$modifier]);
  711. }
  712. /**
  713. * Registers a resource to fetch a template
  714. *
  715. * @param string $type name of resource
  716. * @param array $functions array of functions to handle resource
  717. */
  718. function register_resource($type, $functions)
  719. {
  720. if (count($functions)==4) {
  721. $this->_plugins['resource'][$type] =
  722. array($functions, false);
  723. } elseif (count($functions)==5) {
  724. $this->_plugins['resource'][$type] =
  725. array(array(array(&$functions[0], $functions[1])
  726. ,array(&$functions[0], $functions[2])
  727. ,array(&$functions[0], $functions[3])
  728. ,array(&$functions[0], $functions[4]))
  729. ,false);
  730. } else {
  731. $this->trigger_error("malformed function-list for '$type' in register_resource");
  732. }
  733. }
  734. /**
  735. * Unregisters a resource
  736. *
  737. * @param string $type name of resource
  738. */
  739. function unregister_resource($type)
  740. {
  741. unset($this->_plugins['resource'][$type]);
  742. }
  743. /**
  744. * Registers a prefilter function to apply
  745. * to a template before compiling
  746. *
  747. * @param string $function name of PHP function to register
  748. */
  749. function register_prefilter($function)
  750. {
  751. $_name = (is_array($function)) ? $function[1] : $function;
  752. $this->_plugins['prefilter'][$_name]
  753. = array($function, null, null, false);
  754. }
  755. /**
  756. * Unregisters a prefilter function
  757. *
  758. * @param string $function name of PHP function
  759. */
  760. function unregister_prefilter($function)
  761. {
  762. unset($this->_plugins['prefilter'][$function]);
  763. }
  764. /**
  765. * Registers a postfilter function to apply
  766. * to a compiled template after compilation
  767. *
  768. * @param string $function name of PHP function to register
  769. */
  770. function register_postfilter($function)
  771. {
  772. $_name = (is_array($function)) ? $function[1] : $function;
  773. $this->_plugins['postfilter'][$_name]
  774. = array($function, null, null, false);
  775. }
  776. /**
  777. * Unregisters a postfilter function
  778. *
  779. * @param string $function name of PHP function
  780. */
  781. function unregister_postfilter($function)
  782. {
  783. unset($this->_plugins['postfilter'][$function]);
  784. }
  785. /**
  786. * Registers an output filter function to apply
  787. * to a template output
  788. *
  789. * @param string $function name of PHP function
  790. */
  791. function register_outputfilter($function)
  792. {
  793. $_name = (is_array($function)) ? $function[1] : $function;
  794. $this->_plugins['outputfilter'][$_name]
  795. = array($function, null, null, false);
  796. }
  797. /**
  798. * Unregisters an outputfilter function
  799. *
  800. * @param string $function name of PHP function
  801. */
  802. function unregister_outputfilter($function)
  803. {
  804. unset($this->_plugins['outputfilter'][$function]);
  805. }
  806. /**
  807. * load a filter of specified type and name
  808. *
  809. * @param string $type filter type
  810. * @param string $name filter name
  811. */
  812. function load_filter($type, $name)
  813. {
  814. switch ($type) {
  815. case 'output':
  816. $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));
  817. require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
  818. smarty_core_load_plugins($_params, $this);
  819. break;
  820. case 'pre':
  821. case 'post':
  822. if (!isset($this->_plugins[$type . 'filter'][$name]))
  823. $this->_plugins[$type . 'filter'][$name] = false;
  824. break;
  825. }
  826. }
  827. /**
  828. * clear cached content for the given template and cache id
  829. *
  830. * @param string $tpl_file name of template file
  831. * @param string $cache_id name of cache_id
  832. * @param string $compile_id name of compile_id
  833. * @param string $exp_time expiration time
  834. * @return boolean
  835. */
  836. function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
  837. {
  838. if (!isset($compile_id))
  839. $compile_id = $this->compile_id;
  840. if (!isset($tpl_file))
  841. $compile_id = null;
  842. $_auto_id = $this->_get_auto_id($cache_id, $compile_id);
  843. if (!empty($this->cache_handler_func)) {
  844. return call_user_func_array($this->cache_handler_func,
  845. array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time));
  846. } else {
  847. $_params = array('auto_base' => $this->cache_dir,
  848. 'auto_source' => $tpl_file,
  849. 'auto_id' => $_auto_id,
  850. 'exp_time' => $exp_time);
  851. require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');
  852. return smarty_core_rm_auto($_params, $this);
  853. }
  854. }
  855. /**
  856. * clear the entire contents of cache (all templates)
  857. *
  858. * @param string $exp_time expire time
  859. * @return boolean results of {@link smarty_core_rm_auto()}
  860. */
  861. function clear_all_cache($exp_time = null)
  862. {
  863. return $this->clear_cache(null, null, null, $exp_time);
  864. }
  865. /**
  866. * test to see if valid cache exists for this template
  867. *
  868. * @param string $tpl_file name of template file
  869. * @param string $cache_id
  870. * @param string $compile_id
  871. * @return string|false results of {@link _read_cache_file()}
  872. */
  873. function is_cached($tpl_file, $cache_id = null, $compile_id = null)
  874. {
  875. if (!$this->caching)
  876. return false;
  877. if (!isset($compile_id))
  878. $compile_id = $this->compile_id;
  879. $_params = array(
  880. 'tpl_file' => $tpl_file,
  881. 'cache_id' => $cache_id,
  882. 'compile_id' => $compile_id
  883. );
  884. require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
  885. return smarty_core_read_cache_file($_params, $this);
  886. }
  887. /**
  888. * clear all the assigned template variables.
  889. *
  890. */
  891. function clear_all_assign()
  892. {
  893. $this->_tpl_vars = array();
  894. }
  895. /**
  896. * clears compiled version of specified template resource,
  897. * or all compiled template files if one is not specified.
  898. * This function is for advanced use only, not normally needed.
  899. *
  900. * @param string $tpl_file
  901. * @param string $compile_id
  902. * @param string $exp_time
  903. * @return boolean results of {@link smarty_core_rm_auto()}
  904. */
  905. function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
  906. {
  907. if (!isset($compile_id)) {
  908. $compile_id = $this->compile_id;
  909. }
  910. $_params = array('auto_base' => $this->compile_dir,
  911. 'auto_source' => $tpl_file,
  912. 'auto_id' => $compile_id,
  913. 'exp_time' => $exp_time,
  914. 'extensions' => array('.inc', '.php'));
  915. require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');
  916. return smarty_core_rm_auto($_params, $this);
  917. }
  918. /**
  919. * Checks whether requested template exists.
  920. *
  921. * @param string $tpl_file
  922. * @return boolean
  923. */
  924. function template_exists($tpl_file)
  925. {
  926. $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false);
  927. return $this->_fetch_resource_info($_params);
  928. }
  929. /**
  930. * Returns an array containing template variables
  931. *
  932. * @param string $name
  933. * @param string $type
  934. * @return array
  935. */
  936. function &get_template_vars($name=null)
  937. {
  938. if(!isset($name)) {
  939. return $this->_tpl_vars;
  940. } elseif(isset($this->_tpl_vars[$name])) {
  941. return $this->_tpl_vars[$name];
  942. } else {
  943. // var non-existant, return valid reference
  944. $_tmp = null;
  945. return $_tmp;
  946. }
  947. }
  948. /**
  949. * Returns an array containing config variables
  950. *
  951. * @param string $name
  952. * @param string $type
  953. * @return array
  954. */
  955. function &get_config_vars($name=null)
  956. {
  957. if(!isset($name) && is_array($this->_config[0])) {
  958. return $this->_config[0]['vars'];
  959. } else if(isset($this->_config[0]['vars'][$name])) {
  960. return $this->_config[0]['vars'][$name];
  961. } else {
  962. // var non-existant, return valid reference
  963. $_tmp = null;
  964. return $_tmp;
  965. }
  966. }
  967. /**
  968. * trigger Smarty error
  969. *
  970. * @param string $error_msg
  971. * @param integer $error_type
  972. */
  973. function trigger_error($error_msg, $error_type = E_USER_WARNING)
  974. {
  975. trigger_error("Smarty error: $error_msg", $error_type);
  976. }
  977. /**
  978. * executes & displays the template results
  979. *
  980. * @param string $resource_name
  981. * @param string $cache_id
  982. * @param string $compile_id
  983. */
  984. function display($resource_name, $cache_id = null, $compile_id = null)
  985. {
  986. $this->fetch($resource_name, $cache_id, $compile_id, true);
  987. }
  988. /**
  989. * executes & returns or displays the template results
  990. *
  991. * @param string $resource_name
  992. * @param string $cache_id
  993. * @param string $compile_id
  994. * @param boolean $display
  995. */
  996. function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
  997. {
  998. static $_cache_info = array();
  999. $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)
  1000. ? $this->error_reporting : error_reporting() & ~E_NOTICE);
  1001. if (!$this->debugging && $this->debugging_ctrl == 'URL') {
  1002. $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
  1003. if (@strstr($_query_string, $this->_smarty_debug_id)) {
  1004. if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) {
  1005. // enable debugging for this browser session
  1006. @setcookie('SMARTY_DEBUG', true);
  1007. $this->debugging = true;
  1008. } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) {
  1009. // disable debugging for this browser session
  1010. @setcookie('SMARTY_DEBUG', false);
  1011. $this->debugging = false;
  1012. } else {
  1013. // enable debugging for this page
  1014. $this->debugging = true;
  1015. }
  1016. } else {
  1017. $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']);
  1018. }
  1019. }
  1020. if ($this->debugging) {
  1021. // capture time for debugging info
  1022. $_params = array();
  1023. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  1024. $_debug_start_time = smarty_core_get_microtime($_params, $this);
  1025. $this->_smarty_debug_info[] = array('type' => 'template',
  1026. 'filename' => $resource_name,
  1027. 'depth' => 0);
  1028. $_included_tpls_idx = count($this->_smarty_debug_info) - 1;
  1029. }
  1030. if (!isset($compile_id)) {
  1031. $compile_id = $this->compile_id;
  1032. }
  1033. $this->_compile_id = $compile_id;
  1034. $this->_inclusion_depth = 0;
  1035. if ($this->caching) {
  1036. // save old cache_info, initialize cache_info
  1037. array_push($_cache_info, $this->_cache_info);
  1038. $this->_cache_info = array();
  1039. $_params = array(
  1040. 'tpl_file' => $resource_name,
  1041. 'cache_id' => $cache_id,
  1042. 'compile_id' => $compile_id,
  1043. 'results' => null
  1044. );
  1045. require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
  1046. if (smarty_core_read_cache_file($_params, $this)) {
  1047. $_smarty_results = $_params['results'];
  1048. if (!empty($this->_cache_info['insert_tags'])) {
  1049. $_params = array('plugins' => $this->_cache_info['insert_tags']);
  1050. require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
  1051. smarty_core_load_plugins($_params, $this);
  1052. $_params = array('results' => $_smarty_results);
  1053. require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
  1054. $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
  1055. }
  1056. if (!empty($this->_cache_info['cache_serials'])) {
  1057. $_params = array('results' => $_smarty_results);
  1058. require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');
  1059. $_smarty_results = smarty_core_process_compiled_include($_params, $this);
  1060. }
  1061. if ($display) {
  1062. if ($this->debugging)
  1063. {
  1064. // capture time for debugging info
  1065. $_params = array();
  1066. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  1067. $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;
  1068. require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
  1069. $_smarty_results .= smarty_core_display_debug_console($_params, $this);
  1070. }
  1071. if ($this->cache_modified_check) {
  1072. $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
  1073. $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
  1074. $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
  1075. if (@count($this->_cache_info['insert_tags']) == 0
  1076. && !$this->_cache_serials
  1077. && $_gmt_mtime == $_last_modified_date) {
  1078. if (php_sapi_name()=='cgi')
  1079. header('Status: 304 Not Modified');
  1080. else
  1081. header('HTTP/1.1 304 Not Modified');
  1082. } else {
  1083. header('Last-Modified: '.$_gmt_mtime);
  1084. echo $_smarty_results;
  1085. }
  1086. } else {
  1087. echo $_smarty_results;
  1088. }
  1089. error_reporting($_smarty_old_error_level);
  1090. // restore initial cache_info
  1091. $this->_cache_info = array_pop($_cache_info);
  1092. return true;
  1093. } else {
  1094. error_reporting($_smarty_old_error_level);
  1095. // restore initial cache_info
  1096. $this->_cache_info = array_pop($_cache_info);
  1097. return $_smarty_results;
  1098. }
  1099. } else {
  1100. $this->_cache_info['template'][$resource_name] = true;
  1101. if ($this->cache_modified_check && $display) {
  1102. header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
  1103. }
  1104. }
  1105. }
  1106. // load filters that are marked as autoload
  1107. if (count($this->autoload_filters)) {
  1108. foreach ($this->autoload_filters as $_filter_type => $_filters) {
  1109. foreach ($_filters as $_filter) {
  1110. $this->load_filter($_filter_type, $_filter);
  1111. }
  1112. }
  1113. }
  1114. $_smarty_compile_path = $this->_get_compile_path($resource_name);
  1115. // if we just need to display the results, don't perform output
  1116. // buffering - for speed
  1117. $_cache_including = $this->_cache_including;
  1118. $this->_cache_including = false;
  1119. if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
  1120. if ($this->_is_compiled($resource_name, $_smarty_compile_path)
  1121. || $this->_compile_resource($resource_name, $_smarty_compile_path))
  1122. {
  1123. include($_smarty_compile_path);
  1124. }
  1125. } else {
  1126. ob_start();
  1127. if ($this->_is_compiled($resource_name, $_smarty_compile_path)
  1128. || $this->_compile_resource($resource_name, $_smarty_compile_path))
  1129. {
  1130. include($_smarty_compile_path);
  1131. }
  1132. $_smarty_results = ob_get_contents();
  1133. ob_end_clean();
  1134. foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {
  1135. $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
  1136. }
  1137. }
  1138. if ($this->caching) {
  1139. $_params = array('tpl_file' => $resource_name,
  1140. 'cache_id' => $cache_id,
  1141. 'compile_id' => $compile_id,
  1142. 'results' => $_smarty_results);
  1143. require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');
  1144. smarty_core_write_cache_file($_params, $this);
  1145. require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
  1146. $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
  1147. if ($this->_cache_serials) {
  1148. // strip nocache-tags from output
  1149. $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
  1150. ,''
  1151. ,$_smarty_results);
  1152. }
  1153. // restore initial cache_info
  1154. $this->_cache_info = array_pop($_cache_info);
  1155. }
  1156. $this->_cache_including = $_cache_including;
  1157. if ($display) {
  1158. if (isset($_smarty_results)) { echo $_smarty_results; }
  1159. if ($this->debugging) {
  1160. // capture time for debugging info
  1161. $_params = array();
  1162. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  1163. $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
  1164. require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
  1165. echo smarty_core_display_debug_console($_params, $this);
  1166. }
  1167. error_reporting($_smarty_old_error_level);
  1168. return;
  1169. } else {
  1170. error_reporting($_smarty_old_error_level);
  1171. if (isset($_smarty_results)) { return $_smarty_results; }
  1172. }
  1173. }
  1174. /**
  1175. * load configuration values
  1176. *
  1177. * @param string $file
  1178. * @param string $section
  1179. * @param string $scope
  1180. */
  1181. function config_load($file, $section = null, $scope = 'global')
  1182. {
  1183. require_once($this->_get_plugin_filepath('function', 'config_load'));
  1184. smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);
  1185. }
  1186. /**
  1187. * return a reference to a registered object
  1188. *
  1189. * @param string $name
  1190. * @return object
  1191. */
  1192. function &get_registered_object($name) {
  1193. if (!isset($this->_reg_objects[$name]))
  1194. $this->_trigger_fatal_error("'$name' is not a registered object");
  1195. if (!is_object($this->_reg_objects[$name][0]))
  1196. $this->_trigger_fatal_error("registered '$name' is not an object");
  1197. return $this->_reg_objects[$name][0];
  1198. }
  1199. /**
  1200. * clear configuration values
  1201. *
  1202. * @param string $var
  1203. */
  1204. function clear_config($var = null)
  1205. {
  1206. if(!isset($var)) {
  1207. // clear all values
  1208. $this->_config = array(array('vars' => array(),
  1209. 'files' => array()));
  1210. } else {
  1211. unset($this->_config[0]['vars'][$var]);
  1212. }
  1213. }
  1214. /**
  1215. * get filepath of requested plugin
  1216. *
  1217. * @param string $type
  1218. * @param string $name
  1219. * @return string|false
  1220. */
  1221. function _get_plugin_filepath($type, $name)
  1222. {
  1223. $_params = array('type' => $type, 'name' => $name);
  1224. require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php');
  1225. return smarty_core_assemble_plugin_filepath($_params, $this);
  1226. }
  1227. /**
  1228. * test if resource needs compiling
  1229. *
  1230. * @param string $resource_name
  1231. * @param string $compile_path
  1232. * @return boolean
  1233. */
  1234. function _is_compiled($resource_name, $compile_path)
  1235. {
  1236. if (!$this->force_compile && file_exists($compile_path)) {
  1237. if (!$this->compile_check) {
  1238. // no need to check compiled file
  1239. return true;
  1240. } else {
  1241. // get file source and timestamp
  1242. $_params = array('resource_name' => $resource_name, 'get_source'=>false);
  1243. if (!$this->_fetch_resource_info($_params)) {
  1244. return false;
  1245. }
  1246. if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
  1247. // template not expired, no recompile
  1248. return true;
  1249. } else {
  1250. // compile template
  1251. return false;
  1252. }
  1253. }
  1254. } else {
  1255. // compiled template does not exist, or forced compile
  1256. return false;
  1257. }
  1258. }
  1259. /**
  1260. * compile the template
  1261. *
  1262. * @param string $resource_name
  1263. * @param string $compile_path
  1264. * @return boolean
  1265. */
  1266. function _compile_resource($resource_name, $compile_path)
  1267. {
  1268. $_params = array('resource_name' => $resource_name);
  1269. if (!$this->_fetch_resource_info($_params)) {
  1270. return false;
  1271. }
  1272. $_source_content = $_params['source_content'];
  1273. $_cache_include = substr($compile_path, 0, -4).'.inc';
  1274. if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {
  1275. // if a _cache_serial was set, we also have to write an include-file:
  1276. if ($this->_cache_include_info) {
  1277. require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php');
  1278. smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this);
  1279. }
  1280. $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content);
  1281. require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
  1282. smarty_core_write_compiled_resource($_params, $this);
  1283. return true;
  1284. } else {
  1285. return false;
  1286. }
  1287. }
  1288. /**
  1289. * compile the given source
  1290. *
  1291. * @param string $resource_name
  1292. * @param string $source_content
  1293. * @param string $compiled_content
  1294. * @return boolean
  1295. */
  1296. function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
  1297. {
  1298. if (file_exists(SMARTY_DIR . $this->compiler_file)) {
  1299. require_once(SMARTY_DIR . $this->compiler_file);
  1300. } else {
  1301. // use include_path
  1302. require_once($this->compiler_file);
  1303. }
  1304. $smarty_compiler = new $this->compiler_class;
  1305. $smarty_compiler->template_dir = $this->template_dir;
  1306. $smarty_compiler->compile_dir = $this->compile_dir;
  1307. $smarty_compiler->plugins_dir = $this->plugins_dir;
  1308. $smarty_compiler->config_dir = $this->config_dir;
  1309. $smarty_compiler->force_compile = $this->force_compile;
  1310. $smarty_compiler->caching = $this->caching;
  1311. $smarty_compiler->php_handling = $this->php_handling;
  1312. $smarty_compiler->left_delimiter = $this->left_delimiter;
  1313. $smarty_compiler->right_delimiter = $this->right_delimiter;
  1314. $smarty_compiler->_version = $this->_version;
  1315. $smarty_compiler->security = $this->security;
  1316. $smarty_compiler->secure_dir = $this->secure_dir;
  1317. $smarty_compiler->security_settings = $this->security_settings;
  1318. $smarty_compiler->trusted_dir = $this->trusted_dir;
  1319. $smarty_compiler->use_sub_dirs = $this->use_sub_dirs;
  1320. $smarty_compiler->_reg_objects = &$this->_reg_objects;
  1321. $smarty_compiler->_plugins = &$this->_plugins;
  1322. $smarty_compiler->_tpl_vars = &$this->_tpl_vars;
  1323. $smarty_compiler->default_modifiers = $this->default_modifiers;
  1324. $smarty_compiler->compile_id = $this->_compile_id;
  1325. $smarty_compiler->_config = $this->_config;
  1326. $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;
  1327. if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
  1328. $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];
  1329. }
  1330. $smarty_compiler->_cache_include = $cache_include_path;
  1331. $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
  1332. if ($smarty_compiler->_cache_serial) {
  1333. $this->_cache_include_info = array(
  1334. 'cache_serial'=>$smarty_compiler->_cache_serial
  1335. ,'plugins_code'=>$smarty_compiler->_plugins_code
  1336. ,'include_file_path' => $cache_include_path);
  1337. } else {
  1338. $this->_cache_include_info = null;
  1339. }
  1340. return $_results;
  1341. }
  1342. /**
  1343. * Get the compile path for this resource
  1344. *
  1345. * @param string $resource_name
  1346. * @return string results of {@link _get_auto_filename()}
  1347. */
  1348. function _get_compile_path($resource_name)
  1349. {
  1350. return $this->_get_auto_filename($this->compile_dir, $resource_name,
  1351. $this->_compile_id) . '.php';
  1352. }
  1353. /**
  1354. * fetch the template info. Gets timestamp, and source
  1355. * if get_source is true
  1356. *
  1357. * sets $source_content to the source of the template, and
  1358. * $resource_timestamp to its time stamp
  1359. * @param string $resource_name
  1360. * @param string $source_content
  1361. * @param integer $resource_timestamp
  1362. * @param boolean $get_source
  1363. * @param boolean $quiet
  1364. * @return boolean
  1365. */
  1366. function _fetch_resource_info(&$params)
  1367. {
  1368. if(!isset($params['get_source'])) { $params['get_source'] = true; }
  1369. if(!isset($params['quiet'])) { $params['quiet'] = false; }
  1370. $_return = false;
  1371. $_params = array('resource_name' => $params['resource_name']) ;
  1372. if (isset($params['resource_base_path']))
  1373. $_params['resource_base_path'] = $params['resource_base_path'];
  1374. else
  1375. $_params['resource_base_path'] = $this->template_dir;
  1376. if ($this->_parse_resource_name($_params)) {
  1377. $_resource_type = $_params['resource_type'];
  1378. $_resource_name = $_params['resource_name'];
  1379. switch ($_resource_type) {
  1380. case 'file':
  1381. if ($params['get_source']) {
  1382. $params['source_content'] = $this->_read_file($_resource_name);
  1383. }
  1384. $params['resource_timestamp'] = filemtime($_resource_name);

Large files files are truncated, but you can click here to view the full file