Fixed Code clean up for batch 15
[civicrm-core.git] / CRM / Utils / System / WordPress.php
index 31a003e2abb6d54264e50ba28ff7c12d7c5056c4..d748d112597aa2cb9fdcf31b067906bf81ca8742 100644 (file)
@@ -38,7 +38,6 @@
  */
 class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
-   *
    */
   public function __construct() {
     /**
@@ -75,14 +74,15 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
 
       // yes, set page title, depending on context
       $context = civi_wp()->civicrm_context_get();
-      switch ( $context ) {
+      switch ($context) {
         case 'admin':
         case 'shortcode':
           $template = CRM_Core_Smarty::singleton();
           $template->assign('pageTitle', $pageTitle);
       }
 
-    } elseif (civicrm_wp_in_civicrm()) {
+    }
+    elseif (civicrm_wp_in_civicrm()) {
 
       // legacy pre-4.6 behaviour
       global $civicrm_wp_title;
@@ -102,7 +102,6 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @internal param string $url
    *
    * @return void
-   * @static
    */
   public function appendBreadCrumb($breadCrumbs) {
     $breadCrumb = wp_get_breadcrumb();
@@ -133,7 +132,6 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * Reset an additional breadcrumb tag to the existing breadcrumb
    *
    * @return void
-   * @static
    */
   public function resetBreadCrumb() {
     $bc = array();
@@ -147,7 +145,6 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    *   The new string to be appended.
    *
    * @return void
-   * @static
    */
   public function addHTMLHead($head) {
     static $registered = FALSE;
@@ -172,14 +169,15 @@ class CRM_Utils_System_WordPress 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;
@@ -188,14 +186,15 @@ class CRM_Utils_System_WordPress 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;
@@ -204,14 +203,15 @@ class CRM_Utils_System_WordPress 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) {
     return FALSE;
@@ -220,14 +220,15 @@ class CRM_Utils_System_WordPress 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) {
     return FALSE;
@@ -236,10 +237,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Rewrite various system urls to https
    *
-   * @param null
-   *
    * @return void
-   * @static
    */
   public function mapConfigToSSL() {
     global $base_url;
@@ -252,8 +250,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param mix $action
    *   The default action if one is pre-specified.
    *
-   * @return string the url to post the form
-   * @static
+   * @return string
+   *   the url to post the form
    */
   public function postURL($action) {
     if (!empty($action)) {
@@ -266,26 +264,27 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#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(
+  public function url(
     $path = NULL,
     $query = NULL,
     $absolute = FALSE,
@@ -294,10 +293,10 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     $frontend = FALSE,
     $forceBackend = FALSE
   ) {
-    $config    = CRM_Core_Config::singleton();
-    $script    = '';
+    $config = CRM_Core_Config::singleton();
+    $script = '';
     $separator = $htmlize ? '&' : '&';
-    $wpPageParam    = '';
+    $wpPageParam = '';
     $fragment = isset($fragment) ? ('#' . $fragment) : '';
 
     $path = CRM_Utils_String::stripPathChars($path);
@@ -316,7 +315,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
       // when shortcode is included in page
       // also make sure we have valid query object
       global $wp_query;
-      if ( method_exists( $wp_query, 'get' ) ) {
+      if (method_exists($wp_query, 'get')) {
         if (get_query_var('page_id')) {
           $wpPageParam = "page_id=" . get_query_var('page_id');
         }
@@ -365,7 +364,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @return mixed|null|string
    */
   private function getBaseUrl($absolute, $frontend, $forceBackend) {
-    $config    = CRM_Core_Config::singleton();
+    $config = CRM_Core_Config::singleton();
 
     if (!isset($config->useFrameworkRelativeBase)) {
       $base = parse_url($config->userFrameworkBaseURL);
@@ -400,10 +399,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param bool $loadCMSBootstrap
    * @param null $realPath
    *
-   * @return mixed false if no auth
-   *               array(
-   * contactID, ufID, unique string ) if success
-   * @static
+   * @return array|bool
+   *   [contactID, ufID, uniqueString] if success else false if no auth
    */
   public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
     $config = CRM_Core_Config::singleton();
@@ -433,7 +430,6 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param string $message
    *   The message to set.
    *
-   * @static
    */
   public function setMessage($message) {
   }
@@ -466,7 +462,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Get the locale set in the hosting CMS
    *
-   * @return string  with the locale or null for none
+   * @return string
+   *   with the locale or null for none
    */
   public function getUFLocale() {
     // WPML plugin
@@ -478,7 +475,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
 
     if (isset($language)) {
       return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
-    } else {
+    }
+    else {
       return NULL;
     }
   }
@@ -486,10 +484,10 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Load wordpress bootstrap
    *
-   * @param $name
-   *   String optional username for login.
-   * @param $pass
-   *   String optional password for login.
+   * @param string $name
+   *   optional username for login.
+   * @param string $pass
+   *   optional password for login.
    *
    * @return bool
    */
@@ -536,10 +534,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Determine the location of the CMS root.
    *
-   * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
-   */
-  /**
-   * @return NULL|string
+   * @return string|NULL
+   *   local file system path to CMS root, or NULL if it cannot be determined
    */
   public function cmsRootPath() {
     $cmsRoot = $valid = NULL;
@@ -622,12 +618,12 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   public function updateCMSName($ufID, $ufName) {
     // CRM-10620
     if (function_exists('wp_update_user')) {
-      $ufID   = CRM_Utils_Type::escape($ufID, 'Integer');
+      $ufID = CRM_Utils_Type::escape($ufID, 'Integer');
       $ufName = CRM_Utils_Type::escape($ufName, 'String');
 
       $values = array('ID' => $ufID, 'user_email' => $ufName);
-      if( $ufID ) {
-        wp_update_user( $values );
+      if ($ufID) {
+        wp_update_user($values);
       }
     }
   }
@@ -640,8 +636,8 @@ class CRM_Utils_System_WordPress 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));
 
     if (!empty($params['name'])) {
@@ -669,7 +665,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Check is user logged in.
    *
-   * @return boolean true/false.
+   * @return bool
    */
   public function isUserLoggedIn() {
     $isloggedIn = FALSE;
@@ -685,15 +681,18 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    */
   public function getLoggedInUserObject() {
     if (function_exists('is_user_logged_in') &&
-    is_user_logged_in()) {
+      is_user_logged_in()
+    ) {
       global $current_user;
     }
     return $current_user;
   }
+
   /**
    * Get currently logged in user uf id.
    *
-   * @return int $userID logged in user uf id.
+   * @return int
+   *   $userID logged in user uf id.
    */
   public function getLoggedInUfID() {
     $ufID = NULL;
@@ -704,7 +703,8 @@ 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 $userID logged in user unique identifier
+   * @return string
+   *   logged in user unique identifier
    */
   public function getLoggedInUniqueIdentifier() {
     $user = $this->getLoggedInUserObject();
@@ -715,7 +715,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * Get User ID from UserFramework system (Joomla)
    * @param object $user
    *   Object as described by the CMS.
-   * @return mixed <NULL, number>
+   *
+   * @return int|null
    */
   public function getUserIDFromUserObject($user) {
     return !empty($user->ID) ? $user->ID : NULL;
@@ -725,8 +726,8 @@ 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 mixed $uniqueIdentifer Unique identifier from the user Framework system
-   *
+   * @return int|null
+   *   Unique identifier from the user Framework system
    */
   public function getUniqueIdentifierFromUserObject($user) {
     return empty($user->user_email) ? NULL : $user->user_email;
@@ -738,8 +739,8 @@ class CRM_Utils_System_WordPress 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
    */
   public function getLoginURL($destination = '') {
     $config = CRM_Core_Config::singleton();
@@ -752,14 +753,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param CRM_Core_Form $form
    */
   public function getLoginDestination(&$form) {
-    return;
+    return NULL;
   }
 
   /**
    * Return the current WordPress version if relevant function exists
    *
-   * @return string - version number
-   *
+   * @return string
+   *   version number
    */
   public function getVersion() {
     if (function_exists('get_bloginfo')) {
@@ -772,7 +773,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
 
   /**
    * Get timezone as a string
-   * @return string Timezone e.g. 'America/Los_Angeles'
+   * @return string
+   *   Timezone e.g. 'America/Los_Angeles'
    */
   public function getTimeZoneString() {
     return get_option('timezone_string');
@@ -787,7 +789,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    */
   public function getUserRecordUrl($contactID) {
     $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
-    if (CRM_Core_Session::singleton()->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users'))) {
+    if (CRM_Core_Session::singleton()
+        ->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users'))
+    ) {
       return CRM_Core_Config::singleton()->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
     }
   }