INFRA-132 - @param type fixes
[civicrm-core.git] / CRM / Utils / System / WordPress.php
index 54d3b5c0a38468ec2ed17b012db6896a013544da..73c6f54d904da1e311ce0f92e260f37925039aa7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -40,7 +40,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    *
    */
-  function __construct() {
+  public function __construct() {
     /**
      * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
      * functions and leave the codebase oblivious to the type of CMS
@@ -58,9 +58,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param null $pageTitle
    *
    * @return void
-   * @access public
    */
-  function setTitle($title, $pageTitle = NULL) {
+  public function setTitle($title, $pageTitle = NULL) {
     if (!$pageTitle) {
       $pageTitle = $title;
     }
@@ -76,14 +75,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;
@@ -103,10 +103,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @internal param string $url
    *
    * @return void
-   * @access public
    * @static
    */
-  function appendBreadCrumb($breadCrumbs) {
+  public function appendBreadCrumb($breadCrumbs) {
     $breadCrumb = wp_get_breadcrumb();
 
     if (is_array($breadCrumbs)) {
@@ -135,10 +134,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * Reset an additional breadcrumb tag to the existing breadcrumb
    *
    * @return void
-   * @access public
    * @static
    */
-  function resetBreadCrumb() {
+  public function resetBreadCrumb() {
     $bc = array();
     wp_set_breadcrumb($bc);
   }
@@ -146,13 +144,13 @@ 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
+   * @param string $head
+   *   The new string to be appended.
    *
    * @return void
-   * @access public
    * @static
    */
-  function addHTMLHead($head) {
+  public function addHTMLHead($head) {
     static $registered = FALSE;
     if (!$registered) {
       // front-end view
@@ -165,7 +163,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     ));
   }
 
-  static function _showHTMLHead() {
+  public static function _showHTMLHead() {
     $region = CRM_Core_Region::instance('wp_head', FALSE);
     if ($region) {
       echo $region->render('');
@@ -176,13 +174,13 @@ 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 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
-   * @access public
    */
   public function addScriptUrl($url, $region) {
     return FALSE;
@@ -192,13 +190,13 @@ 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 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
-   * @access public
    */
   public function addScript($code, $region) {
     return FALSE;
@@ -208,13 +206,13 @@ 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 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
-   * @access public
    */
   public function addStyleUrl($url, $region) {
     return FALSE;
@@ -224,13 +222,13 @@ 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 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
-   * @access public
    */
   public function addStyle($code, $region) {
     return FALSE;
@@ -242,10 +240,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param null
    *
    * @return void
-   * @access public
    * @static
    */
-  function mapConfigToSSL() {
+  public function mapConfigToSSL() {
     global $base_url;
     $base_url = str_replace('http://', 'https://', $base_url);
   }
@@ -253,13 +250,13 @@ 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
+   * @param mix $action
+   *   The default action if one is pre-specified.
    *
    * @return string the url to post the form
-   * @access public
    * @static
    */
-  function postURL($action) {
+  public function postURL($action) {
     if (!empty($action)) {
       return $action;
     }
@@ -270,19 +267,24 @@ 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.
-   * @access public
    */
   function url(
     $path = NULL,
@@ -315,7 +317,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');
         }
@@ -391,8 +393,10 @@ 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 string $name
+   *   The user name.
+   * @param string $password
+   *   The password for the above user name.
    *
    * @param bool $loadCMSBootstrap
    * @param null $realPath
@@ -400,10 +404,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @return mixed false if no auth
    *               array(
    * contactID, ufID, unique string ) if success
-   * @access public
    * @static
    */
-  function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
+  public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
     $config = CRM_Core_Config::singleton();
 
     if ($loadCMSBootstrap) {
@@ -428,12 +431,12 @@ 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
+   * @param string $message
+   *   The message to set.
    *
-   * @access public
    * @static
    */
-  function setMessage($message) {
+  public function setMessage($message) {
   }
 
   /**
@@ -441,15 +444,15 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    *
    * @return bool
    */
-  function loadUser( $user ) {
-    return true;
+  public function loadUser($user) {
+    return TRUE;
   }
 
-  function permissionDenied() {
+  public function permissionDenied() {
     CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
   }
 
-  function logout() {
+  public function logout() {
     // destroy session
     if (session_id()) {
       session_destroy();
@@ -458,14 +461,15 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     wp_redirect(wp_login_url());
   }
 
-  function updateCategories() {}
+  public function updateCategories() {
+  }
 
   /**
    * Get the locale set in the hosting CMS
    *
    * @return string  with the locale or null for none
    */
-  function getUFLocale() {
+  public function getUFLocale() {
     // WPML plugin
     if (defined('ICL_LANGUAGE_CODE')) {
       $language = ICL_LANGUAGE_CODE;
@@ -475,7 +479,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;
     }
   }
@@ -483,12 +488,14 @@ 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
    */
-  function loadBootStrap($name = NULL, $pass = NULL) {
+  public function loadBootStrap($name = NULL, $pass = NULL) {
     global $wp, $wp_rewrite, $wp_the_query, $wp_query, $wpdb;
 
     $cmsRootPath = $this->cmsRootPath();
@@ -496,13 +503,13 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
       CRM_Core_Error::fatal("Could not find the install directory for WordPress");
     }
 
-    require_once ($cmsRootPath . DIRECTORY_SEPARATOR . 'wp-load.php');
+    require_once $cmsRootPath . DIRECTORY_SEPARATOR . 'wp-load.php';
     $wpUserTimezone = get_option('timezone_string');
     if ($wpUserTimezone) {
       date_default_timezone_set($wpUserTimezone);
       CRM_Core_Config::singleton()->userSystem->setMySQLTimeZone();
     }
-    require_once ($cmsRootPath . DIRECTORY_SEPARATOR . 'wp-includes/pluggable.php');
+    require_once $cmsRootPath . DIRECTORY_SEPARATOR . 'wp-includes/pluggable.php';
     $uid = CRM_Utils_Array::value('uid', $name);
     if ($uid) {
       $account = wp_set_current_user($uid);
@@ -512,7 +519,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
         return TRUE;
       }
     }
-    return true;
+    return TRUE;
   }
 
   /**
@@ -520,12 +527,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    *
    * @return bool
    */
-  function validInstallDir($dir) {
+  public function validInstallDir($dir) {
     $includePath = "$dir/wp-includes";
-    if (
-      @opendir($includePath) &&
-      file_exists("$includePath/version.php")
-    ) {
+    if (file_exists("$includePath/version.php")) {
       return TRUE;
     }
     return FALSE;
@@ -539,7 +543,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * @return NULL|string
    */
-  function cmsRootPath() {
+  public function cmsRootPath() {
     $cmsRoot = $valid = NULL;
     if (defined('CIVICRM_CMSDIR')) {
       if ($this->validInstallDir(CIVICRM_CMSDIR)) {
@@ -576,7 +580,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    *
    * @return mixed
    */
-  function createUser(&$params, $mail) {
+  public function createUser(&$params, $mail) {
     $user_data = array(
       'ID' => '',
       'user_pass' => $params['cms_pass'],
@@ -612,18 +616,20 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * Change user name in host CMS
    *
-   * @param integer $ufID User ID in CMS
-   * @param string $ufName User name
+   * @param int $ufID
+   *   User ID in CMS.
+   * @param string $ufName
+   *   User name.
    */
-  function updateCMSName($ufID, $ufName) {
+  public function updateCMSName($ufID, $ufName) {
     // CRM-10620
     if (function_exists('wp_update_user')) {
       $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 ) ;
+      $values = array('ID' => $ufID, 'user_email' => $ufName);
+      if ($ufID) {
+        wp_update_user($values);
       }
     }
   }
@@ -633,7 +639,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @param $errors
    * @param string $emailName
    */
-  function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
+  public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
     $config = CRM_Core_Config::singleton();
 
     $dao   = new CRM_Core_DAO();
@@ -679,7 +685,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   /**
    * @return mixed
    */
-  function getLoggedInUserObject() {
+  public function getLoggedInUserObject() {
     if (function_exists('is_user_logged_in') &&
     is_user_logged_in()) {
       global $current_user;
@@ -702,34 +708,37 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    *
    * @return string $userID logged in user unique identifier
    */
-  function getLoggedInUniqueIdentifier() {
+  public function getLoggedInUniqueIdentifier() {
     $user = $this->getLoggedInUserObject();
     return $this->getUniqueIdentifierFromUserObject($user);
   }
 
   /**
    * Get User ID from UserFramework system (Joomla)
-   * @param object $user object as described by the CMS
+   * @param object $user
+   *   Object as described by the CMS.
    * @return mixed <NULL, number>
    */
-  function getUserIDFromUserObject($user) {
+  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
+   * @param object $user
+   *   Object as described by the User Framework.
    * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
    *
    */
-  function getUniqueIdentifierFromUserObject($user) {
+  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)
+   * @param string $destination
+   *   If present, add destination to querystring (works for Drupal only).
    *
    * @return string - loginURL for the current CMS
    *
@@ -754,7 +763,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * @return string - version number
    *
    */
-  function getVersion() {
+  public function getVersion() {
     if (function_exists('get_bloginfo')) {
       return get_bloginfo('version', 'display');
     }
@@ -767,21 +776,21 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * Get timezone as a string
    * @return string Timezone e.g. 'America/Los_Angeles'
    */
-  function getTimeZoneString() {
+  public function getTimeZoneString() {
     return get_option('timezone_string');
   }
 
   /**
    * Get Url to view user record
-   * @param integer $contactID Contact ID
+   * @param int $contactID
+   *   Contact ID.
    *
    * @return string
    */
-  function getUserRecordUrl($contactID) {
+  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'))) {
       return CRM_Core_Config::singleton()->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
     }
   }
 }
-