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