3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
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;
15 include_spip('inc/filtres');
17 // Editer (modification) d'un mot-cle
18 // http://doc.spip.org/@action_editer_mot_dist
19 function action_editer_mot_dist($arg=null)
22 $securiser_action = charger_fonction('securiser_action', 'inc');
23 $arg = $securiser_action();
25 $id_mot = intval($arg);
27 $id_groupe = intval(_request('id_groupe'));
28 if (!$id_mot AND $id_groupe) {
29 $id_mot = mot_inserer($id_groupe);
32 // Enregistre l'envoi dans la BD
33 if ($id_mot > 0) $err = mot_modifier($id_mot);
35 return array($id_mot,$err);
39 * Insertion d'un mot dans un groupe
40 * @param int $id_groupe
43 function mot_inserer($id_groupe) {
46 $row = sql_fetsel("titre", "spip_groupes_mots", "id_groupe=".intval($id_groupe));
48 $champs['id_groupe'] = $id_groupe;
49 $champs['type'] = $row['titre'];
55 // Envoyer aux plugins
56 $champs = pipeline('pre_insertion',
59 'table' => 'spip_mots',
65 $id_mot = sql_insertq("spip_mots", $champs);
67 pipeline('post_insertion',
70 'table' => 'spip_mots',
86 function mot_modifier($id_mot, $set=null) {
87 include_spip('inc/modifier');
88 $c = collecter_requests(
91 'titre', 'descriptif', 'texte', 'id_groupe'
95 // donnees eventuellement fournies
99 if ($err = objet_modifier_champs('mot', $id_mot,
101 'nonvide' => array('titre' => _T('info_sans_titre'))
106 $c = collecter_requests(array('id_groupe', 'type'),array(),$set);
107 $err = mot_instituer($id_mot, $c);
112 * Modifier le groupe parent d'un mot
117 function mot_instituer($id_mot, $c){
120 if (isset($c['id_groupe']) OR isset($c['type'])) {
121 $row = sql_fetsel("titre", "spip_groupes_mots", "id_groupe=".intval($c['id_groupe']));
123 $champs['id_groupe'] = $c['id_groupe'];
124 $champs['type'] = $row['titre'];
128 // Envoyer aux plugins
129 $champs = pipeline('pre_edition',
132 'table' => 'spip_mots',
133 'id_objet' => $id_mot,
134 'action'=>'instituer',
140 if (!$champs) return;
142 sql_updateq('spip_mots', $champs, "id_mot=".intval($id_mot));
145 // Post-modifications
148 // Invalider les caches
149 include_spip('inc/invalideur');
150 suivre_invalideur("id='mot/$id_mot'");
153 pipeline('post_edition',
156 'table' => 'spip_mots',
157 'id_objet' => $id_mot,
158 'action'=>'instituer',
165 if ($notifications = charger_fonction('notifications', 'inc')) {
166 $notifications('instituermot', $id_mot,
167 array('id_groupe' => $champs['id_groupe'])
171 return ''; // pas d'erreur
179 function mot_supprimer($id_mot) {
180 sql_delete("spip_mots", "id_mot=".intval($id_mot));
181 mot_dissocier($id_mot, '*');
182 pipeline('trig_supprimer_objets_lies',
184 array('type'=>'mot','id'=>$id_mot)
192 * Associer un mot a des objets listes sous forme
193 * array($objet=>$id_objets,...)
194 * $id_objets peut lui meme etre un scalaire ou un tableau pour une liste d'objets du meme type
196 * on peut passer optionnellement une qualification du (des) lien(s) qui sera
197 * alors appliquee dans la foulee.
198 * En cas de lot de liens, c'est la meme qualification qui est appliquee a tous
201 * mot_associer(3, array('auteur'=>2));
202 * mot_associer(3, array('auteur'=>2), array('vu'=>'oui)); // ne fonctionnera pas ici car pas de champ 'vu' sur spip_mots_liens
205 * @param array $objets
206 * @param array $qualif
209 function mot_associer($id_mot,$objets, $qualif = null){
211 include_spip('action/editer_liens');
213 // si il s'agit d'un groupe avec 'unseul', alors supprimer d'abord les autres
214 // mots de ce groupe associe a ces objets
215 $id_groupe = sql_getfetsel('id_groupe','spip_mots','id_mot='.intval($id_mot));
216 if (un_seul_mot_dans_groupe($id_groupe)) {
217 $mots_groupe = sql_allfetsel("id_mot", "spip_mots", "id_groupe=".intval($id_groupe));
218 $mots_groupe = array_map('reset',$mots_groupe);
219 objet_dissocier(array('mot'=>$mots_groupe), $objets);
222 return objet_associer(array('mot'=>$id_mot), $objets, $qualif);
228 * Dossocier un mot des objets listes sous forme
229 * array($objet=>$id_objets,...)
230 * $id_objets peut lui meme etre un scalaire ou un tableau pour une liste d'objets du meme type
232 * un * pour $id_mot,$objet,$id_objet permet de traiter par lot
235 * @param array $objets
238 function mot_dissocier($id_mot,$objets){
239 include_spip('action/editer_liens');
240 return objet_dissocier(array('mot'=>$id_mot), $objets);
244 * Qualifier le lien d'un mot avec les objets listes
245 * array($objet=>$id_objets,...)
246 * $id_objets peut lui meme etre un scalaire ou un tableau pour une liste d'objets du meme type
248 * $c = array('vu'=>'oui');
249 * un * pour $id_auteur,$objet,$id_objet permet de traiter par lot
252 * @param array $objets
253 * @param array $qualif
255 function mot_qualifier($id_mot,$objets,$qualif){
256 include_spip('action/editer_liens');
257 return objet_qualifier(array('mot'=>$id_mot), $objets, $qualif);
263 * Renvoyer true si le groupe de mot ne doit etre associe qu'une fois aux objet
264 * (maximum un seul mot de ce groupe associe a chaque objet)
266 * @param int $id_groupe
269 function un_seul_mot_dans_groupe($id_groupe)
271 return sql_countsel('spip_groupes_mots', "id_groupe=$id_groupe AND unseul='oui'");
276 function insert_mot($id_groupe) {
277 return mot_inserer($id_groupe);
279 function mots_set($id_mot, $set=null) {
280 return mot_modifier($id_mot, $set);
282 function revision_mot($id_mot, $c=false) {
283 return mot_modifier($id_mot, $c);