~pwolanin/+junk/AD-pressflow-6

« back to all changes in this revision

Viewing changes to modules/acquia/views/modules/comment.views.inc

  • Committer: Peter Wolanin
  • Date: 2009-09-17 21:56:51 UTC
  • Revision ID: pwolanin@curie.local-20090917215651-jm4azy7ee79zx5bz
   Acquia Drupal 1.2.16 (Drupal 6.14 core) has just been released and
   contains important security updates and bug fixes. We recommend that
   you update to the new version as soon as possible.
    1. Please reference the [1]Getting Started Guide for information about
       updating your site.
    2. Next, [2]download the new version.

   Acquia Drupal consists of Acquia's package of Drupal core with a
   curated set of contributed modules, plus the ability to connect to the
   Acquia Network. 
   Acquia Drupal 1.2.16 (Drupal 6.14 core) includes the
   following updates: 
   ===================================================
     * Updated Drupal core to version [3]6.14. This also fixes a multiple
       security issues described in [4]DRUPAL-SA-CORE-2009-008.
     * Updated the Date module to [5]6.x-2.4. This also fixes a Cross Site
       Scripting security issue described in
       [6]DRUPAL-SA-CONTRIB-2009-057.
     * Added the jquery_ui module, version [7]6.x-1.3. This fixes a
       warning that appears on the status page if you have the date_popup
       module enabled.
     * Updated the Content Construction Kit (CCK) module to [8]6.x-2.5.
     * Updated the Image module to [9]6.x-1.0-beta3.
     * Updated the Mollom module to [10]6.x-1.10.
     * Updated the Voting API module to [11]6.x-2.3.

References

   1. http://acquia.com/documentation/getting-started/introduction
   2. http://acquia.com/downloads
   3. http://drupal.org/node/579476
   4. http://drupal.org/node/579482
   5. http://drupal.org/node/579000
   6. http://drupal.org/node/579144
   7. http://drupal.org/node/497608
   8. http://drupal.org/node/539128
   9. http://drupal.org/node/575958
  10. http://drupal.org/node/551398
  11. http://drupal.org/node/550092

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  // 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.'),
 
135
    'field' => array(
 
136
      'handler' => 'views_handler_field_date',
 
137
      'click sortable' => TRUE,
 
138
    ),
 
139
    'sort' => array(
 
140
      'handler' => 'views_handler_sort_date',
 
141
    ),
 
142
    'filter' => array(
 
143
      'handler' => 'views_handler_filter_date',
 
144
    ),
 
145
  );
 
146
 
 
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.'),
 
151
    'field' => array(
 
152
      'handler' => 'views_handler_field_boolean',
 
153
      'click sortable' => TRUE,
 
154
    ),
 
155
    'filter' => array(
 
156
      'handler' => 'views_handler_filter_boolean_operator',
 
157
      'label' => t('Moderated'),
 
158
      'type' => 'yes-no',
 
159
    ),
 
160
    'sort' => array(
 
161
      'handler' => 'views_handler_sort',
 
162
    ),
 
163
  );
 
164
 
 
165
  // link to view comment
 
166
  $data['comments']['view_comment'] = array(
 
167
    'field' => array(
 
168
      'title' => t('View link'),
 
169
      'help' => t('Provide a simple link to view the comment.'),
 
170
      'handler' => 'views_handler_field_comment_link',
 
171
    ),
 
172
  );
 
173
 
 
174
  // link to edit comment
 
175
  $data['comments']['edit_comment'] = array(
 
176
    'field' => 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',
 
180
    ),
 
181
  );
 
182
 
 
183
  // link to delete comment
 
184
  $data['comments']['delete_comment'] = array(
 
185
    'field' => 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',
 
189
    ),
 
190
  );
 
191
 
 
192
  // link to reply to comment
 
193
  $data['comments']['replyto_comment'] = array(
 
194
    'field' => 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',
 
198
    ),
 
199
  );
 
200
 
 
201
  $data['comments']['node_link'] = array(
 
202
    'field' => 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',
 
206
    ),
 
207
  );  
 
208
 
 
209
  $data['comments']['thread'] = array(
 
210
    'field' => 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',
 
214
    ),
 
215
    'sort' => array(
 
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',
 
219
    ),
 
220
  );
 
221
 
 
222
  $data['comments']['nid'] = array(
 
223
    'title' => t('Node'),
 
224
    'help' => t('The node the comment is a reply to.'),
 
225
    'relationship' => array(
 
226
      'base' => 'node',
 
227
      'field' => 'nid',
 
228
      'handler' => 'views_handler_relationship',
 
229
      'label' => t('Node'),
 
230
    ),
 
231
  );
 
232
 
 
233
  $data['comments']['uid'] = array(
 
234
    'title' => t('User'),
 
235
    'help' => t("The User ID of the comment's author."),
 
236
    'relationship' => array(
 
237
      'base' => 'users',
 
238
      'field' => 'uid',
 
239
      'handler' => 'views_handler_relationship',
 
240
      'label' => t('User'),
 
241
    ),
 
242
  );
 
243
 
 
244
  $data['comments']['pid'] = array(
 
245
    'title' => t('Parent CID'),
 
246
    'help' => t('The Comment ID of the parent comment.'),
 
247
    'field' => array(
 
248
      'handler' => 'views_handler_field',
 
249
    ),
 
250
    'relationship' => array(
 
251
      'title' => t('Parent comment'),
 
252
      'help' => t('The parent comment.'),
 
253
      'base' => 'comments',
 
254
      'field' => 'cid',
 
255
      'handler' => 'views_handler_relationship',
 
256
      'label' => t('Parent comment'),
 
257
    ),
 
258
  );
 
259
 
 
260
  // ----------------------------------------------------------------------
 
261
  // node_comment_statistics table
 
262
 
 
263
  // define the group
 
264
  $data['node_comment_statistics']['table']['group']  = t('Node');
 
265
 
 
266
  // joins
 
267
  $data['node_comment_statistics']['table']['join'] = array(
 
268
    //...to the node table
 
269
    'node' => array(
 
270
      'type' => 'INNER',      
 
271
      'left_field' => 'nid',
 
272
      'field' => 'nid',
 
273
     ),
 
274
  );
 
275
 
 
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.'),
 
280
    'field' => array(
 
281
      'handler' => 'views_handler_field_date',
 
282
      'click sortable' => TRUE,
 
283
    ),
 
284
    'sort' => array(
 
285
      'handler' => 'views_handler_sort_date',
 
286
    ),
 
287
    'filter' => array(
 
288
      'handler' => 'views_handler_filter_date',
 
289
    ),
 
290
  );
 
291
 
 
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.'),
 
296
    'field' => array(
 
297
      'handler' => 'views_handler_field_ncs_last_comment_name',
 
298
      'click sortable' => TRUE,
 
299
    ),
 
300
    'sort' => array(
 
301
      'handler' => 'views_handler_sort_ncs_last_comment_name',
 
302
    ),
 
303
  );
 
304
 
 
305
  // comment_count
 
306
  $data['node_comment_statistics']['comment_count'] = array(
 
307
    'title' => t('Comment count'),
 
308
    'help' => t('The number of comments a node has.'),
 
309
    'field' => array(
 
310
      'handler' => 'views_handler_field_numeric',
 
311
      'click sortable' => TRUE,
 
312
    ),
 
313
    'filter' => array(
 
314
      'handler' => 'views_handler_filter_numeric',
 
315
    ),
 
316
    'sort' => array(
 
317
      'handler' => 'views_handler_sort',
 
318
    ),
 
319
    'argument' => array(
 
320
      'handler' => 'views_handler_argument',
 
321
    ),
 
322
  );
 
323
 
 
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.'),
 
328
    'field' => array(
 
329
      'handler' => 'views_handler_field_ncs_last_updated',
 
330
      'click sortable' => TRUE,
 
331
    ),
 
332
    'sort' => array(
 
333
      'handler' => 'views_handler_sort_ncs_last_updated',
 
334
    ),
 
335
    'filter' => array(
 
336
      'handler' => 'views_handler_filter_ncs_last_updated',
 
337
    ),
 
338
  );
 
339
 
 
340
  return $data;
 
341
}
 
342
 
 
343
/**
 
344
 * Use views_data_alter to add items to the node table that are
 
345
 * relevant to comments.
 
346
 */
 
347
function comment_views_data_alter(&$data) {
 
348
  // new comments
 
349
  $data['node']['new_comments'] = array(
 
350
    'title' => t('New comments'),
 
351
    'help' => t('The number of new comments on the node.'),
 
352
    'field' => array(
 
353
      'handler' => 'views_handler_field_node_new_comments',
 
354
    ),
 
355
  );
 
356
 
 
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.'),
 
361
    'field' => array(
 
362
      'handler' => 'views_handler_field_node_comment',
 
363
      'click sortable' => TRUE,
 
364
    ),
 
365
    'sort' => array(
 
366
      'handler' => 'views_handler_sort',
 
367
    ),
 
368
    'filter' => array(
 
369
      'handler' => 'views_handler_filter_node_comment',
 
370
    ),
 
371
  );
 
372
 
 
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.'),
 
376
    'argument' => array(
 
377
      'field' => 'uid',
 
378
      'name table' => 'users',
 
379
      'name field' => 'name',
 
380
      'handler' => 'views_handler_argument_comment_user_uid',
 
381
    ),
 
382
    'filter' => array(
 
383
      'field' => 'uid',
 
384
      'name table' => 'users',
 
385
      'name field' => 'name',
 
386
      'handler' => 'views_handler_filter_comment_user_uid'
 
387
    ),
 
388
  );
 
389
 
 
390
}
 
391
 
 
392
/**
 
393
 * Implementation of hook_views_plugins
 
394
 */
 
395
function comment_views_plugins() {
 
396
  return array(
 
397
    'module' => 'views', // This just tells views our themes are in Views.
 
398
    'row' => array(
 
399
      'comment' => array(
 
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,
 
407
        'type' => 'normal',
 
408
        'help topic' => 'style-comment',
 
409
      ),
 
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.
 
417
        'type' => 'feed',
 
418
        'help topic' => 'style-comment-rss',
 
419
      ),
 
420
    ),
 
421
  );
 
422
}
 
423
 
 
424
/**
 
425
 * Implementation of hook_views_handlers() to register all of the basic handlers
 
426
 * views uses.
 
427
 */
 
428
function comment_views_handlers() {
 
429
  return array(
 
430
    'info' => array(
 
431
      'path' => drupal_get_path('module', 'views') . '/modules/comment',
 
432
    ),
 
433
    'handlers' => array(
 
434
      'views_handler_field_comment' => array(
 
435
        'parent' => 'views_handler_field',
 
436
      ),
 
437
      'views_handler_field_comment_username' => array(
 
438
        'parent' => 'views_handler_field',
 
439
      ),
 
440
      'views_handler_field_comment_depth' => array(
 
441
        'parent' => 'views_handler_field',
 
442
      ),
 
443
      'views_handler_field_comment_link' => array(
 
444
        'parent' => 'views_handler_field',
 
445
      ),
 
446
      'views_handler_field_comment_link_edit' => array(
 
447
        'parent' => 'views_handler_field_comment_link',
 
448
      ),
 
449
      'views_handler_field_comment_link_delete' => array(
 
450
        'parent' => 'views_handler_field_comment_link',
 
451
      ),
 
452
      'views_handler_field_comment_link_reply' => array(
 
453
        'parent' => 'views_handler_field_comment_link',
 
454
      ),
 
455
      'views_handler_field_comment_node_link' => array(
 
456
       'parent' => 'views_handler_field',
 
457
      ),
 
458
      'views_handler_field_ncs_last_comment_name' => array(
 
459
        'parent' => 'views_handler_field',
 
460
      ),
 
461
      'views_handler_field_ncs_last_updated' => array(
 
462
        'parent' => 'views_handler_field_date',
 
463
      ),
 
464
      'views_handler_field_node_new_comments' => array(
 
465
        'parent' => 'views_handler_field_numeric',
 
466
      ),
 
467
      'views_handler_field_node_comment' => array(
 
468
        'parent' => 'views_handler_field',
 
469
      ),
 
470
 
 
471
      // sort handlers
 
472
      'views_handler_sort_comment_thread' => array(
 
473
        'parent' => 'views_handler_sort',
 
474
      ),
 
475
      'views_handler_sort_ncs_last_comment_name' => array(
 
476
        'parent' => 'views_handler_sort',
 
477
      ),
 
478
      'views_handler_sort_ncs_last_updated' => array(
 
479
        'parent' => 'views_handler_sort_date',
 
480
      ),
 
481
 
 
482
      // filter handlers
 
483
      'views_handler_filter_ncs_last_updated' => array(
 
484
        'parent' => 'views_handler_filter_date',
 
485
      ),
 
486
      'views_handler_filter_node_comment' => array(
 
487
        'parent' => 'views_handler_filter_in_operator',
 
488
      ),
 
489
      'views_handler_filter_comment_user_uid' => array(
 
490
        'parent' => 'views_handler_filter_user_name',
 
491
      ),
 
492
 
 
493
      // argument handlers
 
494
      'views_handler_argument_comment_user_uid' => array(
 
495
        'parent' => 'views_handler_argument',
 
496
      ),
 
497
    ),
 
498
  );
 
499
}
 
500
 
 
501
/**
 
502
 * Template helper for theme_views_view_row_comment
 
503
 */
 
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;
 
512
 
 
513
  $links = '';
 
514
  if (!empty($options['links'])) {
 
515
    $links = module_invoke_all('link', 'comment', $comment, 0);
 
516
    drupal_alter('link', $links, $node);
 
517
  }
 
518
 
 
519
  $vars['comment'] = theme('comment_view', $comment, $node, $links);
 
520
}
 
521
 
 
522
/**
 
523
 * @}
 
524
 */