views_plugin_display_feed.inc

  1. 3.x plugins/views_plugin_display_feed.inc
  2. 2.x plugins/views_plugin_display_feed.inc

Contains the feed display plugin.

File

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