You are here

protected function FeedsCommentProcessor::prepareCommentSubject in Feeds Comment Processor 7

Ensures that a comment subject exists and is valid.

Parameters

stdClass $comment: The comment.

1 call to FeedsCommentProcessor::prepareCommentSubject()
FeedsCommentProcessor::entityValidate in ./FeedsCommentProcessor.inc

File

./FeedsCommentProcessor.inc, line 392
Contains FeedsCommentProcessor.

Class

FeedsCommentProcessor
Creates comments from feed items.

Code

protected function prepareCommentSubject(stdClass $comment) {
  $comment->subject = truncate_utf8(trim(decode_entities(strip_tags($comment->subject))), 64, TRUE);
  if ($comment->subject !== '') {
    return;
  }

  // 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.
  $field = field_info_field('comment_body');
  $langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE;
  $comment_body = $comment->comment_body[$langcode][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 ($comment->subject === '') {
    $comment->subject = t('(No subject)');
  }
}