Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <?php
  2. function comment_node_hide_menu_alter(&$items) {
  3. $items['comment/reply/%node'] = array(
  4. 'title' => 'Reply to comment',
  5. 'page callback' => 'comment_node_hide_reply',
  6. 'page arguments' => array(2),
  7. 'access callback' => 'node_access',
  8. 'access arguments' => array('view', 2),
  9. 'type' => MENU_CALLBACK
  10. );
  11. dsm($items);
  12. }
  13.  
  14. function comment_node_hide_reply($node, $pid = NULL) {
  15. // Set the breadcrumb trail.
  16. drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' . $node->nid)));
  17. $op = isset($_POST['op']) ? $_POST['op'] : '';
  18.  
  19. $output = '';
  20.  
  21. if (user_access('access comments')) {
  22. // The user is previewing a comment prior to submitting it.
  23. if ($op == t('Preview')) {
  24. if (user_access('post comments')) {
  25. $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL);
  26. }
  27. else {
  28. drupal_set_message(t('You are not authorized to post comments.'), 'error');
  29. drupal_goto("node/$node->nid");
  30. }
  31. }
  32. else {
  33. // $pid indicates that this is a reply to a comment.
  34. if ($pid) {
  35. // load the comment whose cid = $pid
  36. if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $pid, COMMENT_PUBLISHED))) {
  37. // If that comment exists, make sure that the current comment and the parent comment both
  38. // belong to the same parent node.
  39. if ($comment->nid != $node->nid) {
  40. // Attempting to reply to a comment not belonging to the current nid.
  41. drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
  42. drupal_goto("node/$node->nid");
  43. }
  44. // Display the parent comment
  45. $comment = drupal_unpack($comment);
  46. $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
  47. $output .= theme('comment_view', $comment, $node);
  48. }
  49. else {
  50. drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
  51. drupal_goto("node/$node->nid");
  52. }
  53. }
  54. // This is the case where the comment is in response to a node. Display the node.
  55. else if (user_access('access content')) {
  56.  
  57. }
  58.  
  59. // Should we show the reply box?
  60. if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
  61. drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
  62. drupal_goto("node/$node->nid");
  63. }
  64. else if (user_access('post comments')) {
  65. $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply'));
  66. }
  67. else {
  68. drupal_set_message(t('You are not authorized to post comments.'), 'error');
  69. drupal_goto("node/$node->nid");
  70. }
  71. }
  72. }
  73. else {
  74. drupal_set_message(t('You are not authorized to view comments.'), 'error');
  75. drupal_goto("node/$node->nid");
  76. }
  77.  
  78. return $output;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement