Commit d9588de9 authored by Dries's avatar Dries

- Patch #1496654 by alexpott, tobiasb: convert aggregator admin form to configuration system.

parent c21ddb75
......@@ -435,7 +435,7 @@ function aggregator_admin_form($form, $form_state) {
'#title' => t('Allowed HTML tags'),
'#size' => 80,
'#maxlength' => 255,
'#default_value' => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
'#default_value' => config('aggregator.settings')->get('items.allowed_html'),
'#description' => t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),
);
......@@ -484,7 +484,7 @@ function aggregator_admin_form($form, $form_state) {
'#title' => t('Fetcher'),
'#description' => t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'),
'#options' => $fetchers,
'#default_value' => variable_get('aggregator_fetcher', 'aggregator'),
'#default_value' => config('aggregator.settings')->get('fetcher'),
);
}
if (count($parsers) > 1) {
......@@ -493,7 +493,7 @@ function aggregator_admin_form($form, $form_state) {
'#title' => t('Parser'),
'#description' => t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'),
'#options' => $parsers,
'#default_value' => variable_get('aggregator_parser', 'aggregator'),
'#default_value' => config('aggregator.settings')->get('parser'),
);
}
if (count($processors) > 1) {
......@@ -502,7 +502,7 @@ function aggregator_admin_form($form, $form_state) {
'#title' => t('Processors'),
'#description' => t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'),
'#options' => $processors,
'#default_value' => variable_get('aggregator_processors', array('aggregator')),
'#default_value' => config('aggregator.settings')->get('processors'),
);
}
if (count($basic_conf)) {
......@@ -519,23 +519,31 @@ function aggregator_admin_form($form, $form_state) {
// Implementing modules will expect an array at $form['modules'].
$form['modules'] = array();
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
return system_config_form($form, $form_state);
}
/**
* Form submission handler for aggregator_admin_form().
*/
function aggregator_admin_form_submit($form, &$form_state) {
$config = config('aggregator.settings');
$config
->set('items.allowed_html', $form_state['values']['aggregator_allowed_html_tags'])
->set('items.expire', $form_state['values']['aggregator_clear'])
->set('items.teaser_length', $form_state['values']['aggregator_teaser_length'])
->set('source.list_max', $form_state['values']['aggregator_summary_items'])
->set('source.category_selector', $form_state['values']['aggregator_category_selector']);
if (isset($form_state['values']['aggregator_fetcher'])) {
$config->set('fetcher', $form_state['values']['aggregator_fetcher']);
}
if (isset($form_state['values']['aggregator_parser'])) {
$config->set('parser', $form_state['values']['aggregator_parser']);
}
if (isset($form_state['values']['aggregator_processors'])) {
$form_state['values']['aggregator_processors'] = array_filter($form_state['values']['aggregator_processors']);
$config->set('processors', array_filter($form_state['values']['aggregator_processors']));
}
system_settings_form_submit($form, $form_state);
$config->save();
}
/**
......
......@@ -5,20 +5,6 @@
* Install, update and uninstall functions for the aggregator module.
*/
/**
* Implements hook_uninstall().
*/
function aggregator_uninstall() {
variable_del('aggregator_allowed_html_tags');
variable_del('aggregator_summary_items');
variable_del('aggregator_clear');
variable_del('aggregator_category_selector');
variable_del('aggregator_fetcher');
variable_del('aggregator_parser');
variable_del('aggregator_processors');
variable_del('aggregator_teaser_length');
}
/**
* Implements hook_schema().
*/
......@@ -271,3 +257,21 @@ function aggregator_schema() {
return $schema;
}
/**
* Moves aggregator settings from variables to config.
*
* @ingroup config_upgrade
*/
function aggregrator_update_8000() {
update_variables_to_config('aggregator.settings', array(
'aggregator_fetcher' => 'fetcher',
'aggregator_parser' => 'parser',
'aggregator_processors' => 'processors',
'aggregator_allowed_html_tags' => 'items.allowed_html',
'aggregator_teaser_length' => 'items.teaser_length',
'aggregator_clear' => 'items.expire',
'aggregator_summary_items' => 'source.list_max',
'aggregator_category_selector' => 'source.category_selector',
));
}
......@@ -596,14 +596,15 @@ function aggregator_remove($feed) {
* An array containing the fetcher, parser, and processors.
*/
function _aggregator_get_variables() {
$fetcher = variable_get('aggregator_fetcher', 'aggregator');
$config = config('aggregator.settings');
$fetcher = $config->get('fetcher');
$parser = variable_get('aggregator_parser', 'aggregator');
$parser = $config->get('parser');
if ($parser == 'aggregator') {
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'aggregator') . '/aggregator.parser.inc';
}
$processors = variable_get('aggregator_processors', array('aggregator'));
$processors = $config->get('processors');
if (in_array('aggregator', $processors)) {
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'aggregator') . '/aggregator.processor.inc';
}
......@@ -747,7 +748,7 @@ function theme_aggregator_block_item($variables) {
* The filtered content.
*/
function aggregator_filter_xss($value) {
return filter_xss($value, preg_split('/\s+|<|>/', variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), -1, PREG_SPLIT_NO_EMPTY));
return filter_xss($value, preg_split('/\s+|<|>/', config('aggregator.settings')->get('items.allowed_html'), -1, PREG_SPLIT_NO_EMPTY));
}
/**
......@@ -775,9 +776,12 @@ function aggregator_sanitize_configuration() {
}
}
if ($reset) {
variable_del('aggregator_fetcher');
variable_del('aggregator_parser');
variable_del('aggregator_processors');
// Reset aggregator config if necessary using the module defaults.
config('aggregator.settings')
->set('fetcher', 'aggregator')
->set('parser', 'aggregator')
->set('processors', array('aggregator' => 'aggregator'))
->save();
return TRUE;
}
return FALSE;
......
......@@ -219,7 +219,7 @@ function aggregator_categorize_items($items, $feed_source = '') {
}
$done = TRUE;
$form['categories'][$item->iid] = array(
'#type' => variable_get('aggregator_category_selector', 'checkboxes'),
'#type' => config('aggregator.settings')->get('source.category_selector'),
'#default_value' => $selected,
'#options' => $categories,
'#size' => 10,
......@@ -356,8 +356,9 @@ function aggregator_page_sources() {
foreach ($result as $feed) {
// Most recent items:
$summary_items = array();
if (variable_get('aggregator_summary_items', 3)) {
$items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = :fid ORDER BY i.timestamp DESC', 0, variable_get('aggregator_summary_items', 3), array(':fid' => $feed->fid));
$aggregator_summary_items = config('aggregator.settings')->get('source.list_max');
if ($aggregator_summary_items) {
$items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = :fid ORDER BY i.timestamp DESC', 0, $aggregator_summary_items, array(':fid' => $feed->fid));
foreach ($items as $item) {
$summary_items[] = theme('aggregator_summary_item', array('item' => $item));
}
......@@ -380,9 +381,10 @@ function aggregator_page_categories() {
$output = '';
foreach ($result as $category) {
if (variable_get('aggregator_summary_items', 3)) {
$aggregator_summary_items = config('aggregator.settings')->get('source.list_max');
if ($aggregator_summary_items) {
$summary_items = array();
$items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = :cid ORDER BY i.timestamp DESC', 0, variable_get('aggregator_summary_items', 3), array(':cid' => $category->cid));
$items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = :cid ORDER BY i.timestamp DESC', 0, $aggregator_summary_items, array(':cid' => $category->cid));
foreach ($items as $item) {
$summary_items[] = theme('aggregator_summary_item', array('item' => $item));
}
......@@ -439,7 +441,7 @@ function theme_aggregator_page_rss($variables) {
foreach ($feeds as $feed) {
switch ($feed_length) {
case 'teaser':
$summary = text_summary($feed->description, NULL, variable_get('aggregator_teaser_length', 600));
$summary = text_summary($feed->description, NULL, config('aggregator.settings')->get('items.teaser_length'));
if ($summary != $feed->description) {
$summary .= '<p><a href="' . check_url($feed->link) . '">' . t('read more') . "</a></p>\n";
}
......
......@@ -70,7 +70,9 @@ function aggregator_aggregator_remove($feed) {
* separate from aggregator API functionality.
*/
function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
if (in_array('aggregator', variable_get('aggregator_processors', array('aggregator')))) {
$config = config('aggregator.settings');
$aggregator_processors = $config->get('processors');
if (in_array('aggregator', $aggregator_processors)) {
$info = module_invoke('aggregator', 'aggregator_process', 'info');
$items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
......@@ -83,7 +85,7 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
'#title' => t('Default processor settings'),
'#description' => $info['description'],
'#collapsible' => TRUE,
'#collapsed' => !in_array('aggregator', variable_get('aggregator_processors', array('aggregator'))),
'#collapsed' => !in_array('aggregator', $aggregator_processors),
);
}
else {
......@@ -93,7 +95,7 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
$form['modules']['aggregator']['aggregator_summary_items'] = array(
'#type' => 'select',
'#title' => t('Number of items shown in listing pages'),
'#default_value' => variable_get('aggregator_summary_items', 3),
'#default_value' => config('aggregator.settings')->get('source.list_max'),
'#empty_value' => 0,
'#options' => $items,
);
......@@ -101,7 +103,7 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
$form['modules']['aggregator']['aggregator_clear'] = array(
'#type' => 'select',
'#title' => t('Discard items older than'),
'#default_value' => variable_get('aggregator_clear', 9676800),
'#default_value' => config('aggregator.settings')->get('items.expire'),
'#options' => $period,
'#description' => t('Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
);
......@@ -109,7 +111,7 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
$form['modules']['aggregator']['aggregator_category_selector'] = array(
'#type' => 'radios',
'#title' => t('Select categories using'),
'#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),
'#default_value' => config('aggregator.settings')->get('source.category_selector'),
'#options' => array('checkboxes' => t('checkboxes'),
'select' => t('multiple selector')),
'#description' => t('For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.'),
......@@ -117,7 +119,7 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {
$form['modules']['aggregator']['aggregator_teaser_length'] = array(
'#type' => 'select',
'#title' => t('Length of trimmed description'),
'#default_value' => variable_get('aggregator_teaser_length', 600),
'#default_value' => config('aggregator.settings')->get('items.teaser_length'),
'#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_aggregator_characters'),
'#description' => t("The maximum number of characters used in the trimmed version of content.")
);
......@@ -184,7 +186,7 @@ function aggregator_save_item($edit) {
* Object describing feed.
*/
function aggregator_expire($feed) {
$aggregator_clear = variable_get('aggregator_clear', 9676800);
$aggregator_clear = config('aggregator.settings')->get('items.expire');
if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
// Remove all items that are older than flush item timer.
......
......@@ -24,7 +24,7 @@ function setUp() {
// Do not remove old aggregator items during these tests, since our sample
// feeds have hardcoded dates in them (which may be expired when this test
// is run).
variable_set('aggregator_clear', AGGREGATOR_CLEAR_NEVER);
config('aggregator.settings')->set('items.expire', AGGREGATOR_CLEAR_NEVER)->save();
}
/**
......
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