function shorten_admin in Shorten URLs 7
Same name and namespace in other branches
- 6 shorten.admin.inc \shorten_admin()
- 7.2 shorten.admin.inc \shorten_admin()
Settings page.
1 string reference to 'shorten_admin'
- shorten_admin_form in ./
shorten.admin.inc - Returns HTML representing the shorten admin form.
File
- ./
shorten.admin.inc, line 19 - Settings for the Shorten module.
Code
function shorten_admin($form, $form_state) {
$form['shorten_www'] = array(
'#type' => 'checkbox',
'#title' => t('Use "www." instead of "http://"'),
'#description' => t('"www." is shorter, but "http://" is automatically link-ified by more services.'),
'#default_value' => variable_get('shorten_www', FALSE),
);
$methods = array();
if (function_exists('file_get_contents')) {
$methods['php'] = t('PHP');
}
if (function_exists('curl_exec')) {
$methods['curl'] = t('cURL');
}
if (empty($methods)) {
if (variable_get('shorten_method', _shorten_method_default()) != 'none') {
variable_set('shorten_method', 'none');
}
$form['shorten_method'] = array(
'#type' => 'radios',
'#title' => t('Method'),
'#description' => '<p>' . t('The method to use to retrieve the abbreviated URL.') . '</p>' . '<p><strong>' . t('Your PHP installation does not support the URL abbreviation feature of the Shorten module.') . '</strong> ' . t('You must compile PHP with either the cURL library or the file_get_contents() function to use this option.') . '</p>',
'#default_value' => 'none',
'#options' => array(
'none' => t('None'),
),
'#disabled' => TRUE,
);
$form['shorten_service'] = array(
'#type' => 'radios',
'#title' => t('Service'),
'#description' => t('The default service to use to create the abbreviated URL.'),
'#default_value' => 'none',
'#options' => array(
'none' => t('None'),
),
);
$form['shorten_service_backup'] = array(
'#type' => 'radios',
'#title' => t('Backup Service'),
'#description' => t('The service to use to create the abbreviated URL if the primary service is down.'),
'#default_value' => 'none',
'#options' => array(
'none' => t('None'),
),
);
}
else {
$form['shorten_method'] = array(
'#type' => 'radios',
'#title' => t('Method'),
'#description' => t('The method to use to retrieve the abbreviated URL. cURL is much faster, if available.'),
'#default_value' => variable_get('shorten_method', _shorten_method_default()),
'#options' => $methods,
);
$all_services = module_invoke_all('shorten_service');
$services = array();
foreach ($all_services as $key => $value) {
$services[$key] = $key;
}
$services['none'] = t('None');
$form['shorten_service'] = array(
'#type' => 'select',
'#title' => t('Service'),
'#description' => t('The default service to use to create the abbreviated URL.') . ' ' . t('If a service is not shown in this list, you probably need to configure it in the Shorten API Keys tab.'),
'#default_value' => variable_get('shorten_service', 'is.gd'),
'#options' => $services,
);
$form['shorten_service_backup'] = array(
'#type' => 'select',
'#title' => t('Backup Service'),
'#description' => t('The service to use to create the abbreviated URL if the primary or requested service is down.'),
'#default_value' => variable_get('shorten_service_backup', 'TinyURL'),
'#options' => $services,
);
$form['shorten_show_service'] = array(
'#type' => 'checkbox',
'#title' => t('Show the list of URL shortening services in the user interface'),
'#default_value' => variable_get('shorten_show_service', FALSE),
'#description' => t('Allow users to choose which service to use in the Shorten URLs block and page.'),
);
}
$form['shorten_use_alias'] = array(
'#type' => 'checkbox',
'#title' => t('Shorten aliased URLs where possible'),
'#description' => t('Where possible, generate shortened URLs based on the aliased version of a URL.') . ' <strong>' . t('Some integrated modules ignore this.') . '</strong>',
'#default_value' => variable_get('shorten_use_alias', 1),
);
$form['shorten_timeout'] = array(
'#type' => 'textfield',
'#title' => t('Time out URL shortening requests after'),
'#field_suffix' => ' ' . t('seconds'),
'#description' => t('Cancel retrieving a shortened URL if the URL shortening service takes longer than this amount of time to respond.') . ' ' . t('Lower values (or shorter timeouts) mean your site will respond more quickly if your URL shortening service is down.') . ' ' . t('However, higher values (or longer timeouts) give the URL shortening service more of a chance to return a value.') . ' ' . t('If a request to the primary service times out, the secondary service is used. If the secondary service times out, the original (long) URL is used.') . ' ' . t('You must enter a nonnegative integer. Enter 0 (zero) to wait for a response indefinitely.'),
'#size' => 3,
'#required' => TRUE,
'#default_value' => variable_get('shorten_timeout', 3),
);
$form['shorten_cache_duration'] = array(
'#type' => 'textfield',
'#title' => t('Cache shortened URLs for'),
'#field_suffix' => ' ' . t('seconds'),
'#description' => t('Shortened URLs are stored after retrieval to improve performance.') . ' ' . t('Enter the number of seconds for which you would like the shortened URLs to be stored.') . ' ' . t('Leave this field blank to store shortened URLs indefinitely (although this is not recommended).') . ' ' . t('The default value is 1814400 (3 weeks).'),
'#size' => 11,
'#default_value' => variable_get('shorten_cache_duration', 1814400),
);
$form['shorten_cache_fail_duration'] = array(
'#type' => 'textfield',
'#title' => t('On failure, cache full URLs for'),
'#field_suffix' => ' ' . t('seconds'),
'#description' => t('When a shortener service is unavilable, the full URL will be cached temporarily to prevent more requests from overloading the server.') . ' ' . t('Enter the number of seconds for which you would like to store these full URLs when shortening the URL fails.') . ' ' . t('The default value is 1800 (30 minutes).'),
'#size' => 11,
'#required' => TRUE,
'#default_value' => variable_get('shorten_cache_fail_duration', 1800),
);
$form['shorten_cache_clear_all'] = array(
'#type' => 'checkbox',
'#title' => t('Clear Shorten URLs cache when all Drupal caches are cleared.'),
'#description' => t('Sometimes Drupal automatically clears all caches, such as after running database updates.') . ' ' . t('However, regenerating the cache of shortened URLs can be performance-intensive, and the cache does not affect Drupal behaviors.') . ' ' . t('To avoid regenerating this cache after clearing all Drupal caches, un-check this option.') . ' ' . t('Note that if you need to completely clear this cache, un-checking this option will require that you do it manually.'),
'#default_value' => variable_get('shorten_cache_clear_all', TRUE),
);
unset($services['none']);
$form['shorten_invisible_services'] = array(
'#type' => 'checkboxes',
'#title' => t('Disallowed services'),
'#description' => t('Checking the box next to a service will make it <strong>unavailable</strong> for use in the Shorten URLs block and page.') . ' ' . t('If you disallow all services, the primary service will be used.'),
'#default_value' => variable_get('shorten_invisible_services', array()),
'#options' => array_map('check_plain', $services),
);
return system_settings_form($form);
}