Completed
Push — master ( 09834f...75dce3 )
by cam
02:05
created
ecrire/plugins/extraire_boutons.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 /**
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
  * @return array
21 21
  */
22 22
 function plugins_extraire_boutons_dist($arbre) {
23
-	$les_boutons = null;
24
-	$ret = ['bouton' => [], 'onglet' => []];
25
-	// recuperer les boutons et onglets si necessaire
26
-	spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons);
27
-	if (is_array($les_boutons) && count($les_boutons)) {
28
-		$ret['bouton'] = [];
29
-		$ret['onglet'] = [];
30
-		foreach ($les_boutons as $bouton => $val) {
31
-			$bouton = spip_xml_decompose_tag($bouton);
32
-			$type = reset($bouton);
33
-			$bouton = end($bouton);
34
-			if (isset($bouton['id'])) {
35
-				$id = $bouton['id'];
36
-				$val = reset($val);
37
-				if (is_array($val)) {
38
-					$ret[$type][$id]['parent'] = $bouton['parent'] ?? '';
39
-					$ret[$type][$id]['position'] = $bouton['position'] ?? '';
40
-					$ret[$type][$id]['titre'] = isset($val['titre']) ? trim((string) spip_xml_aplatit($val['titre'])) : '';
41
-					$ret[$type][$id]['icone'] = isset($val['icone']) ? trim((string) end($val['icone'])) : '';
42
-					$ret[$type][$id]['action'] = isset($val['url']) ? trim((string) end($val['url'])) : '';
43
-					$ret[$type][$id]['parametres'] = isset($val['args']) ? trim((string) end($val['args'])) : '';
44
-				}
45
-			}
46
-		}
47
-	}
23
+    $les_boutons = null;
24
+    $ret = ['bouton' => [], 'onglet' => []];
25
+    // recuperer les boutons et onglets si necessaire
26
+    spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons);
27
+    if (is_array($les_boutons) && count($les_boutons)) {
28
+        $ret['bouton'] = [];
29
+        $ret['onglet'] = [];
30
+        foreach ($les_boutons as $bouton => $val) {
31
+            $bouton = spip_xml_decompose_tag($bouton);
32
+            $type = reset($bouton);
33
+            $bouton = end($bouton);
34
+            if (isset($bouton['id'])) {
35
+                $id = $bouton['id'];
36
+                $val = reset($val);
37
+                if (is_array($val)) {
38
+                    $ret[$type][$id]['parent'] = $bouton['parent'] ?? '';
39
+                    $ret[$type][$id]['position'] = $bouton['position'] ?? '';
40
+                    $ret[$type][$id]['titre'] = isset($val['titre']) ? trim((string) spip_xml_aplatit($val['titre'])) : '';
41
+                    $ret[$type][$id]['icone'] = isset($val['icone']) ? trim((string) end($val['icone'])) : '';
42
+                    $ret[$type][$id]['action'] = isset($val['url']) ? trim((string) end($val['url'])) : '';
43
+                    $ret[$type][$id]['parametres'] = isset($val['args']) ? trim((string) end($val['args'])) : '';
44
+                }
45
+            }
46
+        }
47
+    }
48 48
 
49
-	return $ret;
49
+    return $ret;
50 50
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_repertoires.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -10,110 +10,110 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) {
17
-	$ligne_plug = charger_fonction('afficher_plugin', 'plugins');
18
-	$racine = basename((string) _DIR_PLUGINS);
19
-	$init_dir = $current_dir = '';
20
-	// liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
21
-	// des qu'un path est deja note deplie on s'arrete
22
-	$deplie = [$racine => true];
23
-	$fast_liste_plugins_actifs = [];
24
-	foreach ($liste_plugins_actifs as $key => $plug) {
25
-		$chemin_plug = chemin_plug($racine, $plug);
26
-		$fast_liste_plugins_actifs[$chemin_plug] = true;
27
-		$dir = dirname((string) $chemin_plug);
28
-		$maxiter = 100;
29
-		while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) {
30
-			$deplie[$dir] = true;
31
-			$dir = dirname($dir);
32
-		}
33
-	}
17
+    $ligne_plug = charger_fonction('afficher_plugin', 'plugins');
18
+    $racine = basename((string) _DIR_PLUGINS);
19
+    $init_dir = $current_dir = '';
20
+    // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
21
+    // des qu'un path est deja note deplie on s'arrete
22
+    $deplie = [$racine => true];
23
+    $fast_liste_plugins_actifs = [];
24
+    foreach ($liste_plugins_actifs as $key => $plug) {
25
+        $chemin_plug = chemin_plug($racine, $plug);
26
+        $fast_liste_plugins_actifs[$chemin_plug] = true;
27
+        $dir = dirname((string) $chemin_plug);
28
+        $maxiter = 100;
29
+        while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) {
30
+            $deplie[$dir] = true;
31
+            $dir = dirname($dir);
32
+        }
33
+    }
34 34
 
35
-	// index repertoires --> plugin
36
-	$dir_index = [];
37
-	foreach ($liste_plugins as $key => $plug) {
38
-		$liste_plugins[$key] = chemin_plug($racine, $plug);
39
-		$dir_index[dirname((string) $liste_plugins[$key])][] = $key;
40
-	}
35
+    // index repertoires --> plugin
36
+    $dir_index = [];
37
+    foreach ($liste_plugins as $key => $plug) {
38
+        $liste_plugins[$key] = chemin_plug($racine, $plug);
39
+        $dir_index[dirname((string) $liste_plugins[$key])][] = $key;
40
+    }
41 41
 
42
-	$visible = @isset($deplie[$current_dir]);
43
-	$maxiter = 1000;
42
+    $visible = @isset($deplie[$current_dir]);
43
+    $maxiter = 1000;
44 44
 
45
-	$res = '';
46
-	while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
47
-		// le rep suivant
48
-		$dir = dirname((string) reset($liste_plugins));
49
-		if ($dir != $current_dir) {
50
-			$res .= tree_open_close_dir($current_dir, $dir, $deplie);
51
-		}
45
+    $res = '';
46
+    while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
47
+        // le rep suivant
48
+        $dir = dirname((string) reset($liste_plugins));
49
+        if ($dir != $current_dir) {
50
+            $res .= tree_open_close_dir($current_dir, $dir, $deplie);
51
+        }
52 52
 
53
-		// d'abord tous les plugins du rep courant
54
-		if (isset($dir_index[$current_dir])) {
55
-			foreach ($dir_index[$current_dir] as $key) {
56
-				$plug = $liste_plugins[$key];
57
-				$actif = @isset($fast_liste_plugins_actifs[$plug]);
58
-				$id = substr(md5((string) $plug), 0, 16);
59
-				$res .= $ligne_plug(
60
-					$url_page,
61
-					str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
62
-					$actif,
63
-					'menu-entree'
64
-				) . "\n";
65
-				unset($liste_plugins[$key]);
66
-			}
67
-		}
68
-	}
69
-	$res .= tree_open_close_dir($current_dir, $init_dir, true);
53
+        // d'abord tous les plugins du rep courant
54
+        if (isset($dir_index[$current_dir])) {
55
+            foreach ($dir_index[$current_dir] as $key) {
56
+                $plug = $liste_plugins[$key];
57
+                $actif = @isset($fast_liste_plugins_actifs[$plug]);
58
+                $id = substr(md5((string) $plug), 0, 16);
59
+                $res .= $ligne_plug(
60
+                    $url_page,
61
+                    str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
62
+                    $actif,
63
+                    'menu-entree'
64
+                ) . "\n";
65
+                unset($liste_plugins[$key]);
66
+            }
67
+        }
68
+    }
69
+    $res .= tree_open_close_dir($current_dir, $init_dir, true);
70 70
 
71
-	return "<ul class='menu-liste plugins'>"
72
-	. $res
73
-	. '</ul>';
71
+    return "<ul class='menu-liste plugins'>"
72
+    . $res
73
+    . '</ul>';
74 74
 }
75 75
 
76 76
 
77 77
 // vraiment n'importe quoi la gestion des chemins des plugins
78 78
 // une fonction pour aider...
79 79
 function chemin_plug($racine, $plug) {
80
-	return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
80
+    return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
81 81
 }
82 82
 
83 83
 function tree_open_close_dir(&$current, $target, $deplie = []) {
84
-	if ($current == $target) {
85
-		return '';
86
-	}
87
-	$tcur = explode('/', (string) $current);
88
-	$ttarg = explode('/', (string) $target);
89
-	$tcom = [];
90
-	$output = '';
91
-	// la partie commune
92
-	while (reset($tcur) === reset($ttarg)) {
93
-		$tcom[] = array_shift($tcur);
94
-		array_shift($ttarg);
95
-	}
96
-	// fermer les repertoires courant jusqu'au point de fork
97
-	while ($close = array_pop($tcur)) {
98
-		$output .= "</ul>\n";
99
-		$output .= fin_block();
100
-		$output .= "</li>\n";
101
-	}
102
-	$chemin = '';
103
-	if ($tcom !== []) {
104
-		$chemin .= implode('/', $tcom) . '/';
105
-	}
106
-	// ouvrir les repertoires jusqu'a la cible
107
-	while ($open = array_shift($ttarg)) {
108
-		$visible = @isset($deplie[$chemin . $open]);
109
-		$chemin .= $open . '/';
110
-		$output .= '<li>';
111
-		$output .= bouton_block_depliable($chemin, $visible);
112
-		$output .= debut_block_depliable($visible);
84
+    if ($current == $target) {
85
+        return '';
86
+    }
87
+    $tcur = explode('/', (string) $current);
88
+    $ttarg = explode('/', (string) $target);
89
+    $tcom = [];
90
+    $output = '';
91
+    // la partie commune
92
+    while (reset($tcur) === reset($ttarg)) {
93
+        $tcom[] = array_shift($tcur);
94
+        array_shift($ttarg);
95
+    }
96
+    // fermer les repertoires courant jusqu'au point de fork
97
+    while ($close = array_pop($tcur)) {
98
+        $output .= "</ul>\n";
99
+        $output .= fin_block();
100
+        $output .= "</li>\n";
101
+    }
102
+    $chemin = '';
103
+    if ($tcom !== []) {
104
+        $chemin .= implode('/', $tcom) . '/';
105
+    }
106
+    // ouvrir les repertoires jusqu'a la cible
107
+    while ($open = array_shift($ttarg)) {
108
+        $visible = @isset($deplie[$chemin . $open]);
109
+        $chemin .= $open . '/';
110
+        $output .= '<li>';
111
+        $output .= bouton_block_depliable($chemin, $visible);
112
+        $output .= debut_block_depliable($visible);
113 113
 
114
-		$output .= "<ul>\n";
115
-	}
116
-	$current = $target;
114
+        $output .= "<ul>\n";
115
+    }
116
+    $current = $target;
117 117
 
118
-	return $output;
118
+    return $output;
119 119
 }
Please login to merge, or discard this patch.
ecrire/public/admin.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -33,37 +33,37 @@  discard block
 block discarded – undo
33 33
  *     Contenu HTML, avec boutons d'administrations et sa CSS
34 34
  **/
35 35
 function affiche_boutons_admin($contenu) {
36
-	include_spip('inc/filtres');
36
+    include_spip('inc/filtres');
37 37
 
38
-	// Inserer le css d'admin
39
-	$css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css')))
40
-		. "' type='text/css' />\n";
41
-	if ($f = find_in_path('spip_admin_perso.css')) {
42
-		$css .= "<link rel='stylesheet' href='"
43
-			. url_absolue(direction_css($f)) . "' type='text/css' />\n";
44
-	}
38
+    // Inserer le css d'admin
39
+    $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css')))
40
+        . "' type='text/css' />\n";
41
+    if ($f = find_in_path('spip_admin_perso.css')) {
42
+        $css .= "<link rel='stylesheet' href='"
43
+            . url_absolue(direction_css($f)) . "' type='text/css' />\n";
44
+    }
45 45
 
46
-	if (
47
-		!($pos = stripos($contenu, '</head>'))
48
-		&& !($pos = stripos($contenu, '<body>'))
49
-	) {
50
-		$pos = 0;
51
-	}
52
-	$contenu = substr_replace($contenu, $css, $pos, 0);
46
+    if (
47
+        !($pos = stripos($contenu, '</head>'))
48
+        && !($pos = stripos($contenu, '<body>'))
49
+    ) {
50
+        $pos = 0;
51
+    }
52
+    $contenu = substr_replace($contenu, $css, $pos, 0);
53 53
 
54 54
 
55
-	// Inserer la balise #FORMULAIRE_ADMIN, en float
56
-	$boutons_admin = inclure_balise_dynamique(
57
-		balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'),
58
-		false
59
-	);
60
-	if (
61
-		!($pos = strripos($contenu, '</body>'))
62
-		&& !($pos = strripos($contenu, '</html>'))
63
-	) {
64
-		$pos = strlen($contenu);
65
-	}
55
+    // Inserer la balise #FORMULAIRE_ADMIN, en float
56
+    $boutons_admin = inclure_balise_dynamique(
57
+        balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'),
58
+        false
59
+    );
60
+    if (
61
+        !($pos = strripos($contenu, '</body>'))
62
+        && !($pos = strripos($contenu, '</html>'))
63
+    ) {
64
+        $pos = strlen($contenu);
65
+    }
66 66
 
67 67
 
68
-	return substr_replace($contenu, (string) $boutons_admin, $pos, 0);
68
+    return substr_replace($contenu, (string) $boutons_admin, $pos, 0);
69 69
 }
Please login to merge, or discard this patch.
ecrire/public/format_html.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -10,123 +10,123 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) {
17
-	$preaff = $preaff ? "<BB$nom>$preaff" : '';
18
-	$avant = $avant ? "<B$nom>$avant" : '';
19
-	$apres = $apres ? "$apres</B$nom>" : '';
20
-	$altern = $altern ? "$altern<//B$nom>" : '';
21
-	$postaff = $postaff ? "$postaff</BB$nom>" : '';
22
-	$corps = $corps ? ">$corps</BOUCLE$nom>" : ' />';
23
-
24
-	return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
17
+    $preaff = $preaff ? "<BB$nom>$preaff" : '';
18
+    $avant = $avant ? "<B$nom>$avant" : '';
19
+    $apres = $apres ? "$apres</B$nom>" : '';
20
+    $altern = $altern ? "$altern<//B$nom>" : '';
21
+    $postaff = $postaff ? "$postaff</BB$nom>" : '';
22
+    $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />';
23
+
24
+    return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
25 25
 }
26 26
 
27 27
 function format_inclure_html($file, $args, $prof) {
28
-	if (!str_contains((string) $file, '#')) {
29
-		$t = $file ? ('(' . $file . ')') : '';
30
-	} else {
31
-		$t = '{fond=' . $file . '}';
32
-	}
33
-	$args = $args ? '{' . implode(', ', $args) . '}' : ('');
34
-
35
-	return ('<INCLURE' . $t . $args . '>');
28
+    if (!str_contains((string) $file, '#')) {
29
+        $t = $file ? ('(' . $file . ')') : '';
30
+    } else {
31
+        $t = '{fond=' . $file . '}';
32
+    }
33
+    $args = $args ? '{' . implode(', ', $args) . '}' : ('');
34
+
35
+    return ('<INCLURE' . $t . $args . '>');
36 36
 }
37 37
 
38 38
 function format_polyglotte_html($args, $prof) {
39
-	$contenu = [];
40
-	foreach ($args as $l => $t) {
41
-		$contenu[] = ($l ? "[$l]" : '') . $t;
42
-	}
39
+    $contenu = [];
40
+    foreach ($args as $l => $t) {
41
+        $contenu[] = ($l ? "[$l]" : '') . $t;
42
+    }
43 43
 
44
-	return ('<multi>' . implode(' ', $contenu) . '</multi>');
44
+    return ('<multi>' . implode(' ', $contenu) . '</multi>');
45 45
 }
46 46
 
47 47
 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
48
-	foreach ($args as $k => $v) {
49
-		$args[$k] = "$k=$v";
50
-	}
51
-	$args = ($args ? '{' . implode(',', $args) . '}' : (''));
48
+    foreach ($args as $k => $v) {
49
+        $args[$k] = "$k=$v";
50
+    }
51
+    $args = ($args ? '{' . implode(',', $args) . '}' : (''));
52 52
 
53
-	return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
53
+    return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
54 54
 }
55 55
 
56 56
 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
57
-	$nom = '#'
58
-		. ($boucle ? ($boucle . ':') : '')
59
-		. $nom
60
-		. $etoile
61
-		. $args
62
-		. $filtres;
57
+    $nom = '#'
58
+        . ($boucle ? ($boucle . ':') : '')
59
+        . $nom
60
+        . $etoile
61
+        . $args
62
+        . $filtres;
63 63
 
64
-	// Determiner si c'est un champ etendu,
64
+    // Determiner si c'est un champ etendu,
65 65
 
66
-	$s = ($avant || $apres || $filtres || str_contains((string) $args, '(#'));
66
+    $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#'));
67 67
 
68
-	return ($s ? "[$avant($nom)$apres]" : $nom);
68
+    return ($s ? "[$avant($nom)$apres]" : $nom);
69 69
 }
70 70
 
71 71
 function format_critere_html($critere) {
72
-	foreach ($critere as $k => $crit) {
73
-		$crit_s = '';
74
-		foreach ($crit as $operande) {
75
-			[$type, $valeur] = $operande;
76
-			if ($type == 'champ' && $valeur[0] == '[') {
77
-				$valeur = substr((string) $valeur, 1, -1);
78
-				if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
79
-					$valeur = substr($valeur, 1, -1);
80
-				}
81
-			}
82
-			$crit_s .= $valeur;
83
-		}
84
-		$critere[$k] = $crit_s;
85
-	}
86
-
87
-	return ($critere ? '{' . implode(',', $critere) . '}' : (''));
72
+    foreach ($critere as $k => $crit) {
73
+        $crit_s = '';
74
+        foreach ($crit as $operande) {
75
+            [$type, $valeur] = $operande;
76
+            if ($type == 'champ' && $valeur[0] == '[') {
77
+                $valeur = substr((string) $valeur, 1, -1);
78
+                if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
79
+                    $valeur = substr($valeur, 1, -1);
80
+                }
81
+            }
82
+            $crit_s .= $valeur;
83
+        }
84
+        $critere[$k] = $crit_s;
85
+    }
86
+
87
+    return ($critere ? '{' . implode(',', $critere) . '}' : (''));
88 88
 }
89 89
 
90 90
 function format_liste_html($fonc, $args, $prof) {
91
-	return ((($fonc !== '') ? "|$fonc" : $fonc)
92
-		. ($args ? '{' . implode(',', $args) . '}' : ('')));
91
+    return ((($fonc !== '') ? "|$fonc" : $fonc)
92
+        . ($args ? '{' . implode(',', $args) . '}' : ('')));
93 93
 }
94 94
 
95 95
 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
96 96
 function format_suite_html($args) {
97
-	$argsCount = is_countable($args) ? count($args) : 0;
98
-	for ($i = 0; $i < $argsCount - 1; $i++) {
99
-		[$texte, $type] = $args[$i];
100
-		[$texte2, $type2] = $args[$i + 1];
101
-		if (!$texte || !$texte2) {
102
-			continue;
103
-		}
104
-		$c1 = substr((string) $texte, -1);
105
-		if ($type2 !== 'texte') {
106
-			// si un texte se termine par ( et est suivi d'un champ
107
-			// ou assimiles, forcer la notation pleine
108
-			if ($c1 == '(' && str_starts_with((string) $texte2, '#')) {
109
-				$args[$i + 1][0] = '[(' . $texte2 . ')]';
110
-			}
111
-		} else {
112
-			if ($type == 'texte') {
113
-				continue;
114
-			}
115
-			// si un champ ou assimiles est suivi d'un texte
116
-			// et si celui-ci commence par un caractere de champ
117
-			// forcer la notation pleine
118
-			if (
119
-				$c1 == '}' && str_starts_with(ltrim((string) $texte2), '|')
120
-				|| preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2)
121
-			) {
122
-				$args[$i][0] = '[(' . $texte . ')]';
123
-			}
124
-		}
125
-	}
126
-
127
-	return implode('', array_map(fn($arg) => reset($arg), $args));
97
+    $argsCount = is_countable($args) ? count($args) : 0;
98
+    for ($i = 0; $i < $argsCount - 1; $i++) {
99
+        [$texte, $type] = $args[$i];
100
+        [$texte2, $type2] = $args[$i + 1];
101
+        if (!$texte || !$texte2) {
102
+            continue;
103
+        }
104
+        $c1 = substr((string) $texte, -1);
105
+        if ($type2 !== 'texte') {
106
+            // si un texte se termine par ( et est suivi d'un champ
107
+            // ou assimiles, forcer la notation pleine
108
+            if ($c1 == '(' && str_starts_with((string) $texte2, '#')) {
109
+                $args[$i + 1][0] = '[(' . $texte2 . ')]';
110
+            }
111
+        } else {
112
+            if ($type == 'texte') {
113
+                continue;
114
+            }
115
+            // si un champ ou assimiles est suivi d'un texte
116
+            // et si celui-ci commence par un caractere de champ
117
+            // forcer la notation pleine
118
+            if (
119
+                $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|')
120
+                || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2)
121
+            ) {
122
+                $args[$i][0] = '[(' . $texte . ')]';
123
+            }
124
+        }
125
+    }
126
+
127
+    return implode('', array_map(fn($arg) => reset($arg), $args));
128 128
 }
129 129
 
130 130
 function format_texte_html($texte) {
131
-	return $texte;
131
+    return $texte;
132 132
 }
Please login to merge, or discard this patch.
ecrire/public/sandbox.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  **/
23 23
 
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
  *     texte
41 41
  */
42 42
 function sandbox_composer_texte($texte, &$p) {
43
-	return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
43
+    return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
44 44
 }
45 45
 
46 46
 
@@ -56,38 +56,38 @@  discard block
 block discarded – undo
56 56
  * @return string
57 57
  */
58 58
 function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string {
59
-	if (isset($GLOBALS['spip_matrice'][$fonc])) {
60
-		$code = "filtrer('$fonc',$code$arglist)";
61
-	}
62
-
63
-	// le filtre est defini sous forme de fonction ou de methode
64
-	// par ex. dans inc_texte, inc_filtres ou mes_fonctions
65
-	elseif ($f = chercher_filtre($fonc)) {
66
-		// cas particulier : le filtre |set doit acceder a la $Pile
67
-		// proto: filtre_set(&$Pile, $val, $args...)
68
-		$refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f);
69
-		$refs = $refl->getParameters();
70
-		if (isset($refs[0]) && $refs[0]->name == 'Pile') {
71
-			$code = "$f(\$Pile,$code$arglist)";
72
-			$nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
73
-		} else {
74
-			$code = "$f($code$arglist)";
75
-			$nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
76
-		}
77
-		$nb_args_f = $nb_arg_gauche + $nb_arg_droite;
78
-		$min_f = $refl->getNumberOfRequiredParameters();
79
-		if (($nb_args_f < $min_f)) {
80
-			$msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
81
-			erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
82
-		}
83
-	}
84
-	// le filtre n'existe pas,
85
-	// on le notifie
86
-	else {
87
-		erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
88
-	}
89
-
90
-	return $code;
59
+    if (isset($GLOBALS['spip_matrice'][$fonc])) {
60
+        $code = "filtrer('$fonc',$code$arglist)";
61
+    }
62
+
63
+    // le filtre est defini sous forme de fonction ou de methode
64
+    // par ex. dans inc_texte, inc_filtres ou mes_fonctions
65
+    elseif ($f = chercher_filtre($fonc)) {
66
+        // cas particulier : le filtre |set doit acceder a la $Pile
67
+        // proto: filtre_set(&$Pile, $val, $args...)
68
+        $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f);
69
+        $refs = $refl->getParameters();
70
+        if (isset($refs[0]) && $refs[0]->name == 'Pile') {
71
+            $code = "$f(\$Pile,$code$arglist)";
72
+            $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
73
+        } else {
74
+            $code = "$f($code$arglist)";
75
+            $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
76
+        }
77
+        $nb_args_f = $nb_arg_gauche + $nb_arg_droite;
78
+        $min_f = $refl->getNumberOfRequiredParameters();
79
+        if (($nb_args_f < $min_f)) {
80
+            $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
81
+            erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
82
+        }
83
+    }
84
+    // le filtre n'existe pas,
85
+    // on le notifie
86
+    else {
87
+        erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
88
+    }
89
+
90
+    return $code;
91 91
 }
92 92
 
93 93
 // Calculer un <INCLURE(xx.php)>
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
  * @return string
111 111
  */
112 112
 function sandbox_composer_inclure_php($fichier, &$p, $_contexte) {
113
-	$compil = texte_script(memoriser_contexte_compil($p));
114
-	// si inexistant, on essaiera a l'execution
115
-	$path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")";
113
+    $compil = texte_script(memoriser_contexte_compil($p));
114
+    // si inexistant, on essaiera a l'execution
115
+    $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")";
116 116
 
117
-	return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
117
+    return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
118 118
 }
119 119
 
120 120
 /**
@@ -126,20 +126,20 @@  discard block
 block discarded – undo
126 126
  * @return string
127 127
  */
128 128
 function sandbox_composer_interdire_scripts($code, &$p) {
129
-	// Securite
130
-	if (
131
-		$p->interdire_scripts
132
-		&& $p->etoile != '**'
133
-	) {
134
-		if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
135
-			$code = "interdire_scripts($code)";
136
-		} else {
137
-			$code = interdire_scripts($r[2]);
138
-			$code = "sinon(interdire_scripts($r[1]),'$code')";
139
-		}
140
-	}
141
-
142
-	return $code;
129
+    // Securite
130
+    if (
131
+        $p->interdire_scripts
132
+        && $p->etoile != '**'
133
+    ) {
134
+        if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
135
+            $code = "interdire_scripts($code)";
136
+        } else {
137
+            $code = interdire_scripts($r[2]);
138
+            $code = "sinon(interdire_scripts($r[1]),'$code')";
139
+        }
140
+    }
141
+
142
+    return $code;
143 143
 }
144 144
 
145 145
 
@@ -158,30 +158,30 @@  discard block
 block discarded – undo
158 158
  * @return mixed|string
159 159
  */
160 160
 function sandbox_filtrer_squelette($skel, $corps, $filtres) {
161
-	$series_filtres = func_get_args();
162
-	array_shift($series_filtres);// skel
163
-	array_shift($series_filtres);// corps
164
-
165
-	// proteger les <INCLUDE> et tous les morceaux de php licites
166
-	if ($skel['process_ins'] == 'php') {
167
-		$corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
168
-	}
169
-
170
-	// recuperer les couples de remplacement
171
-	$replace = echapper_php_callback();
172
-
173
-	foreach ($series_filtres as $filtres) {
174
-		if (is_countable($filtres) ? count($filtres) : 0) {
175
-			foreach ($filtres as $filtre) {
176
-				if ($filtre && ($f = chercher_filtre($filtre))) {
177
-					$corps = $f($corps);
178
-				}
179
-			}
180
-		}
181
-	}
182
-
183
-	// restaurer les echappements
184
-	return str_replace($replace[0], $replace[1], (string) $corps);
161
+    $series_filtres = func_get_args();
162
+    array_shift($series_filtres);// skel
163
+    array_shift($series_filtres);// corps
164
+
165
+    // proteger les <INCLUDE> et tous les morceaux de php licites
166
+    if ($skel['process_ins'] == 'php') {
167
+        $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
168
+    }
169
+
170
+    // recuperer les couples de remplacement
171
+    $replace = echapper_php_callback();
172
+
173
+    foreach ($series_filtres as $filtres) {
174
+        if (is_countable($filtres) ? count($filtres) : 0) {
175
+            foreach ($filtres as $filtre) {
176
+                if ($filtre && ($f = chercher_filtre($filtre))) {
177
+                    $corps = $f($corps);
178
+                }
179
+            }
180
+        }
181
+    }
182
+
183
+    // restaurer les echappements
184
+    return str_replace($replace[0], $replace[1], (string) $corps);
185 185
 }
186 186
 
187 187
 
@@ -200,21 +200,21 @@  discard block
 block discarded – undo
200 200
  *     - array : Liste( liste des codes PHP, liste des substitutions )
201 201
  **/
202 202
 function echapper_php_callback($r = null) {
203
-	static $src = [];
204
-	static $dst = [];
203
+    static $src = [];
204
+    static $dst = [];
205 205
 
206
-	// si on recoit un tableau, on est en mode echappement
207
-	// on enregistre le code a echapper dans dst, et le code echappe dans src
208
-	if (is_array($r)) {
209
-		$dst[] = $r[0];
206
+    // si on recoit un tableau, on est en mode echappement
207
+    // on enregistre le code a echapper dans dst, et le code echappe dans src
208
+    if (is_array($r)) {
209
+        $dst[] = $r[0];
210 210
 
211
-		return $src[] = '___' . md5((string) $r[0]) . '___';
212
-	}
211
+        return $src[] = '___' . md5((string) $r[0]) . '___';
212
+    }
213 213
 
214
-	// si on recoit pas un tableau, on renvoit les couples de substitution
215
-	// et on RAZ les remplacements
216
-	$r = [$src, $dst];
217
-	$src = $dst = [];
214
+    // si on recoit pas un tableau, on renvoit les couples de substitution
215
+    // et on RAZ les remplacements
216
+    $r = [$src, $dst];
217
+    $src = $dst = [];
218 218
 
219
-	return $r;
219
+    return $r;
220 220
 }
Please login to merge, or discard this patch.
ecrire/public/styliser.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 // Ce fichier doit imperativement definir la fonction ci-dessous:
@@ -38,59 +38,59 @@  discard block
 block discarded – undo
38 38
  * @return array
39 39
  */
40 40
 function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') {
41
-	static $styliser_par_z;
42
-
43
-	// s'assurer que le fond est licite
44
-	// car il peut etre construit a partir d'une variable d'environnement
45
-	if (str_contains($fond, '../') || str_starts_with($fond, '/')) {
46
-		$fond = '404';
47
-	}
48
-
49
-	if (str_starts_with($fond, 'modeles/')) {
50
-		$modele = substr($fond, 8);
51
-		$modele = styliser_modele($modele, null, $contexte);
52
-		$fond = "modeles/$modele";
53
-	}
54
-
55
-	// Choisir entre $fond-dist.html, $fond=7.html, etc?
56
-	$id_rubrique = 0;
57
-	// Chercher le fond qui va servir de squelette
58
-	if ($r = quete_rubrique_fond($contexte)) {
59
-		[$id_rubrique, $lang] = $r;
60
-	}
61
-
62
-	// trouver un squelette du nom demande
63
-	// ne rien dire si on ne trouve pas,
64
-	// c'est l'appelant qui sait comment gerer la situation
65
-	// ou les plugins qui feront mieux dans le pipeline
66
-	$squelette = trouver_fond($fond, '', true);
67
-	$ext = $squelette['extension'];
68
-
69
-	$flux = [
70
-		'args' => [
71
-			'id_rubrique' => $id_rubrique,
72
-			'ext' => $ext,
73
-			'fond' => $fond,
74
-			'lang' => $lang,
75
-			'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
76
-			'connect' => $connect
77
-		],
78
-		'data' => $squelette['fond'],
79
-	];
80
-
81
-	if (test_espace_prive() || defined('_ZPIP')) {
82
-		if (!$styliser_par_z) {
83
-			$styliser_par_z = charger_fonction('styliser_par_z', 'public');
84
-		}
85
-		$flux = $styliser_par_z($flux);
86
-	}
87
-
88
-	$flux = styliser_par_objets($flux);
89
-
90
-	// pipeline styliser
91
-	$squelette = pipeline('styliser', $flux);
92
-
93
-	return [$squelette, $ext, $ext, "$squelette.$ext"];
41
+    static $styliser_par_z;
42
+
43
+    // s'assurer que le fond est licite
44
+    // car il peut etre construit a partir d'une variable d'environnement
45
+    if (str_contains($fond, '../') || str_starts_with($fond, '/')) {
46
+        $fond = '404';
47
+    }
48
+
49
+    if (str_starts_with($fond, 'modeles/')) {
50
+        $modele = substr($fond, 8);
51
+        $modele = styliser_modele($modele, null, $contexte);
52
+        $fond = "modeles/$modele";
53
+    }
54
+
55
+    // Choisir entre $fond-dist.html, $fond=7.html, etc?
56
+    $id_rubrique = 0;
57
+    // Chercher le fond qui va servir de squelette
58
+    if ($r = quete_rubrique_fond($contexte)) {
59
+        [$id_rubrique, $lang] = $r;
60
+    }
61
+
62
+    // trouver un squelette du nom demande
63
+    // ne rien dire si on ne trouve pas,
64
+    // c'est l'appelant qui sait comment gerer la situation
65
+    // ou les plugins qui feront mieux dans le pipeline
66
+    $squelette = trouver_fond($fond, '', true);
67
+    $ext = $squelette['extension'];
68
+
69
+    $flux = [
70
+        'args' => [
71
+            'id_rubrique' => $id_rubrique,
72
+            'ext' => $ext,
73
+            'fond' => $fond,
74
+            'lang' => $lang,
75
+            'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
76
+            'connect' => $connect
77
+        ],
78
+        'data' => $squelette['fond'],
79
+    ];
80
+
81
+    if (test_espace_prive() || defined('_ZPIP')) {
82
+        if (!$styliser_par_z) {
83
+            $styliser_par_z = charger_fonction('styliser_par_z', 'public');
84
+        }
85
+        $flux = $styliser_par_z($flux);
86
+    }
87
+
88
+    $flux = styliser_par_objets($flux);
89
+
90
+    // pipeline styliser
91
+    $squelette = pipeline('styliser', $flux);
92
+
93
+    return [$squelette, $ext, $ext, "$squelette.$ext"];
94 94
 }
95 95
 
96 96
 /**
@@ -109,32 +109,32 @@  discard block
 block discarded – undo
109 109
  *     Données du pipeline styliser
110 110
  **/
111 111
 function styliser_par_objets($flux) {
112
-	if (
113
-		test_espace_prive()
114
-		&& !($squelette = $flux['data'])
115
-		&& str_starts_with((string) $flux['args']['fond'], 'prive/objets/')
116
-		&& ($echafauder = charger_fonction('echafauder', 'prive', true))
117
-	) {
118
-		if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) {
119
-			$table = table_objet(substr((string) $flux['args']['fond'], 19));
120
-			$table_sql = table_objet_sql($table);
121
-			$objets = lister_tables_objets_sql();
122
-			if (isset($objets[$table_sql])) {
123
-				$flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
124
-			}
125
-		}
126
-		if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) {
127
-			$type = substr((string) $flux['args']['fond'], 21);
128
-			$table = table_objet($type);
129
-			$table_sql = table_objet_sql($table);
130
-			$objets = lister_tables_objets_sql();
131
-			if (isset($objets[$table_sql])) {
132
-				$flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
133
-			}
134
-		}
135
-	}
136
-
137
-	return $flux;
112
+    if (
113
+        test_espace_prive()
114
+        && !($squelette = $flux['data'])
115
+        && str_starts_with((string) $flux['args']['fond'], 'prive/objets/')
116
+        && ($echafauder = charger_fonction('echafauder', 'prive', true))
117
+    ) {
118
+        if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) {
119
+            $table = table_objet(substr((string) $flux['args']['fond'], 19));
120
+            $table_sql = table_objet_sql($table);
121
+            $objets = lister_tables_objets_sql();
122
+            if (isset($objets[$table_sql])) {
123
+                $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
124
+            }
125
+        }
126
+        if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) {
127
+            $type = substr((string) $flux['args']['fond'], 21);
128
+            $table = table_objet($type);
129
+            $table_sql = table_objet_sql($table);
130
+            $objets = lister_tables_objets_sql();
131
+            if (isset($objets[$table_sql])) {
132
+                $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
133
+            }
134
+        }
135
+    }
136
+
137
+    return $flux;
138 138
 }
139 139
 
140 140
 /**
@@ -150,47 +150,47 @@  discard block
 block discarded – undo
150 150
  * @return array|false
151 151
  */
152 152
 function quete_rubrique_fond($contexte) {
153
-	static $liste_objets = null;
154
-	static $quete = [];
155
-	if (is_null($liste_objets)) {
156
-		$liste_objets = [];
157
-		include_spip('inc/urls');
158
-		include_spip('public/quete');
159
-		$l = urls_liste_objets(false);
160
-		// placer la rubrique en tete des objets
161
-		$l = array_diff($l, ['rubrique']);
162
-		array_unshift($l, 'rubrique');
163
-		foreach ($l as $objet) {
164
-			$id = id_table_objet($objet);
165
-			if (!isset($liste_objets[$id])) {
166
-				$liste_objets[$id] = objet_type($objet, false);
167
-			}
168
-		}
169
-	}
170
-	$c = array_intersect_key($contexte, $liste_objets);
171
-	if ($c === []) {
172
-		return false;
173
-	}
174
-
175
-	$c = array_map('intval', $c);
176
-	$s = serialize($c);
177
-	if (isset($quete[$s])) {
178
-		return $quete[$s];
179
-	}
180
-
181
-	if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) {
182
-		unset($c['id_rubrique']);
183
-		$c = ['id_rubrique' => $r] + $c;
184
-	}
185
-
186
-	foreach ($c as $_id => $id) {
187
-		if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) {
188
-			$lang = $row['lang'] ?? '';
189
-			if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) {
190
-				return $quete[$s] = [$id, $lang];
191
-			}
192
-		}
193
-	}
194
-
195
-	return $quete[$s] = false;
153
+    static $liste_objets = null;
154
+    static $quete = [];
155
+    if (is_null($liste_objets)) {
156
+        $liste_objets = [];
157
+        include_spip('inc/urls');
158
+        include_spip('public/quete');
159
+        $l = urls_liste_objets(false);
160
+        // placer la rubrique en tete des objets
161
+        $l = array_diff($l, ['rubrique']);
162
+        array_unshift($l, 'rubrique');
163
+        foreach ($l as $objet) {
164
+            $id = id_table_objet($objet);
165
+            if (!isset($liste_objets[$id])) {
166
+                $liste_objets[$id] = objet_type($objet, false);
167
+            }
168
+        }
169
+    }
170
+    $c = array_intersect_key($contexte, $liste_objets);
171
+    if ($c === []) {
172
+        return false;
173
+    }
174
+
175
+    $c = array_map('intval', $c);
176
+    $s = serialize($c);
177
+    if (isset($quete[$s])) {
178
+        return $quete[$s];
179
+    }
180
+
181
+    if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) {
182
+        unset($c['id_rubrique']);
183
+        $c = ['id_rubrique' => $r] + $c;
184
+    }
185
+
186
+    foreach ($c as $_id => $id) {
187
+        if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) {
188
+            $lang = $row['lang'] ?? '';
189
+            if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) {
190
+                return $quete[$s] = [$id, $lang];
191
+            }
192
+        }
193
+    }
194
+
195
+    return $quete[$s] = false;
196 196
 }
Please login to merge, or discard this patch.
ecrire/public/tracer.php 1 patch
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -10,187 +10,187 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function trace_query_start() {
17
-	static $trace = '?';
18
-	if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) {
19
-		if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) {
20
-			$trace = true;
21
-		}
22
-		else {
23
-			if (empty($GLOBALS['visiteur_session'])) {
24
-				// si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir
25
-				// car ici on ne sait pas si c'est un hit anonyme
26
-				// ou une requete SQL faite avant chargement de la session
27
-				$trace = (empty($_GET['var_profile']) ? false : '?');
28
-			}
29
-			else {
30
-				include_spip('inc/autoriser');
31
-				// gare au bouclage sur calcul de droits au premier appel
32
-				// A fortiori quand on demande une trace
33
-				$trace = false; // on ne trace pas la requete provoquee par autoriser('debug')
34
-				$trace = (!empty($_GET['var_profile']) && autoriser('debug'));
35
-			}
36
-		}
37
-	}
38
-
39
-	return $trace ? microtime() : 0;
17
+    static $trace = '?';
18
+    if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) {
19
+        if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) {
20
+            $trace = true;
21
+        }
22
+        else {
23
+            if (empty($GLOBALS['visiteur_session'])) {
24
+                // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir
25
+                // car ici on ne sait pas si c'est un hit anonyme
26
+                // ou une requete SQL faite avant chargement de la session
27
+                $trace = (empty($_GET['var_profile']) ? false : '?');
28
+            }
29
+            else {
30
+                include_spip('inc/autoriser');
31
+                // gare au bouclage sur calcul de droits au premier appel
32
+                // A fortiori quand on demande une trace
33
+                $trace = false; // on ne trace pas la requete provoquee par autoriser('debug')
34
+                $trace = (!empty($_GET['var_profile']) && autoriser('debug'));
35
+            }
36
+        }
37
+    }
38
+
39
+    return $trace ? microtime() : 0;
40 40
 }
41 41
 
42 42
 function trace_query_end($query, $start, $result, $erreur, $serveur = '') {
43
-	static $trace = '?';
44
-	if ($trace === '?') {
45
-		if (empty($GLOBALS['visiteur_session'])) {
46
-			// si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir
47
-			// car ici on ne sait pas si c'est un hit anonyme
48
-			// ou une requete SQL faite avant chargement de la session
49
-			$trace = (empty($_GET['var_profile']) ? false : '?');
50
-		}
51
-		else {
52
-			include_spip('inc/autoriser');
53
-			// gare au bouclage sur calcul de droits au premier appel
54
-			// A fortiori quand on demande une trace
55
-			$trace = false; // on ne trace pas la requete provoquee par autoriser('debug')
56
-			$trace = (!empty($_GET['var_profile']) && autoriser('debug'));
57
-		}
58
-	}
59
-	if ($start) {
60
-		$end = microtime();
61
-		[$usec, $sec] = explode(' ', (string) $start);
62
-		[$usec2, $sec2] = explode(' ', $end);
63
-		$dt = $sec2 + $usec2 - $sec - $usec;
64
-		pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]);
65
-		if ($trace) {
66
-			trace_query_chrono($dt, $query, $result, $serveur);
67
-		}
68
-	}
69
-	// tracer les erreurs, sauf pour select, c'est fait dans abstract_sql
70
-	if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) {
71
-		erreur_squelette([sql_errno($serveur), $erreur, $query]);
72
-	}
73
-
74
-	return $result;
43
+    static $trace = '?';
44
+    if ($trace === '?') {
45
+        if (empty($GLOBALS['visiteur_session'])) {
46
+            // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir
47
+            // car ici on ne sait pas si c'est un hit anonyme
48
+            // ou une requete SQL faite avant chargement de la session
49
+            $trace = (empty($_GET['var_profile']) ? false : '?');
50
+        }
51
+        else {
52
+            include_spip('inc/autoriser');
53
+            // gare au bouclage sur calcul de droits au premier appel
54
+            // A fortiori quand on demande une trace
55
+            $trace = false; // on ne trace pas la requete provoquee par autoriser('debug')
56
+            $trace = (!empty($_GET['var_profile']) && autoriser('debug'));
57
+        }
58
+    }
59
+    if ($start) {
60
+        $end = microtime();
61
+        [$usec, $sec] = explode(' ', (string) $start);
62
+        [$usec2, $sec2] = explode(' ', $end);
63
+        $dt = $sec2 + $usec2 - $sec - $usec;
64
+        pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]);
65
+        if ($trace) {
66
+            trace_query_chrono($dt, $query, $result, $serveur);
67
+        }
68
+    }
69
+    // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql
70
+    if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) {
71
+        erreur_squelette([sql_errno($serveur), $erreur, $query]);
72
+    }
73
+
74
+    return $result;
75 75
 }
76 76
 
77 77
 function trace_query_chrono($dt, $query, $result, $serveur = '') {
78
-	include_spip('inc/filtres_mini');
79
-	static $tt = 0, $nb = 0;
80
-
81
-	$x = _request('var_mode_objet');
82
-	if (isset($GLOBALS['debug']['aucasou'])) {
83
-		[, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou'];
84
-		if ($x && !preg_match("/$boucle\$/", (string) $x)) {
85
-			return;
86
-		}
87
-		if ($serveur) {
88
-			$boucle .= " ($serveur)";
89
-		}
90
-		$boucle = "<b>$boucle</b>";
91
-	} else {
92
-		if ($x) {
93
-			return;
94
-		}
95
-		$boucle = $contexte = '';
96
-	}
97
-
98
-	$tt += $dt;
99
-	$nb++;
100
-
101
-	$q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query));
102
-	$e = sql_explain($query, $serveur);
103
-	$r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result));
104
-	$GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte];
78
+    include_spip('inc/filtres_mini');
79
+    static $tt = 0, $nb = 0;
80
+
81
+    $x = _request('var_mode_objet');
82
+    if (isset($GLOBALS['debug']['aucasou'])) {
83
+        [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou'];
84
+        if ($x && !preg_match("/$boucle\$/", (string) $x)) {
85
+            return;
86
+        }
87
+        if ($serveur) {
88
+            $boucle .= " ($serveur)";
89
+        }
90
+        $boucle = "<b>$boucle</b>";
91
+    } else {
92
+        if ($x) {
93
+            return;
94
+        }
95
+        $boucle = $contexte = '';
96
+    }
97
+
98
+    $tt += $dt;
99
+    $nb++;
100
+
101
+    $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query));
102
+    $e = sql_explain($query, $serveur);
103
+    $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result));
104
+    $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte];
105 105
 }
106 106
 
107 107
 
108 108
 function chrono_requete($temps) {
109
-	$total = 0;
110
-	$hors = '<i>' . _T('zbug_hors_compilation') . '</i>';
111
-	$t = $q = $n = $d = [];
112
-	// Totaliser les temps et completer le Explain
113
-	foreach ($temps as $key => $v) {
114
-		[$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v;
115
-		if (is_array($contexte)) {
116
-			$k = ($contexte[0] . " $boucle");
117
-			include_spip('public/compiler');
118
-			$env = reconstruire_contexte_compil($contexte);
119
-		} else {
120
-			$k = $env = $boucle;
121
-		}
122
-
123
-		$total += $dt;
124
-		$t[$key] = $dt;
125
-		$q[$key] = $nb;
126
-		if (!isset($d[$k])) {
127
-			$d[$k] = 0;
128
-			$n[$k] = 0;
129
-		}
130
-		$d[$k] += $dt;
131
-		++$n[$k];
132
-
133
-		if (!is_array($explain)) {
134
-			$explain = [];
135
-		}
136
-		foreach ($explain as $j => $v) {
137
-			$explain[$j] = "<tr><th>$j</th><td>"
138
-				. str_replace(';', '<br />', (string) $v)
139
-				. '</td></tr>';
140
-		}
141
-		$e = "<table class='explain'>"
142
-			. '<caption>'
143
-			. $query
144
-			. '</caption>'
145
-			. "<tr><th>Time</th><td>$dt</td></tr>"
146
-			. "<tr><th>Order</th><td>$nb</td></tr>"
147
-			. "<tr><th>Res</th><td>$res</td></tr>"
148
-			. implode('', $explain)
149
-			. '</table>';
150
-
151
-		$temps[$key] = [$e, $env, $k];
152
-	}
153
-	// Trier par temps d'execution decroissant
154
-	array_multisort($t, SORT_DESC, $q, $temps);
155
-	arsort($d);
156
-	$i = 1;
157
-	$t = [];
158
-	// Fabriquer les liens de navigations dans le tableau des temps
159
-	foreach ($temps as $k => $v) {
160
-		$titre = strip_tags((string) $v[2]);
161
-		$href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i";
162
-		$href = str_replace("\\'", '&#39;', $href);
163
-
164
-		if (!isset($t[$v[2]])) {
165
-			$t[$v[2]] = [];
166
-		}
167
-		$t[$v[2]][] = "<span class='spip-debug-arg'> "
168
-			. "<a title='$titre' href='$href'>$i</a>"
169
-			. '</span>'
170
-			. ((count($t[$v[2]]) % 10 == 9) ? '<br />' : '');
171
-		$i++;
172
-	}
173
-
174
-	if ($d['']) {
175
-		$d[$hors] = $d[''];
176
-		$n[$hors] = $n[''];
177
-		$t[$hors] = $t[''];
178
-	}
179
-	unset($d['']);
180
-	// Fabriquer le tableau des liens de navigation dans le grand tableau
181
-	foreach ($d as $k => $v) {
182
-		$d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>"
183
-			. implode('', $t[$k]);
184
-	}
185
-
186
-	$navigation = [
187
-		_T('zbug_statistiques'),
188
-		'<tr><td>'
189
-		. implode("</td></tr>\n<tr><td>", $d)
190
-		. "</td></tr>\n"
191
-		. (# _request('var_mode_objet') ? '' :
192
-		('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>'))
193
-	];
194
-
195
-	return [$temps, $navigation];
109
+    $total = 0;
110
+    $hors = '<i>' . _T('zbug_hors_compilation') . '</i>';
111
+    $t = $q = $n = $d = [];
112
+    // Totaliser les temps et completer le Explain
113
+    foreach ($temps as $key => $v) {
114
+        [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v;
115
+        if (is_array($contexte)) {
116
+            $k = ($contexte[0] . " $boucle");
117
+            include_spip('public/compiler');
118
+            $env = reconstruire_contexte_compil($contexte);
119
+        } else {
120
+            $k = $env = $boucle;
121
+        }
122
+
123
+        $total += $dt;
124
+        $t[$key] = $dt;
125
+        $q[$key] = $nb;
126
+        if (!isset($d[$k])) {
127
+            $d[$k] = 0;
128
+            $n[$k] = 0;
129
+        }
130
+        $d[$k] += $dt;
131
+        ++$n[$k];
132
+
133
+        if (!is_array($explain)) {
134
+            $explain = [];
135
+        }
136
+        foreach ($explain as $j => $v) {
137
+            $explain[$j] = "<tr><th>$j</th><td>"
138
+                . str_replace(';', '<br />', (string) $v)
139
+                . '</td></tr>';
140
+        }
141
+        $e = "<table class='explain'>"
142
+            . '<caption>'
143
+            . $query
144
+            . '</caption>'
145
+            . "<tr><th>Time</th><td>$dt</td></tr>"
146
+            . "<tr><th>Order</th><td>$nb</td></tr>"
147
+            . "<tr><th>Res</th><td>$res</td></tr>"
148
+            . implode('', $explain)
149
+            . '</table>';
150
+
151
+        $temps[$key] = [$e, $env, $k];
152
+    }
153
+    // Trier par temps d'execution decroissant
154
+    array_multisort($t, SORT_DESC, $q, $temps);
155
+    arsort($d);
156
+    $i = 1;
157
+    $t = [];
158
+    // Fabriquer les liens de navigations dans le tableau des temps
159
+    foreach ($temps as $k => $v) {
160
+        $titre = strip_tags((string) $v[2]);
161
+        $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i";
162
+        $href = str_replace("\\'", '&#39;', $href);
163
+
164
+        if (!isset($t[$v[2]])) {
165
+            $t[$v[2]] = [];
166
+        }
167
+        $t[$v[2]][] = "<span class='spip-debug-arg'> "
168
+            . "<a title='$titre' href='$href'>$i</a>"
169
+            . '</span>'
170
+            . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : '');
171
+        $i++;
172
+    }
173
+
174
+    if ($d['']) {
175
+        $d[$hors] = $d[''];
176
+        $n[$hors] = $n[''];
177
+        $t[$hors] = $t[''];
178
+    }
179
+    unset($d['']);
180
+    // Fabriquer le tableau des liens de navigation dans le grand tableau
181
+    foreach ($d as $k => $v) {
182
+        $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>"
183
+            . implode('', $t[$k]);
184
+    }
185
+
186
+    $navigation = [
187
+        _T('zbug_statistiques'),
188
+        '<tr><td>'
189
+        . implode("</td></tr>\n<tr><td>", $d)
190
+        . "</td></tr>\n"
191
+        . (# _request('var_mode_objet') ? '' :
192
+        ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>'))
193
+    ];
194
+
195
+    return [$temps, $navigation];
196 196
 }
Please login to merge, or discard this patch.
ecrire/typographie/en.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -10,35 +10,35 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 // rien sauf les "~" et "-,"
17 17
 
18 18
 function typographie_en_dist($letexte) {
19 19
 
20
-	// zouli apostrophe
21
-	$letexte = str_replace("'", '&#8217;', (string) $letexte);
22
-
23
-	$cherche1 = [
24
-		'/ --?,/S'
25
-	];
26
-	$remplace1 = [
27
-		'~\0'
28
-	];
29
-	$letexte = preg_replace($cherche1, $remplace1, $letexte);
30
-
31
-	$letexte = str_replace('&nbsp;', '~', $letexte);
32
-	$letexte = preg_replace('/ *~+ */', '~', $letexte);
33
-
34
-	$cherche2 = [
35
-		'/([^-\n]|^)--([^-]|$)/',
36
-		'/~/'
37
-	];
38
-	$remplace2 = [
39
-		'\1&mdash;\2',
40
-		'&nbsp;'
41
-	];
42
-
43
-	return preg_replace($cherche2, $remplace2, $letexte);
20
+    // zouli apostrophe
21
+    $letexte = str_replace("'", '&#8217;', (string) $letexte);
22
+
23
+    $cherche1 = [
24
+        '/ --?,/S'
25
+    ];
26
+    $remplace1 = [
27
+        '~\0'
28
+    ];
29
+    $letexte = preg_replace($cherche1, $remplace1, $letexte);
30
+
31
+    $letexte = str_replace('&nbsp;', '~', $letexte);
32
+    $letexte = preg_replace('/ *~+ */', '~', $letexte);
33
+
34
+    $cherche2 = [
35
+        '/([^-\n]|^)--([^-]|$)/',
36
+        '/~/'
37
+    ];
38
+    $remplace2 = [
39
+        '\1&mdash;\2',
40
+        '&nbsp;'
41
+    ];
42
+
43
+    return preg_replace($cherche2, $remplace2, $letexte);
44 44
 }
Please login to merge, or discard this patch.
ecrire/public.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -20,188 +20,188 @@
 block discarded – undo
20 20
 // par souci de compatiilite).
21 21
 
22 22
 if (isset($GLOBALS['_INC_PUBLIC']) && $GLOBALS['_INC_PUBLIC']) {
23
-	echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? '');
23
+    echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? '');
24 24
 } else {
25
-	$GLOBALS['_INC_PUBLIC'] = 1;
26
-	define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : '');
27
-
28
-	// Faut-il initialiser SPIP ? (oui dans le cas general)
29
-	if (!defined('_DIR_RESTREINT_ABS')) {
30
-		if (
31
-			defined('_DIR_RESTREINT')
32
-			&& @file_exists(_ROOT_RESTREINT . 'inc_version.php')
33
-		) {
34
-			include_once _ROOT_RESTREINT . 'inc_version.php';
35
-		} else {
36
-			die('inc_version absent ?');
37
-		}
38
-	} // $fond defini dans le fichier d'appel ?
39
-
40
-	else {
41
-		if (isset($fond) && !_request('fond')) {
42
-		} // fond demande dans l'url par page=xxxx ?
43
-		else {
44
-			if (isset($_GET[_SPIP_PAGE])) {
45
-				$fond = (string)$_GET[_SPIP_PAGE];
46
-
47
-				// Securite
48
-				if (
49
-					strstr($fond, '/')
50
-					&& !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre'))
51
-				) {
52
-					include_spip('inc/minipres');
53
-					echo minipres();
54
-					exit;
55
-				}
56
-				// l'argument Page a priorite sur l'argument action
57
-				// le cas se presente a cause des RewriteRule d'Apache
58
-				// qui permettent d'ajouter un argument dans la QueryString
59
-				// mais pas d'en retirer un en conservant les autres.
60
-				if (isset($_GET['action']) && $_GET['action'] === $fond) {
61
-					unset($_GET['action']);
62
-				}
63
-				# sinon, fond par defaut
64
-			} else {
65
-				// sinon fond par defaut (cf. assembler.php)
66
-				$fond = pipeline('detecter_fond_par_defaut', '');
67
-			}
68
-		}
69
-	}
70
-
71
-	$tableau_des_temps = [];
72
-
73
-	// Particularites de certains squelettes
74
-	if ($fond == 'login') {
75
-		$forcer_lang = true;
76
-	}
77
-
78
-	if (
79
-		isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non'
80
-		&& !_request('action')
81
-		&& $_SERVER['REQUEST_METHOD'] != 'POST'
82
-	) {
83
-		include_spip('inc/lang');
84
-		verifier_lang_url();
85
-	}
86
-
87
-	$lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : '';
88
-
89
-	// Charger l'aiguilleur des traitements derogatoires
90
-	// (action en base SQL, formulaires CVT, AJax)
91
-	if (_request('action') || _request('var_ajax') || _request('formulaire_action')) {
92
-		include_spip('public/aiguiller');
93
-		if (
94
-			// cas des appels actions ?action=xxx
95
-			traiter_appels_actions()
96
-			// cas des hits ajax sur les inclusions ajax
97
-			|| traiter_appels_inclusions_ajax()
98
-			// cas des formulaires charger/verifier/traiter
99
-			|| traiter_formulaires_dynamiques()
100
-		) {
101
-			// lancer les taches sur affichage final, comme le cron
102
-			// mais sans rien afficher
103
-			$GLOBALS['html'] = false; // ne rien afficher
104
-			pipeline('affichage_final' . _PIPELINE_SUFFIX, '');
105
-			exit; // le hit est fini !
106
-		}
107
-	}
108
-
109
-	// Il y a du texte a produire, charger le metteur en page
110
-	include_spip('public/assembler');
111
-	$page = assembler($fond, _request('connect') ?? '');
112
-
113
-	if (isset($page['status'])) {
114
-		include_spip('inc/headers');
115
-		http_response_code($page['status']);
116
-	}
117
-
118
-	// Content-Type ?
119
-	if (!isset($page['entetes']['Content-Type'])) {
120
-		$charset = $GLOBALS['meta']['charset'] ?? 'utf-8';
121
-		$page['entetes']['Content-Type'] = 'text/html; charset=' . $charset;
122
-		$html = true;
123
-	} else {
124
-		$html = preg_match(',^\s*text/html,', (string) $page['entetes']['Content-Type']);
125
-	}
126
-
127
-	// Tester si on est admin et il y a des choses supplementaires a dire
128
-	// type tableau pour y mettre des choses au besoin.
129
-	$debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : [];
130
-
131
-	// affiche-t-on les boutons d'administration ? voir f_admin()
132
-	$affiche_boutons_admin = ($html && (
133
-		isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver)
134
-		|| $debug && include_spip('inc/autoriser') && autoriser('debug')
135
-		|| defined('_VAR_PREVIEW') && _VAR_PREVIEW)
136
-	);
137
-
138
-	if ($affiche_boutons_admin) {
139
-		include_spip('balise/formulaire_admin');
140
-	}
141
-
142
-
143
-	// Execution de la page calculee
144
-
145
-	// traitements sur les entetes avant envoi
146
-	// peut servir pour le plugin de stats
147
-	$page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']);
148
-
149
-
150
-	// eval $page et affecte $res
151
-	include _ROOT_RESTREINT . 'public/evaluer_page.php';
152
-	envoyer_entetes($page['entetes']);
153
-	if ($res === false) {
154
-		include_spip('inc/autoriser');
155
-		$err = _T('zbug_erreur_execution_page');
156
-		if (autoriser('webmestre')) {
157
-			$err .= "\n<hr />\n"
158
-				. highlight_string($page['codephp'], true)
159
-				. "\n<hr />\n";
160
-		}
161
-		$msg = [$err];
162
-		erreur_squelette($msg);
163
-	}
164
-
165
-	//
166
-	// Envoyer le resultat apres post-traitements
167
-	//
168
-	// (c'est ici qu'on fait var_recherche, validation, boutons d'admin,
169
-	// cf. public/assembler.php)
170
-	echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']);
171
-
172
-	if ($lang) {
173
-		lang_select();
174
-	}
175
-	// l'affichage de la page a pu lever des erreurs (inclusion manquante)
176
-	// il faut tester a nouveau
177
-	$debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : [];
178
-
179
-	// Appel au debusqueur en cas d'erreurs ou de demande de trace
180
-	// at last
181
-	if ($debug) {
182
-		// en cas d'erreur, retester l'affichage
183
-		if ($html && ($affiche_boutons_admin || $debug)) {
184
-			$var_mode_affiche = _request('var_mode_affiche');
185
-			$var_mode_objet = _request('var_mode_objet');
186
-			$GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : '');
187
-			echo erreur_squelette(false);
188
-		}
189
-	} else {
190
-		if (
191
-			isset($GLOBALS['meta']['date_prochain_postdate'])
192
-			&& $GLOBALS['meta']['date_prochain_postdate'] <= time()
193
-		) {
194
-			include_spip('inc/rubriques');
195
-			calculer_prochain_postdate(true);
196
-		}
197
-
198
-		// Effectuer une tache de fond ?
199
-		// si _DIRECT_CRON_FORCE est present, on force l'appel
200
-		if (defined('_DIRECT_CRON_FORCE')) {
201
-			cron();
202
-		}
203
-
204
-		// sauver le cache chemin si necessaire
205
-		save_path_cache();
206
-	}
25
+    $GLOBALS['_INC_PUBLIC'] = 1;
26
+    define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : '');
27
+
28
+    // Faut-il initialiser SPIP ? (oui dans le cas general)
29
+    if (!defined('_DIR_RESTREINT_ABS')) {
30
+        if (
31
+            defined('_DIR_RESTREINT')
32
+            && @file_exists(_ROOT_RESTREINT . 'inc_version.php')
33
+        ) {
34
+            include_once _ROOT_RESTREINT . 'inc_version.php';
35
+        } else {
36
+            die('inc_version absent ?');
37
+        }
38
+    } // $fond defini dans le fichier d'appel ?
39
+
40
+    else {
41
+        if (isset($fond) && !_request('fond')) {
42
+        } // fond demande dans l'url par page=xxxx ?
43
+        else {
44
+            if (isset($_GET[_SPIP_PAGE])) {
45
+                $fond = (string)$_GET[_SPIP_PAGE];
46
+
47
+                // Securite
48
+                if (
49
+                    strstr($fond, '/')
50
+                    && !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre'))
51
+                ) {
52
+                    include_spip('inc/minipres');
53
+                    echo minipres();
54
+                    exit;
55
+                }
56
+                // l'argument Page a priorite sur l'argument action
57
+                // le cas se presente a cause des RewriteRule d'Apache
58
+                // qui permettent d'ajouter un argument dans la QueryString
59
+                // mais pas d'en retirer un en conservant les autres.
60
+                if (isset($_GET['action']) && $_GET['action'] === $fond) {
61
+                    unset($_GET['action']);
62
+                }
63
+                # sinon, fond par defaut
64
+            } else {
65
+                // sinon fond par defaut (cf. assembler.php)
66
+                $fond = pipeline('detecter_fond_par_defaut', '');
67
+            }
68
+        }
69
+    }
70
+
71
+    $tableau_des_temps = [];
72
+
73
+    // Particularites de certains squelettes
74
+    if ($fond == 'login') {
75
+        $forcer_lang = true;
76
+    }
77
+
78
+    if (
79
+        isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non'
80
+        && !_request('action')
81
+        && $_SERVER['REQUEST_METHOD'] != 'POST'
82
+    ) {
83
+        include_spip('inc/lang');
84
+        verifier_lang_url();
85
+    }
86
+
87
+    $lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : '';
88
+
89
+    // Charger l'aiguilleur des traitements derogatoires
90
+    // (action en base SQL, formulaires CVT, AJax)
91
+    if (_request('action') || _request('var_ajax') || _request('formulaire_action')) {
92
+        include_spip('public/aiguiller');
93
+        if (
94
+            // cas des appels actions ?action=xxx
95
+            traiter_appels_actions()
96
+            // cas des hits ajax sur les inclusions ajax
97
+            || traiter_appels_inclusions_ajax()
98
+            // cas des formulaires charger/verifier/traiter
99
+            || traiter_formulaires_dynamiques()
100
+        ) {
101
+            // lancer les taches sur affichage final, comme le cron
102
+            // mais sans rien afficher
103
+            $GLOBALS['html'] = false; // ne rien afficher
104
+            pipeline('affichage_final' . _PIPELINE_SUFFIX, '');
105
+            exit; // le hit est fini !
106
+        }
107
+    }
108
+
109
+    // Il y a du texte a produire, charger le metteur en page
110
+    include_spip('public/assembler');
111
+    $page = assembler($fond, _request('connect') ?? '');
112
+
113
+    if (isset($page['status'])) {
114
+        include_spip('inc/headers');
115
+        http_response_code($page['status']);
116
+    }
117
+
118
+    // Content-Type ?
119
+    if (!isset($page['entetes']['Content-Type'])) {
120
+        $charset = $GLOBALS['meta']['charset'] ?? 'utf-8';
121
+        $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset;
122
+        $html = true;
123
+    } else {
124
+        $html = preg_match(',^\s*text/html,', (string) $page['entetes']['Content-Type']);
125
+    }
126
+
127
+    // Tester si on est admin et il y a des choses supplementaires a dire
128
+    // type tableau pour y mettre des choses au besoin.
129
+    $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : [];
130
+
131
+    // affiche-t-on les boutons d'administration ? voir f_admin()
132
+    $affiche_boutons_admin = ($html && (
133
+        isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver)
134
+        || $debug && include_spip('inc/autoriser') && autoriser('debug')
135
+        || defined('_VAR_PREVIEW') && _VAR_PREVIEW)
136
+    );
137
+
138
+    if ($affiche_boutons_admin) {
139
+        include_spip('balise/formulaire_admin');
140
+    }
141
+
142
+
143
+    // Execution de la page calculee
144
+
145
+    // traitements sur les entetes avant envoi
146
+    // peut servir pour le plugin de stats
147
+    $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']);
148
+
149
+
150
+    // eval $page et affecte $res
151
+    include _ROOT_RESTREINT . 'public/evaluer_page.php';
152
+    envoyer_entetes($page['entetes']);
153
+    if ($res === false) {
154
+        include_spip('inc/autoriser');
155
+        $err = _T('zbug_erreur_execution_page');
156
+        if (autoriser('webmestre')) {
157
+            $err .= "\n<hr />\n"
158
+                . highlight_string($page['codephp'], true)
159
+                . "\n<hr />\n";
160
+        }
161
+        $msg = [$err];
162
+        erreur_squelette($msg);
163
+    }
164
+
165
+    //
166
+    // Envoyer le resultat apres post-traitements
167
+    //
168
+    // (c'est ici qu'on fait var_recherche, validation, boutons d'admin,
169
+    // cf. public/assembler.php)
170
+    echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']);
171
+
172
+    if ($lang) {
173
+        lang_select();
174
+    }
175
+    // l'affichage de la page a pu lever des erreurs (inclusion manquante)
176
+    // il faut tester a nouveau
177
+    $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : [];
178
+
179
+    // Appel au debusqueur en cas d'erreurs ou de demande de trace
180
+    // at last
181
+    if ($debug) {
182
+        // en cas d'erreur, retester l'affichage
183
+        if ($html && ($affiche_boutons_admin || $debug)) {
184
+            $var_mode_affiche = _request('var_mode_affiche');
185
+            $var_mode_objet = _request('var_mode_objet');
186
+            $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : '');
187
+            echo erreur_squelette(false);
188
+        }
189
+    } else {
190
+        if (
191
+            isset($GLOBALS['meta']['date_prochain_postdate'])
192
+            && $GLOBALS['meta']['date_prochain_postdate'] <= time()
193
+        ) {
194
+            include_spip('inc/rubriques');
195
+            calculer_prochain_postdate(true);
196
+        }
197
+
198
+        // Effectuer une tache de fond ?
199
+        // si _DIRECT_CRON_FORCE est present, on force l'appel
200
+        if (defined('_DIRECT_CRON_FORCE')) {
201
+            cron();
202
+        }
203
+
204
+        // sauver le cache chemin si necessaire
205
+        save_path_cache();
206
+    }
207 207
 }
Please login to merge, or discard this patch.