X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSystem%2FBase.php;h=aeb5411a44dd63105815c910433d066b9936b201;hb=f4aaa82a04876fea07ca47f9498e4caaddf2810b;hp=e9acb7df1a1e9e58a8b0969715213585f344cb13;hpb=6d5d1d248bb68161685078f1a629a59842af23b3;p=civicrm-core.git diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index e9acb7df1a..aeb5411a44 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -29,7 +29,12 @@ abstract class CRM_Utils_System_Base { // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function // but the parts should be copied into cleaner subclass implementations - if (function_exists('theme') && !$print) { + $config = CRM_Core_Config::singleton(); + if ( + $config->userSystem->is_drupal && + function_exists('theme') && + !$print + ) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); @@ -44,7 +49,8 @@ abstract class CRM_Utils_System_Base { $out = $content; $config = &CRM_Core_Config::singleton(); - if (!$print && + if ( + !$print && $config->userFramework == 'WordPress' ) { if (is_admin()) { @@ -110,6 +116,8 @@ abstract class CRM_Utils_System_Base { * Determine the native ID of the CMS user * * @param $username + * + * @throws CRM_Core_Exception * @return int|NULL */ function getUfId($username) { @@ -141,6 +149,9 @@ abstract class CRM_Utils_System_Base { /** * Return default Site Settings + * + * @param $dir + * * @return array array * - $url, (Joomla - non admin url) * - $siteName, @@ -175,11 +186,105 @@ abstract class CRM_Utils_System_Base { } } + /** * Get timezone from CMS * @return boolean|string */ + /** + * Get timezone from Drupal + * @return boolean|string + */ function getTimeZoneOffset(){ + $timezone = $this->getTimeZoneString(); + if($timezone){ + $tzObj = new DateTimeZone($timezone); + $dateTime = new DateTime("now", $tzObj); + $tz = $tzObj->getOffset($dateTime); + + if(empty($tz)){ + return false; + } + + $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60)); + + if($timeZoneOffset > 0){ + $timeZoneOffset = '+' . $timeZoneOffset; + } + return $timeZoneOffset; + } + } + + /** + * Over-ridable function to get timezone as a string eg. + * @return string Timezone e.g. 'America/Los_Angeles' + */ + function getTimeZoneString() { + return date_default_timezone_get(); + } + + /** + * 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 + * + */ + function getUniqueIdentifierFromUserObject($user) {} + + /** + * Get User ID from UserFramework system (CMS) + * @param object $user object as described by the User Framework + * @return mixed + * + */ + function getUserIDFromUserObject($user) {} + + /** + * Get currently logged in user uf id. + * + * @return int $userID logged in user uf id. + */ + 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() {} + + /** + * return a UFID (user account ID from the UserFramework / CMS system being based on the user object + * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs + * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling + * the function + * + * Note there is already a function getUFId which takes $username as a param - we could add $user + * as a second param to it but it seems messy - just overloading it because the name is taken + * @param object $user + * @return int $ufid - user ID of UF System + */ + function getBestUFID($user = NULL) { + if($user) { + return $this->getUserIDFromUserObject($user); + } + return $this->getLoggedInUfID(); + } + + /** + * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object + * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs + * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling + * the function + * + * @param object $user + * @return string $uniqueIdentifier - unique identifier from the UF System + */ + function getBestUFUniqueIdentifier($user = NULL) { + if($user) { + return $this->getUniqueIdentifierFromUserObject($user); + } + return $this->getLoggedInUniqueIdentifier(); } }