diff --git a/gallery.module b/gallery.module
index 769425b32791ad695f556c9b144cf279772ea3e4..384e2daf22d726653e2acc1f597869e22a102625 100644
--- a/gallery.module
+++ b/gallery.module
@@ -192,6 +192,7 @@ function gallery_block($op = 'list', $delta = 0, $edit = array()) {
* Main gallery display page
*/
function gallery_page() {
+ global $gallery_sidebar;
list ($success, $ret) = _gallery_init(true);
if (!$success) {
gallery_error(t('Unable to initialize embedded Gallery'), $ret);
@@ -200,12 +201,7 @@ function gallery_page() {
array('%link' => url('admin/settings/gallery')));
return $err_msg;
}
- /* Pass any excess path info to G2 - NEEDED??? */
-// $path = substr($_GET['q'], 7 /* length of 'gallery/' */);
- /* if (!empty($path)) {
- $_GET[GALLERY_FORM_VARIABLE_PREFIX . 'path'] = $path;
- }*/
- // Turn off sidebar and pathbar
+ // Turn off sidebar
GalleryCapabilities::set('showSidebarBlocks', false);
$result = GalleryEmbed::handleRequest();
if (!$result['isDone']) {
@@ -217,18 +213,21 @@ function gallery_page() {
drupal_set_title($title);
// Add pathbar. See http://gallery.menalto.com/node/33447
if (isset($result['themeData'])) {
- $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
- $breadcrumb = array(l(t('Home'), ''));
- foreach ($result['themeData']['parents'] as $parent) {
- $parent_title = $parent['title'];
- // Simple strip of bbcode (italics)
- $parent_title = str_replace("[i]", "", $parent_title);
- $parent_title = str_replace("[/i]", "", $parent_title);
- $breadcrumb[] = ''.$parent_title."";
- }
- drupal_set_breadcrumb($breadcrumb);
+ $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
+ $breadcrumb = array(l(t('Home'), ''));
+ foreach ($result['themeData']['parents'] as $parent) {
+ $parent_title = $parent['title'];
+ // Simple strip of bbcode (italics)
+ $parent_title = str_replace("[i]", "", $parent_title);
+ $parent_title = str_replace("[/i]", "", $parent_title);
+ $breadcrumb[] = ''.$parent_title."";
}
+ drupal_set_breadcrumb($breadcrumb);
+ }
+ // Store the sidebar info in a global variable for use in the gallery navigation block
+ $gallery_sidebar = $result['sidebarBlocksHtml'];
+
return $result['bodyHtml'];
}
}
diff --git a/gallery_base.inc b/gallery_base.inc
index 3dfd57bb4c482455f36542ceb4c036a297edafac..d9cbc552caec09ff39f135095ac921b6ee5a7fc9 100644
--- a/gallery_base.inc
+++ b/gallery_base.inc
@@ -29,7 +29,7 @@ function _gallery_init($full = false, $vars = null) {
$gallery_valid = $vars['gallery_valid'];
}
- if (!$gallery_valid) {
+ if ((!$gallery_valid) || (!is_readable($embedPath))) {
// It's probably now bad practice to return a null here, given that $ret=null is a gallery2
// success response
return array(false, null);
@@ -190,7 +190,7 @@ function gallery_error($message, $ret) {
if (isset($ret)) {
$full_message = $message . '
' . $ret->getAsHtml();
- } else {
+ } else {
$full_message = $message;
}
diff --git a/gallery_block.inc b/gallery_block.inc
index 36b83267f64d3782428897f8784a52ac9169913a..527b6dbffeb896bbee44a50343b04160d31b425b 100644
--- a/gallery_block.inc
+++ b/gallery_block.inc
@@ -57,7 +57,9 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
$params['albumFrame'] = variable_get('gallery_album_frame', 'none');
$params['itemFrame'] = variable_get('gallery_item_frame', 'none');
$params['linkTarget'] = variable_get('gallery_link_target', '');
-
+ if (variable_get('gallery_item_id', '') != '') {
+ $params['itemId'] = variable_get('gallery_item_id', '');
+ }
$block = array();
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
@@ -81,17 +83,14 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
break;
// 1 = Navigation Block
case 1:
- if (arg(0) == 'gallery') {
- GalleryCapabilities::set('showSidebarBlocks', false);
- $result = GalleryEmbed::handleRequest();
- if (isset($result['sidebarBlocksHtml']) && !empty($result['sidebarBlocksHtml'])) {
- $block['subject'] = t('Gallery Navigation');
- $block['content'] = '
';
- }
+ global $gallery_sidebar;
+ if ((arg(0) == 'gallery') && (isset($gallery_sidebar) && !empty($gallery_sidebar))) {
+ $block['subject'] = t('Gallery Navigation');
+ $block['content'] = '';
}
break;
// 2 = Image Grid Block
- case 2:
+ case 2:
$num_cols = variable_get('gallery_grid_num_cols', 2);
$num_rows = variable_get('gallery_grid_num_rows', 2);
$num_images = $num_cols * $num_rows;
@@ -105,7 +104,9 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
$params['albumFrame'] = variable_get('gallery_grid_album_frame', 'none');
$params['itemFrame'] = variable_get('gallery_grid_item_frame', 'none');
$params['linkTarget'] = variable_get('gallery_grid_link_target', '');
-
+ if (variable_get('gallery_grid_item_id', '') != '') {
+ $params['itemId'] = variable_get('gallery_grid_item_id', '');
+ }
$block = array();
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
diff --git a/gallery_roles.inc b/gallery_roles.inc
index 9ebbbb193ba81ccf0de7d09705b74d1e017866b1..4d6522c7c4aabaa86872cbde2230bc1162b0cc87 100644
--- a/gallery_roles.inc
+++ b/gallery_roles.inc
@@ -22,6 +22,7 @@ function gallery_sync_groups_for_user($user) {
if ($ret) {
$msg = t('Error retrieving Gallery group Id for \'Everybody\' group');
gallery_error($msg, $ret);
+ return;
}
// Get the Gallery groups for this user
@@ -31,6 +32,7 @@ function gallery_sync_groups_for_user($user) {
$msg = t('Error getting Gallery User info from Drupal Id');
$msg .= ' ' . t('Drupal User Id: ') . $user->uid;
gallery_error($msg, $ret);
+ return;
}
// Then get the groups for this user currently set in G2
list ($ret, $g2_cur_groups) = GalleryCoreApi::fetchGroupsForUser($g2_user->getId());
@@ -38,6 +40,7 @@ function gallery_sync_groups_for_user($user) {
$msg = t('Error getting Gallery group info for user');
$msg .= ' ' . t('Drupal User Id: ') . $user->uid;
gallery_error($msg, $ret);
+ return;
}
// Now convert the new Drupal role Ids into Gallery Group Ids(for comparison)
foreach ($user->roles as $rid=>$role_name) {
@@ -46,6 +49,7 @@ function gallery_sync_groups_for_user($user) {
$msg = t('Error getting Gallery Group Id from Drupal Role Id');
$msg .= ' ' . t('Drupal Role Id: ') . $rid;
gallery_error($msg, $ret);
+ return;
}
$g2_rid[$rid] = $g2_group->getId();
}
@@ -59,6 +63,7 @@ function gallery_sync_groups_for_user($user) {
$msg = t('Error removing user from Gallery group');
$msg .= ' ' . t('Gallery Group Id: ') . $gid . ' ' . t('Gallery Group Name: ') . $gname;
gallery_error($msg, $ret);
+ return;
}
}
}
@@ -71,6 +76,7 @@ function gallery_sync_groups_for_user($user) {
$msg = t('Error adding user to Gallery group');
$msg .= ' ' . t('Gallery Group Id: ') . $gid;
gallery_error($msg, $ret);
+ return;
}
}
}
@@ -100,12 +106,14 @@ function gallery_sync_groups() {
if ($ret) {
$msg = t('Error retrieving Gallery group Id for \'Everybody\' group');
gallery_error($msg, $ret);
+ return;
}
$ret = GalleryEmbed::addExternalIdMapEntry($rid, $g2_gid, 'GalleryGroup');
if ($ret) {
$msg = t('Error creating new Drupal role <-> Gallery group mapping (for \'anonymous user\' role)');
$msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Gallery Group Id: ') . $g2_gid;
gallery_error($msg, $ret);
+ return;
}
break;
// Add mapping for authenticated users role and get the G2 group Id
@@ -114,12 +122,14 @@ function gallery_sync_groups() {
if ($ret) {
$msg = t('Error retrieving Gallery group Id for \'Registered Users\' group');
gallery_error($msg, $ret);
+ return;
}
$ret = GalleryEmbed::addExternalIdMapEntry($rid, $g2_gid, 'GalleryGroup');
if ($ret) {
- $msg = t('Error creating new Drupal role <-> Gallery group mapping (for \'authenticated user\' role)');
- $msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Gallery Group Id: ') . $g2_gid;
- gallery_error($msg, $ret);
+ $msg = t('Error creating new Drupal role <-> Gallery group mapping (for \'authenticated user\' role)');
+ $msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Gallery Group Id: ') . $g2_gid;
+ gallery_error($msg, $ret);
+ return;
}
break;
default:
@@ -132,6 +142,7 @@ function gallery_sync_groups() {
$msg = t('Error creating new Drupal role <-> Gallery group mapping (by name)');
$msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Gallery Group Id: ') . $g2_gid;
gallery_error($msg, $ret);
+ return;
}
} else {
// If not, create a new group
@@ -140,6 +151,7 @@ function gallery_sync_groups() {
$msg = t('Error creating new Gallery group');
$msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Drupal Role Name: ') . $role_name;
gallery_error($msg, $ret);
+ return;
}
}
break;
@@ -152,6 +164,7 @@ function gallery_sync_groups() {
$msg = t('Error retrieving Gallery Group Id from Drupal Role Id');
$msg .= ' ' . t('Drupal Role Id: ') . $rid;
gallery_error($msg, $ret);
+ return;
}
if (($rid != $authenticated_role) && ($rid != $anonymous_role) && ($role_name != $g2_group->getGroupName())) {
$ret = GalleryEmbed::updateGroup($rid, array('groupname'=>$role_name));
@@ -159,6 +172,7 @@ function gallery_sync_groups() {
$msg = t('Error updating Gallery group');
$msg .= ' ' . t('Drupal Role Id: ') . $rid . ' ' . t('Drupal Role Name: ') . $role_name;
gallery_error($msg, $ret);
+ return;
}
}
}
@@ -167,8 +181,9 @@ function gallery_sync_groups() {
// (just in case other groups have been defined which are not meant to be sync'd with Drupal)
list ($ret, $g2_map) = GalleryEmbed::getExternalIdMap('entityId');
if ($ret) {
- $msg = t('Error retrieving all Drupal<->Gallery Map Ids');
- gallery_error($msg, $ret);
+ $msg = t('Error retrieving all Drupal<->Gallery Map Ids');
+ gallery_error($msg, $ret);
+ return;
}
$g2_mapped_groups = gallery_get_mapped_groups();
foreach ($g2_mapped_groups as $rid=>$g2_gid) {
@@ -180,6 +195,7 @@ function gallery_sync_groups() {
$msg = t('Error deleting Gallery group');
$msg .= ' ' . t('Gallery Group Id: ') . $g2_gid;
gallery_error($msg, $ret);
+ return;
}
}
}
@@ -191,8 +207,9 @@ function gallery_sync_groups() {
function gallery_get_mapped_groups() {
list ($ret, $g2_map) = GalleryEmbed::getExternalIdMap('entityId');
if ($ret) {
- $msg = t('Error retrieving all Drupal<->Gallery Map Ids');
- gallery_error($msg, $ret);
+ $msg = t('Error retrieving all Drupal<->Gallery Map Ids');
+ gallery_error($msg, $ret);
+ return;
}
/*
* getExternalIdMap returns groups and user mappings.
diff --git a/gallery_settings.inc b/gallery_settings.inc
index 2058a77c737ae77f06a5dc581f5c68494abb1a8e..dd5825b242785c9f24f016985baa7b85b7231563 100644
--- a/gallery_settings.inc
+++ b/gallery_settings.inc
@@ -220,6 +220,15 @@ function _gallery_block_settings($typeMap , $paramMap) {
$form['block']['gallery_block_block'][$i-1]['#description'] =
t('Pick the type of images you\'d like to see. You can select the same type more than once.');
+ $form['block']['gallery_item_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Album or Item ID'),
+ '#default_value' => variable_get('gallery_item_id', ''),
+ '#size' => 20,
+ '#maxlength' => 20,
+ '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random images will only be selected from that album and its sub-albums.'),
+ );
+
$form['block']['gallery_block_show'] = array(
'#type' => 'checkboxes',
'#title' => t('Image data'),
@@ -303,6 +312,15 @@ function _gallery_grid_block_settings($typeMap , $paramMap) {
'#description' => 'Pick the type of images you\'d like to see in the grid.',
);
+ $form['grid']['gallery_grid_item_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Album or Item ID'),
+ '#default_value' => variable_get('gallery_grid_item_id', ''),
+ '#size' => 20,
+ '#maxlength' => 20,
+ '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random images will only be selected from that album and its sub-albums.'),
+ );
+
$form['grid']['gallery_grid_block_show'] = array(
'#type' => 'checkboxes',
'#title' => t('Image data'),
@@ -901,7 +919,7 @@ function _gallery_configure_url_rewrite() {
// FIX NEEDED: This will fail if the module is installed in the sites/XXX/modules dir.
// Probably not a big deal for 99% of people.
$drupal_root = dirname(__FILE__);
- $gallery_path = drupal_get_path('module', 'gallery');
+ $gallery_path = drupal_get_path('module', 'gallery');
$htaccess_path = str_replace($gallery_path, '', $drupal_root);
$title = t('Gallery2 URL Rewrite Module Auto-Configuration:');
@@ -983,7 +1001,7 @@ function _gallery_g2image_settings_form_validate(&$form_values) {
if (!file_check_directory($path)) {
$results['gallery_g2image']['title'] = $title;
$results['gallery_g2image']['warning'] = true;
- $results['gallery_g2image']['notice'] = t('g2image does not seem to be installed for %mode mode. Please see the INSTALL.txt for instructions.', array('%mode' => $mode));
+ $results['gallery_g2image']['notice'] = t('g2image does not seem to be installed for %mode mode in the required directory (%dir), or the directory is not writable. Please see the INSTALL.txt for instructions.', array('%mode' => $mode, '%dir' => '<drupal_path>'.$path));
$num_warnings++;
return array($num_errors, $num_warnings, $results['gallery_g2image']);
}
diff --git a/gallery_user.inc b/gallery_user.inc
index 67ef784fad954ef99218f15001fb13e79ae9b5be..74f471aeac8b9682267b3885a5bac6b0b6616265 100644
--- a/gallery_user.inc
+++ b/gallery_user.inc
@@ -5,7 +5,12 @@
* gallery.module : gallery_user.inc
* User Modification Functions (create, update, delete...)
*/
-
+
+define("G2_USER_EXISTS", 1);
+define("G2_USER_EXISTS_BUT_NEEDS_MAPPING", 2);
+define("G2_USER_DOES_NOT_EXIST_BUT_IS_MAPPED", 3);
+define("G2_USER_DOES_NOT_EXIST", 4);
+
$path = drupal_get_path('module', 'gallery');
require_once($path . '/gallery_roles.inc');
@@ -51,7 +56,7 @@ function gallery_update_user(&$edit, $user) {
$user->language = ($edit['language']) ? $edit['language'] : gallery_get_language($user);
$user->pass = ($edit['pass']) ? md5($edit['pass']) : $user->pass;
$user->status = ($edit['status']) ? $edit['status'] : $user->status;
- $user->mail = ($edit['email']) ? $edit['mail'] : $user->mail;
+ $user->mail = ($edit['mail']) ? $edit['mail'] : $user->mail;
// Note: $user->roles is organized as [$rid]=>[$role_name], but edit['roles'] is [$rid]=>[$position]
$user->roles = ($edit['roles']) ? $edit['roles'] : $user->roles;
// Use full name from profile if it exists
@@ -104,40 +109,61 @@ function gallery_modify_user($user, $action = 'create') {
$pass = ($user->status == 1) ? $user->pass : user_password(20);
switch ($action) {
- case 'create' :
- $ret = GalleryEmbed::createUser($user->uid,
- array('username' => $user->name,
- 'email' => $user->mail,
- 'fullname' => $fullname,
- 'language' => gallery_get_language($user),
- 'hashedpassword' => $pass,
- 'hashmethod' => 'md5'));
+ case 'create' :
+ case 'update' :
+ // See if user already exists in Gallery2
+ list ($g2_user_state, $g2_user, $ret) = _gallery_check_user_status($user);
if ($ret) {
+ // An unmasked error, so exit now
return array(false, $ret);
- }
- // Add group info
- gallery_sync_groups_for_user($user);
- break;
- case 'update' :
- $ret = GalleryEmbed::updateUser($user->uid,
- array('username' => $user->name,
- 'fullname' => $fullname,
- 'email' => $user->mail,
- 'language' => gallery_get_language($user),
- 'hashedpassword' => $pass,
- 'hashmethod' => 'md5'));
+ }
+
+ switch ($g2_user_state) {
+ case G2_USER_EXISTS_BUT_NEEDS_MAPPING:
+ // No mapping found, so add one
+ $ret = GalleryEmbed::addExternalIdMapEntry($user->uid, $g2_user->getId(), 'GalleryUser');
+ if ($ret) {
+ // mapping the user failed for some reason, so exit
+ return array(false, $ret);
+ }
+ // Continue to update
+ case G2_USER_EXISTS:
+ // May need to update the user info with that from Drupal
+ $ret = GalleryEmbed::updateUser($user->uid,
+ array('username' => $user->name,
+ 'fullname' => $fullname,
+ 'email' => $user->mail,
+ 'language' => gallery_get_language($user),
+ 'hashedpassword' => $pass,
+ 'hashmethod' => 'md5'));
+ if ($ret) {
+ return array(false, $ret);
+ }
+ break;
+ case G2_USER_DOES_NOT_EXIST_BUT_IS_MAPPED:
+ $ret = GalleryCoreApi::removeMapEntry('ExternalIdMap', array('externalId' => $user->uid, 'entityType' => 'GalleryUser'));
+ if ($ret) {
+ // There was an error on removeMapEntry
+ return array(false, $ret2);
+ }
+ // Continue to creation
+ case G2_USER_DOES_NOT_EXIST:
+ // Create the new user
+ $ret = GalleryEmbed::createUser($user->uid,
+ array('username' => $user->name,
+ 'email' => $user->mail,
+ 'fullname' => $fullname,
+ 'language' => gallery_get_language($user),
+ 'hashedpassword' => $pass,
+ 'hashmethod' => 'md5'));
+ if ($ret) {
+ // There was an error on user creation
+ return array(false, $ret);
+ }
+ break;
+ }
if ($ret) {
- // try to create user then.
- $ret = GalleryEmbed::createUser($user->uid,
- array('username' => $user->name,
- 'fullname' => $fullname,
- 'email' => $user->mail,
- 'language' => gallery_get_language($user),
- 'hashedpassword' => $pass,
- 'hashmethod' => 'md5'));
- if ($ret) {
- return array(false, $ret);
- }
+ return array(false, $ret);
}
// Add group info
gallery_sync_groups_for_user($user);
@@ -146,6 +172,61 @@ function gallery_modify_user($user, $action = 'create') {
return array(true, null);
}
+
+function _gallery_create_user_if_necessary($user) {
+
+}
+
+function _gallery_check_user_status($user) {
+ // See if user already exists in Gallery2
+ list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($user->name);
+ if (!$ret) {
+ // The user is in Gallery2, so map the user if needed
+ $ret2 = GalleryEmbed::isExternalIdMapped($user->uid, 'GalleryUser');
+ if ($ret2) {
+ if ($ret2->getErrorCode() & ERROR_MISSING_OBJECT) {
+ return array(G2_USER_EXISTS_BUT_NEEDS_MAPPING, $g2_user, null);
+ } else {
+ // Some other error, so exit
+ return array(null, $g2_user, $ret2);
+ }
+ } else {
+ return array(G2_USER_EXISTS, $g2_user, null);
+ }
+ } elseif ($ret->getErrorCode() & ERROR_MISSING_OBJECT) {
+ // The user does not yet exist in G2
+ // First, check if the extID was mapped (it should not be)
+ $ret2 = GalleryEmbed::isExternalIdMapped($user->uid, 'GalleryUser');
+ if ($ret2) {
+ if ($ret2->getErrorCode() & ERROR_MISSING_OBJECT) {
+ // This should be missing
+ return array(G2_USER_DOES_NOT_EXIST, $g2_user, null);
+ } else {
+ // Some other error, so exit
+ return array(null, $g2_user, $ret2);
+ }
+ } else {
+ // No error, so user is mapped
+ return array(G2_USER_DOES_NOT_EXIST_BUT_IS_MAPPED, $g2_user, null);
+ }
+
+ /* if (!$ret2) {
+ return array(G2_USER_DOES_NOT_EXIST, $g2_user, null);
+ } else {
+ if (!($ret2->getErrorCode() & ERROR_MISSING_OBJECT)) {
+ // There is a mapping for this user even though the user does not exist,
+ return array(G2_USER_DOES_NOT_EXIST_BUT_IS_MAPPED, $g2_user, null);
+ } else {
+ // Some other error, so exit
+ return array(null, $g2_user, $ret2);
+ }
+ }*/
+ } else {
+ // Some other error so exit
+ return array(null, $g2_user, $ret);
+ }
+}
+
/* --------------------------------------------------------------------------
* User View Functions (view all users, view specific users,...)
* --------------------------------------------------------------------------