Completed
Push — master ( 1891d3...7fa313 )
by cam
01:19
created
ecrire/inc/boutons.php 1 patch
Indentation   +82 added lines, -82 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
 /**
@@ -25,51 +25,51 @@  discard block
 block discarded – undo
25 25
  * privée ou dans un de ses sous menus
26 26
  */
27 27
 class Bouton {
28
-	/** @var string L'icone à mettre dans le bouton */
29
-	public $icone;
30
-
31
-	/** @var string Le nom de l'entrée d'i18n associé */
32
-	public $libelle;
33
-
34
-	/** @var null|string L'URL de la page (null => ?exec=nom) */
35
-	public $url = null;
36
-
37
-	/** @var null|string|array Arguments supplementaires de l'URL */
38
-	public $urlArg = null;
39
-
40
-	/** @var null|string URL du javascript */
41
-	public $url2 = null;
42
-
43
-	/** @var null|string Pour ouvrir dans une fenetre a part */
44
-	public $target = null;
45
-
46
-	/** @var null|mixed Sous-barre de boutons / onglets */
47
-	public $sousmenu = null;
48
-
49
-	/**
50
-	 * Définit un bouton
51
-	 *
52
-	 * @param string $icone
53
-	 *    L'icone à mettre dans le bouton
54
-	 * @param string $libelle
55
-	 *    Le nom de l'entrée i18n associé
56
-	 * @param null|string $url
57
-	 *    L'URL de la page
58
-	 * @param null|string|array $urlArg
59
-	 *    Arguments supplémentaires de l'URL
60
-	 * @param null|string $url2
61
-	 *    URL du javascript
62
-	 * @param null|mixed $target
63
-	 *    Pour ouvrir une fenêtre à part
64
-	 */
65
-	public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
-		$this->icone = $icone;
67
-		$this->libelle = $libelle;
68
-		$this->url = $url;
69
-		$this->urlArg = $urlArg;
70
-		$this->url2 = $url2;
71
-		$this->target = $target;
72
-	}
28
+    /** @var string L'icone à mettre dans le bouton */
29
+    public $icone;
30
+
31
+    /** @var string Le nom de l'entrée d'i18n associé */
32
+    public $libelle;
33
+
34
+    /** @var null|string L'URL de la page (null => ?exec=nom) */
35
+    public $url = null;
36
+
37
+    /** @var null|string|array Arguments supplementaires de l'URL */
38
+    public $urlArg = null;
39
+
40
+    /** @var null|string URL du javascript */
41
+    public $url2 = null;
42
+
43
+    /** @var null|string Pour ouvrir dans une fenetre a part */
44
+    public $target = null;
45
+
46
+    /** @var null|mixed Sous-barre de boutons / onglets */
47
+    public $sousmenu = null;
48
+
49
+    /**
50
+     * Définit un bouton
51
+     *
52
+     * @param string $icone
53
+     *    L'icone à mettre dans le bouton
54
+     * @param string $libelle
55
+     *    Le nom de l'entrée i18n associé
56
+     * @param null|string $url
57
+     *    L'URL de la page
58
+     * @param null|string|array $urlArg
59
+     *    Arguments supplémentaires de l'URL
60
+     * @param null|string $url2
61
+     *    URL du javascript
62
+     * @param null|mixed $target
63
+     *    Pour ouvrir une fenêtre à part
64
+     */
65
+    public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
+        $this->icone = $icone;
67
+        $this->libelle = $libelle;
68
+        $this->url = $url;
69
+        $this->urlArg = $urlArg;
70
+        $this->url2 = $url2;
71
+        $this->target = $target;
72
+    }
73 73
 }
74 74
 
75 75
 
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function definir_barre_onglets($script) {
88 88
 
89
-	$onglets = [];
90
-	$liste_onglets = [];
91
-
92
-	// ajouter les onglets issus des plugin via paquet.xml
93
-	if (function_exists('onglets_plugins')) {
94
-		$liste_onglets = onglets_plugins();
95
-	}
96
-
97
-
98
-	foreach ($liste_onglets as $id => $infos) {
99
-		if (
100
-			($parent = $infos['parent'])
101
-			&& $parent == $script
102
-			&& autoriser('onglet', "_$id")
103
-		) {
104
-			$onglets[$id] = new Bouton(
105
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
-				$infos['titre'],  // titre
107
-				(isset($infos['action']) and $infos['action'])
108
-					? generer_url_ecrire(
109
-						$infos['action'],
110
-						(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
-					)
112
-					: null
113
-			);
114
-		}
115
-	}
116
-
117
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
89
+    $onglets = [];
90
+    $liste_onglets = [];
91
+
92
+    // ajouter les onglets issus des plugin via paquet.xml
93
+    if (function_exists('onglets_plugins')) {
94
+        $liste_onglets = onglets_plugins();
95
+    }
96
+
97
+
98
+    foreach ($liste_onglets as $id => $infos) {
99
+        if (
100
+            ($parent = $infos['parent'])
101
+            && $parent == $script
102
+            && autoriser('onglet', "_$id")
103
+        ) {
104
+            $onglets[$id] = new Bouton(
105
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
+                $infos['titre'],  // titre
107
+                (isset($infos['action']) and $infos['action'])
108
+                    ? generer_url_ecrire(
109
+                        $infos['action'],
110
+                        (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
+                    )
112
+                    : null
113
+            );
114
+        }
115
+    }
116
+
117
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
118 118
 }
119 119
 
120 120
 
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
136
-	include_spip('inc/presentation');
136
+    include_spip('inc/presentation');
137 137
 
138
-	$res = '';
138
+    $res = '';
139 139
 
140
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
-		$url = $onglet->url ? $onglet->url : generer_url_ecrire($exec);
142
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143
-	}
140
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
+        $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec);
142
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143
+    }
144 144
 
145
-	return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
145
+    return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
146 146
 }
Please login to merge, or discard this patch.
ecrire/inc/layer.php 1 patch
Indentation   +109 added lines, -109 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
 /**
@@ -26,41 +26,41 @@  discard block
 block discarded – undo
26 26
  * @return string Code HTML du cadre dépliable
27 27
  **/
28 28
 function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') {
29
-	$bouton = bouton_block_depliable($titre, $deplie, $ids);
30
-
31
-	return
32
-		debut_cadre($style_cadre, $icone, '', $bouton, '', '', false)
33
-		. debut_block_depliable($deplie, $ids)
34
-		. "<div class='cadre_padding'>\n"
35
-		. $contenu
36
-		. "</div>\n"
37
-		. fin_block()
38
-		. fin_cadre();
29
+    $bouton = bouton_block_depliable($titre, $deplie, $ids);
30
+
31
+    return
32
+        debut_cadre($style_cadre, $icone, '', $bouton, '', '', false)
33
+        . debut_block_depliable($deplie, $ids)
34
+        . "<div class='cadre_padding'>\n"
35
+        . $contenu
36
+        . "</div>\n"
37
+        . fin_block()
38
+        . fin_cadre();
39 39
 }
40 40
 
41 41
 // https://code.spip.net/@block_parfois_visible
42 42
 function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) {
43
-	return "\n"
44
-	. bouton_block_depliable($invite, $visible, $nom)
45
-	. debut_block_depliable($visible, $nom)
46
-	. $masque
47
-	. fin_block();
43
+    return "\n"
44
+    . bouton_block_depliable($invite, $visible, $nom)
45
+    . debut_block_depliable($visible, $nom)
46
+    . $masque
47
+    . fin_block();
48 48
 }
49 49
 
50 50
 // https://code.spip.net/@debut_block_depliable
51 51
 function debut_block_depliable($deplie, $id = '') {
52
-	$class = ' blocdeplie';
53
-	// si on n'accepte pas js, ne pas fermer
54
-	if (!$deplie) {
55
-		$class = ' blocreplie';
56
-	}
52
+    $class = ' blocdeplie';
53
+    // si on n'accepte pas js, ne pas fermer
54
+    if (!$deplie) {
55
+        $class = ' blocreplie';
56
+    }
57 57
 
58
-	return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>";
58
+    return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>";
59 59
 }
60 60
 
61 61
 // https://code.spip.net/@fin_block
62 62
 function fin_block() {
63
-	return "<div class='nettoyeur'></div>\n</div>";
63
+    return "<div class='nettoyeur'></div>\n</div>";
64 64
 }
65 65
 
66 66
 // $texte : texte du bouton
@@ -68,32 +68,32 @@  discard block
 block discarded – undo
68 68
 // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit)
69 69
 // https://code.spip.net/@bouton_block_depliable
70 70
 function bouton_block_depliable($texte, $deplie, $ids = '') {
71
-	$bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8);
72
-
73
-	$class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie');
74
-	if (strlen($ids)) {
75
-		$cible = explode(',', $ids);
76
-		$cible = '#' . implode(',#', $cible);
77
-	} else {
78
-		$cible = "#$bouton_id + div.bloc_depliable";
79
-	}
80
-
81
-	$b = (strpos($texte, '<h') === false ? 'h3' : 'div');
82
-
83
-	return "<$b "
84
-	. ($bouton_id ? "id='$bouton_id' " : '')
85
-	. "class='titrem$class'"
86
-	. (($deplie === -1)
87
-		? ''
88
-		: " onmouseover=\"jQuery(this).depliant('$cible');\""
89
-	)
90
-	. '>'
91
-	// une ancre pour rendre accessible au clavier le depliage du sous bloc
92
-	. "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>"
93
-	. "$texte</$b>"
94
-	. http_script(($deplie === 'incertain')
95
-		? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});"
96
-		: '');
71
+    $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8);
72
+
73
+    $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie');
74
+    if (strlen($ids)) {
75
+        $cible = explode(',', $ids);
76
+        $cible = '#' . implode(',#', $cible);
77
+    } else {
78
+        $cible = "#$bouton_id + div.bloc_depliable";
79
+    }
80
+
81
+    $b = (strpos($texte, '<h') === false ? 'h3' : 'div');
82
+
83
+    return "<$b "
84
+    . ($bouton_id ? "id='$bouton_id' " : '')
85
+    . "class='titrem$class'"
86
+    . (($deplie === -1)
87
+        ? ''
88
+        : " onmouseover=\"jQuery(this).depliant('$cible');\""
89
+    )
90
+    . '>'
91
+    // une ancre pour rendre accessible au clavier le depliage du sous bloc
92
+    . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>"
93
+    . "$texte</$b>"
94
+    . http_script(($deplie === 'incertain')
95
+        ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});"
96
+        : '');
97 97
 }
98 98
 
99 99
 //
@@ -102,66 +102,66 @@  discard block
 block discarded – undo
102 102
 // https://code.spip.net/@verif_butineur
103 103
 function verif_butineur() {
104 104
 
105
-	preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match);
106
-	$GLOBALS['browser_name'] = $match[1];
107
-	$GLOBALS['browser_version'] = $match[2];
108
-	$GLOBALS['browser_description'] = $match[3];
109
-	$GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur
110
-	$GLOBALS['browser_barre'] = '';
111
-
112
-	if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) {
113
-		$GLOBALS['browser_name'] = 'Opera';
114
-		$GLOBALS['browser_version'] = $match[2];
115
-		$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
116
-	} else {
117
-		if (preg_match(',opera,i', $GLOBALS['browser_description'])) {
118
-			preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match);
119
-			$GLOBALS['browser_name'] = 'Opera';
120
-			$GLOBALS['browser_version'] = $match[1];
121
-			$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
122
-		} else {
123
-			if (preg_match(',msie,i', $GLOBALS['browser_description'])) {
124
-				preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match);
125
-				$GLOBALS['browser_name'] = 'MSIE';
126
-				$GLOBALS['browser_version'] = $match[1];
127
-				$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5);
128
-			} else {
129
-				if (
130
-					preg_match(',KHTML,i', $GLOBALS['browser_description']) &&
131
-					preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match)
132
-				) {
133
-					$GLOBALS['browser_name'] = 'Safari';
134
-					$GLOBALS['browser_version'] = $match[1];
135
-					$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0);
136
-				} else {
137
-					if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) {
138
-						// Numero de version pour Mozilla "authentique"
139
-						if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) {
140
-							$GLOBALS['browser_rev'] = doubleval($match[1]);
141
-						} // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.)
142
-						else {
143
-							if (
144
-								strpos($GLOBALS['browser_description'], 'Gecko') and !strpos(
145
-									$GLOBALS['browser_description'],
146
-									'KHTML'
147
-								)
148
-							) {
149
-								$GLOBALS['browser_rev'] = 1.4;
150
-							} // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.)
151
-							else {
152
-								$GLOBALS['browser_rev'] = 1.0;
153
-							}
154
-						}
155
-						$GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3;
156
-					}
157
-				}
158
-			}
159
-		}
160
-	}
161
-
162
-	if (!$GLOBALS['browser_name']) {
163
-		$GLOBALS['browser_name'] = 'Mozilla';
164
-	}
105
+    preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match);
106
+    $GLOBALS['browser_name'] = $match[1];
107
+    $GLOBALS['browser_version'] = $match[2];
108
+    $GLOBALS['browser_description'] = $match[3];
109
+    $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur
110
+    $GLOBALS['browser_barre'] = '';
111
+
112
+    if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) {
113
+        $GLOBALS['browser_name'] = 'Opera';
114
+        $GLOBALS['browser_version'] = $match[2];
115
+        $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
116
+    } else {
117
+        if (preg_match(',opera,i', $GLOBALS['browser_description'])) {
118
+            preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match);
119
+            $GLOBALS['browser_name'] = 'Opera';
120
+            $GLOBALS['browser_version'] = $match[1];
121
+            $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
122
+        } else {
123
+            if (preg_match(',msie,i', $GLOBALS['browser_description'])) {
124
+                preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match);
125
+                $GLOBALS['browser_name'] = 'MSIE';
126
+                $GLOBALS['browser_version'] = $match[1];
127
+                $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5);
128
+            } else {
129
+                if (
130
+                    preg_match(',KHTML,i', $GLOBALS['browser_description']) &&
131
+                    preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match)
132
+                ) {
133
+                    $GLOBALS['browser_name'] = 'Safari';
134
+                    $GLOBALS['browser_version'] = $match[1];
135
+                    $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0);
136
+                } else {
137
+                    if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) {
138
+                        // Numero de version pour Mozilla "authentique"
139
+                        if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) {
140
+                            $GLOBALS['browser_rev'] = doubleval($match[1]);
141
+                        } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.)
142
+                        else {
143
+                            if (
144
+                                strpos($GLOBALS['browser_description'], 'Gecko') and !strpos(
145
+                                    $GLOBALS['browser_description'],
146
+                                    'KHTML'
147
+                                )
148
+                            ) {
149
+                                $GLOBALS['browser_rev'] = 1.4;
150
+                            } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.)
151
+                            else {
152
+                                $GLOBALS['browser_rev'] = 1.0;
153
+                            }
154
+                        }
155
+                        $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3;
156
+                    }
157
+                }
158
+            }
159
+        }
160
+    }
161
+
162
+    if (!$GLOBALS['browser_name']) {
163
+        $GLOBALS['browser_name'] = 'Mozilla';
164
+    }
165 165
 }
166 166
 
167 167
 verif_butineur();
Please login to merge, or discard this patch.
ecrire/inc/pipelines.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Pipelines
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 if (test_espace_prive()) {
22
-	include_spip('inc/pipelines_ecrire');
22
+    include_spip('inc/pipelines_ecrire');
23 23
 }
24 24
 
25 25
 
@@ -45,29 +45,29 @@  discard block
 block discarded – undo
45 45
  * @return string          Contenu qui sera inséré dans le head HTML
46 46
  **/
47 47
 function f_jQuery($texte) {
48
-	$x = '';
49
-	$jquery_plugins = pipeline(
50
-		'jquery_plugins',
51
-		[
52
-			'javascript/jquery.js',
53
-			'javascript/jquery.form.js',
54
-			'javascript/jquery.autosave.js',
55
-			'javascript/jquery.placeholder-label.js',
56
-			'javascript/ajaxCallback.js',
57
-			'javascript/js.cookie.js',
58
-			'javascript/jquery.cookie.js'
59
-		]
60
-	);
61
-	foreach (array_unique($jquery_plugins) as $script) {
62
-		if ($script = find_in_path(supprimer_timestamp($script))) {
63
-			$script = timestamp($script);
64
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
65
-		}
66
-	}
48
+    $x = '';
49
+    $jquery_plugins = pipeline(
50
+        'jquery_plugins',
51
+        [
52
+            'javascript/jquery.js',
53
+            'javascript/jquery.form.js',
54
+            'javascript/jquery.autosave.js',
55
+            'javascript/jquery.placeholder-label.js',
56
+            'javascript/ajaxCallback.js',
57
+            'javascript/js.cookie.js',
58
+            'javascript/jquery.cookie.js'
59
+        ]
60
+    );
61
+    foreach (array_unique($jquery_plugins) as $script) {
62
+        if ($script = find_in_path(supprimer_timestamp($script))) {
63
+            $script = timestamp($script);
64
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
65
+        }
66
+    }
67 67
 
68
-	$texte = $x . $texte;
68
+    $texte = $x . $texte;
69 69
 
70
-	return $texte;
70
+    return $texte;
71 71
 }
72 72
 
73 73
 
@@ -86,28 +86,28 @@  discard block
 block discarded – undo
86 86
  * @return string         Contenu de la page envoyée au navigateur
87 87
  **/
88 88
 function f_surligne($texte) {
89
-	if (!$GLOBALS['html']) {
90
-		return $texte;
91
-	}
92
-	$rech = _request('var_recherche');
93
-	if (
94
-		!$rech
95
-		and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
96
-			or !_SURLIGNE_RECHERCHE_REFERERS
97
-			or !isset($_SERVER['HTTP_REFERER']))
98
-	) {
99
-		return $texte;
100
-	}
101
-	include_spip('inc/surligne');
89
+    if (!$GLOBALS['html']) {
90
+        return $texte;
91
+    }
92
+    $rech = _request('var_recherche');
93
+    if (
94
+        !$rech
95
+        and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
96
+            or !_SURLIGNE_RECHERCHE_REFERERS
97
+            or !isset($_SERVER['HTTP_REFERER']))
98
+    ) {
99
+        return $texte;
100
+    }
101
+    include_spip('inc/surligne');
102 102
 
103
-	if (isset($_SERVER['HTTP_REFERER'])) {
104
-		$_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
105
-	}
106
-	if ($rech) {
107
-		$rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
108
-	}
103
+    if (isset($_SERVER['HTTP_REFERER'])) {
104
+        $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
105
+    }
106
+    if ($rech) {
107
+        $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
108
+    }
109 109
 
110
-	return surligner_mots($texte, $rech);
110
+    return surligner_mots($texte, $rech);
111 111
 }
112 112
 
113 113
 /**
@@ -124,33 +124,33 @@  discard block
 block discarded – undo
124 124
  * @return string         Contenu de la page envoyée au navigateur
125 125
  **/
126 126
 function f_tidy($texte) {
127
-	/**
128
-	 * Indentation à faire ?
129
-	 *
130
-	 * - true : actif.
131
-	 * - false par défaut.
132
-	 */
127
+    /**
128
+     * Indentation à faire ?
129
+     *
130
+     * - true : actif.
131
+     * - false par défaut.
132
+     */
133 133
 
134
-	if (
135
-		$GLOBALS['xhtml'] # tidy demande
136
-		and $GLOBALS['html'] # verifie que la page avait l'entete text/html
137
-		and strlen($texte)
138
-		and !headers_sent()
139
-	) {
140
-		# Compatibilite ascendante
141
-		if (!is_string($GLOBALS['xhtml'])) {
142
-			$GLOBALS['xhtml'] = 'tidy';
143
-		}
134
+    if (
135
+        $GLOBALS['xhtml'] # tidy demande
136
+        and $GLOBALS['html'] # verifie que la page avait l'entete text/html
137
+        and strlen($texte)
138
+        and !headers_sent()
139
+    ) {
140
+        # Compatibilite ascendante
141
+        if (!is_string($GLOBALS['xhtml'])) {
142
+            $GLOBALS['xhtml'] = 'tidy';
143
+        }
144 144
 
145
-		if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
146
-			spip_log("tidy absent, l'indenteur SPIP le remplace");
147
-			$f = charger_fonction('sax', 'xml');
148
-		}
145
+        if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
146
+            spip_log("tidy absent, l'indenteur SPIP le remplace");
147
+            $f = charger_fonction('sax', 'xml');
148
+        }
149 149
 
150
-		return $f($texte);
151
-	}
150
+        return $f($texte);
151
+    }
152 152
 
153
-	return $texte;
153
+    return $texte;
154 154
 }
155 155
 
156 156
 
@@ -169,21 +169,21 @@  discard block
 block discarded – undo
169 169
  * @return string         Contenu de la page envoyée au navigateur
170 170
  **/
171 171
 function f_insert_head($texte) {
172
-	if (!$GLOBALS['html']) {
173
-		return $texte;
174
-	}
175
-	include_spip('public/admin'); // pour strripos
172
+    if (!$GLOBALS['html']) {
173
+        return $texte;
174
+    }
175
+    include_spip('public/admin'); // pour strripos
176 176
 
177
-	($pos = stripos($texte, '</head>'))
178
-	|| ($pos = stripos($texte, '<body>'))
179
-	|| ($pos = 0);
177
+    ($pos = stripos($texte, '</head>'))
178
+    || ($pos = stripos($texte, '<body>'))
179
+    || ($pos = 0);
180 180
 
181
-	if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) {
182
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
183
-		$texte = substr_replace($texte, $insert, $pos, 0);
184
-	}
181
+    if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) {
182
+        $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
183
+        $texte = substr_replace($texte, $insert, $pos, 0);
184
+    }
185 185
 
186
-	return $texte;
186
+    return $texte;
187 187
 }
188 188
 
189 189
 
@@ -199,34 +199,34 @@  discard block
 block discarded – undo
199 199
  * @return string         Contenu de la page envoyée au navigateur
200 200
  **/
201 201
 function f_admin($texte) {
202
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
203
-		include_spip('inc/filtres'); // pour http_img_pack
204
-		$x = "<div class='spip-previsu' "
205
-			. http_style_background('preview-32.png', '', 32)
206
-			. '>'
207
-			. _T('previsualisation')
208
-			. '</div>';
209
-		if (!$pos = stripos($texte, '</body>')) {
210
-			$pos = strlen($texte);
211
-		}
212
-		$texte = substr_replace($texte, $x, $pos, 0);
213
-		// pas de preview en fenetre enfant
214
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
215
-		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
216
-			$pos = -1;
217
-		}
218
-		$texte = substr_replace($texte, $x, $pos + 1, 0);
219
-	}
202
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
203
+        include_spip('inc/filtres'); // pour http_img_pack
204
+        $x = "<div class='spip-previsu' "
205
+            . http_style_background('preview-32.png', '', 32)
206
+            . '>'
207
+            . _T('previsualisation')
208
+            . '</div>';
209
+        if (!$pos = stripos($texte, '</body>')) {
210
+            $pos = strlen($texte);
211
+        }
212
+        $texte = substr_replace($texte, $x, $pos, 0);
213
+        // pas de preview en fenetre enfant
214
+        $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
215
+        if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
216
+            $pos = -1;
217
+        }
218
+        $texte = substr_replace($texte, $x, $pos + 1, 0);
219
+    }
220 220
 
221
-	if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
222
-		include_spip('public/admin');
223
-		$texte = affiche_boutons_admin($texte);
224
-	}
225
-	if (_request('var_mode') == 'noajax') {
226
-		$texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
227
-	}
221
+    if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
222
+        include_spip('public/admin');
223
+        $texte = affiche_boutons_admin($texte);
224
+    }
225
+    if (_request('var_mode') == 'noajax') {
226
+        $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
227
+    }
228 228
 
229
-	return $texte;
229
+    return $texte;
230 230
 }
231 231
 
232 232
 /**
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
  * @return array $flux  Description et contenu de l'inclusion
245 245
  **/
246 246
 function f_recuperer_fond($flux) {
247
-	if (!test_espace_prive()) {
248
-		return $flux;
249
-	}
247
+    if (!test_espace_prive()) {
248
+        return $flux;
249
+    }
250 250
 
251
-	return f_afficher_blocs_ecrire($flux);
251
+    return f_afficher_blocs_ecrire($flux);
252 252
 }
253 253
 
254 254
 /**
@@ -262,30 +262,30 @@  discard block
 block discarded – undo
262 262
  * @return string         Contenu de la page envoyée au navigateur
263 263
  */
264 264
 function f_queue($texte) {
265
-	// eviter une inclusion si rien a faire
266
-	if (
267
-		_request('action') == 'cron'
268
-		or queue_sleep_time_to_next_job() > 0
269
-		or defined('_DEBUG_BLOCK_QUEUE')
270
-	) {
271
-		return $texte;
272
-	}
265
+    // eviter une inclusion si rien a faire
266
+    if (
267
+        _request('action') == 'cron'
268
+        or queue_sleep_time_to_next_job() > 0
269
+        or defined('_DEBUG_BLOCK_QUEUE')
270
+    ) {
271
+        return $texte;
272
+    }
273 273
 
274
-	include_spip('inc/queue');
275
-	$code = queue_affichage_cron();
274
+    include_spip('inc/queue');
275
+    $code = queue_affichage_cron();
276 276
 
277
-	// si rien a afficher
278
-	// ou si on est pas dans une page html, on ne sait rien faire de mieux
279
-	if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
280
-		return $texte;
281
-	}
277
+    // si rien a afficher
278
+    // ou si on est pas dans une page html, on ne sait rien faire de mieux
279
+    if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
280
+        return $texte;
281
+    }
282 282
 
283
-	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
284
-	if (($p = strpos($texte, '</body>')) !== false) {
285
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
286
-	} else {
287
-		$texte .= $code;
288
-	}
283
+    // inserer avant le </body> fermant si on peut, a la fin de la page sinon
284
+    if (($p = strpos($texte, '</body>')) !== false) {
285
+        $texte = substr($texte, 0, $p) . $code . substr($texte, $p);
286
+    } else {
287
+        $texte .= $code;
288
+    }
289 289
 
290
-	return $texte;
290
+    return $texte;
291 291
 }
Please login to merge, or discard this patch.
ecrire/inc/recherche_to_array.php 1 patch
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -11,298 +11,298 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 
18 18
 // methodes sql
19 19
 function inc_recherche_to_array_dist($recherche, $options = []) {
20 20
 
21
-	// options par defaut
22
-	$options = array_merge(
23
-		[
24
-			'score' => true,
25
-			'champs' => false,
26
-			'toutvoir' => false,
27
-			'matches' => false,
28
-			'jointures' => false
29
-		],
30
-		$options
31
-	);
21
+    // options par defaut
22
+    $options = array_merge(
23
+        [
24
+            'score' => true,
25
+            'champs' => false,
26
+            'toutvoir' => false,
27
+            'matches' => false,
28
+            'jointures' => false
29
+        ],
30
+        $options
31
+    );
32 32
 
33
-	include_spip('inc/rechercher');
34
-	include_spip('inc/autoriser');
33
+    include_spip('inc/rechercher');
34
+    include_spip('inc/autoriser');
35 35
 
36
-	$requete = [
37
-		'SELECT' => [],
38
-		'FROM' => [],
39
-		'WHERE' => [],
40
-		'GROUPBY' => [],
41
-		'ORDERBY' => [],
42
-		'LIMIT' => '',
43
-		'HAVING' => []
44
-	];
36
+    $requete = [
37
+        'SELECT' => [],
38
+        'FROM' => [],
39
+        'WHERE' => [],
40
+        'GROUPBY' => [],
41
+        'ORDERBY' => [],
42
+        'LIMIT' => '',
43
+        'HAVING' => []
44
+    ];
45 45
 
46
-	$table = sinon($options['table'], 'article');
47
-	if ($options['champs']) {
48
-		$champs = $options['champs'];
49
-	} else {
50
-		$l = liste_des_champs();
51
-		$champs = $l['article'];
52
-	}
53
-	$serveur = $options['serveur'];
46
+    $table = sinon($options['table'], 'article');
47
+    if ($options['champs']) {
48
+        $champs = $options['champs'];
49
+    } else {
50
+        $l = liste_des_champs();
51
+        $champs = $l['article'];
52
+    }
53
+    $serveur = $options['serveur'];
54 54
 
55
-	list($methode, $q, $preg) = expression_recherche($recherche, $options);
55
+    list($methode, $q, $preg) = expression_recherche($recherche, $options);
56 56
 
57
-	$jointures = $options['jointures']
58
-		? liste_des_jointures()
59
-		: [];
57
+    $jointures = $options['jointures']
58
+        ? liste_des_jointures()
59
+        : [];
60 60
 
61
-	$_id_table = id_table_objet($table);
61
+    $_id_table = id_table_objet($table);
62 62
 
63
-	// c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
64
-	// (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
65
-	if (strpos($_id_table, ',') !== false) {
66
-		$_id_table = explode(',', $_id_table);
67
-		$_id_table = reset($_id_table);
68
-	}
63
+    // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
64
+    // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
65
+    if (strpos($_id_table, ',') !== false) {
66
+        $_id_table = explode(',', $_id_table);
67
+        $_id_table = reset($_id_table);
68
+    }
69 69
 
70
-	$requete['SELECT'][] = 't.' . $_id_table;
71
-	$a = [];
72
-	// Recherche fulltext
73
-	foreach ($champs as $champ => $poids) {
74
-		if (is_array($champ)) {
75
-			spip_log('requetes imbriquees interdites');
76
-		} else {
77
-			if (strpos($champ, '.') === false) {
78
-				$champ = "t.$champ";
79
-			}
80
-			$requete['SELECT'][] = $champ;
81
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
82
-		}
83
-	}
84
-	if ($a) {
85
-		$requete['WHERE'][] = join(' OR ', $a);
86
-	}
87
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
70
+    $requete['SELECT'][] = 't.' . $_id_table;
71
+    $a = [];
72
+    // Recherche fulltext
73
+    foreach ($champs as $champ => $poids) {
74
+        if (is_array($champ)) {
75
+            spip_log('requetes imbriquees interdites');
76
+        } else {
77
+            if (strpos($champ, '.') === false) {
78
+                $champ = "t.$champ";
79
+            }
80
+            $requete['SELECT'][] = $champ;
81
+            $a[] = $champ . ' ' . $methode . ' ' . $q;
82
+        }
83
+    }
84
+    if ($a) {
85
+        $requete['WHERE'][] = join(' OR ', $a);
86
+    }
87
+    $requete['FROM'][] = table_objet_sql($table) . ' AS t';
88 88
 
89
-	$results = [];
89
+    $results = [];
90 90
 
91
-	$s = sql_select(
92
-		$requete['SELECT'],
93
-		$requete['FROM'],
94
-		$requete['WHERE'],
95
-		implode(' ', $requete['GROUPBY']),
96
-		$requete['ORDERBY'],
97
-		$requete['LIMIT'],
98
-		$requete['HAVING'],
99
-		$serveur
100
-	);
91
+    $s = sql_select(
92
+        $requete['SELECT'],
93
+        $requete['FROM'],
94
+        $requete['WHERE'],
95
+        implode(' ', $requete['GROUPBY']),
96
+        $requete['ORDERBY'],
97
+        $requete['LIMIT'],
98
+        $requete['HAVING'],
99
+        $serveur
100
+    );
101 101
 
102
-	while (
103
-		$t = sql_fetch($s, $serveur)
104
-		and (!isset($t['score']) or $t['score'] > 0)
105
-	) {
106
-		$id = intval($t[$_id_table]);
102
+    while (
103
+        $t = sql_fetch($s, $serveur)
104
+        and (!isset($t['score']) or $t['score'] > 0)
105
+    ) {
106
+        $id = intval($t[$_id_table]);
107 107
 
108
-		if (
109
-			$options['toutvoir']
110
-			or autoriser('voir', $table, $id)
111
-		) {
112
-			// indiquer les champs concernes
113
-			$champs_vus = [];
114
-			$score = 0;
115
-			$matches = [];
108
+        if (
109
+            $options['toutvoir']
110
+            or autoriser('voir', $table, $id)
111
+        ) {
112
+            // indiquer les champs concernes
113
+            $champs_vus = [];
114
+            $score = 0;
115
+            $matches = [];
116 116
 
117
-			$vu = false;
118
-			foreach ($champs as $champ => $poids) {
119
-				$champ = explode('.', $champ);
120
-				$champ = end($champ);
121
-				// translitteration_rapide uniquement si on est deja en utf-8
122
-				$value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
123
-				if (
124
-					$n =
125
-					($options['score'] || $options['matches'])
126
-						? preg_match_all($preg, $value, $regs, PREG_SET_ORDER)
127
-						: preg_match($preg, $value)
128
-				) {
129
-					$vu = true;
117
+            $vu = false;
118
+            foreach ($champs as $champ => $poids) {
119
+                $champ = explode('.', $champ);
120
+                $champ = end($champ);
121
+                // translitteration_rapide uniquement si on est deja en utf-8
122
+                $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
123
+                if (
124
+                    $n =
125
+                    ($options['score'] || $options['matches'])
126
+                        ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER)
127
+                        : preg_match($preg, $value)
128
+                ) {
129
+                    $vu = true;
130 130
 
131
-					if ($options['champs']) {
132
-						$champs_vus[$champ] = $t[$champ];
133
-					}
134
-					if ($options['score']) {
135
-						// compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
136
-						$score += $poids * strlen(implode('', array_column($regs, 0)));
137
-					}
131
+                    if ($options['champs']) {
132
+                        $champs_vus[$champ] = $t[$champ];
133
+                    }
134
+                    if ($options['score']) {
135
+                        // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
136
+                        $score += $poids * strlen(implode('', array_column($regs, 0)));
137
+                    }
138 138
 
139
-					if ($options['matches']) {
140
-						$matches[$champ] = $regs;
141
-					}
139
+                    if ($options['matches']) {
140
+                        $matches[$champ] = $regs;
141
+                    }
142 142
 
143
-					if (
144
-						!$options['champs']
145
-						and !$options['score']
146
-						and !$options['matches']
147
-					) {
148
-						break;
149
-					}
150
-				}
151
-			}
143
+                    if (
144
+                        !$options['champs']
145
+                        and !$options['score']
146
+                        and !$options['matches']
147
+                    ) {
148
+                        break;
149
+                    }
150
+                }
151
+            }
152 152
 
153
-			if ($vu) {
154
-				if (!isset($results)) {
155
-					$results = [];
156
-				}
157
-				$results[$id] = [];
158
-				if ($champs_vus) {
159
-					$results[$id]['champs'] = $champs_vus;
160
-				}
161
-				if ($score) {
162
-					$results[$id]['score'] = $score;
163
-				}
164
-				if ($matches) {
165
-					$results[$id]['matches'] = $matches;
166
-				}
167
-			}
168
-		}
169
-	}
153
+            if ($vu) {
154
+                if (!isset($results)) {
155
+                    $results = [];
156
+                }
157
+                $results[$id] = [];
158
+                if ($champs_vus) {
159
+                    $results[$id]['champs'] = $champs_vus;
160
+                }
161
+                if ($score) {
162
+                    $results[$id]['score'] = $score;
163
+                }
164
+                if ($matches) {
165
+                    $results[$id]['matches'] = $matches;
166
+                }
167
+            }
168
+        }
169
+    }
170 170
 
171 171
 
172
-	// Gerer les donnees associees
173
-	// ici on est un peu naze : pas capables de reconstruire une jointure complexe
174
-	// on ne sait passer que par table de laison en 1 coup
175
-	if (
176
-		isset($jointures[$table])
177
-		and $joints = recherche_en_base(
178
-			$recherche,
179
-			$jointures[$table],
180
-			array_merge($options, ['jointures' => false])
181
-		)
182
-	) {
183
-		include_spip('action/editer_liens');
184
-		$trouver_table = charger_fonction('trouver_table', 'base');
185
-		$cle_depart = id_table_objet($table);
186
-		$table_depart = table_objet($table, $serveur);
187
-		$desc_depart = $trouver_table($table_depart, $serveur);
188
-		$depart_associable = objet_associable($table);
189
-		foreach ($joints as $table_liee => $ids_trouves) {
190
-			// on peut definir une fonction de recherche jointe pour regler les cas particuliers
191
-			if (
192
-				!(
193
-				$rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true)
194
-				or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true)
195
-				or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true)
196
-				)
197
-			) {
198
-				$cle_arrivee = id_table_objet($table_liee);
199
-				$table_arrivee = table_objet($table_liee, $serveur);
200
-				$desc_arrivee = $trouver_table($table_arrivee, $serveur);
201
-				// cas simple : $cle_depart dans la table_liee
202
-				if (isset($desc_arrivee['field'][$cle_depart])) {
203
-					$s = sql_select(
204
-						"$cle_depart, $cle_arrivee",
205
-						$desc_arrivee['table_sql'],
206
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
207
-						'',
208
-						'',
209
-						'',
210
-						'',
211
-						$serveur
212
-					);
213
-				} // cas simple : $cle_arrivee dans la table
214
-				elseif (isset($desc_depart['field'][$cle_arrivee])) {
215
-					$s = sql_select(
216
-						"$cle_depart, $cle_arrivee",
217
-						$desc_depart['table_sql'],
218
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
219
-						'',
220
-						'',
221
-						'',
222
-						'',
223
-						$serveur
224
-					);
225
-				}
226
-				// sinon cherchons une table de liaison
227
-				// cas recherche principale article, objet lie document : passer par spip_documents_liens
228
-				elseif ($l = objet_associable($table_liee)) {
229
-					list($primary, $table_liens) = $l;
230
-					$s = sql_select(
231
-						"id_objet as $cle_depart, $primary as $cle_arrivee",
232
-						$table_liens,
233
-						["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
234
-						'',
235
-						'',
236
-						'',
237
-						'',
238
-						$serveur
239
-					);
240
-				} // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
241
-				elseif ($l = $depart_associable) {
242
-					list($primary, $table_liens) = $l;
243
-					$s = sql_select(
244
-						"$primary as $cle_depart, id_objet as $cle_arrivee",
245
-						$table_liens,
246
-						["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
247
-						'',
248
-						'',
249
-						'',
250
-						'',
251
-						$serveur
252
-					);
253
-				} // cas table de liaison generique spip_xxx_yyy
254
-				elseif (
255
-					$t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)
256
-					or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)
257
-				) {
258
-					$s = sql_select(
259
-						"$cle_depart,$cle_arrivee",
260
-						$t['table_sql'],
261
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
262
-						'',
263
-						'',
264
-						'',
265
-						'',
266
-						$serveur
267
-					);
268
-				}
269
-			} else {
270
-				list($cle_depart, $cle_arrivee, $s) = $rechercher_joints(
271
-					$table,
272
-					$table_liee,
273
-					array_keys($ids_trouves),
274
-					$serveur
275
-				);
276
-			}
172
+    // Gerer les donnees associees
173
+    // ici on est un peu naze : pas capables de reconstruire une jointure complexe
174
+    // on ne sait passer que par table de laison en 1 coup
175
+    if (
176
+        isset($jointures[$table])
177
+        and $joints = recherche_en_base(
178
+            $recherche,
179
+            $jointures[$table],
180
+            array_merge($options, ['jointures' => false])
181
+        )
182
+    ) {
183
+        include_spip('action/editer_liens');
184
+        $trouver_table = charger_fonction('trouver_table', 'base');
185
+        $cle_depart = id_table_objet($table);
186
+        $table_depart = table_objet($table, $serveur);
187
+        $desc_depart = $trouver_table($table_depart, $serveur);
188
+        $depart_associable = objet_associable($table);
189
+        foreach ($joints as $table_liee => $ids_trouves) {
190
+            // on peut definir une fonction de recherche jointe pour regler les cas particuliers
191
+            if (
192
+                !(
193
+                $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true)
194
+                or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true)
195
+                or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true)
196
+                )
197
+            ) {
198
+                $cle_arrivee = id_table_objet($table_liee);
199
+                $table_arrivee = table_objet($table_liee, $serveur);
200
+                $desc_arrivee = $trouver_table($table_arrivee, $serveur);
201
+                // cas simple : $cle_depart dans la table_liee
202
+                if (isset($desc_arrivee['field'][$cle_depart])) {
203
+                    $s = sql_select(
204
+                        "$cle_depart, $cle_arrivee",
205
+                        $desc_arrivee['table_sql'],
206
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
207
+                        '',
208
+                        '',
209
+                        '',
210
+                        '',
211
+                        $serveur
212
+                    );
213
+                } // cas simple : $cle_arrivee dans la table
214
+                elseif (isset($desc_depart['field'][$cle_arrivee])) {
215
+                    $s = sql_select(
216
+                        "$cle_depart, $cle_arrivee",
217
+                        $desc_depart['table_sql'],
218
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
219
+                        '',
220
+                        '',
221
+                        '',
222
+                        '',
223
+                        $serveur
224
+                    );
225
+                }
226
+                // sinon cherchons une table de liaison
227
+                // cas recherche principale article, objet lie document : passer par spip_documents_liens
228
+                elseif ($l = objet_associable($table_liee)) {
229
+                    list($primary, $table_liens) = $l;
230
+                    $s = sql_select(
231
+                        "id_objet as $cle_depart, $primary as $cle_arrivee",
232
+                        $table_liens,
233
+                        ["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
234
+                        '',
235
+                        '',
236
+                        '',
237
+                        '',
238
+                        $serveur
239
+                    );
240
+                } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
241
+                elseif ($l = $depart_associable) {
242
+                    list($primary, $table_liens) = $l;
243
+                    $s = sql_select(
244
+                        "$primary as $cle_depart, id_objet as $cle_arrivee",
245
+                        $table_liens,
246
+                        ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
247
+                        '',
248
+                        '',
249
+                        '',
250
+                        '',
251
+                        $serveur
252
+                    );
253
+                } // cas table de liaison generique spip_xxx_yyy
254
+                elseif (
255
+                    $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)
256
+                    or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)
257
+                ) {
258
+                    $s = sql_select(
259
+                        "$cle_depart,$cle_arrivee",
260
+                        $t['table_sql'],
261
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
262
+                        '',
263
+                        '',
264
+                        '',
265
+                        '',
266
+                        $serveur
267
+                    );
268
+                }
269
+            } else {
270
+                list($cle_depart, $cle_arrivee, $s) = $rechercher_joints(
271
+                    $table,
272
+                    $table_liee,
273
+                    array_keys($ids_trouves),
274
+                    $serveur
275
+                );
276
+            }
277 277
 
278
-			while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
279
-				$id = $t[$cle_depart];
280
-				$joint = $ids_trouves[$t[$cle_arrivee]];
281
-				if (!isset($results)) {
282
-					$results = [];
283
-				}
284
-				if (!isset($results[$id])) {
285
-					$results[$id] = [];
286
-				}
287
-				if (isset($joint['score']) and $joint['score']) {
288
-					if (!isset($results[$id]['score'])) {
289
-						$results[$id]['score'] = 0;
290
-					}
291
-					$results[$id]['score'] += $joint['score'];
292
-				}
293
-				if (isset($joint['champs']) and $joint['champs']) {
294
-					foreach ($joint['champs'] as $c => $val) {
295
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
296
-					}
297
-				}
298
-				if (isset($joint['matches']) and $joint['matches']) {
299
-					foreach ($joint['matches'] as $c => $val) {
300
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
301
-					}
302
-				}
303
-			}
304
-		}
305
-	}
278
+            while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
279
+                $id = $t[$cle_depart];
280
+                $joint = $ids_trouves[$t[$cle_arrivee]];
281
+                if (!isset($results)) {
282
+                    $results = [];
283
+                }
284
+                if (!isset($results[$id])) {
285
+                    $results[$id] = [];
286
+                }
287
+                if (isset($joint['score']) and $joint['score']) {
288
+                    if (!isset($results[$id]['score'])) {
289
+                        $results[$id]['score'] = 0;
290
+                    }
291
+                    $results[$id]['score'] += $joint['score'];
292
+                }
293
+                if (isset($joint['champs']) and $joint['champs']) {
294
+                    foreach ($joint['champs'] as $c => $val) {
295
+                        $results[$id]['champs'][$table_liee . '.' . $c] = $val;
296
+                    }
297
+                }
298
+                if (isset($joint['matches']) and $joint['matches']) {
299
+                    foreach ($joint['matches'] as $c => $val) {
300
+                        $results[$id]['matches'][$table_liee . '.' . $c] = $val;
301
+                    }
302
+                }
303
+            }
304
+        }
305
+    }
306 306
 
307
-	return $results;
307
+    return $results;
308 308
 }
Please login to merge, or discard this patch.
ecrire/inc/headers.php 1 patch
Indentation   +158 added lines, -158 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
 
@@ -38,134 +38,134 @@  discard block
 block discarded – undo
38 38
  * @param int $status Code de redirection (301 ou 302)
39 39
  **/
40 40
 function redirige_par_entete($url, $equiv = '', $status = 302) {
41
-	if (!in_array($status, [301, 302])) {
42
-		$status = 302;
43
-	}
44
-
45
-	$url = trim(strtr($url, "\n\r", '  '));
46
-	# si l'url de redirection est relative, on la passe en absolue
47
-	if (!preg_match(',^(\w+:)?//,', $url)) {
48
-		include_spip('inc/filtres_mini');
49
-		$url = url_absolue($url);
50
-	}
51
-
52
-	if (defined('_AJAX') and _AJAX) {
53
-		$url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
-	}
55
-
56
-	// ne pas laisser passer n'importe quoi dans l'url
57
-	$url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
58
-	$url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
59
-	while (strpos($url, '%0A') !== false) {
60
-		$url = str_replace('%0A', '', $url);
61
-	}
62
-	// interdire les url inline avec des pseudo-protocoles :
63
-	if (
64
-		(preg_match(',data:,i', $url) and preg_match('/base64\s*,/i', $url))
65
-		or preg_match(',(javascript|mailto):,i', $url)
66
-	) {
67
-		$url = './';
68
-	}
69
-
70
-	// Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
-	include_spip('inc/cookie');
72
-	if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
-		define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
-	}
75
-	if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
-		define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
-	}
78
-	if (
79
-		(!$equiv and !spip_cookie_envoye()) or (
80
-			   (!empty($_SERVER['SERVER_SOFTWARE'])
81
-				   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
82
-				   and preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SOFTWARE']))
83
-			or (!empty($_SERVER['SERVER_SIGNATURE'])
84
-				   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
85
-				   and preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SIGNATURE']))
86
-			or function_exists('apache_getenv')
87
-			or defined('_SERVER_APACHE')
88
-		)
89
-	) {
90
-		@header('Location: ' . $url);
91
-		$equiv = '';
92
-	} else {
93
-		@header('Refresh: 0; url=' . $url);
94
-		if (isset($GLOBALS['meta']['charset'])) {
95
-			@header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
96
-		}
97
-		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
98
-	}
99
-	include_spip('inc/lang');
100
-	if ($status != 302) {
101
-		http_status($status);
102
-	}
103
-	echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
104
-	html_lang_attributes(), '
41
+    if (!in_array($status, [301, 302])) {
42
+        $status = 302;
43
+    }
44
+
45
+    $url = trim(strtr($url, "\n\r", '  '));
46
+    # si l'url de redirection est relative, on la passe en absolue
47
+    if (!preg_match(',^(\w+:)?//,', $url)) {
48
+        include_spip('inc/filtres_mini');
49
+        $url = url_absolue($url);
50
+    }
51
+
52
+    if (defined('_AJAX') and _AJAX) {
53
+        $url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
+    }
55
+
56
+    // ne pas laisser passer n'importe quoi dans l'url
57
+    $url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
58
+    $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
59
+    while (strpos($url, '%0A') !== false) {
60
+        $url = str_replace('%0A', '', $url);
61
+    }
62
+    // interdire les url inline avec des pseudo-protocoles :
63
+    if (
64
+        (preg_match(',data:,i', $url) and preg_match('/base64\s*,/i', $url))
65
+        or preg_match(',(javascript|mailto):,i', $url)
66
+    ) {
67
+        $url = './';
68
+    }
69
+
70
+    // Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
+    include_spip('inc/cookie');
72
+    if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
+        define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
+    }
75
+    if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
+        define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
+    }
78
+    if (
79
+        (!$equiv and !spip_cookie_envoye()) or (
80
+                (!empty($_SERVER['SERVER_SOFTWARE'])
81
+                   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
82
+                   and preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SOFTWARE']))
83
+            or (!empty($_SERVER['SERVER_SIGNATURE'])
84
+                   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
85
+                   and preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SIGNATURE']))
86
+            or function_exists('apache_getenv')
87
+            or defined('_SERVER_APACHE')
88
+        )
89
+    ) {
90
+        @header('Location: ' . $url);
91
+        $equiv = '';
92
+    } else {
93
+        @header('Refresh: 0; url=' . $url);
94
+        if (isset($GLOBALS['meta']['charset'])) {
95
+            @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
96
+        }
97
+        $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
98
+    }
99
+    include_spip('inc/lang');
100
+    if ($status != 302) {
101
+        http_status($status);
102
+    }
103
+    echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
104
+    html_lang_attributes(), '
105 105
 <head>',
106
-	$equiv, '
106
+    $equiv, '
107 107
 <title>HTTP ' . $status . '</title>
108 108
 ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
109 109
 </head>
110 110
 <body>
111 111
 <h1>HTTP ' . $status . '</h1>
112 112
 <a href="',
113
-	quote_amp($url),
114
-	'">',
115
-	_T('navigateur_pas_redirige'),
116
-	'</a></body></html>';
113
+    quote_amp($url),
114
+    '">',
115
+    _T('navigateur_pas_redirige'),
116
+    '</a></body></html>';
117 117
 
118
-	spip_log("redirige $status: $url");
118
+    spip_log("redirige $status: $url");
119 119
 
120
-	exit;
120
+    exit;
121 121
 }
122 122
 
123 123
 // https://code.spip.net/@redirige_formulaire
124 124
 function redirige_formulaire($url, $equiv = '', $format = 'message') {
125
-	if (
126
-		!_AJAX
127
-		and !headers_sent()
128
-		and !_request('var_ajax')
129
-	) {
130
-		redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
131
-	} // si c'est une ancre, fixer simplement le window.location.hash
132
-	elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
133
-		return [
134
-			// on renvoie un lien masque qui sera traite par ajaxCallback.js
135
-			"<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
136
-			// et rien dans le message ok
137
-			''
138
-		];
139
-	} else {
140
-		// ne pas laisser passer n'importe quoi dans l'url
141
-		$url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
142
-
143
-		$url = strtr($url, "\n\r", '  ');
144
-		# en theorie on devrait faire ca tout le temps, mais quand la chaine
145
-		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
146
-		if ($url[0] == '?') {
147
-			$url = url_de_base() . $url;
148
-		}
149
-		$url = str_replace('&amp;', '&', $url);
150
-		spip_log("redirige formulaire ajax: $url");
151
-		include_spip('inc/filtres');
152
-		if ($format == 'ajaxform') {
153
-			return [
154
-				// on renvoie un lien masque qui sera traite par ajaxCallback.js
155
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
156
-				// et un message au cas ou
157
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
158
-			];
159
-		} else // format message texte, tout en js inline
160
-		{
161
-			return
162
-				// ie poste les formulaires dans une iframe, il faut donc rediriger son parent
163
-				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
164
-				. http_img_pack('loader.svg', '', " class='loader'")
165
-				. '<br />'
166
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
167
-		}
168
-	}
125
+    if (
126
+        !_AJAX
127
+        and !headers_sent()
128
+        and !_request('var_ajax')
129
+    ) {
130
+        redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
131
+    } // si c'est une ancre, fixer simplement le window.location.hash
132
+    elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
133
+        return [
134
+            // on renvoie un lien masque qui sera traite par ajaxCallback.js
135
+            "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
136
+            // et rien dans le message ok
137
+            ''
138
+        ];
139
+    } else {
140
+        // ne pas laisser passer n'importe quoi dans l'url
141
+        $url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
142
+
143
+        $url = strtr($url, "\n\r", '  ');
144
+        # en theorie on devrait faire ca tout le temps, mais quand la chaine
145
+        # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
146
+        if ($url[0] == '?') {
147
+            $url = url_de_base() . $url;
148
+        }
149
+        $url = str_replace('&amp;', '&', $url);
150
+        spip_log("redirige formulaire ajax: $url");
151
+        include_spip('inc/filtres');
152
+        if ($format == 'ajaxform') {
153
+            return [
154
+                // on renvoie un lien masque qui sera traite par ajaxCallback.js
155
+                '<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
156
+                // et un message au cas ou
157
+                '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
158
+            ];
159
+        } else // format message texte, tout en js inline
160
+        {
161
+            return
162
+                // ie poste les formulaires dans une iframe, il faut donc rediriger son parent
163
+                "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
164
+                . http_img_pack('loader.svg', '', " class='loader'")
165
+                . '<br />'
166
+                . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
167
+        }
168
+    }
169 169
 }
170 170
 
171 171
 /**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
  * @return void
187 187
  **/
188 188
 function redirige_url_ecrire($script = '', $args = '', $equiv = '') {
189
-	return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
189
+    return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
190 190
 }
191 191
 
192 192
 /**
@@ -201,50 +201,50 @@  discard block
 block discarded – undo
201 201
  **/
202 202
 function http_status($status) {
203 203
 
204
-	static $status_string = [
205
-		200 => '200 OK',
206
-		204 => '204 No Content',
207
-		301 => '301 Moved Permanently',
208
-		302 => '302 Found',
209
-		304 => '304 Not Modified',
210
-		400 => '400 Bad Request',
211
-		401 => '401 Unauthorized',
212
-		403 => '403 Forbidden',
213
-		404 => '404 Not Found',
214
-		503 => '503 Service Unavailable'
215
-	];
216
-
217
-	if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
218
-		return;
219
-	}
220
-
221
-	$php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(',cgi,i', @php_sapi_name()));
222
-	if ($php_cgi) {
223
-		header('Status: ' . $status_string[$status]);
224
-	} else {
225
-		header('HTTP/1.0 ' . $status_string[$status]);
226
-	}
204
+    static $status_string = [
205
+        200 => '200 OK',
206
+        204 => '204 No Content',
207
+        301 => '301 Moved Permanently',
208
+        302 => '302 Found',
209
+        304 => '304 Not Modified',
210
+        400 => '400 Bad Request',
211
+        401 => '401 Unauthorized',
212
+        403 => '403 Forbidden',
213
+        404 => '404 Not Found',
214
+        503 => '503 Service Unavailable'
215
+    ];
216
+
217
+    if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
218
+        return;
219
+    }
220
+
221
+    $php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(',cgi,i', @php_sapi_name()));
222
+    if ($php_cgi) {
223
+        header('Status: ' . $status_string[$status]);
224
+    } else {
225
+        header('HTTP/1.0 ' . $status_string[$status]);
226
+    }
227 227
 }
228 228
 
229 229
 // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache
230 230
 // https://code.spip.net/@http_no_cache
231 231
 function http_no_cache() {
232
-	if (headers_sent()) {
233
-		spip_log('http_no_cache arrive trop tard');
234
-
235
-		return;
236
-	}
237
-	$charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
238
-
239
-	// selon http://developer.apple.com/internet/safari/faq.html#anchor5
240
-	// il faudrait aussi pour Safari
241
-	// header("Cache-Control: post-check=0, pre-check=0", false)
242
-	// mais ca ne respecte pas
243
-	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
244
-
245
-	header("Content-Type: text/html; charset=$charset");
246
-	header('Expires: 0');
247
-	header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
248
-	header('Cache-Control: no-cache, must-revalidate');
249
-	header('Pragma: no-cache');
232
+    if (headers_sent()) {
233
+        spip_log('http_no_cache arrive trop tard');
234
+
235
+        return;
236
+    }
237
+    $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
238
+
239
+    // selon http://developer.apple.com/internet/safari/faq.html#anchor5
240
+    // il faudrait aussi pour Safari
241
+    // header("Cache-Control: post-check=0, pre-check=0", false)
242
+    // mais ca ne respecte pas
243
+    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
244
+
245
+    header("Content-Type: text/html; charset=$charset");
246
+    header('Expires: 0');
247
+    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
248
+    header('Cache-Control: no-cache, must-revalidate');
249
+    header('Pragma: no-cache');
250 250
 }
Please login to merge, or discard this patch.
ecrire/inc/install.php 1 patch
Indentation   +359 added lines, -359 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
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
47
-		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
-		. $texte
49
-		. '?' . '>';
46
+    $texte = '<' . "?php\n"
47
+        . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
+        . $texte
49
+        . '?' . '>';
50 50
 
51
-	ecrire_fichier($nom, $texte);
51
+    ecrire_fichier($nom, $texte);
52 52
 }
53 53
 
54 54
 
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
  *
78 78
  **/
79 79
 function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') {
80
-	$adr = addcslashes($adr, "'\\");
81
-	$port = addcslashes($port, "'\\");
82
-	$login = addcslashes($login, "'\\");
83
-	$pass = addcslashes($pass, "'\\");
84
-	$base = addcslashes($base, "'\\");
85
-	$type = addcslashes($type, "'\\");
86
-	$pref = addcslashes($pref, "'\\");
87
-	$ldap = addcslashes($ldap, "'\\");
88
-	$charset = addcslashes($charset, "'\\");
89
-
90
-	return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
-	. 'spip_connect_db('
92
-	. "'$adr','$port','$login','$pass','$base'"
93
-	. ",'$type', '$pref','$ldap','$charset');\n";
80
+    $adr = addcslashes($adr, "'\\");
81
+    $port = addcslashes($port, "'\\");
82
+    $login = addcslashes($login, "'\\");
83
+    $pass = addcslashes($pass, "'\\");
84
+    $base = addcslashes($base, "'\\");
85
+    $type = addcslashes($type, "'\\");
86
+    $pref = addcslashes($pref, "'\\");
87
+    $ldap = addcslashes($ldap, "'\\");
88
+    $charset = addcslashes($charset, "'\\");
89
+
90
+    return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
+    . 'spip_connect_db('
92
+    . "'$adr','$port','$login','$pass','$base'"
93
+    . ",'$type', '$pref','$ldap','$charset');\n";
94 94
 }
95 95
 
96 96
 
@@ -106,26 +106,26 @@  discard block
 block discarded – undo
106 106
  *     Tableau des informations sur la connexion
107 107
  **/
108 108
 function analyse_fichier_connection($file) {
109
-	$s = @join('', file($file));
110
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
-		array_shift($regs);
112
-
113
-		return $regs;
114
-	} else {
115
-		$ar = '\s*\'([^\']*)\'';
116
-		$r = '\s*,' . $ar;
117
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
-		if (preg_match($r, $s, $regs)) {
119
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
-			array_shift($regs);
121
-			array_shift($regs);
122
-
123
-			return $regs;
124
-		}
125
-	}
126
-	spip_log("$file n'est pas un fichier de connexion");
127
-
128
-	return [];
109
+    $s = @join('', file($file));
110
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
+        array_shift($regs);
112
+
113
+        return $regs;
114
+    } else {
115
+        $ar = '\s*\'([^\']*)\'';
116
+        $r = '\s*,' . $ar;
117
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
+        if (preg_match($r, $s, $regs)) {
119
+            $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
+            array_shift($regs);
121
+            array_shift($regs);
122
+
123
+            return $regs;
124
+        }
125
+    }
126
+    spip_log("$file n'est pas un fichier de connexion");
127
+
128
+    return [];
129 129
 }
130 130
 
131 131
 /**
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  *     Liste des noms de connecteurs
143 143
  **/
144 144
 function bases_referencees($exclu = '') {
145
-	$tables = [];
146
-	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
-		if ($f != $exclu and analyse_fichier_connection($f)) {
148
-			$tables[] = basename($f, '.php');
149
-		}
150
-	}
151
-
152
-	return $tables;
145
+    $tables = [];
146
+    foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
+        if ($f != $exclu and analyse_fichier_connection($f)) {
148
+            $tables[] = basename($f, '.php');
149
+        }
150
+    }
151
+
152
+    return $tables;
153 153
 }
154 154
 
155 155
 
156 156
 function install_mode_appel($server_db, $tout = true) {
157
-	return ($server_db != 'mysql') ? ''
158
-		: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
-			. test_sql_mode_mysql($server_db));
157
+    return ($server_db != 'mysql') ? ''
158
+        : (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
+            . test_sql_mode_mysql($server_db));
160 160
 }
161 161
 
162 162
 //
@@ -164,52 +164,52 @@  discard block
 block discarded – undo
164 164
 // (sert a l'etape 1 de l'installation)
165 165
 // https://code.spip.net/@tester_compatibilite_hebergement
166 166
 function tester_compatibilite_hebergement() {
167
-	$err = [];
168
-
169
-	$p = phpversion();
170
-	if (version_compare($p, _PHP_MIN, '<')) {
171
-		$err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
-	}
173
-
174
-	// Si on n'a pas la bonne version de PHP, c'est la fin
175
-	if ($err) {
176
-		die("<div class='error'>"
177
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
-			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
-	}
180
-
181
-	// Il faut une base de donnees tout de meme ...
182
-	$serveurs = install_select_serveur();
183
-	if (!$serveurs) {
184
-		$err[] = _T('install_extension_php_obligatoire')
185
-			. " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
-			. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
-			. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
-	}
189
-
190
-	// et il faut preg
191
-	if (!function_exists('preg_match_all')) {
192
-		$err[] = _T('install_extension_php_obligatoire')
193
-			. " <a href='http://se.php.net/pcre'>PCRE</a>";
194
-	}
195
-
196
-	// et surtout pas ce mbstring.overload
197
-	if ($a = @ini_get('mbstring.func_overload')) {
198
-		$err[] = _T('install_extension_mbstring')
199
-			. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
-	}
201
-
202
-	if ($err) {
203
-		echo "<div class='error'>"
204
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
-		foreach ($err as $e) {
206
-			echo "<li><strong>$e</strong></li>\n";
207
-		}
208
-
209
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
210
-		# de forcer malgre tout (pour tester, ou si bug de detection)
211
-		echo "</ul></div>\n";
212
-	}
167
+    $err = [];
168
+
169
+    $p = phpversion();
170
+    if (version_compare($p, _PHP_MIN, '<')) {
171
+        $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
+    }
173
+
174
+    // Si on n'a pas la bonne version de PHP, c'est la fin
175
+    if ($err) {
176
+        die("<div class='error'>"
177
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
+            . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
+    }
180
+
181
+    // Il faut une base de donnees tout de meme ...
182
+    $serveurs = install_select_serveur();
183
+    if (!$serveurs) {
184
+        $err[] = _T('install_extension_php_obligatoire')
185
+            . " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
+            . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
+            . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
+    }
189
+
190
+    // et il faut preg
191
+    if (!function_exists('preg_match_all')) {
192
+        $err[] = _T('install_extension_php_obligatoire')
193
+            . " <a href='http://se.php.net/pcre'>PCRE</a>";
194
+    }
195
+
196
+    // et surtout pas ce mbstring.overload
197
+    if ($a = @ini_get('mbstring.func_overload')) {
198
+        $err[] = _T('install_extension_mbstring')
199
+            . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
+    }
201
+
202
+    if ($err) {
203
+        echo "<div class='error'>"
204
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
+        foreach ($err as $e) {
206
+            echo "<li><strong>$e</strong></li>\n";
207
+        }
208
+
209
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
210
+        # de forcer malgre tout (pour tester, ou si bug de detection)
211
+        echo "</ul></div>\n";
212
+    }
213 213
 }
214 214
 
215 215
 
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
  * @note superflu ??
220 220
  */
221 221
 function login_hebergeur() {
222
-	$base_hebergeur = 'localhost'; # par defaut
222
+    $base_hebergeur = 'localhost'; # par defaut
223 223
 
224
-	// Free
225
-	if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
-		$base_hebergeur = 'sql.free.fr';
227
-		$login_hebergeur = $regs[1];
228
-	} else {
229
-		$login_hebergeur = '';
230
-	}
224
+    // Free
225
+    if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
+        $base_hebergeur = 'sql.free.fr';
227
+        $login_hebergeur = $regs[1];
228
+    } else {
229
+        $login_hebergeur = '';
230
+    }
231 231
 
232
-	return [$base_hebergeur, $login_hebergeur];
232
+    return [$base_hebergeur, $login_hebergeur];
233 233
 }
234 234
 
235 235
 
236 236
 // https://code.spip.net/@info_etape
237 237
 function info_etape($titre, $complement = '') {
238
-	return '<h2>' . $titre . "</h2>\n" .
239
-	($complement ? '' . $complement . "\n" : '');
238
+    return '<h2>' . $titre . "</h2>\n" .
239
+    ($complement ? '' . $complement . "\n" : '');
240 240
 }
241 241
 
242 242
 /**
@@ -246,156 +246,156 @@  discard block
 block discarded – undo
246 246
  * @return string Code HTML du bouton
247 247
  **/
248 248
 function bouton_suivant($code = '') {
249
-	if ($code == '') {
250
-		$code = _T('bouton_suivant');
251
-	}
252
-	static $suivant = 0;
253
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
-	$suivant += 1;
255
-
256
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
-	$code .
258
-	" >>\" /></p>\n";
249
+    if ($code == '') {
250
+        $code = _T('bouton_suivant');
251
+    }
252
+    static $suivant = 0;
253
+    $id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
+    $suivant += 1;
255
+
256
+    return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
+    $code .
258
+    " >>\" /></p>\n";
259 259
 }
260 260
 
261 261
 // https://code.spip.net/@info_progression_etape
262 262
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
263
-	//$en_cours = _request('etape')?_request('etape'):"";
264
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
-	$debut = 1;
266
-	$etat = 'ok';
267
-	$last = count($liste);
263
+    //$en_cours = _request('etape')?_request('etape'):"";
264
+    $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
+    $debut = 1;
266
+    $etat = 'ok';
267
+    $last = count($liste);
268 268
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
269 269
 
270
-	$intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
-	$intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
-	$intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
-	$intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
270
+    $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
+    $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
+    $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
+    $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
274 274
 
275
-	$intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
-	$intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
-	$intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
-	$intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
-	$intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
275
+    $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
+    $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
+    $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
+    $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
+    $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
280 280
 
281 281
 //	$aff_etapes = "<span id='etapes'>";
282 282
 
283
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
-
285
-	foreach ($liste as $etape => $fichier) {
286
-		if ($debut < $last) {
287
-			if ($debut == $en_cours && $erreur) {
288
-				$class = 'on erreur';
289
-			} else {
290
-				if ($debut == $en_cours) {
291
-					$class = 'on';
292
-				} else {
293
-					if ($debut > $en_cours) {
294
-						$class = 'prochains';
295
-					} else {
296
-						$class = 'valides';
297
-					}
298
-				}
299
-			}
300
-
301
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
302
-			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
-			$aff_etapes .= $intitule_etat["$phase"][$debut];
305
-			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
-			$aff_etapes .= '</div></li>';
307
-		}
308
-		$debut++;
309
-	}
310
-	$aff_etapes .= '</ul>';
311
-	$aff_etapes .= "<br class='nettoyeur' />\n";
312
-
313
-	return $aff_etapes;
283
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
+
285
+    foreach ($liste as $etape => $fichier) {
286
+        if ($debut < $last) {
287
+            if ($debut == $en_cours && $erreur) {
288
+                $class = 'on erreur';
289
+            } else {
290
+                if ($debut == $en_cours) {
291
+                    $class = 'on';
292
+                } else {
293
+                    if ($debut > $en_cours) {
294
+                        $class = 'prochains';
295
+                    } else {
296
+                        $class = 'valides';
297
+                    }
298
+                }
299
+            }
300
+
301
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
302
+            $aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
+            $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
+            $aff_etapes .= $intitule_etat["$phase"][$debut];
305
+            $aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
+            $aff_etapes .= '</div></li>';
307
+        }
308
+        $debut++;
309
+    }
310
+    $aff_etapes .= '</ul>';
311
+    $aff_etapes .= "<br class='nettoyeur' />\n";
312
+
313
+    return $aff_etapes;
314 314
 }
315 315
 
316 316
 
317 317
 // https://code.spip.net/@fieldset
318 318
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
319
-	return "<fieldset>\n" .
320
-	$avant .
321
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
-	fieldset_champs($champs) .
323
-	$apres .
324
-	"</fieldset>\n";
319
+    return "<fieldset>\n" .
320
+    $avant .
321
+    ($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
+    fieldset_champs($champs) .
323
+    $apres .
324
+    "</fieldset>\n";
325 325
 }
326 326
 
327 327
 function fieldset_champs($champs = []) {
328
-	$fieldset = '';
329
-	foreach ($champs as $nom => $contenu) {
330
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
-		if (isset($contenu['alternatives'])) {
333
-			$fieldset .= $contenu['label'] . "\n";
334
-			foreach ($contenu['alternatives'] as $valeur => $label) {
335
-				$fieldset .= "<input type='radio' name='" . $nom .
336
-					"' id='$nom-$valeur' value='$valeur'"
337
-					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
-					. "/>\n";
339
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
-			}
341
-			$fieldset .= "<br />\n";
342
-		} else {
343
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
-				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
-				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
-				. " />\n";
348
-		}
349
-	}
350
-
351
-	return $fieldset;
328
+    $fieldset = '';
329
+    foreach ($champs as $nom => $contenu) {
330
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
+        if (isset($contenu['alternatives'])) {
333
+            $fieldset .= $contenu['label'] . "\n";
334
+            foreach ($contenu['alternatives'] as $valeur => $label) {
335
+                $fieldset .= "<input type='radio' name='" . $nom .
336
+                    "' id='$nom-$valeur' value='$valeur'"
337
+                    . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
+                    . "/>\n";
339
+                $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
+            }
341
+            $fieldset .= "<br />\n";
342
+        } else {
343
+            $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
+            $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
+                . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
+                . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
+                . " />\n";
348
+        }
349
+    }
350
+
351
+    return $fieldset;
352 352
 }
353 353
 
354 354
 function install_select_serveur() {
355
-	$options = [];
356
-	$dir = _DIR_RESTREINT . 'req/';
357
-	$d = opendir($dir);
358
-	if (!$d) {
359
-		return [];
360
-	}
361
-	while (($f = readdir($d)) !== false) {
362
-		if (
363
-			(preg_match('/^(.*)[.]php$/', $f, $s))
364
-			and is_readable($f = $dir . $f)
365
-		) {
366
-			require_once($f);
367
-			$s = $s[1];
368
-			$v = 'spip_versions_' . $s;
369
-			if (function_exists($v) and $v()) {
370
-				$titre = _T("install_select_type_$s");
371
-				// proposer mysql par defaut si dispo
372
-				$checked = ($s == 'mysql' ? " checked='checked'" : '');
373
-				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
-					. "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
-			} else {
376
-				spip_log("$s: portage indisponible");
377
-			}
378
-		}
379
-	}
380
-	sort($options);
381
-
382
-	return $options;
355
+    $options = [];
356
+    $dir = _DIR_RESTREINT . 'req/';
357
+    $d = opendir($dir);
358
+    if (!$d) {
359
+        return [];
360
+    }
361
+    while (($f = readdir($d)) !== false) {
362
+        if (
363
+            (preg_match('/^(.*)[.]php$/', $f, $s))
364
+            and is_readable($f = $dir . $f)
365
+        ) {
366
+            require_once($f);
367
+            $s = $s[1];
368
+            $v = 'spip_versions_' . $s;
369
+            if (function_exists($v) and $v()) {
370
+                $titre = _T("install_select_type_$s");
371
+                // proposer mysql par defaut si dispo
372
+                $checked = ($s == 'mysql' ? " checked='checked'" : '');
373
+                $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
+                    . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
+            } else {
376
+                spip_log("$s: portage indisponible");
377
+            }
378
+        }
379
+    }
380
+    sort($options);
381
+
382
+    return $options;
383 383
 }
384 384
 
385 385
 // https://code.spip.net/@install_connexion_form
386 386
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) {
387
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
388
-
389
-	return generer_form_ecrire('install', (
390
-		"\n<input type='hidden' name='etape' value='$etape' />"
391
-		. $hidden
392
-		. (_request('echec') ?
393
-			('<p><b>' . _T('avis_connexion_echec_1') .
394
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
-			: '')
396
-
397
-		. ($jquery ? http_script('', 'jquery.js') : '')
398
-		. http_script('
387
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
388
+
389
+    return generer_form_ecrire('install', (
390
+        "\n<input type='hidden' name='etape' value='$etape' />"
391
+        . $hidden
392
+        . (_request('echec') ?
393
+            ('<p><b>' . _T('avis_connexion_echec_1') .
394
+                '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
+            : '')
396
+
397
+        . ($jquery ? http_script('', 'jquery.js') : '')
398
+        . http_script('
399 399
 		jQuery(function($) {
400 400
 			$details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur");
401 401
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -428,70 +428,70 @@  discard block
 block discarded – undo
428 428
 			});
429 429
 		});')
430 430
 
431
-		. ($server_db
432
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
-			. (($predef[0])
434
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
-				: '')
436
-			: ('<fieldset><legend>'
437
-				. _T('install_select_type_db')
438
-				. '</legend>'
439
-				. '<p class="explication">'
440
-				. _T('install_types_db_connus')
441
-				// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
-				// . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
-				. '</p>'
444
-				. "\n<div class='p'>\n<ul>\n"
445
-				. join("\n", install_select_serveur())
446
-				. "\n</ul>\n</div></fieldset>")
447
-		)
448
-		. '<div id="install_adresse_base_hebergeur">'
449
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
450
-		. ($predef[1]
451
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
-			: fieldset(
453
-				_T('entree_base_donnee_1'),
454
-				[
455
-					'adresse_db' => [
456
-						'label' => $db[1],
457
-						'valeur' => $db[0]
458
-					],
459
-				]
460
-			)
461
-		)
462
-		. '</div>'
463
-
464
-		. '<div id="install_login_base_hebergeur">'
465
-		. ($predef[2]
466
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
-			: fieldset(
468
-				_T('entree_login_connexion_1'),
469
-				[
470
-					'login_db' => [
471
-						'label' => $login[1],
472
-						'valeur' => $login[0]
473
-					],
474
-				]
475
-			)
476
-		)
477
-		. '</div>'
478
-
479
-		. '<div id="install_pass_base_hebergeur">'
480
-		. ($predef[3]
481
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
-			: fieldset(
483
-				_T('entree_mot_passe_1'),
484
-				[
485
-					'pass_db' => [
486
-						'label' => $pass[1],
487
-						'valeur' => $pass[0]
488
-					],
489
-				]
490
-			)
491
-		)
492
-		. '</div>'
493
-
494
-		. bouton_suivant()));
431
+        . ($server_db
432
+            ? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
+            . (($predef[0])
434
+                ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
+                : '')
436
+            : ('<fieldset><legend>'
437
+                . _T('install_select_type_db')
438
+                . '</legend>'
439
+                . '<p class="explication">'
440
+                . _T('install_types_db_connus')
441
+                // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
+                // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
+                . '</p>'
444
+                . "\n<div class='p'>\n<ul>\n"
445
+                . join("\n", install_select_serveur())
446
+                . "\n</ul>\n</div></fieldset>")
447
+        )
448
+        . '<div id="install_adresse_base_hebergeur">'
449
+        . '<p>' . _T('texte_connexion_mysql') . '</p>'
450
+        . ($predef[1]
451
+            ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
+            : fieldset(
453
+                _T('entree_base_donnee_1'),
454
+                [
455
+                    'adresse_db' => [
456
+                        'label' => $db[1],
457
+                        'valeur' => $db[0]
458
+                    ],
459
+                ]
460
+            )
461
+        )
462
+        . '</div>'
463
+
464
+        . '<div id="install_login_base_hebergeur">'
465
+        . ($predef[2]
466
+            ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
+            : fieldset(
468
+                _T('entree_login_connexion_1'),
469
+                [
470
+                    'login_db' => [
471
+                        'label' => $login[1],
472
+                        'valeur' => $login[0]
473
+                    ],
474
+                ]
475
+            )
476
+        )
477
+        . '</div>'
478
+
479
+        . '<div id="install_pass_base_hebergeur">'
480
+        . ($predef[3]
481
+            ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
+            : fieldset(
483
+                _T('entree_mot_passe_1'),
484
+                [
485
+                    'pass_db' => [
486
+                        'label' => $pass[1],
487
+                        'valeur' => $pass[0]
488
+                    ],
489
+                ]
490
+            )
491
+        )
492
+        . '</div>'
493
+
494
+        . bouton_suivant()));
495 495
 }
496 496
 
497 497
 // 4 valeurs qu'on reconduit d'un script a l'autre
@@ -499,76 +499,76 @@  discard block
 block discarded – undo
499 499
 
500 500
 // https://code.spip.net/@predef_ou_cache
501 501
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
502
-	return ((defined('_INSTALL_HOST_DB'))
503
-		? ''
504
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
-	)
506
-	. ((defined('_INSTALL_USER_DB'))
507
-		? ''
508
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
-	)
510
-	. ((defined('_INSTALL_PASS_DB'))
511
-		? ''
512
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
-	)
514
-
515
-	. ((defined('_INSTALL_SERVER_DB'))
516
-		? ''
517
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
-	);
502
+    return ((defined('_INSTALL_HOST_DB'))
503
+        ? ''
504
+        : "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
+    )
506
+    . ((defined('_INSTALL_USER_DB'))
507
+        ? ''
508
+        : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
+    )
510
+    . ((defined('_INSTALL_PASS_DB'))
511
+        ? ''
512
+        : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
+    )
514
+
515
+    . ((defined('_INSTALL_SERVER_DB'))
516
+        ? ''
517
+        : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
+    );
519 519
 }
520 520
 
521 521
 // presentation des bases existantes
522 522
 
523 523
 // https://code.spip.net/@install_etape_liste_bases
524 524
 function install_etape_liste_bases($server_db, $login_db, $disabled = []) {
525
-	$bases = $checked = [];
526
-	$noms = sql_listdbs($server_db);
527
-	if (!$noms) {
528
-		return '';
529
-	}
530
-
531
-	foreach ($noms as $nom) {
532
-		$id = spip_htmlspecialchars($nom);
533
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
-		$base = ' name="choix_db" value="'
535
-			. $nom
536
-			. '"'
537
-			. $dis
538
-			. " type='radio' id='$id'";
539
-		$label = "<label for='$id'>"
540
-			. ($dis ? "<i>$nom</i>" : $nom)
541
-			. '</label>';
542
-
543
-		if (
544
-			!$checked and !$dis and
545
-			(($nom == $login_db) or
546
-				($GLOBALS['table_prefix'] == $nom))
547
-		) {
548
-			$checked = "<input$base checked='checked' />\n$label";
549
-		} else {
550
-			$bases[] = "<input$base />\n$label";
551
-		}
552
-	}
553
-
554
-	if (!$bases && !$checked) {
555
-		return false;
556
-	}
557
-
558
-	if ($checked) {
559
-		array_unshift($bases, $checked);
560
-		$checked = true;
561
-	}
562
-
563
-	return [$checked, $bases];
525
+    $bases = $checked = [];
526
+    $noms = sql_listdbs($server_db);
527
+    if (!$noms) {
528
+        return '';
529
+    }
530
+
531
+    foreach ($noms as $nom) {
532
+        $id = spip_htmlspecialchars($nom);
533
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
+        $base = ' name="choix_db" value="'
535
+            . $nom
536
+            . '"'
537
+            . $dis
538
+            . " type='radio' id='$id'";
539
+        $label = "<label for='$id'>"
540
+            . ($dis ? "<i>$nom</i>" : $nom)
541
+            . '</label>';
542
+
543
+        if (
544
+            !$checked and !$dis and
545
+            (($nom == $login_db) or
546
+                ($GLOBALS['table_prefix'] == $nom))
547
+        ) {
548
+            $checked = "<input$base checked='checked' />\n$label";
549
+        } else {
550
+            $bases[] = "<input$base />\n$label";
551
+        }
552
+    }
553
+
554
+    if (!$bases && !$checked) {
555
+        return false;
556
+    }
557
+
558
+    if ($checked) {
559
+        array_unshift($bases, $checked);
560
+        $checked = true;
561
+    }
562
+
563
+    return [$checked, $bases];
564 564
 }
565 565
 
566 566
 function install_propager($hidden) {
567
-	$res = '';
568
-	foreach ($hidden as $k) {
569
-		$v = spip_htmlentities(_request($k));
570
-		$res .= "<input type='hidden' name='$k' value='$v' />";
571
-	}
567
+    $res = '';
568
+    foreach ($hidden as $k) {
569
+        $v = spip_htmlentities(_request($k));
570
+        $res .= "<input type='hidden' name='$k' value='$v' />";
571
+    }
572 572
 
573
-	return $res;
573
+    return $res;
574 574
 }
Please login to merge, or discard this patch.
ecrire/inc/icone_renommer.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -11,71 +11,71 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/boutons');
18 18
 include_spip('base/objets');
19 19
 
20 20
 function inc_icone_renommer_dist($fond, $fonction) {
21
-	$size = 24;
22
-	if (
23
-		preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
-		and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
-	) {
26
-		if (isset($match[1]) and $match[1]) {
27
-			$size = $match[1];
28
-		}
29
-		$type = substr($fond, 0, -strlen($match[0]));
30
-		if (!isset($match[2]) or !$match[2]) {
31
-			$fond .= '.png';
32
-		}
33
-	} else {
34
-		$type = $fond;
35
-		$fond .= '.png';
36
-	}
21
+    $size = 24;
22
+    if (
23
+        preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
+        and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
+    ) {
26
+        if (isset($match[1]) and $match[1]) {
27
+            $size = $match[1];
28
+        }
29
+        $type = substr($fond, 0, -strlen($match[0]));
30
+        if (!isset($match[2]) or !$match[2]) {
31
+            $fond .= '.png';
32
+        }
33
+    } else {
34
+        $type = $fond;
35
+        $fond .= '.png';
36
+    }
37 37
 
38
-	$rtl = false;
39
-	if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
-		$rtl = true;
41
-		$type = substr($type, 0, -strlen($match[0]));
42
-	}
38
+    $rtl = false;
39
+    if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
+        $rtl = true;
41
+        $type = substr($type, 0, -strlen($match[0]));
42
+    }
43 43
 
44
-	// objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
-	// et ne finit pas par un s, sauf si c'est une exception declaree
46
-	$type = objet_type($type, false);
44
+    // objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
+    // et ne finit pas par un s, sauf si c'est une exception declaree
46
+    $type = objet_type($type, false);
47 47
 
48
-	$dir = 'images/';
49
-	$f = "$type-$size.png";
50
-	if ($icone = find_in_theme($dir . $f)) {
51
-		$dir = dirname($icone);
52
-		$fond = $icone;
48
+    $dir = 'images/';
49
+    $f = "$type-$size.png";
50
+    if ($icone = find_in_theme($dir . $f)) {
51
+        $dir = dirname($icone);
52
+        $fond = $icone;
53 53
 
54
-		if (
55
-			$rtl
56
-			and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
-			and file_exists($fr)
58
-		) {
59
-			$fond = $fr;
60
-		}
54
+        if (
55
+            $rtl
56
+            and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
+            and file_exists($fr)
58
+        ) {
59
+            $fond = $fr;
60
+        }
61 61
 
62
-		$action = $fonction;
63
-		if ($action == 'supprimer.gif') {
64
-			$action = 'del';
65
-		} elseif ($action == 'creer.gif') {
66
-			$action = 'new';
67
-		} elseif ($action == 'edit.gif') {
68
-			$action = 'edit';
69
-		}
62
+        $action = $fonction;
63
+        if ($action == 'supprimer.gif') {
64
+            $action = 'del';
65
+        } elseif ($action == 'creer.gif') {
66
+            $action = 'new';
67
+        } elseif ($action == 'edit.gif') {
68
+            $action = 'edit';
69
+        }
70 70
 
71
-		$fonction = '';
72
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
-			$fonction = $action;
74
-		}
71
+        $fonction = '';
72
+        if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
+            $fonction = $action;
74
+        }
75 75
 
76
-		// c'est bon !
77
-		return [$fond, $fonction];
78
-	}
76
+        // c'est bon !
77
+        return [$fond, $fonction];
78
+    }
79 79
 
80
-	return [$fond, $fonction];
80
+    return [$fond, $fonction];
81 81
 }
Please login to merge, or discard this patch.
ecrire/inc/presenter_enfants.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/autoriser');
@@ -30,80 +30,80 @@  discard block
 block discarded – undo
30 30
  *  Un tableau des sous rubriques
31 31
  */
32 32
 function enfant_rub($collection, $debut = 0, $limite = 500) {
33
-	$voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non');
34
-	$logo = '';
35
-
36
-	if ($voir_logo) {
37
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
38
-		include_spip('inc/filtres_images_mini');
39
-	}
40
-
41
-	$res = [];
42
-
43
-	$result = sql_select(
44
-		'id_rubrique, id_parent, titre, descriptif, lang',
45
-		'spip_rubriques',
46
-		'id_parent=' . intval($collection),
47
-		'',
48
-		'0+titre,titre',
49
-		"$debut,$limite"
50
-	);
51
-	while ($row = sql_fetch($result)) {
52
-		$id_rubrique = $row['id_rubrique'];
53
-		$id_parent = $row['id_parent'];
54
-		// pour etre sur de passer par tous les traitements
55
-		$titre = generer_info_entite($id_rubrique, 'rubrique', 'titre');
56
-		if ('' !== ($rang = recuperer_numero($row['titre']))) {
57
-			$rang = "<span class='rang'>$rang.</span> ";
58
-		}
59
-
60
-		if (autoriser('voir', 'rubrique', $id_rubrique)) {
61
-			$les_sous_enfants = sous_enfant_rub($id_rubrique);
62
-
63
-			changer_typo($row['lang']);
64
-			$lang_dir = lang_dir($row['lang']);
65
-			$descriptif = propre($row['descriptif']);
66
-
67
-			if ($voir_logo) {
68
-				if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) {
69
-					list($fid, $dir, $nom, $format) = $logo;
70
-					$logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
71
-					if ($logo) {
72
-						$logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
73
-					}
74
-				}
75
-			}
76
-
77
-			$lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' :
78
-					http_img_pack(
79
-						'auteur-0minirezo-16.png',
80
-						'',
81
-						" width='16' height='16'",
82
-						_T('image_administrer_rubrique')
83
-					)) .
84
-				" <a class='titremlien' dir='$lang_dir'" .
85
-				($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
86
-				" href='" .
87
-				generer_url_entite($id_rubrique, 'rubrique') .
88
-				"'><span class='titre'>" .
89
-				$rang . $titre
90
-				. '</span>'
91
-				. (is_string($logo) ? $logo : '')
92
-				. '</a>';
93
-
94
-			$titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
95
-				. (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>")
96
-				;
97
-
98
-			$res[] =
99
-				debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
100
-				$les_sous_enfants .
101
-				fin_cadre_sous_rub(true);
102
-		}
103
-	}
104
-
105
-	changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
106
-	return $res;
33
+    $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non');
34
+    $logo = '';
35
+
36
+    if ($voir_logo) {
37
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
38
+        include_spip('inc/filtres_images_mini');
39
+    }
40
+
41
+    $res = [];
42
+
43
+    $result = sql_select(
44
+        'id_rubrique, id_parent, titre, descriptif, lang',
45
+        'spip_rubriques',
46
+        'id_parent=' . intval($collection),
47
+        '',
48
+        '0+titre,titre',
49
+        "$debut,$limite"
50
+    );
51
+    while ($row = sql_fetch($result)) {
52
+        $id_rubrique = $row['id_rubrique'];
53
+        $id_parent = $row['id_parent'];
54
+        // pour etre sur de passer par tous les traitements
55
+        $titre = generer_info_entite($id_rubrique, 'rubrique', 'titre');
56
+        if ('' !== ($rang = recuperer_numero($row['titre']))) {
57
+            $rang = "<span class='rang'>$rang.</span> ";
58
+        }
59
+
60
+        if (autoriser('voir', 'rubrique', $id_rubrique)) {
61
+            $les_sous_enfants = sous_enfant_rub($id_rubrique);
62
+
63
+            changer_typo($row['lang']);
64
+            $lang_dir = lang_dir($row['lang']);
65
+            $descriptif = propre($row['descriptif']);
66
+
67
+            if ($voir_logo) {
68
+                if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) {
69
+                    list($fid, $dir, $nom, $format) = $logo;
70
+                    $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
71
+                    if ($logo) {
72
+                        $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
73
+                    }
74
+                }
75
+            }
76
+
77
+            $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' :
78
+                    http_img_pack(
79
+                        'auteur-0minirezo-16.png',
80
+                        '',
81
+                        " width='16' height='16'",
82
+                        _T('image_administrer_rubrique')
83
+                    )) .
84
+                " <a class='titremlien' dir='$lang_dir'" .
85
+                ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
86
+                " href='" .
87
+                generer_url_entite($id_rubrique, 'rubrique') .
88
+                "'><span class='titre'>" .
89
+                $rang . $titre
90
+                . '</span>'
91
+                . (is_string($logo) ? $logo : '')
92
+                . '</a>';
93
+
94
+            $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
95
+                . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>")
96
+                ;
97
+
98
+            $res[] =
99
+                debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
100
+                $les_sous_enfants .
101
+                fin_cadre_sous_rub(true);
102
+        }
103
+    }
104
+
105
+    changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
106
+    return $res;
107 107
 }
108 108
 
109 109
 /**
@@ -116,71 +116,71 @@  discard block
 block discarded – undo
116 116
  *  Le contenu du bloc dépliable
117 117
  */
118 118
 function sous_enfant_rub($collection2) {
119
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2));
120
-
121
-	$retour = '';
122
-	$pagination = '';
123
-	$debut = 0;
124
-	$limite = 500;
125
-
126
-	/**
127
-	 * On ne va afficher que 500 résultats max
128
-	 * Si > 500 on affiche une pagination
129
-	 */
130
-	if ($nb > $limite) {
131
-		$debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut;
132
-		$pagination = chercher_filtre('pagination');
133
-		$pagination = '<p class="pagination">' . $pagination(
134
-			$nb,
135
-			'_rubrique' . $collection2,
136
-			$debut,
137
-			$limite,
138
-			true,
139
-			'prive'
140
-		) . '</p>';
141
-		$limite = $debut + $limite;
142
-	}
143
-
144
-	$result = sql_select(
145
-		'id_rubrique, id_parent, titre, lang',
146
-		'spip_rubriques',
147
-		'id_parent=' . intval($collection2),
148
-		'',
149
-		'0+titre,titre',
150
-		"$debut,$limite"
151
-	);
152
-
153
-	while ($row = sql_fetch($result)) {
154
-		$id_rubrique2 = $row['id_rubrique'];
155
-		$titre2 = generer_info_entite(
156
-			$id_rubrique2,
157
-			'rubrique',
158
-			'titre'
159
-		); // pour etre sur de passer par tous les traitements
160
-		if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
161
-			$rang2 = "<span class='rang'>$rang2.</span> ";
162
-		}
163
-
164
-		changer_typo($row['lang']);
165
-		$lang_dir = lang_dir($row['lang']);
166
-		if (autoriser('voir', 'rubrique', $id_rubrique2)) {
167
-			$retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite(
168
-				$id_rubrique2,
169
-				'rubrique'
170
-			) . "'>" . $rang2 . $titre2 . "</a></li>\n";
171
-		}
172
-	}
173
-
174
-	$retour = $pagination . $retour . $pagination;
175
-
176
-	if (!$retour) {
177
-		return '';
178
-	}
179
-
180
-	return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2")
181
-	. "\n<ul class='liste-items sous-sous-rub'>\n"
182
-	. $retour
183
-	. "</ul>\n" . fin_block() . "\n\n";
119
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2));
120
+
121
+    $retour = '';
122
+    $pagination = '';
123
+    $debut = 0;
124
+    $limite = 500;
125
+
126
+    /**
127
+     * On ne va afficher que 500 résultats max
128
+     * Si > 500 on affiche une pagination
129
+     */
130
+    if ($nb > $limite) {
131
+        $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut;
132
+        $pagination = chercher_filtre('pagination');
133
+        $pagination = '<p class="pagination">' . $pagination(
134
+            $nb,
135
+            '_rubrique' . $collection2,
136
+            $debut,
137
+            $limite,
138
+            true,
139
+            'prive'
140
+        ) . '</p>';
141
+        $limite = $debut + $limite;
142
+    }
143
+
144
+    $result = sql_select(
145
+        'id_rubrique, id_parent, titre, lang',
146
+        'spip_rubriques',
147
+        'id_parent=' . intval($collection2),
148
+        '',
149
+        '0+titre,titre',
150
+        "$debut,$limite"
151
+    );
152
+
153
+    while ($row = sql_fetch($result)) {
154
+        $id_rubrique2 = $row['id_rubrique'];
155
+        $titre2 = generer_info_entite(
156
+            $id_rubrique2,
157
+            'rubrique',
158
+            'titre'
159
+        ); // pour etre sur de passer par tous les traitements
160
+        if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
161
+            $rang2 = "<span class='rang'>$rang2.</span> ";
162
+        }
163
+
164
+        changer_typo($row['lang']);
165
+        $lang_dir = lang_dir($row['lang']);
166
+        if (autoriser('voir', 'rubrique', $id_rubrique2)) {
167
+            $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite(
168
+                $id_rubrique2,
169
+                'rubrique'
170
+            ) . "'>" . $rang2 . $titre2 . "</a></li>\n";
171
+        }
172
+    }
173
+
174
+    $retour = $pagination . $retour . $pagination;
175
+
176
+    if (!$retour) {
177
+        return '';
178
+    }
179
+
180
+    return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2")
181
+    . "\n<ul class='liste-items sous-sous-rub'>\n"
182
+    . $retour
183
+    . "</ul>\n" . fin_block() . "\n\n";
184 184
 }
185 185
 
186 186
 /**
@@ -195,44 +195,44 @@  discard block
 block discarded – undo
195 195
  *  Le contenu textuel affiché, la liste des sous rubriques
196 196
  */
197 197
 function afficher_enfant_rub($id_rubrique = 0) {
198
-	$pagination = '';
199
-	$debut = 0;
200
-	$limite = 500;
201
-
202
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique));
203
-
204
-	if ($nb > $limite) {
205
-		$debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut;
206
-		$pagination = chercher_filtre('pagination');
207
-		$pagination = '<br class="nettoyeur"><p class="pagination">' .
208
-			$pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
209
-		'</p>';
210
-	}
211
-
212
-	$les_enfants = enfant_rub($id_rubrique, $debut, $limite);
213
-
214
-	if (!$n = count($les_enfants)) {
215
-		return '';
216
-	}
217
-
218
-	if ($n == 1) {
219
-		$les_enfants = reset($les_enfants);
220
-		$les_enfants2 = '';
221
-	} else {
222
-		$n = ceil($n / 2);
223
-		$les_enfants2 = implode('', array_slice($les_enfants, $n));
224
-		$les_enfants = implode('', array_slice($les_enfants, 0, $n));
225
-	}
226
-
227
-	$res =
228
-		$pagination
229
-		. "<div class='gauche'>"
230
-		. $les_enfants
231
-		. '</div>'
232
-		. "<div class='droite'>"
233
-		. $les_enfants2
234
-		. '</div>'
235
-		. $pagination;
236
-
237
-	return $res;
198
+    $pagination = '';
199
+    $debut = 0;
200
+    $limite = 500;
201
+
202
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique));
203
+
204
+    if ($nb > $limite) {
205
+        $debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut;
206
+        $pagination = chercher_filtre('pagination');
207
+        $pagination = '<br class="nettoyeur"><p class="pagination">' .
208
+            $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
209
+        '</p>';
210
+    }
211
+
212
+    $les_enfants = enfant_rub($id_rubrique, $debut, $limite);
213
+
214
+    if (!$n = count($les_enfants)) {
215
+        return '';
216
+    }
217
+
218
+    if ($n == 1) {
219
+        $les_enfants = reset($les_enfants);
220
+        $les_enfants2 = '';
221
+    } else {
222
+        $n = ceil($n / 2);
223
+        $les_enfants2 = implode('', array_slice($les_enfants, $n));
224
+        $les_enfants = implode('', array_slice($les_enfants, 0, $n));
225
+    }
226
+
227
+    $res =
228
+        $pagination
229
+        . "<div class='gauche'>"
230
+        . $les_enfants
231
+        . '</div>'
232
+        . "<div class='droite'>"
233
+        . $les_enfants2
234
+        . '</div>'
235
+        . $pagination;
236
+
237
+    return $res;
238 238
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 1 patch
Indentation   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = [];
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = [];
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = [];
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = [];
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,31 +91,31 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (
100
-			function_exists('mb_internal_encoding')
101
-			and function_exists('mb_detect_order')
102
-			and function_exists('mb_substr')
103
-			and function_exists('mb_strlen')
104
-			and function_exists('mb_strtolower')
105
-			and function_exists('mb_strtoupper')
106
-			and function_exists('mb_encode_mimeheader')
107
-			and function_exists('mb_encode_numericentity')
108
-			and function_exists('mb_decode_numericentity')
109
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
-		) {
111
-			mb_internal_encoding('utf-8');
112
-			$mb = 1;
113
-		} else {
114
-			$mb = -1;
115
-		}
116
-	}
117
-
118
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (
100
+            function_exists('mb_internal_encoding')
101
+            and function_exists('mb_detect_order')
102
+            and function_exists('mb_substr')
103
+            and function_exists('mb_strlen')
104
+            and function_exists('mb_strtolower')
105
+            and function_exists('mb_strtoupper')
106
+            and function_exists('mb_encode_mimeheader')
107
+            and function_exists('mb_encode_numericentity')
108
+            and function_exists('mb_decode_numericentity')
109
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
+        ) {
111
+            mb_internal_encoding('utf-8');
112
+            $mb = 1;
113
+        } else {
114
+            $mb = -1;
115
+        }
116
+    }
117
+
118
+    return ($mb == 1);
119 119
 }
120 120
 
121 121
 /**
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
  *     true si iconv fonctionne correctement
131 131
  **/
132 132
 function test_iconv() {
133
-	static $iconv_ok;
134
-
135
-	if (!$iconv_ok) {
136
-		if (!function_exists('iconv')) {
137
-			$iconv_ok = -1;
138
-		} else {
139
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
-				$iconv_ok = 1;
141
-			} else {
142
-				$iconv_ok = -1;
143
-			}
144
-		}
145
-	}
146
-
147
-	return ($iconv_ok == 1);
133
+    static $iconv_ok;
134
+
135
+    if (!$iconv_ok) {
136
+        if (!function_exists('iconv')) {
137
+            $iconv_ok = -1;
138
+        } else {
139
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
+                $iconv_ok = 1;
141
+            } else {
142
+                $iconv_ok = -1;
143
+            }
144
+        }
145
+    }
146
+
147
+    return ($iconv_ok == 1);
148 148
 }
149 149
 
150 150
 
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
  *     true si PCRE supporte l'UTF-8 correctement
158 158
  **/
159 159
 function test_pcre_unicode() {
160
-	static $pcre_ok = 0;
161
-
162
-	if (!$pcre_ok) {
163
-		$s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
-		if (preg_match(',\W...\W,u', $s)) {
165
-			$pcre_ok = 1;
166
-		} else {
167
-			$pcre_ok = -1;
168
-		}
169
-	}
170
-
171
-	return $pcre_ok == 1;
160
+    static $pcre_ok = 0;
161
+
162
+    if (!$pcre_ok) {
163
+        $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
+        if (preg_match(',\W...\W,u', $s)) {
165
+            $pcre_ok = 1;
166
+        } else {
167
+            $pcre_ok = -1;
168
+        }
169
+    }
170
+
171
+    return $pcre_ok == 1;
172 172
 }
173 173
 
174 174
 /**
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
  *    Plage de caractères
185 185
  **/
186 186
 function pcre_lettres_unicode() {
187
-	static $plage_unicode;
188
-
189
-	if (!$plage_unicode) {
190
-		if (test_pcre_unicode()) {
191
-			// cf. http://www.unicode.org/charts/
192
-			$plage_unicode = '\w' // iso-latin
193
-				. '\x{100}-\x{24f}' // europeen etendu
194
-				. '\x{300}-\x{1cff}' // des tas de trucs
195
-			;
196
-		} else {
197
-			// fallback a trois sous
198
-			$plage_unicode = '\w';
199
-		}
200
-	}
201
-
202
-	return $plage_unicode;
187
+    static $plage_unicode;
188
+
189
+    if (!$plage_unicode) {
190
+        if (test_pcre_unicode()) {
191
+            // cf. http://www.unicode.org/charts/
192
+            $plage_unicode = '\w' // iso-latin
193
+                . '\x{100}-\x{24f}' // europeen etendu
194
+                . '\x{300}-\x{1cff}' // des tas de trucs
195
+            ;
196
+        } else {
197
+            // fallback a trois sous
198
+            $plage_unicode = '\w';
199
+        }
200
+    }
201
+
202
+    return $plage_unicode;
203 203
 }
204 204
 
205 205
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  *    Plage de caractères
218 218
  **/
219 219
 function plage_punct_unicode() {
220
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
221 221
 }
222 222
 
223 223
 /**
@@ -237,75 +237,75 @@  discard block
 block discarded – undo
237 237
  *     Texte corrigé
238 238
  **/
239 239
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
240
-	static $trans;
241
-
242
-	if (is_array($texte)) {
243
-		return array_map('corriger_caracteres_windows', $texte);
244
-	}
245
-
246
-	if ($charset == 'AUTO') {
247
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
248
-	}
249
-	if ($charset == 'utf-8') {
250
-		$p = chr(194);
251
-		if (strpos($texte, $p) == false) {
252
-			return $texte;
253
-		}
254
-	} else {
255
-		if ($charset == 'iso-8859-1') {
256
-			$p = '';
257
-		} else {
258
-			return $texte;
259
-		}
260
-	}
261
-
262
-	if (!isset($trans[$charset][$charset_cible])) {
263
-		$trans[$charset][$charset_cible] = [
264
-			$p . chr(128) => '&#8364;',
265
-			$p . chr(129) => ' ', # pas affecte
266
-			$p . chr(130) => '&#8218;',
267
-			$p . chr(131) => '&#402;',
268
-			$p . chr(132) => '&#8222;',
269
-			$p . chr(133) => '&#8230;',
270
-			$p . chr(134) => '&#8224;',
271
-			$p . chr(135) => '&#8225;',
272
-			$p . chr(136) => '&#710;',
273
-			$p . chr(137) => '&#8240;',
274
-			$p . chr(138) => '&#352;',
275
-			$p . chr(139) => '&#8249;',
276
-			$p . chr(140) => '&#338;',
277
-			$p . chr(141) => ' ', # pas affecte
278
-			$p . chr(142) => '&#381;',
279
-			$p . chr(143) => ' ', # pas affecte
280
-			$p . chr(144) => ' ', # pas affecte
281
-			$p . chr(145) => '&#8216;',
282
-			$p . chr(146) => '&#8217;',
283
-			$p . chr(147) => '&#8220;',
284
-			$p . chr(148) => '&#8221;',
285
-			$p . chr(149) => '&#8226;',
286
-			$p . chr(150) => '&#8211;',
287
-			$p . chr(151) => '&#8212;',
288
-			$p . chr(152) => '&#732;',
289
-			$p . chr(153) => '&#8482;',
290
-			$p . chr(154) => '&#353;',
291
-			$p . chr(155) => '&#8250;',
292
-			$p . chr(156) => '&#339;',
293
-			$p . chr(157) => ' ', # pas affecte
294
-			$p . chr(158) => '&#382;',
295
-			$p . chr(159) => '&#376;',
296
-		];
297
-		if ($charset_cible != 'unicode') {
298
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
-			}
301
-		}
302
-	}
303
-
304
-	return @str_replace(
305
-		array_keys($trans[$charset][$charset_cible]),
306
-		array_values($trans[$charset][$charset_cible]),
307
-		$texte
308
-	);
240
+    static $trans;
241
+
242
+    if (is_array($texte)) {
243
+        return array_map('corriger_caracteres_windows', $texte);
244
+    }
245
+
246
+    if ($charset == 'AUTO') {
247
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
248
+    }
249
+    if ($charset == 'utf-8') {
250
+        $p = chr(194);
251
+        if (strpos($texte, $p) == false) {
252
+            return $texte;
253
+        }
254
+    } else {
255
+        if ($charset == 'iso-8859-1') {
256
+            $p = '';
257
+        } else {
258
+            return $texte;
259
+        }
260
+    }
261
+
262
+    if (!isset($trans[$charset][$charset_cible])) {
263
+        $trans[$charset][$charset_cible] = [
264
+            $p . chr(128) => '&#8364;',
265
+            $p . chr(129) => ' ', # pas affecte
266
+            $p . chr(130) => '&#8218;',
267
+            $p . chr(131) => '&#402;',
268
+            $p . chr(132) => '&#8222;',
269
+            $p . chr(133) => '&#8230;',
270
+            $p . chr(134) => '&#8224;',
271
+            $p . chr(135) => '&#8225;',
272
+            $p . chr(136) => '&#710;',
273
+            $p . chr(137) => '&#8240;',
274
+            $p . chr(138) => '&#352;',
275
+            $p . chr(139) => '&#8249;',
276
+            $p . chr(140) => '&#338;',
277
+            $p . chr(141) => ' ', # pas affecte
278
+            $p . chr(142) => '&#381;',
279
+            $p . chr(143) => ' ', # pas affecte
280
+            $p . chr(144) => ' ', # pas affecte
281
+            $p . chr(145) => '&#8216;',
282
+            $p . chr(146) => '&#8217;',
283
+            $p . chr(147) => '&#8220;',
284
+            $p . chr(148) => '&#8221;',
285
+            $p . chr(149) => '&#8226;',
286
+            $p . chr(150) => '&#8211;',
287
+            $p . chr(151) => '&#8212;',
288
+            $p . chr(152) => '&#732;',
289
+            $p . chr(153) => '&#8482;',
290
+            $p . chr(154) => '&#353;',
291
+            $p . chr(155) => '&#8250;',
292
+            $p . chr(156) => '&#339;',
293
+            $p . chr(157) => ' ', # pas affecte
294
+            $p . chr(158) => '&#382;',
295
+            $p . chr(159) => '&#376;',
296
+        ];
297
+        if ($charset_cible != 'unicode') {
298
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
+            }
301
+        }
302
+    }
303
+
304
+    return @str_replace(
305
+        array_keys($trans[$charset][$charset_cible]),
306
+        array_values($trans[$charset][$charset_cible]),
307
+        $texte
308
+    );
309 309
 }
310 310
 
311 311
 
@@ -322,26 +322,26 @@  discard block
 block discarded – undo
322 322
  *     Texte converti
323 323
  **/
324 324
 function html2unicode($texte, $secure = false) {
325
-	if (strpos($texte, '&') === false) {
326
-		return $texte;
327
-	}
328
-	static $trans = [];
329
-	if (!$trans) {
330
-		load_charset('html');
331
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
-			$trans["&$key;"] = $val;
333
-		}
334
-	}
335
-
336
-	if ($secure) {
337
-		return str_replace(array_keys($trans), array_values($trans), $texte);
338
-	} else {
339
-		return str_replace(
340
-			['&amp;', '&quot;', '&lt;', '&gt;'],
341
-			['&', '"', '<', '>'],
342
-			str_replace(array_keys($trans), array_values($trans), $texte)
343
-		);
344
-	}
325
+    if (strpos($texte, '&') === false) {
326
+        return $texte;
327
+    }
328
+    static $trans = [];
329
+    if (!$trans) {
330
+        load_charset('html');
331
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
+            $trans["&$key;"] = $val;
333
+        }
334
+    }
335
+
336
+    if ($secure) {
337
+        return str_replace(array_keys($trans), array_values($trans), $texte);
338
+    } else {
339
+        return str_replace(
340
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
341
+            ['&', '"', '<', '>'],
342
+            str_replace(array_keys($trans), array_values($trans), $texte)
343
+        );
344
+    }
345 345
 }
346 346
 
347 347
 
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
  *     Texte converti
357 357
  **/
358 358
 function mathml2unicode($texte) {
359
-	static $trans;
360
-	if (!$trans) {
361
-		load_charset('mathml');
359
+    static $trans;
360
+    if (!$trans) {
361
+        load_charset('mathml');
362 362
 
363
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
-			$trans["&$key;"] = $val;
365
-		}
366
-	}
363
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
+            $trans["&$key;"] = $val;
365
+        }
366
+    }
367 367
 
368
-	return str_replace(array_keys($trans), array_values($trans), $texte);
368
+    return str_replace(array_keys($trans), array_values($trans), $texte);
369 369
 }
370 370
 
371 371
 
@@ -387,75 +387,75 @@  discard block
 block discarded – undo
387 387
  *     Texte converti en unicode
388 388
  **/
389 389
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
390
-	static $trans;
391
-
392
-	if ($charset == 'AUTO') {
393
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
394
-	}
395
-
396
-	if ($charset == '') {
397
-		$charset = 'iso-8859-1';
398
-	}
399
-	$charset = strtolower($charset);
400
-
401
-	switch ($charset) {
402
-		case 'utf-8':
403
-		case 'utf8':
404
-			return utf_8_to_unicode($texte);
405
-
406
-		case 'iso-8859-1':
407
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
-		// pas de break; ici, on suit sur default:
409
-
410
-		default:
411
-			// mbstring presente ?
412
-			if (init_mb_string()) {
413
-				$order = mb_detect_order();
414
-				try {
415
-					# mb_string connait-il $charset?
416
-					if ($order and mb_detect_order($charset)) {
417
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
418
-						if ($s && $s != $texte) {
419
-							return utf_8_to_unicode($s);
420
-						}
421
-					}
422
-				} catch (\Error $e) {
423
-					// Le charset n'existe probablement pas
424
-				} finally {
425
-					mb_detect_order($order); # remettre comme precedemment
426
-				}
427
-			}
428
-
429
-			// Sinon, peut-etre connaissons-nous ce charset ?
430
-			if (!isset($trans[$charset])) {
431
-				if (
432
-					$cset = load_charset($charset)
433
-					and is_array($GLOBALS['CHARSET'][$cset])
434
-				) {
435
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
437
-					}
438
-				}
439
-			}
440
-			if (isset($trans[$charset]) and count($trans[$charset])) {
441
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
-			}
443
-
444
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
-			// caractere n'appartient pas au charset, mais c'est un probleme
446
-			// surtout en utf-8, gere ci-dessus)
447
-			if (test_iconv()) {
448
-				$s = iconv($charset, 'utf-32le', $texte);
449
-				if ($s) {
450
-					return utf_32_to_unicode($s);
451
-				}
452
-			}
453
-
454
-			// Au pire ne rien faire
455
-			spip_log("erreur charset '$charset' non supporte");
456
-
457
-			return $texte;
458
-	}
390
+    static $trans;
391
+
392
+    if ($charset == 'AUTO') {
393
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
394
+    }
395
+
396
+    if ($charset == '') {
397
+        $charset = 'iso-8859-1';
398
+    }
399
+    $charset = strtolower($charset);
400
+
401
+    switch ($charset) {
402
+        case 'utf-8':
403
+        case 'utf8':
404
+            return utf_8_to_unicode($texte);
405
+
406
+        case 'iso-8859-1':
407
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
+        // pas de break; ici, on suit sur default:
409
+
410
+        default:
411
+            // mbstring presente ?
412
+            if (init_mb_string()) {
413
+                $order = mb_detect_order();
414
+                try {
415
+                    # mb_string connait-il $charset?
416
+                    if ($order and mb_detect_order($charset)) {
417
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
418
+                        if ($s && $s != $texte) {
419
+                            return utf_8_to_unicode($s);
420
+                        }
421
+                    }
422
+                } catch (\Error $e) {
423
+                    // Le charset n'existe probablement pas
424
+                } finally {
425
+                    mb_detect_order($order); # remettre comme precedemment
426
+                }
427
+            }
428
+
429
+            // Sinon, peut-etre connaissons-nous ce charset ?
430
+            if (!isset($trans[$charset])) {
431
+                if (
432
+                    $cset = load_charset($charset)
433
+                    and is_array($GLOBALS['CHARSET'][$cset])
434
+                ) {
435
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
437
+                    }
438
+                }
439
+            }
440
+            if (isset($trans[$charset]) and count($trans[$charset])) {
441
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
+            }
443
+
444
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
+            // caractere n'appartient pas au charset, mais c'est un probleme
446
+            // surtout en utf-8, gere ci-dessus)
447
+            if (test_iconv()) {
448
+                $s = iconv($charset, 'utf-32le', $texte);
449
+                if ($s) {
450
+                    return utf_32_to_unicode($s);
451
+                }
452
+            }
453
+
454
+            // Au pire ne rien faire
455
+            spip_log("erreur charset '$charset' non supporte");
456
+
457
+            return $texte;
458
+    }
459 459
 }
460 460
 
461 461
 
@@ -474,44 +474,44 @@  discard block
 block discarded – undo
474 474
  *     Texte transformé dans le charset souhaité
475 475
  **/
476 476
 function unicode2charset($texte, $charset = 'AUTO') {
477
-	static $CHARSET_REVERSE = [];
478
-	static $trans = [];
479
-
480
-	if ($charset == 'AUTO') {
481
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
482
-	}
483
-
484
-	switch ($charset) {
485
-		case 'utf-8':
486
-			return unicode_to_utf_8($texte);
487
-			break;
488
-
489
-		default:
490
-			$charset = load_charset($charset);
491
-
492
-			if (empty($CHARSET_REVERSE[$charset])) {
493
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
-			}
495
-
496
-			if (!isset($trans[$charset])) {
497
-				$trans[$charset] = [];
498
-				$t = &$trans[$charset];
499
-				for ($e = 128; $e < 255; $e++) {
500
-					$h = dechex($e);
501
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
-						$s = $CHARSET_REVERSE[$charset][$e];
503
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
-					} else {
506
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
-					}
509
-				}
510
-			}
511
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
-
513
-			return $texte;
514
-	}
477
+    static $CHARSET_REVERSE = [];
478
+    static $trans = [];
479
+
480
+    if ($charset == 'AUTO') {
481
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
482
+    }
483
+
484
+    switch ($charset) {
485
+        case 'utf-8':
486
+            return unicode_to_utf_8($texte);
487
+            break;
488
+
489
+        default:
490
+            $charset = load_charset($charset);
491
+
492
+            if (empty($CHARSET_REVERSE[$charset])) {
493
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
+            }
495
+
496
+            if (!isset($trans[$charset])) {
497
+                $trans[$charset] = [];
498
+                $t = &$trans[$charset];
499
+                for ($e = 128; $e < 255; $e++) {
500
+                    $h = dechex($e);
501
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
+                        $s = $CHARSET_REVERSE[$charset][$e];
503
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
+                    } else {
506
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
+                    }
509
+                }
510
+            }
511
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
+
513
+            return $texte;
514
+    }
515 515
 }
516 516
 
517 517
 
@@ -529,39 +529,39 @@  discard block
 block discarded – undo
529 529
  *     Texte transformé dans le charset site
530 530
  **/
531 531
 function importer_charset($texte, $charset = 'AUTO') {
532
-	static $trans = [];
533
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
-		if (init_mb_string()) {
537
-			if (
538
-				$order = mb_detect_order() # mb_string connait-il $charset?
539
-				and mb_detect_order($charset)
540
-			) {
541
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
542
-			}
543
-			mb_detect_order($order); # remettre comme precedemment
544
-			return $s;
545
-		}
546
-		// Sinon, peut-etre connaissons-nous ce charset ?
547
-		if (!isset($trans[$charset])) {
548
-			if (
549
-				$cset = load_charset($charset)
550
-				and is_array($GLOBALS['CHARSET'][$cset])
551
-			) {
552
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
-				}
555
-			}
556
-		}
557
-		if (count($trans[$charset])) {
558
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
-		}
560
-
561
-		return $texte;
562
-	}
563
-
564
-	return unicode2charset(charset2unicode($texte, $charset));
532
+    static $trans = [];
533
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
+        if (init_mb_string()) {
537
+            if (
538
+                $order = mb_detect_order() # mb_string connait-il $charset?
539
+                and mb_detect_order($charset)
540
+            ) {
541
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
542
+            }
543
+            mb_detect_order($order); # remettre comme precedemment
544
+            return $s;
545
+        }
546
+        // Sinon, peut-etre connaissons-nous ce charset ?
547
+        if (!isset($trans[$charset])) {
548
+            if (
549
+                $cset = load_charset($charset)
550
+                and is_array($GLOBALS['CHARSET'][$cset])
551
+            ) {
552
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
+                }
555
+            }
556
+        }
557
+        if (count($trans[$charset])) {
558
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
+        }
560
+
561
+        return $texte;
562
+    }
563
+
564
+    return unicode2charset(charset2unicode($texte, $charset));
565 565
 }
566 566
 
567 567
 
@@ -577,92 +577,92 @@  discard block
 block discarded – undo
577 577
  **/
578 578
 function utf_8_to_unicode($source) {
579 579
 
580
-	// mb_string : methode rapide
581
-	if (init_mb_string()) {
582
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
-
584
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
-	}
586
-
587
-	// Sinon methode pas a pas
588
-	static $decrement;
589
-	static $shift;
590
-
591
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
-	if (!is_array($decrement)) {
593
-		// array used to figure what number to decrement from character order value
594
-		// according to number of characters used to map unicode to ascii by utf-8
595
-		$decrement[4] = 240;
596
-		$decrement[3] = 224;
597
-		$decrement[2] = 192;
598
-		$decrement[1] = 0;
599
-		// the number of bits to shift each charNum by
600
-		$shift[1][0] = 0;
601
-		$shift[2][0] = 6;
602
-		$shift[2][1] = 0;
603
-		$shift[3][0] = 12;
604
-		$shift[3][1] = 6;
605
-		$shift[3][2] = 0;
606
-		$shift[4][0] = 18;
607
-		$shift[4][1] = 12;
608
-		$shift[4][2] = 6;
609
-		$shift[4][3] = 0;
610
-	}
611
-
612
-	$pos = 0;
613
-	$len = strlen($source);
614
-	$encodedString = '';
615
-	while ($pos < $len) {
616
-		$char = '';
617
-		$ischar = false;
618
-		$asciiPos = ord(substr($source, $pos, 1));
619
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
-			// 4 chars representing one unicode character
621
-			$thisLetter = substr($source, $pos, 4);
622
-			$pos += 4;
623
-		} else {
624
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
-				// 3 chars representing one unicode character
626
-				$thisLetter = substr($source, $pos, 3);
627
-				$pos += 3;
628
-			} else {
629
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
-					// 2 chars representing one unicode character
631
-					$thisLetter = substr($source, $pos, 2);
632
-					$pos += 2;
633
-				} else {
634
-					// 1 char (lower ascii)
635
-					$thisLetter = substr($source, $pos, 1);
636
-					$pos += 1;
637
-					$char = $thisLetter;
638
-					$ischar = true;
639
-				}
640
-			}
641
-		}
642
-
643
-		if ($ischar) {
644
-			$encodedString .= $char;
645
-		} else {  // process the string representing the letter to a unicode entity
646
-			$thisLen = strlen($thisLetter);
647
-			$thisPos = 0;
648
-			$decimalCode = 0;
649
-			while ($thisPos < $thisLen) {
650
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
-				if ($thisPos == 0) {
652
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
-				} else {
655
-					$charNum = intval($thisCharOrd - 128);
656
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
-				}
658
-				$thisPos++;
659
-			}
660
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
-			$encodedString .= $encodedLetter;
662
-		}
663
-	}
664
-
665
-	return $encodedString;
580
+    // mb_string : methode rapide
581
+    if (init_mb_string()) {
582
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
+
584
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
+    }
586
+
587
+    // Sinon methode pas a pas
588
+    static $decrement;
589
+    static $shift;
590
+
591
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
+    if (!is_array($decrement)) {
593
+        // array used to figure what number to decrement from character order value
594
+        // according to number of characters used to map unicode to ascii by utf-8
595
+        $decrement[4] = 240;
596
+        $decrement[3] = 224;
597
+        $decrement[2] = 192;
598
+        $decrement[1] = 0;
599
+        // the number of bits to shift each charNum by
600
+        $shift[1][0] = 0;
601
+        $shift[2][0] = 6;
602
+        $shift[2][1] = 0;
603
+        $shift[3][0] = 12;
604
+        $shift[3][1] = 6;
605
+        $shift[3][2] = 0;
606
+        $shift[4][0] = 18;
607
+        $shift[4][1] = 12;
608
+        $shift[4][2] = 6;
609
+        $shift[4][3] = 0;
610
+    }
611
+
612
+    $pos = 0;
613
+    $len = strlen($source);
614
+    $encodedString = '';
615
+    while ($pos < $len) {
616
+        $char = '';
617
+        $ischar = false;
618
+        $asciiPos = ord(substr($source, $pos, 1));
619
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
+            // 4 chars representing one unicode character
621
+            $thisLetter = substr($source, $pos, 4);
622
+            $pos += 4;
623
+        } else {
624
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
+                // 3 chars representing one unicode character
626
+                $thisLetter = substr($source, $pos, 3);
627
+                $pos += 3;
628
+            } else {
629
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
+                    // 2 chars representing one unicode character
631
+                    $thisLetter = substr($source, $pos, 2);
632
+                    $pos += 2;
633
+                } else {
634
+                    // 1 char (lower ascii)
635
+                    $thisLetter = substr($source, $pos, 1);
636
+                    $pos += 1;
637
+                    $char = $thisLetter;
638
+                    $ischar = true;
639
+                }
640
+            }
641
+        }
642
+
643
+        if ($ischar) {
644
+            $encodedString .= $char;
645
+        } else {  // process the string representing the letter to a unicode entity
646
+            $thisLen = strlen($thisLetter);
647
+            $thisPos = 0;
648
+            $decimalCode = 0;
649
+            while ($thisPos < $thisLen) {
650
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
+                if ($thisPos == 0) {
652
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
+                } else {
655
+                    $charNum = intval($thisCharOrd - 128);
656
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
+                }
658
+                $thisPos++;
659
+            }
660
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
+            $encodedString .= $encodedLetter;
662
+        }
663
+    }
664
+
665
+    return $encodedString;
666 666
 }
667 667
 
668 668
 /**
@@ -681,32 +681,32 @@  discard block
 block discarded – undo
681 681
  **/
682 682
 function utf_32_to_unicode($source) {
683 683
 
684
-	// mb_string : methode rapide
685
-	if (init_mb_string()) {
686
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
-
689
-		return str_replace(chr(0), '', $source);
690
-	}
691
-
692
-	// Sinon methode lente
693
-	$texte = '';
694
-	while ($source) {
695
-		$words = unpack('V*', substr($source, 0, 1024));
696
-		$source = substr($source, 1024);
697
-		foreach ($words as $word) {
698
-			if ($word < 128) {
699
-				$texte .= chr($word);
700
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
-			else {
702
-				if ($word != 65279) {
703
-					$texte .= '&#' . $word . ';';
704
-				}
705
-			}
706
-		}
707
-	}
708
-
709
-	return $texte;
684
+    // mb_string : methode rapide
685
+    if (init_mb_string()) {
686
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
+
689
+        return str_replace(chr(0), '', $source);
690
+    }
691
+
692
+    // Sinon methode lente
693
+    $texte = '';
694
+    while ($source) {
695
+        $words = unpack('V*', substr($source, 0, 1024));
696
+        $source = substr($source, 1024);
697
+        foreach ($words as $word) {
698
+            if ($word < 128) {
699
+                $texte .= chr($word);
700
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
+            else {
702
+                if ($word != 65279) {
703
+                    $texte .= '&#' . $word . ';';
704
+                }
705
+            }
706
+        }
707
+    }
708
+
709
+    return $texte;
710 710
 }
711 711
 
712 712
 
@@ -723,21 +723,21 @@  discard block
 block discarded – undo
723 723
  *    Caractère utf8 si trouvé, '' sinon
724 724
  **/
725 725
 function caractere_utf_8($num) {
726
-	$num = intval($num);
727
-	if ($num < 128) {
728
-		return chr($num);
729
-	}
730
-	if ($num < 2048) {
731
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
-	}
733
-	if ($num < 65536) {
734
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
-	}
736
-	if ($num < 1114112) {
737
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
-	}
739
-
740
-	return '';
726
+    $num = intval($num);
727
+    if ($num < 128) {
728
+        return chr($num);
729
+    }
730
+    if ($num < 2048) {
731
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
+    }
733
+    if ($num < 65536) {
734
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
+    }
736
+    if ($num < 1114112) {
737
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
+    }
739
+
740
+    return '';
741 741
 }
742 742
 
743 743
 /**
@@ -750,42 +750,42 @@  discard block
 block discarded – undo
750 750
  **/
751 751
 function unicode_to_utf_8($texte) {
752 752
 
753
-	// 1. Entites &#128; et suivantes
754
-	$vu = [];
755
-	if (
756
-		preg_match_all(
757
-			',&#0*([1-9][0-9][0-9]+);,S',
758
-			$texte,
759
-			$regs,
760
-			PREG_SET_ORDER
761
-		)
762
-	) {
763
-		foreach ($regs as $reg) {
764
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
766
-			}
767
-		}
768
-	}
769
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
-
771
-	// 2. Entites > &#xFF;
772
-	//$vu = array();
773
-	if (
774
-		preg_match_all(
775
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
-			$texte,
777
-			$regs,
778
-			PREG_SET_ORDER
779
-		)
780
-	) {
781
-		foreach ($regs as $reg) {
782
-			if (!isset($vu[$reg[0]])) {
783
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
-			}
785
-		}
786
-	}
787
-
788
-	return str_replace(array_keys($vu), array_values($vu), $texte);
753
+    // 1. Entites &#128; et suivantes
754
+    $vu = [];
755
+    if (
756
+        preg_match_all(
757
+            ',&#0*([1-9][0-9][0-9]+);,S',
758
+            $texte,
759
+            $regs,
760
+            PREG_SET_ORDER
761
+        )
762
+    ) {
763
+        foreach ($regs as $reg) {
764
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
766
+            }
767
+        }
768
+    }
769
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
+
771
+    // 2. Entites > &#xFF;
772
+    //$vu = array();
773
+    if (
774
+        preg_match_all(
775
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
+            $texte,
777
+            $regs,
778
+            PREG_SET_ORDER
779
+        )
780
+    ) {
781
+        foreach ($regs as $reg) {
782
+            if (!isset($vu[$reg[0]])) {
783
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
+            }
785
+        }
786
+    }
787
+
788
+    return str_replace(array_keys($vu), array_values($vu), $texte);
789 789
 }
790 790
 
791 791
 /**
@@ -797,15 +797,15 @@  discard block
 block discarded – undo
797 797
  *     Texte converti
798 798
  **/
799 799
 function unicode_to_javascript($texte) {
800
-	$vu = [];
801
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
-		$num = $regs[1];
803
-		$vu[$num] = true;
804
-		$s = '\u' . sprintf('%04x', $num);
805
-		$texte = str_replace($regs[0], $s, $texte);
806
-	}
807
-
808
-	return $texte;
800
+    $vu = [];
801
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
+        $num = $regs[1];
803
+        $vu[$num] = true;
804
+        $s = '\u' . sprintf('%04x', $num);
805
+        $texte = str_replace($regs[0], $s, $texte);
806
+    }
807
+
808
+    return $texte;
809 809
 }
810 810
 
811 811
 /**
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
  *     Texte converti
818 818
  **/
819 819
 function javascript_to_unicode($texte) {
820
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
-	}
820
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
+    }
823 823
 
824
-	return $texte;
824
+    return $texte;
825 825
 }
826 826
 
827 827
 /**
@@ -833,11 +833,11 @@  discard block
 block discarded – undo
833 833
  *     Texte converti
834 834
  **/
835 835
 function javascript_to_binary($texte) {
836
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
-	}
836
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
+    }
839 839
 
840
-	return $texte;
840
+    return $texte;
841 841
 }
842 842
 
843 843
 
@@ -855,26 +855,26 @@  discard block
 block discarded – undo
855 855
  * @return string
856 856
  */
857 857
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
858
-	static $trans = [];
859
-	if ($charset == 'AUTO') {
860
-		$charset = $GLOBALS['meta']['charset'];
861
-	}
862
-	if (!strlen($texte)) {
863
-		return $texte;
864
-	}
865
-
866
-	$table_translit = 'translit' . $complexe;
867
-
868
-	// 2. Translitterer grace a la table predefinie
869
-	if (!isset($trans[$complexe])) {
870
-		$trans[$complexe] = [];
871
-		load_charset($table_translit);
872
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
-			$trans[$complexe][caractere_utf_8($key)] = $val;
874
-		}
875
-	}
876
-
877
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
858
+    static $trans = [];
859
+    if ($charset == 'AUTO') {
860
+        $charset = $GLOBALS['meta']['charset'];
861
+    }
862
+    if (!strlen($texte)) {
863
+        return $texte;
864
+    }
865
+
866
+    $table_translit = 'translit' . $complexe;
867
+
868
+    // 2. Translitterer grace a la table predefinie
869
+    if (!isset($trans[$complexe])) {
870
+        $trans[$complexe] = [];
871
+        load_charset($table_translit);
872
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
+            $trans[$complexe][caractere_utf_8($key)] = $val;
874
+        }
875
+    }
876
+
877
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
878 878
 }
879 879
 
880 880
 /**
@@ -897,14 +897,14 @@  discard block
 block discarded – undo
897 897
  * @return string
898 898
  */
899 899
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
900
-	// 0. Supprimer les caracteres illegaux
901
-	include_spip('inc/filtres');
902
-	$texte = corriger_caracteres($texte);
900
+    // 0. Supprimer les caracteres illegaux
901
+    include_spip('inc/filtres');
902
+    $texte = corriger_caracteres($texte);
903 903
 
904
-	// 1. Passer le charset et les &eacute en utf-8
905
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
904
+    // 1. Passer le charset et les &eacute en utf-8
905
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
906 906
 
907
-	return translitteration_rapide($texte, $charset, $complexe);
907
+    return translitteration_rapide($texte, $charset, $complexe);
908 908
 }
909 909
 
910 910
 /**
@@ -919,19 +919,19 @@  discard block
 block discarded – undo
919 919
  * @return string
920 920
  */
921 921
 function translitteration_complexe($texte, $chiffres = false) {
922
-	$texte = translitteration($texte, 'AUTO', 'complexe');
923
-
924
-	if ($chiffres) {
925
-		$texte = preg_replace_callback(
926
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
-			function ($m) {
928
-			return translitteration_chiffree($m[0]);
929
-			},
930
-			$texte
931
-		);
932
-	}
933
-
934
-	return $texte;
922
+    $texte = translitteration($texte, 'AUTO', 'complexe');
923
+
924
+    if ($chiffres) {
925
+        $texte = preg_replace_callback(
926
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
+            function ($m) {
928
+            return translitteration_chiffree($m[0]);
929
+            },
930
+            $texte
931
+        );
932
+    }
933
+
934
+    return $texte;
935 935
 }
936 936
 
937 937
 /**
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
  * @return string
944 944
  */
945 945
 function translitteration_chiffree($car) {
946
-	return strtr($car, "'`?~.^+(-", '123456789');
946
+    return strtr($car, "'`?~.^+(-", '123456789');
947 947
 }
948 948
 
949 949
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *    true s'il a un BOM
957 957
  **/
958 958
 function bom_utf8($texte) {
959
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
959
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
960 960
 }
961 961
 
962 962
 /**
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
  *     true si c'est le cas
974 974
  **/
975 975
 function is_utf8($string) {
976
-	return !strlen(
977
-		preg_replace(
978
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
-			. ',sS',
987
-			'',
988
-			$string
989
-		)
990
-	);
976
+    return !strlen(
977
+        preg_replace(
978
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
+            . ',sS',
987
+            '',
988
+            $string
989
+        )
990
+    );
991 991
 }
992 992
 
993 993
 /**
@@ -999,13 +999,13 @@  discard block
 block discarded – undo
999 999
  *     true si c'est le cas
1000 1000
  **/
1001 1001
 function is_ascii($string) {
1002
-	return !strlen(
1003
-		preg_replace(
1004
-			',[\x09\x0A\x0D\x20-\x7E],sS',
1005
-			'',
1006
-			$string
1007
-		)
1008
-	);
1002
+    return !strlen(
1003
+        preg_replace(
1004
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
1005
+            '',
1006
+            $string
1007
+        )
1008
+    );
1009 1009
 }
1010 1010
 
1011 1011
 /**
@@ -1024,53 +1024,53 @@  discard block
 block discarded – undo
1024 1024
  **/
1025 1025
 function transcoder_page($texte, $headers = '') {
1026 1026
 
1027
-	// Si tout est < 128 pas la peine d'aller plus loin
1028
-	if (is_ascii($texte)) {
1029
-		#spip_log('charset: ascii');
1030
-		return $texte;
1031
-	}
1032
-
1033
-	if (bom_utf8($texte)) {
1034
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
-		$charset = 'utf-8';
1036
-		$texte = substr($texte, 3);
1037
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
-		// charset precise par le contenu (xml)
1039
-		$charset = trim(strtolower($regs[1]));
1040
-	} elseif (
1041
-		// charset precise par le contenu (html)
1042
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
-		and false === strpos($regs[2], '#')
1045
-		and $tmp = trim(strtolower($regs[2]))
1046
-	) {
1047
-		$charset = $tmp;
1048
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
-		// charset de la reponse http
1050
-		$charset = trim(strtolower($regs[1]));
1051
-	} else {
1052
-		$charset = '';
1053
-	}
1054
-
1055
-
1056
-	// normaliser les noms du shif-jis japonais
1057
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
-		$charset = 'shift-jis';
1059
-	}
1060
-
1061
-	if ($charset) {
1062
-		spip_log("charset: $charset");
1063
-	} else {
1064
-		// valeur par defaut
1065
-		if (is_utf8($texte)) {
1066
-			$charset = 'utf-8';
1067
-		} else {
1068
-			$charset = 'iso-8859-1';
1069
-		}
1070
-		spip_log("charset probable: $charset");
1071
-	}
1072
-
1073
-	return importer_charset($texte, $charset);
1027
+    // Si tout est < 128 pas la peine d'aller plus loin
1028
+    if (is_ascii($texte)) {
1029
+        #spip_log('charset: ascii');
1030
+        return $texte;
1031
+    }
1032
+
1033
+    if (bom_utf8($texte)) {
1034
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
+        $charset = 'utf-8';
1036
+        $texte = substr($texte, 3);
1037
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
+        // charset precise par le contenu (xml)
1039
+        $charset = trim(strtolower($regs[1]));
1040
+    } elseif (
1041
+        // charset precise par le contenu (html)
1042
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
+        and false === strpos($regs[2], '#')
1045
+        and $tmp = trim(strtolower($regs[2]))
1046
+    ) {
1047
+        $charset = $tmp;
1048
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
+        // charset de la reponse http
1050
+        $charset = trim(strtolower($regs[1]));
1051
+    } else {
1052
+        $charset = '';
1053
+    }
1054
+
1055
+
1056
+    // normaliser les noms du shif-jis japonais
1057
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
+        $charset = 'shift-jis';
1059
+    }
1060
+
1061
+    if ($charset) {
1062
+        spip_log("charset: $charset");
1063
+    } else {
1064
+        // valeur par defaut
1065
+        if (is_utf8($texte)) {
1066
+            $charset = 'utf-8';
1067
+        } else {
1068
+            $charset = 'iso-8859-1';
1069
+        }
1070
+        spip_log("charset probable: $charset");
1071
+    }
1072
+
1073
+    return importer_charset($texte, $charset);
1074 1074
 }
1075 1075
 
1076 1076
 
@@ -1094,26 +1094,26 @@  discard block
 block discarded – undo
1094 1094
  *     Le texte coupé
1095 1095
  **/
1096 1096
 function spip_substr($c, $start = 0, $length = null) {
1097
-	// Si ce n'est pas utf-8, utiliser substr
1098
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
-		if ($length) {
1100
-			return substr($c, $start, $length);
1101
-		} else {
1102
-			substr($c, $start);
1103
-		}
1104
-	}
1105
-
1106
-	// Si utf-8, voir si on dispose de mb_string
1107
-	if (init_mb_string()) {
1108
-		if ($length) {
1109
-			return mb_substr($c, $start, $length);
1110
-		} else {
1111
-			return mb_substr($c, $start);
1112
-		}
1113
-	}
1114
-
1115
-	// Version manuelle (cf. ci-dessous)
1116
-	return spip_substr_manuelle($c, $start, $length);
1097
+    // Si ce n'est pas utf-8, utiliser substr
1098
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
+        if ($length) {
1100
+            return substr($c, $start, $length);
1101
+        } else {
1102
+            substr($c, $start);
1103
+        }
1104
+    }
1105
+
1106
+    // Si utf-8, voir si on dispose de mb_string
1107
+    if (init_mb_string()) {
1108
+        if ($length) {
1109
+            return mb_substr($c, $start, $length);
1110
+        } else {
1111
+            return mb_substr($c, $start);
1112
+        }
1113
+    }
1114
+
1115
+    // Version manuelle (cf. ci-dessous)
1116
+    return spip_substr_manuelle($c, $start, $length);
1117 1117
 }
1118 1118
 
1119 1119
 
@@ -1132,40 +1132,40 @@  discard block
 block discarded – undo
1132 1132
  **/
1133 1133
 function spip_substr_manuelle($c, $start, $length = null) {
1134 1134
 
1135
-	// Cas pathologique
1136
-	if ($length === 0) {
1137
-		return '';
1138
-	}
1139
-
1140
-	// S'il y a un demarrage, on se positionne
1141
-	if ($start > 0) {
1142
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
-	} elseif ($start < 0) {
1144
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
-	}
1146
-
1147
-	if (!$length) {
1148
-		return $c;
1149
-	}
1150
-
1151
-	if ($length > 0) {
1152
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
-		// (un caractere utf-8 prenant au maximum n bytes)
1154
-		$n = 0;
1155
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
-			;
1157
-		}
1158
-		$c = substr($c, 0, $n * $length);
1159
-		// puis, tant qu'on est trop long, on coupe...
1160
-		while (($l = spip_strlen($c)) > $length) {
1161
-			$c = substr($c, 0, $length - $l);
1162
-		}
1163
-
1164
-		return $c;
1165
-	}
1166
-
1167
-	// $length < 0
1168
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1135
+    // Cas pathologique
1136
+    if ($length === 0) {
1137
+        return '';
1138
+    }
1139
+
1140
+    // S'il y a un demarrage, on se positionne
1141
+    if ($start > 0) {
1142
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
+    } elseif ($start < 0) {
1144
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
+    }
1146
+
1147
+    if (!$length) {
1148
+        return $c;
1149
+    }
1150
+
1151
+    if ($length > 0) {
1152
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
+        // (un caractere utf-8 prenant au maximum n bytes)
1154
+        $n = 0;
1155
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
+            ;
1157
+        }
1158
+        $c = substr($c, 0, $n * $length);
1159
+        // puis, tant qu'on est trop long, on coupe...
1160
+        while (($l = spip_strlen($c)) > $length) {
1161
+            $c = substr($c, 0, $length - $l);
1162
+        }
1163
+
1164
+        return $c;
1165
+    }
1166
+
1167
+    // $length < 0
1168
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1169 1169
 }
1170 1170
 
1171 1171
 /**
@@ -1179,14 +1179,14 @@  discard block
 block discarded – undo
1179 1179
  *     La chaîne avec une majuscule sur le premier mot
1180 1180
  */
1181 1181
 function spip_ucfirst($c) {
1182
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
-		return ucfirst($c);
1185
-	}
1182
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
+        return ucfirst($c);
1185
+    }
1186 1186
 
1187
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1187
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1188 1188
 
1189
-	return $lettre1 . spip_substr($c, 1);
1189
+    return $lettre1 . spip_substr($c, 1);
1190 1190
 }
1191 1191
 
1192 1192
 /**
@@ -1200,12 +1200,12 @@  discard block
 block discarded – undo
1200 1200
  *     La chaîne en minuscules
1201 1201
  */
1202 1202
 function spip_strtolower($c) {
1203
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
-		return strtolower($c);
1206
-	}
1203
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
+        return strtolower($c);
1206
+    }
1207 1207
 
1208
-	return mb_strtolower($c);
1208
+    return mb_strtolower($c);
1209 1209
 }
1210 1210
 
1211 1211
 /**
@@ -1219,23 +1219,23 @@  discard block
 block discarded – undo
1219 1219
  *     Longueur de la chaîne
1220 1220
  */
1221 1221
 function spip_strlen($c) {
1222
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1223
-	$c = str_replace("\r\n", "\n", $c);
1224
-
1225
-	// Si ce n'est pas utf-8, utiliser strlen
1226
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
-		return strlen($c);
1228
-	}
1229
-
1230
-	// Sinon, utiliser mb_strlen() si disponible
1231
-	if (init_mb_string()) {
1232
-		return mb_strlen($c);
1233
-	}
1234
-
1235
-	// Methode manuelle : on supprime les bytes 10......,
1236
-	// on compte donc les ascii (0.......) et les demarrages
1237
-	// de caracteres utf-8 (11......)
1238
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1222
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1223
+    $c = str_replace("\r\n", "\n", $c);
1224
+
1225
+    // Si ce n'est pas utf-8, utiliser strlen
1226
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
+        return strlen($c);
1228
+    }
1229
+
1230
+    // Sinon, utiliser mb_strlen() si disponible
1231
+    if (init_mb_string()) {
1232
+        return mb_strlen($c);
1233
+    }
1234
+
1235
+    // Methode manuelle : on supprime les bytes 10......,
1236
+    // on compte donc les ascii (0.......) et les demarrages
1237
+    // de caracteres utf-8 (11......)
1238
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1239 1239
 }
1240 1240
 
1241 1241
 // Initialisation
@@ -1245,16 +1245,16 @@  discard block
 block discarded – undo
1245 1245
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1246 1246
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1247 1247
 if (
1248
-	!isset($GLOBALS['meta']['pcre_u'])
1249
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1248
+    !isset($GLOBALS['meta']['pcre_u'])
1249
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1250 1250
 ) {
1251
-	include_spip('inc/meta');
1252
-	ecrire_meta(
1253
-		'pcre_u',
1254
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
-			and test_pcre_unicode())
1256
-			? 'u' : ''
1257
-	);
1251
+    include_spip('inc/meta');
1252
+    ecrire_meta(
1253
+        'pcre_u',
1254
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
+            and test_pcre_unicode())
1256
+            ? 'u' : ''
1257
+    );
1258 1258
 }
1259 1259
 
1260 1260
 
@@ -1270,17 +1270,17 @@  discard block
 block discarded – undo
1270 1270
  *     en unicode : &#128169;
1271 1271
  */
1272 1272
 function utf8_noplanes($x) {
1273
-	$regexp_utf8_4bytes = '/(
1273
+    $regexp_utf8_4bytes = '/(
1274 1274
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1275 1275
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1276 1276
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1277 1277
 )/xS';
1278
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
-		foreach ($z[0] as $k) {
1280
-			$ku = utf_8_to_unicode($k);
1281
-			$x = str_replace($k, $ku, $x);
1282
-		}
1283
-	}
1284
-
1285
-	return $x;
1278
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
+        foreach ($z[0] as $k) {
1280
+            $ku = utf_8_to_unicode($k);
1281
+            $x = str_replace($k, $ku, $x);
1282
+        }
1283
+    }
1284
+
1285
+    return $x;
1286 1286
 }
Please login to merge, or discard this patch.