Completed
Push — master ( 4fa0dc...b74578 )
by cam
01:19
created
ecrire/action/tester.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -29,148 +29,148 @@  discard block
 block discarded – undo
29 29
  * redirige sur l'image ainsi créée (sinon sur une image d'echec).
30 30
  **/
31 31
 function action_tester_dist() {
32
-	$arg = _request('arg');
33
-
34
-	$gd_formats = [];
35
-	$gd_formats_read_gif = '';
36
-	// verifier les formats acceptes par GD
37
-	if ($arg == 'gd1') {
38
-		// Si GD est installe et php >= 4.0.2
39
-		if (function_exists('imagetypes')) {
40
-			if (imagetypes() & IMG_GIF) {
41
-				$gd_formats[] = 'gif';
42
-			} else {
43
-				# Attention GD sait lire le gif mais pas forcement l'ecrire
44
-				if (function_exists('ImageCreateFromGIF')) {
45
-					$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
46
-					if ($srcImage) {
47
-						$gd_formats_read_gif = ',gif';
48
-						ImageDestroy($srcImage);
49
-					}
50
-				}
51
-			}
52
-
53
-			if (imagetypes() & IMG_JPG) {
54
-				$gd_formats[] = 'jpg';
55
-			}
56
-			if (imagetypes() & IMG_PNG) {
57
-				$gd_formats[] = 'png';
58
-			}
59
-			if (imagetypes() & IMG_WEBP) {
60
-				$gd_formats[] = 'webp';
61
-			}
62
-		} else {
63
-			# ancienne methode de detection des formats, qui en plus
64
-			# est bugguee car elle teste les formats en lecture
65
-			# alors que la valeur deduite sert a identifier
66
-			# les formats disponibles en ecriture... (cf. inc_logos)
67
-
68
-			if (function_exists('ImageCreateFromJPEG')) {
69
-				$srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . 'test.jpg');
70
-				if ($srcImage) {
71
-					$gd_formats[] = 'jpg';
72
-					ImageDestroy($srcImage);
73
-				}
74
-			}
75
-			if (function_exists('ImageCreateFromGIF')) {
76
-				$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
77
-				if ($srcImage) {
78
-					$gd_formats[] = 'gif';
79
-					ImageDestroy($srcImage);
80
-				}
81
-			}
82
-			if (function_exists('ImageCreateFromPNG')) {
83
-				$srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . 'test.png');
84
-				if ($srcImage) {
85
-					$gd_formats[] = 'png';
86
-					ImageDestroy($srcImage);
87
-				}
88
-			}
89
-			if (function_exists('ImageCreateFromWEBP')) {
90
-				$srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . 'test.webp');
91
-				if ($srcImage) {
92
-					$gd_formats[] = 'webp';
93
-					ImageDestroy($srcImage);
94
-				}
95
-			}
96
-		}
97
-
98
-		if (! empty($gd_formats)) {
99
-			$gd_formats = implode(',', $gd_formats);
100
-		}
101
-		ecrire_meta('gd_formats_read', $gd_formats . $gd_formats_read_gif);
102
-		ecrire_meta('gd_formats', $gd_formats);
103
-	} // verifier les formats netpbm
104
-	else {
105
-		if ($arg == 'netpbm') {
106
-			if (!defined('_PNMSCALE_COMMAND')) {
107
-				define('_PNMSCALE_COMMAND', 'pnmscale');
108
-			} // Securite : mes_options.php peut preciser le chemin absolu
109
-			if (_PNMSCALE_COMMAND == '') {
110
-				return;
111
-			}
112
-			$netpbm_formats = [];
113
-
114
-			$jpegtopnm_command = str_replace(
115
-				'pnmscale',
116
-				'jpegtopnm',
117
-				_PNMSCALE_COMMAND
118
-			);
119
-			$pnmtojpeg_command = str_replace(
120
-				'pnmscale',
121
-				'pnmtojpeg',
122
-				_PNMSCALE_COMMAND
123
-			);
124
-
125
-			$vignette = _ROOT_IMG_PACK . 'test.jpg';
126
-			$dest = _DIR_VAR . 'test-jpg.jpg';
127
-			$commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
128
-			spip_log($commande);
129
-			exec($commande);
130
-			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
131
-				$netpbm_formats[] = 'jpg';
132
-			}
133
-			$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
134
-			$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
135
-			$vignette = _ROOT_IMG_PACK . 'test.gif';
136
-			$dest = _DIR_VAR . 'test-gif.jpg';
137
-			$commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
138
-			spip_log($commande);
139
-			exec($commande);
140
-			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
141
-				$netpbm_formats[] = 'gif';
142
-			}
143
-
144
-			$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
145
-			$vignette = _ROOT_IMG_PACK . 'test.png';
146
-			$dest = _DIR_VAR . 'test-gif.jpg';
147
-			$commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
148
-			spip_log($commande);
149
-			exec($commande);
150
-			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
151
-				$netpbm_formats[] = 'png';
152
-			}
153
-
154
-			ecrire_meta('netpbm_formats', implode(',', $netpbm_formats ?: []));
155
-		}
156
-	}
157
-
158
-	// et maintenant envoyer la vignette de tests
159
-	if (in_array($arg, ['gd1', 'gd2', 'imagick', 'convert', 'netpbm'])) {
160
-		include_spip('inc/filtres');
161
-		include_spip('inc/filtres_images_mini');
162
-		$taille_preview = 150;
163
-		$image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
164
-
165
-		$image['fichier_dest'] = _DIR_VAR . "test_$arg";
166
-
167
-		if (
168
-			($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)) && $preview['width'] * $preview['height'] > 0
169
-		) {
170
-			redirige_par_entete($preview['fichier']);
171
-		}
172
-	}
173
-
174
-	# image echec
175
-	redirige_par_entete(chemin_image('echec-reducteur-xx.svg'));
32
+    $arg = _request('arg');
33
+
34
+    $gd_formats = [];
35
+    $gd_formats_read_gif = '';
36
+    // verifier les formats acceptes par GD
37
+    if ($arg == 'gd1') {
38
+        // Si GD est installe et php >= 4.0.2
39
+        if (function_exists('imagetypes')) {
40
+            if (imagetypes() & IMG_GIF) {
41
+                $gd_formats[] = 'gif';
42
+            } else {
43
+                # Attention GD sait lire le gif mais pas forcement l'ecrire
44
+                if (function_exists('ImageCreateFromGIF')) {
45
+                    $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
46
+                    if ($srcImage) {
47
+                        $gd_formats_read_gif = ',gif';
48
+                        ImageDestroy($srcImage);
49
+                    }
50
+                }
51
+            }
52
+
53
+            if (imagetypes() & IMG_JPG) {
54
+                $gd_formats[] = 'jpg';
55
+            }
56
+            if (imagetypes() & IMG_PNG) {
57
+                $gd_formats[] = 'png';
58
+            }
59
+            if (imagetypes() & IMG_WEBP) {
60
+                $gd_formats[] = 'webp';
61
+            }
62
+        } else {
63
+            # ancienne methode de detection des formats, qui en plus
64
+            # est bugguee car elle teste les formats en lecture
65
+            # alors que la valeur deduite sert a identifier
66
+            # les formats disponibles en ecriture... (cf. inc_logos)
67
+
68
+            if (function_exists('ImageCreateFromJPEG')) {
69
+                $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . 'test.jpg');
70
+                if ($srcImage) {
71
+                    $gd_formats[] = 'jpg';
72
+                    ImageDestroy($srcImage);
73
+                }
74
+            }
75
+            if (function_exists('ImageCreateFromGIF')) {
76
+                $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
77
+                if ($srcImage) {
78
+                    $gd_formats[] = 'gif';
79
+                    ImageDestroy($srcImage);
80
+                }
81
+            }
82
+            if (function_exists('ImageCreateFromPNG')) {
83
+                $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . 'test.png');
84
+                if ($srcImage) {
85
+                    $gd_formats[] = 'png';
86
+                    ImageDestroy($srcImage);
87
+                }
88
+            }
89
+            if (function_exists('ImageCreateFromWEBP')) {
90
+                $srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . 'test.webp');
91
+                if ($srcImage) {
92
+                    $gd_formats[] = 'webp';
93
+                    ImageDestroy($srcImage);
94
+                }
95
+            }
96
+        }
97
+
98
+        if (! empty($gd_formats)) {
99
+            $gd_formats = implode(',', $gd_formats);
100
+        }
101
+        ecrire_meta('gd_formats_read', $gd_formats . $gd_formats_read_gif);
102
+        ecrire_meta('gd_formats', $gd_formats);
103
+    } // verifier les formats netpbm
104
+    else {
105
+        if ($arg == 'netpbm') {
106
+            if (!defined('_PNMSCALE_COMMAND')) {
107
+                define('_PNMSCALE_COMMAND', 'pnmscale');
108
+            } // Securite : mes_options.php peut preciser le chemin absolu
109
+            if (_PNMSCALE_COMMAND == '') {
110
+                return;
111
+            }
112
+            $netpbm_formats = [];
113
+
114
+            $jpegtopnm_command = str_replace(
115
+                'pnmscale',
116
+                'jpegtopnm',
117
+                _PNMSCALE_COMMAND
118
+            );
119
+            $pnmtojpeg_command = str_replace(
120
+                'pnmscale',
121
+                'pnmtojpeg',
122
+                _PNMSCALE_COMMAND
123
+            );
124
+
125
+            $vignette = _ROOT_IMG_PACK . 'test.jpg';
126
+            $dest = _DIR_VAR . 'test-jpg.jpg';
127
+            $commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
128
+            spip_log($commande);
129
+            exec($commande);
130
+            if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
131
+                $netpbm_formats[] = 'jpg';
132
+            }
133
+            $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
134
+            $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
135
+            $vignette = _ROOT_IMG_PACK . 'test.gif';
136
+            $dest = _DIR_VAR . 'test-gif.jpg';
137
+            $commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
138
+            spip_log($commande);
139
+            exec($commande);
140
+            if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
141
+                $netpbm_formats[] = 'gif';
142
+            }
143
+
144
+            $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
145
+            $vignette = _ROOT_IMG_PACK . 'test.png';
146
+            $dest = _DIR_VAR . 'test-gif.jpg';
147
+            $commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
148
+            spip_log($commande);
149
+            exec($commande);
150
+            if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
151
+                $netpbm_formats[] = 'png';
152
+            }
153
+
154
+            ecrire_meta('netpbm_formats', implode(',', $netpbm_formats ?: []));
155
+        }
156
+    }
157
+
158
+    // et maintenant envoyer la vignette de tests
159
+    if (in_array($arg, ['gd1', 'gd2', 'imagick', 'convert', 'netpbm'])) {
160
+        include_spip('inc/filtres');
161
+        include_spip('inc/filtres_images_mini');
162
+        $taille_preview = 150;
163
+        $image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
164
+
165
+        $image['fichier_dest'] = _DIR_VAR . "test_$arg";
166
+
167
+        if (
168
+            ($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)) && $preview['width'] * $preview['height'] > 0
169
+        ) {
170
+            redirige_par_entete($preview['fichier']);
171
+        }
172
+    }
173
+
174
+    # image echec
175
+    redirige_par_entete(chemin_image('echec-reducteur-xx.svg'));
176 176
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 			} else {
43 43
 				# Attention GD sait lire le gif mais pas forcement l'ecrire
44 44
 				if (function_exists('ImageCreateFromGIF')) {
45
-					$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
45
+					$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK.'test.gif');
46 46
 					if ($srcImage) {
47 47
 						$gd_formats_read_gif = ',gif';
48 48
 						ImageDestroy($srcImage);
@@ -66,28 +66,28 @@  discard block
 block discarded – undo
66 66
 			# les formats disponibles en ecriture... (cf. inc_logos)
67 67
 
68 68
 			if (function_exists('ImageCreateFromJPEG')) {
69
-				$srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . 'test.jpg');
69
+				$srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK.'test.jpg');
70 70
 				if ($srcImage) {
71 71
 					$gd_formats[] = 'jpg';
72 72
 					ImageDestroy($srcImage);
73 73
 				}
74 74
 			}
75 75
 			if (function_exists('ImageCreateFromGIF')) {
76
-				$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif');
76
+				$srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK.'test.gif');
77 77
 				if ($srcImage) {
78 78
 					$gd_formats[] = 'gif';
79 79
 					ImageDestroy($srcImage);
80 80
 				}
81 81
 			}
82 82
 			if (function_exists('ImageCreateFromPNG')) {
83
-				$srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . 'test.png');
83
+				$srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK.'test.png');
84 84
 				if ($srcImage) {
85 85
 					$gd_formats[] = 'png';
86 86
 					ImageDestroy($srcImage);
87 87
 				}
88 88
 			}
89 89
 			if (function_exists('ImageCreateFromWEBP')) {
90
-				$srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . 'test.webp');
90
+				$srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK.'test.webp');
91 91
 				if ($srcImage) {
92 92
 					$gd_formats[] = 'webp';
93 93
 					ImageDestroy($srcImage);
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
 			}
96 96
 		}
97 97
 
98
-		if (! empty($gd_formats)) {
98
+		if (!empty($gd_formats)) {
99 99
 			$gd_formats = implode(',', $gd_formats);
100 100
 		}
101
-		ecrire_meta('gd_formats_read', $gd_formats . $gd_formats_read_gif);
101
+		ecrire_meta('gd_formats_read', $gd_formats.$gd_formats_read_gif);
102 102
 		ecrire_meta('gd_formats', $gd_formats);
103 103
 	} // verifier les formats netpbm
104 104
 	else {
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 				_PNMSCALE_COMMAND
123 123
 			);
124 124
 
125
-			$vignette = _ROOT_IMG_PACK . 'test.jpg';
126
-			$dest = _DIR_VAR . 'test-jpg.jpg';
127
-			$commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
125
+			$vignette = _ROOT_IMG_PACK.'test.jpg';
126
+			$dest = _DIR_VAR.'test-jpg.jpg';
127
+			$commande = "$jpegtopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
128 128
 			spip_log($commande);
129 129
 			exec($commande);
130 130
 			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 			}
133 133
 			$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
134 134
 			$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
135
-			$vignette = _ROOT_IMG_PACK . 'test.gif';
136
-			$dest = _DIR_VAR . 'test-gif.jpg';
137
-			$commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
135
+			$vignette = _ROOT_IMG_PACK.'test.gif';
136
+			$dest = _DIR_VAR.'test-gif.jpg';
137
+			$commande = "$giftopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
138 138
 			spip_log($commande);
139 139
 			exec($commande);
140 140
 			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 			}
143 143
 
144 144
 			$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
145
-			$vignette = _ROOT_IMG_PACK . 'test.png';
146
-			$dest = _DIR_VAR . 'test-gif.jpg';
147
-			$commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest";
145
+			$vignette = _ROOT_IMG_PACK.'test.png';
146
+			$dest = _DIR_VAR.'test-gif.jpg';
147
+			$commande = "$pngtopnm_command $vignette | "._PNMSCALE_COMMAND." -width 10 | $pnmtojpeg_command > $dest";
148 148
 			spip_log($commande);
149 149
 			exec($commande);
150 150
 			if (($taille = @getimagesize($dest)) && $taille[1] == 10) {
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 		include_spip('inc/filtres');
161 161
 		include_spip('inc/filtres_images_mini');
162 162
 		$taille_preview = 150;
163
-		$image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
163
+		$image = _image_valeurs_trans(_DIR_IMG_PACK.'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg');
164 164
 
165
-		$image['fichier_dest'] = _DIR_VAR . "test_$arg";
165
+		$image['fichier_dest'] = _DIR_VAR."test_$arg";
166 166
 
167 167
 		if (
168 168
 			($preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true)) && $preview['width'] * $preview['height'] > 0
Please login to merge, or discard this patch.
ecrire/action/editer_article.php 1 patch
Indentation   +373 added lines, -373 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -38,36 +38,36 @@  discard block
 block discarded – undo
38 38
  *     Liste (identifiant de l'article, texte d'erreur éventuel)
39 39
  */
40 40
 function action_editer_article_dist($arg = null) {
41
-	include_spip('inc/autoriser');
42
-	$err = '';
43
-	if (is_null($arg)) {
44
-		$securiser_action = charger_fonction('securiser_action', 'inc');
45
-		$arg = $securiser_action();
46
-	}
47
-
48
-	// si id_article n'est pas un nombre, c'est une creation
49
-	// mais on verifie qu'on a toutes les donnees qu'il faut.
50
-	if (!$id_article = intval($arg)) {
51
-		$id_parent = _request('id_parent');
52
-		if (!$id_parent) {
53
-			$err = _L("creation interdite d'un article sans rubrique");
54
-		} elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
55
-			$err = _T('info_creerdansrubrique_non_autorise');
56
-		} else {
57
-			$id_article = article_inserer($id_parent);
58
-		}
59
-	}
60
-
61
-	// Enregistre l'envoi dans la BD
62
-	if ($id_article > 0) {
63
-		$err = article_modifier($id_article);
64
-	}
65
-
66
-	if ($err) {
67
-		spip_log("echec editeur article: $err", _LOG_ERREUR);
68
-	}
69
-
70
-	return [$id_article, $err];
41
+    include_spip('inc/autoriser');
42
+    $err = '';
43
+    if (is_null($arg)) {
44
+        $securiser_action = charger_fonction('securiser_action', 'inc');
45
+        $arg = $securiser_action();
46
+    }
47
+
48
+    // si id_article n'est pas un nombre, c'est une creation
49
+    // mais on verifie qu'on a toutes les donnees qu'il faut.
50
+    if (!$id_article = intval($arg)) {
51
+        $id_parent = _request('id_parent');
52
+        if (!$id_parent) {
53
+            $err = _L("creation interdite d'un article sans rubrique");
54
+        } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) {
55
+            $err = _T('info_creerdansrubrique_non_autorise');
56
+        } else {
57
+            $id_article = article_inserer($id_parent);
58
+        }
59
+    }
60
+
61
+    // Enregistre l'envoi dans la BD
62
+    if ($id_article > 0) {
63
+        $err = article_modifier($id_article);
64
+    }
65
+
66
+    if ($err) {
67
+        spip_log("echec editeur article: $err", _LOG_ERREUR);
68
+    }
69
+
70
+    return [$id_article, $err];
71 71
 }
72 72
 
73 73
 /**
@@ -89,50 +89,50 @@  discard block
 block discarded – undo
89 89
  */
90 90
 function article_modifier($id_article, $set = null) {
91 91
 
92
-	// unifier $texte en cas de texte trop long
93
-	trop_longs_articles();
94
-
95
-	include_spip('inc/modifier');
96
-	include_spip('inc/filtres');
97
-	$c = collecter_requests(
98
-		// include list
99
-		objet_info('article', 'champs_editables'),
100
-		// exclude list
101
-		['date', 'statut', 'id_parent'],
102
-		// donnees eventuellement fournies
103
-		$set
104
-	);
105
-
106
-	// Si l'article est publie, invalider les caches et demander sa reindexation
107
-	$t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article));
108
-	$invalideur = $indexation = false;
109
-	if ($t == 'publie') {
110
-		$invalideur = "id='article/$id_article'";
111
-		$indexation = true;
112
-	}
113
-
114
-	if (
115
-		$err = objet_modifier_champs(
116
-			'article',
117
-			$id_article,
118
-			[
119
-			'data' => $set,
120
-			'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article],
121
-			'invalideur' => $invalideur,
122
-			'indexation' => $indexation,
123
-			'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
124
-			],
125
-			$c
126
-		)
127
-	) {
128
-		return $err;
129
-	}
130
-
131
-	// Modification de statut, changement de rubrique ?
132
-	$c = collecter_requests(['date', 'statut', 'id_parent'], [], $set);
133
-	$err = article_instituer($id_article, $c);
134
-
135
-	return $err;
92
+    // unifier $texte en cas de texte trop long
93
+    trop_longs_articles();
94
+
95
+    include_spip('inc/modifier');
96
+    include_spip('inc/filtres');
97
+    $c = collecter_requests(
98
+        // include list
99
+        objet_info('article', 'champs_editables'),
100
+        // exclude list
101
+        ['date', 'statut', 'id_parent'],
102
+        // donnees eventuellement fournies
103
+        $set
104
+    );
105
+
106
+    // Si l'article est publie, invalider les caches et demander sa reindexation
107
+    $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article));
108
+    $invalideur = $indexation = false;
109
+    if ($t == 'publie') {
110
+        $invalideur = "id='article/$id_article'";
111
+        $indexation = true;
112
+    }
113
+
114
+    if (
115
+        $err = objet_modifier_champs(
116
+            'article',
117
+            $id_article,
118
+            [
119
+            'data' => $set,
120
+            'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article],
121
+            'invalideur' => $invalideur,
122
+            'indexation' => $indexation,
123
+            'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
124
+            ],
125
+            $c
126
+        )
127
+    ) {
128
+        return $err;
129
+    }
130
+
131
+    // Modification de statut, changement de rubrique ?
132
+    $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set);
133
+    $err = article_instituer($id_article, $c);
134
+
135
+    return $err;
136 136
 }
137 137
 
138 138
 /**
@@ -168,120 +168,120 @@  discard block
 block discarded – undo
168 168
  */
169 169
 function article_inserer($id_rubrique, $set = null) {
170 170
 
171
-	// Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
172
-	// dans la premiere rubrique racine
173
-	if (!$id_rubrique = intval($id_rubrique)) {
174
-		$row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
175
-		$id_rubrique = $row['id_rubrique'];
176
-	} else {
177
-		$row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique");
178
-	}
179
-
180
-	// eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue
181
-	// cas de id_rubrique = -1 par exemple avec plugin "pages"
182
-	$id_secteur = $row['id_secteur'] ?? 0;
183
-	$lang_rub = $row['lang'] ?? '';
184
-
185
-	$lang = '';
186
-	$choisie = 'non';
187
-	// La langue a la creation : si les liens de traduction sont autorises
188
-	// dans les rubriques, on essaie avec la langue de l'auteur,
189
-	// ou a defaut celle de la rubrique
190
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
191
-	if (
192
-		!empty($GLOBALS['meta']['multi_objets']) and in_array(
193
-			'spip_articles',
194
-			explode(',', $GLOBALS['meta']['multi_objets'])
195
-		)
196
-	) {
197
-		lang_select($GLOBALS['visiteur_session']['lang']);
198
-		if (
199
-			in_array(
200
-				$GLOBALS['spip_lang'],
201
-				explode(',', $GLOBALS['meta']['langues_multilingue'])
202
-			)
203
-		) {
204
-			$lang = $GLOBALS['spip_lang'];
205
-			$choisie = 'oui';
206
-		}
207
-	}
208
-
209
-	if (!$lang) {
210
-		$choisie = 'non';
211
-		$lang = $lang_rub ?: $GLOBALS['meta']['langue_site'];
212
-	}
213
-
214
-	$champs = [
215
-		'id_rubrique' => $id_rubrique,
216
-		'id_secteur' => $id_secteur,
217
-		'statut' => 'prepa',
218
-		'date' => date('Y-m-d H:i:s'),
219
-		'lang' => $lang,
220
-		'langue_choisie' => $choisie
221
-	];
222
-
223
-	if ($set) {
224
-		$champs = array_merge($champs, $set);
225
-	}
226
-
227
-	// Envoyer aux plugins
228
-	$champs = pipeline(
229
-		'pre_insertion',
230
-		[
231
-			'args' => [
232
-				'table' => 'spip_articles',
233
-			],
234
-			'data' => $champs
235
-		]
236
-	);
237
-
238
-	$id_article = sql_insertq('spip_articles', $champs);
239
-
240
-	// controler si le serveur n'a pas renvoye une erreur
241
-	if ($id_article > 0) {
242
-		$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
243
-			$GLOBALS['visiteur_session']['id_auteur']
244
-			: _request('id_auteur'));
245
-		if ($id_auteur) {
246
-			include_spip('action/editer_auteur');
247
-			auteur_associer($id_auteur, ['article' => $id_article]);
248
-		}
249
-	}
250
-
251
-	pipeline(
252
-		'post_insertion',
253
-		[
254
-			'args' => [
255
-				'table' => 'spip_articles',
256
-				'id_objet' => $id_article
257
-			],
258
-			'data' => $champs
259
-		]
260
-	);
261
-
262
-	// Appeler une notification
263
-	if ($notifications = charger_fonction('notifications', 'inc')) {
264
-		$notifications(
265
-			'article_inserer',
266
-			$id_article,
267
-			[
268
-				'id_parent' => $id_rubrique,
269
-				'champs' => $champs,
270
-			]
271
-		);
272
-		$notifications(
273
-			'objet_inserer',
274
-			$id_article,
275
-			[
276
-				'objet' => 'article',
277
-				'id_objet' => $id_article,
278
-				'id_parent' => $id_rubrique,
279
-				'champs' => $champs,
280
-			]
281
-		);
282
-	}
283
-
284
-	return $id_article;
171
+    // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
172
+    // dans la premiere rubrique racine
173
+    if (!$id_rubrique = intval($id_rubrique)) {
174
+        $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
175
+        $id_rubrique = $row['id_rubrique'];
176
+    } else {
177
+        $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique");
178
+    }
179
+
180
+    // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue
181
+    // cas de id_rubrique = -1 par exemple avec plugin "pages"
182
+    $id_secteur = $row['id_secteur'] ?? 0;
183
+    $lang_rub = $row['lang'] ?? '';
184
+
185
+    $lang = '';
186
+    $choisie = 'non';
187
+    // La langue a la creation : si les liens de traduction sont autorises
188
+    // dans les rubriques, on essaie avec la langue de l'auteur,
189
+    // ou a defaut celle de la rubrique
190
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
191
+    if (
192
+        !empty($GLOBALS['meta']['multi_objets']) and in_array(
193
+            'spip_articles',
194
+            explode(',', $GLOBALS['meta']['multi_objets'])
195
+        )
196
+    ) {
197
+        lang_select($GLOBALS['visiteur_session']['lang']);
198
+        if (
199
+            in_array(
200
+                $GLOBALS['spip_lang'],
201
+                explode(',', $GLOBALS['meta']['langues_multilingue'])
202
+            )
203
+        ) {
204
+            $lang = $GLOBALS['spip_lang'];
205
+            $choisie = 'oui';
206
+        }
207
+    }
208
+
209
+    if (!$lang) {
210
+        $choisie = 'non';
211
+        $lang = $lang_rub ?: $GLOBALS['meta']['langue_site'];
212
+    }
213
+
214
+    $champs = [
215
+        'id_rubrique' => $id_rubrique,
216
+        'id_secteur' => $id_secteur,
217
+        'statut' => 'prepa',
218
+        'date' => date('Y-m-d H:i:s'),
219
+        'lang' => $lang,
220
+        'langue_choisie' => $choisie
221
+    ];
222
+
223
+    if ($set) {
224
+        $champs = array_merge($champs, $set);
225
+    }
226
+
227
+    // Envoyer aux plugins
228
+    $champs = pipeline(
229
+        'pre_insertion',
230
+        [
231
+            'args' => [
232
+                'table' => 'spip_articles',
233
+            ],
234
+            'data' => $champs
235
+        ]
236
+    );
237
+
238
+    $id_article = sql_insertq('spip_articles', $champs);
239
+
240
+    // controler si le serveur n'a pas renvoye une erreur
241
+    if ($id_article > 0) {
242
+        $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
243
+            $GLOBALS['visiteur_session']['id_auteur']
244
+            : _request('id_auteur'));
245
+        if ($id_auteur) {
246
+            include_spip('action/editer_auteur');
247
+            auteur_associer($id_auteur, ['article' => $id_article]);
248
+        }
249
+    }
250
+
251
+    pipeline(
252
+        'post_insertion',
253
+        [
254
+            'args' => [
255
+                'table' => 'spip_articles',
256
+                'id_objet' => $id_article
257
+            ],
258
+            'data' => $champs
259
+        ]
260
+    );
261
+
262
+    // Appeler une notification
263
+    if ($notifications = charger_fonction('notifications', 'inc')) {
264
+        $notifications(
265
+            'article_inserer',
266
+            $id_article,
267
+            [
268
+                'id_parent' => $id_rubrique,
269
+                'champs' => $champs,
270
+            ]
271
+        );
272
+        $notifications(
273
+            'objet_inserer',
274
+            $id_article,
275
+            [
276
+                'objet' => 'article',
277
+                'id_objet' => $id_article,
278
+                'id_parent' => $id_rubrique,
279
+                'champs' => $champs,
280
+            ]
281
+        );
282
+    }
283
+
284
+    return $id_article;
285 285
 }
286 286
 
287 287
 
@@ -309,153 +309,153 @@  discard block
 block discarded – undo
309 309
  */
310 310
 function article_instituer($id_article, $c, $calcul_rub = true) {
311 311
 
312
-	include_spip('inc/autoriser');
313
-	include_spip('inc/rubriques');
314
-	include_spip('inc/modifier');
315
-
316
-	$row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article");
317
-	$id_rubrique = $row['id_rubrique'];
318
-	$statut_ancien = $statut = $row['statut'];
319
-	$date_ancienne = $date = $row['date'];
320
-	$champs = [];
321
-
322
-	$d = $c['date'] ?? null;
323
-	$s = $c['statut'] ?? $statut;
324
-
325
-	// cf autorisations dans inc/instituer_article
326
-	if ($s != $statut or ($d and $d != $date)) {
327
-		if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
328
-			$statut = $champs['statut'] = $s;
329
-		} elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
330
-			$statut = $champs['statut'] = $s;
331
-		} else {
332
-			spip_log("editer_article $id_article refus " . join(' ', $c));
333
-		}
334
-
335
-		// En cas de publication, fixer la date a "maintenant"
336
-		// sauf si $c commande autre chose
337
-		// ou si l'article est deja date dans le futur
338
-		// En cas de proposition d'un article (mais pas depublication), idem
339
-		if (
340
-			$champs['statut'] == 'publie'
341
-			or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop'])))
342
-		) {
343
-			if ($d or strtotime($d = $date) > time()) {
344
-				$champs['date'] = $date = $d;
345
-			} else {
346
-				$champs['date'] = $date = date('Y-m-d H:i:s');
347
-			}
348
-		}
349
-	}
350
-
351
-	// Verifier que la rubrique demandee existe et est differente
352
-	// de la rubrique actuelle
353
-	if (
354
-		isset($c['id_parent'])
355
-		and $id_parent = $c['id_parent']
356
-		and $id_parent != $id_rubrique
357
-		and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
358
-	) {
359
-		$champs['id_rubrique'] = $id_parent;
360
-
361
-		// si l'article etait publie
362
-		// et que le demandeur n'est pas admin de la rubrique de destination
363
-		// repasser l'article en statut 'propose'.
364
-		if (
365
-			$statut == 'publie'
366
-			and !autoriser('publierdans', 'rubrique', $id_parent)
367
-		) {
368
-			$champs['statut'] = 'prop';
369
-		}
370
-	}
371
-
372
-	// Envoyer aux plugins
373
-	$champs = pipeline(
374
-		'pre_edition',
375
-		[
376
-			'args' => [
377
-				'table' => 'spip_articles',
378
-				'id_objet' => $id_article,
379
-				'action' => 'instituer',
380
-				'statut_ancien' => $statut_ancien,
381
-				'date_ancienne' => $date_ancienne,
382
-			],
383
-			'data' => $champs
384
-		]
385
-	);
386
-
387
-	if (!(is_countable($champs) ? count($champs) : 0)) {
388
-		return '';
389
-	}
390
-
391
-	// Envoyer les modifs.
392
-	editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
393
-
394
-	// Invalider les caches
395
-	include_spip('inc/invalideur');
396
-	suivre_invalideur("id='article/$id_article'");
397
-
398
-	if ($date) {
399
-		$t = strtotime($date);
400
-		$p = @$GLOBALS['meta']['date_prochain_postdate'];
401
-		if ($t > time() and (!$p or ($t < $p))) {
402
-			ecrire_meta('date_prochain_postdate', $t);
403
-		}
404
-	}
405
-
406
-	// Pipeline
407
-	pipeline(
408
-		'post_edition',
409
-		[
410
-			'args' => [
411
-				'table' => 'spip_articles',
412
-				'id_objet' => $id_article,
413
-				'action' => 'instituer',
414
-				'statut_ancien' => $statut_ancien,
415
-				'date_ancienne' => $date_ancienne,
416
-			],
417
-			'data' => $champs
418
-		]
419
-	);
420
-
421
-	// Notifications
422
-	if ($notifications = charger_fonction('notifications', 'inc')) {
423
-		$notifications(
424
-			'article_instituer',
425
-			$id_article,
426
-			[
427
-				'statut' => $statut,
428
-				'statut_ancien' => $statut_ancien,
429
-				'date' => $date,
430
-				'date_ancienne' => $date_ancienne,
431
-				'id_parent_ancien' => $id_rubrique,
432
-				'champs' => $champs,
433
-			]
434
-		);
435
-		$notifications(
436
-			'objet_instituer',
437
-			$id_article,
438
-			[
439
-				'objet' => 'article',
440
-				'id_objet' => $id_article,
441
-				'statut' => $statut,
442
-				'statut_ancien' => $statut_ancien,
443
-				'date' => $date,
444
-				'date_ancienne' => $date_ancienne,
445
-				'id_parent_ancien' => $id_rubrique,
446
-				'champs' => $champs,
447
-			]
448
-		);
449
-
450
-		// Rétro-compat
451
-		$notifications(
452
-			'instituerarticle',
453
-			$id_article,
454
-			['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
455
-		);
456
-	}
457
-
458
-	return ''; // pas d'erreur
312
+    include_spip('inc/autoriser');
313
+    include_spip('inc/rubriques');
314
+    include_spip('inc/modifier');
315
+
316
+    $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article");
317
+    $id_rubrique = $row['id_rubrique'];
318
+    $statut_ancien = $statut = $row['statut'];
319
+    $date_ancienne = $date = $row['date'];
320
+    $champs = [];
321
+
322
+    $d = $c['date'] ?? null;
323
+    $s = $c['statut'] ?? $statut;
324
+
325
+    // cf autorisations dans inc/instituer_article
326
+    if ($s != $statut or ($d and $d != $date)) {
327
+        if (autoriser('publierdans', 'rubrique', $id_rubrique)) {
328
+            $statut = $champs['statut'] = $s;
329
+        } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') {
330
+            $statut = $champs['statut'] = $s;
331
+        } else {
332
+            spip_log("editer_article $id_article refus " . join(' ', $c));
333
+        }
334
+
335
+        // En cas de publication, fixer la date a "maintenant"
336
+        // sauf si $c commande autre chose
337
+        // ou si l'article est deja date dans le futur
338
+        // En cas de proposition d'un article (mais pas depublication), idem
339
+        if (
340
+            $champs['statut'] == 'publie'
341
+            or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop'])))
342
+        ) {
343
+            if ($d or strtotime($d = $date) > time()) {
344
+                $champs['date'] = $date = $d;
345
+            } else {
346
+                $champs['date'] = $date = date('Y-m-d H:i:s');
347
+            }
348
+        }
349
+    }
350
+
351
+    // Verifier que la rubrique demandee existe et est differente
352
+    // de la rubrique actuelle
353
+    if (
354
+        isset($c['id_parent'])
355
+        and $id_parent = $c['id_parent']
356
+        and $id_parent != $id_rubrique
357
+        and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
358
+    ) {
359
+        $champs['id_rubrique'] = $id_parent;
360
+
361
+        // si l'article etait publie
362
+        // et que le demandeur n'est pas admin de la rubrique de destination
363
+        // repasser l'article en statut 'propose'.
364
+        if (
365
+            $statut == 'publie'
366
+            and !autoriser('publierdans', 'rubrique', $id_parent)
367
+        ) {
368
+            $champs['statut'] = 'prop';
369
+        }
370
+    }
371
+
372
+    // Envoyer aux plugins
373
+    $champs = pipeline(
374
+        'pre_edition',
375
+        [
376
+            'args' => [
377
+                'table' => 'spip_articles',
378
+                'id_objet' => $id_article,
379
+                'action' => 'instituer',
380
+                'statut_ancien' => $statut_ancien,
381
+                'date_ancienne' => $date_ancienne,
382
+            ],
383
+            'data' => $champs
384
+        ]
385
+    );
386
+
387
+    if (!(is_countable($champs) ? count($champs) : 0)) {
388
+        return '';
389
+    }
390
+
391
+    // Envoyer les modifs.
392
+    editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
393
+
394
+    // Invalider les caches
395
+    include_spip('inc/invalideur');
396
+    suivre_invalideur("id='article/$id_article'");
397
+
398
+    if ($date) {
399
+        $t = strtotime($date);
400
+        $p = @$GLOBALS['meta']['date_prochain_postdate'];
401
+        if ($t > time() and (!$p or ($t < $p))) {
402
+            ecrire_meta('date_prochain_postdate', $t);
403
+        }
404
+    }
405
+
406
+    // Pipeline
407
+    pipeline(
408
+        'post_edition',
409
+        [
410
+            'args' => [
411
+                'table' => 'spip_articles',
412
+                'id_objet' => $id_article,
413
+                'action' => 'instituer',
414
+                'statut_ancien' => $statut_ancien,
415
+                'date_ancienne' => $date_ancienne,
416
+            ],
417
+            'data' => $champs
418
+        ]
419
+    );
420
+
421
+    // Notifications
422
+    if ($notifications = charger_fonction('notifications', 'inc')) {
423
+        $notifications(
424
+            'article_instituer',
425
+            $id_article,
426
+            [
427
+                'statut' => $statut,
428
+                'statut_ancien' => $statut_ancien,
429
+                'date' => $date,
430
+                'date_ancienne' => $date_ancienne,
431
+                'id_parent_ancien' => $id_rubrique,
432
+                'champs' => $champs,
433
+            ]
434
+        );
435
+        $notifications(
436
+            'objet_instituer',
437
+            $id_article,
438
+            [
439
+                'objet' => 'article',
440
+                'id_objet' => $id_article,
441
+                'statut' => $statut,
442
+                'statut_ancien' => $statut_ancien,
443
+                'date' => $date,
444
+                'date_ancienne' => $date_ancienne,
445
+                'id_parent_ancien' => $id_rubrique,
446
+                'champs' => $champs,
447
+            ]
448
+        );
449
+
450
+        // Rétro-compat
451
+        $notifications(
452
+            'instituerarticle',
453
+            $id_article,
454
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
455
+        );
456
+    }
457
+
458
+    return ''; // pas d'erreur
459 459
 }
460 460
 
461 461
 /**
@@ -480,37 +480,37 @@  discard block
 block discarded – undo
480 480
  */
481 481
 function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) {
482 482
 
483
-	// Si on deplace l'article
484
-	//  changer aussi son secteur et sa langue (si heritee)
485
-	if (isset($champs['id_rubrique'])) {
486
-		$row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
487
-
488
-		$langue = $row_rub['lang'];
489
-		$champs['id_secteur'] = $row_rub['id_secteur'];
490
-		if (
491
-			sql_fetsel(
492
-				'1',
493
-				'spip_articles',
494
-				'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
495
-			)
496
-		) {
497
-			$champs['lang'] = $langue;
498
-		}
499
-	}
500
-
501
-	if (!$champs) {
502
-		return;
503
-	}
504
-
505
-	sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article));
506
-
507
-	// Changer le statut des rubriques concernees
508
-
509
-	if ($cond) {
510
-		include_spip('inc/rubriques');
511
-		$postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
512
-		calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate);
513
-	}
483
+    // Si on deplace l'article
484
+    //  changer aussi son secteur et sa langue (si heritee)
485
+    if (isset($champs['id_rubrique'])) {
486
+        $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
487
+
488
+        $langue = $row_rub['lang'];
489
+        $champs['id_secteur'] = $row_rub['id_secteur'];
490
+        if (
491
+            sql_fetsel(
492
+                '1',
493
+                'spip_articles',
494
+                'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
495
+            )
496
+        ) {
497
+            $champs['lang'] = $langue;
498
+        }
499
+    }
500
+
501
+    if (!$champs) {
502
+        return;
503
+    }
504
+
505
+    sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article));
506
+
507
+    // Changer le statut des rubriques concernees
508
+
509
+    if ($cond) {
510
+        include_spip('inc/rubriques');
511
+        $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false;
512
+        calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate);
513
+    }
514 514
 }
515 515
 
516 516
 /**
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
  * @return void
520 520
  */
521 521
 function trop_longs_articles() {
522
-	if (is_array($plus = _request('texte_plus'))) {
523
-		foreach ($plus as $n => $t) {
524
-			$plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t);
525
-		}
526
-		set_request('texte', join('', $plus) . _request('texte'));
527
-	}
522
+    if (is_array($plus = _request('texte_plus'))) {
523
+        foreach ($plus as $n => $t) {
524
+            $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t);
525
+        }
526
+        set_request('texte', join('', $plus) . _request('texte'));
527
+    }
528 528
 }
Please login to merge, or discard this patch.
ecrire/action/editer_rubrique.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Rubriques\Edition
16 16
  */
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/rubriques');
@@ -37,34 +37,34 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function action_editer_rubrique_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
-	if (!$id_rubrique = intval($arg)) {
46
-		if ($arg != 'oui') {
47
-			include_spip('inc/headers');
48
-			redirige_url_ecrire();
49
-		}
50
-		$id_rubrique = rubrique_inserer(_request('id_parent'));
51
-	}
52
-
53
-	$err = rubrique_modifier($id_rubrique);
54
-
55
-	if (_request('redirect')) {
56
-		$redirect = parametre_url(
57
-			urldecode(_request('redirect')),
58
-			'id_rubrique',
59
-			$id_rubrique,
60
-			'&'
61
-		);
62
-
63
-		include_spip('inc/headers');
64
-		redirige_par_entete($redirect);
65
-	}
66
-
67
-	return [$id_rubrique, $err];
40
+    if (is_null($arg)) {
41
+        $securiser_action = charger_fonction('securiser_action', 'inc');
42
+        $arg = $securiser_action();
43
+    }
44
+
45
+    if (!$id_rubrique = intval($arg)) {
46
+        if ($arg != 'oui') {
47
+            include_spip('inc/headers');
48
+            redirige_url_ecrire();
49
+        }
50
+        $id_rubrique = rubrique_inserer(_request('id_parent'));
51
+    }
52
+
53
+    $err = rubrique_modifier($id_rubrique);
54
+
55
+    if (_request('redirect')) {
56
+        $redirect = parametre_url(
57
+            urldecode(_request('redirect')),
58
+            'id_rubrique',
59
+            $id_rubrique,
60
+            '&'
61
+        );
62
+
63
+        include_spip('inc/headers');
64
+        redirige_par_entete($redirect);
65
+    }
66
+
67
+    return [$id_rubrique, $err];
68 68
 }
69 69
 
70 70
 
@@ -79,64 +79,64 @@  discard block
 block discarded – undo
79 79
  *     Identifiant de la rubrique crée
80 80
  */
81 81
 function rubrique_inserer($id_parent, $set = null) {
82
-	$champs = [
83
-		'titre' => _T('item_nouvelle_rubrique'),
84
-		'id_parent' => intval($id_parent),
85
-		'statut' => 'prepa'
86
-	];
87
-
88
-	if ($set) {
89
-		$champs = array_merge($champs, $set);
90
-	}
91
-
92
-	// Envoyer aux plugins
93
-	$champs = pipeline(
94
-		'pre_insertion',
95
-		[
96
-			'args' => [
97
-				'table' => 'spip_rubriques',
98
-			],
99
-			'data' => $champs
100
-		]
101
-	);
102
-
103
-	$id_rubrique = sql_insertq('spip_rubriques', $champs);
104
-	pipeline(
105
-		'post_insertion',
106
-		[
107
-			'args' => [
108
-				'table' => 'spip_rubriques',
109
-				'id_objet' => $id_rubrique
110
-			],
111
-			'data' => $champs
112
-		]
113
-	);
114
-	propager_les_secteurs();
115
-	calculer_langues_rubriques();
116
-
117
-	// Appeler une notification
118
-	if ($notifications = charger_fonction('notifications', 'inc')) {
119
-		$notifications(
120
-			'rubrique_inserer',
121
-			$id_rubrique,
122
-			[
123
-				'id_parent' => $id_parent,
124
-				'champs' => $champs,
125
-			]
126
-		);
127
-		$notifications(
128
-			'objet_inserer',
129
-			$id_rubrique,
130
-			[
131
-				'objet' => 'rubrique',
132
-				'id_objet' => $id_rubrique,
133
-				'id_parent' => $id_parent,
134
-				'champs' => $champs,
135
-			]
136
-		);
137
-	}
138
-
139
-	return $id_rubrique;
82
+    $champs = [
83
+        'titre' => _T('item_nouvelle_rubrique'),
84
+        'id_parent' => intval($id_parent),
85
+        'statut' => 'prepa'
86
+    ];
87
+
88
+    if ($set) {
89
+        $champs = array_merge($champs, $set);
90
+    }
91
+
92
+    // Envoyer aux plugins
93
+    $champs = pipeline(
94
+        'pre_insertion',
95
+        [
96
+            'args' => [
97
+                'table' => 'spip_rubriques',
98
+            ],
99
+            'data' => $champs
100
+        ]
101
+    );
102
+
103
+    $id_rubrique = sql_insertq('spip_rubriques', $champs);
104
+    pipeline(
105
+        'post_insertion',
106
+        [
107
+            'args' => [
108
+                'table' => 'spip_rubriques',
109
+                'id_objet' => $id_rubrique
110
+            ],
111
+            'data' => $champs
112
+        ]
113
+    );
114
+    propager_les_secteurs();
115
+    calculer_langues_rubriques();
116
+
117
+    // Appeler une notification
118
+    if ($notifications = charger_fonction('notifications', 'inc')) {
119
+        $notifications(
120
+            'rubrique_inserer',
121
+            $id_rubrique,
122
+            [
123
+                'id_parent' => $id_parent,
124
+                'champs' => $champs,
125
+            ]
126
+        );
127
+        $notifications(
128
+            'objet_inserer',
129
+            $id_rubrique,
130
+            [
131
+                'objet' => 'rubrique',
132
+                'id_objet' => $id_rubrique,
133
+                'id_parent' => $id_parent,
134
+                'champs' => $champs,
135
+            ]
136
+        );
137
+    }
138
+
139
+    return $id_rubrique;
140 140
 }
141 141
 
142 142
 /**
@@ -152,46 +152,46 @@  discard block
 block discarded – undo
152 152
  *     - chaîne : texte d'un message d'erreur
153 153
  */
154 154
 function rubrique_modifier($id_rubrique, $set = null) {
155
-	include_spip('inc/autoriser');
156
-	include_spip('inc/filtres');
157
-
158
-	include_spip('inc/modifier');
159
-	$c = collecter_requests(
160
-		// include list
161
-		objet_info('rubrique', 'champs_editables'),
162
-		// exclude list
163
-		['id_parent', 'confirme_deplace'],
164
-		// donnees eventuellement fournies
165
-		$set
166
-	);
167
-
168
-	if (
169
-		$err = objet_modifier_champs(
170
-			'rubrique',
171
-			$id_rubrique,
172
-			[
173
-			'data' => $set,
174
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
175
-			],
176
-			$c
177
-		)
178
-	) {
179
-		return $err;
180
-	}
181
-
182
-	$c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
183
-	// Deplacer la rubrique
184
-	if (isset($c['id_parent'])) {
185
-		$err = rubrique_instituer($id_rubrique, $c);
186
-	}
187
-
188
-	// invalider les caches marques de cette rubrique
189
-	include_spip('inc/invalideur');
190
-	suivre_invalideur("id='rubrique/$id_rubrique'");
191
-	// et celui de menu_rubriques
192
-	effacer_meta('date_calcul_rubriques');
193
-
194
-	return $err;
155
+    include_spip('inc/autoriser');
156
+    include_spip('inc/filtres');
157
+
158
+    include_spip('inc/modifier');
159
+    $c = collecter_requests(
160
+        // include list
161
+        objet_info('rubrique', 'champs_editables'),
162
+        // exclude list
163
+        ['id_parent', 'confirme_deplace'],
164
+        // donnees eventuellement fournies
165
+        $set
166
+    );
167
+
168
+    if (
169
+        $err = objet_modifier_champs(
170
+            'rubrique',
171
+            $id_rubrique,
172
+            [
173
+            'data' => $set,
174
+            'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
175
+            ],
176
+            $c
177
+        )
178
+    ) {
179
+        return $err;
180
+    }
181
+
182
+    $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
183
+    // Deplacer la rubrique
184
+    if (isset($c['id_parent'])) {
185
+        $err = rubrique_instituer($id_rubrique, $c);
186
+    }
187
+
188
+    // invalider les caches marques de cette rubrique
189
+    include_spip('inc/invalideur');
190
+    suivre_invalideur("id='rubrique/$id_rubrique'");
191
+    // et celui de menu_rubriques
192
+    effacer_meta('date_calcul_rubriques');
193
+
194
+    return $err;
195 195
 }
196 196
 
197 197
 /**
@@ -214,29 +214,29 @@  discard block
 block discarded – undo
214 214
  *     false si la confirmation du déplacement n'est pas présente
215 215
  */
216 216
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) {
217
-	if (!sql_table_exists('spip_breves')) {
218
-		return true;
219
-	}
220
-
221
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
222
-		return true;
223
-	}
224
-
225
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
226
-		return false;
227
-	}
228
-
229
-	if (
230
-		$id_secteur = sql_getfetsel(
231
-			'id_secteur',
232
-			'spip_rubriques',
233
-			"id_rubrique=$id_parent"
234
-		)
235
-	) {
236
-		sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
237
-	}
238
-
239
-	return true;
217
+    if (!sql_table_exists('spip_breves')) {
218
+        return true;
219
+    }
220
+
221
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
222
+        return true;
223
+    }
224
+
225
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
226
+        return false;
227
+    }
228
+
229
+    if (
230
+        $id_secteur = sql_getfetsel(
231
+            'id_secteur',
232
+            'spip_rubriques',
233
+            "id_rubrique=$id_parent"
234
+        )
235
+    ) {
236
+        sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
237
+    }
238
+
239
+    return true;
240 240
 }
241 241
 
242 242
 
@@ -258,72 +258,72 @@  discard block
 block discarded – undo
258 258
  *     Chaîne : texte du message d'erreur
259 259
  */
260 260
 function rubrique_instituer($id_rubrique, $c) {
261
-	// traitement de la rubrique parente
262
-	// interdiction de deplacer vers ou a partir d'une rubrique
263
-	// qu'on n'administre pas.
264
-
265
-	if (null !== ($id_parent = $c['id_parent'])) {
266
-		$id_parent = intval($id_parent);
267
-		$filles = calcul_branche_in($id_rubrique);
268
-		if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
269
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
270
-		} else {
271
-			$s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
272
-			$old_parent = $s['id_parent'];
273
-
274
-			if (
275
-				!($id_parent != $old_parent
276
-				and autoriser('publierdans', 'rubrique', $id_parent)
277
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
278
-				and autoriser('publierdans', 'rubrique', $old_parent)
279
-				)
280
-			) {
281
-				if ($s['statut'] != 'prepa') {
282
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
283
-				}
284
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
285
-				$statut_ancien = $s['statut'];
286
-				sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
287
-
288
-
289
-				propager_les_secteurs();
290
-
291
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
292
-				if ($statut_ancien == 'publie') {
293
-					calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
294
-				}
295
-				// Creation ou deplacement d'une rubrique non publiee
296
-				// invalider le cache de leur menu
297
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
298
-					effacer_meta('date_calcul_rubriques');
299
-				}
300
-
301
-				calculer_langues_rubriques();
302
-
303
-				// Appeler une notification
304
-				if ($notifications = charger_fonction('notifications', 'inc')) {
305
-					$notifications(
306
-						'rubrique_instituer',
307
-						$id_rubrique,
308
-						[
309
-							'statut_ancien' => $statut_ancien,
310
-							'id_parent_ancien' => $old_parent,
311
-						]
312
-					);
313
-					$notifications(
314
-						'objet_instituer',
315
-						$id_rubrique,
316
-						[
317
-							'objet' => 'rubrique',
318
-							'id_objet' => $id_rubrique,
319
-							'statut_ancien' => $statut_ancien,
320
-							'id_parent_ancien' => $old_parent,
321
-						]
322
-					);
323
-				}
324
-			}
325
-		}
326
-	}
327
-
328
-	return ''; // pas d'erreur
261
+    // traitement de la rubrique parente
262
+    // interdiction de deplacer vers ou a partir d'une rubrique
263
+    // qu'on n'administre pas.
264
+
265
+    if (null !== ($id_parent = $c['id_parent'])) {
266
+        $id_parent = intval($id_parent);
267
+        $filles = calcul_branche_in($id_rubrique);
268
+        if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
269
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
270
+        } else {
271
+            $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
272
+            $old_parent = $s['id_parent'];
273
+
274
+            if (
275
+                !($id_parent != $old_parent
276
+                and autoriser('publierdans', 'rubrique', $id_parent)
277
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
278
+                and autoriser('publierdans', 'rubrique', $old_parent)
279
+                )
280
+            ) {
281
+                if ($s['statut'] != 'prepa') {
282
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
283
+                }
284
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
285
+                $statut_ancien = $s['statut'];
286
+                sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
287
+
288
+
289
+                propager_les_secteurs();
290
+
291
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
292
+                if ($statut_ancien == 'publie') {
293
+                    calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
294
+                }
295
+                // Creation ou deplacement d'une rubrique non publiee
296
+                // invalider le cache de leur menu
297
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
298
+                    effacer_meta('date_calcul_rubriques');
299
+                }
300
+
301
+                calculer_langues_rubriques();
302
+
303
+                // Appeler une notification
304
+                if ($notifications = charger_fonction('notifications', 'inc')) {
305
+                    $notifications(
306
+                        'rubrique_instituer',
307
+                        $id_rubrique,
308
+                        [
309
+                            'statut_ancien' => $statut_ancien,
310
+                            'id_parent_ancien' => $old_parent,
311
+                        ]
312
+                    );
313
+                    $notifications(
314
+                        'objet_instituer',
315
+                        $id_rubrique,
316
+                        [
317
+                            'objet' => 'rubrique',
318
+                            'id_objet' => $id_rubrique,
319
+                            'statut_ancien' => $statut_ancien,
320
+                            'id_parent_ancien' => $old_parent,
321
+                        ]
322
+                    );
323
+                }
324
+            }
325
+        }
326
+    }
327
+
328
+    return ''; // pas d'erreur
329 329
 }
Please login to merge, or discard this patch.
ecrire/action/tester_taille.php 2 patches
Indentation   +79 added lines, -79 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
 include_spip('inc/headers');
23 23
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
  *     Sortie du buffer
35 35
  **/
36 36
 function action_tester_taille_error_handler($output) {
37
-	// on est ici, donc echec lors de la creation de l'image
38
-	if (!empty($GLOBALS['redirect'])) {
39
-		return redirige_formulaire($GLOBALS['redirect']);
40
-	}
37
+    // on est ici, donc echec lors de la creation de l'image
38
+    if (!empty($GLOBALS['redirect'])) {
39
+        return redirige_formulaire($GLOBALS['redirect']);
40
+    }
41 41
 
42
-	return $output;
42
+    return $output;
43 43
 }
44 44
 
45 45
 
@@ -57,77 +57,77 @@  discard block
 block discarded – undo
57 57
  **/
58 58
 function action_tester_taille_dist() {
59 59
 
60
-	if (!autoriser('configurer')) {
61
-		return;
62
-	}
63
-
64
-	$taille = _request('arg');
65
-	$taille = explode('-', $taille);
66
-
67
-	$GLOBALS['taille_max'] = end($taille);
68
-	$GLOBALS['taille_min'] = 0;
69
-	if (count($taille) > 1) {
70
-		$GLOBALS['taille_min'] = reset($taille);
71
-	}
72
-
73
-	// si l'intervalle est assez petit, on garde la valeur min
74
-	if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) {
75
-		$t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']);
76
-		if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) {
77
-			$t *= 0.9; // marge de securite
78
-			echo round($t / 1_000_000, 3) . ' Mpx';
79
-		} else {
80
-			// c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue"
81
-			$t = 0;
82
-			echo '&infin;';
83
-		}
84
-		ecrire_meta('max_taille_vignettes', $t, 'non');
85
-		die();
86
-	}
87
-
88
-	$taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2);
89
-
90
-	include_spip('inc/filtres');
91
-	// des inclusions representatives d'un hit prive et/ou public pour la conso memoire
92
-	include_spip('public/assembler');
93
-	include_spip('public/balises');
94
-	include_spip('public/boucles');
95
-	include_spip('public/cacher');
96
-	include_spip('public/compiler');
97
-	include_spip('public/composer');
98
-	include_spip('public/criteres');
99
-	include_spip('public/interfaces');
100
-	include_spip('public/parametrer');
101
-	include_spip('public/phraser_html');
102
-	include_spip('public/references');
103
-
104
-	include_spip('inc/presentation');
105
-	include_spip('inc/charsets');
106
-	include_spip('inc/documents');
107
-	include_spip('inc/header');
108
-	propre('<doc1>'); // charger propre avec le trairement d'un modele
109
-
110
-	$i = _request('i') + 1;
111
-	$image_source = chemin_image('test.png');
112
-	$GLOBALS['redirect'] = generer_url_action(
113
-		'tester_taille',
114
-		"i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test']
115
-	);
116
-
117
-	ob_start('action_tester_taille_error_handler');
118
-	filtrer('image_recadre', $image_source, $taille, $taille);
119
-	$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
120
-
121
-	// si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee
122
-	// si $GLOBALS['taille_min']==0 (car on est au premier coup)
123
-	if ($GLOBALS['taille_min'] == 0) {
124
-		$taille = $GLOBALS['taille_max'];
125
-		filtrer('image_recadre', $image_source, $taille, $taille);
126
-		$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
127
-	}
128
-	ob_end_clean();
129
-
130
-
131
-	// on est ici, donc pas de plantage
132
-	echo redirige_formulaire($GLOBALS['redirect']);
60
+    if (!autoriser('configurer')) {
61
+        return;
62
+    }
63
+
64
+    $taille = _request('arg');
65
+    $taille = explode('-', $taille);
66
+
67
+    $GLOBALS['taille_max'] = end($taille);
68
+    $GLOBALS['taille_min'] = 0;
69
+    if (count($taille) > 1) {
70
+        $GLOBALS['taille_min'] = reset($taille);
71
+    }
72
+
73
+    // si l'intervalle est assez petit, on garde la valeur min
74
+    if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) {
75
+        $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']);
76
+        if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) {
77
+            $t *= 0.9; // marge de securite
78
+            echo round($t / 1_000_000, 3) . ' Mpx';
79
+        } else {
80
+            // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue"
81
+            $t = 0;
82
+            echo '&infin;';
83
+        }
84
+        ecrire_meta('max_taille_vignettes', $t, 'non');
85
+        die();
86
+    }
87
+
88
+    $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2);
89
+
90
+    include_spip('inc/filtres');
91
+    // des inclusions representatives d'un hit prive et/ou public pour la conso memoire
92
+    include_spip('public/assembler');
93
+    include_spip('public/balises');
94
+    include_spip('public/boucles');
95
+    include_spip('public/cacher');
96
+    include_spip('public/compiler');
97
+    include_spip('public/composer');
98
+    include_spip('public/criteres');
99
+    include_spip('public/interfaces');
100
+    include_spip('public/parametrer');
101
+    include_spip('public/phraser_html');
102
+    include_spip('public/references');
103
+
104
+    include_spip('inc/presentation');
105
+    include_spip('inc/charsets');
106
+    include_spip('inc/documents');
107
+    include_spip('inc/header');
108
+    propre('<doc1>'); // charger propre avec le trairement d'un modele
109
+
110
+    $i = _request('i') + 1;
111
+    $image_source = chemin_image('test.png');
112
+    $GLOBALS['redirect'] = generer_url_action(
113
+        'tester_taille',
114
+        "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test']
115
+    );
116
+
117
+    ob_start('action_tester_taille_error_handler');
118
+    filtrer('image_recadre', $image_source, $taille, $taille);
119
+    $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
120
+
121
+    // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee
122
+    // si $GLOBALS['taille_min']==0 (car on est au premier coup)
123
+    if ($GLOBALS['taille_min'] == 0) {
124
+        $taille = $GLOBALS['taille_max'];
125
+        filtrer('image_recadre', $image_source, $taille, $taille);
126
+        $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
127
+    }
128
+    ob_end_clean();
129
+
130
+
131
+    // on est ici, donc pas de plantage
132
+    echo redirige_formulaire($GLOBALS['redirect']);
133 133
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		$t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']);
76 76
 		if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) {
77 77
 			$t *= 0.9; // marge de securite
78
-			echo round($t / 1_000_000, 3) . ' Mpx';
78
+			echo round($t / 1_000_000, 3).' Mpx';
79 79
 		} else {
80 80
 			// c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue"
81 81
 			$t = 0;
@@ -111,19 +111,19 @@  discard block
 block discarded – undo
111 111
 	$image_source = chemin_image('test.png');
112 112
 	$GLOBALS['redirect'] = generer_url_action(
113 113
 		'tester_taille',
114
-		"i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test']
114
+		"i=$i&arg=".$GLOBALS['taille_min'].'-'.$GLOBALS['taille_test']
115 115
 	);
116 116
 
117 117
 	ob_start('action_tester_taille_error_handler');
118 118
 	filtrer('image_recadre', $image_source, $taille, $taille);
119
-	$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
119
+	$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']);
120 120
 
121 121
 	// si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee
122 122
 	// si $GLOBALS['taille_min']==0 (car on est au premier coup)
123 123
 	if ($GLOBALS['taille_min'] == 0) {
124 124
 		$taille = $GLOBALS['taille_max'];
125 125
 		filtrer('image_recadre', $image_source, $taille, $taille);
126
-		$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']);
126
+		$GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']);
127 127
 	}
128 128
 	ob_end_clean();
129 129
 
Please login to merge, or discard this patch.
ecrire/action/supprimer_rubrique.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');  # pour le nom de fichier
@@ -29,45 +29,45 @@  discard block
 block discarded – undo
29 29
  */
30 30
 function action_supprimer_rubrique_dist($id_rubrique = null) {
31 31
 
32
-	if (is_null($id_rubrique)) {
33
-		$securiser_action = charger_fonction('securiser_action', 'inc');
34
-		$id_rubrique = $securiser_action();
35
-	}
32
+    if (is_null($id_rubrique)) {
33
+        $securiser_action = charger_fonction('securiser_action', 'inc');
34
+        $id_rubrique = $securiser_action();
35
+    }
36 36
 
37
-	if ((int) $id_rubrique) {
38
-		sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
39
-		// Les admin restreints qui n'administraient que cette rubrique
40
-		// deviennent redacteurs
41
-		// (il y a sans doute moyen de faire ca avec un having)
37
+    if ((int) $id_rubrique) {
38
+        sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
39
+        // Les admin restreints qui n'administraient que cette rubrique
40
+        // deviennent redacteurs
41
+        // (il y a sans doute moyen de faire ca avec un having)
42 42
 
43
-		$q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique);
44
-		while ($r = sql_fetch($q)) {
45
-			$id_auteur = $r['id_auteur'];
46
-			// degrader avant de supprimer la restriction d'admin
47
-			// section critique sur les droits
48
-			$n = sql_countsel(
49
-				'spip_auteurs_liens',
50
-				"objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
51
-			);
52
-			if (!$n) {
53
-				include_spip('action/editer_auteur');
54
-				auteur_modifier($id_auteur, ['statut' => '1comite']);
55
-			}
56
-			sql_delete(
57
-				'spip_auteurs_liens',
58
-				"objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
59
-			);
60
-		}
61
-		// menu_rubriques devra recalculer
62
-		effacer_meta('date_calcul_rubriques');
43
+        $q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique);
44
+        while ($r = sql_fetch($q)) {
45
+            $id_auteur = $r['id_auteur'];
46
+            // degrader avant de supprimer la restriction d'admin
47
+            // section critique sur les droits
48
+            $n = sql_countsel(
49
+                'spip_auteurs_liens',
50
+                "objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
51
+            );
52
+            if (!$n) {
53
+                include_spip('action/editer_auteur');
54
+                auteur_modifier($id_auteur, ['statut' => '1comite']);
55
+            }
56
+            sql_delete(
57
+                'spip_auteurs_liens',
58
+                "objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
59
+            );
60
+        }
61
+        // menu_rubriques devra recalculer
62
+        effacer_meta('date_calcul_rubriques');
63 63
 
64
-		// Une rubrique supprimable n'avait pas le statut "publie"
65
-		// donc rien de neuf pour la rubrique parente
66
-		include_spip('inc/rubriques');
67
-		calculer_langues_rubriques();
64
+        // Une rubrique supprimable n'avait pas le statut "publie"
65
+        // donc rien de neuf pour la rubrique parente
66
+        include_spip('inc/rubriques');
67
+        calculer_langues_rubriques();
68 68
 
69
-		// invalider les caches marques de cette rubrique
70
-		include_spip('inc/invalideur');
71
-		suivre_invalideur("id='rubrique/$id_rubrique'");
72
-	}
69
+        // invalider les caches marques de cette rubrique
70
+        include_spip('inc/invalideur');
71
+        suivre_invalideur("id='rubrique/$id_rubrique'");
72
+    }
73 73
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	return;
20 20
 }
21 21
 
22
-include_spip('inc/charsets');  # pour le nom de fichier
22
+include_spip('inc/charsets'); # pour le nom de fichier
23 23
 
24 24
 /**
25 25
  * Effacer une rubrique
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	if ((int) $id_rubrique) {
38
-		sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
38
+		sql_delete('spip_rubriques', 'id_rubrique='.(int) $id_rubrique);
39 39
 		// Les admin restreints qui n'administraient que cette rubrique
40 40
 		// deviennent redacteurs
41 41
 		// (il y a sans doute moyen de faire ca avec un having)
42 42
 
43
-		$q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique);
43
+		$q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=".(int) $id_rubrique);
44 44
 		while ($r = sql_fetch($q)) {
45 45
 			$id_auteur = $r['id_auteur'];
46 46
 			// degrader avant de supprimer la restriction d'admin
47 47
 			// section critique sur les droits
48 48
 			$n = sql_countsel(
49 49
 				'spip_auteurs_liens',
50
-				"objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
50
+				"objet='rubrique' AND id_objet!=".(int) $id_rubrique.' AND id_auteur='.(int) $id_auteur
51 51
 			);
52 52
 			if (!$n) {
53 53
 				include_spip('action/editer_auteur');
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 			}
56 56
 			sql_delete(
57 57
 				'spip_auteurs_liens',
58
-				"objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur
58
+				"objet='rubrique' AND id_objet=".(int) $id_rubrique.' AND id_auteur='.(int) $id_auteur
59 59
 			);
60 60
 		}
61 61
 		// menu_rubriques devra recalculer
Please login to merge, or discard this patch.
ecrire/action/session.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -31,16 +31,16 @@  discard block
 block discarded – undo
31 31
  *   Envoyer en réponse : json contenant toutes les variables publiques de la session
32 32
  **/
33 33
 function action_session_dist() {
34
-	if (
35
-		($var = _request('var'))
36
-		&& preg_match(',^[a-z_0-9-]+$,i', $var)
37
-		&& $_SERVER['REQUEST_METHOD'] == 'POST'
38
-	) {
39
-		include_spip('inc/session');
40
-		session_set('session_' . $var, $val = _request('val'));
41
-		#spip_log("autosave:$var:$val",'autosave');
42
-	}
34
+    if (
35
+        ($var = _request('var'))
36
+        && preg_match(',^[a-z_0-9-]+$,i', $var)
37
+        && $_SERVER['REQUEST_METHOD'] == 'POST'
38
+    ) {
39
+        include_spip('inc/session');
40
+        session_set('session_' . $var, $val = _request('val'));
41
+        #spip_log("autosave:$var:$val",'autosave');
42
+    }
43 43
 
44
-	# TODO: mode lecture de session ; n'afficher que ce qu'il faut
45
-	#echo json_encode($GLOBALS['visiteur_session']);
44
+    # TODO: mode lecture de session ; n'afficher que ce qu'il faut
45
+    #echo json_encode($GLOBALS['visiteur_session']);
46 46
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 		&& $_SERVER['REQUEST_METHOD'] == 'POST'
38 38
 	) {
39 39
 		include_spip('inc/session');
40
-		session_set('session_' . $var, $val = _request('val'));
40
+		session_set('session_'.$var, $val = _request('val'));
41 41
 		#spip_log("autosave:$var:$val",'autosave');
42 42
 	}
43 43
 
Please login to merge, or discard this patch.
ecrire/action/editer_auteur.php 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -36,41 +36,41 @@  discard block
 block discarded – undo
36 36
  */
37 37
 function action_editer_auteur_dist($arg = null) {
38 38
 
39
-	if (is_null($arg)) {
40
-		$securiser_action = charger_fonction('securiser_action', 'inc');
41
-		$arg = $securiser_action();
42
-	}
43
-
44
-
45
-	// si id_auteur n'est pas un nombre, c'est une creation
46
-	if (!$id_auteur = intval($arg)) {
47
-		if (($id_auteur = auteur_inserer()) > 0) {
48
-			# cf. GROS HACK
49
-			# recuperer l'eventuel logo charge avant la creation
50
-			# ils ont un id = 0-id_auteur de la session
51
-			$id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
52
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
53
-			foreach (['on', 'off'] as $type) {
54
-				if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
55
-					if ($logo = reset($logo)) {
56
-						rename($logo, str_replace($id_hack, $id_auteur, $logo));
57
-					}
58
-				}
59
-			}
60
-		}
61
-	}
62
-
63
-	// Enregistre l'envoi dans la BD
64
-	$err = '';
65
-	if ($id_auteur > 0) {
66
-		$err = auteur_modifier($id_auteur);
67
-	}
68
-
69
-	if ($err) {
70
-		spip_log("echec editeur auteur: $err", _LOG_ERREUR);
71
-	}
72
-
73
-	return [$id_auteur, $err];
39
+    if (is_null($arg)) {
40
+        $securiser_action = charger_fonction('securiser_action', 'inc');
41
+        $arg = $securiser_action();
42
+    }
43
+
44
+
45
+    // si id_auteur n'est pas un nombre, c'est une creation
46
+    if (!$id_auteur = intval($arg)) {
47
+        if (($id_auteur = auteur_inserer()) > 0) {
48
+            # cf. GROS HACK
49
+            # recuperer l'eventuel logo charge avant la creation
50
+            # ils ont un id = 0-id_auteur de la session
51
+            $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
52
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
53
+            foreach (['on', 'off'] as $type) {
54
+                if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) {
55
+                    if ($logo = reset($logo)) {
56
+                        rename($logo, str_replace($id_hack, $id_auteur, $logo));
57
+                    }
58
+                }
59
+            }
60
+        }
61
+    }
62
+
63
+    // Enregistre l'envoi dans la BD
64
+    $err = '';
65
+    if ($id_auteur > 0) {
66
+        $err = auteur_modifier($id_auteur);
67
+    }
68
+
69
+    if ($err) {
70
+        spip_log("echec editeur auteur: $err", _LOG_ERREUR);
71
+    }
72
+
73
+    return [$id_auteur, $err];
74 74
 }
75 75
 
76 76
 /**
@@ -87,64 +87,64 @@  discard block
 block discarded – undo
87 87
  */
88 88
 function auteur_inserer($source = null, $set = null) {
89 89
 
90
-	// Ce qu'on va demander comme modifications
91
-	$champs = [];
92
-	$champs['source'] = $source ?: 'spip';
93
-
94
-	$champs['login'] = '';
95
-	$champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
96
-	$champs['webmestre'] = 'non';
97
-	if (empty($champs['imessage'])) {
98
-		$champs['imessage'] = 'oui';
99
-	}
100
-
101
-	if ($set) {
102
-		$champs = array_merge($champs, $set);
103
-	}
104
-
105
-	// Envoyer aux plugins
106
-	$champs = pipeline(
107
-		'pre_insertion',
108
-		[
109
-			'args' => [
110
-				'table' => 'spip_auteurs',
111
-			],
112
-			'data' => $champs
113
-		]
114
-	);
115
-	$id_auteur = sql_insertq('spip_auteurs', $champs);
116
-	pipeline(
117
-		'post_insertion',
118
-		[
119
-			'args' => [
120
-				'table' => 'spip_auteurs',
121
-				'id_objet' => $id_auteur
122
-			],
123
-			'data' => $champs
124
-		]
125
-	);
126
-
127
-	// Appeler une notification
128
-	if ($notifications = charger_fonction('notifications', 'inc')) {
129
-		$notifications(
130
-			'auteur_inserer',
131
-			$id_auteur,
132
-			[
133
-				'champs' => $champs,
134
-			]
135
-		);
136
-		$notifications(
137
-			'objet_inserer',
138
-			$id_auteur,
139
-			[
140
-				'objet' => 'auteur',
141
-				'id_objet' => $id_auteur,
142
-				'champs' => $champs,
143
-			]
144
-		);
145
-	}
146
-
147
-	return $id_auteur;
90
+    // Ce qu'on va demander comme modifications
91
+    $champs = [];
92
+    $champs['source'] = $source ?: 'spip';
93
+
94
+    $champs['login'] = '';
95
+    $champs['statut'] = '5poubelle';  // inutilisable tant qu'il n'a pas ete renseigne et institue
96
+    $champs['webmestre'] = 'non';
97
+    if (empty($champs['imessage'])) {
98
+        $champs['imessage'] = 'oui';
99
+    }
100
+
101
+    if ($set) {
102
+        $champs = array_merge($champs, $set);
103
+    }
104
+
105
+    // Envoyer aux plugins
106
+    $champs = pipeline(
107
+        'pre_insertion',
108
+        [
109
+            'args' => [
110
+                'table' => 'spip_auteurs',
111
+            ],
112
+            'data' => $champs
113
+        ]
114
+    );
115
+    $id_auteur = sql_insertq('spip_auteurs', $champs);
116
+    pipeline(
117
+        'post_insertion',
118
+        [
119
+            'args' => [
120
+                'table' => 'spip_auteurs',
121
+                'id_objet' => $id_auteur
122
+            ],
123
+            'data' => $champs
124
+        ]
125
+    );
126
+
127
+    // Appeler une notification
128
+    if ($notifications = charger_fonction('notifications', 'inc')) {
129
+        $notifications(
130
+            'auteur_inserer',
131
+            $id_auteur,
132
+            [
133
+                'champs' => $champs,
134
+            ]
135
+        );
136
+        $notifications(
137
+            'objet_inserer',
138
+            $id_auteur,
139
+            [
140
+                'objet' => 'auteur',
141
+                'id_objet' => $id_auteur,
142
+                'champs' => $champs,
143
+            ]
144
+        );
145
+    }
146
+
147
+    return $id_auteur;
148 148
 }
149 149
 
150 150
 
@@ -169,70 +169,70 @@  discard block
 block discarded – undo
169 169
  */
170 170
 function auteur_modifier($id_auteur, $set = null, $force_update = false) {
171 171
 
172
-	include_spip('inc/modifier');
173
-	include_spip('inc/filtres');
174
-	$c = collecter_requests(
175
-		// include list
176
-		objet_info('auteur', 'champs_editables'),
177
-		// exclude list
178
-		$force_update ? [] : ['webmestre', 'pass', 'login'],
179
-		// donnees eventuellement fournies
180
-		$set
181
-	);
182
-
183
-	if (
184
-		$err = objet_modifier_champs(
185
-			'auteur',
186
-			$id_auteur,
187
-			[
188
-			'data' => $set,
189
-			'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')]
190
-			],
191
-			$c
192
-		)
193
-	) {
194
-		return $err;
195
-	}
196
-	$session = $c;
197
-
198
-	$err = '';
199
-	if (!$force_update) {
200
-		// Modification de statut, changement de rubrique ?
201
-		$c = collecter_requests(
202
-		// include list
203
-			[
204
-				'statut',
205
-				'new_login',
206
-				'new_pass',
207
-				'login',
208
-				'pass',
209
-				'webmestre',
210
-				'restreintes',
211
-				'id_parent'
212
-			],
213
-			// exclude list
214
-			[],
215
-			// donnees eventuellement fournies
216
-			$set
217
-		);
218
-		if (isset($c['new_login']) and !isset($c['login'])) {
219
-			$c['login'] = $c['new_login'];
220
-		}
221
-		if (isset($c['new_pass']) and !isset($c['pass'])) {
222
-			$c['pass'] = $c['new_pass'];
223
-		}
224
-		$err = auteur_instituer($id_auteur, $c);
225
-		$session = array_merge($session, $c);
226
-	}
227
-
228
-	// .. mettre a jour les sessions de cet auteur
229
-	include_spip('inc/session');
230
-	$session['id_auteur'] = $id_auteur;
231
-	unset($session['new_login']);
232
-	unset($session['new_pass']);
233
-	actualiser_sessions($session);
234
-
235
-	return $err;
172
+    include_spip('inc/modifier');
173
+    include_spip('inc/filtres');
174
+    $c = collecter_requests(
175
+        // include list
176
+        objet_info('auteur', 'champs_editables'),
177
+        // exclude list
178
+        $force_update ? [] : ['webmestre', 'pass', 'login'],
179
+        // donnees eventuellement fournies
180
+        $set
181
+    );
182
+
183
+    if (
184
+        $err = objet_modifier_champs(
185
+            'auteur',
186
+            $id_auteur,
187
+            [
188
+            'data' => $set,
189
+            'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')]
190
+            ],
191
+            $c
192
+        )
193
+    ) {
194
+        return $err;
195
+    }
196
+    $session = $c;
197
+
198
+    $err = '';
199
+    if (!$force_update) {
200
+        // Modification de statut, changement de rubrique ?
201
+        $c = collecter_requests(
202
+        // include list
203
+            [
204
+                'statut',
205
+                'new_login',
206
+                'new_pass',
207
+                'login',
208
+                'pass',
209
+                'webmestre',
210
+                'restreintes',
211
+                'id_parent'
212
+            ],
213
+            // exclude list
214
+            [],
215
+            // donnees eventuellement fournies
216
+            $set
217
+        );
218
+        if (isset($c['new_login']) and !isset($c['login'])) {
219
+            $c['login'] = $c['new_login'];
220
+        }
221
+        if (isset($c['new_pass']) and !isset($c['pass'])) {
222
+            $c['pass'] = $c['new_pass'];
223
+        }
224
+        $err = auteur_instituer($id_auteur, $c);
225
+        $session = array_merge($session, $c);
226
+    }
227
+
228
+    // .. mettre a jour les sessions de cet auteur
229
+    include_spip('inc/session');
230
+    $session['id_auteur'] = $id_auteur;
231
+    unset($session['new_login']);
232
+    unset($session['new_pass']);
233
+    actualiser_sessions($session);
234
+
235
+    return $err;
236 236
 }
237 237
 
238 238
 /**
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
  * @return string
254 254
  */
255 255
 function auteur_associer($id_auteur, $objets, $qualif = null) {
256
-	include_spip('action/editer_liens');
256
+    include_spip('action/editer_liens');
257 257
 
258
-	return objet_associer(['auteur' => $id_auteur], $objets, $qualif);
258
+    return objet_associer(['auteur' => $id_auteur], $objets, $qualif);
259 259
 }
260 260
 
261 261
 /**
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
  * @return string
275 275
  */
276 276
 function auteur_dissocier($id_auteur, $objets) {
277
-	include_spip('action/editer_liens');
277
+    include_spip('action/editer_liens');
278 278
 
279
-	return objet_dissocier(['auteur' => $id_auteur], $objets);
279
+    return objet_dissocier(['auteur' => $id_auteur], $objets);
280 280
 }
281 281
 
282 282
 /**
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
  * @return bool|int
298 298
  */
299 299
 function auteur_qualifier($id_auteur, $objets, $qualif) {
300
-	include_spip('action/editer_liens');
300
+    include_spip('action/editer_liens');
301 301
 
302
-	return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif);
302
+    return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif);
303 303
 }
304 304
 
305 305
 
@@ -318,160 +318,160 @@  discard block
 block discarded – undo
318 318
  * @return bool|string
319 319
  */
320 320
 function auteur_instituer($id_auteur, $c, $force_webmestre = false) {
321
-	if (!$id_auteur = intval($id_auteur)) {
322
-		return false;
323
-	}
324
-	$erreurs = []; // contiendra les differentes erreurs a traduire par _T()
325
-	$champs = [];
326
-
327
-	// les memoriser pour les faire passer dans le pipeline pre_edition
328
-	if (isset($c['login']) and strlen($c['login'])) {
329
-		$champs['login'] = $c['login'];
330
-	}
331
-	if (isset($c['pass']) and strlen($c['pass'])) {
332
-		$champs['pass'] = $c['pass'];
333
-	}
334
-
335
-	$statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
336
-
337
-	if (
338
-		isset($c['statut'])
339
-		and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]))
340
-	) {
341
-		$statut = $champs['statut'] = $c['statut'];
342
-	}
343
-
344
-	// Restreindre avant de declarer l'auteur
345
-	// (section critique sur les droits)
346
-	if (isset($c['id_parent']) and $c['id_parent']) {
347
-		if (is_array($c['restreintes'])) {
348
-			$c['restreintes'][] = $c['id_parent'];
349
-		} else {
350
-			$c['restreintes'] = [$c['id_parent']];
351
-		}
352
-	}
353
-
354
-	if (
355
-		isset($c['webmestre'])
356
-		and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?']))
357
-	) {
358
-		$champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
359
-	}
360
-
361
-	// si statut change et n'est pas 0minirezo, on force webmestre a non
362
-	if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
363
-		$champs['webmestre'] = $c['webmestre'] = 'non';
364
-	}
365
-
366
-	// Envoyer aux plugins
367
-	$champs = pipeline(
368
-		'pre_edition',
369
-		[
370
-			'args' => [
371
-				'table' => 'spip_auteurs',
372
-				'id_objet' => $id_auteur,
373
-				'action' => 'instituer',
374
-				'statut_ancien' => $statut_ancien,
375
-			],
376
-			'data' => $champs
377
-		]
378
-	);
379
-
380
-	if (
381
-		isset($c['restreintes']) and is_array($c['restreintes'])
382
-		and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']])
383
-	) {
384
-		$rubriques = array_map('intval', $c['restreintes']);
385
-		$rubriques = array_unique($rubriques);
386
-		$rubriques = array_diff($rubriques, [0]);
387
-		auteur_dissocier($id_auteur, ['rubrique' => '*']);
388
-		auteur_associer($id_auteur, ['rubrique' => $rubriques]);
389
-	}
390
-
391
-	$flag_ecrire_acces = false;
392
-	// commencer par traiter les cas particuliers des logins et pass
393
-	// avant les autres ecritures en base
394
-	if (isset($champs['login']) or isset($champs['pass'])) {
395
-		$auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
396
-		include_spip('inc/auth');
397
-		if (isset($champs['login']) and strlen($champs['login'])) {
398
-			if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
399
-				$erreurs[] = 'ecrire:impossible_modifier_login_auteur';
400
-			}
401
-		}
402
-		if (isset($champs['pass']) and strlen($champs['pass'])) {
403
-			$champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
404
-			if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
405
-				$erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
406
-			}
407
-		}
408
-		unset($champs['login']);
409
-		unset($champs['pass']);
410
-		$flag_ecrire_acces = true;
411
-	}
412
-
413
-	if (!(is_countable($champs) ? count($champs) : 0)) {
414
-		return implode(' ', array_map('_T', $erreurs));
415
-	}
416
-	sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
417
-
418
-	// .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
419
-	if (
420
-		$flag_ecrire_acces
421
-		or isset($champs['statut'])
422
-	) {
423
-		include_spip('inc/acces');
424
-		ecrire_acces();
425
-	}
426
-
427
-	// Invalider les caches
428
-	include_spip('inc/invalideur');
429
-	suivre_invalideur("id='auteur/$id_auteur'");
430
-
431
-	// Pipeline
432
-	pipeline(
433
-		'post_edition',
434
-		[
435
-			'args' => [
436
-				'table' => 'spip_auteurs',
437
-				'id_objet' => $id_auteur,
438
-				'action' => 'instituer',
439
-				'statut_ancien' => $statut_ancien,
440
-			],
441
-			'data' => $champs
442
-		]
443
-	);
444
-
445
-	// Notifications
446
-	if ($notifications = charger_fonction('notifications', 'inc')) {
447
-		$notifications(
448
-			'auteur_instituer',
449
-			$id_auteur,
450
-			[
451
-				'statut' => $statut,
452
-				'statut_ancien' => $statut_ancien,
453
-				'champs' => $champs,
454
-			]
455
-		);
456
-		$notifications(
457
-			'objet_instituer',
458
-			$id_auteur,
459
-			[
460
-				'objet' => 'auteur',
461
-				'id_objet' => $id_auteur,
462
-				'statut' => $statut,
463
-				'statut_ancien' => $statut_ancien,
464
-				'champs' => $champs,
465
-			]
466
-		);
467
-
468
-		// Rétro-compat
469
-		$notifications(
470
-			'instituerauteur',
471
-			$id_auteur,
472
-			['statut' => $statut, 'statut_ancien' => $statut_ancien]
473
-		);
474
-	}
475
-
476
-	return implode(' ', array_map('_T', $erreurs));
321
+    if (!$id_auteur = intval($id_auteur)) {
322
+        return false;
323
+    }
324
+    $erreurs = []; // contiendra les differentes erreurs a traduire par _T()
325
+    $champs = [];
326
+
327
+    // les memoriser pour les faire passer dans le pipeline pre_edition
328
+    if (isset($c['login']) and strlen($c['login'])) {
329
+        $champs['login'] = $c['login'];
330
+    }
331
+    if (isset($c['pass']) and strlen($c['pass'])) {
332
+        $champs['pass'] = $c['pass'];
333
+    }
334
+
335
+    $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
336
+
337
+    if (
338
+        isset($c['statut'])
339
+        and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']]))
340
+    ) {
341
+        $statut = $champs['statut'] = $c['statut'];
342
+    }
343
+
344
+    // Restreindre avant de declarer l'auteur
345
+    // (section critique sur les droits)
346
+    if (isset($c['id_parent']) and $c['id_parent']) {
347
+        if (is_array($c['restreintes'])) {
348
+            $c['restreintes'][] = $c['id_parent'];
349
+        } else {
350
+            $c['restreintes'] = [$c['id_parent']];
351
+        }
352
+    }
353
+
354
+    if (
355
+        isset($c['webmestre'])
356
+        and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?']))
357
+    ) {
358
+        $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non';
359
+    }
360
+
361
+    // si statut change et n'est pas 0minirezo, on force webmestre a non
362
+    if (isset($c['statut']) and $c['statut'] !== '0minirezo') {
363
+        $champs['webmestre'] = $c['webmestre'] = 'non';
364
+    }
365
+
366
+    // Envoyer aux plugins
367
+    $champs = pipeline(
368
+        'pre_edition',
369
+        [
370
+            'args' => [
371
+                'table' => 'spip_auteurs',
372
+                'id_objet' => $id_auteur,
373
+                'action' => 'instituer',
374
+                'statut_ancien' => $statut_ancien,
375
+            ],
376
+            'data' => $champs
377
+        ]
378
+    );
379
+
380
+    if (
381
+        isset($c['restreintes']) and is_array($c['restreintes'])
382
+        and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']])
383
+    ) {
384
+        $rubriques = array_map('intval', $c['restreintes']);
385
+        $rubriques = array_unique($rubriques);
386
+        $rubriques = array_diff($rubriques, [0]);
387
+        auteur_dissocier($id_auteur, ['rubrique' => '*']);
388
+        auteur_associer($id_auteur, ['rubrique' => $rubriques]);
389
+    }
390
+
391
+    $flag_ecrire_acces = false;
392
+    // commencer par traiter les cas particuliers des logins et pass
393
+    // avant les autres ecritures en base
394
+    if (isset($champs['login']) or isset($champs['pass'])) {
395
+        $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
396
+        include_spip('inc/auth');
397
+        if (isset($champs['login']) and strlen($champs['login'])) {
398
+            if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) {
399
+                $erreurs[] = 'ecrire:impossible_modifier_login_auteur';
400
+            }
401
+        }
402
+        if (isset($champs['pass']) and strlen($champs['pass'])) {
403
+            $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur));
404
+            if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) {
405
+                $erreurs[] = 'ecrire:impossible_modifier_pass_auteur';
406
+            }
407
+        }
408
+        unset($champs['login']);
409
+        unset($champs['pass']);
410
+        $flag_ecrire_acces = true;
411
+    }
412
+
413
+    if (!(is_countable($champs) ? count($champs) : 0)) {
414
+        return implode(' ', array_map('_T', $erreurs));
415
+    }
416
+    sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur);
417
+
418
+    // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin
419
+    if (
420
+        $flag_ecrire_acces
421
+        or isset($champs['statut'])
422
+    ) {
423
+        include_spip('inc/acces');
424
+        ecrire_acces();
425
+    }
426
+
427
+    // Invalider les caches
428
+    include_spip('inc/invalideur');
429
+    suivre_invalideur("id='auteur/$id_auteur'");
430
+
431
+    // Pipeline
432
+    pipeline(
433
+        'post_edition',
434
+        [
435
+            'args' => [
436
+                'table' => 'spip_auteurs',
437
+                'id_objet' => $id_auteur,
438
+                'action' => 'instituer',
439
+                'statut_ancien' => $statut_ancien,
440
+            ],
441
+            'data' => $champs
442
+        ]
443
+    );
444
+
445
+    // Notifications
446
+    if ($notifications = charger_fonction('notifications', 'inc')) {
447
+        $notifications(
448
+            'auteur_instituer',
449
+            $id_auteur,
450
+            [
451
+                'statut' => $statut,
452
+                'statut_ancien' => $statut_ancien,
453
+                'champs' => $champs,
454
+            ]
455
+        );
456
+        $notifications(
457
+            'objet_instituer',
458
+            $id_auteur,
459
+            [
460
+                'objet' => 'auteur',
461
+                'id_objet' => $id_auteur,
462
+                'statut' => $statut,
463
+                'statut_ancien' => $statut_ancien,
464
+                'champs' => $champs,
465
+            ]
466
+        );
467
+
468
+        // Rétro-compat
469
+        $notifications(
470
+            'instituerauteur',
471
+            $id_auteur,
472
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien]
473
+        );
474
+    }
475
+
476
+    return implode(' ', array_map('_T', $erreurs));
477 477
 }
Please login to merge, or discard this patch.
ecrire/action/editer_objet.php 1 patch
Indentation   +563 added lines, -563 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -32,36 +32,36 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function action_editer_objet_dist($id = null, $objet = null, $set = null) {
34 34
 
35
-	// appel direct depuis une url avec arg = "objet/id"
36
-	if (is_null($id) or is_null($objet)) {
37
-		$securiser_action = charger_fonction('securiser_action', 'inc');
38
-		$arg = $securiser_action();
39
-		[$objet, $id] = array_pad(explode('/', $arg, 2), 2, null);
40
-	}
41
-
42
-	// appel incorrect ou depuis une url erronnée interdit
43
-	if (is_null($id) or is_null($objet)) {
44
-		include_spip('inc/minipres');
45
-		echo minipres(_T('info_acces_interdit'));
46
-		die();
47
-	}
48
-
49
-	// si id 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 = intval($id)) {
52
-		// on ne sait pas si un parent existe mais on essaye
53
-		$id_parent = _request('id_parent');
54
-		$id = objet_inserer($objet, $id_parent);
55
-	}
56
-
57
-	if (!($id = intval($id)) > 0) {
58
-		return [$id, _L('echec enregistrement en base')];
59
-	}
60
-
61
-	// Enregistre l'envoi dans la BD
62
-	$err = objet_modifier($objet, $id, $set);
63
-
64
-	return [$id, $err];
35
+    // appel direct depuis une url avec arg = "objet/id"
36
+    if (is_null($id) or is_null($objet)) {
37
+        $securiser_action = charger_fonction('securiser_action', 'inc');
38
+        $arg = $securiser_action();
39
+        [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null);
40
+    }
41
+
42
+    // appel incorrect ou depuis une url erronnée interdit
43
+    if (is_null($id) or is_null($objet)) {
44
+        include_spip('inc/minipres');
45
+        echo minipres(_T('info_acces_interdit'));
46
+        die();
47
+    }
48
+
49
+    // si id 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 = intval($id)) {
52
+        // on ne sait pas si un parent existe mais on essaye
53
+        $id_parent = _request('id_parent');
54
+        $id = objet_inserer($objet, $id_parent);
55
+    }
56
+
57
+    if (!($id = intval($id)) > 0) {
58
+        return [$id, _L('echec enregistrement en base')];
59
+    }
60
+
61
+    // Enregistre l'envoi dans la BD
62
+    $err = objet_modifier($objet, $id, $set);
63
+
64
+    return [$id, $err];
65 65
 }
66 66
 
67 67
 /**
@@ -74,85 +74,85 @@  discard block
 block discarded – undo
74 74
  * @return mixed|string
75 75
  */
76 76
 function objet_modifier($objet, $id, $set = null) {
77
-	if (($t = objet_type($objet)) !== $objet) {
78
-		spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
79
-		$objet = $t;
80
-	}
81
-	if (
82
-		include_spip('action/editer_' . $objet)
83
-		and function_exists($modifier = $objet . '_modifier')
84
-	) {
85
-		return $modifier($id, $set);
86
-	}
87
-
88
-	$table_sql = table_objet_sql($objet);
89
-	$trouver_table = charger_fonction('trouver_table', 'base');
90
-	$desc = $trouver_table($table_sql);
91
-	if (!$desc or !isset($desc['field'])) {
92
-		spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR);
93
-
94
-		return _L("Erreur objet $objet inconnu");
95
-	}
96
-	include_spip('inc/modifier');
97
-
98
-	$champ_date = '';
99
-	if (isset($desc['date']) and $desc['date']) {
100
-		$champ_date = $desc['date'];
101
-	} elseif (isset($desc['field']['date'])) {
102
-		$champ_date = 'date';
103
-	}
104
-
105
-	$include_list = array_keys($desc['field']);
106
-	// on ne traite pas la cle primaire par defaut, notamment car
107
-	// sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
108
-	$include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]);
109
-
110
-	if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
111
-		$include_list = $desc['champs_editables'];
112
-	}
113
-	$c = collecter_requests(
114
-		// include list
115
-		$include_list,
116
-		// exclude list
117
-		[$champ_date, 'statut', 'id_parent', 'id_secteur'],
118
-		// donnees eventuellement fournies
119
-		$set
120
-	);
121
-
122
-	// Si l'objet est publie, invalider les caches et demander sa reindexation
123
-	if (objet_test_si_publie($objet, $id)) {
124
-		$invalideur = "id='$objet/$id'";
125
-		$indexation = true;
126
-	} else {
127
-		$invalideur = '';
128
-		$indexation = false;
129
-	}
130
-
131
-	if (
132
-		$err = objet_modifier_champs(
133
-			$objet,
134
-			$id,
135
-			[
136
-			'data' => $set,
137
-			'nonvide' => '',
138
-			'invalideur' => $invalideur,
139
-			'indexation' => $indexation,
140
-			// champ a mettre a date('Y-m-d H:i:s') s'il y a modif
141
-			'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
142
-			],
143
-			$c
144
-		)
145
-	) {
146
-		return $err;
147
-	}
148
-
149
-	// Modification de statut, changement de rubrique ?
150
-	// FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
151
-	//         le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop.
152
-	$c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set);
153
-	$err = objet_instituer($objet, $id, $c);
154
-
155
-	return $err;
77
+    if (($t = objet_type($objet)) !== $objet) {
78
+        spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
79
+        $objet = $t;
80
+    }
81
+    if (
82
+        include_spip('action/editer_' . $objet)
83
+        and function_exists($modifier = $objet . '_modifier')
84
+    ) {
85
+        return $modifier($id, $set);
86
+    }
87
+
88
+    $table_sql = table_objet_sql($objet);
89
+    $trouver_table = charger_fonction('trouver_table', 'base');
90
+    $desc = $trouver_table($table_sql);
91
+    if (!$desc or !isset($desc['field'])) {
92
+        spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR);
93
+
94
+        return _L("Erreur objet $objet inconnu");
95
+    }
96
+    include_spip('inc/modifier');
97
+
98
+    $champ_date = '';
99
+    if (isset($desc['date']) and $desc['date']) {
100
+        $champ_date = $desc['date'];
101
+    } elseif (isset($desc['field']['date'])) {
102
+        $champ_date = 'date';
103
+    }
104
+
105
+    $include_list = array_keys($desc['field']);
106
+    // on ne traite pas la cle primaire par defaut, notamment car
107
+    // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base
108
+    $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]);
109
+
110
+    if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) {
111
+        $include_list = $desc['champs_editables'];
112
+    }
113
+    $c = collecter_requests(
114
+        // include list
115
+        $include_list,
116
+        // exclude list
117
+        [$champ_date, 'statut', 'id_parent', 'id_secteur'],
118
+        // donnees eventuellement fournies
119
+        $set
120
+    );
121
+
122
+    // Si l'objet est publie, invalider les caches et demander sa reindexation
123
+    if (objet_test_si_publie($objet, $id)) {
124
+        $invalideur = "id='$objet/$id'";
125
+        $indexation = true;
126
+    } else {
127
+        $invalideur = '';
128
+        $indexation = false;
129
+    }
130
+
131
+    if (
132
+        $err = objet_modifier_champs(
133
+            $objet,
134
+            $id,
135
+            [
136
+            'data' => $set,
137
+            'nonvide' => '',
138
+            'invalideur' => $invalideur,
139
+            'indexation' => $indexation,
140
+            // champ a mettre a date('Y-m-d H:i:s') s'il y a modif
141
+            'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '')
142
+            ],
143
+            $c
144
+        )
145
+    ) {
146
+        return $err;
147
+    }
148
+
149
+    // Modification de statut, changement de rubrique ?
150
+    // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout
151
+    //         le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop.
152
+    $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set);
153
+    $err = objet_instituer($objet, $id, $c);
154
+
155
+    return $err;
156 156
 }
157 157
 
158 158
 /**
@@ -167,157 +167,157 @@  discard block
 block discarded – undo
167 167
  * @return bool|int
168 168
  */
169 169
 function objet_inserer($objet, $id_parent = null, $set = null) {
170
-	$d = null;
171
-	if (($t = objet_type($objet)) !== $objet) {
172
-		spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
173
-		$objet = $t;
174
-	}
175
-	if (
176
-		include_spip('action/editer_' . $objet)
177
-		and function_exists($inserer = $objet . '_inserer')
178
-	) {
179
-		return $inserer($id_parent, $set);
180
-	}
181
-
182
-	$table_sql = table_objet_sql($objet);
183
-	$trouver_table = charger_fonction('trouver_table', 'base');
184
-	$desc = $trouver_table($table_sql);
185
-	if (!$desc or !isset($desc['field'])) {
186
-		return 0;
187
-	}
188
-
189
-	$lang_rub = '';
190
-	$champs = [];
191
-	if (isset($desc['field']['id_rubrique'])) {
192
-		// Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
193
-		// dans la premiere rubrique racine
194
-		if (!$id_rubrique = intval($id_parent)) {
195
-			$row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
196
-			$id_rubrique = $row['id_rubrique'];
197
-		} else {
198
-			$row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
199
-		}
200
-
201
-		$champs['id_rubrique'] = $id_rubrique;
202
-		if (isset($desc['field']['id_secteur'])) {
203
-			$champs['id_secteur'] = $row['id_secteur'];
204
-		}
205
-		$lang_rub = $row['lang'];
206
-	}
207
-
208
-	// La langue a la creation : si les liens de traduction sont autorises
209
-	// dans les rubriques, on essaie avec la langue de l'auteur,
210
-	// ou a defaut celle de la rubrique
211
-	// Sinon c'est la langue de la rubrique qui est choisie + heritee
212
-	if (
213
-		isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array(
214
-			$table_sql,
215
-			explode(',', $GLOBALS['meta']['multi_objets'])
216
-		)
217
-	) {
218
-		lang_select($GLOBALS['visiteur_session']['lang']);
219
-		if (
220
-			in_array(
221
-				$GLOBALS['spip_lang'],
222
-				explode(',', $GLOBALS['meta']['langues_multilingue'])
223
-			)
224
-		) {
225
-			$champs['lang'] = $GLOBALS['spip_lang'];
226
-			if (isset($desc['field']['langue_choisie'])) {
227
-				$champs['langue_choisie'] = 'oui';
228
-			}
229
-		}
230
-	} elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
231
-		$champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']);
232
-		$champs['langue_choisie'] = 'non';
233
-	}
234
-
235
-	if (isset($desc['field']['statut'])) {
236
-		if (isset($desc['statut_textes_instituer'])) {
237
-			$cles_statut = array_keys($desc['statut_textes_instituer']);
238
-			$champs['statut'] = reset($cles_statut);
239
-		} else {
240
-			$champs['statut'] = 'prepa';
241
-		}
242
-	}
243
-
244
-
245
-	if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
246
-		$champs[$d] = date('Y-m-d H:i:s');
247
-	}
248
-
249
-	if ($set) {
250
-		$champs = array_merge($champs, $set);
251
-	}
252
-
253
-	// Envoyer aux plugins
254
-	$champs = pipeline(
255
-		'pre_insertion',
256
-		[
257
-			'args' => [
258
-				'table' => $table_sql,
259
-				'id_parent' => $id_parent,
260
-			],
261
-			'data' => $champs
262
-		]
263
-	);
264
-
265
-	$id = sql_insertq($table_sql, $champs);
266
-
267
-	if ($id) {
268
-		// controler si le serveur n'a pas renvoye une erreur
269
-		// et associer l'auteur sinon
270
-		// si la table n'a pas deja un champ id_auteur
271
-		// et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
272
-		if (
273
-			$id > 0
274
-			and !isset($desc['field']['id_auteur'])
275
-		) {
276
-			$id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
277
-				$GLOBALS['visiteur_session']['id_auteur']
278
-				: _request('id_auteur'));
279
-			if ($id_auteur) {
280
-				include_spip('action/editer_auteur');
281
-				auteur_associer($id_auteur, [$objet => $id]);
282
-			}
283
-		}
284
-
285
-		pipeline(
286
-			'post_insertion',
287
-			[
288
-				'args' => [
289
-					'table' => $table_sql,
290
-					'id_parent' => $id_parent,
291
-					'id_objet' => $id,
292
-				],
293
-				'data' => $champs
294
-			]
295
-		);
296
-	}
297
-
298
-	// Appeler une notification
299
-	if ($notifications = charger_fonction('notifications', 'inc')) {
300
-		$notifications(
301
-			"{$objet}_inserer",
302
-			$id,
303
-			[
304
-				'id_parent' => $id_parent,
305
-				'champs' => $champs,
306
-			]
307
-		);
308
-		$notifications(
309
-			'objet_inserer',
310
-			$id,
311
-			[
312
-				'objet' => $objet,
313
-				'id_objet' => $id,
314
-				'id_parent' => $id_parent,
315
-				'champs' => $champs,
316
-			]
317
-		);
318
-	}
319
-
320
-	return $id;
170
+    $d = null;
171
+    if (($t = objet_type($objet)) !== $objet) {
172
+        spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
173
+        $objet = $t;
174
+    }
175
+    if (
176
+        include_spip('action/editer_' . $objet)
177
+        and function_exists($inserer = $objet . '_inserer')
178
+    ) {
179
+        return $inserer($id_parent, $set);
180
+    }
181
+
182
+    $table_sql = table_objet_sql($objet);
183
+    $trouver_table = charger_fonction('trouver_table', 'base');
184
+    $desc = $trouver_table($table_sql);
185
+    if (!$desc or !isset($desc['field'])) {
186
+        return 0;
187
+    }
188
+
189
+    $lang_rub = '';
190
+    $champs = [];
191
+    if (isset($desc['field']['id_rubrique'])) {
192
+        // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet
193
+        // dans la premiere rubrique racine
194
+        if (!$id_rubrique = intval($id_parent)) {
195
+            $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1');
196
+            $id_rubrique = $row['id_rubrique'];
197
+        } else {
198
+            $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
199
+        }
200
+
201
+        $champs['id_rubrique'] = $id_rubrique;
202
+        if (isset($desc['field']['id_secteur'])) {
203
+            $champs['id_secteur'] = $row['id_secteur'];
204
+        }
205
+        $lang_rub = $row['lang'];
206
+    }
207
+
208
+    // La langue a la creation : si les liens de traduction sont autorises
209
+    // dans les rubriques, on essaie avec la langue de l'auteur,
210
+    // ou a defaut celle de la rubrique
211
+    // Sinon c'est la langue de la rubrique qui est choisie + heritee
212
+    if (
213
+        isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array(
214
+            $table_sql,
215
+            explode(',', $GLOBALS['meta']['multi_objets'])
216
+        )
217
+    ) {
218
+        lang_select($GLOBALS['visiteur_session']['lang']);
219
+        if (
220
+            in_array(
221
+                $GLOBALS['spip_lang'],
222
+                explode(',', $GLOBALS['meta']['langues_multilingue'])
223
+            )
224
+        ) {
225
+            $champs['lang'] = $GLOBALS['spip_lang'];
226
+            if (isset($desc['field']['langue_choisie'])) {
227
+                $champs['langue_choisie'] = 'oui';
228
+            }
229
+        }
230
+    } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
231
+        $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']);
232
+        $champs['langue_choisie'] = 'non';
233
+    }
234
+
235
+    if (isset($desc['field']['statut'])) {
236
+        if (isset($desc['statut_textes_instituer'])) {
237
+            $cles_statut = array_keys($desc['statut_textes_instituer']);
238
+            $champs['statut'] = reset($cles_statut);
239
+        } else {
240
+            $champs['statut'] = 'prepa';
241
+        }
242
+    }
243
+
244
+
245
+    if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) {
246
+        $champs[$d] = date('Y-m-d H:i:s');
247
+    }
248
+
249
+    if ($set) {
250
+        $champs = array_merge($champs, $set);
251
+    }
252
+
253
+    // Envoyer aux plugins
254
+    $champs = pipeline(
255
+        'pre_insertion',
256
+        [
257
+            'args' => [
258
+                'table' => $table_sql,
259
+                'id_parent' => $id_parent,
260
+            ],
261
+            'data' => $champs
262
+        ]
263
+    );
264
+
265
+    $id = sql_insertq($table_sql, $champs);
266
+
267
+    if ($id) {
268
+        // controler si le serveur n'a pas renvoye une erreur
269
+        // et associer l'auteur sinon
270
+        // si la table n'a pas deja un champ id_auteur
271
+        // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association)
272
+        if (
273
+            $id > 0
274
+            and !isset($desc['field']['id_auteur'])
275
+        ) {
276
+            $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ?
277
+                $GLOBALS['visiteur_session']['id_auteur']
278
+                : _request('id_auteur'));
279
+            if ($id_auteur) {
280
+                include_spip('action/editer_auteur');
281
+                auteur_associer($id_auteur, [$objet => $id]);
282
+            }
283
+        }
284
+
285
+        pipeline(
286
+            'post_insertion',
287
+            [
288
+                'args' => [
289
+                    'table' => $table_sql,
290
+                    'id_parent' => $id_parent,
291
+                    'id_objet' => $id,
292
+                ],
293
+                'data' => $champs
294
+            ]
295
+        );
296
+    }
297
+
298
+    // Appeler une notification
299
+    if ($notifications = charger_fonction('notifications', 'inc')) {
300
+        $notifications(
301
+            "{$objet}_inserer",
302
+            $id,
303
+            [
304
+                'id_parent' => $id_parent,
305
+                'champs' => $champs,
306
+            ]
307
+        );
308
+        $notifications(
309
+            'objet_inserer',
310
+            $id,
311
+            [
312
+                'objet' => $objet,
313
+                'id_objet' => $id,
314
+                'id_parent' => $id_parent,
315
+                'champs' => $champs,
316
+            ]
317
+        );
318
+    }
319
+
320
+    return $id;
321 321
 }
322 322
 
323 323
 
@@ -334,138 +334,138 @@  discard block
 block discarded – undo
334 334
  * @return string
335 335
  */
336 336
 function objet_instituer($objet, $id, $c, $calcul_rub = true) {
337
-	if (($t = objet_type($objet)) !== $objet) {
338
-		spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
339
-		$objet = $t;
340
-	}
341
-	if (
342
-		include_spip('action/editer_' . $objet)
343
-		and function_exists($instituer = $objet . '_instituer')
344
-	) {
345
-		return $instituer($id, $c, $calcul_rub);
346
-	}
347
-
348
-	$table_sql = table_objet_sql($objet);
349
-	$trouver_table = charger_fonction('trouver_table', 'base');
350
-	$desc = $trouver_table($table_sql);
351
-	if (!$desc or !isset($desc['field'])) {
352
-		return _L("Impossible d'instituer $objet : non connu en base");
353
-	}
354
-
355
-	include_spip('inc/autoriser');
356
-	include_spip('inc/rubriques');
357
-	include_spip('inc/modifier');
358
-
359
-	$sel = [];
360
-	$sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut");
361
-
362
-	$champ_date = '';
363
-	if (isset($desc['date']) and $desc['date']) {
364
-		$champ_date = $desc['date'];
365
-	} elseif (isset($desc['field']['date'])) {
366
-		$champ_date = 'date';
367
-	}
368
-
369
-	$sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
370
-	$sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique');
371
-
372
-	$row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
373
-
374
-	$id_rubrique = $row['id_rubrique'];
375
-	$statut_ancien = $statut = $row['statut'];
376
-	$date_ancienne = $date = $row['date'];
377
-	$champs = [];
378
-
379
-	$d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
380
-	$s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
381
-
382
-	// cf autorisations dans inc/instituer_objet
383
-	if ($s != $statut or ($d and $d != $date)) {
384
-		if (
385
-			$id_rubrique ?
386
-			autoriser('publierdans', 'rubrique', $id_rubrique)
387
-			:
388
-			autoriser('instituer', $objet, $id, null, ['statut' => $s])
389
-		) {
390
-			$statut = $champs['statut'] = $s;
391
-		} else {
392
-			if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
393
-				$statut = $champs['statut'] = $s;
394
-			} else {
395
-				spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE);
396
-			}
397
-		}
398
-
399
-		// En cas de publication, fixer la date a "maintenant"
400
-		// sauf si $c commande autre chose
401
-		// ou si l'objet est deja date dans le futur
402
-		// En cas de proposition d'un objet (mais pas depublication), idem
403
-		if ($champ_date) {
404
-			if (
405
-				$champs['statut'] == 'publie'
406
-				or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop']))
407
-				or $d
408
-			) {
409
-				if ($d or strtotime($d = $date) > time()) {
410
-					$champs[$champ_date] = $date = $d;
411
-				} else {
412
-					$champs[$champ_date] = $date = date('Y-m-d H:i:s');
413
-				}
414
-			}
415
-		}
416
-	}
417
-
418
-	// Verifier que la rubrique demandee existe et est differente
419
-	// de la rubrique actuelle
420
-	if (
421
-		$id_rubrique
422
-		and isset($c['id_parent'])
423
-		and $id_parent = $c['id_parent']
424
-		and $id_parent != $id_rubrique
425
-		and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
426
-	) {
427
-		$champs['id_rubrique'] = $id_parent;
428
-
429
-		// si l'objet etait publie
430
-		// et que le demandeur n'est pas admin de la rubrique
431
-		// repasser l'objet en statut 'propose'.
432
-		if (
433
-			$statut == 'publie'
434
-			and !autoriser('publierdans', 'rubrique', $id_rubrique)
435
-		) {
436
-			$champs['statut'] = 'prop';
437
-		}
438
-	}
439
-
440
-
441
-	// Envoyer aux plugins
442
-	$champs = pipeline(
443
-		'pre_edition',
444
-		[
445
-			'args' => [
446
-				'table' => $table_sql,
447
-				'id_objet' => $id,
448
-				'action' => 'instituer',
449
-				'statut_ancien' => $statut_ancien,
450
-				'date_ancienne' => $date_ancienne,
451
-				'id_parent_ancien' => $id_rubrique,
452
-			],
453
-			'data' => $champs
454
-		]
455
-	);
456
-
457
-	if (!(is_countable($champs) ? count($champs) : 0)) {
458
-		return '';
459
-	}
460
-
461
-	// Envoyer les modifs.
462
-	objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
463
-
464
-	// Invalider les caches
465
-	include_spip('inc/invalideur');
466
-	suivre_invalideur("id='$objet/$id'");
467
-
468
-	/*
337
+    if (($t = objet_type($objet)) !== $objet) {
338
+        spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
339
+        $objet = $t;
340
+    }
341
+    if (
342
+        include_spip('action/editer_' . $objet)
343
+        and function_exists($instituer = $objet . '_instituer')
344
+    ) {
345
+        return $instituer($id, $c, $calcul_rub);
346
+    }
347
+
348
+    $table_sql = table_objet_sql($objet);
349
+    $trouver_table = charger_fonction('trouver_table', 'base');
350
+    $desc = $trouver_table($table_sql);
351
+    if (!$desc or !isset($desc['field'])) {
352
+        return _L("Impossible d'instituer $objet : non connu en base");
353
+    }
354
+
355
+    include_spip('inc/autoriser');
356
+    include_spip('inc/rubriques');
357
+    include_spip('inc/modifier');
358
+
359
+    $sel = [];
360
+    $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut");
361
+
362
+    $champ_date = '';
363
+    if (isset($desc['date']) and $desc['date']) {
364
+        $champ_date = $desc['date'];
365
+    } elseif (isset($desc['field']['date'])) {
366
+        $champ_date = 'date';
367
+    }
368
+
369
+    $sel[] = ($champ_date ? "$champ_date as date" : "'' as date");
370
+    $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique');
371
+
372
+    $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id));
373
+
374
+    $id_rubrique = $row['id_rubrique'];
375
+    $statut_ancien = $statut = $row['statut'];
376
+    $date_ancienne = $date = $row['date'];
377
+    $champs = [];
378
+
379
+    $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null;
380
+    $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut;
381
+
382
+    // cf autorisations dans inc/instituer_objet
383
+    if ($s != $statut or ($d and $d != $date)) {
384
+        if (
385
+            $id_rubrique ?
386
+            autoriser('publierdans', 'rubrique', $id_rubrique)
387
+            :
388
+            autoriser('instituer', $objet, $id, null, ['statut' => $s])
389
+        ) {
390
+            $statut = $champs['statut'] = $s;
391
+        } else {
392
+            if ($s != 'publie' and autoriser('modifier', $objet, $id)) {
393
+                $statut = $champs['statut'] = $s;
394
+            } else {
395
+                spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE);
396
+            }
397
+        }
398
+
399
+        // En cas de publication, fixer la date a "maintenant"
400
+        // sauf si $c commande autre chose
401
+        // ou si l'objet est deja date dans le futur
402
+        // En cas de proposition d'un objet (mais pas depublication), idem
403
+        if ($champ_date) {
404
+            if (
405
+                $champs['statut'] == 'publie'
406
+                or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop']))
407
+                or $d
408
+            ) {
409
+                if ($d or strtotime($d = $date) > time()) {
410
+                    $champs[$champ_date] = $date = $d;
411
+                } else {
412
+                    $champs[$champ_date] = $date = date('Y-m-d H:i:s');
413
+                }
414
+            }
415
+        }
416
+    }
417
+
418
+    // Verifier que la rubrique demandee existe et est differente
419
+    // de la rubrique actuelle
420
+    if (
421
+        $id_rubrique
422
+        and isset($c['id_parent'])
423
+        and $id_parent = $c['id_parent']
424
+        and $id_parent != $id_rubrique
425
+        and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent)))
426
+    ) {
427
+        $champs['id_rubrique'] = $id_parent;
428
+
429
+        // si l'objet etait publie
430
+        // et que le demandeur n'est pas admin de la rubrique
431
+        // repasser l'objet en statut 'propose'.
432
+        if (
433
+            $statut == 'publie'
434
+            and !autoriser('publierdans', 'rubrique', $id_rubrique)
435
+        ) {
436
+            $champs['statut'] = 'prop';
437
+        }
438
+    }
439
+
440
+
441
+    // Envoyer aux plugins
442
+    $champs = pipeline(
443
+        'pre_edition',
444
+        [
445
+            'args' => [
446
+                'table' => $table_sql,
447
+                'id_objet' => $id,
448
+                'action' => 'instituer',
449
+                'statut_ancien' => $statut_ancien,
450
+                'date_ancienne' => $date_ancienne,
451
+                'id_parent_ancien' => $id_rubrique,
452
+            ],
453
+            'data' => $champs
454
+        ]
455
+    );
456
+
457
+    if (!(is_countable($champs) ? count($champs) : 0)) {
458
+        return '';
459
+    }
460
+
461
+    // Envoyer les modifs.
462
+    objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub);
463
+
464
+    // Invalider les caches
465
+    include_spip('inc/invalideur');
466
+    suivre_invalideur("id='$objet/$id'");
467
+
468
+    /*
469 469
 	if ($date) {
470 470
 		$t = strtotime($date);
471 471
 		$p = @$GLOBALS['meta']['date_prochain_postdate'];
@@ -474,60 +474,60 @@  discard block
 block discarded – undo
474 474
 		}
475 475
 	}*/
476 476
 
477
-	// Pipeline
478
-	pipeline(
479
-		'post_edition',
480
-		[
481
-			'args' => [
482
-				'table' => $table_sql,
483
-				'id_objet' => $id,
484
-				'action' => 'instituer',
485
-				'statut_ancien' => $statut_ancien,
486
-				'date_ancienne' => $date_ancienne,
487
-				'id_parent_ancien' => $id_rubrique,
488
-			],
489
-			'data' => $champs
490
-		]
491
-	);
492
-
493
-	// Notifications
494
-	if ($notifications = charger_fonction('notifications', 'inc')) {
495
-		$notifications(
496
-			"{$objet}_instituer",
497
-			$id,
498
-			[
499
-				'statut' => $statut,
500
-				'statut_ancien' => $statut_ancien,
501
-				'date' => $date,
502
-				'date_ancienne' => $date_ancienne,
503
-				'id_parent_ancien' => $id_rubrique,
504
-				'champs' => $champs,
505
-			]
506
-		);
507
-		$notifications(
508
-			'objet_instituer',
509
-			$id,
510
-			[
511
-				'objet' => $objet,
512
-				'id_objet' => $id,
513
-				'statut' => $statut,
514
-				'statut_ancien' => $statut_ancien,
515
-				'date' => $date,
516
-				'date_ancienne' => $date_ancienne,
517
-				'id_parent_ancien' => $id_rubrique,
518
-				'champs' => $champs,
519
-			]
520
-		);
521
-
522
-		// Rétro-compat
523
-		$notifications(
524
-			"instituer$objet",
525
-			$id,
526
-			['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
527
-		);
528
-	}
529
-
530
-	return ''; // pas d'erreur
477
+    // Pipeline
478
+    pipeline(
479
+        'post_edition',
480
+        [
481
+            'args' => [
482
+                'table' => $table_sql,
483
+                'id_objet' => $id,
484
+                'action' => 'instituer',
485
+                'statut_ancien' => $statut_ancien,
486
+                'date_ancienne' => $date_ancienne,
487
+                'id_parent_ancien' => $id_rubrique,
488
+            ],
489
+            'data' => $champs
490
+        ]
491
+    );
492
+
493
+    // Notifications
494
+    if ($notifications = charger_fonction('notifications', 'inc')) {
495
+        $notifications(
496
+            "{$objet}_instituer",
497
+            $id,
498
+            [
499
+                'statut' => $statut,
500
+                'statut_ancien' => $statut_ancien,
501
+                'date' => $date,
502
+                'date_ancienne' => $date_ancienne,
503
+                'id_parent_ancien' => $id_rubrique,
504
+                'champs' => $champs,
505
+            ]
506
+        );
507
+        $notifications(
508
+            'objet_instituer',
509
+            $id,
510
+            [
511
+                'objet' => $objet,
512
+                'id_objet' => $id,
513
+                'statut' => $statut,
514
+                'statut_ancien' => $statut_ancien,
515
+                'date' => $date,
516
+                'date_ancienne' => $date_ancienne,
517
+                'id_parent_ancien' => $id_rubrique,
518
+                'champs' => $champs,
519
+            ]
520
+        );
521
+
522
+        // Rétro-compat
523
+        $notifications(
524
+            "instituer$objet",
525
+            $id,
526
+            ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne]
527
+        );
528
+    }
529
+
530
+    return ''; // pas d'erreur
531 531
 }
532 532
 
533 533
 /**
@@ -542,51 +542,51 @@  discard block
 block discarded – undo
542 542
  * @return void
543 543
  */
544 544
 function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) {
545
-	$table_sql = table_objet_sql($objet);
546
-	$trouver_table = charger_fonction('trouver_table', 'base');
547
-	$desc = $trouver_table($table_sql);
548
-
549
-	// Si on deplace l'objet
550
-	// changer aussi son secteur et sa langue (si heritee)
551
-	if (isset($champs['id_rubrique'])) {
552
-		$row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
553
-		$langue = $row_rub['lang'];
554
-
555
-		if (isset($desc['field']['id_secteur'])) {
556
-			$champs['id_secteur'] = $row_rub['id_secteur'];
557
-		}
558
-
559
-		if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
560
-			if (
561
-				sql_fetsel(
562
-					'1',
563
-					$table_sql,
564
-					id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
565
-				)
566
-			) {
567
-				$champs['lang'] = $langue;
568
-			}
569
-		}
570
-	}
571
-
572
-	if (!$champs) {
573
-		return;
574
-	}
575
-	sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
576
-
577
-	// Changer le statut des rubriques concernees
578
-	if ($cond) {
579
-		include_spip('inc/rubriques');
580
-		//$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
581
-		$postdate = false;
582
-		// On rajoute les infos de l'objet
583
-		$infos = [
584
-			'objet' => $objet,
585
-			'id_objet' => $id,
586
-			'statut_ancien' => $statut,
587
-		];
588
-		calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate);
589
-	}
545
+    $table_sql = table_objet_sql($objet);
546
+    $trouver_table = charger_fonction('trouver_table', 'base');
547
+    $desc = $trouver_table($table_sql);
548
+
549
+    // Si on deplace l'objet
550
+    // changer aussi son secteur et sa langue (si heritee)
551
+    if (isset($champs['id_rubrique'])) {
552
+        $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique']));
553
+        $langue = $row_rub['lang'];
554
+
555
+        if (isset($desc['field']['id_secteur'])) {
556
+            $champs['id_secteur'] = $row_rub['id_secteur'];
557
+        }
558
+
559
+        if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) {
560
+            if (
561
+                sql_fetsel(
562
+                    '1',
563
+                    $table_sql,
564
+                    id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue)
565
+                )
566
+            ) {
567
+                $champs['lang'] = $langue;
568
+            }
569
+        }
570
+    }
571
+
572
+    if (!$champs) {
573
+        return;
574
+    }
575
+    sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id));
576
+
577
+    // Changer le statut des rubriques concernees
578
+    if ($cond) {
579
+        include_spip('inc/rubriques');
580
+        //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false;
581
+        $postdate = false;
582
+        // On rajoute les infos de l'objet
583
+        $infos = [
584
+            'objet' => $objet,
585
+            'id_objet' => $id,
586
+            'statut_ancien' => $statut,
587
+        ];
588
+        calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate);
589
+    }
590 590
 }
591 591
 
592 592
 
@@ -615,75 +615,75 @@  discard block
 block discarded – undo
615 615
  *     string|int : valeur du champ demande pour l'objet demande
616 616
  */
617 617
 function objet_lire($objet, $valeur_id, $options = []) {
618
-	if (($t = objet_type($objet)) !== $objet) {
619
-		spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
620
-		$objet = $t;
621
-	}
622
-
623
-	// tableau du cache des descriptions et des id d'objet (au sens id_xxx).
624
-	// Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle]
625
-	static $descriptions = [];
626
-
627
-	// On détermine le nom du champ id de la table.
628
-	include_spip('base/objets');
629
-	$primary = id_table_objet($objet);
630
-
631
-	// On détermine l'id à utiliser.
632
-	$champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary);
633
-
634
-	// Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète.
635
-	if (
636
-		!isset($descriptions[$objet][$champ_id][$valeur_id])
637
-		or (isset($options['force']) and $options['force'])
638
-	) {
639
-		// Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet.
640
-		if (
641
-			include_spip('action/editer_' . $objet)
642
-			and function_exists($lire = "{$objet}_lire_champs")
643
-		) {
644
-			$valeurs = $lire($objet, $valeur_id, $champ_id);
645
-		} else {
646
-			// On récupère la table SQL à partir du type d'objet.
647
-			$table = table_objet_sql($objet);
648
-
649
-			// La condition est appliquée sur le champ désigné par l'utilisateur.
650
-			$where = [
651
-				$champ_id . '=' . sql_quote($valeur_id)
652
-			];
653
-
654
-			// Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide.
655
-			$valeurs = sql_fetsel('*', $table, $where);
656
-		}
657
-
658
-		if (!$valeurs) {
659
-			$valeurs = false;
660
-		}
661
-
662
-		$descriptions[$objet][$champ_id][$valeur_id] = $valeurs;
663
-
664
-		if ($champ_id !== $primary and isset($valeurs[$primary])) {
665
-			$descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs;
666
-			$descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]];
667
-		}
668
-	}
669
-
670
-	$retour = $descriptions[$objet][$champ_id][$valeur_id];
671
-
672
-	// On ne retourne maintenant que les champs demandés.
673
-	// - on détermine les informations à renvoyer.
674
-	if ($retour and !empty($options['champs'])) {
675
-		$champs = $options['champs'];
676
-		// Extraction des seules informations demandées.
677
-		// -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau.
678
-		// -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur.
679
-		if (is_array($champs)) {
680
-			// Tableau des informations valides
681
-			$retour = array_intersect_key($retour, array_flip($champs));
682
-		} else {
683
-			// Valeur unique demandée.
684
-			$retour = ($retour[$champs] ?? false);
685
-		}
686
-	}
687
-
688
-	return $retour;
618
+    if (($t = objet_type($objet)) !== $objet) {
619
+        spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE);
620
+        $objet = $t;
621
+    }
622
+
623
+    // tableau du cache des descriptions et des id d'objet (au sens id_xxx).
624
+    // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle]
625
+    static $descriptions = [];
626
+
627
+    // On détermine le nom du champ id de la table.
628
+    include_spip('base/objets');
629
+    $primary = id_table_objet($objet);
630
+
631
+    // On détermine l'id à utiliser.
632
+    $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary);
633
+
634
+    // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète.
635
+    if (
636
+        !isset($descriptions[$objet][$champ_id][$valeur_id])
637
+        or (isset($options['force']) and $options['force'])
638
+    ) {
639
+        // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet.
640
+        if (
641
+            include_spip('action/editer_' . $objet)
642
+            and function_exists($lire = "{$objet}_lire_champs")
643
+        ) {
644
+            $valeurs = $lire($objet, $valeur_id, $champ_id);
645
+        } else {
646
+            // On récupère la table SQL à partir du type d'objet.
647
+            $table = table_objet_sql($objet);
648
+
649
+            // La condition est appliquée sur le champ désigné par l'utilisateur.
650
+            $where = [
651
+                $champ_id . '=' . sql_quote($valeur_id)
652
+            ];
653
+
654
+            // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide.
655
+            $valeurs = sql_fetsel('*', $table, $where);
656
+        }
657
+
658
+        if (!$valeurs) {
659
+            $valeurs = false;
660
+        }
661
+
662
+        $descriptions[$objet][$champ_id][$valeur_id] = $valeurs;
663
+
664
+        if ($champ_id !== $primary and isset($valeurs[$primary])) {
665
+            $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs;
666
+            $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]];
667
+        }
668
+    }
669
+
670
+    $retour = $descriptions[$objet][$champ_id][$valeur_id];
671
+
672
+    // On ne retourne maintenant que les champs demandés.
673
+    // - on détermine les informations à renvoyer.
674
+    if ($retour and !empty($options['champs'])) {
675
+        $champs = $options['champs'];
676
+        // Extraction des seules informations demandées.
677
+        // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau.
678
+        // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur.
679
+        if (is_array($champs)) {
680
+            // Tableau des informations valides
681
+            $retour = array_intersect_key($retour, array_flip($champs));
682
+        } else {
683
+            // Valeur unique demandée.
684
+            $retour = ($retour[$champs] ?? false);
685
+        }
686
+    }
687
+
688
+    return $retour;
689 689
 }
Please login to merge, or discard this patch.
ecrire/action/relancer_inscription.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -25,22 +25,22 @@  discard block
 block discarded – undo
25 25
  * @return void
26 26
  */
27 27
 function action_relancer_inscription_dist() {
28
-	$securiser_action = charger_fonction('securiser_action', 'inc');
29
-	$id_auteur = $securiser_action();
28
+    $securiser_action = charger_fonction('securiser_action', 'inc');
29
+    $id_auteur = $securiser_action();
30 30
 
31
-	if ((int) $id_auteur && autoriser('relancer', 'inscription')) {
32
-		$auteur = sql_fetsel('prefs, email, nom, statut', 'spip_auteurs', "id_auteur=$id_auteur");
33
-		if ($auteur['statut'] == 'nouveau') {
34
-			include_spip('action/inscrire_auteur');
35
-			action_inscrire_auteur_dist($auteur['prefs'], $auteur['email'], $auteur['nom'], ['force_nouveau' => true]);
36
-		}
37
-	} elseif ($id_auteur === '*' && autoriser('relancer', 'inscription')) {
38
-		$auteurs = sql_allfetsel('prefs, email, nom', 'spip_auteurs', "statut='nouveau'");
39
-		if (is_array($auteurs)) {
40
-			include_spip('action/inscrire_auteur');
41
-			while ($row = array_pop($auteurs)) {
42
-				action_inscrire_auteur_dist($row['prefs'], $row['email'], $row['nom'], ['force_nouveau' => true]);
43
-			}
44
-		}
45
-	}
31
+    if ((int) $id_auteur && autoriser('relancer', 'inscription')) {
32
+        $auteur = sql_fetsel('prefs, email, nom, statut', 'spip_auteurs', "id_auteur=$id_auteur");
33
+        if ($auteur['statut'] == 'nouveau') {
34
+            include_spip('action/inscrire_auteur');
35
+            action_inscrire_auteur_dist($auteur['prefs'], $auteur['email'], $auteur['nom'], ['force_nouveau' => true]);
36
+        }
37
+    } elseif ($id_auteur === '*' && autoriser('relancer', 'inscription')) {
38
+        $auteurs = sql_allfetsel('prefs, email, nom', 'spip_auteurs', "statut='nouveau'");
39
+        if (is_array($auteurs)) {
40
+            include_spip('action/inscrire_auteur');
41
+            while ($row = array_pop($auteurs)) {
42
+                action_inscrire_auteur_dist($row['prefs'], $row['email'], $row['nom'], ['force_nouveau' => true]);
43
+            }
44
+        }
45
+    }
46 46
 }
Please login to merge, or discard this patch.