Another set of PHPdoc corrections
[civicrm-core.git] / CRM / Utils / System / Base.php
1 <?php
2
3 /**
4 * Base class for UF system integrations
5 */
6 abstract class CRM_Utils_System_Base {
7
8 /**
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
12 * functions and leave the codebase oblivious to the type of CMS
13 *
14 * @var bool
15 * @deprecated
16 * TRUE, if the CMS is Drupal.
17 */
18 public $is_drupal = FALSE;
19
20 /**
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
22 * functions and leave the codebase oblivious to the type of CMS
23 *
24 * @var bool
25 * @deprecated
26 * TRUE, if the CMS is Joomla!.
27 */
28 public $is_joomla = FALSE;
29
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 * @var bool
35 * @deprecated
36 * TRUE, if the CMS is WordPress.
37 */
38 public $is_wordpress = FALSE;
39
40 /**
41 * Does this CMS / UF support a CMS specific logging mechanism?
42 * @var bool
43 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
44 */
45 public $supports_UF_Logging = FALSE;
46
47 /**
48 * @var bool
49 * TRUE, if the CMS allows CMS forms to be extended by hooks.
50 */
51 public $supports_form_extensions = FALSE;
52
53 public function initialize() {
54 if (\CRM_Utils_System::isSSL()) {
55 $this->mapConfigToSSL();
56 }
57 }
58
59 abstract public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL);
60
61 /**
62 * Append an additional breadcrumb tag to the existing breadcrumb.
63 *
64 * @param array $breadCrumbs
65 */
66 public function appendBreadCrumb($breadCrumbs) {
67 }
68
69 /**
70 * Reset an additional breadcrumb tag to the existing breadcrumb.
71 */
72 public function resetBreadCrumb() {
73 }
74
75 /**
76 * Append a string to the head of the html file.
77 *
78 * @param string $head
79 * The new string to be appended.
80 */
81 public function addHTMLHead($head) {
82 }
83
84 /**
85 * Rewrite various system urls to https.
86 */
87 public function mapConfigToSSL() {
88 // dont need to do anything, let CMS handle their own switch to SSL
89 }
90
91 /**
92 * Figure out the post url for QuickForm.
93 *
94 * @param string $action
95 * The default url if one is pre-specified.
96 *
97 * @return string
98 * The url to post the form.
99 */
100 public function postURL($action) {
101 $config = CRM_Core_Config::singleton();
102 if (!empty($action)) {
103 return $action;
104 }
105
106 return $this->url(CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET),
107 NULL, TRUE, NULL, FALSE
108 );
109 }
110
111 /**
112 * Generate the url string to a CiviCRM path.
113 *
114 * @param string $path
115 * The path being linked to, such as "civicrm/add".
116 * @param string $query
117 * A query string to append to the link.
118 * @param bool $absolute
119 * Whether to force the output to be an absolute link (beginning with http).
120 * Useful for links that will be displayed outside the site, such as in an RSS feed.
121 * @param string $fragment
122 * A fragment identifier (named anchor) to append to the link.
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 * @param bool $htmlize
128 * Whether to encode special html characters such as &.
129 *
130 * @return string
131 */
132 public function url(
133 $path = NULL,
134 $query = NULL,
135 $absolute = FALSE,
136 $fragment = NULL,
137 $frontend = FALSE,
138 $forceBackend = FALSE,
139 $htmlize = TRUE
140 ) {
141 return NULL;
142 }
143
144 /**
145 * Return the Notification URL for Payments.
146 *
147 * The default is to pass the params through to `url()`. However the WordPress
148 * CMS class overrides this method because Notification URLs must always target
149 * the Base Page to avoid IPN failures when Forms are embedded in pages that
150 * require authentication.
151 *
152 * @param string $path
153 * The path being linked to, such as "civicrm/add".
154 * @param string $query
155 * A query string to append to the link.
156 * @param bool $absolute
157 * Whether to force the output to be an absolute link (beginning with http).
158 * Useful for links that will be displayed outside the site, such as in an RSS feed.
159 * @param string $fragment
160 * A fragment identifier (named anchor) to append to the link.
161 * @param bool $frontend
162 * This link should be to the CMS front end (applies to WP & Joomla).
163 * @param bool $forceBackend
164 * This link should be to the CMS back end (applies to WP & Joomla).
165 * @param bool $htmlize
166 * Whether to encode special html characters such as &.
167 *
168 * @return string
169 * The Notification URL.
170 */
171 public function getNotifyUrl(
172 $path = NULL,
173 $query = NULL,
174 $absolute = FALSE,
175 $fragment = NULL,
176 $frontend = FALSE,
177 $forceBackend = FALSE,
178 $htmlize = TRUE
179 ) {
180 return $this->url($path, $query, $absolute, $fragment, $frontend, $forceBackend, $htmlize);
181 }
182
183 /**
184 * Authenticate the user against the CMS db.
185 *
186 * @param string $name
187 * The user name.
188 * @param string $password
189 * The password for the above user.
190 * @param bool $loadCMSBootstrap
191 * Load cms bootstrap?.
192 * @param string $realPath
193 * Filename of script
194 *
195 * @return array|bool
196 * [contactID, ufID, unique string] else false if no auth
197 * @throws \CRM_Core_Exception.
198 */
199 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
200 return FALSE;
201 }
202
203 /**
204 * Set a message in the CMS to display to a user.
205 *
206 * @param string $message
207 * The message to set.
208 */
209 public function setMessage($message) {
210 }
211
212 /**
213 * Load user into session.
214 *
215 * @param obj $user
216 *
217 * @return bool
218 */
219 public function loadUser($user) {
220 return TRUE;
221 }
222
223 /**
224 * Immediately stop script execution and display a 401 "Access Denied" page.
225 * @throws \CRM_Core_Exception
226 */
227 public function permissionDenied() {
228 throw new CRM_Core_Exception(ts('You do not have permission to access this page.'));
229 }
230
231 /**
232 * Immediately stop script execution, log out the user and redirect to the home page.
233 *
234 * @deprecated
235 * This function should be removed in favor of linking to the CMS's logout page
236 */
237 public function logout() {
238 }
239
240 /**
241 * Clear CMS caches related to the user registration/profile forms.
242 * Used when updating/embedding profiles on CMS user forms.
243 * @see CRM-3600
244 */
245 public function updateCategories() {
246 }
247
248 /**
249 * Get the locale set in the CMS.
250 *
251 * @return string|null
252 * Locale or null for none
253 */
254 public function getUFLocale() {
255 return NULL;
256 }
257
258 /**
259 * If we are using a theming system, invoke theme, else just print the content.
260 *
261 * @param string $content
262 * The content that will be themed.
263 * @param bool $print
264 * Are we displaying to the screen or bypassing theming?.
265 * @param bool $maintenance
266 * For maintenance mode.
267 *
268 * @throws Exception
269 * @return string|null
270 * NULL, If $print is FALSE, and some other criteria match up.
271 * The themed string, otherwise.
272 *
273 * @todo The return value is inconsistent.
274 * @todo Better to always return, and never print.
275 */
276 public function theme(&$content, $print = FALSE, $maintenance = FALSE) {
277 $ret = FALSE;
278
279 // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function
280 // but the parts should be copied into cleaner subclass implementations
281 $config = CRM_Core_Config::singleton();
282 if (
283 $config->userSystem->is_drupal &&
284 function_exists('theme') &&
285 !$print
286 ) {
287 if ($maintenance) {
288 drupal_set_breadcrumb('');
289 drupal_maintenance_theme();
290 if ($region = CRM_Core_Region::instance('html-header', FALSE)) {
291 CRM_Utils_System::addHTMLHead($region->render(''));
292 }
293 print theme('maintenance_page', ['content' => $content]);
294 exit();
295 }
296 // TODO: Figure out why D7 returns but everyone else prints
297 $ret = TRUE;
298 }
299 $out = $content;
300
301 if (
302 !$print &&
303 CRM_Core_Config::singleton()->userFramework == 'WordPress'
304 ) {
305 if (!function_exists('is_admin')) {
306 throw new \Exception('Function "is_admin()" is missing, even though WordPress is the user framework.');
307 }
308 if (!defined('ABSPATH')) {
309 throw new \Exception('Constant "ABSPATH" is not defined, even though WordPress is the user framework.');
310 }
311 if (is_admin()) {
312 require_once ABSPATH . 'wp-admin/admin-header.php';
313 }
314 else {
315 // FIXME: we need to figure out to replace civicrm content on the frontend pages
316 }
317 }
318
319 if ($ret) {
320 return $out;
321 }
322 else {
323 print $out;
324 return NULL;
325 }
326 }
327
328 /**
329 * @return string
330 */
331 public function getDefaultBlockLocation() {
332 return 'left';
333 }
334
335 /**
336 * Get the absolute path to the site's base url.
337 *
338 * @return bool|mixed|string
339 */
340 public function getAbsoluteBaseURL() {
341 if (!defined('CIVICRM_UF_BASEURL')) {
342 return FALSE;
343 }
344
345 $url = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
346
347 //format url for language negotiation, CRM-7803
348 $url = $this->languageNegotiationURL($url);
349
350 if (CRM_Utils_System::isSSL()) {
351 $url = str_replace('http://', 'https://', $url);
352 }
353
354 return $url;
355 }
356
357 /**
358 * Get the relative path to the sites base url.
359 *
360 * @return string|false
361 */
362 public function getRelativeBaseURL() {
363 $absoluteBaseURL = $this->getAbsoluteBaseURL();
364 if ($absoluteBaseURL === FALSE) {
365 return FALSE;
366 }
367 $parts = parse_url($absoluteBaseURL);
368 return $parts['path'];
369 //$this->useFrameworkRelativeBase = empty($base['path']) ? '/' : $base['path'];
370 }
371
372 /**
373 * Get CMS Version.
374 *
375 * @return string
376 */
377 public function getVersion() {
378 return 'Unknown';
379 }
380
381 /**
382 * Format the url as per language Negotiation.
383 *
384 * @param string $url
385 * @param bool $addLanguagePart
386 * @param bool $removeLanguagePart
387 *
388 * @return string
389 * Formatted url.
390 */
391 public function languageNegotiationURL(
392 $url,
393 $addLanguagePart = TRUE,
394 $removeLanguagePart = FALSE
395 ) {
396 return $url;
397 }
398
399 /**
400 * Determine the location of the CMS root.
401 *
402 * @return string|null
403 * Local file system path to CMS root, or NULL if it cannot be determined
404 */
405 public function cmsRootPath() {
406 return NULL;
407 }
408
409 /**
410 * Create a user in the CMS.
411 *
412 * @param array $params
413 * @param string $mail
414 * Email id for cms user.
415 *
416 * @return int|bool
417 * uid if user exists, false otherwise
418 */
419 public function createUser(&$params, $mail) {
420 return FALSE;
421 }
422
423 /**
424 * Update a user's email address in the CMS.
425 *
426 * @param int $ufID
427 * User ID in CMS.
428 * @param string $email
429 * Primary contact email address.
430 */
431 public function updateCMSName($ufID, $email) {
432 }
433
434 /**
435 * Check if user is logged in to the CMS.
436 *
437 * @return bool
438 */
439 public function isUserLoggedIn() {
440 return FALSE;
441 }
442
443 /**
444 * Check if user registration is permitted.
445 *
446 * @return bool
447 */
448 public function isUserRegistrationPermitted() {
449 return FALSE;
450 }
451
452 /**
453 * Check if user can create passwords or is initially assigned a system-generated one.
454 *
455 * @return bool
456 */
457 public function isPasswordUserGenerated() {
458 return FALSE;
459 }
460
461 /**
462 * Is a front end page being accessed.
463 *
464 * Generally this would be a contribution form or other public page as opposed to a backoffice page (like contact edit).
465 *
466 * @todo Drupal uses the is_public setting - clarify & rationalise. See https://github.com/civicrm/civicrm-drupal/pull/546/files
467 *
468 * @return bool
469 */
470 public function isFrontEndPage() {
471 return CRM_Core_Config::singleton()->userFrameworkFrontend;
472 }
473
474 /**
475 * Get user login URL for hosting CMS (method declared in each CMS system class)
476 *
477 * @param string $destination
478 * If present, add destination to querystring (works for Drupal and WordPress only).
479 *
480 * @return string
481 * loginURL for the current CMS
482 */
483 abstract public function getLoginURL($destination = '');
484
485 /**
486 * Get the login destination string.
487 *
488 * When this is passed in the URL the user will be directed to it after filling in the CMS form.
489 *
490 * @param CRM_Core_Form $form
491 * Form object representing the 'current' form - to which the user will be returned.
492 *
493 * @return string|NULL
494 * destination value for URL
495 */
496 public function getLoginDestination(&$form) {
497 return NULL;
498 }
499
500 /**
501 * Determine the native ID of the CMS user.
502 *
503 * @param string $username
504 *
505 * @throws CRM_Core_Exception
506 */
507 public function getUfId($username) {
508 $className = get_class($this);
509 throw new CRM_Core_Exception("Not implemented: {$className}->getUfId");
510 }
511
512 /**
513 * Set the localisation from the user framework.
514 *
515 * @param string $civicrm_language
516 *
517 * @return bool
518 */
519 public function setUFLocale($civicrm_language) {
520 return TRUE;
521 }
522
523 /**
524 * Set a init session with user object.
525 *
526 * @param array $data
527 * Array with user specific data
528 */
529 public function setUserSession($data) {
530 list($userID, $ufID) = $data;
531 $session = CRM_Core_Session::singleton();
532 $session->set('ufID', $ufID);
533 $session->set('userID', $userID);
534 }
535
536 /**
537 * Reset any system caches that may be required for proper CiviCRM integration.
538 */
539 public function flush() {
540 // nullop by default
541 }
542
543 /**
544 * Flush css/js caches.
545 */
546 public function clearResourceCache() {
547 // nullop by default
548 }
549
550 /**
551 * Add a script file.
552 *
553 * Note: This function is not to be called directly
554 * @see CRM_Core_Region::render()
555 *
556 * @param string $url absolute path to file
557 * @param string $region
558 * location within the document: 'html-header', 'page-header', 'page-footer'.
559 *
560 * @return bool
561 * TRUE if we support this operation in this CMS, FALSE otherwise
562 */
563 public function addScriptUrl($url, $region) {
564 return FALSE;
565 }
566
567 /**
568 * Add an inline script.
569 *
570 * Note: This function is not to be called directly
571 * @see CRM_Core_Region::render()
572 *
573 * @param string $code javascript code
574 * @param string $region
575 * location within the document: 'html-header', 'page-header', 'page-footer'.
576 *
577 * @return bool
578 * TRUE if we support this operation in this CMS, FALSE otherwise
579 */
580 public function addScript($code, $region) {
581 return FALSE;
582 }
583
584 /**
585 * Add a css file.
586 *
587 * Note: This function is not to be called directly
588 * @see CRM_Core_Region::render()
589 *
590 * @param string $url absolute path to file
591 * @param string $region
592 * location within the document: 'html-header', 'page-header', 'page-footer'.
593 *
594 * @return bool
595 * TRUE if we support this operation in this CMS, FALSE otherwise
596 */
597 public function addStyleUrl($url, $region) {
598 return FALSE;
599 }
600
601 /**
602 * Add an inline style.
603 *
604 * Note: This function is not to be called directly
605 * @see CRM_Core_Region::render()
606 *
607 * @param string $code css code
608 * @param string $region
609 * location within the document: 'html-header', 'page-header', 'page-footer'.
610 *
611 * @return bool
612 * TRUE if we support this operation in this CMS, FALSE otherwise
613 */
614 public function addStyle($code, $region) {
615 return FALSE;
616 }
617
618 /**
619 * Sets the title of the page.
620 *
621 * @param string $title
622 * Title to set in html header
623 * @param string|null $pageTitle
624 * Title to set in html body (if different)
625 */
626 public function setTitle($title, $pageTitle = NULL) {
627 }
628
629 /**
630 * Return default Site Settings.
631 *
632 * @param string $dir
633 *
634 * @return array
635 * - $url, (Joomla - non admin url)
636 * - $siteName,
637 * - $siteRoot
638 */
639 public function getDefaultSiteSettings($dir) {
640 $config = CRM_Core_Config::singleton();
641 $url = $config->userFrameworkBaseURL;
642 return [$url, NULL, NULL];
643 }
644
645 /**
646 * Determine the default location for file storage.
647 *
648 * FIXME:
649 * 1. This was pulled out from a bigger function. It should be split
650 * into even smaller pieces and marked abstract.
651 * 2. This would be easier to compute by a calling a CMS API, but
652 * for whatever reason Civi gets it from config data.
653 *
654 * @return array
655 * - url: string. ex: "http://example.com/sites/foo.com/files/civicrm"
656 * - path: string. ex: "/var/www/sites/foo.com/files/civicrm"
657 */
658 public function getDefaultFileStorage() {
659 global $civicrm_root;
660 $config = CRM_Core_Config::singleton();
661 $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
662
663 $filesURL = NULL;
664 $filesPath = NULL;
665
666 if ($config->userFramework == 'Joomla') {
667 // gross hack
668 // we need to remove the administrator/ from the end
669 $tempURL = str_replace("/administrator/", "/", $baseURL);
670 $filesURL = $tempURL . "media/civicrm/";
671 }
672 elseif ($config->userFramework == 'UnitTests') {
673 $filesURL = $baseURL . "sites/default/files/civicrm/";
674 }
675 else {
676 throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
677 }
678
679 return [
680 'url' => $filesURL,
681 'path' => CRM_Utils_File::baseFilePath(),
682 ];
683 }
684
685 /**
686 * Determine the location of the CiviCRM source tree.
687 *
688 * FIXME:
689 * 1. This was pulled out from a bigger function. It should be split
690 * into even smaller pieces and marked abstract.
691 * 2. This would be easier to compute by a calling a CMS API, but
692 * for whatever reason we take the hard way.
693 *
694 * @return array
695 * - url: string. ex: "http://example.com/sites/all/modules/civicrm"
696 * - path: string. ex: "/var/www/sites/all/modules/civicrm"
697 */
698 public function getCiviSourceStorage() {
699 global $civicrm_root;
700 $config = CRM_Core_Config::singleton();
701
702 // Don't use $config->userFrameworkBaseURL; it has garbage on it.
703 // More generally, w shouldn't be using $config here.
704 if (!defined('CIVICRM_UF_BASEURL')) {
705 throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
706 }
707 $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
708 if (CRM_Utils_System::isSSL()) {
709 $baseURL = str_replace('http://', 'https://', $baseURL);
710 }
711
712 // @todo this function is only called / code is only reached when is_drupal is true - move this to the drupal classes
713 // and don't implement here.
714 if ($this->is_drupal) {
715 // Drupal setting
716 // check and see if we are installed in sites/all (for D5 and above)
717 // we dont use checkURL since drupal generates an error page and throws
718 // the system for a loop on lobo's macosx box
719 // or in modules
720 $cmsPath = $config->userSystem->cmsRootPath();
721 $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '',
722 str_replace('\\', '/', $civicrm_root)
723 );
724
725 $siteName = $config->userSystem->parseDrupalSiteNameFromRoot($civicrm_root);
726 if ($siteName) {
727 $civicrmDirName = trim(basename($civicrm_root));
728 $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
729 }
730 }
731 else {
732 $userFrameworkResourceURL = NULL;
733 }
734
735 return [
736 'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL, '/'),
737 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
738 ];
739 }
740
741 /**
742 * Perform any post login activities required by the CMS.
743 *
744 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
745 * calls hook_user op 'login' and generates a new session.
746 *
747 * @param array $params
748 *
749 * FIXME: Document values accepted/required by $params
750 */
751 public function userLoginFinalize($params = []) {
752 }
753
754 /**
755 * Set timezone in mysql so that timestamp fields show the correct time.
756 */
757 public function setMySQLTimeZone() {
758 $timeZoneOffset = $this->getTimeZoneOffset();
759 if ($timeZoneOffset) {
760 $sql = "SET time_zone = '$timeZoneOffset'";
761 CRM_Core_DAO::executequery($sql);
762 }
763 }
764
765 /**
766 * Get timezone from CMS.
767 *
768 * @return string|false|null
769 */
770 public function getTimeZoneOffset() {
771 $timezone = $this->getTimeZoneString();
772 if ($timezone) {
773 if ($timezone == 'UTC' || $timezone == 'Etc/UTC') {
774 // CRM-17072 Let's short-circuit all the zero handling & return it here!
775 return '+00:00';
776 }
777 $tzObj = new DateTimeZone($timezone);
778 $dateTime = new DateTime("now", $tzObj);
779 $tz = $tzObj->getOffset($dateTime);
780
781 if ($tz === 0) {
782 // CRM-21422
783 return '+00:00';
784 }
785
786 if (empty($tz)) {
787 return FALSE;
788 }
789
790 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz / 60) % 60));
791
792 if ($timeZoneOffset > 0) {
793 $timeZoneOffset = '+' . $timeZoneOffset;
794 }
795 return $timeZoneOffset;
796 }
797 return NULL;
798 }
799
800 /**
801 * Get timezone as a string.
802 * @return string
803 * Timezone string e.g. 'America/Los_Angeles'
804 */
805 public function getTimeZoneString() {
806 return date_default_timezone_get();
807 }
808
809 /**
810 * Get Unique Identifier from UserFramework system (CMS).
811 *
812 * @param object $user
813 * Object as described by the User Framework.
814 *
815 * @return mixed
816 * Unique identifier from the user Framework system
817 */
818 public function getUniqueIdentifierFromUserObject($user) {
819 return NULL;
820 }
821
822 /**
823 * Get User ID from UserFramework system (CMS).
824 *
825 * @param object $user
826 *
827 * Object as described by the User Framework.
828 * @return null|int
829 */
830 public function getUserIDFromUserObject($user) {
831 return NULL;
832 }
833
834 /**
835 * Get an array of user details for a contact, containing at minimum the user ID & name.
836 *
837 * @param int $contactID
838 *
839 * @return array
840 * CMS user details including
841 * - id
842 * - name (ie the system user name.
843 */
844 public function getUser($contactID) {
845 $ufMatch = civicrm_api3('UFMatch', 'getsingle', [
846 'contact_id' => $contactID,
847 'domain_id' => CRM_Core_Config::domainID(),
848 ]);
849 return [
850 'id' => $ufMatch['uf_id'],
851 'name' => $ufMatch['uf_name'],
852 ];
853 }
854
855 /**
856 * Get currently logged in user uf id.
857 *
858 * @return int|null
859 * logged in user uf id.
860 */
861 public function getLoggedInUfID() {
862 return NULL;
863 }
864
865 /**
866 * Get currently logged in user unique identifier - this tends to be the email address or user name.
867 *
868 * @return string|null
869 * logged in user unique identifier
870 */
871 public function getLoggedInUniqueIdentifier() {
872 return NULL;
873 }
874
875 /**
876 * Return a UFID (user account ID from the UserFramework / CMS system.
877 *
878 * ID is based on the user object passed, defaulting to the logged in user if not passed.
879 *
880 * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would
881 * seem to be resolving the user id before calling the function.
882 *
883 * Note there is already a function getUFId which takes $username as a param - we could add $user
884 * as a second param to it but it seems messy - just overloading it because the name is taken.
885 *
886 * @param object $user
887 *
888 * @return int
889 * User ID of UF System
890 */
891 public function getBestUFID($user = NULL) {
892 if ($user) {
893 return $this->getUserIDFromUserObject($user);
894 }
895 return $this->getLoggedInUfID();
896 }
897
898 /**
899 * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system.
900 *
901 * This is based on the user object passed, defaulting to the logged in user if not passed.
902 *
903 * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be
904 * resolving the unique identifier before calling the function.
905 *
906 * @param object $user
907 *
908 * @return string
909 * unique identifier from the UF System
910 */
911 public function getBestUFUniqueIdentifier($user = NULL) {
912 if ($user) {
913 return $this->getUniqueIdentifierFromUserObject($user);
914 }
915 return $this->getLoggedInUniqueIdentifier();
916 }
917
918 /**
919 * List modules installed in the CMS, including enabled and disabled ones.
920 *
921 * @return array
922 * [CRM_Core_Module]
923 */
924 public function getModules() {
925 return [];
926 }
927
928 /**
929 * Get Url to view user record.
930 *
931 * @param int $contactID
932 * Contact ID.
933 *
934 * @return string|null
935 */
936 public function getUserRecordUrl($contactID) {
937 return NULL;
938 }
939
940 /**
941 * Is the current user permitted to add a user.
942 *
943 * @return bool
944 */
945 public function checkPermissionAddUser() {
946 return FALSE;
947 }
948
949 /**
950 * Output code from error function.
951 *
952 * @param string $content
953 */
954 public function outputError($content) {
955 echo CRM_Utils_System::theme($content);
956 }
957
958 /**
959 * Log error to CMS.
960 *
961 * @param string $message
962 */
963 public function logger($message) {
964 }
965
966 /**
967 * Append to coreResourcesList.
968 *
969 * @param \Civi\Core\Event\GenericHookEvent $e
970 */
971 public function appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) {
972 }
973
974 /**
975 * Modify dynamic assets.
976 *
977 * @param \Civi\Core\Event\GenericHookEvent $e
978 */
979 public function alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) {
980 }
981
982 /**
983 * @param string $name
984 * @param string $value
985 */
986 public function setHttpHeader($name, $value) {
987 header("$name: $value");
988 }
989
990 /**
991 * Create CRM contacts for all existing CMS users
992 *
993 * @return array
994 * @throws \Exception
995 */
996 public function synchronizeUsers() {
997 throw new Exception('CMS user creation not supported for this framework');
998 return [];
999 }
1000
1001 /**
1002 * Send an HTTP Response base on PSR HTTP RespnseInterface response.
1003 *
1004 * @param \Psr\Http\Message\ResponseInterface $response
1005 */
1006 public function sendResponse(\Psr\Http\Message\ResponseInterface $response) {
1007 http_response_code($response->getStatusCode());
1008 foreach ($response->getHeaders() as $name => $values) {
1009 CRM_Utils_System::setHttpHeader($name, implode(', ', (array) $values));
1010 }
1011 echo $response->getBody();
1012 CRM_Utils_System::civiExit();
1013 }
1014
1015 /**
1016 * Start a new session.
1017 */
1018 public function sessionStart() {
1019 session_start();
1020 }
1021
1022 /**
1023 * This exists because of https://www.drupal.org/node/3006306 where
1024 * they changed so that they don't start sessions for anonymous, but we
1025 * want that.
1026 */
1027 public function getSessionId() {
1028 return session_id();
1029 }
1030
1031 /**
1032 * Get role names
1033 *
1034 * @return array|null
1035 */
1036 public function getRoleNames() {
1037 return NULL;
1038 }
1039
1040 /**
1041 * Determine if the Views module exists.
1042 *
1043 * @return bool
1044 */
1045 public function viewsExists() {
1046 return FALSE;
1047 }
1048
1049 /**
1050 * Perform any necessary actions prior to redirecting via POST.
1051 */
1052 public function prePostRedirect() {
1053 }
1054
1055 /**
1056 * Return the CMS-specific url for its permissions page
1057 * @return array
1058 */
1059 public function getCMSPermissionsUrlParams() {
1060 return [];
1061 }
1062
1063 /**
1064 * Get the CRM database as a 'prefix'.
1065 *
1066 * This returns a string that can be prepended to a query to include a CRM table.
1067 *
1068 * However, this string should contain backticks, or not, in accordance with the
1069 * CMS's drupal views expectations, if any.
1070 */
1071 public function getCRMDatabasePrefix(): string {
1072 $crmDatabase = DB::parseDSN(CRM_Core_Config::singleton()->dsn)['database'];
1073 $cmsDatabase = DB::parseDSN(CRM_Core_Config::singleton()->userFrameworkDSN)['database'];
1074 if ($crmDatabase === $cmsDatabase) {
1075 return '';
1076 }
1077 return "`$crmDatabase`.";
1078 }
1079
1080 /**
1081 * Invalidates the cache of dynamic routes and forces a rebuild.
1082 */
1083 public function invalidateRouteCache() {
1084 }
1085
1086 /**
1087 * Should the admin be able to set the password when creating a user
1088 * or does the CMS want it a different way.
1089 */
1090 public function showPasswordFieldWhenAdminCreatesUser() {
1091 return TRUE;
1092 }
1093
1094 /**
1095 * Return the CMS-specific UF Group Types for profiles.
1096 * @return array
1097 */
1098 public function getUfGroupTypes() {
1099 return [];
1100 }
1101
1102 }