Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
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 | ||
16 | // http://doc.spip.org/@action_editer_article_dist | |
17 | function action_editer_article_dist() { | |
18 | ||
19 | $securiser_action = charger_fonction('securiser_action', 'inc'); | |
20 | $arg = $securiser_action(); | |
21 | ||
22 | // si id_article n'est pas un nombre, c'est une creation | |
23 | // mais on verifie qu'on a toutes les données qu'il faut. | |
24 | if (!$id_article = intval($arg)) { | |
25 | $id_parent = _request('id_parent'); | |
26 | $id_auteur = $GLOBALS['auteur_session']['id_auteur']; | |
27 | if (!($id_parent AND $id_auteur)) redirige_par_entete('./'); | |
28 | $id_article = insert_article($id_parent); | |
29 | ||
30 | # cf. GROS HACK ecrire/inc/getdocument | |
31 | # rattrapper les documents associes a cet article nouveau | |
32 | # ils ont un id = 0-id_auteur | |
33 | ||
34 | spip_query("UPDATE spip_documents_articles SET id_article = $id_article WHERE id_article = ".(0-$id_auteur)); | |
35 | } | |
36 | ||
37 | // Enregistre l'envoi dans la BD | |
38 | $err = articles_set($id_article); | |
39 | ||
40 | $redirect = parametre_url(urldecode(_request('redirect')), | |
41 | 'id_article', $id_article, '&') . $err; | |
42 | ||
43 | redirige_par_entete($redirect); | |
44 | } | |
45 | ||
46 | // Appelle toutes les fonctions de modification d'un article | |
47 | // $err est de la forme '&trad_err=1' | |
48 | // http://doc.spip.org/@articles_set | |
49 | function articles_set($id_article, $c=false) { | |
50 | $err = ''; | |
51 | ||
52 | // Edition du contenu ? | |
53 | $err .= revisions_articles($id_article, $c); | |
54 | ||
55 | // Modification de statut, changement de rubrique ? | |
56 | $err .= instituer_article($id_article, $c); | |
57 | ||
58 | // Un lien de trad a prendre en compte | |
59 | $err .= article_referent($id_article, $c); | |
60 | ||
61 | return $err; | |
62 | } | |
63 | ||
64 | // http://doc.spip.org/@insert_article | |
65 | function insert_article($id_rubrique) { | |
66 | ||
67 | include_spip('base/abstract_sql'); | |
68 | include_spip('inc/rubriques'); | |
69 | ||
70 | // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article | |
71 | // dans la premiere rubrique racine | |
72 | if (!$id_rubrique = intval($id_rubrique)) { | |
73 | $row = spip_fetch_array(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0 ORDER by 0+titre,titre LIMIT 1")); | |
74 | $id_rubrique = $row['id_rubrique']; | |
75 | } | |
76 | ||
77 | // La langue a la creation : si les liens de traduction sont autorises | |
78 | // dans les rubriques, on essaie avec la langue de l'auteur, | |
79 | // ou a defaut celle de la rubrique | |
80 | // Sinon c'est la langue de la rubrique qui est choisie + heritee | |
81 | if ($GLOBALS['meta']['multi_articles'] == 'oui') { | |
82 | lang_select($GLOBALS['auteur_session']['lang']); | |
83 | if (in_array($GLOBALS['spip_lang'], | |
84 | explode(',', $GLOBALS['meta']['langues_multilingue']))) { | |
85 | $lang = $GLOBALS['spip_lang']; | |
86 | $choisie = 'oui'; | |
87 | } | |
88 | } | |
89 | ||
90 | $row = spip_fetch_array(spip_query("SELECT lang, id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique")); | |
91 | ||
92 | $id_secteur = $row['id_secteur']; | |
93 | ||
94 | if (!$lang) { | |
95 | $lang = $GLOBALS['meta']['langue_site']; | |
96 | $choisie = 'non'; | |
97 | $lang = $row['lang']; | |
98 | } | |
99 | ||
100 | $id_article = spip_abstract_insert("spip_articles", | |
101 | "(id_rubrique, id_secteur, statut, date, accepter_forum, lang, langue_choisie)", | |
102 | "($id_rubrique, $id_secteur, 'prepa', NOW(), '" | |
103 | . substr($GLOBALS['meta']['forums_publics'],0,3) | |
104 | . "', '$lang', '$choisie')"); | |
105 | spip_abstract_insert('spip_auteurs_articles', "(id_auteur,id_article)", "('" . $GLOBALS['auteur_session']['id_auteur'] . "','$id_article')"); | |
106 | ||
107 | return $id_article; | |
108 | } | |
109 | ||
110 | // Enregistre une revision d'article | |
111 | // $c est un contenu (par defaut on prend le contenu via _request()) | |
112 | // http://doc.spip.org/@revisions_articles | |
113 | function revisions_articles ($id_article, $c=false) { | |
114 | include_spip('inc/modifier'); | |
115 | ||
116 | // unifier $texte en cas de texte trop long (sur methode POST seulement) | |
117 | if (!is_array($c)) trop_longs_articles(); | |
118 | ||
119 | // Si l'article est publie, invalider les caches et demander sa reindexation | |
120 | $t = spip_fetch_array(spip_query( | |
121 | "SELECT statut FROM spip_articles WHERE id_article=$id_article")); | |
122 | if ($t['statut'] == 'publie') { | |
123 | $invalideur = "id='id_article/$id_article'"; | |
124 | $indexation = true; | |
125 | } | |
126 | ||
127 | $r = modifier_contenu('article', $id_article, | |
128 | array( | |
129 | 'champs' => array( | |
130 | 'surtitre', 'titre', 'soustitre', 'descriptif', | |
131 | 'nom_site', 'url_site', 'chapo', 'texte', 'ps', | |
132 | 'url_propre' | |
133 | ), | |
134 | 'nonvide' => array('titre' => _T('info_sans_titre')), | |
135 | 'invalideur' => $invalideur, | |
136 | 'indexation' => $indexation | |
137 | ), | |
138 | $c); | |
139 | ||
140 | if ($r) { | |
141 | spip_query("UPDATE spip_articles SET date_modif=NOW() WHERE id_article="._q($id_article)); | |
142 | } | |
143 | ||
144 | return ''; // pas d'erreur | |
145 | } | |
146 | ||
147 | ||
148 | // $c est un array ('statut', 'id_rubrique') | |
149 | // | |
150 | // statut et rubrique sont lies, car un admin restreint peut deplacer | |
151 | // un article publie vers une rubrique qu'il n'administre pas | |
152 | // http://doc.spip.org/@instituer_article | |
153 | function instituer_article($id_article, $c, $calcul_rub=true) { | |
154 | ||
155 | include_spip('inc/autoriser'); | |
156 | include_spip('inc/rubriques'); | |
157 | include_spip('inc/modifier'); | |
158 | ||
159 | $s = spip_query("SELECT statut, id_rubrique FROM spip_articles WHERE id_article=$id_article"); | |
160 | $row = spip_fetch_array($s); | |
161 | $id_rubrique = $row['id_rubrique']; | |
162 | $statut_ancien = $statut = $row['statut']; | |
163 | $champs = array(); | |
164 | ||
165 | $s = _request('statut', $c); | |
166 | if ($s AND _request('statut', $c) != $statut) { | |
167 | if (autoriser('publierdans', 'rubrique', $id_rubrique)) | |
168 | $statut = $champs['statut'] = $s; | |
169 | else if (autoriser('modifier', 'article', $id_article) AND $s != 'publie') | |
170 | $statut = $champs['statut'] = $s; | |
171 | else | |
172 | spip_log("editer_article $id_article refus " . join(' ', $c)); | |
173 | ||
174 | // En cas de publication, fixer la date a "maintenant" | |
175 | // sauf si $c commande autre chose | |
176 | if ($champs['statut'] == 'publie') { | |
177 | if ($d = _request('date', $c)) | |
178 | $champs['date'] = $d; | |
179 | else | |
180 | $champs['date'] = date('Y-m-d H:i:s'); | |
181 | } | |
182 | } | |
183 | ||
184 | // Verifier que la rubrique demandee existe et est differente | |
185 | // de la rubrique actuelle | |
186 | if ($id_parent = _request('id_parent', $c) | |
187 | AND $id_parent != $id_rubrique | |
188 | AND (spip_fetch_array(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_rubrique=$id_parent")))) { | |
189 | $champs['id_rubrique'] = $id_parent; | |
190 | ||
191 | // si l'article etait publie | |
192 | // et que le demandeur n'est pas admin de la rubrique | |
193 | // repasser l'article en statut 'propose'. | |
194 | if ($statut == 'publie') { | |
195 | if ($GLOBALS['auteur_session']['statut'] != '0minirezo') | |
196 | $champs['statut'] = 'prop'; | |
197 | else { | |
198 | include_spip('inc/auth'); | |
199 | $r = auth_rubrique($GLOBALS['auteur_session']['id_auteur'], $GLOBALS['auteur_session']['statut']); | |
200 | if (is_array($r) AND !$r[$champs['id_rubrique']]) | |
201 | $champs['statut'] = 'prop'; | |
202 | } | |
203 | } | |
204 | } | |
205 | ||
206 | ||
207 | // Envoyer aux plugins | |
208 | $champs = pipeline('pre_edition', | |
209 | array( | |
210 | 'args' => array( | |
211 | 'table' => 'spip_articles', | |
212 | 'id_objet' => $id_article | |
213 | ), | |
214 | 'data' => $champs | |
215 | ) | |
216 | ); | |
217 | ||
218 | if (!count($champs)) return; | |
219 | ||
220 | // Creer la requete SQL | |
221 | $update = array(); | |
222 | foreach ($champs as $champ => $val) | |
223 | $update[] = $champ . '=' . _q($val); | |
224 | ||
225 | spip_query("UPDATE spip_articles SET ".join(', ',$update)." WHERE id_article=$id_article"); | |
226 | ||
227 | // Si on a deplace l'article | |
228 | // - propager les secteurs | |
229 | // - changer sa langue (si heritee) | |
230 | if (isset($champs['id_rubrique'])) { | |
231 | propager_les_secteurs(); | |
232 | ||
233 | $row = spip_fetch_array(spip_query("SELECT lang, langue_choisie FROM spip_articles WHERE id_article=$id_article")); | |
234 | $langue_old = $row['lang']; | |
235 | $langue_choisie_old = $row['langue_choisie']; | |
236 | ||
237 | if ($langue_choisie_old != "oui") { | |
238 | $row = spip_fetch_array(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique="._q($champs['id_rubrique']))); | |
239 | $langue_new = $row['lang']; | |
240 | if ($langue_new != $langue_old) | |
241 | spip_query("UPDATE spip_articles SET lang='$langue_new' WHERE id_article=$id_article"); | |
242 | } | |
243 | } | |
244 | ||
245 | // Invalider les caches | |
246 | include_spip('inc/invalideur'); | |
247 | suivre_invalideur("id='id_article/$id_article'"); | |
248 | ||
249 | // Recalculer les rubriques (statuts et dates) si l'on deplace | |
250 | // un article publie, ou si on le publie/depublie | |
251 | if (($statut == 'publie' AND isset($champs['id_rubrique'])) | |
252 | OR (isset($champs['statut']) | |
253 | AND ($statut_ancien=='publie' OR $champs['statut']=='publie') | |
254 | AND $calcul_rub | |
255 | ) | |
256 | ) | |
257 | calculer_rubriques(); | |
258 | ||
259 | // Pipeline | |
260 | pipeline('post_edition', | |
261 | array( | |
262 | 'args' => array( | |
263 | 'table' => 'spip_articles', | |
264 | 'id_objet' => $id_article | |
265 | ), | |
266 | 'data' => $champs | |
267 | ) | |
268 | ); | |
269 | ||
270 | // Notifications | |
271 | if ($notifications = charger_fonction('notifications', 'inc')) { | |
272 | $notifications('instituerarticle', $id_article, | |
273 | array('statut' => $statut, 'statut_ancien' => $statut_ancien) | |
274 | ); | |
275 | } | |
276 | ||
277 | return ''; // pas d'erreur | |
278 | } | |
279 | ||
280 | ||
281 | // | |
282 | // Reunit les textes decoupes parce que trop longs | |
283 | // | |
284 | ||
285 | // http://doc.spip.org/@trop_longs_articles | |
286 | function trop_longs_articles() { | |
287 | if (is_array($plus = _request('texte_plus'))) { | |
288 | foreach ($plus as $n=>$t) { | |
289 | $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,","", $t); | |
290 | } | |
291 | set_request('texte', join('',$plus) . _request('texte')); | |
292 | } | |
293 | } | |
294 | ||
295 | // Poser un lien de traduction vers un article de reference | |
296 | // http://doc.spip.org/@article_referent | |
297 | function article_referent ($id_article, $c) { | |
298 | ||
299 | if (!$lier_trad = intval(_request('lier_trad', $c))) return; | |
300 | ||
301 | // selectionner l'article cible, qui doit etre different de nous-meme, | |
302 | // et quitter s'il n'existe pas | |
303 | if (!$row = spip_fetch_array( | |
304 | spip_query("SELECT id_trad FROM spip_articles WHERE id_article=$lier_trad AND NOT(id_article=$id_article)"))) | |
305 | { | |
306 | spip_log("echec lien de trad vers article inexistant ($lier_trad)"); | |
307 | return '&trad_err=1'; | |
308 | } | |
309 | ||
310 | // $id_lier est le numero du groupe de traduction | |
311 | $id_lier = $row['id_trad']; | |
312 | ||
313 | // Si l'article vise n'est pas deja traduit, son identifiant devient | |
314 | // le nouvel id_trad de ce nouveau groupe et on l'affecte aux deux | |
315 | // articles | |
316 | if ($id_lier == 0) { | |
317 | spip_query("UPDATE spip_articles SET id_trad = $lier_trad WHERE id_article IN ($lier_trad, $id_article)"); | |
318 | } | |
319 | // sinon on ajouter notre article dans le groupe | |
320 | else { | |
321 | spip_query("UPDATE spip_articles SET id_trad = $id_lier WHERE id_article = $id_article"); | |
322 | } | |
323 | ||
324 | return ''; // pas d'erreur | |
325 | } | |
326 | ||
327 | ||
328 | ?> |