Smarty.class.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: Smarty.class.php
  5. * SVN: $Id: Smarty.class.php 2504 2011-12-28 07:35:29Z liu21st $
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * For questions, help, comments, discussion, etc., please join the
  22. * Smarty mailing list. Send a blank e-mail to
  23. * smarty-discussion-subscribe@googlegroups.com
  24. *
  25. * @link http://www.smarty.net/
  26. * @copyright 2008 New Digital Group, Inc.
  27. * @author Monte Ohrt <monte at ohrt dot com>
  28. * @author Uwe Tews
  29. * @author Rodney Rehm
  30. * @package Smarty
  31. * @version 3.1.6
  32. */
  33. /**
  34. * define shorthand directory separator constant
  35. */
  36. if (!defined('DS')) {
  37. define('DS', DIRECTORY_SEPARATOR);
  38. }
  39. /**
  40. * set SMARTY_DIR to absolute path to Smarty library files.
  41. * Sets SMARTY_DIR only if user application has not already defined it.
  42. */
  43. if (!defined('SMARTY_DIR')) {
  44. define('SMARTY_DIR', dirname(__FILE__) . DS);
  45. }
  46. /**
  47. * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins.
  48. * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
  49. */
  50. if (!defined('SMARTY_SYSPLUGINS_DIR')) {
  51. define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
  52. }
  53. if (!defined('SMARTY_PLUGINS_DIR')) {
  54. define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
  55. }
  56. if (!defined('SMARTY_MBSTRING')) {
  57. define('SMARTY_MBSTRING', function_exists('mb_strlen'));
  58. }
  59. if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
  60. // UTF-8 can only be done properly when mbstring is available!
  61. define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');
  62. }
  63. if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
  64. define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
  65. }
  66. /**
  67. * register the class autoloader
  68. */
  69. if (!defined('SMARTY_SPL_AUTOLOAD')) {
  70. define('SMARTY_SPL_AUTOLOAD', 0);
  71. }
  72. if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
  73. $registeredAutoLoadFunctions = spl_autoload_functions();
  74. if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
  75. spl_autoload_register();
  76. }
  77. } else {
  78. spl_autoload_register('smartyAutoload');
  79. }
  80. /**
  81. * Load always needed external class files
  82. */
  83. include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_data.php';
  84. include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_templatebase.php';
  85. include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_template.php';
  86. include_once SMARTY_SYSPLUGINS_DIR.'smarty_resource.php';
  87. include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_resource_file.php';
  88. include_once SMARTY_SYSPLUGINS_DIR.'smarty_cacheresource.php';
  89. include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php';
  90. /**
  91. * This is the main Smarty class
  92. * @package Smarty
  93. */
  94. class Smarty extends Smarty_Internal_TemplateBase {
  95. /**#@+
  96. * constant definitions
  97. */
  98. /**
  99. * smarty version
  100. */
  101. const SMARTY_VERSION = 'Smarty-3.1.6';
  102. /**
  103. * define variable scopes
  104. */
  105. const SCOPE_LOCAL = 0;
  106. const SCOPE_PARENT = 1;
  107. const SCOPE_ROOT = 2;
  108. const SCOPE_GLOBAL = 3;
  109. /**
  110. * define caching modes
  111. */
  112. const CACHING_OFF = 0;
  113. const CACHING_LIFETIME_CURRENT = 1;
  114. const CACHING_LIFETIME_SAVED = 2;
  115. /**
  116. * define compile check modes
  117. */
  118. const COMPILECHECK_OFF = 0;
  119. const COMPILECHECK_ON = 1;
  120. const COMPILECHECK_CACHEMISS = 2;
  121. /**
  122. * modes for handling of "<?php ... ?>" tags in templates.
  123. */
  124. const PHP_PASSTHRU = 0; //-> print tags as plain text
  125. const PHP_QUOTE = 1; //-> escape tags as entities
  126. const PHP_REMOVE = 2; //-> escape tags as entities
  127. const PHP_ALLOW = 3; //-> escape tags as entities
  128. /**
  129. * filter types
  130. */
  131. const FILTER_POST = 'post';
  132. const FILTER_PRE = 'pre';
  133. const FILTER_OUTPUT = 'output';
  134. const FILTER_VARIABLE = 'variable';
  135. /**
  136. * plugin types
  137. */
  138. const PLUGIN_FUNCTION = 'function';
  139. const PLUGIN_BLOCK = 'block';
  140. const PLUGIN_COMPILER = 'compiler';
  141. const PLUGIN_MODIFIER = 'modifier';
  142. const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
  143. /**#@-*/
  144. /**
  145. * assigned global tpl vars
  146. */
  147. public static $global_tpl_vars = array();
  148. /**
  149. * error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors()
  150. */
  151. public static $_previous_error_handler = null;
  152. /**
  153. * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors()
  154. */
  155. public static $_muted_directories = array();
  156. /**#@+
  157. * variables
  158. */
  159. /**
  160. * auto literal on delimiters with whitspace
  161. * @var boolean
  162. */
  163. public $auto_literal = true;
  164. /**
  165. * display error on not assigned variables
  166. * @var boolean
  167. */
  168. public $error_unassigned = false;
  169. /**
  170. * look up relative filepaths in include_path
  171. * @var boolean
  172. */
  173. public $use_include_path = false;
  174. /**
  175. * template directory
  176. * @var array
  177. */
  178. private $template_dir = array();
  179. /**
  180. * joined template directory string used in cache keys
  181. * @var string
  182. */
  183. public $joined_template_dir = null;
  184. /**
  185. * joined config directory string used in cache keys
  186. * @var string
  187. */
  188. public $joined_config_dir = null;
  189. /**
  190. * default template handler
  191. * @var callable
  192. */
  193. public $default_template_handler_func = null;
  194. /**
  195. * default config handler
  196. * @var callable
  197. */
  198. public $default_config_handler_func = null;
  199. /**
  200. * default plugin handler
  201. * @var callable
  202. */
  203. public $default_plugin_handler_func = null;
  204. /**
  205. * compile directory
  206. * @var string
  207. */
  208. private $compile_dir = null;
  209. /**
  210. * plugins directory
  211. * @var array
  212. */
  213. private $plugins_dir = array();
  214. /**
  215. * cache directory
  216. * @var string
  217. */
  218. private $cache_dir = null;
  219. /**
  220. * config directory
  221. * @var array
  222. */
  223. private $config_dir = array();
  224. /**
  225. * force template compiling?
  226. * @var boolean
  227. */
  228. public $force_compile = false;
  229. /**
  230. * check template for modifications?
  231. * @var boolean
  232. */
  233. public $compile_check = true;
  234. /**
  235. * use sub dirs for compiled/cached files?
  236. * @var boolean
  237. */
  238. public $use_sub_dirs = false;
  239. /**
  240. * allow ambiguous resources (that are made unique by the resource handler)
  241. * @var boolean
  242. */
  243. public $allow_ambiguous_resources = false;
  244. /**
  245. * caching enabled
  246. * @var boolean
  247. */
  248. public $caching = false;
  249. /**
  250. * merge compiled includes
  251. * @var boolean
  252. */
  253. public $merge_compiled_includes = false;
  254. /**
  255. * cache lifetime in seconds
  256. * @var integer
  257. */
  258. public $cache_lifetime = 3600;
  259. /**
  260. * force cache file creation
  261. * @var boolean
  262. */
  263. public $force_cache = false;
  264. /**
  265. * Set this if you want different sets of cache files for the same
  266. * templates.
  267. *
  268. * @var string
  269. */
  270. public $cache_id = null;
  271. /**
  272. * Set this if you want different sets of compiled files for the same
  273. * templates.
  274. *
  275. * @var string
  276. */
  277. public $compile_id = null;
  278. /**
  279. * template left-delimiter
  280. * @var string
  281. */
  282. public $left_delimiter = "{";
  283. /**
  284. * template right-delimiter
  285. * @var string
  286. */
  287. public $right_delimiter = "}";
  288. /**#@+
  289. * security
  290. */
  291. /**
  292. * class name
  293. *
  294. * This should be instance of Smarty_Security.
  295. *
  296. * @var string
  297. * @see Smarty_Security
  298. */
  299. public $security_class = 'Smarty_Security';
  300. /**
  301. * implementation of security class
  302. *
  303. * @var Smarty_Security
  304. */
  305. public $security_policy = null;
  306. /**
  307. * controls handling of PHP-blocks
  308. *
  309. * @var integer
  310. */
  311. public $php_handling = self::PHP_PASSTHRU;
  312. /**
  313. * controls if the php template file resource is allowed
  314. *
  315. * @var bool
  316. */
  317. public $allow_php_templates = false;
  318. /**
  319. * Should compiled-templates be prevented from being called directly?
  320. *
  321. * {@internal
  322. * Currently used by Smarty_Internal_Template only.
  323. * }}
  324. *
  325. * @var boolean
  326. */
  327. public $direct_access_security = true;
  328. /**#@-*/
  329. /**
  330. * debug mode
  331. *
  332. * Setting this to true enables the debug-console.
  333. *
  334. * @var boolean
  335. */
  336. public $debugging = false;
  337. /**
  338. * This determines if debugging is enable-able from the browser.
  339. * <ul>
  340. * <li>NONE => no debugging control allowed</li>
  341. * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  342. * </ul>
  343. * @var string
  344. */
  345. public $debugging_ctrl = 'NONE';
  346. /**
  347. * Name of debugging URL-param.
  348. *
  349. * Only used when $debugging_ctrl is set to 'URL'.
  350. * The name of the URL-parameter that activates debugging.
  351. *
  352. * @var type
  353. */
  354. public $smarty_debug_id = 'SMARTY_DEBUG';
  355. /**
  356. * Path of debug template.
  357. * @var string
  358. */
  359. public $debug_tpl = null;
  360. /**
  361. * When set, smarty uses this value as error_reporting-level.
  362. * @var int
  363. */
  364. public $error_reporting = null;
  365. /**
  366. * Internal flag for getTags()
  367. * @var boolean
  368. */
  369. public $get_used_tags = false;
  370. /**#@+
  371. * config var settings
  372. */
  373. /**
  374. * Controls whether variables with the same name overwrite each other.
  375. * @var boolean
  376. */
  377. public $config_overwrite = true;
  378. /**
  379. * Controls whether config values of on/true/yes and off/false/no get converted to boolean.
  380. * @var boolean
  381. */
  382. public $config_booleanize = true;
  383. /**
  384. * Controls whether hidden config sections/vars are read from the file.
  385. * @var boolean
  386. */
  387. public $config_read_hidden = false;
  388. /**#@-*/
  389. /**#@+
  390. * resource locking
  391. */
  392. /**
  393. * locking concurrent compiles
  394. * @var boolean
  395. */
  396. public $compile_locking = true;
  397. /**
  398. * Controls whether cache resources should emply locking mechanism
  399. * @var boolean
  400. */
  401. public $cache_locking = false;
  402. /**
  403. * seconds to wait for acquiring a lock before ignoring the write lock
  404. * @var float
  405. */
  406. public $locking_timeout = 10;
  407. /**#@-*/
  408. /**
  409. * global template functions
  410. * @var array
  411. */
  412. public $template_functions = array();
  413. /**
  414. * resource type used if none given
  415. *
  416. * Must be an valid key of $registered_resources.
  417. * @var string
  418. */
  419. public $default_resource_type = 'file';
  420. /**
  421. * caching type
  422. *
  423. * Must be an element of $cache_resource_types.
  424. *
  425. * @var string
  426. */
  427. public $caching_type = 'file';
  428. /**
  429. * internal config properties
  430. * @var array
  431. */
  432. public $properties = array();
  433. /**
  434. * config type
  435. * @var string
  436. */
  437. public $default_config_type = 'file';
  438. /**
  439. * cached template objects
  440. * @var array
  441. */
  442. public $template_objects = array();
  443. /**
  444. * check If-Modified-Since headers
  445. * @var boolean
  446. */
  447. public $cache_modified_check = false;
  448. /**
  449. * registered plugins
  450. * @var array
  451. */
  452. public $registered_plugins = array();
  453. /**
  454. * plugin search order
  455. * @var array
  456. */
  457. public $plugin_search_order = array('function', 'block', 'compiler', 'class');
  458. /**
  459. * registered objects
  460. * @var array
  461. */
  462. public $registered_objects = array();
  463. /**
  464. * registered classes
  465. * @var array
  466. */
  467. public $registered_classes = array();
  468. /**
  469. * registered filters
  470. * @var array
  471. */
  472. public $registered_filters = array();
  473. /**
  474. * registered resources
  475. * @var array
  476. */
  477. public $registered_resources = array();
  478. /**
  479. * resource handler cache
  480. * @var array
  481. */
  482. public $_resource_handlers = array();
  483. /**
  484. * registered cache resources
  485. * @var array
  486. */
  487. public $registered_cache_resources = array();
  488. /**
  489. * cache resource handler cache
  490. * @var array
  491. */
  492. public $_cacheresource_handlers = array();
  493. /**
  494. * autoload filter
  495. * @var array
  496. */
  497. public $autoload_filters = array();
  498. /**
  499. * default modifier
  500. * @var array
  501. */
  502. public $default_modifiers = array();
  503. /**
  504. * autoescape variable output
  505. * @var boolean
  506. */
  507. public $escape_html = false;
  508. /**
  509. * global internal smarty vars
  510. * @var array
  511. */
  512. public static $_smarty_vars = array();
  513. /**
  514. * start time for execution time calculation
  515. * @var int
  516. */
  517. public $start_time = 0;
  518. /**
  519. * default file permissions
  520. * @var int
  521. */
  522. public $_file_perms = 0644;
  523. /**
  524. * default dir permissions
  525. * @var int
  526. */
  527. public $_dir_perms = 0771;
  528. /**
  529. * block tag hierarchy
  530. * @var array
  531. */
  532. public $_tag_stack = array();
  533. /**
  534. * self pointer to Smarty object
  535. * @var Smarty
  536. */
  537. public $smarty;
  538. /**
  539. * required by the compiler for BC
  540. * @var string
  541. */
  542. public $_current_file = null;
  543. /**
  544. * internal flag to enable parser debugging
  545. * @var bool
  546. */
  547. public $_parserdebug = false;
  548. /**
  549. * Saved parameter of merged templates during compilation
  550. *
  551. * @var array
  552. */
  553. public $merged_templates_func = array();
  554. /**#@-*/
  555. /**
  556. * Initialize new Smarty object
  557. *
  558. */
  559. public function __construct()
  560. {
  561. // selfpointer needed by some other class methods
  562. $this->smarty = $this;
  563. if (is_callable('mb_internal_encoding')) {
  564. mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
  565. }
  566. $this->start_time = microtime(true);
  567. // set default dirs
  568. $this->setTemplateDir('.' . DS . 'templates' . DS)
  569. ->setCompileDir('.' . DS . 'templates_c' . DS)
  570. ->setPluginsDir(SMARTY_PLUGINS_DIR)
  571. ->setCacheDir('.' . DS . 'cache' . DS)
  572. ->setConfigDir('.' . DS . 'configs' . DS);
  573. $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl';
  574. if (isset($_SERVER['SCRIPT_NAME'])) {
  575. $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
  576. }
  577. }
  578. /**
  579. * Class destructor
  580. */
  581. public function __destruct()
  582. {
  583. // intentionally left blank
  584. }
  585. /**
  586. * <<magic>> set selfpointer on cloned object
  587. */
  588. public function __clone()
  589. {
  590. $this->smarty = $this;
  591. }
  592. /**
  593. * <<magic>> Generic getter.
  594. *
  595. * Calls the appropriate getter function.
  596. * Issues an E_USER_NOTICE if no valid getter is found.
  597. *
  598. * @param string $name property name
  599. * @return mixed
  600. */
  601. public function __get($name)
  602. {
  603. $allowed = array(
  604. 'template_dir' => 'getTemplateDir',
  605. 'config_dir' => 'getConfigDir',
  606. 'plugins_dir' => 'getPluginsDir',
  607. 'compile_dir' => 'getCompileDir',
  608. 'cache_dir' => 'getCacheDir',
  609. );
  610. if (isset($allowed[$name])) {
  611. return $this->{$allowed[$name]}();
  612. } else {
  613. trigger_error('Undefined property: '. get_class($this) .'::$'. $name, E_USER_NOTICE);
  614. }
  615. }
  616. /**
  617. * <<magic>> Generic setter.
  618. *
  619. * Calls the appropriate setter function.
  620. * Issues an E_USER_NOTICE if no valid setter is found.
  621. *
  622. * @param string $name property name
  623. * @param mixed $value parameter passed to setter
  624. */
  625. public function __set($name, $value)
  626. {
  627. $allowed = array(
  628. 'template_dir' => 'setTemplateDir',
  629. 'config_dir' => 'setConfigDir',
  630. 'plugins_dir' => 'setPluginsDir',
  631. 'compile_dir' => 'setCompileDir',
  632. 'cache_dir' => 'setCacheDir',
  633. );
  634. if (isset($allowed[$name])) {
  635. $this->{$allowed[$name]}($value);
  636. } else {
  637. trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
  638. }
  639. }
  640. /**
  641. * Check if a template resource exists
  642. *
  643. * @param string $resource_name template name
  644. * @return boolean status
  645. */
  646. public function templateExists($resource_name)
  647. {
  648. // create template object
  649. $save = $this->template_objects;
  650. $tpl = new $this->template_class($resource_name, $this);
  651. // check if it does exists
  652. $result = $tpl->source->exists;
  653. $this->template_objects = $save;
  654. return $result;
  655. }
  656. /**
  657. * Returns a single or all global variables
  658. *
  659. * @param object $smarty
  660. * @param string $varname variable name or null
  661. * @return string variable value or or array of variables
  662. */
  663. public function getGlobal($varname = null)
  664. {
  665. if (isset($varname)) {
  666. if (isset(self::$global_tpl_vars[$varname])) {
  667. return self::$global_tpl_vars[$varname]->value;
  668. } else {
  669. return '';
  670. }
  671. } else {
  672. $_result = array();
  673. foreach (self::$global_tpl_vars AS $key => $var) {
  674. $_result[$key] = $var->value;
  675. }
  676. return $_result;
  677. }
  678. }
  679. /**
  680. * Empty cache folder
  681. *
  682. * @param integer $exp_time expiration time
  683. * @param string $type resource type
  684. * @return integer number of cache files deleted
  685. */
  686. function clearAllCache($exp_time = null, $type = null)
  687. {
  688. // load cache resource and call clearAll
  689. $_cache_resource = Smarty_CacheResource::load($this, $type);
  690. Smarty_CacheResource::invalidLoadedCache($this);
  691. return $_cache_resource->clearAll($this, $exp_time);
  692. }
  693. /**
  694. * Empty cache for a specific template
  695. *
  696. * @param string $template_name template name
  697. * @param string $cache_id cache id
  698. * @param string $compile_id compile id
  699. * @param integer $exp_time expiration time
  700. * @param string $type resource type
  701. * @return integer number of cache files deleted
  702. */
  703. public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
  704. {
  705. // load cache resource and call clear
  706. $_cache_resource = Smarty_CacheResource::load($this, $type);
  707. Smarty_CacheResource::invalidLoadedCache($this);
  708. return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
  709. }
  710. /**
  711. * Loads security class and enables security
  712. *
  713. * @param string|Smarty_Security $security_class if a string is used, it must be class-name
  714. * @return Smarty current Smarty instance for chaining
  715. * @throws SmartyException when an invalid class name is provided
  716. */
  717. public function enableSecurity($security_class = null)
  718. {
  719. if ($security_class instanceof Smarty_Security) {
  720. $this->security_policy = $security_class;
  721. return $this;
  722. } elseif (is_object($security_class)) {
  723. throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
  724. }
  725. if ($security_class == null) {
  726. $security_class = $this->security_class;
  727. }
  728. if (!class_exists($security_class)) {
  729. throw new SmartyException("Security class '$security_class' is not defined");
  730. } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
  731. throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
  732. } else {
  733. $this->security_policy = new $security_class($this);
  734. }
  735. return $this;
  736. }
  737. /**
  738. * Disable security
  739. * @return Smarty current Smarty instance for chaining
  740. */
  741. public function disableSecurity()
  742. {
  743. $this->security_policy = null;
  744. return $this;
  745. }
  746. /**
  747. * Set template directory
  748. *
  749. * @param string|array $template_dir directory(s) of template sources
  750. * @return Smarty current Smarty instance for chaining
  751. */
  752. public function setTemplateDir($template_dir)
  753. {
  754. $this->template_dir = array();
  755. foreach ((array) $template_dir as $k => $v) {
  756. $this->template_dir[$k] = rtrim($v, '/\\') . DS;
  757. }
  758. $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
  759. return $this;
  760. }
  761. /**
  762. * Add template directory(s)
  763. *
  764. * @param string|array $template_dir directory(s) of template sources
  765. * @param string $key of the array element to assign the template dir to
  766. * @return Smarty current Smarty instance for chaining
  767. * @throws SmartyException when the given template directory is not valid
  768. */
  769. public function addTemplateDir($template_dir, $key=null)
  770. {
  771. // make sure we're dealing with an array
  772. $this->template_dir = (array) $this->template_dir;
  773. if (is_array($template_dir)) {
  774. foreach ($template_dir as $k => $v) {
  775. if (is_int($k)) {
  776. // indexes are not merged but appended
  777. $this->template_dir[] = rtrim($v, '/\\') . DS;
  778. } else {
  779. // string indexes are overridden
  780. $this->template_dir[$k] = rtrim($v, '/\\') . DS;
  781. }
  782. }
  783. } elseif ($key !== null) {
  784. // override directory at specified index
  785. $this->template_dir[$key] = rtrim($template_dir, '/\\') . DS;
  786. } else {
  787. // append new directory
  788. $this->template_dir[] = rtrim($template_dir, '/\\') . DS;
  789. }
  790. $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
  791. return $this;
  792. }
  793. /**
  794. * Get template directories
  795. *
  796. * @param mixed index of directory to get, null to get all
  797. * @return array|string list of template directories, or directory of $index
  798. */
  799. public function getTemplateDir($index=null)
  800. {
  801. if ($index !== null) {
  802. return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
  803. }
  804. return (array)$this->template_dir;
  805. }
  806. /**
  807. * Set config directory
  808. *
  809. * @param string|array $template_dir directory(s) of configuration sources
  810. * @return Smarty current Smarty instance for chaining
  811. */
  812. public function setConfigDir($config_dir)
  813. {
  814. $this->config_dir = array();
  815. foreach ((array) $config_dir as $k => $v) {
  816. $this->config_dir[$k] = rtrim($v, '/\\') . DS;
  817. }
  818. $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
  819. return $this;
  820. }
  821. /**
  822. * Add config directory(s)
  823. *
  824. * @param string|array $config_dir directory(s) of config sources
  825. * @param string key of the array element to assign the config dir to
  826. * @return Smarty current Smarty instance for chaining
  827. */
  828. public function addConfigDir($config_dir, $key=null)
  829. {
  830. // make sure we're dealing with an array
  831. $this->config_dir = (array) $this->config_dir;
  832. if (is_array($config_dir)) {
  833. foreach ($config_dir as $k => $v) {
  834. if (is_int($k)) {
  835. // indexes are not merged but appended
  836. $this->config_dir[] = rtrim($v, '/\\') . DS;
  837. } else {
  838. // string indexes are overridden
  839. $this->config_dir[$k] = rtrim($v, '/\\') . DS;
  840. }
  841. }
  842. } elseif( $key !== null ) {
  843. // override directory at specified index
  844. $this->config_dir[$key] = rtrim($config_dir, '/\\') . DS;
  845. } else {
  846. // append new directory
  847. $this->config_dir[] = rtrim($config_dir, '/\\') . DS;
  848. }
  849. $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
  850. return $this;
  851. }
  852. /**
  853. * Get config directory
  854. *
  855. * @param mixed index of directory to get, null to get all
  856. * @return array|string configuration directory
  857. */
  858. public function getConfigDir($index=null)
  859. {
  860. if ($index !== null) {
  861. return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
  862. }
  863. return (array)$this->config_dir;
  864. }
  865. /**
  866. * Set plugins directory
  867. *
  868. * @param string|array $plugins_dir directory(s) of plugins
  869. * @return Smarty current Smarty instance for chaining
  870. */
  871. public function setPluginsDir($plugins_dir)
  872. {
  873. $this->plugins_dir = array();
  874. foreach ((array)$plugins_dir as $k => $v) {
  875. $this->plugins_dir[$k] = rtrim($v, '/\\') . DS;
  876. }
  877. return $this;
  878. }
  879. /**
  880. * Adds directory of plugin files
  881. *
  882. * @param object $smarty
  883. * @param string $ |array $ plugins folder
  884. * @return Smarty current Smarty instance for chaining
  885. */
  886. public function addPluginsDir($plugins_dir)
  887. {
  888. // make sure we're dealing with an array
  889. $this->plugins_dir = (array) $this->plugins_dir;
  890. if (is_array($plugins_dir)) {
  891. foreach ($plugins_dir as $k => $v) {
  892. if (is_int($k)) {
  893. // indexes are not merged but appended
  894. $this->plugins_dir[] = rtrim($v, '/\\') . DS;
  895. } else {
  896. // string indexes are overridden
  897. $this->plugins_dir[$k] = rtrim($v, '/\\') . DS;
  898. }
  899. }
  900. } else {
  901. // append new directory
  902. $this->plugins_dir[] = rtrim($plugins_dir, '/\\') . DS;
  903. }
  904. $this->plugins_dir = array_unique($this->plugins_dir);
  905. return $this;
  906. }
  907. /**
  908. * Get plugin directories
  909. *
  910. * @return array list of plugin directories
  911. */
  912. public function getPluginsDir()
  913. {
  914. return (array)$this->plugins_dir;
  915. }
  916. /**
  917. * Set compile directory
  918. *
  919. * @param string $compile_dir directory to store compiled templates in
  920. * @return Smarty current Smarty instance for chaining
  921. */
  922. public function setCompileDir($compile_dir)
  923. {
  924. $this->compile_dir = rtrim($compile_dir, '/\\') . DS;
  925. if (!isset(Smarty::$_muted_directories[$this->compile_dir])) {
  926. Smarty::$_muted_directories[$this->compile_dir] = null;
  927. }
  928. return $this;
  929. }
  930. /**
  931. * Get compiled directory
  932. *
  933. * @return string path to compiled templates
  934. */
  935. public function getCompileDir()
  936. {
  937. return $this->compile_dir;
  938. }
  939. /**
  940. * Set cache directory
  941. *
  942. * @param string $cache_dir directory to store cached templates in
  943. * @return Smarty current Smarty instance for chaining
  944. */
  945. public function setCacheDir($cache_dir)
  946. {
  947. $this->cache_dir = rtrim($cache_dir, '/\\') . DS;
  948. if (!isset(Smarty::$_muted_directories[$this->cache_dir])) {
  949. Smarty::$_muted_directories[$this->cache_dir] = null;
  950. }
  951. return $this;
  952. }
  953. /**
  954. * Get cache directory
  955. *
  956. * @return string path of cache directory
  957. */
  958. public function getCacheDir()
  959. {
  960. return $this->cache_dir;
  961. }
  962. /**
  963. * Set default modifiers
  964. *
  965. * @param array|string $modifiers modifier or list of modifiers to set
  966. * @return Smarty current Smarty instance for chaining
  967. */
  968. public function setDefaultModifiers($modifiers)
  969. {
  970. $this->default_modifiers = (array) $modifiers;
  971. return $this;
  972. }
  973. /**
  974. * Add default modifiers
  975. *
  976. * @param array|string $modifiers modifier or list of modifiers to add
  977. * @return Smarty current Smarty instance for chaining
  978. */
  979. public function addDefaultModifiers($modifiers)
  980. {
  981. if (is_array($modifiers)) {
  982. $this->default_modifiers = array_merge($this->default_modifiers, $modifiers);
  983. } else {
  984. $this->default_modifiers[] = $modifiers;
  985. }
  986. return $this;
  987. }
  988. /**
  989. * Get default modifiers
  990. *
  991. * @return array list of default modifiers
  992. */
  993. public function getDefaultModifiers()
  994. {
  995. return $this->default_modifiers;
  996. }
  997. /**
  998. * Set autoload filters
  999. *
  1000. * @param array $filters filters to load automatically
  1001. * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
  1002. * @return Smarty current Smarty instance for chaining
  1003. */
  1004. public function setAutoloadFilters($filters, $type=null)
  1005. {
  1006. if ($type !== null) {
  1007. $this->autoload_filters[$type] = (array) $filters;
  1008. } else {
  1009. $this->autoload_filters = (array) $filters;
  1010. }
  1011. return $this;
  1012. }
  1013. /**
  1014. * Add autoload filters
  1015. *
  1016. * @param array $filters filters to load automatically
  1017. * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
  1018. * @return Smarty current Smarty instance for chaining
  1019. */
  1020. public function addAutoloadFilters($filters, $type=null)
  1021. {
  1022. if ($type !== null) {
  1023. if (!empty($this->autoload_filters[$type])) {
  1024. $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters);
  1025. } else {
  1026. $this->autoload_filters[$type] = (array) $filters;
  1027. }
  1028. } else {
  1029. foreach ((array) $filters as $key => $value) {
  1030. if (!empty($this->autoload_filters[$key])) {
  1031. $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value);
  1032. } else {
  1033. $this->autoload_filters[$key] = (array) $value;
  1034. }
  1035. }
  1036. }
  1037. return $this;
  1038. }
  1039. /**
  1040. * Get autoload filters
  1041. *
  1042. * @param string $type type of filter to get autoloads for. Defaults to all autoload filters
  1043. * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified
  1044. */
  1045. public function getAutoloadFilters($type=null)
  1046. {
  1047. if ($type !== null) {
  1048. return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array();
  1049. }
  1050. return $this->autoload_filters;
  1051. }
  1052. /**
  1053. * return name of debugging template
  1054. *
  1055. * @return string
  1056. */
  1057. public function getDebugTemplate()
  1058. {
  1059. return $this->debug_tpl;
  1060. }
  1061. /**
  1062. * set the debug template
  1063. *
  1064. * @param string $tpl_name
  1065. * @return Smarty current Smarty instance for chaining
  1066. * @throws SmartyException if file is not readable
  1067. */
  1068. public function setDebugTemplate($tpl_name)
  1069. {
  1070. if (!is_readable($tpl_name)) {
  1071. throw new SmartyException("Unknown file '{$tpl_name}'");
  1072. }
  1073. $this->debug_tpl = $tpl_name;
  1074. return $this;
  1075. }
  1076. /**
  1077. * creates a template object
  1078. *
  1079. * @param string $template the resource handle of the template file
  1080. * @param mixed $cache_id cache id to be used with this template
  1081. * @param mixed $compile_id compile id to be used with this template
  1082. * @param object $parent next higher level of Smarty variables
  1083. * @param boolean $do_clone flag is Smarty object shall be cloned
  1084. * @return object template object
  1085. */
  1086. public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
  1087. {
  1088. if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) {
  1089. $parent = $cache_id;
  1090. $cache_id = null;
  1091. }
  1092. if (!empty($parent) && is_array($parent)) {
  1093. $data = $parent;
  1094. $parent = null;
  1095. } else {
  1096. $data = null;
  1097. }
  1098. // default to cache_id and compile_id of Smarty object
  1099. $cache_id = $cache_id === null ? $this->cache_id : $cache_id;
  1100. $compile_id = $compile_id === null ? $this->compile_id : $compile_id;
  1101. // already in template cache?
  1102. if ($this->allow_ambiguous_resources) {
  1103. $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id;
  1104. } else {
  1105. $_templateId = $this->joined_template_dir . '#' . $template . $cache_id . $compile_id;
  1106. }
  1107. if (isset($_templateId[150])) {
  1108. $_templateId = sha1($_templateId);
  1109. }
  1110. if ($do_clone) {
  1111. if (isset($this->template_objects[$_templateId])) {
  1112. // return cached template object
  1113. $tpl = clone $this->template_objects[$_templateId];
  1114. $tpl->smarty = clone $tpl->smarty;
  1115. $tpl->parent = $parent;
  1116. $tpl->tpl_vars = array();
  1117. $tpl->config_vars = array();
  1118. } else {
  1119. $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
  1120. }
  1121. } else {
  1122. if (isset($this->template_objects[$_templateId])) {
  1123. // return cached template object
  1124. $tpl = $this->template_objects[$_templateId];
  1125. $tpl->parent = $parent;
  1126. $tpl->tpl_vars = array();
  1127. $tpl->config_vars = array();
  1128. } else {
  1129. $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
  1130. }
  1131. }
  1132. // fill data if present
  1133. if (!empty($data) && is_array($data)) {
  1134. // set up variable values
  1135. foreach ($data as $_key => $_val) {
  1136. $tpl->tpl_vars[$_key] = new Smarty_variable($_val);
  1137. }
  1138. }
  1139. return $tpl;
  1140. }
  1141. /**
  1142. * Takes unknown classes and loads plugin files for them
  1143. * class name format: Smarty_PluginType_PluginName
  1144. * plugin filename format: plugintype.pluginname.php
  1145. *
  1146. * @param string $plugin_name class plugin name to load
  1147. * @param bool $check check if already loaded
  1148. * @return string |boolean filepath of loaded file or false
  1149. */
  1150. public function loadPlugin($plugin_name, $check = true)
  1151. {
  1152. // if function or class exists, exit silently (already loaded)
  1153. if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) {
  1154. return true;
  1155. }
  1156. // Plugin name is expected to be: Smarty_[Type]_[Name]
  1157. $_name_parts = explode('_', $plugin_name, 3);
  1158. // class name must have three parts to be valid plugin
  1159. // count($_name_parts) < 3 === !isset($_name_parts[2])
  1160. if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') {
  1161. throw new SmartyException("plugin {$plugin_name} is not a valid name format");
  1162. return false;
  1163. }
  1164. // if type is "internal", get plugin from sysplugins
  1165. if (strtolower($_name_parts[1]) == 'internal') {
  1166. $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php';
  1167. if (file_exists($file)) {
  1168. require_once($file);
  1169. return $file;
  1170. } else {
  1171. return false;
  1172. }
  1173. }
  1174. // plugin filename is expected to be: [type].[name].php
  1175. $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
  1176. // loop through plugin dirs and find the plugin
  1177. foreach($this->getPluginsDir() as $_plugin_dir) {
  1178. $names = array(
  1179. $_plugin_dir . $_plugin_filename,
  1180. $_plugin_dir . strtolower($_plugin_filename),
  1181. );
  1182. foreach ($names as $file) {
  1183. if (file_exists($file)) {
  1184. require_once($file);
  1185. return $file;
  1186. }
  1187. if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
  1188. // try PHP include_path
  1189. if (($file = Smarty_Internal_Get_Include_Path::getIncludePath($file)) !== false) {
  1190. require_once($file);
  1191. return $file;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. // no plugin loaded
  1197. return false;
  1198. }
  1199. /**
  1200. * Compile all template files
  1201. *
  1202. * @param string $extension file extension
  1203. * @param bool $force_compile force all to recompile
  1204. * @param int $time_limit
  1205. * @param int $max_errors
  1206. * @return integer number of template files recompiled
  1207. */
  1208. public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
  1209. {
  1210. return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this);
  1211. }
  1212. /**
  1213. * Compile all config files
  1214. *
  1215. * @param string $extension file extension
  1216. * @param bool $force_compile force all to recompile
  1217. * @param int $time_limit
  1218. * @param int $max_errors
  1219. * @return integer number of template files recompiled
  1220. */
  1221. public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
  1222. {
  1223. return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this);
  1224. }
  1225. /**
  1226. * Delete compiled template file
  1227. *
  1228. * @param string $resource_name template name
  1229. * @param string $compile_id compile id
  1230. * @param integer $exp_time expiration time
  1231. * @return integer number of template files deleted
  1232. */
  1233. public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
  1234. {
  1235. return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this);
  1236. }
  1237. /**
  1238. * Return array of tag/attributes of all tags used by an template
  1239. *
  1240. * @param object $templae template object
  1241. * @return array of tag/attributes
  1242. */
  1243. public function getTags(Smarty_Internal_Template $template)
  1244. {
  1245. return Smarty_Internal_Utility::getTags($template);
  1246. }
  1247. /**
  1248. * Run installation test
  1249. *
  1250. * @param array $errors Array to write errors into, rather than outputting them
  1251. * @return boolean true if setup is fine, false if something is wrong
  1252. */
  1253. public function testInstall(&$errors=null)
  1254. {
  1255. return Smarty_Internal_Utility::testInstall($this, $errors);
  1256. }
  1257. /**
  1258. * Error Handler to mute expected messages
  1259. *
  1260. * @link http://php.net/set_error_handler
  1261. * @param integer $errno Error level
  1262. * @return boolean
  1263. */
  1264. public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
  1265. {
  1266. $_is_muted_directory = false;
  1267. // add the SMARTY_DIR to the list of muted directories
  1268. if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) {
  1269. $smarty_dir = realpath(SMARTY_DIR);
  1270. Smarty::$_muted_directories[SMARTY_DIR] = array(
  1271. 'file' => $smarty_dir,
  1272. 'length' => strlen($smarty_dir),
  1273. );
  1274. }
  1275. // walk the muted directories and test against $errfile
  1276. foreach (Smarty::$_muted_directories as $key => &$dir) {
  1277. if (!$dir) {
  1278. // resolve directory and length for speedy comparisons
  1279. $file = realpath($key);
  1280. $dir = array(
  1281. 'file' => $file,
  1282. 'length' => strlen($file),
  1283. );
  1284. }
  1285. if (!strncmp($errfile, $dir['file'], $dir['length'])) {
  1286. $_is_muted_directory = true;
  1287. break;
  1288. }
  1289. }
  1290. // pass to next error handler if this error did not occur inside SMARTY_DIR
  1291. // or the error was within smarty but masked to be ignored
  1292. if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
  1293. if (Smarty::$_previous_error_handler) {
  1294. return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext);
  1295. } else {
  1296. return false;
  1297. }
  1298. }
  1299. }
  1300. /**
  1301. * Enable error handler to mute expected messages
  1302. *
  1303. * @return void
  1304. */
  1305. public static function muteExpectedErrors()
  1306. {
  1307. /*
  1308. error muting is done because some people implemented custom error_handlers using
  1309. http://php.net/set_error_handler and for some reason did not understand the following paragraph:
  1310. It is important to remember that the standard PHP error handler is completely bypassed for the
  1311. error types specified by error_types unless the callback function returns FALSE.
  1312. error_reporting() settings will have no effect and your error handler will be called regardless -
  1313. however you are still able to read the current value of error_reporting and act appropriately.
  1314. Of particular note is that this value will be 0 if the statement that caused the error was
  1315. prepended by the @ error-control operator.
  1316. Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
  1317. - @filemtime() is almost twice as fast as using an additional file_exists()
  1318. - between file_exists() and filemtime() a possible race condition is opened,
  1319. which does not exist using the simple @filemtime() approach.
  1320. */
  1321. $error_handler = array('Smarty', 'mutingErrorHandler');
  1322. $previous = set_error_handler($error_handler);
  1323. // avoid dead loops
  1324. if ($previous !== $error_handler) {
  1325. Smarty::$_previous_error_handler = $previous;
  1326. }
  1327. }
  1328. /**
  1329. * Disable error handler muting expected messages
  1330. *
  1331. * @return void
  1332. */
  1333. public static function unmuteExpectedErrors()
  1334. {
  1335. restore_error_handler();
  1336. }
  1337. }
  1338. /**
  1339. * Smarty exception class
  1340. * @package Smarty
  1341. */
  1342. class SmartyException extends Exception {
  1343. }
  1344. /**
  1345. * Smarty compiler exception class
  1346. * @package Smarty
  1347. */
  1348. class SmartyCompilerException extends SmartyException {
  1349. }
  1350. /**
  1351. * Autoloader
  1352. */
  1353. function smartyAutoload($class)
  1354. {
  1355. $_class = strtolower($class);
  1356. $_classes = array(
  1357. 'smarty_config_source' => true,
  1358. 'smarty_config_compiled' => true,
  1359. 'smarty_security' => true,
  1360. 'smarty_cacheresource' => true,
  1361. 'smarty_cacheresource_custom' => true,
  1362. 'smarty_cacheresource_keyvaluestore' => true,
  1363. 'smarty_resource' => true,
  1364. 'smarty_resource_custom' => true,
  1365. 'smarty_resource_uncompiled' => true,
  1366. 'smarty_resource_recompiled' => true,
  1367. );
  1368. if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) {
  1369. include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
  1370. }
  1371. }
  1372. ?>