• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/node/views_plugin_row_node_rss.inc

Go to the documentation of this file.
00001 <?php
00011 class views_plugin_row_node_rss extends views_plugin_row {
00012   // Basic properties that let the row style follow relationships.
00013   var $base_table = 'node';
00014   var $base_field = 'nid';
00015 
00016   // Stores the nodes loaded with pre_render.
00017   var $nodes = array();
00018 
00019   function option_definition() {
00020     $options = parent::option_definition();
00021 
00022     $options['item_length'] = array('default' => 'default');
00023     $options['links'] = FALSE;
00024 
00025     return $options;
00026   }
00027 
00031   function init(&$view, &$display, $options = NULL) {
00032     parent::init($view, $display, $options);
00033 
00034     if ($this->options['item_length'] == 'fulltext') {
00035       $this->options['item_length'] = 'full';
00036     }
00037   }
00038 
00039   function options_form(&$form, &$form_state) {
00040     parent::options_form($form, $form_state);
00041 
00042     $form['item_length'] = array(
00043       '#type' => 'select',
00044       '#title' => t('Display type'),
00045       '#options' => $this->options_form_summary_options(),
00046       '#default_value' => $this->options['item_length'],
00047     );
00048     $form['links'] = array(
00049       '#type' => 'checkbox',
00050       '#title' => t('Display links'),
00051       '#default_value' => $this->options['links'],
00052     );
00053   }
00054 
00058   function options_form_summary_options() {
00059     $entity_info = entity_get_info('node');
00060     $options = array();
00061     if (!empty($entity_info['view modes'])) {
00062       foreach ($entity_info['view modes'] as $mode => $settings) {
00063         $options[$mode] = $settings['label'];
00064       }
00065     }
00066     $options['title'] = t('Title only');
00067     $options['default'] = t('Use site default RSS settings');
00068     return $options;
00069   }
00070 
00071   function summary_title() {
00072     $options = $this->options_form_summary_options();
00073     return check_plain($options[$this->options['item_length']]);
00074   }
00075 
00076 
00077   function pre_render($values) {
00078     $nids = array();
00079     foreach ($values as $row) {
00080       $nids[] = $row->{$this->field_alias};
00081     }
00082     if (!empty($nids)) {
00083       $this->nodes = node_load_multiple($nids);
00084     }
00085   }
00086 
00087   function render($row) {
00088     // For the most part, this code is taken from node_feed() in node.module
00089     global $base_url;
00090 
00091     $nid = $row->{$this->field_alias};
00092     if (!is_numeric($nid)) {
00093       return;
00094     }
00095 
00096     $display_mode = $this->options['item_length'];
00097     if ($display_mode == 'default') {
00098       $display_mode = variable_get('feed_item_length', 'teaser');
00099     }
00100 
00101     // Load the specified node:
00102     $node = $this->nodes[$nid];
00103     if (empty($node)) {
00104       return;
00105     }
00106 
00107     $item_text = '';
00108 
00109     $uri = entity_uri('node', $node);
00110     $node->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
00111     $node->rss_namespaces = array();
00112     $node->rss_elements = array(
00113       array(
00114         'key' => 'pubDate',
00115         'value' => gmdate('r', $node->created),
00116       ),
00117       array(
00118         'key' => 'dc:creator',
00119         'value' => $node->name,
00120       ),
00121       array(
00122         'key' => 'guid',
00123         'value' => $node->nid . ' at ' . $base_url,
00124         'attributes' => array('isPermaLink' => 'false'),
00125       ),
00126     );
00127 
00128     // The node gets built and modules add to or modify $node->rss_elements
00129     // and $node->rss_namespaces.
00130 
00131     $build_mode = $display_mode;
00132 
00133     $build = node_view($node, $build_mode);
00134     unset($build['#theme']);
00135 
00136     if (!empty($node->rss_namespaces)) {
00137       $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $node->rss_namespaces);
00138     } else if (module_exists('rdf')) {
00139       $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, rdf_get_namespaces());
00140     }
00141 
00142     // Hide the links if desired.
00143     if (!$this->options['links']) {
00144       hide($build['links']);
00145     }
00146 
00147     if ($display_mode != 'title') {
00148       // We render node contents and force links to be last.
00149       $build['links']['#weight'] = 1000;
00150       $item_text .= drupal_render($build);
00151     }
00152 
00153     $item = new stdClass();
00154     $item->description = $item_text;
00155     $item->title = $node->title;
00156     $item->link = $node->link;
00157     $item->elements = $node->rss_elements;
00158     $item->nid = $node->nid;
00159 
00160     return theme($this->theme_functions(), array(
00161       'view' => $this->view,
00162       'options' => $this->options,
00163       'row' => $item
00164     ));
00165   }
00166 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1