Projet

Général

Profil

Paste
Télécharger (3,17 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / views / plugins / views_plugin_style_rss.inc @ 4543c6c7

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
   * Get RSS feed description.
76
   *
77
   * @return string
78
   *   The string containing the description with the tokens replaced.
79
   */
80
  function get_description() {
81
    $description = $this->options['description'];
82

    
83
    // Allow substitutions from the first row.
84
    $description = $this->tokenize_value($description, 0);
85

    
86
    return $description;
87
  }
88

    
89
  function render() {
90
    if (empty($this->row_plugin)) {
91
      vpr('views_plugin_style_default: Missing row plugin');
92
      return;
93
    }
94
    $rows = '';
95

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

    
100
    // Fetch any additional elements for the channel and merge in their
101
    // namespaces.
102
    $this->channel_elements = $this->get_channel_elements();
103
    foreach ($this->channel_elements as $element) {
104
      if (isset($element['namespace'])) {
105
        $this->namespaces = array_merge($this->namespaces, $element['namespace']);
106
      }
107
    }
108

    
109
    foreach ($this->view->result as $row_index => $row) {
110
      $this->view->row_index = $row_index;
111
      $rows .= $this->row_plugin->render($row);
112
    }
113

    
114
    $output = theme($this->theme_functions(),
115
      array(
116
        'view' => $this->view,
117
        'options' => $this->options,
118
        'rows' => $rows
119
      ));
120
    unset($this->view->row_index);
121
    return $output;
122
  }
123
}