Smarty.class.php 47 KB

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