views_plugin_row_node_rss.inc

  1. 3.x modules/node/views_plugin_row_node_rss.inc
  2. 2.x modules/node/views_plugin_row_node_rss.inc

Contains the node RSS row style plugin.

File

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