X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSystem%2FJoomla.php;h=ad04fd5206ffff499cb5db8987664242544c18eb;hb=fa2afd74506815d24940f93f47d748c016fc3224;hp=ffe0b4d1c717733759cb655a4ad358075dd0d676;hpb=0db6c3e15a8324d7f2d73c43c9b219a829351157;p=civicrm-core.git diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index ffe0b4d1c7..ad04fd5206 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -38,7 +38,6 @@ */ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** - * */ public function __construct() { /** @@ -54,20 +53,19 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * Create a user of Joomla. * * @param array $params - * Associated array. * @param string $mail * Email id for cms user. * - * @return uid if user exists, false otherwise - * + * @return int|bool + * uid if user exists, false otherwise */ public function createUser(&$params, $mail) { $baseDir = JPATH_SITE; require_once $baseDir . '/components/com_users/models/registration.php'; $userParams = JComponentHelper::getParams('com_users'); - $model = new UsersModelRegistration(); - $ufID = NULL; + $model = new UsersModelRegistration(); + $ufID = NULL; // get the default usertype $userType = $userParams->get('new_usertype'); @@ -86,11 +84,11 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } // Prepare the values for a new Joomla user. - $values = array(); - $values['name'] = $fullname; - $values['username'] = trim($params['cms_name']); + $values = array(); + $values['name'] = $fullname; + $values['username'] = trim($params['cms_name']); $values['password1'] = $values['password2'] = $params['cms_pass']; - $values['email1'] = $values['email2'] = trim($params[$mail]); + $values['email1'] = $values['email2'] = trim($params[$mail]); $lang = JFactory::getLanguage(); $lang->load('com_users', $baseDir); @@ -135,8 +133,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') { $config = CRM_Core_Config::singleton(); - $dao = new CRM_Core_DAO(); - $name = $dao->escape(CRM_Utils_Array::value('name', $params)); + $dao = new CRM_Core_DAO(); + $name = $dao->escape(CRM_Utils_Array::value('name', $params)); $email = $dao->escape(CRM_Utils_Array::value('mail', $params)); //don't allow the special characters and min. username length is two //regex \\ to match a single backslash would become '/\\\\/' @@ -264,14 +262,15 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Add a script file * - * @param $url: string, absolute path to file - * @param $region - * String, location within the document: 'html-header', 'page-header', 'page-footer'. + * @param $url : string, absolute path to file + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. * * Note: This function is not to be called directly * @see CRM_Core_Region::render() * - * @return bool TRUE if we support this operation in this CMS, FALSE otherwise + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise */ public function addScriptUrl($url, $region) { return FALSE; @@ -280,14 +279,15 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Add an inline script * - * @param $code: string, javascript code - * @param $region - * String, location within the document: 'html-header', 'page-header', 'page-footer'. + * @param $code : string, javascript code + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. * * Note: This function is not to be called directly * @see CRM_Core_Region::render() * - * @return bool TRUE if we support this operation in this CMS, FALSE otherwise + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise */ public function addScript($code, $region) { return FALSE; @@ -296,14 +296,15 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Add a css file * - * @param $url: string, absolute path to file - * @param $region - * String, location within the document: 'html-header', 'page-header', 'page-footer'. + * @param $url : string, absolute path to file + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. * * Note: This function is not to be called directly * @see CRM_Core_Region::render() * - * @return bool TRUE if we support this operation in this CMS, FALSE otherwise + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise */ public function addStyleUrl($url, $region) { if ($region == 'html-header') { @@ -317,14 +318,15 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Add an inline style * - * @param $code: string, css code - * @param $region - * String, location within the document: 'html-header', 'page-header', 'page-footer'. + * @param $code : string, css code + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. * * Note: This function is not to be called directly * @see CRM_Core_Region::render() * - * @return bool TRUE if we support this operation in this CMS, FALSE otherwise + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise */ public function addStyle($code, $region) { if ($region == 'html-header') { @@ -338,35 +340,36 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Generate an internal CiviCRM URL * - * @param $path - * String The path being linked to, such as "civicrm/add". - * @param $query - * String A query string to append to the link. - * @param $absolute - * Boolean Whether to force the output to be an absolute link (beginning with http:). + * @param string $path + * The path being linked to, such as "civicrm/add". + * @param string $query + * A query string to append to the link. + * @param bool $absolute + * Whether to force the output to be an absolute link (beginning with http:). * Useful for links that will be displayed outside the site, such as in an * RSS feed. - * @param $fragment - * String A fragment identifier (named anchor) to append to the link. - * @param $htmlize - * Boolean whether to convert to html eqivalant. - * @param $frontend - * Boolean a gross joomla hack. + * @param string $fragment + * A fragment identifier (named anchor) to append to the link. + * @param bool $htmlize + * whether to convert to html eqivalant. + * @param bool $frontend + * a gross joomla hack. * * @param bool $forceBackend * - * @return string an HTML string containing a link to the given path. + * @return string + * an HTML string containing a link to the given path. */ function url( $path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE ) { - $config = CRM_Core_Config::singleton(); + $config = CRM_Core_Config::singleton(); $separator = $htmlize ? '&' : '&'; - $Itemid = ''; - $script = ''; - $path = CRM_Utils_String::stripPathChars($path); + $Itemid = ''; + $script = ''; + $path = CRM_Utils_String::stripPathChars($path); if ($config->userFrameworkFrontend) { $script = 'index.php'; @@ -434,7 +437,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * @param $action * The default action if one is pre-specified. * - * @return string the url to post the form + * @return string + * the url to post the form */ public function postURL($action) { if (!empty($action)) { @@ -468,12 +472,11 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * The user name. * @param string $password * The password for the above user name. - * @param $loadCMSBootstrap - * Boolean load cms bootstrap?. + * @param bool $loadCMSBootstrap + * load cms bootstrap?. * - * @return mixed false if no auth - * array( - contactID, ufID, unique string ) if success + * @return array|bool + * [contactID, ufID, uniqueString] if success else false if no auth */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE) { require_once 'DB.php'; @@ -512,7 +515,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); - if ( !defined('JVERSION') ) { + if (!defined('JVERSION')) { require $joomlaBase . '/libraries/cms/version/version.php'; $jversion = new JVersion; define('JVERSION', $jversion->getShortVersion()); @@ -523,8 +526,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $dbId = $row->id; $dbEmail = $row->email; - if ( version_compare(JVERSION, '2.5.18', 'lt') || - ( version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt') ) + if (version_compare(JVERSION, '2.5.18', 'lt') || + (version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt')) ) { // now check password if (strpos($dbPassword, ':') === FALSE) { @@ -541,11 +544,12 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } } else { - if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) { return FALSE; + if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) { + return FALSE; } //include additional files required by Joomla 3.2.1+ - if ( version_compare(JVERSION, '3.2.1', 'ge') ) { + if (version_compare(JVERSION, '3.2.1', 'ge')) { require_once $joomlaBase . '/libraries/cms/application/helper.php'; require_once $joomlaBase . '/libraries/cms/application/cms.php'; require_once $joomlaBase . '/libraries/cms/application/administrator.php'; @@ -568,11 +572,10 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * * @param array $data * Array with user specific data. - * */ public function setUserSession($data) { list($userID, $ufID) = $data; - $user = new JUser( $ufID ); + $user = new JUser($ufID); $session = JFactory::getSession(); $session->set('user', $user); @@ -584,7 +587,6 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * * @param string $message * The message to set. - * */ public function setMessage($message) { return; @@ -611,7 +613,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Get the locale set in the hosting CMS * - * @return string the used locale or null for none + * @return string + * the used locale or null for none */ public function getUFLocale() { if (defined('_JEXEC')) { @@ -638,10 +641,10 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Load joomla bootstrap * - * @param $params - * Array with uid or name and password. - * @param $loadUser - * Boolean load cms user?. + * @param array $params + * with uid or name and password. + * @param bool $loadUser + * load cms user?. * @param bool|\throw $throwError throw error on failure? * @param null $realPath * @param bool $loadDefines @@ -654,7 +657,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { // load BootStrap here if needed // We are a valid Joomla entry point. - if ( ! defined( '_JEXEC' ) && $loadDefines ) { + if (!defined('_JEXEC') && $loadDefines) { define('_JEXEC', 1); define('DS', DIRECTORY_SEPARATOR); define('JPATH_BASE', $joomlaBase . '/administrator'); @@ -670,13 +673,13 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { require $joomlaBase . '/configuration.php'; // Files may be in different places depending on Joomla version - if ( !defined('JVERSION') ) { + if (!defined('JVERSION')) { require $joomlaBase . '/libraries/cms/version/version.php'; $jversion = new JVersion; define('JVERSION', $jversion->getShortVersion()); } - if( version_compare(JVERSION, '3.0', 'lt') ) { + if (version_compare(JVERSION, '3.0', 'lt')) { require $joomlaBase . '/libraries/joomla/environment/uri.php'; require $joomlaBase . '/libraries/joomla/application/component/helper.php'; } @@ -697,7 +700,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Check is user logged in. * - * @return boolean true/false. + * @return boolean */ public function isUserLoggedIn() { $user = JFactory::getUser(); @@ -707,7 +710,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Get currently logged in user uf id. * - * @return int logged in user uf id. + * @return int + * logged in user uf id. */ public function getLoggedInUfID() { $user = JFactory::getUser(); @@ -717,17 +721,20 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Get currently logged in user unique identifier - this tends to be the email address or user name. * - * @return string $userID logged in user unique identifier + * @return string + * logged in user unique identifier */ public function getLoggedInUniqueIdentifier() { $user = JFactory::getUser(); return $this->getUniqueIdentifierFromUserObject($user); } + /** * Get User ID from UserFramework system (Joomla) * @param object $user * Object as described by the CMS. - * @return mixed + * @return mixed + * */ public function getUserIDFromUserObject($user) { return !empty($user->id) ? $user->id : NULL; @@ -737,8 +744,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * Get Unique Identifier from UserFramework system (CMS) * @param object $user * Object as described by the User Framework. - * @return mixed $uniqueIdentifer Unique identifier from the user Framework system - * + * @return mixed + * $uniqueIdentifer Unique identifier from the user Framework system */ public function getUniqueIdentifierFromUserObject($user) { return ($user->guest) ? NULL : $user->email; @@ -747,7 +754,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { /** * Get a list of all installed modules, including enabled and disabled ones * - * @return array CRM_Core_Module + * @return array + * CRM_Core_Module */ public function getModules() { $result = array(); @@ -773,7 +781,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * @param string $destination * If present, add destination to querystring (works for Drupal only). * - * @return string - loginURL for the current CMS + * @return string + * loginURL for the current CMS * @static */ public function getLoginURL($destination = '') { @@ -783,8 +792,8 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $loginURL .= 'index.php?option=com_users&view=login'; //CRM-14872 append destination - if ( !empty($destination) ) { - $loginURL .= '&return='.urlencode(base64_encode($destination)); + if (!empty($destination)) { + $loginURL .= '&return=' . urlencode(base64_encode($destination)); } return $loginURL; } @@ -817,7 +826,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $destination = NULL; if ($args) { // append destination so user is returned to form they came from after login - $args = 'reset=1'.$args; + $args = 'reset=1' . $args; $destination = CRM_Utils_System::url(CRM_Utils_System::currentPath(), $args, TRUE, NULL, TRUE, TRUE); } @@ -829,12 +838,13 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * * @param $dir * - * @return array array + * @return array + * array * - $url, (Joomla - non admin url) * - $siteName, * - $siteRoot */ - public function getDefaultSiteSettings($dir){ + public function getDefaultSiteSettings($dir) { $config = CRM_Core_Config::singleton(); $url = preg_replace( '|/administrator|', @@ -887,7 +897,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $error = new Exception($content); JErrorPage::render($error); } - else if (class_exists('JError')) { + elseif (class_exists('JError')) { JError::raiseError('CiviCRM-001', $content); } else {