Initial code using Drupal 6.38
This commit is contained in:
commit
4824608a33
467 changed files with 90887 additions and 0 deletions
34
modules/aggregator/aggregator-feed-source.tpl.php
Normal file
34
modules/aggregator/aggregator-feed-source.tpl.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file aggregator-feed-source.tpl.php
|
||||
* Default theme implementation to present the source of the feed.
|
||||
*
|
||||
* The contents are render above feed listings when browsing source feeds.
|
||||
* For example, "example.com/aggregator/sources/1".
|
||||
*
|
||||
* Available variables:
|
||||
* - $source_icon: Feed icon linked to the source. Rendered through
|
||||
* theme_feed_icon().
|
||||
* - $source_image: Image set by the feed source.
|
||||
* - $source_description: Description set by the feed source.
|
||||
* - $source_url: URL to the feed source.
|
||||
* - $last_checked: How long ago the feed was checked locally.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_aggregator_feed_source()
|
||||
*/
|
||||
?>
|
||||
<div class="feed-source">
|
||||
<?php print $source_icon; ?>
|
||||
<?php print $source_image; ?>
|
||||
<div class="feed-description">
|
||||
<?php print $source_description; ?>
|
||||
</div>
|
||||
<div class="feed-url">
|
||||
<em><?php print t('URL:'); ?></em> <a href="<?php print $source_url; ?>"><?php print $source_url; ?></a>
|
||||
</div>
|
||||
<div class="feed-updated">
|
||||
<em><?php print t('Updated:'); ?></em> <?php print $last_checked; ?>
|
||||
</div>
|
||||
</div>
|
45
modules/aggregator/aggregator-item.tpl.php
Normal file
45
modules/aggregator/aggregator-item.tpl.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file aggregator-item.tpl.php
|
||||
* Default theme implementation to format an individual feed item for display
|
||||
* on the aggregator page.
|
||||
*
|
||||
* Available variables:
|
||||
* - $feed_url: URL to the originating feed item.
|
||||
* - $feed_title: Title of the feed item.
|
||||
* - $source_url: Link to the local source section.
|
||||
* - $source_title: Title of the remote source.
|
||||
* - $source_date: Date the feed was posted on the remote source.
|
||||
* - $content: Feed item content.
|
||||
* - $categories: Linked categories assigned to the feed.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_aggregator_item()
|
||||
*/
|
||||
?>
|
||||
<div class="feed-item">
|
||||
<h3 class="feed-item-title">
|
||||
<a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a>
|
||||
</h3>
|
||||
|
||||
<div class="feed-item-meta">
|
||||
<?php if ($source_url) : ?>
|
||||
<a href="<?php print $source_url; ?>" class="feed-item-source"><?php print $source_title; ?></a> -
|
||||
<?php endif; ?>
|
||||
<span class="feed-item-date"><?php print $source_date; ?></span>
|
||||
</div>
|
||||
|
||||
<?php if ($content) : ?>
|
||||
<div class="feed-item-body">
|
||||
<?php print $content; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($categories) : ?>
|
||||
<div class="feed-item-categories">
|
||||
<?php print t('Categories'); ?>: <?php print implode(', ', $categories); ?>
|
||||
</div>
|
||||
<?php endif ;?>
|
||||
|
||||
</div>
|
4
modules/aggregator/aggregator-rtl.css
Normal file
4
modules/aggregator/aggregator-rtl.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
#aggregator .feed-source .feed-icon {
|
||||
float: left;
|
||||
}
|
18
modules/aggregator/aggregator-summary-item.tpl.php
Normal file
18
modules/aggregator/aggregator-summary-item.tpl.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file aggregator-summary-item.tpl.php
|
||||
* Default theme implementation to present a linked feed item for summaries.
|
||||
*
|
||||
* Available variables:
|
||||
* - $feed_url: Link to originating feed.
|
||||
* - $feed_title: Title of feed.
|
||||
* - $feed_age: Age of remote feed.
|
||||
* - $source_url: Link to remote source.
|
||||
* - $source_title: Locally set title for the source.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_aggregator_summary_item()
|
||||
*/
|
||||
?>
|
||||
<a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a> <span class="age"><?php print $feed_age; ?></span><?php if ($source_url) : ?>, <span class="source"><a href="<?php print $source_url; ?>"><?php print $source_title; ?></a></span><?php endif; ?>
|
23
modules/aggregator/aggregator-summary-items.tpl.php
Normal file
23
modules/aggregator/aggregator-summary-items.tpl.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file aggregator-summary-items.tpl.php
|
||||
* Default theme implementation to present feeds as list items.
|
||||
*
|
||||
* Each iteration generates a single feed source or category.
|
||||
*
|
||||
* Available variables:
|
||||
* - $title: Title of the feed or category.
|
||||
* - $summary_list: Unordered list of linked feed items generated through
|
||||
* theme_item_list().
|
||||
* - $source_url: URL to the local source or category.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_aggregator_summary-items()
|
||||
*/
|
||||
?>
|
||||
<h2><?php print $title; ?></h2>
|
||||
<?php print $summary_list; ?>
|
||||
<div class="links">
|
||||
<a href="<?php print $source_url; ?>"><?php print t('More'); ?></a>
|
||||
</div>
|
18
modules/aggregator/aggregator-wrapper.tpl.php
Normal file
18
modules/aggregator/aggregator-wrapper.tpl.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file comment-wrapper.tpl.php
|
||||
* Default theme implementation to wrap aggregator content.
|
||||
*
|
||||
* Available variables:
|
||||
* - $content: All aggregator content.
|
||||
* - $page: Pager links rendered through theme_pager().
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_comment_wrapper()
|
||||
*/
|
||||
?>
|
||||
<div id="aggregator">
|
||||
<?php print $content; ?>
|
||||
<?php print $pager; ?>
|
||||
</div>
|
351
modules/aggregator/aggregator.admin.inc
Normal file
351
modules/aggregator/aggregator.admin.inc
Normal file
|
@ -0,0 +1,351 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Admin page callbacks for the aggregator module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; displays the aggregator administration page.
|
||||
*/
|
||||
function aggregator_admin_overview() {
|
||||
return aggregator_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the aggregator administration page.
|
||||
*
|
||||
* @return
|
||||
* The page HTML.
|
||||
*/
|
||||
function aggregator_view() {
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
|
||||
|
||||
$output = '<h3>'. t('Feed overview') .'</h3>';
|
||||
|
||||
$header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), array('data' => t('Operations'), 'colspan' => '3'));
|
||||
$rows = array();
|
||||
while ($feed = db_fetch_object($result)) {
|
||||
$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(time() - $feed->checked))) : t('never')),
|
||||
($feed->checked ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - time()))) : t('never')),
|
||||
l(t('edit'), "admin/content/aggregator/edit/feed/$feed->fid"),
|
||||
l(t('remove items'), "admin/content/aggregator/remove/$feed->fid"),
|
||||
l(t('update items'), "admin/content/aggregator/update/$feed->fid", array('query' => array('token' => drupal_get_token("aggregator/update/$feed->fid")))),
|
||||
);
|
||||
}
|
||||
$output .= theme('table', $header, $rows);
|
||||
|
||||
$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 .= '<h3>'. t('Category overview') .'</h3>';
|
||||
|
||||
$header = array(t('Title'), t('Items'), t('Operations'));
|
||||
$rows = array();
|
||||
while ($category = db_fetch_object($result)) {
|
||||
$rows[] = array(l($category->title, "aggregator/categories/$category->cid"), format_plural($category->items, '1 item', '@count items'), l(t('edit'), "admin/content/aggregator/edit/category/$category->cid"));
|
||||
}
|
||||
$output .= theme('table', $header, $rows);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Generate a form to add/edit feed sources.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see aggregator_form_feed_validate()
|
||||
* @see aggregator_form_feed_submit()
|
||||
*/
|
||||
function aggregator_form_feed(&$form_state, $edit = array('refresh' => 900, 'title' => '', 'url' => '', 'fid' => NULL)) {
|
||||
$period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
|
||||
|
||||
if ($edit['refresh'] == '') {
|
||||
$edit['refresh'] = 3600;
|
||||
}
|
||||
|
||||
$form['title'] = array('#type' => 'textfield',
|
||||
'#title' => t('Title'),
|
||||
'#default_value' => $edit['title'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('The name of the feed (or the name of the website providing the feed).'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['url'] = array('#type' => 'textfield',
|
||||
'#title' => t('URL'),
|
||||
'#default_value' => $edit['url'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('The fully-qualified URL of the feed.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['refresh'] = array('#type' => 'select',
|
||||
'#title' => t('Update interval'),
|
||||
'#default_value' => $edit['refresh'],
|
||||
'#options' => $period,
|
||||
'#description' => t('The length of time between feed updates. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
|
||||
);
|
||||
|
||||
// Handling of categories:
|
||||
$options = array();
|
||||
$values = array();
|
||||
$categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title', $edit['fid']);
|
||||
while ($category = db_fetch_object($categories)) {
|
||||
$options[$category->cid] = check_plain($category->title);
|
||||
if ($category->fid) $values[] = $category->cid;
|
||||
}
|
||||
if ($options) {
|
||||
$form['category'] = array('#type' => 'checkboxes',
|
||||
'#title' => t('Categorize news items'),
|
||||
'#default_value' => $values,
|
||||
'#options' => $options,
|
||||
'#description' => t('New feed items are automatically filed in the checked categories.'),
|
||||
);
|
||||
}
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
||||
|
||||
if ($edit['fid']) {
|
||||
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
|
||||
$form['fid'] = array('#type' => 'hidden', '#value' => $edit['fid']);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate aggregator_form_feed form submissions.
|
||||
*/
|
||||
function aggregator_form_feed_validate($form, &$form_state) {
|
||||
if ($form_state['values']['op'] == t('Save')) {
|
||||
// Ensure URL is valid.
|
||||
if (!valid_url($form_state['values']['url'], TRUE)) {
|
||||
form_set_error('url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $form_state['values']['url'])));
|
||||
}
|
||||
// Check for duplicate titles.
|
||||
if (isset($form_state['values']['fid'])) {
|
||||
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = '%s' OR url = '%s') AND fid <> %d", $form_state['values']['title'], $form_state['values']['url'], $form_state['values']['fid']);
|
||||
}
|
||||
else {
|
||||
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = '%s' OR url = '%s'", $form_state['values']['title'], $form_state['values']['url']);
|
||||
}
|
||||
while ($feed = db_fetch_object($result)) {
|
||||
if (strcasecmp($feed->title, $form_state['values']['title']) == 0) {
|
||||
form_set_error('title', t('A feed named %feed already exists. Please enter a unique title.', array('%feed' => $form_state['values']['title'])));
|
||||
}
|
||||
if (strcasecmp($feed->url, $form_state['values']['url']) == 0) {
|
||||
form_set_error('url', t('A feed with this URL %url already exists. Please enter a unique URL.', array('%url' => $form_state['values']['url'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process aggregator_form_feed form submissions.
|
||||
*
|
||||
* @todo Add delete confirmation dialog.
|
||||
*/
|
||||
function aggregator_form_feed_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_feed($form_state['values']);
|
||||
if (isset($form_state['values']['fid'])) {
|
||||
if (isset($form_state['values']['title'])) {
|
||||
drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_state['values']['title'])));
|
||||
if (arg(0) == 'admin') {
|
||||
$form_state['redirect'] = 'admin/content/aggregator/';
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$form_state['redirect'] = 'aggregator/sources/'. $form_state['values']['fid'];
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $title));
|
||||
drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $title)));
|
||||
if (arg(0) == 'admin') {
|
||||
$form_state['redirect'] = 'admin/content/aggregator/';
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$form_state['redirect'] = 'aggregator/sources/';
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
|
||||
drupal_set_message(t('The feed %feed has been added.', array('%feed' => $form_state['values']['title'])));
|
||||
}
|
||||
}
|
||||
|
||||
function aggregator_admin_remove_feed($form_state, $feed) {
|
||||
return confirm_form(
|
||||
array(
|
||||
'feed' => array(
|
||||
'#type' => 'value',
|
||||
'#value' => $feed,
|
||||
),
|
||||
),
|
||||
t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $feed['title'])),
|
||||
'admin/content/aggregator',
|
||||
t('This action cannot be undone.'),
|
||||
t('Remove items'),
|
||||
t('Cancel')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from a feed and redirect to the overview page.
|
||||
*
|
||||
* @param $feed
|
||||
* An associative array describing the feed to be cleared.
|
||||
*/
|
||||
function aggregator_admin_remove_feed_submit($form, &$form_state) {
|
||||
aggregator_remove($form_state['values']['feed']);
|
||||
$form_state['redirect'] = 'admin/content/aggregator';
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; refreshes a feed, then redirects to the overview page.
|
||||
*
|
||||
* @param $feed
|
||||
* An associative array describing the feed to be refreshed.
|
||||
*/
|
||||
function aggregator_admin_refresh_feed($feed) {
|
||||
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'aggregator/update/' . $feed['fid'])) {
|
||||
return drupal_access_denied();
|
||||
}
|
||||
aggregator_refresh($feed);
|
||||
drupal_goto('admin/content/aggregator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Configure the aggregator system.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see system_settings_form()
|
||||
*/
|
||||
function aggregator_admin_settings() {
|
||||
$items = array(0 => t('none')) + 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');
|
||||
|
||||
$form['aggregator_allowed_html_tags'] = array(
|
||||
'#type' => 'textfield', '#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>'),
|
||||
'#description' => t('A space-separated list of HTML tags allowed in the content of feed items. (Tags in this list are not removed by Drupal.)')
|
||||
);
|
||||
|
||||
$form['aggregator_summary_items'] = array(
|
||||
'#type' => 'select', '#title' => t('Items shown in sources and categories pages') ,
|
||||
'#default_value' => variable_get('aggregator_summary_items', 3), '#options' => $items,
|
||||
'#description' => t('Number of feed items displayed in feed and category summary pages.')
|
||||
);
|
||||
|
||||
$form['aggregator_clear'] = array(
|
||||
'#type' => 'select', '#title' => t('Discard items older than'),
|
||||
'#default_value' => variable_get('aggregator_clear', 9676800), '#options' => $period,
|
||||
'#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status')))
|
||||
);
|
||||
|
||||
$form['aggregator_category_selector'] = array(
|
||||
'#type' => 'radios', '#title' => t('Category selection type'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),
|
||||
'#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')),
|
||||
'#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector work well with large numbers of categories.)')
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Generate a form to add/edit/delete aggregator categories.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see aggregator_form_category_validate()
|
||||
* @see aggregator_form_category_submit()
|
||||
*/
|
||||
function aggregator_form_category(&$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['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
||||
|
||||
if ($edit['cid']) {
|
||||
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
|
||||
$form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate aggregator_form_feed form submissions.
|
||||
*/
|
||||
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_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s' AND cid <> %d", $form_state['values']['title'], $form_state['values']['cid']));
|
||||
}
|
||||
else {
|
||||
$category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s'", $form_state['values']['title']));
|
||||
}
|
||||
if ($category) {
|
||||
form_set_error('title', t('A category named %category already exists. Please enter a unique title.', array('%category' => $form_state['values']['title'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process aggregator_form_category form submissions.
|
||||
*
|
||||
* @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/content/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/content/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/content/aggregator'));
|
||||
drupal_set_message(t('The category %category has been added.', array('%category' => $form_state['values']['title'])));
|
||||
}
|
||||
}
|
37
modules/aggregator/aggregator.css
Normal file
37
modules/aggregator/aggregator.css
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
#aggregator .feed-source .feed-title {
|
||||
margin-top: 0;
|
||||
}
|
||||
#aggregator .feed-source .feed-image img {
|
||||
margin-bottom: 0.75em;
|
||||
}
|
||||
#aggregator .feed-source .feed-icon {
|
||||
float: right; /* LTR */
|
||||
display: block;
|
||||
}
|
||||
#aggregator .feed-item {
|
||||
margin-bottom: 1.5em;
|
||||
}
|
||||
#aggregator .feed-item-title {
|
||||
margin-bottom: 0;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
#aggregator .feed-item-meta, #aggregator .feed-item-body {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
#aggregator .feed-item-categories {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
#aggregator td {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
#aggregator td.categorize-item {
|
||||
white-space: nowrap;
|
||||
}
|
||||
#aggregator .categorize-item .news-item .body {
|
||||
margin-top: 0;
|
||||
}
|
||||
#aggregator .categorize-item h3 {
|
||||
margin-bottom: 1em;
|
||||
margin-top: 0;
|
||||
}
|
11
modules/aggregator/aggregator.info
Normal file
11
modules/aggregator/aggregator.info
Normal file
|
@ -0,0 +1,11 @@
|
|||
name = Aggregator
|
||||
description = "Aggregates syndicated content (RSS, RDF, and Atom feeds)."
|
||||
package = Core - optional
|
||||
version = VERSION
|
||||
core = 6.x
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-02-24
|
||||
version = "6.38"
|
||||
project = "drupal"
|
||||
datestamp = "1456343372"
|
||||
|
240
modules/aggregator/aggregator.install
Normal file
240
modules/aggregator/aggregator.install
Normal file
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function aggregator_install() {
|
||||
// Create tables.
|
||||
drupal_install_schema('aggregator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function aggregator_uninstall() {
|
||||
// Remove tables.
|
||||
drupal_uninstall_schema('aggregator');
|
||||
|
||||
variable_del('aggregator_allowed_html_tags');
|
||||
variable_del('aggregator_summary_items');
|
||||
variable_del('aggregator_clear');
|
||||
variable_del('aggregator_category_selector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function aggregator_schema() {
|
||||
$schema['aggregator_category'] = array(
|
||||
'description' => 'Stores categories for aggregator feeds and feed items.',
|
||||
'fields' => array(
|
||||
'cid' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique aggregator category ID.',
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Title of the category.',
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => 'Description of the category',
|
||||
),
|
||||
'block' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
'description' => 'The number of recent items to show within the category block.',
|
||||
)
|
||||
),
|
||||
'primary key' => array('cid'),
|
||||
'unique keys' => array('title' => array('title')),
|
||||
);
|
||||
|
||||
$schema['aggregator_category_feed'] = array(
|
||||
'description' => 'Bridge table; maps feeds to categories.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => "The feed's {aggregator_feed}.fid.",
|
||||
),
|
||||
'cid' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {aggregator_category}.cid to which the feed is being assigned.',
|
||||
)
|
||||
),
|
||||
'primary key' => array('cid', 'fid'),
|
||||
'indexes' => array('fid' => array('fid')),
|
||||
);
|
||||
|
||||
$schema['aggregator_category_item'] = array(
|
||||
'description' => 'Bridge table; maps feed items to categories.',
|
||||
'fields' => array(
|
||||
'iid' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => "The feed item's {aggregator_item}.iid.",
|
||||
),
|
||||
'cid' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {aggregator_category}.cid to which the feed item is being assigned.',
|
||||
)
|
||||
),
|
||||
'primary key' => array('cid', 'iid'),
|
||||
'indexes' => array('iid' => array('iid')),
|
||||
);
|
||||
|
||||
$schema['aggregator_feed'] = array(
|
||||
'description' => 'Stores feeds to be parsed by the aggregator.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique feed ID.',
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Title of the feed.',
|
||||
),
|
||||
'url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'URL to the feed.',
|
||||
),
|
||||
'refresh' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'How often to check for new feed items, in seconds.',
|
||||
),
|
||||
'checked' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Last time feed was checked for new items, as Unix timestamp.',
|
||||
),
|
||||
'link' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The parent website of the feed; comes from the <link> element in the feed.',
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => "The parent website's description; comes from the <description> element in the feed.",
|
||||
),
|
||||
'image' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => 'An image representing the feed.',
|
||||
),
|
||||
'etag' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Entity tag HTTP response header, used for validating cache.',
|
||||
),
|
||||
'modified' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'When the feed was last modified, as a Unix timestamp.',
|
||||
),
|
||||
'block' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
'description' => "Number of items to display in the feed's block.",
|
||||
)
|
||||
),
|
||||
'primary key' => array('fid'),
|
||||
'unique keys' => array(
|
||||
'url' => array('url'),
|
||||
'title' => array('title'),
|
||||
),
|
||||
);
|
||||
|
||||
$schema['aggregator_item'] = array(
|
||||
'description' => 'Stores the individual items imported from feeds.',
|
||||
'fields' => array(
|
||||
'iid' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique ID for feed item.',
|
||||
),
|
||||
'fid' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {aggregator_feed}.fid to which this item belongs.',
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Title of the feed item.',
|
||||
),
|
||||
'link' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Link to the feed item.',
|
||||
),
|
||||
'author' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Author of the feed item.',
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => 'Body of the feed item.',
|
||||
),
|
||||
'timestamp' => array(
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Post date of feed item, as a Unix timestamp.',
|
||||
),
|
||||
'guid' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'description' => 'Unique identifier for the feed item.',
|
||||
)
|
||||
),
|
||||
'primary key' => array('iid'),
|
||||
'indexes' => array('fid' => array('fid')),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
940
modules/aggregator/aggregator.module
Normal file
940
modules/aggregator/aggregator.module
Normal file
|
@ -0,0 +1,940 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Used to aggregate syndicated content (RSS, RDF, and Atom).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function aggregator_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#aggregator':
|
||||
$output = '<p>'. t('The aggregator is a powerful on-site syndicator and news reader that gathers fresh content from RSS-, RDF-, and Atom-based feeds made available across the web. Thousands of sites (particularly news sites and blogs) publish their latest headlines and posts in feeds, using a number of standardized XML-based formats. Formats supported by the aggregator include <a href="@rss">RSS</a>, <a href="@rdf">RDF</a>, and <a href="@atom">Atom</a>.', array('@rss' => 'http://cyber.law.harvard.edu/rss/', '@rdf' => 'http://www.w3.org/RDF/', '@atom' => 'http://www.atomenabled.org')) .'</p>';
|
||||
$output .= '<p>'. t('Feeds contain feed items, or individual posts published by the site providing the feed. Feeds may be grouped in categories, generally by topic. Users view feed items in the <a href="@aggregator">main aggregator display</a> or by <a href="@aggregator-sources">their source</a>. Administrators can <a href="@feededit">add, edit and delete feeds</a> and choose how often to check each feed for newly updated items. The most recent items in either a feed or category can be displayed as a block through the <a href="@admin-block">blocks administration page</a>. A <a href="@aggregator-opml">machine-readable OPML file</a> of all feeds is available. A correctly configured <a href="@cron">cron maintenance task</a> is required to update feeds automatically.', array('@aggregator' => url('aggregator'), '@aggregator-sources' => url('aggregator/sources'), '@feededit' => url('admin/content/aggregator'), '@admin-block' => url('admin/build/block'), '@aggregator-opml' => url('aggregator/opml'), '@cron' => url('admin/reports/status'))) .'</p>';
|
||||
$output .= '<p>'. t('For more information, see the online handbook entry for <a href="@aggregator">Aggregator module</a>.', array('@aggregator' => 'http://drupal.org/handbook/modules/aggregator/')) .'</p>';
|
||||
return $output;
|
||||
case 'admin/content/aggregator':
|
||||
$output = '<p>'. t('Thousands of sites (particularly news sites and blogs) publish their latest headlines and posts in feeds, using a number of standardized XML-based formats. Formats supported by the aggregator include <a href="@rss">RSS</a>, <a href="@rdf">RDF</a>, and <a href="@atom">Atom</a>.', array('@rss' => 'http://cyber.law.harvard.edu/rss/', '@rdf' => 'http://www.w3.org/RDF/', '@atom' => 'http://www.atomenabled.org')) .'</p>';
|
||||
$output .= '<p>'. t('Current feeds are listed below, and <a href="@addfeed">new feeds may be added</a>. For each feed or feed category, the <em>latest items</em> block may be enabled at the <a href="@block">blocks administration page</a>.', array('@addfeed' => url('admin/content/aggregator/add/feed'), '@block' => url('admin/build/block'))) .'</p>';
|
||||
return $output;
|
||||
case 'admin/content/aggregator/add/feed':
|
||||
return '<p>'. t('Add a feed in RSS, RDF or Atom format. A feed may only have one entry.') .'</p>';
|
||||
case 'admin/content/aggregator/add/category':
|
||||
return '<p>'. t('Categories allow feed items from different feeds to be grouped together. For example, several sport-related feeds may belong to a category named <em>Sports</em>. Feed items may be grouped automatically (by selecting a category when creating or editing a feed) or manually (via the <em>Categorize</em> page available from feed item listings). Each category provides its own feed page and block.') .'</p>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme()
|
||||
*/
|
||||
function aggregator_theme() {
|
||||
return array(
|
||||
'aggregator_wrapper' => array(
|
||||
'arguments' => array('content' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
'template' => 'aggregator-wrapper',
|
||||
),
|
||||
'aggregator_categorize_items' => array(
|
||||
'arguments' => array('form' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
),
|
||||
'aggregator_feed_source' => array(
|
||||
'arguments' => array('feed' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
'template' => 'aggregator-feed-source',
|
||||
),
|
||||
'aggregator_block_item' => array(
|
||||
'arguments' => array('item' => NULL, 'feed' => 0),
|
||||
),
|
||||
'aggregator_summary_items' => array(
|
||||
'arguments' => array('summary_items' => NULL, 'source' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
'template' => 'aggregator-summary-items',
|
||||
),
|
||||
'aggregator_summary_item' => array(
|
||||
'arguments' => array('item' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
'template' => 'aggregator-summary-item',
|
||||
),
|
||||
'aggregator_item' => array(
|
||||
'arguments' => array('item' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
'template' => 'aggregator-item',
|
||||
),
|
||||
'aggregator_page_opml' => array(
|
||||
'arguments' => array('feeds' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
),
|
||||
'aggregator_page_rss' => array(
|
||||
'arguments' => array('feeds' => NULL, 'category' => NULL),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function aggregator_menu() {
|
||||
$items['admin/content/aggregator'] = array(
|
||||
'title' => 'Feed aggregator',
|
||||
'description' => "Configure which content your site aggregates from other sites, how often it polls them, and how they're categorized.",
|
||||
'page callback' => 'aggregator_admin_overview',
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/add/feed'] = array(
|
||||
'title' => 'Add feed',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_feed'),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'parent' => 'admin/content/aggregator',
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/add/category'] = array(
|
||||
'title' => 'Add category',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_category'),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'parent' => 'admin/content/aggregator',
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/remove/%aggregator_feed'] = array(
|
||||
'title' => 'Remove items',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_admin_remove_feed', 4),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/update/%aggregator_feed'] = array(
|
||||
'title' => 'Update items',
|
||||
'page callback' => 'aggregator_admin_refresh_feed',
|
||||
'page arguments' => array(4),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/list'] = array(
|
||||
'title' => 'List',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items['admin/content/aggregator/settings'] = array(
|
||||
'title' => 'Settings',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_admin_settings'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 10,
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['aggregator'] = array(
|
||||
'title' => 'Feed aggregator',
|
||||
'page callback' => 'aggregator_page_last',
|
||||
'access arguments' => array('access news feeds'),
|
||||
'weight' => 5,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/sources'] = array(
|
||||
'title' => 'Sources',
|
||||
'page callback' => 'aggregator_page_sources',
|
||||
'access arguments' => array('access news feeds'),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/categories'] = array(
|
||||
'title' => 'Categories',
|
||||
'page callback' => 'aggregator_page_categories',
|
||||
'access callback' => '_aggregator_has_categories',
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/rss'] = array(
|
||||
'title' => 'RSS feed',
|
||||
'page callback' => 'aggregator_page_rss',
|
||||
'access arguments' => array('access news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/opml'] = array(
|
||||
'title' => 'OPML feed',
|
||||
'page callback' => 'aggregator_page_opml',
|
||||
'access arguments' => array('access news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/categories/%aggregator_category'] = array(
|
||||
'title callback' => '_aggregator_category_title',
|
||||
'title arguments' => array(2),
|
||||
'page callback' => 'aggregator_page_category',
|
||||
'page arguments' => array(2),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access news feeds'),
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/categories/%aggregator_category/view'] = array(
|
||||
'title' => 'View',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items['aggregator/categories/%aggregator_category/categorize'] = array(
|
||||
'title' => 'Categorize',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_page_category', 2),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/categories/%aggregator_category/configure'] = array(
|
||||
'title' => 'Configure',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_category', 2),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 1,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['aggregator/sources/%aggregator_feed'] = array(
|
||||
'page callback' => 'aggregator_page_source',
|
||||
'page arguments' => array(2),
|
||||
'access arguments' => array('access news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/sources/%aggregator_feed/view'] = array(
|
||||
'title' => 'View',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items['aggregator/sources/%aggregator_feed/categorize'] = array(
|
||||
'title' => 'Categorize',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_page_source', 2),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'aggregator.pages.inc',
|
||||
);
|
||||
$items['aggregator/sources/%aggregator_feed/configure'] = array(
|
||||
'title' => 'Configure',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_feed', 2),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 1,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/edit/feed/%aggregator_feed'] = array(
|
||||
'title' => 'Edit feed',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_feed', 5),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
$items['admin/content/aggregator/edit/category/%aggregator_category'] = array(
|
||||
'title' => 'Edit category',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('aggregator_form_category', 5),
|
||||
'access arguments' => array('administer news feeds'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'aggregator.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback.
|
||||
*
|
||||
* @return
|
||||
* An aggregator category title.
|
||||
*/
|
||||
function _aggregator_category_title($category) {
|
||||
return $category['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_init().
|
||||
*/
|
||||
function aggregator_init() {
|
||||
drupal_add_css(drupal_get_path('module', 'aggregator') .'/aggregator.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out whether there are any aggregator categories.
|
||||
*
|
||||
* @return
|
||||
* TRUE if there is at least one category and the user has access to them, FALSE otherwise.
|
||||
*/
|
||||
function _aggregator_has_categories() {
|
||||
return user_access('access news feeds') && db_result(db_query('SELECT COUNT(*) FROM {aggregator_category}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_perm().
|
||||
*/
|
||||
function aggregator_perm() {
|
||||
return array('administer news feeds', 'access news feeds');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_cron().
|
||||
*
|
||||
* Checks news feeds for updates once their refresh interval has elapsed.
|
||||
*/
|
||||
function aggregator_cron() {
|
||||
$result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d', time());
|
||||
while ($feed = db_fetch_array($result)) {
|
||||
aggregator_refresh($feed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_block().
|
||||
*
|
||||
* Generates blocks for the latest news items in each category and feed.
|
||||
*/
|
||||
function aggregator_block($op = 'list', $delta = 0, $edit = array()) {
|
||||
if ($op == 'list') {
|
||||
$result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
|
||||
while ($category = db_fetch_object($result)) {
|
||||
$block['category-'. $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title));
|
||||
}
|
||||
$result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid');
|
||||
while ($feed = db_fetch_object($result)) {
|
||||
$block['feed-'. $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title));
|
||||
}
|
||||
}
|
||||
else if ($op == 'configure') {
|
||||
list($type, $id) = explode('-', $delta);
|
||||
if ($type == 'category') {
|
||||
$value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id));
|
||||
}
|
||||
else {
|
||||
$value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
|
||||
}
|
||||
$form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
|
||||
return $form;
|
||||
}
|
||||
else if ($op == 'save') {
|
||||
list($type, $id) = explode('-', $delta);
|
||||
if ($type == 'category') {
|
||||
$value = db_query('UPDATE {aggregator_category} SET block = %d WHERE cid = %d', $edit['block'], $id);
|
||||
}
|
||||
else {
|
||||
$value = db_query('UPDATE {aggregator_feed} SET block = %d WHERE fid = %d', $edit['block'], $id);
|
||||
}
|
||||
}
|
||||
else if ($op == 'view') {
|
||||
if (user_access('access news feeds')) {
|
||||
list($type, $id) = explode('-', $delta);
|
||||
switch ($type) {
|
||||
case 'feed':
|
||||
if ($feed = db_fetch_object(db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE fid = %d', $id))) {
|
||||
$block['subject'] = check_plain($feed->title);
|
||||
$result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, $feed->block);
|
||||
$read_more = theme('more_link', url('aggregator/sources/'. $feed->fid), t("View this feed's recent news."));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
if ($category = db_fetch_object(db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = %d', $id))) {
|
||||
$block['subject'] = check_plain($category->title);
|
||||
$result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = %d ORDER BY i.timestamp DESC, i.iid DESC', $category->cid, 0, $category->block);
|
||||
$read_more = theme('more_link', url('aggregator/categories/'. $category->cid), t("View this category's recent news."));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$items = array();
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$items[] = theme('aggregator_block_item', $item);
|
||||
}
|
||||
|
||||
// Only display the block if there are items to show.
|
||||
if (count($items) > 0) {
|
||||
$block['content'] = theme('item_list', $items) . $read_more;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($block)) {
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/edit/delete aggregator categories.
|
||||
*
|
||||
* @param $edit
|
||||
* An associative array describing the category to be added/edited/deleted.
|
||||
*/
|
||||
function aggregator_save_category($edit) {
|
||||
$link_path = 'aggregator/categories/';
|
||||
if (!empty($edit['cid'])) {
|
||||
$link_path .= $edit['cid'];
|
||||
if (!empty($edit['title'])) {
|
||||
db_query("UPDATE {aggregator_category} SET title = '%s', description = '%s' WHERE cid = %d", $edit['title'], $edit['description'], $edit['cid']);
|
||||
$op = 'update';
|
||||
}
|
||||
else {
|
||||
db_query('DELETE FROM {aggregator_category} WHERE cid = %d', $edit['cid']);
|
||||
// Make sure there is no active block for this category.
|
||||
db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'category-' . $edit['cid']);
|
||||
$edit['title'] = '';
|
||||
$op = 'delete';
|
||||
}
|
||||
}
|
||||
else if (!empty($edit['title'])) {
|
||||
// A single unique id for bundles and feeds, to use in blocks
|
||||
db_query("INSERT INTO {aggregator_category} (title, description, block) VALUES ('%s', '%s', 5)", $edit['title'], $edit['description']);
|
||||
$link_path .= db_last_insert_id('aggregator_category', 'cid');
|
||||
$op = 'insert';
|
||||
}
|
||||
if (isset($op)) {
|
||||
menu_link_maintain('aggregator', $op, $link_path, $edit['title']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/edit/delete an aggregator feed.
|
||||
*
|
||||
* @param $edit
|
||||
* An associative array describing the feed to be added/edited/deleted.
|
||||
*/
|
||||
function aggregator_save_feed($edit) {
|
||||
if (!empty($edit['fid'])) {
|
||||
// An existing feed is being modified, delete the category listings.
|
||||
db_query('DELETE FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
|
||||
}
|
||||
if (!empty($edit['fid']) && !empty($edit['title'])) {
|
||||
db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['fid']);
|
||||
}
|
||||
else if (!empty($edit['fid'])) {
|
||||
$items = array();
|
||||
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$items[] = "iid = $item->iid";
|
||||
}
|
||||
if (!empty($items)) {
|
||||
db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
|
||||
}
|
||||
db_query('DELETE FROM {aggregator_feed} WHERE fid = %d', $edit['fid']);
|
||||
db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
|
||||
// Make sure there is no active block for this feed.
|
||||
db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'feed-' . $edit['fid']);
|
||||
}
|
||||
else if (!empty($edit['title'])) {
|
||||
db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block, description, image) VALUES ('%s', '%s', %d, 5, '', '')", $edit['title'], $edit['url'], $edit['refresh']);
|
||||
// A single unique id for bundles and feeds, to use in blocks.
|
||||
$edit['fid'] = db_last_insert_id('aggregator_feed', 'fid');
|
||||
}
|
||||
if (!empty($edit['title'])) {
|
||||
// The feed is being saved, save the categories as well.
|
||||
if (!empty($edit['category'])) {
|
||||
foreach ($edit['category'] as $cid => $value) {
|
||||
if ($value) {
|
||||
db_query('INSERT INTO {aggregator_category_feed} (fid, cid) VALUES (%d, %d)', $edit['fid'], $cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all items from a feed.
|
||||
*
|
||||
* @param $feed
|
||||
* An associative array describing the feed to be cleared.
|
||||
*/
|
||||
function aggregator_remove($feed) {
|
||||
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$items[] = "iid = $item->iid";
|
||||
}
|
||||
if (!empty($items)) {
|
||||
db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
|
||||
}
|
||||
db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
|
||||
db_query("UPDATE {aggregator_feed} SET checked = 0, etag = '', modified = 0 WHERE fid = %d", $feed['fid']);
|
||||
drupal_set_message(t('The news items from %site have been removed.', array('%site' => $feed['title'])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call-back function used by the XML parser.
|
||||
*/
|
||||
function aggregator_element_start($parser, $name, $attributes) {
|
||||
global $item, $element, $tag, $items, $channel;
|
||||
|
||||
switch ($name) {
|
||||
case 'IMAGE':
|
||||
case 'TEXTINPUT':
|
||||
case 'CONTENT':
|
||||
case 'SUMMARY':
|
||||
case 'TAGLINE':
|
||||
case 'SUBTITLE':
|
||||
case 'LOGO':
|
||||
case 'INFO':
|
||||
$element = $name;
|
||||
break;
|
||||
case 'ID':
|
||||
if ($element != 'ITEM') {
|
||||
$element = $name;
|
||||
}
|
||||
case 'LINK':
|
||||
if (!empty($attributes['REL']) && $attributes['REL'] == 'alternate') {
|
||||
if ($element == 'ITEM') {
|
||||
$items[$item]['LINK'] = $attributes['HREF'];
|
||||
}
|
||||
else {
|
||||
$channel['LINK'] = $attributes['HREF'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'ITEM':
|
||||
$element = $name;
|
||||
$item += 1;
|
||||
break;
|
||||
case 'ENTRY':
|
||||
$element = 'ITEM';
|
||||
$item += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call-back function used by the XML parser.
|
||||
*/
|
||||
function aggregator_element_end($parser, $name) {
|
||||
global $element;
|
||||
|
||||
switch ($name) {
|
||||
case 'IMAGE':
|
||||
case 'TEXTINPUT':
|
||||
case 'ITEM':
|
||||
case 'ENTRY':
|
||||
case 'CONTENT':
|
||||
case 'INFO':
|
||||
$element = '';
|
||||
break;
|
||||
case 'ID':
|
||||
if ($element == 'ID') {
|
||||
$element = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call-back function used by the XML parser.
|
||||
*/
|
||||
function aggregator_element_data($parser, $data) {
|
||||
global $channel, $element, $items, $item, $image, $tag;
|
||||
$items += array($item => array());
|
||||
switch ($element) {
|
||||
case 'ITEM':
|
||||
$items[$item] += array($tag => '');
|
||||
$items[$item][$tag] .= $data;
|
||||
break;
|
||||
case 'IMAGE':
|
||||
case 'LOGO':
|
||||
$image += array($tag => '');
|
||||
$image[$tag] .= $data;
|
||||
break;
|
||||
case 'LINK':
|
||||
if ($data) {
|
||||
$items[$item] += array($tag => '');
|
||||
$items[$item][$tag] .= $data;
|
||||
}
|
||||
break;
|
||||
case 'CONTENT':
|
||||
$items[$item] += array('CONTENT' => '');
|
||||
$items[$item]['CONTENT'] .= $data;
|
||||
break;
|
||||
case 'SUMMARY':
|
||||
$items[$item] += array('SUMMARY' => '');
|
||||
$items[$item]['SUMMARY'] .= $data;
|
||||
break;
|
||||
case 'TAGLINE':
|
||||
case 'SUBTITLE':
|
||||
$channel += array('DESCRIPTION' => '');
|
||||
$channel['DESCRIPTION'] .= $data;
|
||||
break;
|
||||
case 'INFO':
|
||||
case 'ID':
|
||||
case 'TEXTINPUT':
|
||||
// The sub-element is not supported. However, we must recognize
|
||||
// it or its contents will end up in the item array.
|
||||
break;
|
||||
default:
|
||||
$channel += array($tag => '');
|
||||
$channel[$tag] .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a news feed for new items.
|
||||
*
|
||||
* @param $feed
|
||||
* An associative array describing the feed to be refreshed.
|
||||
*/
|
||||
function aggregator_refresh($feed) {
|
||||
global $channel, $image;
|
||||
|
||||
// Generate conditional GET headers.
|
||||
$headers = array();
|
||||
if ($feed['etag']) {
|
||||
$headers['If-None-Match'] = $feed['etag'];
|
||||
}
|
||||
if ($feed['modified']) {
|
||||
$headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) .' GMT';
|
||||
}
|
||||
|
||||
// Request feed.
|
||||
$result = drupal_http_request($feed['url'], $headers);
|
||||
|
||||
// Process HTTP response code.
|
||||
switch ($result->code) {
|
||||
case 304:
|
||||
db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']);
|
||||
drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title'])));
|
||||
break;
|
||||
case 301:
|
||||
$feed['url'] = $result->redirect_url;
|
||||
watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url']));
|
||||
// Deliberate no break.
|
||||
case 200:
|
||||
case 302:
|
||||
case 307:
|
||||
// Filter the input data:
|
||||
if (aggregator_parse_feed($result->data, $feed)) {
|
||||
$modified = empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']);
|
||||
|
||||
// Prepare the channel data.
|
||||
foreach ($channel as $key => $value) {
|
||||
$channel[$key] = trim($value);
|
||||
}
|
||||
|
||||
// Prepare the image data (if any).
|
||||
foreach ($image as $key => $value) {
|
||||
$image[$key] = trim($value);
|
||||
}
|
||||
|
||||
if (!empty($image['LINK']) && !empty($image['URL']) && !empty($image['TITLE'])) {
|
||||
// Note, we should really use theme_image() here but that only works with local images it won't work with images fetched with a URL unless PHP version > 5
|
||||
$image = '<a href="'. check_url($image['LINK']) .'" class="feed-image"><img src="'. check_url($image['URL']) .'" alt="'. check_plain($image['TITLE']) .'" /></a>';
|
||||
}
|
||||
else {
|
||||
$image = NULL;
|
||||
}
|
||||
|
||||
$etag = empty($result->headers['ETag']) ? '' : $result->headers['ETag'];
|
||||
// Update the feed data.
|
||||
db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $etag, $modified, $feed['fid']);
|
||||
|
||||
// Clear the cache.
|
||||
cache_clear_all();
|
||||
|
||||
watchdog('aggregator', 'There is new syndicated content from %site.', array('%site' => $feed['title']));
|
||||
drupal_set_message(t('There is new syndicated content from %site.', array('%site' => $feed['title'])));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error), WATCHDOG_WARNING);
|
||||
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing
|
||||
* functions do not handle this format.
|
||||
* See http://www.w3.org/TR/NOTE-datetime for more information.
|
||||
* Originally from MagpieRSS (http://magpierss.sourceforge.net/).
|
||||
*
|
||||
* @param $date_str
|
||||
* A string with a potentially W3C DTF date.
|
||||
* @return
|
||||
* A timestamp if parsed successfully or FALSE if not.
|
||||
*/
|
||||
function aggregator_parse_w3cdtf($date_str) {
|
||||
if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) {
|
||||
list($year, $month, $day, $hours, $minutes, $seconds) = array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]);
|
||||
// calc epoch for current date assuming GMT
|
||||
$epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year);
|
||||
if ($match[10] != 'Z') { // Z is zulu time, aka GMT
|
||||
list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]);
|
||||
// zero out the variables
|
||||
if (!$tz_hour) {
|
||||
$tz_hour = 0;
|
||||
}
|
||||
if (!$tz_min) {
|
||||
$tz_min = 0;
|
||||
}
|
||||
$offset_secs = (($tz_hour * 60) + $tz_min) * 60;
|
||||
// is timezone ahead of GMT? then subtract offset
|
||||
if ($tz_mod == '+') {
|
||||
$offset_secs *= -1;
|
||||
}
|
||||
$epoch += $offset_secs;
|
||||
}
|
||||
return $epoch;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a feed and store its items.
|
||||
*
|
||||
* @param $data
|
||||
* The feed data.
|
||||
* @param $feed
|
||||
* An associative array describing the feed to be parsed.
|
||||
* @return
|
||||
* 0 on error, 1 otherwise.
|
||||
*/
|
||||
function aggregator_parse_feed(&$data, $feed) {
|
||||
global $items, $image, $channel;
|
||||
|
||||
// Unset the global variables before we use them:
|
||||
unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']);
|
||||
$items = array();
|
||||
$image = array();
|
||||
$channel = array();
|
||||
|
||||
// parse the data:
|
||||
$xml_parser = drupal_xml_parser_create($data);
|
||||
xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end');
|
||||
xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
|
||||
|
||||
if (!xml_parse($xml_parser, $data, 1)) {
|
||||
watchdog('aggregator', 'The feed from %site seems to be broken, due to an error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)), WATCHDOG_WARNING);
|
||||
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error');
|
||||
return 0;
|
||||
}
|
||||
xml_parser_free($xml_parser);
|
||||
|
||||
// We reverse the array such that we store the first item last, and the last
|
||||
// item first. In the database, the newest item should be at the top.
|
||||
$items = array_reverse($items);
|
||||
|
||||
// Initialize variables.
|
||||
$title = $link = $author = $description = $guid = NULL;
|
||||
foreach ($items as $item) {
|
||||
unset($title, $link, $author, $description, $guid);
|
||||
|
||||
// Prepare the item:
|
||||
foreach ($item as $key => $value) {
|
||||
$item[$key] = trim($value);
|
||||
}
|
||||
|
||||
// Resolve the item's title. If no title is found, we use up to 40
|
||||
// characters of the description ending at a word boundary but not
|
||||
// splitting potential entities.
|
||||
if (!empty($item['TITLE'])) {
|
||||
$title = $item['TITLE'];
|
||||
}
|
||||
elseif (!empty($item['DESCRIPTION'])) {
|
||||
$title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40));
|
||||
}
|
||||
else {
|
||||
$title = '';
|
||||
}
|
||||
|
||||
// Resolve the items link.
|
||||
if (!empty($item['LINK'])) {
|
||||
$link = $item['LINK'];
|
||||
}
|
||||
else {
|
||||
$link = $feed['link'];
|
||||
}
|
||||
|
||||
// Atom feeds use ID rather than GUID.
|
||||
if (isset($item['GUID'])) {
|
||||
$guid = $item['GUID'];
|
||||
}
|
||||
elseif (isset($item['ID'])) {
|
||||
$guid = $item['ID'];
|
||||
}
|
||||
else {
|
||||
$guid = '';
|
||||
}
|
||||
|
||||
// Atom feeds have a CONTENT and/or SUMMARY tag instead of a DESCRIPTION tag.
|
||||
if (!empty($item['CONTENT:ENCODED'])) {
|
||||
$item['DESCRIPTION'] = $item['CONTENT:ENCODED'];
|
||||
}
|
||||
else if (!empty($item['SUMMARY'])) {
|
||||
$item['DESCRIPTION'] = $item['SUMMARY'];
|
||||
}
|
||||
else if (!empty($item['CONTENT'])) {
|
||||
$item['DESCRIPTION'] = $item['CONTENT'];
|
||||
}
|
||||
|
||||
// Try to resolve and parse the item's publication date. If no date is
|
||||
// found, we use the current date instead.
|
||||
$date = 'now';
|
||||
foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) {
|
||||
if (!empty($item[$key])) {
|
||||
$date = $item[$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = strtotime($date); // As of PHP 5.1.0, strtotime returns FALSE on failure instead of -1.
|
||||
if ($timestamp <= 0) {
|
||||
$timestamp = aggregator_parse_w3cdtf($date); // Returns FALSE on failure
|
||||
if (!$timestamp) {
|
||||
$timestamp = time(); // better than nothing
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve dc:creator tag as the item author if author tag is not set.
|
||||
if (empty($item['AUTHOR']) && !empty($item['DC:CREATOR'])) {
|
||||
$item['AUTHOR'] = $item['DC:CREATOR'];
|
||||
}
|
||||
|
||||
// Save this item. Try to avoid duplicate entries as much as possible. If
|
||||
// we find a duplicate entry, we resolve it and pass along its ID is such
|
||||
// that we can update it if needed.
|
||||
if (!empty($guid)) {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $guid));
|
||||
}
|
||||
else if ($link && $link != $feed['link'] && $link != $feed['url']) {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link));
|
||||
}
|
||||
else {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title));
|
||||
}
|
||||
$item += array('AUTHOR' => '', 'DESCRIPTION' => '');
|
||||
aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid: ''), 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'], 'guid' => $guid));
|
||||
}
|
||||
|
||||
// Remove all items that are older than flush item timer.
|
||||
$age = time() - variable_get('aggregator_clear', 9676800);
|
||||
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
|
||||
|
||||
$items = array();
|
||||
$num_rows = FALSE;
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$items[] = $item->iid;
|
||||
$num_rows = TRUE;
|
||||
}
|
||||
if ($num_rows) {
|
||||
db_query('DELETE FROM {aggregator_category_item} WHERE iid IN ('. implode(', ', $items) .')');
|
||||
db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/edit/delete an aggregator item.
|
||||
*
|
||||
* @param $edit
|
||||
* An associative array describing the item to be added/edited/deleted.
|
||||
*/
|
||||
function aggregator_save_item($edit) {
|
||||
if ($edit['iid'] && $edit['title']) {
|
||||
db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s', guid = '%s', timestamp = %d WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['guid'], $edit['timestamp'], $edit['iid']);
|
||||
}
|
||||
else if ($edit['iid']) {
|
||||
db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']);
|
||||
db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']);
|
||||
}
|
||||
else if ($edit['title'] && $edit['link']) {
|
||||
db_query("INSERT INTO {aggregator_item} (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp'], $edit['guid']);
|
||||
$edit['iid'] = db_last_insert_id('aggregator_item', 'iid');
|
||||
// file the items in the categories indicated by the feed
|
||||
$categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
|
||||
while ($category = db_fetch_object($categories)) {
|
||||
db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $category->cid, $edit['iid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an aggregator feed.
|
||||
*
|
||||
* @param $fid
|
||||
* The feed id.
|
||||
* @return
|
||||
* An associative array describing the feed.
|
||||
*/
|
||||
function aggregator_feed_load($fid) {
|
||||
static $feeds;
|
||||
if (!isset($feeds[$fid])) {
|
||||
$feeds[$fid] = db_fetch_array(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', $fid));
|
||||
}
|
||||
return $feeds[$fid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an aggregator category.
|
||||
*
|
||||
* @param $cid
|
||||
* The category id.
|
||||
* @return
|
||||
* An associative array describing the category.
|
||||
*/
|
||||
function aggregator_category_load($cid) {
|
||||
static $categories;
|
||||
if (!isset($categories[$cid])) {
|
||||
$categories[$cid] = db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid));
|
||||
}
|
||||
return $categories[$cid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an individual feed item for display in the block.
|
||||
*
|
||||
* @param $item
|
||||
* The item to be displayed.
|
||||
* @param $feed
|
||||
* Not used.
|
||||
* @return
|
||||
* The item HTML.
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_aggregator_block_item($item, $feed = 0) {
|
||||
global $user;
|
||||
|
||||
$output = '';
|
||||
if ($user->uid && module_exists('blog') && user_access('create blog entries')) {
|
||||
if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
|
||||
$output .= '<div class="icon">'. l($image, 'node/add/blog', array('attributes' => array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), 'query' => "iid=$item->iid", 'html' => TRUE)) .'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Display the external link to the item.
|
||||
$output .= '<a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a>\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely render HTML content, as allowed.
|
||||
*
|
||||
* @param $value
|
||||
* The content to be filtered.
|
||||
* @return
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for drupal_map_assoc.
|
||||
*
|
||||
* @param $count
|
||||
* Items count.
|
||||
* @return
|
||||
* Plural-formatted "@count items"
|
||||
*/
|
||||
function _aggregator_items($count) {
|
||||
return format_plural($count, '1 item', '@count items');
|
||||
}
|
490
modules/aggregator/aggregator.pages.inc
Normal file
490
modules/aggregator/aggregator.pages.inc
Normal file
|
@ -0,0 +1,490 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* User page callbacks for the aggregator module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; displays the most recent items gathered from any feed.
|
||||
*
|
||||
* @return
|
||||
* The items HTML.
|
||||
*/
|
||||
function aggregator_page_last() {
|
||||
drupal_add_feed(url('aggregator/rss'), variable_get('site_name', 'Drupal') .' '. t('aggregator'));
|
||||
|
||||
$items = aggregator_feed_items_load('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC');
|
||||
|
||||
return _aggregator_page_list($items, arg(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; displays all the items captured from a particular feed.
|
||||
*
|
||||
* If there are two arguments then this function is the categorize form.
|
||||
*
|
||||
* @param $arg1
|
||||
* If there are two arguments then $arg1 is $form_state. Otherwise, $arg1 is $feed.
|
||||
* @param $arg2
|
||||
* If there are two arguments then $arg2 is feed.
|
||||
* @return
|
||||
* The items HTML.
|
||||
*/
|
||||
function aggregator_page_source($arg1, $arg2 = NULL) {
|
||||
// If there are two arguments then this function is the categorize form, and
|
||||
// $arg1 is $form_state and $arg2 is $feed. Otherwise, $arg1 is $feed.
|
||||
$feed = is_array($arg2) ? $arg2 : $arg1;
|
||||
$feed = (object)$feed;
|
||||
drupal_set_title(check_plain($feed->title));
|
||||
$feed_source = theme('aggregator_feed_source', $feed);
|
||||
|
||||
// It is safe to include the fid in the query because it's loaded from the
|
||||
// database by aggregator_feed_load.
|
||||
$items = aggregator_feed_items_load('SELECT * FROM {aggregator_item} WHERE fid = '. $feed->fid .' ORDER BY timestamp DESC, iid DESC');
|
||||
|
||||
return _aggregator_page_list($items, arg(3), $feed_source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; displays all the items aggregated in a particular category.
|
||||
*
|
||||
* If there are two arguments then this function is called as a form.
|
||||
*
|
||||
* @param $arg1
|
||||
* If there are two arguments then $arg1 is $form_state. Otherwise, $arg1 is $category.
|
||||
* @param $arg2
|
||||
* If there are two arguments then $arg2 is $category.
|
||||
* @return
|
||||
* The items HTML.
|
||||
*/
|
||||
function aggregator_page_category($arg1, $arg2 = NULL) {
|
||||
// If there are two arguments then we are called as a form, $arg1 is
|
||||
// $form_state and $arg2 is $category. Otherwise, $arg1 is $category.
|
||||
$category = is_array($arg2) ? $arg2 : $arg1;
|
||||
|
||||
drupal_add_feed(url('aggregator/rss/'. $category['cid']), variable_get('site_name', 'Drupal') .' '. t('aggregator - @title', array('@title' => $category['title'])));
|
||||
|
||||
// It is safe to include the cid in the query because it's loaded from the
|
||||
// database by aggregator_category_load.
|
||||
$items = aggregator_feed_items_load('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = '. $category['cid'] .' ORDER BY timestamp DESC, i.iid DESC');
|
||||
|
||||
return _aggregator_page_list($items, arg(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load feed items by passing a SQL query.
|
||||
*
|
||||
* @param $sql
|
||||
* The query to be executed.
|
||||
* @return
|
||||
* An array of the feed items.
|
||||
*/
|
||||
function aggregator_feed_items_load($sql) {
|
||||
$items = array();
|
||||
if (isset($sql)) {
|
||||
$result = pager_query($sql, 20);
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$result_category = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
|
||||
$item->categories = array();
|
||||
while ($item_categories = db_fetch_object($result_category)) {
|
||||
$item->categories[] = $item_categories;
|
||||
}
|
||||
$items[$item->iid] = $item;
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an aggregator page listing a number of feed items.
|
||||
*
|
||||
* Various menu callbacks use this function to print their feeds.
|
||||
*
|
||||
* @param $items
|
||||
* The items to be listed.
|
||||
* @param $op
|
||||
* Which form should be added to the items. Only 'categorize' is now recognized.
|
||||
* @param $feed_source
|
||||
* The feed source URL.
|
||||
* @return
|
||||
* The items HTML.
|
||||
*/
|
||||
function _aggregator_page_list($items, $op, $feed_source = '') {
|
||||
if (user_access('administer news feeds') && ($op == 'categorize')) {
|
||||
// Get form data.
|
||||
$output = aggregator_categorize_items($items, $feed_source);
|
||||
}
|
||||
else {
|
||||
// Assemble themed output.
|
||||
$output = $feed_source;
|
||||
foreach ($items as $item) {
|
||||
$output .= theme('aggregator_item', $item);
|
||||
}
|
||||
$output = theme('aggregator_wrapper', $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; build the page list form.
|
||||
*
|
||||
* @param $items
|
||||
* An array of the feed items.
|
||||
* @param $feed_source
|
||||
* The feed source URL.
|
||||
* @return
|
||||
* The form structure.
|
||||
* @ingroup forms
|
||||
* @see aggregator_categorize_items_validate()
|
||||
* @see aggregator_categorize_items_submit()
|
||||
*/
|
||||
function aggregator_categorize_items($items, $feed_source = '') {
|
||||
$form['#submit'][] = 'aggregator_categorize_items_submit';
|
||||
$form['#validate'][] = 'aggregator_categorize_items_validate';
|
||||
$form['#theme'] = 'aggregator_categorize_items';
|
||||
$form['feed_source'] = array('#value' => $feed_source);
|
||||
$categories = array();
|
||||
$done = FALSE;
|
||||
$form['items'] = array();
|
||||
$form['categories'] = array('#tree' => TRUE);
|
||||
foreach ($items as $item) {
|
||||
$form['items'][$item->iid] = array('#value' => theme('aggregator_item', $item));
|
||||
$form['categories'][$item->iid] = array();
|
||||
$categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = %d', $item->iid);
|
||||
$selected = array();
|
||||
while ($category = db_fetch_object($categories_result)) {
|
||||
if (!$done) {
|
||||
$categories[$category->cid] = check_plain($category->title);
|
||||
}
|
||||
if ($category->iid) {
|
||||
$selected[] = $category->cid;
|
||||
}
|
||||
}
|
||||
$done = TRUE;
|
||||
$form['categories'][$item->iid] = array(
|
||||
'#type' => variable_get('aggregator_category_selector', 'checkboxes'),
|
||||
'#default_value' => $selected,
|
||||
'#options' => $categories,
|
||||
'#size' => 10,
|
||||
'#multiple' => TRUE
|
||||
);
|
||||
}
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => t('Save categories'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate aggregator_categorize_items form submissions.
|
||||
*/
|
||||
function aggregator_categorize_items_validate($form, &$form_state) {
|
||||
if (!user_access('administer news feeds')) {
|
||||
form_error($form, t('You are not allowed to categorize this feed item.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process aggregator_categorize_items form submissions.
|
||||
*/
|
||||
function aggregator_categorize_items_submit($form, &$form_state) {
|
||||
if (!empty($form_state['values']['categories'])) {
|
||||
foreach ($form_state['values']['categories'] as $iid => $selection) {
|
||||
db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
|
||||
foreach ($selection as $cid) {
|
||||
if ($cid) {
|
||||
db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
drupal_set_message(t('The categories have been saved.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the page list form for assigning categories.
|
||||
*
|
||||
* @param $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @return
|
||||
* The output HTML.
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_aggregator_categorize_items($form) {
|
||||
$output = drupal_render($form['feed_source']);
|
||||
$rows = array();
|
||||
if ($form['items']) {
|
||||
foreach (element_children($form['items']) as $key) {
|
||||
if (is_array($form['items'][$key])) {
|
||||
$rows[] = array(
|
||||
drupal_render($form['items'][$key]),
|
||||
array('data' => drupal_render($form['categories'][$key]), 'class' => 'categorize-item'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$output .= theme('table', array('', t('Categorize')), $rows);
|
||||
$output .= drupal_render($form['submit']);
|
||||
$output .= drupal_render($form);
|
||||
return theme('aggregator_wrapper', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process variables for aggregator-wrapper.tpl.php.
|
||||
*
|
||||
* @see aggregator-wrapper.tpl.php
|
||||
*/
|
||||
function template_preprocess_aggregator_wrapper(&$variables) {
|
||||
$variables['pager'] = theme('pager', NULL, 20, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process variables for aggregator-item.tpl.php.
|
||||
*
|
||||
* @see aggregator-item.tpl.php
|
||||
*/
|
||||
function template_preprocess_aggregator_item(&$variables) {
|
||||
$item = $variables['item'];
|
||||
|
||||
$variables['feed_url'] = check_url($item->link);
|
||||
$variables['feed_title'] = check_plain($item->title);
|
||||
$variables['content'] = aggregator_filter_xss($item->description);
|
||||
|
||||
$variables['source_url'] = '';
|
||||
$variables['source_title'] = '';
|
||||
if (isset($item->ftitle) && isset($item->fid)) {
|
||||
$variables['source_url'] = url("aggregator/sources/$item->fid");
|
||||
$variables['source_title'] = check_plain($item->ftitle);
|
||||
}
|
||||
if (date('Ymd', $item->timestamp) == date('Ymd')) {
|
||||
$variables['source_date'] = t('%ago ago', array('%ago' => format_interval(time() - $item->timestamp)));
|
||||
}
|
||||
else {
|
||||
$variables['source_date'] = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, m/d/Y - H:i'));
|
||||
}
|
||||
|
||||
$variables['categories'] = array();
|
||||
foreach ($item->categories as $category) {
|
||||
$variables['categories'][$category->cid] = l($category->title, 'aggregator/categories/'. $category->cid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; displays all the feeds used by the aggregator.
|
||||
*/
|
||||
function aggregator_page_sources() {
|
||||
$result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title');
|
||||
|
||||
$output = '';
|
||||
while ($feed = db_fetch_object($result)) {
|
||||
// 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 = %d ORDER BY i.timestamp DESC', $feed->fid, 0, variable_get('aggregator_summary_items', 3));
|
||||
while ($item = db_fetch_object($items)) {
|
||||
$summary_items[] = theme('aggregator_summary_item', $item);
|
||||
}
|
||||
}
|
||||
$feed->url = url('aggregator/sources/'. $feed->fid);
|
||||
$output .= theme('aggregator_summary_items', $summary_items, $feed);
|
||||
}
|
||||
$output .= theme('feed_icon', url('aggregator/opml'), t('OPML feed'));
|
||||
|
||||
return theme('aggregator_wrapper', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; displays all the categories used by the aggregator.
|
||||
*/
|
||||
function aggregator_page_categories() {
|
||||
$result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
|
||||
|
||||
$output = '';
|
||||
while ($category = db_fetch_object($result)) {
|
||||
if (variable_get('aggregator_summary_items', 3)) {
|
||||
$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 = %d ORDER BY i.timestamp DESC', $category->cid, 0, variable_get('aggregator_summary_items', 3));
|
||||
while ($item = db_fetch_object($items)) {
|
||||
$summary_items[] = theme('aggregator_summary_item', $item);
|
||||
}
|
||||
}
|
||||
$category->url = url('aggregator/categories/'. $category->cid);
|
||||
$output .= theme('aggregator_summary_items', $summary_items, $category);
|
||||
}
|
||||
|
||||
return theme('aggregator_wrapper', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
|
||||
*/
|
||||
function aggregator_page_rss() {
|
||||
$result = NULL;
|
||||
// arg(2) is the passed cid, only select for that category
|
||||
if (arg(2)) {
|
||||
$category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2)));
|
||||
$sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, i.iid DESC';
|
||||
$result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
|
||||
}
|
||||
// or, get the default aggregator items
|
||||
else {
|
||||
$category = NULL;
|
||||
$sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC';
|
||||
$result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
|
||||
}
|
||||
|
||||
$feeds = array();
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$feeds[] = $item;
|
||||
}
|
||||
return theme('aggregator_page_rss', $feeds, $category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the RSS output.
|
||||
*
|
||||
* @param $feeds
|
||||
* An array of the feeds to theme.
|
||||
* @param $category
|
||||
* A common category, if any, for all the feeds.
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_aggregator_page_rss($feeds, $category = NULL) {
|
||||
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
|
||||
|
||||
$items = '';
|
||||
$feed_length = variable_get('feed_item_length', 'teaser');
|
||||
foreach ($feeds as $feed) {
|
||||
switch ($feed_length) {
|
||||
case 'teaser':
|
||||
$teaser = node_teaser($feed->description);
|
||||
if ($teaser != $feed->description) {
|
||||
$teaser .= '<p><a href="'. check_url($feed->link) .'">'. t('read more') ."</a></p>\n";
|
||||
}
|
||||
$feed->description = $teaser;
|
||||
break;
|
||||
case 'title':
|
||||
$feed->description = '';
|
||||
break;
|
||||
}
|
||||
$items .= format_rss_item($feed->ftitle .': '. $feed->title, $feed->link, $feed->description, array('pubDate' => date('r', $feed->timestamp)));
|
||||
}
|
||||
|
||||
$site_name = variable_get('site_name', 'Drupal');
|
||||
$url = url((isset($category) ? 'aggregator/categories/'. $category->cid : 'aggregator'), array('absolute' => TRUE));
|
||||
$description = isset($category) ? t('@site_name - aggregated feeds in category @title', array('@site_name' => $site_name, '@title' => $category->title)) : t('@site_name - aggregated feeds', array('@site_name' => $site_name));
|
||||
|
||||
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
||||
$output .= "<rss version=\"2.0\">\n";
|
||||
$output .= format_rss_channel(t('@site_name aggregator', array('@site_name' => $site_name)), $url, $description, $items);
|
||||
$output .= "</rss>\n";
|
||||
|
||||
print $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; generates an OPML representation of all feeds.
|
||||
*
|
||||
* @param $cid
|
||||
* If set, feeds are exported only from a category with this ID. Otherwise, all feeds are exported.
|
||||
* @return
|
||||
* The output XML.
|
||||
*/
|
||||
function aggregator_page_opml($cid = NULL) {
|
||||
if ($cid) {
|
||||
$result = db_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = %d ORDER BY title', $cid);
|
||||
}
|
||||
else {
|
||||
$result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title');
|
||||
}
|
||||
|
||||
$feeds = array();
|
||||
while ($item = db_fetch_object($result)) {
|
||||
$feeds[] = $item;
|
||||
}
|
||||
|
||||
return theme('aggregator_page_opml', $feeds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the OPML feed output.
|
||||
*
|
||||
* @param $feeds
|
||||
* An array of the feeds to theme.
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_aggregator_page_opml($feeds) {
|
||||
|
||||
drupal_set_header('Content-Type: text/xml; charset=utf-8');
|
||||
|
||||
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
||||
$output .= "<opml version=\"1.1\">\n";
|
||||
$output .= "<head>\n";
|
||||
$output .= '<title>'. check_plain(variable_get('site_name', 'Drupal')) ."</title>\n";
|
||||
$output .= '<dateModified>'. gmdate('r') ."</dateModified>\n";
|
||||
$output .= "</head>\n";
|
||||
$output .= "<body>\n";
|
||||
foreach ($feeds as $feed) {
|
||||
$output .= '<outline text="'. check_plain($feed->title) .'" xmlUrl="'. check_url($feed->url) ."\" />\n";
|
||||
}
|
||||
$output .= "</body>\n";
|
||||
$output .= "</opml>\n";
|
||||
|
||||
print $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process variables for aggregator-summary-items.tpl.php.
|
||||
*
|
||||
* @see aggregator-summary-item.tpl.php
|
||||
*/
|
||||
function template_preprocess_aggregator_summary_items(&$variables) {
|
||||
$variables['title'] = check_plain($variables['source']->title);
|
||||
$variables['summary_list'] = theme('item_list', $variables['summary_items']);
|
||||
$variables['source_url'] = $variables['source']->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process variables for aggregator-summary-item.tpl.php.
|
||||
*
|
||||
* @see aggregator-summary-item.tpl.php
|
||||
*/
|
||||
function template_preprocess_aggregator_summary_item(&$variables) {
|
||||
$item = $variables['item'];
|
||||
|
||||
$variables['feed_url'] = check_url($item->link);
|
||||
$variables['feed_title'] = check_plain($item->title);
|
||||
$variables['feed_age'] = t('%age old', array('%age' => format_interval(time() - $item->timestamp)));
|
||||
|
||||
$variables['source_url'] = '';
|
||||
$variables['source_title'] = '';
|
||||
if (!empty($item->feed_link)) {
|
||||
$variables['source_url'] = check_url($item->feed_link);
|
||||
$variables['source_title'] = check_plain($item->feed_title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process variables for aggregator-feed-source.tpl.php.
|
||||
*
|
||||
* @see aggregator-feed-source.tpl.php
|
||||
*/
|
||||
function template_preprocess_aggregator_feed_source(&$variables) {
|
||||
$feed = $variables['feed'];
|
||||
|
||||
$variables['source_icon'] = theme('feed_icon', $feed->url, t('!title feed', array('!title' => $feed->title)));
|
||||
$variables['source_image'] = $feed->image;
|
||||
$variables['source_description'] = aggregator_filter_xss($feed->description);
|
||||
$variables['source_url'] = check_url(url($feed->link, array('absolute' => TRUE)));
|
||||
|
||||
if ($feed->checked) {
|
||||
$variables['last_checked'] = t('@time ago', array('@time' => format_interval(time() - $feed->checked)));
|
||||
}
|
||||
else {
|
||||
$variables['last_checked'] = t('never');
|
||||
}
|
||||
|
||||
if (user_access('administer news feeds')) {
|
||||
$variables['last_checked'] = l($variables['last_checked'], 'admin/content/aggregator');
|
||||
}
|
||||
}
|
Reference in a new issue