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