~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/modules/node/views_plugin_row_node_rss.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: views_plugin_row_node_rss.inc,v 1.6 2009/04/07 22:02:40 merlinofchaos Exp $
 
3
/**
 
4
 * @file
 
5
 * Contains the node RSS row style plugin.
 
6
 */
 
7
 
 
8
/**
 
9
 * Plugin which performs a node_view on the resulting object
 
10
 * and formats it as an RSS item.
 
11
 */
 
12
class views_plugin_row_node_rss extends views_plugin_row {
 
13
  // Basic properties that let the row style follow relationships.
 
14
  var $base_table = 'node';
 
15
  var $base_field = 'nid';
 
16
 
 
17
  function option_definition() {
 
18
    $options = parent::option_definition();
 
19
 
 
20
    $options['item_length'] = array('default' => 'default');
 
21
 
 
22
    return $options;
 
23
  }
 
24
 
 
25
  function options_form(&$form, &$form_state) {
 
26
    parent::options_form($form, $form_state);
 
27
 
 
28
    $form['item_length'] = array(
 
29
      '#type' => 'select',
 
30
      '#title' => t('Display type'),
 
31
      '#options' => array(
 
32
        'fulltext' => t('Full text'),
 
33
        'teaser' => t('Title plus teaser'),
 
34
        'title' => t('Title only'),
 
35
        'default' => t('Use default RSS settings'),
 
36
      ),
 
37
      '#default_value' => $this->options['item_length'],
 
38
    );
 
39
  }
 
40
 
 
41
  function render($row) {
 
42
    // For the most part, this code is taken from node_feed() in node.module
 
43
    global $base_url;
 
44
 
 
45
    $nid = $row->{$this->field_alias};
 
46
    if (!is_numeric($nid)) {
 
47
      return;
 
48
    }
 
49
 
 
50
    $item_length = $this->options['item_length'];
 
51
    if ($item_length == 'default') {
 
52
      $item_length = variable_get('feed_item_length', 'teaser');
 
53
    }
 
54
 
 
55
    // Load the specified node:
 
56
    $node = node_load($nid);
 
57
    if (empty($node)) {
 
58
      return;
 
59
    }
 
60
 
 
61
    $node->build_mode = NODE_BUILD_RSS;
 
62
 
 
63
    if ($item_length != 'title') {
 
64
      $teaser = ($item_length == 'teaser') ? TRUE : FALSE;
 
65
 
 
66
      // Filter and prepare node teaser
 
67
      if (node_hook($node, 'view')) {
 
68
        $node = node_invoke($node, 'view', $teaser, FALSE);
 
69
      }
 
70
      else {
 
71
        $node = node_prepare($node, $teaser);
 
72
      }
 
73
 
 
74
      // Allow modules to change $node->teaser before viewing.
 
75
      node_invoke_nodeapi($node, 'view', $teaser, FALSE);
 
76
    }
 
77
 
 
78
    // Set the proper node part, then unset unused $node part so that a bad
 
79
    // theme can not open a security hole.
 
80
    $content = drupal_render($node->content);
 
81
    if ($teaser) {
 
82
      $node->teaser = $content;
 
83
      unset($node->body);
 
84
    }
 
85
    else {
 
86
      $node->body = $content;
 
87
      unset($node->teaser);
 
88
    }
 
89
 
 
90
    // Allow modules to modify the fully-built node.
 
91
    node_invoke_nodeapi($node, 'alter', $teaser, FALSE);
 
92
 
 
93
    $item = new stdClass();
 
94
    $item->title = $node->title;
 
95
    $item->link = url("node/$row->nid", array('absolute' => TRUE));
 
96
 
 
97
    // Allow modules to add additional item fields and/or modify $item
 
98
    $extra = node_invoke_nodeapi($node, 'rss item');
 
99
    $item->elements = array_merge($extra,
 
100
      array(
 
101
        array('key' => 'pubDate', 'value' => format_date($node->created, 'custom', 'r', variable_get('date_default_timezone', 0))),
 
102
        array(
 
103
          'key' => 'dc:creator',
 
104
          'value' => $node->name,
 
105
          'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'),
 
106
        ),
 
107
        array(
 
108
          'key' => 'guid',
 
109
          'value' => $node->nid . ' at ' . $base_url,
 
110
          'attributes' => array('isPermaLink' => 'false')
 
111
        ),
 
112
      )
 
113
    );
 
114
 
 
115
    foreach ($item->elements as $element) {
 
116
      if (isset($element['namespace'])) {
 
117
        $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']);
 
118
      }
 
119
    }
 
120
 
 
121
    // Prepare the item description
 
122
    switch ($item_length) {
 
123
      case 'fulltext':
 
124
        $item->description = $node->body;
 
125
        break;
 
126
      case 'teaser':
 
127
        $item->description = $node->teaser;
 
128
        if (!empty($item->readmore)) {
 
129
          $item->description .= '<p>' . l(t('read more'), 'node/' . $item->nid, array('absolute' => TRUE, 'attributes' => array('target' => '_blank'))) . '</p>';
 
130
        }
 
131
        break;
 
132
      case 'title':
 
133
        $item->description = '';
 
134
        break;
 
135
    }
 
136
 
 
137
    return theme($this->theme_functions(), $this->view, $this->options, $item);
 
138
  }
 
139
}
 
140