<?php
-// $Id$
+// For Drupal 4.7 with Gallery 2.1
-/**
- * Implementation of hook_help
- */
-function gallery_help($section) {
- switch($section) {
- case 'admin/modules#description':
- return t('Integration with Gallery2 (%gallery_url)', array('%gallery_url' => 'http://gallery.menalto.com/'));
- }
-}
+$path = drupal_get_path('module', 'gallery');
+require_once($path . '/gallery_base.inc');
/**
* Implementation of hook_menu
*/
function gallery_menu($may_cache) {
+ global $user;
$items = array();
-
+ $view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
if ($may_cache) {
- $items[] = array('path' => 'gallery',
- 'title' => t('gallery'),
- 'callback' => 'gallery_page',
- 'access' => user_access('access content'),
- 'type' => MENU_NORMAL_ITEM);
+ $items[] = array(
+ 'path' => 'gallery',
+ 'title' => t('gallery'),
+ 'callback' => 'gallery_page',
+ 'access' => user_access('access gallery'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ $items[] = array(
+ 'path' => 'admin/user/gallery', 'title' => t('gallery'),
+ 'callback' => 'gallery_users',
+ 'access' => user_access('administer users'),
+ 'type' => MENU_LOCAL_TASK,
+ );
+ } else {
+ // Add head info here so that it is included once only per page
+ // May need modification once the merits/issues of theme_add_style are fully known
+ // See http://drupal.org/node/60096
+ theme_add_style(drupal_get_path('module', 'gallery') .'/drupal_g2.css');
}
-
return $items;
+}
+
+/**
+ * Implementation of hook_help
+ */
+function gallery_help($section) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_help.inc');
+ return _gallery_help($section);
}
/**
* 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;
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_settings.inc');
+ return _gallery_settings();
}
/**
* Implementation of hook_user
*/
function gallery_user($op, &$edit, &$user, $category = NULL) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_user.inc');
+
switch ($op) {
case 'login':
/* _gallery_init() will try to create the user, if necessary */
return;
}
break;
-
- case 'insert':
- list ($success, $ret) = _gallery_init();
- if (!$success) {
- gallery_error(t('Unable to initialize embedded Gallery'), $ret);
- return;
+ case 'logout':
+ if (variable_get('gallery_valid', 0)) {
+ $embedPath = variable_get('gallery_dir', './gallery2/') . 'embed.php';
+ require_once($embedPath);
+ $ret = GalleryEmbed::logout();
+ break;
}
+ case 'view':
+ return gallery_view_user($user);
+ case 'insert':
+ return gallery_insert_user($edit, drupal_clone($user));
+ case 'update':
+ return gallery_update_user($edit, drupal_clone($user));
+ case 'delete':
+ return gallery_delete_user($user);
+ }
+}
- $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;
+/**
+ * Gallery Users Page - view a set of users
+ */
+function gallery_users() {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_user.inc');
+ return _gallery_users();
+}
- case 'update':
- list ($success, $ret) = _gallery_init();
- if (!$success) {
- gallery_error(t('Unable to initialize embedded Gallery'), $ret);
- return;
- }
+/**
+ * implementation of hook_search
+ */
+function gallery_search($op = 'search', $keys = null) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_search.inc');
+ return _gallery_search($op, $keys);
+}
- // 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;
+/**
+ * Implementation of hook_search_item to override how to display the item
+ */
+function gallery_search_page($results) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_search.inc');
+ return _gallery_search_page($results);
+}
- case 'delete':
- list ($success, $ret) = _gallery_init();
- if (!$success) {
- gallery_error(t('Unable to initialize embedded Gallery'), $ret);
- return;
- }
+/**
+ * Implementation of hook_filter
+ */
+function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_filter.inc');
+ switch ($op) {
+ case 'list' :
+ return array (0 => t('Gallery2 filter'));
+ case 'description' :
+ return t('Allow users to easily reference Gallery2 items from nodes.');
+ case 'process' :
+ return gallery_filter_process($text);
+ case 'no cache':
+ return !variable_get('gallery_filter_can_cache', 1);
+ default :
+ return $text;
+ }
+}
- $ret = GalleryEmbed::deleteUser($user->uid);
- if ($ret->isError()) {
- gallery_error(t('Error deleting Gallery user'), $ret);
- }
- GalleryEmbed::done();
- break;
- }
+/**
+ * Implementation of hook_filter_tips
+ */
+function gallery_filter_tips($delta = 0, $format = -1, $long = false) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_help.inc');
+ if ($long) {
+ return gallery_filter_long_tip_translated();
+ } else {
+ return gallery_filter_short_tip_translated();
+ }
}
/**
- * Implementation of hook_block
- *
- * - gallery navigation block (recommended)
- * - gallery imageblock (random, most viewed, etc)
+ * Implementation of hook_perm().
*/
-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'));
+function gallery_perm() {
+ return array('access gallery', 'access standalone g2image');
+}
- switch ($op) {
- case 'list':
- $blocks[0]['info'] = t('Gallery Block');
- return $blocks;
-
- case 'configure':
- $form['gallery_block_block_'. $delta] = array(
- '#type' => 'select',
- '#title' => t('Image type'),
- '#default_value' => variable_get('gallery_block_block_' . $delta, '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':
- 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['blocks'] = variable_get('gallery_block_block_' . $delta, 'randomImage');
- $params['show'] = implode('|', array_keys(variable_get('gallery_block_show_' . $delta, array())));
-
- // TODO: parameterize this
- $params['maxSize'] = 160;
+/**
+ * Implementation of hook_elements() - from img_assist
+ */
+function gallery_elements() {
+ $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
+ return $type;
+}
- $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['blocks']];
- $block['content'] = '<center>' . $content . '</center>';
- }
- }
-
- $ret = GalleryEmbed::done();
- if ($ret->isError()) {
- gallery_error(t('Unable to complete Gallery request'), $ret);
- return;
- }
- return $block;
+/*
+ * Add image link underneath textareas
+ */
+function gallery_g2image_textarea($element) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_g2image.inc');
+ if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery') &&
+ (variable_get('gallery_g2image_mode', 'disabled') == 'standalone') &&
+ (user_access('access standalone g2image'))) {
+ gallery_g2image_add_js();
+ $output = theme('gallery_g2image_textarea_link', $element, $link);
+ $element['#suffix'] .= $output;
}
+ return $element;
}
/**
- * implementation of hook_search
+ * Implementation of hook_block
+ *
*/
-function gallery_search($op = 'search', $keys = null) {
- switch ($op) {
- case 'name':
- return t('gallery');
- case 'search':
- $find = array();
-
- list ($success, $ret) = _gallery_init(true);
- if (!$success) {
- gallery_error(t('Unable to initialize embedded Gallery'), $ret);
- return;
- }
-
- list ($ret, $results) = GalleryEmbed::searchScan($keys, 20);
- if (!$ret->isError()) {
- $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
- foreach ($results as $name => $module) {
- if (count($module['results']) > 0) {
- foreach ($module['results'] as $result) {
- $excerpt = array();
- $words = search_index_split($keys);
- foreach ($result['fields'] as $field) {
- foreach ($words as $word) {
- if (preg_match("/$word/i", $field['value'])) {
- $excerpt[] = $field['key'] .': '.search_excerpt($words, $field['value']);
- }
- }
- }
- $link = str_replace('&', '&', $urlGenerator->generateUrl(array('itemId' => $result['itemId'])));
- $find[] = array('title' => $result['fields'][0]['value'],
- 'link' => $link,
- 'type' => $module['name'],
- 'snippet' => implode('<br />', $excerpt));
- }
- }
- }
- }
- return $find;
- }
+function gallery_block($op = 'list', $delta = 0, $edit = array()) {
+ $path = drupal_get_path('module', 'gallery');
+ require_once($path . '/gallery_block.inc');
+ return _gallery_block($op, $delta, $edit);
}
/**
* 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);
- print theme('page', 'You need to <a href="/admin/settings/gallery">configure your embedded Gallery</a>');
- return;
- }
-
- /* Pass any excess path info to G2 */
- $path = substr($_GET['q'], 7 /* length of 'gallery/' */);
- if (!empty($path)) {
- $_GET[GALLERY_FORM_VARIABLE_PREFIX . 'path'] = $path;
+ $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link">
+ configure your embedded Gallery</a>.',
+ array('%link' => url('admin/settings/gallery')));
+ return $err_msg;
}
-
+ // Turn off sidebar
+ GalleryCapabilities::set('showSidebarBlocks', false);
$result = GalleryEmbed::handleRequest();
if (!$result['isDone']) {
list($title, $css, $javascript) = GalleryEmbed::parseHead($result['headHtml']);
if (!empty($javascript)) {
- drupal_set_html_head(implode("\n",$javascript));
+ gallery_set_html_head(implode("\n", $javascript));
}
- drupal_set_html_head(implode("\n",$css));
+ gallery_set_html_head(implode("\n", $css));
drupal_set_title($title);
- print theme('page', $result['bodyHtml']);
- }
-}
-
-/**
- * fetch a galleryEmbed object
- */
-function _gallery_init($full = false) {
- global $user;
-
- $galleryDir = variable_get('gallery_dir', 'gallery2/');
-
- $embedPath = $galleryDir . '/embed.php';
- if (!is_readable($embedPath)) {
- return array(false, null);
- }
-
- 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,
- 'loginRedirect' => url('user/login'),
- 'activeUserId' => $user->uid,
- 'activeLanguage' => $user->language,
- 'fullInit' => $full);
- $ret = GalleryEmbed::init($params);
- 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 (!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->isError()) {
- return array(false, $ret);
- }
-
- list ($ret, $g2_users) = GalleryCoreApi::fetchUsersForGroup($admin_group_id);
- if ($ret->isError()) {
- 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()) {
- return array(false, $ret);
- }
+ // Add pathbar. See http://gallery.menalto.com/node/33447
+ if (isset($result['themeData'])) {
+ $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
+ $breadcrumb = array(l(t('Home'), ''));
+ // Some themes (eg hybrid) do not set $result['themeData']['parents']
+ if ($result['themeData']['parents']) {
+ foreach ($result['themeData']['parents'] as $parent) {
+ $parent_title = $parent['title'];
+ // Simple strip of bbcode (italics)
+ $parent_title = str_replace("[i]", "<i>", $parent_title);
+ $parent_title = str_replace("[/i]", "</i>", $parent_title);
+ // Still does not generate a clean url for /gallery (uses index.php?q=gallery)
+ $link = $urlGenerator->generateUrl(
+ array('view' => 'core.ShowItem',
+ 'itemId' => $parent['id']),
+ array('forceFullUrl' => 1,
+ 'htmlEntities' => false));
+ $breadcrumb[] = l($parent_title, $link);
+ }
}
+ drupal_set_breadcrumb($breadcrumb);
}
+ // Store the sidebar info in a global variable for use in the gallery navigation block
+ $gallery_sidebar = $result['sidebarBlocksHtml'];
- if (isset($g2_user)) {
- $ret = GalleryEmbed::addExternalIdMapEntry($user->uid, $g2_user->getId(), 'GalleryUser');
- if ($ret->isError()) {
- return array(false, $ret);
- }
- } else {
- // No matching G2 user found -- create one.
- $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()) {
- return array(false, $ret);
- }
- }
+ return $result['bodyHtml'];
}
-
- return array(true, GalleryStatus::success());
}
-function gallery_error($message, $ret) {
- $error_mode = variable_get('gallery_error_mode', array());
- if (in_array(2, $error_mode)) {
- drupal_set_message($message);
- }
-
- if (isset($ret)) {
- $full_message = $message . '<br/>' . $ret->getAsHtml();
- } else {
- $full_message = $message;
- }
-
- if (in_array(1, $error_mode)) {
- watchdog('gallery', $full_message, WATCHDOG_ERROR);
- }
-}
?>