1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2006 * |
---|
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 | $p=explode(basename(_DIR_PLUGINS)."/",str_replace('\\','/',realpath(dirname(dirname(__FILE__))))); |
---|
15 | define('_DIR_PLUGIN_MOTS_PARTOUT',(_DIR_PLUGINS.end($p))); |
---|
16 | |
---|
17 | // ne pas faire d'erreur si les chaines sont > 254 caracteres |
---|
18 | // http://doc.spip.org/@levenshtein255 |
---|
19 | function levenshtein255 ($a, $b) { |
---|
20 | $a = substr($a, 0, 254); |
---|
21 | $b = substr($b, 0, 254); |
---|
22 | return @levenshtein($a,$b); |
---|
23 | } |
---|
24 | |
---|
25 | // reduit un mot a sa valeur translitteree et en minuscules |
---|
26 | // http://doc.spip.org/@reduire_mot |
---|
27 | function reduire_mot($mot) { |
---|
28 | return strtr( |
---|
29 | translitteration(trim($mot)), |
---|
30 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', |
---|
31 | 'abcdefghijklmnopqrstuvwxyz' |
---|
32 | ); |
---|
33 | } |
---|
34 | |
---|
35 | // http://doc.spip.org/@mots_ressemblants |
---|
36 | function mots_ressemblants($mot, $table_mots, $table_ids='') { |
---|
37 | $lim = 2; |
---|
38 | $nb = 0; |
---|
39 | $opt = 1000000; |
---|
40 | $mot_opt = ''; |
---|
41 | $mot = reduire_mot($mot); |
---|
42 | $len = strlen($mot); |
---|
43 | |
---|
44 | if (!$table_mots) return ''; |
---|
45 | |
---|
46 | while (!$nb AND $lim < 10) { |
---|
47 | reset($table_mots); |
---|
48 | if ($table_ids) reset($table_ids); |
---|
49 | while (list(, $val) = each($table_mots)) { |
---|
50 | if ($table_ids) list(, $id) = each($table_ids); |
---|
51 | else $id = $val; |
---|
52 | $val2 = trim($val); |
---|
53 | if ($val2) { |
---|
54 | if (!($m = $distance[$id])) { |
---|
55 | $val2 = reduire_mot($val2); |
---|
56 | $len2 = strlen($val2); |
---|
57 | if ($val2 == $mot) |
---|
58 | $m = -2; # resultat exact |
---|
59 | else if (substr($val2, 0, $len) == $mot) |
---|
60 | $m = -1; # sous-chaine |
---|
61 | else { |
---|
62 | # distance |
---|
63 | $m = levenshtein255($val2, $mot); |
---|
64 | # ne pas compter la distance due a la longueur |
---|
65 | $m -= max(0, $len2 - $len); |
---|
66 | } |
---|
67 | $distance[$id] = $m; |
---|
68 | } |
---|
69 | if ($m <= $lim) { |
---|
70 | $selection[$id] = $m; |
---|
71 | if ($m < $opt) { |
---|
72 | $opt = $m; |
---|
73 | $mot_opt = $val; |
---|
74 | } |
---|
75 | $nb++; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | $lim += 2; |
---|
80 | } |
---|
81 | |
---|
82 | if (!$nb) return ''; |
---|
83 | reset($selection); |
---|
84 | if ($opt > -1) { |
---|
85 | $moy = 1; |
---|
86 | while(list(, $val) = each($selection)) $moy *= $val; |
---|
87 | if($moy) $moy = pow($moy, 1.0/$nb); |
---|
88 | $lim = ($opt + $moy) / 2; |
---|
89 | } |
---|
90 | else $lim = -1; |
---|
91 | |
---|
92 | reset($selection); |
---|
93 | while (list($key, $val) = each($selection)) { |
---|
94 | if ($val <= $lim) { |
---|
95 | $result[] = $key; |
---|
96 | } |
---|
97 | } |
---|
98 | return $result; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | /* |
---|
103 | * Affiche la liste des mots-cles associes a l'objet specifie |
---|
104 | * plus le formulaire d'ajout de mot-cle |
---|
105 | */ |
---|
106 | |
---|
107 | // http://doc.spip.org/@formulaire_mots |
---|
108 | function formulaire_mots($objet, $id_objet, $cherche_mot, $select_groupe, $flag_editable) { |
---|
109 | global $connect_statut, $spip_lang_rtl, $spip_lang_right, $spip_lang; |
---|
110 | |
---|
111 | $visible = ($cherche_mot OR ($flag_editable === 'ajax')); |
---|
112 | # spip_log("fm '$cherche_mot' '$flag_editable' '$visible' '$select_groupe'"); |
---|
113 | |
---|
114 | /////////////////////////// |
---|
115 | // MODIFICATION |
---|
116 | /////////////////////////// |
---|
117 | //TODO : trouver mieux que ca pour charger les definitions ? |
---|
118 | global $choses_possibles; |
---|
119 | pipeline('header_prive', ''); |
---|
120 | include(_DIR_PLUGIN_MOTS_PARTOUT."/mots_partout_choses.php"); |
---|
121 | if ($objet == 'syndic') $table=$objet; |
---|
122 | else $table=$objet.'s'; |
---|
123 | if (isset($choses_possibles[$table])) { |
---|
124 | $table_id = $choses_possibles[$table]['id_chose']; |
---|
125 | if ($choses_possibles[$table]['objet']) $objet=$choses_possibles[$table]['objet']; |
---|
126 | else $objet = substr($table,0,-1); |
---|
127 | if ($choses_possibles[$table]['url_base']) $url_base=$choses_possibles[$table]['url_base']; |
---|
128 | else $url_base = $table; |
---|
129 | if (is_array($id_objet)){ |
---|
130 | foreach($id_objet as $key => $value) |
---|
131 | if ($key=='id_objet') $_id_objet=$id_objet['id_objet']; |
---|
132 | else $url_base.=$value; |
---|
133 | $id_objet=$_id_objet; |
---|
134 | } |
---|
135 | } |
---|
136 | /* |
---|
137 | /////////////////////////// |
---|
138 | if ($objet == 'article') { |
---|
139 | $table_id = 'id_article'; |
---|
140 | $table = 'articles'; |
---|
141 | $url_base = "articles"; |
---|
142 | } |
---|
143 | else if ($objet == 'breve') { |
---|
144 | $table_id = 'id_breve'; |
---|
145 | $table = 'breves'; |
---|
146 | $url_base = "breves_voir"; |
---|
147 | } |
---|
148 | else if ($objet == 'rubrique') { |
---|
149 | $table_id = 'id_rubrique'; |
---|
150 | $table = 'rubriques'; |
---|
151 | $url_base = "naviguer"; |
---|
152 | } |
---|
153 | |
---|
154 | else if ($objet == 'syndic') { |
---|
155 | $table_id = 'id_syndic'; |
---|
156 | $table = 'syndic'; |
---|
157 | $url_base = "sites"; |
---|
158 | } |
---|
159 | else {$table = $table_id = $objet = $url_base = '';} |
---|
160 | /////////////////////////// |
---|
161 | // MODIFICATION |
---|
162 | /////////////////////////// |
---|
163 | */ |
---|
164 | /////////////////////////// |
---|
165 | |
---|
166 | $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot")); |
---|
167 | |
---|
168 | if (!($nombre_mots = $cpt['n'])) { |
---|
169 | if (!$flag_editable) return; |
---|
170 | $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui'")); |
---|
171 | |
---|
172 | if (!$cpt['n']) return; |
---|
173 | } |
---|
174 | |
---|
175 | // |
---|
176 | // Preparer l'affichage |
---|
177 | // |
---|
178 | |
---|
179 | // La reponse |
---|
180 | $reponse = ''; |
---|
181 | if ($flag_editable AND $cherche_mot) { |
---|
182 | $reindexer = false; |
---|
183 | list($reponse, $nouveaux_mots) = recherche_mot_cle($cherche_mot, $select_groupe, $objet, $id_objet, $table, $table_id, $url_base); |
---|
184 | foreach($nouveaux_mots as $nouv_mot) { |
---|
185 | if ($nouv_mot!='x') { |
---|
186 | $reindexer |= inserer_mot("spip_mots_$table", $table_id, $id_objet, $nouv_mot); |
---|
187 | } |
---|
188 | } |
---|
189 | if ($reindexer AND ($GLOBALS['meta']['activer_moteur'] == 'oui')) { |
---|
190 | include_spip("inc/indexation"); |
---|
191 | marquer_indexer("spip_$table", $id_objet); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | $form = afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible); |
---|
196 | |
---|
197 | // Envoyer titre + div-id + formulaire + fin |
---|
198 | if ($flag_editable){ |
---|
199 | if ($visible) |
---|
200 | $bouton = bouton_block_visible("lesmots".$id_objet); |
---|
201 | else |
---|
202 | $bouton = bouton_block_invisible("lesmots".$id_objet); |
---|
203 | } else $bouton = ''; |
---|
204 | |
---|
205 | $bouton .= _T('titre_mots_cles').aide ("artmots"); |
---|
206 | |
---|
207 | $res = '<div> </div>' // place pour l'animation pendant Ajax |
---|
208 | . debut_cadre_enfonce("mot-cle-24.gif", true, "", $bouton) |
---|
209 | . $reponse |
---|
210 | . $form |
---|
211 | . fin_cadre_enfonce(true); |
---|
212 | |
---|
213 | return ($flag_editable === 'ajax') |
---|
214 | ? $res |
---|
215 | : "\n<div id='editer_mot-$id_objet'>$res</div>"; |
---|
216 | } |
---|
217 | |
---|
218 | // http://doc.spip.org/@inserer_mot |
---|
219 | function inserer_mot($table, $table_id, $id_objet, $id_mot) |
---|
220 | { |
---|
221 | $result = spip_num_rows(spip_query("SELECT id_mot FROM $table WHERE id_mot=$id_mot AND $table_id=$id_objet")); |
---|
222 | |
---|
223 | if (!$result) { |
---|
224 | spip_query("INSERT INTO $table (id_mot,$table_id) VALUES ($id_mot, $id_objet)"); |
---|
225 | } |
---|
226 | return $result; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | // http://doc.spip.org/@affiche_mots_ressemblant |
---|
231 | function affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base) |
---|
232 | { |
---|
233 | $les_mots = join(',', $resultat); |
---|
234 | $result = spip_query("SELECT * FROM spip_mots WHERE id_mot IN ($les_mots) ORDER BY titre LIMIT 17"); |
---|
235 | |
---|
236 | $res ="<ul>\n"; |
---|
237 | while ($row = spip_fetch_array($result)) { |
---|
238 | $id_mot = $row['id_mot']; |
---|
239 | $titre_mot = $row['titre']; |
---|
240 | $type_mot = typo($row['type']); |
---|
241 | $descriptif_mot = $row['descriptif']; |
---|
242 | |
---|
243 | $res .="<li>" |
---|
244 | . 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") ; |
---|
245 | if (strlen($descriptif_mot) > 1) { |
---|
246 | $res .= "<FONT SIZE=1>".propre(couper($descriptif_mot, 100))."</FONT><br />\n"; |
---|
247 | } |
---|
248 | $res .="</li>\n"; |
---|
249 | } |
---|
250 | $res .= "</ul>"; |
---|
251 | |
---|
252 | if (count($resultat) > 17) |
---|
253 | $res2 .="<br /><b>" ._T('info_trop_resultat', array('cherche_mot' => $cherche_mot)) ."</b><br />\n"; |
---|
254 | |
---|
255 | $res2 = "<b>$type_mot</b> :" ._T('info_plusieurs_mots_trouves', array('cherche_mot' => $cherche_mot)) ."<br />"; |
---|
256 | |
---|
257 | return $res2 . $res; |
---|
258 | } |
---|
259 | |
---|
260 | // http://doc.spip.org/@recherche_mot_cle |
---|
261 | function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, $table_id, $url_base) |
---|
262 | { |
---|
263 | ///////////////////// |
---|
264 | //MODIFICATION |
---|
265 | ///////////////////// |
---|
266 | /* if ($table == 'articles') $ou = _T('info_l_article'); |
---|
267 | else */if ($table == 'breves') $ou = _T('info_la_breve'); |
---|
268 | else if ($table == 'rubriques') $ou = _T('info_la_rubrique'); |
---|
269 | else $ou = _T('info_l_'.$objet); |
---|
270 | ///////////////////// |
---|
271 | $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe=$id_groupe"); |
---|
272 | |
---|
273 | $table_mots = array(); |
---|
274 | $table_ids = array(); |
---|
275 | while ($row = spip_fetch_array($result)) { |
---|
276 | $table_ids[] = $row['id_mot']; |
---|
277 | $table_mots[] = $row['titre']; |
---|
278 | } |
---|
279 | |
---|
280 | $nouveaux_mots = array(); |
---|
281 | $res = ''; |
---|
282 | |
---|
283 | foreach (preg_split("/ *[,;] */", $cherche_mots) as $cherche_mot) { |
---|
284 | if ($cherche_mot) { |
---|
285 | $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids); |
---|
286 | $res .= "<P>" . debut_boite_info(true); |
---|
287 | if (!$resultat) { |
---|
288 | $res .= "<B>"._T('info_non_resultat', array('cherche_mot' => $cherche_mot))."</B><BR>"; |
---|
289 | } |
---|
290 | else if (count($resultat) == 1) { |
---|
291 | $nouveaux_mots[] = $resultat[0]; |
---|
292 | $row = spip_fetch_array(spip_query("SELECT titre FROM spip_mots WHERE id_mot=$resultat[0]")); |
---|
293 | $res .= "<B>"._T('info_mot_cle_ajoute')." $ou : </B><BR><UL>"; |
---|
294 | $res .= "<LI><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE='2'><B><FONT SIZE='3'>".typo($row['titre'])."</FONT></B></FONT></LI>\n"; |
---|
295 | $res .= "</UL>"; |
---|
296 | } |
---|
297 | else $res .= affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base); |
---|
298 | |
---|
299 | /* if (acces_mots()) { |
---|
300 | $titre = rawurlencode($cherche_mot); |
---|
301 | $res .= "<div style='width: 200px;'>"; |
---|
302 | $res .= icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&id_groupe=$id_groupe&ajouter_id_article=$id_objet&table=$table&table_id=$table_id&titre=$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false); |
---|
303 | $res .= "</div> "; |
---|
304 | } |
---|
305 | */ |
---|
306 | |
---|
307 | $res .= fin_boite_info(true) . "</p>"; |
---|
308 | } |
---|
309 | } |
---|
310 | return array($res, $nouveaux_mots); |
---|
311 | } |
---|
312 | |
---|
313 | // http://doc.spip.org/@afficher_mots_cles |
---|
314 | function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible) |
---|
315 | { |
---|
316 | global $spip_lang_rtl, $spip_lang, $spip_lang_right, $connect_statut, $connect_toutes_rubriques, $options; |
---|
317 | |
---|
318 | $les_mots = array(); |
---|
319 | $id_groupes_vus = array(); |
---|
320 | $groupes_vus = array(); |
---|
321 | $result = spip_query("SELECT mots.id_mot, mots.titre, mots.descriptif, mots.id_groupe FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot ORDER BY mots.type, mots.titre"); |
---|
322 | if (spip_num_rows($result) > 0) { |
---|
323 | |
---|
324 | $tableau= array(); |
---|
325 | $cle = http_img_pack('petite-cle.gif', "", "width='23' height='12'"); |
---|
326 | $ret = generer_url_retour($url_base, "$table_id=$id_objet#mots".$id_objet); |
---|
327 | while ($row = spip_fetch_array($result)) { |
---|
328 | |
---|
329 | $id_mot = $row['id_mot']; |
---|
330 | $titre_mot = $row['titre']; |
---|
331 | $descriptif_mot = $row['descriptif']; |
---|
332 | $id_groupe = $row['id_groupe']; |
---|
333 | |
---|
334 | $id_groupes_vus[] = $id_groupe; |
---|
335 | $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret"); |
---|
336 | $vals= array("<A href='$url'>$cle</A>"); |
---|
337 | |
---|
338 | |
---|
339 | $row_groupe = spip_fetch_array(spip_query("SELECT titre, unseul, obligatoire, minirezo, comite FROM spip_groupes_mots WHERE id_groupe = $id_groupe")); |
---|
340 | // On recupere le typo_mot ici, et non dans le mot-cle lui-meme; sinon bug avec arabe |
---|
341 | $type_mot = typo($row_groupe['titre']); |
---|
342 | $flag_groupe = $flag_editable AND (($connect_statut == '1comite' AND $row_groupe['comite'] == 'oui') OR ($connect_statut == '0minirezo' AND $row_groupe['minirezo'] == 'oui')); |
---|
343 | // Changer |
---|
344 | if (($row_groupe['unseul'] == "oui") AND $flag_groupe) { |
---|
345 | $vals[]= formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet); |
---|
346 | } else { |
---|
347 | $vals[]= "<A href='$url'>".typo($titre_mot)."</A>"; |
---|
348 | } |
---|
349 | |
---|
350 | if ($connect_toutes_rubriques) |
---|
351 | $vals[]= "<a href='" . generer_url_ecrire("mots_type","id_groupe=$id_groupe") . "'>$type_mot</a>"; |
---|
352 | |
---|
353 | else $vals[] = $type_mot; |
---|
354 | |
---|
355 | if ($flag_editable){ |
---|
356 | if ($flag_groupe) { |
---|
357 | $s = _T('info_retirer_mot') |
---|
358 | . " " |
---|
359 | . http_img_pack('croix-rouge.gif', "X", "width='7' height='7' align='middle'"); |
---|
360 | $s = ajax_action_auteur('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array($s,''),"&id_objet=$id_objet&objet=$objet"); |
---|
361 | } else $s = " "; |
---|
362 | $vals[] = $s; |
---|
363 | } else $vals[]= ""; |
---|
364 | |
---|
365 | $tableau[] = $vals; |
---|
366 | |
---|
367 | $les_mots[] = $id_mot; |
---|
368 | } |
---|
369 | |
---|
370 | $largeurs = array('25', '', '', ''); |
---|
371 | $styles = array('arial11', 'arial2', 'arial2', 'arial1'); |
---|
372 | |
---|
373 | $res = "\n<div class='liste'>" |
---|
374 | . "\n<table width='100%' cellpadding='3' cellspacing='0' border='0' background=''>" |
---|
375 | . afficher_liste($largeurs, $tableau, $styles) |
---|
376 | . "</table></div>"; |
---|
377 | } else $res =''; |
---|
378 | |
---|
379 | if ($flag_editable) |
---|
380 | $res .= formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet); |
---|
381 | |
---|
382 | return $res; |
---|
383 | } |
---|
384 | |
---|
385 | // http://doc.spip.org/@formulaire_mot_remplace |
---|
386 | function formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet) |
---|
387 | { |
---|
388 | $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe = $id_groupe ORDER by titre"); |
---|
389 | |
---|
390 | $s = ''; |
---|
391 | |
---|
392 | while ($row_autres = spip_fetch_array($result)) { |
---|
393 | $id = $row_autres['id_mot']; |
---|
394 | $le_titre_mot = supprimer_tags(typo($row_autres['titre'])); |
---|
395 | $selected = ($id == $id_mot) ? " selected='selected'" : ""; |
---|
396 | $s .= "<option value='$id'$selected> $le_titre_mot</option>"; |
---|
397 | } |
---|
398 | |
---|
399 | /////////////////// |
---|
400 | //MODIFICATION |
---|
401 | /////////////////// |
---|
402 | // $ancre = "valider_groupe_$id_groupe"; |
---|
403 | $ancre = "valider_groupe_".$id_groupe."_".$id_objet; |
---|
404 | /////////////////// |
---|
405 | // forcer le recalcul du noeud car on est en Ajax |
---|
406 | $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; |
---|
407 | |
---|
408 | return ajax_action_auteur('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", ( |
---|
409 | "<select name='nouv_mot' onchange=\"$jscript1\"" |
---|
410 | . " class='fondl' style='font-size:10px; width:90px;'>" |
---|
411 | . $s |
---|
412 | . "</select>" |
---|
413 | . "<span class='visible_au_chargement' id='$ancre'>" |
---|
414 | . "\n <input type='submit' value='" |
---|
415 | . _T('bouton_changer') |
---|
416 | . "' CLASS='fondo' style='font-size: 10px';>" |
---|
417 | . "</span>"),"&id_objet=$id_objet&objet=$objet"); |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | // http://doc.spip.org/@formulaire_mots_cles |
---|
422 | function formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet) { |
---|
423 | global $connect_statut, $spip_lang, $spip_lang_right, $spip_lang_rtl; |
---|
424 | |
---|
425 | if ($les_mots) { |
---|
426 | $nombre_mots_associes = count($les_mots); |
---|
427 | $les_mots = join($les_mots, ","); |
---|
428 | } else { |
---|
429 | $les_mots = "0"; |
---|
430 | $nombre_mots_associes = 0; |
---|
431 | } |
---|
432 | $cond_id_groupes_vus = "0"; |
---|
433 | if ($id_groupes_vus) $cond_id_groupes_vus = join(",",$id_groupes_vus); |
---|
434 | |
---|
435 | $nb_groupes = spip_num_rows(spip_query("SELECT * FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND obligatoire = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus)")); |
---|
436 | |
---|
437 | if ($visible) |
---|
438 | $res = debut_block_visible("lesmots".$id_objet); |
---|
439 | else if ($nb_groupes > 0) { |
---|
440 | $res = debut_block_visible("lesmots".$id_objet); |
---|
441 | // vilain hack pour redresser un triangle |
---|
442 | $couche_a_redresser = $GLOBALS['numero_block']['lesmots'.$id_objet]; |
---|
443 | if ($GLOBALS['browser_layer']) |
---|
444 | $res .= http_script(" |
---|
445 | triangle = findObj('triangle' + $couche_a_redresser); |
---|
446 | if (triangle) triangle.src = '" . _DIR_IMG_PACK . "deplierbas$spip_lang_rtl.gif';"); |
---|
447 | } else $res = debut_block_invisible("lesmots".$id_objet); |
---|
448 | |
---|
449 | if ($nombre_mots_associes > 3) { |
---|
450 | $res .= "<div align='right' class='arial1'>" |
---|
451 | . ajax_action_auteur('editer_mot', "$id_objet,-1,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array(_T('info_retirer_mots'),''),"&id_objet=$id_objet&objet=$objet") |
---|
452 | . "</div><br />\n"; |
---|
453 | } |
---|
454 | |
---|
455 | $result_groupes = spip_query("SELECT id_groupe,unseul,obligatoire,titre, ".creer_objet_multi ("titre", $spip_lang)." FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND (unseul != 'oui' OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus))) ORDER BY multi"); |
---|
456 | |
---|
457 | // Afficher un menu par groupe de mots |
---|
458 | $ajouter =''; |
---|
459 | while ($row = spip_fetch_array($result_groupes)) { |
---|
460 | if ($menu = menu_mots($row, $id_groupes_vus, $les_mots, $id_objet)) { |
---|
461 | $menu = ajax_action_auteur('editer_mot', |
---|
462 | "$id_objet,,$table,$table_id,$objet", |
---|
463 | $url_base, |
---|
464 | "$table_id=$id_objet", |
---|
465 | $menu, |
---|
466 | "&id_objet=$id_objet&objet=$objet&select_groupe=" |
---|
467 | .$row['id_groupe'] |
---|
468 | ); |
---|
469 | $ajouter .= "<div>$menu</div>\n"; |
---|
470 | } |
---|
471 | } |
---|
472 | if ($ajouter) { |
---|
473 | $message = "<span class='verdana1'><b>"._T('titre_ajouter_mot_cle')."</b></span>\n"; |
---|
474 | $res .= "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>" |
---|
475 | . $ajouter |
---|
476 | ."</div>\n" ; |
---|
477 | } |
---|
478 | |
---|
479 | if (acces_mots()) { |
---|
480 | $titre = _request('cherche_mot') |
---|
481 | ? "&titre=".rawurlencode(_request('cherche_mot')) : ''; |
---|
482 | $bouton_ajouter = icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false) |
---|
483 | . "\n"; |
---|
484 | } |
---|
485 | |
---|
486 | if ($message OR $bouton_ajouter) { |
---|
487 | $res .= "<div style='width:170px;'>$message |
---|
488 | <br />$bouton_ajouter</div>\n"; |
---|
489 | } |
---|
490 | |
---|
491 | return $res . fin_block(); |
---|
492 | } |
---|
493 | |
---|
494 | // http://doc.spip.org/@menu_mots |
---|
495 | function menu_mots($row, $id_groupes_vus, $les_mots,$id_objet) |
---|
496 | { |
---|
497 | $id_groupe = $row['id_groupe']; |
---|
498 | |
---|
499 | $result = spip_query("SELECT id_mot, type, titre FROM spip_mots WHERE id_groupe =$id_groupe " . ($les_mots ? "AND id_mot NOT IN ($les_mots) " : '') . "ORDER BY type, titre"); |
---|
500 | |
---|
501 | $n = spip_num_rows($result); |
---|
502 | if (!$n) return ''; |
---|
503 | |
---|
504 | $titre = textebrut(typo($row['titre'])); |
---|
505 | $titre_groupe = entites_html($titre); |
---|
506 | $unseul = $row['unseul'] == 'oui'; |
---|
507 | $obligatoire = $row['obligatoire']=='oui' AND !in_array($id_groupe, $id_groupes_vus); |
---|
508 | |
---|
509 | $res = ''; |
---|
510 | /////////////////// |
---|
511 | //MODIFICATION |
---|
512 | /////////////////// |
---|
513 | // $ancre = "valider_groupe_$id_groupe"; |
---|
514 | $ancre = "valider_groupe_".$id_groupe."_".$id_objet; |
---|
515 | /////////////////// |
---|
516 | // forcer le recalcul du noeud car on est en Ajax |
---|
517 | $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; |
---|
518 | $jscript2 = "if(!antifocus_mots[$id_groupe]){this.value='';antifocus_mots[$id_groupe]=true;}"; |
---|
519 | |
---|
520 | if ($n > 50) { |
---|
521 | $jscript = "onfocus=\"$jscript1 $jscript2\""; |
---|
522 | |
---|
523 | if ($obligatoire) |
---|
524 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#E86519;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
525 | else if ($unseul) |
---|
526 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#cccccc;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
527 | else |
---|
528 | $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; ' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
529 | |
---|
530 | $res .= "<input type='hidden' name='select_groupe' value='$id_groupe' />"; |
---|
531 | $res .= "<span class='visible_au_chargement' id='$ancre'>"; |
---|
532 | $res .= " <input type='submit' value='"._T('bouton_chercher')."' class='fondo' style='font-size:10px'>"; |
---|
533 | $res .= "</span>"; |
---|
534 | } else { |
---|
535 | |
---|
536 | $jscript = "onchange=\"$jscript1\""; |
---|
537 | |
---|
538 | if ($obligatoire) |
---|
539 | $res .= "<SELECT NAME='nouv_mot' SIZE='1' STYLE='width: 180px; background-color:#E86519;' CLASS='fondl' $jscript />"; |
---|
540 | else if ($unseul) |
---|
541 | $res .= "<SELECT NAME='nouv_mot' SIZE='1' STYLE='width: 180px; background-color:#cccccc;' CLASS='fondl' $jscript />"; |
---|
542 | else |
---|
543 | $res .= "<SELECT NAME='nouv_mot' SIZE='1' STYLE='width: 180px; ' CLASS='fondl' $jscript />"; |
---|
544 | |
---|
545 | $res .= "\n<option value='x' style='font-variant: small-caps;'>$titre</option>"; |
---|
546 | while($row = spip_fetch_array($result)) { |
---|
547 | $res .= "\n<option value='" .$row['id_mot'] . |
---|
548 | "'> " . |
---|
549 | textebrut(typo($row['titre'])) . |
---|
550 | "</option>"; |
---|
551 | } |
---|
552 | $res .= "</SELECT>"; |
---|
553 | $res .= "<span class='visible_au_chargement' id='$ancre'>"; |
---|
554 | $res .= " <input type='submit' value='"._T('bouton_choisir')."' CLASS='fondo' />"; |
---|
555 | $res .= "</span>"; |
---|
556 | } |
---|
557 | |
---|
558 | return $res; |
---|
559 | } |
---|
560 | |
---|
561 | ?> |
---|