[ Index ] |
|
Code source de SPIP 1.8.3 |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2005 * 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 14 // 15 // Ce fichier ne sera execute qu'une fois 16 if (defined("_ECRIRE_INC_MOTS")) return; 17 define("_ECRIRE_INC_MOTS", "1"); 18 19 include_ecrire ("inc_filtres.php3"); # pour http_script (normalement déjà fait) 20 21 22 // ne pas faire d'erreur si les chaines sont > 254 caracteres 23 function levenshtein255 ($a, $b) { 24 $a = substr($a, 0, 254); 25 $b = substr($b, 0, 254); 26 return @levenshtein($a,$b); 27 } 28 29 // reduit un mot a sa valeur translitteree et en minuscules 30 function reduire_mot($mot) { 31 return strtr( 32 translitteration(trim($mot)), 33 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 34 'abcdefghijklmnopqrstuvwxyz' 35 ); 36 } 37 38 function mots_ressemblants($mot, $table_mots, $table_ids='') { 39 $lim = 2; 40 $nb = 0; 41 $opt = 1000000; 42 $mot_opt = ''; 43 $mot = reduire_mot($mot); 44 $len = strlen($mot); 45 46 if (!$table_mots) return ''; 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 (!($m = $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 } 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 ''; 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 106 * specifie, plus le formulaire d'ajout de mot-cle 107 */ 108 109 function formulaire_mots($table, $id_objet, $nouv_mot, $supp_mot, $cherche_mot, $flag_editable) { 110 global $connect_statut, $options; 111 global $spip_lang_rtl, $spip_lang_right; 112 113 $select_groupe = $GLOBALS['select_groupe']; 114 115 if ($table == 'articles') { 116 $id_table = 'id_article'; 117 $objet = 'article'; 118 $url_base = "articles.php3?id_article=$id_objet"; 119 } 120 else if ($table == 'breves') { 121 $id_table = 'id_breve'; 122 $objet = 'breve'; 123 $url_base = "breves_voir.php3?id_breve=$id_objet"; 124 } 125 else if ($table == 'rubriques') { 126 $id_table = 'id_rubrique'; 127 $objet = 'rubrique'; 128 $url_base = "naviguer.php3?id_rubrique=$id_objet"; 129 } 130 131 else if ($table == 'syndic') { 132 $id_table = 'id_syndic'; 133 $objet = 'syndic'; 134 $url_base = "sites.php3?id_syndic=$id_objet"; 135 } 136 137 list($nombre_mots) = spip_fetch_array(spip_query("SELECT COUNT(*) FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$id_table=$id_objet AND mots.id_mot=lien.id_mot")); 138 139 if (!$nombre_mots) { 140 if (!$flag_editable) return; 141 list($nombre_groupes) = spip_fetch_array(spip_query("SELECT COUNT(*) FROM spip_groupes_mots WHERE $table = 'oui' 142 AND ".substr($connect_statut,1)." = 'oui'")); 143 144 if (!$nombre_groupes) return; 145 } 146 147 echo "<a name='mots'></a>"; 148 if ($flag_editable){ 149 if ($nouv_mot.$cherche_mot.$supp_mot) 150 $bouton = bouton_block_visible("lesmots"); 151 else 152 $bouton = bouton_block_invisible("lesmots"); 153 } 154 debut_cadre_enfonce("mot-cle-24.gif", false, "", $bouton._T('titre_mots_cles').aide ("artmots")); 155 156 ////////////////////////////////////////////////////// 157 // Recherche de mot-cle 158 // 159 160 if ($nouv_mot) 161 $nouveaux_mots[] = $nouv_mot; 162 163 $tous_les_mots = split(" *[,;] *", $cherche_mot); 164 while ((list(,$cherche_mot) = each ($tous_les_mots)) AND $cherche_mot) { 165 echo "<P ALIGN='left'>"; 166 $query = "SELECT id_mot, titre FROM spip_mots WHERE id_groupe='$select_groupe'"; 167 $result = spip_query($query); 168 unset($table_mots); 169 unset($table_ids); 170 while ($row = spip_fetch_array($result)) { 171 $table_ids[] = $row['id_mot']; 172 $table_mots[] = $row['titre']; 173 } 174 $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids); 175 debut_boite_info(); 176 if (!$resultat) { 177 echo "<B>"._T('info_non_resultat', array('cherche_mot' => $cherche_mot))."</B><BR>"; 178 } 179 else if (count($resultat) == 1) { 180 list(, $nouv_mot) = each($resultat); 181 $nouveaux_mots[] = $nouv_mot; 182 echo "<B>"._T('info_mot_cle_ajoute')." "; 183 if ($table == 'articles') echo _T('info_l_article'); 184 else if ($table == 'breves') echo _T('info_la_breve'); 185 else if ($table == 'rubriques') echo _T('info_la_rubrique'); 186 echo " : </B><BR>"; 187 $query = "SELECT * FROM spip_mots WHERE id_mot=$nouv_mot"; 188 $result = spip_query($query); 189 echo "<UL>"; 190 while ($row = spip_fetch_array($result)) { 191 $id_mot = $row['id_mot']; 192 $titre_mot = $row['titre']; 193 $type_mot = typo($row['type']); 194 $descriptif_mot = $row['descriptif']; 195 196 echo "<LI><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=2><B><FONT SIZE=3>".typo($titre_mot)."</FONT></B>"; 197 echo "</FONT>\n"; 198 } 199 echo "</UL>"; 200 } 201 else { 202 reset($resultat); 203 unset($les_mots); 204 while (list(, $id_mot) = each($resultat) 205 AND $nombre ++ < 17) 206 $les_mots[] = $id_mot; 207 if ($les_mots) { 208 if (count($resultat) > 17) { 209 echo "<br /><b>"._T('info_trop_resultat', array('cherche_mot' => $cherche_mot))."</b><p />\n"; 210 } 211 $les_mots = join(',', $les_mots); 212 echo "<B>"._T('info_plusieurs_mots_trouves', array('cherche_mot' => $cherche_mot))."</B><BR>"; 213 $query = "SELECT * FROM spip_mots WHERE id_mot IN ($les_mots) ORDER BY titre"; 214 $result = spip_query($query); 215 echo "<UL>"; 216 while ($row = spip_fetch_array($result)) { 217 $id_mot = $row['id_mot']; 218 $titre_mot = $row['titre']; 219 $type_mot = typo($row['type']); 220 $descriptif_mot = $row['descriptif']; 221 222 echo "<LI><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=2><B><FONT SIZE=3>".typo($titre_mot)."</FONT></B>"; 223 224 if ($type_mot) echo " ($type_mot)"; 225 echo " | <A HREF=\"$url_base&nouv_mot=$id_mot#mots\">"._T('info_ajouter_mot')."</A>"; 226 227 if (strlen($descriptif_mot) > 1) { 228 echo "<BR><FONT SIZE=1>".propre(couper($descriptif_mot, 100))."</FONT>\n"; 229 } 230 echo "</FONT><p>\n"; 231 } 232 echo "</UL>"; 233 } 234 } 235 236 if ($GLOBALS['connect_statut'] == '0minirezo') { 237 echo "<div style='width: 200px;'>"; 238 $retour = urlencode($GLOBALS['clean_link']->getUrl()); 239 $titre = urlencode($cherche_mot); 240 icone_horizontale(_T('icone_creer_mot_cle'), "mots_edit.php3?new=oui&ajouter_id_article=$id_objet&table=$table&id_table=$id_table&titre=$titre&redirect=$retour", "mot-cle-24.gif", "creer.gif"); 241 echo "</div> "; 242 } 243 244 fin_boite_info(); 245 echo "<P>"; 246 247 } 248 249 250 ////////////////////////////////////////////////////// 251 // Appliquer les modifications sur les mots-cles 252 // 253 254 if ($nouveaux_mots && $flag_editable) { 255 while ((list(,$nouv_mot) = each($nouveaux_mots)) AND $nouv_mot!='x') { 256 $query = "SELECT * FROM spip_mots_$table WHERE id_mot=$nouv_mot AND $id_table=$id_objet"; 257 $result = spip_query($query); 258 if (!spip_num_rows($result)) { 259 $query = "INSERT INTO spip_mots_$table (id_mot,$id_table) VALUES ($nouv_mot, $id_objet)"; 260 $result = spip_query($query); 261 } 262 } 263 $reindexer = true; 264 } 265 266 if ($supp_mot && $flag_editable) { 267 if ($supp_mot == -1) 268 $mots_supp = ""; 269 else 270 $mots_supp = " AND id_mot=$supp_mot"; 271 $query = "DELETE FROM spip_mots_$table WHERE $id_table=$id_objet $mots_supp"; 272 $result = spip_query($query); 273 $reindexer = true; 274 } 275 276 277 if ($reindexer AND lire_meta('activer_moteur') == 'oui') { 278 include_ecrire ("inc_index.php3"); 279 marquer_indexer($objet, $id_objet); 280 } 281 282 // 283 // Afficher les mots-cles 284 // 285 286 $query = "SELECT DISTINCT type FROM spip_mots"; 287 $result = spip_query($query); 288 $plusieurs_types = (spip_num_rows($result) > 1); 289 290 unset($les_mots); 291 292 $query = "SELECT mots.* FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$id_table=$id_objet AND mots.id_mot=lien.id_mot ORDER BY mots.type, mots.titre"; 293 $result = spip_query($query); 294 295 if (spip_num_rows($result) > 0) { 296 echo "<div class='liste'>"; 297 echo "<table width='100%' cellpadding='3' cellspacing='0' border='0' background=''>"; 298 299 $ifond=0; 300 301 $tableau= ''; 302 while ($row = spip_fetch_array($result)) { 303 $vals = ''; 304 305 $id_mot = $row['id_mot']; 306 $titre_mot = $row['titre']; 307 $descriptif_mot = $row['descriptif']; 308 $id_groupe = $row['id_groupe']; 309 $query_groupe = "SELECT * FROM spip_groupes_mots WHERE id_groupe = $id_groupe"; 310 $result_groupe = spip_query($query_groupe); 311 while($row_groupe = spip_fetch_array($result_groupe)) { 312 $id_groupe = $row_groupe['id_groupe']; 313 $titre_groupe = entites_html($row_groupe['titre']); 314 // On recupere le typo_mot ici, et non dans le mot-cle lui-meme; sinon bug avec arabe 315 $type_mot = typo($row_groupe['titre']); 316 $unseul = $row_groupe['unseul']; 317 $obligatoire = $row_groupe['obligatoire']; 318 $acces_admin = $row_groupe['minirezo']; 319 $acces_redacteur = $row_groupe['comite']; 320 321 $flag_groupe = ($flag_editable AND (($connect_statut == '1comite' AND $acces_redacteur == 'oui') OR ($connect_statut == '0minirezo' AND $acces_admin == 'oui'))); 322 } 323 324 $groupes_vus[$id_groupe] = true; 325 $id_groupes_vus[] = $id_groupe; 326 327 if ($ifond==0){ 328 $ifond=1; 329 $couleur="#FFFFFF"; 330 }else{ 331 $ifond=0; 332 $couleur="#EDF3FE"; 333 } 334 335 $url = "mots_edit.php3?id_mot=$id_mot&redirect=".rawurlencode($url_base.'#mots'); 336 337 $vals[] = "<A HREF='$url'>" . http_img_pack('petite-cle.gif', "", "width='23' height='12' border='0'") ."</A>"; 338 339 340 // Changer 341 if ($unseul == "oui" AND $flag_groupe) { 342 $s = "<form action='$url_base#mots' method='post' style='margin:0px; padding: 0px'>"; 343 $s .= "<INPUT TYPE='Hidden' NAME='$id_table' VALUE='$id_objet'>"; 344 if ($table == 'rubriques') $s .= "<INPUT TYPE='Hidden' NAME='id_rubrique' VALUE='$id_objet'>"; 345 $s .= "<select name='nouv_mot' onChange=\"setvisibility('valider_groupe_$id_groupe', 'visible');\" CLASS='fondl' STYLE='font-size:10px; width:90px;'>"; 346 347 $query_autres_mots = "SELECT * FROM spip_mots WHERE id_groupe = $id_groupe ORDER by titre"; 348 $result_autres_mots = spip_query($query_autres_mots); 349 while ($row_autres = spip_fetch_array($result_autres_mots)) { 350 $le_mot = $row_autres['id_mot']; 351 $le_titre_mot = supprimer_tags(typo($row_autres['titre'])); 352 353 if ($le_mot == $id_mot) $selected = "SELECTED"; 354 else $selected = ""; 355 $s .= "<option value='$le_mot' $selected> $le_titre_mot"; 356 } 357 $s .= "</select>"; 358 $s .= "<INPUT TYPE='Hidden' NAME='supp_mot' VALUE='$id_mot'>"; 359 $s .= "<span class='visible_au_chargement' id='valider_groupe_$id_groupe'>"; 360 $s .= " <INPUT TYPE='submit' NAME='Choisir' VALUE='"._T('bouton_changer')."' CLASS='fondo' style='font-size: 10px';>"; 361 $s .= "</span>"; 362 $s .= "</form>"; 363 364 } else { 365 $s = "<A HREF='$url'>".typo($titre_mot)."</A>"; 366 } 367 $vals[] = $s; 368 369 $vals[] = "$type_mot"; 370 371 if ($flag_editable){ 372 $s = ""; 373 if ($flag_groupe) 374 $s .= "<A HREF=\"$url_base&supp_mot=$id_mot#mots\">"._T('info_retirer_mot')." " . http_img_pack('croix-rouge.gif', "X", "width='7' height='7' border='0' align='middle'") ."</A>"; 375 else $s .= " "; 376 } 377 $vals[] = $s; 378 379 $tableau[] = $vals; 380 381 $les_mots[] = $id_mot; 382 } 383 384 $largeurs = array('25', '', '', ''); 385 $styles = array('arial11', 'arial2', 'arial2', 'arial1'); 386 afficher_liste($largeurs, $tableau, $styles); 387 388 389 echo "</table></div>"; 390 } 391 392 if ($les_mots) { 393 $nombre_mots_associes = count($les_mots); 394 $les_mots = join($les_mots, ","); 395 } else { 396 $les_mots = "0"; 397 } 398 if ($id_groupes_vus) $id_groupes_vus = join($id_groupes_vus, ","); 399 else $id_groupes_vus = "0"; 400 401 $query_groupes = "SELECT * FROM spip_groupes_mots WHERE $table = 'oui' 402 AND ".substr($connect_statut,1)." = 'oui' AND obligatoire = 'oui' 403 AND id_groupe NOT IN ($id_groupes_vus)"; 404 $nb_groupes = spip_num_rows(spip_query($query_groupes)); 405 406 // 407 // Afficher le formulaire d'ajout de mots-cles 408 // 409 410 if ($flag_editable) { 411 if ($nouveaux_mots.$cherche_mot.$supp_mot) 412 echo debut_block_visible("lesmots"); 413 else if ($nb_groupes > 0) { 414 echo debut_block_visible("lesmots"); 415 // vilain hack pour redresser un triangle 416 $couche_a_redresser = $GLOBALS['numero_block']['lesmots']; 417 if ($GLOBALS['browser_layer']) echo http_script(" 418 triangle = findObj('triangle' + $couche_a_redresser); 419 if (triangle) triangle.src = '" . _DIR_IMG_PACK . "deplierbas$spip_lang_rtl.gif';"); 420 } 421 else 422 echo debut_block_invisible("lesmots"); 423 424 if ($nombre_mots_associes > 3) { 425 echo "<div align='right' class='arial1'>"; 426 echo "<a href=\"$url_base&supp_mot=-1#mots\">"._T('info_retirer_mots')."</a>"; 427 echo "</div><br />\n"; 428 } 429 430 431 $form_mot = "<FORM ACTION='$url_base#mots' METHOD='post' STYLE='margin:1px;'>" 432 ."<INPUT TYPE='Hidden' NAME='$id_table' VALUE='$id_objet'>"; 433 434 if ($table == 'rubriques') $form_mot .= "<INPUT TYPE='Hidden' NAME='id_rubrique' VALUE='$id_objet'>"; 435 436 $message_ajouter_mot = "<span class='verdana1'><B>"._T('titre_ajouter_mot_cle')."</B></span> \n"; 437 438 echo "<table border='0' width='100%' style='text-align: $spip_lang_right'>"; 439 440 $query_groupes = "SELECT *, ".creer_objet_multi ("titre", "$spip_lang")." FROM spip_groupes_mots WHERE $table = 'oui' 441 AND ".substr($connect_statut,1)." = 'oui' AND (unseul != 'oui' OR 442 (unseul = 'oui' AND id_groupe NOT IN ($id_groupes_vus))) 443 ORDER BY multi"; 444 $result_groupes = spip_query($query_groupes); 445 446 // Afficher un menu par groupe de mots 447 448 449 while ($row_groupes = spip_fetch_array($result_groupes)) { 450 $id_groupe = $row_groupes['id_groupe']; 451 $titre_groupe = entites_html(textebrut(typo($row_groupes['titre']))); 452 $unseul = $row_groupes['unseul']; 453 $obligatoire = $row_groupes['obligatoire']; 454 $articles = $row_groupes['articles']; 455 $breves = $row_groupes['breves']; 456 $rubriques = $row_groupes['rubriques']; 457 $syndic = $row_groupes['syndic']; 458 $acces_minirezo = $row_groupes['minirezo']; 459 $acces_comite = $row_groupes['comite']; 460 $acces_forum = $row_groupes['forum']; 461 462 $query = "SELECT * FROM spip_mots WHERE id_groupe = '$id_groupe' "; 463 if ($les_mots) $query .= "AND id_mot NOT IN ($les_mots) "; 464 $query .= "ORDER BY type, titre"; 465 $result = spip_query($query); 466 if (spip_num_rows($result) > 0) { 467 if ((spip_num_rows($result) > 50)) { 468 echo "\n<tr>"; 469 echo $form_mot; 470 echo "\n<td>"; 471 echo $message_ajouter_mot; 472 $message_ajouter_mot = ""; 473 echo "</td>\n<td>"; 474 $jscript = "onfocus=\"setvisibility('valider_groupe_$id_groupe', 'visible'); if(!antifocus_mots[$id_groupe]){this.value='';antifocus_mots[$id_groupe]=true;}\""; 475 476 if ($obligatoire == "oui" AND !$groupes_vus[$id_groupe]) 477 echo "<INPUT TYPE='text' NAME='cherche_mot' CLASS='fondl' STYLE='width: 180px; background-color:#E86519;' VALUE=\"$titre_groupe\" SIZE='20' $jscript>"; 478 else if ($unseul == "oui") 479 echo "<INPUT TYPE='text' NAME='cherche_mot' CLASS='fondl' STYLE='width: 180px; background-color:#cccccc;' VALUE=\"$titre_groupe\" SIZE='20' $jscript>"; 480 else 481 echo "<INPUT TYPE='text' NAME='cherche_mot' CLASS='fondl' STYLE='width: 180px; ' VALUE=\"$titre_groupe\" SIZE='20' $jscript>"; 482 483 echo "</td>\n<td>"; 484 echo "<INPUT TYPE='hidden' NAME='select_groupe' VALUE='$id_groupe'>"; 485 486 echo "<span class='visible_au_chargement' id='valider_groupe_$id_groupe'>"; 487 echo " <INPUT TYPE='submit' NAME='Chercher' VALUE='"._T('bouton_chercher')."' CLASS='fondo' STYLE='font-size:10px'>"; 488 echo "</span>"; 489 echo "</td></FORM>"; 490 echo "</tr>"; 491 } 492 else { 493 echo "\n<tr>"; 494 echo $form_mot; 495 echo "\n<td>"; 496 echo $message_ajouter_mot; 497 $message_ajouter_mot = ""; 498 echo "</td>\n<td>"; 499 500 if ($obligatoire == "oui" AND !$groupes_vus[$id_groupe]) 501 echo "<SELECT NAME='nouv_mot' SIZE='1' onChange=\"setvisibility('valider_groupe_$id_groupe', 'visible');\" STYLE='width: 180px; background-color:#E86519;' CLASS='fondl'>"; 502 else if ($unseul == "oui") 503 echo "<SELECT NAME='nouv_mot' SIZE='1' onChange=\"setvisibility('valider_groupe_$id_groupe', 'visible');\" STYLE='width: 180px; background-color:#cccccc;' CLASS='fondl'>"; 504 else 505 echo "<SELECT NAME='nouv_mot' SIZE='1' onChange=\"setvisibility('valider_groupe_$id_groupe', 'visible');\" STYLE='width: 180px; ' CLASS='fondl'>"; 506 507 $ifond == 0; 508 echo "\n<option value='x' style='font-variant: small-caps;'>$titre_groupe</option>"; 509 while($row = spip_fetch_array($result)) { 510 $id_mot = $row['id_mot']; 511 $titre_mot = $row['titre']; 512 $texte_option = entites_html(textebrut(typo($titre_mot))); 513 echo "\n<OPTION VALUE=\"$id_mot\">"; 514 echo " "; 515 echo "$texte_option</option>"; 516 } 517 echo "</SELECT>"; 518 echo "</td>\n<td>"; 519 echo "<span class='visible_au_chargement' id='valider_groupe_$id_groupe'>"; 520 echo " <INPUT TYPE='submit' NAME='Choisir' VALUE='"._T('bouton_choisir')."' CLASS='fondo'>"; 521 echo "</span>"; 522 echo "</td></FORM>"; 523 echo "</tr>"; 524 } 525 } 526 } 527 528 if ($connect_statut == '0minirezo' AND $flag_editable AND $options == "avancees") { 529 echo "<tr><td></td><td colspan='2'>"; 530 echo "<div style='width: 200px;'>"; 531 $retour = urlencode($GLOBALS['clean_link']->getUrl()); 532 icone_horizontale(_T('icone_creer_mot_cle'), "mots_edit.php3?new=oui&ajouter_id_article=$id_objet&table=$table&id_table=$id_table&redirect=$retour", "mot-cle-24.gif", "creer.gif"); 533 echo "</div> "; 534 echo "</td></tr>"; 535 } 536 537 538 539 echo "</table>"; 540 echo fin_block(); 541 } 542 543 544 fin_cadre_enfonce(); 545 } 546 547 548 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Feb 22 22:27:47 2007 | par Balluche grâce à PHPXref 0.7 |