views_plugin_row_aggregator_rss.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_row_aggregator_rss.
  5. */
  6. /**
  7. * Plugin which loads an aggregator item and formats it as an RSS item.
  8. */
  9. class views_plugin_row_aggregator_rss extends views_plugin_row {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public $base_table = 'aggregator_item';
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public $base_field = 'iid';
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function option_definition() {
  22. $options = parent::option_definition();
  23. $options['item_length'] = array('default' => 'default');
  24. return $options;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function options_form(&$form, &$form_state) {
  30. $form['item_length'] = array(
  31. '#type' => 'select',
  32. '#title' => t('Display type'),
  33. '#options' => array(
  34. 'fulltext' => t('Full text'),
  35. 'teaser' => t('Title plus teaser'),
  36. 'title' => t('Title only'),
  37. 'default' => t('Use default RSS settings'),
  38. ),
  39. '#default_value' => $this->options['item_length'],
  40. );
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function render($row) {
  46. $iid = $row->{$this->field_alias};
  47. $sql = "SELECT ai.iid, ai.fid, ai.title, ai.link, ai.author, ai.description, ";
  48. $sql .= "ai.timestamp, ai.guid, af.title AS feed_title, ai.link AS feed_LINK ";
  49. $sql .= "FROM {aggregator_item} ai LEFT JOIN {aggregator_feed} af ON ai.fid = af.fid ";
  50. $sql .= "WHERE ai.iid = :iid";
  51. $item = db_query($sql, array(':iid' => $iid))->fetchObject();
  52. $item->elements = array(
  53. array(
  54. 'key' => 'pubDate',
  55. 'value' => gmdate('r', $item->timestamp),
  56. ),
  57. array(
  58. 'key' => 'dc:creator',
  59. 'value' => $item->author,
  60. ),
  61. array(
  62. 'key' => 'guid',
  63. 'value' => $item->guid,
  64. 'attributes' => array('isPermaLink' => 'false'),
  65. ),
  66. );
  67. foreach ($item->elements as $element) {
  68. if (isset($element['namespace'])) {
  69. $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']);
  70. }
  71. }
  72. return theme($this->theme_functions(), array(
  73. 'view' => $this->view,
  74. 'options' => $this->options,
  75. 'row' => $item,
  76. ));
  77. }
  78. }