/[drupal]/contributions/modules/views/modules/comment.views.inc
ViewVC logotype

Contents of /contributions/modules/views/modules/comment.views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.33 - (show annotations) (download) (as text)
Tue Sep 15 16:48:51 2009 UTC (2 months, 1 week ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.32: +39 -1 lines
File MIME type: text/x-php
#520632 by DamZ: Add comment hostname and mail to available comment fields.
1 <?php
2 // $Id: comment.views.inc,v 1.32 2009/04/08 06:38:41 merlinofchaos Exp $
3 /**
4 * @file
5 * Provide views data and handlers for comment.module
6 */
7
8 /**
9 * @defgroup views_comment_module comment.module handlers
10 *
11 * Includes the tables 'comments' and 'node_comment_statistics'
12 * @{
13 */
14
15 /**
16 * Implementation of hook_views_data()
17 */
18
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');
23
24 $data['comments']['table']['base'] = array(
25 'field' => 'cid',
26 'title' => t('Comment'),
27 'help' => t("Comments are responses to node content."),
28 );
29
30 //joins
31 $data['comments']['table']['join'] = array(
32 //...to the node table
33 'node' => array(
34 'left_field' => 'nid',
35 'field' => 'nid',
36 ),
37 );
38
39 // ----------------------------------------------------------------
40 // Fields
41
42 // subject
43 $data['comments']['subject'] = array(
44 'title' => t('Title'),
45 'help' => t('The title of the comment.'),
46 'field' => array(
47 'handler' => 'views_handler_field_comment',
48 'click sortable' => TRUE,
49 ),
50 'filter' => array(
51 'handler' => 'views_handler_filter_string',
52 ),
53 'sort' => array(
54 'handler' => 'views_handler_sort',
55 ),
56 'argument' => array(
57 'handler' => 'views_handler_argument_string',
58 ),
59 );
60
61 // comment (the comment body)
62 $data['comments']['comment'] = array(
63 'title' => t('Body'),
64 'help' => t('The text of the comment.'),
65 'field' => array(
66 'handler' => 'views_handler_field_markup',
67 'format' => 'format',
68 ),
69 'filter' => array(
70 'handler' => 'views_handler_filter_string',
71 ),
72 );
73
74 // cid
75 $data['comments']['cid'] = array(
76 'title' => t('ID'),
77 'help' => t('The comment ID of the field'),
78 'field' => array(
79 'handler' => 'views_handler_field_comment',
80 'click sortable' => TRUE,
81 ),
82 'filter' => array(
83 'handler' => 'views_handler_filter_numeric',
84 ),
85 'sort' => array(
86 'handler' => 'views_handler_sort',
87 ),
88 'argument' => array(
89 'handler' => 'views_handler_argument',
90 ),
91 );
92
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."),
97 'field' => array(
98 'handler' => 'views_handler_field_comment_username',
99 'click sortable' => TRUE,
100 ),
101 'filter' => array(
102 'handler' => 'views_handler_filter_string',
103 ),
104 'sort' => array(
105 'handler' => 'views_handler_sort',
106 ),
107 'argument' => array(
108 'handler' => 'views_handler_argument_string',
109 ),
110 );
111
112 // homepage
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."),
116 'field' => array(
117 'handler' => 'views_handler_field_url',
118 'click sortable' => TRUE,
119 ),
120 'filter' => array(
121 'handler' => 'views_handler_filter_string',
122 ),
123 'sort' => array(
124 'handler' => 'views_handler_sort',
125 ),
126 'argument' => array(
127 'handler' => 'views_handler_argument_string',
128 ),
129 );
130
131 // hostname
132 $data['comments']['hostname'] = array(
133 'title' => t('Hostname'),
134 'help' => t('Hostname of user that posted the comment.'),
135 'field' => array(
136 'handler' => 'views_handler_field',
137 'click sortable' => TRUE,
138 ),
139 'filter' => array(
140 'handler' => 'views_handler_filter_string',
141 ),
142 'sort' => array(
143 'handler' => 'views_handler_sort',
144 ),
145 'argument' => array(
146 'handler' => 'views_handler_argument_string',
147 ),
148 );
149
150 // mail
151 $data['comments']['mail'] = array(
152 'title' => t('Mail'),
153 'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
154 'field' => array(
155 'handler' => 'views_handler_field',
156 'click sortable' => TRUE,
157 ),
158 'filter' => array(
159 'handler' => 'views_handler_filter_string',
160 ),
161 'sort' => array(
162 'handler' => 'views_handler_sort',
163 ),
164 'argument' => array(
165 'handler' => 'views_handler_argument_string',
166 ),
167 );
168
169 // timestamp (when comment was posted)
170 $data['comments']['timestamp'] = array(
171 'title' => t('Post date'),
172 'help' => t('Date and time of when the comment was posted.'),
173 'field' => array(
174 'handler' => 'views_handler_field_date',
175 'click sortable' => TRUE,
176 ),
177 'sort' => array(
178 'handler' => 'views_handler_sort_date',
179 ),
180 'filter' => array(
181 'handler' => 'views_handler_filter_date',
182 ),
183 );
184
185 // status (approved or not)
186 $data['comments']['status'] = array(
187 'title' => t('In moderation'),
188 'help' => t('Whether or not the comment is currently in moderation.'),
189 'field' => array(
190 'handler' => 'views_handler_field_boolean',
191 'click sortable' => TRUE,
192 ),
193 'filter' => array(
194 'handler' => 'views_handler_filter_boolean_operator',
195 'label' => t('Moderated'),
196 'type' => 'yes-no',
197 ),
198 'sort' => array(
199 'handler' => 'views_handler_sort',
200 ),
201 );
202
203 // link to view comment
204 $data['comments']['view_comment'] = array(
205 'field' => array(
206 'title' => t('View link'),
207 'help' => t('Provide a simple link to view the comment.'),
208 'handler' => 'views_handler_field_comment_link',
209 ),
210 );
211
212 // link to edit comment
213 $data['comments']['edit_comment'] = array(
214 'field' => array(
215 'title' => t('Edit link'),
216 'help' => t('Provide a simple link to edit the comment.'),
217 'handler' => 'views_handler_field_comment_link_edit',
218 ),
219 );
220
221 // link to delete comment
222 $data['comments']['delete_comment'] = array(
223 'field' => array(
224 'title' => t('Delete link'),
225 'help' => t('Provide a simple link to delete the comment.'),
226 'handler' => 'views_handler_field_comment_link_delete',
227 ),
228 );
229
230 // link to reply to comment
231 $data['comments']['replyto_comment'] = array(
232 'field' => array(
233 'title' => t('Reply-to link'),
234 'help' => t('Provide a simple link to reply to the comment.'),
235 'handler' => 'views_handler_field_comment_link_reply',
236 ),
237 );
238
239 $data['comments']['node_link'] = array(
240 'field' => array(
241 'title' => t('Node link'),
242 'help' => t('Display the standard comment link used on regular nodes.'),
243 'handler' => 'views_handler_field_comment_node_link',
244 ),
245 );
246
247 $data['comments']['thread'] = array(
248 'field' => array(
249 'title' => t('Depth'),
250 'help' => t('Display the depth of the comment if it is threaded.'),
251 'handler' => 'views_handler_field_comment_depth',
252 ),
253 'sort' => array(
254 'title' => t('Thread'),
255 'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
256 'handler' => 'views_handler_sort_comment_thread',
257 ),
258 );
259
260 $data['comments']['nid'] = array(
261 'title' => t('Node'),
262 'help' => t('The node the comment is a reply to.'),
263 'relationship' => array(
264 'base' => 'node',
265 'field' => 'nid',
266 'handler' => 'views_handler_relationship',
267 'label' => t('Node'),
268 ),
269 );
270
271 $data['comments']['uid'] = array(
272 'title' => t('User'),
273 'help' => t("The User ID of the comment's author."),
274 'relationship' => array(
275 'base' => 'users',
276 'field' => 'uid',
277 'handler' => 'views_handler_relationship',
278 'label' => t('User'),
279 ),
280 );
281
282 $data['comments']['pid'] = array(
283 'title' => t('Parent CID'),
284 'help' => t('The Comment ID of the parent comment.'),
285 'field' => array(
286 'handler' => 'views_handler_field',
287 ),
288 'relationship' => array(
289 'title' => t('Parent comment'),
290 'help' => t('The parent comment.'),
291 'base' => 'comments',
292 'field' => 'cid',
293 'handler' => 'views_handler_relationship',
294 'label' => t('Parent comment'),
295 ),
296 );
297
298 // ----------------------------------------------------------------------
299 // node_comment_statistics table
300
301 // define the group
302 $data['node_comment_statistics']['table']['group'] = t('Node');
303
304 // joins
305 $data['node_comment_statistics']['table']['join'] = array(
306 //...to the node table
307 'node' => array(
308 'type' => 'INNER',
309 'left_field' => 'nid',
310 'field' => 'nid',
311 ),
312 );
313
314 // last_comment_timestamp
315 $data['node_comment_statistics']['last_comment_timestamp'] = array(
316 'title' => t('Last comment time'),
317 'help' => t('Date and time of when the last comment was posted.'),
318 'field' => array(
319 'handler' => 'views_handler_field_date',
320 'click sortable' => TRUE,
321 ),
322 'sort' => array(
323 'handler' => 'views_handler_sort_date',
324 ),
325 'filter' => array(
326 'handler' => 'views_handler_filter_date',
327 ),
328 );
329
330 // last_comment_name (author's name)
331 $data['node_comment_statistics']['last_comment_name'] = array(
332 'title' => t("Last comment author"),
333 'help' => t('The name of the author of the last posted comment.'),
334 'field' => array(
335 'handler' => 'views_handler_field_ncs_last_comment_name',
336 'click sortable' => TRUE,
337 ),
338 'sort' => array(
339 'handler' => 'views_handler_sort_ncs_last_comment_name',
340 ),
341 );
342
343 // comment_count
344 $data['node_comment_statistics']['comment_count'] = array(
345 'title' => t('Comment count'),
346 'help' => t('The number of comments a node has.'),
347 'field' => array(
348 'handler' => 'views_handler_field_numeric',
349 'click sortable' => TRUE,
350 ),
351 'filter' => array(
352 'handler' => 'views_handler_filter_numeric',
353 ),
354 'sort' => array(
355 'handler' => 'views_handler_sort',
356 ),
357 'argument' => array(
358 'handler' => 'views_handler_argument',
359 ),
360 );
361
362 // last_comment_timestamp
363 $data['node_comment_statistics']['last_updated'] = array(
364 'title' => t('Updated/commented date'),
365 'help' => t('The most recent of last comment posted or node updated time.'),
366 'field' => array(
367 'handler' => 'views_handler_field_ncs_last_updated',
368 'click sortable' => TRUE,
369 ),
370 'sort' => array(
371 'handler' => 'views_handler_sort_ncs_last_updated',
372 ),
373 'filter' => array(
374 'handler' => 'views_handler_filter_ncs_last_updated',
375 ),
376 );
377
378 return $data;
379 }
380
381 /**
382 * Use views_data_alter to add items to the node table that are
383 * relevant to comments.
384 */
385 function comment_views_data_alter(&$data) {
386 // new comments
387 $data['node']['new_comments'] = array(
388 'title' => t('New comments'),
389 'help' => t('The number of new comments on the node.'),
390 'field' => array(
391 'handler' => 'views_handler_field_node_new_comments',
392 ),
393 );
394
395 // Comment status of the node
396 $data['node']['comment'] = array(
397 'title' => t('Comment status'),
398 'help' => t('Whether comments are enabled or disabled on the node.'),
399 'field' => array(
400 'handler' => 'views_handler_field_node_comment',
401 'click sortable' => TRUE,
402 ),
403 'sort' => array(
404 'handler' => 'views_handler_sort',
405 ),
406 'filter' => array(
407 'handler' => 'views_handler_filter_node_comment',
408 ),
409 );
410
411 $data['node']['uid_touch'] = array(
412 'title' => t('User posted or commented'),
413 'help' => t('Display nodes only if a user posted the node or commented on the node.'),
414 'argument' => array(
415 'field' => 'uid',
416 'name table' => 'users',
417 'name field' => 'name',
418 'handler' => 'views_handler_argument_comment_user_uid',
419 ),
420 'filter' => array(
421 'field' => 'uid',
422 'name table' => 'users',
423 'name field' => 'name',
424 'handler' => 'views_handler_filter_comment_user_uid'
425 ),
426 );
427
428 }
429
430 /**
431 * Implementation of hook_views_plugins
432 */
433 function comment_views_plugins() {
434 return array(
435 'module' => 'views', // This just tells views our themes are in Views.
436 'row' => array(
437 'comment' => array(
438 'title' => t('Comment'),
439 'help' => t('Display the comment with standard comment view.'),
440 'handler' => 'views_plugin_row_comment_view',
441 'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
442 'theme' => 'views_view_row_comment',
443 'base' => array('comments'), // only works with 'comment' as base.
444 'uses options' => TRUE,
445 'type' => 'normal',
446 'help topic' => 'style-comment',
447 ),
448 'comment_rss' => array(
449 'title' => t('Comment'),
450 'help' => t('Display the comment as RSS.'),
451 'handler' => 'views_plugin_row_comment_rss',
452 'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
453 'theme' => 'views_view_row_rss',
454 'base' => array('comments'), // only works with 'comment' as base.
455 'type' => 'feed',
456 'help topic' => 'style-comment-rss',
457 ),
458 ),
459 );
460 }
461
462 /**
463 * Implementation of hook_views_handlers() to register all of the basic handlers
464 * views uses.
465 */
466 function comment_views_handlers() {
467 return array(
468 'info' => array(
469 'path' => drupal_get_path('module', 'views') . '/modules/comment',
470 ),
471 'handlers' => array(
472 'views_handler_field_comment' => array(
473 'parent' => 'views_handler_field',
474 ),
475 'views_handler_field_comment_username' => array(
476 'parent' => 'views_handler_field',
477 ),
478 'views_handler_field_comment_depth' => array(
479 'parent' => 'views_handler_field',
480 ),
481 'views_handler_field_comment_link' => array(
482 'parent' => 'views_handler_field',
483 ),
484 'views_handler_field_comment_link_edit' => array(
485 'parent' => 'views_handler_field_comment_link',
486 ),
487 'views_handler_field_comment_link_delete' => array(
488 'parent' => 'views_handler_field_comment_link',
489 ),
490 'views_handler_field_comment_link_reply' => array(
491 'parent' => 'views_handler_field_comment_link',
492 ),
493 'views_handler_field_comment_node_link' => array(
494 'parent' => 'views_handler_field',
495 ),
496 'views_handler_field_ncs_last_comment_name' => array(
497 'parent' => 'views_handler_field',
498 ),
499 'views_handler_field_ncs_last_updated' => array(
500 'parent' => 'views_handler_field_date',
501 ),
502 'views_handler_field_node_new_comments' => array(
503 'parent' => 'views_handler_field_numeric',
504 ),
505 'views_handler_field_node_comment' => array(
506 'parent' => 'views_handler_field',
507 ),
508
509 // sort handlers
510 'views_handler_sort_comment_thread' => array(
511 'parent' => 'views_handler_sort',
512 ),
513 'views_handler_sort_ncs_last_comment_name' => array(
514 'parent' => 'views_handler_sort',
515 ),
516 'views_handler_sort_ncs_last_updated' => array(
517 'parent' => 'views_handler_sort_date',
518 ),
519
520 // filter handlers
521 'views_handler_filter_ncs_last_updated' => array(
522 'parent' => 'views_handler_filter_date',
523 ),
524 'views_handler_filter_node_comment' => array(
525 'parent' => 'views_handler_filter_in_operator',
526 ),
527 'views_handler_filter_comment_user_uid' => array(
528 'parent' => 'views_handler_filter_user_name',
529 ),
530
531 // argument handlers
532 'views_handler_argument_comment_user_uid' => array(
533 'parent' => 'views_handler_argument',
534 ),
535 ),
536 );
537 }
538
539 /**
540 * Template helper for theme_views_view_row_comment
541 */
542 function template_preprocess_views_view_row_comment(&$vars) {
543 $options = $vars['options'];
544 $view = &$vars['view'];
545 $plugin = &$view->style_plugin->row_plugin;
546 $comment = $plugin->comments[$vars['row']->cid];
547 $node = node_load($comment->nid);
548 // Put the view on the node so we can retrieve it in the preprocess.
549 $node->view = &$view;
550
551 $links = '';
552 if (!empty($options['links'])) {
553 $links = module_invoke_all('link', 'comment', $comment, 0);
554 drupal_alter('link', $links, $node);
555 }
556
557 $vars['comment'] = theme('comment_view', $comment, $node, $links);
558 }
559
560 /**
561 * @}
562 */

  ViewVC Help
Powered by ViewVC 1.1.2