Projet

Général

Profil

Paste
Télécharger (6,96 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_display_feed.inc @ 6eb8d15f

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the feed display plugin.
6
 */
7

    
8
/**
9
 * The plugin that handles a feed, such as RSS or atom.
10
 *
11
 * For the most part, feeds are page displays but with some subtle differences.
12
 *
13
 * @ingroup views_display_plugins
14
 */
15
class views_plugin_display_feed extends views_plugin_display_page {
16
  function init(&$view, &$display, $options = NULL) {
17
    parent::init($view, $display, $options);
18

    
19
    // Set the default row style. Ideally this would be part of the option
20
    // definition, but in this case it's dependent on the view's base table,
21
    // which we don't know until init().
22
    $row_plugins = views_fetch_plugin_names('row', $this->get_style_type(), array($view->base_table));
23
    $default_row_plugin = key($row_plugins);
24
    if ($this->options['row_plugin'] == '') {
25
      $this->options['row_plugin'] = $default_row_plugin;
26
    }
27
  }
28

    
29
  function uses_breadcrumb() { return FALSE; }
30
  function get_style_type() { return 'feed'; }
31

    
32
  /**
33
   * Feeds do not go through the normal page theming mechanism. Instead, they
34
   * go through their own little theme function and then return NULL so that
35
   * Drupal believes that the page has already rendered itself...which it has.
36
   */
37
  function execute() {
38
    $output = $this->view->render();
39
    if (empty($output)) {
40
      return MENU_NOT_FOUND;
41
    }
42
    print $output;
43
  }
44

    
45
  function preview() {
46
    if (!empty($this->view->live_preview)) {
47
      return '<pre>' . check_plain($this->view->render()) . '</pre>';
48
    }
49
    return $this->view->render();
50
  }
51

    
52
  /**
53
   * Instead of going through the standard views_view.tpl.php, delegate this
54
   * to the style handler.
55
   */
56
  function render() {
57
    return $this->view->style_plugin->render($this->view->result);
58
  }
59

    
60
  function defaultable_sections($section = NULL) {
61
    if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) {
62
      return FALSE;
63
    }
64

    
65
    $sections = parent::defaultable_sections($section);
66

    
67
    // Tell views our sitename_title option belongs in the title section.
68
    if ($section == 'title') {
69
      $sections[] = 'sitename_title';
70
    }
71
    elseif (!$section) {
72
      $sections['title'][] = 'sitename_title';
73
    }
74
    return $sections;
75
  }
76

    
77
  function option_definition() {
78
    $options = parent::option_definition();
79

    
80
    $options['displays'] = array('default' => array());
81

    
82
    // Overrides for standard stuff:
83
    $options['style_plugin']['default'] = 'rss';
84
    $options['style_options']['default']  = array('description' => '');
85
    $options['sitename_title']['default'] = FALSE;
86
    $options['row_plugin']['default'] = '';
87
    $options['defaults']['default']['style_plugin'] = FALSE;
88
    $options['defaults']['default']['style_options'] = FALSE;
89
    $options['defaults']['default']['row_plugin'] = FALSE;
90
    $options['defaults']['default']['row_options'] = FALSE;
91

    
92
    return $options;
93
  }
94

    
95
  function options_summary(&$categories, &$options) {
96
    // It is very important to call the parent function here:
97
    parent::options_summary($categories, $options);
98

    
99
    // Since we're childing off the 'page' type, we'll still *call* our
100
    // category 'page' but let's override it so it says feed settings.
101
    $categories['page'] = array(
102
      'title' => t('Feed settings'),
103
      'column' => 'second',
104
      'build' => array(
105
        '#weight' => -10,
106
      ),
107
    );
108

    
109
    if ($this->get_option('sitename_title')) {
110
      $options['title']['value'] = t('Using the site name');
111
    }
112

    
113
    // I don't think we want to give feeds menus directly.
114
    unset($options['menu']);
115

    
116
    $displays = array_filter($this->get_option('displays'));
117
    if (count($displays) > 1) {
118
      $attach_to = t('Multiple displays');
119
    }
120
    elseif (count($displays) == 1) {
121
      $display = array_shift($displays);
122
      if (!empty($this->view->display[$display])) {
123
        $attach_to = check_plain($this->view->display[$display]->display_title);
124
      }
125
    }
126

    
127
    if (!isset($attach_to)) {
128
      $attach_to = t('None');
129
    }
130

    
131
    $options['displays'] = array(
132
      'category' => 'page',
133
      'title' => t('Attach to'),
134
      'value' => $attach_to,
135
    );
136
  }
137

    
138
  /**
139
   * Provide the default form for setting options.
140
   */
141
  function options_form(&$form, &$form_state) {
142
    // It is very important to call the parent function here.
143
    parent::options_form($form, $form_state);
144

    
145
    switch ($form_state['section']) {
146
      case 'title':
147
        $title = $form['title'];
148
        // A little juggling to move the 'title' field beyond our checkbox.
149
        unset($form['title']);
150
        $form['sitename_title'] = array(
151
          '#type' => 'checkbox',
152
          '#title' => t('Use the site name for the title'),
153
          '#default_value' => $this->get_option('sitename_title'),
154
        );
155
        $form['title'] = $title;
156
        $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE));
157
        break;
158
      case 'displays':
159
        $form['#title'] .= t('Attach to');
160
        $displays = array();
161
        foreach ($this->view->display as $display_id => $display) {
162
          if (!empty($display->handler) && $display->handler->accept_attachments()) {
163
            $displays[$display_id] = $display->display_title;
164
          }
165
        }
166
        $form['displays'] = array(
167
          '#type' => 'checkboxes',
168
          '#description' => t('The feed icon will be available only to the selected displays.'),
169
          '#options' => $displays,
170
          '#default_value' => $this->get_option('displays'),
171
        );
172
        break;
173
      case 'path':
174
        $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 contextual filter you have defined in the view.');
175
    }
176
  }
177

    
178
  /**
179
   * Perform any necessary changes to the form values prior to storage.
180
   * There is no need for this function to actually store the data.
181
   */
182
  function options_submit(&$form, &$form_state) {
183
    // It is very important to call the parent function here:
184
    parent::options_submit($form, $form_state);
185
    switch ($form_state['section']) {
186
      case 'title':
187
        $this->set_option('sitename_title', $form_state['values']['sitename_title']);
188
        break;
189
      case 'displays':
190
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
191
        break;
192
    }
193
  }
194

    
195
  /**
196
   * Attach to another view.
197
   */
198
  function attach_to($display_id) {
199
    $displays = $this->get_option('displays');
200
    if (empty($displays[$display_id])) {
201
      return;
202
    }
203

    
204
    // Defer to the feed style; it may put in meta information, and/or
205
    // attach a feed icon.
206
    $plugin = $this->get_plugin();
207
    if ($plugin) {
208
      $clone = $this->view->clone_view();
209
      $clone->set_display($this->display->id);
210
      $clone->build_title();
211
      $plugin->attach_to($display_id, $this->get_path(), $clone->get_title());
212

    
213
      // Clean up
214
      $clone->destroy();
215
      unset($clone);
216
    }
217
  }
218

    
219
  function uses_link_display() {
220
    return TRUE;
221
  }
222
}