Commit 1dc53d97 authored by Dries's avatar Dries

- Patch #3986 by James (and Boris :)):consolidated all feed-related settings in one place.

* adds a "feed settings" section to admin/settings where 2 new settings are introduced:
* number of items per feed
* default length of feed descriptions (title only, teaser, full)
* patches all of core to obey the above - including the new aggregator (out) feeds
* adds support for adding namespaces in _nodeapi('rss item') - which means things like iTunes RSS and yahoo's media rss can be implemented by the appropriate modules (i.e. audio.module)
* includes some additional info in the default node feed - specifically the element (links directly to comments) - and dc:creator - to show node author information.
parent ceb9859d
......@@ -1058,21 +1058,33 @@ function aggregator_page_rss() {
$url = '/categories/' . $category->cid;
$title = ' ' . t('in category') . ' ' . $category->title;
$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, iid DESC';
$result = db_query_range($sql, $category->cid, 0, 15);
$result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
}
// or, get the default aggregator items
else {
$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, 15);
$result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
}
while ($item = db_fetch_object($result)) {
switch (variable_get('feed_item_length', 'teaser')) {
case 'teaser':
$teaser = node_teaser($item->description);
if ($teaser != $item_description) {
$teaser .= '<p><a href="'. check_url($item->link) .'">'. t('read more') ."</a></p>\n";
}
$item->description = $teaser;
break;
case 'title':
$item->description = '';
break;
}
$items .= format_rss_item($item->ftitle . ': ' . $item->title, $item->link, $item->description, array('pubDate' => date('r', $item->timestamp)));
}
$output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
$output .= "<rss version=\"0.92\">\n";
$output .= "<rss version=\"2.0\">\n";
$output .= format_rss_channel(variable_get('site_name', t('Drupal')) . ' ' . t('aggregator'), $base_url . '/' . url('aggregator' . $url), variable_get('site_name', t('Drupal')) . ' - ' . t('aggregated feeds') . $title, $items, 'en');
$output .= "</rss>\n";
......
......@@ -1058,21 +1058,33 @@ function aggregator_page_rss() {
$url = '/categories/' . $category->cid;
$title = ' ' . t('in category') . ' ' . $category->title;
$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, iid DESC';
$result = db_query_range($sql, $category->cid, 0, 15);
$result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
}
// or, get the default aggregator items
else {
$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, 15);
$result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
}
while ($item = db_fetch_object($result)) {
switch (variable_get('feed_item_length', 'teaser')) {
case 'teaser':
$teaser = node_teaser($item->description);
if ($teaser != $item_description) {
$teaser .= '<p><a href="'. check_url($item->link) .'">'. t('read more') ."</a></p>\n";
}
$item->description = $teaser;
break;
case 'title':
$item->description = '';
break;
}
$items .= format_rss_item($item->ftitle . ': ' . $item->title, $item->link, $item->description, array('pubDate' => date('r', $item->timestamp)));
}
$output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
$output .= "<rss version=\"0.92\">\n";
$output .= "<rss version=\"2.0\">\n";
$output .= format_rss_channel(variable_get('site_name', t('Drupal')) . ' ' . t('aggregator'), $base_url . '/' . url('aggregator' . $url), variable_get('site_name', t('Drupal')) . ' - ' . t('aggregated feeds') . $title, $items, 'en');
$output .= "</rss>\n";
......
......@@ -77,7 +77,7 @@ function blog_feed_user($uid = 0) {
$account = $user;
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, 15);
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
$channel['title'] = $account->name ."'s blog";
$channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
$channel['description'] = $term->description;
......@@ -88,7 +88,7 @@ function blog_feed_user($uid = 0) {
* Displays an RSS feed containing recent blog entries of all users.
*/
function blog_feed_last() {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
$channel['title'] = variable_get('site_name', 'drupal') .' blogs';
$channel['link'] = url('blog', NULL, NULL, TRUE);
$channel['description'] = $term->description;
......
......@@ -77,7 +77,7 @@ function blog_feed_user($uid = 0) {
$account = $user;
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, 15);
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
$channel['title'] = $account->name ."'s blog";
$channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
$channel['description'] = $term->description;
......@@ -88,7 +88,7 @@ function blog_feed_user($uid = 0) {
* Displays an RSS feed containing recent blog entries of all users.
*/
function blog_feed_last() {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
$channel['title'] = variable_get('site_name', 'drupal') .' blogs';
$channel['link'] = url('blog', NULL, NULL, TRUE);
$channel['description'] = $term->description;
......
......@@ -284,6 +284,8 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
case 'search result':
$comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
return format_plural($comments, '1 comment', '%count comments');
case 'rss item':
return array(array('key' => 'comments', 'value' => url('node/'.$node->nid, NULL, 'comment', TRUE)));
}
}
......
......@@ -284,6 +284,8 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
case 'search result':
$comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
return format_plural($comments, '1 comment', '%count comments');
case 'rss item':
return array(array('key' => 'comments', 'value' => url('node/'.$node->nid, NULL, 'comment', TRUE)));
}
}
......
......@@ -1160,29 +1160,58 @@ function node_feed($nodes = 0, $channel = array()) {
global $base_url, $locale;
if (!$nodes) {
$nodes = db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, 15);
$nodes = db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, variable_get('feed_default_items', 10));
}
$item_length = variable_get('feed_item_length', 'teaser');
$namespaces = array('xmlns:dc="http://purl.org/dc/elements/1.1/"');
while ($node = db_fetch_object($nodes)) {
// Load the specified node:
$item = node_load($node->nid);
$link = url("node/$node->nid", NULL, NULL, 1);
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
node_invoke($item, 'view', TRUE, FALSE);
}
else {
$item = node_prepare($item, TRUE);
if ($item_length != 'title') {
$teaser = ($item_length == 'teaser') ? TRUE : FALSE;
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
node_invoke($item, 'view', $teaser, FALSE);
}
else {
$item = node_prepare($item, $teaser);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', $teaser, FALSE);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', true, false);
// Prepare the item description
switch ($item_length) {
case 'fulltext':
$item_text = $item->body;
break;
case 'teaser':
$item_text = $item->teaser;
if ($item->readmore) {
$item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'</p>';
}
break;
case 'title':
$item_text = '';
break;
}
// Allow modules to add additional item fields
$extra = node_invoke_nodeapi($item, 'rss item');
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created))));
$items .= format_rss_item($item->title, $link, $item->teaser, $extra);
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)),
array('key' => 'dc:creator', 'value' => $item->name)));
foreach ($extra as $element) {
if ($element['namespace']) {
$namespaces = array_merge($namespaces, array($element['namespace']));
}
}
$items .= format_rss_item($item->title, $link, $item_text, $extra);
}
$channel_defaults = array(
......@@ -1196,7 +1225,7 @@ function node_feed($nodes = 0, $channel = array()) {
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n";
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\" ". implode(' ', $namespaces) .">\n";
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
$output .= "</rss>\n";
......
......@@ -1160,29 +1160,58 @@ function node_feed($nodes = 0, $channel = array()) {
global $base_url, $locale;
if (!$nodes) {
$nodes = db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, 15);
$nodes = db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, variable_get('feed_default_items', 10));
}
$item_length = variable_get('feed_item_length', 'teaser');
$namespaces = array('xmlns:dc="http://purl.org/dc/elements/1.1/"');
while ($node = db_fetch_object($nodes)) {
// Load the specified node:
$item = node_load($node->nid);
$link = url("node/$node->nid", NULL, NULL, 1);
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
node_invoke($item, 'view', TRUE, FALSE);
}
else {
$item = node_prepare($item, TRUE);
if ($item_length != 'title') {
$teaser = ($item_length == 'teaser') ? TRUE : FALSE;
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
node_invoke($item, 'view', $teaser, FALSE);
}
else {
$item = node_prepare($item, $teaser);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', $teaser, FALSE);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', true, false);
// Prepare the item description
switch ($item_length) {
case 'fulltext':
$item_text = $item->body;
break;
case 'teaser':
$item_text = $item->teaser;
if ($item->readmore) {
$item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'</p>';
}
break;
case 'title':
$item_text = '';
break;
}
// Allow modules to add additional item fields
$extra = node_invoke_nodeapi($item, 'rss item');
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created))));
$items .= format_rss_item($item->title, $link, $item->teaser, $extra);
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)),
array('key' => 'dc:creator', 'value' => $item->name)));
foreach ($extra as $element) {
if ($element['namespace']) {
$namespaces = array_merge($namespaces, array($element['namespace']));
}
}
$items .= format_rss_item($item->title, $link, $item_text, $extra);
}
$channel_defaults = array(
......@@ -1196,7 +1225,7 @@ function node_feed($nodes = 0, $channel = array()) {
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n";
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\" ". implode(' ', $namespaces) .">\n";
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
$output .= "</rss>\n";
......
......@@ -238,6 +238,12 @@ function system_view_general() {
$output .= form_group_collapsible(t('Image handling'), '<p>'. $group .'</p>', TRUE);
}
// Feed settings
$group = '';
$group .= form_select(t('Number of items per feed'), 'feed_default_items', variable_get('feed_default_items', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default number of items to include in a feed.'));
$group .= form_select(t('Display of XML feed items'), 'feed_item_length', variable_get('feed_item_length','teaser'), array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), t('Global setting for the length of XML feed items that are output by default.'));
$output .= form_group_collapsible(t('RSS feed settings'), $group, TRUE);
// Date settings:
$zones = _system_zonelist();
......
......@@ -238,6 +238,12 @@ function system_view_general() {
$output .= form_group_collapsible(t('Image handling'), '<p>'. $group .'</p>', TRUE);
}
// Feed settings
$group = '';
$group .= form_select(t('Number of items per feed'), 'feed_default_items', variable_get('feed_default_items', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default number of items to include in a feed.'));
$group .= form_select(t('Display of XML feed items'), 'feed_item_length', variable_get('feed_item_length','teaser'), array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), t('Global setting for the length of XML feed items that are output by default.'));
$output .= form_group_collapsible(t('RSS feed settings'), $group, TRUE);
// Date settings:
$zones = _system_zonelist();
......
......@@ -979,7 +979,7 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count);
}
else {
$result = db_query_range($sql, 0, 15);
$result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
}
}
......
......@@ -979,7 +979,7 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count);
}
else {
$result = db_query_range($sql, 0, 15);
$result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment