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

/setup/includes/parser/modinstallsmarty.class.php

http://github.com/modxcms/revolution
PHP | 86 lines | 47 code | 13 blank | 26 comment | 4 complexity | 09fbb5bac9317dd84324ec202853be4f 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. /**
  11. * @package setup
  12. */
  13. include_once strtr(realpath(MODX_CORE_PATH . 'model/smarty/Smarty.class.php'),'\\','/');
  14. require_once strtr(realpath(MODX_SETUP_PATH . 'includes/parser/modinstallparser.class.php'),'\\','/');
  15. /**
  16. * An extension of the Smarty class for use with modX.
  17. *
  18. * Automatically sets appropriate configuration variables for Smarty in
  19. * the MODX context.
  20. * @package setup
  21. */
  22. class modInstallSmarty extends Smarty implements modInstallParser {
  23. public $smarty = null;
  24. public $_blocks;
  25. public $_derived;
  26. function __construct(array $params= array ()) {
  27. parent :: __construct();
  28. /* Set up configuration variables for Smarty. */
  29. $this->template_dir = MODX_SETUP_PATH . 'templates/';
  30. $this->compile_dir = MODX_CORE_PATH . 'cache/' . (MODX_CONFIG_KEY == 'config' ? '' : MODX_CONFIG_KEY . '/') . 'setup/smarty/';
  31. $this->config_dir = MODX_CORE_PATH . 'model/smarty/configs';
  32. $this->plugins_dir = array(
  33. MODX_CORE_PATH . 'model/smarty/plugins',
  34. MODX_CORE_PATH . 'model/smarty/modx',
  35. );
  36. $this->caching = false;
  37. foreach ($params as $paramKey => $paramValue) {
  38. $this->$paramKey= $paramValue;
  39. }
  40. if (!is_dir($this->compile_dir) || !is_writable($this->compile_dir)) $this->writeTree($this->compile_dir, '0777');
  41. $this->set('app_name','MODX');
  42. $this->_blocks = array();
  43. $this->_derived = null;
  44. }
  45. public function render($tpl) {
  46. return $this->fetch($tpl);
  47. }
  48. public function set($key,$value) {
  49. return $this->assign($key,$value);
  50. }
  51. /**
  52. * Recursively writes a directory tree of files to the filesystem
  53. *
  54. * @access public
  55. * @param string $dirname The directory to write
  56. * @return boolean Returns true if the directory was successfully written.
  57. */
  58. public function writeTree($dirname) {
  59. $written= false;
  60. if (!empty ($dirname)) {
  61. $dirname= strtr(trim($dirname), '\\', '/');
  62. if ($dirname{strlen($dirname) - 1} == '/') $dirname = substr($dirname, 0, strlen($dirname) - 1);
  63. if (is_dir($dirname) || (is_writable(dirname($dirname)) && mkdir($dirname))) {
  64. $written= true;
  65. } elseif (!$this->writeTree(dirname($dirname))) {
  66. $written= false;
  67. } else {
  68. $written= mkdir($dirname);
  69. }
  70. }
  71. return $written;
  72. }
  73. }