Changeset 18394


Ignore:
Timestamp:
Oct 1, 2012, 4:40:07 PM (8 years ago)
Author:
mistic100
Message:

use preg_match, usually faster

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/comments_blacklist/include/functions.inc.php

    r18370 r18394  
    66  global $conf;
    77 
    8   if ($comment_action == $conf['comments_blacklist']['action'])
     8  if ( $comment_action==$conf['comments_blacklist']['action'] or $comment_action=='reject' )
    99  {
    1010    return $comment_action;
     
    1212 
    1313  $blacklist = file(COMM_BLACKLIST_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    14   $blacklist = array_map('strtolower', $blacklist);
    15   $content = ' '.strtolower($comm['content']).' ';
    16   $author = ' '.strtolower($comm['author']).' ';
     14  $blacklist = array_map(create_function('$w', 'return " ".preg_quote($w)." ";'), $blacklist);
     15  $blacklist = implode('|', $blacklist);
     16
     17  $content = str_replace(array("\r\n","\n"), ' ', $comm['content']);
    1718 
    18   foreach ($blacklist as $word)
     19  if ( preg_match('#('.$blacklist.')#i', ' '.$comm['author'].' ') or preg_match('#('.$blacklist.')#i', ' '.$content.' ') )
    1920  {
    20     $word = ' '.$word.' ';
    21     if ( strpos($content, $word)!==false or strpos($author, $word)!==false )
    22     {
    23       return $conf['comments_blacklist']['action'];
    24     }
     21    return $conf['comments_blacklist']['action'];
    2522  }
    2623 
Note: See TracChangeset for help on using the changeset viewer.