[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/gallery/ -> gallery_settings.inc (source)

   1  <?php
   2  // $Id: gallery_settings.inc,v 1.12.2.11 2008/08/04 21:13:06 profix898 Exp $
   3  
   4  /**
   5   * gallery.module : gallery_settings.inc
   6   * Settings functions
   7   */
   8  
   9  /**
  10   * Function _gallery_settings_general().
  11   */
  12  function _gallery_settings_general() {
  13    // Short Status
  14    gallery_version();
  15    gallery_plugin_set_status(array('imageblock', 'imageframe', 'search'));
  16    $status = gallery_get_status();
  17    
  18    $form['status'] = array(
  19      '#type' => 'fieldset',
  20      '#title' => t('Status'),
  21      '#description' => gallery_format_status($status, ''),
  22      '#collapsible' => FALSE,
  23      '#collapsed' => FALSE,
  24    );
  25    
  26    // Theme Settings
  27    $form['theme'] = array(
  28      '#type' => 'fieldset',
  29      '#title' => t('Theme and Display settings'),
  30      '#description' => '',
  31      '#collapsible' => TRUE,
  32      '#collapsed' => TRUE,
  33    );
  34    $themes = system_theme_data();
  35    ksort($themes);
  36    $options = array('default' => t('System default'));
  37    foreach ($themes as $theme) {
  38      $options[$theme->name] = $theme->info['name'];
  39    }
  40    $form['theme']['gallery_page_theme'] = array(
  41      '#type' => 'select',
  42      '#title' => t('Gallery page theme'),
  43      '#default_value' => variable_get('gallery_page_theme', 'default'),
  44      '#options' => $options,
  45      '#description' => t('Drupal theme to be used for all gallery pages (gallery/*).'),
  46    );
  47    $form['theme']['gallery_embed_theme'] = array(
  48      '#type' => 'select',
  49      '#title' => t('Gallery embedded theme'),
  50      '#default_value' => variable_get('gallery_embed_theme', 'default'),
  51      '#options' => array('default' => t('Gallery default')) + gallery_list_themes(),
  52      '#description' => t('Gallery2 theme to be used for embedded gallery.'),
  53    );
  54    $form['theme']['gallery_root_album'] = _gallery_settings_album_select(
  55      t('Default root album'),
  56      variable_get('gallery_root_album', 'default'),
  57      t('Default root album to use on gallery pages. If you have a separate album for use with nodes (Filter, G2Image, ...)
  58         it can be helpful to move the root album to hide that album from the browseable gallery.')
  59    );
  60    
  61    // Gallery Block Settings
  62    $form['blocks'] = array(
  63      '#type' => 'fieldset',
  64      '#title' => t('Gallery block settings'),
  65      '#collapsible' => TRUE,
  66      '#collapsed' => TRUE,
  67      '#description' => t('Use these settings to determine the number of available blocks.<br />
  68                           <strong>Warning: If you decrease the number of blocks, always the last
  69                           block (with the highest ID) will be removed.</strong>'),
  70    );
  71    $form['blocks']['gallery_block_num'] = array(
  72      '#type' => 'textfield',
  73      '#title' => t('Number of blocks'),
  74      '#default_value' => variable_get('gallery_block_num', 2),
  75      '#size' => 10,
  76      '#maxlength' => 10,
  77      '#description' => t('Select how many blocks should be available.'),
  78    );
  79    
  80    // Gallery2 Sidebar Settings
  81    $form['sidebar'] = array(
  82      '#type' => 'fieldset',
  83      '#title' => t('Sidebar settings'),
  84      '#description' => '',
  85      '#collapsible' => TRUE,
  86      '#collapsed' => TRUE,
  87    );
  88    $form['sidebar']['gallery_move_sidebar_to_block'] = array(
  89      '#type' => 'checkbox',
  90      '#title' => t('Move Gallery2 sidebar to Drupal Gallery Navigation block'),
  91      '#default_value' => variable_get('gallery_move_sidebar_to_block', 1),
  92      '#description' => t('When selected, the Gallery2 sidebar will be moved into
  93                           the Drupal "Gallery Navigation" block. This typically allows
  94                           for a much cleaner embedded gallery and is generally
  95                           recommended. Note that you will need to enable the Gallery
  96                           Navigation block.'),
  97    );
  98    $form['sidebar']['gallery_move_admin_sidebar_to_block'] = array(
  99      '#type' => 'checkbox',
 100      '#title' => t('Move Gallery2 Admin sidebar to Drupal Gallery Navigation block'),
 101      '#default_value' => variable_get('gallery_move_admin_sidebar_to_block', 0),
 102      '#description' => t('When selected, the Gallery2 Admin sidebar will be moved into
 103                           the Drupal "Gallery Navigation" block. This is not normally
 104                           recommended since the Admin Sitebar is very long and the
 105                           formatting does not always fit with the rest of the block
 106                           (but cannot be changed in the current Gallery2 versions).'),
 107      '#disabled' => !variable_get('gallery_move_sidebar_to_block', 1),
 108    );
 109    
 110    // Gallery2 Google Sitemap Settings
 111    $gallery2_sitemap_status = gallery_single_plugin_status('sitemap');
 112    $gallery2_sitemap_status_str = theme('gallery_plugin_status_message', $gallery2_sitemap_status);
 113    $xmlsitemap_status = module_exists('xmlsitemap');
 114    $xmlsitemap_status_str = theme('gallery_module_status_message', $xmlsitemap_status);
 115    $xmlsitemap_available = $xmlsitemap_status && ($gallery2_sitemap_status == GALLERY_PLUGIN_ENABLED);
 116    
 117    $desc = t('Allows the Gallery2 sitemap to be merged with the Drupal one so that only one URL needs to
 118               be supplied to search engines. Requires the Drupal XML Sitemap module (!xmlsitemap_status) and
 119               the Gallery2 sitemap module (!gallery2_sitemap_status) to be installed/activated.',
 120      array(
 121        '!xmlsitemap_status' => $xmlsitemap_status_str,
 122        '!gallery2_sitemap_status' => $gallery2_sitemap_status_str,
 123      )
 124    );
 125    
 126    $form['sitemap'] = array(
 127      '#type' => 'fieldset',
 128      '#title' => t('XML Sitemap settings'),
 129      '#description' => '',
 130      '#collapsible' => TRUE,
 131      '#collapsed' => TRUE,
 132      '#description' => $desc,
 133    );
 134    $form['sitemap']['gallery_enable_sitemap'] = array(
 135      '#type' => 'checkbox',
 136      '#title' => t('Enable merge of Gallery2 sitemap with Drupal sitemap'),
 137      '#default_value' => $xmlsitemap_available ? variable_get('gallery_enable_sitemap', 1) : FALSE,
 138      '#disabled' => !$xmlsitemap_available,
 139    );
 140    
 141    // Error logging / Debug Settings
 142    $form['error'] = array(
 143      '#type' => 'fieldset',
 144      '#title' => t('Error logging / Debug settings'),
 145      '#description' => '',
 146      '#collapsible' => TRUE,
 147      '#collapsed' => TRUE,
 148    );
 149    $form['error']['gallery_error_mode'] = array(
 150      '#type' => 'checkboxes',
 151      '#title' => t('Error logging'),
 152      '#default_value' => variable_get('gallery_error_mode', array(GALLERY_ERROR_WATCHDOG)),
 153      '#options' => array(GALLERY_ERROR_WATCHDOG => t('Watchdog'),
 154                          GALLERY_ERROR_BROWSER => t('Output to the browser'),
 155                          GALLERY_ERROR_VERBOSE => t('Verbose error messages')),
 156      '#description' => t('Choose where errors are displayed and how detailed they are.'),
 157    );
 158    $form['error']['gallery_report'] = array(
 159      '#type' => 'checkbox',
 160      '#title' => t('Enable bug report assistant'),
 161      '#default_value' => variable_get('gallery_report', 1),
 162      '#description' => t('In case of errors the module can automatically assemble useful data (system info and debug
 163                           traces) to help you with detailed bug reports. Only available to users with \'administer
 164                           site configuration\' permission.')
 165    );
 166    $search_status = module_exists('search') && (gallery_single_plugin_status('search') == GALLERY_PLUGIN_ENABLED);
 167    $form['error']['gallery_error_redirect'] = array(
 168      '#type' => 'checkbox',
 169      '#title' => t('Redirect to Gallery search form for invalid paths'),
 170      '#default_value' => $search_status ? variable_get('gallery_error_redirect', 0) : 0,
 171      '#description' => t('Instead of showing a message that the requested Gallery URL does not exist the
 172                           user is redirected to the search form.'),
 173      '#disabled' => !$search_status,
 174    );
 175    $form['error']['debug'] = array(
 176      '#type' => 'fieldset',
 177      '#title' => t('Debug settings'),
 178      '#description' => '',
 179      '#collapsible' => TRUE,
 180      '#collapsed' => TRUE,
 181    );
 182    $debug = variable_get('gallery_debug', 0);
 183    $form['error']['debug']['gallery_debug'] = array(
 184      '#type' => 'checkbox',
 185      '#title' => t('Enable debug mode'),
 186      '#default_value' => $debug,
 187      '#description' => t('Print out debug variables and verbose error messages. Only visible to users
 188                           with \'administer site configuration\' permission.')
 189    );
 190    $form['error']['debug']['gallery_g2debug'] = array(
 191      '#type' => 'checkbox',
 192      '#title' => t('Enable G2 debug output'),
 193      '#default_value' => $debug && variable_get('gallery_g2debug', 0),
 194      '#description' => t('Enables Gallery2\'s buffered debug output to be displayed.'),
 195      '#disabled' => !$debug
 196    );
 197    
 198    // Relevant links
 199    $form['links'] = array(
 200      '#type' => 'fieldset',
 201      '#title' => t('Links to the most relevant Drupal & Gallery2 pages'),
 202      '#collapsible' => TRUE,
 203      '#collapsed' => TRUE,
 204    );
 205    // Drupal links
 206    $desc  = '<ul>';
 207    $desc .= '<li><a href="@gallery-users">Gallery users</a> : Gallery2 user integration and synchronization.</li>';
 208    $desc .= '<li><a href="@gallery-report">Report Generator</a> : Collect information about your installation. Useful
 209              especially for bug reports.</li>';
 210    $desc .= '</ul>';
 211    $form['links']['drupal'] = array(
 212      '#type' => 'fieldset',
 213      '#title' => t('Links to Drupal paths'),
 214      '#description' => t($desc, array(
 215        '@gallery-users' => url('admin/user/gallery'),
 216        '@gallery-report' => url('admin/settings/gallery/report/download'))),
 217      '#collapsible' => FALSE,
 218      '#collapsed' => FALSE,
 219    );
 220    // Gallery2 links
 221    $desc  = '<ul>';
 222    $desc .= '<li><a href="@g2-modules">Plugins</a> : To install, activate or configure the required and optional plugins
 223              relating to gallery.module (Image Block, Image Frame, URL Rewrite, Sitemap, Search).</li>';
 224    $desc .= '<li><a href="@g2-themes">Themes</a> : To add/remove blocks in the sidebar.</li>';
 225    if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) {
 226      $desc .= '<li><a href="@g2-rewrite">Embedded URL Rewrite settings</a> : To define the rewrite rules.</li>';
 227    }
 228    $desc .= '<li><a href="@g2-cookie">Cookie Settings</a> : Only needed for a small number of site configurations, such
 229              as the use of different subdomains for Gallery2 and Drupal.</li>';
 230    $desc .= '</ul>';
 231    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
 232    $form['links']['gallery'] = array(
 233      '#type' => 'fieldset',
 234      '#title' => t('Links to Gallery2 Site Admin sections'),
 235      '#description' => t($desc, array(
 236        '@g2-modules' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules',
 237        '@g2-themes' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminThemes&g2_mode=defaults',
 238        '@g2-rewrite' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=rewrite.AdminRewrite&g2_mode=setup',
 239        '@g2-cookie' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminCore')),
 240      '#collapsible' => FALSE,
 241      '#collapsed' => FALSE,
 242    );
 243    
 244    $form = system_settings_form($form);
 245    $form['#validate'] = array('_gallery_settings_general_validate');
 246    $form['#submit'] = array('_gallery_settings_general_submit', 'system_settings_form_submit');
 247    return $form;
 248  }
 249  
 250  /**
 251   * Function _gallery_settings_general_validate().
 252   */
 253  function _gallery_settings_general_validate($form, &$form_state) {
 254    if (!is_numeric($form_state['values']['gallery_block_num']) || $form_state['values']['gallery_block_num'] < 1) {
 255      form_set_error('gallery_block_num', t('Number of image blocks must be a positiv integer greater zero.'));
 256    }
 257  }
 258  
 259  /**
 260   * Function _gallery_settings_general_submit().
 261   */
 262  function _gallery_settings_general_submit($form, &$form_state) {
 263    if ($form_state['values']['gallery_enable_sitemap'] != variable_get('gallery_enable_sitemap', 0)) {
 264      drupal_set_message('The XML sitemap setting has been updated, but the new sitemap may not be generated
 265                          immediately (controlled by XML Sitemap).');
 266    }
 267  }
 268  
 269  /**
 270   * Function _gallery_settings_filter().
 271   */
 272  function _gallery_settings_filter() {
 273    require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
 274    $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe'));
 275    
 276    $desc = t('Note that changing the defaults here will change the all the gallery filter images
 277      on the site, not just new images. '); 
 278    $desc .= t('The Gallery Filter requires the Gallery2 Image Block plugin (!imageblock_status) and
 279                optionally the Gallery2 Image Frame plugin (!imageframe_status).',
 280                array(
 281                  '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
 282                  '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
 283                ));
 284    if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
 285      $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
 286      $g2_plugins_page = (variable_get('gallery_valid', 0)) ? 
 287        t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
 288          array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
 289        : t('Gallery2 Site Admin -> Plugins');
 290      $desc .= t(' However the Image Block plugin is unavailable, so the Gallery Filter is
 291        not available and the settings are disabled. To use the filter please go to
 292        the !g2_plugins page and install/activate the Image Block plugin.',
 293          array('!g2_plugins' => $g2_plugins_page));
 294    }    
 295  
 296    $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
 297      t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
 298        array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
 299  
 300    $form['filter'] = array(
 301      '#type' => 'fieldset',
 302      '#title' => t('Gallery Filter settings'),
 303      '#collapsible' => FALSE,
 304      '#collapsed' => FALSE,
 305      '#description' => $desc,
 306    );
 307    
 308    $image_frames = gallery_list_image_frames();
 309    _gallery_block_options($type_map, $param_map);
 310    $type_map['specificItem'] = t('Specific item');
 311    
 312    if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {          
 313      $form['filter']['gallery_filter_prefix'] = array(
 314        '#type' => 'textfield',
 315        '#title' => t('Filter prefix'),
 316        '#default_value' => variable_get('gallery_filter_prefix', 'G2'),
 317        '#size' => 10,
 318        '#maxlength' => 10,
 319        '#description' => t('Prefix to use with filter. Example: \'G2\' means you use [G2: 999].
 320          Be careful when changing this as any pages using the previous prefix will not be changed
 321          and so will not be filtered correctly.'),
 322      );
 323      
 324      $form['filter']['gallery_filter_default_block_type'] = array(
 325        '#type' => 'select',
 326        '#title' => t('Default image type'),
 327        '#default_value' => variable_get('gallery_filter_default_block_type', 'viewedImage'),
 328        '#options' => $type_map,
 329        '#description' => t('Pick the default type of image you would like to use.'),
 330      );
 331      
 332      $form['filter']['gallery_filter_can_cache'] = array(
 333        '#type' => 'checkbox',
 334        '#title' => t('Cache gallery filter pages'),
 335        '#default_value' => variable_get('gallery_filter_can_cache', 1),
 336        '#description' => t('By default the gallery filter output is cached by Drupal to speed up page loading.
 337                             However, it will not cache the css class info for the frames. The best approach is the
 338                             make sure that the sidebar image block and the gallery filter images use the same frames.
 339                             If you are unable to do this you will have to deselect this option to force Drupal not to
 340                             cache the pages, or else your frames will not appear. If you change this option you will
 341                             need to go to <a href="@link">admin/settings/filters</a> and re-save the image formats
 342                             that use gallery filter.', array('@link' => url('admin/settings/filters'))),
 343      );
 344      
 345      $form['filter']['gallery_filter_n_images'] = array(
 346        '#type' => 'textfield',
 347        '#title' => t('Default number of images'),
 348        '#default_value' => variable_get('gallery_filter_n_images', 1),
 349        '#size' => 3,
 350        '#maxlength' => 3,
 351        '#description' => t('How many images you want the default block to show.  Best to keep at 1 and use the n parameter.'),
 352      );
 353      
 354      $form['filter']['gallery_filter_default_show'] = array(
 355        '#type' => 'checkboxes',
 356        '#title' => t('Default image data'),
 357        '#default_value' => variable_get('gallery_filter_default_show', array('none')),
 358        '#options' => $param_map,
 359        '#description' => t('Choose the item metadata you would like to display by default.
 360                             This will change all instances where show parameter was not specified.'),
 361      );
 362      
 363      // Parse gallery_filter.css and extract classes
 364      $css = implode('', file(drupal_get_path('module', 'gallery') .'/gallery_filter.css'));
 365      preg_match_all('/div.giImageBlock.(\w+) {/', $css, $matches);
 366      if (count($matches[1])) {
 367        $classes = array();
 368        foreach ($matches[1] as $class) {
 369          $classes[$class] = $class;
 370        }
 371        $form['filter']['gallery_filter_default_div_class'] = array(
 372          '#type' => 'select',
 373          '#title' => t('Default class'),
 374          '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
 375          '#options' => $classes,
 376        );
 377      }
 378      else {
 379        $form['filter']['gallery_filter_default_div_class'] = array(
 380          '#type' => 'textfield',
 381          '#title' => t('Default class'),
 382          '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
 383          '#size' => 20,
 384          '#maxlength' => 20,
 385          '#description' => t('left, right, or nowrap. (See gallery_filter.css to add more or modify these.)'),
 386        );
 387      }
 388      
 389      $form['filter']['gallery_filter_default_maxsize'] = array(
 390        '#type' => 'textfield',
 391        '#title' => t('Default \'Max Size\' thumbnail size'),
 392        '#default_value' => variable_get('gallery_filter_default_maxsize', GALLERY_FILTER_MAXSIZE_DEFAULT),
 393        '#size' => 10,
 394        '#maxlength' => 10,
 395      );
 396      
 397      $form['filter']['gallery_filter_default_exactsize'] = array(
 398        '#type' => 'textfield',
 399        '#title' => t('Default \'Exact Size\' thumbnail size'),
 400        '#default_value' => variable_get('gallery_filter_default_exactsize', GALLERY_FILTER_EXACTSIZE_DEFAULT),
 401        '#size' => 10,
 402        '#maxlength' => 10,
 403        '#description' => t('If no size is specified when calling the filter, one of
 404          these sizes (and implied method) will be used. <br />\'Max Size\' gives faster
 405          image downloading, but the image size 
 406          may be smaller than the size defined. <br />\'Exact Size\' may be slower
 407          (as a larger image is downloaded and then scaled by the browser) but the image
 408          will be guaranteed to be the size defined. Only supported for G2.2+.
 409          Only fill in one size box (not both) to set the default method.'),
 410      );
 411      
 412      $form['filter']['gallery_filter_default_album_frame'] = array(
 413        '#type' => 'select',
 414        '#title' => t('Default album frame'),
 415        '#default_value' => variable_get('gallery_filter_default_album_frame', 'none'),
 416        '#options' => $image_frames,
 417        '#description' => $imageframe_desc,
 418      );
 419      
 420      $form['filter']['gallery_filter_default_item_frame'] = array(
 421        '#type' => 'select',
 422        '#title' => t('Default item frame'),
 423        '#default_value' => variable_get('gallery_filter_default_item_frame', 'none'),
 424        '#options' => $image_frames,
 425        '#description' => $imageframe_desc,
 426      );
 427      
 428      $form['filter']['gallery_filter_default_link_target'] = array(
 429        '#type' => 'textfield',
 430        '#title' => t('Default link target'),
 431        '#default_value' => variable_get('gallery_filter_default_link_target', ''),
 432        '#size' => 20,
 433        '#maxlength' => 20,
 434        '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
 435      );
 436      
 437      $form['filter']['gallery_filter_default_link'] = array(
 438        '#type' => 'textfield',
 439        '#title' => t('Default Image Link'),
 440        '#default_value' => variable_get('gallery_filter_default_link', ''),
 441        '#size' => 20,
 442        '#maxlength' => 20,
 443        '#description' => t('By default the image has a link to the item in the Gallery. This
 444          can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
 445          to link somewhere else instead.'),
 446      );
 447    }
 448    
 449    $form['array_filter'] = array('#type' => 'value');
 450    $form = system_settings_form($form);
 451    $form['#validate'] = array('_gallery_settings_filter_validate');
 452    $form['#submit'] = array('_gallery_settings_filter_submit', 'system_settings_form_submit');
 453    return $form;
 454  }
 455  
 456  /**
 457   * Function _gallery_settings_filter_validate().
 458   */
 459  function _gallery_settings_filter_validate($form, &$form_state) {
 460    // Only validate if a setting was returned
 461    if (isset($form_state['values']['gallery_filter_default_maxsize'])) {
 462      if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
 463        (strlen($form_state['values']['gallery_filter_default_exactsize']) > 0)) {
 464        form_set_error('gallery_filter_default_maxsize',
 465          t('You must set either the Max Size or the Exact Size, not both.'));  
 466      } 
 467      elseif ((strlen($form_state['values']['gallery_filter_default_maxsize']) == 0) &&
 468        (strlen($form_state['values']['gallery_filter_default_exactsize']) == 0)) {
 469        form_set_error('gallery_filter_default_maxsize',
 470          t('You must set either the Max Size or the Exact Size.'));  
 471      }
 472      if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
 473        (!is_numeric($form_state['values']['gallery_filter_default_maxsize']) ||
 474        $form_state['values']['gallery_filter_default_maxsize'] < 1)) {
 475        form_set_error('gallery_filter_default_maxsize',
 476          t('Max Size must be a number greater than zero.'));
 477      }
 478      if ((strlen($form_state['values']['gallery_filter_default_exactsize']) > 0) &&
 479        (!is_numeric($form_state['values']['gallery_filter_default_exactsize']) ||
 480        $form_state['values']['gallery_filter_default_exactsize'] < 1)) {
 481        form_set_error('gallery_filter_default_exactsize',
 482          t('Exact Size must be a number greater than zero.'));
 483      }
 484      if ((strlen($form_state['values']['gallery_filter_n_images']) > 0) &&
 485        (!is_numeric($form_state['values']['gallery_filter_n_images']) ||
 486        $form_state['values']['gallery_filter_n_images'] < 1)) {
 487        form_set_error('gallery_filter_n_images',
 488          t('Number of images must be a number greater than zero.'));
 489      }
 490    }
 491  }
 492  
 493  /**
 494   * Function _gallery_settings_filter_submit().
 495   */
 496  function _gallery_settings_filter_submit($form, &$form_state) {
 497    // The default values have changed, so the pages containing the gallery filter need
 498    // to be updated (or else it would only occur on an edit), so empty the filter cache.
 499    
 500    // Find out which formats are using the gallery filter
 501    $result = db_query("SELECT format FROM {filters} WHERE module = 'gallery'");
 502    while ($format = db_fetch_object($result)) {
 503      cache_clear_all($format->format .':', 'cache_filter', TRUE);
 504    }
 505    
 506    drupal_set_message('The gallery filter cache has been cleared so that the new defaults apply.');
 507  }
 508  
 509  /**
 510   * Function _gallery_settings_search().
 511   */
 512  function _gallery_settings_search() {
 513    require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
 514    $plugin_status =  gallery_plugin_status(array('imageblock', 'imageframe', 'search'));
 515  
 516    $search_desc = t('The Gallery Search requires the Gallery2 Search plugin (!search_status) and
 517      optionally the Gallery2 Image Block plugin (!imageblock_status) and Gallery2 Image Frame
 518      plugin (!imageframe_status).',
 519        array(
 520          '!search_status' => theme('gallery_plugin_status_message', $plugin_status['search']),
 521          '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
 522          '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
 523        )
 524      );
 525    $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
 526    $g2_plugins_page = (variable_get('gallery_valid', 0)) ? 
 527      t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
 528        array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
 529      : t('Gallery2 Site Admin -> Plugins');
 530    $thumbs_desc = '';
 531    if ($plugin_status['search'] != GALLERY_PLUGIN_ENABLED) {
 532      $search_desc .= t(' However the Search plugin is unavailable, so the search is
 533        not available and these settings are disabled. To use the search feature please go to
 534        the !g2_plugins page and install/activate the Image Block plugin.',
 535          array('!g2_plugins' => $g2_plugins_page));
 536    }   
 537    if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
 538      $thumbs_desc = t('To display search results with thumbnail images requires the Gallery2 Image
 539        Block plugin (!imageblock_status) and optionally the  and Gallery2 Image Frame 
 540        plugin (!imageframe_status).',
 541          array(
 542            '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
 543            '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
 544          )
 545        );
 546      $thumbs_desc .= t(' However the Image Block plugin is unavailable, so the thumbnails are
 547        not available and these settings are disabled. To use this feature please go to
 548        the !g2_plugins page and install/activate the Image Block plugin.',
 549          array('!g2_plugins' => $g2_plugins_page));
 550    }    
 551  
 552    $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
 553      t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
 554          array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
 555       
 556    $form['search'] = array(
 557      '#type' => 'fieldset',
 558      '#title' => t('Search settings'),
 559      '#collapsible' => FALSE,
 560      '#collapsed' => FALSE,
 561      '#description' => $search_desc,
 562    );
 563    
 564    $image_frames = gallery_list_image_frames();
 565    _gallery_block_options($type_map, $param_map);
 566    
 567    if ($plugin_status['search'] == GALLERY_PLUGIN_ENABLED) {
 568      $form['search']['gallery_search_advanced'] = array(
 569        '#type' => 'checkbox',
 570        '#title' => t('Display advanced search options'),
 571        '#default_value' => variable_get('gallery_search_advanced', 1),
 572        '#description' => t('Adds options to the search form to select which Gallery fields to search in.'),
 573      );
 574      
 575      $form['search']['gallery_search_num_per_row'] = array(
 576        '#type' => 'select',
 577        '#title' => t('Number of search results per table row'),
 578        '#default_value' => variable_get('gallery_search_num_per_row', 3),
 579        '#options' => _gallery_range_array(1, 5),
 580        '#description' => t('Select the number of search results per row in the paged table.'),
 581      );
 582      
 583      $form['search']['gallery_search_rows_per_pager'] = array(
 584        '#type' => 'select',
 585        '#title' => t('Number of rows per page'),
 586        '#default_value' => variable_get('gallery_search_rows_per_pager', 4),
 587        '#options' => _gallery_range_array(1, 10),
 588        '#description' => t('Select the number of rows in the paged table.'),
 589      );
 590      
 591      $form['search']['thumbs'] = array(
 592        '#type' => 'fieldset',
 593        '#title' => t('Search thumbnail settings'),
 594        '#collapsible' => TRUE,
 595        '#collapsed' => FALSE,
 596        '#description' => $thumbs_desc,
 597      );
 598      
 599      if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {          
 600        $form['search']['thumbs']['gallery_search_show_thumbs'] = array(
 601          '#type' => 'checkbox',
 602          '#title' => t('Display thumbnails'),
 603          '#default_value' => variable_get('gallery_search_show_thumbs', 1),
 604          '#description' => t('Display thumbnail images for the search results.'),
 605        );
 606        
 607        $form['search']['thumbs']['gallery_search_block_show'] = array(
 608          '#type' => 'checkboxes',
 609          '#title' => t('Image data'),
 610          '#default_value' => variable_get('gallery_search_block_show', array('title' => t('Title'))),
 611          '#options' => $param_map,
 612          '#description' => t('Choose the item metadata you would like to display.'),
 613          );
 614          
 615        $form['search']['thumbs']['gallery_search_size_method'] = array(
 616          '#type' => 'select',
 617          '#title' => t('Image size method'),
 618          '#default_value' => variable_get('gallery_search_size_method', GALLERY_SEARCH_SIZE_METHOD_DEFAULT),
 619          '#options' => array(
 620            'maxsize' => t('Max Size'),
 621            'exactsize' => t('Exact Size'),
 622          ),
 623          '#description' => t('\'Max Size\' gives faster image downloading, but the image size 
 624            may be smaller than the size defined below. <br />\'Exact Size\' may be slower
 625            (as a larger image is downloaded and then scaled by the browser) but the image
 626            will be guaranteed to be the size defined below. Only supported for G2.2+.'),
 627        );  
 628      
 629        $form['search']['thumbs']['gallery_search_size'] = array(
 630          '#type' => 'textfield',
 631          '#title' => t('Image size'),
 632          '#default_value' => variable_get('gallery_search_size', GALLERY_SEARCH_SIZE_DEFAULT),
 633          '#size' => 10,
 634          '#maxlength' => 10,
 635          '#description' => t('Sets the size (in pixels) of the longest side of the image
 636            according to the method defined above.'),
 637        );
 638         
 639        $form['search']['thumbs']['gallery_search_album_frame'] = array(
 640          '#type' => 'select',
 641          '#title' => t('Album frame'),
 642          '#default_value' => variable_get('gallery_search_album_frame', 'none'),
 643          '#options' => $image_frames,
 644          '#description' => $imageframe_desc,
 645        );
 646        
 647        $form['search']['thumbs']['gallery_search_item_frame'] = array(
 648          '#type' => 'select',
 649          '#title' => t('Item frame'),
 650          '#default_value' => variable_get('gallery_search_item_frame', 'none'),
 651          '#options' => $image_frames,
 652          '#description' => $imageframe_desc,
 653        );
 654        
 655        $form['search']['thumbs']['gallery_search_link_target'] = array(
 656          '#type' => 'textfield',
 657          '#title' => t('Link target'),
 658          '#default_value' => variable_get('gallery_search_link_target', ''),
 659          '#size' => 20,
 660          '#maxlength' => 20,
 661          '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
 662        );
 663        
 664        $form['search']['thumbs']['gallery_search_default_link'] = array(
 665          '#type' => 'textfield',
 666          '#title' => t('Image Link'),
 667          '#default_value' => variable_get('gallery_search_default_link', ''),
 668          '#size' => 20,
 669          '#maxlength' => 20,
 670          '#description' => t('By default the image has a link to the item in the Gallery. This
 671            can be overridden here (or leave empty for the default). Use \'none\' for no link, or a
 672            URL to link somewhere else instead.'),
 673        );
 674      }
 675    }
 676    
 677    $form['array_filter'] = array('#type' => 'value');
 678    $form['#validate'] = array('_gallery_settings_search_validate');
 679    return system_settings_form($form);
 680  }
 681  
 682  /**
 683   * Function _gallery_settings_search_validate().
 684   */
 685  function _gallery_settings_search_validate($form, &$form_state) {
 686    if (isset($form_state['values']['gallery_search_size']) &&
 687      (!is_numeric($form_state['values']['gallery_search_size']) || $form_state['values']['gallery_search_size'] < 1)) {
 688      form_set_error('gallery_search_size',
 689        t('Image size must be a number greater than zero.'));
 690    }
 691  }
 692  
 693  /**
 694   * Function _gallery_settings_album_select().
 695   */
 696  function _gallery_settings_album_select($title, $value, $description, $root = NULL, $depth = 1, $uid = NULL) {
 697    $options = array();
 698    $tree = gallery_album_tree($root, $depth, $uid);
 699    _gallery_settings_album_traverse($tree, $options);
 700  
 701    return array(
 702      '#type' => 'select',
 703      '#title' => $title,
 704      '#default_value' => $value,
 705      '#options' => array('default' => t('Default')) + $options,
 706      '#description' => $description
 707    );
 708  }
 709  
 710  /**
 711   * Function _gallery_settings_album_traverse().
 712   */
 713  function _gallery_settings_album_traverse(&$tree, &$items, $indent = '') {
 714    foreach (array_keys($tree) as $id) {
 715      $album = gallery_item_details($id);
 716      $items[$id] = (empty($indent) ? '' : $indent .' ') . $album['title'];
 717      if (count($tree[$id])) {
 718        _gallery_settings_album_traverse($tree[$id], $items, $indent .'--');
 719      }
 720    }
 721  }
 722  
 723  /**
 724   * Function _gallery_range_array().
 725   * (create an associative range array
 726   *  like array($min=>$min, ..., $max=>$max))
 727   */
 728  function _gallery_range_array($min, $max, $interval = 1) {
 729    $range_array = array();
 730    for ($i=$min; $i<=$max; $i+=$interval) {
 731      $range_array[$i] = $i;
 732    }
 733  
 734    return $range_array;
 735  }
 736  
 737  /**
 738   * Function _gallery_php_memcheck().
 739   * (check the amount of PHP memory)
 740   */
 741  function _gallery_php_memcheck($min_memory = 24) {
 742    $mem_limit = trim(ini_get('memory_limit'));
 743    $mem_limit_bytes = parse_size($mem_limit);
 744    
 745    if (empty($mem_limit)) {
 746      return array(
 747        'status' => TRUE,
 748        'info' => t('There is no memory limit restricting your PHP installation.'),
 749      );
 750    }
 751    elseif (($mem_limit_bytes / (1024 * 1024)) < $min_memory) {
 752      return array(
 753        'status' => FALSE,
 754        'info' => t('Your PHP is configured to limit the memory to @mem_limit
 755          (memory_limit parameter in php.ini). You must raise this limit 
 756          to at least @min_mem_limitM for proper embedded Gallery2 operation.',
 757          array(
 758            '@mem_limit' => $mem_limit, 
 759            '@min_mem_limit' => $min_memory,
 760          )
 761        )
 762      );
 763    } 
 764    else {
 765      return array(
 766        'status' => TRUE,
 767        'info' => t('Your PHP is configured to limit the memory to @mem_limit
 768          (memory_limit parameter in php.ini). This should be fine for embedded Gallery2 operation.',
 769          array(
 770            '@mem_limit' => $mem_limit, 
 771          )
 772        )
 773      );
 774    }
 775  }
 776  
 777  /**
 778   * Implementation of hook_gallery_plugin_info().
 779   */
 780  function gallery_gallery_plugin_info($type) {
 781    switch ($type) {
 782      case GALLERY_PLUGIN_WANTED:
 783        return array(
 784          'imageblock' => array(
 785            'title' => 'Image Block',
 786            'info' => t('Allows images to be included in the Drupal sidebar or in nodes.'),
 787            'severity' => GALLERY_SEVERITY_ERROR,
 788            'status' => gallery_single_plugin_status('imageblock'),
 789          ),
 790          'imageframe' => array(
 791            'title' => 'ImageFrame',
 792            'info' => t('Provides a variety of frames around the images.'),
 793            'severity' => GALLERY_SEVERITY_WARNING,
 794            'status' => gallery_single_plugin_status('imageframe'),
 795          ),
 796          'search' => array(
 797            'title' => 'Search',
 798            'info' => t('Allow the Drupal search to also search the Gallery.'),
 799            'severity' => GALLERY_SEVERITY_WARNING,
 800            'status' => gallery_single_plugin_status('search'),
 801          ),
 802          'rewrite' => array(
 803            'title' => 'URL Rewrite',
 804            'info' => t('Allow short URLs (clean URLs).'),
 805            'severity' => GALLERY_SEVERITY_ADVISE,
 806            'status' => gallery_single_plugin_status('rewrite'),
 807          ),
 808        );
 809      case GALLERY_PLUGIN_UNWANTED:
 810        return array(
 811          'register' => array(
 812            'title' => 'Registration',
 813            'info' => t('All user registration must take place via Drupal to ensure that the users
 814              are synchronized between Drupal and Gallery2. This plugin would allow a user to register
 815              only in Gallery2 and not in Drupal and so should not be used.'),
 816            'severity' => GALLERY_SEVERITY_WARNING,
 817            'status' => gallery_single_plugin_status('register'),
 818          ),
 819        );
 820      case GALLERY_PLUGIN_DRUPAL:
 821        return array(
 822          'xmlsitemap' => array(
 823            'title' => 'XML Sitemap',
 824            'status' => module_exists('xmlsitemap'),
 825            'severity' => GALLERY_SEVERITY_ADVISE,
 826            'info' => t('Enables the Drupal and Gallery2 sitemaps to be merged which allows for
 827                         a single sitemap to be sent to Google and other web search sites.'),
 828          ),
 829          'profile' => array(
 830            'title' => 'Profile',
 831            'status' => module_exists('profile'),
 832            'severity' => GALLERY_SEVERITY_ADVISE,
 833            'info' => t('Allows support of the \'Full Name\' field in Gallery2.'),
 834          ),
 835        );
 836      default:
 837        return array();
 838    }
 839  }
 840  
 841  /**
 842   * Function gallery_plugin_set_status().
 843   */
 844  function gallery_plugin_set_status($plugin_names) {
 845    $plugins_status = gallery_plugin_status($plugin_names);
 846    $plugin_info = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED);
 847    // Generate array containing module status
 848    $status = array();
 849    foreach ($plugins_status as $plugin => $plugin_status) {
 850      if ($plugin_status == GALLERY_PLUGIN_ENABLED) {
 851        $status[$plugin] = '';
 852      }
 853      else {
 854        $status[$plugin]['title'] = t('Gallery2 plugin \'@plugin\' is not available',
 855          array('@plugin' => isset($plugin_info[$plugin]) ? $plugin_info[$plugin]['title'] : drupal_ucfirst($plugin)));
 856        $status[$plugin]['severity'] = isset($plugin_info[$plugin]['severity']) ? $plugin_info[$plugin]['severity'] : GALLERY_SEVERITY_WARNING;
 857        $status[$plugin]['url'] = url('admin/settings/gallery/install', array('fragment' => 'gallery-install-plugin-'. $plugin));
 858      }
 859    }
 860    gallery_set_status($status);
 861  }
 862  
 863  /**
 864   * Function gallery_format_status().
 865   */
 866  function gallery_format_status($status = array(), $title = 'Gallery message(s):') {
 867    $message = $title .'<ul>';
 868    if (count($status)) {
 869      foreach ($status as $item) {
 870        $message .= '<li>';
 871        if (isset($item['title'])) {
 872          $message .= empty($item['url']) ? t($item['title']) : '<a href="'. $item['url'] .'">'. t($item['title']) .'</a>';
 873          $message .= ': ';
 874        }
 875        $message .= (isset($item['info']) && !empty($item['info'])) ? t($item['info']) : '';
 876        $message .= isset($item['severity'])  ? (' ['. theme('gallery_severity_message', $item['severity']) .']') : '';
 877        $message .= '</li>';
 878      }
 879    }
 880    else {
 881      $message = t('Status not available');
 882    }
 883    $message .= '</ul>';
 884    
 885    return $message;
 886  }
 887  
 888  /**
 889   * Theme function : theme_gallery_module_status_message().
 890   */
 891  function theme_gallery_module_status_message($status) {
 892    if ($status) {
 893      return '<span class="admin-enabled">'. t('enabled') .'</span>';
 894    } 
 895    else {
 896      return '<span class="admin-disabled">'. t('disabled') .'</span>';
 897    }
 898  }
 899  
 900  /**
 901   * Theme function : theme_gallery_severity_message().
 902   */
 903  function theme_gallery_severity_message($severity = NULL) {
 904    switch ($severity) {
 905      case GALLERY_SEVERITY_SUCCESS:
 906        return '<span class=\'g2_embed_success\'>'. t('OK') .'</span>';
 907      case GALLERY_SEVERITY_ERROR:
 908        return '<span class=\'g2_embed_error\'>'. t('Error') .'</span>';
 909      case GALLERY_SEVERITY_WARNING:
 910        return '<span class=\'g2_embed_warning\'>'. t('Warning') .'</span>';
 911      case GALLERY_SEVERITY_ADVISE:
 912        return '<span class=\'g2_embed_warning\'>'. t('Advisory') .'</span>';
 913      case GALLERY_SEVERITY_UNKNOWN:
 914        return '<span class=\'g2_embed_warning\'>'. t('Unknown') .'</span>';
 915      default:
 916    }      
 917  }
 918  
 919  /**
 920   * Theme function : theme_gallery_plugin_status_message().
 921   */
 922  function theme_gallery_plugin_status_message($status, $invert = FALSE) {
 923    $classes = array('enabled' => 'admin-enabled', 'disabled' => 'admin-disabled');
 924    if ($invert) {
 925      $classes = array_reverse($classes, TRUE);
 926    }
 927  
 928    switch ($status) {
 929      case GALLERY_PLUGIN_ENABLED:
 930        return '<span class="'. $classes['enabled'] .'">'. t('activated') .'</span>';
 931      case GALLERY_PLUGIN_DISABLED:
 932        return '<span class="'. $classes['disabled'] .'">'. t('disabled') .'</span>';
 933      case GALLERY_PLUGIN_NOT_ACTIVE:
 934        return '<span class="'. $classes['disabled'] .'">'. t('deactivated') .'</span>';
 935      case GALLERY_PLUGIN_NOT_INSTALLED:
 936        return '<span class="'. $classes['disabled'] .'">'. t('not installed') .'</span>';
 937      case GALLERY_PLUGIN_MISSING:
 938        return '<span class="'. $classes['disabled'] .'">'. t('missing') .'</span>';
 939      case GALLERY_PLUGIN_STATUS_UNKNOWN:
 940      default:
 941        return '<span class="'. $classes['disabled'] .'">'. t('unknown') .'</span>';
 942    }    
 943  }
 944  
 945  /**
 946   * Theme function : theme_gallery_severity_status_message().
 947   */
 948  function theme_gallery_severity_status_message($severity, $status, $full_msg = FALSE, $invert = FALSE) {
 949    // In some cases (e.g. unwanted plugins) it makes sense to return the full 2 part message
 950    // even on a success, but in most cases a simple "OK" is sufficient.
 951    if ($full_msg) {
 952      return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
 953    }    
 954    switch ($severity) {
 955      case GALLERY_SEVERITY_SUCCESS:
 956        return theme('gallery_severity_message', $severity);
 957      default:
 958        return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
 959    }      
 960  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7