Smarty.class.php 44 KB

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