PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/bblog/libs/Smarty.class.php

https://github.com/escherlat/loquacity
PHP | 2024 lines | 1040 code | 218 blank | 766 comment | 135 complexity | 69709895a55cbe5e707fa3c6d06855ca MD5 | raw file
Possible License(s): AGPL-1.0

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

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

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