1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Contains the RSS style plugin. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Default style plugin to render an RSS feed. |
---|
9 | * |
---|
10 | * @ingroup views_style_plugins |
---|
11 | */ |
---|
12 | class views_plugin_style_rss extends views_plugin_style { |
---|
13 | function attach_to($display_id, $path, $title) { |
---|
14 | $display = $this->view->display[$display_id]->handler; |
---|
15 | $url_options = array(); |
---|
16 | $input = $this->view->get_exposed_input(); |
---|
17 | if ($input) { |
---|
18 | $url_options['query'] = $input; |
---|
19 | } |
---|
20 | |
---|
21 | $url = url($this->view->get_url(NULL, $path), $url_options); |
---|
22 | if ($display->has_path()) { |
---|
23 | if (empty($this->preview)) { |
---|
24 | drupal_add_feed($url, $title); |
---|
25 | } |
---|
26 | } |
---|
27 | else { |
---|
28 | if (empty($this->view->feed_icon)) { |
---|
29 | $this->view->feed_icon = ''; |
---|
30 | } |
---|
31 | |
---|
32 | $this->view->feed_icon .= theme('feed_icon', $url, $title); |
---|
33 | drupal_add_link(array( |
---|
34 | 'rel' => 'alternate', |
---|
35 | 'type' => 'application/rss+xml', |
---|
36 | 'title' => $title, |
---|
37 | 'href' => $url |
---|
38 | )); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | function option_definition() { |
---|
43 | $options = parent::option_definition(); |
---|
44 | |
---|
45 | $options['description'] = array('default' => '', 'translatable' => TRUE); |
---|
46 | $options['mission_description'] = array('default' => '', 'translatable' => TRUE); |
---|
47 | |
---|
48 | return $options; |
---|
49 | } |
---|
50 | |
---|
51 | function options_form(&$form, &$form_state) { |
---|
52 | parent::options_form($form, $form_state); |
---|
53 | |
---|
54 | $form['mission_description'] = array( |
---|
55 | '#type' => 'checkbox', |
---|
56 | '#default_value' => !empty($this->options['mission_description']), |
---|
57 | '#title' => t('Use the site mission for the description'), |
---|
58 | ); |
---|
59 | $form['description'] = array( |
---|
60 | '#type' => 'textfield', |
---|
61 | '#title' => t('RSS description'), |
---|
62 | '#default_value' => $this->options['description'], |
---|
63 | '#description' => t('This will appear in the RSS feed itself.'), |
---|
64 | '#process' => array('views_process_dependency'), |
---|
65 | '#dependency' => array('edit-style-options-override' => array(FALSE)), |
---|
66 | '#maxlength' => 1024, |
---|
67 | ); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Return an array of additional XHTML elements to add to the channel. |
---|
72 | * |
---|
73 | * @return |
---|
74 | * An array that can be passed to format_xml_elements(). |
---|
75 | */ |
---|
76 | function get_channel_elements() { |
---|
77 | return array(); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Get RSS feed description. |
---|
82 | * |
---|
83 | * @return string |
---|
84 | * The string containing the description with the tokens replaced. |
---|
85 | */ |
---|
86 | function get_description() { |
---|
87 | $description = $this->options['description']; |
---|
88 | |
---|
89 | // Allow substitutions from the first row. |
---|
90 | $description = $this->tokenize_value($description, 0); |
---|
91 | |
---|
92 | return $description; |
---|
93 | } |
---|
94 | |
---|
95 | function render() { |
---|
96 | if (empty($this->row_plugin)) { |
---|
97 | vpr('views_plugin_style_default: Missing row plugin'); |
---|
98 | return; |
---|
99 | } |
---|
100 | $rows = ''; |
---|
101 | |
---|
102 | // This will be filled in by the row plugin and is used later on in the |
---|
103 | // theming output. |
---|
104 | $this->namespaces = array(); |
---|
105 | |
---|
106 | // Fetch any additional elements for the channel and merge in their |
---|
107 | // namespaces. |
---|
108 | $this->channel_elements = $this->get_channel_elements(); |
---|
109 | foreach ($this->channel_elements as $element) { |
---|
110 | if (isset($element['namespace'])) { |
---|
111 | $this->namespaces = array_merge($this->namespaces, $element['namespace']); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | foreach ($this->view->result as $row_index => $row) { |
---|
116 | $this->view->row_index = $row_index; |
---|
117 | $rows .= $this->row_plugin->render($row); |
---|
118 | } |
---|
119 | |
---|
120 | $output = theme($this->theme_functions(), $this->view, $this->options, $rows); |
---|
121 | unset($this->view->row_index); |
---|
122 | |
---|
123 | return $output; |
---|
124 | } |
---|
125 | } |
---|