Commit 198855ed authored by nicholasThompson's avatar nicholasThompson

Re-merging Drupal 6 work up to Drupal 7, incuding a SimpleTest.

parent f2b9430c
......@@ -10,61 +10,129 @@
* Function to generate the form setting array
*/
function globalredirect_settings() {
$form['globalredirect_deslash'] = array(
'#type' => 'radios',
$settings = _globalredirect_get_settings();
$form['settings'] = array(
'#tree' => TRUE,
);
$form['settings']['deslash'] = array(
'#type' => 'checkbox',
'#title' => t('Deslash'),
'#description' => t('If enabled, this option will remove the trailing slash from requests. This stops requests such as <code>example.com/node/1/</code> failing to match the corresponding alias and can cause duplicate content. On the other hand, if you require certain requests to have a trailing slash, this feature can cause problems so may need to be disabled.'),
'#options' => array(
GLOBALREDIRECT_FEATURE_DISABLED => t('Off'),
GLOBALREDIRECT_DESLASH_ENABLED => t('On'),
),
'#default_value' => variable_get('globalredirect_deslash', GLOBALREDIRECT_DESLASH_ENABLED),
'#default_value' => $settings['deslash'],
);
$form['globalredirect_nonclean2clean'] = array(
'#type' => 'radios',
$form['settings']['nonclean_to_clean'] = array(
'#type' => 'checkbox',
'#title' => t('Non-clean to Clean'),
'#description' => t('If enabled, this option will redirect from non-clean to clean URL (if Clean URL\'s are enabled). This will stop, for example, node 1 existing on both <code>example.com/node/1</code> AND <code>example.com?q=node/1</code>.'),
'#options' => array(
GLOBALREDIRECT_FEATURE_DISABLED => t('Off'),
GLOBALREDIRECT_NONCLEAN2CLEAN_ENABLED => t('On'),
),
'#default_value' => variable_get('globalredirect_nonclean2clean', GLOBALREDIRECT_NONCLEAN2CLEAN_ENABLED),
'#default_value' => $settings['nonclean_to_clean'],
);
$form['globalredirect_trailingzero'] = array(
$form['settings']['trailing_zero'] = array(
'#type' => 'radios',
'#title' => t('Remove Trailing Zero Argument'),
'#description' => t('If enabled, any instance of "/0" will be trimmed from the right of the URL. This stops duplicate pages such as "taxonomy/term/1" and "taxonomy/term/1/0" where 0 is the default depth. There is an option of limiting this feature to taxonomy term pages ONLY or allowing it to effect any page. <strong>By default this feature is disabled to avoid any unexpected behavior</strong>'),
'#description' => t('If enabled, any instance of "/0" will be trimmed from the right of the URL. This stops duplicate pages such as "taxonomy/term/1" and "taxonomy/term/1/0" where 0 is the default depth. There is an option of limiting this feature to taxonomy term pages ONLY or allowing it to effect any page. <strong>By default this feature is disabled to avoid any unexpected behavior. Also of note, the trailing /0 "depth modifier" was removed from Drupal 7.</strong>'),
'#options' => array(
GLOBALREDIRECT_FEATURE_DISABLED => t('Disabled'),
GLOBALREDIRECT_TRAILINGZERO_TAXTERM => t('Enabled for taxonomy term pages only'),
GLOBALREDIRECT_TRAILINGZERO_ALL => t('Enabled for all pages'),
0 => t('Disabled'),
1 => t('Enabled for all pages'),
2 => t('Enabled for taxonomy term pages only'),
),
'#default_value' => variable_get('globalredirect_trailingzero', GLOBALREDIRECT_FEATURE_DISABLED),
'#default_value' => $settings['trailing_zero'],
);
$form['globalredirect_menu_check'] = array(
'#type' => 'radios',
$form['settings']['menu_check'] = array(
'#type' => 'checkbox',
'#title' => t('Menu Access Checking'),
'#description' => t('If enabled, the module will check the user has access to the page before redirecting. This helps to stop redirection on protected pages and avoids giving away <em>secret</em> URL\'s. <strong>By default this feature is disabled to avoid any unexpected behavior</strong>'),
'#options' => array(
GLOBALREDIRECT_FEATURE_DISABLED => t('Disabled'),
GLOBALREDIRECT_MENU_CHECK_ENABLED => t('Enabled'),
),
'#default_value' => variable_get('globalredirect_menu_check', GLOBALREDIRECT_FEATURE_DISABLED),
'#default_value' => $settings['menu_check'],
);
$form['globalredirect_case_sensitive_urls'] = array(
'#type' => 'radios',
$form['settings']['case_sensitive_urls'] = array(
'#type' => 'checkbox',
'#title' => t('Case Sensitive URL Checking'),
'#description' => t('If enabled, the module will compare the current URL to the alias stored in the system. If there are any differences in case then the user will be redirected to the correct URL.'),
'#options' => array(
GLOBALREDIRECT_FEATURE_DISABLED => t('Disabled'),
GLOBALREDIRECT_CASE_SENSITIVE_URLS_ENABLED => t('Enabled'),
),
'#default_value' => variable_get('globalredirect_case_sensitive_urls', GLOBALREDIRECT_CASE_SENSITIVE_URLS_ENABLED),
'#default_value' => $settings['case_sensitive_urls'],
);
$form['settings']['language_redirect'] = array(
'#type' => 'checkbox',
'#title' => t('Language Path Checking'),
'#description' => t('If enabled, the module will check that the page being viewed matches the language in the URL or the system default. For example, viewing a French node while the site is in English will cause a redirect to the English node.'),
'#default_value' => $settings['language_redirect'],
);
return system_settings_form($form);
$form['settings']['canonical'] = array(
'#type' => 'checkbox',
'#title' => t('Add Canonical Link'),
'#description' => t('If enabled, will add a <a href="!canonical">canonical link</a> to each page.', array('!canonical' => 'http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html')),
'#default_value' => $settings['canonical'],
);
$form['settings']['content_location_header'] = array(
'#type' => 'checkbox',
'#title' => t('Set Content Location Header'),
'#description' => t('If enabled, will add a <a href="!canonical">Content-Location</a> header.', array('!canonical' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14')),
'#default_value' => $settings['content_location_header'],
);
$form['settings']['term_path_handler'] = array(
'#type' => 'checkbox',
'#title' => t('Taxonomy Term Path Handler'),
'#description' => t('If enabled, any request to a taxonomy/term/[tid] page will check that the correct path is being used for the term\'s vocabulary.'),
'#default_value' => $settings['term_path_handler'],
);
$form['buttons']['submit'] = array('#type' => 'submit', '#submit' => array('globalredirect_settings_submit_save'), '#value' => t('Save Configuration') );
$form['buttons']['reset'] = array('#type' => 'submit', '#submit' => array('globalredirect_settings_submit_reset'), '#value' => t('Reset to defaults') );
return $form;
}
/**
* Save submit handler for the globalredirect_settings form.
* Compares the submitted settings to the defaults and unsets any that are equal. This was we only store overrides.
*/
function globalredirect_settings_submit_save($form_id, &$form_state) {
// Grab the defaults
$defaults = _globalredirect_get_settings(TRUE);
// Copy out the settings
$settings = $form_state['values']['settings'];
// Compare each setting to the default. If equal, remove. If not, cast to an int (FormAPI converts keys to string).
foreach ($settings as $key => $value) {
if ($value == $defaults[$key]) {
unset($settings[$key]);
}
else {
$settings[$key] = (int)$value;
}
}
// If we've ended up with an empty settings array, delete the settings variable...
if (empty($settings)) {
variable_del('globalredirect_settings');
}
// ... otherwise store the settings
else {
variable_set('globalredirect_settings', $settings);
}
drupal_set_message(t('Globalredirect settings have been saved.'));
}
/**
* Reset submit handler for the globalredirect_settings form.
* This simply deletes any overridden settings which forces the system to fallback to defaults
*/
function globalredirect_settings_submit_reset($form_id, &$form_state) {
variable_del('globalredirect_settings');
drupal_set_message(t('Globalredirect settings have been reset to default.'));
}
; $Id$
name = Global Redirect
description = "Searches for an alias of the current URL and 301 redirects if found. Stops duplicate content arising when path module is enabled."
dependencies[] = path
core = 7.x
files[] = globalredirect.module
files[] = globalredirect.install
files[] = globalredirect.admin.inc
files[] = globalredirect.test
......@@ -10,11 +10,7 @@
* Implements hook_uninstall().
*/
function globalredirect_uninstall() {
variable_del('globalredirect_menu_check');
variable_del('globalredirect_deslash');
variable_del('globalredirect_trailingzero');
variable_del('globalredirect_nonclean2clean');
variable_del('globalredirect_case_sensitive_urls');
variable_del('globalredirect_settings');
}
/**
......@@ -24,4 +20,49 @@ function globalredirect_update_6100() {
$deslash = variable_get('globalredirect_deslah', variable_get('globalredirect_deslash', 1));
variable_set('globalredirect_deslash', $deslash);
variable_del('globalredirect_deslah');
return array();
}
function globalredirect_update_6101() {
$ret = array();
// Get the default settings
$defaults = _globalredirect_get_settings(TRUE);
// Define a settings array based on the variables already set (or their defaults)
$settings = array(
'deslash' => (int)variable_get('globalredirect_deslash', 1),
'nonclean_to_clean' => (int)variable_get('globalredirect_nonclean2clean', 1),
'trailing_zero' => variable_get('globalredirect_trailingzero', 0),
'menu_check' => (int)variable_get('globalredirect_menu_check', 0),
'case_sensitive_urls' => (int)variable_get('globalredirect_case_sensitive_urls', 1),
);
// If a setting matches the default value, unset it (we wont need to store it)
foreach ($settings as $key => $value) {
// We used to use -1 for disabled, convert this to 0 for the new diabled
if ($value == -1) {
$settings[$key] = 0;
}
// Now compare the value to the defaults. Only store if an "override".
if ($value == $defaults[$key]) {
unset($settings[$key]);
}
}
// Save the settings in a single array rather than individual keys
if (!empty($settings)) {
variable_set('globalredirect_settings', $settings);
}
// Remove all the old settings
variable_del('globalredirect_deslash');
variable_del('globalredirect_nonclean2clean');
variable_del('globalredirect_trailingzero');
variable_del('globalredirect_trailingzero');
variable_del('globalredirect_menu_check');
variable_del('globalredirect_case_sensitive_urls');
return array();
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment