From 17f443df7d2235655cbbfe68bfcf7a13a570b606 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 1 Feb 2015 17:24:01 -0500 Subject: [PATCH] CRM-15903 - Cleanup class inheritance of CRM_Utils_System_* functions ---------------------------------------- * CRM-15903: Restructure UF classes so that CRM_Utils_System_UnitTests does not extend Drupal https://issues.civicrm.org/jira/browse/CRM-15903 --- CRM/Utils/System/Base.php | 310 ++++++++++++++++++++++++++++++-- CRM/Utils/System/Drupal.php | 270 +++------------------------- CRM/Utils/System/Drupal6.php | 259 ++------------------------ CRM/Utils/System/Drupal8.php | 214 ++++------------------ CRM/Utils/System/DrupalBase.php | 148 +++++++-------- CRM/Utils/System/Joomla.php | 259 +++++--------------------- CRM/Utils/System/Soap.php | 86 +-------- CRM/Utils/System/UnitTests.php | 2 +- CRM/Utils/System/WordPress.php | 274 +++++----------------------- 9 files changed, 518 insertions(+), 1304 deletions(-) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 4e994800c9..6c32fcfac7 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -47,6 +47,162 @@ abstract class CRM_Utils_System_Base { */ var $supports_form_extensions = FALSE; + /** + * Append an additional breadcrumb tag to the existing breadcrumb + * + * @param array $breadCrumbs + */ + public function appendBreadCrumb($breadCrumbs) { + } + + /** + * Reset an additional breadcrumb tag to the existing breadcrumb + */ + public function resetBreadCrumb() { + } + + /** + * Append a string to the head of the html file + * + * @param string $head + * The new string to be appended. + */ + public function addHTMLHead($head) { + } + + /** + * Rewrite various system urls to https + */ + public function mapConfigToSSL() { + // dont need to do anything, let CMS handle their own switch to SSL + } + + /** + * Figure out the post url for QuickForm + * + * @param string $action + * The default url if one is pre-specified. + * + * @return string + * The url to post the form. + */ + public function postURL($action) { + $config = CRM_Core_Config::singleton(); + if (!empty($action)) { + return $action; + } + + return $this->url(CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET), + NULL, TRUE, NULL, FALSE + ); + } + + /** + * Generate the url string to a CiviCRM path. + * + * @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 string $fragment + * A fragment identifier (named anchor) to append to the link. + * @param bool $htmlize + * Whether to encode special html characters such as &. + * @param bool $frontend + * This link should be to the CMS front end (applies to WP & Joomla). + * @param bool $forceBackend + * This link should be to the CMS back end (applies to WP & Joomla). + * + * @return string + */ + public function url( + $path = NULL, + $query = NULL, + $absolute = FALSE, + $fragment = NULL, + $htmlize = TRUE, + $frontend = FALSE, + $forceBackend = FALSE + ) { + return NULL; + } + + /** + * Authenticate the user against the CMS db + * + * @param string $name + * The user name. + * @param string $password + * The password for the above user. + * @param bool $loadCMSBootstrap + * Load cms bootstrap?. + * @param string $realPath + * Filename of script + * + * @return array|bool + * [contactID, ufID, unique string] else false if no auth + */ + public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { + return FALSE; + } + + /** + * Set a message in the CMS to display to a user + * + * @param string $message + * The message to set. + */ + public function setMessage($message) { + } + + /** + * Load user into session + * + * @param $user + * + * @return bool + */ + public function loadUser($user) { + return TRUE; + } + + /** + * Immediately stop script execution and display a 401 "Access Denied" page + */ + public function permissionDenied() { + CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + } + + /** + * Immediately stop script execution, log out the user and redirect to the home page + * + * @deprecated + * This function should be removed in favor of linking to the CMS's logout page + */ + public function logout() { + } + + /** + * Clear CMS caches related to the user registration/profile forms. + * Used when updating/embedding profiles on CMS user forms. + * @see CRM-3600 + */ + public function updateCategories() { + } + + /** + * Get the locale set in the CMS + * + * @return string|null + * Locale or null for none + */ + public function getUFLocale() { + return NULL; + } + /** * If we are using a theming system, invoke theme, else just print the * content @@ -126,6 +282,8 @@ abstract class CRM_Utils_System_Base { } /** + * Get CMS Version + * * @return string */ public function getVersion() { @@ -160,6 +318,40 @@ abstract class CRM_Utils_System_Base { return NULL; } + /** + * Create a user in the CMS. + * + * @param array $params + * @param string $mail + * Email id for cms user. + * + * @return int|bool + * uid if user exists, false otherwise + */ + public function createUser(&$params, $mail) { + return FALSE; + } + + /** + * Update a user's email address in the CMS. + * + * @param int $ufID + * User ID in CMS. + * @param string $email + * Primary contact email address. + */ + public function updateCMSName($ufID, $email) { + } + + /** + * Check if user is logged in to the CMS. + * + * @return bool + */ + public function isUserLoggedIn() { + return FALSE; + } + /** * Get user login URL for hosting CMS (method declared in each CMS system class) * @@ -171,13 +363,25 @@ abstract class CRM_Utils_System_Base { */ public abstract function getLoginURL($destination = ''); + /** + * Get the login destination string. When this is passed in the + * URL the user will be directed to it after filling in the CMS form + * + * @param CRM_Core_Form $form + * Form object representing the 'current' form - to which the user will be returned. + * @return string|NULL + * destination value for URL + */ + public function getLoginDestination(&$form) { + return NULL; + } + /** * Determine the native ID of the CMS user * * @param string $username * * @throws CRM_Core_Exception - * @return; */ public function getUfId($username) { $className = get_class($this); @@ -212,6 +416,85 @@ abstract class CRM_Utils_System_Base { // nullop by default } + /** + * Add a script file + * + * Note: This function is not to be called directly + * @see CRM_Core_Region::render() + * + * @param $url : string, absolute path to file + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. + * + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise + */ + public function addScriptUrl($url, $region) { + return FALSE; + } + + /** + * Add an inline script + * + * Note: This function is not to be called directly + * @see CRM_Core_Region::render() + * + * @param $code : string, javascript code + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. + * + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise + */ + public function addScript($code, $region) { + return FALSE; + } + + /** + * Add a css file + * + * Note: This function is not to be called directly + * @see CRM_Core_Region::render() + * + * @param $url : string, absolute path to file + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. + * + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise + */ + public function addStyleUrl($url, $region) { + return FALSE; + } + + /** + * Add an inline style + * + * Note: This function is not to be called directly + * @see CRM_Core_Region::render() + * + * @param $code : string, css code + * @param string $region + * location within the document: 'html-header', 'page-header', 'page-footer'. + * + * @return bool + * TRUE if we support this operation in this CMS, FALSE otherwise + */ + public function addStyle($code, $region) { + return FALSE; + } + + /** + * Sets the title of the page + * + * @param string $title + * Title to set in html header + * @param string|null $pageTitle + * Title to set in html body (if different) + */ + public function setTitle($title, $pageTitle = NULL) { + } + /** * Return default Site Settings * @@ -279,10 +562,9 @@ abstract class CRM_Utils_System_Base { } /** - * Over-ridable function to get timezone as a string eg. - * + * Get timezone as a string * @return string - * Time zone, e.g. 'America/Los_Angeles' + * Timezone string e.g. 'America/Los_Angeles' */ public function getTimeZoneString() { return date_default_timezone_get(); @@ -296,34 +578,37 @@ abstract class CRM_Utils_System_Base { * $uniqueIdentifer Unique identifier from the user Framework system */ public function getUniqueIdentifierFromUserObject($user) { + return NULL; } /** * Get User ID from UserFramework system (CMS) * @param object $user * Object as described by the User Framework. - * @return mixed - * + * @return null|int */ public function getUserIDFromUserObject($user) { + return NULL; } /** * Get currently logged in user uf id. * - * @return; - * $userID logged in user uf id. + * @return int|null + * logged in user uf id. */ public function getLoggedInUfID() { + return NULL; } /** * Get currently logged in user unique identifier - this tends to be the email address or user name. * - * @return; + * @return string|null * logged in user unique identifier */ public function getLoggedInUniqueIdentifier() { + return NULL; } /** @@ -367,7 +652,7 @@ abstract class CRM_Utils_System_Base { * @param int $contactID * Contact ID. * - * @return string + * @return string|null */ public function getUserRecordUrl($contactID) { return NULL; @@ -391,13 +676,16 @@ abstract class CRM_Utils_System_Base { /** * Log error to CMS + * + * $param string $message */ public function logger($message) { - } /** * Append to coreResourcesList + * + * @param array $list */ public function appendCoreResources(&$list) { } diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index c79ff64111..896ec65c7d 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -39,14 +39,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { /** - * Create a user in Drupal. - * - * @param array $params - * @param string $mail - * Email id for cms user. - * - * @return int|bool - * uid if user exists, false otherwise + * @inheritDoc */ public function createUser(&$params, $mail) { $form_state = form_state_defaults(); @@ -98,12 +91,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Change user name in host CMS - * - * @param int $ufID - * User ID in CMS - * @param string $ufName - * User name + * @inheritDoc */ public function updateCMSName($ufID, $ufName) { // CRM-5555 @@ -175,68 +163,15 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Get the drupal destination string. When this is passed in the - * URL the user will be directed to it after filling in the drupal form - * - * @param CRM_Core_Form $form - * Form object representing the 'current' form - to which the user will be returned. - * @return null|string - * destination value for URL - */ - public function getLoginDestination(&$form) { - $args = NULL; - - $id = $form->get('id'); - if ($id) { - $args .= "&id=$id"; - } - else { - $gid = $form->get('gid'); - if ($gid) { - $args .= "&gid=$gid"; - } - else { - // Setup Personal Campaign Page link uses pageId - $pageId = $form->get('pageId'); - if ($pageId) { - $component = $form->get('component'); - $args .= "&pageId=$pageId&component=$component&action=add"; - } - } - } - - $destination = NULL; - if ($args) { - // append destination so user is returned to form they came from after login - $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args; - } - return $destination; - } - - /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @return string - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { $query = $destination ? array('destination' => $destination) : array(); return url('user', array('query' => $query)); } - /** - * Sets the title of the page - * - * @param string $title - * @param null $pageTitle - * - * @paqram string $pageTitle - * - * @return void + * @inheritDoc */ public function setTitle($title, $pageTitle = NULL) { if (arg(0) == 'civicrm') { @@ -249,13 +184,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param array $breadCrumbs - * @internal param string $title - * @internal param string $url - * - * @return void + * @inheritDoc */ public function appendBreadCrumb($breadCrumbs) { $breadCrumb = drupal_get_breadcrumb(); @@ -280,9 +209,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Reset an additional breadcrumb tag to the existing breadcrumb - * - * @return void + * @inheritDoc */ public function resetBreadCrumb() { $bc = array(); @@ -290,12 +217,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Append a string to the head of the html file - * - * @param string $header - * The new string to be appended. - * - * @return void + * @inheritDoc */ public function addHTMLHead($header) { static $count = 0; @@ -310,17 +232,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Add a script file - * - * @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 + * @inheritDoc */ public function addScriptUrl($url, $region) { $params = array('group' => JS_LIBRARY, 'weight' => 10); @@ -340,17 +252,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Add an inline script - * - * @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 + * @inheritDoc */ public function addScript($code, $region) { $params = array('type' => 'inline', 'group' => JS_LIBRARY, 'weight' => 10); @@ -368,17 +270,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Add a css file - * - * @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 + * @inheritDoc */ public function addStyleUrl($url, $region) { if ($region != 'html-header') { @@ -392,17 +284,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Add an inline style - * - * @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 + * @inheritDoc */ public function addStyle($code, $region) { if ($region != 'html-header') { @@ -414,9 +296,7 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Rewrite various system urls to https - * - * @return void + * @inheritDoc */ public function mapConfigToSSL() { global $base_url; @@ -424,37 +304,9 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { } /** - * Figure out the post url for the form - * - * @param mix $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form - */ - public function postURL($action) { - if (!empty($action)) { - return $action; - } - - return $this->url($_GET['q']); - } - - - /** - * Authenticate the user against the drupal db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * @param bool $loadCMSBootstrap - * Load cms bootstrap?. - * @param NULL|string $realPath filename of script - * - * @return mixed false if no auth array(contactID, ufID, unique string ) if success + * @inheritDoc */ - public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { + public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { require_once 'DB.php'; $config = CRM_Core_Config::singleton(); @@ -526,11 +378,7 @@ AND u.status = 1 } /** - * Load user into session - * - * @param string $username - * - * @return bool + * @inheritDoc */ public function loadUser($username) { global $user; @@ -579,30 +427,13 @@ AND u.status = 1 } /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. - */ - public function setMessage($message) { - drupal_set_message($message); - } - - /** - * @return mixed + * @inheritDoc */ public function logout() { module_load_include('inc', 'user', 'user.pages'); return user_logout(); } - public function updateCategories() { - // copied this from profile.module. Seems a bit inefficient, but i dont know a better way - // CRM-3600 - cache_clear_all(); - menu_rebuild(); - } - /** * Get the default location for CiviCRM blocks * @@ -612,44 +443,6 @@ AND u.status = 1 return 'sidebar_first'; } - /** - * Get the locale set in the hosting CMS - * - * @return string - * with the locale or null for none - */ - public function getUFLocale() { - // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale - // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx - // sometimes for CLI based on order called, this might not be set and/or empty - global $language; - - if (empty($language)) { - return NULL; - } - - if ($language->language == 'zh-hans') { - return 'zh_CN'; - } - - if ($language->language == 'zh-hant') { - return 'zh_TW'; - } - - if (preg_match('/^.._..$/', $language->language)) { - return $language->language; - } - - return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); - } - - /** - * @return string - */ - public function getVersion() { - return defined('VERSION') ? VERSION : 'Unknown'; - } - /** * Load drupal bootstrap * @@ -808,9 +601,7 @@ AND u.status = 1 } /** - * Check is user logged in. - * - * @return bool + * @inheritDoc */ public function isUserLoggedIn() { $isloggedIn = FALSE; @@ -822,10 +613,7 @@ AND u.status = 1 } /** - * Get currently logged in user uf id. - * - * @return int - * $userID logged in user uf id. + * @inheritDoc */ public function getLoggedInUfID() { $ufID = NULL; @@ -840,15 +628,7 @@ AND u.status = 1 } /** - * Format the url as per language Negotiation. - * - * @param string $url - * - * @param bool $addLanguagePart - * @param bool $removeLanguagePart - * - * @return string - * , formatted url. + * @inheritDoc */ public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) { if (empty($url)) { @@ -992,9 +772,7 @@ AND u.status = 1 } /** - * Over-ridable function to get timezone as a string eg. - * @return string - * Timezone e.g. 'America/Los_Angeles' + * @inheritDoc */ public function getTimeZoneString() { global $user; @@ -1010,12 +788,4 @@ AND u.status = 1 return $timezone; } - /** - * Reset any system caches that may be required for proper CiviCRM - * integration. - */ - public function flush() { - drupal_flush_all_caches(); - } - } diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 78727b27ba..0d172847df 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -76,14 +76,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Create a user in Drupal. - * - * @param array $params - * @param string $mail - * Email id for cms user. - * - * @return int|bool - * uid if user exists, false otherwise + * @inheritDoc */ public function createUser(&$params, $mail) { $form_state = array(); @@ -122,10 +115,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Change user name in host CMS - * - * @param int $ufID User ID in CMS - * @param string $ufName User name + * @inheritDoc */ public function updateCMSName($ufID, $ufName) { // CRM-5555 @@ -213,53 +203,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Get the drupal destination string. When this is passed in the - * URL the user will be directed to it after filling in the drupal form - * - * @param CRM_Core_Form $form - * Form object representing the 'current' form - to which the user will be returned. - * @return string - * destination value for URL - */ - public function getLoginDestination(&$form) { - $args = NULL; - - $id = $form->get('id'); - if ($id) { - $args .= "&id=$id"; - } - else { - $gid = $form->get('gid'); - if ($gid) { - $args .= "&gid=$gid"; - } - else { - // Setup Personal Campaign Page link uses pageId - $pageId = $form->get('pageId'); - if ($pageId) { - $component = $form->get('component'); - $args .= "&pageId=$pageId&component=$component&action=add"; - } - } - } - - $destination = NULL; - if ($args) { - // append destination so user is returned to form they came from after login - $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args; - } - return $destination; - } - - /** - * Sets the title of the page - * - * @param string $title - * @param null $pageTitle - * - * @paqram string $pageTitle - * - * @return void + * @inheritDoc */ public function setTitle($title, $pageTitle = NULL) { if (!$pageTitle) { @@ -272,14 +216,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param $breadCrumbs - * - * @internal param string $title - * @internal param string $url - * - * @return void + * @inheritDoc */ public function appendBreadCrumb($breadCrumbs) { $breadCrumb = drupal_get_breadcrumb(); @@ -304,9 +241,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Reset an additional breadcrumb tag to the existing breadcrumb - * - * @return void + * @inheritDoc */ public function resetBreadCrumb() { $bc = array(); @@ -325,42 +260,6 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { drupal_set_html_head($head); } - /** - * Add a script file - * - * @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 - */ - public function addScriptUrl($url, $region) { - // CRM-15450 - D6 doesn't order internal/external links correctly so we can't use drupal_add_js - return FALSE; - } - - /** - * Add an inline script - * - * @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 - */ - public function addScript($code, $region) { - // CRM-15450 - ensure scripts are in correct order - return FALSE; - } - /** * Add a css file * @@ -383,24 +282,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Add an inline style - * - * @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 - */ - public function addStyle($code, $region) { - return FALSE; - } - - /** - * Rewrite various system urls to https + * @inheritDoc */ public function mapConfigToSSL() { global $base_url; @@ -408,35 +290,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Figure out the post url for the form - * - * @param mix $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form - */ - public function postURL($action) { - if (!empty($action)) { - return $action; - } - - return $this->url($_GET['q']); - } - - /** - * Authenticate the user against the drupal db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * @param bool $loadCMSBootstrap - * Load cms bootstrap?. - * @param NULL|string $realPath filename of script - * - * @return array|bool - * [contactID, ufID, uniqueString] if success else false if no auth + * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { //@todo this 'PEAR-y' stuff is only required when bookstrap is not being loaded which is rare @@ -488,7 +342,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Load user into session + * @inheritDoc */ public function loadUser($username) { global $user; @@ -535,68 +389,13 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. - */ - public function setMessage($message) { - drupal_set_message($message); - } - - /** - * @return mixed + * @inheritDoc */ public function logout() { module_load_include('inc', 'user', 'user.pages'); return user_logout(); } - public function updateCategories() { - // copied this from profile.module. Seems a bit inefficient, but i dont know a better way - // CRM-3600 - cache_clear_all(); - menu_rebuild(); - } - - /** - * Get the locale set in the hosting CMS - * - * @return string - * with the locale or null for none - */ - public function getUFLocale() { - // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale - // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx - // sometimes for CLI based on order called, this might not be set and/or empty - global $language; - - if (empty($language)) { - return NULL; - } - - if ($language->language == 'zh-hans') { - return 'zh_CN'; - } - - if ($language->language == 'zh-hant') { - return 'zh_TW'; - } - - if (preg_match('/^.._..$/', $language->language)) { - return $language->language; - } - - return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); - } - - /** - * @return string - */ - public function getVersion() { - return defined('VERSION') ? VERSION : 'Unknown'; - } - /** * Load drupal bootstrap * @@ -758,9 +557,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Check is user logged in. - * - * @return bool + * @inheritDoc */ public function isUserLoggedIn() { $isloggedIn = FALSE; @@ -772,10 +569,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Get currently logged in user uf id. - * - * @return int - * $userID logged in user uf id. + * @inheritDoc */ public function getLoggedInUfID() { $ufID = NULL; @@ -790,15 +584,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Format the url as per language Negotiation. - * - * @param string $url - * - * @param bool $addLanguagePart - * @param bool $removeLanguagePart - * - * @return string - * , formatted url. + * @inheritDoc */ public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) { if (empty($url)) { @@ -904,13 +690,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @return string - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { $config = CRM_Core_Config::singleton(); @@ -948,9 +728,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Over-ridable function to get timezone as a string eg. - * @return string - * Timezone e.g. 'America/Los_Angeles' + * @inheritDoc */ public function getTimeZoneString() { global $user; @@ -966,13 +744,4 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { return $timezone; } - - /** - * Reset any system caches that may be required for proper CiviCRM - * integration. - */ - public function flush() { - drupal_flush_all_caches(); - } - } diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index e4e1b0b7b8..a6794a2cdb 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -39,14 +39,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { /** - * Create a user in Drupal. - * - * @param array $params - * @param string $mail - * Email id for cms user. - * - * @return int|bool - * uid if user exists, false otherwise + * @inheritDoc */ public function createUser(&$params, $mail) { $user = \Drupal::currentUser(); @@ -113,12 +106,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Update the Drupal user's email address. - * - * @param int $ufID - * User ID in CMS. - * @param string $email - * Primary contact email address. + * @inheritDoc */ public function updateCMSName($ufID, $email) { $user = user_load($ufID); @@ -183,66 +171,15 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Get the drupal destination string. When this is passed in the - * URL the user will be directed to it after filling in the drupal form - * - * @param CRM_Core_Form $form - * Form object representing the 'current' form - to which the user will be returned. - * @return string - * destination value for URL - */ - public function getLoginDestination(&$form) { - $args = NULL; - - $id = $form->get('id'); - if ($id) { - $args .= "&id=$id"; - } - else { - $gid = $form->get('gid'); - if ($gid) { - $args .= "&gid=$gid"; - } - else { - // Setup Personal Campaign Page link uses pageId - $pageId = $form->get('pageId'); - if ($pageId) { - $component = $form->get('component'); - $args .= "&pageId=$pageId&component=$component&action=add"; - } - } - } - - $destination = NULL; - if ($args) { - // append destination so user is returned to form they came from after login - $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args; - } - return $destination; - } - - /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @return string - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { $query = $destination ? array('destination' => $destination) : array(); return \Drupal::url('user.page', array(), array('query' => $query)); } - /** - * Sets the title of the page - * - * @param string $title - * @param string $pageTitle - * - * @return void + * @inheritDoc */ public function setTitle($title, $pageTitle = NULL) { if (!$pageTitle) { @@ -253,14 +190,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param $breadcrumbs - * - * @internal param string $title - * @internal param string $url - * - * @return void + * @inheritDoc */ public function appendBreadCrumb($breadcrumbs) { $civicrmPageState = \Drupal::service('civicrm.page_state'); @@ -270,38 +200,21 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Reset an additional breadcrumb tag to the existing breadcrumb - * - * @return void + * @inheritDoc */ public function resetBreadCrumb() { \Drupal::service('civicrm.page_state')->resetBreadcrumbs(); } /** - * Append a string to the head of the html file - * - * @param string $header - * The new string to be appended. - * - * @return void + * @inheritDoc */ public function addHTMLHead($header) { \Drupal::service('civicrm.page_state')->addHtmlHeader($header); } /** - * Add a script file - * - * @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 + * @inheritDoc */ public function addScriptUrl($url, $region) { $options = array('group' => JS_LIBRARY, 'weight' => 10); @@ -321,17 +234,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Add an inline script - * - * @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 + * @inheritDoc */ public function addScript($code, $region) { $options = array('type' => 'inline', 'group' => JS_LIBRARY, 'weight' => 10); @@ -349,17 +252,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Add a css file - * - * @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 + * @inheritDoc */ public function addStyleUrl($url, $region) { if ($region != 'html-header') { @@ -373,17 +266,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Add an inline style - * - * @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 + * @inheritDoc */ public function addStyle($code, $region) { if ($region != 'html-header') { @@ -400,6 +283,9 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { * This seems to be a legacy function. We assume all resources are within the drupal * directory and always return TRUE. As well, we clean up the $url. * + * FIXME: This is not a legacy function and the above is not a safe assumption. + * External urls are allowed by CRM_Core_Resources and this needs to return the correct value. + * * @param $url * * @return bool @@ -412,39 +298,29 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { if (($pos = strpos($url, '?')) !== FALSE) { $url = substr($url, 0, $pos); } - + // FIXME: Should not unconditionally return true return TRUE; } /** - * Rewrite various system urls to https - * * This function does nothing in Drupal 8. Changes to the base_url should be made * in settings.php directly. - * - * @return void */ public function mapConfigToSSL() { } /** - * @param string $path - * The base path (eg. civicrm/search/contact). - * @param string $query - * The query string (eg. reset=1&cid=66) but html encoded(?) (optional). - * @param bool $absolute - * Produce an absolute including domain and protocol (optional). - * @param string $fragment - * A named anchor (optional). - * @param bool $htmlize - * Produce a html encoded url (optional). - * @param bool $frontend - * A joomla hack (unused). - * @param bool $forceBackend - * A joomla jack (unused). - * @return string + * @inheritDoc */ - public function url($path = '', $query = '', $absolute = FALSE, $fragment = '', $htmlize = FALSE, $frontend = FALSE, $forceBackend = FALSE) { + public function url( + $path = '', + $query = '', + $absolute = FALSE, + $fragment = NULL, + $htmlize = TRUE, + $frontend = FALSE, + $forceBackend = FALSE + ) { $query = html_entity_decode($query); $url = \Drupal\civicrm\CivicrmHelper::parseURL("{$path}?{$query}"); @@ -465,22 +341,8 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { return $url; } - /** - * Authenticate the user against the drupal db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * @param bool $loadCMSBootstrap - * Load cms bootstrap?. - * @param NULL|string $realPath filename of script - * - * @return array|bool - * [contactID, ufID, uniqueString] if success else false if no auth - * - * This always bootstraps Drupal + * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { (new CRM_Utils_System_Drupal8())->loadBootStrap(array(), FALSE); @@ -492,7 +354,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Load user into session + * @inheritDoc */ public function loadUser($username) { $user = user_load_by_name($username); @@ -526,15 +388,8 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. + * @inheritDoc */ - public function setMessage($message) { - drupal_set_message($message); - } - public function permissionDenied() { \Drupal::service('civicrm.page_state')->setAccessDenied(); } @@ -637,19 +492,14 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Check if user is logged in. - * - * @return bool + * @inheritDoc */ public function isUserLoggedIn() { return \Drupal::currentUser()->isAuthenticated(); } /** - * Get currently logged in user uf id. - * - * @return int - * $userID logged in user uf id. + * @inheritDoc */ public function getLoggedInUfID() { if ($id = \Drupal::currentUser()->id()) { @@ -658,9 +508,7 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } /** - * Get the default location for CiviCRM blocks - * - * @return string + * @inheritDoc */ public function getDefaultBlockLocation() { return 'sidebar_first'; diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 7b821545fe..bdf5e512d2 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -59,13 +59,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * @param string $dir base civicrm directory - * Return default Site Settings - * @return array - * array - * - $url, (Joomla - non admin url) - * - $siteName, - * - $siteRoot + * @inheritDoc */ public function getDefaultSiteSettings($dir) { $config = CRM_Core_Config::singleton(); @@ -146,30 +140,16 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { /** * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) * - * @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 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 - * a gross joomla hack. - * - * @return string - * an HTML string containing a link to the given path. + * @inheritDoc */ public function url( - $path = NULL, $query = NULL, $absolute = FALSE, - $fragment = NULL, $htmlize = TRUE, - $frontend = FALSE, $forceBackend = FALSE + $path = NULL, + $query = NULL, + $absolute = FALSE, + $fragment = NULL, + $htmlize = TRUE, + $frontend = FALSE, + $forceBackend = FALSE ) { $config = CRM_Core_Config::singleton(); $script = 'index.php'; @@ -227,32 +207,28 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Get User ID from UserFramework system (Drupal) - * @param object $user - * Object as described by the CMS. - * @return mixed - * + * @inheritDoc */ public function getUserIDFromUserObject($user) { return !empty($user->uid) ? $user->uid : NULL; } /** - * 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 + * @inheritDoc + */ + public function setMessage($message) { + drupal_set_message($message); + } + + /** + * @inheritDoc */ public function getUniqueIdentifierFromUserObject($user) { return empty($user->mail) ? NULL : $user->mail; } /** - * Get currently logged in user unique identifier - this tends to be the email address or user name. - * - * @return string - * logged in user unique identifier + * @inheritDoc */ public function getLoggedInUniqueIdentifier() { global $user; @@ -260,18 +236,14 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Action to take when access is not permitted + * @inheritDoc */ public function permissionDenied() { drupal_access_denied(); } /** - * Get Url to view user record - * @param int $contactID - * Contact ID. - * - * @return string + * @inheritDoc */ public function getUserRecordUrl($contactID) { $uid = CRM_Core_BAO_UFMatch::getUFId($contactID); @@ -286,18 +258,14 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Is the current user permitted to add a user - * @return bool + * @inheritDoc */ public function checkPermissionAddUser() { - if (CRM_Core_Permission::check('administer users')) { - return TRUE; - } + return CRM_Core_Permission::check('administer users'); } - /** - * Log error to CMS + * @inheritDoc */ public function logger($message) { if (CRM_Core_Config::singleton()->userFrameworkLogging) { @@ -306,22 +274,21 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Flush css/js caches + * @inheritDoc */ public function clearResourceCache() { _drupal_flush_css_js(); } /** - * Append to coreResourcesList + * Append Drupal js to coreResourcesList */ public function appendCoreResources(&$list) { $list[] = 'js/crm.drupal.js'; } /** - * Reset any system caches that may be required for proper CiviCRM - * integration. + * @inheritDoc */ public function flush() { drupal_flush_all_caches(); @@ -363,12 +330,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Format the url as per language Negotiation. - * - * @param string $url - * - * @return string - * , formatted url. + * @inheritDoc */ public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) { if (empty($url)) { @@ -427,27 +389,23 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * GET CMS Version - * @return string + * @inheritDoc */ public function getVersion() { return defined('VERSION') ? VERSION : 'Unknown'; } /** + * @inheritDoc */ public function updateCategories() { - // copied this from profile.module. Seems a bit inefficient, but i dont know a better way - // CRM-3600 + // copied this from profile.module. Seems a bit inefficient, but i don't know a better way cache_clear_all(); menu_rebuild(); } /** - * Get the locale set in the hosting CMS - * - * @return string - * with the locale or null for none + * @inheritDoc */ public function getUFLocale() { // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale @@ -488,13 +446,41 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Figure out the post url for the form - * - * @param mix $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form + * @inheritDoc + */ + public function getLoginDestination(&$form) { + $args = NULL; + + $id = $form->get('id'); + if ($id) { + $args .= "&id=$id"; + } + else { + $gid = $form->get('gid'); + if ($gid) { + $args .= "&gid=$gid"; + } + else { + // Setup Personal Campaign Page link uses pageId + $pageId = $form->get('pageId'); + if ($pageId) { + $component = $form->get('component'); + $args .= "&pageId=$pageId&component=$component&action=add"; + } + } + } + + $destination = NULL; + if ($args) { + // append destination so user is returned to form they came from after login + $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args; + } + return $destination; + } + + /** + * Fixme: Why are we overriding the parent function? Seems inconsistent. + * This version supplies slightly different params to $this->url (not absolute and html encoded) but why? */ public function postURL($action) { if (!empty($action)) { diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 19ce3ccced..a1272e8dd3 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -50,14 +50,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Create a user of Joomla. - * - * @param array $params - * @param string $mail - * Email id for cms user. - * - * @return int|bool - * uid if user exists, false otherwise + * @inheritDoc */ public function createUser(&$params, $mail) { $baseDir = JPATH_SITE; @@ -100,10 +93,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Change user name in host CMS - * - * @param int $ufID - * @param string $ufName User name + * @inheritDoc */ public function updateCMSName($ufID, $ufName) { $ufID = CRM_Utils_Type::escape($ufID, 'Integer'); @@ -176,13 +166,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Sets the title of the page - * - * @param string $title - * Title to set. - * @param string $pageTitle - * - * @return void + * @inheritDoc */ public function setTitle($title, $pageTitle = NULL) { if (!$pageTitle) { @@ -197,14 +181,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param $breadCrumbs - * - * @internal param string $title - * @internal param string $url - * - * @return void + * @inheritDoc */ public function appendBreadCrumb($breadCrumbs) { $template = CRM_Core_Smarty::singleton(); @@ -230,25 +207,15 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Reset an additional breadcrumb tag to the existing breadcrumb - * - * @internal param string $bc the new breadcrumb to be appended - * - * @return void + * @inheritDoc */ public function resetBreadCrumb() { } /** - * Append a string to the head of the html file - * - * @param null $string - * - * @internal param string $head the new string to be appended - * - * @return void + * @inheritDoc */ - public static function addHTMLHead($string = NULL) { + public function addHTMLHead($string = NULL) { if ($string) { $document = JFactory::getDocument(); $document->addCustomTag($string); @@ -256,51 +223,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Add a script file - * - * @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 - */ - public function addScriptUrl($url, $region) { - return FALSE; - } - - /** - * Add an inline script - * - * @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 - */ - public function addScript($code, $region) { - return FALSE; - } - - /** - * Add a css file - * - * @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 + * @inheritDoc */ public function addStyleUrl($url, $region) { if ($region == 'html-header') { @@ -312,17 +235,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Add an inline style - * - * @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 + * @inheritDoc */ public function addStyle($code, $region) { if ($region == 'html-header') { @@ -334,32 +247,16 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Generate an internal CiviCRM URL - * - * @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 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. + * @inheritDoc */ public function url( - $path = NULL, $query = NULL, $absolute = TRUE, - $fragment = NULL, $htmlize = TRUE, - $frontend = FALSE, $forceBackend = FALSE + $path = NULL, + $query = NULL, + $absolute = FALSE, + $fragment = NULL, + $htmlize = TRUE, + $frontend = FALSE, + $forceBackend = FALSE ) { $config = CRM_Core_Config::singleton(); $separator = $htmlize ? '&' : '&'; @@ -416,35 +313,6 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { return $url; } - /** - * Rewrite various system urls to https - * - * @return void - * access public - */ - public function mapConfigToSSL() { - // dont need to do anything, let CMS handle their own switch to SSL - } - - /** - * Figure out the post url for the form - * - * @param $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form - */ - public function postURL($action) { - if (!empty($action)) { - return $action; - } - - return $this->url(CRM_Utils_Array::value('task', $_GET), - NULL, TRUE, NULL, FALSE - ); - } - /** * Set the email address of the user * @@ -461,19 +329,9 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Authenticate the user against the joomla db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * @param bool $loadCMSBootstrap - * load cms bootstrap?. - * - * @return array|bool - * [contactID, ufID, uniqueString] if success else false if no auth + * @inheritDoc */ - public function authenticate($name, $password, $loadCMSBootstrap = FALSE) { + public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { require_once 'DB.php'; $config = CRM_Core_Config::singleton(); @@ -578,37 +436,35 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. + * FIXME: Do something */ public function setMessage($message) { } /** - * @param $user - * - * @return bool + * FIXME: Do something */ public function loadUser($user) { return TRUE; } + /** + * FIXME: Use CMS-native approach + */ public function permissionDenied() { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } + /** + * @inheritDoc + */ public function logout() { session_destroy(); header("Location:index.php"); } /** - * Get the locale set in the hosting CMS - * - * @return string - * the used locale or null for none + * @inheritDoc */ public function getUFLocale() { if (defined('_JEXEC')) { @@ -620,7 +476,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * @return string + * @inheritDoc */ public function getVersion() { if (class_exists('JVersion')) { @@ -692,9 +548,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Check is user logged in. - * - * @return bool + * @inheritDoc */ public function isUserLoggedIn() { $user = JFactory::getUser(); @@ -702,10 +556,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Get currently logged in user uf id. - * - * @return int - * logged in user uf id. + * @inheritDoc */ public function getLoggedInUfID() { $user = JFactory::getUser(); @@ -713,10 +564,7 @@ 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 - * logged in user unique identifier + * @inheritDoc */ public function getLoggedInUniqueIdentifier() { $user = JFactory::getUser(); @@ -724,22 +572,14 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Get User ID from UserFramework system (Joomla) - * @param object $user - * Object as described by the CMS. - * @return mixed - * + * @inheritDoc */ public function getUserIDFromUserObject($user) { return !empty($user->id) ? $user->id : NULL; } /** - * 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 + * @inheritDoc */ public function getUniqueIdentifierFromUserObject($user) { return ($user->guest) ? NULL : $user->email; @@ -770,13 +610,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @return string - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { $config = CRM_Core_Config::singleton(); @@ -792,7 +626,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * @param CRM_Core_Form $form + * @inheritDoc */ public function getLoginDestination(&$form) { $args = NULL; @@ -827,15 +661,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Return default Site Settings - * - * @param $dir - * - * @return array - * array - * - $url, (Joomla - non admin url) - * - $siteName, - * - $siteRoot + * @inheritDoc */ public function getDefaultSiteSettings($dir) { $config = CRM_Core_Config::singleton(); @@ -853,11 +679,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Get Url to view user record - * @param int $contactID - * Contact ID. - * - * @return string + * @inheritDoc */ public function getUserRecordUrl($contactID) { $uid = CRM_Core_BAO_UFMatch::getUFId($contactID); @@ -872,8 +694,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Is the current user permitted to add a user - * @return bool + * @inheritDoc */ public function checkPermissionAddUser() { if (JFactory::getUser()->authorise('core.create', 'com_users')) { @@ -899,7 +720,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * Append to coreResourcesList + * Append Joomla js to coreResourcesList */ public function appendCoreResources(&$list) { $list[] = 'js/crm.joomla.js'; diff --git a/CRM/Utils/System/Soap.php b/CRM/Utils/System/Soap.php index a98269380a..b96ba20d97 100644 --- a/CRM/Utils/System/Soap.php +++ b/CRM/Utils/System/Soap.php @@ -44,21 +44,6 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { static $uf = NULL; static $ufClass = NULL; - /** - * Sets the title of the page - * - * @param string $title - * Title for page. - * @param $pageTitle - * - * @paqram string $pageTitle - * - * @return void - */ - public function setTitle($title, $pageTitle) { - return NULL; - } - /** * Given a permission string, check for access requirements * @@ -73,45 +58,7 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param string $title - * @param string $url - * - * @return void - */ - public function appendBreadCrumb($title, $url) { - return NULL; - } - - /** - * Append a string to the head of the html file - * - * @param string $head - * The new string to be appended. - * - * @return void - */ - public function addHTMLHead($head) { - return NULL; - } - - /** - * Generate an internal CiviCRM URL - * - * @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 string $fragment - * A fragment identifier (named anchor) to append to the link. - * - * @return string - * an HTML string containing a link to the given path. + * @inheritDoc */ public function url($path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL) { if (isset(self::$ufClass)) { @@ -125,10 +72,8 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { } /** - * Figure out the post url for the form - * - * @return string - * the url to post the form + * FIXME: Can this override be removed in favor of the parent? + * @inheritDoc */ public function postURL($action) { return NULL; @@ -146,17 +91,9 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { } /** - * Authenticate a user against the real UF - * - * @param string $name - * Login name. - * @param string $pass - * Login password. - * - * @return array - * Result array + * @inheritDoc */ - public function &authenticate($name, $pass) { + public function authenticate($name, $pass) { if (isset(self::$ufClass)) { $className = self::$ufClass; $result =& $className::authenticate($name, $pass); @@ -180,25 +117,12 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { $config->userFrameworkClass = 'CRM_Utils_System_Soap'; } - /** - * Get the locale set in the hosting CMS - * - * @return null - * as the language is set elsewhere - */ - public function getUFLocale() { - return NULL; - } - /** * Get user login URL for hosting CMS (method declared in each CMS system class) * * @param string $destination - * If present, add destination to querystring (works for Drupal only). * * @throws Exception - * @return; - * loginURL for the current CMS */ public function getLoginURL($destination = '') { throw new Exception("Method not implemented: getLoginURL"); diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index 46ab1904ad..a2e6a593e9 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -84,7 +84,7 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { * * @return mixed */ - public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { + public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { $retVal = array(1, 1, 12345); return $retVal; } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index cc9865e2bb..2a76d999ad 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -51,58 +51,29 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Sets the title of the page - * - * @param string $title - * @param null $pageTitle - * - * @return void + * @inheritDoc */ public function setTitle($title, $pageTitle = NULL) { if (!$pageTitle) { $pageTitle = $title; } - // get civi-wordpress instance - $civi = civi_wp(); - - // do we have functionality provided by plugin version 4.6+ present? - if (method_exists($civi, 'civicrm_context_get')) { - - // FIXME: Why is this global? - global $civicrm_wp_title; - $civicrm_wp_title = $title; - - // yes, set page title, depending on context - $context = civi_wp()->civicrm_context_get(); - switch ($context) { - case 'admin': - case 'shortcode': - $template = CRM_Core_Smarty::singleton(); - $template->assign('pageTitle', $pageTitle); - } - - } - elseif (civicrm_wp_in_civicrm()) { - - // legacy pre-4.6 behaviour - global $civicrm_wp_title; - $civicrm_wp_title = $title; - $template = CRM_Core_Smarty::singleton(); - $template->assign('pageTitle', $pageTitle); + // FIXME: Why is this global? + global $civicrm_wp_title; + $civicrm_wp_title = $title; + // yes, set page title, depending on context + $context = civi_wp()->civicrm_context_get(); + switch ($context) { + case 'admin': + case 'shortcode': + $template = CRM_Core_Smarty::singleton(); + $template->assign('pageTitle', $pageTitle); } } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param $breadCrumbs - * - * @internal param string $title - * @internal param string $url - * - * @return void + * @inheritDoc */ public function appendBreadCrumb($breadCrumbs) { $breadCrumb = wp_get_breadcrumb(); @@ -130,9 +101,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Reset an additional breadcrumb tag to the existing breadcrumb - * - * @return void + * @inheritDoc */ public function resetBreadCrumb() { $bc = array(); @@ -140,12 +109,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Append a string to the head of the html file - * - * @param string $head - * The new string to be appended. - * - * @return void + * @inheritDoc */ public function addHTMLHead($head) { static $registered = FALSE; @@ -160,6 +124,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { )); } + /** + * WP action callback + */ public static function _showHTMLHead() { $region = CRM_Core_Region::instance('wp_head', FALSE); if ($region) { @@ -168,77 +135,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Add a script file - * - * @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 - */ - public function addScriptUrl($url, $region) { - return FALSE; - } - - /** - * Add an inline script - * - * @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 - */ - public function addScript($code, $region) { - return FALSE; - } - - /** - * Add a css file - * - * @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 - */ - public function addStyleUrl($url, $region) { - return FALSE; - } - - /** - * Add an inline style - * - * @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 - */ - public function addStyle($code, $region) { - return FALSE; - } - - /** - * Rewrite various system urls to https - * - * @return void + * @inheritDoc */ public function mapConfigToSSL() { global $base_url; @@ -246,44 +143,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Figure out the post url for the form - * - * @param mix $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form - */ - public function postURL($action) { - if (!empty($action)) { - return $action; - } - - return $this->url($_GET['q'], NULL, TRUE, NULL, FALSE); - } - - /** - * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) - * - * @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 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. + * @inheritDoc */ public function url( $path = NULL, @@ -390,18 +250,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Authenticate the user against the wordpress db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * - * @param bool $loadCMSBootstrap - * @param null $realPath - * - * @return array|bool - * [contactID, ufID, uniqueString] if success else false if no auth + * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { $config = CRM_Core_Config::singleton(); @@ -415,7 +264,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return FALSE; } - // need to change this to make sure we matched only one row + // TODO: need to change this to make sure we matched only one row CRM_Core_BAO_UFMatch::synchronizeUFMatch($user->data, $user->data->ID, $user->data->user_email, 'WordPress'); $contactID = CRM_Core_BAO_UFMatch::getContactId($user->data->ID); @@ -426,28 +275,28 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. - * + * FIXME: Do something */ public function setMessage($message) { } /** - * @param $user - * - * @return bool + * FIXME: Do something */ public function loadUser($user) { return TRUE; } + /** + * FIXME: Use CMS-native approach + */ public function permissionDenied() { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } + /** + * @inheritDoc + */ public function logout() { // destroy session if (session_id()) { @@ -457,14 +306,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { wp_redirect(wp_login_url()); } - public function updateCategories() { - } - /** - * Get the locale set in the hosting CMS - * - * @return string - * with the locale or null for none + * @inheritDoc */ public function getUFLocale() { // WPML plugin @@ -570,10 +413,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * @param array $params - * @param $mail - * - * @return mixed + * @inheritDoc */ public function createUser(&$params, $mail) { $user_data = array( @@ -609,12 +449,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Change user name in host CMS - * - * @param int $ufID - * User ID in CMS. - * @param string $ufName - * User name. + * @inheritDoc */ public function updateCMSName($ufID, $ufName) { // CRM-10620 @@ -664,9 +499,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Check is user logged in. - * - * @return bool + * @inheritDoc */ public function isUserLoggedIn() { $isloggedIn = FALSE; @@ -690,10 +523,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Get currently logged in user uf id. - * - * @return int - * $userID logged in user uf id. + * @inheritDoc */ public function getLoggedInUfID() { $ufID = NULL; @@ -702,10 +532,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Get currently logged in user unique identifier - this tends to be the email address or user name. - * - * @return string - * logged in user unique identifier + * @inheritDoc */ public function getLoggedInUniqueIdentifier() { $user = $this->getLoggedInUserObject(); @@ -724,24 +551,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Get Unique Identifier from UserFramework system (CMS) - * @param object $user - * Object as described by the User Framework. - * @return int|null - * Unique identifier from the user Framework system + * @inheritDoc */ public function getUniqueIdentifierFromUserObject($user) { return empty($user->user_email) ? NULL : $user->user_email; } /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @return string - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { $config = CRM_Core_Config::singleton(); @@ -751,17 +568,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * @param CRM_Core_Form $form + * FIXME: Do something */ public function getLoginDestination(&$form) { return NULL; } /** - * Return the current WordPress version if relevant function exists - * - * @return string - * version number + * @inheritDoc */ public function getVersion() { if (function_exists('get_bloginfo')) { @@ -773,20 +587,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * Get timezone as a string - * @return string - * Timezone e.g. 'America/Los_Angeles' + * @inheritDoc */ public function getTimeZoneString() { return get_option('timezone_string'); } /** - * Get Url to view user record - * @param int $contactID - * Contact ID. - * - * @return string + * @inheritDoc */ public function getUserRecordUrl($contactID) { $uid = CRM_Core_BAO_UFMatch::getUFId($contactID); -- 2.25.1