Projet

Général

Profil

Paste
Télécharger (7,33 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_display_feed.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_display_feed.
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

    
17
  /**
18
   * {@inheritdoc}
19
   */
20
  public function init(&$view, &$display, $options = NULL) {
21
    parent::init($view, $display, $options);
22

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

    
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function uses_breadcrumb() {
37
    return FALSE;
38
  }
39

    
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public function get_style_type() {
44
    return 'feed';
45
  }
46

    
47
  /**
48
   * Feeds do not go through the normal page theming mechanism. Instead, they
49
   * go through their own little theme function and then return NULL so that
50
   * Drupal believes that the page has already rendered itself...which it has.
51
   */
52
  public function execute() {
53
    $output = $this->view->render();
54
    if (empty($output)) {
55
      return MENU_NOT_FOUND;
56
    }
57
    print $output;
58
  }
59

    
60
  /**
61
   * {@inheritdoc}
62
   */
63
  public function preview() {
64
    if (!empty($this->view->live_preview)) {
65
      return '<pre>' . check_plain($this->view->render()) . '</pre>';
66
    }
67
    return $this->view->render();
68
  }
69

    
70
  /**
71
   * Instead of going through the standard views_view.tpl.php, delegate this
72
   * to the style handler.
73
   */
74
  public function render() {
75
    return $this->view->style_plugin->render($this->view->result);
76
  }
77

    
78
  /**
79
   * {@inheritdoc}
80
   */
81
  public function defaultable_sections($section = NULL) {
82
    if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) {
83
      return FALSE;
84
    }
85

    
86
    $sections = parent::defaultable_sections($section);
87

    
88
    // Tell views our sitename_title option belongs in the title section.
89
    if ($section == 'title') {
90
      $sections[] = 'sitename_title';
91
    }
92
    elseif (!$section) {
93
      $sections['title'][] = 'sitename_title';
94
    }
95
    return $sections;
96
  }
97

    
98
  /**
99
   * {@inheritdoc}
100
   */
101
  public function option_definition() {
102
    $options = parent::option_definition();
103

    
104
    $options['displays'] = array('default' => array());
105

    
106
    // Overrides for standard stuff.
107
    $options['style_plugin']['default'] = 'rss';
108
    $options['style_options']['default']  = array('description' => '');
109
    $options['sitename_title']['default'] = FALSE;
110
    $options['row_plugin']['default'] = '';
111
    $options['defaults']['default']['style_plugin'] = FALSE;
112
    $options['defaults']['default']['style_options'] = FALSE;
113
    $options['defaults']['default']['row_plugin'] = FALSE;
114
    $options['defaults']['default']['row_options'] = FALSE;
115

    
116
    return $options;
117
  }
118

    
119
  /**
120
   * {@inheritdoc}
121
   */
122
  public function options_summary(&$categories, &$options) {
123
    // It is very important to call the parent function here.
124
    parent::options_summary($categories, $options);
125

    
126
    // Since we're childing off the 'page' type, we'll still *call* our
127
    // category 'page' but let's override it so it says feed settings.
128
    $categories['page'] = array(
129
      'title' => t('Feed settings'),
130
      'column' => 'second',
131
      'build' => array(
132
        '#weight' => -10,
133
      ),
134
    );
135

    
136
    if ($this->get_option('sitename_title')) {
137
      $options['title']['value'] = t('Using the site name');
138
    }
139

    
140
    // I don't think we want to give feeds menus directly.
141
    unset($options['menu']);
142

    
143
    $displays = array_filter($this->get_option('displays'));
144
    if (count($displays) > 1) {
145
      $attach_to = t('Multiple displays');
146
    }
147
    elseif (count($displays) == 1) {
148
      $display = array_shift($displays);
149
      if (!empty($this->view->display[$display])) {
150
        $attach_to = check_plain($this->view->display[$display]->display_title);
151
      }
152
    }
153

    
154
    if (!isset($attach_to)) {
155
      $attach_to = t('None');
156
    }
157

    
158
    $options['displays'] = array(
159
      'category' => 'page',
160
      'title' => t('Attach to'),
161
      'value' => $attach_to,
162
    );
163
  }
164

    
165
  /**
166
   * Provide the default form for setting options.
167
   */
168
  public function options_form(&$form, &$form_state) {
169
    // It is very important to call the parent function here.
170
    parent::options_form($form, $form_state);
171

    
172
    switch ($form_state['section']) {
173
      case 'title':
174
        $title = $form['title'];
175
        // A little juggling to move the 'title' field beyond our checkbox.
176
        unset($form['title']);
177
        $form['sitename_title'] = array(
178
          '#type' => 'checkbox',
179
          '#title' => t('Use the site name for the title'),
180
          '#default_value' => $this->get_option('sitename_title'),
181
        );
182
        $form['title'] = $title;
183
        $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE));
184
        break;
185

    
186
      case 'displays':
187
        $form['#title'] .= t('Attach to');
188
        $displays = array();
189
        foreach ($this->view->display as $display_id => $display) {
190
          if (!empty($display->handler) && $display->handler->accept_attachments()) {
191
            $displays[$display_id] = $display->display_title;
192
          }
193
        }
194
        $form['displays'] = array(
195
          '#type' => 'checkboxes',
196
          '#description' => t('The feed icon will be available only to the selected displays.'),
197
          '#options' => $displays,
198
          '#default_value' => $this->get_option('displays'),
199
        );
200
        break;
201

    
202
      case 'path':
203
        $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.');
204
        break;
205
    }
206
  }
207

    
208
  /**
209
   * Perform any necessary changes to the form values prior to storage.
210
   * There is no need for this function to actually store the data.
211
   */
212
  public function options_submit(&$form, &$form_state) {
213
    // It is very important to call the parent function here.
214
    parent::options_submit($form, $form_state);
215
    switch ($form_state['section']) {
216
      case 'title':
217
        $this->set_option('sitename_title', $form_state['values']['sitename_title']);
218
        break;
219

    
220
      case 'displays':
221
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
222
        break;
223
    }
224
  }
225

    
226
  /**
227
   * Attach to another view.
228
   */
229
  public function attach_to($display_id) {
230
    $displays = $this->get_option('displays');
231
    if (empty($displays[$display_id])) {
232
      return;
233
    }
234

    
235
    // Defer to the feed style; it may put in meta information, and/or
236
    // attach a feed icon.
237
    $plugin = $this->get_plugin();
238
    if ($plugin) {
239
      $clone = $this->view->clone_view();
240
      $clone->set_display($this->display->id);
241
      $clone->build_title();
242
      $plugin->attach_to($display_id, $this->get_path(), $clone->get_title());
243

    
244
      // Clean up
245
      $clone->destroy();
246
      unset($clone);
247
    }
248
  }
249

    
250
  /**
251
   * {@inheritdoc}
252
   */
253
  public function uses_link_display() {
254
    return TRUE;
255
  }
256

    
257
}