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