c56c371bc6fbff37a9a22cb0df60c58ea815e112
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 the content that will be themed
55 * @param boolean $print are we displaying to the screen or bypassing theming?
56 * @param boolean $maintenance for maintenance mode
60 * NULL, If $print is FALSE, and some other criteria match up.
61 * The themed string, otherwise.
63 * @todo The return value is inconsistent.
64 * @todo Better to always return, and never print.
66 public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
69 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
70 // but the parts should be copied into cleaner subclass implementations
71 $config = CRM_Core_Config
::singleton();
73 $config->userSystem
->is_drupal
&&
74 function_exists('theme') &&
78 drupal_set_breadcrumb('');
79 drupal_maintenance_theme();
80 if ($region = CRM_Core_Region
::instance('html-header', FALSE)) {
81 CRM_Utils_System
::addHTMLHead($region->render(''));
83 print theme('maintenance_page', array('content' => $content));
86 $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
90 $config = &CRM_Core_Config
::singleton();
93 $config->userFramework
== 'WordPress'
95 if (!function_exists('is_admin')) {
96 throw new \
Exception('Function "is_admin()" is missing, even though WordPress is the user framework.');
98 if (!defined('ABSPATH')) {
99 throw new \
Exception('Constant "ABSPATH" is not defined, even though WordPress is the user framework.');
102 require_once (ABSPATH
. 'wp-admin/admin-header.php');
105 // FIXME: we need to figure out to replace civicrm content on the frontend pages
121 public function getDefaultBlockLocation() {
128 public function getVersion() {
133 * Format the url as per language Negotiation.
136 * @param bool $addLanguagePart
137 * @param bool $removeLanguagePart
143 function languageNegotiationURL(
145 $addLanguagePart = TRUE,
146 $removeLanguagePart = FALSE
152 * Determine the location of the CMS root.
154 * @return string|null
155 * Local file system path to CMS root, or NULL if it cannot be determined
157 public function cmsRootPath() {
162 * Get user login URL for hosting CMS (method declared in each CMS system class)
164 * @param string $destination - if present, add destination to querystring (works for Drupal only)
166 * @return string - loginURL for the current CMS
169 public abstract function getLoginURL($destination = '');
172 * Determine the native ID of the CMS user
174 * @param string $username
176 * @throws CRM_Core_Exception
179 public function getUfId($username) {
180 $className = get_class($this);
181 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
185 * Set a init session with user object
188 * Array with user specific data
190 public function setUserSession($data) {
191 list($userID, $ufID) = $data;
192 $session = CRM_Core_Session
::singleton();
193 $session->set('ufID', $ufID);
194 $session->set('userID', $userID);
198 * Reset any system caches that may be required for proper CiviCRM
201 public function flush() {
206 * Flush css/js caches
208 public function clearResourceCache() {
213 * Return default Site Settings
218 * - $url, (Joomla - non admin url)
222 public function getDefaultSiteSettings($dir) {
223 $config = CRM_Core_Config
::singleton();
224 $url = $config->userFrameworkBaseURL
;
225 return array($url, NULL, NULL);
229 * Perform any post login activities required by the CMS -
230 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
231 * calls hook_user op 'login' and generates a new session.
233 * @param array $params
235 * FIXME: Document values accepted/required by $params
237 public function userLoginFinalize($params = array()){
241 * Set timezone in mysql so that timestamp fields show the correct time
243 public function setMySQLTimeZone(){
244 $timeZoneOffset = $this->getTimeZoneOffset();
246 $sql = "SET time_zone = '$timeZoneOffset'";
247 CRM_Core_DAO
::executequery($sql);
253 * Get timezone from CMS
255 * @return string|false|null
257 public function getTimeZoneOffset(){
258 $timezone = $this->getTimeZoneString();
260 $tzObj = new DateTimeZone($timezone);
261 $dateTime = new DateTime("now", $tzObj);
262 $tz = $tzObj->getOffset($dateTime);
268 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
270 if ($timeZoneOffset > 0) {
271 $timeZoneOffset = '+' . $timeZoneOffset;
273 return $timeZoneOffset;
279 * Over-ridable function to get timezone as a string eg.
282 * Time zone, e.g. 'America/Los_Angeles'
284 public function getTimeZoneString() {
285 return date_default_timezone_get();
289 * Get Unique Identifier from UserFramework system (CMS)
290 * @param object $user object as described by the User Framework
291 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
294 public function getUniqueIdentifierFromUserObject($user) {}
297 * Get User ID from UserFramework system (CMS)
298 * @param object $user object as described by the User Framework
299 * @return mixed <NULL, number>
302 public function getUserIDFromUserObject($user) {}
305 * Get currently logged in user uf id.
307 * @return int $userID logged in user uf id.
309 public function getLoggedInUfID() {}
312 * Get currently logged in user unique identifier - this tends to be the email address or user name.
314 * @return string $userID logged in user unique identifier
316 public function getLoggedInUniqueIdentifier() {}
319 * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
320 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
321 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
324 * Note there is already a function getUFId which takes $username as a param - we could add $user
325 * as a second param to it but it seems messy - just overloading it because the name is taken
326 * @param object $user
327 * @return int $ufid - user ID of UF System
329 public function getBestUFID($user = NULL) {
331 return $this->getUserIDFromUserObject($user);
333 return $this->getLoggedInUfID();
337 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
338 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
339 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
342 * @param object $user
343 * @return string $uniqueIdentifier - unique identifier from the UF System
345 public function getBestUFUniqueIdentifier($user = NULL) {
347 return $this->getUniqueIdentifierFromUserObject($user);
349 return $this->getLoggedInUniqueIdentifier();
353 * Get Url to view user record
354 * @param integer $contactID Contact ID
358 public function getUserRecordUrl($contactID) {
362 * Is the current user permitted to add a user
365 public function checkPermissionAddUser() {
370 * Output code from error function
371 * @param string $content
373 public function outputError($content) {
374 echo CRM_Utils_System
::theme($content);
380 public function logger($message) {
385 * Append to coreResourcesList
387 public function appendCoreResources(&$list) {}