I need to check spam in CCK fields but spam module allow to check only title and body

So i made a little dirty hack to allow spam filters works with CCK fields

I just modified spam_get_text() function in spam.module

function spam_get_text($content, $type, $fields, $extra = array(), $full = TRUE) {
  if (is_object($content)) {
    $content = (array)$content;
  }

  /*Dirty hack to concatenate all cck fields into body*/
  if ($type == 'node') {
      foreach($content as $field => $value) {
          if (strpos($field, 'field_') === 0) {
              $content['body'] .= ' '. $value[0]['value'];
          }
      }
  }

  $text = '';

  foreach ($fields['main'] as $field) {
    $text .= $content[$field] .' ';
  }
  if ($full && is_array($fields['other'])) {
    foreach ($fields['other'] as $field) {
      $text .= $content[$field] .' ';
    }
  }
  return $text;
}

I understand that this solution is not very good - but it works for me

Comments

AlexisWilke’s picture

Yes. We'd need to add a content/spam_content_cck.inc file that would take care of the CCK fields.

Your fix would imply that everyone has CCK installed.

Thank you for posting it though. That's a good start for CCK support.
Alexis Wilke

Eugene Fidelin’s picture

Yes my solution imply that everyone has CCK installed and also it doesn't work with multivalued CCK fields, thought it is very easy to fix

function spam_get_text($content, $type, $fields, $extra = array(), $full = TRUE) {
  if (is_object($content)) {
    $content = (array)$content;
  }

  /*Dirty hack to concatenate all cck fields into body*/
  if (($type == 'node') && module_exists('cck')) {
      foreach($content as $field => $value) {
          if (strpos($field, 'field_') === 0) {
              for ($i=0; $i<sizeof($value); $i++) {
                  //check multivalued fields
                  $content['body'] .= ' '. $value[$i]['value'];
              }
          }
      }
  }

  $text = '';

  foreach ($fields['main'] as $field) {
    $text .= $content[$field] .' ';
  }
  if ($full && is_array($fields['other'])) {
    foreach ($fields['other'] as $field) {
      $text .= $content[$field] .' ';
    }
  }
  return $text;
}
apaderno’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

I am closing this issue, since it's for a Drupal version no longer supported.