PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/core/model/smarty/SmartyBC.class.php

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