Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Joomla specific stuff goes here | |
38 | */ | |
39 | class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { | |
bb3a214a | 40 | /** |
bb3a214a | 41 | */ |
00be9182 | 42 | public function __construct() { |
4caaa696 EM |
43 | /** |
44 | * 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 | |
45 | * functions and leave the codebase oblivious to the type of CMS | |
46 | * @deprecated | |
47 | * @var bool | |
48 | */ | |
6a488035 TO |
49 | $this->is_drupal = FALSE; |
50 | } | |
51 | ||
52 | /** | |
17f443df | 53 | * @inheritDoc |
6a488035 | 54 | */ |
00be9182 | 55 | public function createUser(&$params, $mail) { |
6a488035 TO |
56 | $baseDir = JPATH_SITE; |
57 | require_once $baseDir . '/components/com_users/models/registration.php'; | |
58 | ||
59 | $userParams = JComponentHelper::getParams('com_users'); | |
353ffa53 TO |
60 | $model = new UsersModelRegistration(); |
61 | $ufID = NULL; | |
6a488035 TO |
62 | |
63 | // get the default usertype | |
64 | $userType = $userParams->get('new_usertype'); | |
65 | if (!$userType) { | |
66 | $userType = 2; | |
67 | } | |
68 | ||
69 | if (isset($params['name'])) { | |
70 | $fullname = trim($params['name']); | |
71 | } | |
72 | elseif (isset($params['contactID'])) { | |
73 | $fullname = trim(CRM_Contact_BAO_Contact::displayName($params['contactID'])); | |
74 | } | |
75 | else { | |
76 | $fullname = trim($params['cms_name']); | |
77 | } | |
78 | ||
79 | // Prepare the values for a new Joomla user. | |
353ffa53 TO |
80 | $values = array(); |
81 | $values['name'] = $fullname; | |
82 | $values['username'] = trim($params['cms_name']); | |
6a488035 | 83 | $values['password1'] = $values['password2'] = $params['cms_pass']; |
353ffa53 | 84 | $values['email1'] = $values['email2'] = trim($params[$mail]); |
6a488035 TO |
85 | |
86 | $lang = JFactory::getLanguage(); | |
87 | $lang->load('com_users', $baseDir); | |
88 | ||
89 | $register = $model->register($values); | |
90 | ||
91 | $ufID = JUserHelper::getUserId($values['username']); | |
92 | return $ufID; | |
93 | } | |
94 | ||
f4aaa82a | 95 | /** |
17f443df | 96 | * @inheritDoc |
6a488035 | 97 | */ |
00be9182 | 98 | public function updateCMSName($ufID, $ufName) { |
6a488035 TO |
99 | $ufID = CRM_Utils_Type::escape($ufID, 'Integer'); |
100 | $ufName = CRM_Utils_Type::escape($ufName, 'String'); | |
101 | ||
102 | $values = array(); | |
e851ce06 | 103 | $user = JUser::getInstance($ufID); |
6a488035 TO |
104 | |
105 | $values['email'] = $ufName; | |
106 | $user->bind($values); | |
107 | ||
108 | $user->save(); | |
109 | } | |
110 | ||
111 | /** | |
94f9f81a | 112 | * Check if username and email exists in the Joomla db. |
6a488035 | 113 | * |
77855840 TO |
114 | * @param array $params |
115 | * Array of name and mail values. | |
116 | * @param array $errors | |
117 | * Array of errors. | |
118 | * @param string $emailName | |
119 | * Field label for the 'email'. | |
f4aaa82a | 120 | * |
6a488035 TO |
121 | * @return void |
122 | */ | |
00be9182 | 123 | public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') { |
6a488035 TO |
124 | $config = CRM_Core_Config::singleton(); |
125 | ||
353ffa53 TO |
126 | $dao = new CRM_Core_DAO(); |
127 | $name = $dao->escape(CRM_Utils_Array::value('name', $params)); | |
6a488035 TO |
128 | $email = $dao->escape(CRM_Utils_Array::value('mail', $params)); |
129 | //don't allow the special characters and min. username length is two | |
130 | //regex \\ to match a single backslash would become '/\\\\/' | |
131 | $isNotValid = (bool) preg_match('/[\<|\>|\"|\'|\%|\;|\(|\)|\&|\\\\|\/]/im', $name); | |
132 | if ($isNotValid || strlen($name) < 2) { | |
133 | $errors['cms_name'] = ts('Your username contains invalid characters or is too short'); | |
134 | } | |
135 | ||
6a488035 TO |
136 | $JUserTable = &JTable::getInstance('User', 'JTable'); |
137 | ||
138 | $db = $JUserTable->getDbo(); | |
139 | $query = $db->getQuery(TRUE); | |
140 | $query->select('username, email'); | |
141 | $query->from($JUserTable->getTableName()); | |
142 | $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) OR (LOWER(email) = LOWER(\'' . $email . '\'))'); | |
143 | $db->setQuery($query, 0, 10); | |
144 | $users = $db->loadAssocList(); | |
145 | ||
94f9f81a | 146 | $row = array(); |
6a488035 TO |
147 | if (count($users)) { |
148 | $row = $users[0]; | |
149 | } | |
150 | ||
151 | if (!empty($row)) { | |
152 | $dbName = CRM_Utils_Array::value('username', $row); | |
153 | $dbEmail = CRM_Utils_Array::value('email', $row); | |
154 | if (strtolower($dbName) == strtolower($name)) { | |
155 | $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', | |
156 | array(1 => $name) | |
157 | ); | |
158 | } | |
159 | if (strtolower($dbEmail) == strtolower($email)) { | |
160 | $resetUrl = str_replace('administrator/', '', $config->userFrameworkBaseURL) . 'index.php?option=com_users&view=reset'; | |
161 | $errors[$emailName] = ts('The email address %1 is already registered. <a href="%2">Have you forgotten your password?</a>', | |
162 | array(1 => $email, 2 => $resetUrl) | |
163 | ); | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | /** | |
17f443df | 169 | * @inheritDoc |
6a488035 | 170 | */ |
00be9182 | 171 | public function setTitle($title, $pageTitle = NULL) { |
6a488035 TO |
172 | if (!$pageTitle) { |
173 | $pageTitle = $title; | |
174 | } | |
175 | ||
176 | $template = CRM_Core_Smarty::singleton(); | |
177 | $template->assign('pageTitle', $pageTitle); | |
178 | ||
179 | $document = JFactory::getDocument(); | |
180 | $document->setTitle($title); | |
6a488035 TO |
181 | } |
182 | ||
183 | /** | |
17f443df | 184 | * @inheritDoc |
6a488035 | 185 | */ |
00be9182 | 186 | public function appendBreadCrumb($breadCrumbs) { |
6a488035 TO |
187 | $template = CRM_Core_Smarty::singleton(); |
188 | $bc = $template->get_template_vars('breadcrumb'); | |
189 | ||
190 | if (is_array($breadCrumbs)) { | |
191 | foreach ($breadCrumbs as $crumbs) { | |
192 | if (stripos($crumbs['url'], 'id%%')) { | |
193 | $args = array('cid', 'mid'); | |
194 | foreach ($args as $a) { | |
195 | $val = CRM_Utils_Request::retrieve($a, 'Positive', CRM_Core_DAO::$_nullObject, | |
196 | FALSE, NULL, $_GET | |
197 | ); | |
198 | if ($val) { | |
199 | $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']); | |
200 | } | |
201 | } | |
202 | } | |
203 | $bc[] = $crumbs; | |
204 | } | |
205 | } | |
206 | $template->assign_by_ref('breadcrumb', $bc); | |
6a488035 TO |
207 | } |
208 | ||
209 | /** | |
17f443df | 210 | * @inheritDoc |
6a488035 | 211 | */ |
00be9182 | 212 | public function resetBreadCrumb() { |
6a488035 TO |
213 | } |
214 | ||
215 | /** | |
17f443df | 216 | * @inheritDoc |
6a488035 | 217 | */ |
17f443df | 218 | public function addHTMLHead($string = NULL) { |
6a488035 TO |
219 | if ($string) { |
220 | $document = JFactory::getDocument(); | |
221 | $document->addCustomTag($string); | |
222 | } | |
223 | } | |
224 | ||
225 | /** | |
17f443df | 226 | * @inheritDoc |
6a488035 TO |
227 | */ |
228 | public function addStyleUrl($url, $region) { | |
229 | if ($region == 'html-header') { | |
230 | $document = JFactory::getDocument(); | |
231 | $document->addStyleSheet($url); | |
232 | return TRUE; | |
233 | } | |
234 | return FALSE; | |
235 | } | |
236 | ||
237 | /** | |
17f443df | 238 | * @inheritDoc |
6a488035 TO |
239 | */ |
240 | public function addStyle($code, $region) { | |
241 | if ($region == 'html-header') { | |
242 | $document = JFactory::getDocument(); | |
243 | $document->addStyleDeclaration($code); | |
244 | return TRUE; | |
245 | } | |
246 | return FALSE; | |
247 | } | |
248 | ||
249 | /** | |
17f443df | 250 | * @inheritDoc |
6a488035 | 251 | */ |
e7483cbe | 252 | public function url( |
17f443df CW |
253 | $path = NULL, |
254 | $query = NULL, | |
255 | $absolute = FALSE, | |
256 | $fragment = NULL, | |
257 | $htmlize = TRUE, | |
258 | $frontend = FALSE, | |
259 | $forceBackend = FALSE | |
6a488035 | 260 | ) { |
353ffa53 | 261 | $config = CRM_Core_Config::singleton(); |
6a488035 | 262 | $separator = $htmlize ? '&' : '&'; |
353ffa53 TO |
263 | $Itemid = ''; |
264 | $script = ''; | |
265 | $path = CRM_Utils_String::stripPathChars($path); | |
6a488035 TO |
266 | |
267 | if ($config->userFrameworkFrontend) { | |
268 | $script = 'index.php'; | |
269 | if (JRequest::getVar("Itemid")) { | |
270 | $Itemid = "{$separator}Itemid=" . JRequest::getVar("Itemid"); | |
271 | } | |
272 | } | |
273 | ||
274 | if (isset($fragment)) { | |
275 | $fragment = '#' . $fragment; | |
276 | } | |
277 | ||
278 | if (!isset($config->useFrameworkRelativeBase)) { | |
279 | $base = parse_url($config->userFrameworkBaseURL); | |
280 | $config->useFrameworkRelativeBase = $base['path']; | |
281 | } | |
282 | $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; | |
283 | ||
284 | if (!empty($query)) { | |
285 | $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$separator}{$query}{$fragment}"; | |
286 | } | |
287 | else { | |
288 | $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$fragment}"; | |
289 | } | |
290 | ||
291 | // gross hack for joomla, we are in the backend and want to send a frontend url | |
292 | if ($frontend && $config->userFramework == 'Joomla') { | |
293 | // handle both joomla v1.5 and v1.6, CRM-7939 | |
294 | $url = str_replace('/administrator/index2.php', '/index.php', $url); | |
295 | $url = str_replace('/administrator/index.php', '/index.php', $url); | |
296 | ||
297 | // CRM-8215 | |
298 | $url = str_replace('/administrator/', '/index.php', $url); | |
299 | } | |
300 | elseif ($forceBackend) { | |
301 | if (defined('JVERSION')) { | |
302 | $joomlaVersion = JVERSION; | |
0db6c3e1 TO |
303 | } |
304 | else { | |
e7483cbe | 305 | $jversion = new JVersion(); |
6a488035 TO |
306 | $joomlaVersion = $jversion->getShortVersion(); |
307 | } | |
308 | ||
309 | if (version_compare($joomlaVersion, '1.6') >= 0) { | |
310 | $url = str_replace('/index.php', '/administrator/index.php', $url); | |
311 | } | |
312 | } | |
313 | return $url; | |
314 | } | |
315 | ||
6a488035 | 316 | /** |
fe482240 | 317 | * Set the email address of the user. |
6a488035 | 318 | * |
77855840 TO |
319 | * @param object $user |
320 | * Handle to the user object. | |
6a488035 TO |
321 | * |
322 | * @return void | |
6a488035 | 323 | */ |
00be9182 | 324 | public function setEmail(&$user) { |
6a488035 | 325 | global $database; |
94f9f81a EW |
326 | $query = $db->getQuery(TRUE); |
327 | $query->select($db->quoteName('email')) | |
328 | ->from($db->quoteName('#__users')) | |
329 | ->where($db->quoteName('id') . ' = ' . $user->id); | |
6a488035 TO |
330 | $database->setQuery($query); |
331 | $user->email = $database->loadResult(); | |
332 | } | |
333 | ||
334 | /** | |
17f443df | 335 | * @inheritDoc |
6a488035 | 336 | */ |
17f443df | 337 | public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { |
6a488035 TO |
338 | require_once 'DB.php'; |
339 | ||
340 | $config = CRM_Core_Config::singleton(); | |
ebc28bab | 341 | $user = NULL; |
6a488035 TO |
342 | |
343 | if ($loadCMSBootstrap) { | |
344 | $bootStrapParams = array(); | |
345 | if ($name && $password) { | |
346 | $bootStrapParams = array( | |
347 | 'name' => $name, | |
348 | 'pass' => $password, | |
349 | ); | |
350 | } | |
bec3fc7c | 351 | CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, FALSE); |
6a488035 TO |
352 | } |
353 | ||
354 | jimport('joomla.application.component.helper'); | |
355 | jimport('joomla.database.table'); | |
c1f3c6da BS |
356 | jimport('joomla.user.helper'); |
357 | ||
358 | $JUserTable = JTable::getInstance('User', 'JTable'); | |
359 | ||
360 | $db = $JUserTable->getDbo(); | |
361 | $query = $db->getQuery(TRUE); | |
362 | $query->select('id, name, username, email, password'); | |
363 | $query->from($JUserTable->getTableName()); | |
364 | $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)'); | |
365 | $db->setQuery($query, 0, 0); | |
366 | $users = $db->loadObjectList(); | |
367 | ||
368 | $row = array(); | |
369 | if (count($users)) { | |
370 | $row = $users[0]; | |
371 | } | |
6a488035 | 372 | |
e46506b2 | 373 | $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); |
481a74f4 | 374 | if (!defined('JVERSION')) { |
ebc28bab | 375 | require $joomlaBase . '/libraries/cms/version/version.php'; |
e7483cbe | 376 | $jversion = new JVersion(); |
ebc28bab BS |
377 | define('JVERSION', $jversion->getShortVersion()); |
378 | } | |
6a488035 | 379 | |
c1f3c6da BS |
380 | if (!empty($row)) { |
381 | $dbPassword = $row->password; | |
382 | $dbId = $row->id; | |
383 | $dbEmail = $row->email; | |
6a488035 | 384 | |
481a74f4 TO |
385 | if (version_compare(JVERSION, '2.5.18', 'lt') || |
386 | (version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt')) | |
c1f3c6da | 387 | ) { |
ebc28bab | 388 | // now check password |
009eff21 EW |
389 | list($hash, $salt) = explode(':', $dbPassword); |
390 | $cryptpass = md5($password . $salt); | |
391 | if ($hash != $cryptpass) { | |
01c77fa9 EW |
392 | return FALSE; |
393 | } | |
6a488035 | 394 | } |
c1f3c6da | 395 | else { |
4f99ca55 TO |
396 | if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) { |
397 | return FALSE; | |
e7292422 | 398 | } |
9d735153 BS |
399 | |
400 | //include additional files required by Joomla 3.2.1+ | |
481a74f4 | 401 | if (version_compare(JVERSION, '3.2.1', 'ge')) { |
90eac10a BS |
402 | require_once $joomlaBase . '/libraries/cms/application/helper.php'; |
403 | require_once $joomlaBase . '/libraries/cms/application/cms.php'; | |
404 | require_once $joomlaBase . '/libraries/cms/application/administrator.php'; | |
9d735153 | 405 | } |
6a488035 TO |
406 | } |
407 | ||
c1f3c6da | 408 | CRM_Core_BAO_UFMatch::synchronizeUFMatch($row, $dbId, $dbEmail, 'Joomla'); |
6a488035 TO |
409 | $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId); |
410 | if (!$contactID) { | |
411 | return FALSE; | |
412 | } | |
413 | return array($contactID, $dbId, mt_rand()); | |
414 | } | |
c1f3c6da | 415 | |
6a488035 TO |
416 | return FALSE; |
417 | } | |
418 | ||
bec3fc7c | 419 | /** |
fe482240 | 420 | * Set a init session with user object. |
bec3fc7c | 421 | * |
77855840 TO |
422 | * @param array $data |
423 | * Array with user specific data. | |
bec3fc7c | 424 | */ |
00be9182 | 425 | public function setUserSession($data) { |
bec3fc7c | 426 | list($userID, $ufID) = $data; |
481a74f4 | 427 | $user = new JUser($ufID); |
2d8f9c75 | 428 | $session = JFactory::getSession(); |
bec3fc7c BS |
429 | $session->set('user', $user); |
430 | ||
cb0e36de | 431 | parent::setUserSession($data); |
bec3fc7c BS |
432 | } |
433 | ||
6a488035 | 434 | /** |
17f443df | 435 | * FIXME: Do something |
6a488035 | 436 | */ |
00be9182 | 437 | public function setMessage($message) { |
6a488035 TO |
438 | } |
439 | ||
bb3a214a | 440 | /** |
17f443df | 441 | * FIXME: Do something |
bb3a214a | 442 | */ |
00be9182 | 443 | public function loadUser($user) { |
6a488035 TO |
444 | return TRUE; |
445 | } | |
446 | ||
17f443df CW |
447 | /** |
448 | * FIXME: Use CMS-native approach | |
449 | */ | |
00be9182 | 450 | public function permissionDenied() { |
0499b0ad | 451 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
452 | } |
453 | ||
17f443df CW |
454 | /** |
455 | * @inheritDoc | |
456 | */ | |
00be9182 | 457 | public function logout() { |
6a488035 TO |
458 | session_destroy(); |
459 | header("Location:index.php"); | |
460 | } | |
461 | ||
462 | /** | |
17f443df | 463 | * @inheritDoc |
6a488035 | 464 | */ |
00be9182 | 465 | public function getUFLocale() { |
6a488035 TO |
466 | if (defined('_JEXEC')) { |
467 | $conf = JFactory::getConfig(); | |
4965d8e9 | 468 | $locale = $conf->get('language'); |
6a488035 TO |
469 | return str_replace('-', '_', $locale); |
470 | } | |
471 | return NULL; | |
472 | } | |
473 | ||
bb3a214a | 474 | /** |
17f443df | 475 | * @inheritDoc |
bb3a214a | 476 | */ |
00be9182 | 477 | public function getVersion() { |
6a488035 | 478 | if (class_exists('JVersion')) { |
e7483cbe | 479 | $version = new JVersion(); |
6a488035 TO |
480 | return $version->getShortVersion(); |
481 | } | |
482 | else { | |
483 | return 'Unknown'; | |
484 | } | |
485 | } | |
486 | ||
f4aaa82a | 487 | /** |
fe482240 | 488 | * Load joomla bootstrap. |
6a488035 | 489 | * |
5a4f6742 CW |
490 | * @param array $params |
491 | * with uid or name and password. | |
492 | * @param bool $loadUser | |
493 | * load cms user?. | |
f4aaa82a EM |
494 | * @param bool|\throw $throwError throw error on failure? |
495 | * @param null $realPath | |
496 | * @param bool $loadDefines | |
497 | * | |
498 | * @return bool | |
6a488035 | 499 | */ |
00be9182 | 500 | public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE) { |
6a488035 TO |
501 | // Setup the base path related constant. |
502 | $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); | |
503 | ||
504 | // load BootStrap here if needed | |
505 | // We are a valid Joomla entry point. | |
353ffa53 | 506 | if (!defined('_JEXEC') && $loadDefines) { |
6a488035 TO |
507 | define('_JEXEC', 1); |
508 | define('DS', DIRECTORY_SEPARATOR); | |
509 | define('JPATH_BASE', $joomlaBase . '/administrator'); | |
510 | require $joomlaBase . '/administrator/includes/defines.php'; | |
511 | } | |
512 | ||
513 | // Get the framework. | |
2cb7adde | 514 | if (file_exists($joomlaBase . '/libraries/import.legacy.php')) { |
2efcf0c2 | 515 | require $joomlaBase . '/libraries/import.legacy.php'; |
2cb7adde | 516 | } |
6a488035 TO |
517 | require $joomlaBase . '/libraries/import.php'; |
518 | require $joomlaBase . '/libraries/joomla/event/dispatcher.php'; | |
6a488035 TO |
519 | require $joomlaBase . '/configuration.php'; |
520 | ||
6fde79f5 | 521 | // Files may be in different places depending on Joomla version |
481a74f4 | 522 | if (!defined('JVERSION')) { |
6fde79f5 | 523 | require $joomlaBase . '/libraries/cms/version/version.php'; |
e7483cbe | 524 | $jversion = new JVersion(); |
6fde79f5 BS |
525 | define('JVERSION', $jversion->getShortVersion()); |
526 | } | |
527 | ||
481a74f4 | 528 | if (version_compare(JVERSION, '3.0', 'lt')) { |
6fde79f5 BS |
529 | require $joomlaBase . '/libraries/joomla/environment/uri.php'; |
530 | require $joomlaBase . '/libraries/joomla/application/component/helper.php'; | |
531 | } | |
532 | else { | |
87cdafb0 | 533 | require $joomlaBase . '/libraries/cms.php'; |
6fde79f5 | 534 | require $joomlaBase . '/libraries/joomla/uri/uri.php'; |
6fde79f5 BS |
535 | } |
536 | ||
6a488035 | 537 | jimport('joomla.application.cli'); |
f4aaa82a | 538 | |
182f835d | 539 | // CRM-14281 Joomla wasn't available during bootstrap, so hook_civicrm_config never executes. |
540 | $config = CRM_Core_Config::singleton(); | |
541 | CRM_Utils_Hook::config($config); | |
6a488035 TO |
542 | |
543 | return TRUE; | |
544 | } | |
545 | ||
546 | /** | |
17f443df | 547 | * @inheritDoc |
6a488035 TO |
548 | */ |
549 | public function isUserLoggedIn() { | |
550 | $user = JFactory::getUser(); | |
551 | return ($user->guest) ? FALSE : TRUE; | |
552 | } | |
553 | ||
554 | /** | |
17f443df | 555 | * @inheritDoc |
6a488035 TO |
556 | */ |
557 | public function getLoggedInUfID() { | |
558 | $user = JFactory::getUser(); | |
559 | return ($user->guest) ? NULL : $user->id; | |
560 | } | |
561 | ||
2b617cb0 | 562 | /** |
17f443df | 563 | * @inheritDoc |
2b617cb0 | 564 | */ |
00be9182 | 565 | public function getLoggedInUniqueIdentifier() { |
2b617cb0 EM |
566 | $user = JFactory::getUser(); |
567 | return $this->getUniqueIdentifierFromUserObject($user); | |
568 | } | |
353ffa53 | 569 | |
32998c82 | 570 | /** |
17f443df | 571 | * @inheritDoc |
32998c82 | 572 | */ |
00be9182 | 573 | public function getUserIDFromUserObject($user) { |
32998c82 EM |
574 | return !empty($user->id) ? $user->id : NULL; |
575 | } | |
576 | ||
2b617cb0 | 577 | /** |
17f443df | 578 | * @inheritDoc |
2b617cb0 | 579 | */ |
00be9182 | 580 | public function getUniqueIdentifierFromUserObject($user) { |
2b617cb0 EM |
581 | return ($user->guest) ? NULL : $user->email; |
582 | } | |
583 | ||
6a488035 TO |
584 | /** |
585 | * Get a list of all installed modules, including enabled and disabled ones | |
586 | * | |
a6c01b45 CW |
587 | * @return array |
588 | * CRM_Core_Module | |
6a488035 | 589 | */ |
00be9182 | 590 | public function getModules() { |
6a488035 TO |
591 | $result = array(); |
592 | ||
593 | $db = JFactory::getDbo(); | |
e7292422 | 594 | $query = $db->getQuery(TRUE); |
6a488035 TO |
595 | $query->select('type, folder, element, enabled') |
596 | ->from('#__extensions') | |
597 | ->where('type =' . $db->Quote('plugin')); | |
598 | $plugins = $db->setQuery($query)->loadAssocList(); | |
599 | foreach ($plugins as $plugin) { | |
600 | // question: is the folder really a critical part of the plugin's name? | |
601 | $name = implode('.', array('joomla', $plugin['type'], $plugin['folder'], $plugin['element'])); | |
602 | $result[] = new CRM_Core_Module($name, $plugin['enabled'] ? TRUE : FALSE); | |
603 | } | |
604 | ||
605 | return $result; | |
606 | } | |
607 | ||
608 | /** | |
17f443df | 609 | * @inheritDoc |
6a488035 TO |
610 | */ |
611 | public function getLoginURL($destination = '') { | |
612 | $config = CRM_Core_Config::singleton(); | |
613 | $loginURL = $config->userFrameworkBaseURL; | |
614 | $loginURL = str_replace('administrator/', '', $loginURL); | |
615 | $loginURL .= 'index.php?option=com_users&view=login'; | |
091412ab BS |
616 | |
617 | //CRM-14872 append destination | |
481a74f4 | 618 | if (!empty($destination)) { |
92fcb95f | 619 | $loginURL .= '&return=' . urlencode(base64_encode($destination)); |
091412ab | 620 | } |
6a488035 TO |
621 | return $loginURL; |
622 | } | |
f813f78e | 623 | |
bb3a214a | 624 | /** |
17f443df | 625 | * @inheritDoc |
bb3a214a | 626 | */ |
6a488035 | 627 | public function getLoginDestination(&$form) { |
091412ab BS |
628 | $args = NULL; |
629 | ||
630 | $id = $form->get('id'); | |
631 | if ($id) { | |
632 | $args .= "&id=$id"; | |
633 | } | |
634 | else { | |
635 | $gid = $form->get('gid'); | |
636 | if ($gid) { | |
637 | $args .= "&gid=$gid"; | |
638 | } | |
639 | else { | |
640 | // Setup Personal Campaign Page link uses pageId | |
641 | $pageId = $form->get('pageId'); | |
642 | if ($pageId) { | |
643 | $component = $form->get('component'); | |
644 | $args .= "&pageId=$pageId&component=$component&action=add"; | |
645 | } | |
646 | } | |
647 | } | |
648 | ||
649 | $destination = NULL; | |
650 | if ($args) { | |
651 | // append destination so user is returned to form they came from after login | |
92fcb95f | 652 | $args = 'reset=1' . $args; |
091412ab BS |
653 | $destination = CRM_Utils_System::url(CRM_Utils_System::currentPath(), $args, TRUE, NULL, TRUE, TRUE); |
654 | } | |
655 | ||
656 | return $destination; | |
6a488035 | 657 | } |
9977c6f5 | 658 | |
659 | /** | |
17f443df | 660 | * @inheritDoc |
9977c6f5 | 661 | */ |
9b873358 | 662 | public function getDefaultSiteSettings($dir) { |
9977c6f5 | 663 | $config = CRM_Core_Config::singleton(); |
664 | $url = preg_replace( | |
665 | '|/administrator|', | |
666 | '', | |
667 | $config->userFrameworkBaseURL | |
668 | ); | |
669 | $siteRoot = preg_replace( | |
670 | '|/media/civicrm/.*$|', | |
671 | '', | |
672 | $config->imageUploadDir | |
673 | ); | |
674 | return array($url, NULL, $siteRoot); | |
675 | } | |
59f97da6 EM |
676 | |
677 | /** | |
17f443df | 678 | * @inheritDoc |
59f97da6 | 679 | */ |
00be9182 | 680 | public function getUserRecordUrl($contactID) { |
59f97da6 EM |
681 | $uid = CRM_Core_BAO_UFMatch::getUFId($contactID); |
682 | $userRecordUrl = NULL; | |
683 | // if logged in user is super user, then he can view other users joomla profile | |
684 | if (JFactory::getUser()->authorise('core.admin')) { | |
685 | return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid; | |
686 | } | |
687 | elseif (CRM_Core_Session::singleton()->get('userID') == $contactID) { | |
688 | return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid; | |
689 | } | |
690 | } | |
691 | ||
692 | /** | |
17f443df | 693 | * @inheritDoc |
59f97da6 | 694 | */ |
00be9182 | 695 | public function checkPermissionAddUser() { |
59f97da6 EM |
696 | if (JFactory::getUser()->authorise('core.create', 'com_users')) { |
697 | return TRUE; | |
698 | } | |
699 | } | |
f85b1d20 EM |
700 | |
701 | /** | |
fe482240 | 702 | * Output code from error function. |
f85b1d20 EM |
703 | * @param string $content |
704 | */ | |
00be9182 | 705 | public function outputError($content) { |
f85b1d20 EM |
706 | if (class_exists('JErrorPage')) { |
707 | $error = new Exception($content); | |
708 | JErrorPage::render($error); | |
709 | } | |
4c9b6178 | 710 | elseif (class_exists('JError')) { |
f85b1d20 EM |
711 | JError::raiseError('CiviCRM-001', $content); |
712 | } | |
713 | else { | |
714 | parent::outputError($content); | |
715 | } | |
716 | } | |
e7292422 | 717 | |
f58e4c2e | 718 | /** |
fe482240 | 719 | * Append Joomla js to coreResourcesList. |
f58e4c2e | 720 | */ |
00be9182 | 721 | public function appendCoreResources(&$list) { |
f58e4c2e DC |
722 | $list[] = 'js/crm.joomla.js'; |
723 | } | |
96025800 | 724 | |
6a488035 | 725 | } |