[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/comment/ -> comment.pages.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * User page callbacks for the comment module.
   6   */
   7  
   8  /**
   9   * Form builder; generate a comment editing form.
  10   *
  11   * @param $cid
  12   *   ID of the comment to be edited.
  13   * @ingroup forms
  14   */
  15  function comment_edit($cid) {
  16    global $user;
  17  
  18    $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid));
  19    $comment = drupal_unpack($comment);
  20    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
  21    if (comment_access('edit', $comment)) {
  22      return comment_form_box((array)$comment);
  23    }
  24    else {
  25      drupal_access_denied();
  26    }
  27  }
  28  
  29  /**
  30   * This function is responsible for generating a comment reply form.
  31   * There are several cases that have to be handled, including:
  32   *   - replies to comments
  33   *   - replies to nodes
  34   *   - attempts to reply to nodes that can no longer accept comments
  35   *   - respecting access permissions ('access comments', 'post comments', etc.)
  36   *
  37   * The node or comment that is being replied to must appear above the comment
  38   * form to provide the user context while authoring the comment.
  39   *
  40   * @param $node
  41   *   Every comment belongs to a node. This is that node.
  42   *
  43   * @param $pid
  44   *   Some comments are replies to other comments. In those cases, $pid is the parent
  45   *   comment's cid.
  46   *
  47   * @return
  48   *   The rendered parent node or comment plus the new comment form.
  49   */
  50  function comment_reply($node, $pid = NULL) {
  51    // Set the breadcrumb trail.
  52    drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid)));
  53    $op = isset($_POST['op']) ? $_POST['op'] : '';
  54  
  55    $output = '';
  56  
  57    if (user_access('access comments')) {
  58      // The user is previewing a comment prior to submitting it.
  59      if ($op == t('Preview')) {
  60        if (user_access('post comments')) {
  61          $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL);
  62        }
  63        else {
  64          drupal_set_message(t('You are not authorized to post comments.'), 'error');
  65          drupal_goto("node/$node->nid");
  66        }
  67      }
  68      else {
  69        // $pid indicates that this is a reply to a comment.
  70        if ($pid) {
  71          // load the comment whose cid = $pid
  72          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))) {
  73            // If that comment exists, make sure that the current comment and the parent comment both
  74            // belong to the same parent node.
  75            if ($comment->nid != $node->nid) {
  76              // Attempting to reply to a comment not belonging to the current nid.
  77              drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
  78              drupal_goto("node/$node->nid");
  79            }
  80            // Display the parent comment
  81            $comment = drupal_unpack($comment);
  82            $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
  83            $output .= theme('comment_view', $comment, $node);
  84          }
  85          else {
  86            drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
  87            drupal_goto("node/$node->nid");
  88          }
  89        }
  90        // This is the case where the comment is in response to a node. Display the node.
  91        else if (user_access('access content')) {
  92          $output .= node_view($node);
  93        }
  94  
  95        // Should we show the reply box?
  96        if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
  97          drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
  98          drupal_goto("node/$node->nid");
  99        }
 100        else if (user_access('post comments')) {
 101          $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply'));
 102        }
 103        else {
 104          drupal_set_message(t('You are not authorized to post comments.'), 'error');
 105          drupal_goto("node/$node->nid");
 106        }
 107      }
 108    }
 109    else {
 110      drupal_set_message(t('You are not authorized to view comments.'), 'error');
 111      drupal_goto("node/$node->nid");
 112    }
 113  
 114    return $output;
 115  }


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