views_rss_views_fields.theme.inc in Views RSS 7
File
views/views_rss_views_fields.theme.inc
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['description']['feed_description']) {
$description = $view->style_options['description']['feed_description'];
}
else {
$description = variable_get('site_mission', '');
}
$vars['description'] = theme('views_rss_feed_description', array(
'0' => $description,
'1' => $view,
));
global $base_url;
$vars['link'] = $base_url;
$elements = $namespaces = array();
$rows = '';
$items = $view->style_plugin
->map_rows($vars['rows']);
foreach ($items as $item) {
if (isset($item['lat']) && is_numeric($item['lat']) && isset($item['lon']) && is_numeric($item['lon'])) {
$item['georss:point'] = $item['lat'] . ' ' . $item['lon'];
}
if (isset($item['featureName'])) {
$item['georss:featureName'] = $item['featureName'];
}
unset($item['lat']);
unset($item['lon']);
unset($item['featureName']);
$rows .= theme('views_rss_fields_item', array(
'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));
if (empty($vars['view']->live_preview)) {
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
}
}
function theme_views_rss_fields_item($variables) {
$item = $variables['item'];
$row = '';
foreach ($item as $key => $value) {
if ($value) {
$row .= theme('views_rss_fields_element', array(
'key' => $key,
'element' => $value,
));
}
}
return '<item>' . $row . '</item>';
}
function theme_views_rss_fields_element($variables) {
$key = $variables['key'];
$value = $variables['element'];
if ($key == 'enclosure') {
if (isset($value['#raw'][0])) {
$file = (array) $value['#raw'][0]['raw'];
if (isset($value['#raw'][0]['rendered']['file']['#entity_type']) && $value['#raw'][0]['rendered']['file']['#entity_type'] == 'media') {
$style = str_replace("styles_file_", "", $value['#raw'][0]['rendered']['file']['#formatter']);
$url = image_style_url($style, $file['uri']);
}
else {
if (isset($value['#raw'][0]['rendered']['#image_style'])) {
$url = image_style_url($value['#raw'][0]['rendered']['#image_style'], $file['uri']);
}
else {
$url = file_create_url($file['uri']);
}
}
return '<enclosure url="' . $url . '" length="' . $file['filesize'] . '" type="' . $file['filemime'] . '" />';
}
}
else {
return "<{$key}>" . check_plain(htmlspecialchars_decode($value['#markup'])) . "</{$key}>";
}
}
function theme_views_rss_feed_icon($variables) {
$url = $variables['0'];
$title = $variables['1'];
$icon = $variables['2'];
if ($image = theme('image', array(
'path' => $icon,
'width' => t('Download RSS Feed'),
'height' => $title,
))) {
return '<a href="' . check_url($url) . '" class="feed-icon">' . $image . '</a>';
}
}
function theme_views_rss_feed_description($variables) {
$description = $variables['0'];
$view = $variables['1'];
return $description;
}