X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;ds=sidebyside;f=www%2Fplugins%2Fauto%2Fcouteau_suisse%2Fcouteau_suisse%2Foutils%2Fspam.php;fp=www%2Fplugins%2Fauto%2Fcouteau_suisse%2Fcouteau_suisse%2Foutils%2Fspam.php;h=2c99d0146452292a90a5a317e292b311595521a3;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hp=0000000000000000000000000000000000000000;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c;p=velocampus%2Fweb%2Fwww.git diff --git a/www/plugins/auto/couteau_suisse/couteau_suisse/outils/spam.php b/www/plugins/auto/couteau_suisse/couteau_suisse/outils/spam.php new file mode 100644 index 0000000..2c99d01 --- /dev/null +++ b/www/plugins/auto/couteau_suisse/couteau_suisse/outils/spam.php @@ -0,0 +1,61 @@ +', '[url=', '[/url]', '[link=', '[/link]',), + // des regexpr ou ips (sans delimiteurs) + array(), array(), array() + ); + // repere les mots entiers entre parentheses, les regexpr entre slashes et les caracteres unicodes + $spam_mots = defined('_spam_MOTS')?spam_liste_mots(_spam_MOTS):array(); + foreach($spam_mots as $v) { + if(preg_match(',^\((.+)\)$,', $v, $reg)) + $t[1][] = '\b'.preg_quote($reg[1], '/').'\b'; + elseif(preg_match(',^\/(&#)?(.*?)(;?)\/$,', $v, $reg)) + $t[($reg[2] && $reg[3])?2:1][]=$reg[2]; + else $t[0][] = $v; + } + $t[1] = count($t[1])?'/'.join('|',$t[1]).'/i':''; + $t[2] = count($t[2])?'/&#(?:'.join('|',$t[2]).');/i':''; + $spam_mots = defined('_spam_IPS')?spam_liste_mots(_spam_IPS):array(); + array_walk($spam_mots, 'spam_walk'); + $t[3] = count($spam_mots)?'/^(?:' . join('|', $spam_mots) . ')$/':''; + return array($t); +} + +function spam_walk(&$item) { + $item = preg_replace(',[^\d\.\*\?\[\]\-],', '', $item); + if(preg_match(',^\/(.+)\/$,', $item, $reg)) + $item = '('.$reg[1].')'; + else $item = str_replace(array('\*','\?','\[','\]','\-'), array('\d+','\d','[',']','-'), preg_quote($item, '/')); +} + +// retourne un tableau de mots ou d'expressions a partir d'un texte +function spam_liste_mots($texte) { + include_spip('inc/filtres'); + $texte = filtrer_entites(trim($texte)); + $split = explode('"', $texte); + $c = count($split); + $split2 = array(); + for($i=0; $i<$c; $i++) if (($s = trim($split[$i])) != ""){ + if (($i & 1) && ($i != $c-1)) { + // on touche pas au texte entre deux "" + $split2[] = $s; + } else { + // on rassemble tous les separateurs : \s\t\n + $temp = preg_replace("/[\s\t\n\r]+/", "\t", $s); + $temp = str_replace("+"," ", $temp); + $split2 = array_merge($split2, explode("\t", $temp)); + } + } + return array_unique($split2); +} + +?> \ No newline at end of file