You are here

function antispam_prepare_comment_data in AntiSpam 7

Same name and namespace in other branches
  1. 6 antispam.module \antispam_prepare_comment_data()

Prepare comment data for AntiSpam requests.

Parameters

string $content_type: Content type; it can be 'node' or 'comment' .

object $content: Content object.

integer $provider: ANTISPAM_AKISMET_SERVICE

Return value

array

3 calls to antispam_prepare_comment_data()
antispam_api_cmd_comment_check in ./antispam.module
AntiSpam API: Comment Check.
antispam_api_cmd_submit_ham in ./antispam.module
AntiSpam API: Submit Ham
antispam_api_cmd_submit_spam in ./antispam.module
AntiSpam API: Submit Spam

File

./antispam.module, line 2033
Primary hook implementations for the Antispam module.

Code

function antispam_prepare_comment_data($content_type, $content, $provider) {

  // Prepare data that is common to nodes/comments.
  global $user, $base_url;
  $comment_data = array(
    // IP address of the comment submitter.
    'user_ip' => !empty($content->hostname) ? $content->hostname : ip_address(),
    // User agent information of the comment submitter.
    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    // The content of the HTTP_REFERER header should be sent here.
    'referrer' => $_SERVER['HTTP_REFERER'],
    // May be blank, comment, trackback, pingback, or a made up value like
    // "registration".
    'comment_type' => '',
    // Submitted name with the comment.
    'comment_author' => $content->name,
  );
  if ($content_type == 'comment') {
    $comment_data['permalink'] = url('node/' . $content->nid, array(
      'fragment' => 'comment-' . $content->cid,
    ));
    $comment_data['comment_author_email'] = $content->mail;
    $comment_data['comment_author_url'] = $content->homepage;
    $comment_data['comment_content'] = render($content->comment_body[$content->language][0]['value']);

    // If the subject isn't the same as the comment body (which happens when no subject is entered),
    // add it to the beginning.
    if ($content->subject && $content->subject != $comment_data['comment_content']) {
      $comment_data['comment_content'] = $content->subject . "\n\n" . $comment_data['comment_content'];
    }
    $comment_data['comment_content'] = trim($comment_data['comment_content']);
  }
  elseif ($content_type == 'node') {
    $render = reset(entity_view('node', array(
      $content,
    )));
    $rendered = drupal_html_to_text(drupal_render($render), 'a');
    $comment_data['permalink'] = url('node/' . $content->nid);
    $comment_data['comment_author_email'] = isset($user->mail) ? $user->mail : '';
    $comment_data['comment_author_url'] = '';
    $comment_data['comment_content'] = $rendered;
  }
  else {
    $comment_data['permalink'] = '';
    $comment_data['comment-author_email'] = isset($user->mail) ? $user->mail : isset($content->mail) ? $content->mail : '';
    $comment_data['comment-author_url'] = isset($content->homepage) ? $content->homepage : '';
    $comment_data['comment_content'] = render($content->body);
  }
  return $comment_data;
}