Projet

Général

Profil

Paste
Télécharger (4,05 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_style_rss.inc @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the RSS style plugin.
6
 */
7

    
8
/**
9
 * Default style plugin to render an RSS feed.
10
 *
11
 * @ingroup views_style_plugins
12
 */
13
class views_plugin_style_rss extends views_plugin_style {
14
  function attach_to($display_id, $path, $title) {
15
    $display = $this->view->display[$display_id]->handler;
16
    $url_options = array();
17
    $input = $this->view->get_exposed_input();
18
    if ($input) {
19
      $url_options['query'] = $input;
20
    }
21
    $url_options['absolute'] = TRUE;
22

    
23
    $url = url($this->view->get_url(NULL, $path), $url_options);
24
    if ($display->has_path()) {
25
      if (empty($this->preview)) {
26
        drupal_add_feed($url, $title);
27
      }
28
    }
29
    else {
30
      if (empty($this->view->feed_icon)) {
31
        $this->view->feed_icon = '';
32
      }
33

    
34
      $this->view->feed_icon .= theme('feed_icon', array('url' => $url, 'title' => $title));
35
      drupal_add_html_head_link(array(
36
        'rel' => 'alternate',
37
        'type' => 'application/rss+xml',
38
        'title' => $title,
39
        'href' => $url
40
      ));
41
    }
42
  }
43

    
44
  function option_definition() {
45
    $options = parent::option_definition();
46

    
47
    $options['description'] = array('default' => '', 'translatable' => TRUE);
48

    
49
    return $options;
50
  }
51

    
52
  function options_form(&$form, &$form_state) {
53
    parent::options_form($form, $form_state);
54

    
55
    $form['description'] = array(
56
      '#type' => 'textfield',
57
      '#title' => t('RSS description'),
58
      '#default_value' => $this->options['description'],
59
      '#description' => t('This will appear in the RSS feed itself.'),
60
      '#maxlength' => 1024,
61
    );
62
  }
63

    
64
  /**
65
   * Return an array of additional XHTML elements to add to the channel.
66
   *
67
   * @return
68
   *   An array that can be passed to format_xml_elements().
69
   */
70
  function get_channel_elements() {
71
    return array();
72
  }
73

    
74
  /**
75
   * Return an atom:link XHTML element to add to the channel to comply with
76
   * the RSS 2.0 specification.
77
   *
78
   * @see http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html
79
   *
80
   * @return
81
   *   An array that can be passed to format_xml_elements().
82
   */
83
  function get_channel_elements_atom_link() {
84
    $url_options = array('absolute' => TRUE);
85
    $input = $this->view->get_exposed_input();
86
    if ($input) {
87
      $url_options['query'] = $input;
88
    }
89
    $url = url($this->view->get_url(), $url_options);
90

    
91
    return array(
92
      array(
93
        'namespace' => array('xmlns:atom' => 'http://www.w3.org/2005/Atom'),
94
        'key' => 'atom:link',
95
        'attributes' => array(
96
          'href' => $url,
97
          'rel' => 'self',
98
          'type' => 'application/rss+xml',
99
        ),
100
      ),
101
    );
102
  }
103

    
104
  /**
105
   * Get RSS feed description.
106
   *
107
   * @return string
108
   *   The string containing the description with the tokens replaced.
109
   */
110
  function get_description() {
111
    $description = $this->options['description'];
112

    
113
    // Allow substitutions from the first row.
114
    $description = $this->tokenize_value($description, 0);
115

    
116
    return $description;
117
  }
118

    
119
  function render() {
120
    if (empty($this->row_plugin)) {
121
      vpr('views_plugin_style_default: Missing row plugin');
122
      return;
123
    }
124
    $rows = '';
125

    
126
    // This will be filled in by the row plugin and is used later on in the
127
    // theming output.
128
    $this->namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/');
129

    
130
    // Fetch any additional elements for the channel and merge in their
131
    // namespaces.
132
    $this->channel_elements = array_merge(
133
      $this->get_channel_elements(),
134
      $this->get_channel_elements_atom_link()
135
    );
136
    foreach ($this->channel_elements as $element) {
137
      if (isset($element['namespace'])) {
138
        $this->namespaces = array_merge($this->namespaces, $element['namespace']);
139
      }
140
    }
141

    
142
    foreach ($this->view->result as $row_index => $row) {
143
      $this->view->row_index = $row_index;
144
      $rows .= $this->row_plugin->render($row);
145
    }
146

    
147
    $output = theme($this->theme_functions(),
148
      array(
149
        'view' => $this->view,
150
        'options' => $this->options,
151
        'rows' => $rows
152
      ));
153
    unset($this->view->row_index);
154
    return $output;
155
  }
156
}