PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/modules/views/modules/comment.views.inc

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