comment_submit

Versions
mediamosa-21
comment_submit($comment)

Prepare a comment for submission.

Parameters

$comment An associative array containing the comment data.

▾ 1 function calls comment_submit()

comment_form_submit_build_comment in modules/comment/comment.module
Build a comment by processing form values and prepare for a form rebuild.

Code

modules/comment/comment.module, line 2036

<?php
function comment_submit($comment) {
  $comment += array('subject' => '');
  if (empty($comment['date'])) {
    $comment['date'] = 'now';
  }

  $comment['created'] = strtotime($comment['date']);
  $comment['changed'] = REQUEST_TIME;

  if (!empty($comment['name']) && ($account = user_load_by_name($comment['name']))) {
    $comment['uid'] = $account->uid;
  }

  // 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['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment['comment_body'][LANGUAGE_NONE][0]['value'], $comment['comment_body'][LANGUAGE_NONE][0]['format'])))), 29, TRUE);
    // Edge cases where the comment body is populated only by HTML tags will
    // require a default subject.
    if ($comment['subject'] == '') {
      $comment['subject'] = t('(No subject)');
    }
  }
  return (object)$comment;
}
?>