Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: Smarty.class.php
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. * For questions, help, comments, discussion, etc., please join the
  20. * Smarty mailing list. Send a blank e-mail to
  21. * smarty-discussion-subscribe@googlegroups.com
  22. *
  23. * @link http://www.smarty.net/
  24. * @copyright 2018 New Digital Group, Inc.
  25. * @copyright 2018 Uwe Tews
  26. * @author Monte Ohrt <monte at ohrt dot com>
  27. * @author Uwe Tews <uwe dot tews at gmail dot com>
  28. * @author Rodney Rehm
  29. * @package Smarty
  30. * @version 3.1.32
  31. */
  32. /**
  33. * set SMARTY_DIR to absolute path to Smarty library files.
  34. * Sets SMARTY_DIR only if user application has not already defined it.
  35. */
  36. if (!defined('SMARTY_DIR')) {
  37. /**
  38. *
  39. */
  40. define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  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. /**
  48. *
  49. */
  50. define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR);
  51. }
  52. if (!defined('SMARTY_PLUGINS_DIR')) {
  53. /**
  54. *
  55. */
  56. define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR);
  57. }
  58. if (!defined('SMARTY_MBSTRING')) {
  59. /**
  60. *
  61. */
  62. define('SMARTY_MBSTRING', function_exists('mb_get_info'));
  63. }
  64. if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
  65. // UTF-8 can only be done properly when mbstring is available!
  66. /**
  67. * @deprecated in favor of Smarty::$_CHARSET
  68. */
  69. define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');
  70. }
  71. if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
  72. /**
  73. * @deprecated in favor of Smarty::$_DATE_FORMAT
  74. */
  75. define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
  76. }
  77. /**
  78. * Load Smarty_Autoloader
  79. */
  80. if (!class_exists('Smarty_Autoloader')) {
  81. include dirname(__FILE__) . '/bootstrap.php';
  82. }
  83. /**
  84. * Load always needed external class files
  85. */
  86. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
  87. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php';
  88. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
  89. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
  90. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
  91. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
  92. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
  93. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
  94. require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
  95. /**
  96. * This is the main Smarty class
  97. *
  98. * @package Smarty
  99. *
  100. * The following methods will be dynamically loaded by the extension handler when they are called.
  101. * They are located in a corresponding Smarty_Internal_Method_xxxx class
  102. *
  103. * @method int clearAllCache(int $exp_time = null, string $type = null)
  104. * @method int clearCache(string $template_name, string $cache_id = null, string $compile_id = null, int $exp_time = null, string $type = null)
  105. * @method int compileAllTemplates(string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, $max_errors = null)
  106. * @method int compileAllConfig(string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, $max_errors = null)
  107. * @method int clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
  108. */
  109. class Smarty extends Smarty_Internal_TemplateBase
  110. {
  111. /**
  112. * smarty version
  113. */
  114. const SMARTY_VERSION = '3.1.32';
  115. /**
  116. * define variable scopes
  117. */
  118. const SCOPE_LOCAL = 1;
  119. const SCOPE_PARENT = 2;
  120. const SCOPE_TPL_ROOT = 4;
  121. const SCOPE_ROOT = 8;
  122. const SCOPE_SMARTY = 16;
  123. const SCOPE_GLOBAL = 32;
  124. /**
  125. * define caching modes
  126. */
  127. const CACHING_OFF = 0;
  128. const CACHING_LIFETIME_CURRENT = 1;
  129. const CACHING_LIFETIME_SAVED = 2;
  130. /**
  131. * define constant for clearing cache files be saved expiration dates
  132. */
  133. const CLEAR_EXPIRED = -1;
  134. /**
  135. * define compile check modes
  136. */
  137. const COMPILECHECK_OFF = 0;
  138. const COMPILECHECK_ON = 1;
  139. const COMPILECHECK_CACHEMISS = 2;
  140. /**
  141. * define debug modes
  142. */
  143. const DEBUG_OFF = 0;
  144. const DEBUG_ON = 1;
  145. const DEBUG_INDIVIDUAL = 2;
  146. /**
  147. * modes for handling of "<?php ... ?>" tags in templates.
  148. */
  149. const PHP_PASSTHRU = 0; //-> print tags as plain text
  150. const PHP_QUOTE = 1; //-> escape tags as entities
  151. const PHP_REMOVE = 2; //-> escape tags as entities
  152. const PHP_ALLOW = 3; //-> escape tags as entities
  153. /**
  154. * filter types
  155. */
  156. const FILTER_POST = 'post';
  157. const FILTER_PRE = 'pre';
  158. const FILTER_OUTPUT = 'output';
  159. const FILTER_VARIABLE = 'variable';
  160. /**
  161. * plugin types
  162. */
  163. const PLUGIN_FUNCTION = 'function';
  164. const PLUGIN_BLOCK = 'block';
  165. const PLUGIN_COMPILER = 'compiler';
  166. const PLUGIN_MODIFIER = 'modifier';
  167. const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
  168. /**
  169. * assigned global tpl vars
  170. */
  171. public static $global_tpl_vars = array();
  172. /**
  173. * Flag denoting if Multibyte String functions are available
  174. */
  175. public static $_MBSTRING = SMARTY_MBSTRING;
  176. /**
  177. * The character set to adhere to (e.g. "UTF-8")
  178. */
  179. public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
  180. /**
  181. * The date format to be used internally
  182. * (accepts date() and strftime())
  183. */
  184. public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
  185. /**
  186. * Flag denoting if PCRE should run in UTF-8 mode
  187. */
  188. public static $_UTF8_MODIFIER = 'u';
  189. /**
  190. * Flag denoting if operating system is windows
  191. */
  192. public static $_IS_WINDOWS = false;
  193. /**
  194. * auto literal on delimiters with whitespace
  195. *
  196. * @var boolean
  197. */
  198. public $auto_literal = true;
  199. /**
  200. * display error on not assigned variables
  201. *
  202. * @var boolean
  203. */
  204. public $error_unassigned = false;
  205. /**
  206. * look up relative file path in include_path
  207. *
  208. * @var boolean
  209. */
  210. public $use_include_path = false;
  211. /**
  212. * flag if template_dir is normalized
  213. *
  214. * @var bool
  215. */
  216. public $_templateDirNormalized = false;
  217. /**
  218. * joined template directory string used in cache keys
  219. *
  220. * @var string
  221. */
  222. public $_joined_template_dir = null;
  223. /**
  224. * flag if config_dir is normalized
  225. *
  226. * @var bool
  227. */
  228. public $_configDirNormalized = false;
  229. /**
  230. * joined config directory string used in cache keys
  231. *
  232. * @var string
  233. */
  234. public $_joined_config_dir = null;
  235. /**
  236. * default template handler
  237. *
  238. * @var callable
  239. */
  240. public $default_template_handler_func = null;
  241. /**
  242. * default config handler
  243. *
  244. * @var callable
  245. */
  246. public $default_config_handler_func = null;
  247. /**
  248. * default plugin handler
  249. *
  250. * @var callable
  251. */
  252. public $default_plugin_handler_func = null;
  253. /**
  254. * flag if template_dir is normalized
  255. *
  256. * @var bool
  257. */
  258. public $_compileDirNormalized = false;
  259. /**
  260. * flag if plugins_dir is normalized
  261. *
  262. * @var bool
  263. */
  264. public $_pluginsDirNormalized = false;
  265. /**
  266. * flag if template_dir is normalized
  267. *
  268. * @var bool
  269. */
  270. public $_cacheDirNormalized = false;
  271. /**
  272. * force template compiling?
  273. *
  274. * @var boolean
  275. */
  276. public $force_compile = false;
  277. /**
  278. * use sub dirs for compiled/cached files?
  279. *
  280. * @var boolean
  281. */
  282. public $use_sub_dirs = false;
  283. /**
  284. * allow ambiguous resources (that are made unique by the resource handler)
  285. *
  286. * @var boolean
  287. */
  288. public $allow_ambiguous_resources = false;
  289. /**
  290. * merge compiled includes
  291. *
  292. * @var boolean
  293. */
  294. public $merge_compiled_includes = false;
  295. /*
  296. * flag for behaviour when extends: resource and {extends} tag are used simultaneous
  297. * if false disable execution of {extends} in templates called by extends resource.
  298. * (behaviour as versions < 3.1.28)
  299. *
  300. * @var boolean
  301. */
  302. public $extends_recursion = true;
  303. /**
  304. * force cache file creation
  305. *
  306. * @var boolean
  307. */
  308. public $force_cache = false;
  309. /**
  310. * template left-delimiter
  311. *
  312. * @var string
  313. */
  314. public $left_delimiter = "{";
  315. /**
  316. * template right-delimiter
  317. *
  318. * @var string
  319. */
  320. public $right_delimiter = "}";
  321. /**
  322. * array of strings which shall be treated as literal by compiler
  323. *
  324. * @var array string
  325. */
  326. public $literals = array();
  327. /**
  328. * class name
  329. * This should be instance of Smarty_Security.
  330. *
  331. * @var string
  332. * @see Smarty_Security
  333. */
  334. public $security_class = 'Smarty_Security';
  335. /**
  336. * implementation of security class
  337. *
  338. * @var Smarty_Security
  339. */
  340. public $security_policy = null;
  341. /**
  342. * controls handling of PHP-blocks
  343. *
  344. * @var integer
  345. */
  346. public $php_handling = self::PHP_PASSTHRU;
  347. /**
  348. * controls if the php template file resource is allowed
  349. *
  350. * @var bool
  351. */
  352. public $allow_php_templates = false;
  353. /**
  354. * debug mode
  355. * Setting this to true enables the debug-console.
  356. *
  357. * @var boolean
  358. */
  359. public $debugging = false;
  360. /**
  361. * This determines if debugging is enable-able from the browser.
  362. * <ul>
  363. * <li>NONE => no debugging control allowed</li>
  364. * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  365. * </ul>
  366. *
  367. * @var string
  368. */
  369. public $debugging_ctrl = 'NONE';
  370. /**
  371. * Name of debugging URL-param.
  372. * Only used when $debugging_ctrl is set to 'URL'.
  373. * The name of the URL-parameter that activates debugging.
  374. *
  375. * @var string
  376. */
  377. public $smarty_debug_id = 'SMARTY_DEBUG';
  378. /**
  379. * Path of debug template.
  380. *
  381. * @var string
  382. */
  383. public $debug_tpl = null;
  384. /**
  385. * When set, smarty uses this value as error_reporting-level.
  386. *
  387. * @var int
  388. */
  389. public $error_reporting = null;
  390. /**
  391. * Controls whether variables with the same name overwrite each other.
  392. *
  393. * @var boolean
  394. */
  395. public $config_overwrite = true;
  396. /**
  397. * Controls whether config values of on/true/yes and off/false/no get converted to boolean.
  398. *
  399. * @var boolean
  400. */
  401. public $config_booleanize = true;
  402. /**
  403. * Controls whether hidden config sections/vars are read from the file.
  404. *
  405. * @var boolean
  406. */
  407. public $config_read_hidden = false;
  408. /**
  409. * locking concurrent compiles
  410. *
  411. * @var boolean
  412. */
  413. public $compile_locking = true;
  414. /**
  415. * Controls whether cache resources should use locking mechanism
  416. *
  417. * @var boolean
  418. */
  419. public $cache_locking = false;
  420. /**
  421. * seconds to wait for acquiring a lock before ignoring the write lock
  422. *
  423. * @var float
  424. */
  425. public $locking_timeout = 10;
  426. /**
  427. * resource type used if none given
  428. * Must be an valid key of $registered_resources.
  429. *
  430. * @var string
  431. */
  432. public $default_resource_type = 'file';
  433. /**
  434. * caching type
  435. * Must be an element of $cache_resource_types.
  436. *
  437. * @var string
  438. */
  439. public $caching_type = 'file';
  440. /**
  441. * config type
  442. *
  443. * @var string
  444. */
  445. public $default_config_type = 'file';
  446. /**
  447. * check If-Modified-Since headers
  448. *
  449. * @var boolean
  450. */
  451. public $cache_modified_check = false;
  452. /**
  453. * registered plugins
  454. *
  455. * @var array
  456. */
  457. public $registered_plugins = array();
  458. /**
  459. * registered objects
  460. *
  461. * @var array
  462. */
  463. public $registered_objects = array();
  464. /**
  465. * registered classes
  466. *
  467. * @var array
  468. */
  469. public $registered_classes = array();
  470. /**
  471. * registered filters
  472. *
  473. * @var array
  474. */
  475. public $registered_filters = array();
  476. /**
  477. * registered resources
  478. *
  479. * @var array
  480. */
  481. public $registered_resources = array();
  482. /**
  483. * registered cache resources
  484. *
  485. * @var array
  486. */
  487. public $registered_cache_resources = array();
  488. /**
  489. * autoload filter
  490. *
  491. * @var array
  492. */
  493. public $autoload_filters = array();
  494. /**
  495. * default modifier
  496. *
  497. * @var array
  498. */
  499. public $default_modifiers = array();
  500. /**
  501. * autoescape variable output
  502. *
  503. * @var boolean
  504. */
  505. public $escape_html = false;
  506. /**
  507. * start time for execution time calculation
  508. *
  509. * @var int
  510. */
  511. public $start_time = 0;
  512. /**
  513. * required by the compiler for BC
  514. *
  515. * @var string
  516. */
  517. public $_current_file = null;
  518. /**
  519. * internal flag to enable parser debugging
  520. *
  521. * @var bool
  522. */
  523. public $_parserdebug = false;
  524. /**
  525. * This object type (Smarty = 1, template = 2, data = 4)
  526. *
  527. * @var int
  528. */
  529. public $_objType = 1;
  530. /**
  531. * Debug object
  532. *
  533. * @var Smarty_Internal_Debug
  534. */
  535. public $_debug = null;
  536. /**
  537. * template directory
  538. *
  539. * @var array
  540. */
  541. protected $template_dir = array('./templates/');
  542. /**
  543. * flags for normalized template directory entries
  544. *
  545. * @var array
  546. */
  547. protected $_processedTemplateDir = array();
  548. /**
  549. * config directory
  550. *
  551. * @var array
  552. */
  553. protected $config_dir = array('./configs/');
  554. /**
  555. * flags for normalized template directory entries
  556. *
  557. * @var array
  558. */
  559. protected $_processedConfigDir = array();
  560. /**
  561. * compile directory
  562. *
  563. * @var string
  564. */
  565. protected $compile_dir = './templates_c/';
  566. /**
  567. * plugins directory
  568. *
  569. * @var array
  570. */
  571. protected $plugins_dir = array();
  572. /**
  573. * cache directory
  574. *
  575. * @var string
  576. */
  577. protected $cache_dir = './cache/';
  578. /**
  579. * removed properties
  580. *
  581. * @var string[]
  582. */
  583. protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
  584. '_dir_perms', '_file_perms', 'plugin_search_order',
  585. 'inheritance_merge_compiled_includes', 'resource_cache_mode',);
  586. /**
  587. * List of private properties which will call getter/setter on a direct access
  588. *
  589. * @var string[]
  590. */
  591. protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
  592. 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
  593. 'cache_dir' => 'CacheDir',);
  594. /**
  595. * Initialize new Smarty object
  596. */
  597. public function __construct()
  598. {
  599. $this->_clearTemplateCache();
  600. parent::__construct();
  601. if (is_callable('mb_internal_encoding')) {
  602. mb_internal_encoding(Smarty::$_CHARSET);
  603. }
  604. $this->start_time = microtime(true);
  605. if (isset($_SERVER[ 'SCRIPT_NAME' ])) {
  606. Smarty::$global_tpl_vars[ 'SCRIPT_NAME' ] = new Smarty_Variable($_SERVER[ 'SCRIPT_NAME' ]);
  607. }
  608. // Check if we're running on windows
  609. Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
  610. // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8
  611. if (Smarty::$_CHARSET !== 'UTF-8') {
  612. Smarty::$_UTF8_MODIFIER = '';
  613. }
  614. }
  615. /**
  616. * Enable error handler to mute expected messages
  617. *
  618. * @return boolean
  619. * @deprecated
  620. */
  621. public static function muteExpectedErrors()
  622. {
  623. return Smarty_Internal_ErrorHandler::muteExpectedErrors();
  624. }
  625. /**
  626. * Disable error handler muting expected messages
  627. *
  628. * @deprecated
  629. */
  630. public static function unmuteExpectedErrors()
  631. {
  632. restore_error_handler();
  633. }
  634. /**
  635. * Check if a template resource exists
  636. *
  637. * @param string $resource_name template name
  638. *
  639. * @return bool status
  640. * @throws \SmartyException
  641. */
  642. public function templateExists($resource_name)
  643. {
  644. // create source object
  645. $source = Smarty_Template_Source::load(null, $this, $resource_name);
  646. return $source->exists;
  647. }
  648. /**
  649. * Loads security class and enables security
  650. *
  651. * @param string|Smarty_Security $security_class if a string is used, it must be class-name
  652. *
  653. * @return Smarty current Smarty instance for chaining
  654. * @throws SmartyException when an invalid class name is provided
  655. */
  656. public function enableSecurity($security_class = null)
  657. {
  658. Smarty_Security::enableSecurity($this, $security_class);
  659. return $this;
  660. }
  661. /**
  662. * Disable security
  663. *
  664. * @return Smarty current Smarty instance for chaining
  665. */
  666. public function disableSecurity()
  667. {
  668. $this->security_policy = null;
  669. return $this;
  670. }
  671. /**
  672. * Add template directory(s)
  673. *
  674. * @param string|array $template_dir directory(s) of template sources
  675. * @param string $key of the array element to assign the template dir to
  676. * @param bool $isConfig true for config_dir
  677. *
  678. * @return Smarty current Smarty instance for chaining
  679. */
  680. public function addTemplateDir($template_dir, $key = null, $isConfig = false)
  681. {
  682. if ($isConfig) {
  683. $processed = &$this->_processedConfigDir;
  684. $dir = &$this->config_dir;
  685. $this->_configDirNormalized = false;
  686. } else {
  687. $processed = &$this->_processedTemplateDir;
  688. $dir = &$this->template_dir;
  689. $this->_templateDirNormalized = false;
  690. }
  691. if (is_array($template_dir)) {
  692. foreach ($template_dir as $k => $v) {
  693. if (is_int($k)) {
  694. // indexes are not merged but appended
  695. $dir[] = $v;
  696. } else {
  697. // string indexes are overridden
  698. $dir[ $k ] = $v;
  699. unset($processed[ $key ]);
  700. }
  701. }
  702. } else {
  703. if ($key !== null) {
  704. // override directory at specified index
  705. $dir[ $key ] = $template_dir;
  706. unset($processed[ $key ]);
  707. } else {
  708. // append new directory
  709. $dir[] = $template_dir;
  710. }
  711. }
  712. return $this;
  713. }
  714. /**
  715. * Get template directories
  716. *
  717. * @param mixed $index index of directory to get, null to get all
  718. * @param bool $isConfig true for config_dir
  719. *
  720. * @return array list of template directories, or directory of $index
  721. */
  722. public function getTemplateDir($index = null, $isConfig = false)
  723. {
  724. if ($isConfig) {
  725. $dir = &$this->config_dir;
  726. } else {
  727. $dir = &$this->template_dir;
  728. }
  729. if ($isConfig ? !$this->_configDirNormalized : !$this->_templateDirNormalized) {
  730. $this->_normalizeTemplateConfig($isConfig);
  731. }
  732. if ($index !== null) {
  733. return isset($dir[ $index ]) ? $dir[ $index ] : null;
  734. }
  735. return $dir;
  736. }
  737. /**
  738. * Set template directory
  739. *
  740. * @param string|array $template_dir directory(s) of template sources
  741. * @param bool $isConfig true for config_dir
  742. *
  743. * @return \Smarty current Smarty instance for chaining
  744. */
  745. public function setTemplateDir($template_dir, $isConfig = false)
  746. {
  747. if ($isConfig) {
  748. $this->config_dir = array();
  749. $this->_processedConfigDir = array();
  750. } else {
  751. $this->template_dir = array();
  752. $this->_processedTemplateDir = array();
  753. }
  754. $this->addTemplateDir($template_dir, null, $isConfig);
  755. return $this;
  756. }
  757. /**
  758. * Add config directory(s)
  759. *
  760. * @param string|array $config_dir directory(s) of config sources
  761. * @param mixed $key key of the array element to assign the config dir to
  762. *
  763. * @return Smarty current Smarty instance for chaining
  764. */
  765. public function addConfigDir($config_dir, $key = null)
  766. {
  767. return $this->addTemplateDir($config_dir, $key, true);
  768. }
  769. /**
  770. * Get config directory
  771. *
  772. * @param mixed $index index of directory to get, null to get all
  773. *
  774. * @return array configuration directory
  775. */
  776. public function getConfigDir($index = null)
  777. {
  778. return $this->getTemplateDir($index, true);
  779. }
  780. /**
  781. * Set config directory
  782. *
  783. * @param $config_dir
  784. *
  785. * @return Smarty current Smarty instance for chaining
  786. */
  787. public function setConfigDir($config_dir)
  788. {
  789. return $this->setTemplateDir($config_dir, true);
  790. }
  791. /**
  792. * Adds directory of plugin files
  793. *
  794. * @param null|array|string $plugins_dir
  795. *
  796. * @return Smarty current Smarty instance for chaining
  797. */
  798. public function addPluginsDir($plugins_dir)
  799. {
  800. if (empty($this->plugins_dir)) {
  801. $this->plugins_dir[] = SMARTY_PLUGINS_DIR;
  802. }
  803. $this->plugins_dir = array_merge($this->plugins_dir, (array)$plugins_dir);
  804. $this->_pluginsDirNormalized = false;
  805. return $this;
  806. }
  807. /**
  808. * Get plugin directories
  809. *
  810. * @return array list of plugin directories
  811. */
  812. public function getPluginsDir()
  813. {
  814. if (empty($this->plugins_dir)) {
  815. $this->plugins_dir[] = SMARTY_PLUGINS_DIR;
  816. $this->_pluginsDirNormalized = false;
  817. }
  818. if (!$this->_pluginsDirNormalized) {
  819. if (!is_array($this->plugins_dir)) {
  820. $this->plugins_dir = (array)$this->plugins_dir;
  821. }
  822. foreach ($this->plugins_dir as $k => $v) {
  823. $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
  824. }
  825. $this->_cache[ 'plugin_files' ] = array();
  826. $this->_pluginsDirNormalized = true;
  827. }
  828. return $this->plugins_dir;
  829. }
  830. /**
  831. * Set plugins directory
  832. *
  833. * @param string|array $plugins_dir directory(s) of plugins
  834. *
  835. * @return Smarty current Smarty instance for chaining
  836. */
  837. public function setPluginsDir($plugins_dir)
  838. {
  839. $this->plugins_dir = (array)$plugins_dir;
  840. $this->_pluginsDirNormalized = false;
  841. return $this;
  842. }
  843. /**
  844. * Get compiled directory
  845. *
  846. * @return string path to compiled templates
  847. */
  848. public function getCompileDir()
  849. {
  850. if (!$this->_compileDirNormalized) {
  851. $this->_normalizeDir('compile_dir', $this->compile_dir);
  852. $this->_compileDirNormalized = true;
  853. }
  854. return $this->compile_dir;
  855. }
  856. /**
  857. *
  858. * @param string $compile_dir directory to store compiled templates in
  859. *
  860. * @return Smarty current Smarty instance for chaining
  861. */
  862. public function setCompileDir($compile_dir)
  863. {
  864. $this->_normalizeDir('compile_dir', $compile_dir);
  865. $this->_compileDirNormalized = true;
  866. return $this;
  867. }
  868. /**
  869. * Get cache directory
  870. *
  871. * @return string path of cache directory
  872. */
  873. public function getCacheDir()
  874. {
  875. if (!$this->_cacheDirNormalized) {
  876. $this->_normalizeDir('cache_dir', $this->cache_dir);
  877. $this->_cacheDirNormalized = true;
  878. }
  879. return $this->cache_dir;
  880. }
  881. /**
  882. * Set cache directory
  883. *
  884. * @param string $cache_dir directory to store cached templates in
  885. *
  886. * @return Smarty current Smarty instance for chaining
  887. */
  888. public function setCacheDir($cache_dir)
  889. {
  890. $this->_normalizeDir('cache_dir', $cache_dir);
  891. $this->_cacheDirNormalized = true;
  892. return $this;
  893. }
  894. /**
  895. * creates a template object
  896. *
  897. * @param string $template the resource handle of the template file
  898. * @param mixed $cache_id cache id to be used with this template
  899. * @param mixed $compile_id compile id to be used with this template
  900. * @param object $parent next higher level of Smarty variables
  901. * @param boolean $do_clone flag is Smarty object shall be cloned
  902. *
  903. * @return \Smarty_Internal_Template template object
  904. * @throws \SmartyException
  905. */
  906. public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
  907. {
  908. if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) {
  909. $parent = $cache_id;
  910. $cache_id = null;
  911. }
  912. if ($parent !== null && is_array($parent)) {
  913. $data = $parent;
  914. $parent = null;
  915. } else {
  916. $data = null;
  917. }
  918. if (!$this->_templateDirNormalized) {
  919. $this->_normalizeTemplateConfig(false);
  920. }
  921. $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
  922. $tpl = null;
  923. if ($this->caching && isset(Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) {
  924. $tpl = $do_clone ? clone Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] :
  925. Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
  926. $tpl->inheritance = null;
  927. $tpl->tpl_vars = $tpl->config_vars = array();
  928. } else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
  929. $tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
  930. $tpl->inheritance = null;
  931. $tpl->tpl_vars = $tpl->config_vars = array();
  932. } else {
  933. /* @var Smarty_Internal_Template $tpl */
  934. $tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
  935. $tpl->templateId = $_templateId;
  936. }
  937. if ($do_clone) {
  938. $tpl->smarty = clone $tpl->smarty;
  939. }
  940. $tpl->parent = $parent ? $parent : $this;
  941. // fill data if present
  942. if (!empty($data) && is_array($data)) {
  943. // set up variable values
  944. foreach ($data as $_key => $_val) {
  945. $tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val);
  946. }
  947. }
  948. if ($this->debugging || $this->debugging_ctrl === 'URL') {
  949. $tpl->smarty->_debug = new Smarty_Internal_Debug();
  950. // check URL debugging control
  951. if (!$this->debugging && $this->debugging_ctrl === 'URL') {
  952. $tpl->smarty->_debug->debugUrl($tpl->smarty);
  953. }
  954. }
  955. return $tpl;
  956. }
  957. /**
  958. * Takes unknown classes and loads plugin files for them
  959. * class name format: Smarty_PluginType_PluginName
  960. * plugin filename format: plugintype.pluginname.php
  961. *
  962. * @param string $plugin_name class plugin name to load
  963. * @param bool $check check if already loaded
  964. *
  965. * @throws SmartyException
  966. * @return string |boolean filepath of loaded file or false
  967. */
  968. public function loadPlugin($plugin_name, $check = true)
  969. {
  970. return $this->ext->loadPlugin->loadPlugin($this, $plugin_name, $check);
  971. }
  972. /**
  973. * Get unique template id
  974. *
  975. * @param string $template_name
  976. * @param null|mixed $cache_id
  977. * @param null|mixed $compile_id
  978. * @param null $caching
  979. * @param \Smarty_Internal_Template $template
  980. *
  981. * @return string
  982. * @throws \SmartyException
  983. */
  984. public function _getTemplateId($template_name,
  985. $cache_id = null,
  986. $compile_id = null,
  987. $caching = null,
  988. Smarty_Internal_Template $template = null)
  989. {
  990. $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
  991. $template_name;
  992. $cache_id = $cache_id === null ? $this->cache_id : $cache_id;
  993. $compile_id = $compile_id === null ? $this->compile_id : $compile_id;
  994. $caching = (int)($caching === null ? $this->caching : $caching);
  995. if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) {
  996. $_templateId =
  997. Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) .
  998. "#{$cache_id}#{$compile_id}#{$caching}";
  999. } else {
  1000. $_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}";
  1001. }
  1002. if (isset($_templateId[ 150 ])) {
  1003. $_templateId = sha1($_templateId);
  1004. }
  1005. return $_templateId;
  1006. }
  1007. /**
  1008. * Normalize path
  1009. * - remove /./ and /../
  1010. * - make it absolute if required
  1011. *
  1012. * @param string $path file path
  1013. * @param bool $realpath if true - convert to absolute
  1014. * false - convert to relative
  1015. * null - keep as it is but remove /./ /../
  1016. *
  1017. * @return string
  1018. */
  1019. public function _realpath($path, $realpath = null)
  1020. {
  1021. static $nds = null;
  1022. static $sepDotsep = null;
  1023. static $sepDot = null;
  1024. static $sepSep =null;
  1025. if (!isset($nds)) {
  1026. $nds = array('/' => '\\', '\\' => '/');
  1027. $sepDotsep = DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR;
  1028. $sepDot = DIRECTORY_SEPARATOR . '.';
  1029. $sepSep = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
  1030. }
  1031. // normalize DIRECTORY_SEPARATOR
  1032. $path = str_replace(array($nds[DIRECTORY_SEPARATOR], $sepDotsep), DIRECTORY_SEPARATOR, $path);
  1033. if (strpos($path,$sepDot) === false && (($realpath === false && $path[0] === '.') || $realpath === null) && $path[0] !== '\\') {
  1034. return $path;
  1035. }
  1036. preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
  1037. $path,
  1038. $parts);
  1039. $path = $parts[ 'path' ];
  1040. if ($parts[ 'root' ] === '\\') {
  1041. $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
  1042. } else {
  1043. if ($realpath !== null && !$parts[ 'root' ]) {
  1044. $path = getcwd() . DIRECTORY_SEPARATOR . $path;
  1045. }
  1046. }
  1047. // remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
  1048. $path = str_replace(array($sepDotsep,$sepSep), DIRECTORY_SEPARATOR, $path);
  1049. // resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
  1050. if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false &&
  1051. preg_match_all('#[\\\\/]([.][.][\\\\/])+#u', $path, $match)
  1052. ) {
  1053. $counts = array();
  1054. foreach ($match[ 0 ] as $m) {
  1055. $counts[] = (int)((strlen($m) - 1) / 3);
  1056. }
  1057. sort($counts);
  1058. foreach ($counts as $count) {
  1059. $path = preg_replace('#([\\\\/]+[^\\\\/]+){' . $count .
  1060. '}[\\\\/]+([.][.][\\\\/]+){' . $count . '}#u',
  1061. DIRECTORY_SEPARATOR,
  1062. $path);
  1063. }
  1064. }
  1065. return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
  1066. }
  1067. /**
  1068. * Empty template objects cache
  1069. */
  1070. public function _clearTemplateCache()
  1071. {
  1072. Smarty_Internal_Template::$isCacheTplObj = array();
  1073. Smarty_Internal_Template::$tplObjCache = array();
  1074. }
  1075. /**
  1076. * @param boolean $use_sub_dirs
  1077. */
  1078. public function setUseSubDirs($use_sub_dirs)
  1079. {
  1080. $this->use_sub_dirs = $use_sub_dirs;
  1081. }
  1082. /**
  1083. * @param int $error_reporting
  1084. */
  1085. public function setErrorReporting($error_reporting)
  1086. {
  1087. $this->error_reporting = $error_reporting;
  1088. }
  1089. /**
  1090. * @param boolean $escape_html
  1091. */
  1092. public function setEscapeHtml($escape_html)
  1093. {
  1094. $this->escape_html = $escape_html;
  1095. }
  1096. /**
  1097. * Return auto_literal flag
  1098. *
  1099. * @return boolean
  1100. */
  1101. public function getAutoLiteral()
  1102. {
  1103. return $this->auto_literal;
  1104. }
  1105. /**
  1106. * Set auto_literal flag
  1107. *
  1108. * @param boolean $auto_literal
  1109. */
  1110. public function setAutoLiteral($auto_literal = true)
  1111. {
  1112. $this->auto_literal = $auto_literal;
  1113. }
  1114. /**
  1115. * @param boolean $force_compile
  1116. */
  1117. public function setForceCompile($force_compile)
  1118. {
  1119. $this->force_compile = $force_compile;
  1120. }
  1121. /**
  1122. * @param boolean $merge_compiled_includes
  1123. */
  1124. public function setMergeCompiledIncludes($merge_compiled_includes)
  1125. {
  1126. $this->merge_compiled_includes = $merge_compiled_includes;
  1127. }
  1128. /**
  1129. * Get left delimiter
  1130. *
  1131. * @return string
  1132. */
  1133. public function getLeftDelimiter()
  1134. {
  1135. return $this->left_delimiter;
  1136. }
  1137. /**
  1138. * Set left delimiter
  1139. *
  1140. * @param string $left_delimiter
  1141. */
  1142. public function setLeftDelimiter($left_delimiter)
  1143. {
  1144. $this->left_delimiter = $left_delimiter;
  1145. }
  1146. /**
  1147. * Get right delimiter
  1148. *
  1149. * @return string $right_delimiter
  1150. */
  1151. public function getRightDelimiter()
  1152. {
  1153. return $this->right_delimiter;
  1154. }
  1155. /**
  1156. * Set right delimiter
  1157. *
  1158. * @param string
  1159. */
  1160. public function setRightDelimiter($right_delimiter)
  1161. {
  1162. $this->right_delimiter = $right_delimiter;
  1163. }
  1164. /**
  1165. * @param boolean $debugging
  1166. */
  1167. public function setDebugging($debugging)
  1168. {
  1169. $this->debugging = $debugging;
  1170. }
  1171. /**
  1172. * @param boolean $config_overwrite
  1173. */
  1174. public function setConfigOverwrite($config_overwrite)
  1175. {
  1176. $this->config_overwrite = $config_overwrite;
  1177. }
  1178. /**
  1179. * @param boolean $config_booleanize
  1180. */
  1181. public function setConfigBooleanize($config_booleanize)
  1182. {
  1183. $this->config_booleanize = $config_booleanize;
  1184. }
  1185. /**
  1186. * @param boolean $config_read_hidden
  1187. */
  1188. public function setConfigReadHidden($config_read_hidden)
  1189. {
  1190. $this->config_read_hidden = $config_read_hidden;
  1191. }
  1192. /**
  1193. * @param boolean $compile_locking
  1194. */
  1195. public function setCompileLocking($compile_locking)
  1196. {
  1197. $this->compile_locking = $compile_locking;
  1198. }
  1199. /**
  1200. * @param string $default_resource_type
  1201. */
  1202. public function setDefaultResourceType($default_resource_type)
  1203. {
  1204. $this->default_resource_type = $default_resource_type;
  1205. }
  1206. /**
  1207. * @param string $caching_type
  1208. */
  1209. public function setCachingType($caching_type)
  1210. {
  1211. $this->caching_type = $caching_type;
  1212. }
  1213. /**
  1214. * Test install
  1215. *
  1216. * @param null $errors
  1217. */
  1218. public function testInstall(&$errors = null)
  1219. {
  1220. Smarty_Internal_TestInstall::testInstall($this, $errors);
  1221. }
  1222. /**
  1223. * Get Smarty object
  1224. *
  1225. * @return Smarty
  1226. */
  1227. public function _getSmartyObj()
  1228. {
  1229. return $this;
  1230. }
  1231. /**
  1232. * <<magic>> Generic getter.
  1233. * Calls the appropriate getter function.
  1234. * Issues an E_USER_NOTICE if no valid getter is found.
  1235. *
  1236. * @param string $name property name
  1237. *
  1238. * @return mixed
  1239. * @throws \SmartyException
  1240. */
  1241. public function __get($name)
  1242. {
  1243. if (isset($this->accessMap[ $name ])) {
  1244. $method = 'get' . $this->accessMap[ $name ];
  1245. return $this->{$method}();
  1246. } else if (isset($this->_cache[ $name ])) {
  1247. return $this->_cache[ $name ];
  1248. } else if (in_array($name, $this->obsoleteProperties)) {
  1249. return null;
  1250. } else {
  1251. trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
  1252. }
  1253. return null;
  1254. }
  1255. /**
  1256. * <<magic>> Generic setter.
  1257. * Calls the appropriate setter function.
  1258. * Issues an E_USER_NOTICE if no valid setter is found.
  1259. *
  1260. * @param string $name property name
  1261. * @param mixed $value parameter passed to setter
  1262. *
  1263. * @throws \SmartyException
  1264. */
  1265. public function __set($name, $value)
  1266. {
  1267. if (isset($this->accessMap[ $name ])) {
  1268. $method = 'set' . $this->accessMap[ $name ];
  1269. $this->{$method}($value);
  1270. } else if (in_array($name, $this->obsoleteProperties)) {
  1271. return;
  1272. } else {
  1273. if (is_object($value) && method_exists($value, $name)) {
  1274. $this->$name = $value;
  1275. } else {
  1276. trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
  1277. }
  1278. }
  1279. }
  1280. /**
  1281. * Normalize and set directory string
  1282. *
  1283. * @param string $dirName cache_dir or compile_dir
  1284. * @param string $dir filepath of folder
  1285. */
  1286. private function _normalizeDir($dirName, $dir)
  1287. {
  1288. $this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true);
  1289. if (class_exists('Smarty_Internal_ErrorHandler', false)) {
  1290. if (!isset(Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ])) {
  1291. Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ] = null;
  1292. }
  1293. }
  1294. }
  1295. /**
  1296. * Normalize template_dir or config_dir
  1297. *
  1298. * @param bool $isConfig true for config_dir
  1299. *
  1300. */
  1301. private function _normalizeTemplateConfig($isConfig)
  1302. {
  1303. if ($isConfig) {
  1304. $processed = &$this->_processedConfigDir;
  1305. $dir = &$this->config_dir;
  1306. } else {
  1307. $processed = &$this->_processedTemplateDir;
  1308. $dir = &$this->template_dir;
  1309. }
  1310. if (!is_array($dir)) {
  1311. $dir = (array)$dir;
  1312. }
  1313. foreach ($dir as $k => $v) {
  1314. if (!isset($processed[ $k ])) {
  1315. $dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
  1316. $processed[ $k ] = true;
  1317. }
  1318. }
  1319. $isConfig ? $this->_configDirNormalized = true : $this->_templateDirNormalized = true;
  1320. $isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) :
  1321. $this->_joined_template_dir = join('#', $this->template_dir);
  1322. }
  1323. }