Completed
Push — master ( 3fe97a...7569f9 )
by cam
02:24
created
ecrire/balise/url_.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 /**
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
  *     Code compilé
37 37
  **/
38 38
 function generer_generer_url($type, $p) {
39
-	$_id = interprete_argument_balise(1, $p);
39
+    $_id = interprete_argument_balise(1, $p);
40 40
 
41
-	if (!$_id) {
42
-		$primary = id_table_objet($type);
43
-		$_id = champ_sql($primary, $p);
44
-	}
41
+    if (!$_id) {
42
+        $primary = id_table_objet($type);
43
+        $_id = champ_sql($primary, $p);
44
+    }
45 45
 
46
-	return generer_generer_url_arg($type, $p, $_id);
46
+    return generer_generer_url_arg($type, $p, $_id);
47 47
 }
48 48
 
49 49
 /**
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
  *     Code compilé
73 73
  **/
74 74
 function generer_generer_url_arg($type, $p, $_id) {
75
-	if ($s = trouver_nom_serveur_distant($p)) {
76
-		// si une fonction de generation des url a ete definie pour ce connect l'utiliser
77
-		if (function_exists($f = 'generer_generer_url_' . $s)) {
78
-			return $f($type, $_id, $s);
79
-		}
80
-		if (!$GLOBALS['connexions'][strtolower((string) $s)]['spip_connect_version']) {
81
-			return null;
82
-		}
83
-		$s = _q($s);
84
-		# exception des urls de documents sur un serveur distant...
85
-		if ($type == 'document') {
86
-			return
87
-				"quete_meta('adresse_site', $s) . '/' .\n\t" .
88
-				"quete_meta('dir_img', $s) . \n\t" .
89
-				"quete_fichier($_id,$s)";
90
-		}
91
-		$s = ", '', '', $s, quete_meta('type_urls', $s)";
92
-	} else {
93
-		$s = ", '', '', true";
94
-	}
95
-
96
-	return "urlencode_1738(generer_objet_url($_id, '$type'$s))";
75
+    if ($s = trouver_nom_serveur_distant($p)) {
76
+        // si une fonction de generation des url a ete definie pour ce connect l'utiliser
77
+        if (function_exists($f = 'generer_generer_url_' . $s)) {
78
+            return $f($type, $_id, $s);
79
+        }
80
+        if (!$GLOBALS['connexions'][strtolower((string) $s)]['spip_connect_version']) {
81
+            return null;
82
+        }
83
+        $s = _q($s);
84
+        # exception des urls de documents sur un serveur distant...
85
+        if ($type == 'document') {
86
+            return
87
+                "quete_meta('adresse_site', $s) . '/' .\n\t" .
88
+                "quete_meta('dir_img', $s) . \n\t" .
89
+                "quete_fichier($_id,$s)";
90
+        }
91
+        $s = ", '', '', $s, quete_meta('type_urls', $s)";
92
+    } else {
93
+        $s = ", '', '', true";
94
+    }
95
+
96
+    return "urlencode_1738(generer_objet_url($_id, '$type'$s))";
97 97
 }
98 98
 
99 99
 
@@ -118,27 +118,27 @@  discard block
 block discarded – undo
118 118
  */
119 119
 function balise_URL__dist($p) {
120 120
 
121
-	$nom = $p->nom_champ;
122
-	if ($nom === 'URL_') {
123
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' URL_']];
124
-		erreur_squelette($msg, $p);
125
-		$p->interdire_scripts = false;
126
-
127
-		return $p;
128
-	} elseif ($f = charger_fonction($nom, 'balise', true)) {
129
-		return $f($p);
130
-	} else {
131
-		$nom = strtolower((string) $nom);
132
-		$code = generer_generer_url(substr($nom, 4), $p);
133
-		$code = champ_sql($nom, $p, $code);
134
-		$p->code = $code;
135
-		if (!$p->etoile) {
136
-			$p->code = "vider_url($code)";
137
-		}
138
-		$p->interdire_scripts = false;
139
-
140
-		return $p;
141
-	}
121
+    $nom = $p->nom_champ;
122
+    if ($nom === 'URL_') {
123
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' URL_']];
124
+        erreur_squelette($msg, $p);
125
+        $p->interdire_scripts = false;
126
+
127
+        return $p;
128
+    } elseif ($f = charger_fonction($nom, 'balise', true)) {
129
+        return $f($p);
130
+    } else {
131
+        $nom = strtolower((string) $nom);
132
+        $code = generer_generer_url(substr($nom, 4), $p);
133
+        $code = champ_sql($nom, $p, $code);
134
+        $p->code = $code;
135
+        if (!$p->etoile) {
136
+            $p->code = "vider_url($code)";
137
+        }
138
+        $p->interdire_scripts = false;
139
+
140
+        return $p;
141
+    }
142 142
 }
143 143
 
144 144
 /**
@@ -162,16 +162,16 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function balise_URL_ARTICLE_dist($p) {
164 164
 
165
-	// Cas particulier des boucles (SYNDIC_ARTICLES)
166
-	$code = $p->type_requete == 'syndic_articles' ? champ_sql('url', $p) : generer_generer_url('article', $p);
165
+    // Cas particulier des boucles (SYNDIC_ARTICLES)
166
+    $code = $p->type_requete == 'syndic_articles' ? champ_sql('url', $p) : generer_generer_url('article', $p);
167 167
 
168
-	$p->code = $code;
169
-	if (!$p->etoile) {
170
-		$p->code = "vider_url($code)";
171
-	}
172
-	$p->interdire_scripts = false;
168
+    $p->code = $code;
169
+    if (!$p->etoile) {
170
+        $p->code = "vider_url($code)";
171
+    }
172
+    $p->interdire_scripts = false;
173 173
 
174
-	return $p;
174
+    return $p;
175 175
 }
176 176
 
177 177
 /**
@@ -191,21 +191,21 @@  discard block
 block discarded – undo
191 191
  *     Pile complétée par le code à générer
192 192
  */
193 193
 function balise_URL_SITE_dist($p) {
194
-	$code = champ_sql('url_site', $p, '');
195
-	if (!$code) {
196
-		$code = generer_generer_url('site', $p);
197
-		if ($code === null) {
198
-			return null;
199
-		}
200
-	} else {
201
-		if (!$p->etoile) {
202
-			$code = "calculer_url($code,'','url', \$connect)";
203
-		}
204
-	}
205
-	$p->code = $code;
206
-	$p->interdire_scripts = false;
207
-
208
-	return $p;
194
+    $code = champ_sql('url_site', $p, '');
195
+    if (!$code) {
196
+        $code = generer_generer_url('site', $p);
197
+        if ($code === null) {
198
+            return null;
199
+        }
200
+    } else {
201
+        if (!$p->etoile) {
202
+            $code = "calculer_url($code,'','url', \$connect)";
203
+        }
204
+    }
205
+    $p->code = $code;
206
+    $p->interdire_scripts = false;
207
+
208
+    return $p;
209 209
 }
210 210
 
211 211
 // Autres balises URL_*, qui ne concernent pas une table
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
  *     Pile complétée par le code à générer
225 225
  */
226 226
 function balise_URL_SITE_SPIP_dist($p) {
227
-	$p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')";
228
-	$p->code = 'spip_htmlspecialchars(' . $p->code . ')';
229
-	$p->interdire_scripts = false;
227
+    $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')";
228
+    $p->code = 'spip_htmlspecialchars(' . $p->code . ')';
229
+    $p->interdire_scripts = false;
230 230
 
231
-	return $p;
231
+    return $p;
232 232
 }
233 233
 
234 234
 
@@ -257,42 +257,42 @@  discard block
 block discarded – undo
257 257
  */
258 258
 function balise_URL_PAGE_dist($p) {
259 259
 
260
-	$code = interprete_argument_balise(1, $p);
261
-	$args = interprete_argument_balise(2, $p);
262
-	if ($args == null) {
263
-		$args = "''";
264
-	}
265
-
266
-	if ($s = trouver_nom_serveur_distant($p)) {
267
-		// si une fonction de generation des url a ete definie pour ce connect l'utiliser
268
-		// elle devra aussi traiter le cas derogatoire type=page
269
-		if (function_exists($f = 'generer_generer_url_' . $s)) {
270
-			if ($args && $args !== "''") {
271
-				$code .= ", $args";
272
-			}
273
-			$code = $f('page', $code, $s);
274
-			$p->code = $code;
275
-			return $p;
276
-		}
277
-		$s = 'connect=' . addslashes((string) $s);
278
-		$args = (($args && $args !== "''") ? "$args . '&$s'" : "'$s'");
279
-	}
280
-
281
-	if (!$code) {
282
-		$noentities = $p->etoile ? "'&'" : '';
283
-		$code = "url_de_base() . preg_replace(',^./,', '', self($noentities))";
284
-	} else {
285
-		if (!$args) {
286
-			$args = "''";
287
-		}
288
-		$noentities = $p->etoile ? ', true' : '';
289
-		$code = "generer_url_public($code, $args$noentities)";
290
-	}
291
-	$p->code = $code;
292
-	spip_log("Calcul url page : connect vaut $s ca donne :" . $p->code . " args $args", _LOG_INFO);
293
-
294
-	#$p->interdire_scripts = true;
295
-	return $p;
260
+    $code = interprete_argument_balise(1, $p);
261
+    $args = interprete_argument_balise(2, $p);
262
+    if ($args == null) {
263
+        $args = "''";
264
+    }
265
+
266
+    if ($s = trouver_nom_serveur_distant($p)) {
267
+        // si une fonction de generation des url a ete definie pour ce connect l'utiliser
268
+        // elle devra aussi traiter le cas derogatoire type=page
269
+        if (function_exists($f = 'generer_generer_url_' . $s)) {
270
+            if ($args && $args !== "''") {
271
+                $code .= ", $args";
272
+            }
273
+            $code = $f('page', $code, $s);
274
+            $p->code = $code;
275
+            return $p;
276
+        }
277
+        $s = 'connect=' . addslashes((string) $s);
278
+        $args = (($args && $args !== "''") ? "$args . '&$s'" : "'$s'");
279
+    }
280
+
281
+    if (!$code) {
282
+        $noentities = $p->etoile ? "'&'" : '';
283
+        $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))";
284
+    } else {
285
+        if (!$args) {
286
+            $args = "''";
287
+        }
288
+        $noentities = $p->etoile ? ', true' : '';
289
+        $code = "generer_url_public($code, $args$noentities)";
290
+    }
291
+    $p->code = $code;
292
+    spip_log("Calcul url page : connect vaut $s ca donne :" . $p->code . " args $args", _LOG_INFO);
293
+
294
+    #$p->interdire_scripts = true;
295
+    return $p;
296 296
 }
297 297
 
298 298
 
@@ -319,24 +319,24 @@  discard block
 block discarded – undo
319 319
  */
320 320
 function balise_URL_ECRIRE_dist($p) {
321 321
 
322
-	$code = interprete_argument_balise(1, $p);
323
-	if (!$code) {
324
-		$fonc = "''";
325
-	} else {
326
-		$fonc = $code;
327
-		$args = interprete_argument_balise(2, $p);
328
-		if ($args === null) {
329
-			$args = "''";
330
-		}
331
-		$noentities = $p->etoile ? ', true' : '';
332
-		if ($args != "''" || $noentities) {
333
-			$fonc .= ",$args$noentities";
334
-		}
335
-	}
336
-	$p->code = 'generer_url_ecrire(' . $fonc . ')';
337
-	$p->interdire_scripts = false;
338
-
339
-	return $p;
322
+    $code = interprete_argument_balise(1, $p);
323
+    if (!$code) {
324
+        $fonc = "''";
325
+    } else {
326
+        $fonc = $code;
327
+        $args = interprete_argument_balise(2, $p);
328
+        if ($args === null) {
329
+            $args = "''";
330
+        }
331
+        $noentities = $p->etoile ? ', true' : '';
332
+        if ($args != "''" || $noentities) {
333
+            $fonc .= ",$args$noentities";
334
+        }
335
+    }
336
+    $p->code = 'generer_url_ecrire(' . $fonc . ')';
337
+    $p->interdire_scripts = false;
338
+
339
+    return $p;
340 340
 }
341 341
 
342 342
 
@@ -362,24 +362,24 @@  discard block
 block discarded – undo
362 362
  *     Pile complétée par le code à générer
363 363
  */
364 364
 function balise_URL_ACTION_AUTEUR_dist($p) {
365
-	$p->descr['session'] = true;
366
-
367
-	$p->code = interprete_argument_balise(1, $p);
368
-
369
-	$args = interprete_argument_balise(2, $p);
370
-	if ($args != "''" && $args !== null) {
371
-		$p->code .= ',' . $args;
372
-	}
373
-	$redirect = interprete_argument_balise(3, $p);
374
-	if ($redirect != "''" && $redirect !== null) {
375
-		if ($args == "''" || $args === null) {
376
-			$p->code .= ",''";
377
-		}
378
-		$p->code .= ',' . $redirect;
379
-	}
380
-
381
-	$p->code = 'generer_action_auteur(' . $p->code . ')';
382
-	$p->interdire_scripts = false;
383
-
384
-	return $p;
365
+    $p->descr['session'] = true;
366
+
367
+    $p->code = interprete_argument_balise(1, $p);
368
+
369
+    $args = interprete_argument_balise(2, $p);
370
+    if ($args != "''" && $args !== null) {
371
+        $p->code .= ',' . $args;
372
+    }
373
+    $redirect = interprete_argument_balise(3, $p);
374
+    if ($redirect != "''" && $redirect !== null) {
375
+        if ($args == "''" || $args === null) {
376
+            $p->code .= ",''";
377
+        }
378
+        $p->code .= ',' . $redirect;
379
+    }
380
+
381
+    $p->code = 'generer_action_auteur(' . $p->code . ')';
382
+    $p->interdire_scripts = false;
383
+
384
+    return $p;
385 385
 }
Please login to merge, or discard this patch.
ecrire/balise/logo_.php 1 patch
Indentation   +85 added lines, -85 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
 
@@ -55,88 +55,88 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function balise_LOGO__dist($p) {
57 57
 
58
-	preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
59
-	$type = strtolower($regs[1]);
60
-	$suite_logo = $regs[2];
61
-
62
-	// cas de #LOGO_SITE_SPIP
63
-	if ($type == 'site_spip') {
64
-		$type = 'site';
65
-		$_id_objet = "\"'0'\"";
66
-	}
67
-
68
-	$id_objet = id_table_objet($type);
69
-	if (!isset($_id_objet)) {
70
-		$_id_objet = champ_sql($id_objet, $p);
71
-	}
72
-
73
-	$fichier = ($p->etoile === '**') ? -1 : 0;
74
-	$coord = [];
75
-	$align = $lien = '';
76
-	$mode_logo = '';
77
-
78
-	if ($p->param && !$p->param[0][0]) {
79
-		$params = $p->param[0];
80
-		array_shift($params);
81
-		foreach ($params as $a) {
82
-			if ($a[0]->type === 'texte') {
83
-				$n = $a[0]->texte;
84
-				if (is_numeric($n)) {
85
-					$coord[] = $n;
86
-				} elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
87
-					$align = $n;
88
-				} elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
89
-					$mode_logo = $n;
90
-				}
91
-			} else {
92
-				$lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
93
-			}
94
-		}
95
-	}
96
-
97
-	$coord_x = $coord ? (int) array_shift($coord) : 0;
98
-	$coord_y = $coord ? (int) array_shift($coord) : 0;
99
-
100
-	if ($p->etoile === '*') {
101
-		include_spip('balise/url_');
102
-		$lien = generer_generer_url_arg($type, $p, $_id_objet);
103
-	}
104
-
105
-	$connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
106
-	if ($type == 'document') {
107
-		$qconnect = _q($connect);
108
-		$doc = "quete_document($_id_objet, $qconnect)";
109
-		if ($fichier) {
110
-			$code = "quete_logo_file($doc, $qconnect)";
111
-		} else {
112
-			$code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
113
-		}
114
-		// (x=non-faux ? y : '') pour affecter x en retournant y
115
-		if ($p->descr['documents']) {
116
-			$code = '(($doublons["documents"] .= ",". '
117
-				. $_id_objet
118
-				. ") ? $code : '')";
119
-		}
120
-	} elseif ($connect) {
121
-		$code = "''";
122
-		spip_log('Les logos distants ne sont pas prevus');
123
-	} else {
124
-		// pour generer_code_logo
125
-		include_spip('balise/id_logo_');
126
-		$champ_logo = '';
127
-		if ($fichier) {
128
-			$champ_logo = 'fichier';
129
-		}
130
-		$code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo);
131
-	}
132
-
133
-	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
134
-	if ($coord_x || $coord_y) {
135
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
136
-	}
137
-
138
-	$p->code = $code;
139
-	$p->interdire_scripts = false;
140
-
141
-	return $p;
58
+    preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
59
+    $type = strtolower($regs[1]);
60
+    $suite_logo = $regs[2];
61
+
62
+    // cas de #LOGO_SITE_SPIP
63
+    if ($type == 'site_spip') {
64
+        $type = 'site';
65
+        $_id_objet = "\"'0'\"";
66
+    }
67
+
68
+    $id_objet = id_table_objet($type);
69
+    if (!isset($_id_objet)) {
70
+        $_id_objet = champ_sql($id_objet, $p);
71
+    }
72
+
73
+    $fichier = ($p->etoile === '**') ? -1 : 0;
74
+    $coord = [];
75
+    $align = $lien = '';
76
+    $mode_logo = '';
77
+
78
+    if ($p->param && !$p->param[0][0]) {
79
+        $params = $p->param[0];
80
+        array_shift($params);
81
+        foreach ($params as $a) {
82
+            if ($a[0]->type === 'texte') {
83
+                $n = $a[0]->texte;
84
+                if (is_numeric($n)) {
85
+                    $coord[] = $n;
86
+                } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
87
+                    $align = $n;
88
+                } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
89
+                    $mode_logo = $n;
90
+                }
91
+            } else {
92
+                $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
93
+            }
94
+        }
95
+    }
96
+
97
+    $coord_x = $coord ? (int) array_shift($coord) : 0;
98
+    $coord_y = $coord ? (int) array_shift($coord) : 0;
99
+
100
+    if ($p->etoile === '*') {
101
+        include_spip('balise/url_');
102
+        $lien = generer_generer_url_arg($type, $p, $_id_objet);
103
+    }
104
+
105
+    $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
106
+    if ($type == 'document') {
107
+        $qconnect = _q($connect);
108
+        $doc = "quete_document($_id_objet, $qconnect)";
109
+        if ($fichier) {
110
+            $code = "quete_logo_file($doc, $qconnect)";
111
+        } else {
112
+            $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
113
+        }
114
+        // (x=non-faux ? y : '') pour affecter x en retournant y
115
+        if ($p->descr['documents']) {
116
+            $code = '(($doublons["documents"] .= ",". '
117
+                . $_id_objet
118
+                . ") ? $code : '')";
119
+        }
120
+    } elseif ($connect) {
121
+        $code = "''";
122
+        spip_log('Les logos distants ne sont pas prevus');
123
+    } else {
124
+        // pour generer_code_logo
125
+        include_spip('balise/id_logo_');
126
+        $champ_logo = '';
127
+        if ($fichier) {
128
+            $champ_logo = 'fichier';
129
+        }
130
+        $code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo);
131
+    }
132
+
133
+    // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
134
+    if ($coord_x || $coord_y) {
135
+        $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
136
+    }
137
+
138
+    $p->code = $code;
139
+    $p->interdire_scripts = false;
140
+
141
+    return $p;
142 142
 }
Please login to merge, or discard this patch.
ecrire/balise/menu_lang_ecrire.php 1 patch
Indentation   +31 added lines, -31 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,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *     Pile complétée du code compilé
37 37
  **/
38 38
 function balise_MENU_LANG_ECRIRE($p) {
39
-	return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']);
39
+    return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']);
40 40
 }
41 41
 
42 42
 /**
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
  *   - string: Si pas de multilinguisme
56 56
  */
57 57
 function balise_MENU_LANG_ECRIRE_stat($args, $context_compil) {
58
-	include_spip('inc/lang');
59
-	if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) {
60
-		return '';
61
-	}
58
+    include_spip('inc/lang');
59
+    if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) {
60
+        return '';
61
+    }
62 62
 
63
-	return $args;
63
+    return $args;
64 64
 }
65 65
 
66 66
 /**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
  *     Liste : Chemin du squelette, durée du cache, contexte
77 77
  **/
78 78
 function balise_MENU_LANG_ECRIRE_dyn($opt) {
79
-	return menu_lang_pour_tous('var_lang_ecrire', $opt);
79
+    return menu_lang_pour_tous('var_lang_ecrire', $opt);
80 80
 }
81 81
 
82 82
 /**
@@ -96,30 +96,30 @@  discard block
 block discarded – undo
96 96
  *     Liste : Chemin du squelette, durée du cache, contexte
97 97
  **/
98 98
 function menu_lang_pour_tous($nom, $default) {
99
-	include_spip('inc/lang');
99
+    include_spip('inc/lang');
100 100
 
101
-	if ($GLOBALS['spip_lang'] != $default) {
102
-		$opt = lang_select($default);  # et remplace
103
-		if ($GLOBALS['spip_lang'] != $default) {
104
-			$default = '';  # annule tout choix par defaut
105
-			if ($opt) {
106
-				lang_select();
107
-			}
108
-		}
109
-	}
101
+    if ($GLOBALS['spip_lang'] != $default) {
102
+        $opt = lang_select($default);  # et remplace
103
+        if ($GLOBALS['spip_lang'] != $default) {
104
+            $default = '';  # annule tout choix par defaut
105
+            if ($opt) {
106
+                lang_select();
107
+            }
108
+        }
109
+    }
110 110
 
111
-	# lien a partir de /
112
-	$cible = parametre_url(self(), 'lang', '', '&');
113
-	$post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true);
111
+    # lien a partir de /
112
+    $cible = parametre_url(self(), 'lang', '', '&');
113
+    $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true);
114 114
 
115
-	return [
116
-		'formulaires/menu_lang',
117
-		3600,
118
-		[
119
-			'nom' => $nom,
120
-			'url' => $post,
121
-			'name' => $nom,
122
-			'default' => $default,
123
-		]
124
-	];
115
+    return [
116
+        'formulaires/menu_lang',
117
+        3600,
118
+        [
119
+            'nom' => $nom,
120
+            'url' => $post,
121
+            'name' => $nom,
122
+            'default' => $default,
123
+        ]
124
+    ];
125 125
 }
Please login to merge, or discard this patch.
ecrire/balise/formulaire_admin.php 1 patch
Indentation   +141 added lines, -141 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
 /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
  *     Pile complétée du code compilé
42 42
  **/
43 43
 function balise_FORMULAIRE_ADMIN($p) {
44
-	return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []);
44
+    return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []);
45 45
 }
46 46
 
47 47
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
  *   - chaîne vide sinon.
59 59
  */
60 60
 function balise_FORMULAIRE_ADMIN_stat($args, $context_compil) {
61
-	return $args;
61
+    return $args;
62 62
 }
63 63
 
64 64
 
@@ -83,64 +83,64 @@  discard block
 block discarded – undo
83 83
  **/
84 84
 function balise_FORMULAIRE_ADMIN_dyn($float = '', $debug = '') {
85 85
 
86
-	static $dejafait = false;
86
+    static $dejafait = false;
87 87
 
88
-	if (empty($_COOKIE['spip_admin'])) {
89
-		return '';
90
-	}
88
+    if (empty($_COOKIE['spip_admin'])) {
89
+        return '';
90
+    }
91 91
 
92
-	if (!is_array($debug)) {
93
-		if ($dejafait) {
94
-			return '';
95
-		}
96
-	} else {
97
-		if ($dejafait) {
98
-			if (empty($debug['sourcefile'])) {
99
-				return '';
100
-			}
101
-			foreach ($debug['sourcefile'] as $k => $v) {
102
-				if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) {
103
-					return $debug['resultat'][$k . 'tout'];
104
-				}
105
-			}
92
+    if (!is_array($debug)) {
93
+        if ($dejafait) {
94
+            return '';
95
+        }
96
+    } else {
97
+        if ($dejafait) {
98
+            if (empty($debug['sourcefile'])) {
99
+                return '';
100
+            }
101
+            foreach ($debug['sourcefile'] as $k => $v) {
102
+                if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) {
103
+                    return $debug['resultat'][$k . 'tout'];
104
+                }
105
+            }
106 106
 
107
-			return '';
108
-		}
109
-	}
107
+            return '';
108
+        }
109
+    }
110 110
 
111
-	include_spip('inc/autoriser');
112
-	include_spip('base/abstract_sql');
111
+    include_spip('inc/autoriser');
112
+    include_spip('base/abstract_sql');
113 113
 
114 114
 
115
-	$dejafait = true;
115
+    $dejafait = true;
116 116
 
117
-	// Preparer le #ENV des boutons
117
+    // Preparer le #ENV des boutons
118 118
 
119
-	$env = admin_objet();
119
+    $env = admin_objet();
120 120
 
121
-	// Pas de "modifier ce..." ? -> donner "acces a l'espace prive"
122
-	if (!$env) {
123
-		$env['ecrire'] = _DIR_RESTREINT_ABS;
124
-	}
121
+    // Pas de "modifier ce..." ? -> donner "acces a l'espace prive"
122
+    if (!$env) {
123
+        $env['ecrire'] = _DIR_RESTREINT_ABS;
124
+    }
125 125
 
126
-	$env['divclass'] = $float;
127
-	$env['lang'] = admin_lang();
128
-	$env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul');
129
-	$env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug());
130
-	$env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider();
131
-	$env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : '');
126
+    $env['divclass'] = $float;
127
+    $env['lang'] = admin_lang();
128
+    $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul');
129
+    $env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug());
130
+    $env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider();
131
+    $env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : '');
132 132
 
133
-	if (empty($GLOBALS['use_cache'])) {
134
-		$env['use_cache'] = ' *';
135
-	}
133
+    if (empty($GLOBALS['use_cache'])) {
134
+        $env['use_cache'] = ' *';
135
+    }
136 136
 
137
-	if (isset($debug['validation'])) {
138
-		$env['xhtml_error'] = $debug['validation'];
139
-	}
137
+    if (isset($debug['validation'])) {
138
+        $env['xhtml_error'] = $debug['validation'];
139
+    }
140 140
 
141
-	$env['_pipelines']['formulaire_admin'] = [];
141
+    $env['_pipelines']['formulaire_admin'] = [];
142 142
 
143
-	return ['formulaires/administration', 0, $env];
143
+    return ['formulaires/administration', 0, $env];
144 144
 }
145 145
 
146 146
 
@@ -158,46 +158,46 @@  discard block
 block discarded – undo
158 158
  *     Tableau de l'environnement calculé
159 159
  **/
160 160
 function admin_objet() {
161
-	include_spip('inc/urls');
162
-	$env = [];
163
-
164
-	$trouver_table = charger_fonction('trouver_table', 'base');
165
-	$objets = urls_liste_objets(false);
166
-	$objets = array_diff($objets, ['rubrique']);
167
-	$objets = array_reverse($objets);
168
-	array_unshift($objets, 'rubrique');
169
-	foreach ($objets as $obj) {
170
-		$type = $obj;
171
-		if (
172
-			$type == objet_type($type, false)
173
-			&& ($_id_type = id_table_objet($type))
174
-			&& isset($GLOBALS['contexte'][$_id_type])
175
-			&& ($id = $GLOBALS['contexte'][$_id_type])
176
-			&& !is_array($id)
177
-			&& ($id = (int) $id)
178
-			&& ($desc = $trouver_table(table_objet_sql($type)))
179
-		) {
180
-			$id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id);
181
-			if ($id) {
182
-				$env[$_id_type] = $id;
183
-				$env['objet'] = $type;
184
-				$env['id_objet'] = $id;
185
-				$env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false));
186
-				if (
187
-					isset($desc['field']['id_rubrique'])
188
-					&& $type != 'rubrique'
189
-				) {
190
-					unset($env['id_rubrique']);
191
-					unset($env['voir_rubrique']);
192
-					if (admin_preview($type, $id, $desc)) {
193
-						$env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&');
194
-					}
195
-				}
196
-			}
197
-		}
198
-	}
199
-
200
-	return $env;
161
+    include_spip('inc/urls');
162
+    $env = [];
163
+
164
+    $trouver_table = charger_fonction('trouver_table', 'base');
165
+    $objets = urls_liste_objets(false);
166
+    $objets = array_diff($objets, ['rubrique']);
167
+    $objets = array_reverse($objets);
168
+    array_unshift($objets, 'rubrique');
169
+    foreach ($objets as $obj) {
170
+        $type = $obj;
171
+        if (
172
+            $type == objet_type($type, false)
173
+            && ($_id_type = id_table_objet($type))
174
+            && isset($GLOBALS['contexte'][$_id_type])
175
+            && ($id = $GLOBALS['contexte'][$_id_type])
176
+            && !is_array($id)
177
+            && ($id = (int) $id)
178
+            && ($desc = $trouver_table(table_objet_sql($type)))
179
+        ) {
180
+            $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id);
181
+            if ($id) {
182
+                $env[$_id_type] = $id;
183
+                $env['objet'] = $type;
184
+                $env['id_objet'] = $id;
185
+                $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false));
186
+                if (
187
+                    isset($desc['field']['id_rubrique'])
188
+                    && $type != 'rubrique'
189
+                ) {
190
+                    unset($env['id_rubrique']);
191
+                    unset($env['voir_rubrique']);
192
+                    if (admin_preview($type, $id, $desc)) {
193
+                        $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&');
194
+                    }
195
+                }
196
+            }
197
+        }
198
+    }
199
+
200
+    return $env;
201 201
 }
202 202
 
203 203
 
@@ -215,30 +215,30 @@  discard block
 block discarded – undo
215 215
  *     - Tableau d'un élément sinon.
216 216
  **/
217 217
 function admin_preview($type, $id, $desc = null) {
218
-	if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) {
219
-		return '';
220
-	}
221
-
222
-	if (!$desc) {
223
-		$trouver_table = charger_fonction('trouver_table', 'base');
224
-		$desc = $trouver_table(table_objet_sql($type));
225
-	}
226
-	if (!$desc || !isset($desc['field']['statut'])) {
227
-		return '';
228
-	}
229
-
230
-	include_spip('inc/autoriser');
231
-	if (!autoriser('previsualiser')) {
232
-		return '';
233
-	}
234
-
235
-	$notpub = sql_in('statut', ['prop', 'prive']);
236
-
237
-	if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') {
238
-		$notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')';
239
-	}
240
-
241
-	return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)");
218
+    if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) {
219
+        return '';
220
+    }
221
+
222
+    if (!$desc) {
223
+        $trouver_table = charger_fonction('trouver_table', 'base');
224
+        $desc = $trouver_table(table_objet_sql($type));
225
+    }
226
+    if (!$desc || !isset($desc['field']['statut'])) {
227
+        return '';
228
+    }
229
+
230
+    include_spip('inc/autoriser');
231
+    if (!autoriser('previsualiser')) {
232
+        return '';
233
+    }
234
+
235
+    $notpub = sql_in('statut', ['prop', 'prive']);
236
+
237
+    if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') {
238
+        $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')';
239
+    }
240
+
241
+    return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)");
242 242
 }
243 243
 
244 244
 
@@ -249,25 +249,25 @@  discard block
 block discarded – undo
249 249
  *     Code de langue
250 250
  **/
251 251
 function admin_lang() {
252
-	$alang = '';
253
-	if (!empty($_COOKIE['spip_admin'])) {
254
-		$email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']);
255
-		$alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login));
256
-		if (!$alang) {
257
-			$alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login));
258
-		}
259
-	}
260
-	if (!$alang) {
261
-		return '';
262
-	}
263
-
264
-	$l = lang_select($alang);
265
-	$alang = $GLOBALS['spip_lang'];
266
-	if ($l) {
267
-		lang_select();
268
-	}
269
-
270
-	return $alang;
252
+    $alang = '';
253
+    if (!empty($_COOKIE['spip_admin'])) {
254
+        $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']);
255
+        $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login));
256
+        if (!$alang) {
257
+            $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login));
258
+        }
259
+    }
260
+    if (!$alang) {
261
+        return '';
262
+    }
263
+
264
+    $l = lang_select($alang);
265
+    $alang = $GLOBALS['spip_lang'];
266
+    if ($l) {
267
+        lang_select();
268
+    }
269
+
270
+    return $alang;
271 271
 }
272 272
 
273 273
 /**
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
  **/
278 278
 function admin_valider() {
279 279
 
280
-	return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ?
281
-		(parametre_url(self(), 'var_mode', 'debug', '&')
282
-			. '&var_mode_affiche=validation') :
283
-		('http://validator.w3.org/check?uri='
284
-			. rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri())));
280
+    return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ?
281
+        (parametre_url(self(), 'var_mode', 'debug', '&')
282
+            . '&var_mode_affiche=validation') :
283
+        ('http://validator.w3.org/check?uri='
284
+            . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri())));
285 285
 }
286 286
 
287 287
 /**
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
  * @return string
291 291
  **/
292 292
 function admin_debug() {
293
-	return (
294
-		(isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug']
295
-		|| isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug']
296
-		|| defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug')
297
-	)
298
-		? parametre_url(self(), 'var_mode', 'debug', '&') : '';
293
+    return (
294
+        (isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug']
295
+        || isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug']
296
+        || defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug')
297
+    )
298
+        ? parametre_url(self(), 'var_mode', 'debug', '&') : '';
299 299
 }
Please login to merge, or discard this patch.
ecrire/maj/legacy/v40.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @package SPIP\Core\SQL\Upgrade
20 20
  **/
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -34,49 +34,49 @@  discard block
 block discarded – undo
34 34
  **/
35 35
 function maj_timestamp_mysql($tables = null) {
36 36
 
37
-	include_spip('base/dump');
38
-	if (is_null($tables)) {
39
-		$tables = base_lister_toutes_tables();
40
-	} elseif (is_string($tables)) {
41
-		$tables = [$tables];
42
-	} elseif (!is_array($tables)) {
43
-		return;
44
-	}
37
+    include_spip('base/dump');
38
+    if (is_null($tables)) {
39
+        $tables = base_lister_toutes_tables();
40
+    } elseif (is_string($tables)) {
41
+        $tables = [$tables];
42
+    } elseif (!is_array($tables)) {
43
+        return;
44
+    }
45 45
 
46
-	// rien a faire si base non mysql
47
-	if (!str_starts_with((string) $GLOBALS['connexions'][0]['type'], 'mysql')) {
48
-		return;
49
-	}
46
+    // rien a faire si base non mysql
47
+    if (!str_starts_with((string) $GLOBALS['connexions'][0]['type'], 'mysql')) {
48
+        return;
49
+    }
50 50
 
51
-	$trouver_table = charger_fonction('trouver_table', 'base');
52
-	// forcer le vidage de cache
53
-	$trouver_table('');
51
+    $trouver_table = charger_fonction('trouver_table', 'base');
52
+    // forcer le vidage de cache
53
+    $trouver_table('');
54 54
 
55
-	foreach ($tables as $table) {
56
-		if (time() >= _TIME_OUT) {
57
-			return;
58
-		}
59
-		if ($desc = $trouver_table($table)) {
60
-			$fields_corrected = _mysql_remplacements_definitions_table($desc['field']);
61
-			$d = array_diff($desc['field'], $fields_corrected);
62
-			if ($d) {
63
-				spip_log("Table $table TIMESTAMP incorrect", 'maj');
64
-				foreach ($desc['field'] as $field => $type) {
65
-					if ($desc['field'][$field] !== $fields_corrected[$field]) {
66
-						spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE);
67
-						sql_alter("table $table change $field $field " . $fields_corrected[$field]);
68
-						$trouver_table('');
69
-						$new_desc = $trouver_table($table);
70
-						spip_log(
71
-							"Apres conversion $table : " . var_export($new_desc['field'], true),
72
-							'maj.' . _LOG_INFO_IMPORTANTE
73
-						);
74
-					}
75
-				}
76
-			}
77
-		}
78
-	}
55
+    foreach ($tables as $table) {
56
+        if (time() >= _TIME_OUT) {
57
+            return;
58
+        }
59
+        if ($desc = $trouver_table($table)) {
60
+            $fields_corrected = _mysql_remplacements_definitions_table($desc['field']);
61
+            $d = array_diff($desc['field'], $fields_corrected);
62
+            if ($d) {
63
+                spip_log("Table $table TIMESTAMP incorrect", 'maj');
64
+                foreach ($desc['field'] as $field => $type) {
65
+                    if ($desc['field'][$field] !== $fields_corrected[$field]) {
66
+                        spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE);
67
+                        sql_alter("table $table change $field $field " . $fields_corrected[$field]);
68
+                        $trouver_table('');
69
+                        $new_desc = $trouver_table($table);
70
+                        spip_log(
71
+                            "Apres conversion $table : " . var_export($new_desc['field'], true),
72
+                            'maj.' . _LOG_INFO_IMPORTANTE
73
+                        );
74
+                    }
75
+                }
76
+            }
77
+        }
78
+    }
79 79
 
80
-	// forcer le vidage de cache
81
-	$trouver_table('');
80
+    // forcer le vidage de cache
81
+    $trouver_table('');
82 82
 }
Please login to merge, or discard this patch.
ecrire/auth/ldap.php 1 patch
Indentation   +174 added lines, -174 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
 // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok
@@ -24,12 +24,12 @@  discard block
 block discarded – undo
24 24
 // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login
25 25
 // ne pas ecraser une definition perso dans mes_options
26 26
 if (!isset($GLOBALS['ldap_attributes']) || !is_array($GLOBALS['ldap_attributes'])) {
27
-	$GLOBALS['ldap_attributes'] = [
28
-		'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'],
29
-		'nom' => 'cn',
30
-		'email' => 'mail',
31
-		'bio' => 'description'
32
-	];
27
+    $GLOBALS['ldap_attributes'] = [
28
+        'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'],
29
+        'nom' => 'cn',
30
+        'email' => 'mail',
31
+        'bio' => 'description'
32
+    ];
33 33
 }
34 34
 
35 35
 /**
@@ -55,49 +55,49 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) {
57 57
 
58
-	#spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
59
-
60
-	// Utilisateur connu ?
61
-	// si http auth, inutile de reauthentifier: cela
62
-	// ne marchera pas avec auth http autre que basic.
63
-	$checkpass = !isset($_SERVER['REMOTE_USER']);
64
-	if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
65
-		return [];
66
-	}
67
-	$credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass];
68
-
69
-	// Si l'utilisateur figure deja dans la base, y recuperer les infos
70
-	$r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
71
-
72
-	if ($r) {
73
-		return array_merge($r, $credentials_ldap);
74
-	}
75
-
76
-	// sinon importer les infos depuis LDAP,
77
-
78
-	if (
79
-		$GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur))
80
-	) {
81
-		// rajouter le statut indique  a l'install
82
-		$desc['statut'] = $GLOBALS['meta']['ldap_statut_import'];
83
-		$desc['login'] = $login;
84
-		$desc['source'] = 'ldap';
85
-		$desc['pass'] = '';
86
-
87
-		$r = sql_insertq('spip_auteurs', $desc, [], $serveur);
88
-	}
89
-
90
-	if ($r) {
91
-		return array_merge(
92
-			$credentials_ldap,
93
-			sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur)
94
-		);
95
-	}
96
-
97
-	// sinon echec
98
-	spip_log("Creation de l'auteur '$login' impossible");
99
-
100
-	return [];
58
+    #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
59
+
60
+    // Utilisateur connu ?
61
+    // si http auth, inutile de reauthentifier: cela
62
+    // ne marchera pas avec auth http autre que basic.
63
+    $checkpass = !isset($_SERVER['REMOTE_USER']);
64
+    if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
65
+        return [];
66
+    }
67
+    $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass];
68
+
69
+    // Si l'utilisateur figure deja dans la base, y recuperer les infos
70
+    $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
71
+
72
+    if ($r) {
73
+        return array_merge($r, $credentials_ldap);
74
+    }
75
+
76
+    // sinon importer les infos depuis LDAP,
77
+
78
+    if (
79
+        $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur))
80
+    ) {
81
+        // rajouter le statut indique  a l'install
82
+        $desc['statut'] = $GLOBALS['meta']['ldap_statut_import'];
83
+        $desc['login'] = $login;
84
+        $desc['source'] = 'ldap';
85
+        $desc['pass'] = '';
86
+
87
+        $r = sql_insertq('spip_auteurs', $desc, [], $serveur);
88
+    }
89
+
90
+    if ($r) {
91
+        return array_merge(
92
+            $credentials_ldap,
93
+            sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur)
94
+        );
95
+    }
96
+
97
+    // sinon echec
98
+    spip_log("Creation de l'auteur '$login' impossible");
99
+
100
+    return [];
101 101
 }
102 102
 
103 103
 /**
@@ -111,36 +111,36 @@  discard block
 block discarded – undo
111 111
  * @return array
112 112
  */
113 113
 function auth_ldap_connect($serveur = '') {
114
-	include_spip('base/connect_sql');
115
-	static $connexions_ldap = [];
116
-	if (isset($connexions_ldap[$serveur])) {
117
-		return $connexions_ldap[$serveur];
118
-	}
119
-	$connexion = spip_connect($serveur);
120
-	if (!is_array($connexion['ldap'])) {
121
-		if ($connexion['authentification']['ldap']) {
122
-			$f = _DIR_CONNECT . $connexion['authentification']['ldap'];
123
-			unset($GLOBALS['ldap_link']);
124
-			if (is_readable($f)) {
125
-				include_once($f);
126
-			};
127
-			if (isset($GLOBALS['ldap_link'])) {
128
-				$connexion['ldap'] = [
129
-					'link' => $GLOBALS['ldap_link'],
130
-					'base' => $GLOBALS['ldap_base']
131
-				];
132
-			} else {
133
-				spip_log("connection LDAP $serveur mal definie dans $f");
134
-			}
135
-			if (isset($GLOBALS['ldap_champs'])) {
136
-				$connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
137
-			}
138
-		} else {
139
-			spip_log("connection LDAP $serveur inconnue");
140
-		}
141
-	}
142
-
143
-	return $connexions_ldap[$serveur] = $connexion['ldap'];
114
+    include_spip('base/connect_sql');
115
+    static $connexions_ldap = [];
116
+    if (isset($connexions_ldap[$serveur])) {
117
+        return $connexions_ldap[$serveur];
118
+    }
119
+    $connexion = spip_connect($serveur);
120
+    if (!is_array($connexion['ldap'])) {
121
+        if ($connexion['authentification']['ldap']) {
122
+            $f = _DIR_CONNECT . $connexion['authentification']['ldap'];
123
+            unset($GLOBALS['ldap_link']);
124
+            if (is_readable($f)) {
125
+                include_once($f);
126
+            };
127
+            if (isset($GLOBALS['ldap_link'])) {
128
+                $connexion['ldap'] = [
129
+                    'link' => $GLOBALS['ldap_link'],
130
+                    'base' => $GLOBALS['ldap_base']
131
+                ];
132
+            } else {
133
+                spip_log("connection LDAP $serveur mal definie dans $f");
134
+            }
135
+            if (isset($GLOBALS['ldap_champs'])) {
136
+                $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
137
+            }
138
+        } else {
139
+            spip_log("connection LDAP $serveur inconnue");
140
+        }
141
+    }
142
+
143
+    return $connexions_ldap[$serveur] = $connexion['ldap'];
144 144
 }
145 145
 
146 146
 /**
@@ -154,52 +154,52 @@  discard block
 block discarded – undo
154 154
  *    Le login trouvé ou chaine vide si non trouvé
155 155
  */
156 156
 function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') {
157
-	// Securite anti-injection et contre un serveur LDAP laxiste
158
-	$login_search = preg_replace('/[^-@._\s\d\w]/', '', $login);
159
-	if (!strlen($login_search) || $checkpass && !strlen($pass)) {
160
-		return '';
161
-	}
162
-
163
-	// verifier la connexion
164
-	if (!$ldap = auth_ldap_connect($serveur)) {
165
-		return '';
166
-	}
167
-
168
-	$ldap_link = $ldap['link'] ?? null;
169
-	$ldap_base = $ldap['base'] ?? null;
170
-	$desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes'];
171
-
172
-	$logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']];
173
-
174
-	// Tenter une recherche pour essayer de retrouver le DN
175
-	foreach ($logins as $att) {
176
-		$result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']);
177
-		$info = @ldap_get_entries($ldap_link, $result);
178
-		// Ne pas accepter les resultats si plus d'une entree
179
-		// (on veut un attribut unique)
180
-
181
-		if (is_array($info) && $info['count'] == 1) {
182
-			$dn = $info[0]['dn'];
183
-			if (!$checkpass) {
184
-				return $dn;
185
-			}
186
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
187
-				return $dn;
188
-			}
189
-		}
190
-	}
191
-
192
-	if ($checkpass && !isset($dn)) {
193
-		// Si echec, essayer de deviner le DN
194
-		foreach ($logins as $att) {
195
-			$dn = "$att=$login_search, $ldap_base";
196
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
197
-				return "$att=$login_search, $ldap_base";
198
-			}
199
-		}
200
-	}
201
-
202
-	return '';
157
+    // Securite anti-injection et contre un serveur LDAP laxiste
158
+    $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login);
159
+    if (!strlen($login_search) || $checkpass && !strlen($pass)) {
160
+        return '';
161
+    }
162
+
163
+    // verifier la connexion
164
+    if (!$ldap = auth_ldap_connect($serveur)) {
165
+        return '';
166
+    }
167
+
168
+    $ldap_link = $ldap['link'] ?? null;
169
+    $ldap_base = $ldap['base'] ?? null;
170
+    $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes'];
171
+
172
+    $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']];
173
+
174
+    // Tenter une recherche pour essayer de retrouver le DN
175
+    foreach ($logins as $att) {
176
+        $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']);
177
+        $info = @ldap_get_entries($ldap_link, $result);
178
+        // Ne pas accepter les resultats si plus d'une entree
179
+        // (on veut un attribut unique)
180
+
181
+        if (is_array($info) && $info['count'] == 1) {
182
+            $dn = $info[0]['dn'];
183
+            if (!$checkpass) {
184
+                return $dn;
185
+            }
186
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
187
+                return $dn;
188
+            }
189
+        }
190
+    }
191
+
192
+    if ($checkpass && !isset($dn)) {
193
+        // Si echec, essayer de deviner le DN
194
+        foreach ($logins as $att) {
195
+            $dn = "$att=$login_search, $ldap_base";
196
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
197
+                return "$att=$login_search, $ldap_base";
198
+            }
199
+        }
200
+    }
201
+
202
+    return '';
203 203
 }
204 204
 
205 205
 /**
@@ -211,40 +211,40 @@  discard block
 block discarded – undo
211 211
  * @return array
212 212
  */
213 213
 function auth_ldap_retrouver($dn, $desc = [], $serveur = '') {
214
-	// Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
214
+    // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
215 215
 
216
-	if (!$ldap = auth_ldap_connect($serveur)) {
217
-		spip_log("ldap $serveur injoignable");
216
+    if (!$ldap = auth_ldap_connect($serveur)) {
217
+        spip_log("ldap $serveur injoignable");
218 218
 
219
-		return [];
220
-	}
219
+        return [];
220
+    }
221 221
 
222
-	$ldap_link = $ldap['link'];
223
-	if (!$desc) {
224
-		$desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes'];
225
-		unset($desc['login']);
226
-	}
227
-	$result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc));
222
+    $ldap_link = $ldap['link'];
223
+    if (!$desc) {
224
+        $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes'];
225
+        unset($desc['login']);
226
+    }
227
+    $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc));
228 228
 
229
-	if (!$result) {
230
-		return [];
231
-	}
229
+    if (!$result) {
230
+        return [];
231
+    }
232 232
 
233
-	// Recuperer les donnees du premier (unique?) compte de l'auteur
234
-	$val = @ldap_get_entries($ldap_link, $result);
235
-	if (!is_array($val) || !is_array($val[0])) {
236
-		return [];
237
-	}
238
-	$val = $val[0];
233
+    // Recuperer les donnees du premier (unique?) compte de l'auteur
234
+    $val = @ldap_get_entries($ldap_link, $result);
235
+    if (!is_array($val) || !is_array($val[0])) {
236
+        return [];
237
+    }
238
+    $val = $val[0];
239 239
 
240
-	// Convertir depuis UTF-8 (jeu de caracteres par defaut)
241
-	include_spip('inc/charsets');
240
+    // Convertir depuis UTF-8 (jeu de caracteres par defaut)
241
+    include_spip('inc/charsets');
242 242
 
243
-	foreach ($desc as $k => $v) {
244
-		$desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8');
245
-	}
243
+    foreach ($desc as $k => $v) {
244
+        $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8');
245
+    }
246 246
 
247
-	return $desc;
247
+    return $desc;
248 248
 }
249 249
 
250 250
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @return string
257 257
  */
258 258
 function auth_ldap_retrouver_login($login, $serveur = '') {
259
-	return auth_ldap_search($login, '', false, $serveur) ? $login : '';
259
+    return auth_ldap_search($login, '', false, $serveur) ? $login : '';
260 260
 }
261 261
 
262 262
 /**
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
  *   Message d'erreur si login non valide, chaîne vide sinon
277 277
  */
278 278
 function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') {
279
-	include_spip('auth/spip');
279
+    include_spip('auth/spip');
280 280
 
281
-	return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
281
+    return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
282 282
 }
283 283
 
284 284
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  *   ```
300 300
  */
301 301
 function auth_ldap_autoriser_modifier_pass($serveur = '') {
302
-	return true;
302
+    return true;
303 303
 }
304 304
 
305 305
 /**
@@ -317,22 +317,22 @@  discard block
 block discarded – undo
317 317
  *    Informe du succès ou de l'echec du changement du mot de passe
318 318
  */
319 319
 function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') {
320
-	if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
321
-		return false;
322
-	}
323
-	if (!$ldap = auth_ldap_connect($serveur)) {
324
-		return false;
325
-	}
326
-	$link = $ldap['link'];
327
-	include_spip('inc/session');
328
-	$dn = session_get('ldap_dn');
329
-	if ('' == $dn) {
330
-		return false;
331
-	}
332
-	if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
333
-		return false;
334
-	}
335
-	$encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass)));
336
-
337
-	return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]);
320
+    if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
321
+        return false;
322
+    }
323
+    if (!$ldap = auth_ldap_connect($serveur)) {
324
+        return false;
325
+    }
326
+    $link = $ldap['link'];
327
+    include_spip('inc/session');
328
+    $dn = session_get('ldap_dn');
329
+    if ('' == $dn) {
330
+        return false;
331
+    }
332
+    if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
333
+        return false;
334
+    }
335
+    $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass)));
336
+
337
+    return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]);
338 338
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
25
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
25
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
26 26
 }
27 27
 
28 28
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
  *     Description de la boucle complétée des champs
44 44
  */
45 45
 function iterateur_DATA_dist($b) {
46
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
47
-	$b->show = [
48
-		'field' => [
49
-			'cle' => 'STRING',
50
-			'valeur' => 'STRING',
51
-			'*' => 'ALL' // Champ joker *
52
-		]
53
-	];
54
-	$b->select[] = '.valeur';
55
-
56
-	return $b;
46
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
47
+    $b->show = [
48
+        'field' => [
49
+            'cle' => 'STRING',
50
+            'valeur' => 'STRING',
51
+            '*' => 'ALL' // Champ joker *
52
+        ]
53
+    ];
54
+    $b->select[] = '.valeur';
55
+
56
+    return $b;
57 57
 }
58 58
 
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * @return array
69 69
  */
70 70
 function inc_file_to_array_dist($data) {
71
-	return preg_split('/\r?\n/', $data);
71
+    return preg_split('/\r?\n/', $data);
72 72
 }
73 73
 
74 74
 /**
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
  * @return array
78 78
  */
79 79
 function inc_plugins_to_array_dist() {
80
-	include_spip('inc/plugin');
80
+    include_spip('inc/plugin');
81 81
 
82
-	return liste_chemin_plugin_actifs();
82
+    return liste_chemin_plugin_actifs();
83 83
 }
84 84
 
85 85
 /**
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
  * @return array
90 90
  */
91 91
 function inc_xml_to_array_dist($data) {
92
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
92
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
93 93
 }
94 94
 
95 95
 /**
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
  *
102 102
  */
103 103
 function inc_object_to_array($object) {
104
-	if (!is_object($object) && !is_array($object)) {
105
-		return $object;
106
-	}
107
-	if (is_object($object)) {
108
-		$object = get_object_vars($object);
109
-	}
110
-
111
-	return array_map('inc_object_to_array', $object);
104
+    if (!is_object($object) && !is_array($object)) {
105
+        return $object;
106
+    }
107
+    if (is_object($object)) {
108
+        $object = get_object_vars($object);
109
+    }
110
+
111
+    return array_map('inc_object_to_array', $object);
112 112
 }
113 113
 
114 114
 /**
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
  * @return array|bool
119 119
  */
120 120
 function inc_sql_to_array_dist($data) {
121
-	# sortir le connecteur de $data
122
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
123
-	$serveur = (string)$v[1];
124
-	$req = trim($v[2]);
125
-	if ($s = sql_query($req, $serveur)) {
126
-		$r = [];
127
-		while ($t = sql_fetch($s)) {
128
-			$r[] = $t;
129
-		}
130
-
131
-		return $r;
132
-	}
133
-
134
-	return false;
121
+    # sortir le connecteur de $data
122
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
123
+    $serveur = (string)$v[1];
124
+    $req = trim($v[2]);
125
+    if ($s = sql_query($req, $serveur)) {
126
+        $r = [];
127
+        while ($t = sql_fetch($s)) {
128
+            $r[] = $t;
129
+        }
130
+
131
+        return $r;
132
+    }
133
+
134
+    return false;
135 135
 }
136 136
 
137 137
 /**
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
  * @return array|bool
142 142
  */
143 143
 function inc_json_to_array_dist($data) {
144
-	try {
145
-		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
146
-	} catch (JsonException $e) {
147
-		$json = null;
148
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
149
-	}
150
-	return is_array($json) ? (array) $json : [];
144
+    try {
145
+        $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
146
+    } catch (JsonException $e) {
147
+        $json = null;
148
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
149
+    }
150
+    return is_array($json) ? (array) $json : [];
151 151
 }
152 152
 
153 153
 /**
@@ -157,30 +157,30 @@  discard block
 block discarded – undo
157 157
  * @return array|bool
158 158
  */
159 159
 function inc_csv_to_array_dist($data) {
160
-	include_spip('inc/csv');
161
-	[$entete, $csv] = analyse_csv($data);
162
-	array_unshift($csv, $entete);
163
-
164
-	include_spip('inc/charsets');
165
-	$i = 1;
166
-	foreach ($entete as $k => $v) {
167
-		if (trim((string) $v) == '') {
168
-			$v = 'col' . $i;
169
-		} // reperer des eventuelles cases vides
170
-		if (is_numeric($v) && $v < 0) {
171
-			$v = '__' . $v;
172
-		} // ne pas risquer d'ecraser une cle numerique
173
-		if (is_numeric($v)) {
174
-			$v = '_' . $v;
175
-		} // ne pas risquer d'ecraser une cle numerique
176
-		$v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v)));
177
-		foreach ($csv as &$item) {
178
-			$item[$v] = &$item[$k];
179
-		}
180
-		$i++;
181
-	}
182
-
183
-	return $csv;
160
+    include_spip('inc/csv');
161
+    [$entete, $csv] = analyse_csv($data);
162
+    array_unshift($csv, $entete);
163
+
164
+    include_spip('inc/charsets');
165
+    $i = 1;
166
+    foreach ($entete as $k => $v) {
167
+        if (trim((string) $v) == '') {
168
+            $v = 'col' . $i;
169
+        } // reperer des eventuelles cases vides
170
+        if (is_numeric($v) && $v < 0) {
171
+            $v = '__' . $v;
172
+        } // ne pas risquer d'ecraser une cle numerique
173
+        if (is_numeric($v)) {
174
+            $v = '_' . $v;
175
+        } // ne pas risquer d'ecraser une cle numerique
176
+        $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v)));
177
+        foreach ($csv as &$item) {
178
+            $item[$v] = &$item[$k];
179
+        }
180
+        $i++;
181
+    }
182
+
183
+    return $csv;
184 184
 }
185 185
 
186 186
 /**
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
  * @return array|bool
191 191
  */
192 192
 function inc_rss_to_array_dist($data) {
193
-	$tableau = null;
194
-	include_spip('inc/syndic');
195
-	if (is_array($rss = analyser_backend($data))) {
196
-		$tableau = $rss;
197
-	}
193
+    $tableau = null;
194
+    include_spip('inc/syndic');
195
+    if (is_array($rss = analyser_backend($data))) {
196
+        $tableau = $rss;
197
+    }
198 198
 
199
-	return $tableau;
199
+    return $tableau;
200 200
 }
201 201
 
202 202
 /**
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
  * @return array|bool
207 207
  */
208 208
 function inc_atom_to_array_dist($data) {
209
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
209
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
210 210
 
211
-	return $rss_to_array($data);
211
+    return $rss_to_array($data);
212 212
 }
213 213
 
214 214
 /**
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
  * @return array|bool
220 220
  */
221 221
 function inc_glob_to_array_dist($data) {
222
-	$a = glob(
223
-		$data,
224
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
225
-	);
222
+    $a = glob(
223
+        $data,
224
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
225
+    );
226 226
 
227
-	return $a ?: [];
227
+    return $a ?: [];
228 228
 }
229 229
 
230 230
 /**
@@ -235,14 +235,14 @@  discard block
 block discarded – undo
235 235
  * @throws Exception
236 236
  */
237 237
 function inc_yaml_to_array_dist($data) {
238
-	include_spip('inc/yaml-mini');
239
-	if (!function_exists('yaml_decode')) {
240
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
238
+    include_spip('inc/yaml-mini');
239
+    if (!function_exists('yaml_decode')) {
240
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
241 241
 
242
-		return false;
243
-	}
242
+        return false;
243
+    }
244 244
 
245
-	return yaml_decode($data);
245
+    return yaml_decode($data);
246 246
 }
247 247
 
248 248
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
  * @return array|bool
258 258
  */
259 259
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
260
-	return (array)preg_files($dir, $regexp, $limit);
260
+    return (array)preg_files($dir, $regexp, $limit);
261 261
 }
262 262
 
263 263
 /**
@@ -269,23 +269,23 @@  discard block
 block discarded – undo
269 269
  * @return array|bool
270 270
  */
271 271
 function inc_ls_to_array_dist($data) {
272
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
273
-	$a = $glob_to_array($data);
274
-	foreach ($a as &$v) {
275
-		$b = (array)@stat($v);
276
-		foreach (array_keys($b) as $k) {
277
-			if (is_numeric($k)) {
278
-				unset($b[$k]);
279
-			}
280
-		}
281
-		$b['file'] = preg_replace('`/$`', '', (string) $v) ;
282
-		$v = array_merge(
283
-			pathinfo((string) $v),
284
-			$b
285
-		);
286
-	}
287
-
288
-	return $a;
272
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
273
+    $a = $glob_to_array($data);
274
+    foreach ($a as &$v) {
275
+        $b = (array)@stat($v);
276
+        foreach (array_keys($b) as $k) {
277
+            if (is_numeric($k)) {
278
+                unset($b[$k]);
279
+            }
280
+        }
281
+        $b['file'] = preg_replace('`/$`', '', (string) $v) ;
282
+        $v = array_merge(
283
+            pathinfo((string) $v),
284
+            $b
285
+        );
286
+    }
287
+
288
+    return $a;
289 289
 }
290 290
 
291 291
 /**
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
  * @return array|bool
296 296
  */
297 297
 function XMLObjectToArray($object) {
298
-	$xml_array = [];
299
-	for ($object->rewind(); $object->valid(); $object->next()) {
300
-		if (array_key_exists($key = $object->key(), $xml_array)) {
301
-			$key .= '-' . uniqid();
302
-		}
303
-		$vars = get_object_vars($object->current());
304
-		if (isset($vars['@attributes'])) {
305
-			foreach ($vars['@attributes'] as $k => $v) {
306
-				$xml_array[$key][$k] = $v;
307
-			}
308
-		}
309
-		$xml_array[$key][] = $object->hasChildren()
310
-			? XMLObjectToArray($object->current())
311
-			: (string) $object->current();
312
-	}
313
-
314
-	return $xml_array;
298
+    $xml_array = [];
299
+    for ($object->rewind(); $object->valid(); $object->next()) {
300
+        if (array_key_exists($key = $object->key(), $xml_array)) {
301
+            $key .= '-' . uniqid();
302
+        }
303
+        $vars = get_object_vars($object->current());
304
+        if (isset($vars['@attributes'])) {
305
+            foreach ($vars['@attributes'] as $k => $v) {
306
+                $xml_array[$key][$k] = $v;
307
+            }
308
+        }
309
+        $xml_array[$key][] = $object->hasChildren()
310
+            ? XMLObjectToArray($object->current())
311
+            : (string) $object->current();
312
+    }
313
+
314
+    return $xml_array;
315 315
 }
Please login to merge, or discard this patch.
ecrire/inc/csv.php 1 patch
Indentation   +107 added lines, -107 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,117 +32,117 @@  discard block
 block discarded – undo
32 32
  **/
33 33
 function analyse_csv($t) {
34 34
 
35
-	// Quel est le séparateur ?
36
-	$virg = substr_count($t, ',');
37
-	$pvirg = substr_count($t, ';');
38
-	$tab = substr_count($t, "\t");
39
-	if ($virg > $pvirg) {
40
-		$sep = ',';
41
-		$hs = '&#44;';
42
-	} else {
43
-		$sep = ';';
44
-		$hs = '&#59;';
45
-		$virg = $pvirg;
46
-	}
47
-	// un certain nombre de tab => le séparateur est tab
48
-	if ($tab > $virg / 10) {
49
-		$sep = "\t";
50
-		$hs = "\t";
51
-	}
35
+    // Quel est le séparateur ?
36
+    $virg = substr_count($t, ',');
37
+    $pvirg = substr_count($t, ';');
38
+    $tab = substr_count($t, "\t");
39
+    if ($virg > $pvirg) {
40
+        $sep = ',';
41
+        $hs = '&#44;';
42
+    } else {
43
+        $sep = ';';
44
+        $hs = '&#59;';
45
+        $virg = $pvirg;
46
+    }
47
+    // un certain nombre de tab => le séparateur est tab
48
+    if ($tab > $virg / 10) {
49
+        $sep = "\t";
50
+        $hs = "\t";
51
+    }
52 52
 
53
-	// un separateur suivi de 3 guillemets attention !
54
-	// attention au ; ou , suceptible d'etre confondu avec un separateur
55
-	// on substitue un # et on remplacera a la fin
56
-	$t = preg_replace("/([\n$sep])\"\"\"/", '\\1"&#34#', $t);
57
-	$t = str_replace('""', '&#34#', $t);
58
-	preg_match_all('/"[^"]*"/', $t, $r);
59
-	foreach ($r[0] as $cell) {
60
-		$t = str_replace(
61
-			$cell,
62
-			str_replace(
63
-				$sep,
64
-				$hs,
65
-				str_replace(
66
-					"\n",
67
-					'``**``', // échapper les saut de lignes, on les remettra après.
68
-					substr((string) $cell, 1, -1)
69
-				)
70
-			),
71
-			$t
72
-		);
73
-	}
53
+    // un separateur suivi de 3 guillemets attention !
54
+    // attention au ; ou , suceptible d'etre confondu avec un separateur
55
+    // on substitue un # et on remplacera a la fin
56
+    $t = preg_replace("/([\n$sep])\"\"\"/", '\\1"&#34#', $t);
57
+    $t = str_replace('""', '&#34#', $t);
58
+    preg_match_all('/"[^"]*"/', $t, $r);
59
+    foreach ($r[0] as $cell) {
60
+        $t = str_replace(
61
+            $cell,
62
+            str_replace(
63
+                $sep,
64
+                $hs,
65
+                str_replace(
66
+                    "\n",
67
+                    '``**``', // échapper les saut de lignes, on les remettra après.
68
+                    substr((string) $cell, 1, -1)
69
+                )
70
+            ),
71
+            $t
72
+        );
73
+    }
74 74
 
75
-	$t = preg_replace(
76
-		'/\r?\n/',
77
-		"\n",
78
-		preg_replace('/[\r\n]+/', "\n", $t)
79
-	);
75
+    $t = preg_replace(
76
+        '/\r?\n/',
77
+        "\n",
78
+        preg_replace('/[\r\n]+/', "\n", $t)
79
+    );
80 80
 
81
-	[$entete, $corps] = explode("\n", $t, 2);
82
-	$caption = '';
83
-	// sauter la ligne de tete formee seulement de separateurs
84
-	if (substr_count($entete, $sep) === strlen($entete)) {
85
-		[$entete, $corps] = explode("\n", $corps, 2);
86
-	}
87
-	// si une seule colonne, en faire le titre
88
-	if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) {
89
-		$caption = "\n||" . $l[1] . '|';
90
-		[$entete, $corps] = explode("\n", $corps, 2);
91
-	}
92
-	// si premiere colonne vide, le raccourci doit quand meme produire <th...
93
-	if ($entete[0] == $sep) {
94
-		$entete = ' ' . $entete;
95
-	}
81
+    [$entete, $corps] = explode("\n", $t, 2);
82
+    $caption = '';
83
+    // sauter la ligne de tete formee seulement de separateurs
84
+    if (substr_count($entete, $sep) === strlen($entete)) {
85
+        [$entete, $corps] = explode("\n", $corps, 2);
86
+    }
87
+    // si une seule colonne, en faire le titre
88
+    if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) {
89
+        $caption = "\n||" . $l[1] . '|';
90
+        [$entete, $corps] = explode("\n", $corps, 2);
91
+    }
92
+    // si premiere colonne vide, le raccourci doit quand meme produire <th...
93
+    if ($entete[0] == $sep) {
94
+        $entete = ' ' . $entete;
95
+    }
96 96
 
97
-	$lignes = explode("\n", $corps);
97
+    $lignes = explode("\n", $corps);
98 98
 
99
-	// retrait des lignes vides finales
100
-	while (
101
-		$lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1])
102
-	) {
103
-		unset($lignes[count($lignes) - 1]);
104
-	}
105
-	//  calcul du  nombre de colonne a chaque ligne
106
-	$nbcols = [];
107
-	$max = $mil = substr_count($entete, $sep);
108
-	foreach ($lignes as $k => $v) {
109
-		if ($max !== ($nbcols[$k] = substr_count($v, $sep))) {
110
-			if ($max > $nbcols[$k]) {
111
-				$mil = $nbcols[$k];
112
-			} else {
113
-				$mil = $max;
114
-				$max = $nbcols[$k];
115
-			}
116
-		}
117
-	}
118
-	// Si pas le meme nombre, cadrer au nombre max
119
-	if ($mil !== $max) {
120
-		foreach ($nbcols as $k => $v) {
121
-			if ($v < $max) {
122
-				$lignes[$k] .= str_repeat($sep, $max - $v);
123
-			}
124
-		}
125
-	}
126
-	// et retirer les colonnes integralement vides
127
-	while (true) {
128
-		$nbcols = ($entete[strlen($entete) - 1] === $sep);
129
-		foreach ($lignes as $v) {
130
-			$nbcols &= ($v[strlen($v) - 1] === $sep);
131
-		}
132
-		if (!$nbcols) {
133
-			break;
134
-		}
135
-		$entete = substr($entete, 0, -1);
136
-		foreach ($lignes as $k => $v) {
137
-			$lignes[$k] = substr($v, 0, -1);
138
-		}
139
-	}
99
+    // retrait des lignes vides finales
100
+    while (
101
+        $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1])
102
+    ) {
103
+        unset($lignes[count($lignes) - 1]);
104
+    }
105
+    //  calcul du  nombre de colonne a chaque ligne
106
+    $nbcols = [];
107
+    $max = $mil = substr_count($entete, $sep);
108
+    foreach ($lignes as $k => $v) {
109
+        if ($max !== ($nbcols[$k] = substr_count($v, $sep))) {
110
+            if ($max > $nbcols[$k]) {
111
+                $mil = $nbcols[$k];
112
+            } else {
113
+                $mil = $max;
114
+                $max = $nbcols[$k];
115
+            }
116
+        }
117
+    }
118
+    // Si pas le meme nombre, cadrer au nombre max
119
+    if ($mil !== $max) {
120
+        foreach ($nbcols as $k => $v) {
121
+            if ($v < $max) {
122
+                $lignes[$k] .= str_repeat($sep, $max - $v);
123
+            }
124
+        }
125
+    }
126
+    // et retirer les colonnes integralement vides
127
+    while (true) {
128
+        $nbcols = ($entete[strlen($entete) - 1] === $sep);
129
+        foreach ($lignes as $v) {
130
+            $nbcols &= ($v[strlen($v) - 1] === $sep);
131
+        }
132
+        if (!$nbcols) {
133
+            break;
134
+        }
135
+        $entete = substr($entete, 0, -1);
136
+        foreach ($lignes as $k => $v) {
137
+            $lignes[$k] = substr($v, 0, -1);
138
+        }
139
+    }
140 140
 
141
-	foreach ($lignes as &$l) {
142
-		$l = str_replace('&#34#', '"', $l);
143
-		$l = str_replace('``**``', "\n", $l);
144
-		$l = explode($sep, $l);
145
-	}
141
+    foreach ($lignes as &$l) {
142
+        $l = str_replace('&#34#', '"', $l);
143
+        $l = str_replace('``**``', "\n", $l);
144
+        $l = explode($sep, $l);
145
+    }
146 146
 
147
-	return [explode($sep, $entete), $lignes, $caption];
147
+    return [explode($sep, $entete), $lignes, $caption];
148 148
 }
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 1 patch
Indentation   +278 added lines, -278 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,28 +38,28 @@  discard block
 block discarded – undo
38 38
  *     Tableau des champs et valeurs collectées
39 39
  */
40 40
 function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) {
41
-	$c = $set;
42
-	if (!$c) {
43
-		$c = [];
44
-		foreach ($include_list as $champ) {
45
-			// on ne collecte que les champs reellement envoyes par defaut.
46
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
47
-			$val = _request($champ);
48
-			if ($tous || $val !== null) {
49
-				$c[$champ] = $val;
50
-			}
51
-		}
52
-		// on ajoute toujours la lang en saisie possible
53
-		// meme si pas prevu au depart pour l'objet concerne
54
-		if ($l = _request('changer_lang')) {
55
-			$c['lang'] = $l;
56
-		}
57
-	}
58
-	foreach ($exclude_list as $champ) {
59
-		unset($c[$champ]);
60
-	}
61
-
62
-	return $c;
41
+    $c = $set;
42
+    if (!$c) {
43
+        $c = [];
44
+        foreach ($include_list as $champ) {
45
+            // on ne collecte que les champs reellement envoyes par defaut.
46
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
47
+            $val = _request($champ);
48
+            if ($tous || $val !== null) {
49
+                $c[$champ] = $val;
50
+            }
51
+        }
52
+        // on ajoute toujours la lang en saisie possible
53
+        // meme si pas prevu au depart pour l'objet concerne
54
+        if ($l = _request('changer_lang')) {
55
+            $c['lang'] = $l;
56
+        }
57
+    }
58
+    foreach ($exclude_list as $champ) {
59
+        unset($c[$champ]);
60
+    }
61
+
62
+    return $c;
63 63
 }
64 64
 
65 65
 /**
@@ -96,259 +96,259 @@  discard block
 block discarded – undo
96 96
  *     - chaîne : texte d'un message d'erreur
97 97
  */
98 98
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
99
-	if (!$id_objet = (int) $id_objet) {
100
-		spip_log('Erreur $id_objet non defini', 'warn');
101
-
102
-		return _T('erreur_technique_enregistrement_impossible');
103
-	}
104
-
105
-	include_spip('inc/filtres');
106
-
107
-	$table_objet = table_objet($objet, $serveur);
108
-	$spip_table_objet = table_objet_sql($objet, $serveur);
109
-	$id_table_objet = id_table_objet($objet, $serveur);
110
-	$trouver_table = charger_fonction('trouver_table', 'base');
111
-	$desc = $trouver_table($spip_table_objet, $serveur);
112
-
113
-	// Appels incomplets (sans $c)
114
-	if (!is_array($c)) {
115
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
116
-
117
-		return _T('erreur_technique_enregistrement_impossible');
118
-	}
119
-
120
-	// Securite : certaines variables ne sont jamais acceptees ici
121
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
122
-	// il faut passer par instituer_XX()
123
-	// TODO: faut-il passer ces variables interdites
124
-	// dans un fichier de description separe ?
125
-	unset($c['statut']);
126
-	unset($c['id_parent']);
127
-	unset($c['id_rubrique']);
128
-	unset($c['id_secteur']);
129
-
130
-	// Gerer les champs non vides
131
-	if (isset($options['nonvide']) && is_array($options['nonvide'])) {
132
-		foreach ($options['nonvide'] as $champ => $sinon) {
133
-			if (isset($c[$champ]) && $c[$champ] === '') {
134
-				$c[$champ] = $sinon;
135
-			}
136
-		}
137
-	}
138
-
139
-	// N'accepter que les champs qui existent dans la table
140
-	$champs = array_intersect_key($c, $desc['field']);
141
-	// et dont la valeur n'est pas null
142
-	$champs = array_filter($champs, static fn($var) => $var !== null);
143
-	// TODO: ici aussi on peut valider les contenus
144
-	// en fonction du type
145
-
146
-	// Nettoyer les valeurs
147
-	$champs = array_map('corriger_caracteres', $champs);
148
-
149
-	// On récupère l'état avant toute modification
150
-	$row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
151
-
152
-	// Envoyer aux plugins
153
-	$champs = pipeline(
154
-		'pre_edition',
155
-		[
156
-			'args' => [
157
-				'table' => $spip_table_objet, // compatibilite
158
-				'table_objet' => $table_objet,
159
-				'spip_table_objet' => $spip_table_objet,
160
-				'desc' => $desc,
161
-				'type' => $objet,
162
-				'id_objet' => $id_objet,
163
-				'data' => $options['data'] ?? null,
164
-				'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
165
-				'champs_anciens' => $row, // état du contenu avant modif
166
-				'serveur' => $serveur,
167
-				'action' => $options['action'] ?? 'modifier'
168
-			],
169
-			'data' => $champs
170
-		]
171
-	);
172
-
173
-	if (!$champs) {
174
-		return false;
175
-	}
176
-
177
-
178
-	// marquer le fait que l'objet est travaille par toto a telle date
179
-	include_spip('inc/config');
180
-	if (lire_config('articles_modif', 'non') !== 'non') {
181
-		include_spip('inc/drapeau_edition');
182
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
-	}
184
-
185
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
-	include_spip('inc/editer');
187
-	if (!isset($options['data']) || is_null($options['data'])) {
188
-		$options['data'] = &$_POST;
189
-	}
190
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
-	// et gere l'interface
193
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
-	if ($conflits) {
195
-		return _T('titre_conflit_edition');
196
-	}
197
-
198
-	if ($champs) {
199
-		// cas particulier de la langue : passer par instituer_langue_objet
200
-		if (isset($champs['lang'])) {
201
-			if ($changer_lang = $champs['lang']) {
202
-				$id_rubrique = 0;
203
-				if (isset($desc['field']['id_rubrique'])) {
204
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet);
206
-				}
207
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
-			}
210
-			// on laisse 'lang' dans $champs,
211
-			// ca permet de passer dans le pipeline post_edition et de journaliser
212
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
-			// deja pris en compte
214
-		}
215
-
216
-		// la modif peut avoir lieu
217
-
218
-		// faut-il ajouter date_modif ?
219
-		if (
220
-			!empty($options['date_modif']) && !isset($champs[$options['date_modif']])
221
-		) {
222
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
223
-		}
224
-
225
-		// allez on commit la modif
226
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur);
227
-
228
-		// on verifie si elle est bien passee
229
-		$moof = sql_fetsel(
230
-			array_keys($champs),
231
-			$spip_table_objet,
232
-			"$id_table_objet=" . (int) $id_objet,
233
-			[],
234
-			[],
235
-			'',
236
-			[],
237
-			$serveur
238
-		);
239
-		// si difference entre les champs, reperer les champs mal enregistres
240
-		if ($moof != $champs) {
241
-			$liste = [];
242
-			foreach ($moof as $k => $v) {
243
-				if (
244
-					$v !== $champs[$k]
245
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
246
-					&& (!is_numeric($v) || (int) $v !== (int) $champs[$k])
247
-					// ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
248
-					&& (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
249
-				) {
250
-					$liste[] = $k;
251
-					$conflits[$k]['post'] = $champs[$k];
252
-					$conflits[$k]['save'] = $v;
253
-
254
-					// cas specifique MySQL+emoji : si l'un est la
255
-					// conversion utf8_noplanes de l'autre alors c'est OK
256
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
257
-						include_spip('inc/charsets');
258
-						if ($v == utf8_noplanes($champs[$k])) {
259
-							array_pop($liste);
260
-						}
261
-					}
262
-				}
263
-			}
264
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
265
-			// c'est un cas exceptionnel
266
-			if ($liste !== []) {
267
-				spip_log(
268
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
269
-					'modifier.' . _LOG_CRITIQUE
270
-				);
271
-
272
-				return _T(
273
-					'erreur_technique_enregistrement_champs',
274
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
275
-				);
276
-			}
277
-		}
278
-
279
-		// Invalider les caches
280
-		if (isset($options['invalideur']) && $options['invalideur']) {
281
-			include_spip('inc/invalideur');
282
-			if (is_array($options['invalideur'])) {
283
-				array_map('suivre_invalideur', $options['invalideur']);
284
-			} else {
285
-				suivre_invalideur($options['invalideur']);
286
-			}
287
-		}
288
-
289
-		// Notifications, gestion des revisions...
290
-		// en standard, appelle |nouvelle_revision ci-dessous
291
-		pipeline(
292
-			'post_edition',
293
-			[
294
-				'args' => [
295
-					'table' => $spip_table_objet,
296
-					'table_objet' => $table_objet,
297
-					'spip_table_objet' => $spip_table_objet,
298
-					'desc' => $desc,
299
-					'type' => $objet,
300
-					'id_objet' => $id_objet,
301
-					'champs' => $options['champs'] ?? [], // [doc] kesako ?
302
-					'champs_anciens' => $row, // état du contenu avant modif
303
-					'serveur' => $serveur,
304
-					'action' => $options['action'] ?? 'modifier'
305
-				],
306
-				'data' => $champs
307
-			]
308
-		);
309
-	}
310
-
311
-	// Appeler une notification
312
-	if ($notifications = charger_fonction('notifications', 'inc')) {
313
-		$notifications(
314
-			"{$objet}_modifier",
315
-			$id_objet,
316
-			[
317
-				'champs' => $champs,
318
-			]
319
-		);
320
-		$notifications(
321
-			'objet_modifier',
322
-			$id_objet,
323
-			[
324
-				'objet' => $objet,
325
-				'id_objet' => $id_objet,
326
-				'champs' => $champs,
327
-			]
328
-		);
329
-	}
330
-
331
-	// journaliser l'affaire
332
-	// message a affiner :-)
333
-	include_spip('inc/filtres_mini');
334
-	$qui = '';
335
-	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
336
-		$qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
337
-	}
338
-	if (!empty($GLOBALS['visiteur_session']['nom'])) {
339
-		$qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
340
-	}
341
-	if ($qui == '') {
342
-		$qui = '#ip:' . $GLOBALS['ip'] . '#';
343
-	}
344
-	journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode(
345
-		'+',
346
-		array_diff(array_keys($champs), ['date_modif'])
347
-	) . ')'), [
348
-		'faire' => 'modifier',
349
-		'quoi' => $objet,
350
-		'id' => $id_objet
351
-	]);
352
-
353
-	return '';
99
+    if (!$id_objet = (int) $id_objet) {
100
+        spip_log('Erreur $id_objet non defini', 'warn');
101
+
102
+        return _T('erreur_technique_enregistrement_impossible');
103
+    }
104
+
105
+    include_spip('inc/filtres');
106
+
107
+    $table_objet = table_objet($objet, $serveur);
108
+    $spip_table_objet = table_objet_sql($objet, $serveur);
109
+    $id_table_objet = id_table_objet($objet, $serveur);
110
+    $trouver_table = charger_fonction('trouver_table', 'base');
111
+    $desc = $trouver_table($spip_table_objet, $serveur);
112
+
113
+    // Appels incomplets (sans $c)
114
+    if (!is_array($c)) {
115
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
116
+
117
+        return _T('erreur_technique_enregistrement_impossible');
118
+    }
119
+
120
+    // Securite : certaines variables ne sont jamais acceptees ici
121
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
122
+    // il faut passer par instituer_XX()
123
+    // TODO: faut-il passer ces variables interdites
124
+    // dans un fichier de description separe ?
125
+    unset($c['statut']);
126
+    unset($c['id_parent']);
127
+    unset($c['id_rubrique']);
128
+    unset($c['id_secteur']);
129
+
130
+    // Gerer les champs non vides
131
+    if (isset($options['nonvide']) && is_array($options['nonvide'])) {
132
+        foreach ($options['nonvide'] as $champ => $sinon) {
133
+            if (isset($c[$champ]) && $c[$champ] === '') {
134
+                $c[$champ] = $sinon;
135
+            }
136
+        }
137
+    }
138
+
139
+    // N'accepter que les champs qui existent dans la table
140
+    $champs = array_intersect_key($c, $desc['field']);
141
+    // et dont la valeur n'est pas null
142
+    $champs = array_filter($champs, static fn($var) => $var !== null);
143
+    // TODO: ici aussi on peut valider les contenus
144
+    // en fonction du type
145
+
146
+    // Nettoyer les valeurs
147
+    $champs = array_map('corriger_caracteres', $champs);
148
+
149
+    // On récupère l'état avant toute modification
150
+    $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
151
+
152
+    // Envoyer aux plugins
153
+    $champs = pipeline(
154
+        'pre_edition',
155
+        [
156
+            'args' => [
157
+                'table' => $spip_table_objet, // compatibilite
158
+                'table_objet' => $table_objet,
159
+                'spip_table_objet' => $spip_table_objet,
160
+                'desc' => $desc,
161
+                'type' => $objet,
162
+                'id_objet' => $id_objet,
163
+                'data' => $options['data'] ?? null,
164
+                'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
165
+                'champs_anciens' => $row, // état du contenu avant modif
166
+                'serveur' => $serveur,
167
+                'action' => $options['action'] ?? 'modifier'
168
+            ],
169
+            'data' => $champs
170
+        ]
171
+    );
172
+
173
+    if (!$champs) {
174
+        return false;
175
+    }
176
+
177
+
178
+    // marquer le fait que l'objet est travaille par toto a telle date
179
+    include_spip('inc/config');
180
+    if (lire_config('articles_modif', 'non') !== 'non') {
181
+        include_spip('inc/drapeau_edition');
182
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
+    }
184
+
185
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
+    include_spip('inc/editer');
187
+    if (!isset($options['data']) || is_null($options['data'])) {
188
+        $options['data'] = &$_POST;
189
+    }
190
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
+    // et gere l'interface
193
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
+    if ($conflits) {
195
+        return _T('titre_conflit_edition');
196
+    }
197
+
198
+    if ($champs) {
199
+        // cas particulier de la langue : passer par instituer_langue_objet
200
+        if (isset($champs['lang'])) {
201
+            if ($changer_lang = $champs['lang']) {
202
+                $id_rubrique = 0;
203
+                if (isset($desc['field']['id_rubrique'])) {
204
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet);
206
+                }
207
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
+            }
210
+            // on laisse 'lang' dans $champs,
211
+            // ca permet de passer dans le pipeline post_edition et de journaliser
212
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
+            // deja pris en compte
214
+        }
215
+
216
+        // la modif peut avoir lieu
217
+
218
+        // faut-il ajouter date_modif ?
219
+        if (
220
+            !empty($options['date_modif']) && !isset($champs[$options['date_modif']])
221
+        ) {
222
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
223
+        }
224
+
225
+        // allez on commit la modif
226
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur);
227
+
228
+        // on verifie si elle est bien passee
229
+        $moof = sql_fetsel(
230
+            array_keys($champs),
231
+            $spip_table_objet,
232
+            "$id_table_objet=" . (int) $id_objet,
233
+            [],
234
+            [],
235
+            '',
236
+            [],
237
+            $serveur
238
+        );
239
+        // si difference entre les champs, reperer les champs mal enregistres
240
+        if ($moof != $champs) {
241
+            $liste = [];
242
+            foreach ($moof as $k => $v) {
243
+                if (
244
+                    $v !== $champs[$k]
245
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
246
+                    && (!is_numeric($v) || (int) $v !== (int) $champs[$k])
247
+                    // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
248
+                    && (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
249
+                ) {
250
+                    $liste[] = $k;
251
+                    $conflits[$k]['post'] = $champs[$k];
252
+                    $conflits[$k]['save'] = $v;
253
+
254
+                    // cas specifique MySQL+emoji : si l'un est la
255
+                    // conversion utf8_noplanes de l'autre alors c'est OK
256
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
257
+                        include_spip('inc/charsets');
258
+                        if ($v == utf8_noplanes($champs[$k])) {
259
+                            array_pop($liste);
260
+                        }
261
+                    }
262
+                }
263
+            }
264
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
265
+            // c'est un cas exceptionnel
266
+            if ($liste !== []) {
267
+                spip_log(
268
+                    "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
269
+                    'modifier.' . _LOG_CRITIQUE
270
+                );
271
+
272
+                return _T(
273
+                    'erreur_technique_enregistrement_champs',
274
+                    ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
275
+                );
276
+            }
277
+        }
278
+
279
+        // Invalider les caches
280
+        if (isset($options['invalideur']) && $options['invalideur']) {
281
+            include_spip('inc/invalideur');
282
+            if (is_array($options['invalideur'])) {
283
+                array_map('suivre_invalideur', $options['invalideur']);
284
+            } else {
285
+                suivre_invalideur($options['invalideur']);
286
+            }
287
+        }
288
+
289
+        // Notifications, gestion des revisions...
290
+        // en standard, appelle |nouvelle_revision ci-dessous
291
+        pipeline(
292
+            'post_edition',
293
+            [
294
+                'args' => [
295
+                    'table' => $spip_table_objet,
296
+                    'table_objet' => $table_objet,
297
+                    'spip_table_objet' => $spip_table_objet,
298
+                    'desc' => $desc,
299
+                    'type' => $objet,
300
+                    'id_objet' => $id_objet,
301
+                    'champs' => $options['champs'] ?? [], // [doc] kesako ?
302
+                    'champs_anciens' => $row, // état du contenu avant modif
303
+                    'serveur' => $serveur,
304
+                    'action' => $options['action'] ?? 'modifier'
305
+                ],
306
+                'data' => $champs
307
+            ]
308
+        );
309
+    }
310
+
311
+    // Appeler une notification
312
+    if ($notifications = charger_fonction('notifications', 'inc')) {
313
+        $notifications(
314
+            "{$objet}_modifier",
315
+            $id_objet,
316
+            [
317
+                'champs' => $champs,
318
+            ]
319
+        );
320
+        $notifications(
321
+            'objet_modifier',
322
+            $id_objet,
323
+            [
324
+                'objet' => $objet,
325
+                'id_objet' => $id_objet,
326
+                'champs' => $champs,
327
+            ]
328
+        );
329
+    }
330
+
331
+    // journaliser l'affaire
332
+    // message a affiner :-)
333
+    include_spip('inc/filtres_mini');
334
+    $qui = '';
335
+    if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
336
+        $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
337
+    }
338
+    if (!empty($GLOBALS['visiteur_session']['nom'])) {
339
+        $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
340
+    }
341
+    if ($qui == '') {
342
+        $qui = '#ip:' . $GLOBALS['ip'] . '#';
343
+    }
344
+    journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode(
345
+        '+',
346
+        array_diff(array_keys($champs), ['date_modif'])
347
+    ) . ')'), [
348
+        'faire' => 'modifier',
349
+        'quoi' => $objet,
350
+        'id' => $id_objet
351
+    ]);
352
+
353
+    return '';
354 354
 }
Please login to merge, or discard this patch.