PageRenderTime 81ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/legacy/Zikula/View.php

https://github.com/antoniom/core
PHP | 2903 lines | 1206 code | 341 blank | 1356 comment | 142 complexity | 7bddd94170671b1d2b12f6143cb32464 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MIT
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2009 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPLv3 (or at your option, any later version).
  9. * @package Zikula_View
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. use Zikula\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\EventDispatcher\EventDispatcher;
  16. use Zikula\Common\I18n\TranslatableInterface;
  17. use Zikula\Core\Event\GenericEvent;
  18. /**
  19. * Zikula_View class.
  20. */
  21. class Zikula_View extends Smarty implements TranslatableInterface
  22. {
  23. const CACHE_DISABLED = 0;
  24. const CACHE_ENABLED = 1;
  25. const CACHE_INDIVIDUAL = 2;
  26. /**
  27. * Translation domain of the calling module.
  28. *
  29. * @var string
  30. */
  31. public $domain;
  32. /**
  33. * Module info array, indexed by module name.
  34. *
  35. * @var array
  36. */
  37. public $module;
  38. /**
  39. * Module info.
  40. *
  41. * @var array
  42. */
  43. public $modinfo;
  44. /**
  45. * Top level module.
  46. *
  47. * @var string
  48. */
  49. public $toplevelmodule;
  50. /**
  51. * Type.
  52. *
  53. * @var integer
  54. */
  55. public $type;
  56. /**
  57. * Function.
  58. *
  59. * @var string
  60. */
  61. public $func;
  62. /**
  63. * Language.
  64. *
  65. * @var string
  66. */
  67. public $language;
  68. /**
  69. * Homepage flag.
  70. *
  71. * @var boolean
  72. */
  73. public $homepage;
  74. /**
  75. * Theme name.
  76. *
  77. * @var string
  78. */
  79. public $theme;
  80. /**
  81. * Theme info.
  82. *
  83. * @var array
  84. */
  85. public $themeinfo;
  86. /**
  87. * Base Url.
  88. *
  89. * @var string
  90. */
  91. public $baseurl;
  92. /**
  93. * Base Uri.
  94. *
  95. * @var string
  96. */
  97. public $baseuri;
  98. /**
  99. * The service manager instance.
  100. *
  101. * @var \Symfony\Component\DependencyInjection\ContainerBuilder
  102. */
  103. protected $container;
  104. /**
  105. * The event manager instance.
  106. *
  107. * @var EventDispatcher
  108. */
  109. protected $dispatcher;
  110. /**
  111. * Request object.
  112. *
  113. * @var \Symfony\Component\HttpFoundation\Request
  114. */
  115. protected $request;
  116. /**
  117. * Zikula controller.
  118. *
  119. * @var Zikula_AbstractController
  120. */
  121. protected $controller;
  122. /**
  123. * Cache Id.
  124. *
  125. * @var string
  126. */
  127. public $cache_id;
  128. /**
  129. * Whether or not to expose template.
  130. *
  131. * @var boolean
  132. */
  133. public $expose_template;
  134. /**
  135. * Template path (populated by fetch).
  136. *
  137. * @var string
  138. */
  139. protected $templatePath;
  140. /**
  141. * Templates.
  142. *
  143. * @var array
  144. */
  145. protected $templateCache = array();
  146. /**
  147. * Constructor.
  148. *
  149. * @param ContainerBuilder $container ServiceManager.
  150. * @param string $moduleName Module name ("zikula" for system plugins).
  151. * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  152. */
  153. public function __construct(ContainerBuilder $container, $moduleName = '', $caching = null)
  154. {
  155. $this->container = $container;
  156. $this->dispatcher = $this->container->get('event_dispatcher');
  157. $this->request = $this->container->get('request');
  158. // set the error reporting level
  159. $this->error_reporting = isset($container['error_reporting']) ? $container['error_reporting'] : E_ALL;
  160. $this->allow_php_tag = true;
  161. // get variables from input
  162. $module = $this->request->attributes->get('_module', null);
  163. $type = $this->request->attributes->get('_controller', 'user');
  164. $func = $this->request->attributes->get('_action', 'index');
  165. // set vars based on the module structures
  166. $this->homepage = empty($module) ? true : false;
  167. $this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
  168. $this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));
  169. // Initialize the module property with the name of
  170. // the topmost module. For Hooks, Blocks, API Functions and others
  171. // you need to set this property to the name of the respective module!
  172. $this->toplevelmodule = ModUtil::getName();
  173. if (!$moduleName) {
  174. $moduleName = $this->toplevelmodule;
  175. }
  176. $this->modinfo = ModUtil::getInfoFromName($moduleName);
  177. $this->module = array($moduleName => $this->modinfo);
  178. // initialise environment vars
  179. $this->language = ZLanguage::getLanguageCode();
  180. $this->baseurl = System::getBaseUrl();
  181. $this->baseuri = System::getBaseUri();
  182. // system info
  183. $this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
  184. $this->theme = $this->themeinfo['directory'];
  185. //---- Plugins handling -----------------------------------------------
  186. // add plugin paths
  187. switch ($this->modinfo['type']) {
  188. case ModUtil::TYPE_MODULE :
  189. $mpluginPath = "modules/" . $this->modinfo['directory'] . "/Resources/views/plugins";
  190. break;
  191. case ModUtil::TYPE_SYSTEM :
  192. $mpluginPath = "system/" . $this->modinfo['directory'] . "/Rsources/views/plugins";
  193. break;
  194. default:
  195. $mpluginPath = "system/" . $this->modinfo['directory'] . "/Rsources/views/plugins";
  196. }
  197. // add standard plugin search path
  198. $this->plugins_dir = array();
  199. $this->addPluginDir('config/Resources/plugins'); // Official override
  200. $this->addPluginDir('config/plugins'); // Official override
  201. $this->addPluginDir(ZIKULA_ROOT.'/../src/legacy/viewplugins'); // Core plugins
  202. $this->addPluginDir("themes/$this->theme/Resources/views/plugins"); // Theme plugins
  203. $this->addPluginDir(SMARTY_DIR.'plugins'); // Smarty core plugins
  204. $this->addPluginDir($mpluginPath); // Plugins for current module
  205. // check if the 'type' parameter in the URL is admin and if yes,
  206. // include system/Admin/templates/plugins to the plugins_dir array
  207. if ($type === 'admin') {
  208. if (!$this instanceof Zikula_View_Theme) {
  209. $this->addPluginDir('system/AdminModule/Resources/views/plugins');
  210. } else {
  211. $this->load_filter('output', 'admintitle');
  212. }
  213. }
  214. //---- Cache handling -------------------------------------------------
  215. if ($caching && in_array((int)$caching, array(0, 1, 2))) {
  216. $this->caching = (int)$caching;
  217. } else {
  218. $this->caching = (int)ModUtil::getVar('Theme', 'render_cache');
  219. }
  220. $this->compile_id = '';
  221. $this->cache_id = '';
  222. // template compilation
  223. $this->compile_dir = CacheUtil::getLocalDir('view_compiled');
  224. $this->compile_check = ModUtil::getVar('Theme', 'render_compile_check');
  225. $this->force_compile = ModUtil::getVar('Theme', 'render_force_compile');
  226. // template caching
  227. $this->cache_dir = CacheUtil::getLocalDir('view_cache');
  228. $this->cache_lifetime = ModUtil::getVar('Theme', 'render_lifetime');
  229. $this->expose_template = (ModUtil::getVar('Theme', 'render_expose_template') == true) ? true : false;
  230. // register resource type 'z' this defines the way templates are searched
  231. // during {include file='my_template.tpl'} this enables us to store selected module
  232. // templates in the theme while others can be kept in the module itself.
  233. $this->register_resource('z', array('Zikula_View_Resource',
  234. 'z_get_template',
  235. 'z_get_timestamp',
  236. 'z_get_secure',
  237. 'z_get_trusted'));
  238. // set 'z' as default resource type
  239. $this->default_resource_type = 'z';
  240. // process some plugins specially when Render cache is enabled
  241. if (!$this instanceof Zikula_View_Theme && $this->caching) {
  242. $this->register_nocache_plugins();
  243. }
  244. // register the 'nocache' block to allow dynamic zones caching templates
  245. $this->register_block('nocache', array('Zikula_View_Resource', 'block_nocache'), false);
  246. // For ajax requests we use the short urls filter to 'fix' relative paths
  247. if (($this->container->get('zikula')->getStage() & \Zikula\Core\Core::STAGE_AJAX) && System::getVar('shorturls')) {
  248. $this->load_filter('output', 'shorturls');
  249. }
  250. // register prefilters
  251. $this->register_prefilter('z_prefilter_add_literal');
  252. $this->register_prefilter('z_prefilter_gettext_params');
  253. // assign some useful settings
  254. $this->assign('homepage', $this->homepage)
  255. ->assign('modinfo', $this->modinfo)
  256. ->assign('module', $moduleName)
  257. ->assign('toplevelmodule', $this->toplevelmodule)
  258. ->assign('type', $this->type)
  259. ->assign('func', $this->func)
  260. ->assign('lang', $this->language)
  261. ->assign('themeinfo', $this->themeinfo)
  262. ->assign('themepath', $this->baseurl . 'themes/' . $this->theme)
  263. ->assign('baseurl', $this->baseurl)
  264. ->assign('baseuri', $this->baseuri);
  265. // for {gt} template plugin to detect gettext domain
  266. if ($this->modinfo['type'] == ModUtil::TYPE_MODULE) {
  267. $this->domain = ZLanguage::getModuleDomain($this->modinfo['name']);
  268. }
  269. // make render object available to modifiers
  270. parent::assign('zikula_view', $this);
  271. // add ServiceManager, EventManager and others to all templates
  272. parent::assign('container', $this->container);
  273. parent::assign('dispatcher', $this->dispatcher);
  274. parent::assign('zikula_core', $this->container->get('zikula'));
  275. parent::assign('request', $this->request);
  276. parent::assign('modvars', ModUtil::getModvars()); // Get all modvars from any modules that have accessed their modvars at least once.
  277. $this->add_core_data();
  278. // metadata for SEO
  279. if (!isset($this->container['zikula_view.metatags'])) {
  280. $this->container['zikula_view.metatags'] = new ArrayObject(array());
  281. }
  282. parent::assign('metatags', $this->container['zikula_view.metatags']);
  283. $event = new GenericEvent($this);
  284. $this->dispatcher->dispatch('view.init', $event);
  285. }
  286. /**
  287. * Setup the current instance of the Zikula_View class and return it back to the module.
  288. *
  289. * @param string $module Module name.
  290. * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  291. * @param string $cache_id Cache Id.
  292. *
  293. * @return Zikula_View This instance.
  294. */
  295. public static function getInstance($module = null, $caching = null, $cache_id = null)
  296. {
  297. if (is_null($module)) {
  298. $module = ModUtil::getName();
  299. }
  300. $module = preg_match('/\w+Module$/', $module) ? $module : $module.'Module';
  301. $container = ServiceUtil::getManager();
  302. $serviceId = strtolower(sprintf('zikula.view.%s', $module));
  303. if (!$container->has($serviceId)) {
  304. $view = new self($container, $module, $caching);
  305. $container->set($serviceId, $view);
  306. } else {
  307. $view = $container->get($serviceId);
  308. }
  309. if (!is_null($caching)) {
  310. $view->caching = (int)$caching;
  311. }
  312. if (!is_null($cache_id)) {
  313. $view->cache_id = $cache_id;
  314. }
  315. if (!$module) {
  316. $module = $view->toplevelmodule;
  317. }
  318. // if (!array_key_exists($module, $view->module)) {
  319. $view->module[$module] = ModUtil::getInfoFromName($module);
  320. $view->_add_plugins_dir($module);
  321. // }
  322. // for {gt} template plugin to detect gettext domain
  323. if ($view->module[$module]['type'] == ModUtil::TYPE_MODULE) {
  324. $view->domain = ZLanguage::getModuleDomain($view->module[$module]['name']);
  325. }
  326. return $view;
  327. }
  328. /**
  329. * Get module plugin Zikula_View_Plugin instance.
  330. *
  331. * @param string $modName Module name.
  332. * @param string $pluginName Plugin name.
  333. * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  334. * @param string $cache_id Cache Id.
  335. *
  336. * @return Zikula_View_Plugin The plugin instance.
  337. */
  338. public static function getModulePluginInstance($modName, $pluginName, $caching = null, $cache_id = null)
  339. {
  340. return Zikula_View_Plugin::getInstance($modName, $pluginName, $caching, $cache_id);
  341. }
  342. /**
  343. * Get system plugin Zikula_View_Plugin instance.
  344. *
  345. * @param string $pluginName Plugin name.
  346. * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  347. * @param string $cache_id Cache Id.
  348. *
  349. * @return Zikula_View_Plugin The plugin instance.
  350. */
  351. public static function getSystemPluginInstance($pluginName, $caching = null, $cache_id = null)
  352. {
  353. $modName = 'zikula';
  354. return Zikula_View_Plugin::getPluginInstance($modName, $pluginName, $caching, $cache_id);
  355. }
  356. /**
  357. * Internal registration of Zikula core's plugins sensible to cache.
  358. *
  359. * Basically the user-based ones and those that has relation with the theme/pagevars.
  360. *
  361. * @return void
  362. */
  363. protected function register_nocache_plugins()
  364. {
  365. // disables the cache for them and do not load them yet
  366. // that happens later when required
  367. $delayed_load = true;
  368. $cacheable = false;
  369. //// blocks
  370. // checkgroup
  371. Zikula_View_Resource::register($this, 'block', 'checkgroup', $delayed_load, $cacheable, array('gid'));
  372. // checkpermissionblock
  373. Zikula_View_Resource::register($this, 'block', 'checkpermissionblock', $delayed_load, $cacheable, array('component', 'instance'));
  374. // pageaddvarblock
  375. Zikula_View_Resource::register($this, 'block', 'pageaddvarblock', $delayed_load, $cacheable, array('name'));
  376. //// plugins
  377. // ajaxheader
  378. Zikula_View_Resource::register($this, 'function', 'ajaxheader', $delayed_load, $cacheable, array('modname', 'filename', 'noscriptaculous', 'validation', 'lightbox', 'imageviewer', 'assign'));
  379. // assign_cache
  380. Zikula_View_Resource::register($this, 'function', 'assign_cache', $delayed_load, $cacheable, array('var', 'value'));
  381. // checkpermission
  382. Zikula_View_Resource::register($this, 'function', 'checkpermission', $delayed_load, $cacheable, array('component', 'instance', 'level', 'assign'));
  383. // formutil_getfieldmarker
  384. Zikula_View_Resource::register($this, 'function', 'formutil_getfieldmarker', $delayed_load, $cacheable, array('objectType', 'validation', 'field', 'assign'));
  385. // formutil_getpassedvalue
  386. Zikula_View_Resource::register($this, 'function', 'formutil_getpassedvalue', $delayed_load, $cacheable, array('assign', 'html', 'key', 'name', 'default', 'source', 'noprocess'));
  387. // formutil_getvalidationerror
  388. Zikula_View_Resource::register($this, 'function', 'formutil_getvalidationerror', $delayed_load, $cacheable, array('objectType', 'field', 'assign'));
  389. // notifydisplayhooks
  390. Zikula_View_Resource::register($this, 'function', 'notifydisplayhooks', $delayed_load, $cacheable, array('eventname', 'id', 'urlobject', 'assign'));
  391. // notifyevent
  392. Zikula_View_Resource::register($this, 'function', 'notifyevent', $delayed_load, $cacheable, array('eventname', 'eventsubject', 'eventdata', 'assign'));
  393. // pageaddvar
  394. Zikula_View_Resource::register($this, 'function', 'pageaddvar', $delayed_load, $cacheable, array('name', 'value'));
  395. // pagegetvar
  396. Zikula_View_Resource::register($this, 'function', 'pagegetvar', $delayed_load, $cacheable, array('name', 'html', 'assign'));
  397. // pager
  398. Zikula_View_Resource::register($this, 'function', 'pager', $delayed_load, $cacheable, array('modname', 'type', 'func', 'rowcount', 'limit', 'posvar', 'owner', 'template', 'includeStylesheet', 'anchorText', 'maxpages', 'display', 'class', 'processDetailLinks', 'processUrls', 'optimize'));
  399. // pageregistervar
  400. Zikula_View_Resource::register($this, 'function', 'pageregistervar', $delayed_load, $cacheable, array('name'));
  401. // pagesetvar
  402. Zikula_View_Resource::register($this, 'function', 'pagesetvar', $delayed_load, $cacheable, array('name', 'value'));
  403. // servergetvar
  404. Zikula_View_Resource::register($this, 'function', 'servergetvar', $delayed_load, $cacheable, array('name', 'default', 'assign'));
  405. // sessiondelvar
  406. Zikula_View_Resource::register($this, 'function', 'sessiondelvar', $delayed_load, $cacheable, array('name', 'path', 'assign'));
  407. // sessiongetvar
  408. Zikula_View_Resource::register($this, 'function', 'sessiongetvar', $delayed_load, $cacheable, array('name', 'assign', 'default', 'path'));
  409. // sessionsetvar
  410. Zikula_View_Resource::register($this, 'function', 'sessionsetvar', $delayed_load, $cacheable, array('name', 'value', 'path', 'assign'));
  411. // setmetatag
  412. Zikula_View_Resource::register($this, 'function', 'setmetatag', $delayed_load, $cacheable, array('name', 'value'));
  413. // themegetvar
  414. Zikula_View_Resource::register($this, 'function', 'themegetvar', $delayed_load, $cacheable, array('name', 'default', 'assign'));
  415. // themesetvar
  416. Zikula_View_Resource::register($this, 'function', 'themesetvar', $delayed_load, $cacheable, array('name', 'value'));
  417. // user
  418. Zikula_View_Resource::register($this, 'function', 'user', $delayed_load, $cacheable);
  419. // useravatar - without uid caching
  420. Zikula_View_Resource::register($this, 'function', 'useravatar', $delayed_load, $cacheable);
  421. // usergetvar
  422. Zikula_View_Resource::register($this, 'function', 'usergetvar', $delayed_load, $cacheable, array('assign', 'default', 'name', 'uid'));
  423. // userlinks
  424. Zikula_View_Resource::register($this, 'function', 'userlinks', $delayed_load, $cacheable, array('start', 'end', 'seperator'));
  425. // userloggedin
  426. Zikula_View_Resource::register($this, 'function', 'userloggedin', $delayed_load, $cacheable, array('assign'));
  427. // userwelcome
  428. Zikula_View_Resource::register($this, 'function', 'userwelcome', $delayed_load, $cacheable);
  429. // zdebug
  430. Zikula_View_Resource::register($this, 'function', 'zdebug', $delayed_load, $cacheable);
  431. }
  432. /**
  433. * Checks whether requested template exists.
  434. *
  435. * @param string $template Template name.
  436. *
  437. * @return boolean
  438. */
  439. public function template_exists($template)
  440. {
  441. return (bool)$this->get_template_path($template);
  442. }
  443. /**
  444. * Checks which path to use for required template.
  445. *
  446. * @param string $template Template name.
  447. *
  448. * @return string Template path.
  449. */
  450. public function get_template_path($template)
  451. {
  452. if (isset($this->templateCache[$template])) {
  453. return $this->templateCache[$template];
  454. }
  455. // the current module
  456. $modname = ModUtil::getName();
  457. foreach ($this->module as $module => $modinfo) {
  458. // prepare the values for OS
  459. $module = $modinfo['name'];
  460. $os_module = DataUtil::formatForOS($module);
  461. $os_dir = $modinfo['type'] == ModUtil::TYPE_MODULE ? 'modules' : 'system';
  462. $ostemplate = DataUtil::formatForOS($template);
  463. if (is_dir("$os_dir/$os_module/Resources/views")) {
  464. $relativepath = "$os_dir/$os_module/Resources/views";
  465. }
  466. $templatefile = "$relativepath/$ostemplate";
  467. $override = self::getTemplateOverride($templatefile);
  468. if ($override === false) {
  469. // no override present
  470. if (is_readable($templatefile)) {
  471. $this->templateCache[$template] = $relativepath;
  472. return $relativepath;
  473. } else {
  474. return false;
  475. }
  476. } else {
  477. if (is_readable($override)) {
  478. $path = substr($override, 0, strrpos($override, $ostemplate));
  479. $this->templateCache[$template] = $path;
  480. return $path;
  481. }
  482. }
  483. }
  484. // when we arrive here, no path was found
  485. return false;
  486. }
  487. /**
  488. * Add core data to the template.
  489. *
  490. * This function adds some basic data to the template depending on the
  491. * current user and the Zikula settings. There is no need to call this as it's
  492. * invoked automatically on instanciation.
  493. *
  494. * @return Zikula_View
  495. */
  496. public function add_core_data()
  497. {
  498. if (!isset($this->container['zikula_view.coredata'])) {
  499. $this->container['zikula_view.coredata'] = new ArrayObject(array());
  500. }
  501. $core = $this->container['zikula_view.coredata'];
  502. $core['version_num'] = \Zikula\Core\Core::VERSION_NUM;
  503. $core['version_id'] = \Zikula\Core\Core::VERSION_ID;
  504. $core['version_sub'] = \Zikula\Core\Core::VERSION_SUB;
  505. $core['logged_in'] = UserUtil::isLoggedIn();
  506. $core['language'] = $this->language;
  507. // add userdata
  508. $core['user'] = UserUtil::getVars($this->request->getSession()->get('uid'));
  509. // Module vars
  510. parent::assign('coredata', $core);
  511. return $this;
  512. }
  513. /**
  514. * Executes & returns the template results.
  515. *
  516. * This returns the template output instead of displaying it.
  517. * Supply a valid template name.
  518. * As an optional second parameter, you can pass a cache id.
  519. * As an optional third parameter, you can pass a compile id.
  520. *
  521. * @param string $template The name of the template.
  522. * @param string $cache_id The cache ID (optional).
  523. * @param string $compile_id The compile ID (optional).
  524. * @param boolean $display Whether or not to display directly (optional).
  525. * @param boolean $reset Reset singleton defaults (optional). deprecated.
  526. *
  527. * @return string The template output.
  528. */
  529. public function fetch($template, $cache_id = null, $compile_id = null, $display = false, $reset = true)
  530. {
  531. $this->_setup_template($template);
  532. if (is_null($cache_id)) {
  533. $cache_id = $this->cache_id;
  534. }
  535. if (is_null($compile_id)) {
  536. $compile_id = $this->compile_id;
  537. }
  538. $this->template = $this->template_dir . '/' . $template;
  539. $output = $this->_fetch($template, $cache_id, $compile_id, $display);
  540. if ($this->expose_template == true) {
  541. $template = DataUtil::formatForDisplay($template);
  542. $output = "\n<!-- Start " . $this->template_dir . "/$template -->\n" . $output . "\n<!-- End " . $this->template_dir . "/$template -->\n";
  543. }
  544. $event = new GenericEvent($this, array('template' => $template), $output);
  545. try {
  546. $this->dispatcher->dispatch('view.postfetch', $event);
  547. $data = $event->getData();
  548. } catch (Exception $e) {
  549. var_dump($e->getMessage());
  550. }
  551. return $data;
  552. }
  553. /**
  554. * Executes & displays the template results.
  555. *
  556. * This displays the template.
  557. * Supply a valid template name.
  558. * As an optional second parameter, you can pass a cache id.
  559. * As an optional third parameter, you can pass a compile id.
  560. *
  561. * @param string $template The name of the template.
  562. * @param string $cache_id The cache ID (optional).
  563. * @param string $compile_id The compile ID (optional).
  564. *
  565. * @return boolean
  566. */
  567. public function display($template, $cache_id = null, $compile_id = null)
  568. {
  569. echo $this->fetch($template, $cache_id, $compile_id);
  570. return true;
  571. }
  572. /**
  573. * Returns an auto_id for auto-file-functions.
  574. *
  575. * @param string $cache_id The cache ID (optional).
  576. * @param string $compile_id The compile ID (optional).
  577. *
  578. * @return string|null The auto_id, or null if neither $cache_id nor $compile_id are set.
  579. */
  580. public function _get_auto_id($cache_id=null, $compile_id=null)
  581. {
  582. if (!empty($cache_id)) {
  583. $this->_filter_auto_id($cache_id);
  584. }
  585. if (!empty($compile_id)) {
  586. $this->_filter_auto_id($compile_id);
  587. }
  588. $auto_id = $cache_id . (!empty($compile_id) ? '/'.$compile_id : '');
  589. $auto_id = trim($auto_id, '/');
  590. return $auto_id;
  591. }
  592. /**
  593. * utility method to filter the IDs of not desired chars.
  594. *
  595. * @param string &$id Cache or compile ID to filter.
  596. *
  597. * @return void
  598. */
  599. protected function _filter_auto_id(&$id)
  600. {
  601. // convert some chars used as separators
  602. $id = str_replace(array(':', '=', ','), '_', $id);
  603. // convert the "Smarty cache groups" | to paths
  604. $id = str_replace('|', '/', $id);
  605. // and remove anything outside the acceptable range
  606. $id = preg_replace('#[^a-zA-Z0-9-_/]+#', '', $id);
  607. }
  608. /**
  609. * Get a concrete filename for automagically created content.
  610. *
  611. * @param string $path The base path.
  612. * @param string $auto_source The file name (optional).
  613. * @param string $auto_id The ID (optional).
  614. *
  615. * @return string The concrete path and file name to the content.
  616. */
  617. public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
  618. {
  619. // enables a flags to detect when is treating compiled templates
  620. $tocompile = ($path == $this->compile_dir) ? true : false;
  621. // format auto_source for os to make sure that id does not contain 'ugly' characters
  622. $auto_source = DataUtil::formatForOS($auto_source);
  623. // build a hierarchical directory path
  624. $path .= '/' . $this->modinfo['directory'];
  625. if ($this instanceof Zikula_View_Plugin) {
  626. $path .= '_' . $this->pluginName;
  627. }
  628. // add the cache_id path if set
  629. $path .= !empty($auto_id) ? '/' . $auto_id : '';
  630. // takes in account the source subdirectory
  631. $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
  632. // make sure the path exists to write the compiled/cached template there
  633. if (!file_exists($path)) {
  634. mkdir($path, $this->container['system.chmod_dir'], true);
  635. }
  636. // if there's a explicit source, it
  637. if ($auto_source) {
  638. $path .= '/';
  639. $extension = FileUtil::getExtension($auto_source);
  640. // isolates the filename on the source path passed
  641. $path .= FileUtil::getFilebase($auto_source);
  642. // add theme and language to our path
  643. if (empty($themedir)) $themedir = $this->themeinfo['directory'];
  644. $path .= '--t_'.$themedir.'-l_' . $this->language;
  645. // if we are not compiling, end with a suffix
  646. if (!$tocompile) {
  647. $path .= ($extension ? ".$extension" : '');
  648. }
  649. }
  650. return $path;
  651. }
  652. /**
  653. * Finds out if a template is already cached.
  654. *
  655. * This returns true if there is a valid cache for this template.
  656. *
  657. * @param string $template The name of the template.
  658. * @param string $cache_id The cache ID (optional).
  659. * @param string $compile_id The compile ID (optional).
  660. *
  661. * @return boolean
  662. */
  663. public function is_cached($template, $cache_id = null, $compile_id = null)
  664. {
  665. if (is_null($cache_id)) {
  666. $cache_id = $this->cache_id;
  667. }
  668. if (is_null($compile_id)) {
  669. $compile_id = $this->compile_id;
  670. }
  671. return parent::is_cached($template, $cache_id, $compile_id);
  672. }
  673. /**
  674. * Internal function to delete cache of templates.
  675. *
  676. * @param string $tplpath Relative template path.
  677. * @param string $template Template partial filename.
  678. * @param integer $expire Expire limit of the cached templates.
  679. *
  680. * @return boolean True on success, false otherwise
  681. */
  682. protected function rmtpl($tplpath, $template, $expire = null)
  683. {
  684. if (!$template || !is_dir($tplpath) || !is_readable($tplpath)) {
  685. return false;
  686. }
  687. $filebase = FileUtil::getFilebase($template);
  688. $dh = opendir($tplpath);
  689. while (($entry = readdir($dh)) !== false) {
  690. if ($entry != '.' && $entry != '..') {
  691. $path = $tplpath . DIRECTORY_SEPARATOR . $entry;
  692. if (is_dir($path)) {
  693. // search recusively
  694. $this->rmtpl($path, $template, $expire);
  695. } elseif (strpos($entry, $filebase) === 0) {
  696. // delete the files that matches the template base filename
  697. $this->_unlink($path, $expire);
  698. }
  699. }
  700. }
  701. closedir($dh);
  702. return true;
  703. }
  704. /**
  705. * Internal function to delete cache directories and files.
  706. *
  707. * @param string $dirname Relative cache directory path.
  708. * @param integer $expire Expire limit of the cached templates.
  709. * @param boolean $rmbase Remove the passed directory too (default: true).
  710. *
  711. * @return boolean True on success, false otherwise.
  712. */
  713. protected function rmdir($dirname, $expire = null, $rmbase = true)
  714. {
  715. if (!is_dir($dirname) || !is_readable($dirname)) {
  716. return false;
  717. }
  718. $dh = opendir($dirname);
  719. while (($entry = readdir($dh)) !== false) {
  720. if ($entry != '.' && $entry != '..' && $entry != 'index.html') {
  721. $path = $dirname . DIRECTORY_SEPARATOR . $entry;
  722. if (is_dir($path)) {
  723. // remove recursively
  724. $this->rmdir($path, $expire, true);
  725. } elseif ($expire !== false) {
  726. // check expiration time of cached templates
  727. $this->_unlink($path, $expire);
  728. } else {
  729. // delete compiled templates directly
  730. unlink($path);
  731. }
  732. }
  733. }
  734. closedir($dh);
  735. if ($rmbase) {
  736. return rmdir($dirname);
  737. }
  738. return true;
  739. }
  740. /**
  741. * Clears a temporary folder for a auto_id and/or template.
  742. *
  743. * This returns true if the operation was successful.
  744. *
  745. * @param string $tmpdir Name of the temporary folder to clear.
  746. * @param string $auto_id The cache and compile ID.
  747. * @param string $template The name of the template.
  748. * @param string $expire Minimum age in sec. the cache file must be before it will get cleared (optional).
  749. *
  750. * @return boolean
  751. */
  752. protected function clear_folder($tmpdir, $auto_id = null, $template = null, $expire = null, $themedir = null)
  753. {
  754. if (!$auto_id && !$template) {
  755. $result = $this->rmdir($tmpdir, $expire, false);
  756. } else {
  757. $autofolder = $this->_get_auto_filename($tmpdir, null, $auto_id, $themedir);
  758. if ($template) {
  759. $result = $this->rmtpl($autofolder, $template, $expire);
  760. } else {
  761. $result = $this->rmdir($autofolder, $expire);
  762. }
  763. }
  764. return $result;
  765. }
  766. /**
  767. * Clears the cache for a specific template or cache_id.
  768. *
  769. * @param string $template The name of the template.
  770. * @param string $cache_id The cache ID (optional).
  771. * @param string $compile_id The compile ID (optional).
  772. * @param string $expire Minimum age in sec. the cache file must be before it will get cleared (optional).
  773. *
  774. * @return boolean True on success, false otherwise.
  775. */
  776. public function clear_cache($template = null, $cache_id = null, $compile_id = null, $expire = null, $themedir = null)
  777. {
  778. if (is_null($compile_id) && $template) {
  779. $compile_id = $this->compile_id;
  780. }
  781. $auto_id = $this->_get_auto_id($cache_id, $compile_id);
  782. return $this->clear_folder($this->cache_dir, $auto_id, $template, $expire, $themedir);
  783. }
  784. /**
  785. * Clears all view cache for a module.
  786. *
  787. * @return boolean True on success, false otherwise.
  788. */
  789. public function clear_cache_module($moduledir = null)
  790. {
  791. if (is_null($moduledir)) {
  792. $moduledir = $this->modinfo['directory'];
  793. }
  794. return $this->clear_folder($this->cache_dir .'/'. $moduledir);
  795. }
  796. /**
  797. * Clear all compiled templates.
  798. *
  799. * Needs to clear the cache too as non cached plugins information will need regeneration too.
  800. *
  801. * @return boolean True if success, false otherwise.
  802. */
  803. public function clear_compiled()
  804. {
  805. if ($this->clear_folder($this->compile_dir, null, null, false)) {
  806. return $this->clear_all_cache();
  807. }
  808. return false;
  809. }
  810. /**
  811. * Clear all cached templates.
  812. *
  813. * @param string $expire Expire time.
  814. *
  815. * @return boolean Results of clear_cache with null parameters.
  816. */
  817. public function clear_all_cache($expire = null)
  818. {
  819. return $this->clear_cache(null, null, null, $expire);
  820. }
  821. /**
  822. * Set up paths for the template.
  823. *
  824. * This function sets the template and the config path according
  825. * to where the template is found (Theme or Module directory)
  826. *
  827. * @param string $template The template name.
  828. *
  829. * @return void
  830. */
  831. public function _setup_template($template)
  832. {
  833. // default directory for templates
  834. $this->template_dir = $this->get_template_path($template);
  835. $this->templatePath = $this->template_dir . '/' . $template;
  836. $this->config_dir = $this->template_dir . '/config';
  837. }
  838. /**
  839. * Add a plugin dir to the search path.
  840. *
  841. * Avoids adding duplicates.
  842. *
  843. * @param string $dir The directory to add.
  844. * @param boolean $push Whether to push the new dir to the bottom of the stack (default: true).
  845. *
  846. * @return Zikula_View This instance.
  847. */
  848. public function addPluginDir($dir, $push=true)
  849. {
  850. if (in_array($dir, $this->plugins_dir) || !@is_dir($dir)) {
  851. return $this;
  852. }
  853. if ($push) {
  854. array_push($this->plugins_dir, $dir);
  855. } else {
  856. $this->plugins_dir = array_merge(array($dir), $this->plugins_dir);
  857. }
  858. return $this;
  859. }
  860. /**
  861. * add a plugins dir to _plugin_dir array
  862. *
  863. * This function takes module name and adds two path two the plugins_dir array
  864. * when existing
  865. *
  866. * @param string $module Well known module name.
  867. *
  868. * @return void
  869. */
  870. protected function _add_plugins_dir($module)
  871. {
  872. if (empty($module)) {
  873. return;
  874. }
  875. $modinfo = ModUtil::getInfoFromName($module);
  876. if (!$modinfo) {
  877. return;
  878. }
  879. $modpath = ($modinfo['type'] == ModUtil::TYPE_SYSTEM) ? 'system' : 'modules';
  880. if (is_dir("$modpath/$modinfo[directory]/Resources/views/plugins")) {
  881. $this->addPluginDir("$modpath/$modinfo[directory]/Resources/views/plugins");
  882. }
  883. }
  884. /**
  885. * Execute a template override event.
  886. *
  887. * @param string $template Path to template.
  888. *
  889. * @throws InvalidArgumentException If event handler returns a non-existent template.
  890. *
  891. * @return mixed String if found, false if no override present.
  892. */
  893. public static function getTemplateOverride($template)
  894. {
  895. $event = new GenericEvent(null, array(), $template);
  896. EventUtil::getManager()->dispatch('zikula_view.template_override', $event);
  897. if ($event->isPropagationStopped()) {
  898. $ostemplate = DataUtil::formatForOS($event->getData());
  899. if (is_readable($ostemplate)) {
  900. return $ostemplate;
  901. } else {
  902. throw new InvalidArgumentException(__f('zikula_view.template_override returned a non-existent template path %s', $ostemplate));
  903. }
  904. }
  905. return false;
  906. }
  907. /**
  908. * Assign variable to template.
  909. *
  910. * @param string $key Variable name.
  911. * @param mixed $value Value.
  912. *
  913. * @return Zikula_View
  914. */
  915. public function assign($key, $value = null)
  916. {
  917. $this->_assign_check($key);
  918. parent::assign($key, $value);
  919. return $this;
  920. }
  921. /**
  922. * Assign variable to template by reference.
  923. *
  924. * @param string $key Variable name.
  925. * @param mixed &$value Value.
  926. *
  927. * @return Zikula_View
  928. */
  929. public function assign_by_ref($key, &$value)
  930. {
  931. $this->_assign_check($key);
  932. parent::assign_by_ref($key, $value);
  933. return $this;
  934. }
  935. /**
  936. * Prevent certain variables from being overwritten.
  937. *
  938. * @param string $key The protected variable key.
  939. *
  940. * @return void
  941. */
  942. protected function _assign_check($key)
  943. {
  944. if (is_array($key)) {
  945. foreach ($key as $v) {
  946. self::_assign_check($v);
  947. }
  948. return;
  949. }
  950. if (is_string($key)) {
  951. switch (strtolower($key)) {
  952. case 'zikula_view':
  953. case 'zikula_core':
  954. case 'modvars':
  955. case 'metatags':
  956. case 'coredata':
  957. case 'servicemanager':
  958. case 'eventmanager':
  959. $this->trigger_error(__f('%s is a protected template variable and may not be assigned', $key));
  960. break;
  961. }
  962. }
  963. }
  964. /**
  965. * Translate.
  966. *
  967. * @param string $msgid String to be translated.
  968. *
  969. * @return string The $msgid translated by gettext.
  970. */
  971. public function __($msgid)
  972. {
  973. return __($msgid, $this->domain);
  974. }
  975. /**
  976. * Translate with sprintf().
  977. *
  978. * @param string $msgid String to be translated.
  979. * @param string|array $params Args for sprintf().
  980. *
  981. * @return string The $msgid translated by gettext.
  982. */
  983. public function __f($msgid, $params)
  984. {
  985. return __f($msgid, $params, $this->domain);
  986. }
  987. /**
  988. * Translate plural string.
  989. *
  990. * @param string $singular Singular instance.
  991. * @param string $plural Plural instance.
  992. * @param string $count Object count.
  993. *
  994. * @return string Translated string.
  995. */
  996. public function _n($singular, $plural, $count)
  997. {
  998. return _n($singular, $plural, $count, $this->domain);
  999. }
  1000. /**
  1001. * Translate plural string with sprintf().
  1002. *
  1003. * @param string $sin Singular instance.
  1004. * @param string $plu Plural instance.
  1005. * @param string $n Object count.
  1006. * @param string|array $params Sprintf() arguments.
  1007. *
  1008. * @return string The $sin or $plu translated by gettext, based on $n.
  1009. */
  1010. public function _fn($sin, $plu, $n, $params)
  1011. {
  1012. return _fn($sin, $plu, $n, $params, $this->domain);
  1013. }
  1014. /**
  1015. * Retrieves the gettext domain for the module, as {@link ZLanguage::getModuleDomain()}.
  1016. *
  1017. * If the module is a system module this is not set.
  1018. *
  1019. * @return string The gettext domain for the module, or null for system modules.
  1020. */
  1021. public function getDomain()
  1022. {
  1023. return $this->domain;
  1024. }
  1025. /**
  1026. * Retrieve an array of module information, indexed by module name.
  1027. *
  1028. * @return array An array containing the module info, indexed by module name.
  1029. */
  1030. public function getModule()
  1031. {
  1032. return $this->module;
  1033. }
  1034. /**
  1035. * Retrieve the module info array for the top-level module (or the module specified in the constructor).
  1036. *
  1037. * @return array The module info array.
  1038. */
  1039. public function getModInfo()
  1040. {
  1041. return $this->modinfo;
  1042. }
  1043. /**
  1044. * Retrieve the name of the top-level module.
  1045. *
  1046. * @return string The name of the top-level module.
  1047. */
  1048. public function getTopLevelModule()
  1049. {
  1050. return $this->toplevelmodule;
  1051. }
  1052. /**
  1053. * Retrieve module name.
  1054. *
  1055. * @return string Module name.
  1056. */
  1057. public function getModuleName()
  1058. {
  1059. return $this->toplevelmodule;
  1060. }
  1061. /**
  1062. * Retrive the name of the controller type.
  1063. *
  1064. * @return string The name of the controller type.
  1065. */
  1066. public function getType()
  1067. {
  1068. return $this->type;
  1069. }
  1070. /**
  1071. * Retrive the name of the controller function.
  1072. *
  1073. * @return string The name of the controller function.
  1074. */
  1075. public function getFunc()
  1076. {
  1077. return $this->func;
  1078. }
  1079. /**
  1080. * Retrieve the current language code.
  1081. *
  1082. * @return string The current language code.
  1083. */
  1084. public function getLanguage()
  1085. {
  1086. return $this->language;
  1087. }
  1088. /**
  1089. * Retrieve the name of the current theme.
  1090. *
  1091. * @return string The name of the current theme.
  1092. */
  1093. public function getTheme()
  1094. {
  1095. return $this->theme;
  1096. }
  1097. /**
  1098. * Retrieve the theme info array for the current theme.
  1099. *
  1100. * @param string $key Field to retrieve of the theme info.
  1101. *
  1102. * @return array The theme info array.
  1103. */
  1104. public function getThemeInfo($key=null)
  1105. {
  1106. if ($key && array_key_exists($key, $this->themeinfo)) {
  1107. return $this->themeinfo[$key];
  1108. }
  1109. return $this->themeinfo;
  1110. }
  1111. /**
  1112. * Set a value or all the theme info array.
  1113. *
  1114. * @param mixed $value Value to assign.
  1115. * @param string $key Field to set on the theme info.
  1116. *
  1117. * @return void
  1118. */
  1119. public function setThemeInfo($value, $key=null)
  1120. {
  1121. if ($key) {
  1122. $this->themeinfo[$key] = $value;
  1123. }
  1124. $this->themeinfo = $value;
  1125. }
  1126. /**
  1127. * Retrieve the site's base URL.
  1128. *
  1129. * The value returned is the same as {@link System::getBaseUrl()}.
  1130. *
  1131. * @return string The base URL.
  1132. */
  1133. public function getBaseUrl()
  1134. {
  1135. return $this->baseurl;
  1136. }
  1137. /**
  1138. * Retrieve the site's base URI.
  1139. *
  1140. * The value returned is the same as {@link System::getBaseUri()}.
  1141. *
  1142. * @return string The base URI.
  1143. */
  1144. public function getBaseUri()
  1145. {
  1146. return $this->baseuri;
  1147. }
  1148. /**
  1149. * Gets DependencyInjection container.
  1150. *
  1151. * @return ContainerBuilder The service manager.
  1152. */
  1153. public function getContainer()
  1154. {
  1155. return $this->container;
  1156. }
  1157. /**
  1158. * Get EventDispatcher.
  1159. *
  1160. * @return EventDispatcher The event manager.
  1161. */
  1162. public function getDispatcher()
  1163. {
  1164. return $this->dispatcher;
  1165. }
  1166. /**
  1167. * Get the request.
  1168. *
  1169. * @return \Symfony\Component\HttpFoundation\Request
  1170. */
  1171. public function getRequest()
  1172. {
  1173. return $this->request;
  1174. }
  1175. /**
  1176. * Get the Zikula controller.
  1177. *
  1178. * @return \Zikula\Framework\Controller\AbstractController
  1179. */
  1180. public function getController()
  1181. {
  1182. return $this->controller;
  1183. }
  1184. /**
  1185. * Set the controller property.
  1186. *
  1187. * @param \Zikula\Framework\Controller\AbstractController $controller Controller to set.
  1188. *
  1189. * @return void
  1190. */
  1191. public function setController(\Zikula\Framework\Controller\AbstractController $controller)
  1192. {
  1193. $this->controller = $controller;
  1194. }
  1195. /**
  1196. * Retrieve the current setting for the 'render_expose_template' Theme module variable.
  1197. *
  1198. * @return boolean True if The 'render_expose_template' Theme module template is true.
  1199. */
  1200. public function getExposeTemplate()
  1201. {
  1202. return $this->expose_template;
  1203. }
  1204. /**
  1205. * Get template path.
  1206. *
  1207. * This is calculated by _setup_template() invoked during fetch().
  1208. *
  1209. * @return string
  1210. */
  1211. public function getTemplatePath()
  1212. {
  1213. return $this->templatePath;
  1214. }
  1215. /**
  1216. * Retrieve the name of the directory where templates are located.
  1217. *
  1218. * @return string The directory name.
  1219. */
  1220. public function getTemplateDir()
  1221. {
  1222. return $this->template_dir;
  1223. }
  1224. /**
  1225. * Retrieve the template variables array ({@link Smarty::$_tpl_vars}).
  1226. *
  1227. * @return array The template variables array.
  1228. */
  1229. public function getTplVars()
  1230. {
  1231. return $this->_tpl_vars;
  1232. }
  1233. /**
  1234. * Get a template variable.
  1235. *
  1236. * @param string $key Key of assigned template variable.
  1237. *
  1238. * @return mixed
  1239. */
  1240. public function getTplVar($key)
  1241. {
  1242. if (!array_key_exists($key, $this->_tpl_vars)) {
  1243. return null;
  1244. }
  1245. return $this->_tpl_vars[$key];
  1246. }
  1247. /**
  1248. * Retrieve the compile ID used to compile different sets of compiled files for the same templates.
  1249. *
  1250. * @return string|null The compile id, or null if none.
  1251. */
  1252. public function getCompileId()
  1253. {
  1254. return $this->compile_id;
  1255. }
  1256. /**
  1257. * Set this if you want different sets of compiled files for the same templates.
  1258. *
  1259. * This is useful for things like different languages.
  1260. * Instead of creating separate sets of templates per language, you
  1261. * set different compile_ids like 'en' and 'de'.
  1262. *
  1263. * @param string|null $compile_id The compile id, or null.
  1264. *
  1265. * @return $this
  1266. */
  1267. public function setCompileId($compile_id)
  1268. {
  1269. $this->compile_id = $compile_id;
  1270. return $this;
  1271. }
  1272. /**
  1273. * Retrieve the directory where compiled templates are located.
  1274. *
  1275. * @return string The directory name.
  1276. */
  1277. public function getCompileDir()
  1278. {
  1279. return $this->compile_dir;
  1280. }
  1281. /**
  1282. * Set the directory where compiled templates are located.
  1283. *
  1284. * @param string $compile_dir The directory name.
  1285. *
  1286. * @return $this
  1287. */
  1288. public function setCompileDir($compile_dir)
  1289. {
  1290. $this->compile_dir = $compile_dir;
  1291. return $this;
  1292. }
  1293. /**
  1294. * Retrieve the flag that controls whether to check for recompiling or not.
  1295. *
  1296. * Recompiling does not need to happen unless a template or config file is changed.
  1297. * Typically you enable this during development, and disable for production.
  1298. *
  1299. * @return boolean True if checked, otherwise false.
  1300. */
  1301. public function getCompileCheck()
  1302. {
  1303. return $this->compile_check;
  1304. }
  1305. /**
  1306. * Set compile check.
  1307. *
  1308. * @param boolean $doCompileCheck If true, checks for compile will be performed.
  1309. *
  1310. * @return $this
  1311. */
  1312. public function setCompileCheck($doCompileCheck)
  1313. {
  1314. $this->compile_check = $doCompileCheck;
  1315. return $this;
  1316. }
  1317. /**
  1318. * Retrieve whether templates are forced to be compiled.
  1319. *
  1320. * @return boolean True if templates are forced to be compiled, otherwise false.
  1321. */
  1322. public function getForceCompile()
  1323. {
  1324. return $this->force_compile;
  1325. }
  1326. /**
  1327. * Set whether templates are forced to be compiled.
  1328. *
  1329. * @param boolean $force_compile True to force compilation, otherwise false.
  1330. *
  1331. * @return $this
  1332. */
  1333. public function setForceCompile($force_compile)
  1334. {
  1335. $this->force_compile = $force_compile;
  1336. return $this;
  1337. }
  1338. /**
  1339. * Retrieve whether caching is enabled.
  1340. *
  1341. * @return integer A code indicating whether caching is enabled.
  1342. */
  1343. public function getCaching()
  1344. {
  1345. return $this->caching;
  1346. }
  1347. /**
  1348. * Set Caching.
  1349. *
  1350. * Possible value:
  1351. * <ul>
  1352. * <li>0 = no caching</li>
  1353. * <li>1 = use class cache_lifetime value</li>
  1354. * <li>2 = use cache_lifetime in cache file</li>
  1355. * </ul>
  1356. *
  1357. * @param integer $caching Cache value to set.
  1358. *
  1359. * @return $this
  1360. */
  1361. public function setCaching($caching)
  1362. {
  1363. $this->caching = (int)$caching;
  1364. return $this;
  1365. }
  1366. /**
  1367. * Retrieve the current cache ID.
  1368. *
  1369. * @return string The current cache ID.
  1370. */
  1371. public function getCacheId()
  1372. {
  1373. return $this->cache_id;
  1374. }
  1375. /**
  1376. * Set cache ID.
  1377. *
  1378. * @param string $id Cache ID.
  1379. *
  1380. * @return $this
  1381. */
  1382. public function setCacheId($id)
  1383. {
  1384. $this->cache_id = $id;
  1385. return $this;
  1386. }
  1387. /**
  1388. * Retrieve the number of seconds cached content will persist.
  1389. *
  1390. * Special values:
  1391. * <ul>
  1392. * <li>0 = always regenerate cache</li>
  1393. * <li>-1 = never expires</li>
  1394. * </ul>
  1395. *
  1396. * @return integer The number of seconds cached content will persist.
  1397. */
  1398. public function getCacheLifetime()
  1399. {
  1400. return $this->cache_lifetime;
  1401. }
  1402. /**
  1403. * Set cache lifetime.
  1404. *
  1405. * @param integer $time Lifetime in seconds.
  1406. *
  1407. * @return $this
  1408. */
  1409. public function setCacheLifetime($time)
  1410. {
  1411. $this->cache_lifetime = $time;
  1412. return $this;
  1413. }
  1414. /**
  1415. * Retrieve the name of the directory for cache files.
  1416. *
  1417. * @return string The name of the cache file directory.
  1418. */
  1419. public function getCacheDir()
  1420. {
  1421. return $this->cache_dir;
  1422. }
  1423. /**
  1424. * Set the name of the directory for cache files.
  1425. *
  1426. * @param string $cache_dir The name of the cache file directory.
  1427. *
  1428. * @return $this
  1429. */
  1430. public function setCacheDir($cache_dir)
  1431. {
  1432. $this->cache_dir = $cache_dir;
  1433. return $this;
  1434. }
  1435. /**
  1436. * Retrieve whether If-Modified-Since headers are respected.
  1437. *
  1438. * Only used when caching is enabled (see (@link setCaching())). If true, then If-Modified-Since headers
  1439. * are respected with cached content, and appropriate HTTP headers are sent.
  1440. * This way repeated hits to a cached page do not send the entire page to the
  1441. * client every time.
  1442. *
  1443. * @return boolean True if If-Modified-Since headers are respected, otherwise false.
  1444. */
  1445. public function getCacheModifiedCheck()
  1446. {
  1447. return $this->cache_modified_check;
  1448. }
  1449. /**
  1450. * Set whether If-Modified-Since headers are respected.
  1451. *
  1452. * Only used when caching is enabled (see (@link setCaching())). If true, then If-Modified-Since headers
  1453. * are respected with cached content, and appropriate HTTP headers are sent.
  1454. * This way repeated hits to a cached page do not send the entire page to the
  1455. * client every time.
  1456. *
  1457. * @param boolean $cache_modified_check True to respect If-Modified-Since headers, otherwise false.
  1458. *
  1459. * @return $this
  1460. */
  1461. public function setCacheModifiedCheck($cache_modified_check)
  1462. {
  1463. $this->cache_modified_check = $cache_modified_check;
  1464. return $this;
  1465. }
  1466. /**
  1467. * Retrieve the directgory where config files are located.
  1468. *
  1469. * @return string The directory name.
  1470. */
  1471. public function getConfigDir()
  1472. {
  1473. return $this->config_dir;
  1474. }
  1475. /**
  1476. * Set the directgory where config files are located.
  1477. *
  1478. * @param string $config_dir The directory name.
  1479. *
  1480. * @return $this
  1481. */
  1482. public function setConfigDir($config_dir)
  1483. {
  1484. $this->config_dir = $config_dir;
  1485. return $this;
  1486. }
  1487. /**
  1488. * Retrieve the directories that are searched for plugins.
  1489. *
  1490. * @return array An array of directory names.
  1491. */
  1492. public function getPluginsDir()
  1493. {
  1494. return $this->plugins_dir;
  1495. }
  1496. /**
  1497. * Set an array of directories that are searched for plugins.
  1498. *
  1499. * @param array $plugins_dir An array of directory names.
  1500. *
  1501. * @return $this
  1502. */
  1503. public function setPluginsDir($plugins_dir)
  1504. {
  1505. $this->plugins_dir = $plugins_dir;
  1506. return $this;
  1507. }
  1508. /**
  1509. * Retrieve whether debugging mode is enabled or disabled.
  1510. *
  1511. * @return boolean True if enabled, otherwise false.
  1512. */
  1513. public function getDebugging()
  1514. {
  1515. return $this->debugging;
  1516. }
  1517. /**
  1518. * Enable or disable debugging mode.
  1519. *
  1520. * If debugging is enabled, a debug console window will display when the page loads (make sure your browser
  1521. * allows unrequested popup windows)
  1522. *
  1523. * @param boolean $debugging True to enable, otherwise false.
  1524. *
  1525. * @return $this
  1526. */
  1527. public function setDebugging($debugging)
  1528. {
  1529. $this->debugging = $debugging;
  1530. return $this;
  1531. }
  1532. /**
  1533. * Retrieve the PHP error reporting level to be used within this class.
  1534. *
  1535. * @see error_reporting()
  1536. *
  1537. * @return integer The PHP error reporting level.
  1538. */
  1539. public function getErrorReporting()
  1540. {
  1541. return $this->error_reporting;
  1542. }
  1543. /**
  1544. * Set the PHP error reporting level to be used for this class.
  1545. *
  1546. * @param integer $error_reporting The PHP error reporting level.
  1547. *
  1548. * @see error_reporting()
  1549. *
  1550. * @return $this
  1551. */
  1552. public function setErrorReporting($error_reporting)
  1553. {
  1554. $this->error_reporting = $error_reporting;
  1555. return $this;
  1556. }
  1557. /**
  1558. * Retrieve the custom path to the debug console template.
  1559. *
  1560. * If empty, the default template is used.
  1561. *
  1562. * @return string The custom path to the debug console template.
  1563. */
  1564. public function getDebugTpl()
  1565. {
  1566. return $this->debug_tpl;
  1567. }
  1568. /**
  1569. * Set a custom path to the debug console template.
  1570. *
  1571. * If empty, the default template is used.
  1572. *
  1573. * @param string $debug_tpl The custom path to the debug console template.
  1574. *
  1575. * @return $this
  1576. */
  1577. public function setDebugTpl($debug_tpl)
  1578. {
  1579. $this->debug_tpl = $debug_tpl;
  1580. return $this;
  1581. }
  1582. /**
  1583. * Retrieve whether debugging is enable-able from the browser.
  1584. *
  1585. * Values:
  1586. * <ul>
  1587. * <li>NONE => no debugging control allowed</li>
  1588. * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  1589. * </ul>
  1590. *
  1591. * @return string Either 'NONE' or 'URL'.
  1592. */
  1593. public function getDebuggingCtrl()
  1594. {
  1595. return $this->debugging_ctrl;
  1596. }
  1597. /**
  1598. * Set whether debugging is enable-able from the browser.
  1599. *
  1600. * Values:
  1601. * <ul>
  1602. * <li>NONE => no debugging control allowed</li>
  1603. * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  1604. * </ul>
  1605. *
  1606. * http://www.example.com/index.php?SMARTY_DEBUG
  1607. *
  1608. * @param string $debugging_ctrl Either 'NONE' or 'URL'.
  1609. *
  1610. * @return $this
  1611. */
  1612. public function setDebuggingCtrl($debugging_ctrl)
  1613. {
  1614. $this->debugging_ctrl = $debugging_ctrl;
  1615. return $this;
  1616. }
  1617. /**
  1618. * Retrieve how "<?php ... ?>" tags in templates are handled.
  1619. *
  1620. * Possible values:
  1621. * <ul>
  1622. * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
  1623. * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
  1624. * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
  1625. * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
  1626. * </ul>
  1627. *
  1628. * @return integer A code indicating how php tags in templates are handled.
  1629. */
  1630. public function getPhpHandling()
  1631. {
  1632. return $this->php_handling;
  1633. }
  1634. /**
  1635. * Set how "<?php ... ?>" tags in templates are handled.
  1636. *
  1637. * Possible values:
  1638. * <ul>
  1639. * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
  1640. * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
  1641. * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
  1642. * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
  1643. * </ul>
  1644. *
  1645. * @param integer $php_handling A code indicating how php tags in templates are to be handled.
  1646. *
  1647. * @return $this
  1648. */
  1649. public function setPhpHandling($php_handling)
  1650. {
  1651. $this->php_handling = $php_handling;
  1652. return $this;
  1653. }
  1654. /**
  1655. * Retrieve whether template security is enabled or disabled.
  1656. *
  1657. * When enabled, many things are restricted in the templates that normally would go unchecked. This is useful when
  1658. * untrusted parties are editing templates and you want a reasonable level of security.
  1659. * (no direct execution of PHP in templates for example)
  1660. *
  1661. * @return boolean True if enabled, otherwise false.
  1662. */
  1663. public function getSecurity()
  1664. {
  1665. return $this->security;
  1666. }
  1667. /**
  1668. * Enable or disable template security.
  1669. *
  1670. * When enabled, many things are restricted in the templates that normally would go unchecked. This is useful when
  1671. * untrusted parties are editing templates and you want a reasonable level of security.
  1672. * (no direct execution of PHP in templates for example)
  1673. *
  1674. * @param boolean $security True to enable, otherwise false.
  1675. *
  1676. * @return $this
  1677. */
  1678. public function setSecurity($security)
  1679. {
  1680. $this->security = $security;
  1681. return $this;
  1682. }
  1683. /**
  1684. * Retrieve the list of template directories that are considered secure.
  1685. *
  1686. * @return array An array of secure template directories.
  1687. */
  1688. public function getSecureDir()
  1689. {
  1690. return $this->secure_dir;
  1691. }
  1692. /**
  1693. * Set the list of template directories that are considered secure.
  1694. *
  1695. * This is used only if template security enabled (see {@link setSecurity()}). One directory per array
  1696. * element. The template directory (see {@link setTemplateDir()}) is in this list implicitly.
  1697. *
  1698. * @param array $secure_dir An array of secure template directories.
  1699. *
  1700. * @return $this
  1701. */
  1702. public function setSecureDir($secure_dir)
  1703. {
  1704. $this->secure_dir = $secure_dir;
  1705. return $this;
  1706. }
  1707. /**
  1708. * Retrieve an array of security settings, only used if template security is enabled (see {@link setSecurity()).
  1709. *
  1710. * @return array An array of security settings.
  1711. */
  1712. public function getSecuritySettings()
  1713. {
  1714. return $this->security_settings;
  1715. }
  1716. /**
  1717. * Set an array of security settings, only used if template security is enabled (see {@link setSecurity()).
  1718. *
  1719. * @param array $security_settings An array of security settings.
  1720. *
  1721. * @return $this
  1722. */
  1723. public function setSecuritySettings($security_settings)
  1724. {
  1725. $this->security_settings = $security_settings;
  1726. return $this;
  1727. }
  1728. /**
  1729. * Retrieve an array of directories where trusted php scripts reside.
  1730. *
  1731. * @return array An array of trusted directories.
  1732. */
  1733. public function getTrustedDir()
  1734. {
  1735. return $this->trusted_dir;
  1736. }
  1737. /**
  1738. * Set an array of directories where trusted php scripts reside.
  1739. *
  1740. * Template security (see {@link setSecurity()) is disabled during their inclusion/execution.
  1741. *
  1742. * @param array $trusted_dir An array of trusted directories.
  1743. *
  1744. * @return $this
  1745. */
  1746. public function setTrustedDir($trusted_dir)
  1747. {
  1748. $this->trusted_dir = $trusted_dir;
  1749. return $this;
  1750. }
  1751. /**
  1752. * Retrieve the left delimiter used for template tags.
  1753. *
  1754. * @return string The delimiter.
  1755. */
  1756. public function getLeftDelimiter()
  1757. {
  1758. return $this->left_delimiter;
  1759. }
  1760. /**
  1761. * Set the left delimiter used for template tags.
  1762. *
  1763. * @param string $left_delimiter The delimiter.
  1764. *
  1765. * @return $this
  1766. */
  1767. public function setLeftDelimiter($left_delimiter)
  1768. {
  1769. $this->left_delimiter = $left_delimiter;
  1770. return $this;
  1771. }
  1772. /**
  1773. * Retrieve the right delimiter used for template tags.
  1774. *
  1775. * @return string The delimiter.
  1776. */
  1777. public function getRightDelimiter()
  1778. {
  1779. return $this->right_delimiter;
  1780. }
  1781. /**
  1782. * Set the right delimiter used for template tags.
  1783. *
  1784. * @param string $right_delimiter The delimiter.
  1785. *
  1786. * @return $this
  1787. */
  1788. public function setRightDelimiter($right_delimiter)
  1789. {
  1790. $this->right_delimiter = $right_delimiter;
  1791. return $this;
  1792. }
  1793. /**
  1794. * Retrieve the order in which request variables are registered, similar to variables_order in php.ini.
  1795. *
  1796. * E = Environment, G = GET, P = POST, C = Cookies, S = Server
  1797. *
  1798. * @return string The string indicating the order, e.g., 'EGPCS'.
  1799. */
  1800. public function getRequestVarsOrder()
  1801. {
  1802. return $this->request_vars_order;
  1803. }
  1804. /**
  1805. * Set the order in which request variables are registered, similar to variables_order in php.ini.
  1806. *
  1807. * E = Environment, G = GET, P = POST, C = Cookies, S = Server
  1808. *
  1809. * @param string $request_vars_order A string indicating the order, e.g., 'EGPCS'.
  1810. *
  1811. * @return $this
  1812. */
  1813. public function setRequestVarsOrder($request_vars_order)
  1814. {
  1815. $this->request_vars_order = $request_vars_order;
  1816. return $this;
  1817. }
  1818. /**
  1819. * Retrieve whether $HTTP_*_VARS[] (request_use_auto_globals=false) are used as request-vars or $_*[]-vars.
  1820. *
  1821. * @return boolean True if auto globals are used, otherwise false.
  1822. */
  1823. public function getRequestUseAutoGlobals()
  1824. {
  1825. return $this->request_use_auto_globals;
  1826. }
  1827. /**
  1828. * Set whether $HTTP_*_VARS[] (request_use_auto_globals=false) are used as request-vars or $_*[]-vars.
  1829. *
  1830. * Note: if request_use_auto_globals is true, then $request_vars_order has
  1831. * no effect, but the php-ini-value "gpc_order"
  1832. *
  1833. * @param boolean $request_use_auto_globals True to use auto globals, otherwise false.
  1834. *
  1835. * @return $this
  1836. */
  1837. public function setRequestUseAutoGlobals($request_use_auto_globals)
  1838. {
  1839. $this->request_use_auto_globals = $request_use_auto_globals;
  1840. return $this;
  1841. }
  1842. /**
  1843. * Retrieve whether or not sub dirs in the cache/ and templates_c/ directories are used.
  1844. *
  1845. * @return boolean True if sub dirs are used, otherwise false.
  1846. */
  1847. public function getUseSubDirs()
  1848. {
  1849. return $this->use_sub_dirs;
  1850. }
  1851. /**
  1852. * Set whether or not to use sub dirs in the cache/ and templates_c/ directories.
  1853. *
  1854. * Sub directories better organized, but may not work well with PHP safe mode enabled.
  1855. *
  1856. * @param boolean $use_sub_dirs True to use sub dirs, otherwise false.
  1857. *
  1858. * @return $this
  1859. */
  1860. public function setUseSubDirs($use_sub_dirs)
  1861. {
  1862. $this->use_sub_dirs = $use_sub_dirs;
  1863. return $this;
  1864. }
  1865. /**
  1866. * Retrieve a list of the modifiers applied to all template variables.
  1867. *
  1868. * @return array An array of default modifiers.
  1869. */
  1870. public function getDefaultModifiers()
  1871. {
  1872. return $this->default_modifiers;
  1873. }
  1874. /**
  1875. * Set a list of the modifiers to apply to all template variables.
  1876. *
  1877. * Put each modifier in a separate array element in the order you want
  1878. * them applied. example: <code>array('escape:"htmlall"');</code>
  1879. *
  1880. * @param array $default_modifiers An array of default modifiers.
  1881. *
  1882. * @return $this
  1883. */
  1884. public function setDefaultModifiers($default_modifiers)
  1885. {
  1886. $this->default_modifiers = $default_modifiers;
  1887. return $this;
  1888. }
  1889. /**
  1890. * Retrieve the resource type used when not specified at the beginning of the resource path (see {@link Smarty::$default_resource_type}).
  1891. *
  1892. * @return string The resource type used.
  1893. */
  1894. public function getDefaultResourceType()
  1895. {
  1896. return $this->default_resource_type;
  1897. }
  1898. /**
  1899. * Set the resource type to be used when not specified at the beginning of the resource path (see {@link Smarty::$default_resource_type}).
  1900. *
  1901. * @param string $default_resource_type The resource type to use.
  1902. *
  1903. * @return $this
  1904. */
  1905. public function setDefaultResourceType($default_resource_type)
  1906. {
  1907. $this->default_resource_type = $default_resource_type;
  1908. return $this;
  1909. }
  1910. /**
  1911. * Retrieve the name of the function used for cache file handling.
  1912. *
  1913. * If not set, built-in caching is used.
  1914. *
  1915. * @return string|null The name of the function, or null if built-in caching is used.
  1916. */
  1917. public function getCacheHandlerFunc()
  1918. {
  1919. return $this->cache_handler_func;
  1920. }
  1921. /**
  1922. * Set the name of the function used for cache file handling.
  1923. *
  1924. * If not set, built-in caching is used.
  1925. *
  1926. * @param string|null $cache_handler_func The name of the function, or null to use built-in caching.
  1927. *
  1928. * @return $this
  1929. */
  1930. public function setCacheHandlerFunc($cache_handler_func)
  1931. {
  1932. $this->cache_handler_func = $cache_handler_func;
  1933. return $this;
  1934. }
  1935. /**
  1936. * Retrieve whether filters are automatically loaded or not.
  1937. *
  1938. * @return boolean True if automatically loaded, otherwise false.
  1939. */
  1940. public function getAutoloadFilters()
  1941. {
  1942. return $this->autoload_filters;
  1943. }
  1944. /**
  1945. * Set whether filters are automatically loaded or not.
  1946. *
  1947. * @param boolean $autoload_filters True to automatically load, otherwise false.
  1948. *
  1949. * @return $this
  1950. */
  1951. public function setAutoloadFilters($autoload_filters)
  1952. {
  1953. $this->autoload_filters = $autoload_filters;
  1954. return $this;
  1955. }
  1956. /**
  1957. * Retrieve if config file vars of the same name overwrite each other or not.
  1958. *
  1959. * @return boolean True if overwritten, otherwise false.
  1960. */
  1961. public function getConfigOverwrite()
  1962. {
  1963. return $this->config_overwrite;
  1964. }
  1965. /**
  1966. * Set if config file vars of the same name overwrite each other or not.
  1967. *
  1968. * If disabled, same name variables are accumulated in an array.
  1969. *
  1970. * @param boolean $config_overwrite True to overwrite, otherwise false.
  1971. *
  1972. * @return $this
  1973. */
  1974. public function setConfigOverwrite($config_overwrite)
  1975. {
  1976. $this->config_overwrite = $config_overwrite;
  1977. return $this;
  1978. }
  1979. /**
  1980. * Retrieve whether or not to automatically booleanize config file variables.
  1981. *
  1982. * If enabled, then the strings "on", "true", and "yes" are treated as boolean
  1983. * true, and "off", "false" and "no" are treated as boolean false.
  1984. *
  1985. * @return boolean True if config variables are booleanized, otherwise false.
  1986. */
  1987. public function getConfigBooleanize()
  1988. {
  1989. return $this->config_booleanize;
  1990. }
  1991. /**
  1992. * Set whether or not to automatically booleanize config file variables.
  1993. *
  1994. * If enabled, then the strings "on", "true", and "yes" are treated as boolean
  1995. * true, and "off", "false" and "no" are treated as boolean false.
  1996. *
  1997. * @param boolean $config_booleanize True to booleanize, otherwise false.
  1998. *
  1999. * @return $this
  2000. */
  2001. public function setConfigBooleanize($config_booleanize)
  2002. {
  2003. $this->config_booleanize = $config_booleanize;
  2004. return $this;
  2005. }
  2006. /**
  2007. * Retrieve whether hidden sections [.foobar] in config files are readable from the tempalates or not.
  2008. *
  2009. * @return boolean True if hidden sections readable, otherwise false.
  2010. */
  2011. public function getConfigReadHidden()
  2012. {
  2013. return $this->config_read_hidden;
  2014. }
  2015. /**
  2016. * Set whether hidden sections [.foobar] in config files are readable from the tempalates or not.
  2017. *
  2018. * Normally you would never allow this since that is the point behind hidden sections: the application can access
  2019. * them, but the templates cannot.
  2020. *
  2021. * @param boolean $config_read_hidden True to make hidden sections readable, otherwise false.
  2022. *
  2023. * @return $this
  2024. */
  2025. public function setConfigReadHidden($config_read_hidden)
  2026. {
  2027. $this->config_read_hidden = $config_read_hidden;
  2028. return $this;
  2029. }
  2030. /**
  2031. * Retrieve the flag that indicates whether newlines are automatically corrected in config files.
  2032. *
  2033. * This indicates whether or not automatically fix newlines in config files.
  2034. * It basically converts \r (mac) or \r\n (dos) to \n
  2035. *
  2036. * @return boolean True if automatically fixed, otherwise false.
  2037. */
  2038. public function getConfigFixNewlines()
  2039. {
  2040. return $this->config_fix_newlines;
  2041. }
  2042. /**
  2043. * Set the flag that corrects newlines automatically in config files.
  2044. *
  2045. * This indicates whether or not automatically fix newlines in config files.
  2046. * It basically converts \r (mac) or \r\n (dos) to \n
  2047. *
  2048. * @param boolean $config_fix_newlines True to automatically fix, otherwise false.
  2049. *
  2050. * @return $this
  2051. */
  2052. public function setConfigFixNewlines($config_fix_newlines)
  2053. {
  2054. $this->config_fix_newlines = $config_fix_newlines;
  2055. return $this;
  2056. }
  2057. /**
  2058. * Retrieve the name of the PHP function that will be called if a template cannot be found.
  2059. *
  2060. * @return string The name of the PHP function called if a template cannot be found.
  2061. */
  2062. public function getDefaultTemplateHandlerFunc()
  2063. {
  2064. return $this->default_template_handler_func;
  2065. }
  2066. /**
  2067. * Set the name of the PHP function that will be called if a template cannot be found.
  2068. *
  2069. * @param string $default_template_handler_func The name of the PHP function to call if a template cannot be found.
  2070. *
  2071. * @return $this
  2072. */
  2073. public function setDefaultTemplateHandlerFunc($default_template_handler_func)
  2074. {
  2075. $this->default_template_handler_func = $default_template_handler_func;
  2076. return $this;
  2077. }
  2078. /**
  2079. * Retrieve the name of the file that contains the compiler class.
  2080. *
  2081. * This could be a full pathname, or relative to the php_include path.
  2082. *
  2083. * @see Smarty::$compiler_file
  2084. * @see setCompilerClass()
  2085. *
  2086. * @return string The name of the file that contains the compiler class.
  2087. */
  2088. public function getCompilerFile()
  2089. {
  2090. return $this->compiler_file;
  2091. }
  2092. /**
  2093. * Set the name of the file that contains the compiler class.
  2094. *
  2095. * This can a full pathname, or relative to the php_include path.
  2096. *
  2097. * @param string $compiler_file The name of the file that contains the compiler class.
  2098. *
  2099. * @see Smarty::$compiler_file
  2100. * @see setCompilerClass()
  2101. *
  2102. * @return $this
  2103. */
  2104. public function setCompilerFile($compiler_file)
  2105. {
  2106. $this->compiler_file = $compiler_file;
  2107. return $this;
  2108. }
  2109. /**
  2110. * Retrieve the name of the class used to compile templates.
  2111. *
  2112. * @return string The name of the class used to compile templates.
  2113. */
  2114. public function getCompilerClass()
  2115. {
  2116. return $this->compiler_class;
  2117. }
  2118. /**
  2119. * Set the name of the class that will be used to compile templates.
  2120. *
  2121. * @param string $compiler_class The name of the class used to compile templates.
  2122. *
  2123. * @return $this
  2124. */
  2125. public function setCompilerClass($compiler_class)
  2126. {
  2127. $this->compiler_class = $compiler_class;
  2128. return $this;
  2129. }
  2130. /**
  2131. * Retrieve the info that makes up a cache file ({@link Smarty::$_cache_info}).
  2132. *
  2133. * @return array Array of info that makes up a cache file.
  2134. */
  2135. public function getCacheInfo()
  2136. {
  2137. return $this->_cache_info;
  2138. }
  2139. /**
  2140. * Set the info that makes up a cache file ({@link Smarty::$_cache_info}).
  2141. *
  2142. * @param array $_cache_info Array of info that makes up a cache file.
  2143. *
  2144. * @return $this
  2145. */
  2146. public function setCacheInfo($_cache_info)
  2147. {
  2148. $this->_cache_info = $_cache_info;
  2149. return $this;
  2150. }
  2151. /**
  2152. * Retrieve the file permissions ({@link Smarty::$_file_perms}).
  2153. *
  2154. * @return int File permissions.
  2155. */
  2156. public function getFilePerms()
  2157. {
  2158. return $this->_file_perms;
  2159. }
  2160. /**
  2161. * Set the file permissions ({@link Smarty::$_file_perms}).
  2162. *
  2163. * @param int $_file_perms File permissions; use an octal number, e.g. set_file_perms(0664).
  2164. *
  2165. * @return $this
  2166. */
  2167. public function setFilePerms($_file_perms)
  2168. {
  2169. $this->_file_perms = $_file_perms;
  2170. return $this;
  2171. }
  2172. /**
  2173. * Retrieve the directory permissions ({@link Smarty::$_dir_perms}).
  2174. *
  2175. * @return int Directory permissions.
  2176. */
  2177. public function getDirPerms()
  2178. {
  2179. return $this->_dir_perms;
  2180. }
  2181. /**
  2182. * Set the directory permissions ({@link Smarty::$_dir_perms}).
  2183. *
  2184. * @param int $_dir_perms Directory permissions; use an octal number, e.g. set_dir_perms(0771).
  2185. *
  2186. * @return $this
  2187. */
  2188. public function setDirPerms($_dir_perms)
  2189. {
  2190. $this->_dir_perms = $_dir_perms;
  2191. return $this;
  2192. }
  2193. /**
  2194. * Retrieve the {@link Smarty::$_reg_objects} registered objects.
  2195. *
  2196. * @return array Registered objects array.
  2197. */
  2198. public function getRegObjects()
  2199. {
  2200. return $this->_reg_objects;
  2201. }
  2202. /**
  2203. * Set the {@link Smarty::$_reg_objects} registered objects.
  2204. *
  2205. * @param array $_reg_objects Registered objects.
  2206. *
  2207. * @return $this
  2208. */
  2209. public function setRegObjects($_reg_objects)
  2210. {
  2211. $this->_reg_objects = $_reg_objects;
  2212. return $this;
  2213. }
  2214. /**
  2215. * Retrieve the array keeping track of plugins (see {@link Smarty::$_plugins}.
  2216. *
  2217. * @return array An array of plugins by type.
  2218. */
  2219. public function getPlugins()
  2220. {
  2221. return $this->_plugins;
  2222. }
  2223. /**
  2224. * Set the array keeping track of plugins (see {@link Smarty::$_plugins}.
  2225. *
  2226. * @param array $_plugins An array of plugins by type.
  2227. *
  2228. * @return $this
  2229. */
  2230. public function setPlugins($_plugins)
  2231. {
  2232. $this->_plugins = $_plugins;
  2233. return $this;
  2234. }
  2235. /**
  2236. * Retrieve the value of {@link Smarty::$_cache_serials}.
  2237. *
  2238. * @return array Cache serials.
  2239. */
  2240. public function getCacheSerials()
  2241. {
  2242. return $this->_cache_serials;
  2243. }
  2244. /**
  2245. * Setter for {@link Smarty::$_cache_serials}
  2246. *
  2247. * @param array $_cache_serials Cache serials.
  2248. *
  2249. * @return $this
  2250. */
  2251. public function setCacheSerials($_cache_serials)
  2252. {
  2253. $this->_cache_serials = $_cache_serials;
  2254. return $this;
  2255. }
  2256. /**
  2257. * Retrieve the value of {@link Smarty::$_cache_include}.
  2258. *
  2259. * @return string Name of optional cache include file.
  2260. */
  2261. public function getCacheInclude()
  2262. {
  2263. return $this->_cache_include;
  2264. }
  2265. /**
  2266. * Setter for {@link Smarty::$_cache_include}.
  2267. *
  2268. * @param string $_cache_include Name of optional cache include file.
  2269. *
  2270. * @return $this
  2271. */
  2272. public function setCacheInclude($_cache_include)
  2273. {
  2274. $this->_cache_include = $_cache_include;
  2275. return $this;
  2276. }
  2277. /**
  2278. * Retrieve the value of {@link Smarty::$_cache_including}.
  2279. *
  2280. * @return boolean True if the current code is used in a compiled include, otherwise false.
  2281. */
  2282. public function getCacheIncluding()
  2283. {
  2284. return $this->_cache_including;
  2285. }
  2286. /**
  2287. * Setter for {@link Smarty::$_cache_including}.
  2288. *
  2289. * @param boolean $_cache_including Indicate if the current code is used in a compiled include.
  2290. *
  2291. * @return $this
  2292. */
  2293. public function setCacheIncluding($_cache_including)
  2294. {
  2295. $this->_cache_including = $_cache_including;
  2296. return $this;
  2297. }
  2298. /**
  2299. * Disable or enable add the module wrapper.
  2300. *
  2301. * @param boolean $wrap False to disable wrapper, true to enable it.
  2302. *
  2303. * @return $this
  2304. */
  2305. public function setWrapper($wrap)
  2306. {
  2307. if ($this->modinfo['name'] == $this->toplevelmodule) {
  2308. Zikula_View_Theme::getInstance()->themeinfo['system'] = !$wrap;
  2309. }
  2310. return $this;
  2311. }
  2312. /**
  2313. * Smarty override to customize the core.process_cached_inserts
  2314. *
  2315. * @param string $template The name of the template.
  2316. * @param string $cache_id The cache ID (optional).
  2317. * @param string $compile_id The compile ID (optional).
  2318. * @param boolean $display Whether or not to display directly (optional).
  2319. *
  2320. * @return string The template output.
  2321. */
  2322. public function _fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
  2323. {
  2324. static $_cache_info = array();
  2325. $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)
  2326. ? $this->error_reporting : error_reporting() & ~E_NOTICE);
  2327. if (!$this->debugging && $this->debugging_ctrl == 'URL') {
  2328. $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
  2329. if (@strstr($_query_string, $this->_smarty_debug_id)) {
  2330. if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) {
  2331. // enable debugging for this browser session
  2332. @setcookie('SMARTY_DEBUG', true);
  2333. $this->debugging = true;
  2334. } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) {
  2335. // disable debugging for this browser session
  2336. @setcookie('SMARTY_DEBUG', false);
  2337. $this->debugging = false;
  2338. } else {
  2339. // enable debugging for this page
  2340. $this->debugging = true;
  2341. }
  2342. } else {
  2343. $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']);
  2344. }
  2345. }
  2346. if ($this->debugging) {
  2347. // capture time for debugging info
  2348. $_params = array();
  2349. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  2350. $_debug_start_time = smarty_core_get_microtime($_params, $this);
  2351. $this->_smarty_debug_info[] = array('type' => 'template',
  2352. 'filename' => $resource_name,
  2353. 'depth' => 0);
  2354. $_included_tpls_idx = count($this->_smarty_debug_info) - 1;
  2355. }
  2356. if (!isset($compile_id)) {
  2357. $compile_id = $this->compile_id;
  2358. }
  2359. $this->_compile_id = $compile_id;
  2360. $this->_inclusion_depth = 0;
  2361. if ($this->caching) {
  2362. // save old cache_info, initialize cache_info
  2363. array_push($_cache_info, $this->_cache_info);
  2364. $this->_cache_info = array();
  2365. $_params = array(
  2366. 'tpl_file' => $resource_name,
  2367. 'cache_id' => $cache_id,
  2368. 'compile_id' => $compile_id,
  2369. 'results' => null
  2370. );
  2371. require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
  2372. if (smarty_core_read_cache_file($_params, $this)) {
  2373. $_smarty_results = $_params['results'];
  2374. if (!empty($this->_cache_info['insert_tags'])) {
  2375. $_params = array('plugins' => $this->_cache_info['insert_tags']);
  2376. require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
  2377. smarty_core_load_plugins($_params, $this);
  2378. $_params = array('results' => $_smarty_results);
  2379. // ZIKULA OVERRIDE
  2380. require_once('lib/viewplugins/zikula.process_cached_inserts.php');
  2381. $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
  2382. }
  2383. if (!empty($this->_cache_info['cache_serials'])) {
  2384. $_params = array('results' => $_smarty_results);
  2385. require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');
  2386. $_smarty_results = smarty_core_process_compiled_include($_params, $this);
  2387. }
  2388. if ($display) {
  2389. if ($this->debugging) {
  2390. // capture time for debugging info
  2391. $_params = array();
  2392. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  2393. $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;
  2394. require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
  2395. $_smarty_results .= smarty_core_display_debug_console($_params, $this);
  2396. }
  2397. if ($this->cache_modified_check) {
  2398. $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
  2399. $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
  2400. $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
  2401. if (@count($this->_cache_info['insert_tags']) == 0
  2402. && !$this->_cache_serials
  2403. && $_gmt_mtime == $_last_modified_date) {
  2404. if (php_sapi_name()=='cgi')
  2405. header('Status: 304 Not Modified');
  2406. else
  2407. header('HTTP/1.1 304 Not Modified');
  2408. } else {
  2409. header('Last-Modified: '.$_gmt_mtime);
  2410. echo $_smarty_results;
  2411. }
  2412. } else {
  2413. echo $_smarty_results;
  2414. }
  2415. error_reporting($_smarty_old_error_level);
  2416. // restore initial cache_info
  2417. $this->_cache_info = array_pop($_cache_info);
  2418. return true;
  2419. } else {
  2420. error_reporting($_smarty_old_error_level);
  2421. // restore initial cache_info
  2422. $this->_cache_info = array_pop($_cache_info);
  2423. return $_smarty_results;
  2424. }
  2425. } else {
  2426. $this->_cache_info['template'][$resource_name] = true;
  2427. if ($this->cache_modified_check && $display) {
  2428. header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
  2429. }
  2430. }
  2431. }
  2432. // load filters that are marked as autoload
  2433. if (count($this->autoload_filters)) {
  2434. foreach ($this->autoload_filters as $_filter_type => $_filters) {
  2435. foreach ($_filters as $_filter) {
  2436. $this->load_filter($_filter_type, $_filter);
  2437. }
  2438. }
  2439. }
  2440. $_smarty_compile_path = $this->_get_compile_path($resource_name);
  2441. // if we just need to display the results, don't perform output
  2442. // buffering - for speed
  2443. $_cache_including = $this->_cache_including;
  2444. $this->_cache_including = false;
  2445. if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
  2446. if ($this->_is_compiled($resource_name, $_smarty_compile_path) || $this->_compile_resource($resource_name, $_smarty_compile_path)) {
  2447. include($_smarty_compile_path);
  2448. }
  2449. } else {
  2450. ob_start();
  2451. if ($this->_is_compiled($resource_name, $_smarty_compile_path) || $this->_compile_resource($resource_name, $_smarty_compile_path)) {
  2452. include($_smarty_compile_path);
  2453. }
  2454. $_smarty_results = ob_get_contents();
  2455. ob_end_clean();
  2456. foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {
  2457. $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
  2458. }
  2459. }
  2460. if ($this->caching) {
  2461. $_params = array('tpl_file' => $resource_name,
  2462. 'cache_id' => $cache_id,
  2463. 'compile_id' => $compile_id,
  2464. 'results' => $_smarty_results);
  2465. require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');
  2466. smarty_core_write_cache_file($_params, $this);
  2467. // ZIKULA OVERRIDE
  2468. require_once('lib/viewplugins/zikula.process_cached_inserts.php');
  2469. $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
  2470. if ($this->_cache_serials) {
  2471. // strip nocache-tags from output
  2472. $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
  2473. ,''
  2474. ,$_smarty_results);
  2475. }
  2476. // restore initial cache_info
  2477. $this->_cache_info = array_pop($_cache_info);
  2478. }
  2479. $this->_cache_including = $_cache_including;
  2480. if ($display) {
  2481. if (isset($_smarty_results)) {
  2482. echo $_smarty_results;
  2483. }
  2484. if ($this->debugging) {
  2485. // capture time for debugging info
  2486. $_params = array();
  2487. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  2488. $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
  2489. require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
  2490. echo smarty_core_display_debug_console($_params, $this);
  2491. }
  2492. error_reporting($_smarty_old_error_level);
  2493. return;
  2494. } else {
  2495. error_reporting($_smarty_old_error_level);
  2496. if (isset($_smarty_results)) {
  2497. return $_smarty_results;
  2498. }
  2499. }
  2500. }
  2501. }
  2502. /**
  2503. * Callback function for preg_replace_callback.
  2504. *
  2505. * Allows the use of {{ and }} as delimiters within certain tags,
  2506. * even if they use { and } as block delimiters.
  2507. *
  2508. * @param array $matches The $matches array from preg_replace_callback, containing the matched groups.
  2509. *
  2510. * @return string The replacement string for the match.
  2511. */
  2512. function z_prefilter_add_literal_callback($matches)
  2513. {
  2514. $tagOpen = $matches[1];
  2515. $script = $matches[3];
  2516. $tagClose = $matches[4];
  2517. $script = str_replace('{{', '{/literal}{', str_replace('}}', '}{literal}', $script));
  2518. return $tagOpen . '{literal}' . $script . '{/literal}' . $tagClose;
  2519. }
  2520. /**
  2521. * Prefilter for tags that might contain { or } as block delimiters.
  2522. *
  2523. * Such as <script> or <style>. Allows the use of {{ and }} as smarty delimiters,
  2524. * even if the language uses { and } as block delimters. Adds {literal} and
  2525. * {/literal} to the specified opening and closing tags, and converts
  2526. * {{ and }} to {/literal}{ and }{literal}.
  2527. *
  2528. * Tags affected: <script> and <style>.
  2529. *
  2530. * @param string $tpl_source The template's source prior to prefiltering.
  2531. * @param Zikula_View $view A reference to the Zikula_View object.
  2532. *
  2533. * @return string The prefiltered template contents.
  2534. */
  2535. function z_prefilter_add_literal($tpl_source, $view)
  2536. {
  2537. return preg_replace_callback('`(<(script|style)[^>]*>)(.*?)(</\2>)`s', 'z_prefilter_add_literal_callback', $tpl_source);
  2538. }
  2539. /**
  2540. * Prefilter for gettext parameters.
  2541. *
  2542. * @param string $tpl_source The template's source prior to prefiltering.
  2543. * @param Zikula_View $view A reference to the Zikula_View object.
  2544. *
  2545. * @return string The prefiltered template contents.
  2546. */
  2547. function z_prefilter_gettext_params($tpl_source, $view)
  2548. {
  2549. return preg_replace('#((?:(?<!\{)\{(?!\{)(?:\s*)|\G)(?:.+?))__([a-zA-Z0-9][a-zA-Z_0-9]*=([\'"])(?:\\\\?+.)*?\3)#', '$1$2|gt:\$zikula_view', $tpl_source);
  2550. }
  2551. ///**
  2552. // * Prefilter for hookable filters.
  2553. // *
  2554. // * @param string $tpl_source The template's source prior to prefiltering.
  2555. // * @param Zikula_View $view A reference to the Zikula_View object.
  2556. // *
  2557. // * @return string The prefiltered template contents.
  2558. // */
  2559. //function z_prefilter_notifyfilters($tpl_source, $view)
  2560. //{
  2561. // return preg_replace('#((?:(?<!\{)\{(?!\{)(?:\s*)|\G)(?:.*?))(\|notifyfilters(?:([\'"])(?:\\\\?+.)*?\3|[^\s|}])*)#', '$1$2:\$zikula_view', $tpl_source);
  2562. //}