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