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 this CMS / UF support a CMS specific logging mechanism?
13 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
16 var $supports_UF_Logging = FALSE;
19 * Does the CMS allow CMS forms to be extended by hooks
21 var $supports_form_extensions = FALSE;
24 * if we are using a theming system, invoke theme, else just print the
27 * @param string $content the content that will be themed
28 * @param boolean $print are we displaying to the screen or bypassing theming?
29 * @param boolean $maintenance for maintenance mode
31 * @return void prints content on stdout
34 function theme(&$content, $print = FALSE, $maintenance = FALSE) {
37 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
38 // but the parts should be copied into cleaner subclass implementations
39 $config = CRM_Core_Config
::singleton();
41 $config->userSystem
->is_drupal
&&
42 function_exists('theme') &&
46 drupal_set_breadcrumb('');
47 drupal_maintenance_theme();
48 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
49 CRM_Utils_System
::addHTMLHead($region->render(''));
51 print theme('maintenance_page', array('content' => $content));
54 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
58 $config = &CRM_Core_Config
::singleton();
61 $config->userFramework
== 'WordPress'
64 require_once (ABSPATH
. 'wp-admin/admin-header.php');
67 // FIX ME: we need to figure out to replace civicrm content on the frontend pages
82 function getDefaultBlockLocation() {
89 function getVersion() {
94 * Format the url as per language Negotiation.
98 * @param bool $addLanguagePart
99 * @param bool $removeLanguagePart
101 * @return string $url, formatted url.
104 function languageNegotiationURL(
106 $addLanguagePart = TRUE,
107 $removeLanguagePart = FALSE
113 * Determine the location of the CMS root.
115 * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
117 function cmsRootPath() {
122 * Get user login URL for hosting CMS (method declared in each CMS system class)
124 * @param string $destination - if present, add destination to querystring (works for Drupal only)
126 * @return string - loginURL for the current CMS
129 public abstract function getLoginURL($destination = '');
132 * Determine the native ID of the CMS user
136 * @throws CRM_Core_Exception
139 function getUfId($username) {
140 $className = get_class($this);
141 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
145 * Set a init session with user object
147 * @param array $data array with user specific data
151 function setUserSession($data) {
152 list($userID, $ufID) = $data;
153 $session = CRM_Core_Session
::singleton();
154 $session->set('ufID', $ufID);
155 $session->set('userID', $userID);
159 * Reset any system caches that may be required for proper CiviCRM
167 * Return default Site Settings
171 * @return array array
172 * - $url, (Joomla - non admin url)
176 function getDefaultSiteSettings($dir) {
177 $config = CRM_Core_Config
::singleton();
178 $url = $config->userFrameworkBaseURL
;
179 return array($url, NULL, NULL);
183 * Perform any post login activities required by the CMS -
184 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
185 * calls hook_user op 'login' and generates a new session.
187 * @param array params
189 * FIXME: Document values accepted/required by $params
191 function userLoginFinalize($params = array()){
195 * Set timezone in mysql so that timestamp fields show the correct time
197 function setMySQLTimeZone(){
198 $timeZoneOffset = $this->getTimeZoneOffset();
200 $sql = "SET time_zone = '$timeZoneOffset'";
201 CRM_Core_DAO
::executequery($sql);
207 * Get timezone from CMS
208 * @return boolean|string
211 * Get timezone from Drupal
212 * @return boolean|string
214 function getTimeZoneOffset(){
215 $timezone = $this->getTimeZoneString();
217 $tzObj = new DateTimeZone($timezone);
218 $dateTime = new DateTime("now", $tzObj);
219 $tz = $tzObj->getOffset($dateTime);
225 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
227 if($timeZoneOffset > 0){
228 $timeZoneOffset = '+' . $timeZoneOffset;
230 return $timeZoneOffset;
235 * Over-ridable function to get timezone as a string eg.
236 * @return string Timezone e.g. 'America/Los_Angeles'
238 function getTimeZoneString() {
239 return date_default_timezone_get();
243 * Get Unique Identifier from UserFramework system (CMS)
244 * @param object $user object as described by the User Framework
245 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
248 function getUniqueIdentifierFromUserObject($user) {}
251 * Get User ID from UserFramework system (CMS)
252 * @param object $user object as described by the User Framework
253 * @return mixed <NULL, number>
256 function getUserIDFromUserObject($user) {}
259 * Get currently logged in user uf id.
261 * @return int $userID logged in user uf id.
263 function getLoggedInUfID() {}
266 * Get currently logged in user unique identifier - this tends to be the email address or user name.
268 * @return string $userID logged in user unique identifier
270 function getLoggedInUniqueIdentifier() {}
273 * return a UFID (user account ID from the UserFramework / CMS system being based on the user object
274 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
275 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
278 * Note there is already a function getUFId which takes $username as a param - we could add $user
279 * as a second param to it but it seems messy - just overloading it because the name is taken
280 * @param object $user
281 * @return int $ufid - user ID of UF System
283 function getBestUFID($user = NULL) {
285 return $this->getUserIDFromUserObject($user);
287 return $this->getLoggedInUfID();
291 * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
292 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
293 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
296 * @param object $user
297 * @return string $uniqueIdentifier - unique identifier from the UF System
299 function getBestUFUniqueIdentifier($user = NULL) {
301 return $this->getUniqueIdentifierFromUserObject($user);
303 return $this->getLoggedInUniqueIdentifier();
307 * Get Url to view user record
308 * @param integer $contactID Contact ID
312 function getUserRecordUrl($contactID) {
316 * Is the current user permitted to add a user
319 function checkPermissionAddUser() {
324 * output code from error function
325 * @param string $content
327 function outputError($content) {
328 echo CRM_Utils_System
::theme($content);
334 function logger($message) {