gallery_settings.inc 39.8 KB
Newer Older
1 2 3 4 5 6 7
<?php
// $Id$

/**
 * gallery.module : gallery_settings.inc
 * Settings functions
 */
8

9
/**
10
 * Function _gallery_settings_general().
11
 */
12 13 14 15 16
function _gallery_settings_general() {
  // Short Status
  gallery_version();
  gallery_plugin_set_status(array('imageblock', 'imageframe', 'search'));
  $status = gallery_get_status();
17
  
18 19 20 21 22 23
  $form['status'] = array(
    '#type' => 'fieldset',
    '#title' => t('Status'),
    '#description' => gallery_format_status($status, ''),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
24
  );
25 26 27
  
  // Theme Settings
  $form['theme'] = array(
28
    '#type' => 'fieldset',
29
    '#title' => t('Theme and Display settings'),
30
    '#description' => '',
31
    '#collapsible' => TRUE,
32 33
    '#collapsed' => TRUE,
  );
34 35 36 37
  $themes = system_theme_data();
  ksort($themes);
  $options = array('default' => t('System default'));
  foreach ($themes as $theme) {
38
    $options[$theme->name] = $theme->info['name'];
39 40 41 42 43 44 45
  }
  $form['theme']['gallery_page_theme'] = array(
    '#type' => 'select',
    '#title' => t('Gallery page theme'),
    '#default_value' => variable_get('gallery_page_theme', 'default'),
    '#options' => $options,
    '#description' => t('Drupal theme to be used for all gallery pages (gallery/*).'),
46
  );
47 48 49 50 51 52 53 54 55 56 57 58 59
  $form['theme']['gallery_embed_theme'] = array(
    '#type' => 'select',
    '#title' => t('Gallery embedded theme'),
    '#default_value' => variable_get('gallery_embed_theme', 'default'),
    '#options' => array('default' => t('Gallery default')) + gallery_get_themes(),
    '#description' => t('Gallery2 theme to be used for embedded gallery.'),
  );
  $form['theme']['gallery_root_album'] = _gallery_settings_album_select(
    t('Default root album'),
    variable_get('gallery_root_album', 'default'),
    t('Default root album to use on gallery pages. If you have a separate album for use with nodes (Filter, G2Image, ...)
       it can be helpful to move the root album to hide that album from the browseable gallery.')
  );
60 61 62
  
  // Gallery Block Settings
  $form['blocks'] = array(
63
    '#type' => 'fieldset',
64 65
    '#title' => t('Gallery block settings'),
    '#collapsible' => TRUE,
66
    '#collapsed' => TRUE,
67 68 69
    '#description' => t('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>'),
kiz_0987's avatar
kiz_0987 committed
70
  );
71
  $form['blocks']['gallery_block_num'] = array(
kiz_0987's avatar
kiz_0987 committed
72
    '#type' => 'textfield',
73 74
    '#title' => t('Number of blocks'),
    '#default_value' => variable_get('gallery_block_num', 2),
kiz_0987's avatar
kiz_0987 committed
75 76
    '#size' => 10,
    '#maxlength' => 10,
77
    '#description' => t('Select how many blocks should be available.'),
kiz_0987's avatar
kiz_0987 committed
78
  );
79 80 81
  
  // Gallery2 Sidebar Settings
  $form['sidebar'] = array(
82
    '#type' => 'fieldset',
83
    '#title' => t('Sidebar settings'),
84
    '#description' => '',
85
    '#collapsible' => TRUE,
86 87
    '#collapsed' => TRUE,
  );
88
  $form['sidebar']['gallery_move_sidebar_to_block'] = array(
89
    '#type' => 'checkbox',
90 91 92 93 94 95 96
    '#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.'),
97
  );
98 99 100 101 102 103 104 105 106 107
  $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),
108
  );
109
  
110 111 112
  // Gallery2 Google Sitemap Settings
  $gallery2_sitemap_status = gallery_single_plugin_status('sitemap');
  $gallery2_sitemap_status_str = theme('gallery_plugin_status_message', $gallery2_sitemap_status);
113 114 115
  $xmlsitemap_status = module_exists('xmlsitemap');
  $xmlsitemap_status_str = theme('gallery_module_status_message', $xmlsitemap_status);
  $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 123
      '!gallery2_sitemap_status' => $gallery2_sitemap_status_str,
    )
124
  );
125
  
126 127
  $form['sitemap'] = array(
    '#type' => 'fieldset',
128
    '#title' => t('XML Sitemap settings'),
129 130 131 132
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => $desc,
133
  );
134 135 136
  $form['sitemap']['gallery_enable_sitemap'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable merge of Gallery2 sitemap with Drupal sitemap'),
137 138
    '#default_value' => $xmlsitemap_available ? variable_get('gallery_enable_sitemap', 1) : FALSE,
    '#disabled' => !$xmlsitemap_available,
139
  );
140
  
141 142
  // Error logging / Debug Settings
  $form['error'] = array(
143
    '#type' => 'fieldset',
144
    '#title' => t('Error logging / Debug settings'),
145
    '#description' => '',
146
    '#collapsible' => TRUE,
147 148
    '#collapsed' => TRUE,
  );
149 150 151 152 153 154 155 156
  $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.'),
157
  );
158 159 160 161 162 163 164
  $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.')
165
  );
166 167
  $search_status = module_exists('search') && (gallery_single_plugin_status('search') == GALLERY_PLUGIN_ENABLED);
  $form['error']['gallery_error_redirect'] = array(
168
    '#type' => 'checkbox',
169 170
    '#title' => t('Redirect to Gallery search form for invalid paths'),
    '#default_value' => $search_status ? variable_get('gallery_error_redirect', 0) : 0,
171 172
    '#description' => t('Instead of showing a message that the requested Gallery URL does not exist the
                         user is redirected to the search form.'),
173
    '#disabled' => !$search_status,
174
  );
175 176 177 178 179 180 181
  $form['error']['debug'] = array(
    '#type' => 'fieldset',
    '#title' => t('Debug settings'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
182
  $debug = variable_get('gallery_debug', 0);
183
  $form['error']['debug']['gallery_debug'] = array(
184 185
    '#type' => 'checkbox',
    '#title' => t('Enable debug mode'),
186
    '#default_value' => $debug,
187 188
    '#description' => t('Print out debug variables and verbose error messages. Only visible to users
                         with \'administer site configuration\' permission.')
189
  );
190 191 192
  $form['error']['debug']['gallery_g2debug'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable G2 debug output'),
193 194 195
    '#default_value' => $debug && variable_get('gallery_g2debug', 0),
    '#description' => t('Enables Gallery2\'s buffered debug output to be displayed.'),
    '#disabled' => !$debug
196
  );
197
  
198 199
  // Relevant links
  $form['links'] = array(
200
    '#type' => 'fieldset',
201 202
    '#title' => t('Links to the most relevant Drupal & Gallery2 pages'),
    '#collapsible' => TRUE,
203
    '#collapsed' => TRUE,
kiz_0987's avatar
kiz_0987 committed
204
  );
205 206 207
  // Drupal links
  $desc  = '<ul>';
  $desc .= '<li><a href="@gallery-users">Gallery users</a> : Gallery2 user integration and synchronization.</li>';
208 209
  $desc .= '<li><a href="@gallery-report">Report Generator</a> : Collect information about your installation. Useful
            especially for bug reports.</li>';
210 211 212 213 214 215 216 217 218
  $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,
219
  );
220 221
  // Gallery2 links
  $desc  = '<ul>';
222 223
  $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>';
224
  $desc .= '<li><a href="@g2-themes">Themes</a> : To add/remove blocks in the sidebar.</li>';
225 226 227
  if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) {
    $desc .= '<li><a href="@g2-rewrite">Embedded URL Rewrite settings</a> : To define the rewrite rules.</li>';
  }
228 229
  $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>';
230 231 232 233 234 235 236 237 238 239 240 241
  $desc .= '</ul>';
  $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,
242 243
  );
  
244 245 246 247
  $form = system_settings_form($form);
  $form['#validate'] = array('_gallery_settings_general_validate');
  $form['#submit'] = array('_gallery_settings_general_submit', 'system_settings_form_submit');
  return $form;
248
}
249

250 251 252
/**
 * Function _gallery_settings_general_validate().
 */
253
function _gallery_settings_general_validate($form, &$form_state) {
254 255
  if (!is_numeric($form_state['values']['gallery_block_num']) || $form_state['values']['gallery_block_num'] < 1) {
    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 263
function _gallery_settings_general_submit($form, &$form_state) {
  if ($form_state['values']['gallery_enable_sitemap'] != variable_get('gallery_enable_sitemap', 0)) {
264 265
    drupal_set_message('The XML sitemap setting has been updated, but the new sitemap may not be generated
                        immediately (controlled by XML Sitemap).');
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
  }
}

/**
 * Function _gallery_settings_filter().
 */
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']))) : '';
299

300 301 302 303 304 305 306 307 308 309
  $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);
310
  $type_map['specificItem'] = t('Specific item');
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
  
  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')),
      '#options' => $param_map,
359 360
      '#description' => t('Choose the item metadata you would like to display by default.
                           This will change all instances where show parameter was not specified.'),
361 362
    );
    
363
    // Parse gallery_filter.css and extract classes
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
    $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.'),
    );
  }
  
449
  $form['array_filter'] = array('#type' => 'value');
450 451 452 453
  $form = system_settings_form($form);
  $form['#validate'] = array('_gallery_settings_filter_validate');
  $form['#submit'] = array('_gallery_settings_filter_submit', 'system_settings_form_submit');
  return $form;
454
}
455

456 457 458
/**
 * Function _gallery_settings_filter_validate().
 */
459
function _gallery_settings_filter_validate($form, &$form_state) {
460
  // Only validate if a setting was returned
461 462 463
  if (isset($form_state['values']['gallery_filter_default_maxsize'])) {
    if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
      (strlen($form_state['values']['gallery_filter_default_exactsize']) > 0)) {
464 465 466
      form_set_error('gallery_filter_default_maxsize',
        t('You must set either the Max Size or the Exact Size, not both.'));  
    } 
467 468
    elseif ((strlen($form_state['values']['gallery_filter_default_maxsize']) == 0) &&
      (strlen($form_state['values']['gallery_filter_default_exactsize']) == 0)) {
469 470 471
      form_set_error('gallery_filter_default_maxsize',
        t('You must set either the Max Size or the Exact Size.'));  
    }
472 473 474
    if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
      (!is_numeric($form_state['values']['gallery_filter_default_maxsize']) ||
      $form_state['values']['gallery_filter_default_maxsize'] < 1)) {
475 476 477
      form_set_error('gallery_filter_default_maxsize',
        t('Max Size must be a number greater than zero.'));
    }
478 479 480
    if ((strlen($form_state['values']['gallery_filter_default_exactsize']) > 0) &&
      (!is_numeric($form_state['values']['gallery_filter_default_exactsize']) ||
      $form_state['values']['gallery_filter_default_exactsize'] < 1)) {
481 482 483
      form_set_error('gallery_filter_default_exactsize',
        t('Exact Size must be a number greater than zero.'));
    }
484 485 486
    if ((strlen($form_state['values']['gallery_filter_n_images']) > 0) &&
      (!is_numeric($form_state['values']['gallery_filter_n_images']) ||
      $form_state['values']['gallery_filter_n_images'] < 1)) {
487 488 489 490 491
      form_set_error('gallery_filter_n_images',
        t('Number of images must be a number greater than zero.'));
    }
  }
}
492

493 494 495
/**
 * Function _gallery_settings_filter_submit().
 */
496
function _gallery_settings_filter_submit($form, &$form_state) {
497 498 499 500 501 502 503 504 505 506
  // 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.');
507 508
}

509 510 511 512 513 514 515 516
/**
 * Function _gallery_settings_search().
 */
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
517
    optionally the Gallery2 Image Block plugin (!imageblock_status) and Gallery2 Image Frame
518 519
    plugin (!imageframe_status).',
      array(
520
        '!search_status' => theme('gallery_plugin_status_message', $plugin_status['search']),
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
        '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 
        '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
      )
    );
  $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');
  $thumbs_desc = '';
  if ($plugin_status['search'] != GALLERY_PLUGIN_ENABLED) {
    $search_desc .= t(' However the Search plugin is unavailable, so the search is
      not available and these settings are disabled. To use the search feature please go to
      the !g2_plugins page and install/activate the Image Block plugin.',
        array('!g2_plugins' => $g2_plugins_page));
  }   
  if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
    $thumbs_desc = t('To display search results with thumbnail images requires the Gallery2 Image
      Block plugin (!imageblock_status) and optionally the  and 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']),
        )
      );
    $thumbs_desc .= t(' However the Image Block plugin is unavailable, so the thumbnails are
      not available and these settings are disabled. To use this feature 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['search'] = array(
    '#type' => 'fieldset',
    '#title' => t('Search settings'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#description' => $search_desc,
  );
  
  $image_frames = gallery_get_image_frames();
  _gallery_block_options($type_map, $param_map);
  
567
  if ($plugin_status['search'] == GALLERY_PLUGIN_ENABLED) {
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
    $form['search']['gallery_search_advanced'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display advanced search options'),
      '#default_value' => variable_get('gallery_search_advanced', 1),
      '#description' => t('Adds options to the search form to select which Gallery fields to search in.'),
    );
    
    $form['search']['gallery_search_num_per_row'] = array(
      '#type' => 'select',
      '#title' => t('Number of search results per table row'),
      '#default_value' => variable_get('gallery_search_num_per_row', 3),
      '#options' => _gallery_range_array(1, 5),
      '#description' => t('Select the number of search results per row in the paged table.'),
    );
    
    $form['search']['gallery_search_rows_per_pager'] = array(
      '#type' => 'select',
      '#title' => t('Number of rows per page'),
      '#default_value' => variable_get('gallery_search_rows_per_pager', 4),
      '#options' => _gallery_range_array(1, 10),
      '#description' => t('Select the number of rows in the paged table.'),
    );
    
    $form['search']['thumbs'] = array(
      '#type' => 'fieldset',
      '#title' => t('Search thumbnail settings'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => $thumbs_desc,
    );
    
    if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {          
      $form['search']['thumbs']['gallery_search_show_thumbs'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display thumbnails'),
        '#default_value' => variable_get('gallery_search_show_thumbs', 1),
        '#description' => t('Display thumbnail images for the search results.'),
      );
      
      $form['search']['thumbs']['gallery_search_block_show'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Image data'),
        '#default_value' => variable_get('gallery_search_block_show', array('title' => t('Title'))),
        '#options' => $param_map,
        '#description' => t('Choose the item metadata you would like to display.'),
        );
        
      $form['search']['thumbs']['gallery_search_size_method'] = array(
        '#type' => 'select',
        '#title' => t('Image size method'),
        '#default_value' => variable_get('gallery_search_size_method', GALLERY_SEARCH_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['search']['thumbs']['gallery_search_size'] = array(
        '#type' => 'textfield',
        '#title' => t('Image size'),
        '#default_value' => variable_get('gallery_search_size', GALLERY_SEARCH_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['search']['thumbs']['gallery_search_album_frame'] = array(
        '#type' => 'select',
        '#title' => t('Album frame'),
        '#default_value' => variable_get('gallery_search_album_frame', 'none'),
        '#options' => $image_frames,
        '#description' => $imageframe_desc,
      );
      
      $form['search']['thumbs']['gallery_search_item_frame'] = array(
        '#type' => 'select',
        '#title' => t('Item frame'),
        '#default_value' => variable_get('gallery_search_item_frame', 'none'),
        '#options' => $image_frames,
        '#description' => $imageframe_desc,
      );
      
      $form['search']['thumbs']['gallery_search_link_target'] = array(
        '#type' => 'textfield',
        '#title' => t('Link target'),
        '#default_value' => variable_get('gallery_search_link_target', ''),
        '#size' => 20,
        '#maxlength' => 20,
        '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
      );
      
      $form['search']['thumbs']['gallery_search_default_link'] = array(
        '#type' => 'textfield',
        '#title' => t('Image Link'),
        '#default_value' => variable_get('gallery_search_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.'),
      );
    }
  }
  
677
  $form['array_filter'] = array('#type' => 'value');
678
  $form['#validate'] = array('_gallery_settings_search_validate');
679 680 681 682 683 684
  return system_settings_form($form);
}

/**
 * Function _gallery_settings_search_validate().
 */
685 686 687
function _gallery_settings_search_validate($form, &$form_state) {
  if (isset($form_state['values']['gallery_search_size']) &&
    (!is_numeric($form_state['values']['gallery_search_size']) || $form_state['values']['gallery_search_size'] < 1)) {
688 689 690 691 692
    form_set_error('gallery_search_size',
      t('Image size must be a number greater than zero.'));
  }
}

693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
/**
 * Function _gallery_settings_album_select().
 */
function _gallery_settings_album_select($title, $value, $description, $root = NULL, $depth = 1, $uid = NULL) {
  $options = array();
  $tree = gallery_album_tree($root, $depth, $uid);
  _gallery_settings_album_traverse($tree, $options);

  return array(
    '#type' => 'select',
    '#title' => $title,
    '#default_value' => $value,
    '#options' => array('default' => t('Default')) + $options,
    '#description' => $description
  );
}

/**
 * Function _gallery_settings_album_traverse().
 */
function _gallery_settings_album_traverse(&$tree, &$items) {
  foreach (array_keys($tree) as $id) {
    $album = gallery_item_details($id);
    $items[$id] = $album['title'];
    if (count($tree[$id])) {
      _gallery_settings_album_traverse($tree[$id], $items);
    }
  }
}

723 724 725 726 727 728 729 730
/**
 * Function _gallery_range_array().
 * (create an associative range array
 *  like array($min=>$min, ..., $max=>$max))
 */
function _gallery_range_array($min, $max, $interval = 1) {
  $range_array = array();
  for ($i=$min; $i<=$max; $i+=$interval) {
731
    $range_array[$i] = $i;
732
  }
733

734 735 736 737
  return $range_array;
}

/**
738
 * Function _gallery_php_memcheck().
739 740
 * (check the amount of PHP memory)
 */
741
function _gallery_php_memcheck($min_memory = 24) {
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
  $mem_limit = trim(ini_get('memory_limit'));
  $mem_limit_bytes = parse_size($mem_limit);
  
  if (empty($mem_limit)) {
    return array(
      'status' => TRUE,
      'info' => t('There is no memory limit restricting your PHP installation.'),
    );
  }
  elseif (($mem_limit_bytes / (1024 * 1024)) < $min_memory) {
    return array(
      'status' => FALSE,
      'info' => t('Your PHP is configured to limit the memory to @mem_limit
        (memory_limit parameter in php.ini). You must raise this limit 
        to at least @min_mem_limitM for proper embedded Gallery2 operation.',
        array(
          '@mem_limit' => $mem_limit, 
          '@min_mem_limit' => $min_memory,
        )
      )
    );
  } 
  else {
    return array(
      'status' => TRUE,
      'info' => t('Your PHP is configured to limit the memory to @mem_limit
        (memory_limit parameter in php.ini). This should be fine for embedded Gallery2 operation.',
        array(
          '@mem_limit' => $mem_limit, 
        )
      )
    );
  }
}

/**
778
 * Implementation of hook_gallery_plugin_info().
779
 */
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
function gallery_gallery_plugin_info($type) {
  switch ($type) {
    case GALLERY_PLUGIN_WANTED:
      return array(
        'imageblock' => array(
          'title' => 'Image Block',
          'info' => t('Allows images to be included in the Drupal sidebar or in nodes.'),
          'severity' => GALLERY_SEVERITY_ERROR,
          'status' => gallery_single_plugin_status('imageblock'),
        ),
        'imageframe' => array(
          'title' => 'ImageFrame',
          'info' => t('Provides a variety of frames around the images.'),
          'severity' => GALLERY_SEVERITY_WARNING,
          'status' => gallery_single_plugin_status('imageframe'),
        ),
        'search' => array(
          'title' => 'Search',
          'info' => t('Allow the Drupal search to also search the Gallery.'),
          'severity' => GALLERY_SEVERITY_WARNING,
          'status' => gallery_single_plugin_status('search'),
        ),
        'rewrite' => array(
          'title' => 'URL Rewrite',
          'info' => t('Allow short URLs (clean URLs).'),
          'severity' => GALLERY_SEVERITY_ADVISE,
          'status' => gallery_single_plugin_status('rewrite'),
        ),
      );
    case GALLERY_PLUGIN_UNWANTED:
      return array(
        'register' => array(
          'title' => 'Registration',
          'info' => t('All user registration must take place via Drupal to ensure that the users
            are synchronized between Drupal and Gallery2. This plugin would allow a user to register
            only in Gallery2 and not in Drupal and so should not be used.'),
          'severity' => GALLERY_SEVERITY_WARNING,
          'status' => gallery_single_plugin_status('register'),
        ),
      );
    case GALLERY_PLUGIN_DRUPAL:
      return array(
822 823 824
        'xmlsitemap' => array(
          'title' => 'XML Sitemap',
          'status' => module_exists('xmlsitemap'),
825
          'severity' => GALLERY_SEVERITY_ADVISE,
826 827
          'info' => t('Enables the Drupal and Gallery2 sitemaps to be merged which allows for
                       a single sitemap to be sent to Google and other web search sites.'),
828 829 830 831 832 833 834 835 836 837 838
        ),
        'profile' => array(
          'title' => 'Profile',
          'status' => module_exists('profile'),
          'severity' => GALLERY_SEVERITY_ADVISE,
          'info' => t('Allows support of the \'Full Name\' field in Gallery2.'),
        ),
      );
    default:
      return array();
  }
839 840 841 842 843 844 845
}

/**
 * Function gallery_plugin_set_status().
 */
function gallery_plugin_set_status($plugin_names) {
  $plugins_status = gallery_plugin_status($plugin_names);
846
  $plugin_info = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED);
847 848 849 850 851 852 853 854 855 856
  // Generate array containing module status
  $status = array();
  foreach ($plugins_status as $plugin => $plugin_status) {
    if ($plugin_status == GALLERY_PLUGIN_ENABLED) {
      $status[$plugin] = '';
    }
    else {
      $status[$plugin]['title'] = t('Gallery2 plugin \'@plugin\' is not available',
        array('@plugin' => isset($plugin_info[$plugin]) ? $plugin_info[$plugin]['title'] : drupal_ucfirst($plugin)));
      $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 861 862 863 864 865 866 867 868 869 870
    }
  }
  gallery_set_status($status);
}

/**
 * Function gallery_format_status().
 */
function gallery_format_status($status = array(), $title = 'Gallery message(s):') {
  $message = $title .'<ul>';
  if (count($status)) {
    foreach ($status as $item) {
      $message .= '<li>';
871 872 873 874 875
      if (isset($item['title'])) {
        $message .= empty($item['url']) ? t($item['title']) : '<a href="'. $item['url'] .'">'. t($item['title']) .'</a>';
        $message .= ': ';
      }
      $message .= (isset($item['info']) && !empty($item['info'])) ? t($item['info']) : '';
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
      $message .= isset($item['severity'])  ? (' ['. theme('gallery_severity_message', $item['severity']) .']') : '';
      $message .= '</li>';
    }
  }
  else {
    $message = t('Status not available');
  }
  $message .= '</ul>';
  
  return $message;
}

/**
 * Theme function : theme_gallery_module_status_message().
 */
function theme_gallery_module_status_message($status) {
  if ($status) {
    return '<span class="admin-enabled">'. t('enabled') .'</span>';
  } 
  else {
    return '<span class="admin-disabled">'. t('disabled') .'</span>';
  }
}

/**
 * Theme function : theme_gallery_severity_message().
 */
function theme_gallery_severity_message($severity = NULL) {
  switch ($severity) {
    case GALLERY_SEVERITY_SUCCESS:
      return '<span class=\'g2_embed_success\'>'. t('OK') .'</span>';
    case GALLERY_SEVERITY_ERROR:
      return '<span class=\'g2_embed_error\'>'. t('Error') .'</span>';
    case GALLERY_SEVERITY_WARNING:
      return '<span class=\'g2_embed_warning\'>'. t('Warning') .'</span>';
    case GALLERY_SEVERITY_ADVISE:
      return '<span class=\'g2_embed_warning\'>'. t('Advisory') .'</span>';
    case GALLERY_SEVERITY_UNKNOWN:
      return '<span class=\'g2_embed_warning\'>'. t('Unknown') .'</span>';
    default:
  }      
}

/**
 * Theme function : theme_gallery_plugin_status_message().
 */
function theme_gallery_plugin_status_message($status, $invert = FALSE) {
  $classes = array('enabled' => 'admin-enabled', 'disabled' => 'admin-disabled');
  if ($invert) {
    $classes = array_reverse($classes, TRUE);
  }

  switch ($status) {
    case GALLERY_PLUGIN_ENABLED:
      return '<span class="'. $classes['enabled'] .'">'. t('activated') .'</span>';
    case GALLERY_PLUGIN_DISABLED:
      return '<span class="'. $classes['disabled'] .'">'. t('disabled') .'</span>';
    case GALLERY_PLUGIN_NOT_ACTIVE:
      return '<span class="'. $classes['disabled'] .'">'. t('deactivated') .'</span>';
    case GALLERY_PLUGIN_NOT_INSTALLED:
      return '<span class="'. $classes['disabled'] .'">'. t('not installed') .'</span>';
    case GALLERY_PLUGIN_MISSING:
      return '<span class="'. $classes['disabled'] .'">'. t('missing') .'</span>';
    case GALLERY_PLUGIN_STATUS_UNKNOWN:
    default:
      return '<span class="'. $classes['disabled'] .'">'. t('unknown') .'</span>';
942
  }    
943 944 945 946 947 948 949 950 951 952
}

/**
 * Theme function : theme_gallery_severity_status_message().
 */
function theme_gallery_severity_status_message($severity, $status, $full_msg = FALSE, $invert = FALSE) {
  // In some cases (e.g. unwanted plugins) it makes sense to return the full 2 part message
  // even on a success, but in most cases a simple "OK" is sufficient.
  if ($full_msg) {
    return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
953
  }    
954 955 956 957 958
  switch ($severity) {
    case GALLERY_SEVERITY_SUCCESS:
      return theme('gallery_severity_message', $severity);
    default:
      return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
959
  }      
960
}