Completed
Push — master ( 158fed...f65708 )
by cam
01:29
created
ecrire/action/editer_article.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -39,36 +39,36 @@  discard block
 block discarded – undo
39 39
  *     Liste (identifiant de l'article, Texte d'erreur éventuel)
40 40
  */
41 41
 function action_editer_article_dist($arg = null) {
42
-	include_spip('inc/autoriser');
43
-	$err = '';
44
-	if (is_null($arg)) {
45
-		$securiser_action = charger_fonction('securiser_action', 'inc');
46
-		$arg = $securiser_action();
47
-	}
48
-
49
-	// si id_article n'est pas un nombre, c'est une creation
50
-	// mais on verifie qu'on a toutes les donnees qu'il faut.
51
-	if (!$id_article = intval($arg)) {
52
-		$id_parent = _request('id_parent');
53
-		if (!$id_parent) {
54
-			$err = _L("creation interdite d'un article sans rubrique");
55
-		} elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
56
-			$err = _T('info_creerdansrubrique_non_autorise');
57
-		} else {
58
-			$id_article = article_inserer($id_parent);
59
-		}
60
-	}
61
-
62
-	// Enregistre l'envoi dans la BD
63
-	if ($id_article > 0) {
64
-		$err = article_modifier($id_article);
65
-	}
66
-
67
-	if ($err) {
68
-		spip_log("echec editeur article: $err", _LOG_ERREUR);
69
-	}
70
-
71
-	return [$id_article, $err];
42
+    include_spip('inc/autoriser');
43
+    $err = '';
44
+    if (is_null($arg)) {
45
+        $securiser_action = charger_fonction('securiser_action', 'inc');
46
+        $arg = $securiser_action();
47
+    }
48
+
49
+    // si id_article n'est pas un nombre, c'est une creation
50
+    // mais on verifie qu'on a toutes les donnees qu'il faut.
51
+    if (!$id_article = intval($arg)) {
52
+        $id_parent = _request('id_parent');
53
+        if (!$id_parent) {
54
+            $err = _L("creation interdite d'un article sans rubrique");
55
+        } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
56
+            $err = _T('info_creerdansrubrique_non_autorise');
57
+        } else {
58
+            $id_article = article_inserer($id_parent);
59
+        }
60
+    }
61
+
62
+    // Enregistre l'envoi dans la BD
63
+    if ($id_article > 0) {
64
+        $err = article_modifier($id_article);
65
+    }
66
+
67
+    if ($err) {
68
+        spip_log("echec editeur article: $err", _LOG_ERREUR);
69
+    }
70
+
71
+    return [$id_article, $err];
72 72
 }
73 73
 
74 74
 /**
@@ -90,50 +90,50 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function article_modifier($id_article, $set = null) {
92 92
 
93
-	// unifier $texte en cas de texte trop long
94
-	trop_longs_articles();
95
-
96
-	include_spip('inc/modifier');
97
-	include_spip('inc/filtres');
98
-	$c = collecter_requests(
99
-		// include list
100
-		objet_info('article', 'champs_editables'),
101
-		// exclude list
102
-		['date', 'statut', 'id_parent'],
103
-		// donnees eventuellement fournies
104
-		$set
105
-	);
106
-
107
-	// Si l'article est publie, invalider les caches et demander sa reindexation
108
-	$t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article));
109
-	$invalideur = $indexation = false;
110
-	if ($t == 'publie') {
111
-		$invalideur = "id='article/$id_article'";
112
-		$indexation = true;
113
-	}
114
-
115
-	if (
116
-		$err = objet_modifier_champs(
117
-			'article',
118
-			$id_article,
119
-			[
120
-			'data' => $set,
121
-			'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article],
122
-			'invalideur' => $invalideur,
123
-			'indexation' => $indexation,
124
-			'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
125
-			],
126
-			$c
127
-		)
128
-	) {
129
-		return $err;
130
-	}
131
-
132
-	// Modification de statut, changement de rubrique ?
133
-	$c = collecter_requests(['date', 'statut', 'id_parent'], [], $set);
134
-	$err = article_instituer($id_article, $c);
135
-
136
-	return $err;
93
+    // unifier $texte en cas de texte trop long
94
+    trop_longs_articles();
95
+
96
+    include_spip('inc/modifier');
97
+    include_spip('inc/filtres');
98
+    $c = collecter_requests(
99
+        // include list
100
+        objet_info('article', 'champs_editables'),
101
+        // exclude list
102
+        ['date', 'statut', 'id_parent'],
103
+        // donnees eventuellement fournies
104
+        $set
105
+    );
106
+
107
+    // Si l'article est publie, invalider les caches et demander sa reindexation
108
+    $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article));
109
+    $invalideur = $indexation = false;
110
+    if ($t == 'publie') {
111
+        $invalideur = "id='article/$id_article'";
112
+        $indexation = true;
113
+    }
114
+
115
+    if (
116
+        $err = objet_modifier_champs(
117
+            'article',
118
+            $id_article,
119
+            [
120
+            'data' => $set,
121
+            'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article],
122
+            'invalideur' => $invalideur,
123
+            'indexation' => $indexation,
124
+            'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
125
+            ],
126
+            $c
127
+        )
128
+    ) {
129
+        return $err;
130
+    }
131
+
132
+    // Modification de statut, changement de rubrique ?
133
+    $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set);
134
+    $err = article_instituer($id_article, $c);
135
+
136
+    return $err;
137 137
 }
138 138
 
139 139
 /**
@@ -169,98 +169,98 @@  discard block
 block discarded – undo
169 169
  */
170 170
 function article_inserer($id_rubrique, $set = null) {
171 171
 
172
-	// Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
173
-	// dans la premiere rubrique racine
174
-	if (!$id_rubrique = intval($id_rubrique)) {
175
-		$row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
176
-		$id_rubrique = $row['id_rubrique'];
177
-	} else {
178
-		$row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique");
179
-	}
180
-
181
-	// eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue
182
-	// cas de id_rubrique = -1 par exemple avec plugin "pages"
183
-	$id_secteur = $row['id_secteur'] ?? 0;
184
-	$lang_rub = $row['lang'] ?? '';
185
-
186
-	$lang = '';
187
-	$choisie = 'non';
188
-	// La langue a la creation : si les liens de traduction sont autorises
189
-	// dans les rubriques, on essaie avec la langue de l'auteur,
190
-	// ou a defaut celle de la rubrique
191
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
192
-	if (
193
-		!empty($GLOBALS['meta']['multi_objets']) and in_array(
194
-			'spip_articles',
195
-			explode(',', $GLOBALS['meta']['multi_objets'])
196
-		)
197
-	) {
198
-		lang_select($GLOBALS['visiteur_session']['lang']);
199
-		if (
200
-			in_array(
201
-				$GLOBALS['spip_lang'],
202
-				explode(',', $GLOBALS['meta']['langues_multilingue'])
203
-			)
204
-		) {
205
-			$lang = $GLOBALS['spip_lang'];
206
-			$choisie = 'oui';
207
-		}
208
-	}
209
-
210
-	if (!$lang) {
211
-		$choisie = 'non';
212
-		$lang = $lang_rub ?: $GLOBALS['meta']['langue_site'];
213
-	}
214
-
215
-	$champs = [
216
-		'id_rubrique' => $id_rubrique,
217
-		'id_secteur' => $id_secteur,
218
-		'statut' => 'prepa',
219
-		'date' => date('Y-m-d H:i:s'),
220
-		'lang' => $lang,
221
-		'langue_choisie' => $choisie
222
-	];
223
-
224
-	if ($set) {
225
-		$champs = array_merge($champs, $set);
226
-	}
227
-
228
-	// Envoyer aux plugins
229
-	$champs = pipeline(
230
-		'pre_insertion',
231
-		[
232
-			'args' => [
233
-				'table' => 'spip_articles',
234
-			],
235
-			'data' => $champs
236
-		]
237
-	);
238
-
239
-	$id_article = sql_insertq('spip_articles', $champs);
240
-
241
-	// controler si le serveur n'a pas renvoye une erreur
242
-	if ($id_article > 0) {
243
-		$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
244
-			$GLOBALS['visiteur_session']['id_auteur']
245
-			: _request('id_auteur'));
246
-		if ($id_auteur) {
247
-			include_spip('action/editer_auteur');
248
-			auteur_associer($id_auteur, ['article' => $id_article]);
249
-		}
250
-	}
251
-
252
-	pipeline(
253
-		'post_insertion',
254
-		[
255
-			'args' => [
256
-				'table' => 'spip_articles',
257
-				'id_objet' => $id_article
258
-			],
259
-			'data' => $champs
260
-		]
261
-	);
262
-
263
-	return $id_article;
172
+    // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
173
+    // dans la premiere rubrique racine
174
+    if (!$id_rubrique = intval($id_rubrique)) {
175
+        $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
176
+        $id_rubrique = $row['id_rubrique'];
177
+    } else {
178
+        $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique");
179
+    }
180
+
181
+    // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue
182
+    // cas de id_rubrique = -1 par exemple avec plugin "pages"
183
+    $id_secteur = $row['id_secteur'] ?? 0;
184
+    $lang_rub = $row['lang'] ?? '';
185
+
186
+    $lang = '';
187
+    $choisie = 'non';
188
+    // La langue a la creation : si les liens de traduction sont autorises
189
+    // dans les rubriques, on essaie avec la langue de l'auteur,
190
+    // ou a defaut celle de la rubrique
191
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
192
+    if (
193
+        !empty($GLOBALS['meta']['multi_objets']) and in_array(
194
+            'spip_articles',
195
+            explode(',', $GLOBALS['meta']['multi_objets'])
196
+        )
197
+    ) {
198
+        lang_select($GLOBALS['visiteur_session']['lang']);
199
+        if (
200
+            in_array(
201
+                $GLOBALS['spip_lang'],
202
+                explode(',', $GLOBALS['meta']['langues_multilingue'])
203
+            )
204
+        ) {
205
+            $lang = $GLOBALS['spip_lang'];
206
+            $choisie = 'oui';
207
+        }
208
+    }
209
+
210
+    if (!$lang) {
211
+        $choisie = 'non';
212
+        $lang = $lang_rub ?: $GLOBALS['meta']['langue_site'];
213
+    }
214
+
215
+    $champs = [
216
+        'id_rubrique' => $id_rubrique,
217
+        'id_secteur' => $id_secteur,
218
+        'statut' => 'prepa',
219
+        'date' => date('Y-m-d H:i:s'),
220
+        'lang' => $lang,
221
+        'langue_choisie' => $choisie
222
+    ];
223
+
224
+    if ($set) {
225
+        $champs = array_merge($champs, $set);
226
+    }
227
+
228
+    // Envoyer aux plugins
229
+    $champs = pipeline(
230
+        'pre_insertion',
231
+        [
232
+            'args' => [
233
+                'table' => 'spip_articles',
234
+            ],
235
+            'data' => $champs
236
+        ]
237
+    );
238
+
239
+    $id_article = sql_insertq('spip_articles', $champs);
240
+
241
+    // controler si le serveur n'a pas renvoye une erreur
242
+    if ($id_article > 0) {
243
+        $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
244
+            $GLOBALS['visiteur_session']['id_auteur']
245
+            : _request('id_auteur'));
246
+        if ($id_auteur) {
247
+            include_spip('action/editer_auteur');
248
+            auteur_associer($id_auteur, ['article' => $id_article]);
249
+        }
250
+    }
251
+
252
+    pipeline(
253
+        'post_insertion',
254
+        [
255
+            'args' => [
256
+                'table' => 'spip_articles',
257
+                'id_objet' => $id_article
258
+            ],
259
+            'data' => $champs
260
+        ]
261
+    );
262
+
263
+    return $id_article;
264 264
 }
265 265
 
266 266
 
@@ -288,125 +288,125 @@  discard block
 block discarded – undo
288 288
  */
289 289
 function article_instituer($id_article, $c, $calcul_rub = true) {
290 290
 
291
-	include_spip('inc/autoriser');
292
-	include_spip('inc/rubriques');
293
-	include_spip('inc/modifier');
294
-
295
-	$row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article");
296
-	$id_rubrique = $row['id_rubrique'];
297
-	$statut_ancien = $statut = $row['statut'];
298
-	$date_ancienne = $date = $row['date'];
299
-	$champs = [];
300
-
301
-	$d = $c['date'] ?? null;
302
-	$s = $c['statut'] ?? $statut;
303
-
304
-	// cf autorisations dans inc/instituer_article
305
-	if ($s != $statut or ($d and $d != $date)) {
306
-		if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
307
-			$statut = $champs['statut'] = $s;
308
-		} elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
309
-			$statut = $champs['statut'] = $s;
310
-		} else {
311
-			spip_log("editer_article $id_article refus " . join(' ', $c));
312
-		}
313
-
314
-		// En cas de publication, fixer la date a "maintenant"
315
-		// sauf si $c commande autre chose
316
-		// ou si l'article est deja date dans le futur
317
-		// En cas de proposition d'un article (mais pas depublication), idem
318
-		if (
319
-			$champs['statut'] == 'publie'
320
-			or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop'])))
321
-		) {
322
-			if ($d or strtotime($d = $date) > time()) {
323
-				$champs['date'] = $date = $d;
324
-			} else {
325
-				$champs['date'] = $date = date('Y-m-d H:i:s');
326
-			}
327
-		}
328
-	}
329
-
330
-	// Verifier que la rubrique demandee existe et est differente
331
-	// de la rubrique actuelle
332
-	if (
333
-		isset($c['id_parent'])
334
-		and $id_parent = $c['id_parent']
335
-		and $id_parent != $id_rubrique
336
-		and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
337
-	) {
338
-		$champs['id_rubrique'] = $id_parent;
339
-
340
-		// si l'article etait publie
341
-		// et que le demandeur n'est pas admin de la rubrique de destination
342
-		// repasser l'article en statut 'propose'.
343
-		if (
344
-			$statut == 'publie'
345
-			and !autoriser('publierdans', 'rubrique', $id_parent)
346
-		) {
347
-			$champs['statut'] = 'prop';
348
-		}
349
-	}
350
-
351
-	// Envoyer aux plugins
352
-	$champs = pipeline(
353
-		'pre_edition',
354
-		[
355
-			'args' => [
356
-				'table' => 'spip_articles',
357
-				'id_objet' => $id_article,
358
-				'action' => 'instituer',
359
-				'statut_ancien' => $statut_ancien,
360
-				'date_ancienne' => $date_ancienne,
361
-			],
362
-			'data' => $champs
363
-		]
364
-	);
365
-
366
-	if (!(is_countable($champs) ? count($champs) : 0)) {
367
-		return '';
368
-	}
369
-
370
-	// Envoyer les modifs.
371
-	editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
372
-
373
-	// Invalider les caches
374
-	include_spip('inc/invalideur');
375
-	suivre_invalideur("id='article/$id_article'");
376
-
377
-	if ($date) {
378
-		$t = strtotime($date);
379
-		$p = @$GLOBALS['meta']['date_prochain_postdate'];
380
-		if ($t > time() and (!$p or ($t < $p))) {
381
-			ecrire_meta('date_prochain_postdate', $t);
382
-		}
383
-	}
384
-
385
-	// Pipeline
386
-	pipeline(
387
-		'post_edition',
388
-		[
389
-			'args' => [
390
-				'table' => 'spip_articles',
391
-				'id_objet' => $id_article,
392
-				'action' => 'instituer',
393
-				'statut_ancien' => $statut_ancien,
394
-				'date_ancienne' => $date_ancienne,
395
-			],
396
-			'data' => $champs
397
-		]
398
-	);
399
-
400
-	// Notifications
401
-	if ($notifications = charger_fonction('notifications', 'inc')) {
402
-		$notifications(
403
-			'instituerarticle',
404
-			$id_article,
405
-			['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
406
-		);
407
-	}
408
-
409
-	return ''; // pas d'erreur
291
+    include_spip('inc/autoriser');
292
+    include_spip('inc/rubriques');
293
+    include_spip('inc/modifier');
294
+
295
+    $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article");
296
+    $id_rubrique = $row['id_rubrique'];
297
+    $statut_ancien = $statut = $row['statut'];
298
+    $date_ancienne = $date = $row['date'];
299
+    $champs = [];
300
+
301
+    $d = $c['date'] ?? null;
302
+    $s = $c['statut'] ?? $statut;
303
+
304
+    // cf autorisations dans inc/instituer_article
305
+    if ($s != $statut or ($d and $d != $date)) {
306
+        if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
307
+            $statut = $champs['statut'] = $s;
308
+        } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
309
+            $statut = $champs['statut'] = $s;
310
+        } else {
311
+            spip_log("editer_article $id_article refus " . join(' ', $c));
312
+        }
313
+
314
+        // En cas de publication, fixer la date a "maintenant"
315
+        // sauf si $c commande autre chose
316
+        // ou si l'article est deja date dans le futur
317
+        // En cas de proposition d'un article (mais pas depublication), idem
318
+        if (
319
+            $champs['statut'] == 'publie'
320
+            or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop'])))
321
+        ) {
322
+            if ($d or strtotime($d = $date) > time()) {
323
+                $champs['date'] = $date = $d;
324
+            } else {
325
+                $champs['date'] = $date = date('Y-m-d H:i:s');
326
+            }
327
+        }
328
+    }
329
+
330
+    // Verifier que la rubrique demandee existe et est differente
331
+    // de la rubrique actuelle
332
+    if (
333
+        isset($c['id_parent'])
334
+        and $id_parent = $c['id_parent']
335
+        and $id_parent != $id_rubrique
336
+        and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
337
+    ) {
338
+        $champs['id_rubrique'] = $id_parent;
339
+
340
+        // si l'article etait publie
341
+        // et que le demandeur n'est pas admin de la rubrique de destination
342
+        // repasser l'article en statut 'propose'.
343
+        if (
344
+            $statut == 'publie'
345
+            and !autoriser('publierdans', 'rubrique', $id_parent)
346
+        ) {
347
+            $champs['statut'] = 'prop';
348
+        }
349
+    }
350
+
351
+    // Envoyer aux plugins
352
+    $champs = pipeline(
353
+        'pre_edition',
354
+        [
355
+            'args' => [
356
+                'table' => 'spip_articles',
357
+                'id_objet' => $id_article,
358
+                'action' => 'instituer',
359
+                'statut_ancien' => $statut_ancien,
360
+                'date_ancienne' => $date_ancienne,
361
+            ],
362
+            'data' => $champs
363
+        ]
364
+    );
365
+
366
+    if (!(is_countable($champs) ? count($champs) : 0)) {
367
+        return '';
368
+    }
369
+
370
+    // Envoyer les modifs.
371
+    editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
372
+
373
+    // Invalider les caches
374
+    include_spip('inc/invalideur');
375
+    suivre_invalideur("id='article/$id_article'");
376
+
377
+    if ($date) {
378
+        $t = strtotime($date);
379
+        $p = @$GLOBALS['meta']['date_prochain_postdate'];
380
+        if ($t > time() and (!$p or ($t < $p))) {
381
+            ecrire_meta('date_prochain_postdate', $t);
382
+        }
383
+    }
384
+
385
+    // Pipeline
386
+    pipeline(
387
+        'post_edition',
388
+        [
389
+            'args' => [
390
+                'table' => 'spip_articles',
391
+                'id_objet' => $id_article,
392
+                'action' => 'instituer',
393
+                'statut_ancien' => $statut_ancien,
394
+                'date_ancienne' => $date_ancienne,
395
+            ],
396
+            'data' => $champs
397
+        ]
398
+    );
399
+
400
+    // Notifications
401
+    if ($notifications = charger_fonction('notifications', 'inc')) {
402
+        $notifications(
403
+            'instituerarticle',
404
+            $id_article,
405
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
406
+        );
407
+    }
408
+
409
+    return ''; // pas d'erreur
410 410
 }
411 411
 
412 412
 /**
@@ -431,37 +431,37 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) {
433 433
 
434
-	// Si on deplace l'article
435
-	//  changer aussi son secteur et sa langue (si heritee)
436
-	if (isset($champs['id_rubrique'])) {
437
-		$row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
438
-
439
-		$langue = $row_rub['lang'];
440
-		$champs['id_secteur'] = $row_rub['id_secteur'];
441
-		if (
442
-			sql_fetsel(
443
-				'1',
444
-				'spip_articles',
445
-				'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
446
-			)
447
-		) {
448
-			$champs['lang'] = $langue;
449
-		}
450
-	}
451
-
452
-	if (!$champs) {
453
-		return;
454
-	}
455
-
456
-	sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article));
457
-
458
-	// Changer le statut des rubriques concernees
459
-
460
-	if ($cond) {
461
-		include_spip('inc/rubriques');
462
-		$postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
463
-		calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate);
464
-	}
434
+    // Si on deplace l'article
435
+    //  changer aussi son secteur et sa langue (si heritee)
436
+    if (isset($champs['id_rubrique'])) {
437
+        $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
438
+
439
+        $langue = $row_rub['lang'];
440
+        $champs['id_secteur'] = $row_rub['id_secteur'];
441
+        if (
442
+            sql_fetsel(
443
+                '1',
444
+                'spip_articles',
445
+                'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
446
+            )
447
+        ) {
448
+            $champs['lang'] = $langue;
449
+        }
450
+    }
451
+
452
+    if (!$champs) {
453
+        return;
454
+    }
455
+
456
+    sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article));
457
+
458
+    // Changer le statut des rubriques concernees
459
+
460
+    if ($cond) {
461
+        include_spip('inc/rubriques');
462
+        $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
463
+        calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate);
464
+    }
465 465
 }
466 466
 
467 467
 /**
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
  * @return void
471 471
  */
472 472
 function trop_longs_articles() {
473
-	if (is_array($plus = _request('texte_plus'))) {
474
-		foreach ($plus as $n => $t) {
475
-			$plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t);
476
-		}
477
-		set_request('texte', join('', $plus) . _request('texte'));
478
-	}
473
+    if (is_array($plus = _request('texte_plus'))) {
474
+        foreach ($plus as $n => $t) {
475
+            $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t);
476
+        }
477
+        set_request('texte', join('', $plus) . _request('texte'));
478
+    }
479 479
 }
Please login to merge, or discard this patch.
ecrire/action/editer_objet.php 1 patch
Indentation   +513 added lines, -513 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -33,36 +33,36 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function action_editer_objet_dist($id = null, $objet = null, $set = null) {
35 35
 
36
-	// appel direct depuis une url avec arg = "objet/id"
37
-	if (is_null($id) or is_null($objet)) {
38
-		$securiser_action = charger_fonction('securiser_action', 'inc');
39
-		$arg = $securiser_action();
40
-		[$objet, $id] = array_pad(explode('/', $arg, 2), 2, null);
41
-	}
42
-
43
-	// appel incorrect ou depuis une url erronnée interdit
44
-	if (is_null($id) or is_null($objet)) {
45
-		include_spip('inc/minipres');
46
-		echo minipres(_T('info_acces_interdit'));
47
-		die();
48
-	}
49
-
50
-	// si id n'est pas un nombre, c'est une creation
51
-	// mais on verifie qu'on a toutes les donnees qu'il faut.
52
-	if (!$id = intval($id)) {
53
-		// on ne sait pas si un parent existe mais on essaye
54
-		$id_parent = _request('id_parent');
55
-		$id = objet_inserer($objet, $id_parent);
56
-	}
57
-
58
-	if (!($id = intval($id)) > 0) {
59
-		return [$id, _L('echec enregistrement en base')];
60
-	}
61
-
62
-	// Enregistre l'envoi dans la BD
63
-	$err = objet_modifier($objet, $id, $set);
64
-
65
-	return [$id, $err];
36
+    // appel direct depuis une url avec arg = "objet/id"
37
+    if (is_null($id) or is_null($objet)) {
38
+        $securiser_action = charger_fonction('securiser_action', 'inc');
39
+        $arg = $securiser_action();
40
+        [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null);
41
+    }
42
+
43
+    // appel incorrect ou depuis une url erronnée interdit
44
+    if (is_null($id) or is_null($objet)) {
45
+        include_spip('inc/minipres');
46
+        echo minipres(_T('info_acces_interdit'));
47
+        die();
48
+    }
49
+
50
+    // si id n'est pas un nombre, c'est une creation
51
+    // mais on verifie qu'on a toutes les donnees qu'il faut.
52
+    if (!$id = intval($id)) {
53
+        // on ne sait pas si un parent existe mais on essaye
54
+        $id_parent = _request('id_parent');
55
+        $id = objet_inserer($objet, $id_parent);
56
+    }
57
+
58
+    if (!($id = intval($id)) > 0) {
59
+        return [$id, _L('echec enregistrement en base')];
60
+    }
61
+
62
+    // Enregistre l'envoi dans la BD
63
+    $err = objet_modifier($objet, $id, $set);
64
+
65
+    return [$id, $err];
66 66
 }
67 67
 
68 68
 /**
@@ -75,85 +75,85 @@  discard block
 block discarded – undo
75 75
  * @return mixed|string
76 76
  */
77 77
 function objet_modifier($objet, $id, $set = null) {
78
-	if (($t = objet_type($objet)) !== $objet) {
79
-		spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
80
-		$objet = $t;
81
-	}
82
-	if (
83
-		include_spip('action/editer_' . $objet)
84
-		and function_exists($modifier = $objet . '_modifier')
85
-	) {
86
-		return $modifier($id, $set);
87
-	}
88
-
89
-	$table_sql = table_objet_sql($objet);
90
-	$trouver_table = charger_fonction('trouver_table', 'base');
91
-	$desc = $trouver_table($table_sql);
92
-	if (!$desc or !isset($desc['field'])) {
93
-		spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR);
94
-
95
-		return _L("Erreur objet $objet inconnu");
96
-	}
97
-	include_spip('inc/modifier');
98
-
99
-	$champ_date = '';
100
-	if (isset($desc['date']) and $desc['date']) {
101
-		$champ_date = $desc['date'];
102
-	} elseif (isset($desc['field']['date'])) {
103
-		$champ_date = 'date';
104
-	}
105
-
106
-	$include_list = array_keys($desc['field']);
107
-	// on ne traite pas la cle primaire par defaut, notamment car
108
-	// sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
109
-	$include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]);
110
-
111
-	if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
112
-		$include_list = $desc['champs_editables'];
113
-	}
114
-	$c = collecter_requests(
115
-		// include list
116
-		$include_list,
117
-		// exclude list
118
-		[$champ_date, 'statut', 'id_parent', 'id_secteur'],
119
-		// donnees eventuellement fournies
120
-		$set
121
-	);
122
-
123
-	// Si l'objet est publie, invalider les caches et demander sa reindexation
124
-	if (objet_test_si_publie($objet, $id)) {
125
-		$invalideur = "id='$objet/$id'";
126
-		$indexation = true;
127
-	} else {
128
-		$invalideur = '';
129
-		$indexation = false;
130
-	}
131
-
132
-	if (
133
-		$err = objet_modifier_champs(
134
-			$objet,
135
-			$id,
136
-			[
137
-			'data' => $set,
138
-			'nonvide' => '',
139
-			'invalideur' => $invalideur,
140
-			'indexation' => $indexation,
141
-			// champ a mettre a date('Y-m-d H:i:s') s'il y a modif
142
-			'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
143
-			],
144
-			$c
145
-		)
146
-	) {
147
-		return $err;
148
-	}
149
-
150
-	// Modification de statut, changement de rubrique ?
151
-	// FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
152
-	//         le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop.
153
-	$c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set);
154
-	$err = objet_instituer($objet, $id, $c);
155
-
156
-	return $err;
78
+    if (($t = objet_type($objet)) !== $objet) {
79
+        spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
80
+        $objet = $t;
81
+    }
82
+    if (
83
+        include_spip('action/editer_' . $objet)
84
+        and function_exists($modifier = $objet . '_modifier')
85
+    ) {
86
+        return $modifier($id, $set);
87
+    }
88
+
89
+    $table_sql = table_objet_sql($objet);
90
+    $trouver_table = charger_fonction('trouver_table', 'base');
91
+    $desc = $trouver_table($table_sql);
92
+    if (!$desc or !isset($desc['field'])) {
93
+        spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR);
94
+
95
+        return _L("Erreur objet $objet inconnu");
96
+    }
97
+    include_spip('inc/modifier');
98
+
99
+    $champ_date = '';
100
+    if (isset($desc['date']) and $desc['date']) {
101
+        $champ_date = $desc['date'];
102
+    } elseif (isset($desc['field']['date'])) {
103
+        $champ_date = 'date';
104
+    }
105
+
106
+    $include_list = array_keys($desc['field']);
107
+    // on ne traite pas la cle primaire par defaut, notamment car
108
+    // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
109
+    $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]);
110
+
111
+    if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
112
+        $include_list = $desc['champs_editables'];
113
+    }
114
+    $c = collecter_requests(
115
+        // include list
116
+        $include_list,
117
+        // exclude list
118
+        [$champ_date, 'statut', 'id_parent', 'id_secteur'],
119
+        // donnees eventuellement fournies
120
+        $set
121
+    );
122
+
123
+    // Si l'objet est publie, invalider les caches et demander sa reindexation
124
+    if (objet_test_si_publie($objet, $id)) {
125
+        $invalideur = "id='$objet/$id'";
126
+        $indexation = true;
127
+    } else {
128
+        $invalideur = '';
129
+        $indexation = false;
130
+    }
131
+
132
+    if (
133
+        $err = objet_modifier_champs(
134
+            $objet,
135
+            $id,
136
+            [
137
+            'data' => $set,
138
+            'nonvide' => '',
139
+            'invalideur' => $invalideur,
140
+            'indexation' => $indexation,
141
+            // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
142
+            'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
143
+            ],
144
+            $c
145
+        )
146
+    ) {
147
+        return $err;
148
+    }
149
+
150
+    // Modification de statut, changement de rubrique ?
151
+    // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
152
+    //         le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop.
153
+    $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set);
154
+    $err = objet_instituer($objet, $id, $c);
155
+
156
+    return $err;
157 157
 }
158 158
 
159 159
 /**
@@ -168,135 +168,135 @@  discard block
 block discarded – undo
168 168
  * @return bool|int
169 169
  */
170 170
 function objet_inserer($objet, $id_parent = null, $set = null) {
171
-	$d = null;
172
-	if (($t = objet_type($objet)) !== $objet) {
173
-		spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
174
-		$objet = $t;
175
-	}
176
-	if (
177
-		include_spip('action/editer_' . $objet)
178
-		and function_exists($inserer = $objet . '_inserer')
179
-	) {
180
-		return $inserer($id_parent, $set);
181
-	}
182
-
183
-	$table_sql = table_objet_sql($objet);
184
-	$trouver_table = charger_fonction('trouver_table', 'base');
185
-	$desc = $trouver_table($table_sql);
186
-	if (!$desc or !isset($desc['field'])) {
187
-		return 0;
188
-	}
189
-
190
-	$lang_rub = '';
191
-	$champs = [];
192
-	if (isset($desc['field']['id_rubrique'])) {
193
-		// Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
194
-		// dans la premiere rubrique racine
195
-		if (!$id_rubrique = intval($id_parent)) {
196
-			$row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
197
-			$id_rubrique = $row['id_rubrique'];
198
-		} else {
199
-			$row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
200
-		}
201
-
202
-		$champs['id_rubrique'] = $id_rubrique;
203
-		if (isset($desc['field']['id_secteur'])) {
204
-			$champs['id_secteur'] = $row['id_secteur'];
205
-		}
206
-		$lang_rub = $row['lang'];
207
-	}
208
-
209
-	// La langue a la creation : si les liens de traduction sont autorises
210
-	// dans les rubriques, on essaie avec la langue de l'auteur,
211
-	// ou a defaut celle de la rubrique
212
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
213
-	if (
214
-		isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array(
215
-			$table_sql,
216
-			explode(',', $GLOBALS['meta']['multi_objets'])
217
-		)
218
-	) {
219
-		lang_select($GLOBALS['visiteur_session']['lang']);
220
-		if (
221
-			in_array(
222
-				$GLOBALS['spip_lang'],
223
-				explode(',', $GLOBALS['meta']['langues_multilingue'])
224
-			)
225
-		) {
226
-			$champs['lang'] = $GLOBALS['spip_lang'];
227
-			if (isset($desc['field']['langue_choisie'])) {
228
-				$champs['langue_choisie'] = 'oui';
229
-			}
230
-		}
231
-	} elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
232
-		$champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']);
233
-		$champs['langue_choisie'] = 'non';
234
-	}
235
-
236
-	if (isset($desc['field']['statut'])) {
237
-		if (isset($desc['statut_textes_instituer'])) {
238
-			$cles_statut = array_keys($desc['statut_textes_instituer']);
239
-			$champs['statut'] = reset($cles_statut);
240
-		} else {
241
-			$champs['statut'] = 'prepa';
242
-		}
243
-	}
244
-
245
-
246
-	if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
247
-		$champs[$d] = date('Y-m-d H:i:s');
248
-	}
249
-
250
-	if ($set) {
251
-		$champs = array_merge($champs, $set);
252
-	}
253
-
254
-	// Envoyer aux plugins
255
-	$champs = pipeline(
256
-		'pre_insertion',
257
-		[
258
-			'args' => [
259
-				'table' => $table_sql,
260
-				'id_parent' => $id_parent,
261
-			],
262
-			'data' => $champs
263
-		]
264
-	);
265
-
266
-	$id = sql_insertq($table_sql, $champs);
267
-
268
-	if ($id) {
269
-		// controler si le serveur n'a pas renvoye une erreur
270
-		// et associer l'auteur sinon
271
-		// si la table n'a pas deja un champ id_auteur
272
-		// et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
273
-		if (
274
-			$id > 0
275
-			and !isset($desc['field']['id_auteur'])
276
-		) {
277
-			$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
278
-				$GLOBALS['visiteur_session']['id_auteur']
279
-				: _request('id_auteur'));
280
-			if ($id_auteur) {
281
-				include_spip('action/editer_auteur');
282
-				auteur_associer($id_auteur, [$objet => $id]);
283
-			}
284
-		}
285
-
286
-		pipeline(
287
-			'post_insertion',
288
-			[
289
-				'args' => [
290
-					'table' => $table_sql,
291
-					'id_parent' => $id_parent,
292
-					'id_objet' => $id,
293
-				],
294
-				'data' => $champs
295
-			]
296
-		);
297
-	}
298
-
299
-	return $id;
171
+    $d = null;
172
+    if (($t = objet_type($objet)) !== $objet) {
173
+        spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
174
+        $objet = $t;
175
+    }
176
+    if (
177
+        include_spip('action/editer_' . $objet)
178
+        and function_exists($inserer = $objet . '_inserer')
179
+    ) {
180
+        return $inserer($id_parent, $set);
181
+    }
182
+
183
+    $table_sql = table_objet_sql($objet);
184
+    $trouver_table = charger_fonction('trouver_table', 'base');
185
+    $desc = $trouver_table($table_sql);
186
+    if (!$desc or !isset($desc['field'])) {
187
+        return 0;
188
+    }
189
+
190
+    $lang_rub = '';
191
+    $champs = [];
192
+    if (isset($desc['field']['id_rubrique'])) {
193
+        // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
194
+        // dans la premiere rubrique racine
195
+        if (!$id_rubrique = intval($id_parent)) {
196
+            $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
197
+            $id_rubrique = $row['id_rubrique'];
198
+        } else {
199
+            $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
200
+        }
201
+
202
+        $champs['id_rubrique'] = $id_rubrique;
203
+        if (isset($desc['field']['id_secteur'])) {
204
+            $champs['id_secteur'] = $row['id_secteur'];
205
+        }
206
+        $lang_rub = $row['lang'];
207
+    }
208
+
209
+    // La langue a la creation : si les liens de traduction sont autorises
210
+    // dans les rubriques, on essaie avec la langue de l'auteur,
211
+    // ou a defaut celle de la rubrique
212
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
213
+    if (
214
+        isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array(
215
+            $table_sql,
216
+            explode(',', $GLOBALS['meta']['multi_objets'])
217
+        )
218
+    ) {
219
+        lang_select($GLOBALS['visiteur_session']['lang']);
220
+        if (
221
+            in_array(
222
+                $GLOBALS['spip_lang'],
223
+                explode(',', $GLOBALS['meta']['langues_multilingue'])
224
+            )
225
+        ) {
226
+            $champs['lang'] = $GLOBALS['spip_lang'];
227
+            if (isset($desc['field']['langue_choisie'])) {
228
+                $champs['langue_choisie'] = 'oui';
229
+            }
230
+        }
231
+    } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
232
+        $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']);
233
+        $champs['langue_choisie'] = 'non';
234
+    }
235
+
236
+    if (isset($desc['field']['statut'])) {
237
+        if (isset($desc['statut_textes_instituer'])) {
238
+            $cles_statut = array_keys($desc['statut_textes_instituer']);
239
+            $champs['statut'] = reset($cles_statut);
240
+        } else {
241
+            $champs['statut'] = 'prepa';
242
+        }
243
+    }
244
+
245
+
246
+    if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
247
+        $champs[$d] = date('Y-m-d H:i:s');
248
+    }
249
+
250
+    if ($set) {
251
+        $champs = array_merge($champs, $set);
252
+    }
253
+
254
+    // Envoyer aux plugins
255
+    $champs = pipeline(
256
+        'pre_insertion',
257
+        [
258
+            'args' => [
259
+                'table' => $table_sql,
260
+                'id_parent' => $id_parent,
261
+            ],
262
+            'data' => $champs
263
+        ]
264
+    );
265
+
266
+    $id = sql_insertq($table_sql, $champs);
267
+
268
+    if ($id) {
269
+        // controler si le serveur n'a pas renvoye une erreur
270
+        // et associer l'auteur sinon
271
+        // si la table n'a pas deja un champ id_auteur
272
+        // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
273
+        if (
274
+            $id > 0
275
+            and !isset($desc['field']['id_auteur'])
276
+        ) {
277
+            $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
278
+                $GLOBALS['visiteur_session']['id_auteur']
279
+                : _request('id_auteur'));
280
+            if ($id_auteur) {
281
+                include_spip('action/editer_auteur');
282
+                auteur_associer($id_auteur, [$objet => $id]);
283
+            }
284
+        }
285
+
286
+        pipeline(
287
+            'post_insertion',
288
+            [
289
+                'args' => [
290
+                    'table' => $table_sql,
291
+                    'id_parent' => $id_parent,
292
+                    'id_objet' => $id,
293
+                ],
294
+                'data' => $champs
295
+            ]
296
+        );
297
+    }
298
+
299
+    return $id;
300 300
 }
301 301
 
302 302
 
@@ -313,138 +313,138 @@  discard block
 block discarded – undo
313 313
  * @return string
314 314
  */
315 315
 function objet_instituer($objet, $id, $c, $calcul_rub = true) {
316
-	if (($t = objet_type($objet)) !== $objet) {
317
-		spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
318
-		$objet = $t;
319
-	}
320
-	if (
321
-		include_spip('action/editer_' . $objet)
322
-		and function_exists($instituer = $objet . '_instituer')
323
-	) {
324
-		return $instituer($id, $c, $calcul_rub);
325
-	}
326
-
327
-	$table_sql = table_objet_sql($objet);
328
-	$trouver_table = charger_fonction('trouver_table', 'base');
329
-	$desc = $trouver_table($table_sql);
330
-	if (!$desc or !isset($desc['field'])) {
331
-		return _L("Impossible d'instituer $objet : non connu en base");
332
-	}
333
-
334
-	include_spip('inc/autoriser');
335
-	include_spip('inc/rubriques');
336
-	include_spip('inc/modifier');
337
-
338
-	$sel = [];
339
-	$sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut");
340
-
341
-	$champ_date = '';
342
-	if (isset($desc['date']) and $desc['date']) {
343
-		$champ_date = $desc['date'];
344
-	} elseif (isset($desc['field']['date'])) {
345
-		$champ_date = 'date';
346
-	}
347
-
348
-	$sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
349
-	$sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique');
350
-
351
-	$row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
352
-
353
-	$id_rubrique = $row['id_rubrique'];
354
-	$statut_ancien = $statut = $row['statut'];
355
-	$date_ancienne = $date = $row['date'];
356
-	$champs = [];
357
-
358
-	$d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
359
-	$s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
360
-
361
-	// cf autorisations dans inc/instituer_objet
362
-	if ($s != $statut or ($d and $d != $date)) {
363
-		if (
364
-			$id_rubrique ?
365
-			autoriser('publierdans', 'rubrique', $id_rubrique)
366
-			:
367
-			autoriser('instituer', $objet, $id, null, ['statut' => $s])
368
-		) {
369
-			$statut = $champs['statut'] = $s;
370
-		} else {
371
-			if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
372
-				$statut = $champs['statut'] = $s;
373
-			} else {
374
-				spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE);
375
-			}
376
-		}
377
-
378
-		// En cas de publication, fixer la date a "maintenant"
379
-		// sauf si $c commande autre chose
380
-		// ou si l'objet est deja date dans le futur
381
-		// En cas de proposition d'un objet (mais pas depublication), idem
382
-		if ($champ_date) {
383
-			if (
384
-				$champs['statut'] == 'publie'
385
-				or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop']))
386
-				or $d
387
-			) {
388
-				if ($d or strtotime($d = $date) > time()) {
389
-					$champs[$champ_date] = $date = $d;
390
-				} else {
391
-					$champs[$champ_date] = $date = date('Y-m-d H:i:s');
392
-				}
393
-			}
394
-		}
395
-	}
396
-
397
-	// Verifier que la rubrique demandee existe et est differente
398
-	// de la rubrique actuelle
399
-	if (
400
-		$id_rubrique
401
-		and isset($c['id_parent'])
402
-		and $id_parent = $c['id_parent']
403
-		and $id_parent != $id_rubrique
404
-		and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
405
-	) {
406
-		$champs['id_rubrique'] = $id_parent;
407
-
408
-		// si l'objet etait publie
409
-		// et que le demandeur n'est pas admin de la rubrique
410
-		// repasser l'objet en statut 'propose'.
411
-		if (
412
-			$statut == 'publie'
413
-			and !autoriser('publierdans', 'rubrique', $id_rubrique)
414
-		) {
415
-			$champs['statut'] = 'prop';
416
-		}
417
-	}
418
-
419
-
420
-	// Envoyer aux plugins
421
-	$champs = pipeline(
422
-		'pre_edition',
423
-		[
424
-			'args' => [
425
-				'table' => $table_sql,
426
-				'id_objet' => $id,
427
-				'action' => 'instituer',
428
-				'statut_ancien' => $statut_ancien,
429
-				'date_ancienne' => $date_ancienne,
430
-				'id_parent_ancien' => $id_rubrique,
431
-			],
432
-			'data' => $champs
433
-		]
434
-	);
435
-
436
-	if (!(is_countable($champs) ? count($champs) : 0)) {
437
-		return '';
438
-	}
439
-
440
-	// Envoyer les modifs.
441
-	objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
442
-
443
-	// Invalider les caches
444
-	include_spip('inc/invalideur');
445
-	suivre_invalideur("id='$objet/$id'");
446
-
447
-	/*
316
+    if (($t = objet_type($objet)) !== $objet) {
317
+        spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
318
+        $objet = $t;
319
+    }
320
+    if (
321
+        include_spip('action/editer_' . $objet)
322
+        and function_exists($instituer = $objet . '_instituer')
323
+    ) {
324
+        return $instituer($id, $c, $calcul_rub);
325
+    }
326
+
327
+    $table_sql = table_objet_sql($objet);
328
+    $trouver_table = charger_fonction('trouver_table', 'base');
329
+    $desc = $trouver_table($table_sql);
330
+    if (!$desc or !isset($desc['field'])) {
331
+        return _L("Impossible d'instituer $objet : non connu en base");
332
+    }
333
+
334
+    include_spip('inc/autoriser');
335
+    include_spip('inc/rubriques');
336
+    include_spip('inc/modifier');
337
+
338
+    $sel = [];
339
+    $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut");
340
+
341
+    $champ_date = '';
342
+    if (isset($desc['date']) and $desc['date']) {
343
+        $champ_date = $desc['date'];
344
+    } elseif (isset($desc['field']['date'])) {
345
+        $champ_date = 'date';
346
+    }
347
+
348
+    $sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
349
+    $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique');
350
+
351
+    $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
352
+
353
+    $id_rubrique = $row['id_rubrique'];
354
+    $statut_ancien = $statut = $row['statut'];
355
+    $date_ancienne = $date = $row['date'];
356
+    $champs = [];
357
+
358
+    $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
359
+    $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
360
+
361
+    // cf autorisations dans inc/instituer_objet
362
+    if ($s != $statut or ($d and $d != $date)) {
363
+        if (
364
+            $id_rubrique ?
365
+            autoriser('publierdans', 'rubrique', $id_rubrique)
366
+            :
367
+            autoriser('instituer', $objet, $id, null, ['statut' => $s])
368
+        ) {
369
+            $statut = $champs['statut'] = $s;
370
+        } else {
371
+            if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
372
+                $statut = $champs['statut'] = $s;
373
+            } else {
374
+                spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE);
375
+            }
376
+        }
377
+
378
+        // En cas de publication, fixer la date a "maintenant"
379
+        // sauf si $c commande autre chose
380
+        // ou si l'objet est deja date dans le futur
381
+        // En cas de proposition d'un objet (mais pas depublication), idem
382
+        if ($champ_date) {
383
+            if (
384
+                $champs['statut'] == 'publie'
385
+                or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop']))
386
+                or $d
387
+            ) {
388
+                if ($d or strtotime($d = $date) > time()) {
389
+                    $champs[$champ_date] = $date = $d;
390
+                } else {
391
+                    $champs[$champ_date] = $date = date('Y-m-d H:i:s');
392
+                }
393
+            }
394
+        }
395
+    }
396
+
397
+    // Verifier que la rubrique demandee existe et est differente
398
+    // de la rubrique actuelle
399
+    if (
400
+        $id_rubrique
401
+        and isset($c['id_parent'])
402
+        and $id_parent = $c['id_parent']
403
+        and $id_parent != $id_rubrique
404
+        and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
405
+    ) {
406
+        $champs['id_rubrique'] = $id_parent;
407
+
408
+        // si l'objet etait publie
409
+        // et que le demandeur n'est pas admin de la rubrique
410
+        // repasser l'objet en statut 'propose'.
411
+        if (
412
+            $statut == 'publie'
413
+            and !autoriser('publierdans', 'rubrique', $id_rubrique)
414
+        ) {
415
+            $champs['statut'] = 'prop';
416
+        }
417
+    }
418
+
419
+
420
+    // Envoyer aux plugins
421
+    $champs = pipeline(
422
+        'pre_edition',
423
+        [
424
+            'args' => [
425
+                'table' => $table_sql,
426
+                'id_objet' => $id,
427
+                'action' => 'instituer',
428
+                'statut_ancien' => $statut_ancien,
429
+                'date_ancienne' => $date_ancienne,
430
+                'id_parent_ancien' => $id_rubrique,
431
+            ],
432
+            'data' => $champs
433
+        ]
434
+    );
435
+
436
+    if (!(is_countable($champs) ? count($champs) : 0)) {
437
+        return '';
438
+    }
439
+
440
+    // Envoyer les modifs.
441
+    objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
442
+
443
+    // Invalider les caches
444
+    include_spip('inc/invalideur');
445
+    suivre_invalideur("id='$objet/$id'");
446
+
447
+    /*
448 448
 	if ($date) {
449 449
 		$t = strtotime($date);
450 450
 		$p = @$GLOBALS['meta']['date_prochain_postdate'];
@@ -453,32 +453,32 @@  discard block
 block discarded – undo
453 453
 		}
454 454
 	}*/
455 455
 
456
-	// Pipeline
457
-	pipeline(
458
-		'post_edition',
459
-		[
460
-			'args' => [
461
-				'table' => $table_sql,
462
-				'id_objet' => $id,
463
-				'action' => 'instituer',
464
-				'statut_ancien' => $statut_ancien,
465
-				'date_ancienne' => $date_ancienne,
466
-				'id_parent_ancien' => $id_rubrique,
467
-			],
468
-			'data' => $champs
469
-		]
470
-	);
471
-
472
-	// Notifications
473
-	if ($notifications = charger_fonction('notifications', 'inc')) {
474
-		$notifications(
475
-			"instituer$objet",
476
-			$id,
477
-			['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
478
-		);
479
-	}
480
-
481
-	return ''; // pas d'erreur
456
+    // Pipeline
457
+    pipeline(
458
+        'post_edition',
459
+        [
460
+            'args' => [
461
+                'table' => $table_sql,
462
+                'id_objet' => $id,
463
+                'action' => 'instituer',
464
+                'statut_ancien' => $statut_ancien,
465
+                'date_ancienne' => $date_ancienne,
466
+                'id_parent_ancien' => $id_rubrique,
467
+            ],
468
+            'data' => $champs
469
+        ]
470
+    );
471
+
472
+    // Notifications
473
+    if ($notifications = charger_fonction('notifications', 'inc')) {
474
+        $notifications(
475
+            "instituer$objet",
476
+            $id,
477
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
478
+        );
479
+    }
480
+
481
+    return ''; // pas d'erreur
482 482
 }
483 483
 
484 484
 /**
@@ -493,51 +493,51 @@  discard block
 block discarded – undo
493 493
  * @return void
494 494
  */
495 495
 function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) {
496
-	$table_sql = table_objet_sql($objet);
497
-	$trouver_table = charger_fonction('trouver_table', 'base');
498
-	$desc = $trouver_table($table_sql);
499
-
500
-	// Si on deplace l'objet
501
-	// changer aussi son secteur et sa langue (si heritee)
502
-	if (isset($champs['id_rubrique'])) {
503
-		$row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
504
-		$langue = $row_rub['lang'];
505
-
506
-		if (isset($desc['field']['id_secteur'])) {
507
-			$champs['id_secteur'] = $row_rub['id_secteur'];
508
-		}
509
-
510
-		if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
511
-			if (
512
-				sql_fetsel(
513
-					'1',
514
-					$table_sql,
515
-					id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
516
-				)
517
-			) {
518
-				$champs['lang'] = $langue;
519
-			}
520
-		}
521
-	}
522
-
523
-	if (!$champs) {
524
-		return;
525
-	}
526
-	sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
527
-
528
-	// Changer le statut des rubriques concernees
529
-	if ($cond) {
530
-		include_spip('inc/rubriques');
531
-		//$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
532
-		$postdate = false;
533
-		// On rajoute les infos de l'objet
534
-		$infos = [
535
-			'objet' => $objet,
536
-			'id_objet' => $id,
537
-			'statut_ancien' => $statut,
538
-		];
539
-		calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate);
540
-	}
496
+    $table_sql = table_objet_sql($objet);
497
+    $trouver_table = charger_fonction('trouver_table', 'base');
498
+    $desc = $trouver_table($table_sql);
499
+
500
+    // Si on deplace l'objet
501
+    // changer aussi son secteur et sa langue (si heritee)
502
+    if (isset($champs['id_rubrique'])) {
503
+        $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
504
+        $langue = $row_rub['lang'];
505
+
506
+        if (isset($desc['field']['id_secteur'])) {
507
+            $champs['id_secteur'] = $row_rub['id_secteur'];
508
+        }
509
+
510
+        if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
511
+            if (
512
+                sql_fetsel(
513
+                    '1',
514
+                    $table_sql,
515
+                    id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
516
+                )
517
+            ) {
518
+                $champs['lang'] = $langue;
519
+            }
520
+        }
521
+    }
522
+
523
+    if (!$champs) {
524
+        return;
525
+    }
526
+    sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
527
+
528
+    // Changer le statut des rubriques concernees
529
+    if ($cond) {
530
+        include_spip('inc/rubriques');
531
+        //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
532
+        $postdate = false;
533
+        // On rajoute les infos de l'objet
534
+        $infos = [
535
+            'objet' => $objet,
536
+            'id_objet' => $id,
537
+            'statut_ancien' => $statut,
538
+        ];
539
+        calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate);
540
+    }
541 541
 }
542 542
 
543 543
 
@@ -566,75 +566,75 @@  discard block
 block discarded – undo
566 566
  *     string|int : valeur du champ demande pour l'objet demande
567 567
  */
568 568
 function objet_lire($objet, $valeur_id, $options = []) {
569
-	if (($t = objet_type($objet)) !== $objet) {
570
-		spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
571
-		$objet = $t;
572
-	}
573
-
574
-	// tableau du cache des descriptions et des id d'objet (au sens id_xxx).
575
-	// Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle]
576
-	static $descriptions = [];
577
-
578
-	// On détermine le nom du champ id de la table.
579
-	include_spip('base/objets');
580
-	$primary = id_table_objet($objet);
581
-
582
-	// On détermine l'id à utiliser.
583
-	$champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary);
584
-
585
-	// Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète.
586
-	if (
587
-		!isset($descriptions[$objet][$champ_id][$valeur_id])
588
-		or (isset($options['force']) and $options['force'])
589
-	) {
590
-		// Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet.
591
-		if (
592
-			include_spip('action/editer_' . $objet)
593
-			and function_exists($lire = "${objet}_lire_champs")
594
-		) {
595
-			$valeurs = $lire($objet, $valeur_id, $champ_id);
596
-		} else {
597
-			// On récupère la table SQL à partir du type d'objet.
598
-			$table = table_objet_sql($objet);
599
-
600
-			// La condition est appliquée sur le champ désigné par l'utilisateur.
601
-			$where = [
602
-				"${champ_id}=" . sql_quote($valeur_id)
603
-			];
604
-
605
-			// Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide.
606
-			$valeurs = sql_fetsel('*', $table, $where);
607
-		}
608
-
609
-		if (!$valeurs) {
610
-			$valeurs = false;
611
-		}
612
-
613
-		$descriptions[$objet][$champ_id][$valeur_id] = $valeurs;
614
-
615
-		if ($champ_id !== $primary and isset($valeurs[$primary])) {
616
-			$descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs;
617
-			$descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]];
618
-		}
619
-	}
620
-
621
-	$retour = $descriptions[$objet][$champ_id][$valeur_id];
622
-
623
-	// On ne retourne maintenant que les champs demandés.
624
-	// - on détermine les informations à renvoyer.
625
-	if ($retour and !empty($options['champs'])) {
626
-		$champs = $options['champs'];
627
-		// Extraction des seules informations demandées.
628
-		// -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau.
629
-		// -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur.
630
-		if (is_array($champs)) {
631
-			// Tableau des informations valides
632
-			$retour = array_intersect_key($retour, array_flip($champs));
633
-		} else {
634
-			// Valeur unique demandée.
635
-			$retour = ($retour[$champs] ?? false);
636
-		}
637
-	}
638
-
639
-	return $retour;
569
+    if (($t = objet_type($objet)) !== $objet) {
570
+        spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
571
+        $objet = $t;
572
+    }
573
+
574
+    // tableau du cache des descriptions et des id d'objet (au sens id_xxx).
575
+    // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle]
576
+    static $descriptions = [];
577
+
578
+    // On détermine le nom du champ id de la table.
579
+    include_spip('base/objets');
580
+    $primary = id_table_objet($objet);
581
+
582
+    // On détermine l'id à utiliser.
583
+    $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary);
584
+
585
+    // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète.
586
+    if (
587
+        !isset($descriptions[$objet][$champ_id][$valeur_id])
588
+        or (isset($options['force']) and $options['force'])
589
+    ) {
590
+        // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet.
591
+        if (
592
+            include_spip('action/editer_' . $objet)
593
+            and function_exists($lire = "${objet}_lire_champs")
594
+        ) {
595
+            $valeurs = $lire($objet, $valeur_id, $champ_id);
596
+        } else {
597
+            // On récupère la table SQL à partir du type d'objet.
598
+            $table = table_objet_sql($objet);
599
+
600
+            // La condition est appliquée sur le champ désigné par l'utilisateur.
601
+            $where = [
602
+                "${champ_id}=" . sql_quote($valeur_id)
603
+            ];
604
+
605
+            // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide.
606
+            $valeurs = sql_fetsel('*', $table, $where);
607
+        }
608
+
609
+        if (!$valeurs) {
610
+            $valeurs = false;
611
+        }
612
+
613
+        $descriptions[$objet][$champ_id][$valeur_id] = $valeurs;
614
+
615
+        if ($champ_id !== $primary and isset($valeurs[$primary])) {
616
+            $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs;
617
+            $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]];
618
+        }
619
+    }
620
+
621
+    $retour = $descriptions[$objet][$champ_id][$valeur_id];
622
+
623
+    // On ne retourne maintenant que les champs demandés.
624
+    // - on détermine les informations à renvoyer.
625
+    if ($retour and !empty($options['champs'])) {
626
+        $champs = $options['champs'];
627
+        // Extraction des seules informations demandées.
628
+        // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau.
629
+        // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur.
630
+        if (is_array($champs)) {
631
+            // Tableau des informations valides
632
+            $retour = array_intersect_key($retour, array_flip($champs));
633
+        } else {
634
+            // Valeur unique demandée.
635
+            $retour = ($retour[$champs] ?? false);
636
+        }
637
+    }
638
+
639
+    return $retour;
640 640
 }
Please login to merge, or discard this patch.
ecrire/action/editer_rubrique.php 1 patch
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Rubriques\Edition
17 17
  */
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/rubriques');
@@ -38,34 +38,34 @@  discard block
 block discarded – undo
38 38
  */
39 39
 function action_editer_rubrique_dist($arg = null) {
40 40
 
41
-	if (is_null($arg)) {
42
-		$securiser_action = charger_fonction('securiser_action', 'inc');
43
-		$arg = $securiser_action();
44
-	}
45
-
46
-	if (!$id_rubrique = intval($arg)) {
47
-		if ($arg != 'oui') {
48
-			include_spip('inc/headers');
49
-			redirige_url_ecrire();
50
-		}
51
-		$id_rubrique = rubrique_inserer(_request('id_parent'));
52
-	}
53
-
54
-	$err = rubrique_modifier($id_rubrique);
55
-
56
-	if (_request('redirect')) {
57
-		$redirect = parametre_url(
58
-			urldecode(_request('redirect')),
59
-			'id_rubrique',
60
-			$id_rubrique,
61
-			'&'
62
-		);
63
-
64
-		include_spip('inc/headers');
65
-		redirige_par_entete($redirect);
66
-	}
67
-
68
-	return [$id_rubrique, $err];
41
+    if (is_null($arg)) {
42
+        $securiser_action = charger_fonction('securiser_action', 'inc');
43
+        $arg = $securiser_action();
44
+    }
45
+
46
+    if (!$id_rubrique = intval($arg)) {
47
+        if ($arg != 'oui') {
48
+            include_spip('inc/headers');
49
+            redirige_url_ecrire();
50
+        }
51
+        $id_rubrique = rubrique_inserer(_request('id_parent'));
52
+    }
53
+
54
+    $err = rubrique_modifier($id_rubrique);
55
+
56
+    if (_request('redirect')) {
57
+        $redirect = parametre_url(
58
+            urldecode(_request('redirect')),
59
+            'id_rubrique',
60
+            $id_rubrique,
61
+            '&'
62
+        );
63
+
64
+        include_spip('inc/headers');
65
+        redirige_par_entete($redirect);
66
+    }
67
+
68
+    return [$id_rubrique, $err];
69 69
 }
70 70
 
71 71
 
@@ -80,42 +80,42 @@  discard block
 block discarded – undo
80 80
  *     Identifiant de la rubrique crée
81 81
  */
82 82
 function rubrique_inserer($id_parent, $set = null) {
83
-	$champs = [
84
-		'titre' => _T('item_nouvelle_rubrique'),
85
-		'id_parent' => intval($id_parent),
86
-		'statut' => 'prepa'
87
-	];
88
-
89
-	if ($set) {
90
-		$champs = array_merge($champs, $set);
91
-	}
92
-
93
-	// Envoyer aux plugins
94
-	$champs = pipeline(
95
-		'pre_insertion',
96
-		[
97
-			'args' => [
98
-				'table' => 'spip_rubriques',
99
-			],
100
-			'data' => $champs
101
-		]
102
-	);
103
-
104
-	$id_rubrique = sql_insertq('spip_rubriques', $champs);
105
-	pipeline(
106
-		'post_insertion',
107
-		[
108
-			'args' => [
109
-				'table' => 'spip_rubriques',
110
-				'id_objet' => $id_rubrique
111
-			],
112
-			'data' => $champs
113
-		]
114
-	);
115
-	propager_les_secteurs();
116
-	calculer_langues_rubriques();
117
-
118
-	return $id_rubrique;
83
+    $champs = [
84
+        'titre' => _T('item_nouvelle_rubrique'),
85
+        'id_parent' => intval($id_parent),
86
+        'statut' => 'prepa'
87
+    ];
88
+
89
+    if ($set) {
90
+        $champs = array_merge($champs, $set);
91
+    }
92
+
93
+    // Envoyer aux plugins
94
+    $champs = pipeline(
95
+        'pre_insertion',
96
+        [
97
+            'args' => [
98
+                'table' => 'spip_rubriques',
99
+            ],
100
+            'data' => $champs
101
+        ]
102
+    );
103
+
104
+    $id_rubrique = sql_insertq('spip_rubriques', $champs);
105
+    pipeline(
106
+        'post_insertion',
107
+        [
108
+            'args' => [
109
+                'table' => 'spip_rubriques',
110
+                'id_objet' => $id_rubrique
111
+            ],
112
+            'data' => $champs
113
+        ]
114
+    );
115
+    propager_les_secteurs();
116
+    calculer_langues_rubriques();
117
+
118
+    return $id_rubrique;
119 119
 }
120 120
 
121 121
 /**
@@ -131,46 +131,46 @@  discard block
 block discarded – undo
131 131
  *     - chaîne : Texte d'un message d'erreur
132 132
  */
133 133
 function rubrique_modifier($id_rubrique, $set = null) {
134
-	include_spip('inc/autoriser');
135
-	include_spip('inc/filtres');
136
-
137
-	include_spip('inc/modifier');
138
-	$c = collecter_requests(
139
-		// include list
140
-		objet_info('rubrique', 'champs_editables'),
141
-		// exclude list
142
-		['id_parent', 'confirme_deplace'],
143
-		// donnees eventuellement fournies
144
-		$set
145
-	);
146
-
147
-	if (
148
-		$err = objet_modifier_champs(
149
-			'rubrique',
150
-			$id_rubrique,
151
-			[
152
-			'data' => $set,
153
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
154
-			],
155
-			$c
156
-		)
157
-	) {
158
-		return $err;
159
-	}
160
-
161
-	$c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
162
-	// Deplacer la rubrique
163
-	if (isset($c['id_parent'])) {
164
-		$err = rubrique_instituer($id_rubrique, $c);
165
-	}
166
-
167
-	// invalider les caches marques de cette rubrique
168
-	include_spip('inc/invalideur');
169
-	suivre_invalideur("id='rubrique/$id_rubrique'");
170
-	// et celui de menu_rubriques
171
-	effacer_meta('date_calcul_rubriques');
172
-
173
-	return $err;
134
+    include_spip('inc/autoriser');
135
+    include_spip('inc/filtres');
136
+
137
+    include_spip('inc/modifier');
138
+    $c = collecter_requests(
139
+        // include list
140
+        objet_info('rubrique', 'champs_editables'),
141
+        // exclude list
142
+        ['id_parent', 'confirme_deplace'],
143
+        // donnees eventuellement fournies
144
+        $set
145
+    );
146
+
147
+    if (
148
+        $err = objet_modifier_champs(
149
+            'rubrique',
150
+            $id_rubrique,
151
+            [
152
+            'data' => $set,
153
+            'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
154
+            ],
155
+            $c
156
+        )
157
+    ) {
158
+        return $err;
159
+    }
160
+
161
+    $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
162
+    // Deplacer la rubrique
163
+    if (isset($c['id_parent'])) {
164
+        $err = rubrique_instituer($id_rubrique, $c);
165
+    }
166
+
167
+    // invalider les caches marques de cette rubrique
168
+    include_spip('inc/invalideur');
169
+    suivre_invalideur("id='rubrique/$id_rubrique'");
170
+    // et celui de menu_rubriques
171
+    effacer_meta('date_calcul_rubriques');
172
+
173
+    return $err;
174 174
 }
175 175
 
176 176
 /**
@@ -193,25 +193,25 @@  discard block
 block discarded – undo
193 193
  *     false si la confirmation du déplacement n'est pas présente
194 194
  */
195 195
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) {
196
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
197
-		return true;
198
-	}
199
-
200
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
201
-		return false;
202
-	}
203
-
204
-	if (
205
-		$id_secteur = sql_getfetsel(
206
-			'id_secteur',
207
-			'spip_rubriques',
208
-			"id_rubrique=$id_parent"
209
-		)
210
-	) {
211
-		sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
212
-	}
213
-
214
-	return true;
196
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
197
+        return true;
198
+    }
199
+
200
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
201
+        return false;
202
+    }
203
+
204
+    if (
205
+        $id_secteur = sql_getfetsel(
206
+            'id_secteur',
207
+            'spip_rubriques',
208
+            "id_rubrique=$id_parent"
209
+        )
210
+    ) {
211
+        sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
212
+    }
213
+
214
+    return true;
215 215
 }
216 216
 
217 217
 
@@ -233,50 +233,50 @@  discard block
 block discarded – undo
233 233
  *     Chaîne : Texte du message d'erreur
234 234
  */
235 235
 function rubrique_instituer($id_rubrique, $c) {
236
-	// traitement de la rubrique parente
237
-	// interdiction de deplacer vers ou a partir d'une rubrique
238
-	// qu'on n'administre pas.
239
-
240
-	if (null !== ($id_parent = $c['id_parent'])) {
241
-		$id_parent = intval($id_parent);
242
-		$filles = calcul_branche_in($id_rubrique);
243
-		if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
244
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
245
-		} else {
246
-			$s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
247
-			$old_parent = $s['id_parent'];
248
-
249
-			if (
250
-				!($id_parent != $old_parent
251
-				and autoriser('publierdans', 'rubrique', $id_parent)
252
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
253
-				and autoriser('publierdans', 'rubrique', $old_parent)
254
-				)
255
-			) {
256
-				if ($s['statut'] != 'new') {
257
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
258
-				}
259
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260
-				$statut_ancien = $s['statut'];
261
-				sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
262
-
263
-
264
-				propager_les_secteurs();
265
-
266
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
267
-				if ($statut_ancien == 'publie') {
268
-					calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
269
-				}
270
-				// Creation ou deplacement d'une rubrique non publiee
271
-				// invalider le cache de leur menu
272
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
273
-					effacer_meta('date_calcul_rubriques');
274
-				}
275
-
276
-				calculer_langues_rubriques();
277
-			}
278
-		}
279
-	}
280
-
281
-	return ''; // pas d'erreur
236
+    // traitement de la rubrique parente
237
+    // interdiction de deplacer vers ou a partir d'une rubrique
238
+    // qu'on n'administre pas.
239
+
240
+    if (null !== ($id_parent = $c['id_parent'])) {
241
+        $id_parent = intval($id_parent);
242
+        $filles = calcul_branche_in($id_rubrique);
243
+        if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
244
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
245
+        } else {
246
+            $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
247
+            $old_parent = $s['id_parent'];
248
+
249
+            if (
250
+                !($id_parent != $old_parent
251
+                and autoriser('publierdans', 'rubrique', $id_parent)
252
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
253
+                and autoriser('publierdans', 'rubrique', $old_parent)
254
+                )
255
+            ) {
256
+                if ($s['statut'] != 'new') {
257
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
258
+                }
259
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260
+                $statut_ancien = $s['statut'];
261
+                sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
262
+
263
+
264
+                propager_les_secteurs();
265
+
266
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
267
+                if ($statut_ancien == 'publie') {
268
+                    calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
269
+                }
270
+                // Creation ou deplacement d'une rubrique non publiee
271
+                // invalider le cache de leur menu
272
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
273
+                    effacer_meta('date_calcul_rubriques');
274
+                }
275
+
276
+                calculer_langues_rubriques();
277
+            }
278
+        }
279
+    }
280
+
281
+    return ''; // pas d'erreur
282 282
 }
Please login to merge, or discard this patch.
ecrire/action/editer_auteur.php 1 patch
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -37,41 +37,41 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function action_editer_auteur_dist($arg = null) {
39 39
 
40
-	if (is_null($arg)) {
41
-		$securiser_action = charger_fonction('securiser_action', 'inc');
42
-		$arg = $securiser_action();
43
-	}
44
-
45
-
46
-	// si id_auteur n'est pas un nombre, c'est une creation
47
-	if (!$id_auteur = intval($arg)) {
48
-		if (($id_auteur = auteur_inserer()) > 0) {
49
-			# cf. GROS HACK
50
-			# recuperer l'eventuel logo charge avant la creation
51
-			# ils ont un id = 0-id_auteur de la session
52
-			$id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
53
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
54
-			foreach (['on', 'off'] as $type) {
55
-				if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
56
-					if ($logo = reset($logo)) {
57
-						rename($logo, str_replace($id_hack, $id_auteur, $logo));
58
-					}
59
-				}
60
-			}
61
-		}
62
-	}
63
-
64
-	// Enregistre l'envoi dans la BD
65
-	$err = '';
66
-	if ($id_auteur > 0) {
67
-		$err = auteur_modifier($id_auteur);
68
-	}
69
-
70
-	if ($err) {
71
-		spip_log("echec editeur auteur: $err", _LOG_ERREUR);
72
-	}
73
-
74
-	return [$id_auteur, $err];
40
+    if (is_null($arg)) {
41
+        $securiser_action = charger_fonction('securiser_action', 'inc');
42
+        $arg = $securiser_action();
43
+    }
44
+
45
+
46
+    // si id_auteur n'est pas un nombre, c'est une creation
47
+    if (!$id_auteur = intval($arg)) {
48
+        if (($id_auteur = auteur_inserer()) > 0) {
49
+            # cf. GROS HACK
50
+            # recuperer l'eventuel logo charge avant la creation
51
+            # ils ont un id = 0-id_auteur de la session
52
+            $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
53
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
54
+            foreach (['on', 'off'] as $type) {
55
+                if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
56
+                    if ($logo = reset($logo)) {
57
+                        rename($logo, str_replace($id_hack, $id_auteur, $logo));
58
+                    }
59
+                }
60
+            }
61
+        }
62
+    }
63
+
64
+    // Enregistre l'envoi dans la BD
65
+    $err = '';
66
+    if ($id_auteur > 0) {
67
+        $err = auteur_modifier($id_auteur);
68
+    }
69
+
70
+    if ($err) {
71
+        spip_log("echec editeur auteur: $err", _LOG_ERREUR);
72
+    }
73
+
74
+    return [$id_auteur, $err];
75 75
 }
76 76
 
77 77
 /**
@@ -88,44 +88,44 @@  discard block
 block discarded – undo
88 88
  */
89 89
 function auteur_inserer($source = null, $set = null) {
90 90
 
91
-	// Ce qu'on va demander comme modifications
92
-	$champs = [];
93
-	$champs['source'] = $source ?: 'spip';
94
-
95
-	$champs['login'] = '';
96
-	$champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
97
-	$champs['webmestre'] = 'non';
98
-	if (empty($champs['imessage'])) {
99
-		$champs['imessage'] = 'oui';
100
-	}
101
-
102
-	if ($set) {
103
-		$champs = array_merge($champs, $set);
104
-	}
105
-
106
-	// Envoyer aux plugins
107
-	$champs = pipeline(
108
-		'pre_insertion',
109
-		[
110
-			'args' => [
111
-				'table' => 'spip_auteurs',
112
-			],
113
-			'data' => $champs
114
-		]
115
-	);
116
-	$id_auteur = sql_insertq('spip_auteurs', $champs);
117
-	pipeline(
118
-		'post_insertion',
119
-		[
120
-			'args' => [
121
-				'table' => 'spip_auteurs',
122
-				'id_objet' => $id_auteur
123
-			],
124
-			'data' => $champs
125
-		]
126
-	);
127
-
128
-	return $id_auteur;
91
+    // Ce qu'on va demander comme modifications
92
+    $champs = [];
93
+    $champs['source'] = $source ?: 'spip';
94
+
95
+    $champs['login'] = '';
96
+    $champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
97
+    $champs['webmestre'] = 'non';
98
+    if (empty($champs['imessage'])) {
99
+        $champs['imessage'] = 'oui';
100
+    }
101
+
102
+    if ($set) {
103
+        $champs = array_merge($champs, $set);
104
+    }
105
+
106
+    // Envoyer aux plugins
107
+    $champs = pipeline(
108
+        'pre_insertion',
109
+        [
110
+            'args' => [
111
+                'table' => 'spip_auteurs',
112
+            ],
113
+            'data' => $champs
114
+        ]
115
+    );
116
+    $id_auteur = sql_insertq('spip_auteurs', $champs);
117
+    pipeline(
118
+        'post_insertion',
119
+        [
120
+            'args' => [
121
+                'table' => 'spip_auteurs',
122
+                'id_objet' => $id_auteur
123
+            ],
124
+            'data' => $champs
125
+        ]
126
+    );
127
+
128
+    return $id_auteur;
129 129
 }
130 130
 
131 131
 
@@ -150,70 +150,70 @@  discard block
 block discarded – undo
150 150
  */
151 151
 function auteur_modifier($id_auteur, $set = null, $force_update = false) {
152 152
 
153
-	include_spip('inc/modifier');
154
-	include_spip('inc/filtres');
155
-	$c = collecter_requests(
156
-		// include list
157
-		objet_info('auteur', 'champs_editables'),
158
-		// exclude list
159
-		$force_update ? [] : ['webmestre', 'pass', 'login'],
160
-		// donnees eventuellement fournies
161
-		$set
162
-	);
163
-
164
-	if (
165
-		$err = objet_modifier_champs(
166
-			'auteur',
167
-			$id_auteur,
168
-			[
169
-			'data' => $set,
170
-			'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')]
171
-			],
172
-			$c
173
-		)
174
-	) {
175
-		return $err;
176
-	}
177
-	$session = $c;
178
-
179
-	$err = '';
180
-	if (!$force_update) {
181
-		// Modification de statut, changement de rubrique ?
182
-		$c = collecter_requests(
183
-		// include list
184
-			[
185
-				'statut',
186
-				'new_login',
187
-				'new_pass',
188
-				'login',
189
-				'pass',
190
-				'webmestre',
191
-				'restreintes',
192
-				'id_parent'
193
-			],
194
-			// exclude list
195
-			[],
196
-			// donnees eventuellement fournies
197
-			$set
198
-		);
199
-		if (isset($c['new_login']) and !isset($c['login'])) {
200
-			$c['login'] = $c['new_login'];
201
-		}
202
-		if (isset($c['new_pass']) and !isset($c['pass'])) {
203
-			$c['pass'] = $c['new_pass'];
204
-		}
205
-		$err = auteur_instituer($id_auteur, $c);
206
-		$session = array_merge($session, $c);
207
-	}
208
-
209
-	// .. mettre a jour les sessions de cet auteur
210
-	include_spip('inc/session');
211
-	$session['id_auteur'] = $id_auteur;
212
-	unset($session['new_login']);
213
-	unset($session['new_pass']);
214
-	actualiser_sessions($session);
215
-
216
-	return $err;
153
+    include_spip('inc/modifier');
154
+    include_spip('inc/filtres');
155
+    $c = collecter_requests(
156
+        // include list
157
+        objet_info('auteur', 'champs_editables'),
158
+        // exclude list
159
+        $force_update ? [] : ['webmestre', 'pass', 'login'],
160
+        // donnees eventuellement fournies
161
+        $set
162
+    );
163
+
164
+    if (
165
+        $err = objet_modifier_champs(
166
+            'auteur',
167
+            $id_auteur,
168
+            [
169
+            'data' => $set,
170
+            'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')]
171
+            ],
172
+            $c
173
+        )
174
+    ) {
175
+        return $err;
176
+    }
177
+    $session = $c;
178
+
179
+    $err = '';
180
+    if (!$force_update) {
181
+        // Modification de statut, changement de rubrique ?
182
+        $c = collecter_requests(
183
+        // include list
184
+            [
185
+                'statut',
186
+                'new_login',
187
+                'new_pass',
188
+                'login',
189
+                'pass',
190
+                'webmestre',
191
+                'restreintes',
192
+                'id_parent'
193
+            ],
194
+            // exclude list
195
+            [],
196
+            // donnees eventuellement fournies
197
+            $set
198
+        );
199
+        if (isset($c['new_login']) and !isset($c['login'])) {
200
+            $c['login'] = $c['new_login'];
201
+        }
202
+        if (isset($c['new_pass']) and !isset($c['pass'])) {
203
+            $c['pass'] = $c['new_pass'];
204
+        }
205
+        $err = auteur_instituer($id_auteur, $c);
206
+        $session = array_merge($session, $c);
207
+    }
208
+
209
+    // .. mettre a jour les sessions de cet auteur
210
+    include_spip('inc/session');
211
+    $session['id_auteur'] = $id_auteur;
212
+    unset($session['new_login']);
213
+    unset($session['new_pass']);
214
+    actualiser_sessions($session);
215
+
216
+    return $err;
217 217
 }
218 218
 
219 219
 /**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
  * @return string
235 235
  */
236 236
 function auteur_associer($id_auteur, $objets, $qualif = null) {
237
-	include_spip('action/editer_liens');
237
+    include_spip('action/editer_liens');
238 238
 
239
-	return objet_associer(['auteur' => $id_auteur], $objets, $qualif);
239
+    return objet_associer(['auteur' => $id_auteur], $objets, $qualif);
240 240
 }
241 241
 
242 242
 /**
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
  * @return string
256 256
  */
257 257
 function auteur_dissocier($id_auteur, $objets) {
258
-	include_spip('action/editer_liens');
258
+    include_spip('action/editer_liens');
259 259
 
260
-	return objet_dissocier(['auteur' => $id_auteur], $objets);
260
+    return objet_dissocier(['auteur' => $id_auteur], $objets);
261 261
 }
262 262
 
263 263
 /**
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
  * @return bool|int
279 279
  */
280 280
 function auteur_qualifier($id_auteur, $objets, $qualif) {
281
-	include_spip('action/editer_liens');
281
+    include_spip('action/editer_liens');
282 282
 
283
-	return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif);
283
+    return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif);
284 284
 }
285 285
 
286 286
 
@@ -299,139 +299,139 @@  discard block
 block discarded – undo
299 299
  * @return bool|string
300 300
  */
301 301
 function auteur_instituer($id_auteur, $c, $force_webmestre = false) {
302
-	if (!$id_auteur = intval($id_auteur)) {
303
-		return false;
304
-	}
305
-	$erreurs = []; // contiendra les differentes erreurs a traduire par _T()
306
-	$champs = [];
307
-
308
-	// les memoriser pour les faire passer dans le pipeline pre_edition
309
-	if (isset($c['login']) and strlen($c['login'])) {
310
-		$champs['login'] = $c['login'];
311
-	}
312
-	if (isset($c['pass']) and strlen($c['pass'])) {
313
-		$champs['pass'] = $c['pass'];
314
-	}
315
-
316
-	$statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
317
-
318
-	if (
319
-		isset($c['statut'])
320
-		and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]))
321
-	) {
322
-		$statut = $champs['statut'] = $c['statut'];
323
-	}
324
-
325
-	// Restreindre avant de declarer l'auteur
326
-	// (section critique sur les droits)
327
-	if (isset($c['id_parent']) and $c['id_parent']) {
328
-		if (is_array($c['restreintes'])) {
329
-			$c['restreintes'][] = $c['id_parent'];
330
-		} else {
331
-			$c['restreintes'] = [$c['id_parent']];
332
-		}
333
-	}
334
-
335
-	if (
336
-		isset($c['webmestre'])
337
-		and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?']))
338
-	) {
339
-		$champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
340
-	}
341
-
342
-	// si statut change et n'est pas 0minirezo, on force webmestre a non
343
-	if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
344
-		$champs['webmestre'] = $c['webmestre'] = 'non';
345
-	}
346
-
347
-	// Envoyer aux plugins
348
-	$champs = pipeline(
349
-		'pre_edition',
350
-		[
351
-			'args' => [
352
-				'table' => 'spip_auteurs',
353
-				'id_objet' => $id_auteur,
354
-				'action' => 'instituer',
355
-				'statut_ancien' => $statut_ancien,
356
-			],
357
-			'data' => $champs
358
-		]
359
-	);
360
-
361
-	if (
362
-		isset($c['restreintes']) and is_array($c['restreintes'])
363
-		and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']])
364
-	) {
365
-		$rubriques = array_map('intval', $c['restreintes']);
366
-		$rubriques = array_unique($rubriques);
367
-		$rubriques = array_diff($rubriques, [0]);
368
-		auteur_dissocier($id_auteur, ['rubrique' => '*']);
369
-		auteur_associer($id_auteur, ['rubrique' => $rubriques]);
370
-	}
371
-
372
-	$flag_ecrire_acces = false;
373
-	// commencer par traiter les cas particuliers des logins et pass
374
-	// avant les autres ecritures en base
375
-	if (isset($champs['login']) or isset($champs['pass'])) {
376
-		$auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
377
-		include_spip('inc/auth');
378
-		if (isset($champs['login']) and strlen($champs['login'])) {
379
-			if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
380
-				$erreurs[] = 'ecrire:impossible_modifier_login_auteur';
381
-			}
382
-		}
383
-		if (isset($champs['pass']) and strlen($champs['pass'])) {
384
-			$champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
385
-			if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
386
-				$erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
387
-			}
388
-		}
389
-		unset($champs['login']);
390
-		unset($champs['pass']);
391
-		$flag_ecrire_acces = true;
392
-	}
393
-
394
-	if (!(is_countable($champs) ? count($champs) : 0)) {
395
-		return implode(' ', array_map('_T', $erreurs));
396
-	}
397
-	sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
398
-
399
-	// .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
400
-	if (
401
-		$flag_ecrire_acces
402
-		or isset($champs['statut'])
403
-	) {
404
-		include_spip('inc/acces');
405
-		ecrire_acces();
406
-	}
407
-
408
-	// Invalider les caches
409
-	include_spip('inc/invalideur');
410
-	suivre_invalideur("id='auteur/$id_auteur'");
411
-
412
-	// Pipeline
413
-	pipeline(
414
-		'post_edition',
415
-		[
416
-			'args' => [
417
-				'table' => 'spip_auteurs',
418
-				'id_objet' => $id_auteur,
419
-				'action' => 'instituer',
420
-				'statut_ancien' => $statut_ancien,
421
-			],
422
-			'data' => $champs
423
-		]
424
-	);
425
-
426
-
427
-	// Notifications
428
-	if ($notifications = charger_fonction('notifications', 'inc')) {
429
-		$notifications(
430
-			'instituerauteur',
431
-			$id_auteur,
432
-			['statut' => $statut, 'statut_ancien' => $statut_ancien]
433
-		);
434
-	}
435
-
436
-	return implode(' ', array_map('_T', $erreurs));
302
+    if (!$id_auteur = intval($id_auteur)) {
303
+        return false;
304
+    }
305
+    $erreurs = []; // contiendra les differentes erreurs a traduire par _T()
306
+    $champs = [];
307
+
308
+    // les memoriser pour les faire passer dans le pipeline pre_edition
309
+    if (isset($c['login']) and strlen($c['login'])) {
310
+        $champs['login'] = $c['login'];
311
+    }
312
+    if (isset($c['pass']) and strlen($c['pass'])) {
313
+        $champs['pass'] = $c['pass'];
314
+    }
315
+
316
+    $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
317
+
318
+    if (
319
+        isset($c['statut'])
320
+        and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]))
321
+    ) {
322
+        $statut = $champs['statut'] = $c['statut'];
323
+    }
324
+
325
+    // Restreindre avant de declarer l'auteur
326
+    // (section critique sur les droits)
327
+    if (isset($c['id_parent']) and $c['id_parent']) {
328
+        if (is_array($c['restreintes'])) {
329
+            $c['restreintes'][] = $c['id_parent'];
330
+        } else {
331
+            $c['restreintes'] = [$c['id_parent']];
332
+        }
333
+    }
334
+
335
+    if (
336
+        isset($c['webmestre'])
337
+        and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?']))
338
+    ) {
339
+        $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
340
+    }
341
+
342
+    // si statut change et n'est pas 0minirezo, on force webmestre a non
343
+    if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
344
+        $champs['webmestre'] = $c['webmestre'] = 'non';
345
+    }
346
+
347
+    // Envoyer aux plugins
348
+    $champs = pipeline(
349
+        'pre_edition',
350
+        [
351
+            'args' => [
352
+                'table' => 'spip_auteurs',
353
+                'id_objet' => $id_auteur,
354
+                'action' => 'instituer',
355
+                'statut_ancien' => $statut_ancien,
356
+            ],
357
+            'data' => $champs
358
+        ]
359
+    );
360
+
361
+    if (
362
+        isset($c['restreintes']) and is_array($c['restreintes'])
363
+        and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']])
364
+    ) {
365
+        $rubriques = array_map('intval', $c['restreintes']);
366
+        $rubriques = array_unique($rubriques);
367
+        $rubriques = array_diff($rubriques, [0]);
368
+        auteur_dissocier($id_auteur, ['rubrique' => '*']);
369
+        auteur_associer($id_auteur, ['rubrique' => $rubriques]);
370
+    }
371
+
372
+    $flag_ecrire_acces = false;
373
+    // commencer par traiter les cas particuliers des logins et pass
374
+    // avant les autres ecritures en base
375
+    if (isset($champs['login']) or isset($champs['pass'])) {
376
+        $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
377
+        include_spip('inc/auth');
378
+        if (isset($champs['login']) and strlen($champs['login'])) {
379
+            if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
380
+                $erreurs[] = 'ecrire:impossible_modifier_login_auteur';
381
+            }
382
+        }
383
+        if (isset($champs['pass']) and strlen($champs['pass'])) {
384
+            $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
385
+            if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
386
+                $erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
387
+            }
388
+        }
389
+        unset($champs['login']);
390
+        unset($champs['pass']);
391
+        $flag_ecrire_acces = true;
392
+    }
393
+
394
+    if (!(is_countable($champs) ? count($champs) : 0)) {
395
+        return implode(' ', array_map('_T', $erreurs));
396
+    }
397
+    sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
398
+
399
+    // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
400
+    if (
401
+        $flag_ecrire_acces
402
+        or isset($champs['statut'])
403
+    ) {
404
+        include_spip('inc/acces');
405
+        ecrire_acces();
406
+    }
407
+
408
+    // Invalider les caches
409
+    include_spip('inc/invalideur');
410
+    suivre_invalideur("id='auteur/$id_auteur'");
411
+
412
+    // Pipeline
413
+    pipeline(
414
+        'post_edition',
415
+        [
416
+            'args' => [
417
+                'table' => 'spip_auteurs',
418
+                'id_objet' => $id_auteur,
419
+                'action' => 'instituer',
420
+                'statut_ancien' => $statut_ancien,
421
+            ],
422
+            'data' => $champs
423
+        ]
424
+    );
425
+
426
+
427
+    // Notifications
428
+    if ($notifications = charger_fonction('notifications', 'inc')) {
429
+        $notifications(
430
+            'instituerauteur',
431
+            $id_auteur,
432
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien]
433
+        );
434
+    }
435
+
436
+    return implode(' ', array_map('_T', $erreurs));
437 437
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_selecteur_generique.php 1 patch
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  **/
8 8
 
9 9
 if (!defined('_ECRIRE_INC_VERSION')) {
10
-	return;
10
+    return;
11 11
 }
12 12
 
13 13
 /**
@@ -28,51 +28,51 @@  discard block
 block discarded – undo
28 28
  *     - afficher : tableau des objets à afficher (mais pas forcément sélectionnables)
29 29
  */
30 30
 function selecteur_lister_objets($includelist = [], $excludelist = []) {
31
-	static $liste_selecteurs, $liste_parents;
32
-
33
-	if (!$liste_selecteurs) {
34
-		$liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
-	}
36
-	$objets_selectionner = [];
37
-	foreach ($liste_selecteurs as $fichier => $chemin) {
38
-		$objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier);
39
-	}
40
-
41
-	// S'il y a une whitelist on ne garde que ce qui est dedans
42
-	if (!empty($includelist)) {
43
-		$includelist = array_map('table_objet', $includelist);
44
-		$objets_selectionner = array_intersect($objets_selectionner, $includelist);
45
-	}
46
-	// On supprime ce qui est dans la liste d’exclusion
47
-	$excludelist = array_map('table_objet', $excludelist);
48
-	// On enlève toujours la racine
49
-	$excludelist[] = 'racine';
50
-	$objets_selectionner = array_diff($objets_selectionner, $excludelist);
51
-
52
-	// Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
-	$objets_afficher = $objets_selectionner;
54
-
55
-	// Il faut alors chercher d'éventuels parents obligatoires en plus :
56
-	// lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
-	if (!$liste_parents) {
58
-		$liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
-	}
60
-	foreach ($liste_parents as $fichier => $chemin) {
61
-		preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures);
62
-		$parent = $captures[1];
63
-		$type = $captures[2];
64
-		// Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
-		if (in_array($type, $objets_afficher)) {
66
-			$objets_afficher[] = $parent;
67
-		}
68
-	}
69
-
70
-	$objets = [
71
-		'selectionner' => array_unique($objets_selectionner),
72
-		'afficher' => array_unique($objets_afficher),
73
-	];
74
-
75
-	return $objets;
31
+    static $liste_selecteurs, $liste_parents;
32
+
33
+    if (!$liste_selecteurs) {
34
+        $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
+    }
36
+    $objets_selectionner = [];
37
+    foreach ($liste_selecteurs as $fichier => $chemin) {
38
+        $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier);
39
+    }
40
+
41
+    // S'il y a une whitelist on ne garde que ce qui est dedans
42
+    if (!empty($includelist)) {
43
+        $includelist = array_map('table_objet', $includelist);
44
+        $objets_selectionner = array_intersect($objets_selectionner, $includelist);
45
+    }
46
+    // On supprime ce qui est dans la liste d’exclusion
47
+    $excludelist = array_map('table_objet', $excludelist);
48
+    // On enlève toujours la racine
49
+    $excludelist[] = 'racine';
50
+    $objets_selectionner = array_diff($objets_selectionner, $excludelist);
51
+
52
+    // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
+    $objets_afficher = $objets_selectionner;
54
+
55
+    // Il faut alors chercher d'éventuels parents obligatoires en plus :
56
+    // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
+    if (!$liste_parents) {
58
+        $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
+    }
60
+    foreach ($liste_parents as $fichier => $chemin) {
61
+        preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures);
62
+        $parent = $captures[1];
63
+        $type = $captures[2];
64
+        // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
+        if (in_array($type, $objets_afficher)) {
66
+            $objets_afficher[] = $parent;
67
+        }
68
+    }
69
+
70
+    $objets = [
71
+        'selectionner' => array_unique($objets_selectionner),
72
+        'afficher' => array_unique($objets_afficher),
73
+    ];
74
+
75
+    return $objets;
76 76
 }
77 77
 
78 78
 /**
@@ -99,31 +99,31 @@  discard block
 block discarded – undo
99 99
  *     liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet.
100 100
  **/
101 101
 function picker_selected($selected, $type = '') {
102
-	$select = [];
103
-	$type = preg_replace(',\W,', '', $type);
104
-
105
-	if ($selected and !is_array($selected)) {
106
-		$selected = explode(',', $selected);
107
-	}
108
-
109
-	if (is_array($selected)) {
110
-		foreach ($selected as $value) {
111
-			// Si c'est le bon format déjà
112
-			if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) {
113
-				$objet = $captures[1];
114
-				$id_objet = intval($captures[2]);
115
-
116
-				// Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
117
-				if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
118
-					$select[] = $id_objet;
119
-				} elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
120
-					$select[] = ['objet' => $objet, 'id_objet' => $id_objet];
121
-				}
122
-			}
123
-		}
124
-	}
125
-
126
-	return $select;
102
+    $select = [];
103
+    $type = preg_replace(',\W,', '', $type);
104
+
105
+    if ($selected and !is_array($selected)) {
106
+        $selected = explode(',', $selected);
107
+    }
108
+
109
+    if (is_array($selected)) {
110
+        foreach ($selected as $value) {
111
+            // Si c'est le bon format déjà
112
+            if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) {
113
+                $objet = $captures[1];
114
+                $id_objet = intval($captures[2]);
115
+
116
+                // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
117
+                if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
118
+                    $select[] = $id_objet;
119
+                } elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
120
+                    $select[] = ['objet' => $objet, 'id_objet' => $id_objet];
121
+                }
122
+            }
123
+        }
124
+    }
125
+
126
+    return $select;
127 127
 }
128 128
 
129 129
 /**
@@ -140,49 +140,49 @@  discard block
 block discarded – undo
140 140
  *     Booléen indiquant si les articles sont sélectionnables
141 141
  */
142 142
 function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) {
143
-	include_spip('inc/json');
144
-	include_spip('inc/lien');
145
-
146
-	// On construit un tableau des objets sélectionnables suivant les paramètres
147
-	$objets = [];
148
-	if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) {
149
-		$objets = $rubriques_ou_objets;
150
-	} else {
151
-		if ($rubriques_ou_objets) {
152
-			$objets[] = 'rubriques';
153
-		}
154
-		if ($articles) {
155
-			$objets[] = 'articles';
156
-		}
157
-	}
158
-
159
-	// si id numerique et un seul objet possible, pas d'ambiguite
160
-	if (is_numeric($ref) and count($objets) === 1) {
161
-		$ref = reset($objets) . $ref;
162
-	}
163
-
164
-	// Si la référence ne correspond à rien, c'est fini
165
-	if (!($match = typer_raccourci($ref))) {
166
-		return json_export(false);
167
-	}
168
-	// Sinon on récupère les infos utiles
169
-	[$type, , $id, , , , ] = array_pad($match, 7, null);
170
-
171
-	// On regarde si le type trouvé fait partie des objets sélectionnables
172
-	if (!in_array(table_objet($type), $objets)) {
173
-		return json_export(false);
174
-	}
175
-
176
-	// Maintenant que tout est bon, on cherche les informations sur cet objet
177
-	include_spip('inc/filtres');
178
-	if (!$titre = generer_objet_info($id, $type, 'titre')) {
179
-		return json_export(false);
180
-	}
181
-
182
-	// On simplifie le texte
183
-	$titre = attribut_html($titre);
184
-
185
-	return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
143
+    include_spip('inc/json');
144
+    include_spip('inc/lien');
145
+
146
+    // On construit un tableau des objets sélectionnables suivant les paramètres
147
+    $objets = [];
148
+    if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) {
149
+        $objets = $rubriques_ou_objets;
150
+    } else {
151
+        if ($rubriques_ou_objets) {
152
+            $objets[] = 'rubriques';
153
+        }
154
+        if ($articles) {
155
+            $objets[] = 'articles';
156
+        }
157
+    }
158
+
159
+    // si id numerique et un seul objet possible, pas d'ambiguite
160
+    if (is_numeric($ref) and count($objets) === 1) {
161
+        $ref = reset($objets) . $ref;
162
+    }
163
+
164
+    // Si la référence ne correspond à rien, c'est fini
165
+    if (!($match = typer_raccourci($ref))) {
166
+        return json_export(false);
167
+    }
168
+    // Sinon on récupère les infos utiles
169
+    [$type, , $id, , , , ] = array_pad($match, 7, null);
170
+
171
+    // On regarde si le type trouvé fait partie des objets sélectionnables
172
+    if (!in_array(table_objet($type), $objets)) {
173
+        return json_export(false);
174
+    }
175
+
176
+    // Maintenant que tout est bon, on cherche les informations sur cet objet
177
+    include_spip('inc/filtres');
178
+    if (!$titre = generer_objet_info($id, $type, 'titre')) {
179
+        return json_export(false);
180
+    }
181
+
182
+    // On simplifie le texte
183
+    $titre = attribut_html($titre);
184
+
185
+    return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
186 186
 }
187 187
 
188 188
 /**
@@ -205,34 +205,34 @@  discard block
 block discarded – undo
205 205
  *     Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon.
206 206
  */
207 207
 function test_enfants_rubrique($id_rubrique, $types = []) {
208
-	static $has_child = [];
209
-
210
-	if (!isset($has_child[$id_rubrique])) {
211
-		$types = (is_array($types) ? array_filter($types) : []);
212
-
213
-		// recuperer tous les freres et soeurs de la rubrique visee
214
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
215
-		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent));
216
-		$fratrie = array_column($fratrie, 'id_rubrique');
217
-		$has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
218
-		$has = array_column($has, 'id_parent');
219
-		$fratrie = array_diff($fratrie, $has);
220
-
221
-		while (count($fratrie) and is_array($types) and count($types)) {
222
-			$type = array_shift($types);
223
-			$h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
224
-			$h = array_column($h, 'id_rubrique');
225
-			$has = array_merge($has, $h);
226
-			$fratrie = array_diff($fratrie, $h);
227
-		}
228
-
229
-		if (count($has)) {
230
-			$has_child = $has_child + array_combine($has, array_pad([], count($has), true));
231
-		}
232
-		if (count($fratrie)) {
233
-			$has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false));
234
-		}
235
-	}
236
-
237
-	return $has_child[$id_rubrique] ? ' ' : '';
208
+    static $has_child = [];
209
+
210
+    if (!isset($has_child[$id_rubrique])) {
211
+        $types = (is_array($types) ? array_filter($types) : []);
212
+
213
+        // recuperer tous les freres et soeurs de la rubrique visee
214
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
215
+        $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent));
216
+        $fratrie = array_column($fratrie, 'id_rubrique');
217
+        $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
218
+        $has = array_column($has, 'id_parent');
219
+        $fratrie = array_diff($fratrie, $has);
220
+
221
+        while (count($fratrie) and is_array($types) and count($types)) {
222
+            $type = array_shift($types);
223
+            $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
224
+            $h = array_column($h, 'id_rubrique');
225
+            $has = array_merge($has, $h);
226
+            $fratrie = array_diff($fratrie, $h);
227
+        }
228
+
229
+        if (count($has)) {
230
+            $has_child = $has_child + array_combine($has, array_pad([], count($has), true));
231
+        }
232
+        if (count($fratrie)) {
233
+            $has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false));
234
+        }
235
+    }
236
+
237
+    return $has_child[$id_rubrique] ? ' ' : '';
238 238
 }
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
  *     Tableau des champs et valeurs collectées
40 40
  */
41 41
 function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) {
42
-	$c = $set;
43
-	if (!$c) {
44
-		$c = [];
45
-		foreach ($include_list as $champ) {
46
-			// on ne collecte que les champs reellement envoyes par defaut.
47
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
-			$val = _request($champ);
49
-			if ($tous or $val !== null) {
50
-				$c[$champ] = $val;
51
-			}
52
-		}
53
-		// on ajoute toujours la lang en saisie possible
54
-		// meme si pas prevu au depart pour l'objet concerne
55
-		if ($l = _request('changer_lang')) {
56
-			$c['lang'] = $l;
57
-		}
58
-	}
59
-	foreach ($exclude_list as $champ) {
60
-		unset($c[$champ]);
61
-	}
62
-
63
-	return $c;
42
+    $c = $set;
43
+    if (!$c) {
44
+        $c = [];
45
+        foreach ($include_list as $champ) {
46
+            // on ne collecte que les champs reellement envoyes par defaut.
47
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
+            $val = _request($champ);
49
+            if ($tous or $val !== null) {
50
+                $c[$champ] = $val;
51
+            }
52
+        }
53
+        // on ajoute toujours la lang en saisie possible
54
+        // meme si pas prevu au depart pour l'objet concerne
55
+        if ($l = _request('changer_lang')) {
56
+            $c['lang'] = $l;
57
+        }
58
+    }
59
+    foreach ($exclude_list as $champ) {
60
+        unset($c[$champ]);
61
+    }
62
+
63
+    return $c;
64 64
 }
65 65
 
66 66
 /**
@@ -97,237 +97,237 @@  discard block
 block discarded – undo
97 97
  *     - chaîne : Texte d'un message d'erreur
98 98
  */
99 99
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
100
-	if (!$id_objet = intval($id_objet)) {
101
-		spip_log('Erreur $id_objet non defini', 'warn');
102
-
103
-		return _T('erreur_technique_enregistrement_impossible');
104
-	}
105
-
106
-	include_spip('inc/filtres');
107
-
108
-	$table_objet = table_objet($objet, $serveur);
109
-	$spip_table_objet = table_objet_sql($objet, $serveur);
110
-	$id_table_objet = id_table_objet($objet, $serveur);
111
-	$trouver_table = charger_fonction('trouver_table', 'base');
112
-	$desc = $trouver_table($spip_table_objet, $serveur);
113
-
114
-	// Appels incomplets (sans $c)
115
-	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
-
118
-		return _T('erreur_technique_enregistrement_impossible');
119
-	}
120
-
121
-	// Securite : certaines variables ne sont jamais acceptees ici
122
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
123
-	// il faut passer par instituer_XX()
124
-	// TODO: faut-il passer ces variables interdites
125
-	// dans un fichier de description separe ?
126
-	unset($c['statut']);
127
-	unset($c['id_parent']);
128
-	unset($c['id_rubrique']);
129
-	unset($c['id_secteur']);
130
-
131
-	// Gerer les champs non vides
132
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
-		foreach ($options['nonvide'] as $champ => $sinon) {
134
-			if (isset($c[$champ]) and $c[$champ] === '') {
135
-				$c[$champ] = $sinon;
136
-			}
137
-		}
138
-	}
139
-
140
-	// N'accepter que les champs qui existent
141
-	// TODO: ici aussi on peut valider les contenus
142
-	// en fonction du type
143
-	$champs = array_intersect_key($c, $desc['field']);
144
-
145
-	// Nettoyer les valeurs
146
-	$champs = array_map('corriger_caracteres', $champs);
147
-
148
-	// On récupère l'état avant toute modification
149
-	$row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
150
-
151
-	// Envoyer aux plugins
152
-	$champs = pipeline(
153
-		'pre_edition',
154
-		[
155
-			'args' => [
156
-				'table' => $spip_table_objet, // compatibilite
157
-				'table_objet' => $table_objet,
158
-				'spip_table_objet' => $spip_table_objet,
159
-				'desc' => $desc,
160
-				'type' => $objet,
161
-				'id_objet' => $id_objet,
162
-				'data' => $options['data'] ?? null,
163
-				'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
164
-				'champs_anciens' => $row, // état du contenu avant modif
165
-				'serveur' => $serveur,
166
-				'action' => $options['action'] ?? 'modifier'
167
-			],
168
-			'data' => $champs
169
-		]
170
-	);
171
-
172
-	if (!$champs) {
173
-		return false;
174
-	}
175
-
176
-
177
-	// marquer le fait que l'objet est travaille par toto a telle date
178
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
179
-		include_spip('inc/drapeau_edition');
180
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
181
-	}
182
-
183
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
184
-	include_spip('inc/editer');
185
-	if (!isset($options['data']) or is_null($options['data'])) {
186
-		$options['data'] = &$_POST;
187
-	}
188
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
189
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
190
-	// et gere l'interface
191
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
192
-	if ($conflits) {
193
-		return _T('titre_conflit_edition');
194
-	}
195
-
196
-	if ($champs) {
197
-		// cas particulier de la langue : passer par instituer_langue_objet
198
-		if (isset($champs['lang'])) {
199
-			if ($changer_lang = $champs['lang']) {
200
-				$id_rubrique = 0;
201
-				if (isset($desc['field']['id_rubrique'])) {
202
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
203
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
204
-				}
205
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
206
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
207
-			}
208
-			// on laisse 'lang' dans $champs,
209
-			// ca permet de passer dans le pipeline post_edition et de journaliser
210
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
211
-			// deja pris en compte
212
-		}
213
-
214
-		// la modif peut avoir lieu
215
-
216
-		// faut-il ajouter date_modif ?
217
-		if (
218
-			!empty($options['date_modif'])
219
-			and !isset($champs[$options['date_modif']])
220
-		) {
221
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
222
-		}
223
-
224
-		// allez on commit la modif
225
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur);
226
-
227
-		// on verifie si elle est bien passee
228
-		$moof = sql_fetsel(
229
-			array_keys($champs),
230
-			$spip_table_objet,
231
-			"$id_table_objet=" . intval($id_objet),
232
-			[],
233
-			[],
234
-			'',
235
-			[],
236
-			$serveur
237
-		);
238
-		// si difference entre les champs, reperer les champs mal enregistres
239
-		if ($moof != $champs) {
240
-			$liste = [];
241
-			foreach ($moof as $k => $v) {
242
-				if (
243
-					$v !== $champs[$k]
244
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
245
-					and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
246
-					// ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
247
-					and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
248
-				) {
249
-					$liste[] = $k;
250
-					$conflits[$k]['post'] = $champs[$k];
251
-					$conflits[$k]['save'] = $v;
252
-
253
-					// cas specifique MySQL+emoji : si l'un est la
254
-					// conversion utf8_noplanes de l'autre alors c'est OK
255
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
256
-						include_spip('inc/charsets');
257
-						if ($v == utf8_noplanes($champs[$k])) {
258
-							array_pop($liste);
259
-						}
260
-					}
261
-				}
262
-			}
263
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
264
-			// c'est un cas exceptionnel
265
-			if (count($liste)) {
266
-				spip_log(
267
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
268
-					'modifier.' . _LOG_CRITIQUE
269
-				);
270
-
271
-				return _T(
272
-					'erreur_technique_enregistrement_champs',
273
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
274
-				);
275
-			}
276
-		}
277
-
278
-		// Invalider les caches
279
-		if (isset($options['invalideur']) and $options['invalideur']) {
280
-			include_spip('inc/invalideur');
281
-			if (is_array($options['invalideur'])) {
282
-				array_map('suivre_invalideur', $options['invalideur']);
283
-			} else {
284
-				suivre_invalideur($options['invalideur']);
285
-			}
286
-		}
287
-
288
-		// Notifications, gestion des revisions...
289
-		// en standard, appelle |nouvelle_revision ci-dessous
290
-		pipeline(
291
-			'post_edition',
292
-			[
293
-				'args' => [
294
-					'table' => $spip_table_objet,
295
-					'table_objet' => $table_objet,
296
-					'spip_table_objet' => $spip_table_objet,
297
-					'desc' => $desc,
298
-					'type' => $objet,
299
-					'id_objet' => $id_objet,
300
-					'champs' => $options['champs'] ?? [], // [doc] kesako ?
301
-					'champs_anciens' => $row, // état du contenu avant modif
302
-					'serveur' => $serveur,
303
-					'action' => $options['action'] ?? 'modifier'
304
-				],
305
-				'data' => $champs
306
-			]
307
-		);
308
-	}
309
-
310
-	// journaliser l'affaire
311
-	// message a affiner :-)
312
-	include_spip('inc/filtres_mini');
313
-	$qui = '';
314
-	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
315
-		$qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
316
-	}
317
-	if (!empty($GLOBALS['visiteur_session']['nom'])) {
318
-		$qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
319
-	}
320
-	if ($qui == '') {
321
-		$qui = '#ip:' . $GLOBALS['ip'] . '#';
322
-	}
323
-	journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join(
324
-		'+',
325
-		array_diff(array_keys($champs), ['date_modif'])
326
-	) . ')'), [
327
-		'faire' => 'modifier',
328
-		'quoi' => $objet,
329
-		'id' => $id_objet
330
-	]);
331
-
332
-	return '';
100
+    if (!$id_objet = intval($id_objet)) {
101
+        spip_log('Erreur $id_objet non defini', 'warn');
102
+
103
+        return _T('erreur_technique_enregistrement_impossible');
104
+    }
105
+
106
+    include_spip('inc/filtres');
107
+
108
+    $table_objet = table_objet($objet, $serveur);
109
+    $spip_table_objet = table_objet_sql($objet, $serveur);
110
+    $id_table_objet = id_table_objet($objet, $serveur);
111
+    $trouver_table = charger_fonction('trouver_table', 'base');
112
+    $desc = $trouver_table($spip_table_objet, $serveur);
113
+
114
+    // Appels incomplets (sans $c)
115
+    if (!is_array($c)) {
116
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
+
118
+        return _T('erreur_technique_enregistrement_impossible');
119
+    }
120
+
121
+    // Securite : certaines variables ne sont jamais acceptees ici
122
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
123
+    // il faut passer par instituer_XX()
124
+    // TODO: faut-il passer ces variables interdites
125
+    // dans un fichier de description separe ?
126
+    unset($c['statut']);
127
+    unset($c['id_parent']);
128
+    unset($c['id_rubrique']);
129
+    unset($c['id_secteur']);
130
+
131
+    // Gerer les champs non vides
132
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
+        foreach ($options['nonvide'] as $champ => $sinon) {
134
+            if (isset($c[$champ]) and $c[$champ] === '') {
135
+                $c[$champ] = $sinon;
136
+            }
137
+        }
138
+    }
139
+
140
+    // N'accepter que les champs qui existent
141
+    // TODO: ici aussi on peut valider les contenus
142
+    // en fonction du type
143
+    $champs = array_intersect_key($c, $desc['field']);
144
+
145
+    // Nettoyer les valeurs
146
+    $champs = array_map('corriger_caracteres', $champs);
147
+
148
+    // On récupère l'état avant toute modification
149
+    $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
150
+
151
+    // Envoyer aux plugins
152
+    $champs = pipeline(
153
+        'pre_edition',
154
+        [
155
+            'args' => [
156
+                'table' => $spip_table_objet, // compatibilite
157
+                'table_objet' => $table_objet,
158
+                'spip_table_objet' => $spip_table_objet,
159
+                'desc' => $desc,
160
+                'type' => $objet,
161
+                'id_objet' => $id_objet,
162
+                'data' => $options['data'] ?? null,
163
+                'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
164
+                'champs_anciens' => $row, // état du contenu avant modif
165
+                'serveur' => $serveur,
166
+                'action' => $options['action'] ?? 'modifier'
167
+            ],
168
+            'data' => $champs
169
+        ]
170
+    );
171
+
172
+    if (!$champs) {
173
+        return false;
174
+    }
175
+
176
+
177
+    // marquer le fait que l'objet est travaille par toto a telle date
178
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
179
+        include_spip('inc/drapeau_edition');
180
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
181
+    }
182
+
183
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
184
+    include_spip('inc/editer');
185
+    if (!isset($options['data']) or is_null($options['data'])) {
186
+        $options['data'] = &$_POST;
187
+    }
188
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
189
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
190
+    // et gere l'interface
191
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
192
+    if ($conflits) {
193
+        return _T('titre_conflit_edition');
194
+    }
195
+
196
+    if ($champs) {
197
+        // cas particulier de la langue : passer par instituer_langue_objet
198
+        if (isset($champs['lang'])) {
199
+            if ($changer_lang = $champs['lang']) {
200
+                $id_rubrique = 0;
201
+                if (isset($desc['field']['id_rubrique'])) {
202
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
203
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
204
+                }
205
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
206
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
207
+            }
208
+            // on laisse 'lang' dans $champs,
209
+            // ca permet de passer dans le pipeline post_edition et de journaliser
210
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
211
+            // deja pris en compte
212
+        }
213
+
214
+        // la modif peut avoir lieu
215
+
216
+        // faut-il ajouter date_modif ?
217
+        if (
218
+            !empty($options['date_modif'])
219
+            and !isset($champs[$options['date_modif']])
220
+        ) {
221
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
222
+        }
223
+
224
+        // allez on commit la modif
225
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur);
226
+
227
+        // on verifie si elle est bien passee
228
+        $moof = sql_fetsel(
229
+            array_keys($champs),
230
+            $spip_table_objet,
231
+            "$id_table_objet=" . intval($id_objet),
232
+            [],
233
+            [],
234
+            '',
235
+            [],
236
+            $serveur
237
+        );
238
+        // si difference entre les champs, reperer les champs mal enregistres
239
+        if ($moof != $champs) {
240
+            $liste = [];
241
+            foreach ($moof as $k => $v) {
242
+                if (
243
+                    $v !== $champs[$k]
244
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
245
+                    and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
246
+                    // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
247
+                    and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
248
+                ) {
249
+                    $liste[] = $k;
250
+                    $conflits[$k]['post'] = $champs[$k];
251
+                    $conflits[$k]['save'] = $v;
252
+
253
+                    // cas specifique MySQL+emoji : si l'un est la
254
+                    // conversion utf8_noplanes de l'autre alors c'est OK
255
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
256
+                        include_spip('inc/charsets');
257
+                        if ($v == utf8_noplanes($champs[$k])) {
258
+                            array_pop($liste);
259
+                        }
260
+                    }
261
+                }
262
+            }
263
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
264
+            // c'est un cas exceptionnel
265
+            if (count($liste)) {
266
+                spip_log(
267
+                    "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
268
+                    'modifier.' . _LOG_CRITIQUE
269
+                );
270
+
271
+                return _T(
272
+                    'erreur_technique_enregistrement_champs',
273
+                    ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
274
+                );
275
+            }
276
+        }
277
+
278
+        // Invalider les caches
279
+        if (isset($options['invalideur']) and $options['invalideur']) {
280
+            include_spip('inc/invalideur');
281
+            if (is_array($options['invalideur'])) {
282
+                array_map('suivre_invalideur', $options['invalideur']);
283
+            } else {
284
+                suivre_invalideur($options['invalideur']);
285
+            }
286
+        }
287
+
288
+        // Notifications, gestion des revisions...
289
+        // en standard, appelle |nouvelle_revision ci-dessous
290
+        pipeline(
291
+            'post_edition',
292
+            [
293
+                'args' => [
294
+                    'table' => $spip_table_objet,
295
+                    'table_objet' => $table_objet,
296
+                    'spip_table_objet' => $spip_table_objet,
297
+                    'desc' => $desc,
298
+                    'type' => $objet,
299
+                    'id_objet' => $id_objet,
300
+                    'champs' => $options['champs'] ?? [], // [doc] kesako ?
301
+                    'champs_anciens' => $row, // état du contenu avant modif
302
+                    'serveur' => $serveur,
303
+                    'action' => $options['action'] ?? 'modifier'
304
+                ],
305
+                'data' => $champs
306
+            ]
307
+        );
308
+    }
309
+
310
+    // journaliser l'affaire
311
+    // message a affiner :-)
312
+    include_spip('inc/filtres_mini');
313
+    $qui = '';
314
+    if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
315
+        $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
316
+    }
317
+    if (!empty($GLOBALS['visiteur_session']['nom'])) {
318
+        $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
319
+    }
320
+    if ($qui == '') {
321
+        $qui = '#ip:' . $GLOBALS['ip'] . '#';
322
+    }
323
+    journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join(
324
+        '+',
325
+        array_diff(array_keys($champs), ['date_modif'])
326
+    ) . ')'), [
327
+        'faire' => 'modifier',
328
+        'quoi' => $objet,
329
+        'id' => $id_objet
330
+    ]);
331
+
332
+    return '';
333 333
 }
Please login to merge, or discard this patch.