' . t('Feed overview') . ''; $header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), array('data' => t('Operations'), 'colspan' => '3')); $rows = array(); foreach ($result as $feed) { $rows[] = array( l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '@count items'), ($feed->checked ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->checked))) : t('never')), ($feed->checked && $feed->refresh ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - REQUEST_TIME))) : t('never')), l(t('edit'), "admin/config/services/aggregator/edit/feed/$feed->fid"), l(t('remove items'), "admin/config/services/aggregator/remove/$feed->fid"), l(t('update items'), "admin/config/services/aggregator/update/$feed->fid", array('query' => array('token' => drupal_get_token("aggregator/update/$feed->fid")))), ); } $output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No feeds available. Add feed.', array('@link' => url('admin/config/services/aggregator/add/feed'))))); $result = db_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title'); $output .= '
'),
'#description' => t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),
);
// Make sure configuration is sane.
aggregator_sanitize_configuration();
// Get all available fetchers.
$fetchers = module_implements('aggregator_fetch');
foreach ($fetchers as $k => $module) {
if ($info = module_invoke($module, 'aggregator_fetch_info')) {
$label = $info['title'] . ' ' . $info['description'] . '';
}
else {
$label = $module;
}
unset($fetchers[$k]);
$fetchers[$module] = $label;
}
// Get all available parsers.
$parsers = module_implements('aggregator_parse');
foreach ($parsers as $k => $module) {
if ($info = module_invoke($module, 'aggregator_parse_info')) {
$label = $info['title'] . ' ' . $info['description'] . '';
}
else {
$label = $module;
}
unset($parsers[$k]);
$parsers[$module] = $label;
}
// Get all available processors.
$processors = module_implements('aggregator_process');
foreach ($processors as $k => $module) {
if ($info = module_invoke($module, 'aggregator_process_info')) {
$label = $info['title'] . ' ' . $info['description'] . '';
}
else {
$label = $module;
}
unset($processors[$k]);
$processors[$module] = $label;
}
// Only show basic configuration if there are actually options.
$basic_conf = array();
if (count($fetchers) > 1) {
$basic_conf['aggregator_fetcher'] = array(
'#type' => 'radios',
'#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'),
);
}
if (count($parsers) > 1) {
$basic_conf['aggregator_parser'] = array(
'#type' => 'radios',
'#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'),
);
}
if (count($processors) > 1) {
$basic_conf['aggregator_processors'] = array(
'#type' => 'checkboxes',
'#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')),
);
}
if (count($basic_conf)) {
$form['basic_conf'] = array(
'#type' => 'fieldset',
'#title' => t('Basic configuration'),
'#description' => t('For most aggregation tasks, the default settings are fine.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['basic_conf'] += $basic_conf;
}
// 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;
}
/**
* Form submission handler for aggregator_admin_form().
*/
function aggregator_admin_form_submit($form, &$form_state) {
if (isset($form_state['values']['aggregator_processors'])) {
$form_state['values']['aggregator_processors'] = array_filter($form_state['values']['aggregator_processors']);
}
system_settings_form_submit($form, $form_state);
}
/**
* Form constructor to add/edit/delete aggregator categories.
*
* @param $edit
* An associative array containing:
* - title: A string to use for the category title.
* - description: A string to use for the category description.
* - cid: The category ID.
*
* @ingroup forms
* @see aggregator_form_category_validate()
* @see aggregator_form_category_submit()
*/
function aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL)) {
$form['title'] = array('#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $edit['title'],
'#maxlength' => 64,
'#required' => TRUE,
);
$form['description'] = array('#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
if ($edit['cid']) {
$form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
$form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']);
}
return $form;
}
/**
* Form validation handler for aggregator_form_category().
*
* @see aggregator_form_category_submit()
*/
function aggregator_form_category_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Save')) {
// Check for duplicate titles
if (isset($form_state['values']['cid'])) {
$category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => $form_state['values']['title'], ':cid' => $form_state['values']['cid']))->fetchObject();
}
else {
$category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title", array(':title' => $form_state['values']['title']))->fetchObject();
}
if ($category) {
form_set_error('title', t('A category named %category already exists. Enter a unique title.', array('%category' => $form_state['values']['title'])));
}
}
}
/**
* Form submission handler for aggregator_form_category().
*
* @see aggregator_form_category_validate()
*
* @todo Add delete confirmation dialog.
*/
function aggregator_form_category_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Delete')) {
$title = $form_state['values']['title'];
// Unset the title.
unset($form_state['values']['title']);
}
aggregator_save_category($form_state['values']);
if (isset($form_state['values']['cid'])) {
if (isset($form_state['values']['title'])) {
drupal_set_message(t('The category %category has been updated.', array('%category' => $form_state['values']['title'])));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator/';
return;
}
else {
$form_state['redirect'] = 'aggregator/categories/' . $form_state['values']['cid'];
return;
}
}
else {
watchdog('aggregator', 'Category %category deleted.', array('%category' => $title));
drupal_set_message(t('The category %category has been deleted.', array('%category' => $title)));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator/';
return;
}
else {
$form_state['redirect'] = 'aggregator/categories/';
return;
}
}
}
else {
watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/config/services/aggregator'));
drupal_set_message(t('The category %category has been added.', array('%category' => $form_state['values']['title'])));
}
}