| [ Index ] |
|
Code source de SPIP 1.9.2c |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2007 * 7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * 8 * * 9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * 10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * 11 \***************************************************************************/ 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 14 include_spip('inc/actions'); 15 16 // ne pas faire d'erreur si les chaines sont > 254 caracteres 17 // http://doc.spip.org/@levenshtein255 18 function levenshtein255 ($a, $b) { 19 $a = substr($a, 0, 254); 20 $b = substr($b, 0, 254); 21 return @levenshtein($a,$b); 22 } 23 24 // reduit un mot a sa valeur translitteree et en minuscules 25 // http://doc.spip.org/@reduire_mot 26 function reduire_mot($mot) { 27 return strtr( 28 translitteration(trim($mot)), 29 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 30 'abcdefghijklmnopqrstuvwxyz' 31 ); 32 } 33 34 // http://doc.spip.org/@mots_ressemblants 35 function mots_ressemblants($mot, $table_mots, $table_ids='') { 36 37 $result = array(); 38 39 if (!$table_mots) return $result; 40 41 $lim = 2; 42 $nb = 0; 43 $opt = 1000000; 44 $mot_opt = ''; 45 $mot = reduire_mot($mot); 46 $len = strlen($mot); 47 48 while (!$nb AND $lim < 10) { 49 reset($table_mots); 50 if ($table_ids) reset($table_ids); 51 while (list(, $val) = each($table_mots)) { 52 if ($table_ids) list(, $id) = each($table_ids); 53 else $id = $val; 54 $val2 = trim($val); 55 if ($val2) { 56 if (!isset($distance[$id])) { 57 $val2 = reduire_mot($val2); 58 $len2 = strlen($val2); 59 if ($val2 == $mot) 60 $m = -2; # resultat exact 61 else if (substr($val2, 0, $len) == $mot) 62 $m = -1; # sous-chaine 63 else { 64 # distance 65 $m = levenshtein255($val2, $mot); 66 # ne pas compter la distance due a la longueur 67 $m -= max(0, $len2 - $len); 68 } 69 $distance[$id] = $m; 70 } else $m = 0; 71 if ($m <= $lim) { 72 $selection[$id] = $m; 73 if ($m < $opt) { 74 $opt = $m; 75 $mot_opt = $val; 76 } 77 $nb++; 78 } 79 } 80 } 81 $lim += 2; 82 } 83 84 if (!$nb) return $result; 85 reset($selection); 86 if ($opt > -1) { 87 $moy = 1; 88 while(list(, $val) = each($selection)) $moy *= $val; 89 if($moy) $moy = pow($moy, 1.0/$nb); 90 $lim = ($opt + $moy) / 2; 91 } 92 else $lim = -1; 93 94 reset($selection); 95 while (list($key, $val) = each($selection)) { 96 if ($val <= $lim) { 97 $result[] = $key; 98 } 99 } 100 return $result; 101 } 102 103 104 /* 105 * Affiche la liste des mots-cles associes a l'objet specifie 106 * plus le formulaire d'ajout de mot-cle 107 */ 108 109 // http://doc.spip.org/@affiche_mots_ressemblant 110 function affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base) 111 { 112 $les_mots = join(',', $resultat); 113 $result = spip_query("SELECT * FROM spip_mots WHERE id_mot IN ($les_mots) ORDER BY titre LIMIT 17"); 114 115 $res ="<ul>\n"; 116 while ($row = spip_fetch_array($result)) { 117 $id_mot = $row['id_mot']; 118 $titre_mot = $row['titre']; 119 $type_mot = typo($row['type']); 120 $descriptif_mot = $row['descriptif']; 121 122 $res .="<li>" 123 . ajax_action_auteur('editer_mot', "$id_objet,,$table,$table_id,$objet,$id_mot", $url_base, "$table_id=$id_objet", array(typo($titre_mot),' title="' . _T('info_ajouter_mot') .'"'),"&id_objet=$id_objet&objet=$objet") ; 124 if (strlen($descriptif_mot) > 1) { 125 $res .= "\n(<span class='spip_x-small'>".propre(couper($descriptif_mot, 100)).")</span><br />\n"; 126 } 127 $res .="</li>\n"; 128 } 129 $res .= "</ul>"; 130 131 if (count($resultat) > 17) 132 $res2 .="<br /><b>" ._T('info_trop_resultat', array('cherche_mot' => $cherche_mot)) ."</b><br />\n"; 133 134 $res2 = "<b>$type_mot</b> :" ._T('info_plusieurs_mots_trouves', array('cherche_mot' => $cherche_mot)) ."<br />"; 135 136 return $res2 . $res; 137 } 138 139 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 10:20:27 2007 | par Balluche grâce à PHPXref 0.7 |
|