CRM-16408 add check for prior and current location for variable
[civicrm-core.git] / CRM / Utils / System / Base.php
CommitLineData
6a488035
TO
1<?php
2
3/**
4 * Base class for UF system integrations
5 */
6abstract class CRM_Utils_System_Base {
2b0e7d03 7
4caaa696 8 /**
2b0e7d03
EM
9 * Deprecated property to check if this is a drupal install.
10 *
11 * The correct method is to have functions on the UF classes for all UF specific
4caaa696 12 * functions and leave the codebase oblivious to the type of CMS
7cdf0f5b 13 *
4caaa696
EM
14 * @deprecated
15 * @var bool
7cdf0f5b 16 * TRUE, if the CMS is Drupal.
4caaa696 17 */
6a488035 18 var $is_drupal = FALSE;
4caaa696
EM
19
20 /**
100fef9d 21 * 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
4caaa696 22 * functions and leave the codebase oblivious to the type of CMS
7cdf0f5b 23 *
4caaa696
EM
24 * @deprecated
25 * @var bool
7cdf0f5b 26 * TRUE, if the CMS is Joomla!.
4caaa696 27 */
6a488035 28 var $is_joomla = FALSE;
4caaa696 29
7cdf0f5b
AH
30 /**
31 * 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
32 * functions and leave the codebase oblivious to the type of CMS
33 *
34 * @deprecated
35 * @var bool
36 * TRUE, if the CMS is WordPress.
37 */
6a488035
TO
38 var $is_wordpress = FALSE;
39
e0dd98a5
EM
40 /**
41 * Does this CMS / UF support a CMS specific logging mechanism?
42 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
43 * @var bool
44 */
45 var $supports_UF_Logging = FALSE;
46
7cdf0f5b
AH
47 /**
48 * @var bool
49 * TRUE, if the CMS allows CMS forms to be extended by hooks.
6a488035
TO
50 */
51 var $supports_form_extensions = FALSE;
52
d4330c62
TO
53 public function initialize() {
54 if (\CRM_Utils_System::isSSL()) {
55 $this->mapConfigToSSL();
56 }
57 }
58
17f443df 59 /**
fe482240 60 * Append an additional breadcrumb tag to the existing breadcrumb.
17f443df
CW
61 *
62 * @param array $breadCrumbs
63 */
64 public function appendBreadCrumb($breadCrumbs) {
65 }
66
67 /**
fe482240 68 * Reset an additional breadcrumb tag to the existing breadcrumb.
17f443df
CW
69 */
70 public function resetBreadCrumb() {
71 }
72
73 /**
fe482240 74 * Append a string to the head of the html file.
17f443df
CW
75 *
76 * @param string $head
77 * The new string to be appended.
78 */
79 public function addHTMLHead($head) {
80 }
81
82 /**
fe482240 83 * Rewrite various system urls to https.
17f443df
CW
84 */
85 public function mapConfigToSSL() {
86 // dont need to do anything, let CMS handle their own switch to SSL
87 }
88
89 /**
fe482240 90 * Figure out the post url for QuickForm.
17f443df
CW
91 *
92 * @param string $action
93 * The default url if one is pre-specified.
94 *
95 * @return string
96 * The url to post the form.
97 */
98 public function postURL($action) {
99 $config = CRM_Core_Config::singleton();
100 if (!empty($action)) {
101 return $action;
102 }
103
104 return $this->url(CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET),
105 NULL, TRUE, NULL, FALSE
106 );
107 }
108
109 /**
110 * Generate the url string to a CiviCRM path.
111 *
112 * @param string $path
113 * The path being linked to, such as "civicrm/add".
114 * @param string $query
115 * A query string to append to the link.
116 * @param bool $absolute
117 * Whether to force the output to be an absolute link (beginning with http).
118 * Useful for links that will be displayed outside the site, such as in an RSS feed.
119 * @param string $fragment
120 * A fragment identifier (named anchor) to append to the link.
121 * @param bool $htmlize
122 * Whether to encode special html characters such as &.
123 * @param bool $frontend
124 * This link should be to the CMS front end (applies to WP & Joomla).
125 * @param bool $forceBackend
126 * This link should be to the CMS back end (applies to WP & Joomla).
127 *
128 * @return string
129 */
130 public function url(
131 $path = NULL,
132 $query = NULL,
133 $absolute = FALSE,
134 $fragment = NULL,
135 $htmlize = TRUE,
136 $frontend = FALSE,
137 $forceBackend = FALSE
138 ) {
139 return NULL;
140 }
141
142 /**
fe482240 143 * Authenticate the user against the CMS db.
17f443df
CW
144 *
145 * @param string $name
146 * The user name.
147 * @param string $password
148 * The password for the above user.
149 * @param bool $loadCMSBootstrap
150 * Load cms bootstrap?.
151 * @param string $realPath
152 * Filename of script
153 *
154 * @return array|bool
155 * [contactID, ufID, unique string] else false if no auth
156 */
157 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
158 return FALSE;
159 }
160
161 /**
fe482240 162 * Set a message in the CMS to display to a user.
17f443df
CW
163 *
164 * @param string $message
165 * The message to set.
166 */
167 public function setMessage($message) {
168 }
169
170 /**
fe482240 171 * Load user into session.
17f443df 172 *
2b0e7d03 173 * @param obj $user
17f443df
CW
174 *
175 * @return bool
176 */
177 public function loadUser($user) {
178 return TRUE;
179 }
180
181 /**
2b0e7d03 182 * Immediately stop script execution and display a 401 "Access Denied" page.
17f443df
CW
183 */
184 public function permissionDenied() {
185 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
186 }
187
188 /**
2b0e7d03 189 * Immediately stop script execution, log out the user and redirect to the home page.
17f443df
CW
190 *
191 * @deprecated
192 * This function should be removed in favor of linking to the CMS's logout page
193 */
194 public function logout() {
195 }
196
197 /**
198 * Clear CMS caches related to the user registration/profile forms.
199 * Used when updating/embedding profiles on CMS user forms.
200 * @see CRM-3600
201 */
202 public function updateCategories() {
203 }
204
205 /**
fe482240 206 * Get the locale set in the CMS.
17f443df
CW
207 *
208 * @return string|null
209 * Locale or null for none
210 */
211 public function getUFLocale() {
212 return NULL;
213 }
214
6a488035 215 /**
2b0e7d03 216 * If we are using a theming system, invoke theme, else just print the content.
6a488035 217 *
77855840
TO
218 * @param string $content
219 * The content that will be themed.
220 * @param bool $print
221 * Are we displaying to the screen or bypassing theming?.
222 * @param bool $maintenance
223 * For maintenance mode.
6a488035 224 *
7cdf0f5b
AH
225 * @throws Exception
226 * @return string|null
227 * NULL, If $print is FALSE, and some other criteria match up.
228 * The themed string, otherwise.
26659f0c
AH
229 *
230 * @todo The return value is inconsistent.
231 * @todo Better to always return, and never print.
6a488035 232 */
00be9182 233 public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
6a488035
TO
234 $ret = FALSE;
235
236 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
237 // but the parts should be copied into cleaner subclass implementations
1e305b0b
DL
238 $config = CRM_Core_Config::singleton();
239 if (
240 $config->userSystem->is_drupal &&
241 function_exists('theme') &&
242 !$print
243 ) {
6a488035
TO
244 if ($maintenance) {
245 drupal_set_breadcrumb('');
246 drupal_maintenance_theme();
10221f8a
TO
247 if ($region = CRM_Core_Region::instance('html-header', FALSE)) {
248 CRM_Utils_System::addHTMLHead($region->render(''));
249 }
6a488035
TO
250 print theme('maintenance_page', array('content' => $content));
251 exit();
252 }
2b0e7d03
EM
253 // TODO: Figure out why D7 returns but everyone else prints
254 $ret = TRUE;
6a488035
TO
255 }
256 $out = $content;
257
258 $config = &CRM_Core_Config::singleton();
1e305b0b
DL
259 if (
260 !$print &&
6a488035
TO
261 $config->userFramework == 'WordPress'
262 ) {
aecede9a
AH
263 if (!function_exists('is_admin')) {
264 throw new \Exception('Function "is_admin()" is missing, even though WordPress is the user framework.');
265 }
266 if (!defined('ABSPATH')) {
267 throw new \Exception('Constant "ABSPATH" is not defined, even though WordPress is the user framework.');
268 }
6a488035 269 if (is_admin()) {
e7292422 270 require_once ABSPATH . 'wp-admin/admin-header.php';
6a488035
TO
271 }
272 else {
7cdf0f5b 273 // FIXME: we need to figure out to replace civicrm content on the frontend pages
6a488035
TO
274 }
275 }
276
277 if ($ret) {
278 return $out;
279 }
280 else {
281 print $out;
85c5f34c 282 return NULL;
6a488035
TO
283 }
284 }
285
bb3a214a
EM
286 /**
287 * @return string
288 */
00be9182 289 public function getDefaultBlockLocation() {
6a488035
TO
290 return 'left';
291 }
292
d4330c62
TO
293 public function getAbsoluteBaseURL() {
294 if (!defined('CIVICRM_UF_BASEURL')) {
295 return FALSE;
296 }
297
298 $url = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
299
300 //format url for language negotiation, CRM-7803
301 $url = $this->languageNegotiationURL($url);
302
303 if (CRM_Utils_System::isSSL()) {
304 $url = str_replace('http://', 'https://', $url);
305 }
306
307 return $url;
308 }
309
310 public function getRelativeBaseURL() {
311 $absoluteBaseURL = $this->getAbsoluteBaseURL();
312 if ($absoluteBaseURL === FALSE) {
313 return FALSE;
314 }
315 $parts = parse_url($absoluteBaseURL);
316 return $parts['path'];
317 //$this->useFrameworkRelativeBase = empty($base['path']) ? '/' : $base['path'];
318 }
319
bb3a214a 320 /**
fe482240 321 * Get CMS Version.
17f443df 322 *
bb3a214a
EM
323 * @return string
324 */
00be9182 325 public function getVersion() {
6a488035
TO
326 return 'Unknown';
327 }
328
329 /**
330 * Format the url as per language Negotiation.
331 *
332 * @param string $url
77b97be7
EM
333 * @param bool $addLanguagePart
334 * @param bool $removeLanguagePart
335 *
7cdf0f5b
AH
336 * @return string
337 * Formatted url.
6a488035 338 */
d5cc0fc2 339 public function languageNegotiationURL(
6a488035
TO
340 $url,
341 $addLanguagePart = TRUE,
342 $removeLanguagePart = FALSE
343 ) {
344 return $url;
345 }
346
e29aefb4
TO
347 /**
348 * Determine the location of the CMS root.
349 *
7cdf0f5b
AH
350 * @return string|null
351 * Local file system path to CMS root, or NULL if it cannot be determined
6a488035 352 */
00be9182 353 public function cmsRootPath() {
e29aefb4 354 return NULL;
6a488035
TO
355 }
356
17f443df
CW
357 /**
358 * Create a user in the CMS.
359 *
360 * @param array $params
361 * @param string $mail
362 * Email id for cms user.
363 *
364 * @return int|bool
365 * uid if user exists, false otherwise
366 */
367 public function createUser(&$params, $mail) {
368 return FALSE;
369 }
370
371 /**
372 * Update a user's email address in the CMS.
373 *
374 * @param int $ufID
375 * User ID in CMS.
376 * @param string $email
377 * Primary contact email address.
378 */
379 public function updateCMSName($ufID, $email) {
380 }
381
382 /**
383 * Check if user is logged in to the CMS.
384 *
385 * @return bool
386 */
387 public function isUserLoggedIn() {
388 return FALSE;
389 }
390
6a488035
TO
391 /**
392 * Get user login URL for hosting CMS (method declared in each CMS system class)
393 *
77855840
TO
394 * @param string $destination
395 * If present, add destination to querystring (works for Drupal only).
6a488035 396 *
a6c01b45
CW
397 * @return string
398 * loginURL for the current CMS
6a488035
TO
399 */
400 public abstract function getLoginURL($destination = '');
401
17f443df 402 /**
2b0e7d03
EM
403 * Get the login destination string.
404 *
405 * When this is passed in the URL the user will be directed to it after filling in the CMS form.
17f443df
CW
406 *
407 * @param CRM_Core_Form $form
408 * Form object representing the 'current' form - to which the user will be returned.
2b0e7d03 409 *
17f443df
CW
410 * @return string|NULL
411 * destination value for URL
412 */
413 public function getLoginDestination(&$form) {
414 return NULL;
415 }
416
46b6363c 417 /**
fe482240 418 * Determine the native ID of the CMS user.
46b6363c 419 *
100fef9d 420 * @param string $username
f4aaa82a
EM
421 *
422 * @throws CRM_Core_Exception
46b6363c 423 */
00be9182 424 public function getUfId($username) {
46b6363c
TO
425 $className = get_class($this);
426 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
427 }
428
a7c57397
TO
429 public function setUFLocale($civicrm_language) {
430 return TRUE;
431 }
432
5d0eb86b 433 /**
fe482240 434 * Set a init session with user object.
5d0eb86b 435 *
7cdf0f5b
AH
436 * @param array $data
437 * Array with user specific data
5d0eb86b 438 */
00be9182 439 public function setUserSession($data) {
5d0eb86b
BS
440 list($userID, $ufID) = $data;
441 $session = CRM_Core_Session::singleton();
442 $session->set('ufID', $ufID);
443 $session->set('userID', $userID);
444 }
d8a4acc0
C
445
446 /**
2b0e7d03 447 * Reset any system caches that may be required for proper CiviCRM integration.
d8a4acc0 448 */
00be9182 449 public function flush() {
d8a4acc0
C
450 // nullop by default
451 }
82d9c21e 452
f091327b 453 /**
2b0e7d03 454 * Flush css/js caches.
f091327b 455 */
00be9182 456 public function clearResourceCache() {
f091327b
CW
457 // nullop by default
458 }
459
17f443df 460 /**
fe482240 461 * Add a script file.
17f443df
CW
462 *
463 * Note: This function is not to be called directly
464 * @see CRM_Core_Region::render()
465 *
2b0e7d03 466 * @param string $url absolute path to file
17f443df
CW
467 * @param string $region
468 * location within the document: 'html-header', 'page-header', 'page-footer'.
469 *
470 * @return bool
471 * TRUE if we support this operation in this CMS, FALSE otherwise
472 */
473 public function addScriptUrl($url, $region) {
474 return FALSE;
475 }
476
477 /**
fe482240 478 * Add an inline script.
17f443df
CW
479 *
480 * Note: This function is not to be called directly
481 * @see CRM_Core_Region::render()
482 *
2b0e7d03 483 * @param string $code javascript code
17f443df
CW
484 * @param string $region
485 * location within the document: 'html-header', 'page-header', 'page-footer'.
486 *
487 * @return bool
488 * TRUE if we support this operation in this CMS, FALSE otherwise
489 */
490 public function addScript($code, $region) {
491 return FALSE;
492 }
493
494 /**
fe482240 495 * Add a css file.
17f443df
CW
496 *
497 * Note: This function is not to be called directly
498 * @see CRM_Core_Region::render()
499 *
2b0e7d03 500 * @param string $url absolute path to file
17f443df
CW
501 * @param string $region
502 * location within the document: 'html-header', 'page-header', 'page-footer'.
503 *
504 * @return bool
505 * TRUE if we support this operation in this CMS, FALSE otherwise
506 */
507 public function addStyleUrl($url, $region) {
508 return FALSE;
509 }
510
511 /**
fe482240 512 * Add an inline style.
17f443df
CW
513 *
514 * Note: This function is not to be called directly
515 * @see CRM_Core_Region::render()
516 *
2b0e7d03 517 * @param string $code css code
17f443df
CW
518 * @param string $region
519 * location within the document: 'html-header', 'page-header', 'page-footer'.
520 *
521 * @return bool
522 * TRUE if we support this operation in this CMS, FALSE otherwise
523 */
524 public function addStyle($code, $region) {
525 return FALSE;
526 }
527
528 /**
fe482240 529 * Sets the title of the page.
17f443df
CW
530 *
531 * @param string $title
532 * Title to set in html header
533 * @param string|null $pageTitle
534 * Title to set in html body (if different)
535 */
536 public function setTitle($title, $pageTitle = NULL) {
537 }
538
c8950569 539 /**
fe482240 540 * Return default Site Settings.
f4aaa82a 541 *
7cdf0f5b 542 * @param string $dir
f4aaa82a 543 *
7cdf0f5b 544 * @return array
d5cc0fc2 545 * - $url, (Joomla - non admin url)
546 * - $siteName,
547 * - $siteRoot
9977c6f5 548 */
00be9182 549 public function getDefaultSiteSettings($dir) {
9977c6f5 550 $config = CRM_Core_Config::singleton();
551 $url = $config->userFrameworkBaseURL;
552 return array($url, NULL, NULL);
553 }
c8950569 554
f6f958e4
TO
555 /**
556 * Determine the default location for file storage.
557 *
558 * FIXME:
559 * 1. This was pulled out from a bigger function. It should be split
560 * into even smaller pieces and marked abstract.
561 * 2. This would be easier to compute by a calling a CMS API, but
562 * for whatever reason Civi gets it from config data.
563 *
564 * @return array
565 * - url: string. ex: "http://example.com/sites/foo.com/files/civicrm"
566 * - path: string. ex: "/var/www/sites/foo.com/files/civicrm"
567 */
568 public function getDefaultFileStorage() {
569 global $civicrm_root;
570 $config = CRM_Core_Config::singleton();
571 $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
572
573 $filesURL = NULL;
574 $filesPath = NULL;
575
576 if ($config->userFramework == 'Joomla') {
577 // gross hack
578 // we need to remove the administrator/ from the end
579 $tempURL = str_replace("/administrator/", "/", $baseURL);
580 $filesURL = $tempURL . "media/civicrm/";
581 }
f6f958e4
TO
582 elseif ($this->is_drupal) {
583 $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
584 if ($siteName) {
585 $filesURL = $baseURL . "sites/$siteName/files/civicrm/";
586 }
587 else {
588 $filesURL = $baseURL . "sites/default/files/civicrm/";
589 }
590 }
591 elseif ($config->userFramework == 'UnitTests') {
592 $filesURL = $baseURL . "sites/default/files/civicrm/";
593 }
594 else {
595 throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
596 }
597
598 return array(
599 'url' => $filesURL,
600 'path' => CRM_Utils_File::baseFilePath(),
601 );
602 }
603
604 /**
605 * Determine the location of the CiviCRM source tree.
606 *
607 * FIXME:
608 * 1. This was pulled out from a bigger function. It should be split
609 * into even smaller pieces and marked abstract.
610 * 2. This would be easier to compute by a calling a CMS API, but
611 * for whatever reason we take the hard way.
612 *
613 * @return array
614 * - url: string. ex: "http://example.com/sites/all/modules/civicrm"
615 * - path: string. ex: "/var/www/sites/all/modules/civicrm"
616 */
617 public function getCiviSourceStorage() {
618 global $civicrm_root;
619 $config = CRM_Core_Config::singleton();
620
621 // Don't use $config->userFrameworkBaseURL; it has garbage on it.
622 // More generally, w shouldn't be using $config here.
623 if (!defined('CIVICRM_UF_BASEURL')) {
624 throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
625 }
626 $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
627 if (CRM_Utils_System::isSSL()) {
628 $baseURL = str_replace('http://', 'https://', $baseURL);
629 }
630
631 if ($config->userFramework == 'Joomla') {
632 $userFrameworkResourceURL = $baseURL . "components/com_civicrm/civicrm/";
633 }
634 elseif ($config->userFramework == 'WordPress') {
635 $userFrameworkResourceURL = $baseURL . "wp-content/plugins/civicrm/civicrm/";
636 }
637 elseif ($this->is_drupal) {
638 // Drupal setting
639 // check and see if we are installed in sites/all (for D5 and above)
640 // we dont use checkURL since drupal generates an error page and throws
641 // the system for a loop on lobo's macosx box
642 // or in modules
643 $cmsPath = $config->userSystem->cmsRootPath();
644 $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '',
645 str_replace('\\', '/', $civicrm_root)
646 );
647
648 $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
649 if ($siteName) {
650 $civicrmDirName = trim(basename($civicrm_root));
651 $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
652 }
653 }
654 else {
655 $userFrameworkResourceURL = NULL;
656 }
657
658 return array(
2c0f1404 659 'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL),
f6f958e4
TO
660 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
661 );
662 }
663
82d9c21e 664 /**
2b0e7d03
EM
665 * Perform any post login activities required by the CMS.
666 *
53980972 667 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
668 * calls hook_user op 'login' and generates a new session.
e43cc689 669 *
7cdf0f5b 670 * @param array $params
95d68223
TO
671 *
672 * FIXME: Document values accepted/required by $params
c8950569 673 */
9b873358 674 public function userLoginFinalize($params = array()) {
82d9c21e 675 }
5a604d61
E
676
677 /**
fe482240 678 * Set timezone in mysql so that timestamp fields show the correct time.
5a604d61 679 */
9b873358 680 public function setMySQLTimeZone() {
5a604d61 681 $timeZoneOffset = $this->getTimeZoneOffset();
9b873358 682 if ($timeZoneOffset) {
5a604d61
E
683 $sql = "SET time_zone = '$timeZoneOffset'";
684 CRM_Core_DAO::executequery($sql);
685 }
686 }
687
6491539b 688
5a604d61 689 /**
fe482240 690 * Get timezone from CMS.
7cdf0f5b
AH
691 *
692 * @return string|false|null
6491539b 693 */
9b873358 694 public function getTimeZoneOffset() {
6491539b 695 $timezone = $this->getTimeZoneString();
8b647c3a 696 if ($timezone) {
030113f0 697 if ($timezone == 'UTC') {
698 // CRM-17072 Let's short-circuit all the zero handling & return it here!
699 return '+00:00';
700 }
6491539b
DL
701 $tzObj = new DateTimeZone($timezone);
702 $dateTime = new DateTime("now", $tzObj);
703 $tz = $tzObj->getOffset($dateTime);
704
8b647c3a
AH
705 if (empty($tz)) {
706 return FALSE;
6491539b
DL
707 }
708
e7292422 709 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz / 60) % 60));
6491539b 710
8b647c3a 711 if ($timeZoneOffset > 0) {
6491539b
DL
712 $timeZoneOffset = '+' . $timeZoneOffset;
713 }
714 return $timeZoneOffset;
715 }
85c5f34c 716 return NULL;
6491539b
DL
717 }
718
719 /**
fe482240 720 * Get timezone as a string.
7cdf0f5b 721 * @return string
17f443df 722 * Timezone string e.g. 'America/Los_Angeles'
6491539b 723 */
00be9182 724 public function getTimeZoneString() {
48ec57ab 725 return date_default_timezone_get();
5a604d61 726 }
2b617cb0
EM
727
728 /**
2b0e7d03
EM
729 * Get Unique Identifier from UserFramework system (CMS).
730 *
77855840
TO
731 * @param object $user
732 * Object as described by the User Framework.
2b0e7d03 733 *
72b3a70c 734 * @return mixed
2b0e7d03 735 * Unique identifier from the user Framework system
2b617cb0 736 */
e7292422 737 public function getUniqueIdentifierFromUserObject($user) {
17f443df 738 return NULL;
e7292422 739 }
2b617cb0 740
32998c82 741 /**
2b0e7d03
EM
742 * Get User ID from UserFramework system (CMS).
743 *
77855840 744 * @param object $user
2b0e7d03 745 *
77855840 746 * Object as described by the User Framework.
17f443df 747 * @return null|int
32998c82 748 */
e7292422 749 public function getUserIDFromUserObject($user) {
17f443df 750 return NULL;
e7292422 751 }
32998c82 752
2b0e7d03
EM
753 /**
754 * Get an array of user details for a contact, containing at minimum the user ID & name.
755 *
756 * @param int $contactID
757 *
758 * @return array
759 * CMS user details including
760 * - id
761 * - name (ie the system user name.
762 */
763 public function getUser($contactID) {
764 $ufMatch = civicrm_api3('UFMatch', 'getsingle', array(
765 'contact_id' => $contactID,
766 'domain_id' => CRM_Core_Config::domainID(),
767 ));
768 return array(
769 'id' => $ufMatch['uf_id'],
770 'name' => $ufMatch['uf_name'],
771 );
772 }
773
32998c82
EM
774 /**
775 * Get currently logged in user uf id.
776 *
17f443df
CW
777 * @return int|null
778 * logged in user uf id.
32998c82 779 */
e7292422 780 public function getLoggedInUfID() {
17f443df 781 return NULL;
e7292422 782 }
32998c82 783
2b617cb0
EM
784 /**
785 * Get currently logged in user unique identifier - this tends to be the email address or user name.
786 *
17f443df 787 * @return string|null
a6c01b45 788 * logged in user unique identifier
2b617cb0 789 */
e7292422 790 public function getLoggedInUniqueIdentifier() {
17f443df 791 return NULL;
e7292422 792 }
2b617cb0 793
32998c82 794 /**
2b0e7d03
EM
795 * Return a UFID (user account ID from the UserFramework / CMS system.
796 *
797 * ID is based on the user object passed, defaulting to the logged in user if not passed.
798 *
799 * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would
800 * seem to be resolving the user id before calling the function.
32998c82
EM
801 *
802 * Note there is already a function getUFId which takes $username as a param - we could add $user
2b0e7d03
EM
803 * as a second param to it but it seems messy - just overloading it because the name is taken.
804 *
2b617cb0 805 * @param object $user
2b0e7d03 806 *
a6c01b45 807 * @return int
2b0e7d03 808 * User ID of UF System
32998c82 809 */
00be9182 810 public function getBestUFID($user = NULL) {
22e263ad 811 if ($user) {
32998c82
EM
812 return $this->getUserIDFromUserObject($user);
813 }
814 return $this->getLoggedInUfID();
815 }
2b617cb0
EM
816
817 /**
2b0e7d03
EM
818 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system.
819 *
820 * This is based on the user object passed, defaulting to the logged in user if not passed.
821 *
822 * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be
823 * resolving the unique identifier before calling the function.
2b617cb0
EM
824 *
825 * @param object $user
2b0e7d03 826 *
a6c01b45
CW
827 * @return string
828 * unique identifier from the UF System
2b617cb0 829 */
00be9182 830 public function getBestUFUniqueIdentifier($user = NULL) {
22e263ad 831 if ($user) {
2b617cb0
EM
832 return $this->getUniqueIdentifierFromUserObject($user);
833 }
834 return $this->getLoggedInUniqueIdentifier();
835 }
59f97da6 836
66e42142
CW
837 /**
838 * List modules installed in the CMS, including enabled and disabled ones.
839 *
840 * @return array
841 * [CRM_Core_Module]
842 */
843 public function getModules() {
844 return array();
845 }
846
59f97da6 847 /**
fe482240 848 * Get Url to view user record.
2b0e7d03 849 *
77855840
TO
850 * @param int $contactID
851 * Contact ID.
59f97da6 852 *
17f443df 853 * @return string|null
59f97da6 854 */
00be9182 855 public function getUserRecordUrl($contactID) {
59f97da6
EM
856 return NULL;
857 }
353ffa53 858
59f97da6 859 /**
fe482240 860 * Is the current user permitted to add a user.
2b0e7d03 861 *
59f97da6
EM
862 * @return bool
863 */
00be9182 864 public function checkPermissionAddUser() {
59f97da6
EM
865 return FALSE;
866 }
f85b1d20
EM
867
868 /**
fe482240 869 * Output code from error function.
2b0e7d03 870 *
f85b1d20
EM
871 * @param string $content
872 */
00be9182 873 public function outputError($content) {
f85b1d20
EM
874 echo CRM_Utils_System::theme($content);
875 }
e0dd98a5
EM
876
877 /**
fe482240 878 * Log error to CMS.
17f443df
CW
879 *
880 * $param string $message
e0dd98a5 881 */
00be9182 882 public function logger($message) {
e0dd98a5 883 }
f9f361d0
CW
884
885 /**
fe482240 886 * Append to coreResourcesList.
17f443df
CW
887 *
888 * @param array $list
f9f361d0 889 */
e7292422
TO
890 public function appendCoreResources(&$list) {
891 }
96025800 892
d42a224c
CW
893 /**
894 * @param string $name
895 * @param string $value
896 */
897 public function setHttpHeader($name, $value) {
898 header("$name: $value");
899 }
900
6a488035 901}