array( 'title' => 'PHP Memory Limit', 'severity' => GALLERY_SEVERITY_ERROR, ), 'locations' => array( 'title' => 'Gallery2 locations', 'severity' => GALLERY_SEVERITY_ERROR, ), 'plugins' => array( 'title' => 'Drupal Modules / Gallery2 Plugins', 'severity' => GALLERY_SEVERITY_WARNING, ), 'cleanurls' => array( 'title' => 'Clean URL / URL Rewrite', 'severity' => GALLERY_SEVERITY_WARNING, ), 'usersync' => array( 'title' => 'Initial User Synchronization', 'severity' => GALLERY_SEVERITY_ERROR, ), ); if (!isset($form_values)) { $form_values = array(); $form_values['step'] = GALLERY_INSTALL_STEP_PHPMEMORY; $form_values['gallery_valid'] = FALSE; $form_values['initial_check'] = TRUE; if (variable_get('gallery_config_reset', FALSE)) { $form_values['initial_check'] = FALSE; variable_del('gallery_config_reset'); } } else { // Work around a D5 design flaw // manage $form_values to allow the same form to be submitted more than once $form_values = unserialize(variable_get('gallery_wizard_data', array())); $form_values['initial_check'] = FALSE; } $form['install_status'] = array( '#type' => 'fieldset', '#title' => t('Install status'), '#collapsible' => FALSE, '#collapsed' => FALSE, '#description' => t('Correct configuration of the following items is essential for the embedded gallery to function properly.'), ); // Step 1: Check PHP Memory if ($form_values['step'] >= GALLERY_INSTALL_STEP_PHPMEMORY) { _gallery_install_step_php_memory($form, $form_values, $install_status); } // Step 2 : Gallery2 Locations if ($form_values['step'] >= GALLERY_INSTALL_STEP_LOCATIONS) { _gallery_install_step_locations($form, $form_values, $install_status); } // Step 3: Drupal Modules and Gallery2 Plugins check if ($form_values['step'] >= GALLERY_INSTALL_STEP_PLUGINS) { _gallery_install_step_plugins($form, $form_values, $install_status); } // Step 4: Clean URL configuration if ($form_values['step'] >= GALLERY_INSTALL_STEP_URLREWRITE) { _gallery_install_step_urlrewrite($form, $form_values, $install_status); } // Step 5: User Synchronization if ($form_values['step'] >= GALLERY_INSTALL_STEP_USERSYNC) { _gallery_install_step_usersync($form, $form_values, $install_status); } $form['initial_check'] = array( '#type' => 'hidden', '#value' => $form_values['initial_check'], ); $form['gallery_valid'] = array( '#type' => 'hidden', '#value' => $form_values['gallery_valid'], ); $form['plugins_valid'] = array( '#type' => 'hidden', '#value' => $form_values['plugins_valid'], ); $form['step'] = array( '#type' => 'hidden', '#value' => $form_values['step'], ); $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset & Restart')); // Set the global status variable 'gallery_valid' gallery_set_status(array( 'gallery_valid' => array( 'title' => t('Overall Status (Installation)'), 'severity' => $form_values['gallery_valid'] ? GALLERY_SEVERITY_SUCCESS : GALLERY_SEVERITY_ERROR, ), )); // Create install status table $error = FALSE; $rows = array(); foreach ($install_status as $key => $step_status) { // Find the combination of status and severity of the plugin $severity = ($step_status['status'] <= 0) ? $step_status['severity'] : GALLERY_SEVERITY_SUCCESS; if (!$step_status['status']) { $error = TRUE; } $row = array(); $row[] = array('data' => $step_status['title'], 'align' => 'left', 'width' => '20%'); $row[] = array('data' => theme('gallery_severity_message', $severity), 'align' => 'center'); $row[] = array('data' => $step_status['info'], 'class' => 'description', 'id' => $key); $rows[] = $row; } if ($error && !$form_values['initial_check']) { $rows[] = array(array( 'data' => t('Critical errors are present. Your Gallery is not available.'), 'colspan' => '3', 'align' => 'center', 'class' => 'message') ); } $header = array('Step', 'Status', 'Description'); $form['install_status']['status']['#value'] = theme('table', $header, $rows, array('class' => 'package')); return $form; } /** * Function _gallery_install_step_php_memory(). * Step 1: Check PHP Memory */ function _gallery_install_step_php_memory(&$form, &$form_values, &$install_status) { $phpmemory_info = _gallery_php_mem_check(); $desc = $phpmemory_info['info']; if (!$phpmemory_info['status']) { $desc .= ' '. t('Until this is fixed your Gallery2 cannot be installed.'); $form_values['step'] = GALLERY_INSTALL_STEP_PHPMEMORY; } else { $form_values['step']++; } $form['phpmemory'] = array( '#type' => 'fieldset', '#title' => t('Step 1: PHP Memory Test') . ($phpmemory_info['status'] ? ' '. t('(OK)') : ''), '#description' => $desc, '#collapsible' => ($form_values['step'] > GALLERY_INSTALL_STEP_PHPMEMORY), '#collapsed' => $phpmemory_info['status'], ); if (!$phpmemory_info['status']) { $form['phpmemory']['check'] = array('#type' => 'submit', '#value' => t('Check PHP memory again')); } $install_status['phpmemory']['status'] = $phpmemory_info['status']; $install_status['phpmemory']['info'] = $phpmemory_info['info']; } /** * Function _gallery_install_step_locations(). * Step 2: Gallery2 Locations */ function _gallery_install_step_locations(&$form, &$form_values, &$install_status) { if ($form_values['step'] > GALLERY_INSTALL_STEP_LOCATIONS || $form_values['initial_check']) { _gallery_install_locations($form, $form_values, $install_status); } // Check was not successful. Don't proceed with step 3 if (!$form_values['gallery_valid']) { $form_values['step'] = GALLERY_INSTALL_STEP_LOCATIONS; } else { $form_values['step']++; } $autodetect_dir = variable_get('gallery_autodetect_dir', 1); $extra = $autodetect_dir ? t('- Auto Configuration') : t('- Manual Configuration'); // If 'initial_check' = True then this is the first time the user has come through this // step (or the wizard has been restarted). Allow the field to be edited EVEN IF VALID. // If 'initial_check' = False then this step has been completed already, so make read-only. if (!$form_values['gallery_valid']) { $desc = $autodetect_dir ? t('Enter the \'Gallery2 URL or URI\' and click \'Test location settings\' 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.'); } else { $desc = ''; } $form['install'] = array( '#type' => 'fieldset', '#title' => t('Step 2: Gallery2 location settings') .' '. $extra . ($form_values['gallery_valid'] ? ' '. t('(OK)') : ''), '#description' => isset($form['install']['#description']) ? ($desc .'
'. $form['install']['#description'] .'
') : $desc, '#collapsible' => ($form_values['step'] > GALLERY_INSTALL_STEP_LOCATIONS), '#collapsed' => $form_values['gallery_valid'], ); // Only provide these values when autoconfig has been set. Otherwise the user might think // that these had been automatically figured out even though manual config was done. if ($autodetect_dir) { $gallery_uri = isset($form_values['gallery_uri_auto']) ? $form_values['gallery_uri_auto'] : ($form_values['gallery_valid'] ? variable_get('gallery_uri', '/gallery2/') : ''); $gallery_dir = isset($form_values['gallery_dir_auto']) ? $form_values['gallery_dir_auto'] : ($form_values['gallery_valid'] ? variable_get('gallery_dir', './gallery2/') : ''); $embed_uri = isset($form_values['gallery_embed_uri_auto']) ? $form_values['gallery_embed_uri_auto'] : ($form_values['gallery_valid'] ? variable_get('gallery_embed_uri', '?q=gallery') : ''); $form['install']['gallery_uri_auto'] = array( '#type' => 'textfield', '#title' => t('Gallery2 URL or URI'), '#default_value' => $gallery_uri, '#size' => 64, '#maxlength' => 128, '#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' => $form_values['gallery_valid'], ); if (!empty($gallery_dir)) { $form['install']['gallery_dir_auto_item'] = array( '#title' => t('Gallery2 filesystem path'), '#type' => 'item', '#value' => $gallery_dir, ); } $form['install']['gallery_dir_auto'] = array( '#type' => 'value', '#value' => $gallery_dir, ); if (!empty($gallery_dir)) { $form['install']['gallery_embed_uri_auto_item'] = array( '#title' => t('Embed URI'), '#type' => 'item', '#value' => $embed_uri, ); } $form['install']['gallery_embed_uri_auto'] = array( '#type' => 'value', '#value' => $embed_uri, ); } else { $gallery_uri = isset($form_values['gallery_uri_man']) ? $form_values['gallery_uri_man'] : ($form_values['gallery_valid'] ? variable_get('gallery_uri', '/gallery2/') : ''); $gallery_dir = isset($form_values['gallery_dir_man']) ? $form_values['gallery_dir_man'] : ($form_values['gallery_valid'] ? variable_get('gallery_dir', './gallery2/') : ''); $embed_uri = isset($form_values['gallery_embed_uri_man']) ? $form_values['gallery_embed_uri_man'] : ($form_values['gallery_valid'] ? variable_get('gallery_embed_uri', '?q=gallery') : ''); $form['install']['gallery_uri_man'] = array( '#type' => 'textfield', '#title' => t('Gallery2 URL or URI'), '#default_value' => $gallery_uri, '#size' => 64, '#maxlength' => 128, '#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' => $form_values['gallery_valid'], ); $form['install']['gallery_dir_man'] = array( '#type' => 'textfield', '#title' => t('Gallery2 filesystem path'), '#default_value' => $gallery_dir, '#size' => 64, '#maxlength' => 128, '#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' => $form_values['gallery_valid'], ); $form['install']['gallery_embed_uri_man'] = array( '#type' => 'textfield', '#title' => t('Embed URI'), '#default_value' => $embed_uri, '#size' => 64, '#maxlength' => 128, '#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' => $form_values['gallery_valid'], ); } if (!$form_values['gallery_valid']) { $form['install']['location_button'] = array( '#type' => 'submit', '#value' => t('Test location settings'), ); if ($autodetect_dir) { $form['install']['manual_config_button'] = array( '#type' => 'submit', '#value' => t('Use Manual Configuration'), ); } else { $form['install']['auto_config_button'] = array( '#type' => 'submit', '#value' => t('Use Auto Configuration'), ); } } } /** * Function _gallery_install_step_plugins(). * Step 3: Drupal Modules / Gallery2 Plugins */ function _gallery_install_step_plugins(&$form, &$form_values, &$install_status) { $form['plugins'] = array( '#type' => 'fieldset', '#title' => t('Step 3: Drupal Modules / Gallery2 Plugins'), '#collapsible' => ($form_values['step'] > GALLERY_INSTALL_STEP_PLUGINS), '#collapsed' => FALSE, ); $header = array('Name', 'Status', 'Description'); $overall_plugin_severity = GALLERY_SEVERITY_UNKNOWN - 1; $overall_plugin_status = GALLERY_PLUGIN_ENABLED; // Wanted (required) G2 plugins $wanted_g2_plugins = gallery_wanted_plugin_info(); $rows = array(); 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'); $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key); $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 $unwanted_g2_plugins = gallery_unwanted_plugin_info(); $rows = array(); 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'); $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key); $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 $wanted_modules = gallery_wanted_module_info(); $rows = array(); foreach ($wanted_modules as $key => $module) { // Find the combination of status and severity of the plugin $severity = (!$module['status']) ? $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'); $row[] = array('data' => $module['info'], 'class' => 'description', 'id' => $key); $rows[] = $row; if ($module['status'] != GALLERY_PLUGIN_ENABLED && $severity > $overall_plugin_severity) { $overall_plugin_severity = $severity; $overall_plugin_status = $module['status']; } } $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.'), ); // Check if no issue was found. if ($overall_plugin_severity < GALLERY_SEVERITY_UNKNOWN) { $overall_plugin_severity = GALLERY_SEVERITY_SUCCESS; } $install_status['plugins']['status'] = $overall_plugin_status; $install_status['plugins']['severity'] = $overall_plugin_severity; if ($overall_plugin_status <= 0) { // There is a problem with at least one module/plugin $form_values['plugins_valid'] = FALSE; $form['plugins']['#title'] .= ' ('. strip_tags(theme('gallery_severity_message', $overall_plugin_severity)) .')'; $install_status['plugins']['info'] = t('You may have some loss in functionality in your embedded Gallery2 (see below for details). You should check the details and if the functionality is not important for your site you can just ignore this.'); $form['plugins']['#collapsed'] = !$form_values['initial_check']; if ($form_values['initial_check']) { $form_values['step']++; } } else { $form_values['step']++; $form_values['plugins_valid'] = TRUE; $form['plugins']['#collapsible'] = TRUE; $form['plugins']['#collapsed'] = TRUE; $form['plugins']['#title'] .= ' '. t('(OK)'); $install_status['plugins']['info'] = t('The status of all Drupal modules and Gallery2 plugins is optimal for your embedded Gallery2.'); } } /** * Function _gallery_install_step_urlrewrite(). * Step 4: Clean URL configuration */ function _gallery_install_step_urlrewrite(&$form, &$form_values, &$install_status) { $form['rewrite'] = array('#type' => 'fieldset'); $clean_urls_status = variable_get('clean_url', 0); $rewrite_status = gallery_single_plugin_status('rewrite'); if ($clean_urls_status) { if ($rewrite_status == GALLERY_PLUGIN_ENABLED) { _gallery_install_urlrewrite($public_path, $htaccess_path, TRUE); $public_path = isset($form_values['htaccess_public_path']) ? $form_values['htaccess_public_path'] : $public_path; $htaccess_path = isset($form_values['htaccess_filesystem_path']) ? $form_values['htaccess_filesystem_path'] : $htaccess_path; // Check for writable .htaccess file if (file_exists($htaccess_path .'.htaccess')) { if (is_writable($htaccess_path .'.htaccess')) { $form_values['rewrite_valid'] = ($form_values['initial_check'] || $form_values['step'] > GALLERY_INSTALL_STEP_URLREWRITE); $result = t('There is a writable .htaccess file in your defined Drupal directory (@dir).', array('@dir' => $htaccess_path)); // Check syntax of the 'Show Item' rule (must start with 'gallery/') list ($ret, $rules) = GalleryCoreApi::getPluginParameter('module', 'rewrite', 'activeRules'); if (!$ret) { $rules = unserialize($rules); if (isset($rules['rewrite'][0]['pattern']) && substr($rules['rewrite'][0]['pattern'], 0, 7) != 'gallery') { $result .= ' '. t('Your \'Show Item\' rule should start with \'gallery/\'. Make sure to change the URL Rewrite rule(s) accordingly.') .''; } } } else { $form_values['rewrite_valid'] = FALSE; $result = t('The .htaccess file in your defined Drupal directory (@dir) is not writable. Please CHMOD it to 644 (or 666 if 644 does not work).', array('@dir' => $htaccess_path)); } } else { $form_values['rewrite_valid'] = FALSE; $result = t('There is no .htaccess file in your defined Drupal directory (@dir) or the directory does not exist.', array('@dir' => $htaccess_path)); } } else { $form_values['rewrite_valid'] = FALSE; $result = t('Clean URLs are enabled in Drupal, but the Gallery2 URL Rewrite plugin is unavailable.'); } } else { $form_values['rewrite_valid'] = TRUE; $result = t('Clean URLs are disabled in Drupal and the URL Rewrite plugin will not be configured.'); $form['rewrite']['#description'] = t('Clean URLs are disabled in Drupal and the URL Rewrite plugin will not be configured. If you want to use the URL Rewrite plugin please enable clean URLs in Drupal and install and activate the plugin in Gallery2.'); } // User selected to skip the URLRewrite step if (variable_get('gallery_rewrite_disable', 0)) { $form_values['rewrite_valid'] = TRUE; $clean_urls_status = FALSE; $result = $form['rewrite']['#description'] = t('URL Rewrite has been disabled manually.'); $form['rewrite']['#description'] .= ' '. t('\'Reset & Restart\' your configuration to change these settings.'); } if ($form_values['rewrite_valid']) { $form_values['step']++; } $form['rewrite']['#title'] = t('Step 4: Clean URLs / URL Rewrite settings') . ($form_values['rewrite_valid'] ? ' '. t('(OK)') : ''); $form['rewrite']['#collapsible'] = ($form_values['step'] > GALLERY_INSTALL_STEP_URLREWRITE); $form['rewrite']['#collapsed'] = $form_values['rewrite_valid']; if ($clean_urls_status) { if ($rewrite_status < GALLERY_PLUGIN_ENABLED) { $form['rewrite']['#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))); if (!$form_values['initial_check'] && !$form_values['rewrite_valid']) { $form_values['step'] = GALLERY_INSTALL_STEP_URLREWRITE; $form['rewrite']['check'] = array('#type' => 'submit', '#value' => t('Check URL Rewrite status again')); } } else { // CleanURL and URLRewrite are both enabled $form['rewrite']['#description'] = t('Clean URLs are !clean_url_status in Drupal and the Gallery2 URL Rewrite plugin is !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.', array( '!clean_url_status' => theme('gallery_module_status_message', $clean_urls_status), '!rewrite_status' => theme('gallery_plugin_status_message', $rewrite_status) ) ); $form['rewrite']['#description'] .= $form_values['rewrite_valid'] ? '' : (''. $result .'
'); $form['rewrite']['htaccess_public_path'] = array( '#type' => 'textfield', '#title' => t('Public path to your .htaccess file'), '#size' => 64, '#maxlength' => 255, '#default_value' => $public_path, '#description' => t('This is the location of your Drupal .htaccess file relative to your webserver document root.'), '#disabled' => $form_values['rewrite_valid'], ); $form['rewrite']['htaccess_filesystem_path'] = array( '#type' => 'textfield', '#title' => t('Filesystem path to your .htaccess file'), '#size' => 100, '#maxlength' => 255, '#default_value' => $htaccess_path, '#description' => t('This is the absolute directory path of your Drupal .htaccess file.'), '#disabled' => $form_values['rewrite_valid'], ); if (!$form_values['initial_check'] && !$form_values['rewrite_valid']) { $form['rewrite']['config'] = array('#type' => 'submit', '#value' => t('Configure URL Rewrite plugin')); } } if (!$form_values['initial_check'] && !$form_values['rewrite_valid']) { $form['rewrite']['skip'] = array('#type' => 'submit', '#value' => t('Skip URL Rewrite Config')); } } $install_status['cleanurls']['status'] = $form_values['rewrite_valid']; $install_status['cleanurls']['info'] = $result; } /** * Function _gallery_install_step_usersync(). * Step 5: User Synchronization */ function _gallery_install_step_usersync(&$form, &$form_values, &$install_status) { $form_values['gallery_valid'] = variable_get('gallery_valid', 0); if ($form_values['gallery_valid']) { $form_values['step']++; } $form['usersync'] = array( '#type' => 'fieldset', '#title' => t('Step 5: Initial User Synchronization') . ($form_values['gallery_valid'] ? ' '. t('(OK)') : ''), '#collapsible' => ($form_values['step'] > GALLERY_INSTALL_STEP_USERSYNC), '#collapsed' => ($form_values['gallery_valid']), ); $install_status['usersync']['status'] = $form_values['gallery_valid']; if ($form_values['gallery_valid']) { $install_status['usersync']['info'] = $form['usersync']['#description'] = t('Your initial user synchronization has been completed already.'. $errstr .'', 'error'); return FALSE; } } return TRUE; }