4 * Base class for UF system integrations
6 abstract class CRM_Utils_System_Base
{
7 var $is_drupal = FALSE;
8 var $is_joomla = FALSE;
9 var $is_wordpress = FALSE;
12 * Does the CMS allow CMS forms to be extended by hooks
14 var $supports_form_extensions = FALSE;
17 * if we are using a theming system, invoke theme, else just print the
20 * @param string $content the content that will be themed
21 * @param boolean $print are we displaying to the screen or bypassing theming?
22 * @param boolean $maintenance for maintenance mode
24 * @return void prints content on stdout
27 function theme(&$content, $print = FALSE, $maintenance = FALSE) {
30 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
31 // but the parts should be copied into cleaner subclass implementations
32 $config = CRM_Core_Config
::singleton();
34 $config->userSystem
->is_drupal
&&
35 function_exists('theme') &&
39 drupal_set_breadcrumb('');
40 drupal_maintenance_theme();
41 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
42 CRM_Utils_System
::addHTMLHead($region->render(''));
44 print theme('maintenance_page', array('content' => $content));
47 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
51 $config = &CRM_Core_Config
::singleton();
54 $config->userFramework
== 'WordPress'
57 require_once (ABSPATH
. 'wp-admin/admin-header.php');
60 // FIX ME: we need to figure out to replace civicrm content on the frontend pages
75 function getDefaultBlockLocation() {
82 function getVersion() {
87 * Format the url as per language Negotiation.
91 * @param bool $addLanguagePart
92 * @param bool $removeLanguagePart
94 * @return string $url, formatted url.
97 function languageNegotiationURL(
99 $addLanguagePart = TRUE,
100 $removeLanguagePart = FALSE
106 * Determine the location of the CMS root.
108 * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
110 function cmsRootPath() {
115 * Get user login URL for hosting CMS (method declared in each CMS system class)
117 * @param string $destination - if present, add destination to querystring (works for Drupal only)
119 * @return string - loginURL for the current CMS
122 public abstract function getLoginURL($destination = '');
125 * Determine the native ID of the CMS user
129 * @throws CRM_Core_Exception
132 function getUfId($username) {
133 $className = get_class($this);
134 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
138 * Set a init session with user object
140 * @param array $data array with user specific data
144 function setUserSession($data) {
145 list($userID, $ufID) = $data;
146 $session = CRM_Core_Session
::singleton();
147 $session->set('ufID', $ufID);
148 $session->set('userID', $userID);
152 * Reset any system caches that may be required for proper CiviCRM
160 * Return default Site Settings
164 * @return array array
165 * - $url, (Joomla - non admin url)
169 function getDefaultSiteSettings($dir) {
170 $config = CRM_Core_Config
::singleton();
171 $url = $config->userFrameworkBaseURL
;
172 return array($url, NULL, NULL);
176 * Perform any post login activities required by the CMS -
177 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
178 * calls hook_user op 'login' and generates a new session.
180 * @param array params
182 * FIXME: Document values accepted/required by $params
184 function userLoginFinalize($params = array()){
188 * Set timezone in mysql so that timestamp fields show the correct time
190 function setMySQLTimeZone(){
191 $timeZoneOffset = $this->getTimeZoneOffset();
193 $sql = "SET time_zone = '$timeZoneOffset'";
194 CRM_Core_DAO
::executequery($sql);
200 * Get timezone from CMS
201 * @return boolean|string
204 * Get timezone from Drupal
205 * @return boolean|string
207 function getTimeZoneOffset(){
208 $timezone = $this->getTimeZoneString();
210 $tzObj = new DateTimeZone($timezone);
211 $dateTime = new DateTime("now", $tzObj);
212 $tz = $tzObj->getOffset($dateTime);
218 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
220 if($timeZoneOffset > 0){
221 $timeZoneOffset = '+' . $timeZoneOffset;
223 return $timeZoneOffset;
228 * Over-ridable function to get timezone as a string eg.
229 * @return string Timezone e.g. 'America/Los_Angeles'
231 function getTimeZoneString() {
232 return date_default_timezone_get();
236 * Get Unique Identifier from UserFramework system (CMS)
237 * @param object $user object as described by the User Framework
238 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
241 function getUniqueIdentifierFromUserObject($user) {}
244 * Get User ID from UserFramework system (CMS)
245 * @param object $user object as described by the User Framework
246 * @return mixed <NULL, number>
249 function getUserIDFromUserObject($user) {}
252 * Get currently logged in user uf id.
254 * @return int $userID logged in user uf id.
256 function getLoggedInUfID() {}
259 * Get currently logged in user unique identifier - this tends to be the email address or user name.
261 * @return string $userID logged in user unique identifier
263 function getLoggedInUniqueIdentifier() {}
266 * return a UFID (user account ID from the UserFramework / CMS system being based on the user object
267 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
268 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
271 * Note there is already a function getUFId which takes $username as a param - we could add $user
272 * as a second param to it but it seems messy - just overloading it because the name is taken
273 * @param object $user
274 * @return int $ufid - user ID of UF System
276 function getBestUFID($user = NULL) {
278 return $this->getUserIDFromUserObject($user);
280 return $this->getLoggedInUfID();
284 * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
285 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
286 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
289 * @param object $user
290 * @return string $uniqueIdentifier - unique identifier from the UF System
292 function getBestUFUniqueIdentifier($user = NULL) {
294 return $this->getUniqueIdentifierFromUserObject($user);
296 return $this->getLoggedInUniqueIdentifier();
300 * Get Url to view user record
301 * @param integer $contactID Contact ID
305 function getUserRecordUrl($contactID) {
309 * Is the current user permitted to add a user
312 function checkPermissionAddUser() {
317 * output code from error function
318 * @param string $content
320 function outputError($content) {
321 echo CRM_Utils_System
::theme($content);