e1571b09e38c5f58db192cacc29c7fbab3220106
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14 include_spip('inc/actions');
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);
24 // reduit un mot a sa valeur translitteree et en minuscules
25 // http://doc.spip.org/@reduire_mot
26 function reduire_mot($mot) {
28 translitteration(trim($mot)),
29 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
30 'abcdefghijklmnopqrstuvwxyz'
34 // http://doc.spip.org/@mots_ressemblants
35 function mots_ressemblants($mot, $table_mots, $table_ids='') {
39 if (!$table_mots) return $result;
45 $mot = reduire_mot($mot);
48 while (!$nb AND $lim < 10) {
50 if ($table_ids) reset($table_ids);
51 while (list(, $val) = each($table_mots)) {
52 if ($table_ids) list(, $id) = each($table_ids);
56 if (!isset($distance[$id])) {
57 $val2 = reduire_mot($val2);
58 $len2 = strlen($val2);
60 $m = -2; # resultat exact
61 else if (substr($val2, 0, $len) == $mot)
62 $m = -1; # sous-chaine
65 $m = levenshtein255($val2, $mot);
66 # ne pas compter la distance due a la longueur
67 $m -= max(0, $len2 - $len);
84 if (!$nb) return $result;
88 while(list(, $val) = each($selection)) $moy *= $val;
89 if($moy) $moy = pow($moy, 1.0/$nb);
90 $lim = ($opt +
$moy) / 2;
95 while (list($key, $val) = each($selection)) {
105 * Affiche la liste des mots-cles associes a l'objet specifie
106 * plus le formulaire d'ajout de mot-cle
109 // http://doc.spip.org/@affiche_mots_ressemblant
110 function affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base)
112 $les_mots = sql_in('id_mot', $resultat);
113 $res = sql_allfetsel("*", "spip_mots", $les_mots, "", "titre", "17");
115 foreach ($res as $k => $row) {
116 $id_mot = $row['id_mot'];
117 $titre = $row['titre'];
118 $type = typo($row['type']);
119 $descriptif = $row['descriptif'];
121 $res[$k]= ajax_action_auteur('editer_mots', "$id_objet,,$table,$table_id,$objet,$id_mot", $url_base, "$table_id=$id_objet", array(typo($titre),' title="' . _T('info_ajouter_mot') .'"'),"&id_objet=$id_objet&objet=$objet") .
122 (!$descriptif ?
'' : ("\n(<span class='spip_xx-small'>".supprimer_tags(couper(propre($descriptif), 100)).")</span><br />\n"));
127 ?
"<strong>$type</strong> : "
129 . _T('info_plusieurs_mots_trouves', array('cherche_mot' => $cherche_mot))
132 if (count($resultat) > 17)
133 $res2 .= "<br /><strong>" ._T('info_trop_resultat', array('cherche_mot' => $cherche_mot)) ."</strong><br />\n";
135 return $res2 . '<ul><li>' . join("</li>\n<li>", $res) . '</li></ul>';