// // This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. // // To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ // // or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. // // Francais (brouillon): http://creativecommons.org/projects/international/fr/translated-license // ////////////////////////////////////////////////////////////////////////////////////////////////////// // Filtres de texte // v0.1.0 class filtres { var $err = array( "stop" => "oui", "log" => "oui", "debug" => "oui"); var $types = array( "replace" => "Remplacement"); // Pour la détection du langage SMS, pourcentage de mots SMS autorisés dans un texte // avant la signification du texte en "langage SMS" var $sms_percent = 10; // Mots du langage SMS // (inspiré de trouvailles sur skyblogs ;o) var $sms_words = array("bjr","slt","kif","pcq","pkoi","pk","dc","ac","copin","c","kop1","bo","ché", "ya","foto","fotos","lol","mdr","ct","sui","ke","koi","kan","mm","jvé","jai","komen","vré","ki", "2m1","asv","bsr","ayé","cad","càd","keske","stp","qd","rdv","tjs","tjr","bcp","meuf","ct","msg", "pb","kkun","kk1","tt","fo","kune","ele","el","kil","pa","assé","pouré","ben","vs","ny","avai", "dechire","grave","po","koa","cho","otres","otre","ptit","pti","tro","jparle","voi","posible","ds", "moa","fè","bô","arf","acht","tit","ptin","j'ador","jador","hihi","poskeuh","zentil","jle","jui", "jsui","pis","vala","tits","ouej","keum","loul","tlm","alor","gt","tou","pe","ko","kon","kun"); var $sms = array("found_words"=>array(),"found_percentage"=>0); // Gestion des erreurs function _err($err,$debug="") { // Si le debug est activé if($this->err[debug] == "oui" && !empty($debug)) $err.= "\n// DEBUG //\n".$debug; // Si on log les erreurs if($this->err[log] == "oui") $this->erreurs[] = $err; // Si on s'arrête sur les erreurs if($this->err[stop] == "oui") { echo "
".htmlentities(stripslashes($err))."
"; exit; } $this->erreur = $err; return FALSE; } // Supprime les caractères bizarres laissés par Word et autres traitements de textes function kill_word($texte) { $unicode = array( "–" => "-", "—" => "-", "‘" => "'", "‚"=>",", "ƒ"=>"f", "„" => '"', "„" => '"', "„"=>'...', "…"=>"...", "ˆ"=>"^", "ˆ" => '^', "ˆ"=>"'", "‹"=>"'", "Œ"=>"OE", "Œ"=>"OE", "‘"=>"'", "‘"=>"'", "’"=>"'", "’"=>"'", "“"=>'"', "“"=>'"', "”"=>'"', "”"=>'"', "”"=>"-", "”"=>"-", "–"=>"-", "–"=>"-", "—"=>"--", "—"=>"--", " "=>" ", "<"=>"<", ">"=>">"); $texte = strtr($texte,$unicode); return trim($texte); } // Détection de langage SMS // ------------------------ // Si pourcentage de langage SMS autorisé dépassé dans le texte, renvoie TRUE, sinon FALSE. // Le pourcentage de langage trouvé est stocké dans $this->sms['found_percentage'] // Les mots SMS trouvés sont stockés dans $this->sms['found_words'] // Un mot SMS du dictionnaire = 3 points // Un mot contenant des chiffres = 2 points // Un mot de 1 caractère = 1 point function is_sms($texte) { $this->sms = array('found_words' => array(), 'found_percentage' => 0); $texte = ereg_replace("[._:/,;?!'\n\r\t-]"," ",$texte); $texte = ereg_replace("[ ]{2,}"," ",$texte); $texte = strip_tags($texte); $texte = trim($texte); $texte = explode(" ",$texte); $sms_count = 0; foreach($texte as $mot) { if(!eregi("^[a-z0-9]+$",$mot)) continue; if(in_array(strtolower($mot),$this->sms_words)) { $sms_count += 3; $this->sms['found_words'][] = $mot; } elseif(eregi("[0-9]+",$mot)) $sms_count += 2; elseif(strlen($mot) == 1) $sms_count++; } $sms_count = ($sms_count / 3); $this->sms['found_percentage'] = round(($sms_count / count($texte)) * 100,1); if($this->sms['found_percentage'] >= $this->sms_percent) return TRUE; return FALSE; } function add($journal,$type,$auto=FALSE,$opts="") { if(!array_key_exists($type,$this->types)) return FALSE; if(is_array($opts)) $opts = addslashes(serialize($opts)); if($auto == TRUE) $auto = "oui"; else $auto = "non"; $requete = 'INSERT INTO filtres SET journal="'.$journal.'", type="'.$type.'", auto="'.$auto.'", opts="'.$opts.'"'; $res = mysql_query($requete); $id = mysql_insert_id(); mysql_free_result($res); return $id; } function liste($journal) { $requete = 'SELECT * FROM filtres WHERE journal="'.$journal.'"'; $res = mysql_query($requete); $out = array(); while($rec = mysql_fetch_assoc($res)) $out[] = $rec; mysql_free_result($res); return $out; } } ?>