View source
<?php
function views_rss_views_style_plugins() {
return array(
'views_rss' => array(
'name' => t('Views RSS: RSS feed'),
'theme' => 'views_rss_feed',
'needs_table_header' => TRUE,
'needs_fields' => TRUE,
'even_empty' => TRUE,
),
);
}
function views_rss_views_arguments() {
$arguments = array(
'rss_feed' => array(
'name' => t('RSS: RSS Feed Selector'),
'handler' => 'views_handler_arg_rss_feed',
'option' => 'string',
'help' => t('This argument specifies a specific RSS feed selector; it will only select RSS feeds, unlike the built-in selector which can select pluggable feeds. You may enter the title the feed will advertise in the title field here, and the description of the feed in the option field here.'),
),
);
return $arguments;
}
function views_handler_arg_rss_feed($op, &$query, $argtype, $arg = '') {
switch ($op) {
case 'summary':
case 'sort':
case 'link':
case 'title':
break;
case 'filter':
views_rss_views_feed_argument('argument', $GLOBALS['current_view'], $arg, $argtype);
}
}
function views_rss_views_post_view($view, $items, $output) {
foreach ($view->argument as $id => $argument) {
if ($argument['type'] == 'rss_feed') {
$feed = $id;
break;
}
}
if ($feed !== NULL) {
return views_rss_views_feed_argument('post_view', $view, 'rss_feed');
}
}
function views_rss_views_feed_argument($op, &$view, $arg, $argdata = NULL) {
if ($op == 'argument' && $arg == 'feed') {
$view->page_type = 'views_rss';
if ($argdata['options']) {
$view->description = $argdata['options'];
}
$view_args = array();
$max = count($view->args);
foreach ($view->args as $id => $view_arg) {
++$count;
if ($view_arg == $arg && $view->argument[$id]['id'] == $argdata['id']) {
if ($count != $max) {
$view_args[] = $argdata['wildcard'];
}
}
else {
$view_args[] = $view_arg;
}
}
$view->feed_url = views_get_url($view, $view_args);
}
else {
if ($op == 'post_view' && $view->build_type != 'block') {
$args = views_post_view_make_args($view, $arg, 'feed');
$url = views_get_url($view, $args);
$title = views_get_title($view, 'page', $args);
if ($view->used_filters) {
$filters = drupal_query_string_encode($view->used_filters);
}
drupal_add_feed(url($url, $filters), $title);
}
}
}
function theme_views_rss_feed($view, $nodes, $type) {
if ($type == 'block') {
return;
}
global $base_url;
$channel = array(
'title' => views_get_title($view, 'page'),
'link' => url($view->feed_url ? $view->feed_url : $view->real_url, NULL, NULL, true),
'description' => $view->description,
);
$item_length = variable_get('feed_item_length', 'teaser');
$namespaces = array(
'xmlns:dc="http://purl.org/dc/elements/1.1/"',
);
foreach ($nodes as $node) {
$item = node_load($node->nid);
$link = url("node/{$node->nid}", NULL, NULL, 1);
if ($item_length != 'title') {
$teaser = $item_length == 'teaser' ? TRUE : FALSE;
if (node_hook($item, 'view')) {
node_invoke($item, 'view', $teaser, FALSE);
}
else {
$item = node_prepare($item, $teaser);
}
node_invoke_nodeapi($item, 'view', $teaser, FALSE);
}
$extra = node_invoke_nodeapi($item, 'rss item');
$extra = array_merge($extra, array(
array(
'key' => 'pubDate',
'value' => date('r', $item->created),
),
array(
'key' => 'dc:creator',
'value' => $item->name,
),
array(
'key' => 'guid',
'value' => $item->nid . ' at ' . $base_url,
'attributes' => array(
'isPermaLink' => 'false',
),
),
));
foreach ($extra as $element) {
if ($element['namespace']) {
$namespaces = array_merge($namespaces, $element['namespace']);
}
}
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;
}
$items .= format_rss_item($item->title, $link, $item_text, $extra);
}
$channel_defaults = array(
'version' => '2.0',
'title' => variable_get('site_name', 'drupal') . ' - ' . variable_get('site_slogan', ''),
'link' => $base_url,
'description' => variable_get('site_mission', ''),
'language' => $GLOBALS['locale'],
);
$channel = array_merge($channel_defaults, $channel);
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\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";
drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $output;
module_invoke_all('exit');
exit;
}