Fix description.
[project/views_rss.git] / views / views_rss_views_fields.theme.inc
1 <?php
2 // $Id$
3
4 /**
5 * Template preprocessor for views-view-views-rss-fields.tpl.php.
6 */
7 function template_preprocess_views_view_views_rss_fields(&$vars) {
8 $view = $vars['view'];
9
10 // Set basic info - title, description - about the feed
11 $vars['viewtitle'] = variable_get('site_name', array()) . ' | ' . $view->display[$view->current_display]->display_title;
12
13 if ($view->style_options['description']['feed_description']) {
14 $description = $view->style_options['description']['feed_description'];
15 }
16 else {
17 $description = variable_get('site_mission', '');
18 }
19 $vars['description'] = theme('views_rss_feed_description', $description, $view);
20
21 // Base URL for link tag
22 global $base_url;
23 $vars['link'] = $base_url;
24
25 // Grab the rows, push to field mapping function, gather namespaces.
26 $elements = $namespaces = array();
27 $rows = '';
28 $items = $view->style_plugin->map_rows($vars['rows']);
29 foreach($items as $item) {
30 // Special handling for GeoRSS.
31 if (isset($item['lat']) && isset($item['lon'])) {
32 $item['georss:point'] = $item['lat'] .' '. $item['lon'];
33 }
34 unset($item['lat']);
35 unset($item['lon']);
36 $rows .= theme('views_rss_fields_item', $item);
37 foreach ($item as $k => $v) {
38 $elements[$k] = $k;
39 }
40 }
41 $vars['rows'] = $rows;
42 foreach ($elements as $e) {
43 if ($namespace = $view->style_plugin->xml_namespace($e)) {
44 $namespaces[] = "xmlns:{$namespace['local']}=\"{$namespace['namespace']}\"";
45 }
46 }
47 $vars['namespaces'] = implode(' ', $namespaces);
48
49 // Set Headers
50 drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
51 }
52
53 /**
54 * Template preprocessor for views-rss-fields-item.tpl.php.
55 */
56 function template_preprocess_views_rss_fields_item(&$vars) {
57 $item = $vars['item'];
58
59 // GeoRSS
60 if (isset($item['lat']) && isset($item['lon'])) {
61 $item['georss:point'] = check_plain($item['lat'] . ' ' . $item['lon']);
62 unset($item['lat']);
63 unset($item['lon']);
64 }
65
66 // Loop through key=>value pairs
67 $row = '';
68 foreach ($item as $key => $value) {
69 if ($value) {
70 $row .= "<$key>". check_plain($value) ."</$key>\n";
71 }
72 }
73
74 $vars['row'] = $row;
75 }
76
77 /**
78 * Theme function for feed icon.
79 */
80 function theme_views_rss_feed_icon($url, $title, $icon) {
81 if ($image = theme('image', $icon, t('Download RSS Feed'), $title)) {
82 return '<a href="'. check_url($url) .'" class="feed-icon">'. $image .'</a>';
83 }
84 }
85
86 /**
87 * Theme function for feed description.
88 */
89 function theme_views_rss_feed_description($description, $view) {
90 return $description;
91 }