2
// $Id: comment.views.inc,v 1.32 2009/04/08 06:38:41 merlinofchaos Exp $
5
* Provide views data and handlers for comment.module
9
* @defgroup views_comment_module comment.module handlers
11
* Includes the tables 'comments' and 'node_comment_statistics'
16
* Implementation of hook_views_data()
19
function comment_views_data() {
20
// Define the base group of this table. Fields that don't
21
// have a group defined will go into this field by default.
22
$data['comments']['table']['group'] = t('Comment');
24
$data['comments']['table']['base'] = array(
26
'title' => t('Comment'),
27
'help' => t("Comments are responses to node content."),
31
$data['comments']['table']['join'] = array(
32
//...to the node table
34
'left_field' => 'nid',
39
// ----------------------------------------------------------------
43
$data['comments']['subject'] = array(
44
'title' => t('Title'),
45
'help' => t('The title of the comment.'),
47
'handler' => 'views_handler_field_comment',
48
'click sortable' => TRUE,
51
'handler' => 'views_handler_filter_string',
54
'handler' => 'views_handler_sort',
57
'handler' => 'views_handler_argument_string',
61
// comment (the comment body)
62
$data['comments']['comment'] = array(
64
'help' => t('The text of the comment.'),
66
'handler' => 'views_handler_field_markup',
70
'handler' => 'views_handler_filter_string',
75
$data['comments']['cid'] = array(
77
'help' => t('The comment ID of the field'),
79
'handler' => 'views_handler_field_comment',
80
'click sortable' => TRUE,
83
'handler' => 'views_handler_filter_numeric',
86
'handler' => 'views_handler_sort',
89
'handler' => 'views_handler_argument',
93
// name (of comment author)
94
$data['comments']['name'] = array(
95
'title' => t('Author'),
96
'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
98
'handler' => 'views_handler_field_comment_username',
99
'click sortable' => TRUE,
102
'handler' => 'views_handler_filter_string',
105
'handler' => 'views_handler_sort',
108
'handler' => 'views_handler_argument_string',
113
$data['comments']['homepage'] = array(
114
'title' => t("Author's website"),
115
'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
117
'handler' => 'views_handler_field_url',
118
'click sortable' => TRUE,
121
'handler' => 'views_handler_filter_string',
124
'handler' => 'views_handler_sort',
127
'handler' => 'views_handler_argument_string',
131
// timestamp (when comment was posted)
132
$data['comments']['timestamp'] = array(
133
'title' => t('Post date'),
134
'help' => t('Date and time of when the comment was posted.'),
136
'handler' => 'views_handler_field_date',
137
'click sortable' => TRUE,
140
'handler' => 'views_handler_sort_date',
143
'handler' => 'views_handler_filter_date',
147
// status (approved or not)
148
$data['comments']['status'] = array(
149
'title' => t('In moderation'),
150
'help' => t('Whether or not the comment is currently in moderation.'),
152
'handler' => 'views_handler_field_boolean',
153
'click sortable' => TRUE,
156
'handler' => 'views_handler_filter_boolean_operator',
157
'label' => t('Moderated'),
161
'handler' => 'views_handler_sort',
165
// link to view comment
166
$data['comments']['view_comment'] = array(
168
'title' => t('View link'),
169
'help' => t('Provide a simple link to view the comment.'),
170
'handler' => 'views_handler_field_comment_link',
174
// link to edit comment
175
$data['comments']['edit_comment'] = array(
177
'title' => t('Edit link'),
178
'help' => t('Provide a simple link to edit the comment.'),
179
'handler' => 'views_handler_field_comment_link_edit',
183
// link to delete comment
184
$data['comments']['delete_comment'] = array(
186
'title' => t('Delete link'),
187
'help' => t('Provide a simple link to delete the comment.'),
188
'handler' => 'views_handler_field_comment_link_delete',
192
// link to reply to comment
193
$data['comments']['replyto_comment'] = array(
195
'title' => t('Reply-to link'),
196
'help' => t('Provide a simple link to reply to the comment.'),
197
'handler' => 'views_handler_field_comment_link_reply',
201
$data['comments']['node_link'] = array(
203
'title' => t('Node link'),
204
'help' => t('Display the standard comment link used on regular nodes.'),
205
'handler' => 'views_handler_field_comment_node_link',
209
$data['comments']['thread'] = array(
211
'title' => t('Depth'),
212
'help' => t('Display the depth of the comment if it is threaded.'),
213
'handler' => 'views_handler_field_comment_depth',
216
'title' => t('Thread'),
217
'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
218
'handler' => 'views_handler_sort_comment_thread',
222
$data['comments']['nid'] = array(
223
'title' => t('Node'),
224
'help' => t('The node the comment is a reply to.'),
225
'relationship' => array(
228
'handler' => 'views_handler_relationship',
229
'label' => t('Node'),
233
$data['comments']['uid'] = array(
234
'title' => t('User'),
235
'help' => t("The User ID of the comment's author."),
236
'relationship' => array(
239
'handler' => 'views_handler_relationship',
240
'label' => t('User'),
244
$data['comments']['pid'] = array(
245
'title' => t('Parent CID'),
246
'help' => t('The Comment ID of the parent comment.'),
248
'handler' => 'views_handler_field',
250
'relationship' => array(
251
'title' => t('Parent comment'),
252
'help' => t('The parent comment.'),
253
'base' => 'comments',
255
'handler' => 'views_handler_relationship',
256
'label' => t('Parent comment'),
260
// ----------------------------------------------------------------------
261
// node_comment_statistics table
264
$data['node_comment_statistics']['table']['group'] = t('Node');
267
$data['node_comment_statistics']['table']['join'] = array(
268
//...to the node table
271
'left_field' => 'nid',
276
// last_comment_timestamp
277
$data['node_comment_statistics']['last_comment_timestamp'] = array(
278
'title' => t('Last comment time'),
279
'help' => t('Date and time of when the last comment was posted.'),
281
'handler' => 'views_handler_field_date',
282
'click sortable' => TRUE,
285
'handler' => 'views_handler_sort_date',
288
'handler' => 'views_handler_filter_date',
292
// last_comment_name (author's name)
293
$data['node_comment_statistics']['last_comment_name'] = array(
294
'title' => t("Last comment author"),
295
'help' => t('The name of the author of the last posted comment.'),
297
'handler' => 'views_handler_field_ncs_last_comment_name',
298
'click sortable' => TRUE,
301
'handler' => 'views_handler_sort_ncs_last_comment_name',
306
$data['node_comment_statistics']['comment_count'] = array(
307
'title' => t('Comment count'),
308
'help' => t('The number of comments a node has.'),
310
'handler' => 'views_handler_field_numeric',
311
'click sortable' => TRUE,
314
'handler' => 'views_handler_filter_numeric',
317
'handler' => 'views_handler_sort',
320
'handler' => 'views_handler_argument',
324
// last_comment_timestamp
325
$data['node_comment_statistics']['last_updated'] = array(
326
'title' => t('Updated/commented date'),
327
'help' => t('The most recent of last comment posted or node updated time.'),
329
'handler' => 'views_handler_field_ncs_last_updated',
330
'click sortable' => TRUE,
333
'handler' => 'views_handler_sort_ncs_last_updated',
336
'handler' => 'views_handler_filter_ncs_last_updated',
344
* Use views_data_alter to add items to the node table that are
345
* relevant to comments.
347
function comment_views_data_alter(&$data) {
349
$data['node']['new_comments'] = array(
350
'title' => t('New comments'),
351
'help' => t('The number of new comments on the node.'),
353
'handler' => 'views_handler_field_node_new_comments',
357
// Comment status of the node
358
$data['node']['comment'] = array(
359
'title' => t('Comment status'),
360
'help' => t('Whether comments are enabled or disabled on the node.'),
362
'handler' => 'views_handler_field_node_comment',
363
'click sortable' => TRUE,
366
'handler' => 'views_handler_sort',
369
'handler' => 'views_handler_filter_node_comment',
373
$data['node']['uid_touch'] = array(
374
'title' => t('User posted or commented'),
375
'help' => t('Display nodes only if a user posted the node or commented on the node.'),
378
'name table' => 'users',
379
'name field' => 'name',
380
'handler' => 'views_handler_argument_comment_user_uid',
384
'name table' => 'users',
385
'name field' => 'name',
386
'handler' => 'views_handler_filter_comment_user_uid'
393
* Implementation of hook_views_plugins
395
function comment_views_plugins() {
397
'module' => 'views', // This just tells views our themes are in Views.
400
'title' => t('Comment'),
401
'help' => t('Display the comment with standard comment view.'),
402
'handler' => 'views_plugin_row_comment_view',
403
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
404
'theme' => 'views_view_row_comment',
405
'base' => array('comments'), // only works with 'comment' as base.
406
'uses options' => TRUE,
408
'help topic' => 'style-comment',
410
'comment_rss' => array(
411
'title' => t('Comment'),
412
'help' => t('Display the comment as RSS.'),
413
'handler' => 'views_plugin_row_comment_rss',
414
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
415
'theme' => 'views_view_row_rss',
416
'base' => array('comments'), // only works with 'comment' as base.
418
'help topic' => 'style-comment-rss',
425
* Implementation of hook_views_handlers() to register all of the basic handlers
428
function comment_views_handlers() {
431
'path' => drupal_get_path('module', 'views') . '/modules/comment',
434
'views_handler_field_comment' => array(
435
'parent' => 'views_handler_field',
437
'views_handler_field_comment_username' => array(
438
'parent' => 'views_handler_field',
440
'views_handler_field_comment_depth' => array(
441
'parent' => 'views_handler_field',
443
'views_handler_field_comment_link' => array(
444
'parent' => 'views_handler_field',
446
'views_handler_field_comment_link_edit' => array(
447
'parent' => 'views_handler_field_comment_link',
449
'views_handler_field_comment_link_delete' => array(
450
'parent' => 'views_handler_field_comment_link',
452
'views_handler_field_comment_link_reply' => array(
453
'parent' => 'views_handler_field_comment_link',
455
'views_handler_field_comment_node_link' => array(
456
'parent' => 'views_handler_field',
458
'views_handler_field_ncs_last_comment_name' => array(
459
'parent' => 'views_handler_field',
461
'views_handler_field_ncs_last_updated' => array(
462
'parent' => 'views_handler_field_date',
464
'views_handler_field_node_new_comments' => array(
465
'parent' => 'views_handler_field_numeric',
467
'views_handler_field_node_comment' => array(
468
'parent' => 'views_handler_field',
472
'views_handler_sort_comment_thread' => array(
473
'parent' => 'views_handler_sort',
475
'views_handler_sort_ncs_last_comment_name' => array(
476
'parent' => 'views_handler_sort',
478
'views_handler_sort_ncs_last_updated' => array(
479
'parent' => 'views_handler_sort_date',
483
'views_handler_filter_ncs_last_updated' => array(
484
'parent' => 'views_handler_filter_date',
486
'views_handler_filter_node_comment' => array(
487
'parent' => 'views_handler_filter_in_operator',
489
'views_handler_filter_comment_user_uid' => array(
490
'parent' => 'views_handler_filter_user_name',
494
'views_handler_argument_comment_user_uid' => array(
495
'parent' => 'views_handler_argument',
502
* Template helper for theme_views_view_row_comment
504
function template_preprocess_views_view_row_comment(&$vars) {
505
$options = $vars['options'];
506
$view = &$vars['view'];
507
$plugin = &$view->style_plugin->row_plugin;
508
$comment = $plugin->comments[$vars['row']->cid];
509
$node = node_load($comment->nid);
510
// Put the view on the node so we can retrieve it in the preprocess.
511
$node->view = &$view;
514
if (!empty($options['links'])) {
515
$links = module_invoke_all('link', 'comment', $comment, 0);
516
drupal_alter('link', $links, $node);
519
$vars['comment'] = theme('comment_view', $comment, $node, $links);