PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/prestashop/_/tools/smarty/SmartyBC.class.php

https://gitlab.com/A.Julien/sendstockbymail-module-prestashop
PHP | 467 lines | 154 code | 38 blank | 275 comment | 0 complexity | fa38cd66e5affb09324ece9fdafde98b MD5 | raw file
  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: SmartyBC.class.php
  5. * SVN: $Id: $
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. * For questions, help, comments, discussion, etc., please join the
  18. * Smarty mailing list. Send a blank e-mail to
  19. * smarty-discussion-subscribe@googlegroups.com
  20. *
  21. * @link http://www.smarty.net/
  22. * @copyright 2008 New Digital Group, Inc.
  23. * @author Monte Ohrt <monte at ohrt dot com>
  24. * @author Uwe Tews
  25. * @author Rodney Rehm
  26. * @package Smarty
  27. */
  28. /**
  29. * @ignore
  30. */
  31. require_once(dirname(__FILE__) . '/Smarty.class.php');
  32. /**
  33. * Smarty Backward Compatability Wrapper Class
  34. *
  35. * @package Smarty
  36. */
  37. class SmartyBC extends Smarty
  38. {
  39. /**
  40. * Smarty 2 BC
  41. *
  42. * @var string
  43. */
  44. public $_version = self::SMARTY_VERSION;
  45. /**
  46. * Initialize new SmartyBC object
  47. *
  48. * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
  49. */
  50. public function __construct(array $options = array())
  51. {
  52. parent::__construct($options);
  53. // register {php} tag
  54. $this->registerPlugin('block', 'php', 'smarty_php_tag');
  55. }
  56. /**
  57. * wrapper for assign_by_ref
  58. *
  59. * @param string $tpl_var the template variable name
  60. * @param mixed &$value the referenced value to assign
  61. */
  62. public function assign_by_ref($tpl_var, &$value)
  63. {
  64. $this->assignByRef($tpl_var, $value);
  65. }
  66. /**
  67. * wrapper for append_by_ref
  68. *
  69. * @param string $tpl_var the template variable name
  70. * @param mixed &$value the referenced value to append
  71. * @param boolean $merge flag if array elements shall be merged
  72. */
  73. public function append_by_ref($tpl_var, &$value, $merge = false)
  74. {
  75. $this->appendByRef($tpl_var, $value, $merge);
  76. }
  77. /**
  78. * clear the given assigned template variable.
  79. *
  80. * @param string $tpl_var the template variable to clear
  81. */
  82. public function clear_assign($tpl_var)
  83. {
  84. $this->clearAssign($tpl_var);
  85. }
  86. /**
  87. * Registers custom function to be used in templates
  88. *
  89. * @param string $function the name of the template function
  90. * @param string $function_impl the name of the PHP function to register
  91. * @param bool $cacheable
  92. * @param mixed $cache_attrs
  93. */
  94. public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
  95. {
  96. $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
  97. }
  98. /**
  99. * Unregisters custom function
  100. *
  101. * @param string $function name of template function
  102. */
  103. public function unregister_function($function)
  104. {
  105. $this->unregisterPlugin('function', $function);
  106. }
  107. /**
  108. * Registers object to be used in templates
  109. *
  110. * @param string $object name of template object
  111. * @param object $object_impl the referenced PHP object to register
  112. * @param array $allowed list of allowed methods (empty = all)
  113. * @param boolean $smarty_args smarty argument format, else traditional
  114. * @param array $block_methods list of methods that are block format
  115. *
  116. * @throws SmartyException
  117. * @internal param array $block_functs list of methods that are block format
  118. */
  119. public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
  120. {
  121. settype($allowed, 'array');
  122. settype($smarty_args, 'boolean');
  123. $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
  124. }
  125. /**
  126. * Unregisters object
  127. *
  128. * @param string $object name of template object
  129. */
  130. public function unregister_object($object)
  131. {
  132. $this->unregisterObject($object);
  133. }
  134. /**
  135. * Registers block function to be used in templates
  136. *
  137. * @param string $block name of template block
  138. * @param string $block_impl PHP function to register
  139. * @param bool $cacheable
  140. * @param mixed $cache_attrs
  141. */
  142. public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
  143. {
  144. $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
  145. }
  146. /**
  147. * Unregisters block function
  148. *
  149. * @param string $block name of template function
  150. */
  151. public function unregister_block($block)
  152. {
  153. $this->unregisterPlugin('block', $block);
  154. }
  155. /**
  156. * Registers compiler function
  157. *
  158. * @param string $function name of template function
  159. * @param string $function_impl name of PHP function to register
  160. * @param bool $cacheable
  161. */
  162. public function register_compiler_function($function, $function_impl, $cacheable = true)
  163. {
  164. $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
  165. }
  166. /**
  167. * Unregisters compiler function
  168. *
  169. * @param string $function name of template function
  170. */
  171. public function unregister_compiler_function($function)
  172. {
  173. $this->unregisterPlugin('compiler', $function);
  174. }
  175. /**
  176. * Registers modifier to be used in templates
  177. *
  178. * @param string $modifier name of template modifier
  179. * @param string $modifier_impl name of PHP function to register
  180. */
  181. public function register_modifier($modifier, $modifier_impl)
  182. {
  183. $this->registerPlugin('modifier', $modifier, $modifier_impl);
  184. }
  185. /**
  186. * Unregisters modifier
  187. *
  188. * @param string $modifier name of template modifier
  189. */
  190. public function unregister_modifier($modifier)
  191. {
  192. $this->unregisterPlugin('modifier', $modifier);
  193. }
  194. /**
  195. * Registers a resource to fetch a template
  196. *
  197. * @param string $type name of resource
  198. * @param array $functions array of functions to handle resource
  199. */
  200. public function register_resource($type, $functions)
  201. {
  202. $this->registerResource($type, $functions);
  203. }
  204. /**
  205. * Unregisters a resource
  206. *
  207. * @param string $type name of resource
  208. */
  209. public function unregister_resource($type)
  210. {
  211. $this->unregisterResource($type);
  212. }
  213. /**
  214. * Registers a prefilter function to apply
  215. * to a template before compiling
  216. *
  217. * @param callable $function
  218. */
  219. public function register_prefilter($function)
  220. {
  221. $this->registerFilter('pre', $function);
  222. }
  223. /**
  224. * Unregisters a prefilter function
  225. *
  226. * @param callable $function
  227. */
  228. public function unregister_prefilter($function)
  229. {
  230. $this->unregisterFilter('pre', $function);
  231. }
  232. /**
  233. * Registers a postfilter function to apply
  234. * to a compiled template after compilation
  235. *
  236. * @param callable $function
  237. */
  238. public function register_postfilter($function)
  239. {
  240. $this->registerFilter('post', $function);
  241. }
  242. /**
  243. * Unregisters a postfilter function
  244. *
  245. * @param callable $function
  246. */
  247. public function unregister_postfilter($function)
  248. {
  249. $this->unregisterFilter('post', $function);
  250. }
  251. /**
  252. * Registers an output filter function to apply
  253. * to a template output
  254. *
  255. * @param callable $function
  256. */
  257. public function register_outputfilter($function)
  258. {
  259. $this->registerFilter('output', $function);
  260. }
  261. /**
  262. * Unregisters an outputfilter function
  263. *
  264. * @param callable $function
  265. */
  266. public function unregister_outputfilter($function)
  267. {
  268. $this->unregisterFilter('output', $function);
  269. }
  270. /**
  271. * load a filter of specified type and name
  272. *
  273. * @param string $type filter type
  274. * @param string $name filter name
  275. */
  276. public function load_filter($type, $name)
  277. {
  278. $this->loadFilter($type, $name);
  279. }
  280. /**
  281. * clear cached content for the given template and cache id
  282. *
  283. * @param string $tpl_file name of template file
  284. * @param string $cache_id name of cache_id
  285. * @param string $compile_id name of compile_id
  286. * @param string $exp_time expiration time
  287. *
  288. * @return boolean
  289. */
  290. public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
  291. {
  292. return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
  293. }
  294. /**
  295. * clear the entire contents of cache (all templates)
  296. *
  297. * @param string $exp_time expire time
  298. *
  299. * @return boolean
  300. */
  301. public function clear_all_cache($exp_time = null)
  302. {
  303. return $this->clearCache(null, null, null, $exp_time);
  304. }
  305. /**
  306. * test to see if valid cache exists for this template
  307. *
  308. * @param string $tpl_file name of template file
  309. * @param string $cache_id
  310. * @param string $compile_id
  311. *
  312. * @return boolean
  313. */
  314. public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
  315. {
  316. return $this->isCached($tpl_file, $cache_id, $compile_id);
  317. }
  318. /**
  319. * clear all the assigned template variables.
  320. */
  321. public function clear_all_assign()
  322. {
  323. $this->clearAllAssign();
  324. }
  325. /**
  326. * clears compiled version of specified template resource,
  327. * or all compiled template files if one is not specified.
  328. * This function is for advanced use only, not normally needed.
  329. *
  330. * @param string $tpl_file
  331. * @param string $compile_id
  332. * @param string $exp_time
  333. *
  334. * @return boolean results of {@link smarty_core_rm_auto()}
  335. */
  336. public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
  337. {
  338. return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
  339. }
  340. /**
  341. * Checks whether requested template exists.
  342. *
  343. * @param string $tpl_file
  344. *
  345. * @return boolean
  346. */
  347. public function template_exists($tpl_file)
  348. {
  349. return $this->templateExists($tpl_file);
  350. }
  351. /**
  352. * Returns an array containing template variables
  353. *
  354. * @param string $name
  355. *
  356. * @return array
  357. */
  358. public function get_template_vars($name = null)
  359. {
  360. return $this->getTemplateVars($name);
  361. }
  362. /**
  363. * Returns an array containing config variables
  364. *
  365. * @param string $name
  366. *
  367. * @return array
  368. */
  369. public function get_config_vars($name = null)
  370. {
  371. return $this->getConfigVars($name);
  372. }
  373. /**
  374. * load configuration values
  375. *
  376. * @param string $file
  377. * @param string $section
  378. * @param string $scope
  379. */
  380. public function config_load($file, $section = null, $scope = 'global')
  381. {
  382. $this->ConfigLoad($file, $section, $scope);
  383. }
  384. /**
  385. * return a reference to a registered object
  386. *
  387. * @param string $name
  388. *
  389. * @return object
  390. */
  391. public function get_registered_object($name)
  392. {
  393. return $this->getRegisteredObject($name);
  394. }
  395. /**
  396. * clear configuration values
  397. *
  398. * @param string $var
  399. */
  400. public function clear_config($var = null)
  401. {
  402. $this->clearConfig($var);
  403. }
  404. /**
  405. * trigger Smarty error
  406. *
  407. * @param string $error_msg
  408. * @param integer $error_type
  409. */
  410. public function trigger_error($error_msg, $error_type = E_USER_WARNING)
  411. {
  412. trigger_error("Smarty error: $error_msg", $error_type);
  413. }
  414. }
  415. /**
  416. * Smarty {php}{/php} block function
  417. *
  418. * @param array $params parameter list
  419. * @param string $content contents of the block
  420. * @param object $template template object
  421. * @param boolean &$repeat repeat flag
  422. *
  423. * @return string content re-formatted
  424. */
  425. function smarty_php_tag($params, $content, $template, &$repeat)
  426. {
  427. eval($content);
  428. return '';
  429. }