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

modules/comment/views_plugin_row_comment_rss.inc

Go to the documentation of this file.
00001 <?php
00010 class views_plugin_row_comment_rss extends views_plugin_row {
00011    var $base_table = 'comment';
00012    var $base_field = 'cid';
00013 
00014   function option_definition() {
00015     $options = parent::option_definition();
00016 
00017     $options['item_length'] = array('default' => 'default');
00018     $options['links'] = FALSE;
00019 
00020     return $options;
00021   }
00022 
00023   function options_form(&$form, &$form_state) {
00024     parent::options_form($form, $form_state);
00025 
00026     $form['item_length'] = array(
00027       '#type' => 'select',
00028       '#title' => t('Display type'),
00029       '#options' => $this->options_form_summary_options(),
00030       '#default_value' => $this->options['item_length'],
00031     );
00032     $form['links'] = array(
00033       '#type' => 'checkbox',
00034       '#title' => t('Display links'),
00035       '#default_value' => $this->options['links'],
00036     );
00037   }
00038 
00039 
00040   function pre_render($result) {
00041     $cids = array();
00042     $nids = array();
00043 
00044     foreach ($result as $row) {
00045       $cids[] = $row->cid;
00046     }
00047 
00048     $this->comments = comment_load_multiple($cids);
00049     foreach ($this->comments as &$comment) {
00050       $comment->depth = count(explode('.', $comment->thread)) - 1;
00051       $nids[] = $comment->nid;
00052     }
00053 
00054     $this->nodes = node_load_multiple($nids);
00055   }
00056 
00064   function options_form_summary_options() {
00065     $entity_info = entity_get_info('node');
00066     $options = array();
00067     if (!empty($entity_info['view modes'])) {
00068       foreach ($entity_info['view modes'] as $mode => $settings) {
00069         $options[$mode] = $settings['label'];
00070       }
00071     }
00072     $options['title'] = t('Title only');
00073     $options['default'] = t('Use site default RSS settings');
00074     return $options;
00075   }
00076 
00077 
00078   function render($row) {
00079     global $base_url;
00080 
00081     $cid = $row->{$this->field_alias};
00082     if (!is_numeric($cid)) {
00083       return;
00084     }
00085 
00086     $item_length = $this->options['item_length'];
00087     if ($item_length == 'default') {
00088       $item_length = variable_get('feed_item_length', 'teaser');
00089     }
00090 
00091     // Load the specified comment and its associated node:
00092     $comment = $this->comments[$cid];
00093     if (empty($comment) || empty($this->nodes[$comment->nid])) {
00094       return;
00095     }
00096 
00097     $item_text = '';
00098 
00099     $uri = entity_uri('comment', $comment);
00100     $comment->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
00101     $comment->rss_namespaces = array();
00102     $comment->rss_elements = array(
00103       array(
00104         'key' => 'pubDate',
00105         'value' => gmdate('r', $comment->created),
00106       ),
00107       array(
00108         'key' => 'dc:creator',
00109         'value' => $comment->name,
00110       ),
00111       array(
00112         'key' => 'guid',
00113         'value' => 'comment ' . $comment->cid . ' at ' . $base_url,
00114         'attributes' => array('isPermaLink' => 'false'),
00115       ),
00116     );
00117 
00118     // The comment gets built and modules add to or modify
00119     // $comment->rss_elements and $comment->rss_namespaces.
00120     $build = comment_view($comment, $this->nodes[$comment->nid], 'rss');
00121     unset($build['#theme']);
00122 
00123     if (!empty($comment->rss_namespaces)) {
00124       $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
00125     }
00126 
00127     // Hide the links if desired.
00128     if (!$this->options['links']) {
00129       hide($build['links']);
00130     }
00131 
00132     if ($item_length != 'title') {
00133       // We render comment contents and force links to be last.
00134       $build['links']['#weight'] = 1000;
00135       $item_text .= drupal_render($build);
00136     }
00137 
00138     $item = new stdClass();
00139     $item->description = $item_text;
00140     $item->title = $comment->subject;
00141     $item->link = $comment->link;
00142     $item->elements = $comment->rss_elements;
00143     $item->cid = $comment->cid;
00144 
00145     return theme($this->theme_functions(), array(
00146       'view' => $this->view,
00147       'options' => $this->options,
00148       'row' => $item
00149     ));
00150   }
00151 }

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