Skip to content
gallery_settings.inc 67.8 KiB
Newer Older
<?php
// $Id$

/**
 * gallery.module : gallery_settings.inc
 * Settings functions
 */
kiz_0987's avatar
kiz_0987 committed

define(GALLERY_PLUGIN_ENABLED,         1);
define(GALLERY_PLUGIN_DISABLED,        0);
define(GALLERY_PLUGIN_STATUS_UNKNOWN, -1);
define(GALLERY_PLUGIN_NOT_ACTIVE,     -2);
define(GALLERY_PLUGIN_NOT_INSTALLED,  -3);
define(GALLERY_PLUGIN_MISSING,        -4);
function _gallery_settings_install($form_values = NULL) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_install.inc');
  return _gallery_install($form_values);
kiz_0987's avatar
kiz_0987 committed
 
function _gallery_settings_general() {
  // Short Status
  gallery_plugin_status(array('imageblock', 'imageframe', 'search'), TRUE);
  $status = gallery_get_status();
    '#type' => 'fieldset',
    '#title' => t('Status'),
    '#description' => gallery_format_status($status, ''),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  /*
  // Gallery2 Theme Settings
  $form['theme'] = array(
    '#type' => 'fieldset',
    '#title' => t('Gallery2 theme settings'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $themes = array(GALLERY_NO_EMBED_THEME => t('default'));
  $themes += gallery_get_themes();
  $form['theme']['gallery_theme'] = array(
    '#type' => 'select',
    '#title' => t('Gallery2 embedded theme'),
    '#default_value' => variable_get('gallery_theme', GALLERY_NO_EMBED_THEME),
    '#options' => $themes,
    '#description' => t('Gallery2 will switch to this theme when viewed in embedded mode.'),
  );
  */
  $imageblock_desc = t('The Gallery Image Block requires the Gallery2
    Image Block plugin (!imageblock_status) and optionally the Gallery2 Image Frame 
    plugin (!imageframe_status).', array(
        '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
        '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
        ));
  // Gallery Block Settings
  $form['blocks'] = array(
    '#type' => 'fieldset',
    '#title' => t('Gallery block settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('You can now have multiple image blocks and grid blocks. Use these settings to determine
                         the number of available blocks.<br /><strong>Warning: If you decrease the number of blocks,
                         always the last block (with the highest ID) will be removed.</strong>'),
  );
  $form['blocks']['gallery_block_image_num'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of image blocks'),
    '#default_value' => variable_get('gallery_block_image_num', 1),
    '#size' => 10,
    '#maxlength' => 10,
    '#description' => t('Select how many image blocks should be available.'),
  );
  $form['blocks']['gallery_block_grid_num'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of grid image blocks'),
    '#default_value' => variable_get('gallery_block_grid_num', 1),
    '#size' => 10,
    '#maxlength' => 10,
    '#description' => t('Select how many grid image blocks should be available.'),
  );
  
  // Gallery2 Sidebar Settings
  $form['sidebar'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sidebar settings'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['sidebar']['gallery_move_sidebar_to_block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Move Gallery2 sidebar to Drupal Gallery Navigation block'),
    '#default_value' => variable_get('gallery_move_sidebar_to_block', 1),
    '#description' => t('When selected, the Gallery2 sidebar will be moved into
                         the Drupal "Gallery Navigation" block. This typically allows
                         for a much cleaner embedded gallery and is generally
                         recommended. Note that you will need to enable the Gallery
                         Navigation block.'),
  );
  $form['sidebar']['gallery_move_admin_sidebar_to_block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Move Gallery2 Admin sidebar to Drupal Gallery Navigation block'),
    '#default_value' => variable_get('gallery_move_admin_sidebar_to_block', 0),
    '#description' => t('When selected, the Gallery2 Admin sidebar will be moved into
                         the Drupal "Gallery Navigation" block. This is not normally
                         recommended since the Admin Sitebar is very long and the
                         formatting does not always fit with the rest of the block
                         (but cannot be changed in the current Gallery2 versions).'),
    '#disabled' => !variable_get('gallery_move_sidebar_to_block', 1),
  );

  // Gallery2 Google Sitemap Settings
  $gallery2_sitemap_status = gallery_single_plugin_status('sitemap');
  $gallery2_sitemap_status_str = theme('gallery_plugin_status_message', $gallery2_sitemap_status);
  $gsitemap_status = module_exists('gsitemap');
  $gsitemap_status_str = theme('gallery_module_status_message', $gsitemap_status);
  $desc = t('Allows the Gallery2 Google (XML) sitemap to be merged
kiz_0987's avatar
kiz_0987 committed
    with the Drupal one so that only one URL 
    needs to be supplied to Google (or other search site). Requires the
    Drupal gsitemap module (!gsitemap_status) and the Gallery2 sitemap module 
    (!gallery2_sitemap_status) to be installed/activated.',
    array(
      '!gsitemap_status' => $gsitemap_status_str, 
      '!gallery2_sitemap_status' => $gallery2_sitemap_status_str,
    )
  );

  $form['sitemap'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google (XML) sitemap settings'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => $desc,
  );
  $form['sitemap']['gallery_enable_sitemap'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable merge of Gallery2 sitemap with Drupal sitemap'),
    '#default_value' => variable_get('gallery_enable_sitemap', 1),
    '#disabled' => !($gsitemap_status && ($gallery2_sitemap_status == GALLERY_PLUGIN_ENABLED)),
  );
    
  // Error logging / Debug Settings
  $form['error'] = array(
    '#type' => 'fieldset',
    '#title' => t('Error logging / Debug settings'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['error']['gallery_error_mode'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Error logging'),
    '#default_value' => variable_get('gallery_error_mode', array(GALLERY_ERROR_WATCHDOG)),
    '#options' => array(GALLERY_ERROR_WATCHDOG => t('Watchdog'),
                        GALLERY_ERROR_BROWSER => t('Output to the browser'),
                        GALLERY_ERROR_VERBOSE => t('Verbose error messages')),
    '#description' => t('Choose where errors are displayed and how detailed they are.'),
  $form['error']['gallery_report'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable bug report assistant'),
    '#default_value' => variable_get('gallery_report', 1),
    '#description' => t('In case of errors the module can automatically assemble useful data (system info and debug traces) to help you with detailed bug reports. Only available to users with \'administer site configuration\' permission.')
  );
  $form['error']['gallery_debug'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable debug mode'),
    '#default_value' => variable_get('gallery_debug', 0),
    '#description' => t('Print out debug variables and verbose error messages. Only visible to users with \'administer site configuration\' permission.')
  );
  
  // Relevant links
  $form['links'] = array(
    '#type' => 'fieldset',
    '#title' => t('Links to the most relevant Drupal & Gallery2 pages'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $desc .= '<li><a href= "@gallery-users">Gallery users</a> : Gallery2 user integration and synchronization.</li>';
  $desc .= '<li><a href= "@gallery-report">Report Generator</a> : Collect information about your installation. Useful especially for bug reports.</li>';
  $desc .= '</ul>';
  $form['links']['drupal'] = array(
    '#type' => 'fieldset',
    '#title' => t('Links to Drupal paths'),
    '#description' => t($desc, array(
      '@gallery-users' => url('admin/user/gallery'),
      '@gallery-report' => url('admin/settings/gallery/report/download'))),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $desc .= '<li><a href= "@g2-modules">Plugins</a> : To install, activate or configure the required and optional plugins relating to gallery.module (Image Block, Image Frame, URL Rewrite, Sitemap, Search).</li>';
  $desc .= '<li><a href= "@g2-themes">Themes</a> : To add/remove blocks in the sidebar.</li>';
  $desc .= '<li><a href= "@g2-rewrite">Embedded URL Rewrite settings</a> : To define the rewrite rules.</li>';
  $desc .= '<li><a href= "@g2-cookie">Cookie Settings</a> : Only needed for a small number of site configurations, such as the use of different subdomains for Gallery2 and Drupal.</li>';
  $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
  $form['links']['gallery'] = array(
    '#type' => 'fieldset',
    '#title' => t('Links to Gallery2 Site Admin sections'),
    '#description' => t($desc, array(
      '@g2-modules' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules',
      '@g2-themes' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminThemes&g2_mode=defaults',
      '@g2-rewrite' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=rewrite.AdminRewrite&g2_mode=setup',
      '@g2-cookie' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminCore')),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  
  $form['#validate']['_gallery_settings_general_validate'] = array();
  $form['#submit']['_gallery_settings_general_submit'] = array();
  $form['#submit']['system_settings_form_submit'] = array();
function _gallery_settings_general_validate($form_id, $form_values) {
  if (!is_numeric($form_values['gallery_block_image_num']) || $form_values['gallery_block_image_num'] < 1) {
    form_set_error('gallery_block_image_num', t('Number of image blocks must be a positiv integer greater zero.'));
  }
  if (!is_numeric($form_values['gallery_block_grid_num']) || $form_values['gallery_block_grid_num'] < 1) {
    form_set_error('gallery_block_grid_num', t('Number of grid blocks must be a positiv integer greater zero.'));
  }
}

function _gallery_settings_general_submit($form_id, $form_values) {
  if ($form_values['gallery_enable_sitemap'] != variable_get('gallery_enable_sitemap', 0)) {
kiz_0987's avatar
kiz_0987 committed
    drupal_set_message('The Google (XML) sitemap setting has been updated, but the new sitemap may not be generated immediately (controlled by gsitemap).');
function _gallery_settings_block_image($delta) {
  $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe'));

  $imageblock_desc = t('The Gallery Image Block requires the Gallery2
    Image Block plugin (!imageblock_status) and optionally the Gallery2 Image Frame 
    plugin (!imageframe_status).', array(
        '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
        '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
  if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
    $g2_plugins_page = (variable_get('gallery_valid', 0)) ? 
        t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
          array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
        : t('Gallery2 Site Admin -> Plugins');
    $g2_imageblock_desc = t(' However the Image Block plugin is unavailable, so this block is
      not available and the settings are disabled. To use this block please go to
      the !g2_plugins page and install/activate the Image Block plugin.', array(
      '!g2_plugins' => $g2_plugins_page));
    $imageblock_desc .= $g2_imageblock_desc;
  }
  
  $form['#description'] = $imageblock_desc;

  $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
     t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
        array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
kiz_0987's avatar
kiz_0987 committed
  
  $image_frames = gallery_get_image_frames();
  _gallery_block_options($type_map, $param_map);
  
  if (variable_get('gallery_block_image_num', 1) > 1) {
    $form['gallery_block_image_'.$delta.'_blockid'] = array(
      '#type' => 'textfield',
      '#title' => t('Block Identifier [Block @id]', array('@id' => $delta+1)),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_blockid', ''),
      '#size' => 25,
      '#maxlength' => 30,
      '#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)'),
    );
  }
  if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {       
    $numimages = variable_get('gallery_block_image_'.$delta.'_num_images', 3);
    $form['gallery_block_image_'.$delta.'_num_images'] = array(
      '#type' => 'select',
      '#title' => t('Number of images in block'),
      '#default_value' => $numimages,
      '#options' => _gallery_range_array(1, 20),
      '#description' => t('Choose the number of images to appear. You will need to submit the form if you have increased the number in order to choose the image types.'),
    $gallery_block_block = variable_get('gallery_block_image_'.$delta.'_block_block', array('randomImage'));
    $form['gallery_block_image_'.$delta.'_block_block'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image types'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
      '#description' => t('Pick the type of images you would like to see. You can select the same type more than once.'),
    );
    for ($i=0; $i<$numimages; $i++) {
      $form['gallery_block_image_'.$delta.'_block_block'][$i] = array(
        '#type' => 'select',
        '#title' => '',
        '#default_value' => $gallery_block_block[$i],
        '#options' => array_merge(array('none' => t('None')), $type_map),
    $form['gallery_block_image_'.$delta.'_item_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Album or Item ID'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_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['gallery_block_image_'.$delta.'_block_show'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Image data'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_block_show', array('title', 'heading')),
      '#description' => t('Choose the item metadata you would like to display.'),
    );
    
    $form['gallery_block_image_'.$delta.'_size_method'] = array(
      '#type' => 'select',
      '#title' => t('Image size method'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT),
      '#options' => array(
        'maxsize' => t('Max Size'),
        'exactsize' => t('Exact Size'),
      '#description' => t('\'Max Size\' gives faster image downloading, but the image size 
                           may be smaller than the size defined below. <br />\'Exact Size\' may be slower
                           (as a larger image is downloaded and then scaled by the browser) but the image
                           will be guaranteed to be the size defined below. Only supported for G2.2+.'),
    $form['gallery_block_image_'.$delta.'_size'] = array(
      '#type' => 'textfield',
      '#title' => t('Image size'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT),
      '#size' => 10,
      '#maxlength' => 10,
      '#description' => t('Sets the size (in pixels) of the longest side of the image according to the method defined above.'),
    $form['gallery_block_image_'.$delta.'_album_frame'] = array(
      '#type' => 'select',
      '#title' => t('Album frame'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_album_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['gallery_block_image_'.$delta.'_item_frame'] = array(
      '#type' => 'select',
      '#title' => t('Item frame'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_item_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['gallery_block_image_'.$delta.'_link_target'] = array(
      '#type' => 'textfield',
      '#title' => t('Link target'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_link_target', ''),
      '#size' => 20,
      '#maxlength' => 20,
      '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
    );

    $form['gallery_block_image_'.$delta.'_link'] = array(
      '#title' => t('Image Link'),
      '#default_value' => variable_get('gallery_block_image_'.$delta.'_link', ''),
      '#size' => 60,
      '#maxlength' => 255,
      '#description' => t('By default the image has a link to the item in the Gallery. This
        can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
        to link somewhere else instead.'),
  return $form;
}

function _gallery_settings_block_grid($delta) {
  $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe'));

  $gridblock_desc = t('The Gallery Grid Block requires the Gallery2
    Image Block plugin (!imageblock_status) and optionally the Gallery2 Image Frame 
    plugin (!imageframe_status).', array(
        '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
        '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
    ));
  if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
    $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
      t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
        array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
      : t('Gallery2 Site Admin -> Plugins');
    $g2_imageblock_desc = t(' However the Image Block plugin is unavailable, so this block is
      not available and the settings are disabled. To use this block please go to
      the !g2_plugins page and install/activate the Image Block plugin.',
        array('!g2_plugins' => $g2_plugins_page));
    $gridblock_desc .= $g2_imageblock_desc;
  }
  
  $form['#description'] = $gridblock_desc; 

  $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
    t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
      array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
  
  $image_frames = gallery_get_image_frames();
  _gallery_block_options($type_map, $param_map);
  
  if (variable_get('gallery_block_grid_num', 1) > 1) {
    $form['gallery_block_grid_'.$delta.'_blockid'] = array(
      '#type' => 'textfield',
      '#title' => t('Block Identifier [Block @id]', array('@id' => $delta+1)),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_blockid', ''),
      '#size' => 25,
      '#maxlength' => 30,
      '#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)'),
    );
  }
   
  if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {          
    $form['gallery_block_grid_'.$delta.'_num_cols'] = array(
      '#type' => 'select',
      '#title' => t('Number of columns'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_num_cols', 2),
      '#options' => _gallery_range_array(1, 5),
      '#description' => t('Enter the number of columns in the grid.'),
    );
    
    $form['gallery_block_grid_'.$delta.'_num_rows'] = array(
      '#type' => 'select',
      '#title' => t('Number of rows'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_num_rows', 2),
      '#options' => _gallery_range_array(1, 5),
      '#description' => t('Enter the number of rows in the grid.'),
    );
    
    $form['gallery_block_grid_'.$delta.'_block_block'] = array(
      '#type' => 'select',
      '#title' => 'Image types',
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_block_block', 'randomImage'),
      '#description' => 'Pick the type of images you would like to see in the grid.',
    );
      
    $form['gallery_block_grid_'.$delta.'_item_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Album or Item ID'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_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['gallery_block_grid_'.$delta.'_block_show'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Image data'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_block_show', array()),
      '#description' => t('Choose the item metadata you would like to display.'),
    );
    
    $form['gallery_block_grid_'.$delta.'_size_method'] = array(
      '#type' => 'select',
      '#title' => t('Image size method'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT),
      '#options' => array(
        'maxsize' => t('Max Size'),
        'exactsize' => t('Exact Size'),
      '#description' => t('\'Max Size\' gives faster image downloading, but the image size 
                           may be smaller than the size defined below. <br />\'Exact Size\' may be slower
                           (as a larger image is downloaded and then scaled by the browser) but the image
                           will be guaranteed to be the size defined below. Only supported for G2.2+.'),
    $form['gallery_block_grid_'.$delta.'_size'] = array(
      '#type' => 'textfield',
      '#title' => t('Image size'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_size', GALLERY_GRID_SIZE_DEFAULT),
      '#size' => 10,
      '#maxlength' => 10,
      '#description' => t('Sets the size (in pixels) of the longest side of the image according
                          to the method defined above.'),
    );
    
    $form['gallery_block_grid_'.$delta.'_album_frame'] = array(
      '#type' => 'select',
      '#title' => t('Album frame'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_album_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['gallery_block_grid_'.$delta.'_item_frame'] = array(
      '#type' => 'select',
      '#title' => t('Item frame'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_item_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['gallery_block_grid_'.$delta.'_link_target'] = array(
      '#type' => 'textfield',
      '#title' => t('Link target'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_link_target', ''),
      '#size' => 20,
      '#maxlength' => 20,
      '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
    );

    $form['gallery_block_grid_'.$delta.'_link'] = array(
      '#title' => t('Image Link'),
      '#default_value' => variable_get('gallery_block_grid_'.$delta.'_link', ''),
      '#size' => 60,
      '#maxlength' => 255,
      '#description' => t('By default the image has a link to the item in the Gallery. This
        can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
        to link somewhere else instead.'),
function _gallery_settings_block_save($delta, $form_values) {
  // Validate variable values
  if (isset($form_values['gallery_block_image_'.$delta.'_size'])) {
    if (!is_numeric($form_values['gallery_block_image_'.$delta.'_size']) || $form_values['gallery_block_image_'.$delta.'_size'] < 10) {
      $form_values['gallery_block_image_'.$delta.'_size'] = 10;
      drupal_set_message(t('Image size must be a number greater than ten pixels. (The value has been updated to \'10\' for your convenience.)'), 'error');
    }
  }
  if (isset($form_values['gallery_block_grid_'.$delta.'_size'])) {
    if (!is_numeric($form_values['gallery_block_grid_'.$delta.'_size']) || $form_values['gallery_block_grid_'.$delta.'_size'] < 10) {
      $form_values['gallery_block_grid_'.$delta.'_size'] = 10;
      drupal_set_message(t('Image size must be a number greater than ten pixels. (The value has been updated to \'10\' for your convenience.)'), 'error');
  }
  // Save variables
  foreach ($form_values as $key => $value) {
    if (strpos($key, 'gallery_block_') == 0) {
      if (is_array($value) && isset($form_values['array_filter'])) {
        $value = array_keys(array_filter($value));
      }
      variable_set($key, $value);
function _gallery_settings_filter() {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
  $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe'));
  
  $desc = t('Note that changing the defaults here will change the all the gallery filter images
    on the site, not just new images. '); 
  $desc .= t('The Gallery Filter requires the Gallery2 Image Block plugin (!imageblock_status) and
              optionally the Gallery2 Image Frame plugin (!imageframe_status).',
              array(
                '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
                '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
              ));
  if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
    $g2_plugins_page = (variable_get('gallery_valid', 0)) ? 
      t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
        array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
      : t('Gallery2 Site Admin -> Plugins');
    $desc .= t(' However the Image Block plugin is unavailable, so the Gallery Filter is
      not available and the settings are disabled. To use the filter please go to
      the !g2_plugins page and install/activate the Image Block plugin.',
        array('!g2_plugins' => $g2_plugins_page));
  }    

  $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
     t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
      array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
  $form['filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('Gallery Filter settings'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#description' => $desc,
  $image_frames = gallery_get_image_frames();
  _gallery_block_options($type_map, $param_map);
  if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {          
    $form['filter']['gallery_filter_prefix'] = array(
      '#type' => 'textfield',
      '#title' => t('Filter prefix'),
      '#default_value' => variable_get('gallery_filter_prefix', 'G2'),
      '#size' => 10,
      '#maxlength' => 10,
      '#description' => t('Prefix to use with filter. Example: \'G2\' means you use [G2: 999].
        Be careful when changing this as any pages using the previous prefix will not be changed
        and so will not be filtered correctly.'),
    );
    
    $form['filter']['gallery_filter_default_block_type'] = array(
      '#type' => 'select',
      '#title' => t('Default image type'),
      '#default_value' => variable_get('gallery_filter_default_block_type', 'viewedImage'),
      '#options' => $type_map,
      '#description' => t('Pick the default type of image you would like to use.'),
    
    $form['filter']['gallery_filter_can_cache'] = array(
      '#type' => 'checkbox',
      '#title' => t('Cache gallery filter pages'),
      '#default_value' => variable_get('gallery_filter_can_cache', 1),
      '#description' => t('By default the gallery filter output is cached by Drupal to speed up page loading. However, it will not cache the css class info for the frames. The best approach is the make sure that the sidebar image block and the gallery filter images use the same frames. If you are unable to do this you will have to deselect this option to force Drupal not to cache the pages, or else your frames will not appear. If you change this option you will need to go to <a href="@link">admin/settings/filters</a> and re-save the image formats that use gallery filter.', array('@link' => url('admin/settings/filters'))),
    );
    
    $form['filter']['gallery_filter_n_images'] = array(
      '#type' => 'textfield',
      '#title' => t('Default number of images'),
      '#default_value' => variable_get('gallery_filter_n_images', 1),
      '#size' => 3,
      '#maxlength' => 3,
      '#description' => t('How many images you want the default block to show.  Best to keep at 1 and use the n parameter.'),
    );
    
    $form['filter']['gallery_filter_default_show'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Default image data'),
      '#default_value' => variable_get('gallery_filter_default_show', array('none')),
      '#description' => t('Choose the item metadata you would like to display by default.  This will change all instances where show parameter was not specified.'),
    );
    
    // parse gallery_filter.css and extract classes
    $css = implode('', file(drupal_get_path('module', 'gallery') .'/gallery_filter.css'));
    preg_match_all('/div.giImageBlock.(\w+) {/', $css, $matches);
    if (count($matches[1])) {
      $classes = array();
      foreach ($matches[1] as $class) {
        $classes[$class] = $class;
      }
      $form['filter']['gallery_filter_default_div_class'] = array(
        '#type' => 'select',
        '#title' => t('Default class'),
        '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
        '#options' => $classes,
      );
    }
    else {
      $form['filter']['gallery_filter_default_div_class'] = array(
        '#type' => 'textfield',
        '#title' => t('Default class'),
        '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
        '#size' => 20,
        '#maxlength' => 20,
        '#description' => t('left, right, or nowrap. (See gallery_filter.css to add more or modify these.)'),
      );
    }
    
    $form['filter']['gallery_filter_default_maxsize'] = array(
      '#type' => 'textfield',
      '#title' => t('Default \'Max Size\' thumbnail size'),
      '#default_value' => variable_get('gallery_filter_default_maxsize', GALLERY_FILTER_MAXSIZE_DEFAULT),
      '#size' => 10,
      '#maxlength' => 10,
    );
    
    $form['filter']['gallery_filter_default_exactsize'] = array(
      '#type' => 'textfield',
      '#title' => t('Default \'Exact Size\' thumbnail size'),
      '#default_value' => variable_get('gallery_filter_default_exactsize', GALLERY_FILTER_EXACTSIZE_DEFAULT),
      '#size' => 10,
      '#maxlength' => 10,
      '#description' => t('If no size is specified when calling the filter, one of
        these sizes (and implied method) will be used. <br />\'Max Size\' gives faster
        image downloading, but the image size 
        may be smaller than the size defined. <br />\'Exact Size\' may be slower
        (as a larger image is downloaded and then scaled by the browser) but the image
        will be guaranteed to be the size defined. Only supported for G2.2+.
        Only fill in one size box (not both) to set the default method.'),
    );
    
    $form['filter']['gallery_filter_default_album_frame'] = array(
      '#type' => 'select',
      '#title' => t('Default album frame'),
      '#default_value' => variable_get('gallery_filter_default_album_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['filter']['gallery_filter_default_item_frame'] = array(
      '#type' => 'select',
      '#title' => t('Default item frame'),
      '#default_value' => variable_get('gallery_filter_default_item_frame', 'none'),
      '#options' => $image_frames,
      '#description' => $imageframe_desc,
    );
    
    $form['filter']['gallery_filter_default_link_target'] = array(
      '#type' => 'textfield',
      '#title' => t('Default link target'),
      '#default_value' => variable_get('gallery_filter_default_link_target', ''),
      '#size' => 20,
      '#maxlength' => 20,
      '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
    
    $form['filter']['gallery_filter_default_link'] = array(
      '#type' => 'textfield',
      '#title' => t('Default Image Link'),
      '#default_value' => variable_get('gallery_filter_default_link', ''),
      '#size' => 20,
      '#maxlength' => 20,
      '#description' => t('By default the image has a link to the item in the Gallery. This
        can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
        to link somewhere else instead.'),
    );
  // Include both #submit handlers so that the default system submit
  // is also called to save all the variables.
  $form['#submit']['_gallery_settings_filter_submit'] = array();
  $form['#submit']['system_settings_form_submit'] = array();
  return system_settings_form($form);
function _gallery_settings_filter_validate($form_id, $form_values) {
  // Only validate if a setting was returned
  if (isset($form_values['gallery_filter_default_maxsize'])) {
    if ((strlen($form_values['gallery_filter_default_maxsize']) > 0) &&
      (strlen($form_values['gallery_filter_default_exactsize']) > 0)) {
      form_set_error('gallery_filter_default_maxsize',
        t('You must set either the Max Size or the Exact Size, not both.'));  
    } 
    elseif ((strlen($form_values['gallery_filter_default_maxsize']) == 0) &&
      (strlen($form_values['gallery_filter_default_exactsize']) == 0)) {
      form_set_error('gallery_filter_default_maxsize',
        t('You must set either the Max Size or the Exact Size.'));  
    }
    if ((strlen($form_values['gallery_filter_default_maxsize']) > 0) &&
      (!is_numeric($form_values['gallery_filter_default_maxsize']) ||
      $form_values['gallery_filter_default_maxsize'] < 1)) {
      form_set_error('gallery_filter_default_maxsize',
        t('Max Size must be a number greater than zero.'));
    }
    if ((strlen($form_values['gallery_filter_default_exactsize']) > 0) &&
      (!is_numeric($form_values['gallery_filter_default_exactsize']) ||
      $form_values['gallery_filter_default_exactsize'] < 1)) {
      form_set_error('gallery_filter_default_exactsize',
        t('Exact Size must be a number greater than zero.'));
    }
    if ((strlen($form_values['gallery_filter_n_images']) > 0) &&
      (!is_numeric($form_values['gallery_filter_n_images']) ||
      $form_values['gallery_filter_n_images'] < 1)) {
      form_set_error('gallery_filter_n_images',
        t('Number of images must be a number greater than zero.'));
    }
function _gallery_settings_filter_submit($form_id, $form_values) {
  // The default values have changed, so the pages containing the gallery filter need
  // to be updated (or else it would only occur on an edit), so empty the filter cache.
  
  // Find out which formats are using the gallery filter
  $result = db_query("SELECT format FROM {filters} WHERE module = 'gallery'");
  while ($format = db_fetch_object($result)) {
    cache_clear_all($format->format .':', 'cache_filter', TRUE);
  drupal_set_message('The gallery filter cache has been cleared so that the new defaults apply.');
}

function _gallery_settings_g2image() {
  $plugin_status =  gallery_plugin_status(array('imageblock'));

  $desc = t('G2Image requires the Gallery2 Image Block plugin (!imageblock_status) and
             the g2image application to be installed.',
              array('!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock'])));
  if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
    $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
      t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
        array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
      : t('Gallery2 Site Admin -> Plugins');
    $desc .= t(' However the Image Block plugin is unavailable, so G2Image is
      not available and the settings are disabled. To use G2Image please go to
      the !g2_plugins page and install/activate the Image Block plugin.', array(
      '!g2_plugins' => $g2_plugins_page));
  $form['g2image'] = array(
    '#type' => 'fieldset',
    '#title' => t('Gallery Image Assist (G2Image) settings'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#description' => $desc,
  if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
    $form['g2image']['gallery_g2image_mode'] = array(
      '#type' => 'select',
      '#title' => t('Mode'),
      '#default_value' => variable_get('gallery_g2image_mode', 'disabled'),
      '#options' => array(
        'disabled' => t('Disabled'),
        'standalone' => t('Standalone'),
        'tinymce' => t('TinyMCE'),
      ),
      '#description' => t('Determines the mode of operation. For anything other than \'Disabled\' the g2image application has to be installed. See the INSTALL.txt instructions. In \'Standalone\' mode a button will be visible under textfields to launch the g2image window. In \'TinyMCE\' mode the g2image button can be used in the TinyMCE toolbar. Note that the TinyMCE version will NOT work wih Safari - use the standalone version instead.'),
    );
    $options = array(
      t('Show on every page except the listed pages.'),
      t('Show on only the listed pages.')
    );
    $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
  
    $form['g2image']['gallery_g2image_only_listed_pages'] = array(
      '#type' => 'radios',
      '#title' => t('Show g2image link on specific pages (Standalone mode only)'),
      '#default_value' => variable_get('gallery_g2image_only_listed_pages', 1),
      '#options' => $options,
    );
  
    $form['g2image']['gallery_g2image_std_pages'] = array(
      '#type' => 'textarea',
      '#title' => t('Pages (Standalone mode only)'),
      '#default_value' => variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages')),
      '#description' => $description
    );
  
    $form['g2image']['gallery_g2image_regex'] = array(
      '#type' => 'textfield',
      '#title' => t('Image Types Regular Expression'),
      '#default_value' => variable_get('gallery_g2image_regex', '@(jpg|jpeg|png|gif|bmp|svg|mov|mpg|mpeg)$@i'),
      '#size' => 50,
      '#maxlength' => 50,
      '#description' => t('Images with these file extensions will be displayed in g2image'),
    );
  
    $form['g2image']['gallery_g2image_sortby'] = array(
      '#type' => 'select',
      '#title' => t('Default Sort Order'),
      '#default_value' => variable_get('gallery_g2image_sortby', 'title_asc'),
      '#options' => array(
        'title_asc' => t('Gallery2 Title (A-z)'),
        'title_desc' => t('Gallery2 Title (z-A)'),
        'name_asc' => t('Filename (A-z)'),
        'name_desc' => t('Filename (z-A)'),
        'mtime_desc' => t('Last Modification (newest first)'),
        'mtime_asc' => t('Last Modification (oldest first)'),
      ),
      '#description' => t('Determines the default sorting order.'),
    );
  
    $form['g2image']['gallery_g2image_images_per_page'] = array(
      '#type' => 'select',
      '#title' => t('Default Number of images per page'),
      '#default_value' => variable_get('gallery_g2image_images_per_page', 20),
      '#options' => array(10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60),
      '#description' => t('Choose the default number of images per page.'),
    );
  
    $form['g2image']['gallery_g2image_display_filenames'] = array(
      '#type' => 'select',
      '#title' => t('Default Display Options'),
      '#default_value' => variable_get('gallery_g2image_display_filenames', 'thumbnails'),
      '#options' => array(
        'thumbnails' => t('Thumbnails only'),
        'filenames' => t('Thumbnails with title and filename'),
      ),
      '#description' => t('Choose the default display option for images.'),
    );
  
    $form['g2image']['gallery_g2image_click_mode'] = array(
      '#type' => 'select',
      '#title' => t('Default Click Mode'),
      '#default_value' => variable_get('gallery_g2image_click_mode', 'one_click_insert'),
      '#options' => array(
        'one_click_insert' => t('Insert using Default settings'),
        'show_advanced_options' => t('Open the Advanced Options Menu'),
      ),
      '#description' => t('The default settings for the "Results of clicking on an image:" option'),
    );
  
    $form['g2image']['gallery_g2image_click_mode_variable'] = array(
      '#type' => 'checkbox',
      '#title' => t('"Results of clicking on an image:" option is available to user'),
      '#default_value' => variable_get('gallery_g2image_click_mode_variable', 1),
      '#description' => t('Determines if the user can change the "Results of clicking on an image:" option.'),
    );
  
    $form['g2image']['gallery_g2image_default_action'] = array(
      '#type' => 'select',
      '#title' => t('Default Action'),
      '#default_value' => variable_get('gallery_g2image_default_action', 'drupal_g2_filter'),
      '#options' => array(
        'drupal_g2_filter' => t('Gallery Filter ID'),
        'thumbnail_image' => t('Thumbnail with link to image'),
        'thumbnail_album' => t('Thumbnail with link to parent album'),
        'thumbnail_custom_url' => t('Thumbnail with link to custom URL'),
        'thumbnail_only' => t('Thumbnail only'),
        'link_image' => t('Text link to image'),
        'link_parent' => t('Text link to parent album'),
      ),
      '#description' => t('Choose the default method of inserting the image info.'),
    );
  
    $form['g2image']['gallery_g2image_custom_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Default custom url'),
      '#default_value' => variable_get('gallery_g2image_custom_url', 'http://'),
      '#size' => 50,
      '#maxlength' => 50,
      '#description' => t('The default custom url. Used with \'Thumbnail with link to custom URL\' action setting'),
    );
    
    $gallery_g2image_custom_class = variable_get('gallery_g2image_custom_class', array());
    $css_options =  array(
      'none' => t('None'),
      'g2image_normal' => t('Normal'),
      'g2image_float_left' => t('Float Left'),
      'g2image_float_right' => t('Float Right'),
      'g2image_centered' => t('Centered'),
    );
  
    $add_css_options = array();
    foreach ($gallery_g2image_custom_class as $key => $value) {
      if ($value) {
        $add_css_options[$value] = $value;
      }
    }
    $css_options = array_merge($css_options, $add_css_options);
  
    $form['g2image']['gallery_g2image_default_alignment'] = array(
      '#type' => 'select',
      '#title' => t('Default Alignment'),
      '#default_value' => variable_get('gallery_g2image_default_alignment', 'none'),
      '#options' => $css_options,
      '#description' => t('Choose the default alignment of images.'),
    );
  
    $form['g2image']['gallery_g2image_custom_class'] = array('#tree' => TRUE);
  
    for ($i=1; $i<=4; $i++) {
      $form['g2image']['gallery_g2image_custom_class'][$i] = array(
        '#type' => 'textfield',
        '#title' => t('Custom Class @index', array('@index' => $i)),
        '#default_value' => $gallery_g2image_custom_class[$i],
        '#size' => 20,
        '#maxlength' => 50,
      );
    }
    $form['g2image']['gallery_g2image_custom_class'][$i-1]['#description'] = t('Additional css classes to be available for selection (must be defined in .css file).');
  
    $form['g2image']['gallery_g2image_class_mode'] = array(
      '#type' => 'select',
      '#title' => t('Alignment Class Insertion Point'),
      '#default_value' => variable_get('gallery_g2image_class_mode', 'img'),
      '#options' => array(
        'img' => t('<img class=...>'),
        'div' => t('<div class=...><img ...>'),
      ),
      '#description' => t('Determines where the alignment class will be inserted. If you choose \'&lt;div class=...&gt;&lt;img ...&gt;\', you will have to manually delete any &lt;div&gt; tags manually after deleting images from the TinyMCE window.'),
  $form['#validate']['_gallery_g2image_settings_validate'] = array();
  return system_settings_form($form);
function _gallery_settings_search() {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
  $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe', 'search'));

  $search_desc = t('The Gallery Search requires the Gallery2 Search plugin (!search_status) and
    optionally the Gallery2 Image Block plugin (!imageblock_status) and Gallery2 Image Frame 
    plugin (!imageframe_status).',
      array(