View source
<?php
function template_preprocess_views_view_views_rss_fields(&$vars) {
$view = $vars['view'];
if ($view->display_handler
->get_option('sitename_title')) {
$title = variable_get('site_name', 'Drupal');
if ($slogan = variable_get('site_slogan', '')) {
$title .= ' - ' . $slogan;
}
}
else {
$title = $view
->get_title();
}
$vars['viewtitle'] = check_plain($title);
if ($view->style_options['feed_settings']['feed_description']) {
$description = $view->style_options['feed_settings']['feed_description'];
}
else {
$description = variable_get('site_mission', '');
}
$vars['description'] = theme('views_rss_feed_description', $description, $view);
global $base_url;
$vars['link'] = $base_url;
$elements = $namespaces = array();
$rows = '';
$items = $view->style_plugin
->map_rows($vars['rows']);
foreach ($items as $item) {
$rows .= theme('views_rss_fields_item', $item);
foreach ($item as $k => $v) {
$elements[$k] = $k;
}
}
$vars['rows'] = $rows;
foreach ($elements as $e) {
if ($namespace = $view->style_plugin
->xml_namespace($e)) {
$namespaces[] = "xmlns:{$namespace['local']}=\"{$namespace['namespace']}\"";
}
}
$vars['namespaces'] = implode(' ', array_unique($namespaces));
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
}
function template_preprocess_views_rss_fields_item(&$vars) {
$row = '';
foreach ($vars['item'] as $key => $values) {
if ($values) {
switch ($key) {
case 'enclosure':
case 'source':
$row .= $vars['item'][$key] . "\n";
break;
default:
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
$row .= "<{$key}>" . $value . "</{$key}>\n";
}
}
}
}
$vars['row'] = $row;
}
function theme_views_rss_feed_icon($url, $title, $icon) {
if ($image = theme('image', $icon, t('Download RSS Feed'), $title)) {
return '<a href="' . check_url($url) . '" class="feed-icon">' . $image . '</a>';
}
}
function theme_views_rss_feed_description($description, $view) {
return $description;
}
function theme_views_rss_feed_item_source($view) {
global $base_url;
return strtr('<source url="!feed_url">!feed_title</source>', array(
'!feed_url' => $base_url . '/' . $view
->get_url(),
'!feed_title' => $view
->get_title(),
));
}
function theme_views_rss_formatter_enclosure_file($element) {
if (empty($element['#item']['fid'])) {
return;
}
return strtr('<enclosure url="!url" length="!length" type="!type" />', array(
'!url' => url($element['#item']['filepath'], array(
'absolute' => TRUE,
)),
'!length' => $element['#item']['filesize'],
'!type' => $element['#item']['filemime'],
));
}
function theme_views_rss_formatter_enclosure_image($element) {
if (empty($element['#item']['fid'])) {
return;
}
$presets = array();
foreach (imagecache_presets() as $preset) {
$presets[] = $preset['presetname'];
}
$preset_name = str_replace('views_rss_enclosure_image', '', $element['#formatter']);
if ($preset_name && in_array($preset_name, array_keys($presets))) {
$path = imagecache_create_url($preset_name, $element['#item']['filepath']);
}
else {
$path = $element['#item']['filepath'];
}
return strtr('<enclosure url="!url" length="!length" type="!type" />', array(
'!url' => url($path, array(
'absolute' => TRUE,
)),
'!length' => $element['#item']['filesize'],
'!type' => $element['#item']['filemime'],
));
}