Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * Base class for UF system integrations | |
5 | */ | |
6 | abstract class CRM_Utils_System_Base { | |
4caaa696 | 7 | /** |
100fef9d | 8 | * Deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific |
4caaa696 | 9 | * functions and leave the codebase oblivious to the type of CMS |
7cdf0f5b | 10 | * |
4caaa696 EM |
11 | * @deprecated |
12 | * @var bool | |
7cdf0f5b | 13 | * TRUE, if the CMS is Drupal. |
4caaa696 | 14 | */ |
6a488035 | 15 | var $is_drupal = FALSE; |
4caaa696 EM |
16 | |
17 | /** | |
100fef9d | 18 | * 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 | 19 | * functions and leave the codebase oblivious to the type of CMS |
7cdf0f5b | 20 | * |
4caaa696 EM |
21 | * @deprecated |
22 | * @var bool | |
7cdf0f5b | 23 | * TRUE, if the CMS is Joomla!. |
4caaa696 | 24 | */ |
6a488035 | 25 | var $is_joomla = FALSE; |
4caaa696 | 26 | |
7cdf0f5b AH |
27 | /** |
28 | * 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 | |
29 | * functions and leave the codebase oblivious to the type of CMS | |
30 | * | |
31 | * @deprecated | |
32 | * @var bool | |
33 | * TRUE, if the CMS is WordPress. | |
34 | */ | |
6a488035 TO |
35 | var $is_wordpress = FALSE; |
36 | ||
e0dd98a5 EM |
37 | /** |
38 | * Does this CMS / UF support a CMS specific logging mechanism? | |
39 | * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions | |
40 | * @var bool | |
41 | */ | |
42 | var $supports_UF_Logging = FALSE; | |
43 | ||
7cdf0f5b AH |
44 | /** |
45 | * @var bool | |
46 | * TRUE, if the CMS allows CMS forms to be extended by hooks. | |
6a488035 TO |
47 | */ |
48 | var $supports_form_extensions = FALSE; | |
49 | ||
50 | /** | |
100fef9d | 51 | * If we are using a theming system, invoke theme, else just print the |
6a488035 TO |
52 | * content |
53 | * | |
7cdf0f5b AH |
54 | * @param string $content the content that will be themed |
55 | * @param boolean $print are we displaying to the screen or bypassing theming? | |
56 | * @param boolean $maintenance for maintenance mode | |
6a488035 | 57 | * |
7cdf0f5b AH |
58 | * @throws Exception |
59 | * @return string|null | |
60 | * NULL, If $print is FALSE, and some other criteria match up. | |
61 | * The themed string, otherwise. | |
26659f0c AH |
62 | * |
63 | * @todo The return value is inconsistent. | |
64 | * @todo Better to always return, and never print. | |
6a488035 | 65 | */ |
00be9182 | 66 | public function theme(&$content, $print = FALSE, $maintenance = FALSE) { |
6a488035 TO |
67 | $ret = FALSE; |
68 | ||
69 | // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function | |
70 | // but the parts should be copied into cleaner subclass implementations | |
1e305b0b DL |
71 | $config = CRM_Core_Config::singleton(); |
72 | if ( | |
73 | $config->userSystem->is_drupal && | |
74 | function_exists('theme') && | |
75 | ||
76 | ) { | |
6a488035 TO |
77 | if ($maintenance) { |
78 | drupal_set_breadcrumb(''); | |
79 | drupal_maintenance_theme(); | |
10221f8a TO |
80 | if ($region = CRM_Core_Region::instance('html-header', FALSE)) { |
81 | CRM_Utils_System::addHTMLHead($region->render('')); | |
82 | } | |
6a488035 TO |
83 | print theme('maintenance_page', array('content' => $content)); |
84 | exit(); | |
85 | } | |
86 | $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints | |
87 | } | |
88 | $out = $content; | |
89 | ||
90 | $config = &CRM_Core_Config::singleton(); | |
1e305b0b DL |
91 | if ( |
92 | !$print && | |
6a488035 TO |
93 | $config->userFramework == 'WordPress' |
94 | ) { | |
95 | if (is_admin()) { | |
96 | require_once (ABSPATH . 'wp-admin/admin-header.php'); | |
97 | } | |
98 | else { | |
7cdf0f5b | 99 | // FIXME: we need to figure out to replace civicrm content on the frontend pages |
6a488035 TO |
100 | } |
101 | } | |
102 | ||
103 | if ($ret) { | |
104 | return $out; | |
105 | } | |
106 | else { | |
107 | print $out; | |
108 | } | |
109 | } | |
110 | ||
bb3a214a EM |
111 | /** |
112 | * @return string | |
113 | */ | |
00be9182 | 114 | public function getDefaultBlockLocation() { |
6a488035 TO |
115 | return 'left'; |
116 | } | |
117 | ||
bb3a214a EM |
118 | /** |
119 | * @return string | |
120 | */ | |
00be9182 | 121 | public function getVersion() { |
6a488035 TO |
122 | return 'Unknown'; |
123 | } | |
124 | ||
125 | /** | |
126 | * Format the url as per language Negotiation. | |
127 | * | |
128 | * @param string $url | |
77b97be7 EM |
129 | * @param bool $addLanguagePart |
130 | * @param bool $removeLanguagePart | |
131 | * | |
7cdf0f5b AH |
132 | * @return string |
133 | * Formatted url. | |
6a488035 TO |
134 | * @static |
135 | */ | |
136 | function languageNegotiationURL( | |
137 | $url, | |
138 | $addLanguagePart = TRUE, | |
139 | $removeLanguagePart = FALSE | |
140 | ) { | |
141 | return $url; | |
142 | } | |
143 | ||
e29aefb4 TO |
144 | /** |
145 | * Determine the location of the CMS root. | |
146 | * | |
7cdf0f5b AH |
147 | * @return string|null |
148 | * Local file system path to CMS root, or NULL if it cannot be determined | |
6a488035 | 149 | */ |
00be9182 | 150 | public function cmsRootPath() { |
e29aefb4 | 151 | return NULL; |
6a488035 TO |
152 | } |
153 | ||
154 | /** | |
155 | * Get user login URL for hosting CMS (method declared in each CMS system class) | |
156 | * | |
157 | * @param string $destination - if present, add destination to querystring (works for Drupal only) | |
158 | * | |
159 | * @return string - loginURL for the current CMS | |
160 | * @static | |
161 | */ | |
162 | public abstract function getLoginURL($destination = ''); | |
163 | ||
46b6363c TO |
164 | /** |
165 | * Determine the native ID of the CMS user | |
166 | * | |
100fef9d | 167 | * @param string $username |
f4aaa82a EM |
168 | * |
169 | * @throws CRM_Core_Exception | |
46b6363c TO |
170 | * @return int|NULL |
171 | */ | |
00be9182 | 172 | public function getUfId($username) { |
46b6363c TO |
173 | $className = get_class($this); |
174 | throw new CRM_Core_Exception("Not implemented: {$className}->getUfId"); | |
175 | } | |
176 | ||
5d0eb86b BS |
177 | /** |
178 | * Set a init session with user object | |
179 | * | |
7cdf0f5b AH |
180 | * @param array $data |
181 | * Array with user specific data | |
5d0eb86b | 182 | */ |
00be9182 | 183 | public function setUserSession($data) { |
5d0eb86b BS |
184 | list($userID, $ufID) = $data; |
185 | $session = CRM_Core_Session::singleton(); | |
186 | $session->set('ufID', $ufID); | |
187 | $session->set('userID', $userID); | |
188 | } | |
d8a4acc0 C |
189 | |
190 | /** | |
191 | * Reset any system caches that may be required for proper CiviCRM | |
192 | * integration. | |
193 | */ | |
00be9182 | 194 | public function flush() { |
d8a4acc0 C |
195 | // nullop by default |
196 | } | |
82d9c21e | 197 | |
f091327b CW |
198 | /** |
199 | * Flush css/js caches | |
200 | */ | |
00be9182 | 201 | public function clearResourceCache() { |
f091327b CW |
202 | // nullop by default |
203 | } | |
204 | ||
c8950569 | 205 | /** |
9977c6f5 | 206 | * Return default Site Settings |
f4aaa82a | 207 | * |
7cdf0f5b | 208 | * @param string $dir |
f4aaa82a | 209 | * |
7cdf0f5b | 210 | * @return array |
9977c6f5 | 211 | * - $url, (Joomla - non admin url) |
212 | * - $siteName, | |
213 | * - $siteRoot | |
214 | */ | |
00be9182 | 215 | public function getDefaultSiteSettings($dir) { |
9977c6f5 | 216 | $config = CRM_Core_Config::singleton(); |
217 | $url = $config->userFrameworkBaseURL; | |
218 | return array($url, NULL, NULL); | |
219 | } | |
c8950569 | 220 | |
82d9c21e | 221 | /** |
95d68223 | 222 | * Perform any post login activities required by the CMS - |
53980972 | 223 | * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, |
224 | * calls hook_user op 'login' and generates a new session. | |
e43cc689 | 225 | * |
7cdf0f5b | 226 | * @param array $params |
95d68223 TO |
227 | * |
228 | * FIXME: Document values accepted/required by $params | |
c8950569 | 229 | */ |
00be9182 | 230 | public function userLoginFinalize($params = array()){ |
82d9c21e | 231 | } |
5a604d61 E |
232 | |
233 | /** | |
234 | * Set timezone in mysql so that timestamp fields show the correct time | |
235 | */ | |
00be9182 | 236 | public function setMySQLTimeZone(){ |
5a604d61 E |
237 | $timeZoneOffset = $this->getTimeZoneOffset(); |
238 | if($timeZoneOffset){ | |
239 | $sql = "SET time_zone = '$timeZoneOffset'"; | |
240 | CRM_Core_DAO::executequery($sql); | |
241 | } | |
242 | } | |
243 | ||
6491539b | 244 | |
5a604d61 E |
245 | /** |
246 | * Get timezone from CMS | |
7cdf0f5b AH |
247 | * |
248 | * @return string|false|null | |
6491539b | 249 | */ |
00be9182 | 250 | public function getTimeZoneOffset(){ |
6491539b DL |
251 | $timezone = $this->getTimeZoneString(); |
252 | if($timezone){ | |
253 | $tzObj = new DateTimeZone($timezone); | |
254 | $dateTime = new DateTime("now", $tzObj); | |
255 | $tz = $tzObj->getOffset($dateTime); | |
256 | ||
257 | if(empty($tz)){ | |
258 | return false; | |
259 | } | |
260 | ||
b1d339fc | 261 | $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60)); |
6491539b DL |
262 | |
263 | if($timeZoneOffset > 0){ | |
264 | $timeZoneOffset = '+' . $timeZoneOffset; | |
265 | } | |
266 | return $timeZoneOffset; | |
267 | } | |
268 | } | |
269 | ||
270 | /** | |
271 | * Over-ridable function to get timezone as a string eg. | |
7cdf0f5b AH |
272 | * |
273 | * @return string | |
274 | * Time zone, e.g. 'America/Los_Angeles' | |
6491539b | 275 | */ |
00be9182 | 276 | public function getTimeZoneString() { |
48ec57ab | 277 | return date_default_timezone_get(); |
5a604d61 | 278 | } |
2b617cb0 EM |
279 | |
280 | /** | |
281 | * Get Unique Identifier from UserFramework system (CMS) | |
282 | * @param object $user object as described by the User Framework | |
283 | * @return mixed $uniqueIdentifer Unique identifier from the user Framework system | |
284 | * | |
285 | */ | |
00be9182 | 286 | public function getUniqueIdentifierFromUserObject($user) {} |
2b617cb0 | 287 | |
32998c82 EM |
288 | /** |
289 | * Get User ID from UserFramework system (CMS) | |
290 | * @param object $user object as described by the User Framework | |
291 | * @return mixed <NULL, number> | |
292 | * | |
293 | */ | |
00be9182 | 294 | public function getUserIDFromUserObject($user) {} |
32998c82 EM |
295 | |
296 | /** | |
297 | * Get currently logged in user uf id. | |
298 | * | |
299 | * @return int $userID logged in user uf id. | |
300 | */ | |
00be9182 | 301 | public function getLoggedInUfID() {} |
32998c82 | 302 | |
2b617cb0 EM |
303 | /** |
304 | * Get currently logged in user unique identifier - this tends to be the email address or user name. | |
305 | * | |
306 | * @return string $userID logged in user unique identifier | |
307 | */ | |
00be9182 | 308 | public function getLoggedInUniqueIdentifier() {} |
2b617cb0 | 309 | |
32998c82 | 310 | /** |
100fef9d | 311 | * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object |
32998c82 EM |
312 | * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs |
313 | * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling | |
314 | * the function | |
315 | * | |
316 | * Note there is already a function getUFId which takes $username as a param - we could add $user | |
317 | * as a second param to it but it seems messy - just overloading it because the name is taken | |
2b617cb0 | 318 | * @param object $user |
32998c82 EM |
319 | * @return int $ufid - user ID of UF System |
320 | */ | |
00be9182 | 321 | public function getBestUFID($user = NULL) { |
32998c82 EM |
322 | if($user) { |
323 | return $this->getUserIDFromUserObject($user); | |
324 | } | |
325 | return $this->getLoggedInUfID(); | |
326 | } | |
2b617cb0 EM |
327 | |
328 | /** | |
100fef9d | 329 | * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object |
2b617cb0 EM |
330 | * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs |
331 | * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling | |
332 | * the function | |
333 | * | |
334 | * @param object $user | |
335 | * @return string $uniqueIdentifier - unique identifier from the UF System | |
336 | */ | |
00be9182 | 337 | public function getBestUFUniqueIdentifier($user = NULL) { |
2b617cb0 EM |
338 | if($user) { |
339 | return $this->getUniqueIdentifierFromUserObject($user); | |
340 | } | |
341 | return $this->getLoggedInUniqueIdentifier(); | |
342 | } | |
59f97da6 EM |
343 | |
344 | /** | |
345 | * Get Url to view user record | |
346 | * @param integer $contactID Contact ID | |
347 | * | |
348 | * @return string | |
349 | */ | |
00be9182 | 350 | public function getUserRecordUrl($contactID) { |
59f97da6 EM |
351 | return NULL; |
352 | } | |
353 | /** | |
354 | * Is the current user permitted to add a user | |
355 | * @return bool | |
356 | */ | |
00be9182 | 357 | public function checkPermissionAddUser() { |
59f97da6 EM |
358 | return FALSE; |
359 | } | |
f85b1d20 EM |
360 | |
361 | /** | |
100fef9d | 362 | * Output code from error function |
f85b1d20 EM |
363 | * @param string $content |
364 | */ | |
00be9182 | 365 | public function outputError($content) { |
f85b1d20 EM |
366 | echo CRM_Utils_System::theme($content); |
367 | } | |
e0dd98a5 EM |
368 | |
369 | /** | |
370 | * Log error to CMS | |
371 | */ | |
00be9182 | 372 | public function logger($message) { |
e0dd98a5 EM |
373 | |
374 | } | |
f9f361d0 CW |
375 | |
376 | /** | |
377 | * Append to coreResourcesList | |
378 | */ | |
00be9182 | 379 | public function appendCoreResources(&$list) {} |
6a488035 | 380 | } |