first import

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy
2013-01-09 10:53:26 +01:00
commit b20b38f514
526 changed files with 76993 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
/**
* @file
* Definition of views_handler_argument_comment_user_uid.
*/
/**
* Argument handler to accept a user id to check for nodes that
* user posted or commented on.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_comment_user_uid extends views_handler_argument {
function title() {
if (!$this->argument) {
$title = variable_get('anonymous', t('Anonymous'));
}
else {
$title = db_query('SELECT u.name FROM {users} u WHERE u.uid = :uid', array(':uid' => $this->argument))->fetchField();
}
if (empty($title)) {
return t('No user');
}
return check_plain($title);
}
function default_actions($which = NULL) {
// Disallow summary views on this argument.
if (!$which) {
$actions = parent::default_actions();
unset($actions['summary asc']);
unset($actions['summary desc']);
return $actions;
}
if ($which != 'summary asc' && $which != 'summary desc') {
return parent::default_actions($which);
}
}
function query($group_by = FALSE) {
$this->ensure_my_table();
$subselect = db_select('comment', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->argument);
$subselect->where("c.nid = $this->table_alias.nid");
$condition = db_or()
->condition("$this->table_alias.uid", $this->argument, '=')
->exists($subselect);
$this->query->add_where(0, $condition);
}
function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order'));
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* @file
* Definition of views_handler_field_comment.
*/
/**
* Field handler to allow linking to a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment extends views_handler_field {
/**
* Override init function to provide generic option to link to comment.
*/
function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($this->options['link_to_comment'])) {
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['nid'] = 'nid';
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link-to-comment option
*/
function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE;
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;
}
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_depth.
*/
/**
* Field handler to display the depth of a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_depth extends views_handler_field {
/**
* Work out the depth of this comment
*/
function render($values) {
$comment_thread = $this->get_value($values);
return count(explode('.', $comment_thread)) - 1;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link.
*/
/**
* Base field handler to present a link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link extends views_handler_field_entity {
function construct() {
parent::construct();
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$value = $this->get_value($values, 'cid');
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$comment = $this->get_value($values);
$nid = $comment->nid;
$cid = $comment->cid;
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['html'] = TRUE;
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;
}
return $text;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_approve.
*/
/**
* Provides a comment approve link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_approve extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$status = $this->get_value($values, 'status');
// Don't show an approve link on published nodes.
if ($status == COMMENT_PUBLISHED) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('approve');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/approve";
$this->options['alter']['query'] = drupal_get_destination() + array('token' => drupal_get_token("comment/$cid/approve"));
return $text;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_delete.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_delete extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/delete";
$this->options['alter']['query'] = drupal_get_destination();
return $text;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_edit.
*/
/**
* Field handler to present a link node edit.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_edit extends views_handler_field_comment_link {
function option_definition() {
$options = parent::option_definition();
$options['destination'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['destination'] = array(
'#type' => 'checkbox',
'#title' => t('Use destination'),
'#description' => t('Add destination to the link'),
'#default_value' => $this->options['destination'],
'#fieldset' => 'more',
);
}
function render_link($data, $values) {
parent::render_link($data, $values);
// ensure user has access to edit this comment.
$comment = $this->get_value($values);
if (!comment_access('edit', $comment)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
unset($this->options['alter']['fragment']);
if (!empty($this->options['destination'])) {
$this->options['alter']['query'] = drupal_get_destination();
}
$this->options['alter']['path'] = "comment/" . $comment->cid . "/edit";
return $text;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_reply.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_reply extends views_handler_field_comment_link {
function access() {
//check for permission to reply to comments
return user_access('post comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/reply/" . $nid . '/' . $cid;
return $text;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_node_link.
*/
/**
* Handler for showing comment module's node link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_node_link extends views_handler_field_entity {
function construct() {
parent::construct();
// Add the node fields that comment_link will need..
$this->additional_fields['nid'] = array(
'field' => 'nid',
);
$this->additional_fields['type'] = array(
'field' => 'type',
);
$this->additional_fields['comment'] = array(
'field' => 'comment',
);
}
function option_definition() {
$options = parent::option_definition();
$options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Show teaser-style link'),
'#default_value' => $this->options['teaser'],
'#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
// Build fake $node.
$node = $this->get_value($values);
// Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
// Call node by reference so that something is changed here
comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
// question: should we run these through: drupal_alter('link', $links, $node);
// might this have unexpected consequences if these hooks expect items in $node that we don't have?
// Only render the links, if they are defined.
return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_username.
*/
/**
* Field handler to allow linking to a user account or homepage.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_username extends views_handler_field {
/**
* Override init function to add uid and homepage fields.
*/
function init(&$view, &$data) {
parent::init($view, $data);
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['homepage'] = 'homepage';
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['link_to_user'] = array(
'#title' => t("Link this field to its user or an author's homepage"),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_user'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
$account->homepage = $this->get_value($values, 'homepage');
return theme('username', array(
'account' => $account
));
}
else {
return $data;
}
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Definition of views_handler_field_last_comment_timestamp.
*/
/**
* Field handler to display the timestamp of a comment with the count of comments.
*
* @ingroup views_field_handlers
*/
class views_handler_field_last_comment_timestamp extends views_handler_field_date {
function construct() {
parent::construct();
$this->additional_fields['comment_count'] = 'comment_count';
}
function render($values) {
$comment_count = $this->get_value($values, 'comment_count');
if (empty($this->options['empty_zero']) || $comment_count) {
return parent::render($values);
}
else {
return NULL;
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @file
* Definition of views_handler_field_ncs_last_comment_name.
*/
/**
* Field handler to present the name of the last comment poster.
*
* @ingroup views_field_handlers
*/
class views_handler_field_ncs_last_comment_name extends views_handler_field {
function query() {
// last_comment_name only contains data if the user is anonymous. So we
// have to join in a specially related user table.
$this->ensure_my_table();
// join 'users' to this table via vid
$join = new views_join();
$join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
$join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0'));
// ncs_user alias so this can work with the sort handler, below.
// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
$this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
$this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
$this->user_field = $this->query->add_field($this->user_table, 'name');
$this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid');
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function render($values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->name = $this->get_value($values);
$account->uid = $values->{$this->uid};
return theme('username', array(
'account' => $account
));
}
else {
return $this->sanitize_value($this->get_value($values));
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Definition of views_handler_field_ncs_last_updated.
*/
/**
* Field handler to display the newer of last comment / node updated.
*
* @ingroup views_field_handlers
*/
class views_handler_field_ncs_last_updated extends views_handler_field_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$this->field_alias = $this->query->add_field(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_field_node_comment.
*/
/**
* Display node comment status.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_comment extends views_handler_field {
function render($values) {
$value = $this->get_value($values);
switch ($value) {
case COMMENT_NODE_HIDDEN:
default:
return t('Hidden');
case COMMENT_NODE_CLOSED:
return t('Closed');
case COMMENT_NODE_OPEN:
return t('Open');
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* @file
* Definition of views_handler_field_node_new_comments.
*/
/**
* Field handler to display the number of new comments.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_new_comments extends views_handler_field_numeric {
function init(&$view, &$options) {
parent::init($view, $options);
// translate an older setting:
if (!empty($options['no_empty'])) {
$this->options['hide_empty'] = TRUE;
unset($this->options['no_empty']);
}
}
function construct() {
parent::construct();
$this->additional_fields['nid'] = 'nid';
$this->additional_fields['type'] = 'type';
$this->additional_fields['comment_count'] = array('table' => 'node_comment_statistics', 'field' => 'comment_count');
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array(
'#title' => t('Link this field to new comments'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
$this->field_alias = $this->table . '_' . $this->field;
}
function pre_render(&$values) {
global $user;
if (!$user->uid || empty($values)) {
return;
}
$nids = array();
$ids = array();
foreach ($values as $id => $result) {
$nids[] = $result->{$this->aliases['nid']};
$values[$id]->{$this->field_alias} = 0;
// Create a reference so we can find this record in the values again.
if (empty($ids[$result->{$this->aliases['nid']}])) {
$ids[$result->{$this->aliases['nid']}] = array();
}
$ids[$result->{$this->aliases['nid']}][] = $id;
}
if ($nids) {
$result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids)
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid ", array(
':status' => COMMENT_PUBLISHED,
':h_uid' => $user->uid,
':nids' => $nids,
':timestamp' => NODE_NEW_LIMIT,
));
foreach ($result as $node) {
foreach ($ids[$node->nid] as $id) {
$values[$id]->{$this->field_alias} = $node->num_comments;
}
}
}
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node = new stdClass();
$node->nid = $this->get_value($values, 'nid');
$node->type = $this->get_value($values, 'type');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid;
$this->options['alter']['query'] = comment_new_page_count($this->get_value($values, 'comment_count'), $this->get_value($values), $node);
$this->options['alter']['fragment'] = 'new';
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
if (!empty($value)) {
return $this->render_link(parent::render($values), $values);
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_filter_comment_user_uid.
*/
/**
* Filter handler to accept a user id to check for nodes that user posted or
* commented on.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_comment_user_uid extends views_handler_filter_user_name {
function query() {
$this->ensure_my_table();
$subselect = db_select('comment', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->value, $this->operator);
$subselect->where("c.nid = $this->table_alias.nid");
$condition = db_or()
->condition("$this->table_alias.uid", $this->value, $this->operator)
->exists($subselect);
$this->query->add_where($this->options['group'], $condition);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Definition of views_handler_filter_ncs_last_updated.
*/
/**
* Filter handler for the newer of last comment / node updated.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_ncs_last_updated extends views_handler_filter_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$field = "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)";
$info = $this->operators();
if (!empty($info[$this->operator]['method'])) {
$this->{$info[$this->operator]['method']}($field);
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_comment.
*/
/**
* Filter based on comment node status.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_comment extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
COMMENT_NODE_HIDDEN => t('Hidden'),
COMMENT_NODE_CLOSED => t('Closed'),
COMMENT_NODE_OPEN => t('Open'),
);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Definition of views_handler_sort_comment_thread.
*/
/**
* Sort handler for ordering by thread.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_comment_thread extends views_handler_sort {
function query() {
$this->ensure_my_table();
//Read comment_render() in comment.module for an explanation of the
//thinking behind this sort.
if ($this->options['order'] == 'DESC') {
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
}
else {
$alias = $this->table_alias . '_' . $this->real_field . 'asc';
//@todo is this secure?
$this->query->add_orderby(NULL, "SUBSTRING({$this->table_alias}.{$this->real_field}, 1, (LENGTH({$this->table_alias}.{$this->real_field}) - 1))", $this->options['order'], $alias);
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Definition of views_handler_sort_ncs_last_comment_name.
*/
/**
* Sort handler to sort by last comment name which might be in 2 different
* fields.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_ncs_last_comment_name extends views_handler_sort {
function query() {
$this->ensure_my_table();
$join = new views_join();
$join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
// @todo this might be safer if we had an ensure_relationship rather than guessing
// the table alias. Though if we did that we'd be guessing the relationship name
// so that doesn't matter that much.
// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
$this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
$this->user_field = $this->query->add_field($this->user_table, 'name');
// Add the field.
$this->query->add_orderby(NULL, "LOWER(COALESCE($this->user_table.name, $this->table_alias.$this->field))", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* Definition of views_handler_sort_ncs_last_updated.
*/
/**
* Sort handler for the newer of last comment / node updated.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_ncs_last_updated extends views_handler_sort_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$this->field_alias = $this->query->add_orderby(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* @file
* Contains the comment RSS row style plugin.
*/
/**
* Plugin which formats the comments as RSS items.
*/
class views_plugin_row_comment_rss extends views_plugin_row {
var $base_table = 'comment';
var $base_field = 'cid';
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
$options['links'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['item_length'] = array(
'#type' => 'select',
'#title' => t('Display type'),
'#options' => $this->options_form_summary_options(),
'#default_value' => $this->options['item_length'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
function pre_render($result) {
$cids = array();
$nids = array();
foreach ($result as $row) {
$cids[] = $row->cid;
}
$this->comments = comment_load_multiple($cids);
foreach ($this->comments as &$comment) {
$comment->depth = count(explode('.', $comment->thread)) - 1;
$nids[] = $comment->nid;
}
$this->nodes = node_load_multiple($nids);
}
/**
* Return the main options, which are shown in the summary title
*
* @see views_plugin_row_node_rss::options_form_summary_options()
* @todo: Maybe provide a views_plugin_row_rss_entity and reuse this method
* in views_plugin_row_comment|node_rss.inc
*/
function options_form_summary_options() {
$entity_info = entity_get_info('node');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
$options['title'] = t('Title only');
$options['default'] = t('Use site default RSS settings');
return $options;
}
function render($row) {
global $base_url;
$cid = $row->{$this->field_alias};
if (!is_numeric($cid)) {
return;
}
$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['options'] + 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 ' . $comment->cid . ' at ' . $base_url,
'attributes' => array('isPermaLink' => 'false'),
),
);
// The comment gets built and modules add to or modify
// $comment->rss_elements and $comment->rss_namespaces.
$build = comment_view($comment, $this->nodes[$comment->nid], '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,
'row' => $item
));
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* @file
* Contains the node RSS row style plugin.
*/
/**
* Plugin which performs a comment_view on the resulting object.
*/
class views_plugin_row_comment_view extends views_plugin_row {
var $base_field = 'cid';
var $base_table = 'comment';
/**
* Stores all comments which are preloaded.
*/
var $comments = array();
/**
* Stores all nodes of all comments which are preloaded.
*/
var $nodes = array();
function summary_title() {
return t('Settings');
}
function option_definition() {
$options = parent::option_definition();
$options['links'] = array('default' => TRUE, 'bool' => TRUE);
$options['view_mode'] = array('default' => 'full');
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = $this->options_form_summary_options();
$form['view_mode'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('View mode'),
'#default_value' => $this->options['view_mode'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
/**
* Return the main options, which are shown in the summary title.
*/
function options_form_summary_options() {
$entity_info = entity_get_info('comment');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
if (empty($options)) {
$options = array(
'full' => t('Full content')
);
}
return $options;
}
function pre_render($result) {
$cids = array();
foreach ($result as $row) {
$cids[] = $row->cid;
}
// Load all comments.
$cresult = comment_load_multiple($cids);
$nids = array();
foreach ($cresult as $comment) {
$comment->depth = count(explode('.', $comment->thread)) - 1;
$this->comments[$comment->cid] = $comment;
$nids[] = $comment->nid;
}
// Load all nodes of the comments.
$nodes = node_load_multiple(array_unique($nids));
foreach ($nodes as $node) {
$this->nodes[$node->nid] = $node;
}
}
}