4ed43e16b9340a1545a21880414d61424ee574b4
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
53 public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
56 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
57 // but the parts should be copied into cleaner subclass implementations
58 $config = CRM_Core_Config
::singleton();
60 $config->userSystem
->is_drupal
&&
61 function_exists('theme') &&
65 drupal_set_breadcrumb('');
66 drupal_maintenance_theme();
67 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
68 CRM_Utils_System
::addHTMLHead($region->render(''));
70 print theme('maintenance_page', array('content' => $content));
73 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
77 $config = &CRM_Core_Config
::singleton();
80 $config->userFramework
== 'WordPress'
83 require_once (ABSPATH
. 'wp-admin/admin-header.php');
86 // FIX ME: we need to figure out to replace civicrm content on the frontend pages
101 public function getDefaultBlockLocation() {
108 public function getVersion() {
113 * Format the url as per language Negotiation.
117 * @param bool $addLanguagePart
118 * @param bool $removeLanguagePart
120 * @return string $url, formatted url.
123 function languageNegotiationURL(
125 $addLanguagePart = TRUE,
126 $removeLanguagePart = FALSE
132 * Determine the location of the CMS root.
134 * @return string|NULL local file system path to CMS root, or NULL if it cannot be determined
136 public function cmsRootPath() {
141 * Get user login URL for hosting CMS (method declared in each CMS system class)
143 * @param string $destination - if present, add destination to querystring (works for Drupal only)
145 * @return string - loginURL for the current CMS
148 public abstract function getLoginURL($destination = '');
151 * Determine the native ID of the CMS user
153 * @param string $username
155 * @throws CRM_Core_Exception
158 public function getUfId($username) {
159 $className = get_class($this);
160 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
164 * Set a init session with user object
166 * @param array $data array with user specific data
169 public function setUserSession($data) {
170 list($userID, $ufID) = $data;
171 $session = CRM_Core_Session
::singleton();
172 $session->set('ufID', $ufID);
173 $session->set('userID', $userID);
177 * Reset any system caches that may be required for proper CiviCRM
180 public function flush() {
185 * Flush css/js caches
187 public function clearResourceCache() {
192 * Return default Site Settings
196 * @return array array
197 * - $url, (Joomla - non admin url)
201 public function getDefaultSiteSettings($dir) {
202 $config = CRM_Core_Config
::singleton();
203 $url = $config->userFrameworkBaseURL
;
204 return array($url, NULL, NULL);
208 * Perform any post login activities required by the CMS -
209 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
210 * calls hook_user op 'login' and generates a new session.
212 * @param array params
214 * FIXME: Document values accepted/required by $params
216 public function userLoginFinalize($params = array()){
220 * Set timezone in mysql so that timestamp fields show the correct time
222 public function setMySQLTimeZone(){
223 $timeZoneOffset = $this->getTimeZoneOffset();
225 $sql = "SET time_zone = '$timeZoneOffset'";
226 CRM_Core_DAO
::executequery($sql);
232 * Get timezone from CMS
233 * @return boolean|string
236 * Get timezone from Drupal
237 * @return boolean|string
239 public function getTimeZoneOffset(){
240 $timezone = $this->getTimeZoneString();
242 $tzObj = new DateTimeZone($timezone);
243 $dateTime = new DateTime("now", $tzObj);
244 $tz = $tzObj->getOffset($dateTime);
250 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
252 if($timeZoneOffset > 0){
253 $timeZoneOffset = '+' . $timeZoneOffset;
255 return $timeZoneOffset;
260 * Over-ridable function to get timezone as a string eg.
261 * @return string Timezone e.g. 'America/Los_Angeles'
263 public function getTimeZoneString() {
264 return date_default_timezone_get();
268 * Get Unique Identifier from UserFramework system (CMS)
269 * @param object $user object as described by the User Framework
270 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
273 public function getUniqueIdentifierFromUserObject($user) {}
276 * Get User ID from UserFramework system (CMS)
277 * @param object $user object as described by the User Framework
278 * @return mixed <NULL, number>
281 public function getUserIDFromUserObject($user) {}
284 * Get currently logged in user uf id.
286 * @return int $userID logged in user uf id.
288 public function getLoggedInUfID() {}
291 * Get currently logged in user unique identifier - this tends to be the email address or user name.
293 * @return string $userID logged in user unique identifier
295 public function getLoggedInUniqueIdentifier() {}
298 * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
299 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
300 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
303 * Note there is already a function getUFId which takes $username as a param - we could add $user
304 * as a second param to it but it seems messy - just overloading it because the name is taken
305 * @param object $user
306 * @return int $ufid - user ID of UF System
308 public function getBestUFID($user = NULL) {
310 return $this->getUserIDFromUserObject($user);
312 return $this->getLoggedInUfID();
316 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
317 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
318 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
321 * @param object $user
322 * @return string $uniqueIdentifier - unique identifier from the UF System
324 public function getBestUFUniqueIdentifier($user = NULL) {
326 return $this->getUniqueIdentifierFromUserObject($user);
328 return $this->getLoggedInUniqueIdentifier();
332 * Get Url to view user record
333 * @param integer $contactID Contact ID
337 public function getUserRecordUrl($contactID) {
341 * Is the current user permitted to add a user
344 public function checkPermissionAddUser() {
349 * Output code from error function
350 * @param string $content
352 public function outputError($content) {
353 echo CRM_Utils_System
::theme($content);
359 public function logger($message) {
364 * Append to coreResourcesList
366 public function appendCoreResources(&$list) {}