) // modified gallery_1.module from // http://drupal.org/project/comments/add/45159 // to comply with Gallery 2.1 // see http://fisheye.gallery2.org/viewrep/gallery/gallery2/upgrade/index.php // revision 1.23.2.1 notes /** * Implementation of hook_help */ function gallery_help($section) { switch($section) { case 'admin/modules#description': return t('Integration with Gallery2.1 (%gallery_url)', array('%gallery_url' => 'http://gallery.menalto.com/')); } } /** * Implementation of hook_menu */ function gallery_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'gallery', 'title' => t('gallery'), 'callback' => 'gallery_page', 'access' => user_access('access gallery'), 'type' => MENU_NORMAL_ITEM); } return $items; } /** * Implementation of hook_perm(). */ function gallery_perm() { return array('access gallery'); } /** * Implementation of hook_settings */ function gallery_settings() { $form['gallery_dir'] = 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 ("/").'), ); $form['gallery_error_mode'] = array( '#type' => 'checkboxes', '#title' => t('Error logging'), '#default_value' => variable_get('gallery_error_mode', array(1)), '#options' => array(1 => t('Watchdog'), 2 => t('Output to the browser')), '#description' => t('Choose where errors are displayed'), ); return $form; } /** * Implementation of hook_user */ function gallery_user($op, &$edit, &$user, $category = NULL) { switch ($op) { case 'login': /* _gallery_init() will try to create the user, if necessary */ list ($success, $ret) = _gallery_init(); if (!$success) { gallery_error(t('Unable to log in to Gallery'), $ret); return; } break; case 'insert': list ($success, $ret) = _gallery_init(); if (!$success) { gallery_error(t('Unable to initialize embedded Gallery'), $ret); return; } $ret = GalleryEmbed::createUser($user->uid, array('username' => $user->name, 'email' => $user->mail, 'fullname' => $user->name, 'language' => $user->language, 'hashedpassword' => $user->pass, 'hashmethod' => 'md5' )); if ($ret) { gallery_error(t('Error creating Gallery user'), $ret); return; } GalleryEmbed::done(); break; case 'update': list ($success, $ret) = _gallery_init(); if (!$success) { gallery_error(t('Unable to initialize embedded Gallery'), $ret); return; } // on update we can't be sure how much info $edit will contain. $name = ($edit['name']) ? $edit['name'] : $user->name; $language = ($edit['language']) ? $edit['language'] : $user->language; $pass = ($edit['pass']) ? md5($edit['pass']) : $user->pass; $email = ($edit['email']) ? $edit['mail'] : $user->mail; $ret = GalleryEmbed::updateUser($user->uid, array('username' => $name, 'fullname' => $name, 'email' => $mail, 'language' => $language, 'hashedpassword' => $pass, 'hashmethod' => 'md5')); if ($ret) { // try to create user then. $ret = GalleryEmbed::createUser($user->uid, array('username' => $name, 'fullname' => $name, 'email' => $mail, 'language' => $language, 'hashedpassword' => $pass, 'hashmethod' => 'md5' )); if ($ret) { gallery_error(t('Error updating Gallery user'), $ret); return; } } GalleryEmbed::done(); break; case 'delete': list ($success, $ret) = _gallery_init(); if (!$success) { gallery_error(t('Unable to initialize embedded Gallery'), $ret); return; } $ret = GalleryEmbed::deleteUser($user->uid); if ($ret) { gallery_error(t('Error deleting Gallery user'), $ret); } GalleryEmbed::done(); break; } } /** * Implementation of hook_block * * - gallery navigation block (recommended) * - gallery imageblock (random, most viewed, etc) */ function gallery_block($op = 'list', $delta = 0, $edit = array()) { $typeMap = array('randomImage' => t('Random Image'), 'recentImage' => t('Newest Image'), 'viewedImage' => t('Most Viewed Image'), 'randomAlbum' => t('Random Album'), 'recentAlbum' => t('Newest Album'), 'viewedAlbum' => t('Most Viewed Album'), 'dailyImage' => t('Picture of the Day'), 'weeklyImage' => t('Picture of the Week'), 'monthlyImage' => t('Picture of the Month'), 'dailyAlbum' => t('Album of the Day'), 'weeklyAlbum' => t('Album of the Week'), 'monthlyAlbum' => t('Album of the Month')); switch ($op) { case 'list': $blocks[0]['info'] = t('Gallery Block'); return $blocks; case 'configure': $form['gallery_block_block_'. $delta] = array( '#type' => 'checkboxes', '#title' => t('Image type'), '#default_value' => variable_get('gallery_block_block_' . $delta, array('randomImage')), '#options' => $typeMap, '#description' => t("Pick the type of image you'd like to see"), ); $form['gallery_block_show_'. $delta] = array( '#type' => 'checkboxes', '#title' => t('Image data'), '#default_value' => variable_get('gallery_block_show_' . $delta, array('title', 'heading')), '#options' => array('title' => 'Title', 'date' => 'Date', 'views' => 'View Count', 'owner' => 'Item owner', 'heading' => 'Heading', 'fullSize' => 'Full Size'), '#description' => t("Choose the item metadata you'd like to display") ); return $form; case 'save': // if no image types selected, assume randomImage if (count($edit['gallery_block_block_' . $delta])) { variable_set('gallery_block_block_' . $delta, $edit['gallery_block_block_' . $delta]); } else { variable_set('gallery_block_block_' . $delta, array('randomImage')); } variable_set('gallery_block_show_' . $delta, $edit['gallery_block_show_' . $delta]); break; case 'view': list ($success, $ret) = _gallery_init(true); if (!$success) { gallery_error(t('Unable to initialize embedded Gallery'), $ret); return; } $params['blocks'] = implode('|', variable_get('gallery_block_block_' . $delta, array('randomImage'))); $params['show'] = implode('|', variable_get('gallery_block_show_' . $delta, array())); // TODO: parameterize this $params['maxSize'] = 150; $block = array(); list($ret, $content, $head) = GalleryEmbed::getImageBlock($params); if ($ret) { gallery_error(t('Unable to get Gallery image block'), $ret); return; } else { if ($content) { if (count(variable_get('gallery_block_block_' . $delta, 'randomImage')) > 1) { $block['subject'] = t('Gallery'); } else { $block['subject'] = $typeMap[$params['blocks']]; } $block['content'] = '