You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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