1 comment.module | comment_submit($comment) |
Prepare a comment for submission.
File
- core/
modules/ comment/ comment.module, line 2090 - Enables users to comment on published content.
Code
function comment_submit($comment) {
if (empty($comment->date)) {
$comment->date = 'now';
}
$comment->created = strtotime($comment->date);
$comment->changed = REQUEST_TIME;
// If the comment was posted by a registered user, assign the author's ID.
// @todo Too fragile. Should be prepared and stored in comment_form() already.
if (!$comment->is_anonymous && !empty($comment->name) && ($account = user_load_by_name($comment->name))) {
$comment->uid = $account->uid;
}
// If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default.
if ($comment->is_anonymous && (!isset($comment->name) || $comment->name === '')) {
$comment->name = config_get('system.core', 'anonymous');
}
// Validate the comment's subject. If not specified, extract from comment body.
if (trim($comment->subject) == '') {
// The body may be in any format, so:
// 1) Filter it into HTML
// 2) Strip out all HTML tags
// 3) Convert entities back to plain-text.
$comment_text = '';
if (isset($comment->comment_body) && !empty($comment->comment_body[LANGUAGE_NONE][0])) {
$comment_body = $comment->comment_body[LANGUAGE_NONE][0];
if (isset($comment_body['format'])) {
$comment_text = check_markup($comment_body['value'], $comment_body['format']);
}
else {
$comment_text = check_plain($comment_body['value']);
}
}
$comment->subject = truncate_utf8(trim(decode_entities(strip_tags($comment_text))), 29, TRUE);
// Edge cases where the comment body is populated only by HTML tags will
// require a default subject.
if (trim($comment->subject) == '') {
$comment->subject = t('(No subject)');
}
}
return $comment;
}