Index: gallery.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/gallery/gallery.module,v retrieving revision 1.15 diff -u -F^f -r1.15 gallery.module --- gallery.module 16 Dec 2005 02:24:26 -0000 1.15 +++ gallery.module 15 Mar 2006 22:44:15 -0000 @@ -32,18 +32,13 @@ function gallery_menu($may_cache) { * Implementation of hook_settings */ function gallery_settings() { - $form['gallery_dir'] = array( + $form['gallery_g2Uri'] = array( '#type' => 'textfield', '#title' => t('Location of Gallery2'), - '#default_value' => variable_get('gallery_dir', 'gallery2/'), - '#description' => t('Path to your gallery2 directory, relative to the root directory of your drupal installation. Please include a trailing slash ("/").'), - ); - $form['gallery_drupal_dir'] = array( - '#type' => 'textfield', - '#title' => t('Location of Drupal'), - '#default_value' => variable_get('gallery_drupal_dir', '/'), - '#description' => t('Path to your drupal directory, relative to the root of your website. Please include a trailing slash ("/").'), + '#default_value' => variable_get('gallery_g2Uri', '/gallery2/'), + '#description' => t('Path to your gallery2 directory, relative to the root directory of your drupal installation. Please include a starting and trailing slash ("/").'), ); + $form['gallery_error_mode'] = array( '#type' => 'checkboxes', '#title' => t('Error logging'), @@ -84,7 +79,7 @@ function gallery_user($op, &$edit, &$use 'hashedpassword' => $user->pass, 'hashmethod' => 'md5' )); - if ($ret->isError()) { + if ($ret) { gallery_error(t('Error creating Gallery user'), $ret); return; } @@ -110,7 +105,7 @@ function gallery_user($op, &$edit, &$use 'language' => $language, 'hashedpassword' => $pass, 'hashmethod' => 'md5')); - if ($ret->isError()) { + if ($ret) { // try to create user then. $ret = GalleryEmbed::createUser($user->uid, array('username' => $name, @@ -120,7 +115,7 @@ function gallery_user($op, &$edit, &$use 'hashedpassword' => $pass, 'hashmethod' => 'md5' )); - if ($ret->isError()) { + if ($ret) { gallery_error(t('Error updating Gallery user'), $ret); return; } @@ -136,7 +131,7 @@ function gallery_user($op, &$edit, &$use } $ret = GalleryEmbed::deleteUser($user->uid); - if ($ret->isError()) { + if ($ret) { gallery_error(t('Error deleting Gallery user'), $ret); } GalleryEmbed::done(); @@ -211,7 +206,7 @@ function gallery_block($op = 'list', $de $block = array(); list($ret, $content, $head) = GalleryEmbed::getImageBlock($params); - if ($ret->isError()) { + if ($ret) { gallery_error(t('Unable to get Gallery image block'), $ret); return; } else { @@ -230,7 +225,7 @@ function gallery_block($op = 'list', $de } $ret = GalleryEmbed::done(); - if ($ret->isError()) { + if ($ret) { gallery_error(t('Unable to complete Gallery request'), $ret); return; } @@ -255,7 +250,7 @@ function gallery_search($op = 'search', } list ($ret, $results) = GalleryEmbed::searchScan($keys, 20); - if (!$ret->isError()) { + if (!$ret) { $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator(); foreach ($results as $name => $module) { if (count($module['results']) > 0) { @@ -305,6 +300,7 @@ function gallery_page() { if (!empty($javascript)) { drupal_set_html_head(implode("\n",$javascript)); } + drupal_set_html_head(implode("\n",$css)); drupal_set_title($title); print theme('page', $result['bodyHtml']); @@ -317,38 +313,39 @@ function gallery_page() { function _gallery_init($full = false) { global $user; - $galleryDir = variable_get('gallery_dir', 'gallery2/'); + $g2Uri = variable_get('gallery_g2Uri', '/gallery2/'); + $embedPath = '.' . $g2Uri . 'embed.php'; - $embedPath = $galleryDir . '/embed.php'; if (!is_readable($embedPath)) { return array(false, null); } + include_once($embedPath); + - include_once($galleryDir . '/embed.php'); - // TODO: using the galleryDir as the relativeG2Path requires that - // Gallery2 be installed as a subdir of Drupal, which is not necessarily - // ideal. Make this a configuration option. - $relativeG2Path = $galleryDir; - - $embedUri = url('gallery'); - $embedPath =variable_get('gallery_drupal_dir', '/'); - $params = array('embedUri' => $embedUri, - 'embedPath' => $embedPath, - 'relativeG2Path' => $relativeG2Path, + $params = array('embedUri' => url('gallery'), + 'g2Uri' => $g2Uri, 'loginRedirect' => url('user/login'), 'activeUserId' => $user->uid, 'activeLanguage' => $user->language, 'fullInit' => $full); $ret = GalleryEmbed::init($params); + + if (!$ret) { + return array(true, null); + } + if ($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->isError() && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { - return array(false, $ret); + if ($ret) { + if (!$ret->getErrorCode() & ERROR_MISSING_OBJECT) { + return array(false, $ret); + } } if (!isset($g2_user)) { @@ -357,19 +354,19 @@ function _gallery_init($full = false) { if ($user->uid == 1) { list ($ret, $admin_group_id) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup'); - if ($ret->isError()) { + if ($ret) { return array(false, $ret); } list ($ret, $g2_users) = GalleryCoreApi::fetchUsersForGroup($admin_group_id); - if ($ret->isError()) { + 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->isError()) { + if ($ret) { return array(false, $ret); } } @@ -377,7 +374,7 @@ function _gallery_init($full = false) { if (isset($g2_user)) { $ret = GalleryEmbed::addExternalIdMapEntry($user->uid, $g2_user->getId(), 'GalleryUser'); - if ($ret->isError()) { + if ($ret) { return array(false, $ret); } } else { @@ -388,13 +385,12 @@ function _gallery_init($full = false) { 'language' => $user->language, 'hashedpassword' => $user->pass, 'hashmethod' => 'md5')); - if ($ret->isError()) { + if ($ret) { return array(false, $ret); } } } - - return array(true, GalleryStatus::success()); + return array(true, null); } function gallery_error($message, $ret) {