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

/fsn-site-central/mediatheque/include/smarty/libs/SmartyBC.class.php

https://gitlab.com/team_fsn/fsn-php
PHP | 455 lines | 149 code | 37 blank | 269 comment | 0 complexity | 7c166e37933bced8b0adaeb02a9d71d7 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. * This is an array of directories where trusted php scripts reside.
  47. *
  48. * @var array
  49. */
  50. public $trusted_dir = array();
  51. /**
  52. * Initialize new SmartyBC object
  53. *
  54. * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
  55. */
  56. public function __construct(array $options = array())
  57. {
  58. parent::__construct($options);
  59. }
  60. /**
  61. * wrapper for assign_by_ref
  62. *
  63. * @param string $tpl_var the template variable name
  64. * @param mixed &$value the referenced value to assign
  65. */
  66. public function assign_by_ref($tpl_var, &$value)
  67. {
  68. $this->assignByRef($tpl_var, $value);
  69. }
  70. /**
  71. * wrapper for append_by_ref
  72. *
  73. * @param string $tpl_var the template variable name
  74. * @param mixed &$value the referenced value to append
  75. * @param boolean $merge flag if array elements shall be merged
  76. */
  77. public function append_by_ref($tpl_var, &$value, $merge = false)
  78. {
  79. $this->appendByRef($tpl_var, $value, $merge);
  80. }
  81. /**
  82. * clear the given assigned template variable.
  83. *
  84. * @param string $tpl_var the template variable to clear
  85. */
  86. public function clear_assign($tpl_var)
  87. {
  88. $this->clearAssign($tpl_var);
  89. }
  90. /**
  91. * Registers custom function to be used in templates
  92. *
  93. * @param string $function the name of the template function
  94. * @param string $function_impl the name of the PHP function to register
  95. * @param bool $cacheable
  96. * @param mixed $cache_attrs
  97. */
  98. public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
  99. {
  100. $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
  101. }
  102. /**
  103. * Unregisters custom function
  104. *
  105. * @param string $function name of template function
  106. */
  107. public function unregister_function($function)
  108. {
  109. $this->unregisterPlugin('function', $function);
  110. }
  111. /**
  112. * Registers object to be used in templates
  113. *
  114. * @param string $object name of template object
  115. * @param object $object_impl the referenced PHP object to register
  116. * @param array $allowed list of allowed methods (empty = all)
  117. * @param boolean $smarty_args smarty argument format, else traditional
  118. * @param array $block_methods list of methods that are block format
  119. *
  120. * @throws SmartyException
  121. * @internal param array $block_functs list of methods that are block format
  122. */
  123. public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
  124. {
  125. settype($allowed, 'array');
  126. settype($smarty_args, 'boolean');
  127. $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
  128. }
  129. /**
  130. * Unregisters object
  131. *
  132. * @param string $object name of template object
  133. */
  134. public function unregister_object($object)
  135. {
  136. $this->unregisterObject($object);
  137. }
  138. /**
  139. * Registers block function to be used in templates
  140. *
  141. * @param string $block name of template block
  142. * @param string $block_impl PHP function to register
  143. * @param bool $cacheable
  144. * @param mixed $cache_attrs
  145. */
  146. public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
  147. {
  148. $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
  149. }
  150. /**
  151. * Unregisters block function
  152. *
  153. * @param string $block name of template function
  154. */
  155. public function unregister_block($block)
  156. {
  157. $this->unregisterPlugin('block', $block);
  158. }
  159. /**
  160. * Registers compiler function
  161. *
  162. * @param string $function name of template function
  163. * @param string $function_impl name of PHP function to register
  164. * @param bool $cacheable
  165. */
  166. public function register_compiler_function($function, $function_impl, $cacheable = true)
  167. {
  168. $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
  169. }
  170. /**
  171. * Unregisters compiler function
  172. *
  173. * @param string $function name of template function
  174. */
  175. public function unregister_compiler_function($function)
  176. {
  177. $this->unregisterPlugin('compiler', $function);
  178. }
  179. /**
  180. * Registers modifier to be used in templates
  181. *
  182. * @param string $modifier name of template modifier
  183. * @param string $modifier_impl name of PHP function to register
  184. */
  185. public function register_modifier($modifier, $modifier_impl)
  186. {
  187. $this->registerPlugin('modifier', $modifier, $modifier_impl);
  188. }
  189. /**
  190. * Unregisters modifier
  191. *
  192. * @param string $modifier name of template modifier
  193. */
  194. public function unregister_modifier($modifier)
  195. {
  196. $this->unregisterPlugin('modifier', $modifier);
  197. }
  198. /**
  199. * Registers a resource to fetch a template
  200. *
  201. * @param string $type name of resource
  202. * @param array $functions array of functions to handle resource
  203. */
  204. public function register_resource($type, $functions)
  205. {
  206. $this->registerResource($type, $functions);
  207. }
  208. /**
  209. * Unregisters a resource
  210. *
  211. * @param string $type name of resource
  212. */
  213. public function unregister_resource($type)
  214. {
  215. $this->unregisterResource($type);
  216. }
  217. /**
  218. * Registers a prefilter function to apply
  219. * to a template before compiling
  220. *
  221. * @param callable $function
  222. */
  223. public function register_prefilter($function)
  224. {
  225. $this->registerFilter('pre', $function);
  226. }
  227. /**
  228. * Unregisters a prefilter function
  229. *
  230. * @param callable $function
  231. */
  232. public function unregister_prefilter($function)
  233. {
  234. $this->unregisterFilter('pre', $function);
  235. }
  236. /**
  237. * Registers a postfilter function to apply
  238. * to a compiled template after compilation
  239. *
  240. * @param callable $function
  241. */
  242. public function register_postfilter($function)
  243. {
  244. $this->registerFilter('post', $function);
  245. }
  246. /**
  247. * Unregisters a postfilter function
  248. *
  249. * @param callable $function
  250. */
  251. public function unregister_postfilter($function)
  252. {
  253. $this->unregisterFilter('post', $function);
  254. }
  255. /**
  256. * Registers an output filter function to apply
  257. * to a template output
  258. *
  259. * @param callable $function
  260. */
  261. public function register_outputfilter($function)
  262. {
  263. $this->registerFilter('output', $function);
  264. }
  265. /**
  266. * Unregisters an outputfilter function
  267. *
  268. * @param callable $function
  269. */
  270. public function unregister_outputfilter($function)
  271. {
  272. $this->unregisterFilter('output', $function);
  273. }
  274. /**
  275. * load a filter of specified type and name
  276. *
  277. * @param string $type filter type
  278. * @param string $name filter name
  279. */
  280. public function load_filter($type, $name)
  281. {
  282. $this->loadFilter($type, $name);
  283. }
  284. /**
  285. * clear cached content for the given template and cache id
  286. *
  287. * @param string $tpl_file name of template file
  288. * @param string $cache_id name of cache_id
  289. * @param string $compile_id name of compile_id
  290. * @param string $exp_time expiration time
  291. *
  292. * @return boolean
  293. */
  294. public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
  295. {
  296. return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
  297. }
  298. /**
  299. * clear the entire contents of cache (all templates)
  300. *
  301. * @param string $exp_time expire time
  302. *
  303. * @return boolean
  304. */
  305. public function clear_all_cache($exp_time = null)
  306. {
  307. return $this->clearCache(null, null, null, $exp_time);
  308. }
  309. /**
  310. * test to see if valid cache exists for this template
  311. *
  312. * @param string $tpl_file name of template file
  313. * @param string $cache_id
  314. * @param string $compile_id
  315. *
  316. * @return boolean
  317. */
  318. public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
  319. {
  320. return $this->isCached($tpl_file, $cache_id, $compile_id);
  321. }
  322. /**
  323. * clear all the assigned template variables.
  324. */
  325. public function clear_all_assign()
  326. {
  327. $this->clearAllAssign();
  328. }
  329. /**
  330. * clears compiled version of specified template resource,
  331. * or all compiled template files if one is not specified.
  332. * This function is for advanced use only, not normally needed.
  333. *
  334. * @param string $tpl_file
  335. * @param string $compile_id
  336. * @param string $exp_time
  337. *
  338. * @return boolean results of {@link smarty_core_rm_auto()}
  339. */
  340. public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
  341. {
  342. return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
  343. }
  344. /**
  345. * Checks whether requested template exists.
  346. *
  347. * @param string $tpl_file
  348. *
  349. * @return boolean
  350. */
  351. public function template_exists($tpl_file)
  352. {
  353. return $this->templateExists($tpl_file);
  354. }
  355. /**
  356. * Returns an array containing template variables
  357. *
  358. * @param string $name
  359. *
  360. * @return array
  361. */
  362. public function get_template_vars($name = null)
  363. {
  364. return $this->getTemplateVars($name);
  365. }
  366. /**
  367. * Returns an array containing config variables
  368. *
  369. * @param string $name
  370. *
  371. * @return array
  372. */
  373. public function get_config_vars($name = null)
  374. {
  375. return $this->getConfigVars($name);
  376. }
  377. /**
  378. * load configuration values
  379. *
  380. * @param string $file
  381. * @param string $section
  382. * @param string $scope
  383. */
  384. public function config_load($file, $section = null, $scope = 'global')
  385. {
  386. $this->ConfigLoad($file, $section, $scope);
  387. }
  388. /**
  389. * return a reference to a registered object
  390. *
  391. * @param string $name
  392. *
  393. * @return object
  394. */
  395. public function get_registered_object($name)
  396. {
  397. return $this->getRegisteredObject($name);
  398. }
  399. /**
  400. * clear configuration values
  401. *
  402. * @param string $var
  403. */
  404. public function clear_config($var = null)
  405. {
  406. $this->clearConfig($var);
  407. }
  408. /**
  409. * trigger Smarty error
  410. *
  411. * @param string $error_msg
  412. * @param integer $error_type
  413. */
  414. public function trigger_error($error_msg, $error_type = E_USER_WARNING)
  415. {
  416. trigger_error("Smarty error: $error_msg", $error_type);
  417. }
  418. }