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 (($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. return gallery_modify_user($user, 'create'); } } return array(true, null); } /** * Include css files as needed */ function gallery_css_include($css_file = 'drupal_g2.css') { /* The theme may not exist, so neither does path_to_theme(), so need to init */ global $theme; if ($theme === NULL) { $theme = init_theme(); } $output = theme('stylesheet_import', base_path() . drupal_get_path('module', 'gallery') . '/' . $css_file,'screen') ."\n"; $themecss = base_path() . path_to_theme() .'/' . $css_file; if (file_exists($themecss)) { $output .= theme('stylesheet_import', $themecss,'screen') . "\n"; } return $output; } /** * 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_exist('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; } } /* * -------------------------------------------------------------------------- * Error Functions * -------------------------------------------------------------------------- */ function gallery_error($message, $ret) { // Changed default, just in case! $error_mode = variable_get('gallery_error_mode', array(1)); if (in_array(2, $error_mode)) { drupal_set_message($message); } if (isset($ret)) { $full_message = $message . '
' . $ret->getAsHtml(); } else { $full_message = $message; } if (in_array(1, $error_mode)) { watchdog('gallery', $full_message, WATCHDOG_ERROR); } } ?>