function ajax_comment_preview in Ajax 6
Grabs comment preview. This function taken from comment_form_add_preview
Parameters
$form Assoc:
$form_state Assoc:
Return value
String
1 call to ajax_comment_preview()
- ajax_comment_ajax_validate_pass in plugins/
comment/ ajax_comment.module - Validation cleanup procedures
File
- plugins/
comment/ ajax_comment.module, line 69
Code
function ajax_comment_preview(&$form, &$form_state) {
global $user;
$edit = $form_state['values'];
$output = '';
$node = node_load($edit['nid']);
_comment_form_submit($edit);
$comment = (object) $edit;
// Attach the user and time information.
if (!empty($edit['author'])) {
$account = user_load(array(
'name' => $edit['author'],
));
}
elseif ($user->uid && !isset($edit['is_anonymous'])) {
$account = $user;
}
if (!empty($account)) {
$comment->uid = $account->uid;
$comment->name = check_plain($account->name);
}
elseif (empty($comment->name)) {
$comment->name = variable_get('anonymous', t('Anonymous'));
}
$comment->timestamp = !empty($edit['timestamp']) ? $edit['timestamp'] : time();
if ($edit['pid']) {
$comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, ' . 'u.signature, u.picture, u.data FROM {comments} c ' . 'INNER JOIN {users} u ON c.uid = u.uid ' . 'WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED));
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
}
else {
$suffix = empty($form['#suffix']) ? '' : $form['#suffix'];
$form['#suffix'] = $suffix . node_view($node);
$edit['pid'] = 0;
}
$output = '<div class="preview">';
$output .= theme('comment_view', $comment, $node);
$output .= '</div>';
return $output;
}