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 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 | ||
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 | ||
8246bca4 | 290 | /** |
291 | * Get the absolute path to the site's base url. | |
292 | * | |
293 | * @return bool|mixed|string | |
294 | */ | |
d4330c62 TO |
295 | public function getAbsoluteBaseURL() { |
296 | if (!defined('CIVICRM_UF_BASEURL')) { | |
297 | return FALSE; | |
298 | } | |
299 | ||
300 | $url = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/'); | |
301 | ||
302 | //format url for language negotiation, CRM-7803 | |
303 | $url = $this->languageNegotiationURL($url); | |
304 | ||
305 | if (CRM_Utils_System::isSSL()) { | |
306 | $url = str_replace('http://', 'https://', $url); | |
307 | } | |
308 | ||
309 | return $url; | |
310 | } | |
311 | ||
8246bca4 | 312 | /** |
313 | * Get the relative path to the sites base url. | |
314 | * | |
315 | * @return bool | |
316 | */ | |
d4330c62 TO |
317 | public function getRelativeBaseURL() { |
318 | $absoluteBaseURL = $this->getAbsoluteBaseURL(); | |
319 | if ($absoluteBaseURL === FALSE) { | |
320 | return FALSE; | |
321 | } | |
322 | $parts = parse_url($absoluteBaseURL); | |
323 | return $parts['path']; | |
324 | //$this->useFrameworkRelativeBase = empty($base['path']) ? '/' : $base['path']; | |
325 | } | |
326 | ||
bb3a214a | 327 | /** |
fe482240 | 328 | * Get CMS Version. |
17f443df | 329 | * |
bb3a214a EM |
330 | * @return string |
331 | */ | |
00be9182 | 332 | public function getVersion() { |
6a488035 TO |
333 | return 'Unknown'; |
334 | } | |
335 | ||
336 | /** | |
337 | * Format the url as per language Negotiation. | |
338 | * | |
339 | * @param string $url | |
77b97be7 EM |
340 | * @param bool $addLanguagePart |
341 | * @param bool $removeLanguagePart | |
342 | * | |
7cdf0f5b AH |
343 | * @return string |
344 | * Formatted url. | |
6a488035 | 345 | */ |
d5cc0fc2 | 346 | public function languageNegotiationURL( |
6a488035 TO |
347 | $url, |
348 | $addLanguagePart = TRUE, | |
349 | $removeLanguagePart = FALSE | |
350 | ) { | |
351 | return $url; | |
352 | } | |
353 | ||
e29aefb4 TO |
354 | /** |
355 | * Determine the location of the CMS root. | |
356 | * | |
7cdf0f5b AH |
357 | * @return string|null |
358 | * Local file system path to CMS root, or NULL if it cannot be determined | |
6a488035 | 359 | */ |
00be9182 | 360 | public function cmsRootPath() { |
e29aefb4 | 361 | return NULL; |
6a488035 TO |
362 | } |
363 | ||
17f443df CW |
364 | /** |
365 | * Create a user in the CMS. | |
366 | * | |
367 | * @param array $params | |
368 | * @param string $mail | |
369 | * Email id for cms user. | |
370 | * | |
371 | * @return int|bool | |
372 | * uid if user exists, false otherwise | |
373 | */ | |
374 | public function createUser(&$params, $mail) { | |
375 | return FALSE; | |
376 | } | |
377 | ||
378 | /** | |
379 | * Update a user's email address in the CMS. | |
380 | * | |
381 | * @param int $ufID | |
382 | * User ID in CMS. | |
383 | * @param string $email | |
384 | * Primary contact email address. | |
385 | */ | |
386 | public function updateCMSName($ufID, $email) { | |
387 | } | |
388 | ||
389 | /** | |
390 | * Check if user is logged in to the CMS. | |
391 | * | |
392 | * @return bool | |
393 | */ | |
394 | public function isUserLoggedIn() { | |
395 | return FALSE; | |
396 | } | |
397 | ||
8caad0ce | 398 | /** |
399 | * Check if user registration is permitted. | |
400 | * | |
401 | * @return bool | |
402 | */ | |
403 | public function isUserRegistrationPermitted() { | |
404 | return FALSE; | |
405 | } | |
406 | ||
63df6889 HD |
407 | /** |
408 | * Check if user can create passwords or is initially assigned a system-generated one. | |
409 | * | |
410 | * @return bool | |
411 | */ | |
1a6630be | 412 | public function isPasswordUserGenerated() { |
63df6889 HD |
413 | return FALSE; |
414 | } | |
415 | ||
6a488035 TO |
416 | /** |
417 | * Get user login URL for hosting CMS (method declared in each CMS system class) | |
418 | * | |
77855840 TO |
419 | * @param string $destination |
420 | * If present, add destination to querystring (works for Drupal only). | |
6a488035 | 421 | * |
a6c01b45 CW |
422 | * @return string |
423 | * loginURL for the current CMS | |
6a488035 TO |
424 | */ |
425 | public abstract function getLoginURL($destination = ''); | |
426 | ||
17f443df | 427 | /** |
2b0e7d03 EM |
428 | * Get the login destination string. |
429 | * | |
430 | * When this is passed in the URL the user will be directed to it after filling in the CMS form. | |
17f443df CW |
431 | * |
432 | * @param CRM_Core_Form $form | |
433 | * Form object representing the 'current' form - to which the user will be returned. | |
2b0e7d03 | 434 | * |
17f443df CW |
435 | * @return string|NULL |
436 | * destination value for URL | |
437 | */ | |
438 | public function getLoginDestination(&$form) { | |
439 | return NULL; | |
440 | } | |
441 | ||
46b6363c | 442 | /** |
fe482240 | 443 | * Determine the native ID of the CMS user. |
46b6363c | 444 | * |
100fef9d | 445 | * @param string $username |
f4aaa82a EM |
446 | * |
447 | * @throws CRM_Core_Exception | |
46b6363c | 448 | */ |
00be9182 | 449 | public function getUfId($username) { |
46b6363c TO |
450 | $className = get_class($this); |
451 | throw new CRM_Core_Exception("Not implemented: {$className}->getUfId"); | |
452 | } | |
453 | ||
bc854509 | 454 | /** |
455 | * Set the localisation from the user framework. | |
456 | * | |
457 | * @param string $civicrm_language | |
458 | * | |
459 | * @return bool | |
460 | */ | |
a7c57397 TO |
461 | public function setUFLocale($civicrm_language) { |
462 | return TRUE; | |
463 | } | |
464 | ||
5d0eb86b | 465 | /** |
fe482240 | 466 | * Set a init session with user object. |
5d0eb86b | 467 | * |
7cdf0f5b AH |
468 | * @param array $data |
469 | * Array with user specific data | |
5d0eb86b | 470 | */ |
00be9182 | 471 | public function setUserSession($data) { |
5d0eb86b BS |
472 | list($userID, $ufID) = $data; |
473 | $session = CRM_Core_Session::singleton(); | |
474 | $session->set('ufID', $ufID); | |
475 | $session->set('userID', $userID); | |
476 | } | |
d8a4acc0 C |
477 | |
478 | /** | |
2b0e7d03 | 479 | * Reset any system caches that may be required for proper CiviCRM integration. |
d8a4acc0 | 480 | */ |
00be9182 | 481 | public function flush() { |
d8a4acc0 C |
482 | // nullop by default |
483 | } | |
82d9c21e | 484 | |
f091327b | 485 | /** |
2b0e7d03 | 486 | * Flush css/js caches. |
f091327b | 487 | */ |
00be9182 | 488 | public function clearResourceCache() { |
f091327b CW |
489 | // nullop by default |
490 | } | |
491 | ||
17f443df | 492 | /** |
fe482240 | 493 | * Add a script file. |
17f443df CW |
494 | * |
495 | * Note: This function is not to be called directly | |
496 | * @see CRM_Core_Region::render() | |
497 | * | |
2b0e7d03 | 498 | * @param string $url absolute path to file |
17f443df CW |
499 | * @param string $region |
500 | * location within the document: 'html-header', 'page-header', 'page-footer'. | |
501 | * | |
502 | * @return bool | |
503 | * TRUE if we support this operation in this CMS, FALSE otherwise | |
504 | */ | |
505 | public function addScriptUrl($url, $region) { | |
506 | return FALSE; | |
507 | } | |
508 | ||
509 | /** | |
fe482240 | 510 | * Add an inline script. |
17f443df CW |
511 | * |
512 | * Note: This function is not to be called directly | |
513 | * @see CRM_Core_Region::render() | |
514 | * | |
2b0e7d03 | 515 | * @param string $code javascript code |
17f443df CW |
516 | * @param string $region |
517 | * location within the document: 'html-header', 'page-header', 'page-footer'. | |
518 | * | |
519 | * @return bool | |
520 | * TRUE if we support this operation in this CMS, FALSE otherwise | |
521 | */ | |
522 | public function addScript($code, $region) { | |
523 | return FALSE; | |
524 | } | |
525 | ||
526 | /** | |
fe482240 | 527 | * Add a css file. |
17f443df CW |
528 | * |
529 | * Note: This function is not to be called directly | |
530 | * @see CRM_Core_Region::render() | |
531 | * | |
2b0e7d03 | 532 | * @param string $url absolute path to file |
17f443df CW |
533 | * @param string $region |
534 | * location within the document: 'html-header', 'page-header', 'page-footer'. | |
535 | * | |
536 | * @return bool | |
537 | * TRUE if we support this operation in this CMS, FALSE otherwise | |
538 | */ | |
539 | public function addStyleUrl($url, $region) { | |
540 | return FALSE; | |
541 | } | |
542 | ||
543 | /** | |
fe482240 | 544 | * Add an inline style. |
17f443df CW |
545 | * |
546 | * Note: This function is not to be called directly | |
547 | * @see CRM_Core_Region::render() | |
548 | * | |
2b0e7d03 | 549 | * @param string $code css code |
17f443df CW |
550 | * @param string $region |
551 | * location within the document: 'html-header', 'page-header', 'page-footer'. | |
552 | * | |
553 | * @return bool | |
554 | * TRUE if we support this operation in this CMS, FALSE otherwise | |
555 | */ | |
556 | public function addStyle($code, $region) { | |
557 | return FALSE; | |
558 | } | |
559 | ||
560 | /** | |
fe482240 | 561 | * Sets the title of the page. |
17f443df CW |
562 | * |
563 | * @param string $title | |
564 | * Title to set in html header | |
565 | * @param string|null $pageTitle | |
566 | * Title to set in html body (if different) | |
567 | */ | |
568 | public function setTitle($title, $pageTitle = NULL) { | |
569 | } | |
570 | ||
c8950569 | 571 | /** |
fe482240 | 572 | * Return default Site Settings. |
f4aaa82a | 573 | * |
7cdf0f5b | 574 | * @param string $dir |
f4aaa82a | 575 | * |
7cdf0f5b | 576 | * @return array |
d5cc0fc2 | 577 | * - $url, (Joomla - non admin url) |
578 | * - $siteName, | |
579 | * - $siteRoot | |
9977c6f5 | 580 | */ |
00be9182 | 581 | public function getDefaultSiteSettings($dir) { |
9977c6f5 | 582 | $config = CRM_Core_Config::singleton(); |
583 | $url = $config->userFrameworkBaseURL; | |
584 | return array($url, NULL, NULL); | |
585 | } | |
c8950569 | 586 | |
f6f958e4 TO |
587 | /** |
588 | * Determine the default location for file storage. | |
589 | * | |
590 | * FIXME: | |
591 | * 1. This was pulled out from a bigger function. It should be split | |
592 | * into even smaller pieces and marked abstract. | |
593 | * 2. This would be easier to compute by a calling a CMS API, but | |
594 | * for whatever reason Civi gets it from config data. | |
595 | * | |
596 | * @return array | |
597 | * - url: string. ex: "http://example.com/sites/foo.com/files/civicrm" | |
598 | * - path: string. ex: "/var/www/sites/foo.com/files/civicrm" | |
599 | */ | |
600 | public function getDefaultFileStorage() { | |
601 | global $civicrm_root; | |
602 | $config = CRM_Core_Config::singleton(); | |
603 | $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE); | |
604 | ||
605 | $filesURL = NULL; | |
606 | $filesPath = NULL; | |
607 | ||
608 | if ($config->userFramework == 'Joomla') { | |
609 | // gross hack | |
610 | // we need to remove the administrator/ from the end | |
611 | $tempURL = str_replace("/administrator/", "/", $baseURL); | |
612 | $filesURL = $tempURL . "media/civicrm/"; | |
613 | } | |
f6f958e4 TO |
614 | elseif ($config->userFramework == 'UnitTests') { |
615 | $filesURL = $baseURL . "sites/default/files/civicrm/"; | |
616 | } | |
617 | else { | |
618 | throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)"); | |
619 | } | |
620 | ||
621 | return array( | |
622 | 'url' => $filesURL, | |
623 | 'path' => CRM_Utils_File::baseFilePath(), | |
624 | ); | |
625 | } | |
626 | ||
627 | /** | |
628 | * Determine the location of the CiviCRM source tree. | |
629 | * | |
630 | * FIXME: | |
631 | * 1. This was pulled out from a bigger function. It should be split | |
632 | * into even smaller pieces and marked abstract. | |
633 | * 2. This would be easier to compute by a calling a CMS API, but | |
634 | * for whatever reason we take the hard way. | |
635 | * | |
636 | * @return array | |
637 | * - url: string. ex: "http://example.com/sites/all/modules/civicrm" | |
638 | * - path: string. ex: "/var/www/sites/all/modules/civicrm" | |
639 | */ | |
640 | public function getCiviSourceStorage() { | |
641 | global $civicrm_root; | |
642 | $config = CRM_Core_Config::singleton(); | |
643 | ||
644 | // Don't use $config->userFrameworkBaseURL; it has garbage on it. | |
645 | // More generally, w shouldn't be using $config here. | |
646 | if (!defined('CIVICRM_UF_BASEURL')) { | |
647 | throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); | |
648 | } | |
649 | $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/'); | |
650 | if (CRM_Utils_System::isSSL()) { | |
651 | $baseURL = str_replace('http://', 'https://', $baseURL); | |
652 | } | |
653 | ||
654 | if ($config->userFramework == 'Joomla') { | |
655 | $userFrameworkResourceURL = $baseURL . "components/com_civicrm/civicrm/"; | |
656 | } | |
657 | elseif ($config->userFramework == 'WordPress') { | |
750752f2 | 658 | $userFrameworkResourceURL = CIVICRM_PLUGIN_URL . "civicrm/"; |
f6f958e4 | 659 | } |
3403e54b TO |
660 | elseif ($this->is_drupal) { |
661 | // Drupal setting | |
662 | // check and see if we are installed in sites/all (for D5 and above) | |
663 | // we dont use checkURL since drupal generates an error page and throws | |
664 | // the system for a loop on lobo's macosx box | |
665 | // or in modules | |
666 | $cmsPath = $config->userSystem->cmsRootPath(); | |
667 | $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '', | |
668 | str_replace('\\', '/', $civicrm_root) | |
669 | ); | |
670 | ||
671 | $siteName = $config->userSystem->parseDrupalSiteNameFromRoot($civicrm_root); | |
672 | if ($siteName) { | |
673 | $civicrmDirName = trim(basename($civicrm_root)); | |
674 | $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/"; | |
675 | } | |
676 | } | |
f6f958e4 TO |
677 | else { |
678 | $userFrameworkResourceURL = NULL; | |
679 | } | |
680 | ||
681 | return array( | |
2c0f1404 | 682 | 'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL), |
f6f958e4 TO |
683 | 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), |
684 | ); | |
685 | } | |
686 | ||
82d9c21e | 687 | /** |
2b0e7d03 EM |
688 | * Perform any post login activities required by the CMS. |
689 | * | |
53980972 | 690 | * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, |
691 | * calls hook_user op 'login' and generates a new session. | |
e43cc689 | 692 | * |
7cdf0f5b | 693 | * @param array $params |
95d68223 TO |
694 | * |
695 | * FIXME: Document values accepted/required by $params | |
c8950569 | 696 | */ |
9b873358 | 697 | public function userLoginFinalize($params = array()) { |
82d9c21e | 698 | } |
5a604d61 E |
699 | |
700 | /** | |
fe482240 | 701 | * Set timezone in mysql so that timestamp fields show the correct time. |
5a604d61 | 702 | */ |
9b873358 | 703 | public function setMySQLTimeZone() { |
5a604d61 | 704 | $timeZoneOffset = $this->getTimeZoneOffset(); |
9b873358 | 705 | if ($timeZoneOffset) { |
5a604d61 E |
706 | $sql = "SET time_zone = '$timeZoneOffset'"; |
707 | CRM_Core_DAO::executequery($sql); | |
708 | } | |
709 | } | |
710 | ||
6491539b | 711 | |
5a604d61 | 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) { | |
792 | $ufMatch = civicrm_api3('UFMatch', 'getsingle', array( | |
793 | 'contact_id' => $contactID, | |
794 | 'domain_id' => CRM_Core_Config::domainID(), | |
795 | )); | |
796 | return array( | |
797 | 'id' => $ufMatch['uf_id'], | |
798 | 'name' => $ufMatch['uf_name'], | |
799 | ); | |
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() { | |
872 | return array(); | |
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 CW |
915 | * |
916 | * @param array $list | |
f9f361d0 | 917 | */ |
e7292422 TO |
918 | public function appendCoreResources(&$list) { |
919 | } | |
96025800 | 920 | |
d42a224c CW |
921 | /** |
922 | * @param string $name | |
923 | * @param string $value | |
924 | */ | |
925 | public function setHttpHeader($name, $value) { | |
926 | header("$name: $value"); | |
927 | } | |
928 | ||
03d5592a CW |
929 | /** |
930 | * Create CRM contacts for all existing CMS users | |
931 | * | |
932 | * @return array | |
933 | * @throws \Exception | |
934 | */ | |
935 | public function synchronizeUsers() { | |
936 | throw new Exception('CMS user creation not supported for this framework'); | |
937 | return array(); | |
938 | } | |
939 | ||
6a488035 | 940 | } |