diff --git a/modules/aggregator/views_plugin_row_aggregator_rss.inc b/modules/aggregator/views_plugin_row_aggregator_rss.inc index b2ef964..35aadec 100644 --- a/modules/aggregator/views_plugin_row_aggregator_rss.inc +++ b/modules/aggregator/views_plugin_row_aggregator_rss.inc @@ -43,11 +43,13 @@ class views_plugin_row_aggregator_rss extends views_plugin_row { $item = db_query($sql, array(':iid' => $iid))->fetchObject(); $item->elements = array( - array('key' => 'pubDate', 'value' => gmdate('r', $item->timestamp)), + array( + 'key' => 'pubDate', + 'value' => gmdate('r', $item->timestamp), + ), array( 'key' => 'dc:creator', 'value' => $item->author, - 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), ), array( 'key' => 'guid', @@ -69,4 +71,3 @@ class views_plugin_row_aggregator_rss extends views_plugin_row { )); } } - diff --git a/modules/comment/views_plugin_row_comment_rss.inc b/modules/comment/views_plugin_row_comment_rss.inc index 23e830a..d205e8a 100644 --- a/modules/comment/views_plugin_row_comment_rss.inc +++ b/modules/comment/views_plugin_row_comment_rss.inc @@ -10,51 +10,92 @@ class views_plugin_row_comment_rss extends views_plugin_row { var $base_table = 'comment'; var $base_field = 'cid'; - + function pre_render($result) { $cids = array(); - $this->comments = array(); + $nids = array(); foreach ($result as $row) { $cids[] = $row->cid; } - $cresult = comment_load_multiple($cids); - foreach ($cresult as $comment) { - $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + $this->comments = comment_load_multiple($cids); + foreach ($this->comments as &$comment) { $comment->depth = count(explode('.', $comment->thread)) - 1; - $this->comments[$comment->cid] = $comment; + $nids[] = $comment->nid; } + + $this->nodes = node_load_multiple($nids); } function render($row) { + // For the most part, this code is taken from node_feed() in node.module global $base_url; - // Load the specified comment: - $comment = $this->comments[$row->{$this->field_alias}]; + $cid = $row->{$this->field_alias}; + if (!is_numeric($cid)) { + return; + } - $item = new stdClass(); - $item->title = $comment->subject; - $item->link = url('node/' . $comment->nid, array('absolute' => TRUE, 'fragment' => 'comment-' . $comment->cid)); - $items = field_get_items('comment', $comment, 'comment_body'); - $item->description = check_markup($items[0]['value'], $items[0]['format']); - $item->elements = array( - array('key' => 'pubDate', 'value' => gmdate('r', $comment->created)), - array('key' => 'dc:creator', 'value' => $comment->name), + $item_length = $this->options['item_length']; + if ($item_length == 'default') { + $item_length = variable_get('feed_item_length', 'teaser'); + } + + // Load the specified comment and its associated node: + $comment = $this->comments[$cid]; + if (empty($comment) || empty($this->nodes[$comment->nid])) { + return; + } + + $item_text = ''; + + $uri = entity_uri('comment', $comment); + $comment->link = url($uri['path'], $uri['option'] + array('absolute' => TRUE)); + $comment->rss_namespaces = array(); + $comment->rss_elements = array( + array( + 'key' => 'pubDate', + 'value' => gmdate('r', $comment->created), + ), + array( + 'key' => 'dc:creator', + 'value' => $comment->name, + ), array( 'key' => 'guid', - 'value' => 'comment ' . $row->cid . ' at ' . $base_url, + 'value' => 'comment ' . $comment->cid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'), - 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), ), ); - foreach ($item->elements as $element) { - if (isset($element['namespace'])) { - $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']); - } + // The comment gets built and modules add to or modify + // $comment->rss_elements and $comment->rss_namespaces. + $build = comment_view($comment, $this->nodes[$comment->cid], 'rss'); + unset($build['#theme']); + + if (!empty($comment->rss_namespaces)) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces); + } + + // Hide the links if desired. + if (!$this->options['links']) { + hide($build['links']); } + if ($item_length != 'title') { + // We render comment contents and force links to be last. + $build['links']['#weight'] = 1000; + $item_text .= drupal_render($build); + } + + $item = new stdClass(); + $item->description = $item_text; + $item->title = $comment->subject; + $item->link = $comment->link; + $item->elements = $comment->rss_elements; + $item->cid = $comment->cid; + return theme($this->theme_functions(), array( 'view' => $this->view, 'options' => $this->options, diff --git a/modules/node/views_plugin_row_node_rss.inc b/modules/node/views_plugin_row_node_rss.inc index 5beb51b..5617748 100644 --- a/modules/node/views_plugin_row_node_rss.inc +++ b/modules/node/views_plugin_row_node_rss.inc @@ -91,45 +91,56 @@ class views_plugin_row_node_rss extends views_plugin_row { $item_text = ''; - $node->rss_namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'); + $uri = entity_uri('node', $node); + $node->link = url($uri['path'], $uri['option'] + array('absolute' => TRUE)); + $node->rss_namespaces = array(); $node->rss_elements = array( - array('key' => 'pubDate', 'value' => gmdate('r', $node->created)), - array('key' => 'dc:creator', 'value' => $node->name), - array('key' => 'guid', 'value' => $node->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false')) + array( + 'key' => 'pubDate', + 'value' => gmdate('r', $node->created), + ), + array( + 'key' => 'dc:creator', + 'value' => $node->name, + ), + array( + 'key' => 'guid', + 'value' => $node->nid . ' at ' . $base_url, + 'attributes' => array('isPermaLink' => 'false'), + ), ); // The node gets built and modules add to or modify $node->rss_elements // and $node->rss_namespaces. - node_build_content($node, 'rss'); + $build = node_view($node, 'rss'); + unset($build['#theme']); - $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $node->rss_namespaces); + if (!empty($node->rss_namespaces)) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $node->rss_namespaces); + } - if ($item_length != 'title' && !empty($node->content)) { + // Hide the links if desired. + if (!$this->options['links']) { + hide($build['links']); + } + + if ($item_length != 'title') { // We render node contents and force links to be last. - hide($node->content['links']); - $item_text .= drupal_render($node->content); - if ($this->options['links']) { - show($node->content['links']); - $item_text .= drupal_render($node->content['links']); - } + $build['links']['#weight'] = 1000; + $item_text .= drupal_render($build); } - $item = new stdClass; + $item = new stdClass(); $item->description = $item_text; $item->title = $node->title; - $item->link = url("node/$node->nid", array('absolute' => TRUE)); + $item->link = $node->link; $item->elements = $node->rss_elements; $item->nid = $node->nid; - if (isset($node->readmore)) { - $item->readmore = $node->readmore; - } - return theme($this->theme_functions(), - array( - 'view' => $this->view, - 'options' => $this->options, - 'row' => $item - )); + return theme($this->theme_functions(), array( + 'view' => $this->view, + 'options' => $this->options, + 'row' => $item + )); } } - diff --git a/plugins/views_plugin_style_rss.inc b/plugins/views_plugin_style_rss.inc index 020cc28..cb3838f 100644 --- a/plugins/views_plugin_style_rss.inc +++ b/plugins/views_plugin_style_rss.inc @@ -78,7 +78,7 @@ class views_plugin_style_rss extends views_plugin_style { // This will be filled in by the row plugin and is used later on in the // theming output. - $this->namespaces = array(); + $this->namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'); // Fetch any additional elements for the channel and merge in their // namespaces.