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

/core/model/modx/smarty/modsmarty.class.php

http://github.com/modxcms/revolution
PHP | 120 lines | 111 code | 1 blank | 8 comment | 0 complexity | 84cbd84a1b374fcf83d1ced5fec3c7a2 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. include_once (strtr(realpath(dirname(__FILE__)) . '/../../smarty/Smarty.class.php', '\\', '/'));
  11. /**
  12. * An extension of the Smarty class for use with modX.
  13. *
  14. * Automatically sets appropriate configuration variables for Smarty in
  15. * the MODX context.
  16. *
  17. * @package modx
  18. * @subpackage smarty
  19. */
  20. class modSmarty extends SmartyBC {
  21. /**
  22. * A reference to the modX instance
  23. * @var modX
  24. * @access protected
  25. */
  26. public $modx= null;
  27. /**
  28. * A reference to the Smarty instance
  29. * @var Smarty
  30. * @access protected
  31. */
  32. public $smarty;
  33. /**
  34. * Any custom blocks loaded
  35. * @var array
  36. * @access private
  37. */
  38. public $_blocks;
  39. /**
  40. * The derived block loaded
  41. * @var mixed
  42. * @access private
  43. */
  44. public $_derived;
  45. /**
  46. * @param modX $modx A reference to the modX object
  47. * @param array $params An array of configuration parameters
  48. */
  49. function __construct(modX &$modx, $params= array ()) {
  50. parent :: __construct();
  51. $this->modx= & $modx;
  52. /* set up configuration variables for Smarty. */
  53. $this->template_dir = $modx->getOption('manager_path') . 'templates/';
  54. $this->compile_dir = $modx->getOption(xPDO::OPT_CACHE_PATH) . 'mgr/smarty/';
  55. $this->config_dir = $modx->getOption('core_path') . 'model/smarty/configs';
  56. $this->plugins_dir = array(
  57. $this->modx->getOption('core_path') . 'model/smarty/plugins',
  58. );
  59. $this->caching = false;
  60. foreach ($params as $paramKey => $paramValue) {
  61. $this->$paramKey= $paramValue;
  62. }
  63. if (!is_dir($this->compile_dir)) {
  64. $this->modx->getCacheManager();
  65. $this->modx->cacheManager->writeTree($this->compile_dir);
  66. }
  67. $this->assign('app_name','MODX');
  68. $this->_blocks = array();
  69. $this->_derived = null;
  70. }
  71. /**
  72. * Sets the cache path for this Smarty instance
  73. *
  74. * @access public
  75. * @param string $path The path to set. Defaults to '', which in turn
  76. * defaults to $this->modx->cachePath.
  77. */
  78. public function setCachePath($path = '') {
  79. $path = $this->modx->getOption(xPDO::OPT_CACHE_PATH).$path;
  80. if (!is_dir($path)) {
  81. $this->modx->getCacheManager();
  82. $this->modx->cacheManager->writeTree($path);
  83. }
  84. $this->compile_dir = $path;
  85. }
  86. /**
  87. * Sets the template path for this Smarty instance
  88. *
  89. * @access public
  90. * @param string $path The path to set.
  91. * @return boolean True if successful
  92. */
  93. public function setTemplatePath($path = '') {
  94. if ($path == '') return false;
  95. $this->setTemplateDir($path);
  96. return true;
  97. }
  98. /**
  99. * Display a template by echoing the output of a Smarty::fetch().
  100. *
  101. * @param string|object $template the resource handle of the template file or template object
  102. * @param mixed $cache_id cache id to be used with this template
  103. * @param mixed $compile_id compile id to be used with this template
  104. * @param object $parent next higher level of Smarty variables
  105. */
  106. public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {
  107. echo $this->fetch($template, $cache_id, $compile_id, $parent);
  108. }
  109. }