views_plugin_style_rss.inc

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

Contains the RSS style plugin.

File

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