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 * TRUE, if the CMS is Drupal.
15 var $is_drupal = FALSE;
18 * 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
19 * functions and leave the codebase oblivious to the type of CMS
23 * TRUE, if the CMS is Joomla!.
25 var $is_joomla = FALSE;
28 * 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
29 * functions and leave the codebase oblivious to the type of CMS
33 * TRUE, if the CMS is WordPress.
35 var $is_wordpress = FALSE;
38 * Does this CMS / UF support a CMS specific logging mechanism?
39 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
42 var $supports_UF_Logging = FALSE;
46 * TRUE, if the CMS allows CMS forms to be extended by hooks.
48 var $supports_form_extensions = FALSE;
51 * If we are using a theming system, invoke theme, else just print the
54 * @param string $content
55 * The content that will be themed.
57 * Are we displaying to the screen or bypassing theming?.
58 * @param bool $maintenance
59 * For maintenance mode.
63 * NULL, If $print is FALSE, and some other criteria match up.
64 * The themed string, otherwise.
66 * @todo The return value is inconsistent.
67 * @todo Better to always return, and never print.
69 public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
72 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
73 // but the parts should be copied into cleaner subclass implementations
74 $config = CRM_Core_Config
::singleton();
76 $config->userSystem
->is_drupal
&&
77 function_exists('theme') &&
81 drupal_set_breadcrumb('');
82 drupal_maintenance_theme();
83 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
84 CRM_Utils_System
::addHTMLHead($region->render(''));
86 print theme('maintenance_page', array('content' => $content));
89 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
93 $config = &CRM_Core_Config
::singleton();
96 $config->userFramework
== 'WordPress'
98 if (!function_exists('is_admin')) {
99 throw new \
Exception('Function "is_admin()" is missing, even though WordPress is the user framework.');
101 if (!defined('ABSPATH')) {
102 throw new \
Exception('Constant "ABSPATH" is not defined, even though WordPress is the user framework.');
105 require_once ABSPATH
. 'wp-admin/admin-header.php';
108 // FIXME: we need to figure out to replace civicrm content on the frontend pages
124 public function getDefaultBlockLocation() {
131 public function getVersion() {
136 * Format the url as per language Negotiation.
139 * @param bool $addLanguagePart
140 * @param bool $removeLanguagePart
146 function languageNegotiationURL(
148 $addLanguagePart = TRUE,
149 $removeLanguagePart = FALSE
155 * Determine the location of the CMS root.
157 * @return string|null
158 * Local file system path to CMS root, or NULL if it cannot be determined
160 public function cmsRootPath() {
165 * Get user login URL for hosting CMS (method declared in each CMS system class)
167 * @param string $destination
168 * If present, add destination to querystring (works for Drupal only).
171 * loginURL for the current CMS
174 public abstract function getLoginURL($destination = '');
177 * Determine the native ID of the CMS user
179 * @param string $username
181 * @throws CRM_Core_Exception
184 public function getUfId($username) {
185 $className = get_class($this);
186 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
190 * Set a init session with user object
193 * Array with user specific data
195 public function setUserSession($data) {
196 list($userID, $ufID) = $data;
197 $session = CRM_Core_Session
::singleton();
198 $session->set('ufID', $ufID);
199 $session->set('userID', $userID);
203 * Reset any system caches that may be required for proper CiviCRM
206 public function flush() {
211 * Flush css/js caches
213 public function clearResourceCache() {
218 * Return default Site Settings
223 * - $url, (Joomla - non admin url)
227 public function getDefaultSiteSettings($dir) {
228 $config = CRM_Core_Config
::singleton();
229 $url = $config->userFrameworkBaseURL
;
230 return array($url, NULL, NULL);
234 * Perform any post login activities required by the CMS -
235 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
236 * calls hook_user op 'login' and generates a new session.
238 * @param array $params
240 * FIXME: Document values accepted/required by $params
242 public function userLoginFinalize($params = array()) {
246 * Set timezone in mysql so that timestamp fields show the correct time
248 public function setMySQLTimeZone() {
249 $timeZoneOffset = $this->getTimeZoneOffset();
250 if ($timeZoneOffset) {
251 $sql = "SET time_zone = '$timeZoneOffset'";
252 CRM_Core_DAO
::executequery($sql);
258 * Get timezone from CMS
260 * @return string|false|null
262 public function getTimeZoneOffset() {
263 $timezone = $this->getTimeZoneString();
265 $tzObj = new DateTimeZone($timezone);
266 $dateTime = new DateTime("now", $tzObj);
267 $tz = $tzObj->getOffset($dateTime);
273 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz / 60) %
60));
275 if ($timeZoneOffset > 0) {
276 $timeZoneOffset = '+' . $timeZoneOffset;
278 return $timeZoneOffset;
284 * Over-ridable function to get timezone as a string eg.
287 * Time zone, e.g. 'America/Los_Angeles'
289 public function getTimeZoneString() {
290 return date_default_timezone_get();
294 * Get Unique Identifier from UserFramework system (CMS)
295 * @param object $user
296 * Object as described by the User Framework.
297 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
300 public function getUniqueIdentifierFromUserObject($user) {
304 * Get User ID from UserFramework system (CMS)
305 * @param object $user
306 * Object as described by the User Framework.
307 * @return mixed <NULL, number>
310 public function getUserIDFromUserObject($user) {
314 * Get currently logged in user uf id.
317 * $userID logged in user uf id.
319 public function getLoggedInUfID() {
323 * Get currently logged in user unique identifier - this tends to be the email address or user name.
326 * logged in user unique identifier
328 public function getLoggedInUniqueIdentifier() {
332 * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
333 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
334 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
337 * Note there is already a function getUFId which takes $username as a param - we could add $user
338 * as a second param to it but it seems messy - just overloading it because the name is taken
339 * @param object $user
341 * $ufid - user ID of UF System
343 public function getBestUFID($user = NULL) {
345 return $this->getUserIDFromUserObject($user);
347 return $this->getLoggedInUfID();
351 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
352 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
353 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
356 * @param object $user
358 * unique identifier from the UF System
360 public function getBestUFUniqueIdentifier($user = NULL) {
362 return $this->getUniqueIdentifierFromUserObject($user);
364 return $this->getLoggedInUniqueIdentifier();
368 * Get Url to view user record
369 * @param int $contactID
374 public function getUserRecordUrl($contactID) {
378 * Is the current user permitted to add a user
381 public function checkPermissionAddUser() {
386 * Output code from error function
387 * @param string $content
389 public function outputError($content) {
390 echo CRM_Utils_System
::theme($content);
396 public function logger($message) {
401 * Append to coreResourcesList
403 public function appendCoreResources(&$list) {