Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function comment_node_hide_menu_alter(&$items) {
- $items['comment/reply/%node'] = array(
- 'title' => 'Reply to comment',
- 'page callback' => 'comment_node_hide_reply',
- 'page arguments' => array(2),
- 'access callback' => 'node_access',
- 'access arguments' => array('view', 2),
- 'type' => MENU_CALLBACK
- );
- dsm($items);
- }
- function comment_node_hide_reply($node, $pid = NULL) {
- // Set the breadcrumb trail.
- drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' . $node->nid)));
- $op = isset($_POST['op']) ? $_POST['op'] : '';
- $output = '';
- if (user_access('access comments')) {
- // The user is previewing a comment prior to submitting it.
- if ($op == t('Preview')) {
- if (user_access('post comments')) {
- $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL);
- }
- else {
- drupal_set_message(t('You are not authorized to post comments.'), 'error');
- drupal_goto("node/$node->nid");
- }
- }
- else {
- // $pid indicates that this is a reply to a comment.
- if ($pid) {
- // load the comment whose cid = $pid
- 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))) {
- // If that comment exists, make sure that the current comment and the parent comment both
- // belong to the same parent node.
- if ($comment->nid != $node->nid) {
- // Attempting to reply to a comment not belonging to the current nid.
- drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
- drupal_goto("node/$node->nid");
- }
- // Display the parent comment
- $comment = drupal_unpack($comment);
- $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
- $output .= theme('comment_view', $comment, $node);
- }
- else {
- drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
- drupal_goto("node/$node->nid");
- }
- }
- // This is the case where the comment is in response to a node. Display the node.
- else if (user_access('access content')) {
- }
- // Should we show the reply box?
- if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
- drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
- drupal_goto("node/$node->nid");
- }
- else if (user_access('post comments')) {
- $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply'));
- }
- else {
- drupal_set_message(t('You are not authorized to post comments.'), 'error');
- drupal_goto("node/$node->nid");
- }
- }
- }
- else {
- drupal_set_message(t('You are not authorized to view comments.'), 'error');
- drupal_goto("node/$node->nid");
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement