1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Contains the feed display plugin. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * The plugin that handles a feed, such as RSS or atom. |
---|
9 | * |
---|
10 | * For the most part, feeds are page displays but with some subtle differences. |
---|
11 | * |
---|
12 | * @ingroup views_display_plugins |
---|
13 | */ |
---|
14 | class views_plugin_display_feed extends views_plugin_display_page { |
---|
15 | function uses_breadcrumb() { return FALSE; } |
---|
16 | function get_style_type() { return 'feed'; } |
---|
17 | |
---|
18 | /** |
---|
19 | * Feeds do not go through the normal page theming mechanism. Instead, they |
---|
20 | * go through their own little theme function and then return NULL so that |
---|
21 | * Drupal believes that the page has already rendered itself...which it has. |
---|
22 | */ |
---|
23 | function execute() { |
---|
24 | $output = $this->view->render(); |
---|
25 | if (empty($output)) { |
---|
26 | return drupal_not_found(); |
---|
27 | } |
---|
28 | print $output; |
---|
29 | } |
---|
30 | |
---|
31 | function preview() { |
---|
32 | if (!empty($this->view->live_preview)) { |
---|
33 | return '<pre>' . check_plain($this->view->render()) . '</pre>'; |
---|
34 | } |
---|
35 | return $this->view->render(); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * Instead of going through the standard views_view.tpl.php, delegate this |
---|
40 | * to the style handler. |
---|
41 | */ |
---|
42 | function render() { |
---|
43 | return $this->view->style_plugin->render($this->view->result); |
---|
44 | } |
---|
45 | |
---|
46 | function defaultable_sections($section = NULL) { |
---|
47 | if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) { |
---|
48 | return FALSE; |
---|
49 | } |
---|
50 | |
---|
51 | $sections = parent::defaultable_sections($section); |
---|
52 | |
---|
53 | // Tell views our sitename_title option belongs in the title section. |
---|
54 | if ($section == 'title') { |
---|
55 | $sections[] = 'sitename_title'; |
---|
56 | } |
---|
57 | elseif (!$section) { |
---|
58 | $sections['title'][] = 'sitename_title'; |
---|
59 | } |
---|
60 | return $sections; |
---|
61 | } |
---|
62 | |
---|
63 | function option_definition() { |
---|
64 | $options = parent::option_definition(); |
---|
65 | |
---|
66 | $options['displays'] = array('default' => array()); |
---|
67 | |
---|
68 | // Overrides for standard stuff: |
---|
69 | $options['style_plugin']['default'] = 'rss'; |
---|
70 | $options['style_options']['default'] = array('mission_description' => FALSE, 'description' => ''); |
---|
71 | $options['sitename_title']['default'] = FALSE; |
---|
72 | $options['row_plugin']['default'] = ''; |
---|
73 | $options['defaults']['default']['style_plugin'] = FALSE; |
---|
74 | $options['defaults']['default']['style_options'] = FALSE; |
---|
75 | $options['defaults']['default']['row_plugin'] = FALSE; |
---|
76 | $options['defaults']['default']['row_options'] = FALSE; |
---|
77 | |
---|
78 | return $options; |
---|
79 | } |
---|
80 | |
---|
81 | function options_summary(&$categories, &$options) { |
---|
82 | // It is very important to call the parent function here: |
---|
83 | parent::options_summary($categories, $options); |
---|
84 | |
---|
85 | // Since we're childing off the 'page' type, we'll still *call* our |
---|
86 | // category 'page' but let's override it so it says feed settings. |
---|
87 | $categories['page'] = array( |
---|
88 | 'title' => t('Feed settings'), |
---|
89 | ); |
---|
90 | |
---|
91 | if ($this->get_option('sitename_title')) { |
---|
92 | $options['title']['value'] = t('Using the site name'); |
---|
93 | } |
---|
94 | |
---|
95 | // I don't think we want to give feeds menus directly. |
---|
96 | unset($options['menu']); |
---|
97 | |
---|
98 | $displays = array_filter($this->get_option('displays')); |
---|
99 | if (count($displays) > 1) { |
---|
100 | $attach_to = t('Multiple displays'); |
---|
101 | } |
---|
102 | else if (count($displays) == 1) { |
---|
103 | $display = array_shift($displays); |
---|
104 | if (!empty($this->view->display[$display])) { |
---|
105 | $attach_to = check_plain($this->view->display[$display]->display_title); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | if (!isset($attach_to)) { |
---|
110 | $attach_to = t('None'); |
---|
111 | } |
---|
112 | |
---|
113 | $options['displays'] = array( |
---|
114 | 'category' => 'page', |
---|
115 | 'title' => t('Attach to'), |
---|
116 | 'value' => $attach_to, |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * Provide the default form for setting options. |
---|
122 | */ |
---|
123 | function options_form(&$form, &$form_state) { |
---|
124 | // It is very important to call the parent function here. |
---|
125 | parent::options_form($form, $form_state); |
---|
126 | |
---|
127 | switch ($form_state['section']) { |
---|
128 | case 'title': |
---|
129 | $title = $form['title']; |
---|
130 | // A little juggling to move the 'title' field beyond our checkbox. |
---|
131 | unset($form['title']); |
---|
132 | $form['sitename_title'] = array( |
---|
133 | '#type' => 'checkbox', |
---|
134 | '#title' => t('Use the site name for the title'), |
---|
135 | '#default_value' => $this->get_option('sitename_title'), |
---|
136 | ); |
---|
137 | $form['title'] = $title; |
---|
138 | $form['title']['#process'] = array('views_process_dependency'); |
---|
139 | $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE)); |
---|
140 | break; |
---|
141 | case 'displays': |
---|
142 | $form['#title'] .= t('Attach to'); |
---|
143 | $displays = array(); |
---|
144 | foreach ($this->view->display as $display_id => $display) { |
---|
145 | if (!empty($display->handler) && $display->handler->accept_attachments()) { |
---|
146 | $displays[$display_id] = $display->display_title; |
---|
147 | } |
---|
148 | } |
---|
149 | $form['displays'] = array( |
---|
150 | '#type' => 'checkboxes', |
---|
151 | '#description' => t('The feed icon will be available only to the selected displays.'), |
---|
152 | '#options' => $displays, |
---|
153 | '#default_value' => $this->get_option('displays'), |
---|
154 | ); |
---|
155 | break; |
---|
156 | case 'path': |
---|
157 | $form['path']['#description'] = t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each argument you have defined in the view.'); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * Perform any necessary changes to the form values prior to storage. |
---|
163 | * There is no need for this function to actually store the data. |
---|
164 | */ |
---|
165 | function options_submit($form, &$form_state) { |
---|
166 | // It is very important to call the parent function here: |
---|
167 | parent::options_submit($form, $form_state); |
---|
168 | switch ($form_state['section']) { |
---|
169 | case 'title': |
---|
170 | $this->set_option('sitename_title', $form_state['values']['sitename_title']); |
---|
171 | break; |
---|
172 | case 'displays': |
---|
173 | $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); |
---|
174 | break; |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Attach to another view. |
---|
180 | */ |
---|
181 | function attach_to($display_id) { |
---|
182 | $displays = $this->get_option('displays'); |
---|
183 | if (empty($displays[$display_id])) { |
---|
184 | return; |
---|
185 | } |
---|
186 | |
---|
187 | // Defer to the feed style; it may put in meta information, and/or |
---|
188 | // attach a feed icon. |
---|
189 | $plugin = $this->get_plugin(); |
---|
190 | if ($plugin) { |
---|
191 | $clone = $this->view->clone_view(); |
---|
192 | $clone->set_display($this->display->id); |
---|
193 | $clone->build_title(); |
---|
194 | $plugin->attach_to($display_id, $this->get_path(), $clone->get_title()); |
---|
195 | |
---|
196 | // Clean up |
---|
197 | $clone->destroy(); |
---|
198 | unset($clone); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | function uses_link_display() { |
---|
203 | return TRUE; |
---|
204 | } |
---|
205 | } |
---|