You are here

function theme_spam_link in Spam 5

Display spam status (if enabled), and provide adminsitrators with links to mark content as spam or not spam.

Parameters

$content comment or node object:

$type comment or node:

1 theme call to theme_spam_link()
spam_link in ./spam.module
Drupal _link hook. Adds themable spam related links to content if enabled.

File

./spam.module, line 1474

Code

function theme_spam_link($content, $type = 'comment') {
  $output = array();
  if ($type == 'comment' && variable_get('spam_filter_comments', 1)) {
    $id = $content->cid;
  }
  else {
    if ($type == 'node' && variable_get("spam_filter_{$content->type}", 0)) {
      $id = $content->nid;
    }
    else {
      return $output;
    }
  }
  $p = db_fetch_object(db_query("SELECT probability FROM {spam_tracker} WHERE id = %d AND source = '%s'", $id, $type));
  $spam = array(
    'href' => "spam/{$type}/{$id}/spam",
    'title' => t('mark as spam'),
  );
  $notspam = array(
    'href' => "spam/{$type}/{$id}/notspam",
    'title' => t('mark as not spam'),
  );
  $access = user_access('access spam');
  $report = user_access('report spam');
  $admin = user_access('administer spam');
  $display = variable_get('spam_display_probability', 0);
  if (variable_get('spam_log_level', SPAM_LOG)) {
    $display_text = " (" . l($p->probability, "admin/content/spam/logs/{$type}/{$id}") . ")";
  }
  else {
    $display_text = " ({$p->probability})";
  }
  if (!$p->probability && $admin) {
    $output['spam-spam'] = $spam;
    $output['spam-notspam'] = $notspam;
  }
  else {
    if ($p->probability < variable_get('spam_threshold', 80)) {
      if ($access) {
        $output['spam-probability'] = array(
          'title' => t('not spam') . ($display ? $display_text : ''),
          'html' => TRUE,
        );
      }
      if ($admin) {
        $output['spam-spam'] = $spam;
      }
    }
    else {
      if ($access) {
        $output['spam-probability'] = array(
          'title' => t('spam') . ($display ? $display_text : ''),
          'html' => TRUE,
        );
      }
      if ($admin) {
        $output['spam-notspam'] = $notspam;
      }
    }
  }
  if ($report) {
    $output['spam-report'] = array(
      'href' => "spam/report/{$type}/{$id}",
      "title" => t('report spam'),
    );
  }
  return $output;
}