1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2015 * |
---|
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 | * Gestion de l'action editer_breve |
---|
15 | * |
---|
16 | * @package SPIP\Breves\Actions |
---|
17 | */ |
---|
18 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
19 | |
---|
20 | /** |
---|
21 | * Action d'édition d'une brève dans la base de données dont |
---|
22 | * l'identifiant est donné en paramètre de cette fonction ou |
---|
23 | * en argument de l'action sécurisée |
---|
24 | * |
---|
25 | * Si aucun identifiant n'est donné, on crée alors une nouvelle brève. |
---|
26 | * |
---|
27 | * @param null|int $arg |
---|
28 | * Identifiant de la brève. En absence utilise l'argument |
---|
29 | * de l'action sécurisée. |
---|
30 | * @return array |
---|
31 | * Liste : identifiant de la brève, texte d'erreur éventuel |
---|
32 | **/ |
---|
33 | function action_editer_breve_dist($arg = null) { |
---|
34 | |
---|
35 | if (is_null($arg)){ |
---|
36 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
---|
37 | $arg = $securiser_action(); |
---|
38 | } |
---|
39 | |
---|
40 | // Envoi depuis le formulaire d'edition d'une breve |
---|
41 | if (!$id_breve = intval($arg)) { |
---|
42 | $id_breve = breve_inserer(_request('id_parent')); |
---|
43 | } |
---|
44 | |
---|
45 | if (!$id_breve) |
---|
46 | return array(0,''); // erreur |
---|
47 | |
---|
48 | $err = breve_modifier($id_breve); |
---|
49 | |
---|
50 | return array($id_breve,$err); |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | /** |
---|
55 | * Insertion d'une brève dans une rubrique |
---|
56 | * |
---|
57 | * @pipeline_appel pre_insertion |
---|
58 | * @pipeline_appel post_insertion |
---|
59 | * |
---|
60 | * @param int $id_rubrique |
---|
61 | * Identifiant de la rubrique |
---|
62 | * @param array|null $set |
---|
63 | * @return int |
---|
64 | * Identifiant de la nouvelle brève. |
---|
65 | */ |
---|
66 | function breve_inserer($id_rubrique, $set = null) { |
---|
67 | |
---|
68 | include_spip('inc/rubriques'); |
---|
69 | |
---|
70 | // Si id_rubrique vaut 0 ou n'est pas definie, creer la breve |
---|
71 | // dans la premiere rubrique racine |
---|
72 | if (!$id_rubrique = intval($id_rubrique)) { |
---|
73 | $id_rubrique = sql_getfetsel("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"); |
---|
74 | } |
---|
75 | |
---|
76 | // La langue a la creation : c'est la langue de la rubrique |
---|
77 | $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique"); |
---|
78 | $lang = $row['lang']; |
---|
79 | $id_rubrique = $row['id_secteur']; // garantir la racine |
---|
80 | |
---|
81 | $champs = array( |
---|
82 | 'id_rubrique' => $id_rubrique, |
---|
83 | 'statut' => 'prop', |
---|
84 | 'date_heure' => date('Y-m-d H:i:s'), |
---|
85 | 'lang' => $lang, |
---|
86 | 'langue_choisie' => 'non'); |
---|
87 | |
---|
88 | if ($set) |
---|
89 | $champs = array_merge($champs, $set); |
---|
90 | |
---|
91 | // Envoyer aux plugins |
---|
92 | $champs = pipeline('pre_insertion', |
---|
93 | array( |
---|
94 | 'args' => array( |
---|
95 | 'table' => 'spip_breves', |
---|
96 | ), |
---|
97 | 'data' => $champs |
---|
98 | ) |
---|
99 | ); |
---|
100 | $id_breve = sql_insertq("spip_breves", $champs); |
---|
101 | pipeline('post_insertion', |
---|
102 | array( |
---|
103 | 'args' => array( |
---|
104 | 'table' => 'spip_breves', |
---|
105 | 'id_objet' => $id_breve |
---|
106 | ), |
---|
107 | 'data' => $champs |
---|
108 | ) |
---|
109 | ); |
---|
110 | return $id_breve; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | /** |
---|
116 | * Modifier une brève en base |
---|
117 | * |
---|
118 | * @param int $id_breve |
---|
119 | * Identifiant de la brève à modifier |
---|
120 | * @param array|null $set |
---|
121 | * Couples (colonne => valeur) de données à modifier. |
---|
122 | * En leur absence, on cherche les données dans les champs éditables |
---|
123 | * qui ont été postés (via _request()) |
---|
124 | * @return string|null |
---|
125 | * Chaîne vide si aucune erreur, |
---|
126 | * Null si aucun champ à modifier, |
---|
127 | * Chaîne contenant un texte d'erreur sinon. |
---|
128 | */ |
---|
129 | function breve_modifier ($id_breve, $set = null) { |
---|
130 | |
---|
131 | include_spip('inc/modifier'); |
---|
132 | $c = collecter_requests( |
---|
133 | // white list |
---|
134 | array('titre', 'texte', 'lien_titre', 'lien_url'), |
---|
135 | // black list |
---|
136 | array('id_parent', 'statut'), |
---|
137 | // donnees eventuellement fournies |
---|
138 | $set |
---|
139 | ); |
---|
140 | |
---|
141 | $invalideur = ''; |
---|
142 | $indexation = false; |
---|
143 | |
---|
144 | // Si la breve est publiee, invalider les caches et demander sa reindexation |
---|
145 | $t = sql_getfetsel("statut", "spip_breves", "id_breve=$id_breve"); |
---|
146 | if ($t == 'publie') { |
---|
147 | $invalideur = "id='breve/$id_breve'"; |
---|
148 | $indexation = true; |
---|
149 | } |
---|
150 | |
---|
151 | if ($err = objet_modifier_champs('breve', $id_breve, |
---|
152 | array( |
---|
153 | 'data' => $set, |
---|
154 | 'nonvide' => array('titre' => _T('breves:titre_nouvelle_breve')." "._T('info_numero_abbreviation').$id_breve), |
---|
155 | 'invalideur' => $invalideur, |
---|
156 | 'indexation' => $indexation |
---|
157 | ), |
---|
158 | $c)) |
---|
159 | return $err; |
---|
160 | |
---|
161 | $c = collecter_requests(array('id_parent', 'statut'),array(),$set); |
---|
162 | $err = breve_instituer($id_breve, $c); |
---|
163 | return $err; |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | /** |
---|
168 | * Instituer une brève : modifier son statut ou son parent |
---|
169 | * |
---|
170 | * @pipeline_appel pre_insertion |
---|
171 | * @pipeline_appel post_insertion |
---|
172 | * |
---|
173 | * @param int $id_breve |
---|
174 | * Identifiant de la brève |
---|
175 | * @param array $c |
---|
176 | * Couples (colonne => valeur) des données à instituer |
---|
177 | * @return string|null |
---|
178 | * Null si aucun champ à modifier, chaîne vide sinon. |
---|
179 | */ |
---|
180 | function breve_instituer($id_breve, $c) { |
---|
181 | $champs = array(); |
---|
182 | |
---|
183 | // Changer le statut de la breve ? |
---|
184 | $row = sql_fetsel("statut, id_rubrique,lang, langue_choisie", "spip_breves", "id_breve=".intval($id_breve)); |
---|
185 | $id_rubrique = $row['id_rubrique']; |
---|
186 | |
---|
187 | $statut_ancien = $statut = $row['statut']; |
---|
188 | $langue_old = $row['lang']; |
---|
189 | $langue_choisie_old = $row['langue_choisie']; |
---|
190 | |
---|
191 | if (isset($c['statut']) |
---|
192 | AND $c['statut'] |
---|
193 | AND $c['statut'] != $statut |
---|
194 | AND autoriser('publierdans', 'rubrique', $id_rubrique)) { |
---|
195 | $statut = $champs['statut'] = $c['statut']; |
---|
196 | } |
---|
197 | |
---|
198 | // Changer de rubrique ? |
---|
199 | // Verifier que la rubrique demandee est a la racine et differente |
---|
200 | // de la rubrique actuelle |
---|
201 | if ($id_parent = intval($c['id_parent']) |
---|
202 | AND $id_parent != $id_rubrique |
---|
203 | AND (NULL !== ($lang=sql_getfetsel('lang', 'spip_rubriques', "id_parent=0 AND id_rubrique=".intval($id_parent))))) { |
---|
204 | $champs['id_rubrique'] = $id_parent; |
---|
205 | // - changer sa langue (si heritee) |
---|
206 | if ($langue_choisie_old != "oui") { |
---|
207 | if ($lang != $langue_old) |
---|
208 | $champs['lang'] = $lang; |
---|
209 | } |
---|
210 | // si la breve est publiee |
---|
211 | // et que le demandeur n'est pas admin de la rubrique |
---|
212 | // repasser la breve en statut 'prop'. |
---|
213 | if ($statut == 'publie') { |
---|
214 | if (!autoriser('publierdans','rubrique',$id_parent)) |
---|
215 | $champs['statut'] = $statut = 'prop'; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | // Envoyer aux plugins |
---|
220 | $champs = pipeline('pre_edition', |
---|
221 | array( |
---|
222 | 'args' => array( |
---|
223 | 'table' => 'spip_breves', |
---|
224 | 'id_objet' => $id_breve, |
---|
225 | 'action'=>'instituer', |
---|
226 | 'statut_ancien' => $statut_ancien, |
---|
227 | ), |
---|
228 | 'data' => $champs |
---|
229 | ) |
---|
230 | ); |
---|
231 | |
---|
232 | if (!$champs) return; |
---|
233 | |
---|
234 | sql_updateq('spip_breves', $champs, "id_breve=".intval($id_breve)); |
---|
235 | |
---|
236 | // |
---|
237 | // Post-modifications |
---|
238 | // |
---|
239 | |
---|
240 | // Invalider les caches |
---|
241 | include_spip('inc/invalideur'); |
---|
242 | suivre_invalideur("id='breve/$id_breve'"); |
---|
243 | |
---|
244 | // Au besoin, changer le statut des rubriques concernees |
---|
245 | include_spip('inc/rubriques'); |
---|
246 | calculer_rubriques_if($id_rubrique, $champs, $statut_ancien); |
---|
247 | |
---|
248 | // Pipeline |
---|
249 | pipeline('post_edition', |
---|
250 | array( |
---|
251 | 'args' => array( |
---|
252 | 'table' => 'spip_breves', |
---|
253 | 'id_objet' => $id_breve, |
---|
254 | 'action'=>'instituer', |
---|
255 | 'statut_ancien' => $statut_ancien, |
---|
256 | ), |
---|
257 | 'data' => $champs |
---|
258 | ) |
---|
259 | ); |
---|
260 | |
---|
261 | |
---|
262 | // Notifications |
---|
263 | if ($notifications = charger_fonction('notifications', 'inc')) { |
---|
264 | $notifications('instituerbreve', $id_breve, |
---|
265 | array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
---|
266 | ); |
---|
267 | } |
---|
268 | |
---|
269 | return ''; // pas d'erreur |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | // Fonctions Dépréciées |
---|
274 | // -------------------- |
---|
275 | |
---|
276 | /** |
---|
277 | * Insertion d'une brève dans une rubrique |
---|
278 | * |
---|
279 | * @deprecated Utiliser breve_inserer() |
---|
280 | * @see breve_inserer() |
---|
281 | * |
---|
282 | * @param int $id_rubrique |
---|
283 | * Identifiant de la rubrique |
---|
284 | * @return int |
---|
285 | * Identifiant de la nouvelle brève. |
---|
286 | */ |
---|
287 | function insert_breve($id_rubrique) { |
---|
288 | return breve_inserer($id_rubrique); |
---|
289 | } |
---|
290 | |
---|
291 | /** |
---|
292 | * Créer une révision de brève |
---|
293 | * |
---|
294 | * @deprecated Utiliser breve_modifier() |
---|
295 | * @see breve_modifier() |
---|
296 | * |
---|
297 | * @param int $id_breve |
---|
298 | * Identifiant de la brève à modifier |
---|
299 | * @param array|null $set |
---|
300 | * Couples (colonne => valeur) de données à modifier. |
---|
301 | * En leur absence, on cherche les données dans les champs éditables |
---|
302 | * qui ont été postés (via _request()) |
---|
303 | * @return string|null |
---|
304 | * Chaîne vide si aucune erreur, |
---|
305 | * Null si aucun champ à modifier, |
---|
306 | * Chaîne contenant un texte d'erreur sinon. |
---|
307 | */ |
---|
308 | function revisions_breves ($id_breve, $set = false) { |
---|
309 | return breve_modifier($id_breve,$set); |
---|
310 | } |
---|
311 | ?> |
---|