Completed
Push — master ( a07606...4c3c71 )
by cam
02:01
created
ecrire/xml/valider.php 2 patches
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -23,333 +23,333 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 class ValidateurXML {
25 25
 
26
-	// https://code.spip.net/@validerElement
27
-	public function validerElement($phraseur, $name, $attrs) {
28
-		if (!($p = isset($this->dtc->elements[$name]))) {
29
-			if ($p = strpos($name, ':')) {
30
-				$name = substr($name, $p + 1);
31
-				$p = isset($this->dtc->elements[$name]);
32
-			}
33
-			if (!$p) {
34
-				coordonnees_erreur($this, " <b>$name</b>&nbsp;: "
35
-					. _T('zxml_inconnu_balise'));
36
-
37
-				return;
38
-			}
39
-		}
40
-		// controler les filles illegitimes, ca suffit
41
-		$depth = $this->depth;
42
-		$ouvrant = $this->ouvrant;
43
-		#spip_log("trouve $name apres " . $ouvrant[$depth]);
44
-		if (isset($ouvrant[$depth])) {
45
-			if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) {
46
-				$pere = $r[1];
47
-				#spip_log("pere $pere");
48
-				if (isset($this->dtc->elements[$pere])) {
49
-					$fils = $this->dtc->elements[$pere];
50
-					#spip_log("rejeton $name fils " . @join(',',$fils));
51
-					if (!($p = @in_array($name, $fils))) {
52
-						if ($p = strpos($name, ':')) {
53
-							$p = substr($name, $p + 1);
54
-							$p = @in_array($p, $fils);
55
-						}
56
-					}
57
-					if (!$p) {
58
-						$bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]);
59
-						coordonnees_erreur($this, " <b>$name</b> "
60
-							. _T('zxml_non_fils')
61
-							. ' <b>'
62
-							. $pere
63
-							. '</b>'
64
-							. (!$bons_peres ? ''
65
-								: ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
66
-					} elseif ($this->dtc->regles[$pere][0] == '/') {
67
-						$frat = substr($depth, 2);
68
-						if (!isset($this->fratrie[$frat])) {
69
-							$this->fratrie[$frat] = '';
70
-						}
71
-						$this->fratrie[$frat] .= "$name ";
72
-					}
73
-				}
74
-			}
75
-		}
76
-		// Init de la suite des balises a memoriser si regle difficile
77
-		if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') {
78
-			$this->fratrie[$depth] = '';
79
-		}
80
-		if (isset($this->dtc->attributs[$name])) {
81
-			foreach ($this->dtc->attributs[$name] as $n => $v) {
82
-				if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) {
83
-					coordonnees_erreur($this, " <b>$n</b>"
84
-						. '&nbsp;:&nbsp;'
85
-						. _T('zxml_obligatoire_attribut')
86
-						. " <b>$name</b>");
87
-				}
88
-			}
89
-		}
90
-	}
91
-
92
-	// https://code.spip.net/@validerAttribut
93
-	public function validerAttribut($phraseur, $name, $val, $bal) {
94
-		// Si la balise est inconnue, eviter d'insister
95
-		if (!isset($this->dtc->attributs[$bal])) {
96
-			return;
97
-		}
98
-
99
-		$a = $this->dtc->attributs[$bal];
100
-		if (!isset($a[$name])) {
101
-			$bons = join(', ', array_keys($a));
102
-			if ($bons) {
103
-				$bons = " title=' " .
104
-					_T('zxml_connus_attributs') .
105
-					'&nbsp;: ' .
106
-					$bons .
107
-					"'";
108
-			}
109
-			$bons .= " style='font-weight: bold'";
110
-			coordonnees_erreur($this, " <b>$name</b> "
111
-				. _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
112
-				. " <a$bons>$bal</a> ("
113
-				. _T('zxml_survoler')
114
-				. ')');
115
-		} else {
116
-			$type = $a[$name][0];
117
-			if (!preg_match('/^\w+$/', $type)) {
118
-				$this->valider_motif($phraseur, $name, $val, $bal, $type);
119
-			} else {
120
-				if (method_exists($this, $f = 'validerAttribut_' . $type)) {
121
-					$this->$f($phraseur, $name, $val, $bal);
122
-				}
123
-			}
124
-			#		else spip_log("$type type d'attribut inconnu");
125
-		}
126
-	}
127
-
128
-	public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) {
129
-		$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN);
130
-	}
131
-
132
-	public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) {
133
-		$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS);
134
-	}
135
-
136
-	// https://code.spip.net/@validerAttribut_ID
137
-	public function validerAttribut_ID($phraseur, $name, $val, $bal) {
138
-		if (isset($this->ids[$val])) {
139
-			list($l, $c) = $this->ids[$val];
140
-			coordonnees_erreur($this, " <p><b>$val</b> "
141
-				. _T('zxml_valeur_attribut')
142
-				. " <b>$name</b> "
143
-				. _T('zxml_de')
144
-				. " <b>$bal</b> "
145
-				. _T('zxml_vu')
146
-				. " (L$l,C$c)");
147
-		} else {
148
-			$this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID);
149
-			$this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
150
-		}
151
-	}
152
-
153
-	// https://code.spip.net/@validerAttribut_IDREF
154
-	public function validerAttribut_IDREF($phraseur, $name, $val, $bal) {
155
-		$this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
156
-	}
157
-
158
-	// https://code.spip.net/@validerAttribut_IDREFS
159
-	public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) {
160
-		$this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
161
-	}
162
-
163
-	// https://code.spip.net/@valider_motif
164
-	public function valider_motif($phraseur, $name, $val, $bal, $motif) {
165
-		if (!preg_match($motif, $val)) {
166
-			coordonnees_erreur($this, "<b>$val</b> "
167
-				. _T('zxml_valeur_attribut')
168
-				. " <b>$name</b> "
169
-				. _T('zxml_de')
170
-				. " <b>$bal</b> "
171
-				. _T('zxml_non_conforme')
172
-				. '</p><p>'
173
-				. '<b>' . $motif . '</b>');
174
-		}
175
-	}
176
-
177
-	// https://code.spip.net/@valider_idref
178
-	public function valider_idref($nom, $ligne, $col) {
179
-		if (!isset($this->ids[$nom])) {
180
-			$this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col];
181
-		}
182
-	}
183
-
184
-	// https://code.spip.net/@valider_passe2
185
-	public function valider_passe2() {
186
-		if (!$this->err) {
187
-			foreach ($this->idrefs as $idref) {
188
-				list($nom, $ligne, $col) = $idref;
189
-				$this->valider_idref($nom, $ligne, $col);
190
-			}
191
-			foreach ($this->idrefss as $idref) {
192
-				list($noms, $ligne, $col) = $idref;
193
-				foreach (preg_split('/\s+/', $noms) as $nom) {
194
-					$this->valider_idref($nom, $ligne, $col);
195
-				}
196
-			}
197
-		}
198
-	}
199
-
200
-	// https://code.spip.net/@debutElement
201
-	public function debutElement($phraseur, $name, $attrs) {
202
-		if ($this->dtc->elements) {
203
-			$this->validerElement($phraseur, $name, $attrs);
204
-		}
205
-
206
-		if ($f = $this->process['debut']) {
207
-			$f($this, $name, $attrs);
208
-		}
209
-		$depth = $this->depth;
210
-		$this->debuts[$depth] = strlen($this->res);
211
-		foreach ($attrs as $k => $v) {
212
-			$this->validerAttribut($phraseur, $k, $v, $name);
213
-		}
214
-	}
215
-
216
-	// https://code.spip.net/@finElement
217
-	public function finElement($phraseur, $name) {
218
-		$depth = $this->depth;
219
-		$contenu = $this->contenu;
220
-
221
-		$n = strlen($this->res);
222
-		$c = strlen(trim($contenu[$depth]));
223
-		$k = $this->debuts[$depth];
224
-
225
-		$regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false;
226
-		$vide = ($regle == 'EMPTY');
227
-		// controler que les balises devant etre vides le sont
228
-		if ($vide) {
229
-			if ($n <> ($k + $c)) {
230
-				coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
231
-			}
232
-			// pour les regles PCDATA ou iteration de disjonction, tout est fait
233
-		} elseif ($regle and ($regle != '*')) {
234
-			if ($regle == '+') {
235
-				// iteration de disjonction non vide: 1 balise au -
236
-				if ($n == $k) {
237
-					coordonnees_erreur($this, "<p>\n<b>$name</b> "
238
-						. _T('zxml_vide_balise'));
239
-				}
240
-			} else {
241
-				$f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null;
242
-				if (is_null($f) or !preg_match($regle, $f)) {
243
-					coordonnees_erreur(
244
-						$this,
245
-						" <p>\n<b>$name</b> "
246
-						. _T('zxml_succession_fils_incorrecte')
247
-						. '&nbsp;: <b>'
248
-						. $f
249
-						. '</b>'
250
-					);
251
-				}
252
-			}
253
-		}
254
-		if ($f = $this->process['fin']) {
255
-			$f($this, $name, $vide);
256
-		}
257
-	}
258
-
259
-	// https://code.spip.net/@textElement
260
-	public function textElement($phraseur, $data) {
261
-		if (trim($data)) {
262
-			$d = $this->depth;
263
-			$d = $this->ouvrant[$d];
264
-			preg_match('/^\s*(\S+)/', $d, $m);
265
-			if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
266
-				coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> '
267
-					. _T('zxml_nonvide_balise')); // message a affiner
268
-			}
269
-		}
270
-		if ($f = $this->process['text']) {
271
-			$f($this, $data);
272
-		}
273
-	}
274
-
275
-	public function piElement($phraseur, $target, $data) {
276
-		if ($f = $this->process['pi']) {
277
-			$f($this, $target, $data);
278
-		}
279
-	}
280
-
281
-	// Denonciation des entitees XML inconnues
282
-	// Pour contourner le bug de conception de SAX qui ne signale pas si elles
283
-	// sont dans un attribut, les  entites les plus frequentes ont ete
284
-	// transcodees au prealable  (sauf & < > " que SAX traite correctement).
285
-	// On ne les verra donc pas passer a cette etape, contrairement a ce que
286
-	// le source de la page laisse legitimement supposer.
287
-
288
-	// https://code.spip.net/@defautElement
289
-	public function defaultElement($phraseur, $data) {
290
-		if (
291
-			!preg_match('/^<!--/', $data)
292
-			and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER))
293
-		) {
294
-			foreach ($r as $m) {
295
-				list($t, $e) = $m;
296
-				if (!isset($this->dtc->entites[$e])) {
297
-					coordonnees_erreur($this, " <b>$e</b> "
298
-						. _T('zxml_inconnu_entite')
299
-						. ' ');
300
-				}
301
-			}
302
-		}
303
-		if (isset($this->process['default']) and ($f = $this->process['default'])) {
304
-			$f($this, $data);
305
-		}
306
-	}
307
-
308
-	// https://code.spip.net/@phraserTout
309
-	public function phraserTout($phraseur, $data) {
310
-		xml_parsestring($this, $data);
311
-
312
-		if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
313
-			$this->err[] = ['DOCTYPE ?', 0, 0];
314
-		} else {
315
-			$this->valider_passe2($this);
316
-		}
317
-	}
318
-
319
-	/**
320
-	 * Constructeur
321
-	 *
322
-	 * @param array $process ?
323
-	 **/
324
-	public function __construct($process = []) {
325
-		if (is_array($process)) {
326
-			$this->process = $process;
327
-		}
328
-	}
329
-
330
-	public $ids = [];
331
-	public $idrefs = [];
332
-	public $idrefss = [];
333
-	public $debuts = [];
334
-	public $fratrie = [];
335
-
336
-	public $dtc = null;
337
-	public $sax = null;
338
-	public $depth = '';
339
-	public $entete = '';
340
-	public $page = '';
341
-	public $res = '';
342
-	public $err = [];
343
-	public $contenu = [];
344
-	public $ouvrant = [];
345
-	public $reperes = [];
346
-	public $process = [
347
-		'debut' => 'xml_debutElement',
348
-		'fin' => 'xml_finElement',
349
-		'text' => 'xml_textElement',
350
-		'pi' => 'xml_piElement',
351
-		'default' => 'xml_defaultElement'
352
-	];
26
+    // https://code.spip.net/@validerElement
27
+    public function validerElement($phraseur, $name, $attrs) {
28
+        if (!($p = isset($this->dtc->elements[$name]))) {
29
+            if ($p = strpos($name, ':')) {
30
+                $name = substr($name, $p + 1);
31
+                $p = isset($this->dtc->elements[$name]);
32
+            }
33
+            if (!$p) {
34
+                coordonnees_erreur($this, " <b>$name</b>&nbsp;: "
35
+                    . _T('zxml_inconnu_balise'));
36
+
37
+                return;
38
+            }
39
+        }
40
+        // controler les filles illegitimes, ca suffit
41
+        $depth = $this->depth;
42
+        $ouvrant = $this->ouvrant;
43
+        #spip_log("trouve $name apres " . $ouvrant[$depth]);
44
+        if (isset($ouvrant[$depth])) {
45
+            if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) {
46
+                $pere = $r[1];
47
+                #spip_log("pere $pere");
48
+                if (isset($this->dtc->elements[$pere])) {
49
+                    $fils = $this->dtc->elements[$pere];
50
+                    #spip_log("rejeton $name fils " . @join(',',$fils));
51
+                    if (!($p = @in_array($name, $fils))) {
52
+                        if ($p = strpos($name, ':')) {
53
+                            $p = substr($name, $p + 1);
54
+                            $p = @in_array($p, $fils);
55
+                        }
56
+                    }
57
+                    if (!$p) {
58
+                        $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]);
59
+                        coordonnees_erreur($this, " <b>$name</b> "
60
+                            . _T('zxml_non_fils')
61
+                            . ' <b>'
62
+                            . $pere
63
+                            . '</b>'
64
+                            . (!$bons_peres ? ''
65
+                                : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
66
+                    } elseif ($this->dtc->regles[$pere][0] == '/') {
67
+                        $frat = substr($depth, 2);
68
+                        if (!isset($this->fratrie[$frat])) {
69
+                            $this->fratrie[$frat] = '';
70
+                        }
71
+                        $this->fratrie[$frat] .= "$name ";
72
+                    }
73
+                }
74
+            }
75
+        }
76
+        // Init de la suite des balises a memoriser si regle difficile
77
+        if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') {
78
+            $this->fratrie[$depth] = '';
79
+        }
80
+        if (isset($this->dtc->attributs[$name])) {
81
+            foreach ($this->dtc->attributs[$name] as $n => $v) {
82
+                if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) {
83
+                    coordonnees_erreur($this, " <b>$n</b>"
84
+                        . '&nbsp;:&nbsp;'
85
+                        . _T('zxml_obligatoire_attribut')
86
+                        . " <b>$name</b>");
87
+                }
88
+            }
89
+        }
90
+    }
91
+
92
+    // https://code.spip.net/@validerAttribut
93
+    public function validerAttribut($phraseur, $name, $val, $bal) {
94
+        // Si la balise est inconnue, eviter d'insister
95
+        if (!isset($this->dtc->attributs[$bal])) {
96
+            return;
97
+        }
98
+
99
+        $a = $this->dtc->attributs[$bal];
100
+        if (!isset($a[$name])) {
101
+            $bons = join(', ', array_keys($a));
102
+            if ($bons) {
103
+                $bons = " title=' " .
104
+                    _T('zxml_connus_attributs') .
105
+                    '&nbsp;: ' .
106
+                    $bons .
107
+                    "'";
108
+            }
109
+            $bons .= " style='font-weight: bold'";
110
+            coordonnees_erreur($this, " <b>$name</b> "
111
+                . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
112
+                . " <a$bons>$bal</a> ("
113
+                . _T('zxml_survoler')
114
+                . ')');
115
+        } else {
116
+            $type = $a[$name][0];
117
+            if (!preg_match('/^\w+$/', $type)) {
118
+                $this->valider_motif($phraseur, $name, $val, $bal, $type);
119
+            } else {
120
+                if (method_exists($this, $f = 'validerAttribut_' . $type)) {
121
+                    $this->$f($phraseur, $name, $val, $bal);
122
+                }
123
+            }
124
+            #		else spip_log("$type type d'attribut inconnu");
125
+        }
126
+    }
127
+
128
+    public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) {
129
+        $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN);
130
+    }
131
+
132
+    public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) {
133
+        $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS);
134
+    }
135
+
136
+    // https://code.spip.net/@validerAttribut_ID
137
+    public function validerAttribut_ID($phraseur, $name, $val, $bal) {
138
+        if (isset($this->ids[$val])) {
139
+            list($l, $c) = $this->ids[$val];
140
+            coordonnees_erreur($this, " <p><b>$val</b> "
141
+                . _T('zxml_valeur_attribut')
142
+                . " <b>$name</b> "
143
+                . _T('zxml_de')
144
+                . " <b>$bal</b> "
145
+                . _T('zxml_vu')
146
+                . " (L$l,C$c)");
147
+        } else {
148
+            $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID);
149
+            $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
150
+        }
151
+    }
152
+
153
+    // https://code.spip.net/@validerAttribut_IDREF
154
+    public function validerAttribut_IDREF($phraseur, $name, $val, $bal) {
155
+        $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
156
+    }
157
+
158
+    // https://code.spip.net/@validerAttribut_IDREFS
159
+    public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) {
160
+        $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)];
161
+    }
162
+
163
+    // https://code.spip.net/@valider_motif
164
+    public function valider_motif($phraseur, $name, $val, $bal, $motif) {
165
+        if (!preg_match($motif, $val)) {
166
+            coordonnees_erreur($this, "<b>$val</b> "
167
+                . _T('zxml_valeur_attribut')
168
+                . " <b>$name</b> "
169
+                . _T('zxml_de')
170
+                . " <b>$bal</b> "
171
+                . _T('zxml_non_conforme')
172
+                . '</p><p>'
173
+                . '<b>' . $motif . '</b>');
174
+        }
175
+    }
176
+
177
+    // https://code.spip.net/@valider_idref
178
+    public function valider_idref($nom, $ligne, $col) {
179
+        if (!isset($this->ids[$nom])) {
180
+            $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col];
181
+        }
182
+    }
183
+
184
+    // https://code.spip.net/@valider_passe2
185
+    public function valider_passe2() {
186
+        if (!$this->err) {
187
+            foreach ($this->idrefs as $idref) {
188
+                list($nom, $ligne, $col) = $idref;
189
+                $this->valider_idref($nom, $ligne, $col);
190
+            }
191
+            foreach ($this->idrefss as $idref) {
192
+                list($noms, $ligne, $col) = $idref;
193
+                foreach (preg_split('/\s+/', $noms) as $nom) {
194
+                    $this->valider_idref($nom, $ligne, $col);
195
+                }
196
+            }
197
+        }
198
+    }
199
+
200
+    // https://code.spip.net/@debutElement
201
+    public function debutElement($phraseur, $name, $attrs) {
202
+        if ($this->dtc->elements) {
203
+            $this->validerElement($phraseur, $name, $attrs);
204
+        }
205
+
206
+        if ($f = $this->process['debut']) {
207
+            $f($this, $name, $attrs);
208
+        }
209
+        $depth = $this->depth;
210
+        $this->debuts[$depth] = strlen($this->res);
211
+        foreach ($attrs as $k => $v) {
212
+            $this->validerAttribut($phraseur, $k, $v, $name);
213
+        }
214
+    }
215
+
216
+    // https://code.spip.net/@finElement
217
+    public function finElement($phraseur, $name) {
218
+        $depth = $this->depth;
219
+        $contenu = $this->contenu;
220
+
221
+        $n = strlen($this->res);
222
+        $c = strlen(trim($contenu[$depth]));
223
+        $k = $this->debuts[$depth];
224
+
225
+        $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false;
226
+        $vide = ($regle == 'EMPTY');
227
+        // controler que les balises devant etre vides le sont
228
+        if ($vide) {
229
+            if ($n <> ($k + $c)) {
230
+                coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
231
+            }
232
+            // pour les regles PCDATA ou iteration de disjonction, tout est fait
233
+        } elseif ($regle and ($regle != '*')) {
234
+            if ($regle == '+') {
235
+                // iteration de disjonction non vide: 1 balise au -
236
+                if ($n == $k) {
237
+                    coordonnees_erreur($this, "<p>\n<b>$name</b> "
238
+                        . _T('zxml_vide_balise'));
239
+                }
240
+            } else {
241
+                $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null;
242
+                if (is_null($f) or !preg_match($regle, $f)) {
243
+                    coordonnees_erreur(
244
+                        $this,
245
+                        " <p>\n<b>$name</b> "
246
+                        . _T('zxml_succession_fils_incorrecte')
247
+                        . '&nbsp;: <b>'
248
+                        . $f
249
+                        . '</b>'
250
+                    );
251
+                }
252
+            }
253
+        }
254
+        if ($f = $this->process['fin']) {
255
+            $f($this, $name, $vide);
256
+        }
257
+    }
258
+
259
+    // https://code.spip.net/@textElement
260
+    public function textElement($phraseur, $data) {
261
+        if (trim($data)) {
262
+            $d = $this->depth;
263
+            $d = $this->ouvrant[$d];
264
+            preg_match('/^\s*(\S+)/', $d, $m);
265
+            if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
266
+                coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> '
267
+                    . _T('zxml_nonvide_balise')); // message a affiner
268
+            }
269
+        }
270
+        if ($f = $this->process['text']) {
271
+            $f($this, $data);
272
+        }
273
+    }
274
+
275
+    public function piElement($phraseur, $target, $data) {
276
+        if ($f = $this->process['pi']) {
277
+            $f($this, $target, $data);
278
+        }
279
+    }
280
+
281
+    // Denonciation des entitees XML inconnues
282
+    // Pour contourner le bug de conception de SAX qui ne signale pas si elles
283
+    // sont dans un attribut, les  entites les plus frequentes ont ete
284
+    // transcodees au prealable  (sauf & < > " que SAX traite correctement).
285
+    // On ne les verra donc pas passer a cette etape, contrairement a ce que
286
+    // le source de la page laisse legitimement supposer.
287
+
288
+    // https://code.spip.net/@defautElement
289
+    public function defaultElement($phraseur, $data) {
290
+        if (
291
+            !preg_match('/^<!--/', $data)
292
+            and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER))
293
+        ) {
294
+            foreach ($r as $m) {
295
+                list($t, $e) = $m;
296
+                if (!isset($this->dtc->entites[$e])) {
297
+                    coordonnees_erreur($this, " <b>$e</b> "
298
+                        . _T('zxml_inconnu_entite')
299
+                        . ' ');
300
+                }
301
+            }
302
+        }
303
+        if (isset($this->process['default']) and ($f = $this->process['default'])) {
304
+            $f($this, $data);
305
+        }
306
+    }
307
+
308
+    // https://code.spip.net/@phraserTout
309
+    public function phraserTout($phraseur, $data) {
310
+        xml_parsestring($this, $data);
311
+
312
+        if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
313
+            $this->err[] = ['DOCTYPE ?', 0, 0];
314
+        } else {
315
+            $this->valider_passe2($this);
316
+        }
317
+    }
318
+
319
+    /**
320
+     * Constructeur
321
+     *
322
+     * @param array $process ?
323
+     **/
324
+    public function __construct($process = []) {
325
+        if (is_array($process)) {
326
+            $this->process = $process;
327
+        }
328
+    }
329
+
330
+    public $ids = [];
331
+    public $idrefs = [];
332
+    public $idrefss = [];
333
+    public $debuts = [];
334
+    public $fratrie = [];
335
+
336
+    public $dtc = null;
337
+    public $sax = null;
338
+    public $depth = '';
339
+    public $entete = '';
340
+    public $page = '';
341
+    public $res = '';
342
+    public $err = [];
343
+    public $contenu = [];
344
+    public $ouvrant = [];
345
+    public $reperes = [];
346
+    public $process = [
347
+        'debut' => 'xml_debutElement',
348
+        'fin' => 'xml_finElement',
349
+        'text' => 'xml_textElement',
350
+        'pi' => 'xml_piElement',
351
+        'default' => 'xml_defaultElement'
352
+    ];
353 353
 }
354 354
 
355 355
 
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
  *
360 360
  **/
361 361
 function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) {
362
-	$f = new ValidateurXML($process);
363
-	$sax = charger_fonction('sax', 'xml');
362
+    $f = new ValidateurXML($process);
363
+    $sax = charger_fonction('sax', 'xml');
364 364
 
365
-	return $sax($page, $apply, $f, $doctype, $charset);
365
+    return $sax($page, $apply, $f, $doctype, $charset);
366 366
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 							. $pere
63 63
 							. '</b>'
64 64
 							. (!$bons_peres ? ''
65
-								: ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>')));
65
+								: ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>')));
66 66
 					} elseif ($this->dtc->regles[$pere][0] == '/') {
67 67
 						$frat = substr($depth, 2);
68 68
 						if (!isset($this->fratrie[$frat])) {
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 		if (!isset($a[$name])) {
101 101
 			$bons = join(', ', array_keys($a));
102 102
 			if ($bons) {
103
-				$bons = " title=' " .
104
-					_T('zxml_connus_attributs') .
105
-					'&nbsp;: ' .
106
-					$bons .
103
+				$bons = " title=' ".
104
+					_T('zxml_connus_attributs').
105
+					'&nbsp;: '.
106
+					$bons.
107 107
 					"'";
108 108
 			}
109 109
 			$bons .= " style='font-weight: bold'";
110 110
 			coordonnees_erreur($this, " <b>$name</b> "
111
-				. _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de')
111
+				. _T('zxml_inconnu_attribut').' '._T('zxml_de')
112 112
 				. " <a$bons>$bal</a> ("
113 113
 				. _T('zxml_survoler')
114 114
 				. ')');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 			if (!preg_match('/^\w+$/', $type)) {
118 118
 				$this->valider_motif($phraseur, $name, $val, $bal, $type);
119 119
 			} else {
120
-				if (method_exists($this, $f = 'validerAttribut_' . $type)) {
120
+				if (method_exists($this, $f = 'validerAttribut_'.$type)) {
121 121
 					$this->$f($phraseur, $name, $val, $bal);
122 122
 				}
123 123
 			}
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
 				. " <b>$bal</b> "
171 171
 				. _T('zxml_non_conforme')
172 172
 				. '</p><p>'
173
-				. '<b>' . $motif . '</b>');
173
+				. '<b>'.$motif.'</b>');
174 174
 		}
175 175
 	}
176 176
 
177 177
 	// https://code.spip.net/@valider_idref
178 178
 	public function valider_idref($nom, $ligne, $col) {
179 179
 		if (!isset($this->ids[$nom])) {
180
-			$this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col];
180
+			$this->err[] = [" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col];
181 181
 		}
182 182
 	}
183 183
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		// controler que les balises devant etre vides le sont
228 228
 		if ($vide) {
229 229
 			if ($n <> ($k + $c)) {
230
-				coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise'));
230
+				coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise'));
231 231
 			}
232 232
 			// pour les regles PCDATA ou iteration de disjonction, tout est fait
233 233
 		} elseif ($regle and ($regle != '*')) {
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 			$d = $this->ouvrant[$d];
264 264
 			preg_match('/^\s*(\S+)/', $d, $m);
265 265
 			if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) {
266
-				coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> '
266
+				coordonnees_erreur($this, ' <p><b>'.$m[1].'</b> '
267 267
 					. _T('zxml_nonvide_balise')); // message a affiner
268 268
 			}
269 269
 		}
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	public function phraserTout($phraseur, $data) {
310 310
 		xml_parsestring($this, $data);
311 311
 
312
-		if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) {
312
+		if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) {
313 313
 			$this->err[] = ['DOCTYPE ?', 0, 0];
314 314
 		} else {
315 315
 			$this->valider_passe2($this);
Please login to merge, or discard this patch.
ecrire/xml/analyser_dtd.php 2 patches
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('xml/interfaces');
18 18
 
19 19
 // https://code.spip.net/@charger_dtd
20 20
 function charger_dtd($grammaire, $avail, $rotlvl) {
21
-	static $dtd = []; # cache bien utile pour le validateur en boucle
22
-
23
-	if (isset($dtd[$grammaire])) {
24
-		return $dtd[$grammaire];
25
-	}
26
-
27
-	if ($avail == 'SYSTEM') {
28
-		$grammaire = find_in_path($grammaire);
29
-	}
30
-
31
-	$file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz';
32
-
33
-	if (lire_fichier($file, $r)) {
34
-		if (!$grammaire) {
35
-			return [];
36
-		}
37
-		if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) {
38
-			$r = false;
39
-		}
40
-	}
41
-
42
-	if ($r) {
43
-		$dtc = unserialize($r);
44
-	} else {
45
-		spip_timer('dtd');
46
-		$dtc = new DTC();
47
-		// L'analyseur retourne un booleen de reussite et modifie $dtc.
48
-		// Retourner vide en cas d'echec
49
-		if (!analyser_dtd($grammaire, $avail, $dtc)) {
50
-			$dtc = [];
51
-		} else {
52
-			// tri final pour presenter les suggestions de corrections
53
-			foreach ($dtc->peres as $k => $v) {
54
-				asort($v);
55
-				$dtc->peres[$k] = $v;
56
-			}
57
-
58
-			spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites');
59
-			#	$r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit;
60
-			ecrire_fichier($file, serialize($dtc), true);
61
-		}
62
-	}
63
-	$dtd[$grammaire] = $dtc;
64
-
65
-	return $dtc;
21
+    static $dtd = []; # cache bien utile pour le validateur en boucle
22
+
23
+    if (isset($dtd[$grammaire])) {
24
+        return $dtd[$grammaire];
25
+    }
26
+
27
+    if ($avail == 'SYSTEM') {
28
+        $grammaire = find_in_path($grammaire);
29
+    }
30
+
31
+    $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz';
32
+
33
+    if (lire_fichier($file, $r)) {
34
+        if (!$grammaire) {
35
+            return [];
36
+        }
37
+        if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) {
38
+            $r = false;
39
+        }
40
+    }
41
+
42
+    if ($r) {
43
+        $dtc = unserialize($r);
44
+    } else {
45
+        spip_timer('dtd');
46
+        $dtc = new DTC();
47
+        // L'analyseur retourne un booleen de reussite et modifie $dtc.
48
+        // Retourner vide en cas d'echec
49
+        if (!analyser_dtd($grammaire, $avail, $dtc)) {
50
+            $dtc = [];
51
+        } else {
52
+            // tri final pour presenter les suggestions de corrections
53
+            foreach ($dtc->peres as $k => $v) {
54
+                asort($v);
55
+                $dtc->peres[$k] = $v;
56
+            }
57
+
58
+            spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites');
59
+            #	$r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit;
60
+            ecrire_fichier($file, serialize($dtc), true);
61
+        }
62
+    }
63
+    $dtd[$grammaire] = $dtc;
64
+
65
+    return $dtc;
66 66
 }
67 67
 
68 68
 // Compiler une regle de production en une Regexp qu'on appliquera sur la
@@ -75,157 +75,157 @@  discard block
 block discarded – undo
75 75
 
76 76
 // https://code.spip.net/@compilerRegle
77 77
 function compilerRegle($val) {
78
-	$x = str_replace(
79
-		'()',
80
-		'',
81
-		preg_replace(
82
-			'/\s*,\s*/',
83
-			'',
84
-			preg_replace(
85
-				'/(\w+)\s*/',
86
-				'(?:\1 )',
87
-				preg_replace(
88
-					'/\s*\)/',
89
-					')',
90
-					preg_replace(
91
-						'/\s*([(+*|?])\s*/',
92
-						'\1',
93
-						preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)
94
-					)
95
-				)
96
-			)
97
-		)
98
-	);
99
-
100
-	return $x;
78
+    $x = str_replace(
79
+        '()',
80
+        '',
81
+        preg_replace(
82
+            '/\s*,\s*/',
83
+            '',
84
+            preg_replace(
85
+                '/(\w+)\s*/',
86
+                '(?:\1 )',
87
+                preg_replace(
88
+                    '/\s*\)/',
89
+                    ')',
90
+                    preg_replace(
91
+                        '/\s*([(+*|?])\s*/',
92
+                        '\1',
93
+                        preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)
94
+                    )
95
+                )
96
+            )
97
+        )
98
+    );
99
+
100
+    return $x;
101 101
 }
102 102
 
103 103
 
104 104
 // https://code.spip.net/@analyser_dtd
105 105
 function analyser_dtd($loc, $avail, &$dtc) {
106
-	// creer le repertoire de cache si ce n'est fait
107
-	// (utile aussi pour le resultat de la compil)
108
-	$file = sous_repertoire(_DIR_CACHE_XML);
109
-	// si DTD locale, ignorer ce repertoire pour le moment
110
-	if ($avail == 'SYSTEM') {
111
-		$file = $loc;
112
-		if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
113
-			$file = substr($file, strlen(_DIR_RACINE));
114
-		}
115
-		$file = find_in_path($file);
116
-	} else {
117
-		$file .= preg_replace('/[^\w.]/', '_', $loc);
118
-	}
119
-
120
-	$dtd = '';
121
-	if (@is_readable($file)) {
122
-		lire_fichier($file, $dtd);
123
-	} else {
124
-		if ($avail == 'PUBLIC') {
125
-			include_spip('inc/distant');
126
-			$dtd = recuperer_url($loc);
127
-			$dtd = trim($dtd['page'] ?? '');
128
-			if ($dtd) {
129
-				ecrire_fichier($file, $dtd, true);
130
-			}
131
-		}
132
-	}
133
-
134
-	$dtd = ltrim($dtd);
135
-	if (!$dtd) {
136
-		spip_log("DTD '$loc' ($file) inaccessible");
137
-
138
-		return false;
139
-	} else {
140
-		spip_log("analyse de la DTD $loc ");
141
-	}
142
-
143
-	while ($dtd) {
144
-		if ($dtd[0] != '<') {
145
-			$r = analyser_dtd_lexeme($dtd, $dtc, $loc);
146
-		} elseif ($dtd[1] != '!') {
147
-			$r = analyser_dtd_pi($dtd, $dtc, $loc);
148
-		} elseif ($dtd[2] == '[') {
149
-			$r = analyser_dtd_data($dtd, $dtc, $loc);
150
-		} else {
151
-			switch ($dtd[3]) {
152
-				case '%':
153
-					$r = analyser_dtd_data($dtd, $dtc, $loc);
154
-					break;
155
-				case 'T':
156
-					$r = analyser_dtd_attlist($dtd, $dtc, $loc);
157
-					break;
158
-				case 'L':
159
-					$r = analyser_dtd_element($dtd, $dtc, $loc);
160
-					break;
161
-				case 'N':
162
-					$r = analyser_dtd_entity($dtd, $dtc, $loc);
163
-					break;
164
-				case 'O':
165
-					$r = analyser_dtd_notation($dtd, $dtc, $loc);
166
-					break;
167
-				case '-':
168
-					$r = analyser_dtd_comment($dtd, $dtc, $loc);
169
-					break;
170
-				default:
171
-					$r = -1;
172
-			}
173
-		}
174
-		if (!is_string($r)) {
175
-			spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . '.....');
176
-
177
-			return false;
178
-		}
179
-		$dtd = $r;
180
-	}
181
-
182
-	return true;
106
+    // creer le repertoire de cache si ce n'est fait
107
+    // (utile aussi pour le resultat de la compil)
108
+    $file = sous_repertoire(_DIR_CACHE_XML);
109
+    // si DTD locale, ignorer ce repertoire pour le moment
110
+    if ($avail == 'SYSTEM') {
111
+        $file = $loc;
112
+        if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
113
+            $file = substr($file, strlen(_DIR_RACINE));
114
+        }
115
+        $file = find_in_path($file);
116
+    } else {
117
+        $file .= preg_replace('/[^\w.]/', '_', $loc);
118
+    }
119
+
120
+    $dtd = '';
121
+    if (@is_readable($file)) {
122
+        lire_fichier($file, $dtd);
123
+    } else {
124
+        if ($avail == 'PUBLIC') {
125
+            include_spip('inc/distant');
126
+            $dtd = recuperer_url($loc);
127
+            $dtd = trim($dtd['page'] ?? '');
128
+            if ($dtd) {
129
+                ecrire_fichier($file, $dtd, true);
130
+            }
131
+        }
132
+    }
133
+
134
+    $dtd = ltrim($dtd);
135
+    if (!$dtd) {
136
+        spip_log("DTD '$loc' ($file) inaccessible");
137
+
138
+        return false;
139
+    } else {
140
+        spip_log("analyse de la DTD $loc ");
141
+    }
142
+
143
+    while ($dtd) {
144
+        if ($dtd[0] != '<') {
145
+            $r = analyser_dtd_lexeme($dtd, $dtc, $loc);
146
+        } elseif ($dtd[1] != '!') {
147
+            $r = analyser_dtd_pi($dtd, $dtc, $loc);
148
+        } elseif ($dtd[2] == '[') {
149
+            $r = analyser_dtd_data($dtd, $dtc, $loc);
150
+        } else {
151
+            switch ($dtd[3]) {
152
+                case '%':
153
+                    $r = analyser_dtd_data($dtd, $dtc, $loc);
154
+                    break;
155
+                case 'T':
156
+                    $r = analyser_dtd_attlist($dtd, $dtc, $loc);
157
+                    break;
158
+                case 'L':
159
+                    $r = analyser_dtd_element($dtd, $dtc, $loc);
160
+                    break;
161
+                case 'N':
162
+                    $r = analyser_dtd_entity($dtd, $dtc, $loc);
163
+                    break;
164
+                case 'O':
165
+                    $r = analyser_dtd_notation($dtd, $dtc, $loc);
166
+                    break;
167
+                case '-':
168
+                    $r = analyser_dtd_comment($dtd, $dtc, $loc);
169
+                    break;
170
+                default:
171
+                    $r = -1;
172
+            }
173
+        }
174
+        if (!is_string($r)) {
175
+            spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . '.....');
176
+
177
+            return false;
178
+        }
179
+        $dtd = $r;
180
+    }
181
+
182
+    return true;
183 183
 }
184 184
 
185 185
 // https://code.spip.net/@analyser_dtd_comment
186 186
 function analyser_dtd_comment($dtd, &$dtc, $grammaire) {
187
-	// ejecter les commentaires, surtout quand ils contiennent du code.
188
-	// Option /s car sur plusieurs lignes parfois
187
+    // ejecter les commentaires, surtout quand ils contiennent du code.
188
+    // Option /s car sur plusieurs lignes parfois
189 189
 
190
-	if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
191
-		return -6;
192
-	}
190
+    if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
191
+        return -6;
192
+    }
193 193
 
194
-	return $m[1];
194
+    return $m[1];
195 195
 }
196 196
 
197 197
 // https://code.spip.net/@analyser_dtd_pi
198 198
 function analyser_dtd_pi($dtd, &$dtc, $grammaire) {
199
-	if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
200
-		return -10;
201
-	}
199
+    if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
200
+        return -10;
201
+    }
202 202
 
203
-	return $m[1];
203
+    return $m[1];
204 204
 }
205 205
 
206 206
 // https://code.spip.net/@analyser_dtd_lexeme
207 207
 function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) {
208 208
 
209
-	if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
210
-		return -9;
211
-	}
212
-
213
-	list(, $s) = $m;
214
-	$n = $dtc->macros[$s];
215
-
216
-	if (is_array($n)) {
217
-		// en cas d'inclusion, l'espace de nom est le meme
218
-		// mais gaffe aux DTD dont l'URL est relative a l'engloblante
219
-		if (
220
-			($n[0] == 'PUBLIC')
221
-			and !tester_url_absolue($n[1])
222
-		) {
223
-			$n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
224
-		}
225
-		analyser_dtd($n[1], $n[0], $dtc);
226
-	}
227
-
228
-	return ltrim(substr($dtd, strlen($m[0])));
209
+    if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
210
+        return -9;
211
+    }
212
+
213
+    list(, $s) = $m;
214
+    $n = $dtc->macros[$s];
215
+
216
+    if (is_array($n)) {
217
+        // en cas d'inclusion, l'espace de nom est le meme
218
+        // mais gaffe aux DTD dont l'URL est relative a l'engloblante
219
+        if (
220
+            ($n[0] == 'PUBLIC')
221
+            and !tester_url_absolue($n[1])
222
+        ) {
223
+            $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
224
+        }
225
+        analyser_dtd($n[1], $n[0], $dtc);
226
+    }
227
+
228
+    return ltrim(substr($dtd, strlen($m[0])));
229 229
 }
230 230
 
231 231
 // il faudrait gerer plus proprement les niveaux d'inclusion:
@@ -234,85 +234,85 @@  discard block
 block discarded – undo
234 234
 // https://code.spip.net/@analyser_dtd_data
235 235
 function analyser_dtd_data($dtd, &$dtc, $grammaire) {
236 236
 
237
-	if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
238
-		return -11;
239
-	}
240
-	if (
241
-		!preg_match(
242
-			'/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s',
243
-			$m[2],
244
-			$r
245
-		)
246
-	) {
247
-		return -12;
248
-	}
249
-
250
-	if ($dtc->macros[$m[1]] == 'INCLUDE') {
251
-		$retour = $r[1] . substr($m[2], strlen($r[0]));
252
-	} else {
253
-		$retour = substr($m[2], strlen($r[0]));
254
-	}
255
-
256
-	return $retour;
237
+    if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
238
+        return -11;
239
+    }
240
+    if (
241
+        !preg_match(
242
+            '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s',
243
+            $m[2],
244
+            $r
245
+        )
246
+    ) {
247
+        return -12;
248
+    }
249
+
250
+    if ($dtc->macros[$m[1]] == 'INCLUDE') {
251
+        $retour = $r[1] . substr($m[2], strlen($r[0]));
252
+    } else {
253
+        $retour = substr($m[2], strlen($r[0]));
254
+    }
255
+
256
+    return $retour;
257 257
 }
258 258
 
259 259
 // https://code.spip.net/@analyser_dtd_notation
260 260
 function analyser_dtd_notation($dtd, &$dtc, $grammaire) {
261
-	if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
262
-		return -8;
263
-	}
264
-	spip_log('analyser_dtd_notation a ecrire');
261
+    if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
262
+        return -8;
263
+    }
264
+    spip_log('analyser_dtd_notation a ecrire');
265 265
 
266
-	return $m[1];
266
+    return $m[1];
267 267
 }
268 268
 
269 269
 // https://code.spip.net/@analyser_dtd_entity
270 270
 function analyser_dtd_entity($dtd, &$dtc, $grammaire) {
271
-	if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
272
-		return -2;
273
-	}
274
-
275
-	list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m;
276
-
277
-	if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
278
-		return $dtd;
279
-	}
280
-	if (isset($dtc->entites[$nom])) {
281
-		spip_log("redefinition de l'entite $nom");
282
-	}
283
-	if ($k6) {
284
-		return $k6 . $dtd;
285
-	} // cas du synonyme complet
286
-	$val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
287
-
288
-	// cas particulier double evaluation: 'PUBLIC "..." "...."'
289
-	if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
290
-		list($t, $type, $val, $q, $alt) = $r;
291
-	}
292
-
293
-	if (!$term) {
294
-		$dtc->entites[$nom] = $val;
295
-	} elseif (!$type) {
296
-		$dtc->macros[$nom] = $val;
297
-	} else {
298
-		if (($type == 'SYSTEM') and !$alt) {
299
-			$alt = $val;
300
-		}
301
-		if (!$alt) {
302
-			$dtc->macros[$nom] = $val;
303
-		} else {
304
-			if (
305
-				($type == 'PUBLIC')
306
-				and (strpos($alt, '/') === false)
307
-			) {
308
-				$alt = preg_replace(',/[^/]+$,', '/', $grammaire)
309
-					. $alt;
310
-			}
311
-			$dtc->macros[$nom] = [$type, $alt];
312
-		}
313
-	}
314
-
315
-	return $dtd;
271
+    if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
272
+        return -2;
273
+    }
274
+
275
+    list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m;
276
+
277
+    if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
278
+        return $dtd;
279
+    }
280
+    if (isset($dtc->entites[$nom])) {
281
+        spip_log("redefinition de l'entite $nom");
282
+    }
283
+    if ($k6) {
284
+        return $k6 . $dtd;
285
+    } // cas du synonyme complet
286
+    $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
287
+
288
+    // cas particulier double evaluation: 'PUBLIC "..." "...."'
289
+    if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
290
+        list($t, $type, $val, $q, $alt) = $r;
291
+    }
292
+
293
+    if (!$term) {
294
+        $dtc->entites[$nom] = $val;
295
+    } elseif (!$type) {
296
+        $dtc->macros[$nom] = $val;
297
+    } else {
298
+        if (($type == 'SYSTEM') and !$alt) {
299
+            $alt = $val;
300
+        }
301
+        if (!$alt) {
302
+            $dtc->macros[$nom] = $val;
303
+        } else {
304
+            if (
305
+                ($type == 'PUBLIC')
306
+                and (strpos($alt, '/') === false)
307
+            ) {
308
+                $alt = preg_replace(',/[^/]+$,', '/', $grammaire)
309
+                    . $alt;
310
+            }
311
+            $dtc->macros[$nom] = [$type, $alt];
312
+        }
313
+    }
314
+
315
+    return $dtd;
316 316
 }
317 317
 
318 318
 // Dresser le tableau des filles potentielles de l'element
@@ -326,77 +326,77 @@  discard block
 block discarded – undo
326 326
 
327 327
 // https://code.spip.net/@analyser_dtd_element
328 328
 function analyser_dtd_element($dtd, &$dtc, $grammaire) {
329
-	if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
330
-		return -3;
331
-	}
332
-
333
-	list(, $nom, $contenu, $dtd) = $m;
334
-	$nom = expanserEntite($nom, $dtc->macros);
335
-
336
-	if (isset($dtc->elements[$nom])) {
337
-		spip_log("redefinition de l'element $nom dans la DTD");
338
-
339
-		return -4;
340
-	}
341
-	$filles = [];
342
-	$contenu = expanserEntite($contenu, $dtc->macros);
343
-	$val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
344
-	if ($val == '(?:EMPTY )') {
345
-		$dtc->regles[$nom] = 'EMPTY';
346
-	} elseif ($val == '(?:ANY )') {
347
-		$dtc->regles[$nom] = 'ANY';
348
-	} else {
349
-		$last = substr($val, -1);
350
-		if (
351
-			preg_match('/ \w/', $val)
352
-			or (!empty($last) and strpos('*+?', $last) === false)
353
-		) {
354
-			$dtc->regles[$nom] = "/^$val$/";
355
-		} else {
356
-			$dtc->regles[$nom] = $last;
357
-		}
358
-		$filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
359
-
360
-		foreach ($filles as $k) {
361
-			if (!isset($dtc->peres[$k])) {
362
-				$dtc->peres[$k] = [];
363
-			}
364
-			if (!in_array($nom, $dtc->peres[$k])) {
365
-				$dtc->peres[$k][] = $nom;
366
-			}
367
-		}
368
-	}
369
-	$dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
370
-	$dtc->elements[$nom] = $filles;
371
-
372
-	return $dtd;
329
+    if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
330
+        return -3;
331
+    }
332
+
333
+    list(, $nom, $contenu, $dtd) = $m;
334
+    $nom = expanserEntite($nom, $dtc->macros);
335
+
336
+    if (isset($dtc->elements[$nom])) {
337
+        spip_log("redefinition de l'element $nom dans la DTD");
338
+
339
+        return -4;
340
+    }
341
+    $filles = [];
342
+    $contenu = expanserEntite($contenu, $dtc->macros);
343
+    $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
344
+    if ($val == '(?:EMPTY )') {
345
+        $dtc->regles[$nom] = 'EMPTY';
346
+    } elseif ($val == '(?:ANY )') {
347
+        $dtc->regles[$nom] = 'ANY';
348
+    } else {
349
+        $last = substr($val, -1);
350
+        if (
351
+            preg_match('/ \w/', $val)
352
+            or (!empty($last) and strpos('*+?', $last) === false)
353
+        ) {
354
+            $dtc->regles[$nom] = "/^$val$/";
355
+        } else {
356
+            $dtc->regles[$nom] = $last;
357
+        }
358
+        $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
359
+
360
+        foreach ($filles as $k) {
361
+            if (!isset($dtc->peres[$k])) {
362
+                $dtc->peres[$k] = [];
363
+            }
364
+            if (!in_array($nom, $dtc->peres[$k])) {
365
+                $dtc->peres[$k][] = $nom;
366
+            }
367
+        }
368
+    }
369
+    $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
370
+    $dtc->elements[$nom] = $filles;
371
+
372
+    return $dtd;
373 373
 }
374 374
 
375 375
 
376 376
 // https://code.spip.net/@analyser_dtd_attlist
377 377
 function analyser_dtd_attlist($dtd, &$dtc, $grammaire) {
378
-	if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
379
-		return -5;
380
-	}
381
-
382
-	list(, $nom, $val, $dtd) = $m;
383
-	$nom = expanserEntite($nom, $dtc->macros);
384
-	$val = expanserEntite($val, $dtc->macros);
385
-	if (!isset($dtc->attributs[$nom])) {
386
-		$dtc->attributs[$nom] = [];
387
-	}
388
-
389
-	if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
390
-		foreach ($r2 as $m2) {
391
-			$v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
392
-				: ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
393
-			$m21 = expanserEntite($m2[1], $dtc->macros);
394
-			$m25 = expanserEntite($m2[5], $dtc->macros);
395
-			$dtc->attributs[$nom][$m21] = [$v, $m25];
396
-		}
397
-	}
398
-
399
-	return $dtd;
378
+    if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
379
+        return -5;
380
+    }
381
+
382
+    list(, $nom, $val, $dtd) = $m;
383
+    $nom = expanserEntite($nom, $dtc->macros);
384
+    $val = expanserEntite($val, $dtc->macros);
385
+    if (!isset($dtc->attributs[$nom])) {
386
+        $dtc->attributs[$nom] = [];
387
+    }
388
+
389
+    if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
390
+        foreach ($r2 as $m2) {
391
+            $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
392
+                : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
393
+            $m21 = expanserEntite($m2[1], $dtc->macros);
394
+            $m25 = expanserEntite($m2[5], $dtc->macros);
395
+            $dtc->attributs[$nom][$m21] = [$v, $m25];
396
+        }
397
+    }
398
+
399
+    return $dtd;
400 400
 }
401 401
 
402 402
 
@@ -412,26 +412,26 @@  discard block
 block discarded – undo
412 412
  * @return string|array
413 413
  **/
414 414
 function expanserEntite($val, $macros = []) {
415
-	static $vu = [];
416
-	if (!is_string($val)) {
417
-		return $vu;
418
-	}
419
-
420
-	if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
421
-		foreach ($r as $m) {
422
-			$ent = $m[1];
423
-			// il peut valoir ""
424
-			if (!isset($macros[$ent])) {
425
-				spip_log("Entite $ent inconnu");
426
-			} else {
427
-				if (!isset($vu[$ent])) {
428
-					$vu[$ent] = 0;
429
-				}
430
-				++$vu[$ent];
431
-				$val = str_replace($m[0], $macros[$ent], $val);
432
-			}
433
-		}
434
-	}
435
-
436
-	return trim(preg_replace('/\s+/', ' ', $val));
415
+    static $vu = [];
416
+    if (!is_string($val)) {
417
+        return $vu;
418
+    }
419
+
420
+    if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
421
+        foreach ($r as $m) {
422
+            $ent = $m[1];
423
+            // il peut valoir ""
424
+            if (!isset($macros[$ent])) {
425
+                spip_log("Entite $ent inconnu");
426
+            } else {
427
+                if (!isset($vu[$ent])) {
428
+                    $vu[$ent] = 0;
429
+                }
430
+                ++$vu[$ent];
431
+                $val = str_replace($m[0], $macros[$ent], $val);
432
+            }
433
+        }
434
+    }
435
+
436
+    return trim(preg_replace('/\s+/', ' ', $val));
437 437
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$grammaire = find_in_path($grammaire);
29 29
 	}
30 30
 
31
-	$file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz';
31
+	$file = _DIR_CACHE_XML.preg_replace('/[^\w.]/', '_', $rotlvl).'.gz';
32 32
 
33 33
 	if (lire_fichier($file, $r)) {
34 34
 		if (!$grammaire) {
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 				$dtc->peres[$k] = $v;
56 56
 			}
57 57
 
58
-			spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites');
58
+			spip_log("Analyser DTD $avail $grammaire (".spip_timer('dtd').') '.count($dtc->macros).' macros, '.count($dtc->elements).' elements, '.count($dtc->attributs)." listes d'attributs, ".count($dtc->entites).' entites');
59 59
 			#	$r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit;
60 60
 			ecrire_fichier($file, serialize($dtc), true);
61 61
 		}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			}
173 173
 		}
174 174
 		if (!is_string($r)) {
175
-			spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . '.....');
175
+			spip_log("erreur $r dans la DTD  ".substr($dtd, 0, 80).'.....');
176 176
 
177 177
 			return false;
178 178
 		}
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 			($n[0] == 'PUBLIC')
221 221
 			and !tester_url_absolue($n[1])
222 222
 		) {
223
-			$n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
223
+			$n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1).$n[1];
224 224
 		}
225 225
 		analyser_dtd($n[1], $n[0], $dtc);
226 226
 	}
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	}
249 249
 
250 250
 	if ($dtc->macros[$m[1]] == 'INCLUDE') {
251
-		$retour = $r[1] . substr($m[2], strlen($r[0]));
251
+		$retour = $r[1].substr($m[2], strlen($r[0]));
252 252
 	} else {
253 253
 		$retour = substr($m[2], strlen($r[0]));
254 254
 	}
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		spip_log("redefinition de l'entite $nom");
282 282
 	}
283 283
 	if ($k6) {
284
-		return $k6 . $dtd;
284
+		return $k6.$dtd;
285 285
 	} // cas du synonyme complet
286 286
 	$val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
287 287
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
390 390
 		foreach ($r2 as $m2) {
391 391
 			$v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
392
-				: ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
392
+				: ('/^'.preg_replace('/\s+/', '', $m2[2]).'$/');
393 393
 			$m21 = expanserEntite($m2[1], $dtc->macros);
394 394
 			$m25 = expanserEntite($m2[5], $dtc->macros);
395 395
 			$dtc->attributs[$nom][$m21] = [$v, $m25];
Please login to merge, or discard this patch.
ecrire/xml/indenter.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -11,61 +11,61 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 class IndenteurXML {
18 18
 
19
-	// https://code.spip.net/@debutElement
20
-	public function debutElement($phraseur, $name, $attrs) {
21
-		xml_debutElement($this, $name, $attrs);
22
-	}
19
+    // https://code.spip.net/@debutElement
20
+    public function debutElement($phraseur, $name, $attrs) {
21
+        xml_debutElement($this, $name, $attrs);
22
+    }
23 23
 
24
-	// https://code.spip.net/@finElement
25
-	public function finElement($phraseur, $name) {
26
-		xml_finElement($this, $name);
27
-	}
24
+    // https://code.spip.net/@finElement
25
+    public function finElement($phraseur, $name) {
26
+        xml_finElement($this, $name);
27
+    }
28 28
 
29
-	// https://code.spip.net/@textElement
30
-	public function textElement($phraseur, $data) {
31
-		xml_textElement($this, $data);
32
-	}
29
+    // https://code.spip.net/@textElement
30
+    public function textElement($phraseur, $data) {
31
+        xml_textElement($this, $data);
32
+    }
33 33
 
34
-	public function piElement($phraseur, $target, $data) {
35
-		xml_PiElement($this, $target, $data);
36
-	}
34
+    public function piElement($phraseur, $target, $data) {
35
+        xml_PiElement($this, $target, $data);
36
+    }
37 37
 
38
-	// https://code.spip.net/@defautElement
39
-	public function defaultElement($phraseur, $data) {
40
-		xml_defaultElement($this, $data);
41
-	}
38
+    // https://code.spip.net/@defautElement
39
+    public function defaultElement($phraseur, $data) {
40
+        xml_defaultElement($this, $data);
41
+    }
42 42
 
43
-	// https://code.spip.net/@phraserTout
44
-	public function phraserTout($phraseur, $data) {
45
-		xml_parsestring($this, $data);
46
-	}
43
+    // https://code.spip.net/@phraserTout
44
+    public function phraserTout($phraseur, $data) {
45
+        xml_parsestring($this, $data);
46
+    }
47 47
 
48
-	public $depth = '';
49
-	public $res = '';
50
-	public $err = [];
51
-	public $contenu = [];
52
-	public $ouvrant = [];
53
-	public $reperes = [];
54
-	public $entete = '';
55
-	public $page = '';
56
-	public $dtc = null;
57
-	public $sax = null;
48
+    public $depth = '';
49
+    public $res = '';
50
+    public $err = [];
51
+    public $contenu = [];
52
+    public $ouvrant = [];
53
+    public $reperes = [];
54
+    public $entete = '';
55
+    public $page = '';
56
+    public $dtc = null;
57
+    public $sax = null;
58 58
 }
59 59
 
60 60
 // https://code.spip.net/@xml_indenter_dist
61 61
 function xml_indenter_dist($page, $apply = false) {
62
-	$sax = charger_fonction('sax', 'xml');
63
-	$f = new IndenteurXML();
64
-	$sax($page, $apply, $f);
65
-	if (!$f->err) {
66
-		return $f->entete . $f->res;
67
-	}
68
-	spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation');
62
+    $sax = charger_fonction('sax', 'xml');
63
+    $f = new IndenteurXML();
64
+    $sax($page, $apply, $f);
65
+    if (!$f->err) {
66
+        return $f->entete . $f->res;
67
+    }
68
+    spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation');
69 69
 
70
-	return $f->entete . $f->page;
70
+    return $f->entete . $f->page;
71 71
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@
 block discarded – undo
63 63
 	$f = new IndenteurXML();
64 64
 	$sax($page, $apply, $f);
65 65
 	if (!$f->err) {
66
-		return $f->entete . $f->res;
66
+		return $f->entete.$f->res;
67 67
 	}
68
-	spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation');
68
+	spip_log('indentation impossible '.count($f->err).' erreurs de validation');
69 69
 
70
-	return $f->entete . $f->page;
70
+	return $f->entete.$f->page;
71 71
 }
Please login to merge, or discard this patch.
ecrire/xml/sax.php 2 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/charsets');
@@ -24,229 +24,229 @@  discard block
 block discarded – undo
24 24
  * @return string
25 25
  */
26 26
 function xml_entites_html($texte) {
27
-	if (
28
-		!is_string($texte) or !$texte
29
-		or strpbrk($texte, "&\"'<>") == false
30
-	) {
31
-		return $texte;
32
-	}
33
-
34
-	if (!function_exists('spip_htmlspecialchars')) {
35
-		include_spip('inc/filtres_mini');
36
-	}
37
-	$texte = spip_htmlspecialchars($texte, ENT_QUOTES);
38
-
39
-	return $texte;
27
+    if (
28
+        !is_string($texte) or !$texte
29
+        or strpbrk($texte, "&\"'<>") == false
30
+    ) {
31
+        return $texte;
32
+    }
33
+
34
+    if (!function_exists('spip_htmlspecialchars')) {
35
+        include_spip('inc/filtres_mini');
36
+    }
37
+    $texte = spip_htmlspecialchars($texte, ENT_QUOTES);
38
+
39
+    return $texte;
40 40
 }
41 41
 
42 42
 // https://code.spip.net/@xml_debutElement
43 43
 function xml_debutElement($phraseur, $name, $attrs) {
44
-	$depth = $phraseur->depth;
45
-
46
-	$t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
47
-	// espace initial signifie: deja integree au resultat
48
-	if ($t[0] != ' ') {
49
-		$phraseur->res .= '<' . $t . '>';
50
-		$phraseur->ouvrant[$depth] = ' ' . $t;
51
-	}
52
-	$t = $phraseur->contenu[$depth];
53
-	// n'indenter que s'il y a un separateur avant
54
-	$phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
55
-	$phraseur->contenu[$depth] = '';
56
-	$att = '';
57
-	$sep = ' ';
58
-	foreach ($attrs as $k => $v) {
59
-		$delim = strpos($v, "'") === false ? "'" : '"';
60
-		$val = xml_entites_html($v);
61
-		$att .= $sep . $k . '=' . $delim
62
-			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
63
-			. $delim;
64
-		$sep = "\n $depth";
65
-	}
66
-	$phraseur->depth .= '  ';
67
-	$phraseur->contenu[$phraseur->depth] = '';
68
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
69
-	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
44
+    $depth = $phraseur->depth;
45
+
46
+    $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
47
+    // espace initial signifie: deja integree au resultat
48
+    if ($t[0] != ' ') {
49
+        $phraseur->res .= '<' . $t . '>';
50
+        $phraseur->ouvrant[$depth] = ' ' . $t;
51
+    }
52
+    $t = $phraseur->contenu[$depth];
53
+    // n'indenter que s'il y a un separateur avant
54
+    $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
55
+    $phraseur->contenu[$depth] = '';
56
+    $att = '';
57
+    $sep = ' ';
58
+    foreach ($attrs as $k => $v) {
59
+        $delim = strpos($v, "'") === false ? "'" : '"';
60
+        $val = xml_entites_html($v);
61
+        $att .= $sep . $k . '=' . $delim
62
+            . ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
63
+            . $delim;
64
+        $sep = "\n $depth";
65
+    }
66
+    $phraseur->depth .= '  ';
67
+    $phraseur->contenu[$phraseur->depth] = '';
68
+    $phraseur->ouvrant[$phraseur->depth] = $name . $att;
69
+    $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
70 70
 }
71 71
 
72 72
 // https://code.spip.net/@xml_finElement
73 73
 function xml_finElement($phraseur, $name, $fusion_bal = false) {
74
-	$ouv = $phraseur->ouvrant[$phraseur->depth];
75
-
76
-	if ($ouv[0] != ' ') {
77
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
78
-	} else {
79
-		$ouv = '';
80
-	}
81
-	$t = $phraseur->contenu[$phraseur->depth];
82
-	$phraseur->depth = substr($phraseur->depth, 2);
83
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
84
-
85
-	// fusion <balise></balise> en <balise />.
86
-	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
87
-	// en particulier pour les balises Script et A.
88
-	// en presence d'attributs ne le faire que si la DTD est dispo et d'accord
89
-	// (param fusion_bal)
90
-
91
-	if ($t || (($ouv != $name) and !$fusion_bal)) {
92
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
93
-	} else {
94
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
95
-	}
74
+    $ouv = $phraseur->ouvrant[$phraseur->depth];
75
+
76
+    if ($ouv[0] != ' ') {
77
+        $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
78
+    } else {
79
+        $ouv = '';
80
+    }
81
+    $t = $phraseur->contenu[$phraseur->depth];
82
+    $phraseur->depth = substr($phraseur->depth, 2);
83
+    $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
84
+
85
+    // fusion <balise></balise> en <balise />.
86
+    // ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
87
+    // en particulier pour les balises Script et A.
88
+    // en presence d'attributs ne le faire que si la DTD est dispo et d'accord
89
+    // (param fusion_bal)
90
+
91
+    if ($t || (($ouv != $name) and !$fusion_bal)) {
92
+        $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
93
+    } else {
94
+        $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
95
+    }
96 96
 }
97 97
 
98 98
 // https://code.spip.net/@xml_textElement
99 99
 function xml_textElement($phraseur, $data) {
100
-	$depth = $phraseur->depth;
101
-	$phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
102
-		? $data
103
-		: xml_entites_html($data);
100
+    $depth = $phraseur->depth;
101
+    $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
102
+        ? $data
103
+        : xml_entites_html($data);
104 104
 }
105 105
 
106 106
 function xml_piElement($phraseur, $target, $data) {
107
-	$depth = $phraseur->depth;
108
-
109
-	if (strtolower($target) != 'php') {
110
-		$phraseur->contenu[$depth] .= $data;
111
-	} else {
112
-		ob_start();
113
-		eval($data);
114
-		$data = ob_get_contents();
115
-		ob_end_clean();
116
-		$phraseur->contenu[$depth] .= $data;
117
-	}
107
+    $depth = $phraseur->depth;
108
+
109
+    if (strtolower($target) != 'php') {
110
+        $phraseur->contenu[$depth] .= $data;
111
+    } else {
112
+        ob_start();
113
+        eval($data);
114
+        $data = ob_get_contents();
115
+        ob_end_clean();
116
+        $phraseur->contenu[$depth] .= $data;
117
+    }
118 118
 }
119 119
 
120 120
 
121 121
 // https://code.spip.net/@xml_defautElement
122 122
 function xml_defaultElement($phraseur, $data) {
123
-	$depth = $phraseur->depth;
123
+    $depth = $phraseur->depth;
124 124
 
125
-	if (!isset($phraseur->contenu[$depth])) {
126
-		$phraseur->contenu[$depth] = '';
127
-	}
128
-	$phraseur->contenu[$depth] .= $data;
125
+    if (!isset($phraseur->contenu[$depth])) {
126
+        $phraseur->contenu[$depth] = '';
127
+    }
128
+    $phraseur->contenu[$depth] .= $data;
129 129
 }
130 130
 
131 131
 // https://code.spip.net/@xml_parsestring
132 132
 function xml_parsestring($phraseur, $data) {
133
-	$phraseur->contenu[$phraseur->depth] = '';
134
-
135
-	if (!xml_parse($phraseur->sax, $data, true)) {
136
-		coordonnees_erreur(
137
-			$phraseur,
138
-			xml_error_string(xml_get_error_code($phraseur->sax))
139
-			. "<br />\n" .
140
-			(!$phraseur->depth ? '' :
141
-				('(' .
142
-					_T('erreur_balise_non_fermee') .
143
-					' <tt>' .
144
-					$phraseur->ouvrant[$phraseur->depth] .
145
-					'</tt> ' .
146
-					_T('ligne') .
147
-					' ' .
148
-					$phraseur->reperes[$phraseur->depth] .
149
-			") <br />\n"))
150
-		);
151
-	}
133
+    $phraseur->contenu[$phraseur->depth] = '';
134
+
135
+    if (!xml_parse($phraseur->sax, $data, true)) {
136
+        coordonnees_erreur(
137
+            $phraseur,
138
+            xml_error_string(xml_get_error_code($phraseur->sax))
139
+            . "<br />\n" .
140
+            (!$phraseur->depth ? '' :
141
+                ('(' .
142
+                    _T('erreur_balise_non_fermee') .
143
+                    ' <tt>' .
144
+                    $phraseur->ouvrant[$phraseur->depth] .
145
+                    '</tt> ' .
146
+                    _T('ligne') .
147
+                    ' ' .
148
+                    $phraseur->reperes[$phraseur->depth] .
149
+            ") <br />\n"))
150
+        );
151
+    }
152 152
 }
153 153
 
154 154
 // https://code.spip.net/@coordonnees_erreur
155 155
 function coordonnees_erreur($phraseur, $msg) {
156
-	$entete_length = substr_count($phraseur->entete, "\n");
157
-	$phraseur->err[] = [
158
-		$msg,
159
-		xml_get_current_line_number($phraseur->sax) + $entete_length,
160
-		xml_get_current_column_number($phraseur->sax)
161
-	];
156
+    $entete_length = substr_count($phraseur->entete, "\n");
157
+    $phraseur->err[] = [
158
+        $msg,
159
+        xml_get_current_line_number($phraseur->sax) + $entete_length,
160
+        xml_get_current_column_number($phraseur->sax)
161
+    ];
162 162
 }
163 163
 
164 164
 // https://code.spip.net/@xml_sax_dist
165 165
 function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) {
166
-	if (is_null($charset)) {
167
-		$charset = $GLOBALS['meta']['charset'];
168
-	}
169
-	if ($apply) {
170
-		ob_start();
171
-		if (is_array($apply)) {
172
-			$r = call_user_func_array($page, $apply);
173
-		} else {
174
-			$r = $page();
175
-		}
176
-		$page = ob_get_contents();
177
-		ob_end_clean();
178
-		// fonction sans aucun "echo", ca doit etre le resultat
179
-		if (!$page) {
180
-			$page = $r;
181
-		}
182
-	}
183
-
184
-	if (!$page) {
185
-		return '';
186
-	}
187
-	// charger la DTD et transcoder les entites,
188
-	// et escamoter le doctype que sax mange en php5 mais pas en  php4
189
-	if (!$doctype) {
190
-		if (!$r = analyser_doctype($page)) {
191
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
192
-				. preg_replace(_REGEXP_DOCTYPE, '', $page);
193
-			$r = analyser_doctype($page);
194
-		}
195
-		list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null);
196
-		$page = substr($page, strlen($entete));
197
-	} else {
198
-		$avail = 'SYSTEM';
199
-		$grammaire = $doctype;
200
-		$rotlvl = basename($grammaire);
201
-	}
202
-
203
-	include_spip('xml/analyser_dtd');
204
-	$dtc = charger_dtd($grammaire, $avail, $rotlvl);
205
-	$page = sax_bug($page, $dtc, $charset);
206
-
207
-	// compatibilite Tidy espace public
208
-	if (!$phraseur) {
209
-		$indenter_xml = charger_fonction('indenter', 'xml');
210
-
211
-		return $indenter_xml($page, $apply);
212
-	}
213
-
214
-	$xml_parser = xml_parser_create($charset);
215
-
216
-	xml_set_element_handler(
217
-		$xml_parser,
218
-		[$phraseur, 'debutElement'],
219
-		[$phraseur, 'finElement']
220
-	);
221
-
222
-	xml_set_character_data_handler(
223
-		$xml_parser,
224
-		[$phraseur, 'textElement']
225
-	);
226
-
227
-	xml_set_processing_instruction_handler(
228
-		$xml_parser,
229
-		[$phraseur, 'piElement']
230
-	);
231
-
232
-	xml_set_default_handler(
233
-		$xml_parser,
234
-		[$phraseur, 'defaultElement']
235
-	);
236
-
237
-	xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
238
-
239
-	$phraseur->sax = $xml_parser;
240
-	if (isset($entete)) {
241
-		$phraseur->entete = $entete;
242
-	}
243
-	$phraseur->page = $page;
244
-	$phraseur->dtc = $dtc;
245
-	$phraseur->phraserTout($xml_parser, $page);
246
-	xml_parser_free($xml_parser);
247
-	$phraseur->sax = '';
248
-
249
-	return $phraseur;
166
+    if (is_null($charset)) {
167
+        $charset = $GLOBALS['meta']['charset'];
168
+    }
169
+    if ($apply) {
170
+        ob_start();
171
+        if (is_array($apply)) {
172
+            $r = call_user_func_array($page, $apply);
173
+        } else {
174
+            $r = $page();
175
+        }
176
+        $page = ob_get_contents();
177
+        ob_end_clean();
178
+        // fonction sans aucun "echo", ca doit etre le resultat
179
+        if (!$page) {
180
+            $page = $r;
181
+        }
182
+    }
183
+
184
+    if (!$page) {
185
+        return '';
186
+    }
187
+    // charger la DTD et transcoder les entites,
188
+    // et escamoter le doctype que sax mange en php5 mais pas en  php4
189
+    if (!$doctype) {
190
+        if (!$r = analyser_doctype($page)) {
191
+            $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
192
+                . preg_replace(_REGEXP_DOCTYPE, '', $page);
193
+            $r = analyser_doctype($page);
194
+        }
195
+        list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null);
196
+        $page = substr($page, strlen($entete));
197
+    } else {
198
+        $avail = 'SYSTEM';
199
+        $grammaire = $doctype;
200
+        $rotlvl = basename($grammaire);
201
+    }
202
+
203
+    include_spip('xml/analyser_dtd');
204
+    $dtc = charger_dtd($grammaire, $avail, $rotlvl);
205
+    $page = sax_bug($page, $dtc, $charset);
206
+
207
+    // compatibilite Tidy espace public
208
+    if (!$phraseur) {
209
+        $indenter_xml = charger_fonction('indenter', 'xml');
210
+
211
+        return $indenter_xml($page, $apply);
212
+    }
213
+
214
+    $xml_parser = xml_parser_create($charset);
215
+
216
+    xml_set_element_handler(
217
+        $xml_parser,
218
+        [$phraseur, 'debutElement'],
219
+        [$phraseur, 'finElement']
220
+    );
221
+
222
+    xml_set_character_data_handler(
223
+        $xml_parser,
224
+        [$phraseur, 'textElement']
225
+    );
226
+
227
+    xml_set_processing_instruction_handler(
228
+        $xml_parser,
229
+        [$phraseur, 'piElement']
230
+    );
231
+
232
+    xml_set_default_handler(
233
+        $xml_parser,
234
+        [$phraseur, 'defaultElement']
235
+    );
236
+
237
+    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
238
+
239
+    $phraseur->sax = $xml_parser;
240
+    if (isset($entete)) {
241
+        $phraseur->entete = $entete;
242
+    }
243
+    $phraseur->page = $page;
244
+    $phraseur->dtc = $dtc;
245
+    $phraseur->phraserTout($xml_parser, $page);
246
+    xml_parser_free($xml_parser);
247
+    $phraseur->sax = '';
248
+
249
+    return $phraseur;
250 250
 }
251 251
 
252 252
 // SAX ne dit pas si une Entite est dans un attribut ou non.
@@ -258,24 +258,24 @@  discard block
 block discarded – undo
258 258
 
259 259
 // https://code.spip.net/@sax_bug
260 260
 function sax_bug($data, $dtc, $charset = null) {
261
-	if (is_null($charset)) {
262
-		$charset = $GLOBALS['meta']['charset'];
263
-	}
264
-
265
-	if ($dtc) {
266
-		$trans = [];
267
-
268
-		foreach ($dtc->entites as $k => $v) {
269
-			if (!strpos(' amp lt gt quot ', $k)) {
270
-				$trans["&$k;"] = $v;
271
-			}
272
-		}
273
-		$data = strtr($data, $trans);
274
-	} else {
275
-		$data = html2unicode($data, true);
276
-	}
277
-
278
-	return unicode2charset($data, $charset);
261
+    if (is_null($charset)) {
262
+        $charset = $GLOBALS['meta']['charset'];
263
+    }
264
+
265
+    if ($dtc) {
266
+        $trans = [];
267
+
268
+        foreach ($dtc->entites as $k => $v) {
269
+            if (!strpos(' amp lt gt quot ', $k)) {
270
+                $trans["&$k;"] = $v;
271
+            }
272
+        }
273
+        $data = strtr($data, $trans);
274
+    } else {
275
+        $data = html2unicode($data, true);
276
+    }
277
+
278
+    return unicode2charset($data, $charset);
279 279
 }
280 280
 
281 281
 // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut
@@ -286,52 +286,52 @@  discard block
 block discarded – undo
286 286
 // mais un XML Schema que SPIP ne fait pas encore lire.
287 287
 // https://code.spip.net/@analyser_doctype
288 288
 function analyser_doctype($data) {
289
-	if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
290
-		if (preg_match(_REGEXP_XML, $data, $page)) {
291
-			list(, $entete, $topelement) = $page;
292
-			if ($topelement == 'rss') {
293
-				return [
294
-					$entete,
295
-					'PUBLIC',
296
-					_DOCTYPE_RSS,
297
-					'rss-0.91.dtd'
298
-				];
299
-			} else {
300
-				$dtd = $topelement . '.dtd';
301
-				$f = find_in_path($dtd);
302
-				if (file_exists($f)) {
303
-					return [$entete, 'SYSTEM', $f, $dtd];
304
-				}
305
-			}
306
-		}
307
-		spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
308
-
309
-		return [];
310
-	}
311
-	list($entete, , $topelement, $avail, $suite) = $page;
312
-
313
-	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
314
-		if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
315
-			return [];
316
-		}
317
-	}
318
-	list(, $rotlvl, $suite) = $r;
319
-
320
-	if (!$suite) {
321
-		if ($avail != 'SYSTEM') {
322
-			return [];
323
-		}
324
-		$grammaire = $rotlvl;
325
-		$rotlvl = '';
326
-	} else {
327
-		if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) {
328
-			if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
329
-				return [];
330
-			}
331
-		}
332
-
333
-		$grammaire = $r[1];
334
-	}
335
-
336
-	return [$entete, $avail, $grammaire, $rotlvl];
289
+    if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
290
+        if (preg_match(_REGEXP_XML, $data, $page)) {
291
+            list(, $entete, $topelement) = $page;
292
+            if ($topelement == 'rss') {
293
+                return [
294
+                    $entete,
295
+                    'PUBLIC',
296
+                    _DOCTYPE_RSS,
297
+                    'rss-0.91.dtd'
298
+                ];
299
+            } else {
300
+                $dtd = $topelement . '.dtd';
301
+                $f = find_in_path($dtd);
302
+                if (file_exists($f)) {
303
+                    return [$entete, 'SYSTEM', $f, $dtd];
304
+                }
305
+            }
306
+        }
307
+        spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
308
+
309
+        return [];
310
+    }
311
+    list($entete, , $topelement, $avail, $suite) = $page;
312
+
313
+    if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
314
+        if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
315
+            return [];
316
+        }
317
+    }
318
+    list(, $rotlvl, $suite) = $r;
319
+
320
+    if (!$suite) {
321
+        if ($avail != 'SYSTEM') {
322
+            return [];
323
+        }
324
+        $grammaire = $rotlvl;
325
+        $rotlvl = '';
326
+    } else {
327
+        if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) {
328
+            if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
329
+                return [];
330
+            }
331
+        }
332
+
333
+        $grammaire = $r[1];
334
+    }
335
+
336
+    return [$entete, $avail, $grammaire, $rotlvl];
337 337
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -22 removed lines patch added patch discarded remove patch
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	$t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
47 47
 	// espace initial signifie: deja integree au resultat
48 48
 	if ($t[0] != ' ') {
49
-		$phraseur->res .= '<' . $t . '>';
50
-		$phraseur->ouvrant[$depth] = ' ' . $t;
49
+		$phraseur->res .= '<'.$t.'>';
50
+		$phraseur->ouvrant[$depth] = ' '.$t;
51 51
 	}
52 52
 	$t = $phraseur->contenu[$depth];
53 53
 	// n'indenter que s'il y a un separateur avant
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	foreach ($attrs as $k => $v) {
59 59
 		$delim = strpos($v, "'") === false ? "'" : '"';
60 60
 		$val = xml_entites_html($v);
61
-		$att .= $sep . $k . '=' . $delim
61
+		$att .= $sep.$k.'='.$delim
62 62
 			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
63 63
 			. $delim;
64 64
 		$sep = "\n $depth";
65 65
 	}
66 66
 	$phraseur->depth .= '  ';
67 67
 	$phraseur->contenu[$phraseur->depth] = '';
68
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
68
+	$phraseur->ouvrant[$phraseur->depth] = $name.$att;
69 69
 	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
70 70
 }
71 71
 
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
 	$ouv = $phraseur->ouvrant[$phraseur->depth];
75 75
 
76 76
 	if ($ouv[0] != ' ') {
77
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
77
+		$phraseur->ouvrant[$phraseur->depth] = ' '.$ouv;
78 78
 	} else {
79 79
 		$ouv = '';
80 80
 	}
81 81
 	$t = $phraseur->contenu[$phraseur->depth];
82 82
 	$phraseur->depth = substr($phraseur->depth, 2);
83
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
83
+	$t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t);
84 84
 
85 85
 	// fusion <balise></balise> en <balise />.
86 86
 	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	// (param fusion_bal)
90 90
 
91 91
 	if ($t || (($ouv != $name) and !$fusion_bal)) {
92
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
92
+		$phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t.'</'.$name.'>';
93 93
 	} else {
94
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
94
+		$phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ('</'.$name.'>'));
95 95
 	}
96 96
 }
97 97
 
@@ -136,16 +136,15 @@  discard block
 block discarded – undo
136 136
 		coordonnees_erreur(
137 137
 			$phraseur,
138 138
 			xml_error_string(xml_get_error_code($phraseur->sax))
139
-			. "<br />\n" .
140
-			(!$phraseur->depth ? '' :
141
-				('(' .
142
-					_T('erreur_balise_non_fermee') .
143
-					' <tt>' .
144
-					$phraseur->ouvrant[$phraseur->depth] .
145
-					'</tt> ' .
146
-					_T('ligne') .
147
-					' ' .
148
-					$phraseur->reperes[$phraseur->depth] .
139
+			. "<br />\n".
140
+			(!$phraseur->depth ? '' : ('('.
141
+					_T('erreur_balise_non_fermee').
142
+					' <tt>'.
143
+					$phraseur->ouvrant[$phraseur->depth].
144
+					'</tt> '.
145
+					_T('ligne').
146
+					' '.
147
+					$phraseur->reperes[$phraseur->depth].
149 148
 			") <br />\n"))
150 149
 		);
151 150
 	}
@@ -188,7 +187,7 @@  discard block
 block discarded – undo
188 187
 	// et escamoter le doctype que sax mange en php5 mais pas en  php4
189 188
 	if (!$doctype) {
190 189
 		if (!$r = analyser_doctype($page)) {
191
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
190
+			$page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE
192 191
 				. preg_replace(_REGEXP_DOCTYPE, '', $page);
193 192
 			$r = analyser_doctype($page);
194 193
 		}
@@ -297,18 +296,18 @@  discard block
 block discarded – undo
297 296
 					'rss-0.91.dtd'
298 297
 				];
299 298
 			} else {
300
-				$dtd = $topelement . '.dtd';
299
+				$dtd = $topelement.'.dtd';
301 300
 				$f = find_in_path($dtd);
302 301
 				if (file_exists($f)) {
303 302
 					return [$entete, 'SYSTEM', $f, $dtd];
304 303
 				}
305 304
 			}
306 305
 		}
307
-		spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
306
+		spip_log('Dtd pas vu pour '.substr($data, 0, 100));
308 307
 
309 308
 		return [];
310 309
 	}
311
-	list($entete, , $topelement, $avail, $suite) = $page;
310
+	list($entete,, $topelement, $avail, $suite) = $page;
312 311
 
313 312
 	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) {
314 313
 		if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
Please login to merge, or discard this patch.
ecrire/index.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 /** Drapeau indiquant que l'on est dans l'espace privé */
20 20
 define('_ESPACE_PRIVE', true);
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	include 'inc_version.php';
22
+    include 'inc_version.php';
23 23
 }
24 24
 
25 25
 // Verification anti magic_quotes_sybase, pour qui addslashes("'") = "''"
26 26
 // On prefere la faire ici plutot que dans inc_version, c'est moins souvent et
27 27
 // si le reglage est modifie sur un site en prod, ca fait moins mal
28 28
 if (addslashes("'") !== "\\'") {
29
-	die('SPIP incompatible magic_quotes_sybase');
29
+    die('SPIP incompatible magic_quotes_sybase');
30 30
 }
31 31
 
32 32
 include_spip('inc/cookie');
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
 // alors il faut blinder les variables d'URL
43 43
 //
44 44
 if (autoriser_sans_cookie($exec, false)) {
45
-	if (!isset($reinstall)) {
46
-		$reinstall = 'non';
47
-	}
48
-	$var_auth = true;
45
+    if (!isset($reinstall)) {
46
+        $reinstall = 'non';
47
+    }
48
+    $var_auth = true;
49 49
 } else {
50
-	// Authentification, redefinissable
51
-	$auth = charger_fonction('auth', 'inc');
52
-	$var_auth = $auth();
53
-	if ($var_auth) {
54
-		echo auth_echec($var_auth);
55
-		exit;
56
-	}
50
+    // Authentification, redefinissable
51
+    $auth = charger_fonction('auth', 'inc');
52
+    $var_auth = $auth();
53
+    if ($var_auth) {
54
+        echo auth_echec($var_auth);
55
+        exit;
56
+    }
57 57
 }
58 58
 
59 59
 // initialiser a la langue par defaut
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
 
65 65
 
66 66
 if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
67
-	if (!autoriser_sans_cookie($exec)) {
68
-		// Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
-		include_spip('public/aiguiller');
70
-		if (
71
-			// cas des appels actions ?action=xxx
72
-			traiter_appels_actions()
73
-			or
74
-			// cas des hits ajax sur les inclusions ajax
75
-			traiter_appels_inclusions_ajax()
76
-			or
77
-			// cas des formulaires charger/verifier/traiter
78
-			traiter_formulaires_dynamiques()
79
-		) {
80
-			exit;
81
-		} // le hit est fini !
82
-	}
67
+    if (!autoriser_sans_cookie($exec)) {
68
+        // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
+        include_spip('public/aiguiller');
70
+        if (
71
+            // cas des appels actions ?action=xxx
72
+            traiter_appels_actions()
73
+            or
74
+            // cas des hits ajax sur les inclusions ajax
75
+            traiter_appels_inclusions_ajax()
76
+            or
77
+            // cas des formulaires charger/verifier/traiter
78
+            traiter_formulaires_dynamiques()
79
+        ) {
80
+            exit;
81
+        } // le hit est fini !
82
+    }
83 83
 }
84 84
 // securiser les redirect du back-office
85 85
 if (_request('redirect')) {
86
-	if (!function_exists('securiser_redirect_action')) {
87
-		include_spip('public/aiguiller');
88
-	}
89
-	set_request('redirect', securiser_redirect_action(_request('redirect')));
86
+    if (!function_exists('securiser_redirect_action')) {
87
+        include_spip('public/aiguiller');
88
+    }
89
+    set_request('redirect', securiser_redirect_action(_request('redirect')));
90 90
 }
91 91
 
92 92
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 
97 97
 // Controle de la version, sauf si on est deja en train de s'en occuper
98 98
 if (
99
-	!$reinstall == 'oui'
100
-	and !_AJAX
101
-	and isset($GLOBALS['meta']['version_installee'])
102
-	and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
99
+    !$reinstall == 'oui'
100
+    and !_AJAX
101
+    and isset($GLOBALS['meta']['version_installee'])
102
+    and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
103 103
 ) {
104
-	$exec = 'demande_mise_a_jour';
104
+    $exec = 'demande_mise_a_jour';
105 105
 }
106 106
 
107 107
 // Quand une action d'administration est en cours (meta "admin"),
@@ -111,45 +111,45 @@  discard block
 block discarded – undo
111 111
 // sinon c'est qu'elle a ete interrompue et il faut la reprendre
112 112
 
113 113
 elseif (isset($GLOBALS['meta']['admin'])) {
114
-	if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) {
115
-		list(, $var_f, $n) = $l;
116
-	}
117
-	if (
118
-		_AJAX
119
-		or !(
120
-			isset($_COOKIE['spip_admin'])
121
-			or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
122
-		)
123
-	) {
124
-		spip_log('Quand la meta admin vaut ' .
125
-			$GLOBALS['meta']['admin'] .
126
-			' seul un admin peut se connecter et sans AJAX.' .
127
-			' En cas de probleme, detruire cette meta.');
128
-		die(_T('info_travaux_texte'));
129
-	}
130
-	if ($n) {
131
-		list(, $var_f, $n) = $l;
132
-		if (tester_url_ecrire("base_$var_f")) {
133
-			$var_f = "base_$var_f";
134
-		}
135
-		if ($var_f != $exec) {
136
-			spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
137
-			$exec = $var_f;
138
-			set_request('exec', $exec);
139
-		}
140
-	}
114
+    if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) {
115
+        list(, $var_f, $n) = $l;
116
+    }
117
+    if (
118
+        _AJAX
119
+        or !(
120
+            isset($_COOKIE['spip_admin'])
121
+            or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
122
+        )
123
+    ) {
124
+        spip_log('Quand la meta admin vaut ' .
125
+            $GLOBALS['meta']['admin'] .
126
+            ' seul un admin peut se connecter et sans AJAX.' .
127
+            ' En cas de probleme, detruire cette meta.');
128
+        die(_T('info_travaux_texte'));
129
+    }
130
+    if ($n) {
131
+        list(, $var_f, $n) = $l;
132
+        if (tester_url_ecrire("base_$var_f")) {
133
+            $var_f = "base_$var_f";
134
+        }
135
+        if ($var_f != $exec) {
136
+            spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
137
+            $exec = $var_f;
138
+            set_request('exec', $exec);
139
+        }
140
+    }
141 141
 }
142 142
 // si nom pas plausible, prendre le script par defaut
143 143
 // attention aux deux cas 404/403 qui commencent par un 4 !
144 144
 elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) {
145
-	$exec = 'accueil';
146
-	set_request('exec', $exec);
145
+    $exec = 'accueil';
146
+    set_request('exec', $exec);
147 147
 }
148 148
 
149 149
 // compatibilite ascendante : obsolete, ne plus utiliser
150 150
 $GLOBALS['spip_display'] = isset($GLOBALS['visiteur_session']['prefs']['display'])
151
-	? (int) $GLOBALS['visiteur_session']['prefs']['display']
152
-	: 0;
151
+    ? (int) $GLOBALS['visiteur_session']['prefs']['display']
152
+    : 0;
153 153
 $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? preg_replace('/[^a-z0-9]/i', '', $_COOKIE['spip_ecran']) : 'etroit';
154 154
 
155 155
 //  si la langue est specifiee par cookie et ne correspond pas
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie
158 158
 // si le cookie n'est pas pose correctement dans l'action
159 159
 if (
160
-	!$var_auth and isset($_COOKIE['spip_lang_ecrire'])
161
-	and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
160
+    !$var_auth and isset($_COOKIE['spip_lang_ecrire'])
161
+    and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
162 162
 ) {
163
-	include_spip('action/converser');
164
-	action_converser_post($GLOBALS['visiteur_session']['lang'], true);
163
+    include_spip('action/converser');
164
+    action_converser_post($GLOBALS['visiteur_session']['lang'], true);
165 165
 }
166 166
 
167 167
 if ($var_f = tester_url_ecrire($exec)) {
168
-	$var_f = charger_fonction($var_f);
169
-	$var_f(); // at last
168
+    $var_f = charger_fonction($var_f);
169
+    $var_f(); // at last
170 170
 } else {
171
-	// Rien de connu: rerouter vers exec=404 au lieu d'echouer
172
-	// ce qui permet de laisser la main a un plugin
173
-	$var_f = charger_fonction('404');
174
-	$var_f($exec);
171
+    // Rien de connu: rerouter vers exec=404 au lieu d'echouer
172
+    // ce qui permet de laisser la main a un plugin
173
+    $var_f = charger_fonction('404');
174
+    $var_f($exec);
175 175
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 // Determiner l'action demandee
36 36
 //
37 37
 
38
-$exec = (string)_request('exec');
38
+$exec = (string) _request('exec');
39 39
 $reinstall = (!is_null(_request('reinstall'))) ? _request('reinstall') : ($exec == 'install' ? 'oui' : null);
40 40
 //
41 41
 // Les scripts d'insallation n'authentifient pas, forcement,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 			or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
122 122
 		)
123 123
 	) {
124
-		spip_log('Quand la meta admin vaut ' .
125
-			$GLOBALS['meta']['admin'] .
126
-			' seul un admin peut se connecter et sans AJAX.' .
124
+		spip_log('Quand la meta admin vaut '.
125
+			$GLOBALS['meta']['admin'].
126
+			' seul un admin peut se connecter et sans AJAX.'.
127 127
 			' En cas de probleme, detruire cette meta.');
128 128
 		die(_T('info_travaux_texte'));
129 129
 	}
Please login to merge, or discard this patch.
ecrire/inc_version.php 2 patches
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 define('_PHP_MIN', '7.3.0');
37 37
 
38 38
 if (!defined('_DIR_RESTREINT_ABS')) {
39
-	/** le nom du repertoire ecrire/ */
40
-	define('_DIR_RESTREINT_ABS', 'ecrire/');
39
+    /** le nom du repertoire ecrire/ */
40
+    define('_DIR_RESTREINT_ABS', 'ecrire/');
41 41
 }
42 42
 
43 43
 /** Chemin relatif pour aller dans ecrire
44 44
  *  vide si on est dans ecrire, 'ecrire/' sinon */
45 45
 define(
46
-	'_DIR_RESTREINT',
47
-	(!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS)
46
+    '_DIR_RESTREINT',
47
+    (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS)
48 48
 );
49 49
 
50 50
 /** Chemin relatif pour aller à la racine */
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 
60 60
 // Icones
61 61
 if (!defined('_NOM_IMG_PACK')) {
62
-	/** Nom du dossier images */
63
-	define('_NOM_IMG_PACK', 'images/');
62
+    /** Nom du dossier images */
63
+    define('_NOM_IMG_PACK', 'images/');
64 64
 }
65 65
 /** le chemin http (relatif) vers les images standard */
66 66
 define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK));
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK);
70 70
 
71 71
 if (!defined('_JAVASCRIPT')) {
72
-	/** Nom du repertoire des  bibliotheques JavaScript */
73
-	define('_JAVASCRIPT', 'javascript/');
72
+    /** Nom du repertoire des  bibliotheques JavaScript */
73
+    define('_JAVASCRIPT', 'javascript/');
74 74
 } // utilisable avec #CHEMIN et find_in_path
75 75
 /** le nom du repertoire des  bibliotheques JavaScript du prive */
76 76
 define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT));
@@ -80,47 +80,47 @@  discard block
 block discarded – undo
80 80
 # mais on peut les mettre ailleurs et changer completement les noms
81 81
 
82 82
 if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) {
83
-	/** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */
84
-	define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/');
83
+    /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */
84
+    define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/');
85 85
 }
86 86
 if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) {
87
-	/** Nom du repertoire des fichiers Temporaires Accessibles par http:// */
88
-	define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/');
87
+    /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */
88
+    define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/');
89 89
 }
90 90
 if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) {
91
-	/** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */
92
-	define('_NOM_PERMANENTS_INACCESSIBLES', 'config/');
91
+    /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */
92
+    define('_NOM_PERMANENTS_INACCESSIBLES', 'config/');
93 93
 }
94 94
 if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) {
95
-	/** Nom du repertoire des fichiers Permanents Accessibles par http:// */
96
-	define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/');
95
+    /** Nom du repertoire des fichiers Permanents Accessibles par http:// */
96
+    define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/');
97 97
 }
98 98
 
99 99
 
100 100
 /** Le nom du fichier de personnalisation */
101 101
 if (!defined('_NOM_CONFIG')) {
102
-	define('_NOM_CONFIG', 'mes_options');
102
+    define('_NOM_CONFIG', 'mes_options');
103 103
 }
104 104
 
105 105
 // Son emplacement absolu si on le trouve
106 106
 if (
107
-	@file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php')
108
-	or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php'))
107
+    @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php')
108
+    or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php'))
109 109
 ) {
110
-	/** Emplacement absolu du fichier d'option */
111
-	define('_FILE_OPTIONS', $f);
110
+    /** Emplacement absolu du fichier d'option */
111
+    define('_FILE_OPTIONS', $f);
112 112
 } else {
113
-	define('_FILE_OPTIONS', '');
113
+    define('_FILE_OPTIONS', '');
114 114
 }
115 115
 
116 116
 if (!defined('MODULES_IDIOMES')) {
117
-	/**
118
-	 * Modules par défaut pour la traduction.
119
-	 *
120
-	 * Constante utilisée par le compilateur et le décompilateur
121
-	 * sa valeur etant traitée par inc_traduire_dist
122
-	 */
123
-	define('MODULES_IDIOMES', 'public|spip|ecrire');
117
+    /**
118
+     * Modules par défaut pour la traduction.
119
+     *
120
+     * Constante utilisée par le compilateur et le décompilateur
121
+     * sa valeur etant traitée par inc_traduire_dist
122
+     */
123
+    define('MODULES_IDIOMES', 'public|spip|ecrire');
124 124
 }
125 125
 
126 126
 // *** Fin des define *** //
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 
129 129
 // Inclure l'ecran de securite
130 130
 if (
131
-	!defined('_ECRAN_SECURITE')
132
-	and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php')
131
+    !defined('_ECRAN_SECURITE')
132
+    and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php')
133 133
 ) {
134
-	include $f;
134
+    include $f;
135 135
 }
136 136
 
137 137
 
@@ -139,30 +139,30 @@  discard block
 block discarded – undo
139 139
  * Détecteur de robot d'indexation
140 140
  */
141 141
 if (!defined('_IS_BOT')) {
142
-	define(
143
-		'_IS_BOT',
144
-		isset($_SERVER['HTTP_USER_AGENT'])
145
-		and preg_match(
146
-			// mots generiques
147
-			',bot|slurp|crawler|spider|webvac|yandex|'
148
-			// MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot
149
-			. 'MSIE 6\.0|'
150
-			// UA plus cibles
151
-			. '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti'
152
-			. ',i',
153
-			(string)$_SERVER['HTTP_USER_AGENT']
154
-		)
155
-	);
142
+    define(
143
+        '_IS_BOT',
144
+        isset($_SERVER['HTTP_USER_AGENT'])
145
+        and preg_match(
146
+            // mots generiques
147
+            ',bot|slurp|crawler|spider|webvac|yandex|'
148
+            // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot
149
+            . 'MSIE 6\.0|'
150
+            // UA plus cibles
151
+            . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti'
152
+            . ',i',
153
+            (string)$_SERVER['HTTP_USER_AGENT']
154
+        )
155
+    );
156 156
 }
157 157
 
158 158
 if (!defined('_IS_CLI')) {
159
-	define(
160
-		'_IS_CLI',
161
-		!isset($_SERVER['HTTP_HOST'])
162
-		and !strlen($_SERVER['DOCUMENT_ROOT'])
163
-		and !empty($_SERVER['argv'])
164
-		and empty($_SERVER['REQUEST_METHOD'])
165
-	);
159
+    define(
160
+        '_IS_CLI',
161
+        !isset($_SERVER['HTTP_HOST'])
162
+        and !strlen($_SERVER['DOCUMENT_ROOT'])
163
+        and !empty($_SERVER['argv'])
164
+        and empty($_SERVER['REQUEST_METHOD'])
165
+    );
166 166
 }
167 167
 
168 168
 // *** Parametrage par defaut de SPIP ***
@@ -174,61 +174,61 @@  discard block
 block discarded – undo
174 174
 // Ne pas les rendre indefinies.
175 175
 
176 176
 global
177
-	$nombre_de_logs,
178
-	$taille_des_logs,
179
-	$table_prefix,
180
-	$cookie_prefix,
181
-	$dossier_squelettes,
182
-	$filtrer_javascript,
183
-	$type_urls,
184
-	$debut_date_publication,
185
-	$ip,
186
-	$mysql_rappel_connexion,
187
-	$mysql_rappel_nom_base,
188
-	$test_i18n,
189
-	$ignore_auth_http,
190
-	$ignore_remote_user,
191
-	$derniere_modif_invalide,
192
-	$home_server,
193
-	$help_server,
194
-	$url_glossaire_externe,
195
-	$tex_server,
196
-	$traiter_math,
197
-	$xhtml,
198
-	$xml_indent,
199
-	$source_vignettes,
200
-	$formats_logos,
201
-	$controler_dates_rss,
202
-	$spip_pipeline,
203
-	$spip_matrice,
204
-	$plugins,
205
-	$surcharges,
206
-	$exceptions_des_tables,
207
-	$tables_principales,
208
-	$table_des_tables,
209
-	$tables_auxiliaires,
210
-	$table_primary,
211
-	$table_date,
212
-	$table_titre,
213
-	$tables_jointures,
214
-	$liste_des_statuts,
215
-	$liste_des_etats,
216
-	$liste_des_authentifications,
217
-	$spip_version_branche,
218
-	$spip_version_code,
219
-	$spip_version_base,
220
-	$spip_sql_version,
221
-	$spip_version_affichee,
222
-	$visiteur_session,
223
-	$auteur_session,
224
-	$connect_statut,
225
-	$connect_toutes_rubriques,
226
-	$hash_recherche,
227
-	$hash_recherche_strict,
228
-	$ldap_present,
229
-	$meta,
230
-	$connect_id_rubrique,
231
-	$puce;
177
+    $nombre_de_logs,
178
+    $taille_des_logs,
179
+    $table_prefix,
180
+    $cookie_prefix,
181
+    $dossier_squelettes,
182
+    $filtrer_javascript,
183
+    $type_urls,
184
+    $debut_date_publication,
185
+    $ip,
186
+    $mysql_rappel_connexion,
187
+    $mysql_rappel_nom_base,
188
+    $test_i18n,
189
+    $ignore_auth_http,
190
+    $ignore_remote_user,
191
+    $derniere_modif_invalide,
192
+    $home_server,
193
+    $help_server,
194
+    $url_glossaire_externe,
195
+    $tex_server,
196
+    $traiter_math,
197
+    $xhtml,
198
+    $xml_indent,
199
+    $source_vignettes,
200
+    $formats_logos,
201
+    $controler_dates_rss,
202
+    $spip_pipeline,
203
+    $spip_matrice,
204
+    $plugins,
205
+    $surcharges,
206
+    $exceptions_des_tables,
207
+    $tables_principales,
208
+    $table_des_tables,
209
+    $tables_auxiliaires,
210
+    $table_primary,
211
+    $table_date,
212
+    $table_titre,
213
+    $tables_jointures,
214
+    $liste_des_statuts,
215
+    $liste_des_etats,
216
+    $liste_des_authentifications,
217
+    $spip_version_branche,
218
+    $spip_version_code,
219
+    $spip_version_base,
220
+    $spip_sql_version,
221
+    $spip_version_affichee,
222
+    $visiteur_session,
223
+    $auteur_session,
224
+    $connect_statut,
225
+    $connect_toutes_rubriques,
226
+    $hash_recherche,
227
+    $hash_recherche_strict,
228
+    $ldap_present,
229
+    $meta,
230
+    $connect_id_rubrique,
231
+    $puce;
232 232
 
233 233
 # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log
234 234
 $nombre_de_logs = 4;
@@ -283,48 +283,48 @@  discard block
 block discarded – undo
283 283
 // Prendre en compte les entetes HTTP_X_FORWARDED_XX
284 284
 //
285 285
 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
286
-	if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
287
-		$_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST'];
288
-	}
289
-	if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
290
-		$_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
291
-	}
286
+    if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
287
+        $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST'];
288
+    }
289
+    if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
290
+        $_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
291
+    }
292 292
 }
293 293
 if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
294
-	if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) {
295
-		$_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
296
-		if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
297
-			$_SERVER['HTTPS'] = 'on';
298
-			if (isset($_SERVER['REQUEST_SCHEME'])) {
299
-				$_SERVER['REQUEST_SCHEME'] = 'https';
300
-			}
301
-		}
302
-	}
303
-	$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
304
-	if (strpos($host, ',') !== false) {
305
-		$h = explode(',', $host);
306
-		$host = trim(reset($h));
307
-	}
308
-	// securite sur le contenu de l'entete
309
-	$host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________');
310
-	$_SERVER['HTTP_HOST'] = $host;
294
+    if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) {
295
+        $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
296
+        if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
297
+            $_SERVER['HTTPS'] = 'on';
298
+            if (isset($_SERVER['REQUEST_SCHEME'])) {
299
+                $_SERVER['REQUEST_SCHEME'] = 'https';
300
+            }
301
+        }
302
+    }
303
+    $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
304
+    if (strpos($host, ',') !== false) {
305
+        $h = explode(',', $host);
306
+        $host = trim(reset($h));
307
+    }
308
+    // securite sur le contenu de l'entete
309
+    $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________');
310
+    $_SERVER['HTTP_HOST'] = $host;
311 311
 }
312 312
 //
313 313
 // On note le numero IP du client dans la variable $ip
314 314
 //
315 315
 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
316
-	$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
317
-	if (strpos($ip, ',') !== false) {
318
-		$ip = explode(',', $ip);
319
-		$ip = reset($ip);
320
-	}
321
-	// ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost
322
-	if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') {
323
-		$_SERVER['REMOTE_ADDR'] = $ip;
324
-	}
316
+    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
317
+    if (strpos($ip, ',') !== false) {
318
+        $ip = explode(',', $ip);
319
+        $ip = reset($ip);
320
+    }
321
+    // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost
322
+    if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') {
323
+        $_SERVER['REMOTE_ADDR'] = $ip;
324
+    }
325 325
 }
326 326
 if (isset($_SERVER['REMOTE_ADDR'])) {
327
-	$ip = $_SERVER['REMOTE_ADDR'];
327
+    $ip = $_SERVER['REMOTE_ADDR'];
328 328
 }
329 329
 
330 330
 // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la
@@ -409,24 +409,24 @@  discard block
 block discarded – undo
409 409
 
410 410
 // Liste des statuts.
411 411
 $liste_des_statuts = [
412
-	'info_administrateurs' => '0minirezo',
413
-	'info_redacteurs' => '1comite',
414
-	'info_visiteurs' => '6forum',
415
-	'texte_statut_poubelle' => '5poubelle'
412
+    'info_administrateurs' => '0minirezo',
413
+    'info_redacteurs' => '1comite',
414
+    'info_visiteurs' => '6forum',
415
+    'texte_statut_poubelle' => '5poubelle'
416 416
 ];
417 417
 
418 418
 $liste_des_etats = [
419
-	'texte_statut_en_cours_redaction' => 'prepa',
420
-	'texte_statut_propose_evaluation' => 'prop',
421
-	'texte_statut_publie' => 'publie',
422
-	'texte_statut_poubelle' => 'poubelle',
423
-	'texte_statut_refuse' => 'refuse'
419
+    'texte_statut_en_cours_redaction' => 'prepa',
420
+    'texte_statut_propose_evaluation' => 'prop',
421
+    'texte_statut_publie' => 'publie',
422
+    'texte_statut_poubelle' => 'poubelle',
423
+    'texte_statut_refuse' => 'refuse'
424 424
 ];
425 425
 
426 426
 // liste des methodes d'authentifications
427 427
 $liste_des_authentifications = [
428
-	'spip' => 'spip',
429
-	'ldap' => 'ldap'
428
+    'spip' => 'spip',
429
+    'ldap' => 'ldap'
430 430
 ];
431 431
 
432 432
 // Experimental : pour supprimer systematiquement l'affichage des numeros
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
 // Definition personnelles eventuelles
477 477
 
478 478
 if (_FILE_OPTIONS) {
479
-	include_once _FILE_OPTIONS;
479
+    include_once _FILE_OPTIONS;
480 480
 }
481 481
 
482 482
 if (!defined('SPIP_ERREUR_REPORT')) {
483
-	/** Masquer les warning */
484
-	define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED);
483
+    /** Masquer les warning */
484
+    define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED);
485 485
 }
486 486
 error_reporting(SPIP_ERREUR_REPORT);
487 487
 
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
 // ===> on execute en neutralisant les messages d'erreur
495 495
 
496 496
 spip_initialisation_core(
497
-	(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
498
-	(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
499
-	(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
500
-	(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
497
+    (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
498
+    (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
499
+    (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
500
+    (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
501 501
 );
502 502
 
503 503
 
@@ -507,70 +507,70 @@  discard block
 block discarded – undo
507 507
 // donc il faut avoir tout fini ici avant de charger les plugins
508 508
 
509 509
 if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) {
510
-	// chargement optimise precompile
511
-	include_once(_CACHE_PLUGINS_OPT);
510
+    // chargement optimise precompile
511
+    include_once(_CACHE_PLUGINS_OPT);
512 512
 } else {
513
-	spip_initialisation_suite();
514
-	include_spip('inc/plugin');
515
-	// generer les fichiers php precompiles
516
-	// de chargement des plugins et des pipelines
517
-	actualise_plugins_actifs();
513
+    spip_initialisation_suite();
514
+    include_spip('inc/plugin');
515
+    // generer les fichiers php precompiles
516
+    // de chargement des plugins et des pipelines
517
+    actualise_plugins_actifs();
518 518
 }
519 519
 
520 520
 // Initialisations non critiques surchargeables par les plugins
521 521
 spip_initialisation_suite();
522 522
 
523 523
 if (!defined('_LOG_FILTRE_GRAVITE')) {
524
-	/** niveau maxi d'enregistrement des logs */
525
-	define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE);
524
+    /** niveau maxi d'enregistrement des logs */
525
+    define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE);
526 526
 }
527 527
 
528 528
 if (!defined('_OUTILS_DEVELOPPEURS')) {
529
-	/** Activer des outils pour développeurs ? */
530
-	define('_OUTILS_DEVELOPPEURS', false);
529
+    /** Activer des outils pour développeurs ? */
530
+    define('_OUTILS_DEVELOPPEURS', false);
531 531
 }
532 532
 
533 533
 // charger systematiquement inc/autoriser dans l'espace restreint
534 534
 if (test_espace_prive()) {
535
-	include_spip('inc/autoriser');
535
+    include_spip('inc/autoriser');
536 536
 }
537 537
 //
538 538
 // Installer Spip si pas installe... sauf si justement on est en train
539 539
 //
540 540
 if (
541
-	!(_FILE_CONNECT
542
-	or autoriser_sans_cookie(_request('exec'))
543
-	or _request('action') == 'cookie'
544
-	or _request('action') == 'converser'
545
-	or _request('action') == 'test_dirs')
541
+    !(_FILE_CONNECT
542
+    or autoriser_sans_cookie(_request('exec'))
543
+    or _request('action') == 'cookie'
544
+    or _request('action') == 'converser'
545
+    or _request('action') == 'test_dirs')
546 546
 ) {
547
-	// Si on peut installer, on lance illico
548
-	if (test_espace_prive()) {
549
-		include_spip('inc/headers');
550
-		redirige_url_ecrire('install');
551
-	} else {
552
-		// Si on est dans le site public, dire que qq s'en occupe
553
-		include_spip('inc/minipres');
554
-		utiliser_langue_visiteur();
555
-		echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]);
556
-		exit;
557
-	}
558
-	// autrement c'est une install ad hoc (spikini...), on sait pas faire
547
+    // Si on peut installer, on lance illico
548
+    if (test_espace_prive()) {
549
+        include_spip('inc/headers');
550
+        redirige_url_ecrire('install');
551
+    } else {
552
+        // Si on est dans le site public, dire que qq s'en occupe
553
+        include_spip('inc/minipres');
554
+        utiliser_langue_visiteur();
555
+        echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]);
556
+        exit;
557
+    }
558
+    // autrement c'est une install ad hoc (spikini...), on sait pas faire
559 559
 }
560 560
 
561 561
 // memoriser un tri sessionne eventuel
562 562
 if (
563
-	isset($_REQUEST['var_memotri'])
564
-	and $t = $_REQUEST['var_memotri']
565
-	and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0)
563
+    isset($_REQUEST['var_memotri'])
564
+    and $t = $_REQUEST['var_memotri']
565
+    and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0)
566 566
 ) {
567
-	if (!function_exists('session_set')) {
568
-		include_spip('inc/session');
569
-	}
570
-	$t = preg_replace(',\W,', '_', $t);
571
-	if ($v = _request($t)) {
572
-		session_set($t, $v);
573
-	}
567
+    if (!function_exists('session_set')) {
568
+        include_spip('inc/session');
569
+    }
570
+    $t = preg_replace(',\W,', '_', $t);
571
+    if ($v = _request($t)) {
572
+        session_set($t, $v);
573
+    }
574 574
 }
575 575
 
576 576
 /**
@@ -580,22 +580,22 @@  discard block
 block discarded – undo
580 580
  * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite
581 581
  */
582 582
 if (!defined('_HEADER_COMPOSED_BY')) {
583
-	define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP');
583
+    define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP');
584 584
 }
585 585
 if (!headers_sent() and _HEADER_COMPOSED_BY) {
586
-	if (!defined('_HEADER_VARY')) {
587
-		define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding');
588
-	}
589
-	if (_HEADER_VARY) {
590
-		header(_HEADER_VARY);
591
-	}
592
-	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
593
-		include_spip('inc/filtres_mini');
594
-		header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt'));
595
-	} else {
596
-		// header minimal
597
-		header(_HEADER_COMPOSED_BY . ' @ www.spip.net');
598
-	}
586
+    if (!defined('_HEADER_VARY')) {
587
+        define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding');
588
+    }
589
+    if (_HEADER_VARY) {
590
+        header(_HEADER_VARY);
591
+    }
592
+    if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
593
+        include_spip('inc/filtres_mini');
594
+        header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt'));
595
+    } else {
596
+        // header minimal
597
+        header(_HEADER_COMPOSED_BY . ' @ www.spip.net');
598
+    }
599 599
 }
600 600
 
601 601
 $methode = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ((php_sapi_name() == 'cli') ? 'cli' : ''));
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -51,11 +51,11 @@  discard block
 block discarded – undo
51 51
 define('_DIR_RACINE', _DIR_RESTREINT ? '' : '../');
52 52
 
53 53
 /** chemin absolu vers la racine */
54
-define('_ROOT_RACINE', dirname(__DIR__) . '/');
54
+define('_ROOT_RACINE', dirname(__DIR__).'/');
55 55
 /** chemin absolu vers le repertoire de travail */
56
-define('_ROOT_CWD', getcwd() . '/');
56
+define('_ROOT_CWD', getcwd().'/');
57 57
 /** chemin absolu vers ecrire */
58
-define('_ROOT_RESTREINT', _ROOT_CWD . _DIR_RESTREINT);
58
+define('_ROOT_RESTREINT', _ROOT_CWD._DIR_RESTREINT);
59 59
 
60 60
 // Icones
61 61
 if (!defined('_NOM_IMG_PACK')) {
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
 	define('_NOM_IMG_PACK', 'images/');
64 64
 }
65 65
 /** le chemin http (relatif) vers les images standard */
66
-define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK));
66
+define('_DIR_IMG_PACK', (_DIR_RACINE.'prive/'._NOM_IMG_PACK));
67 67
 
68 68
 /** le chemin php (absolu) vers les images standard (pour hebergement centralise) */
69
-define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK);
69
+define('_ROOT_IMG_PACK', dirname(__DIR__).'/prive/'._NOM_IMG_PACK);
70 70
 
71 71
 if (!defined('_JAVASCRIPT')) {
72 72
 	/** Nom du repertoire des  bibliotheques JavaScript */
73 73
 	define('_JAVASCRIPT', 'javascript/');
74 74
 } // utilisable avec #CHEMIN et find_in_path
75 75
 /** le nom du repertoire des  bibliotheques JavaScript du prive */
76
-define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT));
76
+define('_DIR_JAVASCRIPT', (_DIR_RACINE.'prive/'._JAVASCRIPT));
77 77
 
78 78
 # Le nom des 4 repertoires modifiables par les scripts lances par httpd
79 79
 # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas)
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 
105 105
 // Son emplacement absolu si on le trouve
106 106
 if (
107
-	@file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php')
108
-	or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php'))
107
+	@file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES._NOM_CONFIG.'.php')
108
+	or (@file_exists($f = _ROOT_RESTREINT._NOM_CONFIG.'.php'))
109 109
 ) {
110 110
 	/** Emplacement absolu du fichier d'option */
111 111
 	define('_FILE_OPTIONS', $f);
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 // Inclure l'ecran de securite
130 130
 if (
131 131
 	!defined('_ECRAN_SECURITE')
132
-	and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php')
132
+	and @file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES.'ecran_securite.php')
133 133
 ) {
134 134
 	include $f;
135 135
 }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			// UA plus cibles
151 151
 			. '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti'
152 152
 			. ',i',
153
-			(string)$_SERVER['HTTP_USER_AGENT']
153
+			(string) $_SERVER['HTTP_USER_AGENT']
154 154
 		)
155 155
 	);
156 156
 }
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 # la matrice standard (fichiers definissant les fonctions a inclure)
393 393
 $spip_matrice = [];
394 394
 # les plugins a activer
395
-$plugins = [];  // voir le contenu du repertoire /plugins/
395
+$plugins = []; // voir le contenu du repertoire /plugins/
396 396
 # les surcharges de include_spip()
397 397
 $surcharges = []; // format 'inc_truc' => '/plugins/chose/inc_truc2.php'
398 398
 
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
 //
471 471
 // Charger les fonctions liees aux serveurs Http et Sql.
472 472
 //
473
-require_once _ROOT_RESTREINT . 'inc/utils.php';
474
-require_once _ROOT_RESTREINT . 'base/connect_sql.php';
473
+require_once _ROOT_RESTREINT.'inc/utils.php';
474
+require_once _ROOT_RESTREINT.'base/connect_sql.php';
475 475
 
476 476
 // Definition personnelles eventuelles
477 477
 
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
 // ===> on execute en neutralisant les messages d'erreur
495 495
 
496 496
 spip_initialisation_core(
497
-	(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
498
-	(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
499
-	(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
500
-	(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
497
+	(_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES),
498
+	(_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES),
499
+	(_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES),
500
+	(_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES)
501 501
 );
502 502
 
503 503
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 		// Si on est dans le site public, dire que qq s'en occupe
553 553
 		include_spip('inc/minipres');
554 554
 		utiliser_langue_visiteur();
555
-		echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]);
555
+		echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>"._T('info_travaux_texte').'</p>', ['status' => 503]);
556 556
 		exit;
557 557
 	}
558 558
 	// autrement c'est une install ad hoc (spikini...), on sait pas faire
@@ -591,12 +591,12 @@  discard block
 block discarded – undo
591 591
 	}
592 592
 	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
593 593
 		include_spip('inc/filtres_mini');
594
-		header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt'));
594
+		header(_HEADER_COMPOSED_BY." $spip_version_affichee @ www.spip.net + ".url_absolue(_DIR_VAR.'config.txt'));
595 595
 	} else {
596 596
 		// header minimal
597
-		header(_HEADER_COMPOSED_BY . ' @ www.spip.net');
597
+		header(_HEADER_COMPOSED_BY.' @ www.spip.net');
598 598
 	}
599 599
 }
600 600
 
601 601
 $methode = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ((php_sapi_name() == 'cli') ? 'cli' : ''));
602
-spip_log($methode . ' ' . self() . ' - ' . _FILE_CONNECT, _LOG_DEBUG);
602
+spip_log($methode.' '.self().' - '._FILE_CONNECT, _LOG_DEBUG);
Please login to merge, or discard this patch.
ecrire/iterateur/sql.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -28,208 +28,208 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class IterateurSQL implements Iterator {
30 30
 
31
-	/**
32
-	 * ressource sql
33
-	 *
34
-	 * @var resource|bool
35
-	 */
36
-	protected $sqlresult = false;
37
-
38
-	/**
39
-	 * row sql courante
40
-	 *
41
-	 * @var array|null
42
-	 */
43
-	protected $row = null;
44
-
45
-	protected $firstseek = false;
46
-
47
-	/**
48
-	 * Erreur presente ?
49
-	 *
50
-	 * @var bool
51
-	 **/
52
-	public $err = false;
53
-
54
-	/**
55
-	 * Calcul du total des elements
56
-	 *
57
-	 * @var int|null
58
-	 **/
59
-	public $total = null;
60
-
61
-	/**
62
-	 * selectionner les donnees, ie faire la requete SQL
63
-	 *
64
-	 * @return void
65
-	 */
66
-	protected function select() {
67
-		$this->row = null;
68
-		$v = &$this->command;
69
-		$this->sqlresult = calculer_select(
70
-			$v['select'],
71
-			$v['from'],
72
-			$v['type'],
73
-			$v['where'],
74
-			$v['join'],
75
-			$v['groupby'],
76
-			$v['orderby'],
77
-			$v['limit'],
78
-			$v['having'],
79
-			$v['table'],
80
-			$v['id'],
81
-			$v['connect'],
82
-			$this->info
83
-		);
84
-		$this->err = !$this->sqlresult;
85
-		$this->firstseek = false;
86
-		$this->pos = -1;
87
-
88
-		// pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
89
-		//$this->total = $this->count();
90
-	}
91
-
92
-	/*
31
+    /**
32
+     * ressource sql
33
+     *
34
+     * @var resource|bool
35
+     */
36
+    protected $sqlresult = false;
37
+
38
+    /**
39
+     * row sql courante
40
+     *
41
+     * @var array|null
42
+     */
43
+    protected $row = null;
44
+
45
+    protected $firstseek = false;
46
+
47
+    /**
48
+     * Erreur presente ?
49
+     *
50
+     * @var bool
51
+     **/
52
+    public $err = false;
53
+
54
+    /**
55
+     * Calcul du total des elements
56
+     *
57
+     * @var int|null
58
+     **/
59
+    public $total = null;
60
+
61
+    /**
62
+     * selectionner les donnees, ie faire la requete SQL
63
+     *
64
+     * @return void
65
+     */
66
+    protected function select() {
67
+        $this->row = null;
68
+        $v = &$this->command;
69
+        $this->sqlresult = calculer_select(
70
+            $v['select'],
71
+            $v['from'],
72
+            $v['type'],
73
+            $v['where'],
74
+            $v['join'],
75
+            $v['groupby'],
76
+            $v['orderby'],
77
+            $v['limit'],
78
+            $v['having'],
79
+            $v['table'],
80
+            $v['id'],
81
+            $v['connect'],
82
+            $this->info
83
+        );
84
+        $this->err = !$this->sqlresult;
85
+        $this->firstseek = false;
86
+        $this->pos = -1;
87
+
88
+        // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
89
+        //$this->total = $this->count();
90
+    }
91
+
92
+    /*
93 93
 	 * array command: les commandes d'initialisation
94 94
 	 * array info: les infos sur le squelette
95 95
 	 */
96
-	public function __construct($command, $info = []) {
97
-		$this->type = 'SQL';
98
-		$this->command = $command;
99
-		$this->info = $info;
100
-		$this->select();
101
-	}
102
-
103
-	/**
104
-	 * Rembobiner
105
-	 *
106
-	 * @return bool
107
-	 */
108
-	public function rewind() {
109
-		return ($this->pos > 0)
110
-			? $this->seek(0)
111
-			: true;
112
-	}
113
-
114
-	/**
115
-	 * Verifier l'etat de l'iterateur
116
-	 *
117
-	 * @return bool
118
-	 */
119
-	public function valid() {
120
-		if ($this->err) {
121
-			return false;
122
-		}
123
-		if (!$this->firstseek) {
124
-			$this->next();
125
-		}
126
-
127
-		return is_array($this->row);
128
-	}
129
-
130
-	/**
131
-	 * Valeurs sur la position courante
132
-	 *
133
-	 * @return array
134
-	 */
135
-	public function current() {
136
-		return $this->row;
137
-	}
138
-
139
-	public function key() {
140
-		return $this->pos;
141
-	}
142
-
143
-	/**
144
-	 * Sauter a une position absolue
145
-	 *
146
-	 * @param int $n
147
-	 * @param null|string $continue
148
-	 * @return bool
149
-	 */
150
-	public function seek($n = 0, $continue = null) {
151
-		if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) {
152
-			// SQLite ne sait pas seek(), il faut relancer la query
153
-			// si la position courante est apres la position visee
154
-			// il faut relancer la requete
155
-			if ($this->pos > $n) {
156
-				$this->free();
157
-				$this->select();
158
-				$this->valid();
159
-			}
160
-			// et utiliser la methode par defaut pour se deplacer au bon endroit
161
-			// (sera fait en cas d'echec de cette fonction)
162
-			return false;
163
-		}
164
-		$this->row = sql_fetch($this->sqlresult, $this->command['connect']);
165
-		$this->pos = min($n, $this->count());
166
-
167
-		return true;
168
-	}
169
-
170
-	/**
171
-	 * Avancer d'un cran
172
-	 *
173
-	 * @return void
174
-	 */
175
-	public function next() {
176
-		$this->row = sql_fetch($this->sqlresult, $this->command['connect']);
177
-		$this->pos++;
178
-		$this->firstseek |= true;
179
-	}
180
-
181
-	/**
182
-	 * Avancer et retourner les donnees pour le nouvel element
183
-	 *
184
-	 * @return array|bool|null
185
-	 */
186
-	public function fetch() {
187
-		if ($this->valid()) {
188
-			$r = $this->current();
189
-			$this->next();
190
-		} else {
191
-			$r = false;
192
-		}
193
-
194
-		return $r;
195
-	}
196
-
197
-	/**
198
-	 * liberer les ressources
199
-	 *
200
-	 * @return bool
201
-	 */
202
-	public function free() {
203
-		if (!$this->sqlresult) {
204
-			return true;
205
-		}
206
-		$a = sql_free($this->sqlresult, $this->command['connect']);
207
-		$this->sqlresult = null;
208
-
209
-		return $a;
210
-	}
211
-
212
-	/**
213
-	 * Compter le nombre de resultats
214
-	 *
215
-	 * @return int
216
-	 */
217
-	public function count() {
218
-		if (is_null($this->total)) {
219
-			if (!$this->sqlresult) {
220
-				$this->total = 0;
221
-			} else {
222
-				# cas count(*)
223
-				if (in_array('count(*)', $this->command['select'])) {
224
-					$this->valid();
225
-					$s = $this->current();
226
-					$this->total = $s['count(*)'];
227
-				} else {
228
-					$this->total = sql_count($this->sqlresult, $this->command['connect']);
229
-				}
230
-			}
231
-		}
232
-
233
-		return $this->total;
234
-	}
96
+    public function __construct($command, $info = []) {
97
+        $this->type = 'SQL';
98
+        $this->command = $command;
99
+        $this->info = $info;
100
+        $this->select();
101
+    }
102
+
103
+    /**
104
+     * Rembobiner
105
+     *
106
+     * @return bool
107
+     */
108
+    public function rewind() {
109
+        return ($this->pos > 0)
110
+            ? $this->seek(0)
111
+            : true;
112
+    }
113
+
114
+    /**
115
+     * Verifier l'etat de l'iterateur
116
+     *
117
+     * @return bool
118
+     */
119
+    public function valid() {
120
+        if ($this->err) {
121
+            return false;
122
+        }
123
+        if (!$this->firstseek) {
124
+            $this->next();
125
+        }
126
+
127
+        return is_array($this->row);
128
+    }
129
+
130
+    /**
131
+     * Valeurs sur la position courante
132
+     *
133
+     * @return array
134
+     */
135
+    public function current() {
136
+        return $this->row;
137
+    }
138
+
139
+    public function key() {
140
+        return $this->pos;
141
+    }
142
+
143
+    /**
144
+     * Sauter a une position absolue
145
+     *
146
+     * @param int $n
147
+     * @param null|string $continue
148
+     * @return bool
149
+     */
150
+    public function seek($n = 0, $continue = null) {
151
+        if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) {
152
+            // SQLite ne sait pas seek(), il faut relancer la query
153
+            // si la position courante est apres la position visee
154
+            // il faut relancer la requete
155
+            if ($this->pos > $n) {
156
+                $this->free();
157
+                $this->select();
158
+                $this->valid();
159
+            }
160
+            // et utiliser la methode par defaut pour se deplacer au bon endroit
161
+            // (sera fait en cas d'echec de cette fonction)
162
+            return false;
163
+        }
164
+        $this->row = sql_fetch($this->sqlresult, $this->command['connect']);
165
+        $this->pos = min($n, $this->count());
166
+
167
+        return true;
168
+    }
169
+
170
+    /**
171
+     * Avancer d'un cran
172
+     *
173
+     * @return void
174
+     */
175
+    public function next() {
176
+        $this->row = sql_fetch($this->sqlresult, $this->command['connect']);
177
+        $this->pos++;
178
+        $this->firstseek |= true;
179
+    }
180
+
181
+    /**
182
+     * Avancer et retourner les donnees pour le nouvel element
183
+     *
184
+     * @return array|bool|null
185
+     */
186
+    public function fetch() {
187
+        if ($this->valid()) {
188
+            $r = $this->current();
189
+            $this->next();
190
+        } else {
191
+            $r = false;
192
+        }
193
+
194
+        return $r;
195
+    }
196
+
197
+    /**
198
+     * liberer les ressources
199
+     *
200
+     * @return bool
201
+     */
202
+    public function free() {
203
+        if (!$this->sqlresult) {
204
+            return true;
205
+        }
206
+        $a = sql_free($this->sqlresult, $this->command['connect']);
207
+        $this->sqlresult = null;
208
+
209
+        return $a;
210
+    }
211
+
212
+    /**
213
+     * Compter le nombre de resultats
214
+     *
215
+     * @return int
216
+     */
217
+    public function count() {
218
+        if (is_null($this->total)) {
219
+            if (!$this->sqlresult) {
220
+                $this->total = 0;
221
+            } else {
222
+                # cas count(*)
223
+                if (in_array('count(*)', $this->command['select'])) {
224
+                    $this->valid();
225
+                    $s = $this->current();
226
+                    $this->total = $s['count(*)'];
227
+                } else {
228
+                    $this->total = sql_count($this->sqlresult, $this->command['connect']);
229
+                }
230
+            }
231
+        }
232
+
233
+        return $this->total;
234
+    }
235 235
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 2 patches
Indentation   +635 added lines, -635 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
24
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
24
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
25 25
 }
26 26
 
27 27
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
  *     Description de la boucle complétée des champs
43 43
  */
44 44
 function iterateur_DATA_dist($b) {
45
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
46
-	$b->show = [
47
-		'field' => [
48
-			'cle' => 'STRING',
49
-			'valeur' => 'STRING',
50
-			'*' => 'ALL' // Champ joker *
51
-		]
52
-	];
53
-	$b->select[] = '.valeur';
54
-
55
-	return $b;
45
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
46
+    $b->show = [
47
+        'field' => [
48
+            'cle' => 'STRING',
49
+            'valeur' => 'STRING',
50
+            '*' => 'ALL' // Champ joker *
51
+        ]
52
+    ];
53
+    $b->select[] = '.valeur';
54
+
55
+    return $b;
56 56
 }
57 57
 
58 58
 
@@ -62,522 +62,522 @@  discard block
 block discarded – undo
62 62
  * Pour itérer sur des données quelconques (transformables en tableau)
63 63
  */
64 64
 class IterateurDATA implements Iterator {
65
-	/**
66
-	 * tableau de donnees
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $tableau = [];
71
-
72
-	/**
73
-	 * Conditions de filtrage
74
-	 * ie criteres de selection
75
-	 *
76
-	 * @var array
77
-	 */
78
-	protected $filtre = [];
79
-
80
-
81
-	/**
82
-	 * Cle courante
83
-	 *
84
-	 * @var null
85
-	 */
86
-	protected $cle = null;
87
-
88
-	/**
89
-	 * Valeur courante
90
-	 *
91
-	 * @var null
92
-	 */
93
-	protected $valeur = null;
94
-
95
-	/**
96
-	 * Erreur presente ?
97
-	 *
98
-	 * @var bool
99
-	 **/
100
-	public $err = false;
101
-
102
-	/**
103
-	 * Calcul du total des elements
104
-	 *
105
-	 * @var int|null
106
-	 **/
107
-	public $total = null;
108
-
109
-	/**
110
-	 * Constructeur
111
-	 *
112
-	 * @param  $command
113
-	 * @param array $info
114
-	 */
115
-	public function __construct($command, $info = []) {
116
-		$this->type = 'DATA';
117
-		$this->command = $command;
118
-		$this->info = $info;
119
-
120
-		$this->select($command);
121
-	}
122
-
123
-	/**
124
-	 * Revenir au depart
125
-	 *
126
-	 * @return void
127
-	 */
128
-	public function rewind() {
129
-		reset($this->tableau);
130
-		$this->cle = key($this->tableau);
131
-		$this->valeur = current($this->tableau);
132
-		next($this->tableau);
133
-	}
134
-
135
-	/**
136
-	 * Déclarer les critères exceptions
137
-	 *
138
-	 * @return array
139
-	 */
140
-	public function exception_des_criteres() {
141
-		return ['tableau'];
142
-	}
143
-
144
-	/**
145
-	 * Récupérer depuis le cache si possible
146
-	 *
147
-	 * @param string $cle
148
-	 * @return mixed
149
-	 */
150
-	protected function cache_get($cle) {
151
-		if (!$cle) {
152
-			return;
153
-		}
154
-		# utiliser memoization si dispo
155
-		if (!function_exists('cache_get')) {
156
-			return;
157
-		}
158
-
159
-		return cache_get($cle);
160
-	}
161
-
162
-	/**
163
-	 * Stocker en cache si possible
164
-	 *
165
-	 * @param string $cle
166
-	 * @param int $ttl
167
-	 * @param null|mixed $valeur
168
-	 * @return bool
169
-	 */
170
-	protected function cache_set($cle, $ttl, $valeur = null) {
171
-		if (!$cle) {
172
-			return;
173
-		}
174
-		if (is_null($valeur)) {
175
-			$valeur = $this->tableau;
176
-		}
177
-		# utiliser memoization si dispo
178
-		if (!function_exists('cache_set')) {
179
-			return;
180
-		}
181
-
182
-		return cache_set(
183
-			$cle,
184
-			[
185
-				'data' => $valeur,
186
-				'time' => time(),
187
-				'ttl' => $ttl
188
-			],
189
-			3600 + $ttl
190
-		);
191
-		# conserver le cache 1h de plus que la validite demandee,
192
-		# pour le cas ou le serveur distant ne reponde plus
193
-	}
194
-
195
-	/**
196
-	 * Aller chercher les données de la boucle DATA
197
-	 *
198
-	 * @throws Exception
199
-	 * @param array $command
200
-	 * @return void
201
-	 */
202
-	protected function select($command) {
203
-
204
-		// l'iterateur DATA peut etre appele en passant (data:type)
205
-		// le type se retrouve dans la commande 'from'
206
-		// dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
207
-		if (isset($this->command['from'][0])) {
208
-			if (isset($this->command['source']) and is_array($this->command['source'])) {
209
-				array_unshift($this->command['source'], $this->command['sourcemode']);
210
-			}
211
-			$this->command['sourcemode'] = $this->command['from'][0];
212
-		}
213
-
214
-		// cherchons differents moyens de creer le tableau de donnees
215
-		// les commandes connues pour l'iterateur DATA
216
-		// sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
217
-
218
-		// {source format, [URL], [arg2]...}
219
-		if (
220
-			isset($this->command['source'])
221
-			and isset($this->command['sourcemode'])
222
-		) {
223
-			$this->select_source();
224
-		}
225
-
226
-		// Critere {liste X1, X2, X3}
227
-		if (isset($this->command['liste'])) {
228
-			$this->select_liste();
229
-		}
230
-		if (isset($this->command['enum'])) {
231
-			$this->select_enum();
232
-		}
233
-
234
-		// Si a ce stade on n'a pas de table, il y a un bug
235
-		if (!is_array($this->tableau)) {
236
-			$this->err = true;
237
-			spip_log('erreur datasource ' . var_export($command, true));
238
-		}
239
-
240
-		// {datapath query.results}
241
-		// extraire le chemin "query.results" du tableau de donnees
242
-		if (
243
-			!$this->err
244
-			and isset($this->command['datapath'])
245
-			and is_array($this->command['datapath'])
246
-		) {
247
-			$this->select_datapath();
248
-		}
249
-
250
-		// tri {par x}
251
-		if ($this->command['orderby']) {
252
-			$this->select_orderby();
253
-		}
254
-
255
-		// grouper les resultats {fusion /x/y/z} ;
256
-		if ($this->command['groupby']) {
257
-			$this->select_groupby();
258
-		}
259
-
260
-		$this->rewind();
261
-		#var_dump($this->tableau);
262
-	}
263
-
264
-
265
-	/**
266
-	 * Aller chercher les donnees de la boucle DATA
267
-	 * depuis une source
268
-	 * {source format, [URL], [arg2]...}
269
-	 */
270
-	protected function select_source() {
271
-		# un peu crado : avant de charger le cache il faut charger
272
-		# les class indispensables, sinon PHP ne saura pas gerer
273
-		# l'objet en cache ; cf plugins/icalendar
274
-		# perf : pas de fonction table_to_array ! (table est deja un array)
275
-		if (
276
-			isset($this->command['sourcemode'])
277
-			and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278
-		) {
279
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
280
-		}
281
-
282
-		# le premier argument peut etre un array, une URL etc.
283
-		$src = $this->command['source'][0];
284
-
285
-		# avons-nous un cache dispo ?
286
-		$cle = null;
287
-		if (is_string($src)) {
288
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
289
-		}
290
-
291
-		$cache = $this->cache_get($cle);
292
-		if (isset($this->command['datacache'])) {
293
-			$ttl = intval($this->command['datacache']);
294
-		}
295
-		if (
296
-			$cache
297
-			and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
298
-				> time())
299
-			and !(_request('var_mode') === 'recalcul'
300
-				and include_spip('inc/autoriser')
301
-				and autoriser('recalcul')
302
-			)
303
-		) {
304
-			$this->tableau = $cache['data'];
305
-		} else {
306
-			try {
307
-				if (
308
-					isset($this->command['sourcemode'])
309
-					and in_array(
310
-						$this->command['sourcemode'],
311
-						['table', 'array', 'tableau']
312
-					)
313
-				) {
314
-					if (
315
-						is_array($a = $src)
316
-						or (is_string($a)
317
-							and $a = str_replace('&quot;', '"', $a) # fragile!
318
-							and is_array($a = @unserialize($a)))
319
-					) {
320
-						$this->tableau = $a;
321
-					}
322
-				} else {
323
-					$data = $src;
324
-					if (is_string($src)) {
325
-						if (tester_url_absolue($src)) {
326
-							include_spip('inc/distant');
327
-							$data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
328
-							$data = $data['page'] ?? '';
329
-							if (!$data) {
330
-								throw new Exception('404');
331
-							}
332
-							if (!isset($ttl)) {
333
-								$ttl = 24 * 3600;
334
-							}
335
-						} elseif (@is_dir($src)) {
336
-							$data = $src;
337
-						} elseif (@is_readable($src) && @is_file($src)) {
338
-							$data = spip_file_get_contents($src);
339
-						}
340
-						if (!isset($ttl)) {
341
-							$ttl = 10;
342
-						}
343
-					}
344
-
345
-					if (
346
-						!$this->err
347
-						and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
348
-					) {
349
-						$args = $this->command['source'];
350
-						$args[0] = $data;
351
-						if (is_array($a = $data_to_array(...$args))) {
352
-							$this->tableau = $a;
353
-						}
354
-					}
355
-				}
356
-
357
-				if (!is_array($this->tableau)) {
358
-					$this->err = true;
359
-				}
360
-
361
-				if (!$this->err and isset($ttl) and $ttl > 0) {
362
-					$this->cache_set($cle, $ttl);
363
-				}
364
-			} catch (Exception $e) {
365
-				$e = $e->getMessage();
366
-				$err = sprintf(
367
-					"[%s, %s] $e",
368
-					$src,
369
-					$this->command['sourcemode']
370
-				);
371
-				erreur_squelette([$err, []]);
372
-				$this->err = true;
373
-			}
374
-		}
375
-
376
-		# en cas d'erreur, utiliser le cache si encore dispo
377
-		if (
378
-			$this->err
379
-			and $cache
380
-		) {
381
-			$this->tableau = $cache['data'];
382
-			$this->err = false;
383
-		}
384
-	}
385
-
386
-
387
-	/**
388
-	 * Retourne un tableau donne depuis un critère liste
389
-	 *
390
-	 * Critère `{liste X1, X2, X3}`
391
-	 *
392
-	 * @see critere_DATA_liste_dist()
393
-	 *
394
-	 **/
395
-	protected function select_liste() {
396
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
397
-		if (!isset($this->command['liste'][1])) {
398
-			if (!is_array($this->command['liste'][0])) {
399
-				$this->command['liste'] = explode(',', $this->command['liste'][0]);
400
-			} else {
401
-				$this->command['liste'] = $this->command['liste'][0];
402
-			}
403
-		}
404
-		$this->tableau = $this->command['liste'];
405
-	}
406
-
407
-	/**
408
-	 * Retourne un tableau donne depuis un critere liste
409
-	 * Critere {enum Xmin, Xmax}
410
-	 *
411
-	 **/
412
-	protected function select_enum() {
413
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
414
-		if (!isset($this->command['enum'][1])) {
415
-			if (!is_array($this->command['enum'][0])) {
416
-				$this->command['enum'] = explode(',', $this->command['enum'][0]);
417
-			} else {
418
-				$this->command['enum'] = $this->command['enum'][0];
419
-			}
420
-		}
421
-		if (count($this->command['enum']) >= 3) {
422
-			$enum = range(
423
-				array_shift($this->command['enum']),
424
-				array_shift($this->command['enum']),
425
-				array_shift($this->command['enum'])
426
-			);
427
-		} else {
428
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
429
-		}
430
-		$this->tableau = $enum;
431
-	}
432
-
433
-
434
-	/**
435
-	 * extraire le chemin "query.results" du tableau de donnees
436
-	 * {datapath query.results}
437
-	 *
438
-	 **/
439
-	protected function select_datapath() {
440
-		$base = reset($this->command['datapath']);
441
-		if (strlen($base = ltrim(trim($base), '/'))) {
442
-			$this->tableau = table_valeur($this->tableau, $base);
443
-			if (!is_array($this->tableau)) {
444
-				$this->tableau = [];
445
-				$this->err = true;
446
-				spip_log("datapath '$base' absent");
447
-			}
448
-		}
449
-	}
450
-
451
-	/**
452
-	 * Ordonner les resultats
453
-	 * {par x}
454
-	 *
455
-	 **/
456
-	protected function select_orderby() {
457
-		$sortfunc = '';
458
-		$aleas = 0;
459
-		foreach ($this->command['orderby'] as $tri) {
460
-			// virer le / initial pour les criteres de la forme {par /xx}
461
-			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
462
-				$r = array_pad($r, 3, null);
463
-
464
-				// tri par cle
465
-				if ($r[1] == 'cle') {
466
-					if (isset($r[2]) and $r[2]) {
467
-						krsort($this->tableau);
468
-					} else {
469
-						ksort($this->tableau);
470
-					}
471
-				} # {par hasard}
472
-				else {
473
-					if ($r[1] == 'hasard') {
474
-						$k = array_keys($this->tableau);
475
-						shuffle($k);
476
-						$v = [];
477
-						foreach ($k as $cle) {
478
-							$v[$cle] = $this->tableau[$cle];
479
-						}
480
-						$this->tableau = $v;
481
-					} else {
482
-						# {par valeur}
483
-						if ($r[1] == 'valeur') {
484
-							$tv = '%s';
485
-						} # {par valeur/xx/yy} ??
486
-						else {
487
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
488
-						}
489
-						$sortfunc .= '
65
+    /**
66
+     * tableau de donnees
67
+     *
68
+     * @var array
69
+     */
70
+    protected $tableau = [];
71
+
72
+    /**
73
+     * Conditions de filtrage
74
+     * ie criteres de selection
75
+     *
76
+     * @var array
77
+     */
78
+    protected $filtre = [];
79
+
80
+
81
+    /**
82
+     * Cle courante
83
+     *
84
+     * @var null
85
+     */
86
+    protected $cle = null;
87
+
88
+    /**
89
+     * Valeur courante
90
+     *
91
+     * @var null
92
+     */
93
+    protected $valeur = null;
94
+
95
+    /**
96
+     * Erreur presente ?
97
+     *
98
+     * @var bool
99
+     **/
100
+    public $err = false;
101
+
102
+    /**
103
+     * Calcul du total des elements
104
+     *
105
+     * @var int|null
106
+     **/
107
+    public $total = null;
108
+
109
+    /**
110
+     * Constructeur
111
+     *
112
+     * @param  $command
113
+     * @param array $info
114
+     */
115
+    public function __construct($command, $info = []) {
116
+        $this->type = 'DATA';
117
+        $this->command = $command;
118
+        $this->info = $info;
119
+
120
+        $this->select($command);
121
+    }
122
+
123
+    /**
124
+     * Revenir au depart
125
+     *
126
+     * @return void
127
+     */
128
+    public function rewind() {
129
+        reset($this->tableau);
130
+        $this->cle = key($this->tableau);
131
+        $this->valeur = current($this->tableau);
132
+        next($this->tableau);
133
+    }
134
+
135
+    /**
136
+     * Déclarer les critères exceptions
137
+     *
138
+     * @return array
139
+     */
140
+    public function exception_des_criteres() {
141
+        return ['tableau'];
142
+    }
143
+
144
+    /**
145
+     * Récupérer depuis le cache si possible
146
+     *
147
+     * @param string $cle
148
+     * @return mixed
149
+     */
150
+    protected function cache_get($cle) {
151
+        if (!$cle) {
152
+            return;
153
+        }
154
+        # utiliser memoization si dispo
155
+        if (!function_exists('cache_get')) {
156
+            return;
157
+        }
158
+
159
+        return cache_get($cle);
160
+    }
161
+
162
+    /**
163
+     * Stocker en cache si possible
164
+     *
165
+     * @param string $cle
166
+     * @param int $ttl
167
+     * @param null|mixed $valeur
168
+     * @return bool
169
+     */
170
+    protected function cache_set($cle, $ttl, $valeur = null) {
171
+        if (!$cle) {
172
+            return;
173
+        }
174
+        if (is_null($valeur)) {
175
+            $valeur = $this->tableau;
176
+        }
177
+        # utiliser memoization si dispo
178
+        if (!function_exists('cache_set')) {
179
+            return;
180
+        }
181
+
182
+        return cache_set(
183
+            $cle,
184
+            [
185
+                'data' => $valeur,
186
+                'time' => time(),
187
+                'ttl' => $ttl
188
+            ],
189
+            3600 + $ttl
190
+        );
191
+        # conserver le cache 1h de plus que la validite demandee,
192
+        # pour le cas ou le serveur distant ne reponde plus
193
+    }
194
+
195
+    /**
196
+     * Aller chercher les données de la boucle DATA
197
+     *
198
+     * @throws Exception
199
+     * @param array $command
200
+     * @return void
201
+     */
202
+    protected function select($command) {
203
+
204
+        // l'iterateur DATA peut etre appele en passant (data:type)
205
+        // le type se retrouve dans la commande 'from'
206
+        // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
207
+        if (isset($this->command['from'][0])) {
208
+            if (isset($this->command['source']) and is_array($this->command['source'])) {
209
+                array_unshift($this->command['source'], $this->command['sourcemode']);
210
+            }
211
+            $this->command['sourcemode'] = $this->command['from'][0];
212
+        }
213
+
214
+        // cherchons differents moyens de creer le tableau de donnees
215
+        // les commandes connues pour l'iterateur DATA
216
+        // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
217
+
218
+        // {source format, [URL], [arg2]...}
219
+        if (
220
+            isset($this->command['source'])
221
+            and isset($this->command['sourcemode'])
222
+        ) {
223
+            $this->select_source();
224
+        }
225
+
226
+        // Critere {liste X1, X2, X3}
227
+        if (isset($this->command['liste'])) {
228
+            $this->select_liste();
229
+        }
230
+        if (isset($this->command['enum'])) {
231
+            $this->select_enum();
232
+        }
233
+
234
+        // Si a ce stade on n'a pas de table, il y a un bug
235
+        if (!is_array($this->tableau)) {
236
+            $this->err = true;
237
+            spip_log('erreur datasource ' . var_export($command, true));
238
+        }
239
+
240
+        // {datapath query.results}
241
+        // extraire le chemin "query.results" du tableau de donnees
242
+        if (
243
+            !$this->err
244
+            and isset($this->command['datapath'])
245
+            and is_array($this->command['datapath'])
246
+        ) {
247
+            $this->select_datapath();
248
+        }
249
+
250
+        // tri {par x}
251
+        if ($this->command['orderby']) {
252
+            $this->select_orderby();
253
+        }
254
+
255
+        // grouper les resultats {fusion /x/y/z} ;
256
+        if ($this->command['groupby']) {
257
+            $this->select_groupby();
258
+        }
259
+
260
+        $this->rewind();
261
+        #var_dump($this->tableau);
262
+    }
263
+
264
+
265
+    /**
266
+     * Aller chercher les donnees de la boucle DATA
267
+     * depuis une source
268
+     * {source format, [URL], [arg2]...}
269
+     */
270
+    protected function select_source() {
271
+        # un peu crado : avant de charger le cache il faut charger
272
+        # les class indispensables, sinon PHP ne saura pas gerer
273
+        # l'objet en cache ; cf plugins/icalendar
274
+        # perf : pas de fonction table_to_array ! (table est deja un array)
275
+        if (
276
+            isset($this->command['sourcemode'])
277
+            and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278
+        ) {
279
+            charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
280
+        }
281
+
282
+        # le premier argument peut etre un array, une URL etc.
283
+        $src = $this->command['source'][0];
284
+
285
+        # avons-nous un cache dispo ?
286
+        $cle = null;
287
+        if (is_string($src)) {
288
+            $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
289
+        }
290
+
291
+        $cache = $this->cache_get($cle);
292
+        if (isset($this->command['datacache'])) {
293
+            $ttl = intval($this->command['datacache']);
294
+        }
295
+        if (
296
+            $cache
297
+            and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
298
+                > time())
299
+            and !(_request('var_mode') === 'recalcul'
300
+                and include_spip('inc/autoriser')
301
+                and autoriser('recalcul')
302
+            )
303
+        ) {
304
+            $this->tableau = $cache['data'];
305
+        } else {
306
+            try {
307
+                if (
308
+                    isset($this->command['sourcemode'])
309
+                    and in_array(
310
+                        $this->command['sourcemode'],
311
+                        ['table', 'array', 'tableau']
312
+                    )
313
+                ) {
314
+                    if (
315
+                        is_array($a = $src)
316
+                        or (is_string($a)
317
+                            and $a = str_replace('&quot;', '"', $a) # fragile!
318
+                            and is_array($a = @unserialize($a)))
319
+                    ) {
320
+                        $this->tableau = $a;
321
+                    }
322
+                } else {
323
+                    $data = $src;
324
+                    if (is_string($src)) {
325
+                        if (tester_url_absolue($src)) {
326
+                            include_spip('inc/distant');
327
+                            $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
328
+                            $data = $data['page'] ?? '';
329
+                            if (!$data) {
330
+                                throw new Exception('404');
331
+                            }
332
+                            if (!isset($ttl)) {
333
+                                $ttl = 24 * 3600;
334
+                            }
335
+                        } elseif (@is_dir($src)) {
336
+                            $data = $src;
337
+                        } elseif (@is_readable($src) && @is_file($src)) {
338
+                            $data = spip_file_get_contents($src);
339
+                        }
340
+                        if (!isset($ttl)) {
341
+                            $ttl = 10;
342
+                        }
343
+                    }
344
+
345
+                    if (
346
+                        !$this->err
347
+                        and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
348
+                    ) {
349
+                        $args = $this->command['source'];
350
+                        $args[0] = $data;
351
+                        if (is_array($a = $data_to_array(...$args))) {
352
+                            $this->tableau = $a;
353
+                        }
354
+                    }
355
+                }
356
+
357
+                if (!is_array($this->tableau)) {
358
+                    $this->err = true;
359
+                }
360
+
361
+                if (!$this->err and isset($ttl) and $ttl > 0) {
362
+                    $this->cache_set($cle, $ttl);
363
+                }
364
+            } catch (Exception $e) {
365
+                $e = $e->getMessage();
366
+                $err = sprintf(
367
+                    "[%s, %s] $e",
368
+                    $src,
369
+                    $this->command['sourcemode']
370
+                );
371
+                erreur_squelette([$err, []]);
372
+                $this->err = true;
373
+            }
374
+        }
375
+
376
+        # en cas d'erreur, utiliser le cache si encore dispo
377
+        if (
378
+            $this->err
379
+            and $cache
380
+        ) {
381
+            $this->tableau = $cache['data'];
382
+            $this->err = false;
383
+        }
384
+    }
385
+
386
+
387
+    /**
388
+     * Retourne un tableau donne depuis un critère liste
389
+     *
390
+     * Critère `{liste X1, X2, X3}`
391
+     *
392
+     * @see critere_DATA_liste_dist()
393
+     *
394
+     **/
395
+    protected function select_liste() {
396
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
397
+        if (!isset($this->command['liste'][1])) {
398
+            if (!is_array($this->command['liste'][0])) {
399
+                $this->command['liste'] = explode(',', $this->command['liste'][0]);
400
+            } else {
401
+                $this->command['liste'] = $this->command['liste'][0];
402
+            }
403
+        }
404
+        $this->tableau = $this->command['liste'];
405
+    }
406
+
407
+    /**
408
+     * Retourne un tableau donne depuis un critere liste
409
+     * Critere {enum Xmin, Xmax}
410
+     *
411
+     **/
412
+    protected function select_enum() {
413
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
414
+        if (!isset($this->command['enum'][1])) {
415
+            if (!is_array($this->command['enum'][0])) {
416
+                $this->command['enum'] = explode(',', $this->command['enum'][0]);
417
+            } else {
418
+                $this->command['enum'] = $this->command['enum'][0];
419
+            }
420
+        }
421
+        if (count($this->command['enum']) >= 3) {
422
+            $enum = range(
423
+                array_shift($this->command['enum']),
424
+                array_shift($this->command['enum']),
425
+                array_shift($this->command['enum'])
426
+            );
427
+        } else {
428
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
429
+        }
430
+        $this->tableau = $enum;
431
+    }
432
+
433
+
434
+    /**
435
+     * extraire le chemin "query.results" du tableau de donnees
436
+     * {datapath query.results}
437
+     *
438
+     **/
439
+    protected function select_datapath() {
440
+        $base = reset($this->command['datapath']);
441
+        if (strlen($base = ltrim(trim($base), '/'))) {
442
+            $this->tableau = table_valeur($this->tableau, $base);
443
+            if (!is_array($this->tableau)) {
444
+                $this->tableau = [];
445
+                $this->err = true;
446
+                spip_log("datapath '$base' absent");
447
+            }
448
+        }
449
+    }
450
+
451
+    /**
452
+     * Ordonner les resultats
453
+     * {par x}
454
+     *
455
+     **/
456
+    protected function select_orderby() {
457
+        $sortfunc = '';
458
+        $aleas = 0;
459
+        foreach ($this->command['orderby'] as $tri) {
460
+            // virer le / initial pour les criteres de la forme {par /xx}
461
+            if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
462
+                $r = array_pad($r, 3, null);
463
+
464
+                // tri par cle
465
+                if ($r[1] == 'cle') {
466
+                    if (isset($r[2]) and $r[2]) {
467
+                        krsort($this->tableau);
468
+                    } else {
469
+                        ksort($this->tableau);
470
+                    }
471
+                } # {par hasard}
472
+                else {
473
+                    if ($r[1] == 'hasard') {
474
+                        $k = array_keys($this->tableau);
475
+                        shuffle($k);
476
+                        $v = [];
477
+                        foreach ($k as $cle) {
478
+                            $v[$cle] = $this->tableau[$cle];
479
+                        }
480
+                        $this->tableau = $v;
481
+                    } else {
482
+                        # {par valeur}
483
+                        if ($r[1] == 'valeur') {
484
+                            $tv = '%s';
485
+                        } # {par valeur/xx/yy} ??
486
+                        else {
487
+                            $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
488
+                        }
489
+                        $sortfunc .= '
490 490
 					$a = ' . sprintf($tv, '$aa') . ';
491 491
 					$b = ' . sprintf($tv, '$bb') . ';
492 492
 					if ($a <> $b)
493 493
 						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
494
-					}
495
-				}
496
-			}
497
-		}
498
-
499
-		if ($sortfunc) {
500
-			$sortfunc .= "\n return 0;";
501
-			uasort($this->tableau, function ($aa, $bb) use ($sortfunc) {
502
-				return eval($sortfunc);
503
-			});
504
-		}
505
-	}
506
-
507
-
508
-	/**
509
-	 * Grouper les resultats
510
-	 * {fusion /x/y/z}
511
-	 *
512
-	 **/
513
-	protected function select_groupby() {
514
-		// virer le / initial pour les criteres de la forme {fusion /xx}
515
-		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
516
-			$vu = [];
517
-			foreach ($this->tableau as $k => $v) {
518
-				$val = table_valeur($v, $fusion);
519
-				if (isset($vu[$val])) {
520
-					unset($this->tableau[$k]);
521
-				} else {
522
-					$vu[$val] = true;
523
-				}
524
-			}
525
-		}
526
-	}
527
-
528
-
529
-	/**
530
-	 * L'iterateur est-il encore valide ?
531
-	 *
532
-	 * @return bool
533
-	 */
534
-	public function valid() {
535
-		return !is_null($this->cle);
536
-	}
537
-
538
-	/**
539
-	 * Retourner la valeur
540
-	 *
541
-	 * @return null
542
-	 */
543
-	public function current() {
544
-		return $this->valeur;
545
-	}
546
-
547
-	/**
548
-	 * Retourner la cle
549
-	 *
550
-	 * @return null
551
-	 */
552
-	public function key() {
553
-		return $this->cle;
554
-	}
555
-
556
-	/**
557
-	 * Passer a la valeur suivante
558
-	 *
559
-	 * @return void
560
-	 */
561
-	public function next() {
562
-		if ($this->valid()) {
563
-			$this->cle = key($this->tableau);
564
-			$this->valeur = current($this->tableau);
565
-			next($this->tableau);
566
-		}
567
-	}
568
-
569
-	/**
570
-	 * Compter le nombre total de resultats
571
-	 *
572
-	 * @return int
573
-	 */
574
-	public function count() {
575
-		if (is_null($this->total)) {
576
-			$this->total = count($this->tableau);
577
-		}
578
-
579
-		return $this->total;
580
-	}
494
+                    }
495
+                }
496
+            }
497
+        }
498
+
499
+        if ($sortfunc) {
500
+            $sortfunc .= "\n return 0;";
501
+            uasort($this->tableau, function ($aa, $bb) use ($sortfunc) {
502
+                return eval($sortfunc);
503
+            });
504
+        }
505
+    }
506
+
507
+
508
+    /**
509
+     * Grouper les resultats
510
+     * {fusion /x/y/z}
511
+     *
512
+     **/
513
+    protected function select_groupby() {
514
+        // virer le / initial pour les criteres de la forme {fusion /xx}
515
+        if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
516
+            $vu = [];
517
+            foreach ($this->tableau as $k => $v) {
518
+                $val = table_valeur($v, $fusion);
519
+                if (isset($vu[$val])) {
520
+                    unset($this->tableau[$k]);
521
+                } else {
522
+                    $vu[$val] = true;
523
+                }
524
+            }
525
+        }
526
+    }
527
+
528
+
529
+    /**
530
+     * L'iterateur est-il encore valide ?
531
+     *
532
+     * @return bool
533
+     */
534
+    public function valid() {
535
+        return !is_null($this->cle);
536
+    }
537
+
538
+    /**
539
+     * Retourner la valeur
540
+     *
541
+     * @return null
542
+     */
543
+    public function current() {
544
+        return $this->valeur;
545
+    }
546
+
547
+    /**
548
+     * Retourner la cle
549
+     *
550
+     * @return null
551
+     */
552
+    public function key() {
553
+        return $this->cle;
554
+    }
555
+
556
+    /**
557
+     * Passer a la valeur suivante
558
+     *
559
+     * @return void
560
+     */
561
+    public function next() {
562
+        if ($this->valid()) {
563
+            $this->cle = key($this->tableau);
564
+            $this->valeur = current($this->tableau);
565
+            next($this->tableau);
566
+        }
567
+    }
568
+
569
+    /**
570
+     * Compter le nombre total de resultats
571
+     *
572
+     * @return int
573
+     */
574
+    public function count() {
575
+        if (is_null($this->total)) {
576
+            $this->total = count($this->tableau);
577
+        }
578
+
579
+        return $this->total;
580
+    }
581 581
 }
582 582
 
583 583
 /*
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
  * @return array
592 592
  */
593 593
 function inc_file_to_array_dist($data) {
594
-	return preg_split('/\r?\n/', $data);
594
+    return preg_split('/\r?\n/', $data);
595 595
 }
596 596
 
597 597
 /**
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
  * @return array
601 601
  */
602 602
 function inc_plugins_to_array_dist() {
603
-	include_spip('inc/plugin');
603
+    include_spip('inc/plugin');
604 604
 
605
-	return liste_chemin_plugin_actifs();
605
+    return liste_chemin_plugin_actifs();
606 606
 }
607 607
 
608 608
 /**
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
  * @return array
613 613
  */
614 614
 function inc_xml_to_array_dist($data) {
615
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
615
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
616 616
 }
617 617
 
618 618
 /**
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
  *
625 625
  */
626 626
 function inc_object_to_array($object) {
627
-	if (!is_object($object) && !is_array($object)) {
628
-		return $object;
629
-	}
630
-	if (is_object($object)) {
631
-		$object = get_object_vars($object);
632
-	}
633
-
634
-	return array_map('inc_object_to_array', $object);
627
+    if (!is_object($object) && !is_array($object)) {
628
+        return $object;
629
+    }
630
+    if (is_object($object)) {
631
+        $object = get_object_vars($object);
632
+    }
633
+
634
+    return array_map('inc_object_to_array', $object);
635 635
 }
636 636
 
637 637
 /**
@@ -641,20 +641,20 @@  discard block
 block discarded – undo
641 641
  * @return array|bool
642 642
  */
643 643
 function inc_sql_to_array_dist($data) {
644
-	# sortir le connecteur de $data
645
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
-	$serveur = (string)$v[1];
647
-	$req = trim($v[2]);
648
-	if ($s = sql_query($req, $serveur)) {
649
-		$r = [];
650
-		while ($t = sql_fetch($s)) {
651
-			$r[] = $t;
652
-		}
653
-
654
-		return $r;
655
-	}
656
-
657
-	return false;
644
+    # sortir le connecteur de $data
645
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
+    $serveur = (string)$v[1];
647
+    $req = trim($v[2]);
648
+    if ($s = sql_query($req, $serveur)) {
649
+        $r = [];
650
+        while ($t = sql_fetch($s)) {
651
+            $r[] = $t;
652
+        }
653
+
654
+        return $r;
655
+    }
656
+
657
+    return false;
658 658
 }
659 659
 
660 660
 /**
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
  * @return array|bool
665 665
  */
666 666
 function inc_json_to_array_dist($data) {
667
-	if (is_array($json = json_decode($data, true))) {
668
-		return (array)$json;
669
-	}
667
+    if (is_array($json = json_decode($data, true))) {
668
+        return (array)$json;
669
+    }
670 670
 }
671 671
 
672 672
 /**
@@ -676,30 +676,30 @@  discard block
 block discarded – undo
676 676
  * @return array|bool
677 677
  */
678 678
 function inc_csv_to_array_dist($data) {
679
-	include_spip('inc/csv');
680
-	list($entete, $csv) = analyse_csv($data);
681
-	array_unshift($csv, $entete);
682
-
683
-	include_spip('inc/charsets');
684
-	$i = 1;
685
-	foreach ($entete as $k => $v) {
686
-		if (trim($v) == '') {
687
-			$v = 'col' . $i;
688
-		} // reperer des eventuelles cases vides
689
-		if (is_numeric($v) and $v < 0) {
690
-			$v = '__' . $v;
691
-		} // ne pas risquer d'ecraser une cle numerique
692
-		if (is_numeric($v)) {
693
-			$v = '_' . $v;
694
-		} // ne pas risquer d'ecraser une cle numerique
695
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
696
-		foreach ($csv as &$item) {
697
-			$item[$v] = &$item[$k];
698
-		}
699
-		$i++;
700
-	}
701
-
702
-	return $csv;
679
+    include_spip('inc/csv');
680
+    list($entete, $csv) = analyse_csv($data);
681
+    array_unshift($csv, $entete);
682
+
683
+    include_spip('inc/charsets');
684
+    $i = 1;
685
+    foreach ($entete as $k => $v) {
686
+        if (trim($v) == '') {
687
+            $v = 'col' . $i;
688
+        } // reperer des eventuelles cases vides
689
+        if (is_numeric($v) and $v < 0) {
690
+            $v = '__' . $v;
691
+        } // ne pas risquer d'ecraser une cle numerique
692
+        if (is_numeric($v)) {
693
+            $v = '_' . $v;
694
+        } // ne pas risquer d'ecraser une cle numerique
695
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
696
+        foreach ($csv as &$item) {
697
+            $item[$v] = &$item[$k];
698
+        }
699
+        $i++;
700
+    }
701
+
702
+    return $csv;
703 703
 }
704 704
 
705 705
 /**
@@ -709,12 +709,12 @@  discard block
 block discarded – undo
709 709
  * @return array|bool
710 710
  */
711 711
 function inc_rss_to_array_dist($data) {
712
-	include_spip('inc/syndic');
713
-	if (is_array($rss = analyser_backend($data))) {
714
-		$tableau = $rss;
715
-	}
712
+    include_spip('inc/syndic');
713
+    if (is_array($rss = analyser_backend($data))) {
714
+        $tableau = $rss;
715
+    }
716 716
 
717
-	return $tableau;
717
+    return $tableau;
718 718
 }
719 719
 
720 720
 /**
@@ -724,9 +724,9 @@  discard block
 block discarded – undo
724 724
  * @return array|bool
725 725
  */
726 726
 function inc_atom_to_array_dist($data) {
727
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
727
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
728 728
 
729
-	return $rss_to_array($data);
729
+    return $rss_to_array($data);
730 730
 }
731 731
 
732 732
 /**
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
  * @return array|bool
738 738
  */
739 739
 function inc_glob_to_array_dist($data) {
740
-	$a = glob(
741
-		$data,
742
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
743
-	);
740
+    $a = glob(
741
+        $data,
742
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
743
+    );
744 744
 
745
-	return $a ? $a : [];
745
+    return $a ? $a : [];
746 746
 }
747 747
 
748 748
 /**
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
  * @throws Exception
754 754
  */
755 755
 function inc_yaml_to_array_dist($data) {
756
-	include_spip('inc/yaml-mini');
757
-	if (!function_exists('yaml_decode')) {
758
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
756
+    include_spip('inc/yaml-mini');
757
+    if (!function_exists('yaml_decode')) {
758
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
759 759
 
760
-		return false;
761
-	}
760
+        return false;
761
+    }
762 762
 
763
-	return yaml_decode($data);
763
+    return yaml_decode($data);
764 764
 }
765 765
 
766 766
 
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
  * @return array|bool
776 776
  */
777 777
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
778
-	return (array)preg_files($dir, $regexp, $limit);
778
+    return (array)preg_files($dir, $regexp, $limit);
779 779
 }
780 780
 
781 781
 /**
@@ -787,23 +787,23 @@  discard block
 block discarded – undo
787 787
  * @return array|bool
788 788
  */
789 789
 function inc_ls_to_array_dist($data) {
790
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
791
-	$a = $glob_to_array($data);
792
-	foreach ($a as &$v) {
793
-		$b = (array)@stat($v);
794
-		foreach ($b as $k => $ignore) {
795
-			if (is_numeric($k)) {
796
-				unset($b[$k]);
797
-			}
798
-		}
799
-		$b['file'] = preg_replace('`/$`', '', $v) ;
800
-		$v = array_merge(
801
-			pathinfo($v),
802
-			$b
803
-		);
804
-	}
805
-
806
-	return $a;
790
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
791
+    $a = $glob_to_array($data);
792
+    foreach ($a as &$v) {
793
+        $b = (array)@stat($v);
794
+        foreach ($b as $k => $ignore) {
795
+            if (is_numeric($k)) {
796
+                unset($b[$k]);
797
+            }
798
+        }
799
+        $b['file'] = preg_replace('`/$`', '', $v) ;
800
+        $v = array_merge(
801
+            pathinfo($v),
802
+            $b
803
+        );
804
+    }
805
+
806
+    return $a;
807 807
 }
808 808
 
809 809
 /**
@@ -813,25 +813,25 @@  discard block
 block discarded – undo
813 813
  * @return array|bool
814 814
  */
815 815
 function XMLObjectToArray($object) {
816
-	$xml_array = [];
817
-	for ($object->rewind(); $object->valid(); $object->next()) {
818
-		if (array_key_exists($key = $object->key(), $xml_array)) {
819
-			$key .= '-' . uniqid();
820
-		}
821
-		$vars = get_object_vars($object->current());
822
-		if (isset($vars['@attributes'])) {
823
-			foreach ($vars['@attributes'] as $k => $v) {
824
-				$xml_array[$key][$k] = $v;
825
-			}
826
-		}
827
-		if ($object->hasChildren()) {
828
-			$xml_array[$key][] = XMLObjectToArray(
829
-				$object->current()
830
-			);
831
-		} else {
832
-			$xml_array[$key][] = strval($object->current());
833
-		}
834
-	}
835
-
836
-	return $xml_array;
816
+    $xml_array = [];
817
+    for ($object->rewind(); $object->valid(); $object->next()) {
818
+        if (array_key_exists($key = $object->key(), $xml_array)) {
819
+            $key .= '-' . uniqid();
820
+        }
821
+        $vars = get_object_vars($object->current());
822
+        if (isset($vars['@attributes'])) {
823
+            foreach ($vars['@attributes'] as $k => $v) {
824
+                $xml_array[$key][$k] = $v;
825
+            }
826
+        }
827
+        if ($object->hasChildren()) {
828
+            $xml_array[$key][] = XMLObjectToArray(
829
+                $object->current()
830
+            );
831
+        } else {
832
+            $xml_array[$key][] = strval($object->current());
833
+        }
834
+    }
835
+
836
+    return $xml_array;
837 837
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		// Si a ce stade on n'a pas de table, il y a un bug
235 235
 		if (!is_array($this->tableau)) {
236 236
 			$this->err = true;
237
-			spip_log('erreur datasource ' . var_export($command, true));
237
+			spip_log('erreur datasource '.var_export($command, true));
238 238
 		}
239 239
 
240 240
 		// {datapath query.results}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			isset($this->command['sourcemode'])
277 277
 			and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278 278
 		) {
279
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
279
+			charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true);
280 280
 		}
281 281
 
282 282
 		# le premier argument peut etre un array, une URL etc.
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		# avons-nous un cache dispo ?
286 286
 		$cle = null;
287 287
 		if (is_string($src)) {
288
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
288
+			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true));
289 289
 		}
290 290
 
291 291
 		$cache = $this->cache_get($cle);
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
 					if (
346 346
 						!$this->err
347
-						and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
347
+						and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true)
348 348
 					) {
349 349
 						$args = $this->command['source'];
350 350
 						$args[0] = $data;
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
 							$tv = '%s';
485 485
 						} # {par valeur/xx/yy} ??
486 486
 						else {
487
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
487
+							$tv = 'table_valeur(%s, '.var_export($r[1], true).')';
488 488
 						}
489 489
 						$sortfunc .= '
490
-					$a = ' . sprintf($tv, '$aa') . ';
491
-					$b = ' . sprintf($tv, '$bb') . ';
490
+					$a = ' . sprintf($tv, '$aa').';
491
+					$b = ' . sprintf($tv, '$bb').';
492 492
 					if ($a <> $b)
493
-						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
493
+						return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;';
494 494
 					}
495 495
 				}
496 496
 			}
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 
499 499
 		if ($sortfunc) {
500 500
 			$sortfunc .= "\n return 0;";
501
-			uasort($this->tableau, function ($aa, $bb) use ($sortfunc) {
501
+			uasort($this->tableau, function($aa, $bb) use ($sortfunc) {
502 502
 				return eval($sortfunc);
503 503
 			});
504 504
 		}
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 function inc_sql_to_array_dist($data) {
644 644
 	# sortir le connecteur de $data
645 645
 	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
-	$serveur = (string)$v[1];
646
+	$serveur = (string) $v[1];
647 647
 	$req = trim($v[2]);
648 648
 	if ($s = sql_query($req, $serveur)) {
649 649
 		$r = [];
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
  */
666 666
 function inc_json_to_array_dist($data) {
667 667
 	if (is_array($json = json_decode($data, true))) {
668
-		return (array)$json;
668
+		return (array) $json;
669 669
 	}
670 670
 }
671 671
 
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
 	$i = 1;
685 685
 	foreach ($entete as $k => $v) {
686 686
 		if (trim($v) == '') {
687
-			$v = 'col' . $i;
687
+			$v = 'col'.$i;
688 688
 		} // reperer des eventuelles cases vides
689 689
 		if (is_numeric($v) and $v < 0) {
690
-			$v = '__' . $v;
690
+			$v = '__'.$v;
691 691
 		} // ne pas risquer d'ecraser une cle numerique
692 692
 		if (is_numeric($v)) {
693
-			$v = '_' . $v;
693
+			$v = '_'.$v;
694 694
 		} // ne pas risquer d'ecraser une cle numerique
695 695
 		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
696 696
 		foreach ($csv as &$item) {
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
  * @return array|bool
776 776
  */
777 777
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
778
-	return (array)preg_files($dir, $regexp, $limit);
778
+	return (array) preg_files($dir, $regexp, $limit);
779 779
 }
780 780
 
781 781
 /**
@@ -790,13 +790,13 @@  discard block
 block discarded – undo
790 790
 	$glob_to_array = charger_fonction('glob_to_array', 'inc');
791 791
 	$a = $glob_to_array($data);
792 792
 	foreach ($a as &$v) {
793
-		$b = (array)@stat($v);
793
+		$b = (array) @stat($v);
794 794
 		foreach ($b as $k => $ignore) {
795 795
 			if (is_numeric($k)) {
796 796
 				unset($b[$k]);
797 797
 			}
798 798
 		}
799
-		$b['file'] = preg_replace('`/$`', '', $v) ;
799
+		$b['file'] = preg_replace('`/$`', '', $v);
800 800
 		$v = array_merge(
801 801
 			pathinfo($v),
802 802
 			$b
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	$xml_array = [];
817 817
 	for ($object->rewind(); $object->valid(); $object->next()) {
818 818
 		if (array_key_exists($key = $object->key(), $xml_array)) {
819
-			$key .= '-' . uniqid();
819
+			$key .= '-'.uniqid();
820 820
 		}
821 821
 		$vars = get_object_vars($object->current());
822 822
 		if (isset($vars['@attributes'])) {
Please login to merge, or discard this patch.
ecrire/iterateur/php.php 1 patch
Indentation   +14 added lines, -14 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,22 +36,22 @@  discard block
 block discarded – undo
36 36
  *     Description de la boucle complétée des champs
37 37
  */
38 38
 function iterateur_php_dist($b, $iteratorName) {
39
-	$b->iterateur = $iteratorName; # designe la classe d'iterateur
40
-	$b->show = [
41
-		'field' => [
42
-			'cle' => 'STRING',
43
-			'valeur' => 'STRING',
44
-		]
45
-	];
46
-	foreach (get_class_methods($iteratorName) as $method) {
47
-		$b->show['field'][strtolower($method)] = 'METHOD';
48
-	}
49
-
50
-	/*
39
+    $b->iterateur = $iteratorName; # designe la classe d'iterateur
40
+    $b->show = [
41
+        'field' => [
42
+            'cle' => 'STRING',
43
+            'valeur' => 'STRING',
44
+        ]
45
+    ];
46
+    foreach (get_class_methods($iteratorName) as $method) {
47
+        $b->show['field'][strtolower($method)] = 'METHOD';
48
+    }
49
+
50
+    /*
51 51
 	foreach (get_class_vars($iteratorName) as $property) {
52 52
 		$b->show['field'][ strtolower($property) ] = 'PROPERTY';
53 53
 	}
54 54
 	*/
55 55
 
56
-	return $b;
56
+    return $b;
57 57
 }
Please login to merge, or discard this patch.