'http://gallery.menalto.com/')); } } /** * Implementation of hook_menu */ function gallery_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'gallery', 'callback' => 'gallery_page', 'access' => user_access('access content'), 'type' => MENU_SUGGESTED_ITEM); } return $items; } /** * Implementation of hook_settings */ function gallery_settings() { $output = ''; $output.= form_textfield(t('Location of Gallery2'), 'gallery_dir', variable_get('gallery_dir', 'gallery2/'), 64, 64, t('Path to your gallery2 directory, relative to the root directory of your drupal installation. Please include a trailing slash ("/").')); $output .= form_checkboxes(t('Error logging'), 'gallery_error_mode', variable_get('gallery_error_mode', array(1)), array(1 => t('Watchdog'), 2 => t('Output to the browser')), t('Choose where errors are displayed')); return $output; } /** * 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->isError()) { 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->isError()) { // 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->isError()) { 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->isError()) { 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('Recent image'), 'viewedImage' => t('Viewed image'), 'randomAlbum' => t('Random album'), 'recentAlbum' => t('Recent album'), 'viewedAlbum' => t('Viewed album'), 'dailyImage' => t('Daily image'), 'weeklyImage' => t('Weekly image'), 'monthlyImage' => t('Monthly image'), 'dailyAlbum' => t('Daily album'), 'weeklyAlbum' => t('Weekly album'), 'monthlyAlbum' => t('Monthly album')); switch ($op) { case 'list': $blocks[0]['info'] = t('Gallery Block'); return $blocks; case 'configure': $output = form_select(t('Image type'), 'gallery_block_block_' . $delta, variable_get('gallery_block_block_' . $delta, 'randomImage'), $typeMap, t('Pick the type of image you\'d like to see')); $output .= form_checkboxes( t('Image data'), 'gallery_block_show_' . $delta, variable_get('gallery_block_show_' . $delta, array('title', 'heading')), array('title' => 'Title', 'date' => 'Date', 'views' => 'View Count', 'owner' => 'Item owner', 'heading' => 'Heading', 'fullSize' => 'Full Size'), t('Choose the item metadata you\'d like to display')); return $output; case 'save': variable_set('gallery_block_block_' . $delta, $edit['gallery_block_block_' . $delta]); 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['block'] = variable_get('gallery_block_block_' . $delta, 'randomImage'); $params['show'] = implode('|', variable_get('gallery_block_show_' . $delta, array())); // TODO: parameterize this $params['maxSize'] = 160; $block = array(); list($ret, $content) = GalleryEmbed::getImageBlock($params); if ($ret->isError()) { gallery_error(t('Unable to get Gallery image block'), $ret); return; } else { if ($content) { $block['subject'] = $typeMap[$params['block']]; $block['content'] = '