diff --git a/installation/application/web.php b/installation/application/web.php index 2b1ae2d2d9b24..a78928b269677 100644 --- a/installation/application/web.php +++ b/installation/application/web.php @@ -10,7 +10,7 @@ defined('_JEXEC') or die; /** - * Joomla! Installation Application class + * Joomla! Installation Application class. * * @package Joomla.Installation * @subpackage Application @@ -25,10 +25,10 @@ final class InstallationApplicationWeb extends JApplicationCms */ public function __construct() { - // Run the parent constructor + // Run the parent constructor. parent::__construct(); - // Load and set the dispatcher + // Load and set the dispatcher. $this->loadDispatcher(); // Enable sessions by default. @@ -48,23 +48,23 @@ public function __construct() { $this->loadSession(); - // Register the session with JFactory + // Register the session with JFactory. JFactory::$session = $this->getSession(); } - // Store the debug value to config based on the JDEBUG flag + // Store the debug value to config based on the JDEBUG flag. $this->config->set('debug', JDEBUG); - // Register the config to JFactory + // Register the config to JFactory. JFactory::$config = $this->config; - // Register the application to JFactory + // Register the application to JFactory. JFactory::$application = $this; - // Register the application name + // Register the application name. $this->_name = 'installation'; - // Register the client ID + // Register the client ID. $this->_clientId = 2; // Set the root in the URI one level up. @@ -74,9 +74,9 @@ public function __construct() } /** - * Method to display errors in language parsing + * Method to display errors in language parsing. * - * @return string Language debug output + * @return string Language debug output. * * @since 3.1 */ @@ -112,11 +112,13 @@ public function debugLanguage() ksort($orphans, SORT_STRING); $guesses = array(); + foreach ($orphans as $key => $occurance) { $guess = str_replace('_', ' ', $key); $parts = explode(' ', $guess); + if (count($parts) > 1) { array_shift($parts); @@ -129,7 +131,7 @@ public function debugLanguage() $key = preg_replace('#\s+#', '_', $key); $key = preg_replace('#\W#', '', $key); - // Prepare the text + // Prepare the text. $guesses[] = $key . '="' . $guess . '"'; } @@ -146,7 +148,7 @@ public function debugLanguage() } /** - * Dispatch the application + * Dispatch the application. * * @return void * @@ -156,13 +158,13 @@ public function dispatch() { try { - // Load the document to the API + // Load the document to the API. $this->loadDocument(); // Set up the params $document = $this->getDocument(); - // Register the document object with JFactory + // Register the document object with JFactory. JFactory::$document = $document; if ($document->getType() == 'html') @@ -171,7 +173,7 @@ public function dispatch() $document->setTitle(JText::_('INSTL_PAGE_TITLE')); } - // Define component path + // Define component path. define('JPATH_COMPONENT', JPATH_BASE); define('JPATH_COMPONENT_SITE', JPATH_SITE); define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR); @@ -188,7 +190,7 @@ public function dispatch() $this->close($e->getCode()); } - // If debug language is set, append its output to the contents + // If debug language is set, append its output to the contents. if ($this->config->get('debug_lang')) { $contents .= $this->debugLanguage(); @@ -215,10 +217,10 @@ public function dispatch() */ protected function doExecute() { - // Initialise the application + // Initialise the application. $this->initialiseApp(); - // Dispatch the application + // Dispatch the application. $this->dispatch(); } @@ -258,7 +260,7 @@ protected function fetchController($task) $task = 'default'; } - // Set the controller class name based on the task + // Set the controller class name based on the task. $class = 'InstallationController' . ucfirst($task); // If the requested controller exists let's use it. @@ -288,7 +290,7 @@ public function getLocalise() return false; } - // Check that it's a localise file + // Check that it's a localise file. if ($xml->getName() != 'localise') { return false; @@ -308,19 +310,19 @@ public function getLocalise() * Returns the installed language files in the administrative and * front-end area. * - * @param mixed $db JDatabaseDriver instance + * @param mixed $db JDatabaseDriver instance. * - * @return array Array with installed language packs in admin and site area + * @return array Array with installed language packs in admin and site area. * * @since 3.1 */ public function getLocaliseAdmin($db = false) { - // Read the files in the admin area + // Read the files in the admin area. $path = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR); $langfiles['admin'] = JFolder::folders($path); - // Read the files in the site area + // Read the files in the site area. $path = JLanguage::getLanguagePath(JPATH_SITE); $langfiles['site'] = JFolder::folders($path); @@ -341,7 +343,7 @@ public function getLocaliseAdmin($db = false) { switch ($lang->client_id) { - // Site + // Site. case 0: if (in_array($lang->element, $langfiles_disk['site'])) { @@ -350,7 +352,7 @@ public function getLocaliseAdmin($db = false) break; - // Administrator + // Administrator. case 1: if (in_array($lang->element, $langfiles_disk['admin'])) { @@ -381,6 +383,7 @@ public function getTemplate($params = false) $template = new stdClass; $template->template = 'template'; $template->params = new JRegistry; + return $template; } @@ -405,6 +408,7 @@ protected function initialiseApp($options = array()) if (empty($options['language'])) { $requestLang = $this->input->getCmd('lang', null); + if (!is_null($requestLang)) { $options['language'] = $requestLang; @@ -440,13 +444,13 @@ protected function initialiseApp($options = array()) } } - // Give the user English + // Give the user English. if (empty($options['language'])) { $options['language'] = 'en-GB'; } - // Check for custom helpurl + // Check for custom helpurl. if (empty($forced['helpurl'])) { $options['helpurl'] = 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}'; @@ -456,10 +460,10 @@ protected function initialiseApp($options = array()) $options['helpurl'] = $forced['helpurl']; } - // Store helpurl in the session + // Store helpurl in the session. $this->getSession()->set('setup.helpurl', $options['helpurl']); - // Set the language in the class + // Set the language in the class. $this->config->set('language', $options['language']); $this->config->set('debug_lang', $forced['debug']); $this->config->set('sampledata', $forced['sampledata']); @@ -497,7 +501,7 @@ public function loadDocument(JDocument $document = null) $document = JDocument::getInstance($type, $attributes); - // Register the instance to JFactory + // Register the instance to JFactory. JFactory::$document = $document; } @@ -552,7 +556,7 @@ public function loadSession(JSession $session = null) if (!$session->get('registry') instanceof JRegistry) { - // Registry has been corrupted somehow + // Registry has been corrupted somehow. $session->set('registry', new JRegistry('session')); } @@ -622,7 +626,7 @@ public function sendJsonResponse($response) } /** - * Set configuration values + * Set configuration values. * * @param array $vars Array of configuration values * @param string $namespace The namespace diff --git a/installation/controller/install/database_backup.php b/installation/controller/install/database_backup.php index 598efb7657389..1c56a6ed93e0d 100644 --- a/installation/controller/install/database_backup.php +++ b/installation/controller/install/database_backup.php @@ -27,7 +27,7 @@ class InstallationControllerInstallDatabase_backup extends JControllerBase */ public function execute() { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = $this->getApplication(); @@ -37,7 +37,7 @@ public function execute() // Get the setup model. $model = new InstallationModelSetup; - // Get the options from the session + // Get the options from the session. $options = $model->getOptions(); // Get the database model. @@ -49,7 +49,7 @@ public function execute() $r = new stdClass; $r->view = 'install'; - // Check if the database was initialised + // Check if the database was initialised. if (!$return) { $r->view = 'database'; diff --git a/installation/controller/removefolder.php b/installation/controller/removefolder.php index d25eedb62d8b8..4d82244f40ad1 100644 --- a/installation/controller/removefolder.php +++ b/installation/controller/removefolder.php @@ -27,7 +27,7 @@ class InstallationControllerRemovefolder extends JControllerBase */ public function execute() { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = $this->getApplication(); @@ -36,26 +36,27 @@ public function execute() $path = JPATH_INSTALLATION; - // Check whether the folder still exists + // Check whether the folder still exists. if (!file_exists($path)) { $app->sendJsonResponse(new Exception(JText::sprintf('INSTL_COMPLETE_ERROR_FOLDER_ALREADY_REMOVED'), 500)); } - // Check whether we need to use FTP + // Check whether we need to use FTP. $useFTP = false; + if ((file_exists($path) && !is_writable($path))) { $useFTP = true; } - // Check for safe mode + // Check for safe mode. if (ini_get('safe_mode')) { $useFTP = true; } - // Enable/Disable override + // Enable/Disable override. if (!isset($options->ftpEnable) || ($options->ftpEnable != 1)) { $useFTP = false; @@ -63,25 +64,26 @@ public function execute() if ($useFTP == true) { - // Connect the FTP client + // Connect the FTP client. $ftp = JClientFtp::getInstance($options->ftp_host, $options->ftp_port); $ftp->login($options->ftp_user, $options->ftp_pass); - // Translate path for the FTP account + // Translate path for the FTP account. $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/'); $return = $ftp->delete($file); - // Delete the extra XML file while we're at it + // Delete the extra XML file while we're at it. if ($return) { $file = JPath::clean($options->ftp_root . '/joomla.xml'); + if (file_exists($file)) { $return = $ftp->delete($file); } } - // Rename the robots.txt.dist file to robots.txt + // Rename the robots.txt.dist file to robots.txt. if ($return) { $robotsFile = JPath::clean($options->ftp_root . '/robots.txt'); @@ -125,7 +127,7 @@ public function execute() $r->text = JText::_('INSTL_COMPLETE_FOLDER_REMOVED'); /* - * Send the response + * Send the response. * This is a hack since by now, the rest of the folder is deleted and we can't make a new request */ $this->sendJsonResponse($r); @@ -183,13 +185,13 @@ public function __construct($data) // The old token is invalid so send a new one. $this->token = JSession::getFormToken(true); - // Get the language and send it's tag along + // Get the language and send it's tag along. $this->lang = JFactory::getLanguage()->getTag(); // Get the message queue $messages = JFactory::getApplication()->getMessageQueue(); - // Build the sorted message list + // Build the sorted message list. if (is_array($messages) && count($messages)) { foreach ($messages as $msg) @@ -201,7 +203,7 @@ public function __construct($data) } } - // If messages exist add them to the output + // If messages exist add them to the output. if (isset($lists) && is_array($lists)) { $this->messages = $lists; diff --git a/installation/helper/html/installation.php b/installation/helper/html/installation.php index a671e61862692..c871df31989b4 100644 --- a/installation/helper/html/installation.php +++ b/installation/helper/html/installation.php @@ -17,15 +17,14 @@ class JHtmlInstallation { /** - * Method to generate the side bar + * Method to generate the side bar. * - * @return string Markup for the side bar + * @return string Markup for the side bar. * * @since 1.6 */ public static function stepbar() { - // Determine if the configuration file path is writable. $path = JPATH_CONFIGURATION . '/configuration.php'; $useftp = (file_exists($path)) ? !is_writable($path) : !is_writable(JPATH_CONFIGURATION . '/'); @@ -33,32 +32,36 @@ public static function stepbar() $tabs = array(); $tabs[] = 'site'; $tabs[] = 'database'; + if ($useftp) { $tabs[] = 'ftp'; } + $tabs[] = 'summary'; $html = array(); $html[] = ''; + return implode('', $html); } /** - * Method to generate the side bar + * Method to generate the side bar. * - * @return string Markup for the side bar + * @return string Markup for the side bar. * * @since 3.1 */ public static function stepbarlanguages() { - $tabs = array(); $tabs[] = 'languages'; $tabs[] = 'defaultlanguage'; @@ -66,22 +69,24 @@ public static function stepbarlanguages() $html = array(); $html[] = ''; return implode('', $html); } /** - * Method to generate the navigation tab + * Method to generate the navigation tab. * - * @param string $id The container ID - * @param array $tabs The navigation tabs + * @param string $id The container ID. + * @param array $tabs The navigation tabs. * - * @return string Markup for the tab + * @return string Markup for the tab. * * @since 3.1 */ @@ -109,12 +114,12 @@ private static function getTab($id, $tabs) } /** - * Method to determine the tab (step) number + * Method to determine the tab (step) number. * - * @param string $id The container ID - * @param array $tabs The navigation tabs + * @param string $id The container ID. + * @param array $tabs The navigation tabs. * - * @return integer Tab number in navigation sequence + * @return integer Tab number in navigation sequence. * * @since 3.1 */ diff --git a/installation/model/configuration.php b/installation/model/configuration.php index 83cbbf5f63d88..577688f322c4b 100644 --- a/installation/model/configuration.php +++ b/installation/model/configuration.php @@ -56,12 +56,12 @@ public function setup($options) * * @since 3.1 */ - function _createConfiguration($options) + public function _createConfiguration($options) { // Create a new registry to build the configuration options. $registry = new JRegistry; - /* Site Settings */ + // Site settings. $registry->set('offline', $options->site_offline); $registry->set('offline_message', JText::_('INSTL_STD_OFFLINE_MSG')); $registry->set('display_offline_message', 1); @@ -72,11 +72,11 @@ function _createConfiguration($options) $registry->set('list_limit', 20); $registry->set('access', 1); - /* Debug Settings */ + // Debug settings. $registry->set('debug', 0); $registry->set('debug_lang', 0); - /* Database Settings */ + // Database settings. $registry->set('dbtype', $options->db_type); $registry->set('host', $options->db_host); $registry->set('user', $options->db_user); @@ -84,7 +84,7 @@ function _createConfiguration($options) $registry->set('db', $options->db_name); $registry->set('dbprefix', $options->db_prefix); - /* Server Settings */ + // Server settings. $registry->set('live_site', ''); $registry->set('secret', JUserHelper::genRandomPassword(16)); $registry->set('gzip', 0); @@ -97,10 +97,10 @@ function _createConfiguration($options) $registry->set('ftp_root', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_root)) ? $options->ftp_root : ''); $registry->set('ftp_enable', isset($options->ftp_host) ? $options->ftp_enable : ''); - /* Locale Settings */ + // Locale settings. $registry->set('offset', 'UTC'); - /* Mail Settings */ + // Mail settings. $registry->set('mailonline', 1); $registry->set('mailer', 'mail'); $registry->set('mailfrom', $options->admin_email); @@ -113,12 +113,12 @@ function _createConfiguration($options) $registry->set('smtpsecure', 'none'); $registry->set('smtpport', '25'); - /* Cache Settings */ + // Cache settings. $registry->set('caching', 0); $registry->set('cache_handler', 'file'); $registry->set('cachetime', 15); - /* Meta Settings */ + // Meta settings. $registry->set('MetaDesc', $options->site_metadesc); $registry->set('MetaKeys', ''); $registry->set('MetaTitle', 1); @@ -126,18 +126,18 @@ function _createConfiguration($options) $registry->set('MetaVersion', 0); $registry->set('robots', ''); - /* SEO Settings */ + // SEO settings. $registry->set('sef', 1); $registry->set('sef_rewrite', 0); $registry->set('sef_suffix', 0); $registry->set('unicodeslugs', 0); - /* Feed Settings */ + // Feed settings. $registry->set('feed_limit', 10); $registry->set('log_path', JPATH_ROOT . '/logs'); $registry->set('tmp_path', JPATH_ROOT . '/tmp'); - /* Session Setting */ + // Session setting. $registry->set('lifetime', 15); $registry->set('session_handler', 'database'); @@ -159,7 +159,7 @@ function _createConfiguration($options) /* * If the file exists but isn't writable OR if the file doesn't exist and the parent directory - * is not writable we need to use FTP + * is not writable we need to use FTP. */ $useFTP = false; @@ -168,13 +168,13 @@ function _createConfiguration($options) $useFTP = true; } - // Check for safe mode + // Check for safe mode. if (ini_get('safe_mode')) { $useFTP = true; } - // Enable/Disable override + // Enable/Disable override. if (!isset($options->ftpEnable) || ($options->ftpEnable != 1)) { $useFTP = false; @@ -182,14 +182,14 @@ function _createConfiguration($options) if ($useFTP == true) { - // Connect the FTP client + // Connect the FTP client. $ftp = JClientFtp::getInstance($options->ftp_host, $options->ftp_port); $ftp->login($options->ftp_user, $options->ftp_pass); - // Translate path for the FTP account + // Translate path for the FTP account. $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/'); - // Use FTP write buffer to file + // Use FTP write buffer to file. if (!$ftp->write($file, $buffer)) { // Set the config string to the session. @@ -219,11 +219,11 @@ function _createConfiguration($options) } /** - * Method to create the root user for the site + * Method to create the root user for the site. * - * @param object $options The session options + * @param object $options The session options. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ @@ -236,7 +236,14 @@ private function _createRootUser($options) // Get a database object. try { - $db = InstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix); + $db = InstallationHelperDatabase::getDBO( + $options->db_type, + $options->db_host, + $options->db_user, + $options->db_pass, + $options->db_name, + $options->db_prefix + ); } catch (RuntimeException $e) { @@ -247,18 +254,18 @@ private function _createRootUser($options) $cryptpass = JUserHelper::hashPassword($options->admin_password); - // Take the admin user id + // Take the admin user id. $userId = InstallationModelDatabase::getUserId(); - // We don't need the randUserId in the session any longer, let's remove it + // We don't need the randUserId in the session any longer, let's remove it. InstallationModelDatabase::resetRandUserId(); - // Create the admin user + // Create the admin user. date_default_timezone_set('UTC'); $installdate = date('Y-m-d H:i:s'); $nullDate = $db->getNullDate(); - // Sqlsrv change + // Sqlsrv change. $query = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__users')) @@ -284,20 +291,27 @@ private function _createRootUser($options) } else { - $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'), - $db->quoteName('email'), $db->quoteName('password'), - $db->quoteName('block'), - $db->quoteName('sendEmail'), $db->quoteName('registerDate'), - $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params')); + $columns = array( + $db->quoteName('id'), $db->quoteName('name'), + $db->quoteName('username'), + $db->quoteName('email'), + $db->quoteName('password'), + $db->quoteName('block'), + $db->quoteName('sendEmail'), + $db->quoteName('registerDate'), + $db->quoteName('lastvisitDate'), + $db->quoteName('activation'), + $db->quoteName('params') + ); $query->clear() ->insert('#__users', true) ->columns($columns) ->values( - $db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote(trim($options->admin_user)) . ', ' . - $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' . - $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' . - $db->quote('0') . ', ' . $db->quote('') - ); + $db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote(trim($options->admin_user)) . ', ' . + $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' . + $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' . + $db->quote('0') . ', ' . $db->quote('') + ); } $db->setQuery($query); @@ -309,6 +323,7 @@ private function _createRootUser($options) catch (RuntimeException $e) { $app->enqueueMessage($e->getMessage(), 'notice'); + return false; } @@ -344,6 +359,7 @@ private function _createRootUser($options) catch (RuntimeException $e) { $app->enqueueMessage($e->getMessage(), 'notice'); + return false; } diff --git a/installation/model/database.php b/installation/model/database.php index da6d6be24ee87..34080e29b3da8 100644 --- a/installation/model/database.php +++ b/installation/model/database.php @@ -18,7 +18,7 @@ class InstallationModelDatabase extends JModelBase { /** - * The generated user ID + * The generated user ID. * * @var integer * @since 3.1 @@ -26,9 +26,9 @@ class InstallationModelDatabase extends JModelBase protected static $userId = 0; /** - * Generates the user ID + * Generates the user ID. * - * @return integer The user ID + * @return integer The user ID. * * @since 3.1 */ @@ -39,7 +39,7 @@ protected static function generateRandUserId() if (empty($randUserId)) { - // Create the ID for the root user only once and store in session + // Create the ID for the root user only once and store in session. $randUserId = mt_rand(1, 1000); $session->set('randUserId', $randUserId); } @@ -48,7 +48,7 @@ protected static function generateRandUserId() } /** - * Resets the user ID + * Resets the user ID. * * @return void * @@ -62,9 +62,9 @@ public static function resetRandUserId() } /** - * Retrieves the default user ID and sets it if necessary + * Retrieves the default user ID and sets it if necessary. * - * @return integer The user ID + * @return integer The user ID. * * @since 3.1 */ @@ -79,24 +79,24 @@ public static function getUserId() } /** - * Method to initialise the database + * Method to initialise the database. * - * @param array $options The options to use for configuration + * @param array $options The options to use for configuration. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ public function initialise($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); // Get the options as a object for easier handling. $options = JArrayHelper::toObject($options); - // Load the back-end language files so that the DB error messages work + // Load the back-end language files so that the DB error messages work. $lang = JFactory::getLanguage(); $currentLang = $lang->getTag(); @@ -105,7 +105,7 @@ public function initialise($options) { $lang->load('joomla', JPATH_ADMINISTRATOR, $currentLang, true); } - // Pre-load en-GB in case the chosen language files do not exist + // Pre-load en-GB in case the chosen language files do not exist. else { $lang->load('joomla', JPATH_ADMINISTRATOR, 'en-GB', true); @@ -115,6 +115,7 @@ public function initialise($options) if (empty($options->db_type)) { $app->enqueueMessage(JText::_('INSTL_DATABASE_INVALID_TYPE'), 'notice'); + return false; } @@ -122,6 +123,7 @@ public function initialise($options) if (empty($options->db_host) || empty($options->db_user)) { $app->enqueueMessage(JText::_('INSTL_DATABASE_INVALID_DB_DETAILS'), 'notice'); + return false; } @@ -129,6 +131,7 @@ public function initialise($options) if (empty($options->db_name)) { $app->enqueueMessage(JText::_('INSTL_DATABASE_EMPTY_NAME'), 'notice'); + return false; } @@ -136,6 +139,7 @@ public function initialise($options) if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $options->db_prefix)) { $app->enqueueMessage(JText::_('INSTL_DATABASE_PREFIX_MSG'), 'notice'); + return false; } @@ -143,6 +147,7 @@ public function initialise($options) if (strlen($options->db_prefix) > 15) { $app->enqueueMessage(JText::_('INSTL_DATABASE_FIX_TOO_LONG'), 'notice'); + return false; } @@ -150,6 +155,7 @@ public function initialise($options) if (strlen($options->db_name) > 64) { $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_TOO_LONG'), 'notice'); + return false; } @@ -163,6 +169,7 @@ public function initialise($options) catch (RuntimeException $e) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()), 'notice'); + return false; } } @@ -178,17 +185,18 @@ public function initialise($options) */ public function createDatabase($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); - // Disable autoselect database before it's created + // Disable autoselect database before it's created. $tmpSelect = true; if (isset($options['db_select'])) { $tmpSelect = $options['db_select']; } + $options['db_select'] = false; if (!$db = $this->initialise($options)) @@ -209,36 +217,41 @@ public function createDatabase($options) catch (RuntimeException $e) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()), 'notice'); + return false; } if (!$db->isMinimumVersion()) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($type) . '_VERSION', $db_version), 'notice'); + return false; } if (($type == 'mysql') || ($type == 'mysqli')) { - // @internal MySQL versions pre 5.1.6 forbid . / or \ or NULL + // @internal MySQL versions pre 5.1.6 forbid . / or \ or NULL. if ((preg_match('#[\\\/\.\0]#', $options->db_name)) && (!version_compare($db_version, '5.1.6', '>='))) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_INVALID_NAME', $db_version), 'notice'); + return false; } } - // @internal Check for spaces in beginning or end of name + // @internal Check for spaces in beginning or end of name. if (strlen(trim($options->db_name)) <> strlen($options->db_name)) { $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_INVALID_SPACES'), 'notice'); + return false; } - // @internal Check for asc(00) Null in name + // @internal Check for asc(00) Null in name. if (strpos($options->db_name, chr(00)) !== false) { $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_INVALID_CHAR'), 'notice'); + return false; } @@ -249,10 +262,10 @@ public function createDatabase($options) $db->execute(); } - // Get database's UTF support + // Get database's UTF support. $utfSupport = $db->hasUTFSupport(); - // Try to select the database + // Try to select the database. try { $db->select($options->db_name); @@ -267,13 +280,14 @@ public function createDatabase($options) else { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_ERROR_CREATE', $options->db_name), 'notice'); + return false; } } $options = (array) $options; - // Remove *_errors value + // Remove *_errors value. foreach ($options as $i => $option) { if (isset($i['1']) && $i['1'] == '*') @@ -282,9 +296,10 @@ public function createDatabase($options) break; } } + $options = array_merge(array('db_created' => 1), $options); - // Restore autoselect value after database creation + // Restore autoselect value after database creation. $options['db_select'] = $tmpSelect; $session = JFactory::getSession(); @@ -294,11 +309,11 @@ public function createDatabase($options) } /** - * Method to process the old database + * Method to process the old database. * - * @param array $options The options array + * @param array $options The options array. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ @@ -343,17 +358,17 @@ public function handleOldDatabase($options) } /** - * Method to create the database tables + * Method to create the database tables. * - * @param array $options The options array + * @param array $options The options array. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ public function createTables($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); @@ -394,6 +409,7 @@ public function createTables($options) if (!is_file($schema)) { $app->enqueueMessage(JText::sprintf('INSTL_ERROR_DB', JText::_('INSTL_DATABASE_NO_SCHEMA')), 'notice'); + return false; } @@ -418,13 +434,16 @@ public function createTables($options) { $pathPart .= $type . '/'; } + $files = JFolder::files($pathPart, '\.sql$'); if (empty($files)) { $app->enqueueMessage(JText::_('INSTL_ERROR_INITIALISE_SCHEMA'), 'notice'); + return false; } + $version = ''; foreach ($files as $file) @@ -434,6 +453,7 @@ public function createTables($options) $version = JFile::stripExt($file); } } + $query = $db->getQuery(true) ->insert($db->quoteName('#__schemas')) ->columns( @@ -452,10 +472,11 @@ public function createTables($options) catch (RuntimeException $e) { $app->enqueueMessage($e->getMessage(), 'notice'); + return false; } - // Attempt to refresh manifest caches + // Attempt to refresh manifest caches. $query->clear() ->select('*') ->from('#__extensions'); @@ -481,11 +502,12 @@ public function createTables($options) if (!$installer->refreshManifestCache($extension->extension_id)) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_REFRESH_MANIFEST_CACHE', $extension->name), 'notice'); + return false; } } - // Load the localise.sql for translating the data in joomla.sql + // Load the localise.sql for translating the data in joomla.sql. if ($type == 'mysqli' || $type == 'mysql') { $dblocalise = 'sql/mysql/localise.sql'; @@ -516,7 +538,7 @@ public function createTables($options) // Build the language parameters for the language manager. $params = array(); - // Set default administrator/site language to sample data values: + // Set default administrator/site language to sample data values. $params['administrator'] = 'en-GB'; $params['site'] = 'en-GB'; @@ -529,6 +551,7 @@ public function createTables($options) { $params['site'] = $options->language; } + $params = json_encode($params); // Update the language settings in the language manager. @@ -553,17 +576,17 @@ public function createTables($options) } /** - * Method to install the sample data + * Method to install the sample data. * - * @param array $options The options array + * @param array $options The options array. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ public function installSampleData($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); @@ -600,6 +623,7 @@ public function installSampleData($options) if (!file_exists($data)) { $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_FILE_DOES_NOT_EXIST', $data), 'notice'); + return false; } elseif (!$this->populateDatabase($db, $data)) @@ -614,9 +638,9 @@ public function installSampleData($options) } /** - * Method to update the user id of the sample data content to the new rand user id + * Method to update the user id of the sample data content to the new rand user id. * - * @param JDatabaseDriver $db Database connector object $db* + * @param JDatabaseDriver $db Database connector object $db*. * * @return void * @@ -624,11 +648,11 @@ public function installSampleData($options) */ protected function postInstallSampleData($db) { - // Create the ID for the root user + // Create the ID for the root user. $userId = self::getUserId(); // Update all created_by field of the tables with the random user id - // categories (created_user_id), contact_details, content, newsfeeds, weblinks + // categories (created_user_id), contact_details, content, newsfeeds, weblinks. $updates_array = array( 'categories' => 'created_user_id', 'contact_details' => 'created_by', @@ -798,6 +822,7 @@ public function populateDatabase($db, $schema) if (!($buffer = file_get_contents($schema))) { $app->enqueueMessage($db->getErrorMsg(), 'notice'); + return false; } @@ -881,10 +906,10 @@ protected function _splitQueries($query) // Remove PostgreSQL comment lines. $query = preg_replace("/\n\--[^\n]*/", '', "\n" . $query); - // Find function + // Find function. $funct = explode('CREATE OR REPLACE FUNCTION', $query); - // Save sql before function and parse it + // Save sql before function and parse it. $query = $funct[0]; // Parse the schema file to break up queries. @@ -905,10 +930,12 @@ protected function _splitQueries($query) { $in_string = $query[$i]; } + if (isset ($buffer[1])) { $buffer[0] = $buffer[1]; } + $buffer[1] = $query[$i]; } @@ -918,7 +945,7 @@ protected function _splitQueries($query) $queries[] = $query; } - // Add function part as is + // Add function part as is. for ($f = 1; $f < count($funct); $f++) { $queries[] = 'CREATE OR REPLACE FUNCTION ' . $funct[$f]; diff --git a/installation/model/fields/prefix.php b/installation/model/fields/prefix.php index d64ca11d7135d..872714f498b79 100644 --- a/installation/model/fields/prefix.php +++ b/installation/model/fields/prefix.php @@ -40,26 +40,27 @@ protected function getInput() $readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : ''; $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : ''; - // Make sure somebody doesn't put in a too large prefix size value: + // Make sure somebody doesn't put in a too large prefix size value. if ($size > 10) { $size = 10; } - // If a prefix is already set, use it instead + // If a prefix is already set, use it instead. $session = JFactory::getSession()->get('setup.options', array()); + if (empty($session['db_prefix'])) { - // Create the random prefix: + // Create the random prefix. $prefix = ''; $chars = range('a', 'z'); $numbers = range(0, 9); - // We want the fist character to be a random letter: + // We want the fist character to be a random letter. shuffle($chars); $prefix .= $chars[0]; - // Next we combine the numbers and characters to get the other characters: + // Next we combine the numbers and characters to get the other characters. $symbols = array_merge($numbers, $chars); shuffle($symbols); @@ -68,7 +69,7 @@ protected function getInput() $prefix .= $symbols[$i]; } - // Add in the underscore: + // Add in the underscore. $prefix .= '_'; } else diff --git a/installation/model/ftp.php b/installation/model/ftp.php index d339fe4db0d21..a64f302fa4f1c 100644 --- a/installation/model/ftp.php +++ b/installation/model/ftp.php @@ -29,7 +29,7 @@ class InstallationModelFtp extends JModelBase */ public function detectFtpRoot($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); @@ -44,29 +44,36 @@ public function detectFtpRoot($options) if (!$ftp->isConnected()) { $app->enqueueMessage($options->get('ftp_host') . ':' . $options->get('ftp_port') . ' ' . JText::_('INSTL_FTP_NOCONNECT'), 'error'); + return false; } if (!$ftp->login($options->get('ftp_user'), $options->get('ftp_pass'))) { $app->enqueueMessage(JText::_('INSTL_FTP_NOLOGIN'), 'error'); + return false; } // Get the current working directory from the FTP server. $cwd = $ftp->pwd(); + if ($cwd === false) { $app->enqueueMessage(JText::_('INSTL_FTP_NOPWD'), 'error'); + return false; } + $cwd = rtrim($cwd, '/'); // Get a list of folders in the current working directory. $cwdFolders = $ftp->listDetails(null, 'folders'); + if ($cwdFolders === false || count($cwdFolders) == 0) { $app->enqueueMessage(JText::_('INSTL_FTP_NODIRECTORYLISTING'), 'error'); + return false; } @@ -79,6 +86,7 @@ public function detectFtpRoot($options) // Check to see if Joomla is installed at the FTP current working directory. $paths = array(); $known = array('administrator', 'components', 'installation', 'language', 'libraries', 'plugins'); + if (count(array_diff($known, $cwdFolders)) == 0) { $paths[] = $cwd . '/'; @@ -87,9 +95,11 @@ public function detectFtpRoot($options) // Search through the segments of JPATH_SITE looking for root possibilities. $parts = explode(DIRECTORY_SEPARATOR, JPATH_SITE); $tmp = ''; + for ($i = count($parts) - 1; $i >= 0; $i--) { $tmp = '/' . $parts[$i] . $tmp; + if (in_array($parts[$i], $cwdFolders)) { $paths[] = $cwd . $tmp; @@ -99,11 +109,13 @@ public function detectFtpRoot($options) // Check all possible paths for the real Joomla installation by comparing version files. $rootPath = false; $checkValue = file_get_contents(JPATH_LIBRARIES . '/cms/version/version.php'); + foreach ($paths as $tmp) { $filePath = rtrim($tmp, '/') . '/libraries/cms/version/version.php'; $buffer = null; @ $ftp->read($filePath, $buffer); + if ($buffer == $checkValue) { $rootPath = $tmp; @@ -118,6 +130,7 @@ public function detectFtpRoot($options) if ($rootPath === false) { $app->enqueueMessage(JText::_('INSTL_FTP_UNABLE_DETECT_ROOT_FOLDER'), 'error'); + return false; } @@ -135,7 +148,7 @@ public function detectFtpRoot($options) */ public function verifyFtpSettings($options) { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); @@ -149,12 +162,15 @@ public function verifyFtpSettings($options) if (!$ftp->isConnected()) { $app->enqueueMessage(JText::_('INSTL_FTP_NOCONNECT'), 'error'); + return false; } + if (!$ftp->login($options->get('ftp_user'), $options->get('ftp_pass'))) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOLOGIN'), 'error'); + return false; } @@ -162,106 +178,122 @@ public function verifyFtpSettings($options) // we want to test with the same value as well. $root = rtrim($options->get('ftp_root'), '/'); - // Verify PWD function + // Verify PWD function. if ($ftp->pwd() === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOPWD'), 'error'); + return false; } - // Verify root path exists + // Verify root path exists. if (!$ftp->chdir($root)) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOROOT'), 'error'); + return false; } - // Verify NLST function + // Verify NLST function. if (($rootList = $ftp->listNames()) === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NONLST'), 'error'); + return false; } - // Verify LIST function + // Verify LIST function. if ($ftp->listDetails() === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOLIST'), 'error'); + return false; } - // Verify SYST function + // Verify SYST function. if ($ftp->syst() === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOSYST'), 'error'); + return false; } - // Verify valid root path, part one + // Verify valid root path, part one. $checkList = array('robots.txt', 'index.php'); + if (count(array_diff($checkList, $rootList))) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_INVALIDROOT'), 'error'); + return false; } // Verify RETR function $buffer = null; + if ($ftp->read($root . '/libraries/cms/version/version.php', $buffer) === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NORETR'), 'error'); + return false; } - // Verify valid root path, part two + // Verify valid root path, part two. $checkValue = file_get_contents(JPATH_ROOT . '/libraries/cms/version/version.php'); + if ($buffer !== $checkValue) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_INVALIDROOT'), 'error'); + return false; } - // Verify STOR function + // Verify STOR function. if ($ftp->create($root . '/ftp_testfile') === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOSTOR'), 'error'); + return false; } - // Verify DELE function + // Verify DELE function. if ($ftp->delete($root . '/ftp_testfile') === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NODELE'), 'error'); + return false; } - // Verify MKD function + // Verify MKD function. if ($ftp->mkdir($root . '/ftp_testdir') === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NOMKD'), 'error'); + return false; } - // Verify RMD function + // Verify RMD function. if ($ftp->delete($root . '/ftp_testdir') === false) { $ftp->quit(); $app->enqueueMessage(JText::_('INSTL_FTP_NORMD'), 'error'); + return false; } $ftp->quit(); + return true; } } diff --git a/installation/model/languages.php b/installation/model/languages.php index 64fec19046577..c83c01cf2d4c5 100644 --- a/installation/model/languages.php +++ b/installation/model/languages.php @@ -22,31 +22,31 @@ class InstallationModelLanguages extends JModelBase { /** - * @var object Client object + * @var object Client object. * @since 3.1 */ protected $client = null; /** - * @var array Languages description + * @var array Languages description. * @since 3.1 */ protected $data = null; /** - * @var string Language path + * @var string Language path. * @since 3.1 */ protected $path = null; /** - * @var integer Total number of languages installed + * @var integer Total number of languages installed. * @since 3.1 */ protected $langlist = null; /** - * @var Admin Id, author of all generated content + * @var Admin Id, author of all generated content. * @since 3.1 */ protected $adminId = null; @@ -58,7 +58,7 @@ class InstallationModelLanguages extends JModelBase */ public function __construct() { - // Overrides application config and set the configuration.php file so tokens and database works + // Overrides application config and set the configuration.php file so tokens and database works. JFactory::$config = null; JFactory::getConfig(JPATH_SITE . '/configuration.php'); JFactory::$session = null; @@ -67,9 +67,9 @@ public function __construct() } /** - * Generate a list of language choices to install in the Joomla CMS + * Generate a list of language choices to install in the Joomla CMS. * - * @return boolean True if successful + * @return boolean True if successful. * * @since 3.1 */ @@ -79,14 +79,14 @@ public function getItems() /* * The following function uses extension_id 600, that is the English language extension id. - * In #__update_sites_extensions you should have 600 linked to the Accredited Translations Repo + * In #__update_sites_extensions you should have 600 linked to the Accredited Translations Repo. */ $updater->findUpdates(array(600), 0); $db = JFactory::getDbo(); $query = $db->getQuery(true); - // Select the required fields from the updates table + // Select the required fields from the updates table. $query->select('update_id, name, version') ->from('#__updates') ->order('name'); @@ -105,7 +105,7 @@ public function getItems() /** * Method that installs in Joomla! the selected languages in the Languages View of the installer. * - * @param array $lids List of the update_id value of the languages to install + * @param array $lids List of the update_id value of the languages to install. * * @return boolean True if successful */ @@ -115,51 +115,51 @@ public function install($lids) $app = JFactory::getApplication(); $installer = JInstaller::getInstance(); - // Loop through every selected language + // Loop through every selected language. foreach ($lids as $id) { - // Loads the update database object that represents the language + // Loads the update database object that represents the language. $language = JTable::getInstance('update'); $language->load($id); - // Get the url to the XML manifest file of the selected language + // Get the url to the XML manifest file of the selected language. $remote_manifest = $this->getLanguageManifest($id); if (!$remote_manifest) { - // Could not find the url, the information in the update server may be corrupt + // Could not find the url, the information in the update server may be corrupt. $message = JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name); $message .= ' ' . JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER'); $app->enqueueMessage($message); continue; } - // Based on the language XML manifest get the url of the package to download + // Based on the language XML manifest get the url of the package to download. $package_url = $this->getPackageUrl($remote_manifest); if (!$package_url) { - // Could not find the url , maybe the url is wrong in the update server, or there is not internet access + // Could not find the url , maybe the url is wrong in the update server, or there is not internet access. $message = JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name); $message .= ' ' . JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER'); $app->enqueueMessage($message); continue; } - // Download the package to the tmp folder + // Download the package to the tmp folder. $package = $this->downloadPackage($package_url); - // Install the package + // Install the package. if (!$installer->install($package['dir'])) { - // There was an error installing the package + // There was an error installing the package. $message = JText::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_INSTALL_LANGUAGE', $language->name); $message .= ' ' . JText::_('INSTL_DEFAULTLANGUAGE_TRY_LATER'); $app->enqueueMessage($message); continue; } - // Cleanup the install files in tmp folder + // Cleanup the install files in tmp folder. if (!is_file($package['packagefile'])) { $config = JFactory::getConfig(); @@ -168,7 +168,7 @@ public function install($lids) JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); - // Delete the installed language from the list + // Delete the installed language from the list. $language->delete($id); } @@ -178,7 +178,7 @@ public function install($lids) /** * Gets the manifest file of a selected language from a the language list in a update server. * - * @param integer $uid The id of the language in the #__updates table + * @param integer $uid The id of the language in the #__updates table. * * @return string * @@ -196,7 +196,7 @@ protected function getLanguageManifest($uid) /** * Finds the url of the package to download. * - * @param string $remote_manifest Url to the manifest XML file of the remote package + * @param string $remote_manifest Url to the manifest XML file of the remote package. * * @return string|bool * @@ -214,15 +214,15 @@ protected function getPackageUrl($remote_manifest) /** * Download a language package from a URL and unpack it in the tmp folder. * - * @param string $url Url of the package + * @param string $url Url of the package. * - * @return array|bool Package details or false on failure + * @return array|bool Package details or false on failure. * * @since 3.1 */ protected function downloadPackage($url) { - // Download the package from the given URL + // Download the package from the given URL. $p_file = JInstallerHelper::downloadPackage($url); // Was the package downloaded? @@ -236,14 +236,14 @@ protected function downloadPackage($url) $config = JFactory::getConfig(); $tmp_dest = $config->get('tmp_path'); - // Unpack the downloaded package file + // Unpack the downloaded package file. $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file); return $package; } /** - * Get Languages item data for the Administrator + * Get Languages item data for the Administrator. * * @return array * @@ -255,9 +255,9 @@ public function getInstalledlangsAdministrator() } /** - * Get Languages item data for the Frontend + * Get Languages item data for the Frontend. * - * @return array List of installed languages in the frontend application + * @return array List of installed languages in the frontend application. * * @since 3.1 */ @@ -267,9 +267,9 @@ public function getInstalledlangsFrontend() } /** - * Get Languages item data + * Get Languages item data. * - * @param string $cms_client Name of the cms client + * @param string $cms_client Name of the cms client. * * @return array * @@ -277,12 +277,12 @@ public function getInstalledlangsFrontend() */ protected function getInstalledlangs($cms_client = 'administrator') { - // Get information + // Get information. $path = $this->getPath(); $client = $this->getClient($cms_client); $langlist = $this->getLanguageList($client->id); - // Compute all the languages + // Compute all the languages. $data = array(); foreach ($langlist as $lang) @@ -302,7 +302,7 @@ protected function getInstalledlangs($cms_client = 'administrator') $row->$key = $value; } - // If current then set published + // If current then set published. $params = JComponentHelper::getParams('com_languages'); if ($params->get($client->name, 'en-GB') == $row->language) @@ -326,9 +326,9 @@ protected function getInstalledlangs($cms_client = 'administrator') /** * Get installed languages data. * - * @param integer $client_id The client ID to retrieve data for + * @param integer $client_id The client ID to retrieve data for. * - * @return object The language data + * @return object The language data. * * @since 3.1 */ @@ -356,8 +356,8 @@ protected function getLanguageList($client_id = 1) /** * Compare two languages in order to sort them. * - * @param object $lang1 The first language - * @param object $lang2 The second language + * @param object $lang1 The first language. + * @param object $lang2 The second language. * * @return integer * @@ -371,7 +371,7 @@ protected function compareLanguages($lang1, $lang2) /** * Get the languages folder path. * - * @return string The path to the languages folders + * @return string The path to the languages folders. * * @since 3.1 */ @@ -389,7 +389,7 @@ protected function getPath() /** * Get the client object of Administrator or Frontend. * - * @param string $client Name of the client object + * @param string $client Name of the client object. * * @return object * @@ -405,8 +405,8 @@ protected function getClient($client = 'administrator') /** * Set the default language. * - * @param string $language The language to be set as default - * @param string $cms_client The name of the CMS client + * @param string $language The language to be set as default. + * @param string $cms_client The name of the CMS client. * * @return boolean * @@ -414,7 +414,7 @@ protected function getClient($client = 'administrator') */ public function setDefault($language, $cms_client = 'administrator') { - // Get the application + // Get the application. /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); @@ -436,7 +436,7 @@ public function setDefault($language, $cms_client = 'administrator') $table->params = (string) $params; - // Pre-save checks + // Pre-save checks. if (!$table->check()) { $app->enqueueMessage($table->getError(), 'warning'); @@ -444,7 +444,7 @@ public function setDefault($language, $cms_client = 'administrator') return false; } - // Save the changes + // Save the changes. if (!$table->store()) { $app->enqueueMessage($table->getError(), 'warning'); @@ -473,7 +473,7 @@ public function getOptions() /** * Get the model form. * - * @param string $view The view being processed + * @param string $view The view being processed. * * @return mixed JForm object on success, false on failure. * @@ -518,9 +518,9 @@ public function getForm($view = null) } /** - * Enable a Joomla plugin + * Enable a Joomla plugin. * - * @param string $pluginName The name of plugin + * @param string $pluginName The name of plugin. * * @return boolean * @@ -546,7 +546,7 @@ public function enablePlugin($pluginName) return false; } - // Store language filter plugin parameters + // Store language filter plugin parameters. if ($pluginName == 'plg_system_languagefilter') { $params = '{' @@ -626,9 +626,9 @@ public function addModuleLanguageSwitcher() } /** - * Add a Module in Module menus + * Add a Module in Module menus. * - * @param integer $moduleId The Id of module + * @param integer $moduleId The Id of module. * * @return boolean * @@ -640,7 +640,7 @@ public function addModuleInModuleMenu($moduleId) $db = JFactory::getDbo(); $query = $db->getQuery(true); - // Add Module in Module menus + // Add Module in Module menus. $query->clear() ->insert('#__modules_menu') ->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid'))) @@ -660,15 +660,15 @@ public function addModuleInModuleMenu($moduleId) } /** - * Gets a unique language SEF string + * Gets a unique language SEF string. * * This function checks other existing language with the same code, if they exist provides a unique SEF name. * For instance: en-GB, en-US and en-AU will share the same SEF code by default: www.mywebsite.com/en/ * To avoid this conflict, this function creates an specific SEF in case of existing conflict: * For example: www.mywebsite.com/en-au/ * - * @param stdClass $itemLanguage Language Object - * @param stdClass[] $siteLanguages All Language Objects + * @param stdClass $itemLanguage Language Object. + * @param stdClass[] $siteLanguages All Language Objects. * * @return string * @@ -680,6 +680,7 @@ public function getSefString($itemLanguage, $siteLanguages) $prefixToFind = $langs[0]; $numberPrefixesFound = 0; + foreach ($siteLanguages as $siteLang) { $langs = explode('-', $siteLang->language); @@ -695,14 +696,15 @@ public function getSefString($itemLanguage, $siteLanguages) { return $prefixToFind; } + return strtolower($itemLanguage->language); } /** - * Add a Content Language + * Add a Content Language. * - * @param stdClass $itemLanguage Language Object - * @param string $sefLangString String to use for SEF so it doesn't conflict + * @param stdClass $itemLanguage Language Object. + * @param string $sefLangString String to use for SEF so it doesn't conflict. * * @return boolean * @@ -714,11 +716,11 @@ public function addLanguage($itemLanguage, $sefLangString) $flag = strtolower(str_replace('-', '_', $itemLanguage->language)); - // Load the native language name + // Load the native language name. $installationLocalisedIni = new JLanguage($itemLanguage->language, false); $nativeLanguageName = $installationLocalisedIni->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); - // If the local name do not exist in the translation file we use the international standard name + // If the local name do not exist in the translation file we use the international standard name. if ($nativeLanguageName == 'INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME') { $nativeLanguageName = $itemLanguage->name; @@ -763,9 +765,9 @@ public function addLanguage($itemLanguage, $sefLangString) } /** - * Add Menu Group + * Add Menu Group. * - * @param stdClass $itemLanguage Language Object + * @param stdClass $itemLanguage Language Object. * * @return boolean * @@ -773,11 +775,11 @@ public function addLanguage($itemLanguage, $sefLangString) */ public function addMenuGroup($itemLanguage) { - // Add menus + // Add menus. JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables/'); - // Add Menu Group + // Add Menu Group. $tableMenu = JTable::getInstance('Type', 'JTableMenu'); $menuData = array( @@ -811,7 +813,7 @@ public function addMenuGroup($itemLanguage) /** * Add Menu Item. * - * @param stdClass $itemLanguage Language Object + * @param stdClass $itemLanguage Language Object. * * @return boolean * @@ -819,7 +821,7 @@ public function addMenuGroup($itemLanguage) */ public function addMenuItem($itemLanguage) { - // Add Menu Item + // Add Menu Item. $tableItem = JTable::getInstance('Menu', 'MenusTable'); $newlanguage = new JLanguage($itemLanguage->language, false); @@ -882,9 +884,9 @@ public function addMenuItem($itemLanguage) } /** - * Add Module Menu + * Add Module Menu. * - * @param stdClass $itemLanguage Language Object + * @param stdClass $itemLanguage Language Object. * * @return boolean * @@ -934,7 +936,7 @@ public function addModuleMenu($itemLanguage) } /** - * Disable Default Main Menu Module + * Disable Default Main Menu Module. * * @return boolean * @@ -946,7 +948,7 @@ public function disableModuleMainMenu() $db = JFactory::getDbo(); $query = $db->getQuery(true); - // Add Module in Module menus + // Add Module in Module menus. $query ->clear() ->update($db->quoteName('#__modules')) @@ -966,9 +968,9 @@ public function disableModuleMainMenu() } /** - * Enable a module + * Enable a module. * - * @param string $moduleName The Name of the module to activate + * @param string $moduleName The Name of the module to activate. * * @return boolean * @@ -996,11 +998,11 @@ public function enableModule($moduleName) } /** - * Method create a category for a specific language + * Method create a category for a specific language. * - * @param stdClass $itemLanguage Language Object + * @param stdClass $itemLanguage Language Object. * - * @return JTable Category Object + * @return JTable Category Object. * * @since 3.2 */ @@ -1010,7 +1012,7 @@ public function addCategory($itemLanguage) $newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true); $title = $newlanguage->_('JCATEGORY'); - // Initialize a new category + // Initialize a new category. $category = JTable::getInstance('Category'); $category->extension = 'com_content'; $category->title = $title . ' (' . strtolower($itemLanguage->language) . ')'; @@ -1022,32 +1024,32 @@ public function addCategory($itemLanguage) $category->created_time = JFactory::getDate()->toSql(); $category->language = $itemLanguage->language; - // Set the location in the tree + // Set the location in the tree. $category->setLocation(1, 'last-child'); - // Check to make sure our data is valid + // Check to make sure our data is valid. if (!$category->check()) { return false; } - // Store the category + // Store the category. if (!$category->store(true)) { return false; } - // Build the path for our category + // Build the path for our category. $category->rebuildPath($category->id); return $category; } /** - * Create an article in a specific language + * Create an article in a specific language. * - * @param stdClass $itemLanguage Language Object - * @param int $categoryId The id of the category where we want to add the article + * @param stdClass $itemLanguage Language Object. + * @param int $categoryId The id of the category where we want to add the article. * * @return JTable Category Object * @@ -1083,19 +1085,19 @@ public function addArticle($itemLanguage, $categoryId) $article->language = $itemLanguage->language; $article->featured = 1; - // Check to make sure our data is valid + // Check to make sure our data is valid. if (!$article->check()) { return false; } - // Now store the category + // Now store the category. if (!$article->store(true)) { return false; } - // Get the new item ID + // Get the new item ID. $newId = $article->get('id'); $query = $db->getQuery(true) @@ -1115,7 +1117,7 @@ public function addArticle($itemLanguage, $categoryId) /** * Retrieve the admin user id. * - * @return int|bool One Administrator ID + * @return int|bool One Administrator ID. * * @since 3.2 */ @@ -1123,14 +1125,14 @@ private function getAdminId() { if ($this->adminId) { - // Return local cached admin ID + // Return local cached admin ID. return $this->adminId; } $db = JFactory::getDbo(); $query = $db->getQuery(true); - // Select the required fields from the updates table + // Select the required fields from the updates table. $query ->clear() ->select('u.id') diff --git a/installation/model/setup.php b/installation/model/setup.php index fd315b581883c..4ce4a088aa558 100644 --- a/installation/model/setup.php +++ b/installation/model/setup.php @@ -21,7 +21,7 @@ class InstallationModelSetup extends JModelBase /** * Get the current setup options from the session. * - * @return array An array of options from the session + * @return array An array of options from the session. * * @since 3.1 */ @@ -36,9 +36,9 @@ public function getOptions() /** * Store the current setup options in the session. * - * @param array $options The installation options + * @param array $options The installation options. * - * @return array An array of options from the session + * @return array An array of options from the session. * * @since 3.1 */ @@ -66,7 +66,7 @@ public function storeOptions($options) /** * Method to get the form. * - * @param string $view The view being processed + * @param string $view The view being processed. * * @return mixed JForm object on success, false on failure. * @@ -94,6 +94,7 @@ public function getForm($view = null) catch (Exception $e) { $app->enqueueMessage($e->getMessage(), 'error'); + return false; } @@ -110,11 +111,11 @@ public function getForm($view = null) } /** - * Method to check the form data + * Method to check the form data. * - * @param string $page The view being checked + * @param string $page The view being checked. * - * @return array Validated form data + * @return array Validated form data. * * @since 3.1 */ @@ -128,7 +129,7 @@ public function checkForm($page = 'site') $data = $app->input->post->get('jform', array(), 'array'); $return = $this->validate($data, $page); - // Attempt to save the data before validation + // Attempt to save the data before validation. $form = $this->getForm(); $data = $form->filter($data); unset($data['admin_password2']); @@ -152,9 +153,9 @@ public function checkForm($page = 'site') } /** - * Generate a panel of language choices for the user to select their language + * Generate a panel of language choices for the user to select their language. * - * @return boolean True if successful + * @return boolean True if successful. * * @since 3.1 */ @@ -193,7 +194,7 @@ public function getLanguages() /** * Checks the availability of the parse_ini_file and parse_ini_string functions. * - * @return boolean True if the method exists + * @return boolean True if the method exists. * * @since 3.1 */ @@ -203,7 +204,7 @@ public function getIniParserAvailability() if (!empty($disabled_functions)) { - // Attempt to detect them in the disable_functions black list + // Attempt to detect them in the disable_functions black list. $disabled_functions = explode(',', trim($disabled_functions)); $number_of_disabled_functions = count($disabled_functions); @@ -297,14 +298,14 @@ public function getPhpOptions() $options[] = $option; } - // Check for a missing native parse_ini_file implementation + // Check for a missing native parse_ini_file implementation. $option = new stdClass; $option->label = JText::_('INSTL_PARSE_INI_FILE_AVAILABLE'); $option->state = $this->getIniParserAvailability(); $option->notice = null; $options[] = $option; - // Check for missing native json_encode / json_decode support + // Check for missing native json_encode / json_decode support. $option = new stdClass; $option->label = JText::_('INSTL_JSON_SUPPORT_AVAILABLE'); $option->state = function_exists('json_encode') && function_exists('json_decode'); @@ -325,9 +326,9 @@ public function getPhpOptions() } /** - * Checks if all of the mandatory PHP options are met + * Checks if all of the mandatory PHP options are met. * - * @return boolean True on success + * @return boolean True on success. * * @since 3.1 */ @@ -400,7 +401,7 @@ public function getPhpSettings() $setting->recommended = false; $settings[] = $setting; - // Check for native ZIP support + // Check for native ZIP support. $setting = new stdClass; $setting->label = JText::_('INSTL_ZIP_SUPPORT_AVAILABLE'); $setting->state = function_exists('zip_open') && function_exists('zip_read'); @@ -442,6 +443,7 @@ public function validate($data, $view = null) if ($return instanceof Exception) { $app->enqueueMessage($return->getMessage(), 'warning'); + return false; } diff --git a/installation/view/preinstall/html.php b/installation/view/preinstall/html.php index 6dec48734202b..0aacd6a0dbdaf 100644 --- a/installation/view/preinstall/html.php +++ b/installation/view/preinstall/html.php @@ -19,17 +19,17 @@ class InstallationViewPreinstallHtml extends InstallationViewDefault { /** - * Array of PHP config options - * - * @var array + * Array of PHP config options. + * + * @var array * @since 3.1 */ protected $options; /** * Array of PHP settings - * - * @var array + * + * @var array * @since 3.1 */ protected $settings;