5 * Contains the comment RSS row style plugin.
9 * Plugin which formats the comments as RSS items.
11 class views_plugin_row_comment_rss extends views_plugin_row {
12 var $base_table = 'comment';
13 var $base_field = 'cid';
15 function option_definition() {
16 $options = parent::option_definition();
18 $options['item_length'] = array('default' => 'default');
19 $options['links'] = array('default' => FALSE, 'bool' => TRUE);
24 function options_form(&$form, &$form_state) {
25 parent::options_form($form, $form_state);
27 $form['item_length'] = array(
29 '#title' => t('Display type'),
30 '#options' => $this->options_form_summary_options(),
31 '#default_value' => $this->options['item_length'],
33 $form['links'] = array(
34 '#type' => 'checkbox',
35 '#title' => t('Display links'),
36 '#default_value' => $this->options['links'],
41 function pre_render($result) {
45 foreach ($result as $row) {
49 $this->comments = comment_load_multiple($cids);
50 foreach ($this->comments as &$comment) {
51 $comment->depth = count(explode('.', $comment->thread)) - 1;
52 $nids[] = $comment->nid;
55 $this->nodes = node_load_multiple($nids);
59 * Return the main options, which are shown in the summary title
61 * @see views_plugin_row_node_rss::options_form_summary_options()
62 * @todo: Maybe provide a views_plugin_row_rss_entity and reuse this method
63 * in views_plugin_row_comment|node_rss.inc
65 function options_form_summary_options() {
66 $entity_info = entity_get_info('node');
68 if (!empty($entity_info['view modes'])) {
69 foreach ($entity_info['view modes'] as $mode => $settings) {
70 $options[$mode] = $settings['label'];
73 $options['title'] = t('Title only');
74 $options['default'] = t('Use site default RSS settings');
79 function render($row) {
82 $cid = $row->{$this->field_alias};
83 if (!is_numeric($cid)) {
87 $item_length = $this->options['item_length'];
88 if ($item_length == 'default') {
89 $item_length = variable_get('feed_item_length', 'teaser');
92 // Load the specified comment and its associated node:
93 $comment = $this->comments[$cid];
94 if (empty($comment) || empty($this->nodes[$comment->nid])) {
100 $uri = entity_uri('comment', $comment);
101 $comment->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
102 $comment->rss_namespaces = array();
103 $comment->rss_elements = array(
106 'value' => gmdate('r', $comment->created),
109 'key' => 'dc:creator',
110 'value' => format_username($comment),
114 'value' => 'comment ' . $comment->cid . ' at ' . $base_url,
115 'attributes' => array('isPermaLink' => 'false'),
119 // The comment gets built and modules add to or modify
120 // $comment->rss_elements and $comment->rss_namespaces.
121 $build = comment_view($comment, $this->nodes[$comment->nid], 'rss');
122 unset($build['#theme']);
124 if (!empty($comment->rss_namespaces)) {
125 $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
128 // Hide the links if desired.
129 if (!$this->options['links']) {
130 hide($build['links']);
133 if ($item_length != 'title') {
134 // We render comment contents and force links to be last.
135 $build['links']['#weight'] = 1000;
136 $item_text .= drupal_render($build);
139 $item = new stdClass();
140 $item->description = $item_text;
141 $item->title = $comment->subject;
142 $item->link = $comment->link;
143 $item->elements = $comment->rss_elements;
144 $item->cid = $comment->cid;
146 return theme($this->theme_functions(), array(
147 'view' => $this->view,
148 'options' => $this->options,