comment.views.inc

  1. cis7 sites/all/modules/ulmus/views/modules/comment.views.inc
  2. cle7 sites/all/modules/ulmus/views/modules/comment.views.inc
  3. ecd7 sites/all/modules/ulmus/views/modules/comment.views.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/modules/comment.views.inc
  5. harmony7 sites/all/modules/ulmus/views/modules/comment.views.inc
  6. icor7 sites/all/modules/ulmus/views/modules/comment.views.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/modules/comment.views.inc
  8. mooc7 sites/all/modules/ulmus/views/modules/comment.views.inc

Provide views data and handlers for comment.module.

Functions

Namesort descending Description
comment_views_data
comment_views_data_alter Use views_data_alter to add items to the node table that are relevant to comments.
comment_views_plugins Implements hook_views_plugins().
template_preprocess_views_view_row_comment Template helper for theme_views_view_row_comment

File

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

Related topics