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'
96 require_once (ABSPATH
. 'wp-admin/admin-header.php');
99 // FIXME: we need to figure out to replace civicrm content on the frontend pages
115 public function getDefaultBlockLocation() {
122 public function getVersion() {
127 * Format the url as per language Negotiation.
130 * @param bool $addLanguagePart
131 * @param bool $removeLanguagePart
137 function languageNegotiationURL(
139 $addLanguagePart = TRUE,
140 $removeLanguagePart = FALSE
146 * Determine the location of the CMS root.
148 * @return string|null
149 * Local file system path to CMS root, or NULL if it cannot be determined
151 public function cmsRootPath() {
156 * Get user login URL for hosting CMS (method declared in each CMS system class)
158 * @param string $destination - if present, add destination to querystring (works for Drupal only)
160 * @return string - loginURL for the current CMS
163 public abstract function getLoginURL($destination = '');
166 * Determine the native ID of the CMS user
168 * @param string $username
170 * @throws CRM_Core_Exception
173 public function getUfId($username) {
174 $className = get_class($this);
175 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
179 * Set a init session with user object
182 * Array with user specific data
184 public function setUserSession($data) {
185 list($userID, $ufID) = $data;
186 $session = CRM_Core_Session
::singleton();
187 $session->set('ufID', $ufID);
188 $session->set('userID', $userID);
192 * Reset any system caches that may be required for proper CiviCRM
195 public function flush() {
200 * Flush css/js caches
202 public function clearResourceCache() {
207 * Return default Site Settings
212 * - $url, (Joomla - non admin url)
216 public function getDefaultSiteSettings($dir) {
217 $config = CRM_Core_Config
::singleton();
218 $url = $config->userFrameworkBaseURL
;
219 return array($url, NULL, NULL);
223 * Perform any post login activities required by the CMS -
224 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
225 * calls hook_user op 'login' and generates a new session.
227 * @param array $params
229 * FIXME: Document values accepted/required by $params
231 public function userLoginFinalize($params = array()){
235 * Set timezone in mysql so that timestamp fields show the correct time
237 public function setMySQLTimeZone(){
238 $timeZoneOffset = $this->getTimeZoneOffset();
240 $sql = "SET time_zone = '$timeZoneOffset'";
241 CRM_Core_DAO
::executequery($sql);
247 * Get timezone from CMS
249 * @return string|false|null
251 public function getTimeZoneOffset(){
252 $timezone = $this->getTimeZoneString();
254 $tzObj = new DateTimeZone($timezone);
255 $dateTime = new DateTime("now", $tzObj);
256 $tz = $tzObj->getOffset($dateTime);
262 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60
));
264 if ($timeZoneOffset > 0) {
265 $timeZoneOffset = '+' . $timeZoneOffset;
267 return $timeZoneOffset;
273 * Over-ridable function to get timezone as a string eg.
276 * Time zone, e.g. 'America/Los_Angeles'
278 public function getTimeZoneString() {
279 return date_default_timezone_get();
283 * Get Unique Identifier from UserFramework system (CMS)
284 * @param object $user object as described by the User Framework
285 * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
288 public function getUniqueIdentifierFromUserObject($user) {}
291 * Get User ID from UserFramework system (CMS)
292 * @param object $user object as described by the User Framework
293 * @return mixed <NULL, number>
296 public function getUserIDFromUserObject($user) {}
299 * Get currently logged in user uf id.
301 * @return int $userID logged in user uf id.
303 public function getLoggedInUfID() {}
306 * Get currently logged in user unique identifier - this tends to be the email address or user name.
308 * @return string $userID logged in user unique identifier
310 public function getLoggedInUniqueIdentifier() {}
313 * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
314 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
315 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
318 * Note there is already a function getUFId which takes $username as a param - we could add $user
319 * as a second param to it but it seems messy - just overloading it because the name is taken
320 * @param object $user
321 * @return int $ufid - user ID of UF System
323 public function getBestUFID($user = NULL) {
325 return $this->getUserIDFromUserObject($user);
327 return $this->getLoggedInUfID();
331 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
332 * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
333 * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
336 * @param object $user
337 * @return string $uniqueIdentifier - unique identifier from the UF System
339 public function getBestUFUniqueIdentifier($user = NULL) {
341 return $this->getUniqueIdentifierFromUserObject($user);
343 return $this->getLoggedInUniqueIdentifier();
347 * Get Url to view user record
348 * @param integer $contactID Contact ID
352 public function getUserRecordUrl($contactID) {
356 * Is the current user permitted to add a user
359 public function checkPermissionAddUser() {
364 * Output code from error function
365 * @param string $content
367 public function outputError($content) {
368 echo CRM_Utils_System
::theme($content);
374 public function logger($message) {
379 * Append to coreResourcesList
381 public function appendCoreResources(&$list) {}