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