aca82dc8d9875c0d9c76d01098410feab473bdda
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 public 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 public function getDefaultBlockLocation() {
109 public 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 public 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
154 * @param string $username
156 * @throws CRM_Core_Exception
159 public 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 public 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
182 public function flush() {
187 * Flush css/js caches
189 public function clearResourceCache() {
194 * Return default Site Settings
198 * @return array array
199 * - $url, (Joomla - non admin url)
203 public function getDefaultSiteSettings($dir) {
204 $config = CRM_Core_Config
::singleton();
205 $url = $config->userFrameworkBaseURL
;
206 return array($url, NULL, NULL);
210 * Perform any post login activities required by the CMS -
211 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
212 * calls hook_user op 'login' and generates a new session.
214 * @param array params
216 * FIXME: Document values accepted/required by $params
218 public function userLoginFinalize($params = array()){
222 * Set timezone in mysql so that timestamp fields show the correct time
224 public function setMySQLTimeZone(){
225 $timeZoneOffset = $this->getTimeZoneOffset();
227 $sql = "SET time_zone = '$timeZoneOffset'";
228 CRM_Core_DAO
::executequery($sql);
234 * Get timezone from CMS
235 * @return boolean|string
238 * Get timezone from Drupal
239 * @return boolean|string
241 public function getTimeZoneOffset(){
242 $timezone = $this->getTimeZoneString();
244 $tzObj = new DateTimeZone($timezone);
245 $dateTime = new DateTime("now", $tzObj);
246 $tz = $tzObj->getOffset($dateTime);
252 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
254 if($timeZoneOffset > 0){
255 $timeZoneOffset = '+' . $timeZoneOffset;
257 return $timeZoneOffset;
262 * Over-ridable function to get timezone as a string eg.
263 * @return string Timezone e.g. 'America/Los_Angeles'
265 public function getTimeZoneString() {
266 return date_default_timezone_get();
270 * Get Unique Identifier from UserFramework system (CMS)
271 * @param object $user object as described by the User Framework
272 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
275 public function getUniqueIdentifierFromUserObject($user) {}
278 * Get User ID from UserFramework system (CMS)
279 * @param object $user object as described by the User Framework
280 * @return mixed <NULL, number>
283 public function getUserIDFromUserObject($user) {}
286 * Get currently logged in user uf id.
288 * @return int $userID logged in user uf id.
290 public function getLoggedInUfID() {}
293 * Get currently logged in user unique identifier - this tends to be the email address or user name.
295 * @return string $userID logged in user unique identifier
297 public function getLoggedInUniqueIdentifier() {}
300 * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
301 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
302 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
305 * Note there is already a function getUFId which takes $username as a param - we could add $user
306 * as a second param to it but it seems messy - just overloading it because the name is taken
307 * @param object $user
308 * @return int $ufid - user ID of UF System
310 public function getBestUFID($user = NULL) {
312 return $this->getUserIDFromUserObject($user);
314 return $this->getLoggedInUfID();
318 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
319 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
320 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
323 * @param object $user
324 * @return string $uniqueIdentifier - unique identifier from the UF System
326 public function getBestUFUniqueIdentifier($user = NULL) {
328 return $this->getUniqueIdentifierFromUserObject($user);
330 return $this->getLoggedInUniqueIdentifier();
334 * Get Url to view user record
335 * @param integer $contactID Contact ID
339 public function getUserRecordUrl($contactID) {
343 * Is the current user permitted to add a user
346 public function checkPermissionAddUser() {
351 * Output code from error function
352 * @param string $content
354 public function outputError($content) {
355 echo CRM_Utils_System
::theme($content);
361 public function logger($message) {
366 * Append to coreResourcesList
368 public function appendCoreResources(&$list) {}