X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSystem%2FJoomla.php;h=fcbf34b7ca2f604840e198e75d768c4ad9e28ca3;hb=ebc28bab96eebf7b53f735f8f89019046c793609;hp=d644e1bbbc89d48ba24f5ae95c7c082e23d3557f;hpb=cb0e36deaf4a8f98cc5863439374812d1a6e2cd2;p=civicrm-core.git diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index d644e1bbbc..fcbf34b7ca 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -1,7 +1,7 @@ addScript($url); - return TRUE; - } return FALSE; } @@ -282,11 +277,6 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * @access public */ public function addScript($code, $region) { - if ($region == 'html-header') { - $document = JFactory::getDocument(); - $document->addScriptDeclaration($code); - return TRUE; - } return FALSE; } @@ -466,6 +456,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { require_once 'DB.php'; $config = CRM_Core_Config::singleton(); + $user = NULL; if ($loadCMSBootstrap) { $bootStrapParams = array(); @@ -481,41 +472,77 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { jimport('joomla.application.component.helper'); jimport('joomla.database.table'); - $JUserTable = &JTable::getInstance('User', 'JTable'); + if ( !defined('JVERSION') ) { + $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); + require $joomlaBase . '/libraries/cms/version/version.php'; + $jversion = new JVersion; + define('JVERSION', $jversion->getShortVersion()); + } - $db = $JUserTable->getDbo(); - $query = $db->getQuery(TRUE); - $query->select('id, username, email, password'); - $query->from($JUserTable->getTableName()); - $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)'); - $db->setQuery($query, 0, 0); - $users = $db->loadAssocList(); + if ( version_compare(JVERSION, '2.5.18', 'lt') || + ( version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.2', 'lt') ) + ) { + //old method for authenticating + $JUserTable = JTable::getInstance('User', 'JTable'); + + $db = $JUserTable->getDbo(); + $query = $db->getQuery(TRUE); + $query->select('id, username, email, password'); + $query->from($JUserTable->getTableName()); + $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)'); + $db->setQuery($query, 0, 0); + $users = $db->loadAssocList(); + + $row = array();; + if (count($users)) { + $row = $users[0]; + } - $row = array();; - if (count($users)) { - $row = $users[0]; - } + if (!empty($row)) { + $dbPassword = CRM_Utils_Array::value('password', $row); + $dbId = CRM_Utils_Array::value('id', $row); + $dbEmail = CRM_Utils_Array::value('email', $row); - $user = NULL; - if (!empty($row)) { - $dbPassword = CRM_Utils_Array::value('password', $row); - $dbId = CRM_Utils_Array::value('id', $row); - $dbEmail = CRM_Utils_Array::value('email', $row); - - // now check password - if (strpos($dbPassword, ':') === FALSE) { - if ($dbPassword != md5($password)) { - return FALSE; + // now check password + if (strpos($dbPassword, ':') === FALSE) { + if ($dbPassword != md5($password)) { + return FALSE; + } + } + else { + list($hash, $salt) = explode(':', $dbPassword); + $cryptpass = md5($password . $salt); + if ($hash != $cryptpass) { + return FALSE; + } } } - else { - list($hash, $salt) = explode(':', $dbPassword); - $cryptpass = md5($password . $salt); - if ($hash != $cryptpass) { - return FALSE; + } + else { + //new authentication method (J2.5.18/3.2.2 and greater) + // Get a database object + $db = JFactory::getDbo(); + $query = $db->getQuery(TRUE); + + $query->select('id, password'); + $query->from('#__users'); + $query->where('username='.$db->quote($name)); + + $db->setQuery( $query ); + $result = $db->loadObject(); + + if ($result) { + $match = JUserHelper::verifyPassword($password, $result->password, $result->id); + + if ($match === TRUE) { + $jUser = JUser::getInstance($result->id); // Bring this in line with the rest of the system + $dbId = $row['id'] = $result->id; + $dbEmail = $row['email'] = $jUser->email; } } + } + if (!empty($row)) { CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $dbId, $dbEmail, 'Joomla'); $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId); if (!$contactID) { @@ -536,7 +563,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { function setUserSession($data) { list($userID, $ufID) = $data; $user = new JUser( $ufID ); - $session = &JFactory::getSession(); + $session = JFactory::getSession(); $session->set('user', $user); parent::setUserSession($data); @@ -574,7 +601,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { function getUFLocale() { if (defined('_JEXEC')) { $conf = JFactory::getConfig(); - $locale = $conf->getValue('config.language'); + $locale = $conf->get('language'); return str_replace('-', '_', $locale); } return NULL; @@ -597,7 +624,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * @param $loadUser boolean load cms user? * @param $throwError throw error on failure? */ - function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $loadDefines = TRUE) { + function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE) { // Setup the base path related constant. $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); @@ -611,12 +638,28 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } // Get the framework. + if (file_exists($joomlaBase . '/libraries/import.legacy.php')) { + require $joomlaBase . '/libraries/import.legacy.php'; + } require $joomlaBase . '/libraries/import.php'; require $joomlaBase . '/libraries/joomla/event/dispatcher.php'; - require $joomlaBase . '/libraries/joomla/environment/uri.php'; - require $joomlaBase . '/libraries/joomla/application/component/helper.php'; require $joomlaBase . '/configuration.php'; + // Files may be in different places depending on Joomla version + if ( !defined('JVERSION') ) { + require $joomlaBase . '/libraries/cms/version/version.php'; + $jversion = new JVersion; + define('JVERSION', $jversion->getShortVersion()); + } + + if( version_compare(JVERSION, '3.0', 'lt') ) { + require $joomlaBase . '/libraries/joomla/environment/uri.php'; + require $joomlaBase . '/libraries/joomla/application/component/helper.php'; + } + else { + require $joomlaBase . '/libraries/joomla/uri/uri.php'; + } + jimport('joomla.application.cli'); return TRUE; @@ -680,9 +723,31 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $loginURL .= 'index.php?option=com_users&view=login'; return $loginURL; } - + public function getLoginDestination(&$form) { return; } + + /** + * Return default Site Settings + * @return array array + * - $url, (Joomla - non admin url) + * - $siteName, + * - $siteRoot + */ + function getDefaultSiteSettings($dir){ + $config = CRM_Core_Config::singleton(); + $url = preg_replace( + '|/administrator|', + '', + $config->userFrameworkBaseURL + ); + $siteRoot = preg_replace( + '|/media/civicrm/.*$|', + '', + $config->imageUploadDir + ); + return array($url, NULL, $siteRoot); + } }