INFRA-132 - Add space before "{"
[civicrm-core.git] / CRM / Utils / System / Base.php
index c5c4fe761a76ccf4adfba312837ccdf03ff8ee7c..f06d6c3732df9a22e5475ea83eac4e602e7ace0f 100644 (file)
@@ -7,25 +7,31 @@ abstract class CRM_Utils_System_Base {
   /**
    * 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
+   *
    * @deprecated
    * @var bool
+   *   TRUE, if the CMS is Drupal.
    */
   var $is_drupal = FALSE;
 
   /**
    * Deprecated property to check if this is a joomla 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
+   *
    * @deprecated
    * @var bool
+   *   TRUE, if the CMS is Joomla!.
    */
   var $is_joomla = FALSE;
 
-    /**
-     * deprecated property to check if this is a wordpress 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
-     * @deprecated
-     * @var bool
-     */
+  /**
+   * deprecated property to check if this is a wordpress 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
+   *
+   * @deprecated
+   * @var bool
+   *   TRUE, if the CMS is WordPress.
+   */
   var $is_wordpress = FALSE;
 
   /**
@@ -35,8 +41,9 @@ abstract class CRM_Utils_System_Base {
    */
   var $supports_UF_Logging = FALSE;
 
-  /*
-   * Does the CMS allow CMS forms to be extended by hooks
+  /**
+   * @var bool
+   *   TRUE, if the CMS allows CMS forms to be extended by hooks.
    */
   var $supports_form_extensions = FALSE;
 
@@ -44,14 +51,22 @@ abstract class CRM_Utils_System_Base {
    * If we are using a theming system, invoke theme, else just print the
    * content
    *
-   * @param string  $content the content that will be themed
-   * @param boolean $print   are we displaying to the screen or bypassing theming?
-   * @param boolean $maintenance  for maintenance mode
+   * @param string $content
+   *   The content that will be themed.
+   * @param bool $print
+   *   Are we displaying to the screen or bypassing theming?.
+   * @param bool $maintenance
+   *   For maintenance mode.
+   *
+   * @throws Exception
+   * @return string|null
+   *   NULL, If $print is FALSE, and some other criteria match up.
+   *   The themed string, otherwise.
    *
-   * @return void           prints content on stdout
-   * @access public
+   * @todo The return value is inconsistent.
+   * @todo Better to always return, and never print.
    */
-  function theme(&$content, $print = FALSE, $maintenance = FALSE) {
+  public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
     $ret = FALSE;
 
     // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
@@ -80,11 +95,17 @@ abstract class CRM_Utils_System_Base {
       !$print &&
       $config->userFramework == 'WordPress'
     ) {
+      if (!function_exists('is_admin')) {
+        throw new \Exception('Function "is_admin()" is missing, even though WordPress is the user framework.');
+      }
+      if (!defined('ABSPATH')) {
+        throw new \Exception('Constant "ABSPATH" is not defined, even though WordPress is the user framework.');
+      }
       if (is_admin()) {
-        require_once (ABSPATH . 'wp-admin/admin-header.php');
+        require_once ABSPATH . 'wp-admin/admin-header.php';
       }
       else {
-        // FIX ME: we need to figure out to replace civicrm content on the frontend pages
+        // FIXME: we need to figure out to replace civicrm content on the frontend pages
       }
     }
 
@@ -93,20 +114,21 @@ abstract class CRM_Utils_System_Base {
     }
     else {
       print $out;
+      return NULL;
     }
   }
 
   /**
    * @return string
    */
-  function getDefaultBlockLocation() {
+  public function getDefaultBlockLocation() {
     return 'left';
   }
 
   /**
    * @return string
    */
-  function getVersion() {
+  public function getVersion() {
     return 'Unknown';
   }
 
@@ -114,11 +136,11 @@ abstract class CRM_Utils_System_Base {
    * Format the url as per language Negotiation.
    *
    * @param string $url
-   *
    * @param bool $addLanguagePart
    * @param bool $removeLanguagePart
    *
-   * @return string $url, formatted url.
+   * @return string
+   *   Formatted url.
    * @static
    */
   function languageNegotiationURL(
@@ -132,16 +154,18 @@ abstract class 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 string|null
+   *   Local file system path to CMS root, or NULL if it cannot be determined
    */
-  function cmsRootPath() {
+  public function cmsRootPath() {
     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)
+   * @param string $destination
+   *   If present, add destination to querystring (works for Drupal only).
    *
    * @return string - loginURL for the current CMS
    * @static
@@ -156,7 +180,7 @@ abstract class CRM_Utils_System_Base {
    * @throws CRM_Core_Exception
    * @return int|NULL
    */
-  function getUfId($username) {
+  public function getUfId($username) {
     $className = get_class($this);
     throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
   }
@@ -164,11 +188,10 @@ abstract class CRM_Utils_System_Base {
   /**
    * Set a init session with user object
    *
-   * @param array $data  array with user specific data
-   *
-   * @access public
+   * @param array $data
+   *   Array with user specific data
    */
-  function setUserSession($data) {
+  public function setUserSession($data) {
     list($userID, $ufID) = $data;
     $session = CRM_Core_Session::singleton();
     $session->set('ufID', $ufID);
@@ -179,28 +202,28 @@ abstract class CRM_Utils_System_Base {
    * Reset any system caches that may be required for proper CiviCRM
    * integration.
    */
-  function flush() {
+  public function flush() {
     // nullop by default
   }
 
   /**
    * Flush css/js caches
    */
-  function clearResourceCache() {
+  public function clearResourceCache() {
     // nullop by default
   }
 
   /**
    * Return default Site Settings
    *
-   * @param $dir
+   * @param string $dir
    *
-   * @return array array
+   * @return array
    * - $url, (Joomla - non admin url)
    * - $siteName,
    * - $siteRoot
    */
-  function getDefaultSiteSettings($dir) {
+  public function getDefaultSiteSettings($dir) {
     $config = CRM_Core_Config::singleton();
     $url = $config->userFrameworkBaseURL;
     return array($url, NULL, NULL);
@@ -211,19 +234,19 @@ abstract class CRM_Utils_System_Base {
    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
    * calls hook_user op 'login' and generates a new session.
    *
-   * @param array params
+   * @param array $params
    *
    * FIXME: Document values accepted/required by $params
    */
-  function userLoginFinalize($params = array()){
+  public function userLoginFinalize($params = array()) {
   }
 
   /**
    * Set timezone in mysql so that timestamp fields show the correct time
    */
-  function setMySQLTimeZone(){
+  public function setMySQLTimeZone() {
     $timeZoneOffset = $this->getTimeZoneOffset();
-    if($timeZoneOffset){
+    if ($timeZoneOffset) {
       $sql = "SET time_zone = '$timeZoneOffset'";
       CRM_Core_DAO::executequery($sql);
     }
@@ -232,69 +255,75 @@ abstract class CRM_Utils_System_Base {
 
   /**
    * Get timezone from CMS
-   * @return boolean|string
-   */
-  /**
-   * Get timezone from Drupal
-   * @return boolean|string
+   *
+   * @return string|false|null
    */
-  function getTimeZoneOffset(){
+  public function getTimeZoneOffset() {
     $timezone = $this->getTimeZoneString();
-    if($timezone){
+    if ($timezone) {
       $tzObj = new DateTimeZone($timezone);
       $dateTime = new DateTime("now", $tzObj);
       $tz = $tzObj->getOffset($dateTime);
 
-      if(empty($tz)){
-        return false;
+      if (empty($tz)) {
+        return FALSE;
       }
 
-      $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60));
+      $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz / 60) % 60));
 
-      if($timeZoneOffset > 0){
+      if ($timeZoneOffset > 0) {
         $timeZoneOffset = '+' . $timeZoneOffset;
       }
       return $timeZoneOffset;
     }
+    return NULL;
   }
 
   /**
    * Over-ridable function to get timezone as a string eg.
-   * @return string Timezone e.g. 'America/Los_Angeles'
+   *
+   * @return string
+   *   Time zone, e.g. 'America/Los_Angeles'
    */
-  function getTimeZoneString() {
+  public function getTimeZoneString() {
     return date_default_timezone_get();
   }
 
   /**
    * 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) {
+  }
 
   /**
    * Get User ID 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 <NULL, number>
    *
    */
-  function getUserIDFromUserObject($user) {}
+  public function getUserIDFromUserObject($user) {
+  }
 
   /**
    * Get currently logged in user uf id.
    *
    * @return int $userID logged in user uf id.
    */
-  function getLoggedInUfID() {}
+  public function getLoggedInUfID() {
+  }
 
   /**
    * 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
    */
-  function getLoggedInUniqueIdentifier() {}
+  public function getLoggedInUniqueIdentifier() {
+  }
 
   /**
    * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
@@ -307,8 +336,8 @@ abstract class CRM_Utils_System_Base {
    * @param object $user
    * @return int $ufid - user ID of UF System
    */
-  function getBestUFID($user = NULL) {
-    if($user) {
+  public function getBestUFID($user = NULL) {
+    if ($user) {
       return $this->getUserIDFromUserObject($user);
     }
     return $this->getLoggedInUfID();
@@ -323,8 +352,8 @@ abstract class CRM_Utils_System_Base {
    * @param object $user
    * @return string $uniqueIdentifier - unique identifier from the UF System
    */
-  function getBestUFUniqueIdentifier($user = NULL) {
-    if($user) {
+  public function getBestUFUniqueIdentifier($user = NULL) {
+    if ($user) {
       return $this->getUniqueIdentifierFromUserObject($user);
     }
     return $this->getLoggedInUniqueIdentifier();
@@ -332,18 +361,19 @@ abstract class CRM_Utils_System_Base {
 
   /**
    * 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) {
     return NULL;
   }
   /**
    * Is the current user permitted to add a user
    * @return bool
    */
-  function checkPermissionAddUser() {
+  public function checkPermissionAddUser() {
     return FALSE;
   }
 
@@ -351,20 +381,20 @@ abstract class CRM_Utils_System_Base {
    * Output code from error function
    * @param string $content
    */
-  function outputError($content) {
+  public function outputError($content) {
     echo CRM_Utils_System::theme($content);
   }
 
   /**
    * Log error to CMS
    */
-  function logger($message) {
+  public function logger($message) {
 
   }
 
   /**
    * Append to coreResourcesList
    */
-  function appendCoreResources(&$list) {}
+  public function appendCoreResources(&$list) {
+  }
 }
-