3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * Drupal specific stuff goes here
39 class CRM_Utils_System_Drupal
extends CRM_Utils_System_DrupalBase
{
42 * Function to create a user in Drupal.
44 * @param array $params associated array
45 * @param string $mail email id for cms user
47 * @return uid if user exists, false otherwise
52 function createUser(&$params, $mail) {
53 $form_state = array();
54 $form_state['input'] = array(
55 'name' => $params['cms_name'],
56 'mail' => $params[$mail],
57 'op' => 'Create new account',
60 $admin = user_access('administer users');
61 if (!variable_get('user_email_verification', TRUE) ||
$admin) {
62 $form_state['input']['pass'] = array('pass1'=>$params['cms_pass'],'pass2'=>$params['cms_pass']);
65 if(!empty($params['notify'])){
66 $form_state['input']['notify'] = $params['notify'];
69 $form_state['rebuild'] = FALSE;
70 $form_state['programmed'] = TRUE;
71 $form_state['complete form'] = FALSE;
72 $form_state['method'] = 'post';
73 $form_state['build_info']['args'] = array();
75 * if we want to submit this form more than once in a process (e.g. create more than one user)
76 * we must force it to validate each time for this form. Otherwise it will not validate
77 * subsequent submissions and the manner in which the password is passed in will be invalid
79 $form_state['must_validate'] = TRUE;
80 $config = CRM_Core_Config
::singleton();
82 // we also need to redirect b
83 $config->inCiviCRM
= TRUE;
85 $form = drupal_retrieve_form('user_register_form', $form_state);
86 $form_state['process_input'] = 1;
87 $form_state['submitted'] = 1;
88 $form['#array_parents'] = array();
89 $form['#tree'] = FALSE;
90 drupal_process_form('user_register_form', $form, $form_state);
92 $config->inCiviCRM
= FALSE;
94 if (form_get_errors()) {
97 return $form_state['user']->uid
;
101 * Change user name in host CMS
103 * @param integer $ufID User ID in CMS
104 * @param string $ufName User name
106 function updateCMSName($ufID, $ufName) {
108 if (function_exists('user_load')) {
109 $user = user_load($ufID);
110 if ($user->mail
!= $ufName) {
111 user_save($user, array('mail' => $ufName));
112 $user = user_load($ufID);
118 * Check if username and email exists in the drupal db
120 * @params $params array array of name and mail values
121 * @params $errors array array of errors
122 * @params $emailName string field label for the 'email'
126 static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
127 $config = CRM_Core_Config
::singleton();
129 $dao = new CRM_Core_DAO();
130 $name = $dao->escape(CRM_Utils_Array
::value('name', $params));
131 $email = $dao->escape(CRM_Utils_Array
::value('mail', $params));
132 $errors = form_get_errors();
134 // unset drupal messages to avoid twice display of errors
135 unset($_SESSION['messages']);
138 if (CRM_Utils_Array
::value('name', $params)) {
139 if ($nameError = user_validate_name($params['name'])) {
140 $errors['cms_name'] = $nameError;
144 "SELECT uid FROM {users} WHERE name = :name",
145 array(':name' => $params['name'])
148 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $params['name']));
153 if (CRM_Utils_Array
::value('mail', $params)) {
154 if ($emailError = user_validate_mail($params['mail'])) {
155 $errors[$emailName] = $emailError;
159 "SELECT uid FROM {users} WHERE mail = :mail",
160 array(':mail' => $params['mail'])
163 $resetUrl = $config->userFrameworkBaseURL
. 'user/password';
164 $errors[$emailName] = ts('The email address %1 is already registered. <a href="%2">Have you forgotten your password?</a>',
165 array(1 => $params['mail'], 2 => $resetUrl)
173 * Function to get the drupal destination string. When this is passed in the
174 * URL the user will be directed to it after filling in the drupal form
176 * @param object $form Form object representing the 'current' form - to which the user will be returned
177 * @return string $destination destination value for URL
180 function getLoginDestination(&$form) {
183 $id = $form->get('id');
188 $gid = $form->get('gid');
190 $args .= "&gid=$gid";
193 // Setup Personal Campaign Page link uses pageId
194 $pageId = $form->get('pageId');
196 $component = $form->get('component');
197 $args .= "&pageId=$pageId&component=$component&action=add";
204 // append destination so user is returned to form they came from after login
205 $destination = CRM_Utils_System
::currentPath() . '?reset=1' . $args;
211 * Get user login URL for hosting CMS (method declared in each CMS system class)
213 * @param string $destination - if present, add destination to querystring (works for Drupal only)
215 * @return string - loginURL for the current CMS
218 public function getLoginURL($destination = '') {
219 $config = CRM_Core_Config
::singleton();
220 $loginURL = $config->userFrameworkBaseURL
;
222 if (!empty($destination)) {
223 // append destination so user is returned to form they came from after login
224 $loginURL .= '?destination=' . urlencode($destination);
231 * sets the title of the page
233 * @param string $title
234 * @paqram string $pageTitle
239 function setTitle($title, $pageTitle = NULL) {
240 if (arg(0) == 'civicrm') {
245 drupal_set_title($pageTitle, PASS_THROUGH
);
250 * Append an additional breadcrumb tag to the existing breadcrumb
252 * @param string $title
258 function appendBreadCrumb($breadCrumbs) {
259 $breadCrumb = drupal_get_breadcrumb();
261 if (is_array($breadCrumbs)) {
262 foreach ($breadCrumbs as $crumbs) {
263 if (stripos($crumbs['url'], 'id%%')) {
264 $args = array('cid', 'mid');
265 foreach ($args as $a) {
266 $val = CRM_Utils_Request
::retrieve($a, 'Positive', CRM_Core_DAO
::$_nullObject,
270 $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']);
274 $breadCrumb[] = "<a href=\"{$crumbs['url']}\">{$crumbs['title']}</a>";
277 drupal_set_breadcrumb($breadCrumb);
281 * Reset an additional breadcrumb tag to the existing breadcrumb
286 function resetBreadCrumb() {
288 drupal_set_breadcrumb($bc);
292 * Append a string to the head of the html file
294 * @param string $header the new string to be appended
299 function addHTMLHead($header) {
301 if (!empty($header)) {
302 $key = 'civi_' . ++
$count;
305 '#markup' => $header,
307 drupal_add_html_head($data, $key);
314 * @param $url: string, absolute path to file
315 * @param $region string, location within the document: 'html-header', 'page-header', 'page-footer'
317 * Note: This function is not to be called directly
318 * @see CRM_Core_Region::render()
320 * @return bool TRUE if we support this operation in this CMS, FALSE otherwise
323 public function addScriptUrl($url, $region) {
324 $params = array('group' => JS_LIBRARY
, 'weight' => 10);
328 $params['scope'] = substr($region, 5);
333 // If the path is within the drupal directory we can use the more efficient 'file' setting
334 $params['type'] = $this->formatResourceUrl($url) ?
'file' : 'external';
335 drupal_add_js($url, $params);
340 * Add an inline script
342 * @param $code: string, javascript code
343 * @param $region string, location within the document: 'html-header', 'page-header', 'page-footer'
345 * Note: This function is not to be called directly
346 * @see CRM_Core_Region::render()
348 * @return bool TRUE if we support this operation in this CMS, FALSE otherwise
351 public function addScript($code, $region) {
352 $params = array('type' => 'inline', 'group' => JS_LIBRARY
, 'weight' => 10);
356 $params['scope'] = substr($region, 5);
361 drupal_add_js($code, $params);
368 * @param $url: string, absolute path to file
369 * @param $region string, location within the document: 'html-header', 'page-header', 'page-footer'
371 * Note: This function is not to be called directly
372 * @see CRM_Core_Region::render()
374 * @return bool TRUE if we support this operation in this CMS, FALSE otherwise
377 public function addStyleUrl($url, $region) {
378 if ($region != 'html-header') {
382 // If the path is within the drupal directory we can use the more efficient 'file' setting
383 $params['type'] = $this->formatResourceUrl($url) ?
'file' : 'external';
384 drupal_add_css($url, $params);
389 * Add an inline style
391 * @param $code: string, css code
392 * @param $region string, location within the document: 'html-header', 'page-header', 'page-footer'
394 * Note: This function is not to be called directly
395 * @see CRM_Core_Region::render()
397 * @return bool TRUE if we support this operation in this CMS, FALSE otherwise
400 public function addStyle($code, $region) {
401 if ($region != 'html-header') {
404 $params = array('type' => 'inline');
405 drupal_add_css($code, $params);
410 * rewrite various system urls to https
417 function mapConfigToSSL() {
419 $base_url = str_replace('http://', 'https://', $base_url);
423 * figure out the post url for the form
425 * @param mix $action the default action if one is pre-specified
427 * @return string the url to post the form
430 function postURL($action) {
431 if (!empty($action)) {
435 return $this->url($_GET['q']);
439 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
441 * @param $path string The path being linked to, such as "civicrm/add"
442 * @param $query string A query string to append to the link.
443 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
444 * Useful for links that will be displayed outside the site, such as in an
446 * @param $fragment string A fragment identifier (named anchor) to append to the link.
447 * @param $htmlize boolean whether to convert to html eqivalant
448 * @param $frontend boolean a gross joomla hack
450 * @return string an HTML string containing a link to the given path.
454 function url($path = NULL, $query = NULL, $absolute = FALSE,
455 $fragment = NULL, $htmlize = TRUE,
456 $frontend = FALSE, $forceBackend = FALSE
458 $config = CRM_Core_Config
::singleton();
459 $script = 'index.php';
461 $path = CRM_Utils_String
::stripPathChars($path);
463 if (isset($fragment)) {
464 $fragment = '#' . $fragment;
467 if (!isset($config->useFrameworkRelativeBase
)) {
468 $base = parse_url($config->userFrameworkBaseURL
);
469 $config->useFrameworkRelativeBase
= $base['path'];
471 $base = $absolute ?
$config->userFrameworkBaseURL
: $config->useFrameworkRelativeBase
;
473 $separator = $htmlize ?
'&' : '&';
475 if (!$config->cleanURL
) {
478 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
481 return $base . $script . '?q=' . $path . $fragment;
486 return $base . $script . '?' . $query . $fragment;
489 return $base . $fragment;
496 return $base . $path . '?' . $query . $fragment;
499 return $base . $path . $fragment;
504 return $base . $script . '?' . $query . $fragment;
507 return $base . $fragment;
514 * Authenticate the user against the drupal db
516 * @param string $name the user name
517 * @param string $password the password for the above user name
518 * @param boolean $loadCMSBootstrap load cms bootstrap?
519 * @param NULL|string $realPath filename of script
521 * @return mixed false if no auth
523 * contactID, ufID, unique string ) if success
526 static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
527 require_once 'DB.php';
529 $config = CRM_Core_Config
::singleton();
531 $dbDrupal = DB
::connect($config->userFrameworkDSN
);
532 if (DB
::isError($dbDrupal)) {
533 CRM_Core_Error
::fatal("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage());
536 $account = $userUid = $userMail = NULL;
537 if ($loadCMSBootstrap) {
538 $bootStrapParams = array();
539 if ($name && $password) {
540 $bootStrapParams = array(
545 CRM_Utils_System
::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
549 $userUid = $user->uid
;
550 $userMail = $user->mail
;
555 // SOAP cannot load drupal bootstrap and hence we do it the old way
556 // Contact CiviSMTP folks if we run into issues with this :)
557 $cmsPath = $config->userSystem
->cmsRootPath($realPath);
559 require_once ("$cmsPath/includes/bootstrap.inc");
560 require_once ("$cmsPath/includes/password.inc");
562 $strtolower = function_exists('mb_strtolower') ?
'mb_strtolower' : 'strtolower';
563 $name = $dbDrupal->escapeSimple($strtolower($name));
566 FROM {$config->userFrameworkUsersTableName} u
567 WHERE LOWER(u.name) = '$name'
571 $query = $dbDrupal->query($sql);
572 $row = $query->fetchRow(DB_FETCHMODE_ASSOC
);
575 $fakeDrupalAccount = drupal_anonymous_user();
576 $fakeDrupalAccount->name
= $name;
577 $fakeDrupalAccount->pass
= $row['pass'];
578 $passwordCheck = user_check_password($password, $fakeDrupalAccount);
579 if ($passwordCheck) {
580 $userUid = $row['uid'];
581 $userMail = $row['mail'];
586 if ($userUid && $userMail) {
587 CRM_Core_BAO_UFMatch
::synchronizeUFMatch($account, $userUid, $userMail, 'Drupal');
588 $contactID = CRM_Core_BAO_UFMatch
::getContactId($userUid);
592 return array($contactID, $userUid, mt_rand());
598 * Load user into session
600 function loadUser($username) {
603 $user = user_load_by_name($username);
605 if (empty($user->uid
)) {
610 $contact_id = CRM_Core_BAO_UFMatch
::getContactId($uid);
612 // lets store contact id and user id in session
613 $session = CRM_Core_Session
::singleton();
614 $session->set('ufID', $uid);
615 $session->set('userID', $contact_id);
620 * Perform any post login activities required by the UF -
621 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
622 * calls hook_user op 'login' and generates a new session.
624 * @param array params
626 * FIXME: Document values accepted/required by $params
628 function userLoginFinalize($params = array()){
629 user_login_finalize($params);
633 * Determine the native ID of the CMS user
638 function getUfId($username) {
639 $user = user_load_by_name($username);
640 if (empty($user->uid
)) {
647 * Set a message in the UF to display to a user
649 * @param string $message the message to set
653 function setMessage($message) {
654 drupal_set_message($message);
657 function permissionDenied() {
658 drupal_access_denied();
662 module_load_include('inc', 'user', 'user.pages');
663 return user_logout();
666 function updateCategories() {
667 // copied this from profile.module. Seems a bit inefficient, but i dont know a better way
674 * Get the default location for CiviCRM blocks
678 function getDefaultBlockLocation() {
679 return 'sidebar_first';
683 * Get the locale set in the hosting CMS
685 * @return string with the locale or null for none
687 function getUFLocale() {
688 // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale
689 // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx
690 // sometimes for CLI based on order called, this might not be set and/or empty
693 if (empty($language)) {
697 if ($language->language
== 'zh-hans') {
701 if ($language->language
== 'zh-hant') {
705 if (preg_match('/^.._..$/', $language->language
)) {
706 return $language->language
;
709 return CRM_Core_I18n_PseudoConstant
::longForShort(substr($language->language
, 0, 2));
712 function getVersion() {
713 return defined('VERSION') ? VERSION
: 'Unknown';
717 * load drupal bootstrap
719 * @param array $params Either uid, or name & pass.
720 * @param boolean $loadUser boolean Require CMS user load.
721 * @param boolean $throwError If true, print error on failure and exit.
722 * @param boolean|string $realPath path to script
724 function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
725 //take the cms root path.
726 $cmsPath = $this->cmsRootPath($realPath);
728 if (!file_exists("$cmsPath/includes/bootstrap.inc")) {
730 echo '<br />Sorry, could not locate bootstrap.inc\n';
735 // load drupal bootstrap
737 define('DRUPAL_ROOT', $cmsPath);
739 // For drupal multi-site CRM-11313
740 if ($realPath && strpos($realPath, 'sites/all/modules/') === FALSE) {
741 preg_match('@sites/([^/]*)/modules@s', $realPath, $matches);
742 if (!empty($matches[1])) {
743 $_SERVER['HTTP_HOST'] = $matches[1];
746 require_once 'includes/bootstrap.inc';
747 // @ to suppress notices eg 'DRUPALFOO already defined'.
748 @drupal_bootstrap
(DRUPAL_BOOTSTRAP_FULL
);
750 // explicitly setting error reporting, since we cannot handle drupal related notices
752 if (!function_exists('module_exists') ||
!module_exists('civicrm')) {
754 echo '<br />Sorry, could not load drupal bootstrap.';
760 // seems like we've bootstrapped drupal
761 $config = CRM_Core_Config
::singleton();
763 // lets also fix the clean url setting
765 $config->cleanURL
= (int) variable_get('clean_url', '0');
767 // we need to call the config hook again, since we now know
768 // all the modules that are listening on it, does not apply
769 // to J! and WP as yet
771 CRM_Utils_Hook
::config($config);
777 $uid = CRM_Utils_Array
::value('uid', $params);
779 //load user, we need to check drupal permissions.
780 $name = CRM_Utils_Array
::value('name', $params, FALSE) ?
$params['name'] : trim(CRM_Utils_Array
::value('name', $_REQUEST));
781 $pass = CRM_Utils_Array
::value('pass', $params, FALSE) ?
$params['pass'] : trim(CRM_Utils_Array
::value('pass', $_REQUEST));
784 $uid = user_authenticate($name, $pass);
787 echo '<br />Sorry, unrecognized username or password.';
796 $account = user_load($uid);
797 if ($account && $account->uid
) {
805 echo '<br />Sorry, can not load CMS user account.';
809 // CRM-6948: When using loadBootStrap, it's implicit that CiviCRM has already loaded its settings
810 // which means that define(CIVICRM_CLEANURL) was correctly set.
812 $config = CRM_Core_Config
::singleton();
813 $config->cleanURL
= (int)variable_get('clean_url', '0');
815 // CRM-8655: Drupal wasn't available during bootstrap, so hook_civicrm_config never executes
816 CRM_Utils_Hook
::config($config);
824 function cmsRootPath($scriptFilename = NULL) {
825 $cmsRoot = $valid = NULL;
827 if (!is_null($scriptFilename)) {
828 $path = $scriptFilename;
831 $path = $_SERVER['SCRIPT_FILENAME'];
834 if (function_exists('drush_get_context')) {
835 // drush anyway takes care of multisite install etc
836 return drush_get_context('DRUSH_DRUPAL_ROOT');
839 $pathVars = explode('/',
840 str_replace('//', '/',
841 str_replace('\\', '/', $path)
845 //lets store first var,
846 //need to get back for windows.
847 $firstVar = array_shift($pathVars);
849 //lets remove sript name to reduce one iteration.
850 array_pop($pathVars);
852 //CRM-7429 --do check for upper most 'includes' dir,
853 //which would effectually work for multisite installation.
855 $cmsRoot = $firstVar . '/' . implode('/', $pathVars);
856 $cmsIncludePath = "$cmsRoot/includes";
857 //stop as we found bootstrap.
858 if (@opendir
($cmsIncludePath) &&
859 file_exists("$cmsIncludePath/bootstrap.inc")
864 //remove one directory level.
865 array_pop($pathVars);
866 } while (count($pathVars));
868 return ($valid) ?
$cmsRoot : NULL;
872 * check is user logged in.
874 * @return boolean true/false.
876 public function isUserLoggedIn() {
878 if (function_exists('user_is_logged_in')) {
879 $isloggedIn = user_is_logged_in();
886 * Get currently logged in user uf id.
888 * @return int $userID logged in user uf id.
890 public function getLoggedInUfID() {
892 if (function_exists('user_is_logged_in') &&
893 user_is_logged_in() &&
894 function_exists('user_uid_optional_to_arg')
896 $ufID = user_uid_optional_to_arg(array());
903 * Format the url as per language Negotiation.
907 * @return string $url, formatted url.
910 function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) {
915 //CRM-7803 -from d7 onward.
916 $config = CRM_Core_Config
::singleton();
917 if (function_exists('variable_get') &&
918 module_exists('locale') &&
919 function_exists('language_negotiation_get')
923 //does user configuration allow language
924 //support from the URL (Path prefix or domain)
925 if (language_negotiation_get('language') == 'locale-url') {
926 $urlType = variable_get('locale_language_negotiation_url_part');
929 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX
) {
930 if (isset($language->prefix
) && $language->prefix
) {
931 if ($addLanguagePart) {
932 $url .= $language->prefix
. '/';
934 if ($removeLanguagePart) {
935 $url = str_replace("/{$language->prefix}/", '/', $url);
940 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN
) {
941 if (isset($language->domain
) && $language->domain
) {
942 if ($addLanguagePart) {
943 $url = (CRM_Utils_System
::isSSL() ?
'https' : 'http') . '://' . $language->domain
. base_path();
945 if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) {
946 $url = str_replace('\\', '/', $url);
947 $parseUrl = parse_url($url);
949 //kinda hackish but not sure how to do it right
950 //hope http_build_url() will help at some point.
951 if (is_array($parseUrl) && !empty($parseUrl)) {
952 $urlParts = explode('/', $url);
953 $hostKey = array_search($parseUrl['host'], $urlParts);
954 $ufUrlParts = parse_url(CIVICRM_UF_BASEURL
);
955 $urlParts[$hostKey] = $ufUrlParts['host'];
956 $url = implode('/', $urlParts);
968 * Find any users/roles/security-principals with the given permission
969 * and replace it with one or more permissions.
971 * @param $oldPerm string
972 * @param $newPerms array, strings
976 function replacePermission($oldPerm, $newPerms) {
977 $roles = user_roles(FALSE, $oldPerm);
978 if (!empty($roles)) {
979 foreach (array_keys($roles) as $rid) {
980 user_role_revoke_permissions($rid, array($oldPerm));
981 user_role_grant_permissions($rid, $newPerms);
987 * Get a list of all installed modules, including enabled and disabled ones
989 * @return array CRM_Core_Module
991 function getModules() {
993 $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1');
994 foreach ($q as $row) {
995 $result[] = new CRM_Core_Module('drupal.' . $row->name
, ($row->status
== 1) ?
TRUE : FALSE);
1001 * Wrapper for og_membership creation
1003 * @param integer $ogID Organic Group ID
1004 * @param integer $drupalID drupal User ID
1006 function og_membership_create($ogID, $drupalID){
1007 if (function_exists('og_entity_query_alter')) {
1008 // sort-of-randomly chose a function that only exists in the // 7.x-2.x branch
1010 // @TODO Find more solid way to check - try system_get_info('module', 'og').
1012 // Also, since we don't know how to get the entity type of the // group, we'll assume it's 'node'
1013 og_group('node', $ogID, array('entity' => user_load($drupalID)));
1016 // Works for the OG 7.x-1.x branch
1017 og_group($ogID, array('entity' => user_load($drupalID)));
1022 * Wrapper for og_membership deletion
1024 * @param integer $ogID Organic Group ID
1025 * @param integer $drupalID drupal User ID
1027 function og_membership_delete($ogID, $drupalID) {
1028 if (function_exists('og_entity_query_alter')) {
1029 // sort-of-randomly chose a function that only exists in the 7.x-2.x branch
1030 // TODO: Find a more solid way to make this test
1031 // Also, since we don't know how to get the entity type of the group, we'll assume it's 'node'
1032 og_ungroup('node', $ogID, 'user', user_load($drupalID));
1034 // Works for the OG 7.x-1.x branch
1035 og_ungroup($ogID, 'user', user_load($drupalID));
1040 * Get timezone from Drupal
1041 * @return boolean|string
1043 function getTimeZoneOffset(){
1045 if (variable_get('configurable_timezones', 1) && $user->uid
&& strlen($user->timezone
)) {
1046 $timezone = $user->timezone
;
1048 $timezone = variable_get('date_default_timezone', null);
1050 $tzObj = new DateTimeZone($timezone);
1051 $dateTime = new DateTime("now", $tzObj);
1052 $tz = $tzObj->getOffset($dateTime);
1058 $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60
);
1060 if($timeZoneOffset > 0){
1061 $timeZoneOffset = '+' . $timeZoneOffset;
1063 return $timeZoneOffset;
1066 * Reset any system caches that may be required for proper CiviCRM
1070 drupal_flush_all_caches();