MODX Revolution PHP Cross Reference Content Management Systems

Source: /setup/includes/request/modinstallrequest.class.php - 238 lines - 8941 bytes - Summary - Text - Print

Description: modInstallRequest

   1  <?php
   2  /*
   3   * MODX Revolution
   4   *
   5   * Copyright 2006-2014 by MODX, LLC.
   6   * All rights reserved.
   7   *
   8   * This program is free software; you can redistribute it and/or modify it under
   9   * the terms of the GNU General Public License as published by the Free Software
  10   * Foundation; either version 2 of the License, or (at your option) any later
  11   * version.
  12   *
  13   * This program is distributed in the hope that it will be useful, but WITHOUT
  14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16   * details.
  17   *
  18   * You should have received a copy of the GNU General Public License along with
  19   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20   * Place, Suite 330, Boston, MA 02111-1307 USA
  21   */
  22  
  23  /**
  24   * modInstallRequest
  25   *
  26   * @package setup
  27   */
  28  /**
  29   * The Installation Request handler.
  30   *
  31   * @package setup
  32   */
  33  class modInstallRequest {
  34      /**
  35       * @var modInstall $install A reference to the modInstall object.
  36       * @access public
  37       */
  38      public $install = null;
  39      /** @var modInstallParser|modInstallSmarty $parser */
  40      public $parser = null;
  41      public $action = '';
  42      /** @var modConfigReader $reader */
  43      public $configReader;
  44  
  45      /**
  46       * Initializes the modInstallRequest object.
  47       *
  48       * @constructor
  49       * @param modInstall &$installer A reference to the modInstall object.
  50       */
  51      function __construct(modInstall &$installer) {
  52          $this->install =& $installer;
  53          $this->loadParser();
  54      }
  55  
  56      /**
  57       * Handles the request and loads the appropriate controller.
  58       *
  59       * @return string
  60       */
  61      public function handle() {
  62          $install =& $this->install;
  63          $install->loadSettings();
  64          $install->loadDriver();
  65          $this->parser->set('config',$install->settings->fetch());
  66  
  67          $currentVersion = include MODX_CORE_PATH . 'docs/version.inc.php';
  68  
  69          $this->parser->set('app_name', 'MODX '.$currentVersion['code_name']);
  70          $this->parser->set('app_version', $currentVersion['full_version']);
  71  
  72          $agreed= isset ($_REQUEST['agreed']) ? true : false;
  73          $agreedChecked= $agreed ? ' checked="checked"' : '';
  74  
  75          $this->install->lexicon->load('default');
  76          $this->install->lexicon->load('drivers');
  77          $this->parser->set('_lang',$this->install->lexicon->fetch());
  78  
  79          $this->action= isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'language';
  80          $this->parser->set('action',$this->action);
  81  
  82  
  83          $output = $this->parser->fetch('header.tpl');
  84          $parser =& $this->parser;
  85          $output .= include MODX_SETUP_PATH . 'controllers/' . $this->action . '.php';
  86          $output .= $this->parser->fetch('footer.tpl');
  87  
  88          return $output;
  89      }
  90  
  91      /**
  92       * Get the existing or create a new configuration.
  93       *
  94       * @param integer $mode The install mode.
  95       * @param array $config An array of config attributes.
  96       * @return array A copy of the config attributes array.
  97       */
  98      public function getConfig($mode = 0, array $config = array ()) {
  99          switch ($mode) {
 100              case modInstall::MODE_UPGRADE_EVO :
 101                  $this->loadConfigReader('config.modEvolutionConfigReader');
 102                  $config = $this->configReader->read($config);
 103                  break;
 104  
 105              case modInstall::MODE_UPGRADE_REVO :
 106              case modInstall::MODE_UPGRADE_REVO_ADVANCED :
 107                  $this->loadConfigReader('config.modRevolutionConfigReader');
 108                  $config = $this->configReader->read($config);
 109                  break;
 110  
 111              default :
 112                  $this->loadConfigReader('config.modRevolutionConfigReader');
 113                  $config = $this->configReader->loadDefaults($config);
 114                  $config = $this->setDefaultPaths($config);
 115                  break;
 116          }
 117          $this->install->config = array_merge($this->install->config, $config);
 118          $this->install->config['database_dsn'] = $this->getDatabaseDSN($this->install->config['database_type'],$this->install->config['database_server'],$this->install->config['dbase'],$this->install->config['database_connection_charset']);
 119          return $this->install->config;
 120      }
 121  
 122      /**
 123       * Ensure default paths are set for the server on new installations
 124       * @param array $config
 125       * @return array
 126       */
 127      public function setDefaultPaths(array $config = array()) {
 128          $webUrl= substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'setup/'));
 129          $webUrl= rtrim($webUrl,'/').'/';
 130          $defaults = array();
 131          $defaults['context_web_path'] = rtrim(MODX_INSTALL_PATH,'/').'/';
 132          $defaults['context_web_url'] = $webUrl;
 133          $defaults['context_mgr_path'] = rtrim(MODX_INSTALL_PATH,'/') . '/manager/';
 134          $defaults['context_mgr_url'] = $webUrl . 'manager/';
 135          $defaults['context_connectors_path'] = rtrim(MODX_INSTALL_PATH,'/') . '/connectors/';
 136          $defaults['context_connectors_url'] = $webUrl . 'connectors/';
 137          $defaults['core_path'] = MODX_CORE_PATH;
 138  
 139          /* first allow overwriting of defaults from config.xml for CLI installs if found */
 140          foreach ($defaults as $k => $v) {
 141              if (array_key_exists($k,$config)) {
 142                  $defaults[$k] = $config[$k];
 143              }
 144          }
 145  
 146          $defaults['web_path'] = $defaults['context_web_path'];
 147          $defaults['web_url'] = $defaults['context_web_url'];
 148          $defaults['mgr_path'] = $defaults['context_mgr_path'];
 149          $defaults['mgr_url'] = $defaults['context_mgr_url'];
 150          $defaults['connectors_path'] = $defaults['context_connectors_path'];
 151          $defaults['connectors_url'] = $defaults['context_connectors_url'];
 152          $defaults['web_path_auto'] = 0;
 153          $defaults['web_url_auto'] = 0;
 154          $defaults['mgr_path_auto'] = 0;
 155          $defaults['mgr_url_auto'] = 0;
 156          $defaults['connectors_path_auto'] = 0;
 157          $defaults['connectors_url_auto'] = 0;
 158          $defaults['processors_path'] = MODX_CORE_PATH . 'model/modx/processors/';
 159          $defaults['assets_path'] = $defaults['web_path'] . 'assets/';
 160          $defaults['assets_url'] = $defaults['web_url'] . 'assets/';
 161  
 162          foreach ($defaults as $k => $v) {
 163              if (!array_key_exists($k,$config)) {
 164                  $config[$k] = $defaults[$k];
 165              }
 166          }
 167          return $config;
 168      }
 169  
 170      /**
 171       * Get the database DSN from the passed parameters
 172       * @param string $databaseType
 173       * @param string $databaseServer
 174       * @param string $database
 175       * @param string $databaseConnectionCharset
 176       * @return string
 177       */
 178      public function getDatabaseDSN($databaseType,$databaseServer,$database,$databaseConnectionCharset = '') {
 179          $dsn = '';
 180          switch ($databaseType) {
 181              case 'sqlsrv':
 182                  $dsn = "{$databaseType}:server={$databaseServer};database={$database}";
 183                  break;
 184              case 'mysql':
 185                  $dsn = "{$databaseType}:host={$databaseServer};dbname={$database};charset={$databaseConnectionCharset}";
 186                  break;
 187              default:
 188                  break;
 189          }
 190          return $dsn;
 191      }
 192  
 193      /**
 194       * Loads the Config Reader
 195       *
 196       * @param string $class
 197       * @param string $path The path to the parser
 198       * @return boolean True if successful.
 199       */
 200      public function loadConfigReader($class = 'config.modRevolutionConfigReader',$path = '') {
 201          $loaded = false;
 202          $className = $this->install->loadClass($class,$path);
 203          if (empty($className)) {
 204              die ('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure all the files in the MODX setup package have been uploaded to your server.</p></body></html>');
 205          }
 206          $this->configReader = new $className($this->install);
 207          return $loaded;
 208      }
 209  
 210      /**
 211       * Loads the Smarty parser
 212       *
 213       * @param string $class
 214       * @param string $path The path to the parser
 215       * @return boolean True if successful.
 216       */
 217      public function loadParser($class = 'parser.modInstallSmarty',$path = '') {
 218          $loaded = false;
 219          $className = $this->install->loadClass($class,$path);
 220          if (empty($className)) {
 221              if (!@include (MODX_SETUP_PATH . 'provisioner/bootstrap.php')) {
 222                  die ('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure all the files in the MODX setup package have been uploaded to your server.</p></body></html>');
 223              }
 224              $loaded = false;
 225          }
 226          $this->parser = new $className();
 227          return $loaded;
 228      }
 229  
 230      public function proceed($action) {
 231          $this->sendRedirect(MODX_SETUP_URL.'?action='.$action);
 232      }
 233      public function sendRedirect($url) {
 234          $header= 'Location: ' . $url;
 235          header($header);
 236          exit();
 237      }
 238  }

title

Description

title

Description

title

Description

title

title

Body