comment_preview

Versions
4.6
comment_preview($edit)
7
comment_preview($comment)

Code

modules/comment.module, line 492

<?php
function comment_preview($edit) {
  global $user;

  $output = '';

  $comment = array2object($edit);

  // Attach the user and time information.
  $comment->uid = $user->uid;
  $comment->timestamp = time();
  $comment->name = check_plain($user->name ? $user->name : $comment->name);

  // Preview the comment if there were no errors, including the 'The supplied input format is invalid.'
  // error message, ie. this is a security check here.
  if (!form_get_errors()) {
    $output .= theme('comment_preview', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
  }
  $output .= theme('comment_form', $edit, t('Reply'));

  if ($edit['pid']) {
    $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0', $edit['pid']));
    $comment = drupal_unpack($comment);
    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
    $output .= theme('comment_view', $comment);
  }
  else {
    $output .= node_view(node_load(array('nid' => $edit['nid'])));
    $edit['pid'] = 0;
  }

  return $output;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.