comment fixes
[civicrm-core.git] / CRM / Utils / System / Drupal.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * Drupal specific stuff goes here
36 */
37 class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase {
38
39 /**
40 * @inheritDoc
41 */
42 public function createUser(&$params, $mail) {
43 $form_state = form_state_defaults();
44
45 $form_state['input'] = array(
46 'name' => $params['cms_name'],
47 'mail' => $params[$mail],
48 'op' => 'Create new account',
49 );
50
51 $admin = user_access('administer users');
52 if (!variable_get('user_email_verification', TRUE) || $admin) {
53 $form_state['input']['pass'] = array('pass1' => $params['cms_pass'], 'pass2' => $params['cms_pass']);
54 }
55
56 if (!empty($params['notify'])) {
57 $form_state['input']['notify'] = $params['notify'];
58 }
59
60 $form_state['rebuild'] = FALSE;
61 $form_state['programmed'] = TRUE;
62 $form_state['complete form'] = FALSE;
63 $form_state['method'] = 'post';
64 $form_state['build_info']['args'] = array();
65 /*
66 * if we want to submit this form more than once in a process (e.g. create more than one user)
67 * we must force it to validate each time for this form. Otherwise it will not validate
68 * subsequent submissions and the manner in which the password is passed in will be invalid
69 */
70 $form_state['must_validate'] = TRUE;
71 $config = CRM_Core_Config::singleton();
72
73 // we also need to redirect b
74 $config->inCiviCRM = TRUE;
75
76 $form = drupal_retrieve_form('user_register_form', $form_state);
77 $form_state['process_input'] = 1;
78 $form_state['submitted'] = 1;
79 $form['#array_parents'] = array();
80 $form['#tree'] = FALSE;
81 drupal_process_form('user_register_form', $form, $form_state);
82
83 $config->inCiviCRM = FALSE;
84
85 if (form_get_errors()) {
86 return FALSE;
87 }
88 return $form_state['user']->uid;
89 }
90
91 /**
92 * @inheritDoc
93 */
94 public function updateCMSName($ufID, $ufName) {
95 // CRM-5555
96 if (function_exists('user_load')) {
97 $user = user_load($ufID);
98 if ($user->mail != $ufName) {
99 user_save($user, array('mail' => $ufName));
100 $user = user_load($ufID);
101 }
102 }
103 }
104
105 /**
106 * Check if username and email exists in the drupal db.
107 *
108 * @param array $params
109 * Array of name and mail values.
110 * @param array $errors
111 * Array of errors.
112 * @param string $emailName
113 * Field label for the 'email'.
114 */
115 public static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
116 $config = CRM_Core_Config::singleton();
117
118 $dao = new CRM_Core_DAO();
119 $name = $dao->escape(CRM_Utils_Array::value('name', $params));
120 $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
121 $errors = form_get_errors();
122 if ($errors) {
123 // unset drupal messages to avoid twice display of errors
124 unset($_SESSION['messages']);
125 }
126
127 if (!empty($params['name'])) {
128 if ($nameError = user_validate_name($params['name'])) {
129 $errors['cms_name'] = $nameError;
130 }
131 else {
132 $uid = db_query(
133 "SELECT uid FROM {users} WHERE name = :name",
134 array(':name' => $params['name'])
135 )->fetchField();
136 if ((bool) $uid) {
137 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $params['name']));
138 }
139 }
140 }
141
142 if (!empty($params['mail'])) {
143 if ($emailError = user_validate_mail($params['mail'])) {
144 $errors[$emailName] = $emailError;
145 }
146 else {
147 $uid = db_query(
148 "SELECT uid FROM {users} WHERE mail = :mail",
149 array(':mail' => $params['mail'])
150 )->fetchField();
151 if ((bool) $uid) {
152 $resetUrl = $config->userFrameworkBaseURL . 'user/password';
153 $errors[$emailName] = ts('The email address %1 already has an account associated with it. <a href="%2">Have you forgotten your password?</a>',
154 array(1 => $params['mail'], 2 => $resetUrl)
155 );
156 }
157 }
158 }
159 }
160
161 /**
162 * @inheritDoc
163 */
164 public function getLoginURL($destination = '') {
165 $query = $destination ? array('destination' => $destination) : array();
166 return url('user', array('query' => $query), TRUE);
167 }
168
169 /**
170 * @inheritDoc
171 */
172 public function setTitle($title, $pageTitle = NULL) {
173 if (arg(0) == 'civicrm') {
174 if (!$pageTitle) {
175 $pageTitle = $title;
176 }
177
178 drupal_set_title($pageTitle, PASS_THROUGH);
179 }
180 }
181
182 /**
183 * @inheritDoc
184 */
185 public function appendBreadCrumb($breadCrumbs) {
186 $breadCrumb = drupal_get_breadcrumb();
187
188 if (is_array($breadCrumbs)) {
189 foreach ($breadCrumbs as $crumbs) {
190 if (stripos($crumbs['url'], 'id%%')) {
191 $args = array('cid', 'mid');
192 foreach ($args as $a) {
193 $val = CRM_Utils_Request::retrieve($a, 'Positive', CRM_Core_DAO::$_nullObject,
194 FALSE, NULL, $_GET
195 );
196 if ($val) {
197 $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']);
198 }
199 }
200 }
201 $breadCrumb[] = "<a href=\"{$crumbs['url']}\">{$crumbs['title']}</a>";
202 }
203 }
204 drupal_set_breadcrumb($breadCrumb);
205 }
206
207 /**
208 * @inheritDoc
209 */
210 public function resetBreadCrumb() {
211 $bc = array();
212 drupal_set_breadcrumb($bc);
213 }
214
215 /**
216 * @inheritDoc
217 */
218 public function addHTMLHead($header) {
219 static $count = 0;
220 if (!empty($header)) {
221 $key = 'civi_' . ++$count;
222 $data = array(
223 '#type' => 'markup',
224 '#markup' => $header,
225 );
226 drupal_add_html_head($data, $key);
227 }
228 }
229
230 /**
231 * @inheritDoc
232 */
233 public function addScriptUrl($url, $region) {
234 $params = array('group' => JS_LIBRARY, 'weight' => 10);
235 switch ($region) {
236 case 'html-header':
237 case 'page-footer':
238 $params['scope'] = substr($region, 5);
239 break;
240
241 default:
242 return FALSE;
243 }
244 // If the path is within the drupal directory we can use the more efficient 'file' setting
245 $params['type'] = $this->formatResourceUrl($url) ? 'file' : 'external';
246 drupal_add_js($url, $params);
247 return TRUE;
248 }
249
250 /**
251 * @inheritDoc
252 */
253 public function addScript($code, $region) {
254 $params = array('type' => 'inline', 'group' => JS_LIBRARY, 'weight' => 10);
255 switch ($region) {
256 case 'html-header':
257 case 'page-footer':
258 $params['scope'] = substr($region, 5);
259 break;
260
261 default:
262 return FALSE;
263 }
264 drupal_add_js($code, $params);
265 return TRUE;
266 }
267
268 /**
269 * @inheritDoc
270 */
271 public function addStyleUrl($url, $region) {
272 if ($region != 'html-header') {
273 return FALSE;
274 }
275 $params = array();
276 // If the path is within the drupal directory we can use the more efficient 'file' setting
277 $params['type'] = $this->formatResourceUrl($url) ? 'file' : 'external';
278 drupal_add_css($url, $params);
279 return TRUE;
280 }
281
282 /**
283 * @inheritDoc
284 */
285 public function addStyle($code, $region) {
286 if ($region != 'html-header') {
287 return FALSE;
288 }
289 $params = array('type' => 'inline');
290 drupal_add_css($code, $params);
291 return TRUE;
292 }
293
294 /**
295 * @inheritDoc
296 */
297 public function mapConfigToSSL() {
298 global $base_url;
299 $base_url = str_replace('http://', 'https://', $base_url);
300 }
301
302 protected function getUsersTableName() {
303 $userFrameworkUsersTableName = Civi::settings()->get('userFrameworkUsersTableName');
304 if (empty($userFrameworkUsersTableName)) {
305 $userFrameworkUsersTableName = 'users';
306 }
307 return $userFrameworkUsersTableName;
308 }
309
310 /**
311 * @inheritDoc
312 */
313 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
314 require_once 'DB.php';
315
316 $config = CRM_Core_Config::singleton();
317
318 $dbDrupal = DB::connect($config->userFrameworkDSN);
319 if (DB::isError($dbDrupal)) {
320 CRM_Core_Error::fatal("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage());
321 }
322
323 $account = $userUid = $userMail = NULL;
324 if ($loadCMSBootstrap) {
325 $bootStrapParams = array();
326 if ($name && $password) {
327 $bootStrapParams = array(
328 'name' => $name,
329 'pass' => $password,
330 );
331 }
332 CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
333
334 global $user;
335 if ($user) {
336 $userUid = $user->uid;
337 $userMail = $user->mail;
338 }
339 }
340 else {
341 // CRM-8638
342 // SOAP cannot load drupal bootstrap and hence we do it the old way
343 // Contact CiviSMTP folks if we run into issues with this :)
344 $cmsPath = $config->userSystem->cmsRootPath($realPath);
345
346 require_once "$cmsPath/includes/bootstrap.inc";
347 require_once "$cmsPath/includes/password.inc";
348
349 $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
350 $name = $dbDrupal->escapeSimple($strtolower($name));
351 $userFrameworkUsersTableName = $this->getUsersTableName();
352 $sql = "
353 SELECT u.*
354 FROM {$userFrameworkUsersTableName} u
355 WHERE LOWER(u.name) = '$name'
356 AND u.status = 1
357 ";
358
359 $query = $dbDrupal->query($sql);
360 $row = $query->fetchRow(DB_FETCHMODE_ASSOC);
361
362 if ($row) {
363 $fakeDrupalAccount = drupal_anonymous_user();
364 $fakeDrupalAccount->name = $name;
365 $fakeDrupalAccount->pass = $row['pass'];
366 $passwordCheck = user_check_password($password, $fakeDrupalAccount);
367 if ($passwordCheck) {
368 $userUid = $row['uid'];
369 $userMail = $row['mail'];
370 }
371 }
372 }
373
374 if ($userUid && $userMail) {
375 CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $userUid, $userMail, 'Drupal');
376 $contactID = CRM_Core_BAO_UFMatch::getContactId($userUid);
377 if (!$contactID) {
378 return FALSE;
379 }
380 return array($contactID, $userUid, mt_rand());
381 }
382 return FALSE;
383 }
384
385 /**
386 * @inheritDoc
387 */
388 public function loadUser($username) {
389 global $user;
390
391 $user = user_load_by_name($username);
392
393 if (empty($user->uid)) {
394 return FALSE;
395 }
396
397 $uid = $user->uid;
398 $contact_id = CRM_Core_BAO_UFMatch::getContactId($uid);
399
400 // lets store contact id and user id in session
401 $session = CRM_Core_Session::singleton();
402 $session->set('ufID', $uid);
403 $session->set('userID', $contact_id);
404 return TRUE;
405 }
406
407 /**
408 * Perform any post login activities required by the UF -
409 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
410 * calls hook_user op 'login' and generates a new session.
411 *
412 * @param array $params
413 *
414 * FIXME: Document values accepted/required by $params
415 */
416 public function userLoginFinalize($params = array()) {
417 user_login_finalize($params);
418 }
419
420 /**
421 * Determine the native ID of the CMS user.
422 *
423 * @param string $username
424 * @return int|NULL
425 */
426 public function getUfId($username) {
427 $user = user_load_by_name($username);
428 if (empty($user->uid)) {
429 return NULL;
430 }
431 return $user->uid;
432 }
433
434 /**
435 * @inheritDoc
436 */
437 public function logout() {
438 module_load_include('inc', 'user', 'user.pages');
439 return user_logout();
440 }
441
442 /**
443 * Get the default location for CiviCRM blocks.
444 *
445 * @return string
446 */
447 public function getDefaultBlockLocation() {
448 return 'sidebar_first';
449 }
450
451 /**
452 * Load drupal bootstrap.
453 *
454 * @param array $params
455 * Either uid, or name & pass.
456 * @param bool $loadUser
457 * Boolean Require CMS user load.
458 * @param bool $throwError
459 * If true, print error on failure and exit.
460 * @param bool|string $realPath path to script
461 *
462 * @return bool
463 */
464 public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
465 //take the cms root path.
466 $cmsPath = $this->cmsRootPath($realPath);
467
468 if (!file_exists("$cmsPath/includes/bootstrap.inc")) {
469 if ($throwError) {
470 echo '<br />Sorry, could not locate bootstrap.inc\n';
471 exit();
472 }
473 return FALSE;
474 }
475 // load drupal bootstrap
476 chdir($cmsPath);
477 define('DRUPAL_ROOT', $cmsPath);
478
479 // For drupal multi-site CRM-11313
480 if ($realPath && strpos($realPath, 'sites/all/modules/') === FALSE) {
481 preg_match('@sites/([^/]*)/modules@s', $realPath, $matches);
482 if (!empty($matches[1])) {
483 $_SERVER['HTTP_HOST'] = $matches[1];
484 }
485 }
486 require_once 'includes/bootstrap.inc';
487 // @ to suppress notices eg 'DRUPALFOO already defined'.
488 @drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
489
490 // explicitly setting error reporting, since we cannot handle drupal related notices
491 error_reporting(1);
492 if (!function_exists('module_exists') || !module_exists('civicrm')) {
493 if ($throwError) {
494 echo '<br />Sorry, could not load drupal bootstrap.';
495 exit();
496 }
497 return FALSE;
498 }
499
500 // seems like we've bootstrapped drupal
501 $config = CRM_Core_Config::singleton();
502
503 // lets also fix the clean url setting
504 // CRM-6948
505 $config->cleanURL = (int) variable_get('clean_url', '0');
506
507 // we need to call the config hook again, since we now know
508 // all the modules that are listening on it, does not apply
509 // to J! and WP as yet
510 // CRM-8655
511 CRM_Utils_Hook::config($config);
512
513 if (!$loadUser) {
514 return TRUE;
515 }
516
517 $uid = CRM_Utils_Array::value('uid', $params);
518 if (!$uid) {
519 //load user, we need to check drupal permissions.
520 $name = CRM_Utils_Array::value('name', $params, FALSE) ? $params['name'] : trim(CRM_Utils_Array::value('name', $_REQUEST));
521 $pass = CRM_Utils_Array::value('pass', $params, FALSE) ? $params['pass'] : trim(CRM_Utils_Array::value('pass', $_REQUEST));
522
523 if ($name) {
524 $uid = user_authenticate($name, $pass);
525 if (!$uid) {
526 if ($throwError) {
527 echo '<br />Sorry, unrecognized username or password.';
528 exit();
529 }
530 return FALSE;
531 }
532 }
533 }
534
535 if ($uid) {
536 $account = user_load($uid);
537 if ($account && $account->uid) {
538 global $user;
539 $user = $account;
540 return TRUE;
541 }
542 }
543
544 if ($throwError) {
545 echo '<br />Sorry, can not load CMS user account.';
546 exit();
547 }
548
549 // CRM-6948: When using loadBootStrap, it's implicit that CiviCRM has already loaded its settings
550 // which means that define(CIVICRM_CLEANURL) was correctly set.
551 // So we correct it
552 $config = CRM_Core_Config::singleton();
553 $config->cleanURL = (int) variable_get('clean_url', '0');
554
555 // CRM-8655: Drupal wasn't available during bootstrap, so hook_civicrm_config never executes
556 CRM_Utils_Hook::config($config);
557
558 return FALSE;
559 }
560
561 /**
562 * Get CMS root path.
563 *
564 * @param string $scriptFilename
565 *
566 * @return null|string
567 */
568 public function cmsRootPath($scriptFilename = NULL) {
569 $cmsRoot = $valid = NULL;
570
571 if (!is_null($scriptFilename)) {
572 $path = $scriptFilename;
573 }
574 else {
575 $path = $_SERVER['SCRIPT_FILENAME'];
576 }
577
578 if (function_exists('drush_get_context')) {
579 // drush anyway takes care of multisite install etc
580 return drush_get_context('DRUSH_DRUPAL_ROOT');
581 }
582 // CRM-7582
583 $pathVars = explode('/',
584 str_replace('//', '/',
585 str_replace('\\', '/', $path)
586 )
587 );
588
589 //lets store first var,
590 //need to get back for windows.
591 $firstVar = array_shift($pathVars);
592
593 //lets remove sript name to reduce one iteration.
594 array_pop($pathVars);
595
596 // CRM-7429 -- do check for uppermost 'includes' dir, which would
597 // work for multisite installation.
598 do {
599 $cmsRoot = $firstVar . '/' . implode('/', $pathVars);
600 $cmsIncludePath = "$cmsRoot/includes";
601 // Stop if we find bootstrap.
602 if (file_exists("$cmsIncludePath/bootstrap.inc")) {
603 $valid = TRUE;
604 break;
605 }
606 //remove one directory level.
607 array_pop($pathVars);
608 } while (count($pathVars));
609
610 return ($valid) ? $cmsRoot : NULL;
611 }
612
613 /**
614 * @inheritDoc
615 */
616 public function isUserLoggedIn() {
617 $isloggedIn = FALSE;
618 if (function_exists('user_is_logged_in')) {
619 $isloggedIn = user_is_logged_in();
620 }
621
622 return $isloggedIn;
623 }
624
625 /**
626 * @inheritDoc
627 */
628 public function getLoggedInUfID() {
629 $ufID = NULL;
630 if (function_exists('user_is_logged_in') &&
631 user_is_logged_in() &&
632 function_exists('user_uid_optional_to_arg')
633 ) {
634 $ufID = user_uid_optional_to_arg(array());
635 }
636
637 return $ufID;
638 }
639
640 /**
641 * @inheritDoc
642 */
643 public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) {
644 if (empty($url)) {
645 return $url;
646 }
647
648 //CRM-7803 -from d7 onward.
649 $config = CRM_Core_Config::singleton();
650 if (function_exists('variable_get') &&
651 module_exists('locale') &&
652 function_exists('language_negotiation_get')
653 ) {
654 global $language;
655
656 //does user configuration allow language
657 //support from the URL (Path prefix or domain)
658 if (language_negotiation_get('language') == 'locale-url') {
659 $urlType = variable_get('locale_language_negotiation_url_part');
660
661 //url prefix
662 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) {
663 if (isset($language->prefix) && $language->prefix) {
664 if ($addLanguagePart) {
665 $url .= $language->prefix . '/';
666 }
667 if ($removeLanguagePart) {
668 $url = str_replace("/{$language->prefix}/", '/', $url);
669 }
670 }
671 }
672 //domain
673 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN) {
674 if (isset($language->domain) && $language->domain) {
675 if ($addLanguagePart) {
676 $cleanedUrl = preg_replace('#^https?://#', '', $language->domain);
677 // drupal function base_path() adds a "/" to the beginning and end of the returned path
678 if (substr($cleanedUrl, -1) == '/') {
679 $cleanedUrl = substr($cleanedUrl, 0, -1);
680 }
681 $url = (CRM_Utils_System::isSSL() ? 'https' : 'http') . '://' . $cleanedUrl . base_path();
682 }
683 if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) {
684 $url = str_replace('\\', '/', $url);
685 $parseUrl = parse_url($url);
686
687 //kinda hackish but not sure how to do it right
688 //hope http_build_url() will help at some point.
689 if (is_array($parseUrl) && !empty($parseUrl)) {
690 $urlParts = explode('/', $url);
691 $hostKey = array_search($parseUrl['host'], $urlParts);
692 $ufUrlParts = parse_url(CIVICRM_UF_BASEURL);
693 $urlParts[$hostKey] = $ufUrlParts['host'];
694 $url = implode('/', $urlParts);
695 }
696 }
697 }
698 }
699 }
700 }
701
702 return $url;
703 }
704
705 /**
706 * Find any users/roles/security-principals with the given permission
707 * and replace it with one or more permissions.
708 *
709 * @param string $oldPerm
710 * @param array $newPerms
711 * Array, strings.
712 */
713 public function replacePermission($oldPerm, $newPerms) {
714 $roles = user_roles(FALSE, $oldPerm);
715 if (!empty($roles)) {
716 foreach (array_keys($roles) as $rid) {
717 user_role_revoke_permissions($rid, array($oldPerm));
718 user_role_grant_permissions($rid, $newPerms);
719 }
720 }
721 }
722
723 /**
724 * Wrapper for og_membership creation.
725 *
726 * @param int $ogID
727 * Organic Group ID.
728 * @param int $drupalID
729 * Drupal User ID.
730 */
731 public function og_membership_create($ogID, $drupalID) {
732 if (function_exists('og_entity_query_alter')) {
733 // sort-of-randomly chose a function that only exists in the // 7.x-2.x branch
734 //
735 // @TODO Find more solid way to check - try system_get_info('module', 'og').
736 //
737 // Also, since we don't know how to get the entity type of the // group, we'll assume it's 'node'
738 og_group('node', $ogID, array('entity' => user_load($drupalID)));
739 }
740 else {
741 // Works for the OG 7.x-1.x branch
742 og_group($ogID, array('entity' => user_load($drupalID)));
743 }
744 }
745
746 /**
747 * Wrapper for og_membership deletion.
748 *
749 * @param int $ogID
750 * Organic Group ID.
751 * @param int $drupalID
752 * Drupal User ID.
753 */
754 public function og_membership_delete($ogID, $drupalID) {
755 if (function_exists('og_entity_query_alter')) {
756 // sort-of-randomly chose a function that only exists in the 7.x-2.x branch
757 // TODO: Find a more solid way to make this test
758 // Also, since we don't know how to get the entity type of the group, we'll assume it's 'node'
759 og_ungroup('node', $ogID, 'user', user_load($drupalID));
760 }
761 else {
762 // Works for the OG 7.x-1.x branch
763 og_ungroup($ogID, 'user', user_load($drupalID));
764 }
765 }
766
767 /**
768 * @inheritDoc
769 */
770 public function getTimeZoneString() {
771 global $user;
772 // Note that 0 is a valid timezone (GMT) so we use strlen not empty to check.
773 if (variable_get('configurable_timezones', 1) && $user->uid && isset($user->timezone) && strlen($user->timezone)) {
774 $timezone = $user->timezone;
775 }
776 else {
777 $timezone = variable_get('date_default_timezone', NULL);
778 }
779 if (!$timezone) {
780 $timezone = parent::getTimeZoneString();
781 }
782 return $timezone;
783 }
784
785 /**
786 * @inheritDoc
787 */
788 public function setHttpHeader($name, $value) {
789 drupal_add_http_header($name, $value);
790 }
791
792 }