[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/installation/models/ -> configuration.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Installation
   4   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
   5   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   6   */
   7  
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.model');
  11  jimport('joomla.filesystem.file');
  12  require_once JPATH_INSTALLATION.'/helpers/database.php';
  13  
  14  /**
  15   * Install Configuration model for the Joomla Core Installer.
  16   *
  17   * @package        Joomla.Installation
  18   * @since        1.6
  19   */
  20  class JInstallationModelConfiguration extends JModel
  21  {
  22      /**
  23       * @return boolean
  24       */
  25  	public function setup($options)
  26      {
  27          // Get the options as a JObject for easier handling.
  28          $options = JArrayHelper::toObject($options, 'JObject');
  29  
  30          // Attempt to create the root user.
  31          if (!$this->_createConfiguration($options)) {
  32              return false;
  33          }
  34  
  35          // Attempt to create the root user.
  36          if (!$this->_createRootUser($options)) {
  37              return false;
  38          }
  39  
  40          return true;
  41      }
  42  
  43  	function _createConfiguration($options)
  44      {
  45          // Create a new registry to build the configuration options.
  46          $registry = new JRegistry();
  47  
  48          /* Site Settings */
  49          $registry->set('offline', $options->site_offline);
  50          $registry->set('offline_message', JText::_('INSTL_STD_OFFLINE_MSG'));
  51          $registry->set('display_offline_message', 1);
  52          $registry->set('offline_image', '');
  53          $registry->set('sitename', $options->site_name);
  54          $registry->set('editor', 'tinymce');
  55          $registry->set('captcha', '0');
  56          $registry->set('list_limit', 20);
  57          $registry->set('access', 1);
  58  
  59          /* Debug Settings */
  60          $registry->set('debug', 0);
  61          $registry->set('debug_lang', 0);
  62  
  63          /* Database Settings */
  64          $registry->set('dbtype', $options->db_type);
  65          $registry->set('host', $options->db_host);
  66          $registry->set('user', $options->db_user);
  67          $registry->set('password', $options->db_pass);
  68          $registry->set('db', $options->db_name);
  69          $registry->set('dbprefix', $options->db_prefix);
  70  
  71          /* Server Settings */
  72          $registry->set('live_site', '');
  73          $registry->set('secret', JUserHelper::genRandomPassword(16));
  74          $registry->set('gzip', 0);
  75          $registry->set('error_reporting', 'default');
  76          $registry->set('helpurl', 'http://help.joomla.org/proxy/index.php?option=com_help&amp;keyref=Help{major}{minor}:{keyref}');
  77          $registry->set('ftp_host', $options->ftp_host);
  78          $registry->set('ftp_port', $options->ftp_port);
  79          $registry->set('ftp_user', $options->ftp_save ? $options->ftp_user : '');
  80          $registry->set('ftp_pass', $options->ftp_save ? $options->ftp_pass : '');
  81          $registry->set('ftp_root', $options->ftp_save ? $options->ftp_root : '');
  82          $registry->set('ftp_enable', $options->ftp_enable);
  83  
  84          /* Locale Settings */
  85          $registry->set('offset', 'UTC');
  86          $registry->set('offset_user', 'UTC');
  87  
  88          /* Mail Settings */
  89          $registry->set('mailer', 'mail');
  90          $registry->set('mailfrom', $options->admin_email);
  91          $registry->set('fromname', $options->site_name);
  92          $registry->set('sendmail', '/usr/sbin/sendmail');
  93          $registry->set('smtpauth', 0);
  94          $registry->set('smtpuser', '');
  95          $registry->set('smtppass', '');
  96          $registry->set('smtphost', 'localhost');
  97          $registry->set('smtpsecure', 'none');
  98          $registry->set('smtpport', '25');
  99  
 100          /* Cache Settings */
 101          $registry->set('caching', 0);
 102          $registry->set('cache_handler', 'file');
 103          $registry->set('cachetime', 15);
 104  
 105          /* Meta Settings */
 106          $registry->set('MetaDesc', $options->site_metadesc);
 107          $registry->set('MetaKeys', $options->site_metakeys);
 108          $registry->set('MetaTitle', 1);
 109          $registry->set('MetaAuthor', 1);
 110          $registry->set('MetaVersion', 0);
 111          $registry->set('robots', '');
 112  
 113          /* SEO Settings */
 114          $registry->set('sef', 1);
 115          $registry->set('sef_rewrite', 0);
 116          $registry->set('sef_suffix', 0);
 117          $registry->set('unicodeslugs', 0);
 118  
 119          /* Feed Settings */
 120          $registry->set('feed_limit', 10);
 121          $registry->set('log_path', JPATH_ROOT . '/logs');
 122          $registry->set('tmp_path', JPATH_ROOT . '/tmp');
 123  
 124          /* Session Setting */
 125          $registry->set('lifetime', 15);
 126          $registry->set('session_handler', 'database');
 127  
 128          // Generate the configuration class string buffer.
 129          $buffer = $registry->toString('PHP', array('class'=>'JConfig', 'closingtag' => false));
 130  
 131  
 132          // Build the configuration file path.
 133          $path = JPATH_CONFIGURATION . '/configuration.php';
 134  
 135          // Determine if the configuration file path is writable.
 136          if (file_exists($path)) {
 137              $canWrite = is_writable($path);
 138          } else {
 139              $canWrite = is_writable(JPATH_CONFIGURATION . '/');
 140          }
 141  
 142          /*
 143           * If the file exists but isn't writable OR if the file doesn't exist and the parent directory
 144           * is not writable we need to use FTP
 145           */
 146          $useFTP = false;
 147          if ((file_exists($path) && !is_writable($path)) || (!file_exists($path) && !is_writable(dirname($path).'/'))) {
 148              $useFTP = true;
 149          }
 150  
 151          // Check for safe mode
 152          if (ini_get('safe_mode')) {
 153              $useFTP = true;
 154          }
 155  
 156          // Enable/Disable override
 157          if (!isset($options->ftpEnable) || ($options->ftpEnable != 1)) {
 158              $useFTP = false;
 159          }
 160  
 161          if ($useFTP == true) {
 162              // Connect the FTP client
 163              jimport('joomla.client.ftp');
 164              jimport('joomla.filesystem.path');
 165  
 166              $ftp = JFTP::getInstance($options->ftp_host, $options->ftp_port);
 167              $ftp->login($options->ftp_user, $options->ftp_pass);
 168  
 169              // Translate path for the FTP account
 170              $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/');
 171  
 172              // Use FTP write buffer to file
 173              if (!$ftp->write($file, $buffer)) {
 174                  // Set the config string to the session.
 175                  $session = JFactory::getSession();
 176                  $session->set('setup.config', $buffer);
 177              }
 178  
 179              $ftp->quit();
 180          } else {
 181              if ($canWrite) {
 182                  file_put_contents($path, $buffer);
 183                  $session = JFactory::getSession();
 184                  $session->set('setup.config', null);
 185              } else {
 186                  // Set the config string to the session.
 187                  $session = JFactory::getSession();
 188                  $session->set('setup.config', $buffer);
 189              }
 190          }
 191  
 192          return true;
 193      }
 194  
 195  	function _createRootUser($options)
 196      {
 197          // Get a database object.
 198          try
 199          {
 200              $db = JInstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
 201          }
 202          catch (JDatabaseException $e)
 203          {
 204              $this->setError(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()));
 205          }
 206  
 207          // Create random salt/password for the admin user
 208          $salt = JUserHelper::genRandomPassword(32);
 209          $crypt = JUserHelper::getCryptedPassword($options->admin_password, $salt);
 210          $cryptpass = $crypt.':'.$salt;
 211  
 212          // create the admin user
 213          date_default_timezone_set('UTC');
 214          $installdate    = date('Y-m-d H:i:s');
 215          $nullDate        = $db->getNullDate();
 216          //sqlsrv change
 217          $query = $db->getQuery(true);
 218          $query->select('id');
 219          $query->from('#__users');
 220          $query->where('id = 42');
 221  
 222          $db->setQuery($query);
 223  
 224          if($db->loadResult())
 225          {
 226            $query = $db->getQuery(true);
 227            $query->update('#__users');
 228            $query->set('name = '.$db->quote('Super User'));
 229            $query->set('username = '.$db->quote($options->admin_user));
 230            $query->set('email = '.$db->quote($options->admin_email));
 231            $query->set('password = '.$db->quote($cryptpass));
 232            $query->set('usertype = '.$db->quote('deprecated'));
 233            $query->set('block = 0');
 234            $query->set('sendEmail = 1');
 235            $query->set('registerDate = '.$db->quote($installdate));
 236            $query->set('lastvisitDate = '.$db->quote($nullDate));
 237            $query->set('activation = '.$db->quote('0'));
 238            $query->set('params = '.$db->quote(''));
 239            $query->where('id = 42');
 240          } else {
 241           $query = $db->getQuery(true);
 242            $columns =  array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'),
 243                              $db->quoteName('email'), $db->quoteName('password'),
 244                              $db->quoteName('usertype'),
 245                              $db->quoteName('block'),
 246                              $db->quoteName('sendEmail'), $db->quoteName('registerDate'),
 247                              $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
 248            $query->insert('#__users', true);
 249            $query->columns($columns);
 250  
 251            $query->values('42'. ', '. $db->quote('Super User'). ', '. $db->quote($options->admin_user). ', '.
 252                      $db->quote($options->admin_email). ', '. $db->quote($cryptpass). ', '. $db->quote('deprecated').', '.$db->quote('0').', '.$db->quote('1').', '.
 253                      $db->quote($installdate).', '.$db->quote($nullDate).', '.$db->quote('0').', '.$db->quote(''));
 254      }
 255      $db->setQuery($query);
 256      if (!$db->query()) {
 257          $this->setError($db->getErrorMsg());
 258          return false;
 259      }
 260  
 261      // Map the super admin to the Super Admin Group
 262      $query = $db->getQuery(true);
 263      $query->select('user_id');
 264      $query->from('#__user_usergroup_map');
 265      $query->where('user_id = 42');
 266  
 267      $db->setQuery($query);
 268  
 269      if($db->loadResult())
 270      {
 271        $query = $db->getQuery(true);
 272        $query->update('#__user_usergroup_map');
 273        $query->set('user_id = 42');
 274        $query->set('group_id = 8');
 275      } else {
 276        $query = $db->getQuery(true);
 277        $query->insert('#__user_usergroup_map', false);
 278        $query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
 279        $query->values('42'. ', '. '8');
 280  
 281      }
 282  
 283      $db->setQuery($query);
 284      if (!$db->query()) {
 285          $this->setError($db->getErrorMsg());
 286          return false;
 287      }
 288  
 289      return true;
 290      }
 291  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1