1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2008 * |
---|
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 | include_spip('inc/mots'); |
---|
16 | //include_spip('public/assembler'); //pour recuperer_fond |
---|
17 | |
---|
18 | // http://doc.spip.org/@inc_editer_mots_dist |
---|
19 | function inc_editer_mots($objet, $id_objet, $cherche_mot, $select_groupe, $flag, $visible = false) { |
---|
20 | |
---|
21 | if ($GLOBALS['meta']["articles_mots"] == 'non') return ''; |
---|
22 | |
---|
23 | $visible = ($visible OR $cherche_mot OR ($flag === 'ajax')); |
---|
24 | |
---|
25 | /////////////////////////// |
---|
26 | // MODIFICATION |
---|
27 | /////////////////////////// |
---|
28 | |
---|
29 | |
---|
30 | include_spip("mots_partout_choses"); |
---|
31 | global $choses_possibles; |
---|
32 | |
---|
33 | if ($objet == 'syndic') $table=$objet; |
---|
34 | else $table=$objet.'s'; |
---|
35 | |
---|
36 | //bloc de modification du core : on utilise chose possibles et pas des if |
---|
37 | if (isset($choses_possibles[$table])) { |
---|
38 | if ($choses_possibles[$table]['id_chose']) |
---|
39 | $table_id = $choses_possibles[$table]['id_chose']; |
---|
40 | else $table_id = 'id_'.$objet; |
---|
41 | if ($choses_possibles[$table]['objet']) $objet=$choses_possibles[$table]['objet']; |
---|
42 | else $objet = substr($table,0,-1); |
---|
43 | if ($choses_possibles[$table]['url_base']) $url_base=$choses_possibles[$table]['url_base']; |
---|
44 | else $url_base = $table; |
---|
45 | if (is_array($id_objet)){ |
---|
46 | foreach($id_objet as $key => $value) |
---|
47 | if ($key=='id_objet') $_id_objet=$id_objet['id_objet']; |
---|
48 | else $url_base.=$value; |
---|
49 | $id_objet=$_id_objet; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | //Ceci n'est plus vraiment utile dans le cas de la squeletisation |
---|
54 | $cpt = sql_countsel("spip_mots AS mots, spip_mots_$table AS lien", "lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot"); |
---|
55 | |
---|
56 | if (!$cpt) { |
---|
57 | if (!$flag) return; |
---|
58 | $cpt = sql_fetch(editer_mots_droits("COUNT(*) AS n", "$table = 'oui'")); |
---|
59 | |
---|
60 | if (!$cpt['n']) return; |
---|
61 | } |
---|
62 | ////////////////////// |
---|
63 | |
---|
64 | //preparation de l'utilisation de recuperer_fond a ce niveau |
---|
65 | //definition du contexte |
---|
66 | |
---|
67 | //$squel=recup_squelette_motspartout("listemot_".$table); |
---|
68 | //$contexte_liste=array("table"=>$table,"id_objet"=>$id_objet,"visible"=>$visible,"simplifie"=>$simplifie); |
---|
69 | //$res=recuperer_fond($squel,$contexte_liste); |
---|
70 | |
---|
71 | |
---|
72 | // |
---|
73 | // Preparer l'affichage |
---|
74 | // |
---|
75 | |
---|
76 | // La reponse |
---|
77 | $reponse = ''; |
---|
78 | $modifier = false; |
---|
79 | if ($flag AND $cherche_mot) { |
---|
80 | list($reponse, $nouveaux_mots) = recherche_mot_cle($cherche_mot, $select_groupe, $objet, $id_objet, $table, $table_id, $url_base); |
---|
81 | foreach($nouveaux_mots as $nouv_mot) { |
---|
82 | if ($nouv_mot!='x') { |
---|
83 | $modifier |= inserer_mot("spip_mots_$table", $table_id, $id_objet, $nouv_mot); |
---|
84 | } |
---|
85 | } |
---|
86 | if ($modifier) { |
---|
87 | pipeline('post_edition', |
---|
88 | array( |
---|
89 | 'args' => array( |
---|
90 | 'table' => 'spip_'.$table, |
---|
91 | 'id_objet' => $id_objet |
---|
92 | ), |
---|
93 | 'data' => null |
---|
94 | ) |
---|
95 | ); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | $form = afficher_mots_cles($flag, $objet, $id_objet, $table, $table_id, $url_base, $visible); |
---|
100 | // Envoyer titre + div-id + formulaire + fin |
---|
101 | $bouton = _T('titre_mots_cles').aide ("artmots"); |
---|
102 | if ($flag) |
---|
103 | $bouton = bouton_block_depliable($bouton,'incertain',"lesmots-".$table.$id_objet); // on n'est pas sur de l'etat du bloc, le bouton se mettra dans le bon etat au chargement |
---|
104 | $res = debut_cadre_enfonce("mot-cle-24.gif", true, "", $bouton) |
---|
105 | . $reponse |
---|
106 | . $form |
---|
107 | . fin_cadre_enfonce(true); |
---|
108 | |
---|
109 | return ajax_action_greffe("editer_mots", $id_objet, $res); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | function chercher_inserer_mot($cherche_mot, $select_groupe, $objet, $id_objet, $nom, $table_id, $url_base) |
---|
114 | { |
---|
115 | $modifier = false; |
---|
116 | |
---|
117 | list($reponse, $nouveaux_mots) = recherche_mot_cle($cherche_mot, $select_groupe, $objet, $id_objet, $nom, $table_id, $url_base); |
---|
118 | foreach($nouveaux_mots as $nouv_mot) { |
---|
119 | if ($nouv_mot!='x') { |
---|
120 | $modifier |= inserer_mot("spip_mots_$nom", $table_id, $id_objet, $nouv_mot); |
---|
121 | } |
---|
122 | } |
---|
123 | if ($modifier) { |
---|
124 | pipeline('post_edition', |
---|
125 | array( |
---|
126 | 'args' => array( |
---|
127 | 'table' => $table, |
---|
128 | 'id_objet' => $id_objet |
---|
129 | ), |
---|
130 | 'data' => null |
---|
131 | ) |
---|
132 | ); |
---|
133 | } |
---|
134 | return $reponse; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | // http://doc.spip.org/@inserer_mot |
---|
139 | function inserer_mot($table, $table_id, $id_objet, $id_mot) |
---|
140 | { |
---|
141 | $r = sql_countsel($table, "id_mot=$id_mot AND $table_id=$id_objet"); |
---|
142 | |
---|
143 | if (!$r) sql_insertq($table, array('id_mot' =>$id_mot, $table_id => $id_objet)); |
---|
144 | |
---|
145 | return $r; |
---|
146 | } |
---|
147 | |
---|
148 | // http://doc.spip.org/@recherche_mot_cle |
---|
149 | function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, $table_id, $url_base) |
---|
150 | { |
---|
151 | ///////////////////// |
---|
152 | //MODIFICATION |
---|
153 | ///////////////////// |
---|
154 | /*if ($table == 'articles') $ou = _T('info_l_article'); |
---|
155 | else*/ if ($table == 'breves') $ou = _T('info_la_breve'); |
---|
156 | else if ($table == 'rubriques') $ou = _T('info_la_rubrique'); |
---|
157 | else $ou = _T('info_l_'.$objet); |
---|
158 | ///////////////////// |
---|
159 | |
---|
160 | $result = sql_select("id_mot, titre", "spip_mots", "id_groupe=" . sql_quote($id_groupe)); |
---|
161 | |
---|
162 | $table_mots = array(); |
---|
163 | $table_ids = array(); |
---|
164 | while ($row = sql_fetch($result)) { |
---|
165 | $table_ids[] = $row['id_mot']; |
---|
166 | $table_mots[] = $row['titre']; |
---|
167 | } |
---|
168 | |
---|
169 | $nouveaux_mots = array(); |
---|
170 | $res = ''; |
---|
171 | |
---|
172 | foreach (split(" *[,;] *", $cherche_mots) as $cherche_mot) { |
---|
173 | if ($cherche_mot) { |
---|
174 | $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids); |
---|
175 | $res .= "<br />" . debut_boite_info(true); |
---|
176 | if (!$resultat) { |
---|
177 | $res .= "<b>"._T('info_non_resultat', array('cherche_mot' => htmlspecialchars($cherche_mot)))."</b><br />"; |
---|
178 | } |
---|
179 | else if (count($resultat) == 1) { |
---|
180 | $n = $resultat[0]; |
---|
181 | $nouveaux_mots[] = $n; |
---|
182 | $t = sql_getfetsel("titre", "spip_mots", "id_mot=$n"); |
---|
183 | $res .= "<b>"._T('info_mot_cle_ajoute')." $ou : </b><br />\n<ul>"; |
---|
184 | $res .= "\n<li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($t)."</span></b></span></li>"; |
---|
185 | $res .= "\n</ul>"; |
---|
186 | } |
---|
187 | else $res .= affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base); |
---|
188 | |
---|
189 | /* if (autoriser('modifier','groupemots',$id_groupe)) { |
---|
190 | $titre = rawurlencode($cherche_mot); |
---|
191 | $res .= "<div style='width: 200px;'>"; |
---|
192 | $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); |
---|
193 | $res .= "</div> "; |
---|
194 | } |
---|
195 | */ |
---|
196 | |
---|
197 | $res .= fin_boite_info(true) . "<br />"; |
---|
198 | } |
---|
199 | } |
---|
200 | return array($res, $nouveaux_mots); |
---|
201 | } |
---|
202 | |
---|
203 | // http://doc.spip.org/@afficher_mots_cles |
---|
204 | function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible) |
---|
205 | { |
---|
206 | |
---|
207 | $requete = array('SELECT' => "mots.id_mot, mots.titre , 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", 'GROUP BY' => "mots.type, mots.titre", 'ORDER BY' => "mots.type, mots.titre"); |
---|
208 | |
---|
209 | $cle = http_img_pack('petite-cle.gif', "", "width='23' height='12'"); |
---|
210 | $ret = generer_url_retour($url_base, "$table_id=$id_objet#mots"); |
---|
211 | $largeurs = array('25', '', '', ''); |
---|
212 | $styles = array('arial11', 'arial2', 'arial2', 'arial1'); |
---|
213 | |
---|
214 | $presenter_liste = charger_fonction('presenter_liste', 'inc'); |
---|
215 | |
---|
216 | // cette variable est passe par reference et recevra les valeurs du champ indique |
---|
217 | $les_mots = 'id_mot'; |
---|
218 | $res = $presenter_liste($requete, 'editer_mots_un', $les_mots, array($cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base), false, $largeurs, $styles); |
---|
219 | |
---|
220 | if ($flag_editable) |
---|
221 | $res .= formulaire_mots_cles($id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet); |
---|
222 | |
---|
223 | return $res; |
---|
224 | } |
---|
225 | |
---|
226 | // http://doc.spip.org/@formulaire_mot_remplace |
---|
227 | function formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet) |
---|
228 | { |
---|
229 | $result = sql_select("id_mot, titre", "spip_mots", "id_groupe = $id_groupe", "", "titre"); |
---|
230 | |
---|
231 | $s = ''; |
---|
232 | |
---|
233 | while ($row_autres = sql_fetch($result)) { |
---|
234 | $id = $row_autres['id_mot']; |
---|
235 | $le_titre_mot = supprimer_tags(typo($row_autres['titre'])); |
---|
236 | $selected = ($id == $id_mot) ? " selected='selected'" : ""; |
---|
237 | $s .= "\n<option value='$id'$selected> $le_titre_mot</option>"; |
---|
238 | } |
---|
239 | |
---|
240 | $ancre = "valider_groupe_".$table."-".$id_groupe."-".$id_objet; |
---|
241 | // forcer le recalcul du noeud car on est en Ajax |
---|
242 | $jscript1 = "findObj_forcer('choisir-$ancre').style.visibility='visible';"; |
---|
243 | |
---|
244 | $corps = "\n<select name='nouv_mot' id='nouv_mot$id_groupe' onchange=\"$jscript1\"" |
---|
245 | . " class='fondl spip_xx-small' style='width:90px;'>" |
---|
246 | . $s |
---|
247 | . "</select>\n " ; |
---|
248 | |
---|
249 | $t = _T('bouton_changer'); |
---|
250 | |
---|
251 | return ajax_action_post('editer_mots', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet",$corps, $t, " class='fondo spip_xx-small visible_au_chargement' id='choisir-$ancre'", "", "&id_objet=$id_objet&objet=$objet"); |
---|
252 | } |
---|
253 | |
---|
254 | // http://doc.spip.org/@formulaire_mots_cles |
---|
255 | function formulaire_mots_cles($id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet) { |
---|
256 | global $spip_lang, $spip_lang_right; |
---|
257 | |
---|
258 | //Yoann |
---|
259 | if(!$table) $table="articles"; //nous evite d'avoir des plantages |
---|
260 | //TODO a tester en enlevant ca |
---|
261 | //FIN YOANN |
---|
262 | |
---|
263 | $cond_mots_vus = !$les_mots ? '' : |
---|
264 | sql_in('id_mot', $les_mots); |
---|
265 | |
---|
266 | $id_groupes_vus = array(); |
---|
267 | $flag_tous = 1; |
---|
268 | if ($cond_mots_vus) { |
---|
269 | |
---|
270 | $droit = substr($GLOBALS['visiteur_session']['statut'],1); |
---|
271 | $q = sql_select("M.id_groupe, G.$droit", "spip_mots AS M LEFT JOIN spip_groupes_mots AS G ON M.id_groupe=G.id_groupe", $cond_mots_vus, "M.id_groupe"); |
---|
272 | while($r = sql_fetch($q)) { |
---|
273 | $id_groupes_vus[]= $r['id_groupe']; |
---|
274 | $flag_tous &= ($r[$droit] === 'oui'); |
---|
275 | } |
---|
276 | $cond_id_groupes_vus = (" OR (unseul = 'oui' AND " . sql_in('id_groupe', $id_groupes_vus, 'NOT')." ) "); |
---|
277 | } else { |
---|
278 | $cond_id_groupes_vus = ''; |
---|
279 | } |
---|
280 | |
---|
281 | $nb_groupes = sql_fetch(editer_mots_droits('count(*) AS n', "$table = 'oui' AND obligatoire = 'oui'$cond_id_groupes_vus")); |
---|
282 | $nb_groupes = $nb_groupes['n']; |
---|
283 | |
---|
284 | $res = debut_block_depliable($visible OR ($nb_groupes > 0),"lesmots-".$table.$id_objet); |
---|
285 | if ($flag_tous AND count($les_mots)>= 3) { |
---|
286 | $res .= "<div style='text-align: right' class='arial1'>" |
---|
287 | . ajax_action_auteur('editer_mots', "$id_objet,-1,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array(_T('info_retirer_mots'),''),"&id_objet=$id_objet&objet=$objet") |
---|
288 | . "</div><br />\n"; |
---|
289 | } |
---|
290 | |
---|
291 | $result = editer_mots_droits("id_groupe,unseul,obligatoire,titre, ".sql_multi ("titre", $spip_lang), "$table = 'oui' AND (unseul != 'oui' $cond_id_groupes_vus) ORDER BY multi"); |
---|
292 | |
---|
293 | // Afficher un menu par groupe de mots non vu |
---|
294 | $ajouter =''; |
---|
295 | $cond_mots_vus = !$les_mots ? '' : |
---|
296 | (" AND " . sql_in('id_mot', $les_mots, 'NOT')); |
---|
297 | |
---|
298 | while ($row = sql_fetch($result)) { |
---|
299 | |
---|
300 | $ancre=$table."-".$id_groupe."-".$id_objet; |
---|
301 | |
---|
302 | if ($menu = menu_mots($row, $id_groupes_vus, $cond_mots_vus,$ancre)) { |
---|
303 | $id_groupe = $row['id_groupe']; |
---|
304 | list($corps, $clic) = $menu; |
---|
305 | |
---|
306 | |
---|
307 | $ajouter .= ajax_action_post('editer_mots', |
---|
308 | "$id_objet,,$table,$table_id,$objet", |
---|
309 | $url_base, |
---|
310 | "$table_id=$id_objet", |
---|
311 | $corps, |
---|
312 | $clic, |
---|
313 | " class='visible_au_chargement fondo spip_xx-small' id='valider_groupe_$ancre'", "", |
---|
314 | "&id_objet=$id_objet&objet=$objet&select_groupe=$id_groupe"); |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | //if( ($table=="articles" || $table=="rubriques")){ |
---|
319 | |
---|
320 | if ($ajouter) { |
---|
321 | $message = "<span class='verdana1'><b>"._T('titre_ajouter_mot_cle')."</b></span>\n"; |
---|
322 | $res .= "<div>" |
---|
323 | . $ajouter |
---|
324 | ."</div>\n" ; |
---|
325 | } else $message =''; |
---|
326 | |
---|
327 | // Creer un nouveau mot ? |
---|
328 | if (autoriser('modifier','groupemots')) { |
---|
329 | $titre = _request('cherche_mot') |
---|
330 | ? "&titre=".rawurlencode(_request('cherche_mot')) : ''; |
---|
331 | $titre = _T('icone_creer_mot_cle'); |
---|
332 | $titres = array( |
---|
333 | 'articles'=>'icone_creer_mot_cle', |
---|
334 | 'breves'=>'icone_creer_mot_cle_breve', |
---|
335 | 'rubriques'=>'icone_creer_mot_cle_rubrique', |
---|
336 | 'sites'=>'icone_creer_mot_cle_site' ); |
---|
337 | $bouton_ajouter = icone_horizontale_display(isset($titres[$table])?_T($titres[$table]):_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false) |
---|
338 | . "\n"; |
---|
339 | } else $bouton_ajouter = ''; |
---|
340 | |
---|
341 | if ($message OR $bouton_ajouter) { |
---|
342 | $res .= "$message<br />$bouton_ajouter"; |
---|
343 | } |
---|
344 | //} |
---|
345 | return $res . fin_block(); |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | // http://doc.spip.org/@menu_mots |
---|
350 | function menu_mots($row, $id_groupes_vus, $les_mots,$ancre="") |
---|
351 | { |
---|
352 | $id_groupe = $row['id_groupe']; |
---|
353 | |
---|
354 | $n = sql_countsel("spip_mots", "id_groupe=$id_groupe" . $les_mots); |
---|
355 | // MODIFICATION |
---|
356 | //dans le cas ou on a pas de mots clefs associes au groupe (principe de l'arborescence) |
---|
357 | //on va prendre les sous-groupe comme etant signe d'affichage |
---|
358 | if (!$n) { |
---|
359 | $n = sql_countsel("spip_groupes_mots", "id_parent=$id_groupe"); |
---|
360 | if(!$n) return ''; |
---|
361 | } |
---|
362 | //FIN |
---|
363 | |
---|
364 | $titre = textebrut(typo($row['titre'])); |
---|
365 | $titre_groupe = entites_html($titre); |
---|
366 | $unseul = $row['unseul'] == 'oui'; |
---|
367 | $obligatoire = $row['obligatoire']=='oui' AND !in_array($id_groupe, $id_groupes_vus); |
---|
368 | |
---|
369 | $res = ''; |
---|
370 | // forcer le recalcul du noeud car on est en Ajax |
---|
371 | $rand = rand(0,10000); # pour antifocus & ajax |
---|
372 | $ancre = "valider_groupe_".$ancre; |
---|
373 | |
---|
374 | |
---|
375 | $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; |
---|
376 | $jscript2 = "if(!antifocus_mots['$rand-$id_groupe']){this.value='';antifocus_mots['$rand-$id_groupe']=true;}"; |
---|
377 | |
---|
378 | if ($n > 50) { |
---|
379 | $jscript = "onfocus=\"$jscript1 $jscript2\""; |
---|
380 | |
---|
381 | if ($obligatoire) |
---|
382 | $res .= "<input type='text' name='cherche_mot' id='cherche_mot$id_groupe' class='fondl' style='background-color:#E86519;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
383 | else if ($unseul) |
---|
384 | $res .= "<input type='text' name='cherche_mot' id='cherche_mot$id_groupe' class='fondl' style='background-color:#cccccc;' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
385 | else |
---|
386 | $res .= "<input type='text' name='cherche_mot' id='cherche_mot$id_groupe' class='fondl' value=\"$titre_groupe\" size='20' $jscript />"; |
---|
387 | |
---|
388 | $res .= "<input type='hidden' name='select_groupe' value='$id_groupe' /> "; |
---|
389 | return array($res, _T('bouton_chercher')); |
---|
390 | } else { |
---|
391 | |
---|
392 | $jscript = "onchange=\"$jscript1\""; |
---|
393 | |
---|
394 | if ($obligatoire) |
---|
395 | $res .= "<select name='nouv_mot' id='nouv_mot$id_groupe' size='1' style='background-color:#E86519;' class='fondl' $jscript>"; |
---|
396 | else if ($unseul) |
---|
397 | $res .= "<select name='nouv_mot' id='nouv_mot$id_groupe' size='1' style=' background-color:#cccccc;' class='fondl' $jscript>"; |
---|
398 | else |
---|
399 | $res .= "<select name='nouv_mot' id='nouv_mot$id_groupe' size='1' class='fondl' $jscript>"; |
---|
400 | |
---|
401 | //on a le groupe de mots de base |
---|
402 | $res .= "\n<option value='x' style='font-variant: small-caps;'>$titre</option>"; |
---|
403 | |
---|
404 | $result = sql_select("id_mot, type, titre", "spip_mots", "id_groupe =$id_groupe " . $les_mots, "", "titre"); |
---|
405 | |
---|
406 | |
---|
407 | //on boucle sur les mots du groupe de base |
---|
408 | while($row = sql_fetch($result)) { |
---|
409 | $res .= "\n<option value='" .$row['id_mot'] . |
---|
410 | "'> " . |
---|
411 | textebrut(typo($row['titre'])) . |
---|
412 | "</option>"; |
---|
413 | } |
---|
414 | } |
---|
415 | //ARBORESCENCE : on va rajouter dans le select les sous-groupes ainsi que leurs mots clefs |
---|
416 | $res.=select_sous_menu_groupe_mots($id_groupe,$table); //gestion de la hierarchie des mots clefs |
---|
417 | $res .= "</select> "; |
---|
418 | return array($res, _T('bouton_choisir')); |
---|
419 | |
---|
420 | } |
---|
421 | |
---|
422 | // http://doc.spip.org/@select_sous_menu_groupe_mots |
---|
423 | function select_sous_menu_groupe_mots($id_groupe,$table='articles',$niveau=0){ |
---|
424 | //fonction recursive qui permet de recuperer larborescence des groupes de mots et les mots |
---|
425 | return; |
---|
426 | global $spip_lang,$connect_statut,$cond_id_groupes_vus; |
---|
427 | //$query="SELECT id_groupe,titre, ".creer_objet_multi ("titre", $spip_lang)." FROM spip_groupes_mots WHERE `".$table."` = 'oui' AND ".substr($connect_statut,1)." = 'oui' ".($cond_id_groupes_vus?" AND (unseul != 'oui' OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus)) )":"")." AND id_parent=".$id_groupe." ORDER BY multi"; |
---|
428 | |
---|
429 | //boucle sur les sous groupes |
---|
430 | //$result_sous_groupes = spip_query($query); |
---|
431 | |
---|
432 | |
---|
433 | |
---|
434 | //hum hum |
---|
435 | if(!$table) $table="articles"; |
---|
436 | |
---|
437 | |
---|
438 | if($table!="articles" && $table!="rubriques") $cond_table=$table." = 'oui' AND "; |
---|
439 | else $cond_table="tables_liees REGEXP '(^|,)$table($|,)' AND "; |
---|
440 | |
---|
441 | if($cond_id_groupes_vus){ |
---|
442 | $result_sous_groupes = editer_mots_droits("id_groupe,titre, ".sql_multi ("titre", $spip_lang), " (unseul != 'oui' OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus))) ORDER BY multi"); |
---|
443 | }else { |
---|
444 | $result_sous_groupes = editer_mots_droits("id_groupe,titre, ".sql_multi ("titre", $spip_lang), "$table = 'oui' AND (unseul != 'oui' OR (unseul = 'oui')) ORDER BY multi"); |
---|
445 | } |
---|
446 | |
---|
447 | while ($row = sql_fetch($result_sous_groupes)) { |
---|
448 | $res .= "\n<option value='" .$row['id_groupe'] . |
---|
449 | "'>".str_repeat(" ",$niveau) . |
---|
450 | textebrut(typo($row['titre'])) . |
---|
451 | "</option>"; |
---|
452 | //BOUCLES sur les mots de chaque sous groupe |
---|
453 | //$result = spip_query("SELECT id_mot, type, titre,".creer_objet_multi ("titre", $spip_lang)." FROM spip_mots WHERE id_groupe =".$row['id_groupe']." ORDER BY type, titre"); |
---|
454 | $result = sql_select("id_mot, type, titre", "spip_mots", "id_groupe =$id_groupe " . ($les_mots ? "AND id_mot NOT IN ($les_mots) " : '') . "", "", "titre"); |
---|
455 | |
---|
456 | while($row2 = sql_fetch($result)) { |
---|
457 | $res .= "\n<option value='" .$row2['id_mot'] . |
---|
458 | "'>".str_repeat(" ",$niveau)." ->" . |
---|
459 | textebrut(typo($row2['titre'])) . |
---|
460 | "</option>"; |
---|
461 | } |
---|
462 | |
---|
463 | $res.=select_sous_menu_groupe_mots($row['id_groupe'],$table,$niveau+1); |
---|
464 | } |
---|
465 | return $res; |
---|
466 | } |
---|
467 | |
---|
468 | /*function recup_squelette_motspartout($squel){ |
---|
469 | |
---|
470 | if($fond=find_in_path($squel)) return $fond; |
---|
471 | else {//on va aller chercher l'interface g�n�rale |
---|
472 | $squel="fond/listemot_general"; |
---|
473 | return find_in_path($squel); |
---|
474 | } |
---|
475 | |
---|
476 | }*/ |
---|
477 | |
---|
478 | // Fonction verifiant que l'auteur a le droit de modifier un groupe de mots. |
---|
479 | // Fondee sur l'egalite du nom du statut et du nom du champ. |
---|
480 | // Il vaudrait mieux rajouter une table des statuts (ou un groupe de mots) |
---|
481 | // et un table de jointure entre ca et la table des groupes de mots. |
---|
482 | |
---|
483 | // http://doc.spip.org/@editer_mots_droits |
---|
484 | function editer_mots_droits($select, $cond) |
---|
485 | { |
---|
486 | |
---|
487 | $droit = substr($GLOBALS['visiteur_session']['statut'],1); |
---|
488 | return sql_select("$select", "spip_groupes_mots", "$droit = 'oui' AND $cond"); |
---|
489 | } |
---|
490 | |
---|
491 | |
---|
492 | function creer_mot($table, $id_objet, $table_id, $url_base, $mot='', $id_groupe=0) |
---|
493 | { |
---|
494 | static $titres = array( |
---|
495 | 'articles'=>'icone_creer_mot_cle', |
---|
496 | 'breves'=>'icone_creer_mot_cle_breve', |
---|
497 | 'rubriques'=>'icone_creer_mot_cle_rubrique', |
---|
498 | 'sites'=>'icone_creer_mot_cle_site' |
---|
499 | ); |
---|
500 | |
---|
501 | if (!($id_groupe ? |
---|
502 | autoriser('modifier','groupemots', $id_groupe) : |
---|
503 | autoriser('modifier','groupemots')) |
---|
504 | ) |
---|
505 | return ''; |
---|
506 | |
---|
507 | $legende = isset($titres[$table]) |
---|
508 | ? _T($titres[$table]) |
---|
509 | : _T('icone_creer_mot_cle'); |
---|
510 | |
---|
511 | $args = "new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id" |
---|
512 | . (!$mot ? '' : ("&titre=".rawurlencode($mot))) |
---|
513 | . (!$id_groupe ? '' : ("&id_groupe=".intval($id_groupe))) |
---|
514 | . "&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet"); |
---|
515 | |
---|
516 | return icone_horizontale_display($legende, generer_url_ecrire("mots_edit", $args), "mot-cle-24.gif", "creer.gif", false); |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | // http://doc.spip.org/@editer_mots_un |
---|
521 | function editer_mots_un($row, $own) |
---|
522 | { |
---|
523 | $puce_statut = charger_fonction('puce_statut', 'inc'); |
---|
524 | |
---|
525 | list ($cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base) = $own; |
---|
526 | |
---|
527 | $id_mot = $row['id_mot']; |
---|
528 | $titre_mot = $row['titre']; |
---|
529 | $id_groupe = $row['id_groupe']; |
---|
530 | |
---|
531 | $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret"); |
---|
532 | // On recupere le typo_mot ici, et non dans le mot-cle lui-meme; |
---|
533 | // sinon bug avec arabe |
---|
534 | |
---|
535 | |
---|
536 | |
---|
537 | if ($table!="documents"){ //interface simplifiée documents |
---|
538 | $groupe = typo(sql_getfetsel("titre", "spip_groupes_mots", "id_groupe = $id_groupe")); |
---|
539 | if(autoriser('modifier', 'groupemots', $id_groupe) ){ |
---|
540 | $groupe = "<a href='" . generer_url_ecrire("mots_type","id_groupe=$id_groupe") . "'>$groupe</a>"; |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | $retire = $unseul = ''; |
---|
545 | |
---|
546 | if ($flag_editable) { |
---|
547 | $r = editer_mots_droits('unseul', "id_groupe = $id_groupe"); |
---|
548 | if ($r) { |
---|
549 | $unseul = ($r[0]['unseul'] == 'oui'); |
---|
550 | $r=""; |
---|
551 | if($table!="documents"){ //interface simplifiée poru els documents |
---|
552 | $r = _T('info_retirer_mot') |
---|
553 | . " "; |
---|
554 | } |
---|
555 | |
---|
556 | $r.=http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"); |
---|
557 | |
---|
558 | $retire = ajax_action_auteur('editer_mots', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array($r,''),"&id_objet=$id_objet&objet=$objet"); |
---|
559 | } |
---|
560 | } |
---|
561 | // Changer |
---|
562 | if ($unseul) { |
---|
563 | $mot = formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet); |
---|
564 | } else { |
---|
565 | $mot = "<a href='$url'>".typo($titre_mot)."</a>"; |
---|
566 | } |
---|
567 | |
---|
568 | $cle = $puce_statut($id_mot, 'publie', $id_groupe, 'mot'); |
---|
569 | |
---|
570 | return array("<a href='$url'>$cle</a>", $mot, $groupe, $retire); |
---|
571 | } |
---|
572 | |
---|
573 | ?> |
---|