From 1dc53d9761fbf256f59e1d9cd07741a2f8e9d27e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 18 Sep 2005 10:37:57 +0000 Subject: - 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. --- modules/node/node.module | 53 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'modules/node/node.module') diff --git a/modules/node/node.module b/modules/node/node.module index 331267551..3a17febf5 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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 .= '

'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'

'; + } + 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 = "\n"; $output .= "]>\n"; - $output .= "\n"; + $output .= "\n"; $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']); $output .= "\n"; -- cgit v1.2.3