uid>0) ? $user->uid : ''; $params = array('embedUri' => $embedUri, 'g2Uri' => $g2Uri, 'loginRedirect' => url('user/login', null, null, true), 'activeUserId' => $active_id, 'activeLanguage' => gallery_get_language($user), 'fullInit' => $full); $ret = GalleryEmbed::init($params); if (!$ret) { // No error returned, but it is still possible that the ExternalID mapping has not been done $ret2 = GalleryEmbed::isExternalIdMapped($user->uid, 'GalleryUser'); if ($ret2 && ($ret2->getErrorCode() & ERROR_MISSING_OBJECT)) { // Need to make a new user, but don't try to map anonymous user. $new_user_needed = ($user->uid>0); } } if (!empty($user->uid) && (($new_user_needed) || ($ret && ($ret->getErrorCode() & ERROR_MISSING_OBJECT)))) { // Our user mapping is missing. Make a mapping, or create a new user. $g2_user = null; // Get the G2 user that matches the Drupal username list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($user->name); if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return array(false, $ret); } if (!isset($g2_user)) { // No G2 user with a matching username. If this is the admin user, we're going to // try a little harder and match it to the oldest admin in G2. if ($user->uid == 1) { list ($ret, $admin_group_id) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup'); if ($ret) { return array(false, $ret); } list ($ret, $g2_users) = GalleryCoreApi::fetchUsersForGroup($admin_group_id); if ($ret) { return array(false, $ret); } $keys = array_keys($g2_users); $g2_user_name = $g2_users[$keys[0]]; list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($g2_user_name); if ($ret) { return array(false, $ret); } } } if (isset($g2_user)) { // The G2 user was found so add to the External ID Map $ret = GalleryEmbed::addExternalIdMapEntry($user->uid, $g2_user->getId(), 'GalleryUser'); if ($ret) { return array(false, $ret); } } else { // No matching G2 user found -- create one. $path = drupal_get_path('module', 'gallery'); require_once($path . '/gallery_user.inc'); return gallery_modify_user($user, 'create'); } } return array(true, null); } /** * Include head information with check made for uniqueness (see drupal_add_js) */ function gallery_set_html_head($info, $unique=true) { static $sent = array(); if ($unique) { // Only set html head if this info has not been sent before. $hash_info = md5($info); if (!isset($sent[$hash_info])) { drupal_set_html_head($info); $sent[$hash_info] = true; } } else { drupal_set_html_head($info); } } /** * Get the language for the user. If unknown, make a best guess. */ function gallery_get_language($user) { // Added depdev patch for language support (http://drupal.org/node/32374) // without i18 part (I seem to remember a Rewrite issue with it // Added test for no user language defined if (($user->uid==0 || !($user->language)) && module_exists('locale')) { // This is a visitor and locale module is enabled // Get drupal's default language $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1'); $row = db_fetch_object($result); return $row->locale; } else { return $user->language; } } /** * Split an image block result into individual images * (Kludge until imageblock has this option) */ function _gallery_split_imageblock($html) { /** * From http://uk.php.net/manual/en/function.preg-split.php * Split the html from image block into <...> parts */ $pattern = '/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/'; $html_array = preg_split ($pattern, trim ($html), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $ndx = 0; $images = array(); $image_html = ''; // Now iterate through this array and combine again, but on a per-image basis foreach ($html_array as $value) { $value = trim($value); $image_html .= $value; if (!strcmp($value, '