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'] = self
::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'] = self
::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 * Check if a resource url is within the drupal directory and format appropriately
412 * @param url (reference)
414 * @return bool: TRUE for internal paths, FALSE for external
416 static function formatResourceUrl(&$url) {
418 $base = CRM_Core_Config
::singleton()->resourceBase
;
420 // Handle absolute urls
421 if (strpos($url, $base_url) === 0) {
423 $url = trim(str_replace($base_url, '', $url), '/');
425 // Handle relative urls
426 elseif (strpos($url, $base) === 0) {
428 $url = substr(drupal_get_path('module', 'civicrm'), 0, -6) . trim(substr($url, strlen($base)), '/');
430 // Strip query string
431 $q = strpos($url, '?');
432 if ($q && $internal) {
433 $url = substr($url, 0, $q);
439 * rewrite various system urls to https
446 function mapConfigToSSL() {
448 $base_url = str_replace('http://', 'https://', $base_url);
452 * figure out the post url for the form
454 * @param mix $action the default action if one is pre-specified
456 * @return string the url to post the form
459 function postURL($action) {
460 if (!empty($action)) {
464 return $this->url($_GET['q']);
468 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
470 * @param $path string The path being linked to, such as "civicrm/add"
471 * @param $query string A query string to append to the link.
472 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
473 * Useful for links that will be displayed outside the site, such as in an
475 * @param $fragment string A fragment identifier (named anchor) to append to the link.
476 * @param $htmlize boolean whether to convert to html eqivalant
477 * @param $frontend boolean a gross joomla hack
479 * @return string an HTML string containing a link to the given path.
483 function url($path = NULL, $query = NULL, $absolute = FALSE,
484 $fragment = NULL, $htmlize = TRUE,
485 $frontend = FALSE, $forceBackend = FALSE
487 $config = CRM_Core_Config
::singleton();
488 $script = 'index.php';
490 $path = CRM_Utils_String
::stripPathChars($path);
492 if (isset($fragment)) {
493 $fragment = '#' . $fragment;
496 if (!isset($config->useFrameworkRelativeBase
)) {
497 $base = parse_url($config->userFrameworkBaseURL
);
498 $config->useFrameworkRelativeBase
= $base['path'];
500 $base = $absolute ?
$config->userFrameworkBaseURL
: $config->useFrameworkRelativeBase
;
502 $separator = $htmlize ?
'&' : '&';
504 if (!$config->cleanURL
) {
507 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
510 return $base . $script . '?q=' . $path . $fragment;
515 return $base . $script . '?' . $query . $fragment;
518 return $base . $fragment;
525 return $base . $path . '?' . $query . $fragment;
528 return $base . $path . $fragment;
533 return $base . $script . '?' . $query . $fragment;
536 return $base . $fragment;
543 * Authenticate the user against the drupal db
545 * @param string $name the user name
546 * @param string $password the password for the above user name
547 * @param boolean $loadCMSBootstrap load cms bootstrap?
548 * @param NULL|string $realPath filename of script
550 * @return mixed false if no auth
552 * contactID, ufID, unique string ) if success
555 static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
556 require_once 'DB.php';
558 $config = CRM_Core_Config
::singleton();
560 $dbDrupal = DB
::connect($config->userFrameworkDSN
);
561 if (DB
::isError($dbDrupal)) {
562 CRM_Core_Error
::fatal("Cannot connect to drupal db via $config->userFrameworkDSN, " . $dbDrupal->getMessage());
565 $account = $userUid = $userMail = NULL;
566 if ($loadCMSBootstrap) {
567 $bootStrapParams = array();
568 if ($name && $password) {
569 $bootStrapParams = array(
574 CRM_Utils_System
::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
578 $userUid = $user->uid
;
579 $userMail = $user->mail
;
584 // SOAP cannot load drupal bootstrap and hence we do it the old way
585 // Contact CiviSMTP folks if we run into issues with this :)
586 $cmsPath = $config->userSystem
->cmsRootPath($realPath);
588 require_once ("$cmsPath/includes/bootstrap.inc");
589 require_once ("$cmsPath/includes/password.inc");
591 $strtolower = function_exists('mb_strtolower') ?
'mb_strtolower' : 'strtolower';
592 $name = $dbDrupal->escapeSimple($strtolower($name));
595 FROM {$config->userFrameworkUsersTableName} u
596 WHERE LOWER(u.name) = '$name'
600 $query = $dbDrupal->query($sql);
601 $row = $query->fetchRow(DB_FETCHMODE_ASSOC
);
604 $fakeDrupalAccount = drupal_anonymous_user();
605 $fakeDrupalAccount->name
= $name;
606 $fakeDrupalAccount->pass
= $row['pass'];
607 $passwordCheck = user_check_password($password, $fakeDrupalAccount);
608 if ($passwordCheck) {
609 $userUid = $row['uid'];
610 $userMail = $row['mail'];
615 if ($userUid && $userMail) {
616 CRM_Core_BAO_UFMatch
::synchronizeUFMatch($account, $userUid, $userMail, 'Drupal');
617 $contactID = CRM_Core_BAO_UFMatch
::getContactId($userUid);
621 return array($contactID, $userUid, mt_rand());
627 * Load user into session
629 function loadUser($username) {
632 $user = user_load_by_name($username);
634 if (empty($user->uid
)) {
639 $contact_id = CRM_Core_BAO_UFMatch
::getContactId($uid);
641 // lets store contact id and user id in session
642 $session = CRM_Core_Session
::singleton();
643 $session->set('ufID', $uid);
644 $session->set('userID', $contact_id);
649 * Perform any post login activities required by the UF -
650 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
651 * calls hook_user op 'login' and generates a new session.
653 * @param array params
655 * FIXME: Document values accepted/required by $params
657 function userLoginFinalize($params = array()){
658 user_login_finalize($params);
662 * Determine the native ID of the CMS user
667 function getUfId($username) {
668 $user = user_load_by_name($username);
669 if (empty($user->uid
)) {
676 * Set a message in the UF to display to a user
678 * @param string $message the message to set
682 function setMessage($message) {
683 drupal_set_message($message);
686 function permissionDenied() {
687 drupal_access_denied();
691 module_load_include('inc', 'user', 'user.pages');
692 return user_logout();
695 function updateCategories() {
696 // copied this from profile.module. Seems a bit inefficient, but i dont know a better way
703 * Get the default location for CiviCRM blocks
707 function getDefaultBlockLocation() {
708 return 'sidebar_first';
712 * Get the locale set in the hosting CMS
714 * @return string with the locale or null for none
716 function getUFLocale() {
717 // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale
718 // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx
719 // sometimes for CLI based on order called, this might not be set and/or empty
722 if (empty($language)) {
726 if ($language->language
== 'zh-hans') {
730 if ($language->language
== 'zh-hant') {
734 if (preg_match('/^.._..$/', $language->language
)) {
735 return $language->language
;
738 return CRM_Core_I18n_PseudoConstant
::longForShort(substr($language->language
, 0, 2));
741 function getVersion() {
742 return defined('VERSION') ? VERSION
: 'Unknown';
746 * load drupal bootstrap
748 * @param array $params Either uid, or name & pass.
749 * @param boolean $loadUser boolean Require CMS user load.
750 * @param boolean $throwError If true, print error on failure and exit.
751 * @param boolean|string $realPath path to script
753 function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
754 //take the cms root path.
755 $cmsPath = $this->cmsRootPath($realPath);
757 if (!file_exists("$cmsPath/includes/bootstrap.inc")) {
759 echo '<br />Sorry, could not locate bootstrap.inc\n';
764 // load drupal bootstrap
766 define('DRUPAL_ROOT', $cmsPath);
768 // For drupal multi-site CRM-11313
769 if ($realPath && strpos($realPath, 'sites/all/modules/') === FALSE) {
770 preg_match('@sites/([^/]*)/modules@s', $realPath, $matches);
771 if (!empty($matches[1])) {
772 $_SERVER['HTTP_HOST'] = $matches[1];
775 require_once 'includes/bootstrap.inc';
776 // @ to suppress notices eg 'DRUPALFOO already defined'.
777 @drupal_bootstrap
(DRUPAL_BOOTSTRAP_FULL
);
779 // explicitly setting error reporting, since we cannot handle drupal related notices
781 if (!function_exists('module_exists') ||
!module_exists('civicrm')) {
783 echo '<br />Sorry, could not load drupal bootstrap.';
789 // seems like we've bootstrapped drupal
790 $config = CRM_Core_Config
::singleton();
792 // lets also fix the clean url setting
794 $config->cleanURL
= (int) variable_get('clean_url', '0');
796 // we need to call the config hook again, since we now know
797 // all the modules that are listening on it, does not apply
798 // to J! and WP as yet
800 CRM_Utils_Hook
::config($config);
806 $uid = CRM_Utils_Array
::value('uid', $params);
808 //load user, we need to check drupal permissions.
809 $name = CRM_Utils_Array
::value('name', $params, FALSE) ?
$params['name'] : trim(CRM_Utils_Array
::value('name', $_REQUEST));
810 $pass = CRM_Utils_Array
::value('pass', $params, FALSE) ?
$params['pass'] : trim(CRM_Utils_Array
::value('pass', $_REQUEST));
813 $uid = user_authenticate($name, $pass);
816 echo '<br />Sorry, unrecognized username or password.';
825 $account = user_load($uid);
826 if ($account && $account->uid
) {
834 echo '<br />Sorry, can not load CMS user account.';
838 // CRM-6948: When using loadBootStrap, it's implicit that CiviCRM has already loaded its settings
839 // which means that define(CIVICRM_CLEANURL) was correctly set.
841 $config = CRM_Core_Config
::singleton();
842 $config->cleanURL
= (int)variable_get('clean_url', '0');
844 // CRM-8655: Drupal wasn't available during bootstrap, so hook_civicrm_config never executes
845 CRM_Utils_Hook
::config($config);
853 function cmsRootPath($scriptFilename = NULL) {
854 $cmsRoot = $valid = NULL;
856 if (!is_null($scriptFilename)) {
857 $path = $scriptFilename;
860 $path = $_SERVER['SCRIPT_FILENAME'];
863 if (function_exists('drush_get_context')) {
864 // drush anyway takes care of multisite install etc
865 return drush_get_context('DRUSH_DRUPAL_ROOT');
868 $pathVars = explode('/',
869 str_replace('//', '/',
870 str_replace('\\', '/', $path)
874 //lets store first var,
875 //need to get back for windows.
876 $firstVar = array_shift($pathVars);
878 //lets remove sript name to reduce one iteration.
879 array_pop($pathVars);
881 //CRM-7429 --do check for upper most 'includes' dir,
882 //which would effectually work for multisite installation.
884 $cmsRoot = $firstVar . '/' . implode('/', $pathVars);
885 $cmsIncludePath = "$cmsRoot/includes";
886 //stop as we found bootstrap.
887 if (@opendir
($cmsIncludePath) &&
888 file_exists("$cmsIncludePath/bootstrap.inc")
893 //remove one directory level.
894 array_pop($pathVars);
895 } while (count($pathVars));
897 return ($valid) ?
$cmsRoot : NULL;
901 * check is user logged in.
903 * @return boolean true/false.
905 public function isUserLoggedIn() {
907 if (function_exists('user_is_logged_in')) {
908 $isloggedIn = user_is_logged_in();
915 * Get currently logged in user uf id.
917 * @return int $userID logged in user uf id.
919 public function getLoggedInUfID() {
921 if (function_exists('user_is_logged_in') &&
922 user_is_logged_in() &&
923 function_exists('user_uid_optional_to_arg')
925 $ufID = user_uid_optional_to_arg(array());
932 * Format the url as per language Negotiation.
936 * @return string $url, formatted url.
939 function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) {
944 //CRM-7803 -from d7 onward.
945 $config = CRM_Core_Config
::singleton();
946 if (function_exists('variable_get') &&
947 module_exists('locale') &&
948 function_exists('language_negotiation_get')
952 //does user configuration allow language
953 //support from the URL (Path prefix or domain)
954 if (language_negotiation_get('language') == 'locale-url') {
955 $urlType = variable_get('locale_language_negotiation_url_part');
958 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX
) {
959 if (isset($language->prefix
) && $language->prefix
) {
960 if ($addLanguagePart) {
961 $url .= $language->prefix
. '/';
963 if ($removeLanguagePart) {
964 $url = str_replace("/{$language->prefix}/", '/', $url);
969 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN
) {
970 if (isset($language->domain
) && $language->domain
) {
971 if ($addLanguagePart) {
972 $url = CRM_Utils_File
::addTrailingSlash($language->domain
, '/');
974 if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) {
975 $url = str_replace('\\', '/', $url);
976 $parseUrl = parse_url($url);
978 //kinda hackish but not sure how to do it right
979 //hope http_build_url() will help at some point.
980 if (is_array($parseUrl) && !empty($parseUrl)) {
981 $urlParts = explode('/', $url);
982 $hostKey = array_search($parseUrl['host'], $urlParts);
983 $ufUrlParts = parse_url(CIVICRM_UF_BASEURL
);
984 $urlParts[$hostKey] = $ufUrlParts['host'];
985 $url = implode('/', $urlParts);
997 * Find any users/roles/security-principals with the given permission
998 * and replace it with one or more permissions.
1000 * @param $oldPerm string
1001 * @param $newPerms array, strings
1005 function replacePermission($oldPerm, $newPerms) {
1006 $roles = user_roles(FALSE, $oldPerm);
1007 if (!empty($roles)) {
1008 foreach (array_keys($roles) as $rid) {
1009 user_role_revoke_permissions($rid, array($oldPerm));
1010 user_role_grant_permissions($rid, $newPerms);
1016 * Get a list of all installed modules, including enabled and disabled ones
1018 * @return array CRM_Core_Module
1020 function getModules() {
1022 $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1');
1023 foreach ($q as $row) {
1024 $result[] = new CRM_Core_Module('drupal.' . $row->name
, ($row->status
== 1) ?
TRUE : FALSE);
1030 * Wrapper for og_membership creation
1032 * @param integer $ogID Organic Group ID
1033 * @param integer $drupalID drupal User ID
1035 function og_membership_create($ogID, $drupalID){
1036 if (function_exists('og_entity_query_alter')) {
1037 // sort-of-randomly chose a function that only exists in the // 7.x-2.x branch
1039 // @TODO Find more solid way to check - try system_get_info('module', 'og').
1041 // Also, since we don't know how to get the entity type of the // group, we'll assume it's 'node'
1042 og_group('node', $ogID, array('entity' => user_load($drupalID)));
1045 // Works for the OG 7.x-1.x branch
1046 og_group($ogID, array('entity' => user_load($drupalID)));
1051 * Wrapper for og_membership deletion
1053 * @param integer $ogID Organic Group ID
1054 * @param integer $drupalID drupal User ID
1056 function og_membership_delete($ogID, $drupalID) {
1057 if (function_exists('og_entity_query_alter')) {
1058 // sort-of-randomly chose a function that only exists in the 7.x-2.x branch
1059 // TODO: Find a more solid way to make this test
1060 // Also, since we don't know how to get the entity type of the group, we'll assume it's 'node'
1061 og_ungroup('node', $ogID, 'user', user_load($drupalID));
1063 // Works for the OG 7.x-1.x branch
1064 og_ungroup($ogID, 'user', user_load($drupalID));
1069 * Reset any system caches that may be required for proper CiviCRM
1073 drupal_flush_all_caches();