4 * Base class for UF system integrations
6 abstract class CRM_Utils_System_Base
{
8 * 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
9 * functions and leave the codebase oblivious to the type of CMS
13 var $is_drupal = FALSE;
16 * 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
17 * functions and leave the codebase oblivious to the type of CMS
21 var $is_joomla = FALSE;
24 * 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
25 * functions and leave the codebase oblivious to the type of CMS
29 var $is_wordpress = FALSE;
32 * Does this CMS / UF support a CMS specific logging mechanism?
33 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
36 var $supports_UF_Logging = FALSE;
39 * Does the CMS allow CMS forms to be extended by hooks
41 var $supports_form_extensions = FALSE;
44 * if we are using a theming system, invoke theme, else just print the
47 * @param string $content the content that will be themed
48 * @param boolean $print are we displaying to the screen or bypassing theming?
49 * @param boolean $maintenance for maintenance mode
51 * @return void prints content on stdout
54 function theme(&$content, $print = FALSE, $maintenance = FALSE) {
57 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
58 // but the parts should be copied into cleaner subclass implementations
59 $config = CRM_Core_Config
::singleton();
61 $config->userSystem
->is_drupal
&&
62 function_exists('theme') &&
66 drupal_set_breadcrumb('');
67 drupal_maintenance_theme();
68 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
69 CRM_Utils_System
::addHTMLHead($region->render(''));
71 print theme('maintenance_page', array('content' => $content));
74 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
78 $config = &CRM_Core_Config
::singleton();
81 $config->userFramework
== 'WordPress'
84 require_once (ABSPATH
. 'wp-admin/admin-header.php');
87 // FIX ME: we need to figure out to replace civicrm content on the frontend pages
102 function getDefaultBlockLocation() {
109 function getVersion() {
114 * Format the url as per language Negotiation.
118 * @param bool $addLanguagePart
119 * @param bool $removeLanguagePart
121 * @return string $url, formatted url.
124 function languageNegotiationURL(
126 $addLanguagePart = TRUE,
127 $removeLanguagePart = FALSE
133 * Determine the location of the CMS root.
135 * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
137 function cmsRootPath() {
142 * Get user login URL for hosting CMS (method declared in each CMS system class)
144 * @param string $destination - if present, add destination to querystring (works for Drupal only)
146 * @return string - loginURL for the current CMS
149 public abstract function getLoginURL($destination = '');
152 * Determine the native ID of the CMS user
156 * @throws CRM_Core_Exception
159 function getUfId($username) {
160 $className = get_class($this);
161 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
165 * Set a init session with user object
167 * @param array $data array with user specific data
171 function setUserSession($data) {
172 list($userID, $ufID) = $data;
173 $session = CRM_Core_Session
::singleton();
174 $session->set('ufID', $ufID);
175 $session->set('userID', $userID);
179 * Reset any system caches that may be required for proper CiviCRM
187 * Return default Site Settings
191 * @return array array
192 * - $url, (Joomla - non admin url)
196 function getDefaultSiteSettings($dir) {
197 $config = CRM_Core_Config
::singleton();
198 $url = $config->userFrameworkBaseURL
;
199 return array($url, NULL, NULL);
203 * Perform any post login activities required by the CMS -
204 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
205 * calls hook_user op 'login' and generates a new session.
207 * @param array params
209 * FIXME: Document values accepted/required by $params
211 function userLoginFinalize($params = array()){
215 * Set timezone in mysql so that timestamp fields show the correct time
217 function setMySQLTimeZone(){
218 $timeZoneOffset = $this->getTimeZoneOffset();
220 $sql = "SET time_zone = '$timeZoneOffset'";
221 CRM_Core_DAO
::executequery($sql);
227 * Get timezone from CMS
228 * @return boolean|string
231 * Get timezone from Drupal
232 * @return boolean|string
234 function getTimeZoneOffset(){
235 $timezone = $this->getTimeZoneString();
237 $tzObj = new DateTimeZone($timezone);
238 $dateTime = new DateTime("now", $tzObj);
239 $tz = $tzObj->getOffset($dateTime);
245 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
247 if($timeZoneOffset > 0){
248 $timeZoneOffset = '+' . $timeZoneOffset;
250 return $timeZoneOffset;
255 * Over-ridable function to get timezone as a string eg.
256 * @return string Timezone e.g. 'America/Los_Angeles'
258 function getTimeZoneString() {
259 return date_default_timezone_get();
263 * Get Unique Identifier from UserFramework system (CMS)
264 * @param object $user object as described by the User Framework
265 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
268 function getUniqueIdentifierFromUserObject($user) {}
271 * Get User ID from UserFramework system (CMS)
272 * @param object $user object as described by the User Framework
273 * @return mixed <NULL, number>
276 function getUserIDFromUserObject($user) {}
279 * Get currently logged in user uf id.
281 * @return int $userID logged in user uf id.
283 function getLoggedInUfID() {}
286 * Get currently logged in user unique identifier - this tends to be the email address or user name.
288 * @return string $userID logged in user unique identifier
290 function getLoggedInUniqueIdentifier() {}
293 * return a UFID (user account ID from the UserFramework / CMS system being based on the user object
294 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
295 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
298 * Note there is already a function getUFId which takes $username as a param - we could add $user
299 * as a second param to it but it seems messy - just overloading it because the name is taken
300 * @param object $user
301 * @return int $ufid - user ID of UF System
303 function getBestUFID($user = NULL) {
305 return $this->getUserIDFromUserObject($user);
307 return $this->getLoggedInUfID();
311 * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
312 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
313 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
316 * @param object $user
317 * @return string $uniqueIdentifier - unique identifier from the UF System
319 function getBestUFUniqueIdentifier($user = NULL) {
321 return $this->getUniqueIdentifierFromUserObject($user);
323 return $this->getLoggedInUniqueIdentifier();
327 * Get Url to view user record
328 * @param integer $contactID Contact ID
332 function getUserRecordUrl($contactID) {
336 * Is the current user permitted to add a user
339 function checkPermissionAddUser() {
344 * output code from error function
345 * @param string $content
347 function outputError($content) {
348 echo CRM_Utils_System
::theme($content);
354 function logger($message) {