Skip to content
gallery.module 13.1 KiB
Newer Older
require_once(drupal_get_path('module', 'gallery') .'/gallery_base.inc');

// Default variable values
define(GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT, 'maxsize');
define(GALLERY_IMAGEBLOCK_SIZE_DEFAULT, 150);
define(GALLERY_GRID_SIZE_METHOD_DEFAULT, 'maxsize');
define(GALLERY_GRID_SIZE_DEFAULT, 90);
define(GALLERY_SEARCH_SIZE_METHOD_DEFAULT, 'maxsize');
define(GALLERY_SEARCH_SIZE_DEFAULT, 150);
define(GALLERY_FILTER_MAXSIZE_DEFAULT, 150);
define(GALLERY_FILTER_EXACTSIZE_DEFAULT, '');

/**
 * Implementation of hook_perm().
 */
function gallery_perm() {
  return array('administer gallery settings', 'access gallery', 'access standalone g2image');
}

/**
 * Implementation of hook_menu
 */
function gallery_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    if (variable_get('gallery_valid', 0)) {
      $items[] = array(
        'path' => 'gallery',
        'title' => t('Gallery'),
        'description' => t('Visit your embedded Gallery2.'),
        'callback' => variable_get('gallery_page_callback', 'gallery_page'),
        'access' => user_access('access gallery'),
      );
    }
    // settings / general administration
kiz_0987's avatar
kiz_0987 committed
    $items[] = array(
      'path' => 'admin/settings/gallery',
      'title' => t('Gallery settings'),
      'callback' => 'gallery_settings',
      'callback arguments' => '_gallery_settings_general',
      'description' => t('Configure settings for embedding Gallery2 into Drupal.'),
      'access' => user_access('administer gallery settings'),
    );
    $items[] = array(
      'path' => 'admin/settings/gallery/install',
      'title' => t('Install'),
      'callback' => 'gallery_settings',
      'callback arguments' => '_gallery_settings_install',
      'access' => user_access('administer gallery settings'),
      'type' => variable_get('gallery_valid', 0) ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK,
    if (variable_get('gallery_valid', 0)) {
      $items[] = array(
        'path' => 'admin/settings/gallery/general',
        'title' => t('General'),
        'access' => user_access('administer gallery settings'),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => 1
      );
      $items[] = array(
        'path' => 'admin/settings/gallery/filter',
        'title' => t('Filter'),
        'callback' => 'gallery_settings',
        'callback arguments' => '_gallery_settings_filter',
        'access' => user_access('administer gallery settings'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 2
      );
      $items[] = array(
        'path' => 'admin/settings/gallery/g2image',
        'title' => t('G2Image'),
        'callback' => 'gallery_settings',
        'callback arguments' => '_gallery_settings_g2image',
        'access' => user_access('administer gallery settings'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 3
      );
      $items[] = array(
        'path' => 'admin/settings/gallery/search',
        'title' => t('Search'),
        'callback' => 'gallery_settings',
        'callback arguments' => '_gallery_settings_search',
        'access' => user_access('administer gallery settings'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 4
      $items[] = array(
        'path' => 'admin/settings/gallery/report',
        'callback' => 'gallery_report',
        'access' => user_access('administer site configuration'),
        'type' => MENU_CALLBACK
      );
      // user administration
      $items[] = array(
        'path' => 'admin/user/gallery', 
        'title' => t('Gallery users'),
        'description' => t('Gallery2 user integration and synchronization'),
        'callback' => 'gallery_users',
        'access' => user_access('administer users'),
      );
      $items[] = array(
        'path' => 'admin/user/gallery/users',
        'title' => t('User Status'),
        'access' => user_access('administer users'),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => 0
      );
      $items[] = array(
        'path' => 'admin/user/gallery/advanced',
        'title' => t('Advanced Sync'),
        'callback' => 'gallery_user_admin',
        'callback arguments' => '_gallery_user_advanced',
        'access' => user_access('administer users'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 1
      );
      $items[] = array(
        'path' => 'admin/user/gallery/settings',
        'title' => t('User Settings'),
        'callback' => 'gallery_user_admin',
        'callback arguments' => '_gallery_user_settings',
        'access' => user_access('administer users') && user_access('administer gallery settings'),
        'type' => MENU_LOCAL_TASK,
        'weight' => 2
      );
      $items[] = array(
        'path' => 'admin/user/gallery/advanced_progress',
        'callback' => 'gallery_user_admin_advanced_progress',
        'access' => user_access('administer users'),
        'type' => MENU_CALLBACK
      );
      $items[] = array(
        'path' => 'admin/user/gallery/users/sync',
        'callback' => 'gallery_users',
        'access' => user_access('administer users'),
        'type' => MENU_CALLBACK
      );
    }
    drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery.css');
    drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery_filter.css');
} 

/**
 * Implementation of hook_help
 */
function gallery_help($section) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
  return _gallery_help($section);
 * Implementation of gallery_settings
function gallery_settings($form = '_gallery_settings_general') {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
  return drupal_get_form(variable_get('gallery_valid', 0) ? $form : '_gallery_settings_install');
/**
 * Implementation of gallery_report
 */
function gallery_report($download = NULL) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_report.inc');
  return _gallery_report(isset($download));
}

/**
 * Implementation of hook_user
 */
function gallery_user($op, &$edit, &$user, $category = NULL) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
  case 'login':
    break;
    return gallery_user_view($user);
    return gallery_user_insert($edit, drupal_clone($user));
    return gallery_user_update($edit, drupal_clone($user));
    return gallery_user_delete($user);
function gallery_users($args = NULL) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
  return _gallery_user_users($args);
}

function gallery_user_admin($form) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
  return drupal_get_form($form);
}

function gallery_user_admin_advanced_progress() {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
  return _gallery_user_advanced_progress();
 * Implementation of hook_search
function gallery_search($op = 'search', $keys = NULL) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
  return _gallery_search($op, $keys); 
}
/**
 * Implementation of hook_search_item to override how to display the item
 */
function gallery_search_page($results) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
  return _gallery_search_page($results); 
function gallery_form_alter($form_id, &$form) {
  if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) {
    require_once(drupal_get_path('module', 'gallery') .'/gallery_groups.inc');
    $form['#submit']['_gallery_groups_submit'] = array();
  }
  if ($form_id == 'search_form' && arg(1) == 'gallery' && variable_get('gallery_search_advanced', 1) && user_access('access gallery')) {
    require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
    _gallery_search_form($form);
/**
 * Implementation of hook_filter
function gallery_filter($op, $delta = 0, $format = -1, $text = '') {
  require_once(drupal_get_path('module', 'gallery') .'/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', TRUE);
    default:
      return $text;
  }
/**
 * Implementation of hook_filter_tips
function gallery_filter_tips($delta = 0, $format = -1, $long = FALSE) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
  if ($long) {
    return gallery_filter_long_tip_translated();
  }
    return gallery_filter_short_tip_translated();
  }
/**
 * Implementation of hook_elements() - from img_assist
 */
function gallery_elements() {
  $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array()));
  return $type;
}

/*
 * Add image link underneath textareas
 */
function gallery_g2image_textarea($element) {
    require_once(drupal_get_path('module', 'gallery') .'/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;
}

/**
 * Implementation of hook_block
 *
 */
function gallery_block($op = 'list', $delta = 0, $edit = array()) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
  if (variable_get('gallery_valid', 0)) {
    return _gallery_block($op, $delta, $edit);
  }
}

/**
 * Main gallery display page
 */
function gallery_page() {
  if (!_gallery_init(FALSE)) {
  if (variable_get('gallery_move_sidebar_to_block', 1)) {
    GalleryCapabilities::set('showSidebarBlocks', FALSE);
  $result = gallery_handle_request();
  if ($result && !$result['isDone']) {
    gallery_set_head($result['headHtml'], TRUE);
    // add pathbar. See http://gallery.menalto.com/node/33447
    if (isset($result['themeData'])) {
      $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 (italic, bold)
kiz_0987's avatar
kiz_0987 committed
          $parent_title = str_replace(
            array('[i]', '[/i]', '[b]', '[/b]'),
            array('<i>', '</i>', '<strong>', '</strong>'),
            $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 = gallery_generate_url(array('view' => 'core.ShowItem', 'itemId' => $parent['id']), FALSE);
          $breadcrumb[] = l($parent_title, $link);
        }
      drupal_set_breadcrumb($breadcrumb);
    }
    // Hack to get the admin sidebar
    if (variable_get('gallery_move_admin_sidebar_to_block', 0)) {
      if (preg_match("/^(.*<td id=\"gsSidebarCol\">)(.*?)(<\/td>.*?)$/s", $result['bodyHtml'], $match)) {
        // new body
        $result['bodyHtml'] = $match[1] . $match[3];
        // insert admin sidebar in $result['sidebarBlocksHtml']
        if (empty($result['sidebarBlocksHtml'][1])) {
          $result['sidebarBlocksHtml'][1] = $match[2];
        } 
        else {
          $result['sidebarBlocksHtml'][] = $match[2];
    // store the sidebar info in a global variable for use in the gallery navigation block
    $GLOBALS['_gallery_sidebar_'] = $result['sidebarBlocksHtml'];
    return $result['bodyHtml'];
kiz_0987's avatar
kiz_0987 committed
/**
 * Define additional links to add to the site map.
 *
 * This hook allows modules to add additional links to the site map. Links
 * may be associated with nodes, terms, or users, as shown in the example.
 *
 * @param $type
 *   If given, the type of link to associate additional links with.
 * @param $excludes
 *   If given, an array of criteria for excluding links.
 * @return
 *   An array of links or an empty array.
 */
function gallery_gsitemap($type = NULL, $excludes = array()) {
  if (($type != 'xml') || !variable_get('gallery_enable_sitemap', 1)) {
kiz_0987's avatar
kiz_0987 committed
    return;
  }
 
  // Need to do a full init
  if (!_gallery_init(TRUE)) {
    return;
  }

  $view_name = 'sitemap.Sitemap';
  list($ret, $view) = GalleryView::loadView($view_name);
kiz_0987's avatar
kiz_0987 committed
  if ($ret) {
    gallery_error(t('Error loading the Gallery2 Google Sitemap. Make sure the \'Google Sitemap\' plugin is enabled in Gallery2.'), $ret);
    return;
  }
  list($ret, $root_id) = GalleryCoreApi::getDefaultAlbumId();
  if ($ret) {
kiz_0987's avatar
kiz_0987 committed
    gallery_error(t('Error loading the Gallery2 Default Album Id.'), $ret);
    return;
kiz_0987's avatar
kiz_0987 committed
  
  // Get the sitemap from Gallery2
  ob_start();
  $ret = $view->renderSitemap($root_id);
  $g2_sitemap = ob_get_contents();
  ob_end_clean();

  return $g2_sitemap;
}