3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2016 *
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 // http://code.spip.net/@action_editer_breve_dist
16 function action_editer_breve_dist($arg=null) {
19 $securiser_action = charger_fonction('securiser_action', 'inc');
20 $arg = $securiser_action();
23 // Envoi depuis le formulaire d'edition d'une breve
24 if (!$id_breve = intval($arg)) {
25 $id_breve = breve_inserer(_request('id_parent'));
29 return array(0,''); // erreur
31 $err = breve_modifier($id_breve);
33 return array($id_breve,$err);
37 * Inserer une breve en base
38 * http://code.spip.net/@insert_breve
40 * @param int $id_rubrique
43 function breve_inserer($id_rubrique) {
45 include_spip('inc/rubriques');
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");
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");
56 $id_rubrique = $row['id_secteur']; // garantir la racine
59 'id_rubrique' => $id_rubrique,
61 'date_heure' => date('Y-m-d H:i:s'),
63 'langue_choisie' => 'non');
65 // Envoyer aux plugins
66 $champs = pipeline('pre_insertion',
69 'table' => 'spip_breves',
74 $id_breve = sql_insertq("spip_breves", $champs);
75 pipeline('post_insertion',
78 'table' => 'spip_breves',
79 'id_objet' => $id_breve
89 * Modifier une breve en base
90 * $c est un contenu (par defaut on prend le contenu via _request())
92 * http://code.spip.net/@revisions_breves
94 * @param int $id_breve
98 function breve_modifier ($id_breve, $set=null) {
100 include_spip('inc/modifier');
101 $c = collecter_requests(
103 array('titre', 'texte', 'lien_titre', 'lien_url'),
105 array('id_parent', 'statut'),
106 // donnees eventuellement fournies
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'";
117 if ($err = objet_modifier_champs('breve', $id_breve,
119 'nonvide' => array('titre' => _T('breves:titre_nouvelle_breve')." "._T('info_numero_abbreviation').$id_breve),
120 'invalideur' => $invalideur,
121 'indexation' => $indexation
126 $c = collecter_requests(array('id_parent', 'statut'),array(),$set);
127 $err = breve_instituer($id_breve, $c);
132 * Instituer une breve : modifier son statut ou son parent
134 * @param int $id_breve
138 function breve_instituer($id_breve, $c) {
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'];
145 $statut_ancien = $statut = $row['statut'];
146 $langue_old = $row['lang'];
147 $langue_choisie_old = $row['langue_choisie'];
150 AND $c['statut'] != $statut
151 AND autoriser('publierdans', 'rubrique', $id_rubrique)) {
152 $statut = $champs['statut'] = $c['statut'];
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;
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';
176 // Envoyer aux plugins
177 $champs = pipeline('pre_edition',
180 'table' => 'spip_breves',
181 'id_objet' => $id_breve,
182 'action'=>'instituer',
183 'statut_ancien' => $statut_ancien,
189 if (!$champs) return;
191 sql_updateq('spip_breves', $champs, "id_breve=".intval($id_breve));
194 // Post-modifications
197 // Invalider les caches
198 include_spip('inc/invalideur');
199 suivre_invalideur("id='breve/$id_breve'");
201 // Au besoin, changer le statut des rubriques concernees
202 include_spip('inc/rubriques');
203 calculer_rubriques_if($id_rubrique, $champs, $statut_ancien);
206 pipeline('post_edition',
209 'table' => 'spip_breves',
210 'id_objet' => $id_breve,
211 'action'=>'instituer',
212 'statut_ancien' => $statut_ancien,
220 if ($notifications = charger_fonction('notifications', 'inc')) {
221 $notifications('instituerbreve', $id_breve,
222 array('statut' => $statut, 'statut_ancien' => $statut_ancien)
226 return ''; // pas d'erreur
229 function insert_breve($id_rubrique) {
230 return breve_inserer($id_rubrique);
232 function revisions_breves ($id_breve, $set=false) {
233 return breve_modifier($id_breve,$set);