gallery_install.inc 48.4 KB
Newer Older
1 2 3
<?php
// $Id$

4 5
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');

6 7 8 9 10
/**
 * gallery.module : gallery_install.inc
 * Configure embedded Gallery install (directory options, etc.)
 */

11 12 13 14 15
define('GALLERY_INSTALL_STEP_PHPMEMORY',  1);
define('GALLERY_INSTALL_STEP_LOCATIONS',  2);
define('GALLERY_INSTALL_STEP_PLUGINS',    3);
define('GALLERY_INSTALL_STEP_URLREWRITE', 4);
define('GALLERY_INSTALL_STEP_USERSYNC',   5);
16 17

/**
18
 * Function _gallery_install_status_init().
19
 */
20 21
function _gallery_install_status_init() {
  return array(
22
    'phpmemory' => array(
23
      'title' => t('PHP Memory Limit'),
24
      'severity' => GALLERY_SEVERITY_ERROR,
25
      'status' => FALSE
26 27
    ),
    'locations' => array(
28
      'title' => t('Gallery2 locations'),
29
      'severity' => GALLERY_SEVERITY_ERROR,
30
      'status' => FALSE
31 32
    ),
    'plugins' => array(
33
      'title' => t('Drupal Modules / Gallery2 Plugins'),
34
      'severity' => GALLERY_SEVERITY_WARNING,
35
      'status' => FALSE
36
    ),
37 38
    'urlrewrite' => array(
      'title' => t('Clean URL / URL Rewrite'),
39
      'severity' => GALLERY_SEVERITY_WARNING,
40
      'status' => FALSE
41 42
    ),
    'usersync' => array(
43
      'title' => t('Initial User Synchronization'),
44
      'severity' => GALLERY_SEVERITY_ERROR,
45
      'status' => FALSE
46 47
    ),
  );
48
}
49

50 51 52 53 54 55 56 57 58 59
/**
 * Function _gallery_install_status_report().
 */
function _gallery_install_status_report($install_status) {
  // Install status table
  $error = FALSE;
  $rows = array();
  foreach ($install_status as $step => $status) {
    // Find the combination of status and severity of the plugin
    $severity = ($status['status'] <= 0) ? $status['severity'] : GALLERY_SEVERITY_SUCCESS;
60
    if (!$status['status'] && $severity == GALLERY_SEVERITY_ERROR) {
61
      $error = TRUE;
62
    }
63 64 65
    $row = array();
    $row[] = array('data' => $status['title'], 'align' => 'left', 'width' => '20%');
    $row[] = array('data' => theme('gallery_severity_message', $severity), 'align' => 'center');
66
    $row[] = array('data' => isset($status['info'])? $status['info'] : '', 'class' => 'description', 'id' => 'gallery-install-status-'. $step);
67
    $rows[] = $row;
68
  }
69 70 71 72 73 74 75 76
  
  if ($error) {
    $rows[] = array(array(
      'data' => t('Critical errors are present.'),
      'colspan' => '3',
      'align' => 'center',
      'class' => 'message')
    );
77
  }
78 79 80 81 82 83 84 85

  // Set the global status variable 'gallery_valid'
  gallery_set_status(array(
    'gallery_valid' => array(
      'title' => t('Overall Status (Installation)'),
      'severity' => $error ? GALLERY_SEVERITY_ERROR : GALLERY_SEVERITY_SUCCESS,
    ),
  ));
86
  
87 88 89 90 91 92 93 94
  return theme('table', array(t('Step'), t('Status'), t('Description')), $rows, array('class' => 'package'));
}

/**
 * Function _gallery_install_status().
 */
function _gallery_install_status($form_state) {
  $form['install'] = array(
95 96 97 98
    '#type' => 'fieldset',
    '#title' => t('Install status'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
99 100
    '#description' => t('Correct configuration of the following items is essential for the
                         embedded gallery to function properly.'),
101 102
  );
  
103 104
  $install_status = _gallery_install_status_init();

105
  // Step 1: Check PHP Memory
106 107 108 109 110 111 112 113
  $phpmemory_info = _gallery_php_memcheck();
  $install_status['phpmemory']['status'] = $phpmemory_info['status'];
  $install_status['phpmemory']['info'] = $phpmemory_info['info'];

  // Step 2: Gallery2 Locations
  $values['gallery_uri'] = variable_get('gallery_uri', '/gallery2/');
  $values['gallery_dir'] = variable_get('gallery_dir', './gallery2/');
  $values['gallery_embed_uri'] = variable_get('gallery_embed_uri', '?q=gallery');
profix898's avatar
profix898 committed
114
  $values['gallery_base'] = variable_get('gallery_base', 'gallery');
115 116
  $autodetect = variable_get('gallery_autodetect_dir', 1);
  list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect);
profix898's avatar
profix898 committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  if ($install_status['locations']['status']) {
    $install_status['locations']['info'] = t('The Gallery2 location settings appear to be correct.');
    $form['locations'] = array(
      '#type' => 'fieldset',
      '#title' => t('Gallery2 location settings') .' - '. ($autodetect ? t('Auto Configuration') : t('Manual Configuration')),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('Overview of your Gallery2 location settings as specified or autodetected during install.')
    );
    $form['locations']['gallery_uri'] = array(
      '#title' => t('Gallery2 URL or URI'),
      '#type' => 'item',
      '#value' => $values['gallery_uri']
    );
    $form['locations']['gallery_dir'] = array(
      '#title' => t('Gallery2 filesystem path'),
      '#type' => 'item',
      '#value' => $values['gallery_dir']
    );
    $form['locations']['gallery_embed_uri'] = array(
      '#title' => t('Embed URI'),
      '#type' => 'item',
      '#value' => $values['gallery_embed_uri']
    );
    $form['locations']['gallery_base'] = array(
      '#title' => t('Gallery base'),
      '#type' => 'item',
      '#value' => $values['gallery_base']
    );
  }
  else {
    $install_status['locations']['info'] = gallery_format_status($result, t('Errors in your current Gallery2 location settings:'));
  }
150 151 152

  // Step 3: Drupal Modules and Gallery2 Plugins check
  $form += _gallery_install_plugins($install_status);
153
  
154 155
  // Step 4: Clean URL configuration
  _gallery_install_urlrewrite_check($install_status);
156 157 158 159 160 161 162 163 164 165 166 167 168
  if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) {
    if (_gallery_install_urlrewrite($public_path, $htaccess_path, TRUE)) {
      $form['urlrewrite'] = array(
          '#type' => 'fieldset',
          '#title' => t('Clean URLs / URL Rewrite settings'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#description' => t('Overview of your URL Rewrite settings as specified during install.')
        );
      $form['urlrewrite']['htaccess_public_path'] = array(
        '#title' => t('Public path to your .htaccess file'),
        '#type' => 'item',
        '#value' => $public_path
169
      );
170 171 172 173 174 175
      $form['urlrewrite']['htaccess_filesystem_path'] = array(
        '#title' => t('Filesystem path to your .htaccess file'),
        '#type' => 'item',
        '#value' => $htaccess_path
      );
    }
176
  }
177
      
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
  // Step 5: User Synchronization
  $install_status['usersync']['status'] = TRUE;
  $install_status['usersync']['info'] = t('Your initial user synchronization has been completed already.<br /> If you
                                           want to resync all your users or you want to import users from an existing
                                           Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced
                                           Sync</a> options in the Gallery user administration.',
                                           array('@gallery-usersync' => url('admin/user/gallery/advanced')));

  $form['install']['status'] = array(
    '#value' => _gallery_install_status_report($install_status)
  );
  
  $form['buttons']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset & Restart'),
    '#submit' => array('_gallery_install_reset')
  );

  return $form;
}

/**
 * Function _gallery_install().
 */
function _gallery_install($form_state) {
  $form['install'] = array(
    '#type' => 'fieldset',
    '#title' => t('Install status'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#description' => t(''),
  );
  
  if (!isset($form_state['storage'])) {
    $install_status = _gallery_install_status_init();
    $install_status['step'] = GALLERY_INSTALL_STEP_PHPMEMORY;
214
  }
215 216 217 218 219 220
  else {
    $install_status = $form_state['storage'];
  }
  
  // Step 1: Check PHP Memory
  _gallery_install_step_phpmemory($form, $form_state, $install_status);
221 222

  // Step 2 : Gallery2 Locations
223 224
  if ($install_status['step'] >= GALLERY_INSTALL_STEP_LOCATIONS) {
    _gallery_install_step_locations($form, $form_state, $install_status);
225
  }
226

227
  // Step 3: Drupal Modules and Gallery2 Plugins check
228 229
  if ($install_status['step'] >= GALLERY_INSTALL_STEP_PLUGINS) {
    _gallery_install_step_plugins($form, $form_state, $install_status);
230 231 232
  }

  // Step 4: Clean URL configuration
233 234
  if ($install_status['step'] >= GALLERY_INSTALL_STEP_URLREWRITE) {
    _gallery_install_step_urlrewrite($form, $form_state, $install_status);
235
  }
236

237
  // Step 5: User Synchronization
238 239
  if ($install_status['step'] >= GALLERY_INSTALL_STEP_USERSYNC) {
    _gallery_install_step_usersync($form, $form_state, $install_status);
240
  }
241 242 243

  $form['install']['status'] = array(
    '#value' => _gallery_install_status_report($install_status)
244
  );
245 246 247 248
  
  $form['install_status'] = array(
    '#type' => 'value',
    '#value' => $install_status
249 250
  );
  
251 252 253 254 255
  $form['buttons']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset & Restart'),
    '#submit' => array('_gallery_install_reset')
  );
256 257 258 259 260

  return $form;
}

/**
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
 * Function _gallery_install_reset().
 */
function _gallery_install_reset($form, &$form_state) {
  variable_del('gallery_autodetect_dir');
  variable_del('gallery_uri');
  variable_del('gallery_dir');
  variable_del('gallery_embed_uri');
  variable_del('gallery_valid');
  variable_del('gallery_rewrite_disable');
  menu_rebuild();

  unset($form_state['storage']);
  $form_state['redirect'] = 'admin/settings/gallery/install';
}

/**
 * Function _gallery_install_step_phpmemory().
278
 * Step 1: Check PHP Memory
279 280 281 282 283 284 285 286 287
 */
function _gallery_install_step_phpmemory(&$form, &$form_state, &$install_status) {
  if ($install_status['step'] == GALLERY_INSTALL_STEP_PHPMEMORY) {
    $phpmemory_info = _gallery_php_memcheck();
    $install_status['phpmemory']['status'] = $phpmemory_info['status'];
    $install_status['phpmemory']['info'] = $phpmemory_info['info'];
    if ($phpmemory_info['status']) {
      $install_status['step'] = GALLERY_INSTALL_STEP_LOCATIONS;
    }
288 289 290 291
  }
  
  $form['phpmemory'] = array(
    '#type' => 'fieldset',
292 293 294 295
    '#title' => t('Step 1: PHP Memory Test') . ($install_status['phpmemory']['status'] ? ' '. t('(OK)') : ''),
    '#description' => $install_status['phpmemory']['info'],
    '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_PHPMEMORY),
    '#collapsed' => $install_status['phpmemory']['status'],
296
  );
297 298 299
  if (!$install_status['phpmemory']['status']) {
    $form['phpmemory']['#description'] .= ' '. t('Until this is fixed your Gallery2 cannot be installed.');
    $form['phpmemory']['check'] = array('#type' => 'submit', '#value' => t('Check PHP memory again'));
300 301 302 303 304 305
  }
}

/**
 * Function _gallery_install_step_locations().
 * Step 2: Gallery2 Locations
306 307
 */
function _gallery_install_step_locations(&$form, &$form_state, &$install_status) {
profix898's avatar
profix898 committed
308 309 310
  $autodetect = variable_get('gallery_autodetect_dir', 1);
  $title = t('Step 2: Gallery2 location settings') .' - '. ($autodetect ? t('Auto Configuration') : t('Manual Configuration'));
  $desc = $install_status['locations']['status'] ? '' : $autodetect ?
311
      t('Enter the \'Gallery2 URL or URI\' and click \'Test location settings\'
312 313 314 315 316 317 318 319
         to automatically configure the settings needed for embedding Gallery2 into Drupal. Note that
         the auto-config will not work for all host configurations. If you have tried it with a value
         you know is correct and it did not work then just use the manual configuration instead.') :
      t('Enter the \'Gallery2 URL or URI\' and \'Gallery2 filesystem path\' and then click
         \'Test location settings\'. This will check and configure the settings needed for embedding
         Gallery2 into Drupal.');

  $form['locations'] = array(
320
    '#type' => 'fieldset',
321 322 323 324 325 326
    '#title' => $title . ($install_status['locations']['status'] ? ' '. t('(OK)') : ''),
    '#description' => isset($install_status['locations']['details']) ? ($desc .'<p>'. $install_status['locations']['details'] .'</p>') : $desc,
    '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_LOCATIONS),
    '#collapsed' => $install_status['locations']['status']
  );

profix898's avatar
profix898 committed
327
  if ($autodetect) {
328
    // Autodetect
profix898's avatar
profix898 committed
329 330 331 332 333 334 335
    $gallery_uri = empty($form_state['values']['gallery_uri_auto']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_uri', '/gallery2/') : '') :
      $form_state['values']['gallery_uri_auto'];

    $gallery_dir = empty($form_state['values']['gallery_dir_auto']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_dir', './gallery2/') : '') :
      $form_state['values']['gallery_dir_auto'];
336

profix898's avatar
profix898 committed
337 338 339
    $embed_uri = empty($form_state['values']['gallery_embed_uri_auto']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_embed_uri', '?q=gallery') : '') :
      $form_state['values']['gallery_embed_uri_auto'];
340

profix898's avatar
profix898 committed
341 342 343
    $gallery_base = empty($form_state['values']['gallery_base']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_base', 'gallery') : 'gallery') :
      $form_state['values']['gallery_base'];
344 345

    $form['locations']['gallery_uri_auto'] = array(
346 347 348 349 350
      '#type' => 'textfield',
      '#title' => t('Gallery2 URL or URI'),
      '#default_value' => $gallery_uri,
      '#size' => 64,
      '#maxlength' => 128,
351 352 353 354
      '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2
                           (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory
                           (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'),
      '#disabled' => $install_status['locations']['status']
355 356 357
    );

    if (!empty($gallery_dir)) {
358
      $form['locations']['gallery_dir_auto_item'] = array(
359 360
        '#title' => t('Gallery2 filesystem path'),
        '#type' => 'item',
361
        '#value' => $gallery_dir
362 363
      );
    }
364
    $form['locations']['gallery_dir_auto'] = array(
365
      '#type' => 'value',
366
      '#value' => $gallery_dir
367 368
    );
    
369 370
    if (!empty($embed_uri)) {
      $form['locations']['gallery_embed_uri_auto_item'] = array(
371 372
        '#title' => t('Embed URI'),
        '#type' => 'item',
373
        '#value' => $embed_uri
374 375
      );
    }
376
    $form['locations']['gallery_embed_uri_auto'] = array(
377
      '#type' => 'value',
378
      '#value' => $embed_uri
379
    );
profix898's avatar
profix898 committed
380 381 382 383 384 385 386 387 388 389 390
    
    $form['locations']['gallery_base'] = array(
      '#type' => 'textfield',
      '#title' => t('Gallery base (optional)'),
      '#default_value' => $gallery_base,
      '#size' => 32,
      '#maxlength' => 64,
      '#description' => t('Drupal path to embedded Gallery. This option defaults to \'gallery\' and the embedded gallery
                           will be located at \'@default-base\'.', array('@default-base' => url('gallery'))),
      '#disabled' => $install_status['locations']['status']
    );
391 392
  }
  else {
393
    // No Autodetect (manual)
profix898's avatar
profix898 committed
394 395 396
    $gallery_uri = empty($form_state['values']['gallery_uri_man']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_uri', '/gallery2/') : '') :
      $form_state['values']['gallery_uri_man'];
397

profix898's avatar
profix898 committed
398 399 400
    $gallery_dir = empty($form_state['values']['gallery_dir_man']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_dir', './gallery2/') : '') :
      $form_state['values']['gallery_dir_man'];
401

profix898's avatar
profix898 committed
402 403 404
    $embed_uri = empty($form_state['values']['gallery_embed_uri_man']) ?
      ($install_status['locations']['status'] ? variable_get('gallery_embed_uri', '?q=gallery') : '') :
      $form_state['values']['gallery_embed_uri_man'];
405 406

    $form['locations']['gallery_uri_man'] = array(
407 408 409 410 411
      '#type' => 'textfield',
      '#title' => t('Gallery2 URL or URI'),
      '#default_value' => $gallery_uri,
      '#size' => 64,
      '#maxlength' => 128,
412 413 414 415
      '#description' => t('URL or URI of the G2 standalone location. This can be either the full URL to Gallery2
                           (e.g. http://www.example.com/gallery2) or the path from docroot to the Gallery2 directory
                           (e.g. /gallery2). If using a URI the protocol/hostname are both optional.'),
      '#disabled' => $install_status['locations']['status']
416
    );
profix898's avatar
profix898 committed
417
    
418
    $form['locations']['gallery_dir_man'] = array(
419 420 421 422 423
      '#type' => 'textfield',
      '#title' => t('Gallery2 filesystem path'),
      '#default_value' => $gallery_dir,
      '#size' => 64,
      '#maxlength' => 128,
424 425 426 427
      '#description' => t('The filesystem path of your Gallery2 directory. This can be either an absolute path
                           (e.g. /home/mysite/htdocs/gallery2) or relative to the root directory of your Drupal
                           installation (e.g. ../gallery2).'),
      '#disabled' => $install_status['locations']['status']
428
    );
profix898's avatar
profix898 committed
429
    
430
    $form['locations']['gallery_embed_uri_man'] = array(
431 432 433 434 435
      '#type' => 'textfield',
      '#title' => t('Embed URI'),
      '#default_value' => $embed_uri,
      '#size' => 64,
      '#maxlength' => 128,
436 437 438 439
      '#description' => t('URI to access G2 via Drupal. Don\'t worry if you are using clean urls in Drupal and this
                           still ends in \'index.php?q=gallery\'. This is needed to get the Gallery2 URL rewrite module
                           to work correctly and will not be visible.'),
      '#disabled' => $install_status['locations']['status']
440 441
    );
  }
profix898's avatar
profix898 committed
442
  
443 444
  if (!$install_status['locations']['status']) {
    $form['locations']['location_button'] = array(
445 446
      '#type' => 'submit',
      '#value' => t('Test location settings'),
447 448 449 450
      '#submit' => array('_gallery_install_step_locations_check')
    );
    $form['locations']['switch_config_button'] = array(
      '#type' => 'submit',
profix898's avatar
profix898 committed
451
      '#value' => $autodetect ? t('Use Manual Configuration') : t('Use Auto Configuration'),
452
      '#submit' => array('_gallery_install_step_locations_switch')
453 454 455 456 457
    );
  }
}

/**
458 459 460 461 462 463 464
 * Function _gallery_install_step_locations_check().
 */
function _gallery_install_step_locations_check($form, &$form_state) {
  $install_status = $form_state['values']['install_status'];
  $autodetect = variable_get('gallery_autodetect_dir', 1);
  if ($autodetect) {
    $values['gallery_uri'] = $form_state['values']['gallery_uri_auto'];
profix898's avatar
profix898 committed
465
    $values['gallery_base'] = empty($form_state['values']['gallery_base']) ? 'gallery' : $form_state['values']['gallery_base'];
466
  }
467 468 469 470
  else {
    $values['gallery_uri'] = $form_state['values']['gallery_uri_man'];
    $values['gallery_dir'] = $form_state['values']['gallery_dir_man'];
    $values['gallery_embed_uri'] = $form_state['values']['gallery_embed_uri_man'];
471
  }
472 473 474 475
  
  list($install_status['locations']['status'], $values, $result) = _gallery_install_locations($values, $autodetect);
  if (!$install_status['locations']['status']) {
    $install_status['locations']['details'] = gallery_format_status($result, t('Errors in your current Gallery2 location settings:'));
476
  }
477 478 479 480
  else {
    variable_set('gallery_uri', $values['gallery_uri']);
    variable_set('gallery_dir', $values['gallery_dir']);
    variable_set('gallery_embed_uri', $values['gallery_embed_uri']);
profix898's avatar
profix898 committed
481
    variable_set('gallery_base', $values['gallery_base']);
482
    $install_status['step'] = GALLERY_INSTALL_STEP_PLUGINS;
483 484
  }
  
485 486 487 488
  if ($autodetect) {
    $form_state['values']['gallery_uri_auto'] = $values['gallery_uri'];
    $form_state['values']['gallery_dir_auto'] = $values['gallery_dir'];
    $form_state['values']['gallery_embed_uri_auto'] = $values['gallery_embed_uri'];
489 490
  }
  else {
491 492 493
    $form_state['values']['gallery_uri_man'] = $values['gallery_uri'];
    $form_state['values']['gallery_dir_man'] = $values['gallery_dir'];
    $form_state['values']['gallery_embed_uri_man'] = $values['gallery_embed_uri'];
494
  }
495 496 497 498 499 500 501
  
  $install_status['locations']['info'] = $install_status['locations']['status'] ?
    t('The Gallery2 location settings appear to be correct.') :
    t('There is a problem with the Gallery2 location settings. Please check below and retest.
       Remember that the auto-config will not work for all hosts.');

  $form_state['storage'] = $install_status;
502 503 504
}

/**
505
 * Function _gallery_install_step_locations_switch().
506
 */
507 508 509
function _gallery_install_step_locations_switch($form, &$form_state) {
  variable_set('gallery_autodetect_dir', !variable_get('gallery_autodetect_dir', 1));
}
510

511 512 513 514 515 516 517 518 519
/**
 * Function _gallery_install_step_plugins().
 * Step 3: Drupal Modules / Gallery2 Plugins
 */
function _gallery_install_step_plugins(&$form, &$form_state, &$install_status) {
  $title = t('Step 3: Drupal Modules / Gallery2 Plugins') . ($install_status['plugins']['status'] ? ' '. t('(OK)') : '');
  $form += _gallery_install_plugins($install_status, $title, ($install_status['step'] > GALLERY_INSTALL_STEP_PLUGINS));
  
  if ($install_status['step'] == GALLERY_INSTALL_STEP_PLUGINS) {
520
    if (!in_array($install_status['plugins']['status'], array(GALLERY_SEVERITY_ERROR, GALLERY_SEVERITY_WARNING))) {
521 522
      $install_status['step'] = GALLERY_INSTALL_STEP_URLREWRITE;
      $form['plugins']['#collapsed'] = TRUE;
523 524
    }
    else {
525 526 527 528 529 530 531 532 533 534
      $form['plugins']['plugins_button_desc'] = array(
        '#type' => 'item',
        '#value' => t('There are errors in your plugin configuration. Enable/Disable the
                       respective plugins to meet the requirements.')
      );
      $form['plugins']['plugins_button'] = array(
        '#type' => 'submit',
        '#value' => t('Check Plugins status again'),
        '#submit' => array('_gallery_install_step_plugins_check')
      );
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
}

/**
 * Function _gallery_install_step_plugins_check().
 */
function _gallery_install_step_plugins_check($form, &$form_state) {
  $install_status = $form_state['values']['install_status'];
  _gallery_init(TRUE, array(), FALSE);
  $form_state['storage'] = $install_status;
}

/**
 * Function _gallery_install_step_urlrewrite().
 * Step 4: Clean URL configuration
 */
function _gallery_install_step_urlrewrite(&$form, &$form_state, &$install_status) {
  $title = t('Step 4: Clean URLs / URL Rewrite settings') . ($install_status['urlrewrite']['status'] ? ' '. t('(OK)') : '');
  $form['urlrewrite'] = array(
    '#type' => 'fieldset',
    '#title' => $title,
    '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_URLREWRITE),
    '#collapsed' => $install_status['urlrewrite']['status']
  );
560 561 562
  
  // User selected to skip the URLRewrite step
  if (variable_get('gallery_rewrite_disable', 0)) {
563 564 565
    $form['urlrewrite']['#description'] = $install_status['urlrewrite']['info'];
    $form['urlrewrite']['#description'] .= ' '. t('\'Reset & Restart\' your configuration to change these settings.');
    return;
566 567
  }
  
568 569
  $clean_urls_status = variable_get('clean_url', 0);
  $rewrite_status = gallery_single_plugin_status('rewrite');
570 571 572
  
  if ($clean_urls_status) {
    if ($rewrite_status < GALLERY_PLUGIN_ENABLED) {
573 574 575 576 577 578 579
      $form['urlrewrite']['#description'] = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin is unavailable (!status).',
                                            array('!status' => theme('gallery_plugin_status_message', $rewrite_status)));
      $form['urlrewrite']['check'] = array(
        '#type' => 'submit',
        '#value' => t('Check URL Rewrite status again'),
        '#submit' => array('_gallery_install_step_urlrewrite_check')
      );
580 581 582
    }
    else {
      // CleanURL and URLRewrite are both enabled
583
      $form['urlrewrite']['#description'] = t('Clean URLs are !clean_url_status in Drupal and the Gallery2 URL Rewrite plugin is
584 585 586 587
                                            !rewrite_status. It is possible to automatically configure the URL Rewrite plugin.
                                            The configuration assumes that the rules should be placed in your Drupal .htaccess
                                            file (it will add them to the beginning) which works in most applications. If you
                                            need a special configuration, enter the desired values manually.',
588 589 590 591
                                            array(
                                              '!clean_url_status' => theme('gallery_module_status_message', $clean_urls_status),
                                              '!rewrite_status' => theme('gallery_plugin_status_message', $rewrite_status)
                                            )
592 593
      );
      
594 595
      _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE);
      $form['urlrewrite']['htaccess_public_path'] = array(
596 597 598
        '#type' => 'textfield',
        '#title' => t('Public path to your .htaccess file'),
        '#size' => 64,
profix898's avatar
profix898 committed
599
        '#maxlength' => 255,
600 601
        '#default_value' => $public_path,
        '#description' => t('This is the location of your Drupal .htaccess file relative to your webserver document root.'),
profix898's avatar
profix898 committed
602
        '#disabled' => $install_status['urlrewrite']['status'],
603
      );
604
      $form['urlrewrite']['htaccess_filesystem_path'] = array(
605 606
        '#type' => 'textfield',
        '#title' => t('Filesystem path to your .htaccess file'),
profix898's avatar
profix898 committed
607 608
        '#size' => 100,
        '#maxlength' => 255,
609 610
        '#default_value' => $htaccess_path,
        '#description' => t('This is the absolute directory path of your Drupal .htaccess file.'),
611 612 613 614 615 616 617
        '#disabled' => $install_status['urlrewrite']['status'],
      );
      
      $form['urlrewrite']['config'] = array(
        '#type' => 'submit',
        '#value' => t('Configure URL Rewrite plugin'),
        '#submit' => array('_gallery_install_step_urlrewrite_configure')
618 619 620
      );
    }
  }
621 622 623 624 625 626 627 628 629 630 631 632 633 634
  else {
    $form['urlrewrite']['check'] = array(
      '#type' => 'submit',
      '#value' => t('Check URL Rewrite status again'),
      '#submit' => array('_gallery_install_step_urlrewrite_check')
    );
  }
  
  $form['urlrewrite']['skip'] = array(
    '#type' => 'submit',
    '#value' => t('Skip URL Rewrite Config'),
    '#submit' => array('_gallery_install_step_urlrewrite_skip')
  );
}
635

636 637 638 639 640 641 642
/**
 * Function _gallery_install_step_urlrewrite_check().
 */
function _gallery_install_step_urlrewrite_check($form, &$form_state) {
  $install_status = $form_state['values']['install_status'];
  _gallery_init(TRUE, array(), FALSE);
  $form_state['storage'] = $install_status;
643 644 645
}

/**
646 647 648 649
 * Function _gallery_install_step_urlrewrite_skip().
 */
function _gallery_install_step_urlrewrite_skip($form, &$form_state) {
  $install_status = $form_state['values']['install_status'];
650
  
651
  variable_set('gallery_rewrite_disable', 1);
652
  
653 654
  _gallery_init(TRUE, array(), FALSE);
  _gallery_install_urlrewrite_check($install_status);
655
  
656 657
  $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC;
  $form_state['storage'] = $install_status;
658 659 660
}

/**
661
 * Function _gallery_install_step_urlrewrite_configure().
662
 */
663 664 665 666
function _gallery_install_step_urlrewrite_configure($form, &$form_state) {
  $install_status = $form_state['values']['install_status'];
  
  _gallery_init(TRUE, array(), FALSE);
profix898's avatar
profix898 committed
667 668 669 670 671 672
  if (_gallery_install_urlrewrite($form_state['values']['htaccess_public_path'], $form_state['values']['htaccess_filesystem_path'])) {
    _gallery_install_urlrewrite_check($install_status);
  }
  else {
    $install_status['urlrewrite']['status'] = FALSE;
  }
673 674 675 676 677
  
  if ($install_status['urlrewrite']['status']) {
    $install_status['step'] = GALLERY_INSTALL_STEP_USERSYNC;
  }
  $form_state['storage'] = $install_status;
678 679 680
}

/**
681 682
 * Function _gallery_install_step_usersync().
 * Step 5: User Synchronization
683
 */
684 685 686 687 688 689 690 691
function _gallery_install_step_usersync(&$form, &$form_state, &$install_status) {
  $title = t('Step 5: Initial User Synchronization') . ($install_status['usersync']['status'] ? ' '. t('(OK)') : '');
  $form['usersync'] = array(
    '#type' => 'fieldset',
    '#title' => $title,
    '#collapsible' => ($install_status['step'] > GALLERY_INSTALL_STEP_USERSYNC),
    '#collapsed' => $install_status['usersync']['status'],
  );
692

693 694 695 696 697 698
  if ($install_status['usersync']['status']) {
    $form['usersync']['#description'] = t('Your initial user synchronization has been completed already.<br />
                                           If you want to resync all your users or you want to import users from an existing
                                           Gallery2 setup, you can always use the <a href= "@gallery-usersync">Advanced Sync
                                           </a> options in the Gallery user administration.',
                                           array('@gallery-usersync' => url('admin/user/gallery/advanced')));
699 700
  }
  else {
701 702 703 704 705 706 707 708
    $form['usersync']['#description'] = t('User synchronization is essential for the embedded Gallery to work correctly.
                                           Drupal users/groups are usually synced with their Gallery counterparts when a
                                           user/group is modified in Drupal. Missing user mappings will cause errors in your
                                           embedded Gallery.<br /><br />
                                           It is recommended that you sync your users now. However there can be reasons to
                                           skip this step, e.g. if you have a working Gallery with many users and a fresh
                                           Drupal installation. Note that the current user and the Drupal superuser (uid=1)
                                           will always be sync.');
709

710 711 712 713 714 715 716 717 718 719
    $form['usersync']['sync'] = array(
      '#type' => 'submit',
      '#value' => t('Sync users/groups'),
      '#submit' => array('_gallery_install_step_usersync_sync')
    );
    $form['usersync']['skip'] = array(
      '#type' => 'submit',
      '#value' => t('Skip sync'),
      '#submit' => array('_gallery_install_step_usersync_skip')
    );
720
  }
721
}
722

723 724 725 726 727 728 729 730 731 732 733 734
/**
 * Function _gallery_install_step_usersync_skip().
 */
function _gallery_install_step_usersync_skip($form, &$form_state) {
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
  global $user;
  // Always sync (at least) the current user to avoid
  // errors (unknown user) during GalleryEmbed::init()
  gallery_user_modify($user, 'update', TRUE, array());
  // Make sure the Drupal superuser (uid=1) always gets admin right
  if ($user->uid != 1) {
    gallery_user_modify(user_load(array('uid' => 1)), 'update', FALSE, array());
735
  }
736 737 738 739 740 741 742 743 744
  
  // Set the global status variable 'gallery_valid'
  gallery_set_status(array(
    'gallery_valid' => array(
      'title' => t('Overall Status (Installation)'),
      'severity' => GALLERY_SEVERITY_SUCCESS,
    ),
  ));
  variable_set('gallery_valid', TRUE);
745 746
  // Clear cache and rebuild menu
  cache_clear_all('gallery', 'cache', TRUE);
747 748 749 750 751
  menu_rebuild();
  
  $form_state['redirect'] = 'admin/settings/gallery';
  $form_state['storage'] = array();
}
752

753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
/**
 * Function _gallery_install_step_usersync_sync().
 */
function _gallery_install_step_usersync_sync($form, &$form_state) {
  _gallery_install_step_usersync_skip($form, $form_state);
  
  // Trigger bulk user/group sync
  require_once(drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc');
  $batch = array(
    'title' => t('Initial User Synchronization'),
    'operations' => array(array('_gallery_user_advanced_sync', array())),
    'file' => drupal_get_path('module', 'gallery') .'/gallery_user_admin.inc',
    'finished' => '_gallery_user_advanced_finished'
  );
  batch_set($batch);
768 769 770
}

/**
771
 * Function _gallery_install_locations().
772
 */
773 774 775 776
function _gallery_install_locations($orig, $autodetect = TRUE) {
  include_once(drupal_get_path('module', 'gallery') .'/G2EmbedDiscoveryUtilities.class');
  
  // Result status array
777
  $result = array(
778
    'gallery_uri' => array(
779 780 781
          'title' => t('URI of Gallery2'),
          'severity' => GALLERY_SEVERITY_ERROR,
    ),
782
    'gallery_dir' => array(
783 784 785 786 787 788 789 790 791 792
          'title' => t('Location of Gallery2'),
          'severity' => GALLERY_SEVERITY_ERROR,
    ),
    'init' => array(
          'title' => t('Gallery Init'),
          'severity' => GALLERY_SEVERITY_ERROR,
    ),
  );
  
  $vars = array();
793
  $vars['locations_valid'] = TRUE;
794
  
profix898's avatar
profix898 committed
795 796 797 798 799 800
  // Extract gallery_base_from embed_uri if required
  $vars['gallery_base'] = isset($orig['gallery_base']) ? $orig['gallery_base'] : strtolower($orig['gallery_embed_uri']);
  if (($pos = strrpos($vars['gallery_base'], '=')) !== FALSE) {
    $vars['gallery_base'] = trim(substr($vars['gallery_base'], $pos + 1), '/');
  }
  // Construct embed_uri value
801
  $embed_uri = isset($orig['gallery_embed_uri']) ? $orig['gallery_embed_uri'] : '';
802
  if ($autodetect || empty($embed_uri)) {
profix898's avatar
profix898 committed
803 804
    $embed_uri = url($vars['gallery_base']);
    
805 806 807 808 809
    // TODO
    // i18n/locale rewrites the link to gallery to include a ?q=en or something
    /*if (function_exists('language_url_rewrite')) {
      $embed_uri = trim(substr($embed_uri, strlen($prefix)), '/');
    }*/
profix898's avatar
profix898 committed
810 811 812 813 814 815 816
    
    // Strip the end /gallery if present and replace with index.php?q=gallery to avoid any
    // url rewrite issues. See http://gallery.menalto.com/node/46181
    // Note the use of index.php in all cases. Not needed for Apache, but for IIS
    $length = strlen('/'. $vars['gallery_base']);
    if (substr($embed_uri, - $length) == '/'. $vars['gallery_base']) {
      $embed_uri = substr($embed_uri, 0, - $length + 1) .'index.php?q='. $vars['gallery_base'];
817 818 819 820 821
    }
  }
  
  // Normalise the Embed Application URI
  $embed_uri = G2EmbedDiscoveryUtilities::normalizeEmbedUri($embed_uri); 
822 823 824 825 826 827
  $vars['gallery_embed_uri'] = $embed_uri;
  
  // Normalise the G2 URI
  $g2_uri = G2EmbedDiscoveryUtilities::normalizeG2Uri($orig['gallery_uri']);
  $vars['gallery_uri'] = $g2_uri;
  
828 829 830
    // Find the Gallery Directory and Embed URI
  if ($autodetect) {
    // Auto-Detect the G2 embed path 
831
    list($success, $embed_php_path, $error_string) = G2EmbedDiscoveryUtilities::getG2EmbedPathByG2Uri($g2_uri);
832 833
    if ($success) {
      // G2 Embed Path is found OK
834
      $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php');
835 836 837 838
    }
    else {
      // Something is wrong with the G2 URI given as the G2 embed path is not found
      // Try getG2EmbedPathByG2UriEmbedUriAndLocation instead
839
      $drupal_path = realpath(".") .'/';
840 841 842 843
      list($success, $embed_php_path, $error_string) =
        G2EmbedDiscoveryUtilities::getG2EmbedPathByG2UriEmbedUriAndLocation($g2_uri, $embed_uri, $drupal_path);
      if ($success) {
        // G2 Embed Path is found OK
844
        $vars['gallery_dir'] = rtrim($embed_php_path, 'embed.php');
845
      }
846 847 848 849 850
      else {                     
        $result['gallery_uri']['info'] = $error_string;
        $result['gallery_uri']['status'] = FALSE;
        $vars['gallery_dir'] = '';
        $vars['locations_valid'] = FALSE;
851 852 853 854
      } 
    }
    // Check for config.php in the embed_path (not existing => invalid path)
    //  e.g. this is the path to the G2 codebase, but we have a multisite configuration
855 856
    if (!empty($vars['gallery_dir'])) {
      list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($vars['gallery_dir'] .'config.php');
857
      if (!$ok) {
858 859 860 861
        $result['gallery_dir']['status'] = FALSE;
        $result['gallery_dir']['info'] = $error_string;
        $vars['gallery_dir'] = '';
        $vars['locations_valid'] = FALSE;
862 863 864 865 866
      }
    }
  } 
  else {
    // Do not autodetect the variables, but check the manually entered ones.
867
    $embed_php_path = $orig['gallery_dir'];
868 869 870
    $embed_php_path .= (substr($embed_php_path, -1) != '/') ? '/' : '';
    // Check path can be read, adding embed.php if needed
    list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($embed_php_path .'embed.php');
871
    $vars['gallery_dir'] = $embed_php_path;
872
    if (!$ok) {
873 874 875
      $result['gallery_dir']['status'] = FALSE;
      $result['gallery_dir']['info'] = $error_string;
      $vars['locations_valid'] = FALSE;
876 877 878 879 880 881
    }
    else {
      // Check for config.php in the embed_path (not existing => invalid path)
      //  e.g. this is the path to the G2 codebase, but we have a multisite configuration
      list($ok, $error_string) = G2EmbedDiscoveryUtilities::isFileReadable($embed_php_path .'config.php');
      if (!$ok) {
882 883 884
        $result['gallery_dir']['status'] = FALSE;
        $result['gallery_dir']['info'] = $error_string;
        $vars['locations_valid'] = FALSE;
885 886 887 888 889
      }
    }
  }
  
  // If the filepaths seem correct then check Gallery2 works and has the correct module configs
890
  if ($vars['locations_valid']) {
891 892 893
    // Gallery install is thought valid, so init it.
    if (!_gallery_init(TRUE, $vars, FALSE)) {
      // Gallery install was supposed to be valid, but it still failed. Something is wrong.
894 895 896 897
      $result['gallery_init']['status'] = FALSE;
      $result['gallery_init']['info'] = t('Everything seemed OK, but the Gallery could still not be initialised.
                                           Perhaps a manually entered value is incorrect.');
      $vars['locations_valid'] = FALSE;
898 899
    }
    else {
profix898's avatar
profix898 committed
900 901 902
      // Is Gallery2 installed inside the Drupal root directory?
      _gallery_install_in_drupal_folder($vars['gallery_dir']);
      // Update version info
903 904 905 906
      gallery_version();       
      GalleryEmbed::done();
    }
  }
907
  
908 909 910 911 912 913 914
  // Only return items where status has been set
  foreach ($result as $key => $value) {
    if (!isset($value['status'])) {
      unset($result[$key]);
    }
  }
  
915
  return array($vars['locations_valid'], $vars, $result);
916 917
}

profix898's avatar
profix898 committed
918 919 920 921
/**
 * Function _gallery_install_in_drupal_folder().
 */
function _gallery_install_in_drupal_folder($gallery_dir) {
922
  global $base_url;
profix898's avatar
profix898 committed
923 924
  static $warn = TRUE;

925 926 927 928 929
  // Dont proceed if G2 was not initialized
  if (!isset($GLOBALS['gallery'])) {
    return;
  }

profix898's avatar
profix898 committed
930 931 932
  if (!empty($gallery_dir)) {
    // Reset 'gallery_outside' state
    variable_del('gallery_outside');
933 934 935 936 937 938
    // Get location of Drupal, Gallery2, etc.
    $docroot = strtolower(str_replace('/', '\\' , $_SERVER['DOCUMENT_ROOT']));
    $base_path = strtolower(str_replace('/', '\\' , base_path()));
    $g2_base = strtolower($GLOBALS['gallery']->getConfig('galleryBaseUrl'));
    if ((strpos(strtolower($gallery_dir), $base_path) === FALSE && strpos(strtolower($gallery_dir), $docroot) !== FALSE)
        || (!empty($g2_base) && strpos($g2_base, $base_url) === FALSE) || strpos(strtolower($gallery_dir), '../') !== FALSE) {
profix898's avatar
profix898 committed
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
      // G2 is installed outside the Drupal root directory
      variable_set('gallery_outside', TRUE);
      if ($warn) {
        // Avoid duplicate warning
        $warn = FALSE;
        drupal_set_message(t('Your location settings are valid, but your Gallery2 is installed outside the Drupal
                              root directory. It is highly advisable to move G2 into the Drupal folder or to create
                              a symbolic link in the Drupal directory pointing to your G2 installation (see
                              instructions on <a href="@codex">codex.gallery2.org</a>).',
                              array('@codex' => url('http://codex.gallery2.org/Integration:Drupal:Installation'))), 'error');
      }
    }
  }
}

954
/**
955
 * Function _gallery_install_plugins().
956
 */
957 958 959 960 961 962 963 964 965 966 967
function _gallery_install_plugins(&$install_status, $title = NULL, $collapse = FALSE) {
  $form['plugins'] = array(
    '#type' => 'fieldset',
    '#title' => isset($title) ? $title : t('Drupal Modules / Gallery2 Plugins'),
    '#collapsible' => TRUE,
    '#collapsed' => $collapse,
  );

  $header = array(t('Name'), t('Status'), t('Description'));
  $overall_plugin_severity = GALLERY_SEVERITY_UNKNOWN - 1;
  $overall_plugin_status = GALLERY_PLUGIN_ENABLED;
968
  
969 970 971 972 973 974 975 976 977
  // Wanted (required) G2 plugins
  $rows = array();
  $wanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED);
  foreach ($wanted_g2_plugins as $key => $module) {
    // Find the combination of status and severity of the plugin
    $severity = ($module['status'] != GALLERY_PLUGIN_ENABLED) ? $module['severity'] : GALLERY_SEVERITY_SUCCESS;
    $row = array();
    $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
    $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center');
978
    $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key);
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
    $rows[] = $row;
    if ($module['status'] != GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) {
      $overall_plugin_severity = $severity;
      $overall_plugin_status = $module['status'];
    }
  }
  $form['plugins']['wanted_g2_plugins'] = array(
    '#type' => 'fieldset',
    '#title' => t('Recommended Gallery2 plugins'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => theme('table', $header, $rows, array('class' => 'package')),
    '#description' => t('These Gallery2 plugins support much of the functionality that the Drupal Gallery module provides.
                         None of them are strictly required, but you will almost certainly want to activate at least some
                         of them (particularly the Image Block plugin).'),
  );

  // Unwanted (interfering) G2 plugins
  $rows = array();
  $unwanted_g2_plugins = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_UNWANTED);
  foreach ($unwanted_g2_plugins as $key => $module) {
    // Find the combination of status and severity of the plugin
    $severity = ($module['status'] == GALLERY_PLUGIN_ENABLED) ? $module['severity'] : GALLERY_SEVERITY_SUCCESS;
    $row = array();
    $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
    $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status'], TRUE, TRUE), 'align' => 'center');
1005
    $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key);
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
    $rows[] = $row;
    if ($module['status'] == GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) {
      $overall_plugin_severity = $severity;
      $overall_plugin_status = $module['status'];
    }
  }
  $form['plugins']['unwanted_g2_plugins'] = array(
    '#type' => 'fieldset',
    '#title' =>  t('Gallery2 plugins which should not be installed'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => theme('table', $header, $rows, array('class' => 'package')),
    '#description' => t('These Gallery2 plugins should not be used when Gallery2 is
                         embedded into Drupal as they may cause problems.'),
  );

  // Wanted (optional) Drupal modules
  $rows = array();
  $wanted_modules = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_DRUPAL);
  foreach ($wanted_modules as $key => $module) {
    // Find the combination of status and severity of the plugin
    $severity = $module['status'] ? GALLERY_SEVERITY_SUCCESS : $module['severity'];
    $row = array();
    $row[] = array('data' => $module['title'], 'align' => 'left', 'width' => '15%');
    $row[] = array('data' => theme('gallery_severity_status_message', $severity, $module['status']), 'align' => 'center');
1031
    $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => 'gallery-install-plugin-'. $key);
1032 1033 1034 1035 1036
    $rows[] = $row;
    if ($module['status'] != GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) {
      $overall_plugin_severity = $severity;
      $overall_plugin_status = $module['status'];
    }
1037
  }
1038 1039 1040 1041 1042 1043 1044 1045
  $form['plugins']['wanted_modules'] = array(
    '#type' => 'fieldset',
    '#title' =>  t('Optional Drupal modules'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => theme('table', $header, $rows, array('class' => 'package')),
    '#description' => t('These Drupal modules can optionally be used to enhance the functionality of the Gallery module.'),
  );
1046
  
1047 1048 1049 1050
  // Check if no issue was found.
  if ($overall_plugin_severity < GALLERY_SEVERITY_UNKNOWN) {
    $overall_plugin_severity = GALLERY_SEVERITY_SUCCESS;
  }
1051