[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views/modules/ -> comment.views.inc (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7