Completed
Push — master ( 3caaa9...7e8601 )
by cam
01:42
created
ecrire/inc/meta.php 1 patch
Indentation   +197 added lines, -197 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
 // Les parametres generaux du site sont dans une table SQL;
@@ -27,51 +27,51 @@  discard block
 block discarded – undo
27 27
 define('_META_CACHE_TIME', 1 << 24);
28 28
 
29 29
 function inc_meta_dist($table = 'meta') {
30
-	$new = null;
31
-	// Lire les meta, en cache si present, valide et lisible
32
-	// en cas d'install ne pas faire confiance au meta_cache eventuel
33
-	$cache = cache_meta($table);
30
+    $new = null;
31
+    // Lire les meta, en cache si present, valide et lisible
32
+    // en cas d'install ne pas faire confiance au meta_cache eventuel
33
+    $cache = cache_meta($table);
34 34
 
35
-	if (
36
-		(!$exec = _request('exec') or !autoriser_sans_cookie($exec))
37
-		and $new = jeune_fichier($cache, _META_CACHE_TIME)
38
-		and lire_fichier_securise($cache, $meta)
39
-		and $meta = @unserialize($meta)
40
-	) {
41
-		$GLOBALS[$table] = $meta;
42
-	}
35
+    if (
36
+        (!$exec = _request('exec') or !autoriser_sans_cookie($exec))
37
+        and $new = jeune_fichier($cache, _META_CACHE_TIME)
38
+        and lire_fichier_securise($cache, $meta)
39
+        and $meta = @unserialize($meta)
40
+    ) {
41
+        $GLOBALS[$table] = $meta;
42
+    }
43 43
 
44
-	if (
45
-		isset($GLOBALS[$table]['touch'])
46
-		and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME)
47
-	) {
48
-		$GLOBALS[$table] = [];
49
-	}
50
-	// sinon lire en base
51
-	if (!$GLOBALS[$table]) {
52
-		$new = !lire_metas($table);
53
-	}
44
+    if (
45
+        isset($GLOBALS[$table]['touch'])
46
+        and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME)
47
+    ) {
48
+        $GLOBALS[$table] = [];
49
+    }
50
+    // sinon lire en base
51
+    if (!$GLOBALS[$table]) {
52
+        $new = !lire_metas($table);
53
+    }
54 54
 
55
-	// renouveller l'alea general si trop vieux ou sur demande explicite
56
-	if (
57
-		(test_espace_prive() || isset($_GET['renouvelle_alea']))
58
-		and $GLOBALS[$table]
59
-		and (time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0))
60
-	) {
61
-		// si on n'a pas l'acces en ecriture sur le cache,
62
-		// ne pas renouveller l'alea sinon le cache devient faux
63
-		if (supprimer_fichier($cache)) {
64
-			include_spip('inc/acces');
65
-			renouvelle_alea();
66
-			$new = false;
67
-		} else {
68
-			spip_log("impossible d'ecrire dans " . $cache);
69
-		}
70
-	}
71
-	// et refaire le cache si on a du lire en base
72
-	if (!$new) {
73
-		touch_meta(false, $table);
74
-	}
55
+    // renouveller l'alea general si trop vieux ou sur demande explicite
56
+    if (
57
+        (test_espace_prive() || isset($_GET['renouvelle_alea']))
58
+        and $GLOBALS[$table]
59
+        and (time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0))
60
+    ) {
61
+        // si on n'a pas l'acces en ecriture sur le cache,
62
+        // ne pas renouveller l'alea sinon le cache devient faux
63
+        if (supprimer_fichier($cache)) {
64
+            include_spip('inc/acces');
65
+            renouvelle_alea();
66
+            $new = false;
67
+        } else {
68
+            spip_log("impossible d'ecrire dans " . $cache);
69
+        }
70
+    }
71
+    // et refaire le cache si on a du lire en base
72
+    if (!$new) {
73
+        touch_meta(false, $table);
74
+    }
75 75
 }
76 76
 
77 77
 // fonctions aussi appelees a l'install ==> spip_query en premiere requete
@@ -79,39 +79,39 @@  discard block
 block discarded – undo
79 79
 
80 80
 function lire_metas($table = 'meta') {
81 81
 
82
-	if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) {
83
-		include_spip('base/abstract_sql');
84
-		$GLOBALS[$table] = [];
85
-		while ($row = sql_fetch($result)) {
86
-			$GLOBALS[$table][$row['nom']] = $row['valeur'];
87
-		}
88
-		sql_free($result);
82
+    if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) {
83
+        include_spip('base/abstract_sql');
84
+        $GLOBALS[$table] = [];
85
+        while ($row = sql_fetch($result)) {
86
+            $GLOBALS[$table][$row['nom']] = $row['valeur'];
87
+        }
88
+        sql_free($result);
89 89
 
90
-		if (
91
-			!isset($GLOBALS[$table]['charset'])
92
-			or !$GLOBALS[$table]['charset']
93
-			or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install
94
-		) {
95
-			ecrire_meta('charset', _DEFAULT_CHARSET, null, $table);
96
-		}
90
+        if (
91
+            !isset($GLOBALS[$table]['charset'])
92
+            or !$GLOBALS[$table]['charset']
93
+            or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install
94
+        ) {
95
+            ecrire_meta('charset', _DEFAULT_CHARSET, null, $table);
96
+        }
97 97
 
98
-		// noter cette table de configuration dans les meta de SPIP
99
-		if ($table !== 'meta') {
100
-			$liste = [];
101
-			if (isset($GLOBALS['meta']['tables_config'])) {
102
-				$liste = unserialize($GLOBALS['meta']['tables_config']);
103
-			}
104
-			if (!$liste) {
105
-				$liste = [];
106
-			}
107
-			if (!in_array($table, $liste)) {
108
-				$liste[] = $table;
109
-				ecrire_meta('tables_config', serialize($liste));
110
-			}
111
-		}
112
-	}
98
+        // noter cette table de configuration dans les meta de SPIP
99
+        if ($table !== 'meta') {
100
+            $liste = [];
101
+            if (isset($GLOBALS['meta']['tables_config'])) {
102
+                $liste = unserialize($GLOBALS['meta']['tables_config']);
103
+            }
104
+            if (!$liste) {
105
+                $liste = [];
106
+            }
107
+            if (!in_array($table, $liste)) {
108
+                $liste[] = $table;
109
+                ecrire_meta('tables_config', serialize($liste));
110
+            }
111
+        }
112
+    }
113 113
 
114
-	return $GLOBALS[$table] ?? null;
114
+    return $GLOBALS[$table] ?? null;
115 115
 }
116 116
 
117 117
 
@@ -125,22 +125,22 @@  discard block
 block discarded – undo
125 125
  *      Table SQL d'enregistrement des meta.
126 126
  **/
127 127
 function touch_meta($antidate = false, $table = 'meta') {
128
-	$file = cache_meta($table);
129
-	if (!$antidate or !@touch($file, $antidate)) {
130
-		$r = $GLOBALS[$table] ?? [];
131
-		if ($table == 'meta') {
132
-			unset($r['alea_ephemere']);
133
-			unset($r['alea_ephemere_ancien']);
134
-			// le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables
135
-			// mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique
136
-			// meme si son squelette est en cache
137
-			//unset($r['secret_du_site']);
138
-			if ($antidate) {
139
-				$r['touch'] = $antidate;
140
-			}
141
-		}
142
-		ecrire_fichier_securise($file, serialize($r));
143
-	}
128
+    $file = cache_meta($table);
129
+    if (!$antidate or !@touch($file, $antidate)) {
130
+        $r = $GLOBALS[$table] ?? [];
131
+        if ($table == 'meta') {
132
+            unset($r['alea_ephemere']);
133
+            unset($r['alea_ephemere_ancien']);
134
+            // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables
135
+            // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique
136
+            // meme si son squelette est en cache
137
+            //unset($r['secret_du_site']);
138
+            if ($antidate) {
139
+                $r['touch'] = $antidate;
140
+            }
141
+        }
142
+        ecrire_fichier_securise($file, serialize($r));
143
+    }
144 144
 }
145 145
 
146 146
 /**
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
  *     Table SQL d'enregistrement de la meta.
157 157
  **/
158 158
 function effacer_meta($nom, $table = 'meta') {
159
-	// section critique sur le cache:
160
-	// l'invalider avant et apres la MAJ de la BD
161
-	// c'est un peu moins bien qu'un vrai verrou mais ca suffira
162
-	// et utiliser une statique pour eviter des acces disques a repetition
163
-	static $touch = [];
164
-	$antidate = time() - (_META_CACHE_TIME << 4);
165
-	if (!isset($touch[$table])) {
166
-		touch_meta($antidate, $table);
167
-	}
168
-	sql_delete('spip_' . $table, "nom='$nom'", '', 'continue');
169
-	unset($GLOBALS[$table][$nom]);
170
-	if (!isset($touch[$table])) {
171
-		touch_meta($antidate, $table);
172
-		$touch[$table] = false;
173
-	}
159
+    // section critique sur le cache:
160
+    // l'invalider avant et apres la MAJ de la BD
161
+    // c'est un peu moins bien qu'un vrai verrou mais ca suffira
162
+    // et utiliser une statique pour eviter des acces disques a repetition
163
+    static $touch = [];
164
+    $antidate = time() - (_META_CACHE_TIME << 4);
165
+    if (!isset($touch[$table])) {
166
+        touch_meta($antidate, $table);
167
+    }
168
+    sql_delete('spip_' . $table, "nom='$nom'", '', 'continue');
169
+    unset($GLOBALS[$table][$nom]);
170
+    if (!isset($touch[$table])) {
171
+        touch_meta($antidate, $table);
172
+        $touch[$table] = false;
173
+    }
174 174
 }
175 175
 
176 176
 /**
@@ -191,53 +191,53 @@  discard block
 block discarded – undo
191 191
  **/
192 192
 function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') {
193 193
 
194
-	static $touch = [];
195
-	if (!$nom) {
196
-		return;
197
-	}
198
-	include_spip('base/abstract_sql');
199
-	$res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue');
200
-	// table pas encore installee, travailler en php seulement
201
-	if (!$res) {
202
-		$GLOBALS[$table][$nom] = $valeur;
194
+    static $touch = [];
195
+    if (!$nom) {
196
+        return;
197
+    }
198
+    include_spip('base/abstract_sql');
199
+    $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue');
200
+    // table pas encore installee, travailler en php seulement
201
+    if (!$res) {
202
+        $GLOBALS[$table][$nom] = $valeur;
203 203
 
204
-		return;
205
-	}
206
-	$row = sql_fetch($res);
207
-	sql_free($res);
204
+        return;
205
+    }
206
+    $row = sql_fetch($res);
207
+    sql_free($res);
208 208
 
209
-	// ne pas invalider le cache si affectation a l'identique
210
-	// (tant pis si impt aurait du changer)
211
-	if (
212
-		$row and $valeur == $row['valeur']
213
-		and isset($GLOBALS[$table][$nom])
214
-		and $GLOBALS[$table][$nom] == $valeur
215
-	) {
216
-		return;
217
-	}
209
+    // ne pas invalider le cache si affectation a l'identique
210
+    // (tant pis si impt aurait du changer)
211
+    if (
212
+        $row and $valeur == $row['valeur']
213
+        and isset($GLOBALS[$table][$nom])
214
+        and $GLOBALS[$table][$nom] == $valeur
215
+    ) {
216
+        return;
217
+    }
218 218
 
219
-	$GLOBALS[$table][$nom] = $valeur;
220
-	// cf effacer pour comprendre le double touch
221
-	$antidate = time() - (_META_CACHE_TIME << 1);
222
-	if (!isset($touch[$table])) {
223
-		touch_meta($antidate, $table);
224
-	}
225
-	$r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')];
226
-	// Gaffe aux tables sans impt (vieilles versions de SPIP notamment)
227
-	// ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot
228
-	// de lecture des descriptions des tables
229
-	if ($importable and isset($row['impt'])) {
230
-		$r['impt'] = sql_quote($importable, '', 'text');
231
-	}
232
-	if ($row) {
233
-		sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom));
234
-	} else {
235
-		sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')');
236
-	}
237
-	if (!isset($touch[$table])) {
238
-		touch_meta($antidate, $table);
239
-		$touch[$table] = false;
240
-	}
219
+    $GLOBALS[$table][$nom] = $valeur;
220
+    // cf effacer pour comprendre le double touch
221
+    $antidate = time() - (_META_CACHE_TIME << 1);
222
+    if (!isset($touch[$table])) {
223
+        touch_meta($antidate, $table);
224
+    }
225
+    $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')];
226
+    // Gaffe aux tables sans impt (vieilles versions de SPIP notamment)
227
+    // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot
228
+    // de lecture des descriptions des tables
229
+    if ($importable and isset($row['impt'])) {
230
+        $r['impt'] = sql_quote($importable, '', 'text');
231
+    }
232
+    if ($row) {
233
+        sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom));
234
+    } else {
235
+        sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')');
236
+    }
237
+    if (!isset($touch[$table])) {
238
+        touch_meta($antidate, $table);
239
+        $touch[$table] = false;
240
+    }
241 241
 }
242 242
 
243 243
 /**
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
  *     Nom du fichier cache
250 250
  **/
251 251
 function cache_meta($table = 'meta') {
252
-	return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php');
252
+    return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php');
253 253
 }
254 254
 
255 255
 /**
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
  * @param string $table
259 259
  */
260 260
 function installer_table_meta($table) {
261
-	$trouver_table = charger_fonction('trouver_table', 'base');
262
-	if (!$trouver_table("spip_$table")) {
263
-		include_spip('base/auxiliaires');
264
-		include_spip('base/create');
265
-		creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false);
266
-		$trouver_table('');
267
-	}
268
-	lire_metas($table);
261
+    $trouver_table = charger_fonction('trouver_table', 'base');
262
+    if (!$trouver_table("spip_$table")) {
263
+        include_spip('base/auxiliaires');
264
+        include_spip('base/create');
265
+        creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false);
266
+        $trouver_table('');
267
+    }
268
+    lire_metas($table);
269 269
 }
270 270
 
271 271
 /**
@@ -277,47 +277,47 @@  discard block
 block discarded – undo
277 277
  * @param bool $force
278 278
  */
279 279
 function supprimer_table_meta($table, $force = false) {
280
-	if ($table !== 'meta') {
281
-		// Vérifier le contenu restant de la table
282
-		$nb_variables = sql_countsel("spip_$table");
280
+    if ($table !== 'meta') {
281
+        // Vérifier le contenu restant de la table
282
+        $nb_variables = sql_countsel("spip_$table");
283 283
 
284
-		// Supprimer si :
285
-		// - la table est vide
286
-		// - ou limitée à la variable charset
287
-		// - ou qu'on force la suppression
288
-		if (
289
-			$force
290
-			or !$nb_variables
291
-			or (
292
-				($nb_variables == 1)
293
-				and isset($GLOBALS[$table]['charset'])
294
-			)
295
-		) {
296
-			// Supprimer la table des globaleset de la base
297
-			unset($GLOBALS[$table]);
298
-			sql_drop_table("spip_$table");
299
-			// Supprimer le fichier cache
300
-			include_spip('inc/flock');
301
-			$cache = cache_meta($table);
302
-			supprimer_fichier($cache);
284
+        // Supprimer si :
285
+        // - la table est vide
286
+        // - ou limitée à la variable charset
287
+        // - ou qu'on force la suppression
288
+        if (
289
+            $force
290
+            or !$nb_variables
291
+            or (
292
+                ($nb_variables == 1)
293
+                and isset($GLOBALS[$table]['charset'])
294
+            )
295
+        ) {
296
+            // Supprimer la table des globaleset de la base
297
+            unset($GLOBALS[$table]);
298
+            sql_drop_table("spip_$table");
299
+            // Supprimer le fichier cache
300
+            include_spip('inc/flock');
301
+            $cache = cache_meta($table);
302
+            supprimer_fichier($cache);
303 303
 
304
-			// vider le cache des tables
305
-			$trouver_table = charger_fonction('trouver_table', 'base');
306
-			$trouver_table('');
304
+            // vider le cache des tables
305
+            $trouver_table = charger_fonction('trouver_table', 'base');
306
+            $trouver_table('');
307 307
 
308
-			// Supprimer la table de la liste des tables de configuration autres que spip_meta
309
-			if (isset($GLOBALS['meta']['tables_config'])) {
310
-				$liste = unserialize($GLOBALS['meta']['tables_config']);
311
-				$cle = array_search($table, $liste);
312
-				if ($cle !== false) {
313
-					unset($liste[$cle]);
314
-					if ($liste) {
315
-						ecrire_meta('tables_config', serialize($liste));
316
-					} else {
317
-						effacer_meta('tables_config');
318
-					}
319
-				}
320
-			}
321
-		}
322
-	}
308
+            // Supprimer la table de la liste des tables de configuration autres que spip_meta
309
+            if (isset($GLOBALS['meta']['tables_config'])) {
310
+                $liste = unserialize($GLOBALS['meta']['tables_config']);
311
+                $cle = array_search($table, $liste);
312
+                if ($cle !== false) {
313
+                    unset($liste[$cle]);
314
+                    if ($liste) {
315
+                        ecrire_meta('tables_config', serialize($liste));
316
+                    } else {
317
+                        effacer_meta('tables_config');
318
+                    }
319
+                }
320
+            }
321
+        }
322
+    }
323 323
 }
Please login to merge, or discard this patch.
ecrire/inc/json.php 1 patch
Indentation   +50 added lines, -50 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
 // Les fonctions de toggg pour faire du JSON
@@ -25,63 +25,63 @@  discard block
 block discarded – undo
25 25
  */
26 26
 
27 27
 function var2js($var) {
28
-	$asso = false;
29
-	switch (true) {
30
-		case is_null($var):
31
-			return 'null';
32
-		case is_string($var):
33
-			return '"' . addcslashes($var, "\"\\\n\r/") . '"';
34
-		case is_bool($var):
35
-			return $var ? 'true' : 'false';
36
-		case is_scalar($var):
37
-			return (string)$var;
38
-		case is_object($var):// blam
39
-			$var = get_object_vars($var);
40
-			$asso = true;
41
-			// $var devient un array, on continue
42
-		case is_array($var):
43
-			$keys = array_keys($var);
44
-			$ikey = count($keys);
45
-			while (!$asso && $ikey--) {
46
-				$asso = $ikey !== $keys[$ikey];
47
-			}
48
-			$sep = '';
49
-			if ($asso) {
50
-				$ret = '{';
51
-				foreach ($var as $key => $elt) {
52
-					$ret .= $sep . '"' . $key . '":' . var2js($elt);
53
-					$sep = ',';
54
-				}
28
+    $asso = false;
29
+    switch (true) {
30
+        case is_null($var):
31
+            return 'null';
32
+        case is_string($var):
33
+            return '"' . addcslashes($var, "\"\\\n\r/") . '"';
34
+        case is_bool($var):
35
+            return $var ? 'true' : 'false';
36
+        case is_scalar($var):
37
+            return (string)$var;
38
+        case is_object($var):// blam
39
+            $var = get_object_vars($var);
40
+            $asso = true;
41
+            // $var devient un array, on continue
42
+        case is_array($var):
43
+            $keys = array_keys($var);
44
+            $ikey = count($keys);
45
+            while (!$asso && $ikey--) {
46
+                $asso = $ikey !== $keys[$ikey];
47
+            }
48
+            $sep = '';
49
+            if ($asso) {
50
+                $ret = '{';
51
+                foreach ($var as $key => $elt) {
52
+                    $ret .= $sep . '"' . $key . '":' . var2js($elt);
53
+                    $sep = ',';
54
+                }
55 55
 
56
-				return $ret . '}';
57
-			} else {
58
-				$ret = '[';
59
-				foreach ($var as $elt) {
60
-					$ret .= $sep . var2js($elt);
61
-					$sep = ',';
62
-				}
56
+                return $ret . '}';
57
+            } else {
58
+                $ret = '[';
59
+                foreach ($var as $elt) {
60
+                    $ret .= $sep . var2js($elt);
61
+                    $sep = ',';
62
+                }
63 63
 
64
-				return $ret . ']';
65
-			}
66
-	}
64
+                return $ret . ']';
65
+            }
66
+    }
67 67
 
68
-	return false;
68
+    return false;
69 69
 }
70 70
 
71 71
 if (!function_exists('json_encode')) {
72
-	function json_encode($v) {
73
-		return var2js($v);
74
-	}
72
+    function json_encode($v) {
73
+        return var2js($v);
74
+    }
75 75
 }
76 76
 
77 77
 function json_export($var) {
78
-	$var = json_encode($var, JSON_THROW_ON_ERROR);
78
+    $var = json_encode($var, JSON_THROW_ON_ERROR);
79 79
 
80
-	// flag indiquant qu'on est en iframe et qu'il faut proteger nos
81
-	// donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop
82
-	if (defined('FILE_UPLOAD')) {
83
-		return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>';
84
-	} else {
85
-		return $var;
86
-	}
80
+    // flag indiquant qu'on est en iframe et qu'il faut proteger nos
81
+    // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop
82
+    if (defined('FILE_UPLOAD')) {
83
+        return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>';
84
+    } else {
85
+        return $var;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
ecrire/inc/genie.php 1 patch
Indentation   +88 added lines, -88 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
 /**
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
  * @return
76 76
  **/
77 77
 function inc_genie_dist($taches = []) {
78
-	include_spip('inc/queue');
79
-
80
-	if (_request('exec') == 'job_queue') {
81
-		return false;
82
-	}
83
-
84
-	$force_jobs = [];
85
-	// l'ancienne facon de lancer une tache cron immediatement
86
-	// etait de la passer en parametre a ing_genie_dist
87
-	// on reroute en ajoutant simplement le job a la queue, ASAP
88
-	foreach ($taches as $function => $period) {
89
-		$force_jobs[] = queue_add_job(
90
-			$function,
91
-			_T('tache_cron_asap', ['function' => $function]),
92
-			[time() - abs($period)],
93
-			'genie/'
94
-		);
95
-	}
96
-
97
-	// et on passe la main a la gestion de la queue !
98
-	// en forcant eventuellement les jobs ajoute a l'instant
99
-	return queue_schedule(count($force_jobs) ? $force_jobs : null);
78
+    include_spip('inc/queue');
79
+
80
+    if (_request('exec') == 'job_queue') {
81
+        return false;
82
+    }
83
+
84
+    $force_jobs = [];
85
+    // l'ancienne facon de lancer une tache cron immediatement
86
+    // etait de la passer en parametre a ing_genie_dist
87
+    // on reroute en ajoutant simplement le job a la queue, ASAP
88
+    foreach ($taches as $function => $period) {
89
+        $force_jobs[] = queue_add_job(
90
+            $function,
91
+            _T('tache_cron_asap', ['function' => $function]),
92
+            [time() - abs($period)],
93
+            'genie/'
94
+        );
95
+    }
96
+
97
+    // et on passe la main a la gestion de la queue !
98
+    // en forcant eventuellement les jobs ajoute a l'instant
99
+    return queue_schedule(count($force_jobs) ? $force_jobs : null);
100 100
 }
101 101
 
102 102
 //
@@ -109,33 +109,33 @@  discard block
 block discarded – undo
109 109
 //
110 110
 function taches_generales($taches_generales = []) {
111 111
 
112
-	// verifier que toutes les taches cron sont planifiees
113
-	// c'est une tache cron !
114
-	$taches_generales['queue_watch'] = 3600 * 24;
112
+    // verifier que toutes les taches cron sont planifiees
113
+    // c'est une tache cron !
114
+    $taches_generales['queue_watch'] = 3600 * 24;
115 115
 
116
-	// MAJ des rubriques publiques (cas de la publication post-datee)
117
-	// est fait au coup par coup a present
118
-	//	$taches_generales['rubriques'] = 3600;
116
+    // MAJ des rubriques publiques (cas de la publication post-datee)
117
+    // est fait au coup par coup a present
118
+    //	$taches_generales['rubriques'] = 3600;
119 119
 
120
-	// Optimisation de la base
121
-	$taches_generales['optimiser'] = 3600 * 48;
120
+    // Optimisation de la base
121
+    $taches_generales['optimiser'] = 3600 * 48;
122 122
 
123
-	// nouveautes
124
-	if (
125
-		isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf']
126
-		and $GLOBALS['meta']['jours_neuf']
127
-		and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui')
128
-	) {
129
-		$taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf'];
130
-	}
123
+    // nouveautes
124
+    if (
125
+        isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf']
126
+        and $GLOBALS['meta']['jours_neuf']
127
+        and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui')
128
+    ) {
129
+        $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf'];
130
+    }
131 131
 
132
-	// maintenance (ajax, verifications diverses)
133
-	$taches_generales['maintenance'] = 3600 * 2;
132
+    // maintenance (ajax, verifications diverses)
133
+    $taches_generales['maintenance'] = 3600 * 2;
134 134
 
135
-	// verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement)
136
-	$taches_generales['mise_a_jour'] = 3 * 24 * 3600;
135
+    // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement)
136
+    $taches_generales['mise_a_jour'] = 3 * 24 * 3600;
137 137
 
138
-	return pipeline('taches_generales_cron', $taches_generales);
138
+    return pipeline('taches_generales_cron', $taches_generales);
139 139
 }
140 140
 
141 141
 /**
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
  * @return int
152 152
  */
153 153
 function genie_queue_watch_dist() {
154
-	static $deja_la = false;
155
-	if ($deja_la) {
156
-		return;
157
-	} // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple)
158
-	$deja_la = true;
159
-	$taches = taches_generales();
160
-	$programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches)));
161
-	$programmees = array_column($programmees, 'fonction');
162
-	foreach ($taches as $tache => $periode) {
163
-		if (!in_array($tache, $programmees)) {
164
-			queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0);
165
-		}
166
-	}
167
-	$deja_la = false;
168
-
169
-	return 1;
154
+    static $deja_la = false;
155
+    if ($deja_la) {
156
+        return;
157
+    } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple)
158
+    $deja_la = true;
159
+    $taches = taches_generales();
160
+    $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches)));
161
+    $programmees = array_column($programmees, 'fonction');
162
+    foreach ($taches as $tache => $periode) {
163
+        if (!in_array($tache, $programmees)) {
164
+            queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0);
165
+        }
166
+    }
167
+    $deja_la = false;
168
+
169
+    return 1;
170 170
 }
171 171
 
172 172
 /**
@@ -187,32 +187,32 @@  discard block
 block discarded – undo
187 187
  * @return void
188 188
  */
189 189
 function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) {
190
-	static $done = [];
191
-	if (isset($done[$function])) {
192
-		return;
193
-	}
194
-	$done[$function] = true;
195
-	if (is_null($time)) {
196
-		$time = time();
197
-		if ($last) {
198
-			$time = max($last + $period, $time);
199
-		}
200
-	}
201
-	if (!$last) {
202
-		$last = $time - $period;
203
-	}
204
-	spip_log("replan_job $function $period $last $time $priority", 'queue');
205
-	include_spip('inc/queue');
206
-	// on replanifie un job cron
207
-	// uniquement si il n'y en a pas deja un avec le meme nom
208
-	// independament de l'argument
209
-	queue_add_job(
210
-		$function,
211
-		_T('tache_cron_secondes', ['function' => $function, 'nb' => $period]),
212
-		[$last],
213
-		'genie/',
214
-		'function_only',
215
-		$time,
216
-		$priority
217
-	);
190
+    static $done = [];
191
+    if (isset($done[$function])) {
192
+        return;
193
+    }
194
+    $done[$function] = true;
195
+    if (is_null($time)) {
196
+        $time = time();
197
+        if ($last) {
198
+            $time = max($last + $period, $time);
199
+        }
200
+    }
201
+    if (!$last) {
202
+        $last = $time - $period;
203
+    }
204
+    spip_log("replan_job $function $period $last $time $priority", 'queue');
205
+    include_spip('inc/queue');
206
+    // on replanifie un job cron
207
+    // uniquement si il n'y en a pas deja un avec le meme nom
208
+    // independament de l'argument
209
+    queue_add_job(
210
+        $function,
211
+        _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]),
212
+        [$last],
213
+        'genie/',
214
+        'function_only',
215
+        $time,
216
+        $priority
217
+    );
218 218
 }
Please login to merge, or discard this patch.
ecrire/inc/informer.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -11,73 +11,73 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 # Les information d'une rubrique selectionnee dans le mini navigateur
18 18
 
19 19
 function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') {
20
-	include_spip('inc/texte');
21
-	$titre = $descriptif = '';
22
-	if ($type == 'rubrique') {
23
-		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
24
-		if ($row) {
25
-			$titre = typo($row['titre']);
26
-			$descriptif = propre($row['descriptif']);
27
-		} else {
28
-			$titre = _T('info_racine_site');
29
-		}
30
-	}
20
+    include_spip('inc/texte');
21
+    $titre = $descriptif = '';
22
+    if ($type == 'rubrique') {
23
+        $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
24
+        if ($row) {
25
+            $titre = typo($row['titre']);
26
+            $descriptif = propre($row['descriptif']);
27
+        } else {
28
+            $titre = _T('info_racine_site');
29
+        }
30
+    }
31 31
 
32
-	$res = '';
33
-	if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) {
34
-		if ($GLOBALS['meta']['image_process'] != 'non') {
35
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
36
-			if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
37
-				[$fid, $dir, $nom, $format] = $res;
38
-				include_spip('inc/filtres_images_mini');
39
-				$res = image_reduire("<img src='$fid' alt='' />", 100, 48);
40
-				if ($res) {
41
-					$res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
42
-				}
43
-			}
44
-		}
45
-	}
32
+    $res = '';
33
+    if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) {
34
+        if ($GLOBALS['meta']['image_process'] != 'non') {
35
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
36
+            if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
37
+                [$fid, $dir, $nom, $format] = $res;
38
+                include_spip('inc/filtres_images_mini');
39
+                $res = image_reduire("<img src='$fid' alt='' />", 100, 48);
40
+                if ($res) {
41
+                    $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
42
+                }
43
+            }
44
+        }
45
+    }
46 46
 
47
-	$rac = spip_htmlentities($rac, ENT_QUOTES);
48
-	$do = spip_htmlentities($do, ENT_QUOTES);
49
-	$id = intval($id);
47
+    $rac = spip_htmlentities($rac, ENT_QUOTES);
48
+    $do = spip_htmlentities($do, ENT_QUOTES);
49
+    $id = intval($id);
50 50
 
51 51
 # ce lien provoque la selection (directe) de la rubrique cliquee
52 52
 # et l'affichage de son titre dans le bandeau
53
-	$titre = strtr(
54
-		str_replace(
55
-			"'",
56
-			'&#8217;',
57
-			str_replace('"', '&#34;', textebrut($titre))
58
-		),
59
-		"\n\r",
60
-		'  '
61
-	);
53
+    $titre = strtr(
54
+        str_replace(
55
+            "'",
56
+            '&#8217;',
57
+            str_replace('"', '&#34;', textebrut($titre))
58
+        ),
59
+        "\n\r",
60
+        '  '
61
+    );
62 62
 
63
-	$js_func = $do . '_selection_titre';
63
+    $js_func = $do . '_selection_titre';
64 64
 
65
-	return "<div style='display: none;'>"
66
-	. "<input type='text' id='" . $rac . "_sel' value='$id' />"
67
-	. "<input type='text' id='" . $rac . "_sel2' value=\""
68
-	. entites_html($titre)
69
-	. '" />'
70
-	. '</div>'
71
-	. "<div class='informer' style='padding: 5px; border-top: 0px;'>"
72
-	. '<div class="informer__item">'
73
-	. (!$res ? '' : $res)
74
-	. "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
75
-	. (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
76
-	. '</div>'
77
-	. "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
78
-	. "<input type='submit' class='fondo btn submit' value='"
79
-	. _T('bouton_choisir')
80
-	. "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
81
-	. '</div>'
82
-	. '</div>';
65
+    return "<div style='display: none;'>"
66
+    . "<input type='text' id='" . $rac . "_sel' value='$id' />"
67
+    . "<input type='text' id='" . $rac . "_sel2' value=\""
68
+    . entites_html($titre)
69
+    . '" />'
70
+    . '</div>'
71
+    . "<div class='informer' style='padding: 5px; border-top: 0px;'>"
72
+    . '<div class="informer__item">'
73
+    . (!$res ? '' : $res)
74
+    . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
75
+    . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
76
+    . '</div>'
77
+    . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
78
+    . "<input type='submit' class='fondo btn submit' value='"
79
+    . _T('bouton_choisir')
80
+    . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
81
+    . '</div>'
82
+    . '</div>';
83 83
 }
Please login to merge, or discard this patch.
ecrire/inc/lang.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Langue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -39,36 +39,36 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function changer_langue($lang, $liste_langues = null) {
41 41
 
42
-	if (is_null($liste_langues)) {
43
-		$liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue'];
44
-	}
45
-	else {
46
-		if (is_array($liste_langues)) {
47
-			$liste_langues = implode(',', $liste_langues);
48
-		}
49
-	}
50
-	$liste_langues = ',' . $liste_langues . ',';
51
-
52
-	// Si la langue demandee n'existe pas, on essaie d'autres variantes
53
-	// Exemple : 'pt-br' => 'pt_br' => 'pt'
54
-	$lang = str_replace('-', '_', trim($lang));
55
-	if (!$lang) {
56
-		return false;
57
-	}
58
-
59
-	if (
60
-		strpos($liste_langues, (string) ",$lang,") !== false
61
-		or ($lang = preg_replace(',_.*,', '', $lang)
62
-			and strpos($liste_langues, (string) ",$lang,") !== false)
63
-	) {
64
-		$GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
65
-		$GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
66
-		$GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
67
-
68
-		return $GLOBALS['spip_lang'] = $lang;
69
-	} else {
70
-		return false;
71
-	}
42
+    if (is_null($liste_langues)) {
43
+        $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue'];
44
+    }
45
+    else {
46
+        if (is_array($liste_langues)) {
47
+            $liste_langues = implode(',', $liste_langues);
48
+        }
49
+    }
50
+    $liste_langues = ',' . $liste_langues . ',';
51
+
52
+    // Si la langue demandee n'existe pas, on essaie d'autres variantes
53
+    // Exemple : 'pt-br' => 'pt_br' => 'pt'
54
+    $lang = str_replace('-', '_', trim($lang));
55
+    if (!$lang) {
56
+        return false;
57
+    }
58
+
59
+    if (
60
+        strpos($liste_langues, (string) ",$lang,") !== false
61
+        or ($lang = preg_replace(',_.*,', '', $lang)
62
+            and strpos($liste_langues, (string) ",$lang,") !== false)
63
+    ) {
64
+        $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
65
+        $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
66
+        $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
67
+
68
+        return $GLOBALS['spip_lang'] = $lang;
69
+    } else {
70
+        return false;
71
+    }
72 72
 }
73 73
 
74 74
 //
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
82 82
 
83 83
 function choisir_traduction($trads, $lang = '') {
84
-	$k = approcher_langue($trads, $lang);
84
+    $k = approcher_langue($trads, $lang);
85 85
 
86
-	return $k ? $trads[$k] : array_shift($trads);
86
+    return $k ? $trads[$k] : array_shift($trads);
87 87
 }
88 88
 
89 89
 // retourne son 2e argument si c'est un index du premier
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 // la langue X etant consideree comme une approche de X_Y
92 92
 function approcher_langue($trads, $lang = '') {
93 93
 
94
-	if (!$lang) {
95
-		$lang = $GLOBALS['spip_lang'];
96
-	}
97
-
98
-	if (isset($trads[$lang])) {
99
-		return $lang;
100
-	} // cas des langues xx_yy
101
-	else {
102
-		$r = explode('_', $lang);
103
-		if (isset($trads[$r[0]])) {
104
-			return $r[0];
105
-		}
106
-	}
107
-
108
-	return '';
94
+    if (!$lang) {
95
+        $lang = $GLOBALS['spip_lang'];
96
+    }
97
+
98
+    if (isset($trads[$lang])) {
99
+        return $lang;
100
+    } // cas des langues xx_yy
101
+    else {
102
+        $r = explode('_', $lang);
103
+        if (isset($trads[$r[0]])) {
104
+            return $r[0];
105
+        }
106
+    }
107
+
108
+    return '';
109 109
 }
110 110
 
111 111
 /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
  *     Nom de la langue, sinon son code.
121 121
  **/
122 122
 function traduire_nom_langue($lang) {
123
-	include_spip('inc/lang_liste');
124
-	include_spip('inc/charsets');
123
+    include_spip('inc/lang_liste');
124
+    include_spip('inc/charsets');
125 125
 
126
-	return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang);
126
+    return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang);
127 127
 }
128 128
 
129 129
 //
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 // hebreu a priori), 'droitier' sinon.
137 137
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
138 138
 function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') {
139
-	static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
139
+    static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
140 140
 
141
-	return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ?
142
-		$gaucher : $droitier;
141
+    return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ?
142
+        $gaucher : $droitier;
143 143
 }
144 144
 
145 145
 // typo francaise ou anglaise ?
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
 // sinon determiner la typo en fonction de la langue courante
149 149
 
150 150
 function lang_typo($lang = '') {
151
-	if (!$lang) {
152
-		$lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang'];
153
-	}
154
-	if (
155
-		$lang == 'eo'
156
-		or $lang == 'fr'
157
-		or strncmp($lang, 'fr_', 3) == 0
158
-		or $lang == 'cpf'
159
-	) {
160
-		return 'fr';
161
-	} else {
162
-		return 'en';
163
-	}
151
+    if (!$lang) {
152
+        $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang'];
153
+    }
154
+    if (
155
+        $lang == 'eo'
156
+        or $lang == 'fr'
157
+        or strncmp($lang, 'fr_', 3) == 0
158
+        or $lang == 'cpf'
159
+    ) {
160
+        return 'fr';
161
+    } else {
162
+        return 'en';
163
+    }
164 164
 }
165 165
 
166 166
 // gestion de la globale $lang_objet pour que les textes soient affiches
167 167
 // avec les memes typo et direction dans l'espace prive que dans le public
168 168
 function changer_typo($lang = '') {
169
-	if ($lang) {
170
-		$GLOBALS['lang_objet'] = $lang;
171
-	} else {
172
-		unset($GLOBALS['lang_objet']);
173
-	}
169
+    if ($lang) {
170
+        $GLOBALS['lang_objet'] = $lang;
171
+    } else {
172
+        unset($GLOBALS['lang_objet']);
173
+    }
174 174
 }
175 175
 
176 176
 //
@@ -180,58 +180,58 @@  discard block
 block discarded – undo
180 180
 // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax
181 181
 //
182 182
 function menu_langues($nom_select, $default = '') {
183
-	include_spip('inc/actions');
184
-
185
-	$langues = liste_options_langues($nom_select);
186
-	$ret = '';
187
-	if (!count($langues)) {
188
-		return '';
189
-	}
190
-
191
-	if (!$default) {
192
-		$default = $GLOBALS['spip_lang'];
193
-	}
194
-	foreach ($langues as $l) {
195
-		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
196
-		$ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
197
-	}
198
-
199
-	if (!test_espace_prive()) {
200
-		$cible = self();
201
-		$base = '';
202
-	} else {
203
-		$cible = self();
204
-		$base = spip_connect() ? 'base' : '';
205
-	}
206
-
207
-	$change = ' onchange="this.parentNode.parentNode.submit()"';
208
-
209
-	return generer_action_auteur(
210
-		'converser',
211
-		$base,
212
-		$cible,
213
-		(select_langues($nom_select, $change, $ret)
214
-			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
215
-		" method='post'"
216
-	);
183
+    include_spip('inc/actions');
184
+
185
+    $langues = liste_options_langues($nom_select);
186
+    $ret = '';
187
+    if (!count($langues)) {
188
+        return '';
189
+    }
190
+
191
+    if (!$default) {
192
+        $default = $GLOBALS['spip_lang'];
193
+    }
194
+    foreach ($langues as $l) {
195
+        $selected = ($l == $default) ? ' selected=\'selected\'' : '';
196
+        $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
197
+    }
198
+
199
+    if (!test_espace_prive()) {
200
+        $cible = self();
201
+        $base = '';
202
+    } else {
203
+        $cible = self();
204
+        $base = spip_connect() ? 'base' : '';
205
+    }
206
+
207
+    $change = ' onchange="this.parentNode.parentNode.submit()"';
208
+
209
+    return generer_action_auteur(
210
+        'converser',
211
+        $base,
212
+        $cible,
213
+        (select_langues($nom_select, $change, $ret)
214
+            . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
215
+        " method='post'"
216
+    );
217 217
 }
218 218
 
219 219
 function select_langues($nom_select, $change, $options, $label = '') {
220
-	static $cpt = 0;
221
-	$id = 'menu_langues' . $cpt++;
222
-
223
-	return
224
-		"<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' .
225
-		"<select name='$nom_select' id='$id' "
226
-		. ((!test_espace_prive()) ?
227
-			("class='forml menu_langues'") :
228
-			(($nom_select == 'var_lang_ecrire') ?
229
-				("class='lang_ecrire'") :
230
-				"class='fondl'"))
231
-		. $change
232
-		. ">\n"
233
-		. $options
234
-		. '</select>';
220
+    static $cpt = 0;
221
+    $id = 'menu_langues' . $cpt++;
222
+
223
+    return
224
+        "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' .
225
+        "<select name='$nom_select' id='$id' "
226
+        . ((!test_espace_prive()) ?
227
+            ("class='forml menu_langues'") :
228
+            (($nom_select == 'var_lang_ecrire') ?
229
+                ("class='lang_ecrire'") :
230
+                "class='fondl'"))
231
+        . $change
232
+        . ">\n"
233
+        . $options
234
+        . '</select>';
235 235
 }
236 236
 
237 237
 /**
@@ -253,34 +253,34 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function liste_options_langues($nom_select) {
255 255
 
256
-	switch ($nom_select) {
257
-		# #MENU_LANG
258
-		case 'var_lang':
259
-			# menu de changement de la langue d'un article
260
-			# les langues selectionnees dans la configuration "multilinguisme"
261
-		case 'changer_lang':
262
-			$langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
263
-			break;
264
-		# menu de l'interface (privee, installation et panneau de login)
265
-		# les langues presentes sous forme de fichiers de langue
266
-		# on force la relecture du repertoire des langues pour etre synchrone.
267
-		case 'var_lang_ecrire':
268
-		default:
269
-			$GLOBALS['meta']['langues_proposees'] = '';
270
-			init_langues();
271
-			$langues = explode(',', $GLOBALS['meta']['langues_proposees']);
272
-			break;
256
+    switch ($nom_select) {
257
+        # #MENU_LANG
258
+        case 'var_lang':
259
+            # menu de changement de la langue d'un article
260
+            # les langues selectionnees dans la configuration "multilinguisme"
261
+        case 'changer_lang':
262
+            $langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
263
+            break;
264
+        # menu de l'interface (privee, installation et panneau de login)
265
+        # les langues presentes sous forme de fichiers de langue
266
+        # on force la relecture du repertoire des langues pour etre synchrone.
267
+        case 'var_lang_ecrire':
268
+        default:
269
+            $GLOBALS['meta']['langues_proposees'] = '';
270
+            init_langues();
271
+            $langues = explode(',', $GLOBALS['meta']['langues_proposees']);
272
+            break;
273 273
 
274 274
 # dernier choix possible : toutes les langues = langues_proposees
275 275
 # + langues_multilingues ; mais, ne sert pas
276 276
 #			$langues = explode(',', $GLOBALS['all_langs']);
277
-	}
278
-	if (count($langues) <= 1) {
279
-		return [];
280
-	}
281
-	sort($langues);
277
+    }
278
+    if (count($langues) <= 1) {
279
+        return [];
280
+    }
281
+    sort($langues);
282 282
 
283
-	return $langues;
283
+    return $langues;
284 284
 }
285 285
 
286 286
 
@@ -295,39 +295,39 @@  discard block
 block discarded – undo
295 295
  **/
296 296
 function verifier_lang_url() {
297 297
 
298
-	// quelle langue est demandee ?
299
-	$lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
300
-	if (isset($_COOKIE['spip_lang_ecrire'])) {
301
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
302
-	}
303
-	if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
304
-		$lang_demandee = $_COOKIE['spip_lang'];
305
-	}
306
-	if (isset($_GET['lang'])) {
307
-		$lang_demandee = $_GET['lang'];
308
-	}
309
-
310
-	// Renvoyer si besoin (et si la langue demandee existe)
311
-	if (
312
-		$GLOBALS['spip_lang'] != $lang_demandee
313
-		and changer_langue($lang_demandee)
314
-		and $lang_demandee != @$_GET['lang']
315
-	) {
316
-		$destination = parametre_url(self(), 'lang', $lang_demandee, '&');
317
-		// ici on a besoin des var_truc
318
-		foreach ($_GET as $var => $val) {
319
-			if (!strncmp('var_', $var, 4)) {
320
-				$destination = parametre_url($destination, $var, $val, '&');
321
-			}
322
-		}
323
-		include_spip('inc/headers');
324
-		redirige_par_entete($destination);
325
-	}
326
-
327
-	// Subtilite : si la langue demandee par cookie est la bonne
328
-	// alors on fait comme si $lang etait passee dans l'URL
329
-	// (pour criteres {lang}).
330
-	$GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
298
+    // quelle langue est demandee ?
299
+    $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
300
+    if (isset($_COOKIE['spip_lang_ecrire'])) {
301
+        $lang_demandee = $_COOKIE['spip_lang_ecrire'];
302
+    }
303
+    if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
304
+        $lang_demandee = $_COOKIE['spip_lang'];
305
+    }
306
+    if (isset($_GET['lang'])) {
307
+        $lang_demandee = $_GET['lang'];
308
+    }
309
+
310
+    // Renvoyer si besoin (et si la langue demandee existe)
311
+    if (
312
+        $GLOBALS['spip_lang'] != $lang_demandee
313
+        and changer_langue($lang_demandee)
314
+        and $lang_demandee != @$_GET['lang']
315
+    ) {
316
+        $destination = parametre_url(self(), 'lang', $lang_demandee, '&');
317
+        // ici on a besoin des var_truc
318
+        foreach ($_GET as $var => $val) {
319
+            if (!strncmp('var_', $var, 4)) {
320
+                $destination = parametre_url($destination, $var, $val, '&');
321
+            }
322
+        }
323
+        include_spip('inc/headers');
324
+        redirige_par_entete($destination);
325
+    }
326
+
327
+    // Subtilite : si la langue demandee par cookie est la bonne
328
+    // alors on fait comme si $lang etait passee dans l'URL
329
+    // (pour criteres {lang}).
330
+    $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
331 331
 }
332 332
 
333 333
 
@@ -345,22 +345,22 @@  discard block
 block discarded – undo
345 345
  *     La langue sélectionnée
346 346
  **/
347 347
 function utiliser_langue_site($liste_langues = null) {
348
-	// s'il existe une langue du site (en gros tout le temps en théorie)
349
-	if (
350
-		isset($GLOBALS['meta']['langue_site'])
351
-		// et si spip_langue est pas encore définie (ce que va faire changer_langue())
352
-		// ou qu'elle n'est pas identique à la langue du site
353
-		and (!isset($GLOBALS['spip_lang'])
354
-			or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
355
-	) {
356
-		return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
357
-	}
358
-	// en theorie là, la globale est définie, sinon c'est un problème.
359
-	if (!isset($GLOBALS['spip_lang'])) {
360
-		spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
361
-	}
362
-
363
-	return $GLOBALS['spip_lang'];
348
+    // s'il existe une langue du site (en gros tout le temps en théorie)
349
+    if (
350
+        isset($GLOBALS['meta']['langue_site'])
351
+        // et si spip_langue est pas encore définie (ce que va faire changer_langue())
352
+        // ou qu'elle n'est pas identique à la langue du site
353
+        and (!isset($GLOBALS['spip_lang'])
354
+            or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
355
+    ) {
356
+        return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
357
+    }
358
+    // en theorie là, la globale est définie, sinon c'est un problème.
359
+    if (!isset($GLOBALS['spip_lang'])) {
360
+        spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
361
+    }
362
+
363
+    return $GLOBALS['spip_lang'];
364 364
 }
365 365
 
366 366
 /**
@@ -379,30 +379,30 @@  discard block
 block discarded – undo
379 379
  **/
380 380
 function utiliser_langue_visiteur($liste_langues = null) {
381 381
 
382
-	$l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
383
-	if (isset($_COOKIE[$l])) {
384
-		if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
385
-			return $l;
386
-		}
387
-	}
388
-
389
-	if (isset($GLOBALS['visiteur_session']['lang'])) {
390
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
391
-			return $l;
392
-		}
393
-	}
394
-
395
-	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
396
-		foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
397
-			if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
398
-				if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
399
-					return $l;
400
-				}
401
-			}
402
-		}
403
-	}
404
-
405
-	return utiliser_langue_site($liste_langues);
382
+    $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
383
+    if (isset($_COOKIE[$l])) {
384
+        if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
385
+            return $l;
386
+        }
387
+    }
388
+
389
+    if (isset($GLOBALS['visiteur_session']['lang'])) {
390
+        if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
391
+            return $l;
392
+        }
393
+    }
394
+
395
+    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
396
+        foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
397
+            if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
398
+                if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
399
+                    return $l;
400
+                }
401
+            }
402
+        }
403
+    }
404
+
405
+    return utiliser_langue_site($liste_langues);
406 406
 }
407 407
 
408 408
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
  * @return int
413 413
  */
414 414
 function match_langue($chaine) {
415
-	return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
415
+    return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
416 416
 }
417 417
 
418 418
 /**
@@ -430,36 +430,36 @@  discard block
 block discarded – undo
430 430
  **/
431 431
 function init_langues() {
432 432
 
433
-	// liste des langues dans les meta, sauf a l'install
434
-	$all_langs = @$GLOBALS['meta']['langues_proposees'];
435
-
436
-	$tout = [];
437
-	if (!$all_langs) {
438
-		// trouver tous les modules lang/spip_xx.php
439
-		$modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
440
-		foreach ($modules as $name => $path) {
441
-			if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
442
-				if (match_langue($regs[1])) {
443
-					$tout[] = $regs[1];
444
-				}
445
-			}
446
-		}
447
-		sort($tout);
448
-		$tout = join(',', $tout);
449
-		// Si les langues n'ont pas change, ne rien faire
450
-		if ($tout != $all_langs) {
451
-			$GLOBALS['meta']['langues_proposees'] = $tout;
452
-			include_spip('inc/meta');
453
-			ecrire_meta('langues_proposees', $tout);
454
-		}
455
-	}
456
-	if (!isset($GLOBALS['meta']['langue_site'])) {
457
-		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
458
-		$GLOBALS['meta']['langue_site'] = $tout =
459
-			(!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false))
460
-				? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
461
-		ecrire_meta('langue_site', $tout);
462
-	}
433
+    // liste des langues dans les meta, sauf a l'install
434
+    $all_langs = @$GLOBALS['meta']['langues_proposees'];
435
+
436
+    $tout = [];
437
+    if (!$all_langs) {
438
+        // trouver tous les modules lang/spip_xx.php
439
+        $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
440
+        foreach ($modules as $name => $path) {
441
+            if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
442
+                if (match_langue($regs[1])) {
443
+                    $tout[] = $regs[1];
444
+                }
445
+            }
446
+        }
447
+        sort($tout);
448
+        $tout = join(',', $tout);
449
+        // Si les langues n'ont pas change, ne rien faire
450
+        if ($tout != $all_langs) {
451
+            $GLOBALS['meta']['langues_proposees'] = $tout;
452
+            include_spip('inc/meta');
453
+            ecrire_meta('langues_proposees', $tout);
454
+        }
455
+    }
456
+    if (!isset($GLOBALS['meta']['langue_site'])) {
457
+        // Initialisation : le francais si dispo, sinon la premiere langue trouvee
458
+        $GLOBALS['meta']['langue_site'] = $tout =
459
+            (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false))
460
+                ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
461
+        ecrire_meta('langue_site', $tout);
462
+    }
463 463
 }
464 464
 
465 465
 /**
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
  *     Code html de la balise <html>
474 474
  **/
475 475
 function html_lang_attributes() {
476
-	$lang = $GLOBALS['spip_lang'];
477
-	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
476
+    $lang = $GLOBALS['spip_lang'];
477
+    $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
478 478
 
479
-	return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
479
+    return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
480 480
 }
481 481
 
482 482
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  * @return string
491 491
  */
492 492
 function aide_lang_dir($spip_lang, $spip_lang_rtl) {
493
-	return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
493
+    return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
494 494
 }
495 495
 
496 496
 
Please login to merge, or discard this patch.
ecrire/inc/xml.php 1 patch
Indentation   +157 added lines, -157 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
 
@@ -47,24 +47,24 @@  discard block
 block discarded – undo
47 47
  *     - false si l'arbre xml ne peut être créé ou est vide
48 48
  **/
49 49
 function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) {
50
-	$contenu = '';
51
-	if (tester_url_absolue($fichier)) {
52
-		include_spip('inc/distant');
53
-		$contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]);
54
-		$contenu = $contenu['page'] ?? '';
55
-	} else {
56
-		lire_fichier($fichier, $contenu);
57
-	}
58
-	$arbre = [];
59
-	if ($contenu) {
60
-		$arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
61
-	}
50
+    $contenu = '';
51
+    if (tester_url_absolue($fichier)) {
52
+        include_spip('inc/distant');
53
+        $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]);
54
+        $contenu = $contenu['page'] ?? '';
55
+    } else {
56
+        lire_fichier($fichier, $contenu);
57
+    }
58
+    $arbre = [];
59
+    if ($contenu) {
60
+        $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
61
+    }
62 62
 
63
-	return count($arbre) ? $arbre : false;
63
+    return count($arbre) ? $arbre : false;
64 64
 }
65 65
 
66 66
 if (!defined('_SPIP_XML_TAG_SPLIT')) {
67
-	define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS');
67
+    define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS');
68 68
 }
69 69
 
70 70
 /**
@@ -83,150 +83,150 @@  discard block
 block discarded – undo
83 83
  *     - false si l'arbre xml ne peut être créé ou est vide
84 84
  **/
85 85
 function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) {
86
-	$out = [];
87
-	// enlever les commentaires
88
-	$charset = 'AUTO';
89
-	if ($clean === true) {
90
-		if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
91
-			$charset = $regs[2];
92
-		}
93
-		$texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
94
-		$texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
95
-		include_spip('inc/charsets');
96
-		$clean = $charset;
97
-		//$texte = importer_charset($texte,$charset);
98
-	}
99
-	if (is_string($clean)) {
100
-		$charset = $clean;
101
-	}
102
-	$txt = $texte;
86
+    $out = [];
87
+    // enlever les commentaires
88
+    $charset = 'AUTO';
89
+    if ($clean === true) {
90
+        if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
91
+            $charset = $regs[2];
92
+        }
93
+        $texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
94
+        $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
95
+        include_spip('inc/charsets');
96
+        $clean = $charset;
97
+        //$texte = importer_charset($texte,$charset);
98
+    }
99
+    if (is_string($clean)) {
100
+        $charset = $clean;
101
+    }
102
+    $txt = $texte;
103 103
 
104
-	// tant qu'il y a des tags
105
-	$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
106
-	while ((is_countable($chars) ? count($chars) : 0) >= 2) {
107
-		// tag ouvrant
108
-		//$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
104
+    // tant qu'il y a des tags
105
+    $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
106
+    while ((is_countable($chars) ? count($chars) : 0) >= 2) {
107
+        // tag ouvrant
108
+        //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
109 109
 
110
-		// $before doit etre vide ou des espaces uniquements!
111
-		$before = trim($chars[0]);
110
+        // $before doit etre vide ou des espaces uniquements!
111
+        $before = trim($chars[0]);
112 112
 
113
-		if (strlen($before) > 0) {
114
-			return importer_charset($texte, $charset);
115
-		}//$texte; // before non vide, donc on est dans du texte
113
+        if (strlen($before) > 0) {
114
+            return importer_charset($texte, $charset);
115
+        }//$texte; // before non vide, donc on est dans du texte
116 116
 
117
-		$tag = rtrim($chars[1]);
118
-		$txt = $chars[2];
117
+        $tag = rtrim($chars[1]);
118
+        $txt = $chars[2];
119 119
 
120
-		if (strncmp($tag, '![CDATA[', 8) == 0) {
121
-			return importer_charset($texte, $charset);
122
-		}//$texte;
123
-		if (substr($tag, -1) == '/') { // self closing tag
124
-			$tag = rtrim(substr($tag, 0, strlen($tag) - 1));
125
-			$out[$tag][] = '';
126
-		} else {
127
-			$closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
128
-			$closing_tag = reset($closing_tag);
129
-			// tag fermant
130
-			$ncclos = strlen("</$closing_tag>");
131
-			$p = strpos($txt, (string) "</$closing_tag>");
132
-			if ($p !== false and (strpos($txt, '<') < $p)) {
133
-				$nclose = 0;
134
-				$nopen = 0;
135
-				$d = 0;
136
-				while (
137
-					$p !== false
138
-					and ($morceau = substr($txt, $d, $p - $d))
139
-					and (($nopen += preg_match_all(
140
-						'{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is',
141
-						$morceau,
142
-						$matches,
143
-						PREG_SET_ORDER
144
-					)) > $nclose)
145
-				) {
146
-					$nclose++;
147
-					$d = $p + $ncclos;
148
-					$p = strpos($txt, (string) "</$closing_tag>", $d);
149
-				}
150
-			}
151
-			if ($p === false) {
152
-				if ($strict) {
153
-					$out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
120
+        if (strncmp($tag, '![CDATA[', 8) == 0) {
121
+            return importer_charset($texte, $charset);
122
+        }//$texte;
123
+        if (substr($tag, -1) == '/') { // self closing tag
124
+            $tag = rtrim(substr($tag, 0, strlen($tag) - 1));
125
+            $out[$tag][] = '';
126
+        } else {
127
+            $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
128
+            $closing_tag = reset($closing_tag);
129
+            // tag fermant
130
+            $ncclos = strlen("</$closing_tag>");
131
+            $p = strpos($txt, (string) "</$closing_tag>");
132
+            if ($p !== false and (strpos($txt, '<') < $p)) {
133
+                $nclose = 0;
134
+                $nopen = 0;
135
+                $d = 0;
136
+                while (
137
+                    $p !== false
138
+                    and ($morceau = substr($txt, $d, $p - $d))
139
+                    and (($nopen += preg_match_all(
140
+                        '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is',
141
+                        $morceau,
142
+                        $matches,
143
+                        PREG_SET_ORDER
144
+                    )) > $nclose)
145
+                ) {
146
+                    $nclose++;
147
+                    $d = $p + $ncclos;
148
+                    $p = strpos($txt, (string) "</$closing_tag>", $d);
149
+                }
150
+            }
151
+            if ($p === false) {
152
+                if ($strict) {
153
+                    $out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
154 154
 
155
-					return $out;
156
-				} else {
157
-					return importer_charset($texte, $charset);
158
-				}//$texte // un tag qui constitue du texte a reporter dans $before
159
-			}
160
-			$content = substr($txt, 0, $p);
161
-			$txt = substr($txt, $p + $ncclos);
162
-			if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile
163
-			$out[$tag][] = importer_charset($content, $charset);
164
-			}//$content;
165
-			else {
166
-				$out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
167
-			}
168
-		}
169
-		$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
170
-	}
171
-	if (count($out) && (strlen(trim($txt)) == 0)) {
172
-		return $out;
173
-	} else {
174
-		return importer_charset($texte, $charset);
175
-	}//$texte;
155
+                    return $out;
156
+                } else {
157
+                    return importer_charset($texte, $charset);
158
+                }//$texte // un tag qui constitue du texte a reporter dans $before
159
+            }
160
+            $content = substr($txt, 0, $p);
161
+            $txt = substr($txt, $p + $ncclos);
162
+            if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile
163
+            $out[$tag][] = importer_charset($content, $charset);
164
+            }//$content;
165
+            else {
166
+                $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
167
+            }
168
+        }
169
+        $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
170
+    }
171
+    if (count($out) && (strlen(trim($txt)) == 0)) {
172
+        return $out;
173
+    } else {
174
+        return importer_charset($texte, $charset);
175
+    }//$texte;
176 176
 }
177 177
 
178 178
 function spip_xml_aplatit($arbre, $separateur = ' ') {
179
-	$s = '';
180
-	if (is_array($arbre)) {
181
-		foreach ($arbre as $tag => $feuille) {
182
-			if (is_array($feuille)) {
183
-				if ($tag !== intval($tag)) {
184
-					$f = spip_xml_aplatit($feuille, $separateur);
185
-					if (strlen($f)) {
186
-						$tagf = explode(' ', $tag);
187
-						$tagf = $tagf[0];
188
-						$s .= "<$tag>$f</$tagf>";
189
-					} else {
190
-						$s .= "<$tag />";
191
-					}
192
-				} else {
193
-					$s .= spip_xml_aplatit($feuille);
194
-				}
195
-				$s .= $separateur;
196
-			} else {
197
-				$s .= "$feuille$separateur";
198
-			}
199
-		}
200
-	}
179
+    $s = '';
180
+    if (is_array($arbre)) {
181
+        foreach ($arbre as $tag => $feuille) {
182
+            if (is_array($feuille)) {
183
+                if ($tag !== intval($tag)) {
184
+                    $f = spip_xml_aplatit($feuille, $separateur);
185
+                    if (strlen($f)) {
186
+                        $tagf = explode(' ', $tag);
187
+                        $tagf = $tagf[0];
188
+                        $s .= "<$tag>$f</$tagf>";
189
+                    } else {
190
+                        $s .= "<$tag />";
191
+                    }
192
+                } else {
193
+                    $s .= spip_xml_aplatit($feuille);
194
+                }
195
+                $s .= $separateur;
196
+            } else {
197
+                $s .= "$feuille$separateur";
198
+            }
199
+        }
200
+    }
201 201
 
202
-	return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
202
+    return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
203 203
 }
204 204
 
205 205
 function spip_xml_tagname($tag) {
206
-	if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
207
-		return $reg[1];
208
-	}
206
+    if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
207
+        return $reg[1];
208
+    }
209 209
 
210
-	return '';
210
+    return '';
211 211
 }
212 212
 
213 213
 function spip_xml_decompose_tag($tag) {
214
-	$tagname = spip_xml_tagname($tag);
215
-	$liste = [];
216
-	$tag = ltrim(strpbrk($tag, " \n\t"));
217
-	$p = strpos($tag, '=');
218
-	while ($p !== false) {
219
-		$attr = trim(substr($tag, 0, $p));
220
-		$tag = ltrim(substr($tag, $p + 1));
221
-		$quote = $tag[0];
222
-		$p = strpos($tag, $quote, 1);
223
-		$cont = substr($tag, 1, $p - 1);
224
-		$liste[$attr] = $cont;
225
-		$tag = substr($tag, $p + 1);
226
-		$p = strpos($tag, '=');
227
-	}
214
+    $tagname = spip_xml_tagname($tag);
215
+    $liste = [];
216
+    $tag = ltrim(strpbrk($tag, " \n\t"));
217
+    $p = strpos($tag, '=');
218
+    while ($p !== false) {
219
+        $attr = trim(substr($tag, 0, $p));
220
+        $tag = ltrim(substr($tag, $p + 1));
221
+        $quote = $tag[0];
222
+        $p = strpos($tag, $quote, 1);
223
+        $cont = substr($tag, 1, $p - 1);
224
+        $liste[$attr] = $cont;
225
+        $tag = substr($tag, $p + 1);
226
+        $p = strpos($tag, '=');
227
+    }
228 228
 
229
-	return [$tagname, $liste];
229
+    return [$tagname, $liste];
230 230
 }
231 231
 
232 232
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  *     false si aucun élément ne valide l'expression régulière, true sinon.
250 250
  **/
251 251
 function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) {
252
-	if ($init) {
253
-		$matches = [];
254
-	}
255
-	if (is_array($arbre) && count($arbre)) {
256
-		foreach (array_keys($arbre) as $tag) {
257
-			if (preg_match($regexp, $tag)) {
258
-				$matches[$tag] = &$arbre[$tag];
259
-			}
260
-			if (is_array($arbre[$tag])) {
261
-				foreach (array_keys($arbre[$tag]) as $occurences) {
262
-					spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
-				}
264
-			}
265
-		}
266
-	}
252
+    if ($init) {
253
+        $matches = [];
254
+    }
255
+    if (is_array($arbre) && count($arbre)) {
256
+        foreach (array_keys($arbre) as $tag) {
257
+            if (preg_match($regexp, $tag)) {
258
+                $matches[$tag] = &$arbre[$tag];
259
+            }
260
+            if (is_array($arbre[$tag])) {
261
+                foreach (array_keys($arbre[$tag]) as $occurences) {
262
+                    spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
+                }
264
+            }
265
+        }
266
+    }
267 267
 
268
-	return (is_countable($matches) ? count($matches) : 0);
268
+    return (is_countable($matches) ? count($matches) : 0);
269 269
 }
Please login to merge, or discard this patch.
ecrire/inc/invalideur.php 1 patch
Indentation   +138 added lines, -138 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
 include_spip('base/serial');
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * en droit de l'éliminer
28 28
  */
29 29
 if (!defined('_AGE_CACHE_ATIME')) {
30
-	define('_AGE_CACHE_ATIME', 3600);
30
+    define('_AGE_CACHE_ATIME', 3600);
31 31
 }
32 32
 
33 33
 
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
  * @return int Taille approximative en octets
41 41
  **/
42 42
 function taille_du_cache() {
43
-	# check dirs until we reach > 500 files
44
-	$t = 0;
45
-	$n = 0;
46
-	$time = $GLOBALS['meta']['cache_mark'] ?? 0;
47
-	for ($i = 0; $i < 256; $i++) {
48
-		$dir = _DIR_CACHE . sprintf('%02s', dechex($i));
49
-		if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
-			while (($f = readdir($d)) !== false) {
51
-				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
-					$n++;
53
-					if ($a['mtime'] >= $time) {
54
-						if ($a['blocks'] > 0) {
55
-							$t += 512 * $a['blocks'];
56
-						} else {
57
-							$t += $a['size'];
58
-						}
59
-					}
60
-				}
61
-			}
62
-		}
63
-		if ($n > 500) {
64
-			return intval(256 * $t / (1 + $i));
65
-		}
66
-	}
67
-	return $t;
43
+    # check dirs until we reach > 500 files
44
+    $t = 0;
45
+    $n = 0;
46
+    $time = $GLOBALS['meta']['cache_mark'] ?? 0;
47
+    for ($i = 0; $i < 256; $i++) {
48
+        $dir = _DIR_CACHE . sprintf('%02s', dechex($i));
49
+        if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
+            while (($f = readdir($d)) !== false) {
51
+                if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
+                    $n++;
53
+                    if ($a['mtime'] >= $time) {
54
+                        if ($a['blocks'] > 0) {
55
+                            $t += 512 * $a['blocks'];
56
+                        } else {
57
+                            $t += $a['size'];
58
+                        }
59
+                    }
60
+                }
61
+            }
62
+        }
63
+        if ($n > 500) {
64
+            return intval(256 * $t / (1 + $i));
65
+        }
66
+    }
67
+    return $t;
68 68
 }
69 69
 
70 70
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     Inutilisé
92 92
  **/
93 93
 function inc_suivre_invalideur_dist($cond, $modif = true) {
94
-	if (!$modif) {
95
-		return;
96
-	}
97
-
98
-	// determiner l'objet modifie : forum, article, etc
99
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
-		$objet = objet_type($r[1]);
101
-	}
102
-
103
-	// stocker la date_modif_$objet (ne sert a rien pour le moment)
104
-	if (isset($objet)) {
105
-		ecrire_meta('derniere_modif_' . $objet, time());
106
-	}
107
-
108
-	// si $derniere_modif_invalide est un array('article', 'rubrique')
109
-	// n'affecter la meta que si un de ces objets est modifie
110
-	if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
-			ecrire_meta('derniere_modif', time());
113
-		}
114
-	} // sinon, cas standard, toujours affecter la meta
115
-	else {
116
-		ecrire_meta('derniere_modif', time());
117
-	}
94
+    if (!$modif) {
95
+        return;
96
+    }
97
+
98
+    // determiner l'objet modifie : forum, article, etc
99
+    if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
+        $objet = objet_type($r[1]);
101
+    }
102
+
103
+    // stocker la date_modif_$objet (ne sert a rien pour le moment)
104
+    if (isset($objet)) {
105
+        ecrire_meta('derniere_modif_' . $objet, time());
106
+    }
107
+
108
+    // si $derniere_modif_invalide est un array('article', 'rubrique')
109
+    // n'affecter la meta que si un de ces objets est modifie
110
+    if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
+        if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
+            ecrire_meta('derniere_modif', time());
113
+        }
114
+    } // sinon, cas standard, toujours affecter la meta
115
+    else {
116
+        ecrire_meta('derniere_modif', time());
117
+    }
118 118
 }
119 119
 
120 120
 
@@ -139,57 +139,57 @@  discard block
 block discarded – undo
139 139
  *     Nombre de fichiers supprimés
140 140
  **/
141 141
 function purger_repertoire($dir, $options = []) {
142
-	if (!is_dir($dir) or !is_readable($dir)) {
143
-		return 0;
144
-	}
145
-
146
-	// sur certains sites on veut absolument garder certains caches référencés dans un CDN
147
-	// on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
148
-	if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
149
-		return 0;
150
-	}
151
-
152
-	$handle = opendir($dir);
153
-	if (!$handle) {
154
-		return 0;
155
-	}
156
-
157
-	$total = 0;
158
-
159
-	while (($fichier = @readdir($handle)) !== false) {
160
-		// Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
161
-		if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
162
-			continue;
163
-		}
164
-		$chemin = "$dir/$fichier";
165
-		if (is_file($chemin)) {
166
-			if (
167
-				(!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
168
-				and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
169
-			) {
170
-				supprimer_fichier($chemin);
171
-				$total++;
172
-			}
173
-		} else {
174
-			if (is_dir($chemin)) {
175
-				$opts = $options;
176
-				if (isset($options['limit'])) {
177
-					$opts['limit'] = $options['limit'] - $total;
178
-				}
179
-				$total += purger_repertoire($chemin, $opts);
180
-				if (isset($options['subdir']) && $options['subdir']) {
181
-					spip_unlink($chemin);
182
-				}
183
-			}
184
-		}
185
-
186
-		if (isset($options['limit']) and $total >= $options['limit']) {
187
-			break;
188
-		}
189
-	}
190
-	closedir($handle);
191
-
192
-	return $total;
142
+    if (!is_dir($dir) or !is_readable($dir)) {
143
+        return 0;
144
+    }
145
+
146
+    // sur certains sites on veut absolument garder certains caches référencés dans un CDN
147
+    // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
148
+    if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
149
+        return 0;
150
+    }
151
+
152
+    $handle = opendir($dir);
153
+    if (!$handle) {
154
+        return 0;
155
+    }
156
+
157
+    $total = 0;
158
+
159
+    while (($fichier = @readdir($handle)) !== false) {
160
+        // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
161
+        if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
162
+            continue;
163
+        }
164
+        $chemin = "$dir/$fichier";
165
+        if (is_file($chemin)) {
166
+            if (
167
+                (!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
168
+                and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
169
+            ) {
170
+                supprimer_fichier($chemin);
171
+                $total++;
172
+            }
173
+        } else {
174
+            if (is_dir($chemin)) {
175
+                $opts = $options;
176
+                if (isset($options['limit'])) {
177
+                    $opts['limit'] = $options['limit'] - $total;
178
+                }
179
+                $total += purger_repertoire($chemin, $opts);
180
+                if (isset($options['subdir']) && $options['subdir']) {
181
+                    spip_unlink($chemin);
182
+                }
183
+            }
184
+        }
185
+
186
+        if (isset($options['limit']) and $total >= $options['limit']) {
187
+            break;
188
+        }
189
+    }
190
+    closedir($handle);
191
+
192
+    return $total;
193 193
 }
194 194
 
195 195
 
@@ -200,26 +200,26 @@  discard block
 block discarded – undo
200 200
 // Securite : est sur que c'est un cache
201 201
 function retire_cache($cache) {
202 202
 
203
-	if (
204
-		preg_match(
205
-			',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
206
-			$cache
207
-		)
208
-	) {
209
-		// supprimer le fichier (de facon propre)
210
-		supprimer_fichier(_DIR_CACHE . $cache);
211
-	} else {
212
-		spip_log("Nom de fichier cache incorrect : $cache");
213
-	}
203
+    if (
204
+        preg_match(
205
+            ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
206
+            $cache
207
+        )
208
+    ) {
209
+        // supprimer le fichier (de facon propre)
210
+        supprimer_fichier(_DIR_CACHE . $cache);
211
+    } else {
212
+        spip_log("Nom de fichier cache incorrect : $cache");
213
+    }
214 214
 }
215 215
 
216 216
 // Supprimer les caches marques "x"
217 217
 // A priori dans cette version la fonction ne sera pas appelee, car
218 218
 // la meta est toujours false ; mais evitons un bug si elle est appellee
219 219
 function inc_retire_caches_dist($chemin = '') {
220
-	if (isset($GLOBALS['meta']['invalider_caches'])) {
221
-		effacer_meta('invalider_caches');
222
-	} # concurrence
220
+    if (isset($GLOBALS['meta']['invalider_caches'])) {
221
+        effacer_meta('invalider_caches');
222
+    } # concurrence
223 223
 }
224 224
 
225 225
 #######################################################################
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 ##
231 231
 
232 232
 function retire_caches($chemin = '') {
233
-	if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
234
-		return $retire_caches($chemin);
235
-	}
233
+    if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
234
+        return $retire_caches($chemin);
235
+    }
236 236
 }
237 237
 
238 238
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 // (note: si absente, n'est pas appellee)
241 241
 
242 242
 function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) {
243
-	if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
244
-		return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
245
-	}
246
-	return $corps;
243
+    if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
244
+        return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
245
+    }
246
+    return $corps;
247 247
 }
248 248
 
249 249
 
@@ -252,41 +252,41 @@  discard block
 block discarded – undo
252 252
 // invoquee quand on vide tout le cache en bloc (action/purger)
253 253
 //
254 254
 function supprime_invalideurs() {
255
-	if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
256
-		return $supprime_invalideurs();
257
-	}
255
+    if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
256
+        return $supprime_invalideurs();
257
+    }
258 258
 }
259 259
 
260 260
 
261 261
 // Calcul des pages : noter dans la base les liens d'invalidation
262 262
 function maj_invalideurs($fichier, &$page) {
263
-	if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
264
-		return $maj_invalideurs($fichier, $page);
265
-	}
263
+    if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
264
+        return $maj_invalideurs($fichier, $page);
265
+    }
266 266
 }
267 267
 
268 268
 
269 269
 // les invalideurs sont de la forme "objet/id_objet"
270 270
 function insere_invalideur($inval, $fichier) {
271
-	if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
272
-		return $insere_invalideur($inval, $fichier);
273
-	}
271
+    if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
272
+        return $insere_invalideur($inval, $fichier);
273
+    }
274 274
 }
275 275
 
276 276
 //
277 277
 // Marquer les fichiers caches invalides comme etant a supprimer
278 278
 //
279 279
 function applique_invalideur($depart) {
280
-	if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
281
-		return $applique_invalideur($depart);
282
-	}
280
+    if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
281
+        return $applique_invalideur($depart);
282
+    }
283 283
 }
284 284
 
285 285
 //
286 286
 // Invalider les caches liés à telle condition
287 287
 //
288 288
 function suivre_invalideur($cond, $modif = true) {
289
-	if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
290
-		return $suivre_invalideur($cond, $modif);
291
-	}
289
+    if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
290
+        return $suivre_invalideur($cond, $modif);
291
+    }
292 292
 }
Please login to merge, or discard this patch.
ecrire/xml/indenter.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -11,55 +11,55 @@
 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
-	public function debutElement($phraseur, $name, $attrs) {
20
-		xml_debutElement($this, $name, $attrs);
21
-	}
19
+    public function debutElement($phraseur, $name, $attrs) {
20
+        xml_debutElement($this, $name, $attrs);
21
+    }
22 22
 
23
-	public function finElement($phraseur, $name) {
24
-		xml_finElement($this, $name);
25
-	}
23
+    public function finElement($phraseur, $name) {
24
+        xml_finElement($this, $name);
25
+    }
26 26
 
27
-	public function textElement($phraseur, $data) {
28
-		xml_textElement($this, $data);
29
-	}
27
+    public function textElement($phraseur, $data) {
28
+        xml_textElement($this, $data);
29
+    }
30 30
 
31
-	public function piElement($phraseur, $target, $data) {
32
-		xml_PiElement($this, $target, $data);
33
-	}
31
+    public function piElement($phraseur, $target, $data) {
32
+        xml_PiElement($this, $target, $data);
33
+    }
34 34
 
35
-	public function defaultElement($phraseur, $data) {
36
-		xml_defaultElement($this, $data);
37
-	}
35
+    public function defaultElement($phraseur, $data) {
36
+        xml_defaultElement($this, $data);
37
+    }
38 38
 
39
-	public function phraserTout($phraseur, $data) {
40
-		xml_parsestring($this, $data);
41
-	}
39
+    public function phraserTout($phraseur, $data) {
40
+        xml_parsestring($this, $data);
41
+    }
42 42
 
43
-	public $depth = '';
44
-	public $res = '';
45
-	public $err = [];
46
-	public $contenu = [];
47
-	public $ouvrant = [];
48
-	public $reperes = [];
49
-	public $entete = '';
50
-	public $page = '';
51
-	public $dtc = null;
52
-	public $sax = null;
43
+    public $depth = '';
44
+    public $res = '';
45
+    public $err = [];
46
+    public $contenu = [];
47
+    public $ouvrant = [];
48
+    public $reperes = [];
49
+    public $entete = '';
50
+    public $page = '';
51
+    public $dtc = null;
52
+    public $sax = null;
53 53
 }
54 54
 
55 55
 function xml_indenter_dist($page, $apply = false) {
56
-	$sax = charger_fonction('sax', 'xml');
57
-	$f = new IndenteurXML();
58
-	$sax($page, $apply, $f);
59
-	if (!$f->err) {
60
-		return $f->entete . $f->res;
61
-	}
62
-	spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation');
56
+    $sax = charger_fonction('sax', 'xml');
57
+    $f = new IndenteurXML();
58
+    $sax($page, $apply, $f);
59
+    if (!$f->err) {
60
+        return $f->entete . $f->res;
61
+    }
62
+    spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation');
63 63
 
64
-	return $f->entete . $f->page;
64
+    return $f->entete . $f->page;
65 65
 }
Please login to merge, or discard this patch.
ecrire/xml/analyser_dtd.php 1 patch
Indentation   +335 added lines, -335 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
 function charger_dtd($grammaire, $avail, $rotlvl) {
20
-	$r = null;
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') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' 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;
20
+    $r = null;
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') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' 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
@@ -74,153 +74,153 @@  discard block
 block discarded – undo
74 74
 // et parentheser le tout pour que  | + * ? s'applique dessus.
75 75
 
76 76
 function compilerRegle($val) {
77
-	$x = str_replace(
78
-		'()',
79
-		'',
80
-		preg_replace(
81
-			'/\s*,\s*/',
82
-			'',
83
-			preg_replace(
84
-				'/(\w+)\s*/',
85
-				'(?:\1 )',
86
-				preg_replace(
87
-					'/\s*\)/',
88
-					')',
89
-					preg_replace(
90
-						'/\s*([(+*|?])\s*/',
91
-						'\1',
92
-						preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)
93
-					)
94
-				)
95
-			)
96
-		)
97
-	);
98
-
99
-	return $x;
77
+    $x = str_replace(
78
+        '()',
79
+        '',
80
+        preg_replace(
81
+            '/\s*,\s*/',
82
+            '',
83
+            preg_replace(
84
+                '/(\w+)\s*/',
85
+                '(?:\1 )',
86
+                preg_replace(
87
+                    '/\s*\)/',
88
+                    ')',
89
+                    preg_replace(
90
+                        '/\s*([(+*|?])\s*/',
91
+                        '\1',
92
+                        preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)
93
+                    )
94
+                )
95
+            )
96
+        )
97
+    );
98
+
99
+    return $x;
100 100
 }
101 101
 
102 102
 
103 103
 function analyser_dtd($loc, $avail, &$dtc) {
104
-	// creer le repertoire de cache si ce n'est fait
105
-	// (utile aussi pour le resultat de la compil)
106
-	$file = sous_repertoire(_DIR_CACHE_XML);
107
-	// si DTD locale, ignorer ce repertoire pour le moment
108
-	if ($avail == 'SYSTEM') {
109
-		$file = $loc;
110
-		if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
111
-			$file = substr($file, strlen(_DIR_RACINE));
112
-		}
113
-		$file = find_in_path($file);
114
-	} else {
115
-		$file .= preg_replace('/[^\w.]/', '_', $loc);
116
-	}
117
-
118
-	$dtd = '';
119
-	if (@is_readable($file)) {
120
-		lire_fichier($file, $dtd);
121
-	} else {
122
-		if ($avail == 'PUBLIC') {
123
-			include_spip('inc/distant');
124
-			$dtd = recuperer_url($loc);
125
-			$dtd = trim($dtd['page'] ?? '');
126
-			if ($dtd) {
127
-				ecrire_fichier($file, $dtd, true);
128
-			}
129
-		}
130
-	}
131
-
132
-	$dtd = ltrim($dtd);
133
-	if (!$dtd) {
134
-		spip_log("DTD '$loc' ($file) inaccessible");
135
-
136
-		return false;
137
-	} else {
138
-		spip_log("analyse de la DTD $loc ");
139
-	}
140
-
141
-	while ($dtd) {
142
-		if ($dtd[0] != '<') {
143
-			$r = analyser_dtd_lexeme($dtd, $dtc, $loc);
144
-		} elseif ($dtd[1] != '!') {
145
-			$r = analyser_dtd_pi($dtd, $dtc, $loc);
146
-		} elseif ($dtd[2] == '[') {
147
-			$r = analyser_dtd_data($dtd, $dtc, $loc);
148
-		} else {
149
-			switch ($dtd[3]) {
150
-				case '%':
151
-					$r = analyser_dtd_data($dtd, $dtc, $loc);
152
-					break;
153
-				case 'T':
154
-					$r = analyser_dtd_attlist($dtd, $dtc, $loc);
155
-					break;
156
-				case 'L':
157
-					$r = analyser_dtd_element($dtd, $dtc, $loc);
158
-					break;
159
-				case 'N':
160
-					$r = analyser_dtd_entity($dtd, $dtc, $loc);
161
-					break;
162
-				case 'O':
163
-					$r = analyser_dtd_notation($dtd, $dtc, $loc);
164
-					break;
165
-				case '-':
166
-					$r = analyser_dtd_comment($dtd, $dtc, $loc);
167
-					break;
168
-				default:
169
-					$r = -1;
170
-			}
171
-		}
172
-		if (!is_string($r)) {
173
-			spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . '.....');
174
-
175
-			return false;
176
-		}
177
-		$dtd = $r;
178
-	}
179
-
180
-	return true;
104
+    // creer le repertoire de cache si ce n'est fait
105
+    // (utile aussi pour le resultat de la compil)
106
+    $file = sous_repertoire(_DIR_CACHE_XML);
107
+    // si DTD locale, ignorer ce repertoire pour le moment
108
+    if ($avail == 'SYSTEM') {
109
+        $file = $loc;
110
+        if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
111
+            $file = substr($file, strlen(_DIR_RACINE));
112
+        }
113
+        $file = find_in_path($file);
114
+    } else {
115
+        $file .= preg_replace('/[^\w.]/', '_', $loc);
116
+    }
117
+
118
+    $dtd = '';
119
+    if (@is_readable($file)) {
120
+        lire_fichier($file, $dtd);
121
+    } else {
122
+        if ($avail == 'PUBLIC') {
123
+            include_spip('inc/distant');
124
+            $dtd = recuperer_url($loc);
125
+            $dtd = trim($dtd['page'] ?? '');
126
+            if ($dtd) {
127
+                ecrire_fichier($file, $dtd, true);
128
+            }
129
+        }
130
+    }
131
+
132
+    $dtd = ltrim($dtd);
133
+    if (!$dtd) {
134
+        spip_log("DTD '$loc' ($file) inaccessible");
135
+
136
+        return false;
137
+    } else {
138
+        spip_log("analyse de la DTD $loc ");
139
+    }
140
+
141
+    while ($dtd) {
142
+        if ($dtd[0] != '<') {
143
+            $r = analyser_dtd_lexeme($dtd, $dtc, $loc);
144
+        } elseif ($dtd[1] != '!') {
145
+            $r = analyser_dtd_pi($dtd, $dtc, $loc);
146
+        } elseif ($dtd[2] == '[') {
147
+            $r = analyser_dtd_data($dtd, $dtc, $loc);
148
+        } else {
149
+            switch ($dtd[3]) {
150
+                case '%':
151
+                    $r = analyser_dtd_data($dtd, $dtc, $loc);
152
+                    break;
153
+                case 'T':
154
+                    $r = analyser_dtd_attlist($dtd, $dtc, $loc);
155
+                    break;
156
+                case 'L':
157
+                    $r = analyser_dtd_element($dtd, $dtc, $loc);
158
+                    break;
159
+                case 'N':
160
+                    $r = analyser_dtd_entity($dtd, $dtc, $loc);
161
+                    break;
162
+                case 'O':
163
+                    $r = analyser_dtd_notation($dtd, $dtc, $loc);
164
+                    break;
165
+                case '-':
166
+                    $r = analyser_dtd_comment($dtd, $dtc, $loc);
167
+                    break;
168
+                default:
169
+                    $r = -1;
170
+            }
171
+        }
172
+        if (!is_string($r)) {
173
+            spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . '.....');
174
+
175
+            return false;
176
+        }
177
+        $dtd = $r;
178
+    }
179
+
180
+    return true;
181 181
 }
182 182
 
183 183
 function analyser_dtd_comment($dtd, &$dtc, $grammaire) {
184
-	// ejecter les commentaires, surtout quand ils contiennent du code.
185
-	// Option /s car sur plusieurs lignes parfois
184
+    // ejecter les commentaires, surtout quand ils contiennent du code.
185
+    // Option /s car sur plusieurs lignes parfois
186 186
 
187
-	if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
188
-		return -6;
189
-	}
187
+    if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
188
+        return -6;
189
+    }
190 190
 
191
-	return $m[1];
191
+    return $m[1];
192 192
 }
193 193
 
194 194
 function analyser_dtd_pi($dtd, &$dtc, $grammaire) {
195
-	if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
196
-		return -10;
197
-	}
195
+    if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
196
+        return -10;
197
+    }
198 198
 
199
-	return $m[1];
199
+    return $m[1];
200 200
 }
201 201
 
202 202
 function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) {
203 203
 
204
-	if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
205
-		return -9;
206
-	}
207
-
208
-	[, $s] = $m;
209
-	$n = $dtc->macros[$s];
210
-
211
-	if (is_array($n)) {
212
-		// en cas d'inclusion, l'espace de nom est le meme
213
-		// mais gaffe aux DTD dont l'URL est relative a l'engloblante
214
-		if (
215
-			($n[0] == 'PUBLIC')
216
-			and !tester_url_absolue($n[1])
217
-		) {
218
-			$n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
219
-		}
220
-		analyser_dtd($n[1], $n[0], $dtc);
221
-	}
222
-
223
-	return ltrim(substr($dtd, strlen($m[0])));
204
+    if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
205
+        return -9;
206
+    }
207
+
208
+    [, $s] = $m;
209
+    $n = $dtc->macros[$s];
210
+
211
+    if (is_array($n)) {
212
+        // en cas d'inclusion, l'espace de nom est le meme
213
+        // mais gaffe aux DTD dont l'URL est relative a l'engloblante
214
+        if (
215
+            ($n[0] == 'PUBLIC')
216
+            and !tester_url_absolue($n[1])
217
+        ) {
218
+            $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
219
+        }
220
+        analyser_dtd($n[1], $n[0], $dtc);
221
+    }
222
+
223
+    return ltrim(substr($dtd, strlen($m[0])));
224 224
 }
225 225
 
226 226
 // il faudrait gerer plus proprement les niveaux d'inclusion:
@@ -228,83 +228,83 @@  discard block
 block discarded – undo
228 228
 
229 229
 function analyser_dtd_data($dtd, &$dtc, $grammaire) {
230 230
 
231
-	if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
232
-		return -11;
233
-	}
234
-	if (
235
-		!preg_match(
236
-			'/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s',
237
-			$m[2],
238
-			$r
239
-		)
240
-	) {
241
-		return -12;
242
-	}
243
-
244
-	if ($dtc->macros[$m[1]] == 'INCLUDE') {
245
-		$retour = $r[1] . substr($m[2], strlen($r[0]));
246
-	} else {
247
-		$retour = substr($m[2], strlen($r[0]));
248
-	}
249
-
250
-	return $retour;
231
+    if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
232
+        return -11;
233
+    }
234
+    if (
235
+        !preg_match(
236
+            '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s',
237
+            $m[2],
238
+            $r
239
+        )
240
+    ) {
241
+        return -12;
242
+    }
243
+
244
+    if ($dtc->macros[$m[1]] == 'INCLUDE') {
245
+        $retour = $r[1] . substr($m[2], strlen($r[0]));
246
+    } else {
247
+        $retour = substr($m[2], strlen($r[0]));
248
+    }
249
+
250
+    return $retour;
251 251
 }
252 252
 
253 253
 function analyser_dtd_notation($dtd, &$dtc, $grammaire) {
254
-	if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
255
-		return -8;
256
-	}
257
-	spip_log('analyser_dtd_notation a ecrire');
254
+    if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
255
+        return -8;
256
+    }
257
+    spip_log('analyser_dtd_notation a ecrire');
258 258
 
259
-	return $m[1];
259
+    return $m[1];
260 260
 }
261 261
 
262 262
 function analyser_dtd_entity($dtd, &$dtc, $grammaire) {
263
-	if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
264
-		return -2;
265
-	}
266
-
267
-	[$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m;
268
-
269
-	if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
270
-		return $dtd;
271
-	}
272
-	if (isset($dtc->entites[$nom])) {
273
-		spip_log("redefinition de l'entite $nom");
274
-	}
275
-	if ($k6) {
276
-		return $k6 . $dtd;
277
-	} // cas du synonyme complet
278
-	$val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
279
-
280
-	// cas particulier double evaluation: 'PUBLIC "..." "...."'
281
-	if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
282
-		[$t, $type, $val, $q, $alt] = $r;
283
-	}
284
-
285
-	if (!$term) {
286
-		$dtc->entites[$nom] = $val;
287
-	} elseif (!$type) {
288
-		$dtc->macros[$nom] = $val;
289
-	} else {
290
-		if (($type == 'SYSTEM') and !$alt) {
291
-			$alt = $val;
292
-		}
293
-		if (!$alt) {
294
-			$dtc->macros[$nom] = $val;
295
-		} else {
296
-			if (
297
-				($type == 'PUBLIC')
298
-				and (strpos($alt, '/') === false)
299
-			) {
300
-				$alt = preg_replace(',/[^/]+$,', '/', $grammaire)
301
-					. $alt;
302
-			}
303
-			$dtc->macros[$nom] = [$type, $alt];
304
-		}
305
-	}
306
-
307
-	return $dtd;
263
+    if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
264
+        return -2;
265
+    }
266
+
267
+    [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m;
268
+
269
+    if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
270
+        return $dtd;
271
+    }
272
+    if (isset($dtc->entites[$nom])) {
273
+        spip_log("redefinition de l'entite $nom");
274
+    }
275
+    if ($k6) {
276
+        return $k6 . $dtd;
277
+    } // cas du synonyme complet
278
+    $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
279
+
280
+    // cas particulier double evaluation: 'PUBLIC "..." "...."'
281
+    if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
282
+        [$t, $type, $val, $q, $alt] = $r;
283
+    }
284
+
285
+    if (!$term) {
286
+        $dtc->entites[$nom] = $val;
287
+    } elseif (!$type) {
288
+        $dtc->macros[$nom] = $val;
289
+    } else {
290
+        if (($type == 'SYSTEM') and !$alt) {
291
+            $alt = $val;
292
+        }
293
+        if (!$alt) {
294
+            $dtc->macros[$nom] = $val;
295
+        } else {
296
+            if (
297
+                ($type == 'PUBLIC')
298
+                and (strpos($alt, '/') === false)
299
+            ) {
300
+                $alt = preg_replace(',/[^/]+$,', '/', $grammaire)
301
+                    . $alt;
302
+            }
303
+            $dtc->macros[$nom] = [$type, $alt];
304
+        }
305
+    }
306
+
307
+    return $dtd;
308 308
 }
309 309
 
310 310
 // Dresser le tableau des filles potentielles de l'element
@@ -317,76 +317,76 @@  discard block
 block discarded – undo
317 317
 // Fin du controle en finElement
318 318
 
319 319
 function analyser_dtd_element($dtd, &$dtc, $grammaire) {
320
-	if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
321
-		return -3;
322
-	}
323
-
324
-	[, $nom, $contenu, $dtd] = $m;
325
-	$nom = expanserEntite($nom, $dtc->macros);
326
-
327
-	if (isset($dtc->elements[$nom])) {
328
-		spip_log("redefinition de l'element $nom dans la DTD");
329
-
330
-		return -4;
331
-	}
332
-	$filles = [];
333
-	$contenu = expanserEntite($contenu, $dtc->macros);
334
-	$val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
335
-	if ($val == '(?:EMPTY )') {
336
-		$dtc->regles[$nom] = 'EMPTY';
337
-	} elseif ($val == '(?:ANY )') {
338
-		$dtc->regles[$nom] = 'ANY';
339
-	} else {
340
-		$last = substr($val, -1);
341
-		if (
342
-			preg_match('/ \w/', $val)
343
-			or (!empty($last) and strpos('*+?', $last) === false)
344
-		) {
345
-			$dtc->regles[$nom] = "/^$val$/";
346
-		} else {
347
-			$dtc->regles[$nom] = $last;
348
-		}
349
-		$filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
350
-
351
-		foreach ($filles as $k) {
352
-			if (!isset($dtc->peres[$k])) {
353
-				$dtc->peres[$k] = [];
354
-			}
355
-			if (!in_array($nom, $dtc->peres[$k])) {
356
-				$dtc->peres[$k][] = $nom;
357
-			}
358
-		}
359
-	}
360
-	$dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
361
-	$dtc->elements[$nom] = $filles;
362
-
363
-	return $dtd;
320
+    if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
321
+        return -3;
322
+    }
323
+
324
+    [, $nom, $contenu, $dtd] = $m;
325
+    $nom = expanserEntite($nom, $dtc->macros);
326
+
327
+    if (isset($dtc->elements[$nom])) {
328
+        spip_log("redefinition de l'element $nom dans la DTD");
329
+
330
+        return -4;
331
+    }
332
+    $filles = [];
333
+    $contenu = expanserEntite($contenu, $dtc->macros);
334
+    $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
335
+    if ($val == '(?:EMPTY )') {
336
+        $dtc->regles[$nom] = 'EMPTY';
337
+    } elseif ($val == '(?:ANY )') {
338
+        $dtc->regles[$nom] = 'ANY';
339
+    } else {
340
+        $last = substr($val, -1);
341
+        if (
342
+            preg_match('/ \w/', $val)
343
+            or (!empty($last) and strpos('*+?', $last) === false)
344
+        ) {
345
+            $dtc->regles[$nom] = "/^$val$/";
346
+        } else {
347
+            $dtc->regles[$nom] = $last;
348
+        }
349
+        $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
350
+
351
+        foreach ($filles as $k) {
352
+            if (!isset($dtc->peres[$k])) {
353
+                $dtc->peres[$k] = [];
354
+            }
355
+            if (!in_array($nom, $dtc->peres[$k])) {
356
+                $dtc->peres[$k][] = $nom;
357
+            }
358
+        }
359
+    }
360
+    $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
361
+    $dtc->elements[$nom] = $filles;
362
+
363
+    return $dtd;
364 364
 }
365 365
 
366 366
 
367 367
 function analyser_dtd_attlist($dtd, &$dtc, $grammaire) {
368
-	if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
369
-		return -5;
370
-	}
371
-
372
-	[, $nom, $val, $dtd] = $m;
373
-	$nom = expanserEntite($nom, $dtc->macros);
374
-	$val = expanserEntite($val, $dtc->macros);
375
-	if (!isset($dtc->attributs[$nom])) {
376
-		$dtc->attributs[$nom] = [];
377
-	}
378
-
379
-	if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
380
-		foreach ($r2 as $m2) {
381
-			$v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
382
-				: ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
383
-			$m21 = expanserEntite($m2[1], $dtc->macros);
384
-			$m25 = expanserEntite($m2[5], $dtc->macros);
385
-			$dtc->attributs[$nom][$m21] = [$v, $m25];
386
-		}
387
-	}
388
-
389
-	return $dtd;
368
+    if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
369
+        return -5;
370
+    }
371
+
372
+    [, $nom, $val, $dtd] = $m;
373
+    $nom = expanserEntite($nom, $dtc->macros);
374
+    $val = expanserEntite($val, $dtc->macros);
375
+    if (!isset($dtc->attributs[$nom])) {
376
+        $dtc->attributs[$nom] = [];
377
+    }
378
+
379
+    if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
380
+        foreach ($r2 as $m2) {
381
+            $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
382
+                : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
383
+            $m21 = expanserEntite($m2[1], $dtc->macros);
384
+            $m25 = expanserEntite($m2[5], $dtc->macros);
385
+            $dtc->attributs[$nom][$m21] = [$v, $m25];
386
+        }
387
+    }
388
+
389
+    return $dtd;
390 390
 }
391 391
 
392 392
 
@@ -402,26 +402,26 @@  discard block
 block discarded – undo
402 402
  * @return string|array
403 403
  **/
404 404
 function expanserEntite($val, $macros = []) {
405
-	static $vu = [];
406
-	if (!is_string($val)) {
407
-		return $vu;
408
-	}
409
-
410
-	if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
411
-		foreach ($r as $m) {
412
-			$ent = $m[1];
413
-			// il peut valoir ""
414
-			if (!isset($macros[$ent])) {
415
-				spip_log("Entite $ent inconnu");
416
-			} else {
417
-				if (!isset($vu[$ent])) {
418
-					$vu[$ent] = 0;
419
-				}
420
-				++$vu[$ent];
421
-				$val = str_replace($m[0], $macros[$ent], $val);
422
-			}
423
-		}
424
-	}
425
-
426
-	return trim(preg_replace('/\s+/', ' ', $val));
405
+    static $vu = [];
406
+    if (!is_string($val)) {
407
+        return $vu;
408
+    }
409
+
410
+    if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
411
+        foreach ($r as $m) {
412
+            $ent = $m[1];
413
+            // il peut valoir ""
414
+            if (!isset($macros[$ent])) {
415
+                spip_log("Entite $ent inconnu");
416
+            } else {
417
+                if (!isset($vu[$ent])) {
418
+                    $vu[$ent] = 0;
419
+                }
420
+                ++$vu[$ent];
421
+                $val = str_replace($m[0], $macros[$ent], $val);
422
+            }
423
+        }
424
+    }
425
+
426
+    return trim(preg_replace('/\s+/', ' ', $val));
427 427
 }
Please login to merge, or discard this patch.