comment_form_add_preview
modules/comment/comment.module, строка 1581
- Версии
- 5
comment_form_add_preview($form,
$edit)- 6
comment_form_add_preview($form, &$form_state)
Конструктор формы; Формирует и проверяет форму предпросмотра комментария.
Код
<?php
function comment_form_add_preview($form, $edit) {
global $user;
drupal_set_title(t('Preview comment'));
$output = '';
// Invoke full validation for the form, to protect against cross site
// request forgeries (CSRF) and setting arbitrary values for fields such as
// the input format. Preview the comment only when form validation does not
// set any errors.
drupal_validate_form($form['form_id']['#value'], $form);
if (!form_get_errors()) {
$comment = (object)_comment_form_submit($edit);
// Attach the user and time information.
if ($edit['author']) {
$account = user_load(array('name' => $edit['author']));
}
elseif ($user->uid && !isset($edit['is_anonymous'])) {
$account = $user;
}
if ($account) {
$comment->uid = $account->uid;
$comment->name = check_plain($account->name);
}
$comment->timestamp = $edit['timestamp'] ? $edit['timestamp'] : time();
$output .= theme('comment_view', $comment);
}
$form['comment_preview'] = array(
'#value' => $output,
'#weight' => -100,
'#prefix' => '<div class="preview">',
'#suffix' => '</div>',
);
$output = '';
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 = %d', $edit['pid'], COMMENT_PUBLISHED));
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$output .= theme('comment_view', $comment);
}
else {
$suffix = empty($form['#suffix']) ? '' : $form['#suffix'];
$form['#suffix'] = $suffix . node_view(node_load($edit['nid']));
$edit['pid'] = 0;
}
$form['comment_preview_below'] = array('#value' => $output, '#weight' => 100);
return $form;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии