[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / plugins-dist / breves / action / editer_breve.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
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
15 // http://code.spip.net/@action_editer_breve_dist
16 function action_editer_breve_dist($arg=null) {
17
18 if (is_null($arg)){
19 $securiser_action = charger_fonction('securiser_action', 'inc');
20 $arg = $securiser_action();
21 }
22
23 // Envoi depuis le formulaire d'edition d'une breve
24 if (!$id_breve = intval($arg)) {
25 $id_breve = breve_inserer(_request('id_parent'));
26 }
27
28 if (!$id_breve)
29 return array(0,''); // erreur
30
31 $err = breve_modifier($id_breve);
32
33 return array($id_breve,$err);
34 }
35
36 /**
37 * Inserer une breve en base
38 * http://code.spip.net/@insert_breve
39 *
40 * @param int $id_rubrique
41 * @return int
42 */
43 function breve_inserer($id_rubrique) {
44
45 include_spip('inc/rubriques');
46
47 // Si id_rubrique vaut 0 ou n'est pas definie, creer la breve
48 // dans la premiere rubrique racine
49 if (!$id_rubrique = intval($id_rubrique)) {
50 $id_rubrique = sql_getfetsel("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1");
51 }
52
53 // La langue a la creation : c'est la langue de la rubrique
54 $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
55 $lang = $row['lang'];
56 $id_rubrique = $row['id_secteur']; // garantir la racine
57
58 $champs = array(
59 'id_rubrique' => $id_rubrique,
60 'statut' => 'prop',
61 'date_heure' => date('Y-m-d H:i:s'),
62 'lang' => $lang,
63 'langue_choisie' => 'non');
64
65 // Envoyer aux plugins
66 $champs = pipeline('pre_insertion',
67 array(
68 'args' => array(
69 'table' => 'spip_breves',
70 ),
71 'data' => $champs
72 )
73 );
74 $id_breve = sql_insertq("spip_breves", $champs);
75 pipeline('post_insertion',
76 array(
77 'args' => array(
78 'table' => 'spip_breves',
79 'id_objet' => $id_breve
80 ),
81 'data' => $champs
82 )
83 );
84 return $id_breve;
85 }
86
87
88 /**
89 * Modifier une breve en base
90 * $c est un contenu (par defaut on prend le contenu via _request())
91 *
92 * http://code.spip.net/@revisions_breves
93 *
94 * @param int $id_breve
95 * @param array $set
96 * @return string|bool
97 */
98 function breve_modifier ($id_breve, $set=null) {
99
100 include_spip('inc/modifier');
101 $c = collecter_requests(
102 // white list
103 array('titre', 'texte', 'lien_titre', 'lien_url'),
104 // black list
105 array('id_parent', 'statut'),
106 // donnees eventuellement fournies
107 $set
108 );
109
110 // Si la breve est publiee, invalider les caches et demander sa reindexation
111 $t = sql_getfetsel("statut", "spip_breves", "id_breve=$id_breve");
112 if ($t == 'publie') {
113 $invalideur = "id='breve/$id_breve'";
114 $indexation = true;
115 }
116
117 if ($err = objet_modifier_champs('breve', $id_breve,
118 array(
119 'nonvide' => array('titre' => _T('breves:titre_nouvelle_breve')." "._T('info_numero_abbreviation').$id_breve),
120 'invalideur' => $invalideur,
121 'indexation' => $indexation
122 ),
123 $c))
124 return $err;
125
126 $c = collecter_requests(array('id_parent', 'statut'),array(),$set);
127 $err = breve_instituer($id_breve, $c);
128 return $err;
129 }
130
131 /**
132 * Instituer une breve : modifier son statut ou son parent
133 *
134 * @param int $id_breve
135 * @param array $c
136 * @return string
137 */
138 function breve_instituer($id_breve, $c) {
139 $champs = array();
140
141 // Changer le statut de la breve ?
142 $row = sql_fetsel("statut, id_rubrique,lang, langue_choisie", "spip_breves", "id_breve=".intval($id_breve));
143 $id_rubrique = $row['id_rubrique'];
144
145 $statut_ancien = $statut = $row['statut'];
146 $langue_old = $row['lang'];
147 $langue_choisie_old = $row['langue_choisie'];
148
149 if ($c['statut']
150 AND $c['statut'] != $statut
151 AND autoriser('publierdans', 'rubrique', $id_rubrique)) {
152 $statut = $champs['statut'] = $c['statut'];
153 }
154
155 // Changer de rubrique ?
156 // Verifier que la rubrique demandee est a la racine et differente
157 // de la rubrique actuelle
158 if ($id_parent = intval($c['id_parent'])
159 AND $id_parent != $id_rubrique
160 AND (NULL !== ($lang=sql_getfetsel('lang', 'spip_rubriques', "id_parent=0 AND id_rubrique=".intval($id_parent))))) {
161 $champs['id_rubrique'] = $id_parent;
162 // - changer sa langue (si heritee)
163 if ($langue_choisie_old != "oui") {
164 if ($lang != $langue_old)
165 $champs['lang'] = $lang;
166 }
167 // si la breve est publiee
168 // et que le demandeur n'est pas admin de la rubrique
169 // repasser la breve en statut 'prop'.
170 if ($statut == 'publie') {
171 if (!autoriser('publierdans','rubrique',$id_parent))
172 $champs['statut'] = $statut = 'prop';
173 }
174 }
175
176 // Envoyer aux plugins
177 $champs = pipeline('pre_edition',
178 array(
179 'args' => array(
180 'table' => 'spip_breves',
181 'id_objet' => $id_breve,
182 'action'=>'instituer',
183 'statut_ancien' => $statut_ancien,
184 ),
185 'data' => $champs
186 )
187 );
188
189 if (!$champs) return;
190
191 sql_updateq('spip_breves', $champs, "id_breve=".intval($id_breve));
192
193 //
194 // Post-modifications
195 //
196
197 // Invalider les caches
198 include_spip('inc/invalideur');
199 suivre_invalideur("id='breve/$id_breve'");
200
201 // Au besoin, changer le statut des rubriques concernees
202 include_spip('inc/rubriques');
203 calculer_rubriques_if($id_rubrique, $champs, $statut_ancien);
204
205 // Pipeline
206 pipeline('post_edition',
207 array(
208 'args' => array(
209 'table' => 'spip_breves',
210 'id_objet' => $id_breve,
211 'action'=>'instituer',
212 'statut_ancien' => $statut_ancien,
213 ),
214 'data' => $champs
215 )
216 );
217
218
219 // Notifications
220 if ($notifications = charger_fonction('notifications', 'inc')) {
221 $notifications('instituerbreve', $id_breve,
222 array('statut' => $statut, 'statut_ancien' => $statut_ancien)
223 );
224 }
225
226 return ''; // pas d'erreur
227 }
228
229 function insert_breve($id_rubrique) {
230 return breve_inserer($id_rubrique);
231 }
232 function revisions_breves ($id_breve, $set=false) {
233 return breve_modifier($id_breve,$set);
234 }
235 ?>