Completed
Push — spip-3.0 ( 484b62...e817f1 )
by cam
34:33
created
ecrire/inc/admin.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -177,6 +177,9 @@
 block discarded – undo
177 177
 }
178 178
 
179 179
 // http://doc.spip.org/@copy_request
180
+/**
181
+ * @param string $suite
182
+ */
180 183
 function copy_request($script, $suite, $submit='')
181 184
 {
182 185
 	include_spip('inc/filtres');
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -19,22 +19,22 @@  discard block
 block discarded – undo
19 19
 // http://doc.spip.org/@inc_admin_dist
20 20
 function inc_admin_dist($script, $titre, $comment='', $anonymous=false)
21 21
 {
22
-	$reprise = true;
23
-	if (!isset($GLOBALS['meta'][$script])
24
-	OR  !isset($GLOBALS['meta']['admin'])) {
25
-		$reprise = false;
26
-		$res = debut_admin($script, $titre, $comment); 
27
-		if ($res) return $res;
28
-		spip_log("meta: $script " . join(',', $_POST));
29
-		ecrire_meta($script, serialize($_POST));
30
-	} 
31
-
32
-	$res = admin_verifie_session($script,$anonymous);
33
-	if ($res) return $res;
34
-	$base = charger_fonction($script, 'base');
35
-	$base($titre,$reprise);
36
-	fin_admin($script);
37
-	return '';
22
+    $reprise = true;
23
+    if (!isset($GLOBALS['meta'][$script])
24
+    OR  !isset($GLOBALS['meta']['admin'])) {
25
+        $reprise = false;
26
+        $res = debut_admin($script, $titre, $comment); 
27
+        if ($res) return $res;
28
+        spip_log("meta: $script " . join(',', $_POST));
29
+        ecrire_meta($script, serialize($_POST));
30
+    } 
31
+
32
+    $res = admin_verifie_session($script,$anonymous);
33
+    if ($res) return $res;
34
+    $base = charger_fonction($script, 'base');
35
+    $base($titre,$reprise);
36
+    fin_admin($script);
37
+    return '';
38 38
 }
39 39
 
40 40
 // Gestion dans la meta "admin" du script d'administation demande,
@@ -55,46 +55,46 @@  discard block
 block discarded – undo
55 55
 // http://doc.spip.org/@admin_verifie_session
56 56
 function admin_verifie_session($script, $anonymous=false) {
57 57
 
58
-	include_spip('base/abstract_sql');
59
-	$pref = sprintf("_%d_",$GLOBALS['visiteur_session']['id_auteur']);
60
-	$signal = fichier_admin($script, "$script$pref");
61
-	$valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
62
-	if ($valeur === NULL) {
63
-		ecrire_meta('admin', $signal, 'non');
64
-	} else {
65
-		if (!$anonymous AND ($valeur != $signal)) {
66
-			if (!preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)
67
-				OR intval($l[2])!=$GLOBALS['visiteur_session']['id_auteur']) {
68
-				include_spip('inc/minipres');
69
-				spip_log("refus de lancer $script, priorite a $valeur");
70
-				return minipres(_T('info_travaux_texte'));
71
-			}
72
-		}
73
-	}
74
-	$journal = "spip";
75
-	if (autoriser('configurer')) // c'est une action webmestre, soit par ftp soit par statut webmestre
76
-		$journal = 'webmestre';
77
-	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
78
-
79
-	spip_log("admin $pref" . ($valeur ? " (reprise)" : ' (init)'),$journal);
80
-	return '';
58
+    include_spip('base/abstract_sql');
59
+    $pref = sprintf("_%d_",$GLOBALS['visiteur_session']['id_auteur']);
60
+    $signal = fichier_admin($script, "$script$pref");
61
+    $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
62
+    if ($valeur === NULL) {
63
+        ecrire_meta('admin', $signal, 'non');
64
+    } else {
65
+        if (!$anonymous AND ($valeur != $signal)) {
66
+            if (!preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)
67
+                OR intval($l[2])!=$GLOBALS['visiteur_session']['id_auteur']) {
68
+                include_spip('inc/minipres');
69
+                spip_log("refus de lancer $script, priorite a $valeur");
70
+                return minipres(_T('info_travaux_texte'));
71
+            }
72
+        }
73
+    }
74
+    $journal = "spip";
75
+    if (autoriser('configurer')) // c'est une action webmestre, soit par ftp soit par statut webmestre
76
+        $journal = 'webmestre';
77
+    // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
78
+
79
+    spip_log("admin $pref" . ($valeur ? " (reprise)" : ' (init)'),$journal);
80
+    return '';
81 81
 }
82 82
 
83 83
 // http://doc.spip.org/@dir_admin
84 84
 function dir_admin()
85 85
 {
86
-	if (autoriser('configurer')) {
87
-		return _DIR_TMP;
88
-	} else {
89
-		return  _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
90
-	}
86
+    if (autoriser('configurer')) {
87
+        return _DIR_TMP;
88
+    } else {
89
+        return  _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
90
+    }
91 91
 }
92 92
 
93 93
 // http://doc.spip.org/@fichier_admin
94 94
 function fichier_admin($action, $pref='admin_') {
95 95
 
96
-	return $pref . 
97
-	  substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10);
96
+    return $pref . 
97
+        substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10);
98 98
 }
99 99
 
100 100
 // demande la creation d'un repertoire et sort
@@ -103,89 +103,89 @@  discard block
 block discarded – undo
103 103
 // http://doc.spip.org/@debut_admin
104 104
 function debut_admin($script, $action='', $corps='') {
105 105
 
106
-	if ((!$action) || !(autoriser('webmestre') OR autoriser('chargerftp'))) {
107
-		include_spip('inc/minipres');
108
-		return minipres();
109
-	} else {
110
-		$dir = dir_admin();
111
-		$signal = fichier_admin($script);
112
-		if (@file_exists($dir . $signal)) {
113
-			spip_log ("Action admin: $action");
114
-			return '';
115
-		}
116
-		include_spip('inc/minipres');
117
-
118
-	// Si on est un super-admin, un bouton de validation suffit
119
-	// sauf dans les cas destroy
120
-		if ((autoriser('webmestre') OR $script === 'repair')
121
-		AND $script != 'delete_all') {
122
-			if (_request('validation_admin') == $signal) {
123
-				spip_log ("Action super-admin: $action");
124
-				return '';
125
-			}
126
-			$corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />';
127
-			$suivant = _T('bouton_valider');
128
-			$js = '';
129
-		} else {
130
-			// cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
131
-			// l'insertion du script a cet endroit n'est pas xhtml licite mais evite de l'embarquer dans toutes les pages minipres
132
-			$corps .= http_script('',  "spip_barre.js");
133
-
134
-			$corps .= "<fieldset><legend>"
135
-			. _T('info_authentification_ftp')
136
-			. aide("ftp_auth")
137
-			. "</legend>\n<label for='fichier'>"
138
-			. _T('info_creer_repertoire')
139
-			. "</label>\n"
106
+    if ((!$action) || !(autoriser('webmestre') OR autoriser('chargerftp'))) {
107
+        include_spip('inc/minipres');
108
+        return minipres();
109
+    } else {
110
+        $dir = dir_admin();
111
+        $signal = fichier_admin($script);
112
+        if (@file_exists($dir . $signal)) {
113
+            spip_log ("Action admin: $action");
114
+            return '';
115
+        }
116
+        include_spip('inc/minipres');
117
+
118
+    // Si on est un super-admin, un bouton de validation suffit
119
+    // sauf dans les cas destroy
120
+        if ((autoriser('webmestre') OR $script === 'repair')
121
+        AND $script != 'delete_all') {
122
+            if (_request('validation_admin') == $signal) {
123
+                spip_log ("Action super-admin: $action");
124
+                return '';
125
+            }
126
+            $corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />';
127
+            $suivant = _T('bouton_valider');
128
+            $js = '';
129
+        } else {
130
+            // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
131
+            // l'insertion du script a cet endroit n'est pas xhtml licite mais evite de l'embarquer dans toutes les pages minipres
132
+            $corps .= http_script('',  "spip_barre.js");
133
+
134
+            $corps .= "<fieldset><legend>"
135
+            . _T('info_authentification_ftp')
136
+            . aide("ftp_auth")
137
+            . "</legend>\n<label for='fichier'>"
138
+            . _T('info_creer_repertoire')
139
+            . "</label>\n"
140 140
             . "<span id='signal' class='formo'>".$signal."</span>"
141 141
             . "<input type='hidden' id='fichier' name='fichier' value='" 
142
-			. $signal
143
-			. "' />"
144
-			. _T('info_creer_repertoire_2', array('repertoire' => joli_repertoire($dir)))
145
-			. "</fieldset>";
146
-
147
-			$suivant = _T('bouton_recharger_page');
148
-
149
-			// code volontairement tordu:
150
-			// provoquer la copie dans le presse papier du nom du repertoire
151
-			// en remettant a vide le champ pour que ca marche aussi en cas
152
-			// de JavaScript inactif.
153
-			$js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
154
-
155
-		}
156
-
157
-		// admin/xxx correspond
158
-		// a exec/base_xxx de preference
159
-		// et exec/xxx sinon (compat)
160
-		if (tester_url_ecrire("base_$script"))
161
-			$script = "base_$script";
162
-		$form = copy_request($script, $corps, $suivant);
163
-		$info_action = _T('info_action', array('action' => "$action"));
164
-		return minipres($info_action, $form, $js);
165
-	}
142
+            . $signal
143
+            . "' />"
144
+            . _T('info_creer_repertoire_2', array('repertoire' => joli_repertoire($dir)))
145
+            . "</fieldset>";
146
+
147
+            $suivant = _T('bouton_recharger_page');
148
+
149
+            // code volontairement tordu:
150
+            // provoquer la copie dans le presse papier du nom du repertoire
151
+            // en remettant a vide le champ pour que ca marche aussi en cas
152
+            // de JavaScript inactif.
153
+            $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
154
+
155
+        }
156
+
157
+        // admin/xxx correspond
158
+        // a exec/base_xxx de preference
159
+        // et exec/xxx sinon (compat)
160
+        if (tester_url_ecrire("base_$script"))
161
+            $script = "base_$script";
162
+        $form = copy_request($script, $corps, $suivant);
163
+        $info_action = _T('info_action', array('action' => "$action"));
164
+        return minipres($info_action, $form, $js);
165
+    }
166 166
 }
167 167
 
168 168
 // http://doc.spip.org/@fin_admin
169 169
 function fin_admin($action) {
170
-	$signal = dir_admin() . fichier_admin($action);
171
-	spip_unlink($signal);
172
-	if ($action != 'delete_all') {
173
-		effacer_meta($action);
174
-		effacer_meta('admin');
175
-		spip_log("efface les meta admin et $action ");
176
-	}
170
+    $signal = dir_admin() . fichier_admin($action);
171
+    spip_unlink($signal);
172
+    if ($action != 'delete_all') {
173
+        effacer_meta($action);
174
+        effacer_meta('admin');
175
+        spip_log("efface les meta admin et $action ");
176
+    }
177 177
 }
178 178
 
179 179
 // http://doc.spip.org/@copy_request
180 180
 function copy_request($script, $suite, $submit='')
181 181
 {
182
-	include_spip('inc/filtres');
183
-	foreach(array_merge($_POST,$_GET) as $n => $c) {
184
-		if (!in_array($n,array('fichier','exec','validation_admin')) AND !is_array($c))
185
-		$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='" .
186
-			entites_html($c) .
187
-			"'  />";
188
-	}
189
-	return  generer_form_ecrire($script, $suite, '', $submit);
182
+    include_spip('inc/filtres');
183
+    foreach(array_merge($_POST,$_GET) as $n => $c) {
184
+        if (!in_array($n,array('fichier','exec','validation_admin')) AND !is_array($c))
185
+        $suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='" .
186
+            entites_html($c) .
187
+            "'  />";
188
+    }
189
+    return  generer_form_ecrire($script, $suite, '', $submit);
190 190
 }
191 191
 ?>
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 // si elle y est deja c'est qu'il y a eu suspension du script, on reprend.
18 18
 
19 19
 // http://doc.spip.org/@inc_admin_dist
20
-function inc_admin_dist($script, $titre, $comment='', $anonymous=false)
20
+function inc_admin_dist($script, $titre, $comment = '', $anonymous = false)
21 21
 {
22 22
 	$reprise = true;
23 23
 	if (!isset($GLOBALS['meta'][$script])
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
 		$reprise = false;
26 26
 		$res = debut_admin($script, $titre, $comment); 
27 27
 		if ($res) return $res;
28
-		spip_log("meta: $script " . join(',', $_POST));
28
+		spip_log("meta: $script ".join(',', $_POST));
29 29
 		ecrire_meta($script, serialize($_POST));
30 30
 	} 
31 31
 
32
-	$res = admin_verifie_session($script,$anonymous);
32
+	$res = admin_verifie_session($script, $anonymous);
33 33
 	if ($res) return $res;
34 34
 	$base = charger_fonction($script, 'base');
35
-	$base($titre,$reprise);
35
+	$base($titre, $reprise);
36 36
 	fin_admin($script);
37 37
 	return '';
38 38
 }
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 // 	c'est que l'operation se passe mal, on la stoppe
54 54
 
55 55
 // http://doc.spip.org/@admin_verifie_session
56
-function admin_verifie_session($script, $anonymous=false) {
56
+function admin_verifie_session($script, $anonymous = false) {
57 57
 
58 58
 	include_spip('base/abstract_sql');
59
-	$pref = sprintf("_%d_",$GLOBALS['visiteur_session']['id_auteur']);
59
+	$pref = sprintf("_%d_", $GLOBALS['visiteur_session']['id_auteur']);
60 60
 	$signal = fichier_admin($script, "$script$pref");
61 61
 	$valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
62 62
 	if ($valeur === NULL) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	} else {
65 65
 		if (!$anonymous AND ($valeur != $signal)) {
66 66
 			if (!preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)
67
-				OR intval($l[2])!=$GLOBALS['visiteur_session']['id_auteur']) {
67
+				OR intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur']) {
68 68
 				include_spip('inc/minipres');
69 69
 				spip_log("refus de lancer $script, priorite a $valeur");
70 70
 				return minipres(_T('info_travaux_texte'));
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		$journal = 'webmestre';
77 77
 	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
78 78
 
79
-	spip_log("admin $pref" . ($valeur ? " (reprise)" : ' (init)'),$journal);
79
+	spip_log("admin $pref".($valeur ? " (reprise)" : ' (init)'), $journal);
80 80
 	return '';
81 81
 }
82 82
 
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 	if (autoriser('configurer')) {
87 87
 		return _DIR_TMP;
88 88
 	} else {
89
-		return  _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
89
+		return  _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/';
90 90
 	}
91 91
 }
92 92
 
93 93
 // http://doc.spip.org/@fichier_admin
94
-function fichier_admin($action, $pref='admin_') {
94
+function fichier_admin($action, $pref = 'admin_') {
95 95
 
96
-	return $pref . 
96
+	return $pref. 
97 97
 	  substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10);
98 98
 }
99 99
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 // ou retourne sans rien faire si repertoire deja la.
102 102
 
103 103
 // http://doc.spip.org/@debut_admin
104
-function debut_admin($script, $action='', $corps='') {
104
+function debut_admin($script, $action = '', $corps = '') {
105 105
 
106 106
 	if ((!$action) || !(autoriser('webmestre') OR autoriser('chargerftp'))) {
107 107
 		include_spip('inc/minipres');
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	} else {
110 110
 		$dir = dir_admin();
111 111
 		$signal = fichier_admin($script);
112
-		if (@file_exists($dir . $signal)) {
113
-			spip_log ("Action admin: $action");
112
+		if (@file_exists($dir.$signal)) {
113
+			spip_log("Action admin: $action");
114 114
 			return '';
115 115
 		}
116 116
 		include_spip('inc/minipres');
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		if ((autoriser('webmestre') OR $script === 'repair')
121 121
 		AND $script != 'delete_all') {
122 122
 			if (_request('validation_admin') == $signal) {
123
-				spip_log ("Action super-admin: $action");
123
+				spip_log("Action super-admin: $action");
124 124
 				return '';
125 125
 			}
126 126
 			$corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />';
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		} else {
130 130
 			// cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
131 131
 			// l'insertion du script a cet endroit n'est pas xhtml licite mais evite de l'embarquer dans toutes les pages minipres
132
-			$corps .= http_script('',  "spip_barre.js");
132
+			$corps .= http_script('', "spip_barre.js");
133 133
 
134 134
 			$corps .= "<fieldset><legend>"
135 135
 			. _T('info_authentification_ftp')
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 // http://doc.spip.org/@fin_admin
169 169
 function fin_admin($action) {
170
-	$signal = dir_admin() . fichier_admin($action);
170
+	$signal = dir_admin().fichier_admin($action);
171 171
 	spip_unlink($signal);
172 172
 	if ($action != 'delete_all') {
173 173
 		effacer_meta($action);
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
 }
178 178
 
179 179
 // http://doc.spip.org/@copy_request
180
-function copy_request($script, $suite, $submit='')
180
+function copy_request($script, $suite, $submit = '')
181 181
 {
182 182
 	include_spip('inc/filtres');
183
-	foreach(array_merge($_POST,$_GET) as $n => $c) {
184
-		if (!in_array($n,array('fichier','exec','validation_admin')) AND !is_array($c))
185
-		$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='" .
186
-			entites_html($c) .
183
+	foreach (array_merge($_POST, $_GET) as $n => $c) {
184
+		if (!in_array($n, array('fichier', 'exec', 'validation_admin')) AND !is_array($c))
185
+		$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='".
186
+			entites_html($c).
187 187
 			"'  />";
188 188
 	}
189 189
 	return  generer_form_ecrire($script, $suite, '', $submit);
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // demande/verifie le droit de creation de repertoire par le demandeur;
16 18
 // memorise dans les meta que ce script est en cours d'execution
@@ -24,13 +26,17 @@  discard block
 block discarded – undo
24 26
 	OR  !isset($GLOBALS['meta']['admin'])) {
25 27
 		$reprise = false;
26 28
 		$res = debut_admin($script, $titre, $comment); 
27
-		if ($res) return $res;
29
+		if ($res) {
30
+		    return $res;
31
+		}
28 32
 		spip_log("meta: $script " . join(',', $_POST));
29 33
 		ecrire_meta($script, serialize($_POST));
30 34
 	} 
31 35
 
32 36
 	$res = admin_verifie_session($script,$anonymous);
33
-	if ($res) return $res;
37
+	if ($res) {
38
+	    return $res;
39
+	}
34 40
 	$base = charger_fonction($script, 'base');
35 41
 	$base($titre,$reprise);
36 42
 	fin_admin($script);
@@ -72,8 +78,10 @@  discard block
 block discarded – undo
72 78
 		}
73 79
 	}
74 80
 	$journal = "spip";
75
-	if (autoriser('configurer')) // c'est une action webmestre, soit par ftp soit par statut webmestre
81
+	if (autoriser('configurer')) {
82
+	    // c'est une action webmestre, soit par ftp soit par statut webmestre
76 83
 		$journal = 'webmestre';
84
+	}
77 85
 	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
78 86
 
79 87
 	spip_log("admin $pref" . ($valeur ? " (reprise)" : ' (init)'),$journal);
@@ -157,8 +165,9 @@  discard block
 block discarded – undo
157 165
 		// admin/xxx correspond
158 166
 		// a exec/base_xxx de preference
159 167
 		// et exec/xxx sinon (compat)
160
-		if (tester_url_ecrire("base_$script"))
161
-			$script = "base_$script";
168
+		if (tester_url_ecrire("base_$script")) {
169
+					$script = "base_$script";
170
+		}
162 171
 		$form = copy_request($script, $corps, $suivant);
163 172
 		$info_action = _T('info_action', array('action' => "$action"));
164 173
 		return minipres($info_action, $form, $js);
@@ -181,10 +190,11 @@  discard block
 block discarded – undo
181 190
 {
182 191
 	include_spip('inc/filtres');
183 192
 	foreach(array_merge($_POST,$_GET) as $n => $c) {
184
-		if (!in_array($n,array('fichier','exec','validation_admin')) AND !is_array($c))
185
-		$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='" .
193
+		if (!in_array($n,array('fichier','exec','validation_admin')) AND !is_array($c)) {
194
+				$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='" .
186 195
 			entites_html($c) .
187 196
 			"'  />";
197
+		}
188 198
 	}
189 199
 	return  generer_form_ecrire($script, $suite, '', $submit);
190 200
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
  * @param string $charset
34 34
  *     Charset à charger
35 35
  *     Par défaut (AUTO), utilise le charset du site
36
- * @return string|bool
36
+ * @return string|false
37 37
  *     Nom du charset
38 38
  *     false si le charset n'est pas décrit dans le répertoire charsets/
39 39
 **/
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
  * 
645 645
  * @param int $num
646 646
  *    Numéro de l'entité unicode
647
- * @return char
647
+ * @return string
648 648
  *    Caractère utf8 si trouvé, '' sinon
649 649
 **/
650 650
 function caractere_utf_8($num) {
Please login to merge, or discard this patch.
Indentation   +585 added lines, -585 removed lines patch added patch discarded remove patch
@@ -38,30 +38,30 @@  discard block
 block discarded – undo
38 38
  *     false si le charset n'est pas décrit dans le répertoire charsets/
39 39
 **/
40 40
 function load_charset ($charset = 'AUTO') {
41
-	if ($charset == 'AUTO')
42
-		$charset = $GLOBALS['meta']['charset'];
43
-	$charset = trim(strtolower($charset));
44
-	if (isset($GLOBALS['CHARSET'][$charset]))
45
-		return $charset;
46
-
47
-	if ($charset == 'utf-8') {
48
-		$GLOBALS['CHARSET'][$charset] = array();
49
-		return $charset;
50
-	}
41
+    if ($charset == 'AUTO')
42
+        $charset = $GLOBALS['meta']['charset'];
43
+    $charset = trim(strtolower($charset));
44
+    if (isset($GLOBALS['CHARSET'][$charset]))
45
+        return $charset;
46
+
47
+    if ($charset == 'utf-8') {
48
+        $GLOBALS['CHARSET'][$charset] = array();
49
+        return $charset;
50
+    }
51 51
 	
52
-	// Quelques synonymes
53
-	if ($charset == '') $charset = 'iso-8859-1';
54
-	else if ($charset == 'windows-1250') $charset = 'cp1250';
55
-	else if ($charset == 'windows-1251') $charset = 'cp1251';
56
-	else if ($charset == 'windows-1256') $charset = 'cp1256';
57
-
58
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
59
-		return $charset;
60
-	} else {
61
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
62
-		$GLOBALS['CHARSET'][$charset] = array();
63
-		return false;
64
-	}
52
+    // Quelques synonymes
53
+    if ($charset == '') $charset = 'iso-8859-1';
54
+    else if ($charset == 'windows-1250') $charset = 'cp1250';
55
+    else if ($charset == 'windows-1251') $charset = 'cp1251';
56
+    else if ($charset == 'windows-1256') $charset = 'cp1256';
57
+
58
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
59
+        return $charset;
60
+    } else {
61
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
62
+        $GLOBALS['CHARSET'][$charset] = array();
63
+        return false;
64
+    }
65 65
 }
66 66
 
67 67
 
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
  *     true si toutes les fonctions mb nécessaires sont présentes
73 73
 **/
74 74
 function init_mb_string() {
75
-	static $mb;
76
-
77
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
78
-	// et que le charset interne est connu de mb_string
79
-	if (!$mb) {
80
-		if (function_exists('mb_internal_encoding')
81
-		AND function_exists('mb_detect_order')
82
-		AND function_exists('mb_substr')
83
-		AND function_exists('mb_strlen')
84
-		AND function_exists('mb_encode_mimeheader')
85
-		AND function_exists('mb_encode_numericentity')
86
-		AND function_exists('mb_decode_numericentity')
87
-		AND mb_detect_order($GLOBALS['meta']['charset'])
88
-		) {
89
-			mb_internal_encoding('utf-8');
90
-			$mb = 1;
91
-		} else
92
-			$mb = -1;
93
-	}
94
-
95
-	return ($mb == 1);
75
+    static $mb;
76
+
77
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
78
+    // et que le charset interne est connu de mb_string
79
+    if (!$mb) {
80
+        if (function_exists('mb_internal_encoding')
81
+        AND function_exists('mb_detect_order')
82
+        AND function_exists('mb_substr')
83
+        AND function_exists('mb_strlen')
84
+        AND function_exists('mb_encode_mimeheader')
85
+        AND function_exists('mb_encode_numericentity')
86
+        AND function_exists('mb_decode_numericentity')
87
+        AND mb_detect_order($GLOBALS['meta']['charset'])
88
+        ) {
89
+            mb_internal_encoding('utf-8');
90
+            $mb = 1;
91
+        } else
92
+            $mb = -1;
93
+    }
94
+
95
+    return ($mb == 1);
96 96
 }
97 97
 
98 98
 /**
@@ -107,19 +107,19 @@  discard block
 block discarded – undo
107 107
  *     true si iconv fonctionne correctement
108 108
 **/
109 109
 function test_iconv() {
110
-	static $iconv_ok;
111
-
112
-	if (!$iconv_ok) {
113
-		if (!function_exists('iconv'))
114
-			$iconv_ok = -1;
115
-		else {
116
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test')
117
-				$iconv_ok = 1;
118
-			else
119
-				$iconv_ok = -1;
120
-		}
121
-	}
122
-	return ($iconv_ok == 1);
110
+    static $iconv_ok;
111
+
112
+    if (!$iconv_ok) {
113
+        if (!function_exists('iconv'))
114
+            $iconv_ok = -1;
115
+        else {
116
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test')
117
+                $iconv_ok = 1;
118
+            else
119
+                $iconv_ok = -1;
120
+        }
121
+    }
122
+    return ($iconv_ok == 1);
123 123
 }
124 124
 
125 125
 
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
  *     true si PCRE supporte l'UTF-8 correctement
133 133
 **/
134 134
 function test_pcre_unicode() {
135
-	static $pcre_ok = 0;
136
-
137
-	if (!$pcre_ok) {
138
-		$s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
139
-		if (preg_match(',\W...\W,u', $s)) $pcre_ok = 1;
140
-		else $pcre_ok = -1;
141
-	}
142
-	return $pcre_ok == 1;
135
+    static $pcre_ok = 0;
136
+
137
+    if (!$pcre_ok) {
138
+        $s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
139
+        if (preg_match(',\W...\W,u', $s)) $pcre_ok = 1;
140
+        else $pcre_ok = -1;
141
+    }
142
+    return $pcre_ok == 1;
143 143
 }
144 144
 
145 145
 /**
@@ -155,22 +155,22 @@  discard block
 block discarded – undo
155 155
  *    Plage de caractères
156 156
 **/
157 157
 function pcre_lettres_unicode() {
158
-	static $plage_unicode;
159
-
160
-	if (!$plage_unicode) {
161
-		if (test_pcre_unicode()) {
162
-			// cf. http://www.unicode.org/charts/
163
-			$plage_unicode = '\w' // iso-latin
164
-				. '\x{100}-\x{24f}' // europeen etendu
165
-				. '\x{300}-\x{1cff}' // des tas de trucs
166
-			;
167
-		}
168
-		else {
169
-			// fallback a trois sous
170
-			$plage_unicode = '\w';
171
-		}
172
-	}
173
-	return $plage_unicode;
158
+    static $plage_unicode;
159
+
160
+    if (!$plage_unicode) {
161
+        if (test_pcre_unicode()) {
162
+            // cf. http://www.unicode.org/charts/
163
+            $plage_unicode = '\w' // iso-latin
164
+                . '\x{100}-\x{24f}' // europeen etendu
165
+                . '\x{300}-\x{1cff}' // des tas de trucs
166
+            ;
167
+        }
168
+        else {
169
+            // fallback a trois sous
170
+            $plage_unicode = '\w';
171
+        }
172
+    }
173
+    return $plage_unicode;
174 174
 }
175 175
 
176 176
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
  *    Plage de caractères
189 189
 **/
190 190
 function plage_punct_unicode() {
191
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
191
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
192 192
 }
193 193
 
194 194
 /**
@@ -208,65 +208,65 @@  discard block
 block discarded – undo
208 208
  *     Texte corrigé
209 209
 **/
210 210
 function corriger_caracteres_windows($texte, $charset='AUTO', $charset_cible='unicode') {
211
-	static $trans;
211
+    static $trans;
212 212
 	
213
-	if (is_array($texte)) {
214
-		return array_map('corriger_caracteres_windows', $texte);
215
-	}
213
+    if (is_array($texte)) {
214
+        return array_map('corriger_caracteres_windows', $texte);
215
+    }
216 216
 	
217
-	if ($charset=='AUTO') $charset = $GLOBALS['meta']['charset'];
218
-	if ($charset == 'utf-8') {
219
-		$p = chr(194);
220
-		if (strpos($texte,$p)==false)
221
-			return $texte;
222
-	} else if ($charset == 'iso-8859-1') {
223
-		$p = '';
224
-	} else
225
-		return $texte;
226
-
227
-	if (!isset($trans[$charset][$charset_cible])) {
228
-		$trans[$charset][$charset_cible] = array(
229
-			$p.chr(128) => "&#8364;",
230
-			$p.chr(129) => ' ', # pas affecte
231
-			$p.chr(130) => "&#8218;",
232
-			$p.chr(131) => "&#402;",
233
-			$p.chr(132) => "&#8222;",
234
-			$p.chr(133) => "&#8230;",
235
-			$p.chr(134) => "&#8224;",
236
-			$p.chr(135) => "&#8225;",
237
-			$p.chr(136) => "&#710;",
238
-			$p.chr(137) => "&#8240;",
239
-			$p.chr(138) => "&#352;",
240
-			$p.chr(139) => "&#8249;",
241
-			$p.chr(140) => "&#338;",
242
-			$p.chr(141) => ' ', # pas affecte
243
-			$p.chr(142) => "&#381;",
244
-			$p.chr(143) => ' ', # pas affecte
245
-			$p.chr(144) => ' ', # pas affecte
246
-			$p.chr(145) => "&#8216;",
247
-			$p.chr(146) => "&#8217;",
248
-			$p.chr(147) => "&#8220;",
249
-			$p.chr(148) => "&#8221;",
250
-			$p.chr(149) => "&#8226;",
251
-			$p.chr(150) => "&#8211;",
252
-			$p.chr(151) => "&#8212;",
253
-			$p.chr(152) => "&#732;",
254
-			$p.chr(153) => "&#8482;", 
255
-			$p.chr(154) => "&#353;",
256
-			$p.chr(155) => "&#8250;",
257
-			$p.chr(156) => "&#339;",
258
-			$p.chr(157) => ' ', # pas affecte
259
-			$p.chr(158) => "&#382;",
260
-			$p.chr(159) => "&#376;",
261
-		);
262
-		if ($charset_cible!='unicode'){
263
-			foreach($trans[$charset][$charset_cible] as $k=>$c)
264
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
265
-		}
266
-	}
267
-
268
-	return @str_replace(array_keys($trans[$charset][$charset_cible]),
269
-			   array_values($trans[$charset][$charset_cible]),$texte);
217
+    if ($charset=='AUTO') $charset = $GLOBALS['meta']['charset'];
218
+    if ($charset == 'utf-8') {
219
+        $p = chr(194);
220
+        if (strpos($texte,$p)==false)
221
+            return $texte;
222
+    } else if ($charset == 'iso-8859-1') {
223
+        $p = '';
224
+    } else
225
+        return $texte;
226
+
227
+    if (!isset($trans[$charset][$charset_cible])) {
228
+        $trans[$charset][$charset_cible] = array(
229
+            $p.chr(128) => "&#8364;",
230
+            $p.chr(129) => ' ', # pas affecte
231
+            $p.chr(130) => "&#8218;",
232
+            $p.chr(131) => "&#402;",
233
+            $p.chr(132) => "&#8222;",
234
+            $p.chr(133) => "&#8230;",
235
+            $p.chr(134) => "&#8224;",
236
+            $p.chr(135) => "&#8225;",
237
+            $p.chr(136) => "&#710;",
238
+            $p.chr(137) => "&#8240;",
239
+            $p.chr(138) => "&#352;",
240
+            $p.chr(139) => "&#8249;",
241
+            $p.chr(140) => "&#338;",
242
+            $p.chr(141) => ' ', # pas affecte
243
+            $p.chr(142) => "&#381;",
244
+            $p.chr(143) => ' ', # pas affecte
245
+            $p.chr(144) => ' ', # pas affecte
246
+            $p.chr(145) => "&#8216;",
247
+            $p.chr(146) => "&#8217;",
248
+            $p.chr(147) => "&#8220;",
249
+            $p.chr(148) => "&#8221;",
250
+            $p.chr(149) => "&#8226;",
251
+            $p.chr(150) => "&#8211;",
252
+            $p.chr(151) => "&#8212;",
253
+            $p.chr(152) => "&#732;",
254
+            $p.chr(153) => "&#8482;", 
255
+            $p.chr(154) => "&#353;",
256
+            $p.chr(155) => "&#8250;",
257
+            $p.chr(156) => "&#339;",
258
+            $p.chr(157) => ' ', # pas affecte
259
+            $p.chr(158) => "&#382;",
260
+            $p.chr(159) => "&#376;",
261
+        );
262
+        if ($charset_cible!='unicode'){
263
+            foreach($trans[$charset][$charset_cible] as $k=>$c)
264
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
265
+        }
266
+    }
267
+
268
+    return @str_replace(array_keys($trans[$charset][$charset_cible]),
269
+                array_values($trans[$charset][$charset_cible]),$texte);
270 270
 }
271 271
 
272 272
 
@@ -284,22 +284,22 @@  discard block
 block discarded – undo
284 284
  *     Texte converti
285 285
 **/
286 286
 function html2unicode($texte, $secure=false) {
287
-	if (strpos($texte,'&') === false) return $texte;
288
-	static $trans = array();
289
-	if (!$trans) {
290
-		global $CHARSET;
291
-		load_charset('html');
292
-		foreach ($CHARSET['html'] as $key => $val) {
293
-			$trans["&$key;"] = $val;
294
-		}
295
-	}
296
-
297
-	if ($secure)
298
-		return str_replace(array_keys($trans),array_values($trans),$texte);
299
-	else
300
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'),array('&', '"', '<', '>'),
301
-		  str_replace(array_keys($trans),array_values($trans),$texte)			
302
-		);
287
+    if (strpos($texte,'&') === false) return $texte;
288
+    static $trans = array();
289
+    if (!$trans) {
290
+        global $CHARSET;
291
+        load_charset('html');
292
+        foreach ($CHARSET['html'] as $key => $val) {
293
+            $trans["&$key;"] = $val;
294
+        }
295
+    }
296
+
297
+    if ($secure)
298
+        return str_replace(array_keys($trans),array_values($trans),$texte);
299
+    else
300
+        return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'),array('&', '"', '<', '>'),
301
+            str_replace(array_keys($trans),array_values($trans),$texte)			
302
+        );
303 303
 }
304 304
 
305 305
 
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 314
  *     Texte converti
315 315
 **/
316 316
 function mathml2unicode($texte) {
317
-	static $trans;
318
-	if (!$trans) {
319
-		global $CHARSET;
320
-		load_charset('mathml');
317
+    static $trans;
318
+    if (!$trans) {
319
+        global $CHARSET;
320
+        load_charset('mathml');
321 321
 		
322
-		foreach ($CHARSET['mathml'] as $key => $val)
323
-			$trans["&$key;"] = $val;
324
-	}
322
+        foreach ($CHARSET['mathml'] as $key => $val)
323
+            $trans["&$key;"] = $val;
324
+    }
325 325
 
326
-	return str_replace(array_keys($trans),array_values($trans),$texte);
326
+    return str_replace(array_keys($trans),array_values($trans),$texte);
327 327
 }
328 328
 
329 329
 
@@ -345,58 +345,58 @@  discard block
 block discarded – undo
345 345
  *     Texte converti en unicode
346 346
 **/
347 347
 function charset2unicode($texte, $charset='AUTO' /* $forcer: obsolete*/) {
348
-	static $trans;
349
-
350
-	if ($charset == 'AUTO')
351
-		$charset = $GLOBALS['meta']['charset'];
352
-
353
-	if ($charset == '') $charset = 'iso-8859-1';
354
-	$charset = strtolower($charset);
355
-
356
-	switch ($charset) {
357
-	case 'utf-8':
358
-	case 'utf8':
359
-		return utf_8_to_unicode($texte);
360
-
361
-	case 'iso-8859-1':
362
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
363
-		// pas de break; ici, on suit sur default:
364
-
365
-	default:
366
-		// mbstring presente ?
367
-		if (init_mb_string()) {
368
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
369
-			AND mb_detect_order($charset)) {
370
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
371
-				if ($s && $s != $texte) return utf_8_to_unicode($s);
372
-			}
373
-			mb_detect_order($order); # remettre comme precedemment
374
-		}
375
-
376
-		// Sinon, peut-etre connaissons-nous ce charset ?
377
-		if (!isset($trans[$charset])) {
378
-			global $CHARSET;
379
-			if ($cset = load_charset($charset)
380
-			AND is_array($CHARSET[$cset]))
381
-				foreach ($CHARSET[$cset] as $key => $val) {
382
-					$trans[$charset][chr($key)] = '&#'.$val.';';
383
-			}
384
-		}
385
-		if (count($trans[$charset]))
386
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
387
-
388
-		// Sinon demander a iconv (malgre le fait qu'il coupe quand un
389
-		// caractere n'appartient pas au charset, mais c'est un probleme
390
-		// surtout en utf-8, gere ci-dessus)
391
-		if (test_iconv()) {
392
-			$s = iconv($charset, 'utf-32le', $texte);
393
-			if ($s) return utf_32_to_unicode($s);
394
-		}
395
-
396
-		// Au pire ne rien faire
397
-		spip_log("erreur charset '$charset' non supporte");
398
-		return $texte;
399
-	}
348
+    static $trans;
349
+
350
+    if ($charset == 'AUTO')
351
+        $charset = $GLOBALS['meta']['charset'];
352
+
353
+    if ($charset == '') $charset = 'iso-8859-1';
354
+    $charset = strtolower($charset);
355
+
356
+    switch ($charset) {
357
+    case 'utf-8':
358
+    case 'utf8':
359
+        return utf_8_to_unicode($texte);
360
+
361
+    case 'iso-8859-1':
362
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
363
+        // pas de break; ici, on suit sur default:
364
+
365
+    default:
366
+        // mbstring presente ?
367
+        if (init_mb_string()) {
368
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
369
+            AND mb_detect_order($charset)) {
370
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
371
+                if ($s && $s != $texte) return utf_8_to_unicode($s);
372
+            }
373
+            mb_detect_order($order); # remettre comme precedemment
374
+        }
375
+
376
+        // Sinon, peut-etre connaissons-nous ce charset ?
377
+        if (!isset($trans[$charset])) {
378
+            global $CHARSET;
379
+            if ($cset = load_charset($charset)
380
+            AND is_array($CHARSET[$cset]))
381
+                foreach ($CHARSET[$cset] as $key => $val) {
382
+                    $trans[$charset][chr($key)] = '&#'.$val.';';
383
+            }
384
+        }
385
+        if (count($trans[$charset]))
386
+            return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
387
+
388
+        // Sinon demander a iconv (malgre le fait qu'il coupe quand un
389
+        // caractere n'appartient pas au charset, mais c'est un probleme
390
+        // surtout en utf-8, gere ci-dessus)
391
+        if (test_iconv()) {
392
+            $s = iconv($charset, 'utf-32le', $texte);
393
+            if ($s) return utf_32_to_unicode($s);
394
+        }
395
+
396
+        // Au pire ne rien faire
397
+        spip_log("erreur charset '$charset' non supporte");
398
+        return $texte;
399
+    }
400 400
 }
401 401
 
402 402
 
@@ -415,43 +415,43 @@  discard block
 block discarded – undo
415 415
  *     Texte transformé dans le charset souhaité
416 416
 **/
417 417
 function unicode2charset($texte, $charset='AUTO') {
418
-	static $CHARSET_REVERSE;
419
-	static $trans = array();
418
+    static $CHARSET_REVERSE;
419
+    static $trans = array();
420 420
 	
421
-	if ($charset == 'AUTO')
422
-		$charset = $GLOBALS['meta']['charset'];
423
-
424
-	switch($charset) {
425
-	case 'utf-8':
426
-		return unicode_to_utf_8($texte);
427
-		break;
428
-
429
-	default:
430
-		$charset = load_charset($charset);
431
-
432
-		if (!is_array($CHARSET_REVERSE[$charset])) {
433
-			$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
434
-		}
435
-
436
-		if (!isset($trans[$charset])){
437
-			$trans[$charset]=array();
438
-			$t = &$trans[$charset];
439
-			for($e=128;$e<255;$e++){
440
-				$h = dechex($e);
441
-				if ($s = isset($CHARSET_REVERSE[$charset][$e])){
442
-					$s = $CHARSET_REVERSE[$charset][$e];
443
-					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444
-					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445
-				}
446
-				else{
447
-					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448
-					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449
-				}
450
-			}
451
-		}
452
-		$texte = str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
453
-		return $texte;
454
-	}
421
+    if ($charset == 'AUTO')
422
+        $charset = $GLOBALS['meta']['charset'];
423
+
424
+    switch($charset) {
425
+    case 'utf-8':
426
+        return unicode_to_utf_8($texte);
427
+        break;
428
+
429
+    default:
430
+        $charset = load_charset($charset);
431
+
432
+        if (!is_array($CHARSET_REVERSE[$charset])) {
433
+            $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
434
+        }
435
+
436
+        if (!isset($trans[$charset])){
437
+            $trans[$charset]=array();
438
+            $t = &$trans[$charset];
439
+            for($e=128;$e<255;$e++){
440
+                $h = dechex($e);
441
+                if ($s = isset($CHARSET_REVERSE[$charset][$e])){
442
+                    $s = $CHARSET_REVERSE[$charset][$e];
443
+                    $t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444
+                    $t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445
+                }
446
+                else{
447
+                    $t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448
+                    $t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449
+                }
450
+            }
451
+        }
452
+        $texte = str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
453
+        return $texte;
454
+    }
455 455
 }
456 456
 
457 457
 
@@ -469,32 +469,32 @@  discard block
 block discarded – undo
469 469
  *     Texte transformé dans le charset site
470 470
 **/
471 471
 function importer_charset($texte, $charset = 'AUTO') {
472
-	static $trans = array();
473
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
474
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset']=='utf-8')){
475
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1',$GLOBALS['meta']['charset']);
476
-		if (init_mb_string()) {
477
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
478
-			AND mb_detect_order($charset)) {
479
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
480
-			}
481
-			mb_detect_order($order); # remettre comme precedemment
482
-			return $s;
483
-		}
484
-		// Sinon, peut-etre connaissons-nous ce charset ?
485
-		if (!isset($trans[$charset])) {
486
-			global $CHARSET;
487
-			if ($cset = load_charset($charset)
488
-			AND is_array($CHARSET[$cset]))
489
-				foreach ($CHARSET[$cset] as $key => $val) {
490
-					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
491
-			}
492
-		}
493
-		if (count($trans[$charset]))
494
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
495
-		return $texte;
496
-	}
497
-	return unicode2charset(charset2unicode($texte, $charset));
472
+    static $trans = array();
473
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
474
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset']=='utf-8')){
475
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1',$GLOBALS['meta']['charset']);
476
+        if (init_mb_string()) {
477
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
478
+            AND mb_detect_order($charset)) {
479
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
480
+            }
481
+            mb_detect_order($order); # remettre comme precedemment
482
+            return $s;
483
+        }
484
+        // Sinon, peut-etre connaissons-nous ce charset ?
485
+        if (!isset($trans[$charset])) {
486
+            global $CHARSET;
487
+            if ($cset = load_charset($charset)
488
+            AND is_array($CHARSET[$cset]))
489
+                foreach ($CHARSET[$cset] as $key => $val) {
490
+                    $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
491
+            }
492
+        }
493
+        if (count($trans[$charset]))
494
+            return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
495
+        return $texte;
496
+    }
497
+    return unicode2charset(charset2unicode($texte, $charset));
498 498
 }
499 499
 
500 500
 
@@ -510,89 +510,89 @@  discard block
 block discarded – undo
510 510
 **/
511 511
 function utf_8_to_unicode($source) {
512 512
 
513
-	// mb_string : methode rapide
514
-	if (init_mb_string()) {
515
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
516
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
517
-	}
518
-
519
-	// Sinon methode pas a pas
520
-	static $decrement;
521
-	static $shift;
522
-
523
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
524
-	if (!is_array($decrement)) {
525
-		// array used to figure what number to decrement from character order value
526
-		// according to number of characters used to map unicode to ascii by utf-8
527
-		$decrement[4] = 240;
528
-		$decrement[3] = 224;
529
-		$decrement[2] = 192;
530
-		$decrement[1] = 0;
531
-		// the number of bits to shift each charNum by
532
-		$shift[1][0] = 0;
533
-		$shift[2][0] = 6;
534
-		$shift[2][1] = 0;
535
-		$shift[3][0] = 12;
536
-		$shift[3][1] = 6;
537
-		$shift[3][2] = 0;
538
-		$shift[4][0] = 18;
539
-		$shift[4][1] = 12;
540
-		$shift[4][2] = 6;
541
-		$shift[4][3] = 0;
542
-	}
543
-
544
-	$pos = 0;
545
-	$len = strlen ($source);
546
-	$encodedString = '';
547
-	while ($pos < $len) {
548
-		$char = '';
549
-		$ischar = false;
550
-		$asciiPos = ord (substr ($source, $pos, 1));
551
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
552
-			// 4 chars representing one unicode character
553
-			$thisLetter = substr ($source, $pos, 4);
554
-			$pos += 4;
555
-		}
556
-		else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
557
-			// 3 chars representing one unicode character
558
-			$thisLetter = substr ($source, $pos, 3);
559
-			$pos += 3;
560
-		}
561
-		else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
562
-			// 2 chars representing one unicode character
563
-			$thisLetter = substr ($source, $pos, 2);
564
-			$pos += 2;
565
-		}
566
-		else {
567
-			// 1 char (lower ascii)
568
-			$thisLetter = substr ($source, $pos, 1);
569
-			$pos += 1;
570
-			$char = $thisLetter;
571
-			$ischar = true;
572
-		}
573
-
574
-		if ($ischar)
575
-			$encodedString .= $char;
576
-		else {	// process the string representing the letter to a unicode entity
577
-			$thisLen = strlen ($thisLetter);
578
-			$thisPos = 0;
579
-			$decimalCode = 0;
580
-			while ($thisPos < $thisLen) {
581
-				$thisCharOrd = ord (substr ($thisLetter, $thisPos, 1));
582
-				if ($thisPos == 0) {
583
-					$charNum = intval ($thisCharOrd - $decrement[$thisLen]);
584
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
585
-				} else {
586
-					$charNum = intval ($thisCharOrd - 128);
587
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
-				}
589
-				$thisPos++;
590
-			}
591
-			$encodedLetter = "&#". preg_replace('/^0+/', '', $decimalCode) . ';';
592
-			$encodedString .= $encodedLetter;
593
-		}
594
-	}
595
-	return $encodedString;
513
+    // mb_string : methode rapide
514
+    if (init_mb_string()) {
515
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
516
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
517
+    }
518
+
519
+    // Sinon methode pas a pas
520
+    static $decrement;
521
+    static $shift;
522
+
523
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
524
+    if (!is_array($decrement)) {
525
+        // array used to figure what number to decrement from character order value
526
+        // according to number of characters used to map unicode to ascii by utf-8
527
+        $decrement[4] = 240;
528
+        $decrement[3] = 224;
529
+        $decrement[2] = 192;
530
+        $decrement[1] = 0;
531
+        // the number of bits to shift each charNum by
532
+        $shift[1][0] = 0;
533
+        $shift[2][0] = 6;
534
+        $shift[2][1] = 0;
535
+        $shift[3][0] = 12;
536
+        $shift[3][1] = 6;
537
+        $shift[3][2] = 0;
538
+        $shift[4][0] = 18;
539
+        $shift[4][1] = 12;
540
+        $shift[4][2] = 6;
541
+        $shift[4][3] = 0;
542
+    }
543
+
544
+    $pos = 0;
545
+    $len = strlen ($source);
546
+    $encodedString = '';
547
+    while ($pos < $len) {
548
+        $char = '';
549
+        $ischar = false;
550
+        $asciiPos = ord (substr ($source, $pos, 1));
551
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
552
+            // 4 chars representing one unicode character
553
+            $thisLetter = substr ($source, $pos, 4);
554
+            $pos += 4;
555
+        }
556
+        else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
557
+            // 3 chars representing one unicode character
558
+            $thisLetter = substr ($source, $pos, 3);
559
+            $pos += 3;
560
+        }
561
+        else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
562
+            // 2 chars representing one unicode character
563
+            $thisLetter = substr ($source, $pos, 2);
564
+            $pos += 2;
565
+        }
566
+        else {
567
+            // 1 char (lower ascii)
568
+            $thisLetter = substr ($source, $pos, 1);
569
+            $pos += 1;
570
+            $char = $thisLetter;
571
+            $ischar = true;
572
+        }
573
+
574
+        if ($ischar)
575
+            $encodedString .= $char;
576
+        else {	// process the string representing the letter to a unicode entity
577
+            $thisLen = strlen ($thisLetter);
578
+            $thisPos = 0;
579
+            $decimalCode = 0;
580
+            while ($thisPos < $thisLen) {
581
+                $thisCharOrd = ord (substr ($thisLetter, $thisPos, 1));
582
+                if ($thisPos == 0) {
583
+                    $charNum = intval ($thisCharOrd - $decrement[$thisLen]);
584
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
585
+                } else {
586
+                    $charNum = intval ($thisCharOrd - 128);
587
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
+                }
589
+                $thisPos++;
590
+            }
591
+            $encodedLetter = "&#". preg_replace('/^0+/', '', $decimalCode) . ';';
592
+            $encodedString .= $encodedLetter;
593
+        }
594
+    }
595
+    return $encodedString;
596 596
 }
597 597
 
598 598
 /**
@@ -611,27 +611,27 @@  discard block
 block discarded – undo
611 611
 **/
612 612
 function utf_32_to_unicode($source) {
613 613
 
614
-	// mb_string : methode rapide
615
-	if (init_mb_string()) {
616
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
617
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
618
-		return str_replace(chr(0), '', $source);
619
-	}
620
-
621
-	// Sinon methode lente
622
-	$texte = '';
623
-	while ($source) {
624
-		$words = unpack("V*", substr($source, 0, 1024));
625
-		$source = substr($source, 1024);
626
-		foreach ($words as $word) {
627
-			if ($word < 128)
628
-				$texte .= chr($word);
629
-			// ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
630
-			else if ($word != 65279)
631
-				$texte .= '&#'.$word.';';
632
-		}
633
-	}
634
-	return $texte;
614
+    // mb_string : methode rapide
615
+    if (init_mb_string()) {
616
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
617
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
618
+        return str_replace(chr(0), '', $source);
619
+    }
620
+
621
+    // Sinon methode lente
622
+    $texte = '';
623
+    while ($source) {
624
+        $words = unpack("V*", substr($source, 0, 1024));
625
+        $source = substr($source, 1024);
626
+        foreach ($words as $word) {
627
+            if ($word < 128)
628
+                $texte .= chr($word);
629
+            // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
630
+            else if ($word != 65279)
631
+                $texte .= '&#'.$word.';';
632
+        }
633
+    }
634
+    return $texte;
635 635
 
636 636
 }
637 637
 
@@ -648,15 +648,15 @@  discard block
 block discarded – undo
648 648
  *    Caractère utf8 si trouvé, '' sinon
649 649
 **/
650 650
 function caractere_utf_8($num) {
651
-	if($num<128)
652
-		return chr($num);
653
-	if($num<2048)
654
-		return chr(($num>>6)+192).chr(($num&63)+128);
655
-	if($num<65536)
656
-		return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
657
-	if($num<1114112)
658
-		return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
659
-	return '';
651
+    if($num<128)
652
+        return chr($num);
653
+    if($num<2048)
654
+        return chr(($num>>6)+192).chr(($num&63)+128);
655
+    if($num<65536)
656
+        return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
657
+    if($num<1114112)
658
+        return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
659
+    return '';
660 660
 }
661 661
 
662 662
 /**
@@ -669,25 +669,25 @@  discard block
 block discarded – undo
669 669
 **/
670 670
 function unicode_to_utf_8($texte) {
671 671
 
672
-	// 1. Entites &#128; et suivantes
673
-	$vu = array();
674
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
675
-	$texte, $regs, PREG_SET_ORDER))
676
-	foreach ($regs as $reg) {
677
-		if ($reg[1]>127 AND !isset($vu[$reg[0]]))
678
-			$vu[$reg[0]] = caractere_utf_8($reg[1]);
679
-	}
680
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
681
-
682
-	// 2. Entites > &#xFF;
683
-	//$vu = array();
684
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
685
-	$texte, $regs, PREG_SET_ORDER))
686
-	foreach ($regs as $reg) {
687
-		if (!isset($vu[$reg[0]]))
688
-			$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
689
-	}
690
-	return str_replace(array_keys($vu), array_values($vu), $texte);
672
+    // 1. Entites &#128; et suivantes
673
+    $vu = array();
674
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
675
+    $texte, $regs, PREG_SET_ORDER))
676
+    foreach ($regs as $reg) {
677
+        if ($reg[1]>127 AND !isset($vu[$reg[0]]))
678
+            $vu[$reg[0]] = caractere_utf_8($reg[1]);
679
+    }
680
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
681
+
682
+    // 2. Entites > &#xFF;
683
+    //$vu = array();
684
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
685
+    $texte, $regs, PREG_SET_ORDER))
686
+    foreach ($regs as $reg) {
687
+        if (!isset($vu[$reg[0]]))
688
+            $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
689
+    }
690
+    return str_replace(array_keys($vu), array_values($vu), $texte);
691 691
 
692 692
 }
693 693
 
@@ -700,14 +700,14 @@  discard block
 block discarded – undo
700 700
  *     Texte converti
701 701
 **/
702 702
 function unicode_to_javascript($texte) {
703
-	$vu = array();
704
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) AND !isset($vu[$regs[1]])) {
705
-		$num = $regs[1];
706
-		$vu[$num] = true;
707
-		$s = '\u'.sprintf("%04x", $num);
708
-		$texte = str_replace($regs[0], $s, $texte);
709
-	}
710
-	return $texte;
703
+    $vu = array();
704
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) AND !isset($vu[$regs[1]])) {
705
+        $num = $regs[1];
706
+        $vu[$num] = true;
707
+        $s = '\u'.sprintf("%04x", $num);
708
+        $texte = str_replace($regs[0], $s, $texte);
709
+    }
710
+    return $texte;
711 711
 }
712 712
 
713 713
 /**
@@ -719,9 +719,9 @@  discard block
 block discarded – undo
719 719
  *     Texte converti
720 720
 **/
721 721
 function javascript_to_unicode ($texte) {
722
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs))
723
-		$texte = str_replace($regs[0],"&#".hexdec($regs[1]).";", $texte);
724
-	return $texte;
722
+    while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs))
723
+        $texte = str_replace($regs[0],"&#".hexdec($regs[1]).";", $texte);
724
+    return $texte;
725 725
 }
726 726
 
727 727
 /**
@@ -733,31 +733,31 @@  discard block
 block discarded – undo
733 733
  *     Texte converti
734 734
 **/
735 735
 function javascript_to_binary ($texte) {
736
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs))
737
-		$texte = str_replace($regs[0],chr(hexdec($regs[1])), $texte);
738
-	return $texte;
736
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs))
737
+        $texte = str_replace($regs[0],chr(hexdec($regs[1])), $texte);
738
+    return $texte;
739 739
 }
740 740
 
741 741
 
742 742
 // http://doc.spip.org/@translitteration_rapide
743 743
 function translitteration_rapide($texte, $charset='AUTO', $complexe='') {
744
-	static $trans;
745
-	if ($charset == 'AUTO')
746
-		$charset = $GLOBALS['meta']['charset'];
747
-	if (!strlen($texte))
748
-		return $texte;
749
-
750
-	$table_translit ='translit'.$complexe;
751
-
752
-	// 2. Translitterer grace a la table predefinie
753
-	if (!$trans[$complexe]) {
754
-		global $CHARSET;
755
-		load_charset($table_translit);
756
-		foreach ($CHARSET[$table_translit] as $key => $val)
757
-			$trans[$complexe][caractere_utf_8($key)] = $val;
758
-	}
759
-
760
-	return str_replace(array_keys($trans[$complexe]),array_values($trans[$complexe]),$texte);
744
+    static $trans;
745
+    if ($charset == 'AUTO')
746
+        $charset = $GLOBALS['meta']['charset'];
747
+    if (!strlen($texte))
748
+        return $texte;
749
+
750
+    $table_translit ='translit'.$complexe;
751
+
752
+    // 2. Translitterer grace a la table predefinie
753
+    if (!$trans[$complexe]) {
754
+        global $CHARSET;
755
+        load_charset($table_translit);
756
+        foreach ($CHARSET[$table_translit] as $key => $val)
757
+            $trans[$complexe][caractere_utf_8($key)] = $val;
758
+    }
759
+
760
+    return str_replace(array_keys($trans[$complexe]),array_values($trans[$complexe]),$texte);
761 761
 }
762 762
 
763 763
 //
@@ -766,32 +766,32 @@  discard block
 block discarded – undo
766 766
 //
767 767
 // http://doc.spip.org/@translitteration
768 768
 function translitteration($texte, $charset='AUTO', $complexe='') {
769
-	// 0. Supprimer les caracteres illegaux
770
-	include_spip('inc/filtres');
771
-	$texte = corriger_caracteres($texte);
769
+    // 0. Supprimer les caracteres illegaux
770
+    include_spip('inc/filtres');
771
+    $texte = corriger_caracteres($texte);
772 772
 
773
-	// 1. Passer le charset et les &eacute en utf-8
774
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
773
+    // 1. Passer le charset et les &eacute en utf-8
774
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
775 775
 
776
-	return translitteration_rapide($texte,$charset,$complexe);
776
+    return translitteration_rapide($texte,$charset,$complexe);
777 777
 }
778 778
 
779 779
 // &agrave; est retourne sous la forme "a`" et pas "a"
780 780
 // mais si $chiffre=true, on retourne "a8" (vietnamien)
781 781
 // http://doc.spip.org/@translitteration_complexe
782 782
 function translitteration_complexe($texte, $chiffres=false) {
783
-	$texte = translitteration($texte,'AUTO','complexe');
783
+    $texte = translitteration($texte,'AUTO','complexe');
784 784
 
785
-	if ($chiffres) {
786
-		$texte = preg_replace("/[aeiuoyd]['`?~.^+(-]{1,2}/eS",
787
-			"translitteration_chiffree('\\0')", $texte);
788
-	}
785
+    if ($chiffres) {
786
+        $texte = preg_replace("/[aeiuoyd]['`?~.^+(-]{1,2}/eS",
787
+            "translitteration_chiffree('\\0')", $texte);
788
+    }
789 789
 	
790
-	return $texte;
790
+    return $texte;
791 791
 }
792 792
 // http://doc.spip.org/@translitteration_chiffree
793 793
 function translitteration_chiffree($car) {
794
-	return strtr($car, "'`?~.^+(-", "123456789");
794
+    return strtr($car, "'`?~.^+(-", "123456789");
795 795
 }
796 796
 
797 797
 
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
  *    true s'il a un BOM
805 805
 **/
806 806
 function bom_utf8($texte) {
807
-	return (substr($texte, 0,3) == chr(0xEF).chr(0xBB).chr(0xBF));
807
+    return (substr($texte, 0,3) == chr(0xEF).chr(0xBB).chr(0xBF));
808 808
 }
809 809
 
810 810
 /**
@@ -821,18 +821,18 @@  discard block
 block discarded – undo
821 821
  *     true si c'est le cas
822 822
 **/
823 823
 function is_utf8($string) {
824
-	return !strlen(
825
-	preg_replace(
826
-	  ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
827
-	. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
828
-	. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
829
-	. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
830
-	. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
831
-	. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
832
-	. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
833
-	. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
834
-	. ',sS',
835
-	'', $string));
824
+    return !strlen(
825
+    preg_replace(
826
+        ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
827
+    . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
828
+    . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
829
+    . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
830
+    . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
831
+    . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
832
+    . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
833
+    . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
834
+    . ',sS',
835
+    '', $string));
836 836
 }
837 837
 
838 838
 /**
@@ -844,10 +844,10 @@  discard block
 block discarded – undo
844 844
  *     true si c'est le cas
845 845
 **/
846 846
 function is_ascii($string) {
847
-	return !strlen(
848
-	preg_replace(
849
-	',[\x09\x0A\x0D\x20-\x7E],sS',
850
-	'', $string));
847
+    return !strlen(
848
+    preg_replace(
849
+    ',[\x09\x0A\x0D\x20-\x7E],sS',
850
+    '', $string));
851 851
 }
852 852
 
853 853
 // Transcode une page (attrapee sur le web, ou un squelette) en essayant
@@ -855,49 +855,49 @@  discard block
 block discarded – undo
855 855
 // http://doc.spip.org/@transcoder_page
856 856
 function transcoder_page($texte, $headers='') {
857 857
 
858
-	// Si tout est < 128 pas la peine d'aller plus loin
859
-	if (is_ascii($texte)) {
860
-		#spip_log('charset: ascii');
861
-		return $texte;
862
-	}
863
-
864
-	// Reconnaitre le BOM utf-8 (0xEFBBBF)
865
-	if (bom_utf8($texte)) {
866
-		$charset = 'utf-8';
867
-		$texte = substr($texte,3);
868
-	}
869
-
870
-	// charset precise par le contenu (xml)
871
-	else if (preg_match(
872
-	',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs))
873
-		$charset = trim(strtolower($regs[1]));
874
-	// charset precise par le contenu (html)
875
-	else if (preg_match(
876
-	',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
877
-	$texte, $regs)
878
-	# eviter #CHARSET des squelettes
879
-	AND (($tmp = trim(strtolower($regs[2]))) != 'charset'))
880
-		$charset = $tmp;
881
-	// charset de la reponse http
882
-	else if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs))
883
-		$charset = trim(strtolower($regs[1]));
884
-	else $charset = '';
885
-	// normaliser les noms du shif-jis japonais
886
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset))
887
-		$charset = 'shift-jis';
888
-
889
-	if ($charset) {
890
-		spip_log("charset: $charset");
891
-	} else {
892
-		// valeur par defaut
893
-		if (is_utf8($texte))
894
-			$charset = 'utf-8';
895
-		else
896
-			$charset = 'iso-8859-1';
897
-		spip_log("charset probable: $charset");
898
-	}
899
-
900
-	return importer_charset($texte, $charset);
858
+    // Si tout est < 128 pas la peine d'aller plus loin
859
+    if (is_ascii($texte)) {
860
+        #spip_log('charset: ascii');
861
+        return $texte;
862
+    }
863
+
864
+    // Reconnaitre le BOM utf-8 (0xEFBBBF)
865
+    if (bom_utf8($texte)) {
866
+        $charset = 'utf-8';
867
+        $texte = substr($texte,3);
868
+    }
869
+
870
+    // charset precise par le contenu (xml)
871
+    else if (preg_match(
872
+    ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs))
873
+        $charset = trim(strtolower($regs[1]));
874
+    // charset precise par le contenu (html)
875
+    else if (preg_match(
876
+    ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
877
+    $texte, $regs)
878
+    # eviter #CHARSET des squelettes
879
+    AND (($tmp = trim(strtolower($regs[2]))) != 'charset'))
880
+        $charset = $tmp;
881
+    // charset de la reponse http
882
+    else if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs))
883
+        $charset = trim(strtolower($regs[1]));
884
+    else $charset = '';
885
+    // normaliser les noms du shif-jis japonais
886
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset))
887
+        $charset = 'shift-jis';
888
+
889
+    if ($charset) {
890
+        spip_log("charset: $charset");
891
+    } else {
892
+        // valeur par defaut
893
+        if (is_utf8($texte))
894
+            $charset = 'utf-8';
895
+        else
896
+            $charset = 'iso-8859-1';
897
+        spip_log("charset probable: $charset");
898
+    }
899
+
900
+    return importer_charset($texte, $charset);
901 901
 }
902 902
 
903 903
 
@@ -920,24 +920,24 @@  discard block
 block discarded – undo
920 920
  *     Le texte coupé
921 921
 **/
922 922
 function spip_substr($c, $start=0, $length = NULL) {
923
-	// Si ce n'est pas utf-8, utiliser substr
924
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
925
-		if ($length)
926
-			return substr($c, $start, $length);
927
-		else
928
-			substr($c, $start);
929
-	}
930
-
931
-	// Si utf-8, voir si on dispose de mb_string
932
-	if (init_mb_string()) {
933
-		if ($length)
934
-			return mb_substr($c, $start, $length);
935
-		else
936
-			return mb_substr($c, $start);
937
-	}
938
-
939
-	// Version manuelle (cf. ci-dessous)
940
-	return spip_substr_manuelle($c, $start, $length);
923
+    // Si ce n'est pas utf-8, utiliser substr
924
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
925
+        if ($length)
926
+            return substr($c, $start, $length);
927
+        else
928
+            substr($c, $start);
929
+    }
930
+
931
+    // Si utf-8, voir si on dispose de mb_string
932
+    if (init_mb_string()) {
933
+        if ($length)
934
+            return mb_substr($c, $start, $length);
935
+        else
936
+            return mb_substr($c, $start);
937
+    }
938
+
939
+    // Version manuelle (cf. ci-dessous)
940
+    return spip_substr_manuelle($c, $start, $length);
941 941
 }
942 942
 
943 943
 
@@ -957,32 +957,32 @@  discard block
 block discarded – undo
957 957
 **/
958 958
 function spip_substr_manuelle($c, $start, $length = NULL) {
959 959
 
960
-	// Cas pathologique
961
-	if ($length === 0)
962
-		return '';
963
-
964
-	// S'il y a un demarrage, on se positionne
965
-	if ($start > 0)
966
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
967
-	elseif ($start < 0)
968
-		return spip_substr_manuelle($c, spip_strlen($c)+$start, $length);
969
-
970
-	if (!$length)
971
-		return $c;
972
-
973
-	if ($length > 0) {
974
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
975
-		// (un caractere utf-8 prenant au maximum n bytes)
976
-		$n = 0; while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c));
977
-		$c = substr($c, 0, $n*$length);
978
-		// puis, tant qu'on est trop long, on coupe...
979
-		while (($l = spip_strlen($c)) > $length)
980
-			$c = substr($c, 0, $length - $l);
981
-		return $c;
982
-	}
983
-
984
-	// $length < 0
985
-	return spip_substr_manuelle($c, 0, spip_strlen($c)+$length);
960
+    // Cas pathologique
961
+    if ($length === 0)
962
+        return '';
963
+
964
+    // S'il y a un demarrage, on se positionne
965
+    if ($start > 0)
966
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
967
+    elseif ($start < 0)
968
+        return spip_substr_manuelle($c, spip_strlen($c)+$start, $length);
969
+
970
+    if (!$length)
971
+        return $c;
972
+
973
+    if ($length > 0) {
974
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
975
+        // (un caractere utf-8 prenant au maximum n bytes)
976
+        $n = 0; while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c));
977
+        $c = substr($c, 0, $n*$length);
978
+        // puis, tant qu'on est trop long, on coupe...
979
+        while (($l = spip_strlen($c)) > $length)
980
+            $c = substr($c, 0, $length - $l);
981
+        return $c;
982
+    }
983
+
984
+    // $length < 0
985
+    return spip_substr_manuelle($c, 0, spip_strlen($c)+$length);
986 986
 }
987 987
 
988 988
 /**
@@ -996,15 +996,15 @@  discard block
 block discarded – undo
996 996
  *     La chaîne avec une majuscule sur le premier mot 
997 997
  */
998 998
 function spip_ucfirst($c){
999
-	// Si ce n'est pas utf-8, utiliser ucfirst 
1000
-	if ($GLOBALS['meta']['charset'] != 'utf-8')
1001
-		return ucfirst($c);
1002
-	// Si on n'a pas mb_* on utilise ucfirst
1003
-	if (!init_mb_string())
1004
-		return ucfirst($c);
999
+    // Si ce n'est pas utf-8, utiliser ucfirst 
1000
+    if ($GLOBALS['meta']['charset'] != 'utf-8')
1001
+        return ucfirst($c);
1002
+    // Si on n'a pas mb_* on utilise ucfirst
1003
+    if (!init_mb_string())
1004
+        return ucfirst($c);
1005 1005
 	
1006
-	$lettre1 = mb_strtoupper(spip_substr($c,0,1));
1007
-	return $lettre1.spip_substr($c,1);
1006
+    $lettre1 = mb_strtoupper(spip_substr($c,0,1));
1007
+    return $lettre1.spip_substr($c,1);
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1018,21 +1018,21 @@  discard block
 block discarded – undo
1018 1018
  *     Longueur de la chaîne
1019 1019
  */
1020 1020
 function spip_strlen($c) {
1021
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1022
-	$c = str_replace("\r\n", "\n", $c);
1021
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1022
+    $c = str_replace("\r\n", "\n", $c);
1023 1023
 	
1024
-	// Si ce n'est pas utf-8, utiliser strlen
1025
-	if ($GLOBALS['meta']['charset'] != 'utf-8')
1026
-		return strlen($c);
1027
-
1028
-	// Sinon, utiliser mb_strlen() si disponible
1029
-	if (init_mb_string())
1030
-		return mb_strlen($c);
1031
-
1032
-	// Methode manuelle : on supprime les bytes 10......,
1033
-	// on compte donc les ascii (0.......) et les demarrages
1034
-	// de caracteres utf-8 (11......)
1035
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1024
+    // Si ce n'est pas utf-8, utiliser strlen
1025
+    if ($GLOBALS['meta']['charset'] != 'utf-8')
1026
+        return strlen($c);
1027
+
1028
+    // Sinon, utiliser mb_strlen() si disponible
1029
+    if (init_mb_string())
1030
+        return mb_strlen($c);
1031
+
1032
+    // Methode manuelle : on supprime les bytes 10......,
1033
+    // on compte donc les ascii (0.......) et les demarrages
1034
+    // de caracteres utf-8 (11......)
1035
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1036 1036
 }
1037 1037
 
1038 1038
 // Initialisation
@@ -1043,12 +1043,12 @@  discard block
 block discarded – undo
1043 1043
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1044 1044
 if (!isset($GLOBALS['meta']['pcre_u'])
1045 1045
   OR (isset($_GET['var_mode']) AND !isset($_GET['var_profile']))) {
1046
-	include_spip('inc/meta');
1047
-	ecrire_meta('pcre_u',
1048
-		$u = ($GLOBALS['meta']['charset'] == 'utf-8'
1049
-		AND test_pcre_unicode())
1050
-			? 'u' :''
1051
-	);
1046
+    include_spip('inc/meta');
1047
+    ecrire_meta('pcre_u',
1048
+        $u = ($GLOBALS['meta']['charset'] == 'utf-8'
1049
+        AND test_pcre_unicode())
1050
+            ? 'u' :''
1051
+    );
1052 1052
 }
1053 1053
 
1054 1054
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -354,48 +354,48 @@  discard block
 block discarded – undo
354 354
 	$charset = strtolower($charset);
355 355
 
356 356
 	switch ($charset) {
357
-	case 'utf-8':
358
-	case 'utf8':
359
-		return utf_8_to_unicode($texte);
360
-
361
-	case 'iso-8859-1':
362
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
363
-		// pas de break; ici, on suit sur default:
364
-
365
-	default:
366
-		// mbstring presente ?
367
-		if (init_mb_string()) {
368
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
369
-			AND mb_detect_order($charset)) {
370
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
371
-				if ($s && $s != $texte) return utf_8_to_unicode($s);
372
-			}
373
-			mb_detect_order($order); # remettre comme precedemment
374
-		}
375
-
376
-		// Sinon, peut-etre connaissons-nous ce charset ?
377
-		if (!isset($trans[$charset])) {
378
-			global $CHARSET;
379
-			if ($cset = load_charset($charset)
380
-			AND is_array($CHARSET[$cset]))
381
-				foreach ($CHARSET[$cset] as $key => $val) {
382
-					$trans[$charset][chr($key)] = '&#'.$val.';';
383
-			}
384
-		}
385
-		if (count($trans[$charset]))
386
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
387
-
388
-		// Sinon demander a iconv (malgre le fait qu'il coupe quand un
389
-		// caractere n'appartient pas au charset, mais c'est un probleme
390
-		// surtout en utf-8, gere ci-dessus)
391
-		if (test_iconv()) {
392
-			$s = iconv($charset, 'utf-32le', $texte);
393
-			if ($s) return utf_32_to_unicode($s);
394
-		}
395
-
396
-		// Au pire ne rien faire
397
-		spip_log("erreur charset '$charset' non supporte");
398
-		return $texte;
357
+	    case 'utf-8':
358
+	    case 'utf8':
359
+		    return utf_8_to_unicode($texte);
360
+
361
+	    case 'iso-8859-1':
362
+		    $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
363
+		    // pas de break; ici, on suit sur default:
364
+
365
+	    default:
366
+		    // mbstring presente ?
367
+		    if (init_mb_string()) {
368
+			    if ($order = mb_detect_order() # mb_string connait-il $charset?
369
+			    AND mb_detect_order($charset)) {
370
+				    $s = mb_convert_encoding($texte, 'utf-8', $charset);
371
+				    if ($s && $s != $texte) return utf_8_to_unicode($s);
372
+			    }
373
+			    mb_detect_order($order); # remettre comme precedemment
374
+		    }
375
+
376
+		    // Sinon, peut-etre connaissons-nous ce charset ?
377
+		    if (!isset($trans[$charset])) {
378
+			    global $CHARSET;
379
+			    if ($cset = load_charset($charset)
380
+			    AND is_array($CHARSET[$cset]))
381
+				    foreach ($CHARSET[$cset] as $key => $val) {
382
+					    $trans[$charset][chr($key)] = '&#'.$val.';';
383
+			    }
384
+		    }
385
+		    if (count($trans[$charset]))
386
+			    return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
387
+
388
+		    // Sinon demander a iconv (malgre le fait qu'il coupe quand un
389
+		    // caractere n'appartient pas au charset, mais c'est un probleme
390
+		    // surtout en utf-8, gere ci-dessus)
391
+		    if (test_iconv()) {
392
+			    $s = iconv($charset, 'utf-32le', $texte);
393
+			    if ($s) return utf_32_to_unicode($s);
394
+		    }
395
+
396
+		    // Au pire ne rien faire
397
+		    spip_log("erreur charset '$charset' non supporte");
398
+		    return $texte;
399 399
 	}
400 400
 }
401 401
 
@@ -422,35 +422,35 @@  discard block
 block discarded – undo
422 422
 		$charset = $GLOBALS['meta']['charset'];
423 423
 
424 424
 	switch($charset) {
425
-	case 'utf-8':
426
-		return unicode_to_utf_8($texte);
427
-		break;
428
-
429
-	default:
430
-		$charset = load_charset($charset);
431
-
432
-		if (!is_array($CHARSET_REVERSE[$charset])) {
433
-			$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
434
-		}
435
-
436
-		if (!isset($trans[$charset])){
437
-			$trans[$charset]=array();
438
-			$t = &$trans[$charset];
439
-			for($e=128;$e<255;$e++){
440
-				$h = dechex($e);
441
-				if ($s = isset($CHARSET_REVERSE[$charset][$e])){
442
-					$s = $CHARSET_REVERSE[$charset][$e];
443
-					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444
-					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445
-				}
446
-				else{
447
-					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448
-					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449
-				}
450
-			}
451
-		}
452
-		$texte = str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
453
-		return $texte;
425
+	    case 'utf-8':
426
+		    return unicode_to_utf_8($texte);
427
+		    break;
428
+
429
+	    default:
430
+		    $charset = load_charset($charset);
431
+
432
+		    if (!is_array($CHARSET_REVERSE[$charset])) {
433
+			    $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
434
+		    }
435
+
436
+		    if (!isset($trans[$charset])){
437
+			    $trans[$charset]=array();
438
+			    $t = &$trans[$charset];
439
+			    for($e=128;$e<255;$e++){
440
+				    $h = dechex($e);
441
+				    if ($s = isset($CHARSET_REVERSE[$charset][$e])){
442
+					    $s = $CHARSET_REVERSE[$charset][$e];
443
+					    $t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444
+					    $t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445
+				    }
446
+				    else{
447
+					    $t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448
+					    $t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449
+				    }
450
+			    }
451
+		    }
452
+		    $texte = str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
453
+		    return $texte;
454 454
 	}
455 455
 }
456 456
 
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  *     Nom du charset
38 38
  *     false si le charset n'est pas décrit dans le répertoire charsets/
39 39
 **/
40
-function load_charset ($charset = 'AUTO') {
40
+function load_charset($charset = 'AUTO') {
41 41
 	if ($charset == 'AUTO')
42 42
 		$charset = $GLOBALS['meta']['charset'];
43 43
 	$charset = trim(strtolower($charset));
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	else if ($charset == 'windows-1251') $charset = 'cp1251';
56 56
 	else if ($charset == 'windows-1256') $charset = 'cp1256';
57 57
 
58
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
58
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
59 59
 		return $charset;
60 60
 	} else {
61 61
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -207,17 +207,17 @@  discard block
 block discarded – undo
207 207
  * @return string
208 208
  *     Texte corrigé
209 209
 **/
210
-function corriger_caracteres_windows($texte, $charset='AUTO', $charset_cible='unicode') {
210
+function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
211 211
 	static $trans;
212 212
 	
213 213
 	if (is_array($texte)) {
214 214
 		return array_map('corriger_caracteres_windows', $texte);
215 215
 	}
216 216
 	
217
-	if ($charset=='AUTO') $charset = $GLOBALS['meta']['charset'];
217
+	if ($charset == 'AUTO') $charset = $GLOBALS['meta']['charset'];
218 218
 	if ($charset == 'utf-8') {
219 219
 		$p = chr(194);
220
-		if (strpos($texte,$p)==false)
220
+		if (strpos($texte, $p) == false)
221 221
 			return $texte;
222 222
 	} else if ($charset == 'iso-8859-1') {
223 223
 		$p = '';
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 			$p.chr(158) => "&#382;",
260 260
 			$p.chr(159) => "&#376;",
261 261
 		);
262
-		if ($charset_cible!='unicode'){
263
-			foreach($trans[$charset][$charset_cible] as $k=>$c)
262
+		if ($charset_cible != 'unicode') {
263
+			foreach ($trans[$charset][$charset_cible] as $k=>$c)
264 264
 				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
265 265
 		}
266 266
 	}
267 267
 
268 268
 	return @str_replace(array_keys($trans[$charset][$charset_cible]),
269
-			   array_values($trans[$charset][$charset_cible]),$texte);
269
+			   array_values($trans[$charset][$charset_cible]), $texte);
270 270
 }
271 271
 
272 272
 
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
  * @return string
284 284
  *     Texte converti
285 285
 **/
286
-function html2unicode($texte, $secure=false) {
287
-	if (strpos($texte,'&') === false) return $texte;
286
+function html2unicode($texte, $secure = false) {
287
+	if (strpos($texte, '&') === false) return $texte;
288 288
 	static $trans = array();
289 289
 	if (!$trans) {
290 290
 		global $CHARSET;
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
 	}
296 296
 
297 297
 	if ($secure)
298
-		return str_replace(array_keys($trans),array_values($trans),$texte);
298
+		return str_replace(array_keys($trans), array_values($trans), $texte);
299 299
 	else
300
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'),array('&', '"', '<', '>'),
301
-		  str_replace(array_keys($trans),array_values($trans),$texte)			
300
+		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
301
+		  str_replace(array_keys($trans), array_values($trans), $texte)			
302 302
 		);
303 303
 }
304 304
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 			$trans["&$key;"] = $val;
324 324
 	}
325 325
 
326
-	return str_replace(array_keys($trans),array_values($trans),$texte);
326
+	return str_replace(array_keys($trans), array_values($trans), $texte);
327 327
 }
328 328
 
329 329
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
  * @return string
345 345
  *     Texte converti en unicode
346 346
 **/
347
-function charset2unicode($texte, $charset='AUTO' /* $forcer: obsolete*/) {
347
+function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
348 348
 	static $trans;
349 349
 
350 350
 	if ($charset == 'AUTO')
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 			}
384 384
 		}
385 385
 		if (count($trans[$charset]))
386
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
386
+			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
387 387
 
388 388
 		// Sinon demander a iconv (malgre le fait qu'il coupe quand un
389 389
 		// caractere n'appartient pas au charset, mais c'est un probleme
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
  * @return string
415 415
  *     Texte transformé dans le charset souhaité
416 416
 **/
417
-function unicode2charset($texte, $charset='AUTO') {
417
+function unicode2charset($texte, $charset = 'AUTO') {
418 418
 	static $CHARSET_REVERSE;
419 419
 	static $trans = array();
420 420
 	
421 421
 	if ($charset == 'AUTO')
422 422
 		$charset = $GLOBALS['meta']['charset'];
423 423
 
424
-	switch($charset) {
424
+	switch ($charset) {
425 425
 	case 'utf-8':
426 426
 		return unicode_to_utf_8($texte);
427 427
 		break;
@@ -433,23 +433,23 @@  discard block
 block discarded – undo
433 433
 			$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
434 434
 		}
435 435
 
436
-		if (!isset($trans[$charset])){
437
-			$trans[$charset]=array();
436
+		if (!isset($trans[$charset])) {
437
+			$trans[$charset] = array();
438 438
 			$t = &$trans[$charset];
439
-			for($e=128;$e<255;$e++){
439
+			for ($e = 128; $e < 255; $e++) {
440 440
 				$h = dechex($e);
441
-				if ($s = isset($CHARSET_REVERSE[$charset][$e])){
441
+				if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
442 442
 					$s = $CHARSET_REVERSE[$charset][$e];
443 443
 					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444 444
 					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445 445
 				}
446
-				else{
446
+				else {
447 447
 					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448 448
 					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449 449
 				}
450 450
 			}
451 451
 		}
452
-		$texte = str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
452
+		$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
453 453
 		return $texte;
454 454
 	}
455 455
 }
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 function importer_charset($texte, $charset = 'AUTO') {
472 472
 	static $trans = array();
473 473
 	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
474
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset']=='utf-8')){
475
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1',$GLOBALS['meta']['charset']);
474
+	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
475
+		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
476 476
 		if (init_mb_string()) {
477 477
 			if ($order = mb_detect_order() # mb_string connait-il $charset?
478 478
 			AND mb_detect_order($charset)) {
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 			}
492 492
 		}
493 493
 		if (count($trans[$charset]))
494
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
494
+			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
495 495
 		return $texte;
496 496
 	}
497 497
 	return unicode2charset(charset2unicode($texte, $charset));
@@ -542,30 +542,30 @@  discard block
 block discarded – undo
542 542
 	}
543 543
 
544 544
 	$pos = 0;
545
-	$len = strlen ($source);
545
+	$len = strlen($source);
546 546
 	$encodedString = '';
547 547
 	while ($pos < $len) {
548 548
 		$char = '';
549 549
 		$ischar = false;
550
-		$asciiPos = ord (substr ($source, $pos, 1));
550
+		$asciiPos = ord(substr($source, $pos, 1));
551 551
 		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
552 552
 			// 4 chars representing one unicode character
553
-			$thisLetter = substr ($source, $pos, 4);
553
+			$thisLetter = substr($source, $pos, 4);
554 554
 			$pos += 4;
555 555
 		}
556 556
 		else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
557 557
 			// 3 chars representing one unicode character
558
-			$thisLetter = substr ($source, $pos, 3);
558
+			$thisLetter = substr($source, $pos, 3);
559 559
 			$pos += 3;
560 560
 		}
561 561
 		else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
562 562
 			// 2 chars representing one unicode character
563
-			$thisLetter = substr ($source, $pos, 2);
563
+			$thisLetter = substr($source, $pos, 2);
564 564
 			$pos += 2;
565 565
 		}
566 566
 		else {
567 567
 			// 1 char (lower ascii)
568
-			$thisLetter = substr ($source, $pos, 1);
568
+			$thisLetter = substr($source, $pos, 1);
569 569
 			$pos += 1;
570 570
 			$char = $thisLetter;
571 571
 			$ischar = true;
@@ -574,21 +574,21 @@  discard block
 block discarded – undo
574 574
 		if ($ischar)
575 575
 			$encodedString .= $char;
576 576
 		else {	// process the string representing the letter to a unicode entity
577
-			$thisLen = strlen ($thisLetter);
577
+			$thisLen = strlen($thisLetter);
578 578
 			$thisPos = 0;
579 579
 			$decimalCode = 0;
580 580
 			while ($thisPos < $thisLen) {
581
-				$thisCharOrd = ord (substr ($thisLetter, $thisPos, 1));
581
+				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
582 582
 				if ($thisPos == 0) {
583
-					$charNum = intval ($thisCharOrd - $decrement[$thisLen]);
583
+					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
584 584
 					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
585 585
 				} else {
586
-					$charNum = intval ($thisCharOrd - 128);
586
+					$charNum = intval($thisCharOrd - 128);
587 587
 					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588 588
 				}
589 589
 				$thisPos++;
590 590
 			}
591
-			$encodedLetter = "&#". preg_replace('/^0+/', '', $decimalCode) . ';';
591
+			$encodedLetter = "&#".preg_replace('/^0+/', '', $decimalCode).';';
592 592
 			$encodedString .= $encodedLetter;
593 593
 		}
594 594
 	}
@@ -648,14 +648,14 @@  discard block
 block discarded – undo
648 648
  *    Caractère utf8 si trouvé, '' sinon
649 649
 **/
650 650
 function caractere_utf_8($num) {
651
-	if($num<128)
651
+	if ($num < 128)
652 652
 		return chr($num);
653
-	if($num<2048)
654
-		return chr(($num>>6)+192).chr(($num&63)+128);
655
-	if($num<65536)
656
-		return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
657
-	if($num<1114112)
658
-		return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
653
+	if ($num < 2048)
654
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
655
+	if ($num < 65536)
656
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
657
+	if ($num < 1114112)
658
+		return chr($num >> 18 + 240).chr((($num >> 12) & 63) + 128).chr(($num >> 6) & 63 + 128).chr($num & 63 + 128);
659 659
 	return '';
660 660
 }
661 661
 
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
675 675
 	$texte, $regs, PREG_SET_ORDER))
676 676
 	foreach ($regs as $reg) {
677
-		if ($reg[1]>127 AND !isset($vu[$reg[0]]))
677
+		if ($reg[1] > 127 AND !isset($vu[$reg[0]]))
678 678
 			$vu[$reg[0]] = caractere_utf_8($reg[1]);
679 679
 	}
680 680
 	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
@@ -718,9 +718,9 @@  discard block
 block discarded – undo
718 718
  * @return string
719 719
  *     Texte converti
720 720
 **/
721
-function javascript_to_unicode ($texte) {
721
+function javascript_to_unicode($texte) {
722 722
 	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs))
723
-		$texte = str_replace($regs[0],"&#".hexdec($regs[1]).";", $texte);
723
+		$texte = str_replace($regs[0], "&#".hexdec($regs[1]).";", $texte);
724 724
 	return $texte;
725 725
 }
726 726
 
@@ -732,22 +732,22 @@  discard block
 block discarded – undo
732 732
  * @return string
733 733
  *     Texte converti
734 734
 **/
735
-function javascript_to_binary ($texte) {
735
+function javascript_to_binary($texte) {
736 736
 	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs))
737
-		$texte = str_replace($regs[0],chr(hexdec($regs[1])), $texte);
737
+		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
738 738
 	return $texte;
739 739
 }
740 740
 
741 741
 
742 742
 // http://doc.spip.org/@translitteration_rapide
743
-function translitteration_rapide($texte, $charset='AUTO', $complexe='') {
743
+function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
744 744
 	static $trans;
745 745
 	if ($charset == 'AUTO')
746 746
 		$charset = $GLOBALS['meta']['charset'];
747 747
 	if (!strlen($texte))
748 748
 		return $texte;
749 749
 
750
-	$table_translit ='translit'.$complexe;
750
+	$table_translit = 'translit'.$complexe;
751 751
 
752 752
 	// 2. Translitterer grace a la table predefinie
753 753
 	if (!$trans[$complexe]) {
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 			$trans[$complexe][caractere_utf_8($key)] = $val;
758 758
 	}
759 759
 
760
-	return str_replace(array_keys($trans[$complexe]),array_values($trans[$complexe]),$texte);
760
+	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
761 761
 }
762 762
 
763 763
 //
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 // Attention les caracteres non reconnus sont renvoyes en utf-8
766 766
 //
767 767
 // http://doc.spip.org/@translitteration
768
-function translitteration($texte, $charset='AUTO', $complexe='') {
768
+function translitteration($texte, $charset = 'AUTO', $complexe = '') {
769 769
 	// 0. Supprimer les caracteres illegaux
770 770
 	include_spip('inc/filtres');
771 771
 	$texte = corriger_caracteres($texte);
@@ -773,14 +773,14 @@  discard block
 block discarded – undo
773 773
 	// 1. Passer le charset et les &eacute en utf-8
774 774
 	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
775 775
 
776
-	return translitteration_rapide($texte,$charset,$complexe);
776
+	return translitteration_rapide($texte, $charset, $complexe);
777 777
 }
778 778
 
779 779
 // &agrave; est retourne sous la forme "a`" et pas "a"
780 780
 // mais si $chiffre=true, on retourne "a8" (vietnamien)
781 781
 // http://doc.spip.org/@translitteration_complexe
782
-function translitteration_complexe($texte, $chiffres=false) {
783
-	$texte = translitteration($texte,'AUTO','complexe');
782
+function translitteration_complexe($texte, $chiffres = false) {
783
+	$texte = translitteration($texte, 'AUTO', 'complexe');
784 784
 
785 785
 	if ($chiffres) {
786 786
 		$texte = preg_replace("/[aeiuoyd]['`?~.^+(-]{1,2}/eS",
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
  *    true s'il a un BOM
805 805
 **/
806 806
 function bom_utf8($texte) {
807
-	return (substr($texte, 0,3) == chr(0xEF).chr(0xBB).chr(0xBF));
807
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
808 808
 }
809 809
 
810 810
 /**
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 // Transcode une page (attrapee sur le web, ou un squelette) en essayant
854 854
 // par tous les moyens de deviner son charset (y compris headers HTTP)
855 855
 // http://doc.spip.org/@transcoder_page
856
-function transcoder_page($texte, $headers='') {
856
+function transcoder_page($texte, $headers = '') {
857 857
 
858 858
 	// Si tout est < 128 pas la peine d'aller plus loin
859 859
 	if (is_ascii($texte)) {
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 	// Reconnaitre le BOM utf-8 (0xEFBBBF)
865 865
 	if (bom_utf8($texte)) {
866 866
 		$charset = 'utf-8';
867
-		$texte = substr($texte,3);
867
+		$texte = substr($texte, 3);
868 868
 	}
869 869
 
870 870
 	// charset precise par le contenu (xml)
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
  * @return string
920 920
  *     Le texte coupé
921 921
 **/
922
-function spip_substr($c, $start=0, $length = NULL) {
922
+function spip_substr($c, $start = 0, $length = NULL) {
923 923
 	// Si ce n'est pas utf-8, utiliser substr
924 924
 	if ($GLOBALS['meta']['charset'] != 'utf-8') {
925 925
 		if ($length)
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 	if ($start > 0)
966 966
 		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
967 967
 	elseif ($start < 0)
968
-		return spip_substr_manuelle($c, spip_strlen($c)+$start, $length);
968
+		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
969 969
 
970 970
 	if (!$length)
971 971
 		return $c;
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
975 975
 		// (un caractere utf-8 prenant au maximum n bytes)
976 976
 		$n = 0; while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c));
977
-		$c = substr($c, 0, $n*$length);
977
+		$c = substr($c, 0, $n * $length);
978 978
 		// puis, tant qu'on est trop long, on coupe...
979 979
 		while (($l = spip_strlen($c)) > $length)
980 980
 			$c = substr($c, 0, $length - $l);
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 	}
983 983
 
984 984
 	// $length < 0
985
-	return spip_substr_manuelle($c, 0, spip_strlen($c)+$length);
985
+	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
986 986
 }
987 987
 
988 988
 /**
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
  * @return string
996 996
  *     La chaîne avec une majuscule sur le premier mot 
997 997
  */
998
-function spip_ucfirst($c){
998
+function spip_ucfirst($c) {
999 999
 	// Si ce n'est pas utf-8, utiliser ucfirst 
1000 1000
 	if ($GLOBALS['meta']['charset'] != 'utf-8')
1001 1001
 		return ucfirst($c);
@@ -1003,8 +1003,8 @@  discard block
 block discarded – undo
1003 1003
 	if (!init_mb_string())
1004 1004
 		return ucfirst($c);
1005 1005
 	
1006
-	$lettre1 = mb_strtoupper(spip_substr($c,0,1));
1007
-	return $lettre1.spip_substr($c,1);
1006
+	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1007
+	return $lettre1.spip_substr($c, 1);
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 	ecrire_meta('pcre_u',
1048 1048
 		$u = ($GLOBALS['meta']['charset'] == 'utf-8'
1049 1049
 		AND test_pcre_unicode())
1050
-			? 'u' :''
1050
+			? 'u' : ''
1051 1051
 	);
1052 1052
 }
1053 1053
 
Please login to merge, or discard this patch.
Braces   +187 added lines, -128 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 **/
22 22
 
23 23
 // securité
24
-if (!defined('_ECRIRE_INC_VERSION')) return;
24
+if (!defined('_ECRIRE_INC_VERSION')) {
25
+    return;
26
+}
25 27
 
26 28
 
27 29
 /**
@@ -38,11 +40,13 @@  discard block
 block discarded – undo
38 40
  *     false si le charset n'est pas décrit dans le répertoire charsets/
39 41
 **/
40 42
 function load_charset ($charset = 'AUTO') {
41
-	if ($charset == 'AUTO')
42
-		$charset = $GLOBALS['meta']['charset'];
43
+	if ($charset == 'AUTO') {
44
+			$charset = $GLOBALS['meta']['charset'];
45
+	}
43 46
 	$charset = trim(strtolower($charset));
44
-	if (isset($GLOBALS['CHARSET'][$charset]))
45
-		return $charset;
47
+	if (isset($GLOBALS['CHARSET'][$charset])) {
48
+			return $charset;
49
+	}
46 50
 
47 51
 	if ($charset == 'utf-8') {
48 52
 		$GLOBALS['CHARSET'][$charset] = array();
@@ -50,10 +54,15 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 	
52 56
 	// Quelques synonymes
53
-	if ($charset == '') $charset = 'iso-8859-1';
54
-	else if ($charset == 'windows-1250') $charset = 'cp1250';
55
-	else if ($charset == 'windows-1251') $charset = 'cp1251';
56
-	else if ($charset == 'windows-1256') $charset = 'cp1256';
57
+	if ($charset == '') {
58
+	    $charset = 'iso-8859-1';
59
+	} else if ($charset == 'windows-1250') {
60
+	    $charset = 'cp1250';
61
+	} else if ($charset == 'windows-1251') {
62
+	    $charset = 'cp1251';
63
+	} else if ($charset == 'windows-1256') {
64
+	    $charset = 'cp1256';
65
+	}
57 66
 
58 67
 	if (find_in_path($charset . '.php', 'charsets/', true)) {
59 68
 		return $charset;
@@ -88,8 +97,9 @@  discard block
 block discarded – undo
88 97
 		) {
89 98
 			mb_internal_encoding('utf-8');
90 99
 			$mb = 1;
91
-		} else
92
-			$mb = -1;
100
+		} else {
101
+					$mb = -1;
102
+		}
93 103
 	}
94 104
 
95 105
 	return ($mb == 1);
@@ -110,13 +120,14 @@  discard block
 block discarded – undo
110 120
 	static $iconv_ok;
111 121
 
112 122
 	if (!$iconv_ok) {
113
-		if (!function_exists('iconv'))
114
-			$iconv_ok = -1;
115
-		else {
116
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test')
117
-				$iconv_ok = 1;
118
-			else
119
-				$iconv_ok = -1;
123
+		if (!function_exists('iconv')) {
124
+					$iconv_ok = -1;
125
+		} else {
126
+			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
127
+							$iconv_ok = 1;
128
+			} else {
129
+							$iconv_ok = -1;
130
+			}
120 131
 		}
121 132
 	}
122 133
 	return ($iconv_ok == 1);
@@ -136,8 +147,11 @@  discard block
 block discarded – undo
136 147
 
137 148
 	if (!$pcre_ok) {
138 149
 		$s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
139
-		if (preg_match(',\W...\W,u', $s)) $pcre_ok = 1;
140
-		else $pcre_ok = -1;
150
+		if (preg_match(',\W...\W,u', $s)) {
151
+		    $pcre_ok = 1;
152
+		} else {
153
+		    $pcre_ok = -1;
154
+		}
141 155
 	}
142 156
 	return $pcre_ok == 1;
143 157
 }
@@ -164,8 +178,7 @@  discard block
 block discarded – undo
164 178
 				. '\x{100}-\x{24f}' // europeen etendu
165 179
 				. '\x{300}-\x{1cff}' // des tas de trucs
166 180
 			;
167
-		}
168
-		else {
181
+		} else {
169 182
 			// fallback a trois sous
170 183
 			$plage_unicode = '\w';
171 184
 		}
@@ -214,15 +227,19 @@  discard block
 block discarded – undo
214 227
 		return array_map('corriger_caracteres_windows', $texte);
215 228
 	}
216 229
 	
217
-	if ($charset=='AUTO') $charset = $GLOBALS['meta']['charset'];
230
+	if ($charset=='AUTO') {
231
+	    $charset = $GLOBALS['meta']['charset'];
232
+	}
218 233
 	if ($charset == 'utf-8') {
219 234
 		$p = chr(194);
220
-		if (strpos($texte,$p)==false)
221
-			return $texte;
235
+		if (strpos($texte,$p)==false) {
236
+					return $texte;
237
+		}
222 238
 	} else if ($charset == 'iso-8859-1') {
223 239
 		$p = '';
224
-	} else
225
-		return $texte;
240
+	} else {
241
+			return $texte;
242
+	}
226 243
 
227 244
 	if (!isset($trans[$charset][$charset_cible])) {
228 245
 		$trans[$charset][$charset_cible] = array(
@@ -260,8 +277,9 @@  discard block
 block discarded – undo
260 277
 			$p.chr(159) => "&#376;",
261 278
 		);
262 279
 		if ($charset_cible!='unicode'){
263
-			foreach($trans[$charset][$charset_cible] as $k=>$c)
264
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
280
+			foreach($trans[$charset][$charset_cible] as $k=>$c) {
281
+							$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
282
+			}
265 283
 		}
266 284
 	}
267 285
 
@@ -284,7 +302,9 @@  discard block
 block discarded – undo
284 302
  *     Texte converti
285 303
 **/
286 304
 function html2unicode($texte, $secure=false) {
287
-	if (strpos($texte,'&') === false) return $texte;
305
+	if (strpos($texte,'&') === false) {
306
+	    return $texte;
307
+	}
288 308
 	static $trans = array();
289 309
 	if (!$trans) {
290 310
 		global $CHARSET;
@@ -294,13 +314,14 @@  discard block
 block discarded – undo
294 314
 		}
295 315
 	}
296 316
 
297
-	if ($secure)
298
-		return str_replace(array_keys($trans),array_values($trans),$texte);
299
-	else
300
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'),array('&', '"', '<', '>'),
317
+	if ($secure) {
318
+			return str_replace(array_keys($trans),array_values($trans),$texte);
319
+	} else {
320
+			return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'),array('&', '"', '<', '>'),
301 321
 		  str_replace(array_keys($trans),array_values($trans),$texte)			
302 322
 		);
303
-}
323
+	}
324
+	}
304 325
 
305 326
 
306 327
 /**
@@ -319,8 +340,9 @@  discard block
 block discarded – undo
319 340
 		global $CHARSET;
320 341
 		load_charset('mathml');
321 342
 		
322
-		foreach ($CHARSET['mathml'] as $key => $val)
323
-			$trans["&$key;"] = $val;
343
+		foreach ($CHARSET['mathml'] as $key => $val) {
344
+					$trans["&$key;"] = $val;
345
+		}
324 346
 	}
325 347
 
326 348
 	return str_replace(array_keys($trans),array_values($trans),$texte);
@@ -347,10 +369,13 @@  discard block
 block discarded – undo
347 369
 function charset2unicode($texte, $charset='AUTO' /* $forcer: obsolete*/) {
348 370
 	static $trans;
349 371
 
350
-	if ($charset == 'AUTO')
351
-		$charset = $GLOBALS['meta']['charset'];
372
+	if ($charset == 'AUTO') {
373
+			$charset = $GLOBALS['meta']['charset'];
374
+	}
352 375
 
353
-	if ($charset == '') $charset = 'iso-8859-1';
376
+	if ($charset == '') {
377
+	    $charset = 'iso-8859-1';
378
+	}
354 379
 	$charset = strtolower($charset);
355 380
 
356 381
 	switch ($charset) {
@@ -368,7 +393,9 @@  discard block
 block discarded – undo
368 393
 			if ($order = mb_detect_order() # mb_string connait-il $charset?
369 394
 			AND mb_detect_order($charset)) {
370 395
 				$s = mb_convert_encoding($texte, 'utf-8', $charset);
371
-				if ($s && $s != $texte) return utf_8_to_unicode($s);
396
+				if ($s && $s != $texte) {
397
+				    return utf_8_to_unicode($s);
398
+				}
372 399
 			}
373 400
 			mb_detect_order($order); # remettre comme precedemment
374 401
 		}
@@ -377,20 +404,24 @@  discard block
 block discarded – undo
377 404
 		if (!isset($trans[$charset])) {
378 405
 			global $CHARSET;
379 406
 			if ($cset = load_charset($charset)
380
-			AND is_array($CHARSET[$cset]))
381
-				foreach ($CHARSET[$cset] as $key => $val) {
407
+			AND is_array($CHARSET[$cset])) {
408
+							foreach ($CHARSET[$cset] as $key => $val) {
382 409
 					$trans[$charset][chr($key)] = '&#'.$val.';';
383 410
 			}
411
+			}
412
+		}
413
+		if (count($trans[$charset])) {
414
+					return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
384 415
 		}
385
-		if (count($trans[$charset]))
386
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
387 416
 
388 417
 		// Sinon demander a iconv (malgre le fait qu'il coupe quand un
389 418
 		// caractere n'appartient pas au charset, mais c'est un probleme
390 419
 		// surtout en utf-8, gere ci-dessus)
391 420
 		if (test_iconv()) {
392 421
 			$s = iconv($charset, 'utf-32le', $texte);
393
-			if ($s) return utf_32_to_unicode($s);
422
+			if ($s) {
423
+			    return utf_32_to_unicode($s);
424
+			}
394 425
 		}
395 426
 
396 427
 		// Au pire ne rien faire
@@ -418,8 +449,9 @@  discard block
 block discarded – undo
418 449
 	static $CHARSET_REVERSE;
419 450
 	static $trans = array();
420 451
 	
421
-	if ($charset == 'AUTO')
422
-		$charset = $GLOBALS['meta']['charset'];
452
+	if ($charset == 'AUTO') {
453
+			$charset = $GLOBALS['meta']['charset'];
454
+	}
423 455
 
424 456
 	switch($charset) {
425 457
 	case 'utf-8':
@@ -442,8 +474,7 @@  discard block
 block discarded – undo
442 474
 					$s = $CHARSET_REVERSE[$charset][$e];
443 475
 					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
444 476
 					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
445
-				}
446
-				else{
477
+				} else{
447 478
 					$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
448 479
 					$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
449 480
 				}
@@ -485,13 +516,15 @@  discard block
 block discarded – undo
485 516
 		if (!isset($trans[$charset])) {
486 517
 			global $CHARSET;
487 518
 			if ($cset = load_charset($charset)
488
-			AND is_array($CHARSET[$cset]))
489
-				foreach ($CHARSET[$cset] as $key => $val) {
519
+			AND is_array($CHARSET[$cset])) {
520
+							foreach ($CHARSET[$cset] as $key => $val) {
490 521
 					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
491 522
 			}
523
+			}
524
+		}
525
+		if (count($trans[$charset])) {
526
+					return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
492 527
 		}
493
-		if (count($trans[$charset]))
494
-			return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte);
495 528
 		return $texte;
496 529
 	}
497 530
 	return unicode2charset(charset2unicode($texte, $charset));
@@ -552,18 +585,15 @@  discard block
 block discarded – undo
552 585
 			// 4 chars representing one unicode character
553 586
 			$thisLetter = substr ($source, $pos, 4);
554 587
 			$pos += 4;
555
-		}
556
-		else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
588
+		} else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
557 589
 			// 3 chars representing one unicode character
558 590
 			$thisLetter = substr ($source, $pos, 3);
559 591
 			$pos += 3;
560
-		}
561
-		else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
592
+		} else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
562 593
 			// 2 chars representing one unicode character
563 594
 			$thisLetter = substr ($source, $pos, 2);
564 595
 			$pos += 2;
565
-		}
566
-		else {
596
+		} else {
567 597
 			// 1 char (lower ascii)
568 598
 			$thisLetter = substr ($source, $pos, 1);
569 599
 			$pos += 1;
@@ -571,9 +601,9 @@  discard block
 block discarded – undo
571 601
 			$ischar = true;
572 602
 		}
573 603
 
574
-		if ($ischar)
575
-			$encodedString .= $char;
576
-		else {	// process the string representing the letter to a unicode entity
604
+		if ($ischar) {
605
+					$encodedString .= $char;
606
+		} else {	// process the string representing the letter to a unicode entity
577 607
 			$thisLen = strlen ($thisLetter);
578 608
 			$thisPos = 0;
579 609
 			$decimalCode = 0;
@@ -624,11 +654,13 @@  discard block
 block discarded – undo
624 654
 		$words = unpack("V*", substr($source, 0, 1024));
625 655
 		$source = substr($source, 1024);
626 656
 		foreach ($words as $word) {
627
-			if ($word < 128)
628
-				$texte .= chr($word);
657
+			if ($word < 128) {
658
+							$texte .= chr($word);
659
+			}
629 660
 			// ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
630
-			else if ($word != 65279)
631
-				$texte .= '&#'.$word.';';
661
+			else if ($word != 65279) {
662
+							$texte .= '&#'.$word.';';
663
+			}
632 664
 		}
633 665
 	}
634 666
 	return $texte;
@@ -648,14 +680,18 @@  discard block
 block discarded – undo
648 680
  *    Caractère utf8 si trouvé, '' sinon
649 681
 **/
650 682
 function caractere_utf_8($num) {
651
-	if($num<128)
652
-		return chr($num);
653
-	if($num<2048)
654
-		return chr(($num>>6)+192).chr(($num&63)+128);
655
-	if($num<65536)
656
-		return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
657
-	if($num<1114112)
658
-		return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
683
+	if($num<128) {
684
+			return chr($num);
685
+	}
686
+	if($num<2048) {
687
+			return chr(($num>>6)+192).chr(($num&63)+128);
688
+	}
689
+	if($num<65536) {
690
+			return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
691
+	}
692
+	if($num<1114112) {
693
+			return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
694
+	}
659 695
 	return '';
660 696
 }
661 697
 
@@ -672,21 +708,23 @@  discard block
 block discarded – undo
672 708
 	// 1. Entites &#128; et suivantes
673 709
 	$vu = array();
674 710
 	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
675
-	$texte, $regs, PREG_SET_ORDER))
676
-	foreach ($regs as $reg) {
711
+	$texte, $regs, PREG_SET_ORDER)) {
712
+		foreach ($regs as $reg) {
677 713
 		if ($reg[1]>127 AND !isset($vu[$reg[0]]))
678 714
 			$vu[$reg[0]] = caractere_utf_8($reg[1]);
679 715
 	}
716
+	}
680 717
 	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
681 718
 
682 719
 	// 2. Entites > &#xFF;
683 720
 	//$vu = array();
684 721
 	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
685
-	$texte, $regs, PREG_SET_ORDER))
686
-	foreach ($regs as $reg) {
722
+	$texte, $regs, PREG_SET_ORDER)) {
723
+		foreach ($regs as $reg) {
687 724
 		if (!isset($vu[$reg[0]]))
688 725
 			$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
689 726
 	}
727
+	}
690 728
 	return str_replace(array_keys($vu), array_values($vu), $texte);
691 729
 
692 730
 }
@@ -719,8 +757,9 @@  discard block
 block discarded – undo
719 757
  *     Texte converti
720 758
 **/
721 759
 function javascript_to_unicode ($texte) {
722
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs))
723
-		$texte = str_replace($regs[0],"&#".hexdec($regs[1]).";", $texte);
760
+	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
761
+			$texte = str_replace($regs[0],"&#".hexdec($regs[1]).";", $texte);
762
+	}
724 763
 	return $texte;
725 764
 }
726 765
 
@@ -733,8 +772,9 @@  discard block
 block discarded – undo
733 772
  *     Texte converti
734 773
 **/
735 774
 function javascript_to_binary ($texte) {
736
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs))
737
-		$texte = str_replace($regs[0],chr(hexdec($regs[1])), $texte);
775
+	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
776
+			$texte = str_replace($regs[0],chr(hexdec($regs[1])), $texte);
777
+	}
738 778
 	return $texte;
739 779
 }
740 780
 
@@ -742,10 +782,12 @@  discard block
 block discarded – undo
742 782
 // http://doc.spip.org/@translitteration_rapide
743 783
 function translitteration_rapide($texte, $charset='AUTO', $complexe='') {
744 784
 	static $trans;
745
-	if ($charset == 'AUTO')
746
-		$charset = $GLOBALS['meta']['charset'];
747
-	if (!strlen($texte))
748
-		return $texte;
785
+	if ($charset == 'AUTO') {
786
+			$charset = $GLOBALS['meta']['charset'];
787
+	}
788
+	if (!strlen($texte)) {
789
+			return $texte;
790
+	}
749 791
 
750 792
 	$table_translit ='translit'.$complexe;
751 793
 
@@ -753,8 +795,9 @@  discard block
 block discarded – undo
753 795
 	if (!$trans[$complexe]) {
754 796
 		global $CHARSET;
755 797
 		load_charset($table_translit);
756
-		foreach ($CHARSET[$table_translit] as $key => $val)
757
-			$trans[$complexe][caractere_utf_8($key)] = $val;
798
+		foreach ($CHARSET[$table_translit] as $key => $val) {
799
+					$trans[$complexe][caractere_utf_8($key)] = $val;
800
+		}
758 801
 	}
759 802
 
760 803
 	return str_replace(array_keys($trans[$complexe]),array_values($trans[$complexe]),$texte);
@@ -869,31 +912,37 @@  discard block
 block discarded – undo
869 912
 
870 913
 	// charset precise par le contenu (xml)
871 914
 	else if (preg_match(
872
-	',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs))
873
-		$charset = trim(strtolower($regs[1]));
915
+	',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
916
+			$charset = trim(strtolower($regs[1]));
917
+	}
874 918
 	// charset precise par le contenu (html)
875 919
 	else if (preg_match(
876 920
 	',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
877 921
 	$texte, $regs)
878 922
 	# eviter #CHARSET des squelettes
879
-	AND (($tmp = trim(strtolower($regs[2]))) != 'charset'))
880
-		$charset = $tmp;
923
+	AND (($tmp = trim(strtolower($regs[2]))) != 'charset')) {
924
+			$charset = $tmp;
925
+	}
881 926
 	// charset de la reponse http
882
-	else if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs))
883
-		$charset = trim(strtolower($regs[1]));
884
-	else $charset = '';
927
+	else if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
928
+			$charset = trim(strtolower($regs[1]));
929
+	} else {
930
+	    $charset = '';
931
+	}
885 932
 	// normaliser les noms du shif-jis japonais
886
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset))
887
-		$charset = 'shift-jis';
933
+	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
934
+			$charset = 'shift-jis';
935
+	}
888 936
 
889 937
 	if ($charset) {
890 938
 		spip_log("charset: $charset");
891 939
 	} else {
892 940
 		// valeur par defaut
893
-		if (is_utf8($texte))
894
-			$charset = 'utf-8';
895
-		else
896
-			$charset = 'iso-8859-1';
941
+		if (is_utf8($texte)) {
942
+					$charset = 'utf-8';
943
+		} else {
944
+					$charset = 'iso-8859-1';
945
+		}
897 946
 		spip_log("charset probable: $charset");
898 947
 	}
899 948
 
@@ -922,18 +971,20 @@  discard block
 block discarded – undo
922 971
 function spip_substr($c, $start=0, $length = NULL) {
923 972
 	// Si ce n'est pas utf-8, utiliser substr
924 973
 	if ($GLOBALS['meta']['charset'] != 'utf-8') {
925
-		if ($length)
926
-			return substr($c, $start, $length);
927
-		else
928
-			substr($c, $start);
974
+		if ($length) {
975
+					return substr($c, $start, $length);
976
+		} else {
977
+					substr($c, $start);
978
+		}
929 979
 	}
930 980
 
931 981
 	// Si utf-8, voir si on dispose de mb_string
932 982
 	if (init_mb_string()) {
933
-		if ($length)
934
-			return mb_substr($c, $start, $length);
935
-		else
936
-			return mb_substr($c, $start);
983
+		if ($length) {
984
+					return mb_substr($c, $start, $length);
985
+		} else {
986
+					return mb_substr($c, $start);
987
+		}
937 988
 	}
938 989
 
939 990
 	// Version manuelle (cf. ci-dessous)
@@ -958,17 +1009,20 @@  discard block
 block discarded – undo
958 1009
 function spip_substr_manuelle($c, $start, $length = NULL) {
959 1010
 
960 1011
 	// Cas pathologique
961
-	if ($length === 0)
962
-		return '';
1012
+	if ($length === 0) {
1013
+			return '';
1014
+	}
963 1015
 
964 1016
 	// S'il y a un demarrage, on se positionne
965
-	if ($start > 0)
966
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
967
-	elseif ($start < 0)
968
-		return spip_substr_manuelle($c, spip_strlen($c)+$start, $length);
1017
+	if ($start > 0) {
1018
+			$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1019
+	} elseif ($start < 0) {
1020
+			return spip_substr_manuelle($c, spip_strlen($c)+$start, $length);
1021
+	}
969 1022
 
970
-	if (!$length)
971
-		return $c;
1023
+	if (!$length) {
1024
+			return $c;
1025
+	}
972 1026
 
973 1027
 	if ($length > 0) {
974 1028
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
@@ -976,8 +1030,9 @@  discard block
 block discarded – undo
976 1030
 		$n = 0; while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c));
977 1031
 		$c = substr($c, 0, $n*$length);
978 1032
 		// puis, tant qu'on est trop long, on coupe...
979
-		while (($l = spip_strlen($c)) > $length)
980
-			$c = substr($c, 0, $length - $l);
1033
+		while (($l = spip_strlen($c)) > $length) {
1034
+					$c = substr($c, 0, $length - $l);
1035
+		}
981 1036
 		return $c;
982 1037
 	}
983 1038
 
@@ -997,11 +1052,13 @@  discard block
 block discarded – undo
997 1052
  */
998 1053
 function spip_ucfirst($c){
999 1054
 	// Si ce n'est pas utf-8, utiliser ucfirst 
1000
-	if ($GLOBALS['meta']['charset'] != 'utf-8')
1001
-		return ucfirst($c);
1055
+	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1056
+			return ucfirst($c);
1057
+	}
1002 1058
 	// Si on n'a pas mb_* on utilise ucfirst
1003
-	if (!init_mb_string())
1004
-		return ucfirst($c);
1059
+	if (!init_mb_string()) {
1060
+			return ucfirst($c);
1061
+	}
1005 1062
 	
1006 1063
 	$lettre1 = mb_strtoupper(spip_substr($c,0,1));
1007 1064
 	return $lettre1.spip_substr($c,1);
@@ -1022,12 +1079,14 @@  discard block
 block discarded – undo
1022 1079
 	$c = str_replace("\r\n", "\n", $c);
1023 1080
 	
1024 1081
 	// Si ce n'est pas utf-8, utiliser strlen
1025
-	if ($GLOBALS['meta']['charset'] != 'utf-8')
1026
-		return strlen($c);
1082
+	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1083
+			return strlen($c);
1084
+	}
1027 1085
 
1028 1086
 	// Sinon, utiliser mb_strlen() si disponible
1029
-	if (init_mb_string())
1030
-		return mb_strlen($c);
1087
+	if (init_mb_string()) {
1088
+			return mb_strlen($c);
1089
+	}
1031 1090
 
1032 1091
 	// Methode manuelle : on supprime les bytes 10......,
1033 1092
 	// on compte donc les ascii (0.......) et les demarrages
Please login to merge, or discard this patch.
ecrire/inc/cvt_autosave.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 /**
16 16
  * Nettoyer les echappements
17
- * @param $val
17
+ * @param string $val
18 18
  * @return string
19 19
  */
20 20
 function autosave_clean_value($val){
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @return string
19 19
  */
20 20
 function autosave_clean_value($val){
21
-	return stripslashes(urldecode($val));
21
+    return stripslashes(urldecode($val));
22 22
 }
23 23
 
24 24
 /**
@@ -29,37 +29,37 @@  discard block
 block discarded – undo
29 29
  * @return array
30 30
  */
31 31
 function cvtautosave_formulaire_charger($flux){
32
-	if (is_array($flux['data'])
33
-	  AND isset($flux['data']['_autosave_id'])
34
-	  AND $cle_autosave = $flux['data']['_autosave_id']){
32
+    if (is_array($flux['data'])
33
+      AND isset($flux['data']['_autosave_id'])
34
+      AND $cle_autosave = $flux['data']['_autosave_id']){
35 35
 
36
-		$form = $flux['args']['form'];
37
-		$je_suis_poste = $flux['args']['je_suis_poste'];
36
+        $form = $flux['args']['form'];
37
+        $je_suis_poste = $flux['args']['je_suis_poste'];
38 38
 
39
-		$cle_autosave = serialize($cle_autosave);
40
-		$cle_autosave = $form."_".md5($cle_autosave);
39
+        $cle_autosave = serialize($cle_autosave);
40
+        $cle_autosave = $form."_".md5($cle_autosave);
41 41
 
42
-		// si on a un backup en session et qu'on est au premier chargement, non poste
43
-		// on restitue les donnees
44
-		if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
45
-		  AND !$je_suis_poste) {
46
-			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
47
-			foreach ($vars as $key=>$val) {
48
-				if (isset($flux['data'][$key]))
49
-					$flux['data'][$key] = (is_string($val)?autosave_clean_value($val):array_map('autosave_clean_value',$val));
50
-			}
51
-		}
42
+        // si on a un backup en session et qu'on est au premier chargement, non poste
43
+        // on restitue les donnees
44
+        if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
45
+          AND !$je_suis_poste) {
46
+            parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
47
+            foreach ($vars as $key=>$val) {
48
+                if (isset($flux['data'][$key]))
49
+                    $flux['data'][$key] = (is_string($val)?autosave_clean_value($val):array_map('autosave_clean_value',$val));
50
+            }
51
+        }
52 52
 
53
-		/**
54
-		 * Envoyer le input hidden et le bout de js qui l'utilisera
55
-		 */
56
-		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
57
-		  .'<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
53
+        /**
54
+         * Envoyer le input hidden et le bout de js qui l'utilisera
55
+         */
56
+        $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
57
+            .'<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
58 58
 		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"'.$GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon");
59 59
 			});/*]]>*/</script>';
60 60
 
61
-	}
62
-	return $flux;
61
+    }
62
+    return $flux;
63 63
 }
64 64
 
65 65
 /**
@@ -70,32 +70,32 @@  discard block
 block discarded – undo
70 70
  * @return
71 71
  */
72 72
 function cvtautosave_formulaire_traiter($flux){
73
-	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
74
-	// on elimine les donnees de la session
75
-	if ($cle_autosave = _request('autosave')){
76
-		include_spip('inc/session');
77
-		session_set('session_autosave_'.$cle_autosave, null);
78
-	}
73
+    // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
74
+    // on elimine les donnees de la session
75
+    if ($cle_autosave = _request('autosave')){
76
+        include_spip('inc/session');
77
+        session_set('session_autosave_'.$cle_autosave, null);
78
+    }
79 79
 
80
-	if (isset($GLOBALS['visiteur_session']) AND $GLOBALS['visiteur_session']){
81
-		// delai par defaut avant purge d'un backup de form : 72H
82
-		if (!defined('_AUTOSAVE_GB_DELAY')) define('_AUTOSAVE_GB_DELAY',72*3600);
83
-		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
84
-		// purger aussi toutes les vieilles autosave
85
-		$session = $GLOBALS['visiteur_session'];
86
-		foreach($session as $k=>$v){
87
-			if (strncmp($k,'session_autosave_',17)==0){
88
-				$timestamp = 0;
89
-				if (preg_match(",&__timestamp=(\d+)$,",$v,$m)){
90
-					$timestamp = intval($m[1]);
91
-				}
92
-				if ($timestamp<$time_too_old)
93
-					session_set($k, null);
94
-			}
95
-		}
96
-	}
80
+    if (isset($GLOBALS['visiteur_session']) AND $GLOBALS['visiteur_session']){
81
+        // delai par defaut avant purge d'un backup de form : 72H
82
+        if (!defined('_AUTOSAVE_GB_DELAY')) define('_AUTOSAVE_GB_DELAY',72*3600);
83
+        $time_too_old = time() - _AUTOSAVE_GB_DELAY;
84
+        // purger aussi toutes les vieilles autosave
85
+        $session = $GLOBALS['visiteur_session'];
86
+        foreach($session as $k=>$v){
87
+            if (strncmp($k,'session_autosave_',17)==0){
88
+                $timestamp = 0;
89
+                if (preg_match(",&__timestamp=(\d+)$,",$v,$m)){
90
+                    $timestamp = intval($m[1]);
91
+                }
92
+                if ($timestamp<$time_too_old)
93
+                    session_set($k, null);
94
+            }
95
+        }
96
+    }
97 97
 	
98
-	return $flux;
98
+    return $flux;
99 99
 }
100 100
 
101 101
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 /**
16 18
  * Nettoyer les echappements
@@ -45,8 +47,9 @@  discard block
 block discarded – undo
45 47
 		  AND !$je_suis_poste) {
46 48
 			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
47 49
 			foreach ($vars as $key=>$val) {
48
-				if (isset($flux['data'][$key]))
49
-					$flux['data'][$key] = (is_string($val)?autosave_clean_value($val):array_map('autosave_clean_value',$val));
50
+				if (isset($flux['data'][$key])) {
51
+									$flux['data'][$key] = (is_string($val)?autosave_clean_value($val):array_map('autosave_clean_value',$val));
52
+				}
50 53
 			}
51 54
 		}
52 55
 
@@ -79,7 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 	if (isset($GLOBALS['visiteur_session']) AND $GLOBALS['visiteur_session']){
81 84
 		// delai par defaut avant purge d'un backup de form : 72H
82
-		if (!defined('_AUTOSAVE_GB_DELAY')) define('_AUTOSAVE_GB_DELAY',72*3600);
85
+		if (!defined('_AUTOSAVE_GB_DELAY')) {
86
+		    define('_AUTOSAVE_GB_DELAY',72*3600);
87
+		}
83 88
 		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
84 89
 		// purger aussi toutes les vieilles autosave
85 90
 		$session = $GLOBALS['visiteur_session'];
@@ -89,8 +94,9 @@  discard block
 block discarded – undo
89 94
 				if (preg_match(",&__timestamp=(\d+)$,",$v,$m)){
90 95
 					$timestamp = intval($m[1]);
91 96
 				}
92
-				if ($timestamp<$time_too_old)
93
-					session_set($k, null);
97
+				if ($timestamp<$time_too_old) {
98
+									session_set($k, null);
99
+				}
94 100
 			}
95 101
 		}
96 102
 	}
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @param $val
18 18
  * @return string
19 19
  */
20
-function autosave_clean_value($val){
20
+function autosave_clean_value($val) {
21 21
 	return stripslashes(urldecode($val));
22 22
 }
23 23
 
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
  * @param array $flux
29 29
  * @return array
30 30
  */
31
-function cvtautosave_formulaire_charger($flux){
31
+function cvtautosave_formulaire_charger($flux) {
32 32
 	if (is_array($flux['data'])
33 33
 	  AND isset($flux['data']['_autosave_id'])
34
-	  AND $cle_autosave = $flux['data']['_autosave_id']){
34
+	  AND $cle_autosave = $flux['data']['_autosave_id']) {
35 35
 
36 36
 		$form = $flux['args']['form'];
37 37
 		$je_suis_poste = $flux['args']['je_suis_poste'];
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
47 47
 			foreach ($vars as $key=>$val) {
48 48
 				if (isset($flux['data'][$key]))
49
-					$flux['data'][$key] = (is_string($val)?autosave_clean_value($val):array_map('autosave_clean_value',$val));
49
+					$flux['data'][$key] = (is_string($val) ?autosave_clean_value($val) : array_map('autosave_clean_value', $val));
50 50
 			}
51 51
 		}
52 52
 
@@ -69,27 +69,27 @@  discard block
 block discarded – undo
69 69
  * @param $flux
70 70
  * @return
71 71
  */
72
-function cvtautosave_formulaire_traiter($flux){
72
+function cvtautosave_formulaire_traiter($flux) {
73 73
 	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
74 74
 	// on elimine les donnees de la session
75
-	if ($cle_autosave = _request('autosave')){
75
+	if ($cle_autosave = _request('autosave')) {
76 76
 		include_spip('inc/session');
77 77
 		session_set('session_autosave_'.$cle_autosave, null);
78 78
 	}
79 79
 
80
-	if (isset($GLOBALS['visiteur_session']) AND $GLOBALS['visiteur_session']){
80
+	if (isset($GLOBALS['visiteur_session']) AND $GLOBALS['visiteur_session']) {
81 81
 		// delai par defaut avant purge d'un backup de form : 72H
82
-		if (!defined('_AUTOSAVE_GB_DELAY')) define('_AUTOSAVE_GB_DELAY',72*3600);
82
+		if (!defined('_AUTOSAVE_GB_DELAY')) define('_AUTOSAVE_GB_DELAY', 72 * 3600);
83 83
 		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
84 84
 		// purger aussi toutes les vieilles autosave
85 85
 		$session = $GLOBALS['visiteur_session'];
86
-		foreach($session as $k=>$v){
87
-			if (strncmp($k,'session_autosave_',17)==0){
86
+		foreach ($session as $k=>$v) {
87
+			if (strncmp($k, 'session_autosave_', 17) == 0) {
88 88
 				$timestamp = 0;
89
-				if (preg_match(",&__timestamp=(\d+)$,",$v,$m)){
89
+				if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
90 90
 					$timestamp = intval($m[1]);
91 91
 				}
92
-				if ($timestamp<$time_too_old)
92
+				if ($timestamp < $time_too_old)
93 93
 					session_set($k, null);
94 94
 			}
95 95
 		}
Please login to merge, or discard this patch.
ecrire/inc/documents.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * http://doc.spip.org/@get_spip_doc
35 35
  *
36 36
  * @param string $fichier
37
- * @return bool|string
37
+ * @return string|false
38 38
  */
39 39
 function get_spip_doc($fichier) {
40 40
 	// fichier distant
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
  * @param string $ext
112 112
  * @param string $orig
113 113
  * @param string $source
114
- * @return bool|mixed|string
114
+ * @return string|false
115 115
  */
116 116
 function copier_document($ext, $orig, $source) {
117 117
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
  * http://doc.spip.org/@determine_upload
143 143
  *
144 144
  * @param string $type
145
- * @return bool|string
145
+ * @return false|string
146 146
  */
147 147
 function determine_upload($type='') {
148 148
 	if(!function_exists('autoriser'))
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
  * @param string $source
173 173
  * @param string $dest
174 174
  * @param bool $move
175
- * @return bool|mixed|string
175
+ * @return string|false
176 176
  */
177 177
 function deplacer_fichier_upload($source, $dest, $move=false) {
178 178
 	// Securite
Please login to merge, or discard this patch.
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
  * @return string
23 23
  */
24 24
 function set_spip_doc($fichier) {
25
-	if (strpos($fichier, _DIR_IMG) === 0)
26
-		return substr($fichier, strlen(_DIR_IMG));
27
-	else
28
-		return $fichier; // ex: fichier distant
25
+    if (strpos($fichier, _DIR_IMG) === 0)
26
+        return substr($fichier, strlen(_DIR_IMG));
27
+    else
28
+        return $fichier; // ex: fichier distant
29 29
 }
30 30
 
31 31
 /**
@@ -37,22 +37,22 @@  discard block
 block discarded – undo
37 37
  * @return bool|string
38 38
  */
39 39
 function get_spip_doc($fichier) {
40
-	// fichier distant
41
-	if (preg_match(',^\w+://,', $fichier))
42
-		return $fichier;
43
-
44
-	// gestion d'erreurs, fichier=''
45
-	if (!strlen($fichier))
46
-		return false;
47
-
48
-	$fichier = (
49
-		    strncmp($fichier,_DIR_IMG, strlen(_DIR_IMG))!=0
50
-		)
51
-		? _DIR_IMG . $fichier
52
-		: $fichier ;
53
-
54
-	// fichier normal
55
-	return $fichier;
40
+    // fichier distant
41
+    if (preg_match(',^\w+://,', $fichier))
42
+        return $fichier;
43
+
44
+    // gestion d'erreurs, fichier=''
45
+    if (!strlen($fichier))
46
+        return false;
47
+
48
+    $fichier = (
49
+            strncmp($fichier,_DIR_IMG, strlen(_DIR_IMG))!=0
50
+        )
51
+        ? _DIR_IMG . $fichier
52
+        : $fichier ;
53
+
54
+    // fichier normal
55
+    return $fichier;
56 56
 }
57 57
 
58 58
 /**
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
  * @return string
65 65
  */
66 66
 function creer_repertoire_documents($ext) {
67
-	$rep = sous_repertoire(_DIR_IMG, $ext);
67
+    $rep = sous_repertoire(_DIR_IMG, $ext);
68 68
 
69
-	if (!$ext OR !$rep) {
70
-		spip_log("creer_repertoire_documents '$rep' interdit");
71
-		exit;
72
-	}
69
+    if (!$ext OR !$rep) {
70
+        spip_log("creer_repertoire_documents '$rep' interdit");
71
+        exit;
72
+    }
73 73
 
74
-	// Cette variable de configuration peut etre posee par un plugin
75
-	// par exemple acces_restreint
76
-	if (isset($GLOBALS['meta']["creer_htaccess"]) AND $GLOBALS['meta']["creer_htaccess"] == 'oui') {
77
-		include_spip('inc/acces');
78
-		verifier_htaccess($rep);
79
-	}
74
+    // Cette variable de configuration peut etre posee par un plugin
75
+    // par exemple acces_restreint
76
+    if (isset($GLOBALS['meta']["creer_htaccess"]) AND $GLOBALS['meta']["creer_htaccess"] == 'oui') {
77
+        include_spip('inc/acces');
78
+        verifier_htaccess($rep);
79
+    }
80 80
 
81
-	return $rep;
81
+    return $rep;
82 82
 }
83 83
 
84 84
 /**
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
  * @param string $nom
90 90
  */
91 91
 function effacer_repertoire_temporaire($nom) {
92
-	$d = opendir($nom);
93
-	while (($f = readdir($d)) !== false) {
94
-		if (is_file("$nom/$f"))
95
-			spip_unlink("$nom/$f");
96
-		else if ($f <> '.' AND $f <> '..'
97
-		AND is_dir("$nom/$f"))
98
-			effacer_repertoire_temporaire("$nom/$f");
99
-	}
100
-	closedir($d);
101
-	@rmdir($nom);
92
+    $d = opendir($nom);
93
+    while (($f = readdir($d)) !== false) {
94
+        if (is_file("$nom/$f"))
95
+            spip_unlink("$nom/$f");
96
+        else if ($f <> '.' AND $f <> '..'
97
+        AND is_dir("$nom/$f"))
98
+            effacer_repertoire_temporaire("$nom/$f");
99
+    }
100
+    closedir($d);
101
+    @rmdir($nom);
102 102
 }
103 103
 
104 104
 //
@@ -115,25 +115,25 @@  discard block
 block discarded – undo
115 115
  */
116 116
 function copier_document($ext, $orig, $source) {
117 117
 
118
-	$orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
119
-	$dir = creer_repertoire_documents($ext);
120
-	$dest = preg_replace("/[^.=\w-]+/", "_",
121
-			translitteration(preg_replace("/\.([^.]+)$/", "",
122
-						      preg_replace("/<[^>]*>/", '', basename($orig)))));
118
+    $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
119
+    $dir = creer_repertoire_documents($ext);
120
+    $dest = preg_replace("/[^.=\w-]+/", "_",
121
+            translitteration(preg_replace("/\.([^.]+)$/", "",
122
+                                preg_replace("/<[^>]*>/", '', basename($orig)))));
123 123
 
124
-	// ne pas accepter de noms de la forme -r90.jpg qui sont reserves
125
-	// pour les images transformees par rotation (action/documenter)
126
-	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
124
+    // ne pas accepter de noms de la forme -r90.jpg qui sont reserves
125
+    // pour les images transformees par rotation (action/documenter)
126
+    $dest = preg_replace(',-r(90|180|270)$,', '', $dest);
127 127
 
128
-	// Si le document "source" est deja au bon endroit, ne rien faire
129
-	if ($source == ($dir . $dest . '.' . $ext))
130
-		return $source;
128
+    // Si le document "source" est deja au bon endroit, ne rien faire
129
+    if ($source == ($dir . $dest . '.' . $ext))
130
+        return $source;
131 131
 
132
-	// sinon tourner jusqu'a trouver un numero correct
133
-	$n = 0;
134
-	while (@file_exists($newFile = $dir . $dest .($n++ ? ('-'.$n) : '').'.'.$ext));
132
+    // sinon tourner jusqu'a trouver un numero correct
133
+    $n = 0;
134
+    while (@file_exists($newFile = $dir . $dest .($n++ ? ('-'.$n) : '').'.'.$ext));
135 135
 
136
-	return deplacer_fichier_upload($source, $newFile);
136
+    return deplacer_fichier_upload($source, $newFile);
137 137
 }
138 138
 
139 139
 /**
@@ -145,23 +145,23 @@  discard block
 block discarded – undo
145 145
  * @return bool|string
146 146
  */
147 147
 function determine_upload($type='') {
148
-	if(!function_exists('autoriser'))
149
-		include_spip('inc/autoriser');
148
+    if(!function_exists('autoriser'))
149
+        include_spip('inc/autoriser');
150 150
 	
151
-	if (!autoriser('chargerftp')
152
-	OR $type == 'logos') # on ne le permet pas pour les logos
153
-		return false;
154
-
155
-	$repertoire = _DIR_TRANSFERT;
156
-	if (!@is_dir($repertoire)) {
157
-		$repertoire = str_replace(_DIR_TMP, '', $repertoire);
158
-		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
159
-	}
160
-
161
-	if (!$GLOBALS['visiteur_session']['restreint'])
162
-		return $repertoire;
163
-	else
164
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
151
+    if (!autoriser('chargerftp')
152
+    OR $type == 'logos') # on ne le permet pas pour les logos
153
+        return false;
154
+
155
+    $repertoire = _DIR_TRANSFERT;
156
+    if (!@is_dir($repertoire)) {
157
+        $repertoire = str_replace(_DIR_TMP, '', $repertoire);
158
+        $repertoire = sous_repertoire(_DIR_TMP, $repertoire);
159
+    }
160
+
161
+    if (!$GLOBALS['visiteur_session']['restreint'])
162
+        return $repertoire;
163
+    else
164
+        return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
165 165
 }
166 166
 
167 167
 /**
@@ -175,28 +175,28 @@  discard block
 block discarded – undo
175 175
  * @return bool|mixed|string
176 176
  */
177 177
 function deplacer_fichier_upload($source, $dest, $move=false) {
178
-	// Securite
179
-	if (substr($dest,0,strlen(_DIR_RACINE))==_DIR_RACINE)
180
-		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest,strlen(_DIR_RACINE)));
181
-	else
182
-		$dest = preg_replace(',\.\.+,', '.', $dest);
183
-
184
-	if ($move)	$ok = @rename($source, $dest);
185
-	else				$ok = @copy($source, $dest);
186
-	if (!$ok) $ok = @move_uploaded_file($source, $dest);
187
-	if ($ok)
188
-		@chmod($dest, _SPIP_CHMOD & ~0111);
189
-	else {
190
-		$f = @fopen($dest,'w');
191
-		if ($f) {
192
-			fclose ($f);
193
-		} else {
194
-			include_spip('inc/flock');
195
-			raler_fichier($dest);
196
-		}
197
-		spip_unlink($dest);
198
-	}
199
-	return $ok ? $dest : false;
178
+    // Securite
179
+    if (substr($dest,0,strlen(_DIR_RACINE))==_DIR_RACINE)
180
+        $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest,strlen(_DIR_RACINE)));
181
+    else
182
+        $dest = preg_replace(',\.\.+,', '.', $dest);
183
+
184
+    if ($move)	$ok = @rename($source, $dest);
185
+    else				$ok = @copy($source, $dest);
186
+    if (!$ok) $ok = @move_uploaded_file($source, $dest);
187
+    if ($ok)
188
+        @chmod($dest, _SPIP_CHMOD & ~0111);
189
+    else {
190
+        $f = @fopen($dest,'w');
191
+        if ($f) {
192
+            fclose ($f);
193
+        } else {
194
+            include_spip('inc/flock');
195
+            raler_fichier($dest);
196
+        }
197
+        spip_unlink($dest);
198
+    }
199
+    return $ok ? $dest : false;
200 200
 }
201 201
 
202 202
 
@@ -206,50 +206,50 @@  discard block
 block discarded – undo
206 206
 // pour les autres erreurs affiche le message d'erreur et meurt
207 207
 // http://doc.spip.org/@check_upload_error
208 208
 function check_upload_error($error, $msg='', $return=false) {
209
-	global $spip_lang_right;
210
-
211
-	if (!$error) return false;
212
-
213
-	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
214
-
215
-	switch ($error) {
216
-
217
-		case 4: /* UPLOAD_ERR_NO_FILE */
218
-			return true;
219
-
220
-		# on peut affiner les differents messages d'erreur
221
-		case 1: /* UPLOAD_ERR_INI_SIZE */
222
-			$msg = _T('upload_limit',
223
-			array('max' => ini_get('upload_max_filesize')));
224
-			break;
225
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
226
-			$msg = _T('upload_limit',
227
-			array('max' => ini_get('upload_max_filesize')));
228
-			break;
229
-		case 3: /* UPLOAD_ERR_PARTIAL  */
230
-			$msg = _T('upload_limit',
231
-			array('max' => ini_get('upload_max_filesize')));
232
-			break;
233
-
234
-		default: /* autre */
235
-			if (!$msg)
236
-			$msg = _T('pass_erreur').' '. $error
237
-			. '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
238
-			break;
239
-	}
240
-
241
-	spip_log ("erreur upload $error");
242
-	if ($return)
243
-		return $msg;
244
-
245
-  if(_request("iframe")=="iframe") {
246
-	  echo "<div class='upload_answer upload_error'>$msg</div>";
247
-	  exit;
248
-	}
249
-
250
-	include_spip('inc/minipres');
251
-	echo minipres($msg,
252
-		      "<div style='text-align: $spip_lang_right'><a href='"  . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>");
253
-	exit;
209
+    global $spip_lang_right;
210
+
211
+    if (!$error) return false;
212
+
213
+    spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
214
+
215
+    switch ($error) {
216
+
217
+        case 4: /* UPLOAD_ERR_NO_FILE */
218
+            return true;
219
+
220
+        # on peut affiner les differents messages d'erreur
221
+        case 1: /* UPLOAD_ERR_INI_SIZE */
222
+            $msg = _T('upload_limit',
223
+            array('max' => ini_get('upload_max_filesize')));
224
+            break;
225
+        case 2: /* UPLOAD_ERR_FORM_SIZE */
226
+            $msg = _T('upload_limit',
227
+            array('max' => ini_get('upload_max_filesize')));
228
+            break;
229
+        case 3: /* UPLOAD_ERR_PARTIAL  */
230
+            $msg = _T('upload_limit',
231
+            array('max' => ini_get('upload_max_filesize')));
232
+            break;
233
+
234
+        default: /* autre */
235
+            if (!$msg)
236
+            $msg = _T('pass_erreur').' '. $error
237
+            . '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
238
+            break;
239
+    }
240
+
241
+    spip_log ("erreur upload $error");
242
+    if ($return)
243
+        return $msg;
244
+
245
+    if(_request("iframe")=="iframe") {
246
+        echo "<div class='upload_answer upload_error'>$msg</div>";
247
+        exit;
248
+    }
249
+
250
+    include_spip('inc/minipres');
251
+    echo minipres($msg,
252
+                "<div style='text-align: $spip_lang_right'><a href='"  . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>");
253
+    exit;
254 254
 }
255 255
 ?>
Please login to merge, or discard this patch.
Braces   +62 added lines, -40 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 /**
16 18
  * donne le chemin du fichier relatif a _DIR_IMG
@@ -22,10 +24,12 @@  discard block
 block discarded – undo
22 24
  * @return string
23 25
  */
24 26
 function set_spip_doc($fichier) {
25
-	if (strpos($fichier, _DIR_IMG) === 0)
26
-		return substr($fichier, strlen(_DIR_IMG));
27
-	else
28
-		return $fichier; // ex: fichier distant
27
+	if (strpos($fichier, _DIR_IMG) === 0) {
28
+			return substr($fichier, strlen(_DIR_IMG));
29
+	} else {
30
+			return $fichier;
31
+	}
32
+	// ex: fichier distant
29 33
 }
30 34
 
31 35
 /**
@@ -38,12 +42,14 @@  discard block
 block discarded – undo
38 42
  */
39 43
 function get_spip_doc($fichier) {
40 44
 	// fichier distant
41
-	if (preg_match(',^\w+://,', $fichier))
42
-		return $fichier;
45
+	if (preg_match(',^\w+://,', $fichier)) {
46
+			return $fichier;
47
+	}
43 48
 
44 49
 	// gestion d'erreurs, fichier=''
45
-	if (!strlen($fichier))
46
-		return false;
50
+	if (!strlen($fichier)) {
51
+			return false;
52
+	}
47 53
 
48 54
 	$fichier = (
49 55
 		    strncmp($fichier,_DIR_IMG, strlen(_DIR_IMG))!=0
@@ -91,11 +97,12 @@  discard block
 block discarded – undo
91 97
 function effacer_repertoire_temporaire($nom) {
92 98
 	$d = opendir($nom);
93 99
 	while (($f = readdir($d)) !== false) {
94
-		if (is_file("$nom/$f"))
95
-			spip_unlink("$nom/$f");
96
-		else if ($f <> '.' AND $f <> '..'
97
-		AND is_dir("$nom/$f"))
98
-			effacer_repertoire_temporaire("$nom/$f");
100
+		if (is_file("$nom/$f")) {
101
+					spip_unlink("$nom/$f");
102
+		} else if ($f <> '.' AND $f <> '..'
103
+		AND is_dir("$nom/$f")) {
104
+					effacer_repertoire_temporaire("$nom/$f");
105
+		}
99 106
 	}
100 107
 	closedir($d);
101 108
 	@rmdir($nom);
@@ -126,8 +133,9 @@  discard block
 block discarded – undo
126 133
 	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
127 134
 
128 135
 	// Si le document "source" est deja au bon endroit, ne rien faire
129
-	if ($source == ($dir . $dest . '.' . $ext))
130
-		return $source;
136
+	if ($source == ($dir . $dest . '.' . $ext)) {
137
+			return $source;
138
+	}
131 139
 
132 140
 	// sinon tourner jusqu'a trouver un numero correct
133 141
 	$n = 0;
@@ -145,12 +153,15 @@  discard block
 block discarded – undo
145 153
  * @return bool|string
146 154
  */
147 155
 function determine_upload($type='') {
148
-	if(!function_exists('autoriser'))
149
-		include_spip('inc/autoriser');
156
+	if(!function_exists('autoriser')) {
157
+			include_spip('inc/autoriser');
158
+	}
150 159
 	
151 160
 	if (!autoriser('chargerftp')
152
-	OR $type == 'logos') # on ne le permet pas pour les logos
161
+	OR $type == 'logos') {
162
+	    # on ne le permet pas pour les logos
153 163
 		return false;
164
+	}
154 165
 
155 166
 	$repertoire = _DIR_TRANSFERT;
156 167
 	if (!@is_dir($repertoire)) {
@@ -158,11 +169,12 @@  discard block
 block discarded – undo
158 169
 		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
159 170
 	}
160 171
 
161
-	if (!$GLOBALS['visiteur_session']['restreint'])
162
-		return $repertoire;
163
-	else
164
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
165
-}
172
+	if (!$GLOBALS['visiteur_session']['restreint']) {
173
+			return $repertoire;
174
+	} else {
175
+			return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
176
+	}
177
+	}
166 178
 
167 179
 /**
168 180
  * Deplacer ou copier un fichier
@@ -176,17 +188,23 @@  discard block
 block discarded – undo
176 188
  */
177 189
 function deplacer_fichier_upload($source, $dest, $move=false) {
178 190
 	// Securite
179
-	if (substr($dest,0,strlen(_DIR_RACINE))==_DIR_RACINE)
180
-		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest,strlen(_DIR_RACINE)));
181
-	else
182
-		$dest = preg_replace(',\.\.+,', '.', $dest);
183
-
184
-	if ($move)	$ok = @rename($source, $dest);
185
-	else				$ok = @copy($source, $dest);
186
-	if (!$ok) $ok = @move_uploaded_file($source, $dest);
187
-	if ($ok)
188
-		@chmod($dest, _SPIP_CHMOD & ~0111);
189
-	else {
191
+	if (substr($dest,0,strlen(_DIR_RACINE))==_DIR_RACINE) {
192
+			$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest,strlen(_DIR_RACINE)));
193
+	} else {
194
+			$dest = preg_replace(',\.\.+,', '.', $dest);
195
+	}
196
+
197
+	if ($move) {
198
+	    $ok = @rename($source, $dest);
199
+	} else {
200
+	    $ok = @copy($source, $dest);
201
+	}
202
+	if (!$ok) {
203
+	    $ok = @move_uploaded_file($source, $dest);
204
+	}
205
+	if ($ok) {
206
+			@chmod($dest, _SPIP_CHMOD & ~0111);
207
+	} else {
190 208
 		$f = @fopen($dest,'w');
191 209
 		if ($f) {
192 210
 			fclose ($f);
@@ -208,7 +226,9 @@  discard block
 block discarded – undo
208 226
 function check_upload_error($error, $msg='', $return=false) {
209 227
 	global $spip_lang_right;
210 228
 
211
-	if (!$error) return false;
229
+	if (!$error) {
230
+	    return false;
231
+	}
212 232
 
213 233
 	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
214 234
 
@@ -232,15 +252,17 @@  discard block
 block discarded – undo
232 252
 			break;
233 253
 
234 254
 		default: /* autre */
235
-			if (!$msg)
236
-			$msg = _T('pass_erreur').' '. $error
255
+			if (!$msg) {
256
+						$msg = _T('pass_erreur').' '. $error
237 257
 			. '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
258
+			}
238 259
 			break;
239 260
 	}
240 261
 
241 262
 	spip_log ("erreur upload $error");
242
-	if ($return)
243
-		return $msg;
263
+	if ($return) {
264
+			return $msg;
265
+	}
244 266
 
245 267
   if(_request("iframe")=="iframe") {
246 268
 	  echo "<div class='upload_answer upload_error'>$msg</div>";
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 		return false;
47 47
 
48 48
 	$fichier = (
49
-		    strncmp($fichier,_DIR_IMG, strlen(_DIR_IMG))!=0
49
+		    strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0
50 50
 		)
51 51
 		? _DIR_IMG . $fichier
52
-		: $fichier ;
52
+		: $fichier;
53 53
 
54 54
 	// fichier normal
55 55
 	return $fichier;
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
127 127
 
128 128
 	// Si le document "source" est deja au bon endroit, ne rien faire
129
-	if ($source == ($dir . $dest . '.' . $ext))
129
+	if ($source == ($dir.$dest.'.'.$ext))
130 130
 		return $source;
131 131
 
132 132
 	// sinon tourner jusqu'a trouver un numero correct
133 133
 	$n = 0;
134
-	while (@file_exists($newFile = $dir . $dest .($n++ ? ('-'.$n) : '').'.'.$ext));
134
+	while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext));
135 135
 
136 136
 	return deplacer_fichier_upload($source, $newFile);
137 137
 }
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
  * @param string $type
145 145
  * @return bool|string
146 146
  */
147
-function determine_upload($type='') {
148
-	if(!function_exists('autoriser'))
147
+function determine_upload($type = '') {
148
+	if (!function_exists('autoriser'))
149 149
 		include_spip('inc/autoriser');
150 150
 	
151 151
 	if (!autoriser('chargerftp')
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
  * @param bool $move
175 175
  * @return bool|mixed|string
176 176
  */
177
-function deplacer_fichier_upload($source, $dest, $move=false) {
177
+function deplacer_fichier_upload($source, $dest, $move = false) {
178 178
 	// Securite
179
-	if (substr($dest,0,strlen(_DIR_RACINE))==_DIR_RACINE)
180
-		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest,strlen(_DIR_RACINE)));
179
+	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE)
180
+		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
181 181
 	else
182 182
 		$dest = preg_replace(',\.\.+,', '.', $dest);
183 183
 
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
 	if ($ok)
188 188
 		@chmod($dest, _SPIP_CHMOD & ~0111);
189 189
 	else {
190
-		$f = @fopen($dest,'w');
190
+		$f = @fopen($dest, 'w');
191 191
 		if ($f) {
192
-			fclose ($f);
192
+			fclose($f);
193 193
 		} else {
194 194
 			include_spip('inc/flock');
195 195
 			raler_fichier($dest);
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 // et true si erreur = pas de fichier
206 206
 // pour les autres erreurs affiche le message d'erreur et meurt
207 207
 // http://doc.spip.org/@check_upload_error
208
-function check_upload_error($error, $msg='', $return=false) {
208
+function check_upload_error($error, $msg = '', $return = false) {
209 209
 	global $spip_lang_right;
210 210
 
211 211
 	if (!$error) return false;
@@ -233,23 +233,23 @@  discard block
 block discarded – undo
233 233
 
234 234
 		default: /* autre */
235 235
 			if (!$msg)
236
-			$msg = _T('pass_erreur').' '. $error
237
-			. '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
236
+			$msg = _T('pass_erreur').' '.$error
237
+			. '<br />'.propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
238 238
 			break;
239 239
 	}
240 240
 
241
-	spip_log ("erreur upload $error");
241
+	spip_log("erreur upload $error");
242 242
 	if ($return)
243 243
 		return $msg;
244 244
 
245
-  if(_request("iframe")=="iframe") {
245
+  if (_request("iframe") == "iframe") {
246 246
 	  echo "<div class='upload_answer upload_error'>$msg</div>";
247 247
 	  exit;
248 248
 	}
249 249
 
250 250
 	include_spip('inc/minipres');
251 251
 	echo minipres($msg,
252
-		      "<div style='text-align: $spip_lang_right'><a href='"  . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>");
252
+		      "<div style='text-align: $spip_lang_right'><a href='".rawurldecode($GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant')."</button></a></div>");
253 253
 	exit;
254 254
 }
255 255
 ?>
Please login to merge, or discard this patch.
ecrire/inc/drapeau_edition.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -105,6 +105,9 @@
 block discarded – undo
105 105
 }
106 106
 
107 107
 // http://doc.spip.org/@mention_qui_edite
108
+/**
109
+ * @param integer $id
110
+ */
108 111
 function mention_qui_edite ($id, $type='article') {
109 112
 	$modif = qui_edite($id, $type);
110 113
 	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -30,40 +30,40 @@  discard block
 block discarded – undo
30 30
 
31 31
 // http://doc.spip.org/@lire_tableau_edition
32 32
 function lire_tableau_edition () {
33
-	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
34
-	if (!$edition) return array();
35
-	$changed = false;
36
-
37
-	$bon_pour_le_service = time()-3600;
38
-	// parcourir le tableau et virer les vieux
39
-	foreach ($edition as $objet => $data) {
40
-		if (!is_array($data))
41
-			unset ($edition[$objet]); // vieille version
42
-		else foreach ($data as $id => $tab) {
43
-			if (!is_array($tab))
44
-			  unset ($edition[$objet][$tab]); // vieille version
45
-			else foreach ($tab as $n => $duo) {
46
-				if (current($duo) < $bon_pour_le_service) {
47
-					unset($edition[$objet][$id][$n]);
48
-					$changed = true;
49
-				}
50
-			}
51
-			if (!$edition[$objet][$id])
52
-				unset($edition[$objet][$id]);
53
-		}
54
-		if (!$edition[$objet])
55
-			unset($edition[$objet]);
56
-	}
57
-
58
-	if ($changed)
59
-		ecrire_tableau_edition($edition);
60
-
61
-	return $edition;
33
+    $edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
34
+    if (!$edition) return array();
35
+    $changed = false;
36
+
37
+    $bon_pour_le_service = time()-3600;
38
+    // parcourir le tableau et virer les vieux
39
+    foreach ($edition as $objet => $data) {
40
+        if (!is_array($data))
41
+            unset ($edition[$objet]); // vieille version
42
+        else foreach ($data as $id => $tab) {
43
+            if (!is_array($tab))
44
+                unset ($edition[$objet][$tab]); // vieille version
45
+            else foreach ($tab as $n => $duo) {
46
+                if (current($duo) < $bon_pour_le_service) {
47
+                    unset($edition[$objet][$id][$n]);
48
+                    $changed = true;
49
+                }
50
+            }
51
+            if (!$edition[$objet][$id])
52
+                unset($edition[$objet][$id]);
53
+        }
54
+        if (!$edition[$objet])
55
+            unset($edition[$objet]);
56
+    }
57
+
58
+    if ($changed)
59
+        ecrire_tableau_edition($edition);
60
+
61
+    return $edition;
62 62
 }
63 63
 
64 64
 // http://doc.spip.org/@ecrire_tableau_edition
65 65
 function ecrire_tableau_edition($edition) {
66
-	ecrire_meta('drapeau_edition', serialize($edition));
66
+    ecrire_meta('drapeau_edition', serialize($edition));
67 67
 }
68 68
 
69 69
 /**
@@ -79,48 +79,48 @@  discard block
 block discarded – undo
79 79
  * @return mixed
80 80
  */
81 81
 function signale_edition ($id, $auteur, $type='article') {
82
-	include_spip('base/objets');
83
-	include_spip('inc/filtres');
84
-	if (objet_info($type,'editable')!=='oui')
85
-		return;
86
-
87
-	$edition = lire_tableau_edition();
88
-	if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur'])
89
-		$nom = $auteur['nom'];
90
-	else
91
-		$nom = $id_a = $GLOBALS['ip'];
92
-	if (!is_array($edition[$type][$id]))
93
-		$edition[$type][$id] = array();
94
-	$edition[$type][$id][$id_a][$nom] = time();
95
-	ecrire_tableau_edition($edition);
82
+    include_spip('base/objets');
83
+    include_spip('inc/filtres');
84
+    if (objet_info($type,'editable')!=='oui')
85
+        return;
86
+
87
+    $edition = lire_tableau_edition();
88
+    if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur'])
89
+        $nom = $auteur['nom'];
90
+    else
91
+        $nom = $id_a = $GLOBALS['ip'];
92
+    if (!is_array($edition[$type][$id]))
93
+        $edition[$type][$id] = array();
94
+    $edition[$type][$id][$id_a][$nom] = time();
95
+    ecrire_tableau_edition($edition);
96 96
 }
97 97
 
98 98
 // Qui edite mon objet ?
99 99
 // http://doc.spip.org/@qui_edite
100 100
 function qui_edite ($id, $type='article') {
101 101
 
102
-	$edition = lire_tableau_edition();
102
+    $edition = lire_tableau_edition();
103 103
 
104
-	return $edition ? $edition[$type][$id] : array();
104
+    return $edition ? $edition[$type][$id] : array();
105 105
 }
106 106
 
107 107
 // http://doc.spip.org/@mention_qui_edite
108 108
 function mention_qui_edite ($id, $type='article') {
109
-	$modif = qui_edite($id, $type);
110
-	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
111
-
112
-	if ($modif) {
113
-		$quand = 0;
114
-		foreach ($modif as $duo) {
115
-			$auteurs[] = typo(key($duo));
116
-			$quand = max($quand, current($duo));
117
-		}
118
-		// format lie a la chaine de langue 'avis_article_modifie'
119
-		return array(
120
-			'nom_auteur_modif' => join(' | ', $auteurs),
121
-			'date_diff' => ceil((time()-$quand) / 60)
122
-		);
123
-	}
109
+    $modif = qui_edite($id, $type);
110
+    unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
111
+
112
+    if ($modif) {
113
+        $quand = 0;
114
+        foreach ($modif as $duo) {
115
+            $auteurs[] = typo(key($duo));
116
+            $quand = max($quand, current($duo));
117
+        }
118
+        // format lie a la chaine de langue 'avis_article_modifie'
119
+        return array(
120
+            'nom_auteur_modif' => join(' | ', $auteurs),
121
+            'date_diff' => ceil((time()-$quand) / 60)
122
+        );
123
+    }
124 124
 }
125 125
 
126 126
 /**
@@ -132,55 +132,55 @@  discard block
 block discarded – undo
132 132
  * @return array
133 133
  */
134 134
 function liste_drapeau_edition ($id_auteur) {
135
-	$edition = lire_tableau_edition();
136
-	$objets_ouverts = array();
137
-
138
-	foreach ($edition as $objet => $data)
139
-		foreach ($data as $id => $auteurs)
140
-		{
141
-			if (isset($auteurs[$id_auteur])
142
-			AND is_array($auteurs[$id_auteur]) // precaution
143
-			AND (array_pop($auteurs[$id_auteur]) > time()-3600)) {
144
-				$objets_ouverts[] = array(
145
-					'objet'=>$objet,
146
-					'id_objet' => $id,
147
-				);
148
-			}
149
-		}
150
-	return $objets_ouverts;
135
+    $edition = lire_tableau_edition();
136
+    $objets_ouverts = array();
137
+
138
+    foreach ($edition as $objet => $data)
139
+        foreach ($data as $id => $auteurs)
140
+        {
141
+            if (isset($auteurs[$id_auteur])
142
+            AND is_array($auteurs[$id_auteur]) // precaution
143
+            AND (array_pop($auteurs[$id_auteur]) > time()-3600)) {
144
+                $objets_ouverts[] = array(
145
+                    'objet'=>$objet,
146
+                    'id_objet' => $id,
147
+                );
148
+            }
149
+        }
150
+    return $objets_ouverts;
151 151
 }
152 152
 
153 153
 // Quand l'auteur veut liberer tous ses objets (tous types)
154 154
 // http://doc.spip.org/@debloquer_tous
155 155
 function debloquer_tous($id_auteur) {
156
-	$edition = lire_tableau_edition();
157
-	foreach ($edition as $objet => $data) {
158
-		foreach ($data as $id => $auteurs)
159
-		{
160
-			if (isset($auteurs[$id_auteur])) {
161
-				unset ($edition[$objet][$id][$id_auteur]);
162
-				ecrire_tableau_edition($edition);
163
-			}
164
-		}
165
-	}
156
+    $edition = lire_tableau_edition();
157
+    foreach ($edition as $objet => $data) {
158
+        foreach ($data as $id => $auteurs)
159
+        {
160
+            if (isset($auteurs[$id_auteur])) {
161
+                unset ($edition[$objet][$id][$id_auteur]);
162
+                ecrire_tableau_edition($edition);
163
+            }
164
+        }
165
+    }
166 166
 }
167 167
 
168 168
 // quand l'auteur libere un objet precis
169 169
 // http://doc.spip.org/@debloquer_edition
170 170
 function debloquer_edition($id_auteur, $id_objet, $type='article') {
171
-	$edition = lire_tableau_edition();
172
-
173
-	foreach ($edition as $objet => $data){
174
-		if ($objet == $type) {
175
-			foreach ($data as $id => $auteurs)
176
-			{
177
-				if ($id == $id_objet
178
-				AND isset($auteurs[$id_auteur])) {
179
-					unset ($edition[$objet][$id][$id_auteur]);
180
-					ecrire_tableau_edition($edition);
181
-				}
182
-			}
183
-		}
184
-	}
171
+    $edition = lire_tableau_edition();
172
+
173
+    foreach ($edition as $objet => $data){
174
+        if ($objet == $type) {
175
+            foreach ($data as $id => $auteurs)
176
+            {
177
+                if ($id == $id_objet
178
+                AND isset($auteurs[$id_auteur])) {
179
+                    unset ($edition[$objet][$id][$id_auteur]);
180
+                    ecrire_tableau_edition($edition);
181
+                }
182
+            }
183
+        }
184
+    }
185 185
 }
186 186
 ?>
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
 
30 30
 
31 31
 // http://doc.spip.org/@lire_tableau_edition
32
-function lire_tableau_edition () {
32
+function lire_tableau_edition() {
33 33
 	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
34 34
 	if (!$edition) return array();
35 35
 	$changed = false;
36 36
 
37
-	$bon_pour_le_service = time()-3600;
37
+	$bon_pour_le_service = time() - 3600;
38 38
 	// parcourir le tableau et virer les vieux
39 39
 	foreach ($edition as $objet => $data) {
40 40
 		if (!is_array($data))
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
  * @param string $type
79 79
  * @return mixed
80 80
  */
81
-function signale_edition ($id, $auteur, $type='article') {
81
+function signale_edition($id, $auteur, $type = 'article') {
82 82
 	include_spip('base/objets');
83 83
 	include_spip('inc/filtres');
84
-	if (objet_info($type,'editable')!=='oui')
84
+	if (objet_info($type, 'editable') !== 'oui')
85 85
 		return;
86 86
 
87 87
 	$edition = lire_tableau_edition();
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
 // Qui edite mon objet ?
99 99
 // http://doc.spip.org/@qui_edite
100
-function qui_edite ($id, $type='article') {
100
+function qui_edite($id, $type = 'article') {
101 101
 
102 102
 	$edition = lire_tableau_edition();
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 }
106 106
 
107 107
 // http://doc.spip.org/@mention_qui_edite
108
-function mention_qui_edite ($id, $type='article') {
108
+function mention_qui_edite($id, $type = 'article') {
109 109
 	$modif = qui_edite($id, $type);
110 110
 	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
111 111
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		// format lie a la chaine de langue 'avis_article_modifie'
119 119
 		return array(
120 120
 			'nom_auteur_modif' => join(' | ', $auteurs),
121
-			'date_diff' => ceil((time()-$quand) / 60)
121
+			'date_diff' => ceil((time() - $quand) / 60)
122 122
 		);
123 123
 	}
124 124
 }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
  * @param $id_auteur
132 132
  * @return array
133 133
  */
134
-function liste_drapeau_edition ($id_auteur) {
134
+function liste_drapeau_edition($id_auteur) {
135 135
 	$edition = lire_tableau_edition();
136 136
 	$objets_ouverts = array();
137 137
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		{
141 141
 			if (isset($auteurs[$id_auteur])
142 142
 			AND is_array($auteurs[$id_auteur]) // precaution
143
-			AND (array_pop($auteurs[$id_auteur]) > time()-3600)) {
143
+			AND (array_pop($auteurs[$id_auteur]) > time() - 3600)) {
144 144
 				$objets_ouverts[] = array(
145 145
 					'objet'=>$objet,
146 146
 					'id_objet' => $id,
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
 
168 168
 // quand l'auteur libere un objet precis
169 169
 // http://doc.spip.org/@debloquer_edition
170
-function debloquer_edition($id_auteur, $id_objet, $type='article') {
170
+function debloquer_edition($id_auteur, $id_objet, $type = 'article') {
171 171
 	$edition = lire_tableau_edition();
172 172
 
173
-	foreach ($edition as $objet => $data){
173
+	foreach ($edition as $objet => $data) {
174 174
 		if ($objet == $type) {
175 175
 			foreach ($data as $id => $auteurs)
176 176
 			{
Please login to merge, or discard this patch.
Braces   +41 added lines, -23 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // Drapeau d'edition : on regarde qui a ouvert quel objet editorial en 
16 18
 // edition, et on le signale aux autres redacteurs pour eviter de se marcher 
@@ -31,32 +33,44 @@  discard block
 block discarded – undo
31 33
 // http://doc.spip.org/@lire_tableau_edition
32 34
 function lire_tableau_edition () {
33 35
 	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
34
-	if (!$edition) return array();
36
+	if (!$edition) {
37
+	    return array();
38
+	}
35 39
 	$changed = false;
36 40
 
37 41
 	$bon_pour_le_service = time()-3600;
38 42
 	// parcourir le tableau et virer les vieux
39 43
 	foreach ($edition as $objet => $data) {
40
-		if (!is_array($data))
41
-			unset ($edition[$objet]); // vieille version
42
-		else foreach ($data as $id => $tab) {
44
+		if (!is_array($data)) {
45
+					unset ($edition[$objet]);
46
+		}
47
+		// vieille version
48
+		else {
49
+		    foreach ($data as $id => $tab) {
43 50
 			if (!is_array($tab))
44
-			  unset ($edition[$objet][$tab]); // vieille version
45
-			else foreach ($tab as $n => $duo) {
51
+			  unset ($edition[$objet][$tab]);
52
+		}
53
+		// vieille version
54
+			else {
55
+			    foreach ($tab as $n => $duo) {
46 56
 				if (current($duo) < $bon_pour_le_service) {
47 57
 					unset($edition[$objet][$id][$n]);
58
+			}
48 59
 					$changed = true;
49 60
 				}
50 61
 			}
51
-			if (!$edition[$objet][$id])
52
-				unset($edition[$objet][$id]);
62
+			if (!$edition[$objet][$id]) {
63
+							unset($edition[$objet][$id]);
64
+			}
65
+		}
66
+		if (!$edition[$objet]) {
67
+					unset($edition[$objet]);
53 68
 		}
54
-		if (!$edition[$objet])
55
-			unset($edition[$objet]);
56 69
 	}
57 70
 
58
-	if ($changed)
59
-		ecrire_tableau_edition($edition);
71
+	if ($changed) {
72
+			ecrire_tableau_edition($edition);
73
+	}
60 74
 
61 75
 	return $edition;
62 76
 }
@@ -81,16 +95,19 @@  discard block
 block discarded – undo
81 95
 function signale_edition ($id, $auteur, $type='article') {
82 96
 	include_spip('base/objets');
83 97
 	include_spip('inc/filtres');
84
-	if (objet_info($type,'editable')!=='oui')
85
-		return;
98
+	if (objet_info($type,'editable')!=='oui') {
99
+			return;
100
+	}
86 101
 
87 102
 	$edition = lire_tableau_edition();
88
-	if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur'])
89
-		$nom = $auteur['nom'];
90
-	else
91
-		$nom = $id_a = $GLOBALS['ip'];
92
-	if (!is_array($edition[$type][$id]))
93
-		$edition[$type][$id] = array();
103
+	if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur']) {
104
+			$nom = $auteur['nom'];
105
+	} else {
106
+			$nom = $id_a = $GLOBALS['ip'];
107
+	}
108
+	if (!is_array($edition[$type][$id])) {
109
+			$edition[$type][$id] = array();
110
+	}
94 111
 	$edition[$type][$id][$id_a][$nom] = time();
95 112
 	ecrire_tableau_edition($edition);
96 113
 }
@@ -135,8 +152,8 @@  discard block
 block discarded – undo
135 152
 	$edition = lire_tableau_edition();
136 153
 	$objets_ouverts = array();
137 154
 
138
-	foreach ($edition as $objet => $data)
139
-		foreach ($data as $id => $auteurs)
155
+	foreach ($edition as $objet => $data) {
156
+			foreach ($data as $id => $auteurs)
140 157
 		{
141 158
 			if (isset($auteurs[$id_auteur])
142 159
 			AND is_array($auteurs[$id_auteur]) // precaution
@@ -145,6 +162,7 @@  discard block
 block discarded – undo
145 162
 					'objet'=>$objet,
146 163
 					'id_objet' => $id,
147 164
 				);
165
+	}
148 166
 			}
149 167
 		}
150 168
 	return $objets_ouverts;
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -142,6 +142,9 @@
 block discarded – undo
142 142
 	return @mail($destinataire, $sujet, $texte, $headers);
143 143
 }
144 144
 
145
+/**
146
+ * @param string $to
147
+ */
145 148
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts="")
146 149
 {
147 150
 	$charset = $GLOBALS['meta']['charset'];
Please login to merge, or discard this patch.
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -17,27 +17,27 @@  discard block
 block discarded – undo
17 17
 
18 18
 // http://doc.spip.org/@nettoyer_titre_email
19 19
 function nettoyer_titre_email($titre) {
20
-	return str_replace("\n", ' ', textebrut(corriger_typo($titre)));
20
+    return str_replace("\n", ' ', textebrut(corriger_typo($titre)));
21 21
 }
22 22
 
23 23
 // http://doc.spip.org/@nettoyer_caracteres_mail
24 24
 function nettoyer_caracteres_mail($t) {
25 25
 
26
-	$t = filtrer_entites($t);
26
+    $t = filtrer_entites($t);
27 27
 
28
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
29
-		$t = str_replace(
30
-			array("&#8217;","&#8220;","&#8221;"),
31
-			array("'",      '"',      '"'),
32
-		$t);
33
-	}
28
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
29
+        $t = str_replace(
30
+            array("&#8217;","&#8220;","&#8221;"),
31
+            array("'",      '"',      '"'),
32
+        $t);
33
+    }
34 34
 
35
-	$t = str_replace(
36
-		array("&mdash;", "&endash;"),
37
-		array("--","-" ),
38
-	$t);
35
+    $t = str_replace(
36
+        array("&mdash;", "&endash;"),
37
+        array("--","-" ),
38
+    $t);
39 39
 
40
-	return $t;
40
+    return $t;
41 41
 }
42 42
 
43 43
 /**
@@ -71,122 +71,122 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = "", $headers = "") {
73 73
 
74
-	if (!email_valide($destinataire)) return false;
75
-	if ($destinataire == _T('info_mail_fournisseur')) return false; // tres fort
76
-
77
-	// Fournir si possible un Message-Id: conforme au RFC1036,
78
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
79
-
80
-	$email_envoi = $GLOBALS['meta']["email_envoi"];
81
-	if (!email_valide($email_envoi)) {
82
-		spip_log("Meta email_envoi invalide. Le mail sera probablement vu comme spam.");
83
-		$email_envoi = $destinataire;
84
-	}
85
-
86
-	if (is_array($corps)){
87
-		$texte = $corps['texte'];
88
-		$from = (isset($corps['from'])?$corps['from']:$from);
89
-		$headers = (isset($corps['headers'])?$corps['headers']:$headers);
90
-		if (is_array($headers))
91
-			$headers = implode("\n",$headers);
92
-		$parts = "";
93
-		if ($corps['pieces_jointes'] AND function_exists('mail_embarquer_pieces_jointes'))
94
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
95
-	} else
96
-		$texte = $corps;
97
-
98
-	if (!$from) $from = $email_envoi;
99
-
100
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
101
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from))
102
-		$from .= ' (' . str_replace(')','', translitteration(str_replace('@', ' at ', $from))) . ')';
103
-
104
-	// nettoyer les &eacute; &#8217, &emdash; etc...
105
-	// les 'cliquer ici' etc sont a eviter;  voir:
106
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
107
-	$texte = nettoyer_caracteres_mail($texte);
108
-	$sujet = nettoyer_caracteres_mail($sujet);
109
-
110
-	// encoder le sujet si possible selon la RFC
111
-	if (init_mb_string()) {
112
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
113
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
114
-		$charset = $GLOBALS['meta']['charset'];
115
-		mb_internal_encoding($charset);
116
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
117
-		mb_internal_encoding('utf-8');
118
-	}
119
-
120
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,',$headers) == 0))
121
-		$texte = wordwrap($texte);
122
-
123
-	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
124
-
125
-	if (_OS_SERVEUR == 'windows') {
126
-		$texte = preg_replace ("@\r*\n@","\r\n", $texte);
127
-		$headers = preg_replace ("@\r*\n@","\r\n", $headers);
128
-		$sujet = preg_replace ("@\r*\n@","\r\n", $sujet);
129
-	}
130
-
131
-	spip_log("mail $destinataire\n$sujet\n$headers",'mails');
132
-	// mode TEST : forcer l'email
133
-	if (defined('_TEST_EMAIL_DEST')) {
134
-		if (!_TEST_EMAIL_DEST)
135
-			return false;
136
-		else {
137
-			$texte = "Dest : $destinataire\r\n" . $texte;
138
-			$destinataire = _TEST_EMAIL_DEST;
139
-		}
140
-	}
141
-
142
-	return @mail($destinataire, $sujet, $texte, $headers);
74
+    if (!email_valide($destinataire)) return false;
75
+    if ($destinataire == _T('info_mail_fournisseur')) return false; // tres fort
76
+
77
+    // Fournir si possible un Message-Id: conforme au RFC1036,
78
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
79
+
80
+    $email_envoi = $GLOBALS['meta']["email_envoi"];
81
+    if (!email_valide($email_envoi)) {
82
+        spip_log("Meta email_envoi invalide. Le mail sera probablement vu comme spam.");
83
+        $email_envoi = $destinataire;
84
+    }
85
+
86
+    if (is_array($corps)){
87
+        $texte = $corps['texte'];
88
+        $from = (isset($corps['from'])?$corps['from']:$from);
89
+        $headers = (isset($corps['headers'])?$corps['headers']:$headers);
90
+        if (is_array($headers))
91
+            $headers = implode("\n",$headers);
92
+        $parts = "";
93
+        if ($corps['pieces_jointes'] AND function_exists('mail_embarquer_pieces_jointes'))
94
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
95
+    } else
96
+        $texte = $corps;
97
+
98
+    if (!$from) $from = $email_envoi;
99
+
100
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
101
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from))
102
+        $from .= ' (' . str_replace(')','', translitteration(str_replace('@', ' at ', $from))) . ')';
103
+
104
+    // nettoyer les &eacute; &#8217, &emdash; etc...
105
+    // les 'cliquer ici' etc sont a eviter;  voir:
106
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
107
+    $texte = nettoyer_caracteres_mail($texte);
108
+    $sujet = nettoyer_caracteres_mail($sujet);
109
+
110
+    // encoder le sujet si possible selon la RFC
111
+    if (init_mb_string()) {
112
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
113
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
114
+        $charset = $GLOBALS['meta']['charset'];
115
+        mb_internal_encoding($charset);
116
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
117
+        mb_internal_encoding('utf-8');
118
+    }
119
+
120
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,',$headers) == 0))
121
+        $texte = wordwrap($texte);
122
+
123
+    list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
124
+
125
+    if (_OS_SERVEUR == 'windows') {
126
+        $texte = preg_replace ("@\r*\n@","\r\n", $texte);
127
+        $headers = preg_replace ("@\r*\n@","\r\n", $headers);
128
+        $sujet = preg_replace ("@\r*\n@","\r\n", $sujet);
129
+    }
130
+
131
+    spip_log("mail $destinataire\n$sujet\n$headers",'mails');
132
+    // mode TEST : forcer l'email
133
+    if (defined('_TEST_EMAIL_DEST')) {
134
+        if (!_TEST_EMAIL_DEST)
135
+            return false;
136
+        else {
137
+            $texte = "Dest : $destinataire\r\n" . $texte;
138
+            $destinataire = _TEST_EMAIL_DEST;
139
+        }
140
+    }
141
+
142
+    return @mail($destinataire, $sujet, $texte, $headers);
143 143
 }
144 144
 
145 145
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts="")
146 146
 {
147
-	$charset = $GLOBALS['meta']['charset'];
148
-
149
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
150
-	if (strpos($headers, "Content-Type: ") === false)
151
-		$type =
152
-		"Content-Type: text/plain;charset=\"$charset\";\n".
153
-		"Content-Transfer-Encoding: 8bit\n";
154
-	else $type = '';
155
-
156
-	// calculer un identifiant unique
157
-	preg_match('/@\S+/', $from, $domain);
158
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
159
-
160
-	// Si multi-part, s'en servir comme borne ...
161
-	if ($parts) {
162
-		$texte = "--$uniq\n$type\n" . $texte ."\n";
163
-		foreach ($parts as $part) {
164
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
165
-			$e = join("\n", $part[0]);
166
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
167
-		}
168
-		$texte .= "\n\n--$uniq--\n";
169
-		// Si boundary n'est pas entre guillemets,
170
-		// elle est comprise mais le charset est ignoree !
171
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
172
-	}
173
-
174
-	// .. et s'en servir pour plaire a SpamAssassin
175
-
176
-	$mid = 'Message-Id: <' . $uniq . ">";
177
-
178
-	// indispensable pour les sites qui collent d'office From: serveur-http
179
-	// sauf si deja mis par l'envoyeur
180
-	$rep = (strpos($headers,"Reply-To:")!==FALSE) ? '' : "Reply-To: $from\n";
181
-
182
-	// Nettoyer les en-tetes envoyees
183
-	// Ajouter le \n final
184
-	if (strlen($headers = trim($headers))) $headers .= "\n";
185
-
186
-	// Et mentionner l'indeboulonable nomenclature ratee 
187
-
188
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
189
-
190
-	return array($headers, $texte);
147
+    $charset = $GLOBALS['meta']['charset'];
148
+
149
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
150
+    if (strpos($headers, "Content-Type: ") === false)
151
+        $type =
152
+        "Content-Type: text/plain;charset=\"$charset\";\n".
153
+        "Content-Transfer-Encoding: 8bit\n";
154
+    else $type = '';
155
+
156
+    // calculer un identifiant unique
157
+    preg_match('/@\S+/', $from, $domain);
158
+    $uniq = rand() . '_' . md5($to . $texte) . $domain[0];
159
+
160
+    // Si multi-part, s'en servir comme borne ...
161
+    if ($parts) {
162
+        $texte = "--$uniq\n$type\n" . $texte ."\n";
163
+        foreach ($parts as $part) {
164
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
165
+            $e = join("\n", $part[0]);
166
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
167
+        }
168
+        $texte .= "\n\n--$uniq--\n";
169
+        // Si boundary n'est pas entre guillemets,
170
+        // elle est comprise mais le charset est ignoree !
171
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
172
+    }
173
+
174
+    // .. et s'en servir pour plaire a SpamAssassin
175
+
176
+    $mid = 'Message-Id: <' . $uniq . ">";
177
+
178
+    // indispensable pour les sites qui collent d'office From: serveur-http
179
+    // sauf si deja mis par l'envoyeur
180
+    $rep = (strpos($headers,"Reply-To:")!==FALSE) ? '' : "Reply-To: $from\n";
181
+
182
+    // Nettoyer les en-tetes envoyees
183
+    // Ajouter le \n final
184
+    if (strlen($headers = trim($headers))) $headers .= "\n";
185
+
186
+    // Et mentionner l'indeboulonable nomenclature ratee 
187
+
188
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
189
+
190
+    return array($headers, $texte);
191 191
 }
192 192
 ?>
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,14 +27,14 @@  discard block
 block discarded – undo
27 27
 
28 28
 	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
29 29
 		$t = str_replace(
30
-			array("&#8217;","&#8220;","&#8221;"),
31
-			array("'",      '"',      '"'),
30
+			array("&#8217;", "&#8220;", "&#8221;"),
31
+			array("'", '"', '"'),
32 32
 		$t);
33 33
 	}
34 34
 
35 35
 	$t = str_replace(
36 36
 		array("&mdash;", "&endash;"),
37
-		array("--","-" ),
37
+		array("--", "-"),
38 38
 	$t);
39 39
 
40 40
 	return $t;
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		$email_envoi = $destinataire;
84 84
 	}
85 85
 
86
-	if (is_array($corps)){
86
+	if (is_array($corps)) {
87 87
 		$texte = $corps['texte'];
88
-		$from = (isset($corps['from'])?$corps['from']:$from);
89
-		$headers = (isset($corps['headers'])?$corps['headers']:$headers);
88
+		$from = (isset($corps['from']) ? $corps['from'] : $from);
89
+		$headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
90 90
 		if (is_array($headers))
91
-			$headers = implode("\n",$headers);
91
+			$headers = implode("\n", $headers);
92 92
 		$parts = "";
93 93
 		if ($corps['pieces_jointes'] AND function_exists('mail_embarquer_pieces_jointes'))
94 94
 			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
101 101
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from))
102
-		$from .= ' (' . str_replace(')','', translitteration(str_replace('@', ' at ', $from))) . ')';
102
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')';
103 103
 
104 104
 	// nettoyer les &eacute; &#8217, &emdash; etc...
105 105
 	// les 'cliquer ici' etc sont a eviter;  voir:
@@ -117,24 +117,24 @@  discard block
 block discarded – undo
117 117
 		mb_internal_encoding('utf-8');
118 118
 	}
119 119
 
120
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,',$headers) == 0))
120
+	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0))
121 121
 		$texte = wordwrap($texte);
122 122
 
123 123
 	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
124 124
 
125 125
 	if (_OS_SERVEUR == 'windows') {
126
-		$texte = preg_replace ("@\r*\n@","\r\n", $texte);
127
-		$headers = preg_replace ("@\r*\n@","\r\n", $headers);
128
-		$sujet = preg_replace ("@\r*\n@","\r\n", $sujet);
126
+		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
127
+		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
128
+		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
129 129
 	}
130 130
 
131
-	spip_log("mail $destinataire\n$sujet\n$headers",'mails');
131
+	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
132 132
 	// mode TEST : forcer l'email
133 133
 	if (defined('_TEST_EMAIL_DEST')) {
134 134
 		if (!_TEST_EMAIL_DEST)
135 135
 			return false;
136 136
 		else {
137
-			$texte = "Dest : $destinataire\r\n" . $texte;
137
+			$texte = "Dest : $destinataire\r\n".$texte;
138 138
 			$destinataire = _TEST_EMAIL_DEST;
139 139
 		}
140 140
 	}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	return @mail($destinataire, $sujet, $texte, $headers);
143 143
 }
144 144
 
145
-function mail_normaliser_headers($headers, $from, $to, $texte, $parts="")
145
+function mail_normaliser_headers($headers, $from, $to, $texte, $parts = "")
146 146
 {
147 147
 	$charset = $GLOBALS['meta']['charset'];
148 148
 
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 
156 156
 	// calculer un identifiant unique
157 157
 	preg_match('/@\S+/', $from, $domain);
158
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
158
+	$uniq = rand().'_'.md5($to.$texte).$domain[0];
159 159
 
160 160
 	// Si multi-part, s'en servir comme borne ...
161 161
 	if ($parts) {
162
-		$texte = "--$uniq\n$type\n" . $texte ."\n";
162
+		$texte = "--$uniq\n$type\n".$texte."\n";
163 163
 		foreach ($parts as $part) {
164
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
164
+			$n = strlen($part[1]).($part[0] ? "\n" : '');
165 165
 			$e = join("\n", $part[0]);
166
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
166
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
167 167
 		}
168 168
 		$texte .= "\n\n--$uniq--\n";
169 169
 		// Si boundary n'est pas entre guillemets,
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 
174 174
 	// .. et s'en servir pour plaire a SpamAssassin
175 175
 
176
-	$mid = 'Message-Id: <' . $uniq . ">";
176
+	$mid = 'Message-Id: <'.$uniq.">";
177 177
 
178 178
 	// indispensable pour les sites qui collent d'office From: serveur-http
179 179
 	// sauf si deja mis par l'envoyeur
180
-	$rep = (strpos($headers,"Reply-To:")!==FALSE) ? '' : "Reply-To: $from\n";
180
+	$rep = (strpos($headers, "Reply-To:") !== FALSE) ? '' : "Reply-To: $from\n";
181 181
 
182 182
 	// Nettoyer les en-tetes envoyees
183 183
 	// Ajouter le \n final
Please login to merge, or discard this patch.
Braces   +39 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 include_spip('inc/charsets');
16 18
 include_spip('inc/texte');
@@ -71,8 +73,13 @@  discard block
 block discarded – undo
71 73
  */
72 74
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = "", $headers = "") {
73 75
 
74
-	if (!email_valide($destinataire)) return false;
75
-	if ($destinataire == _T('info_mail_fournisseur')) return false; // tres fort
76
+	if (!email_valide($destinataire)) {
77
+	    return false;
78
+	}
79
+	if ($destinataire == _T('info_mail_fournisseur')) {
80
+	    return false;
81
+	}
82
+	// tres fort
76 83
 
77 84
 	// Fournir si possible un Message-Id: conforme au RFC1036,
78 85
 	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
@@ -87,19 +94,25 @@  discard block
 block discarded – undo
87 94
 		$texte = $corps['texte'];
88 95
 		$from = (isset($corps['from'])?$corps['from']:$from);
89 96
 		$headers = (isset($corps['headers'])?$corps['headers']:$headers);
90
-		if (is_array($headers))
91
-			$headers = implode("\n",$headers);
97
+		if (is_array($headers)) {
98
+					$headers = implode("\n",$headers);
99
+		}
92 100
 		$parts = "";
93
-		if ($corps['pieces_jointes'] AND function_exists('mail_embarquer_pieces_jointes'))
94
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
95
-	} else
96
-		$texte = $corps;
101
+		if ($corps['pieces_jointes'] AND function_exists('mail_embarquer_pieces_jointes')) {
102
+					$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
103
+		}
104
+	} else {
105
+			$texte = $corps;
106
+	}
97 107
 
98
-	if (!$from) $from = $email_envoi;
108
+	if (!$from) {
109
+	    $from = $email_envoi;
110
+	}
99 111
 
100 112
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
101
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from))
102
-		$from .= ' (' . str_replace(')','', translitteration(str_replace('@', ' at ', $from))) . ')';
113
+	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
114
+			$from .= ' (' . str_replace(')','', translitteration(str_replace('@', ' at ', $from))) . ')';
115
+	}
103 116
 
104 117
 	// nettoyer les &eacute; &#8217, &emdash; etc...
105 118
 	// les 'cliquer ici' etc sont a eviter;  voir:
@@ -117,8 +130,9 @@  discard block
 block discarded – undo
117 130
 		mb_internal_encoding('utf-8');
118 131
 	}
119 132
 
120
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,',$headers) == 0))
121
-		$texte = wordwrap($texte);
133
+	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,',$headers) == 0)) {
134
+			$texte = wordwrap($texte);
135
+	}
122 136
 
123 137
 	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
124 138
 
@@ -131,9 +145,9 @@  discard block
 block discarded – undo
131 145
 	spip_log("mail $destinataire\n$sujet\n$headers",'mails');
132 146
 	// mode TEST : forcer l'email
133 147
 	if (defined('_TEST_EMAIL_DEST')) {
134
-		if (!_TEST_EMAIL_DEST)
135
-			return false;
136
-		else {
148
+		if (!_TEST_EMAIL_DEST) {
149
+					return false;
150
+		} else {
137 151
 			$texte = "Dest : $destinataire\r\n" . $texte;
138 152
 			$destinataire = _TEST_EMAIL_DEST;
139 153
 		}
@@ -147,11 +161,13 @@  discard block
 block discarded – undo
147 161
 	$charset = $GLOBALS['meta']['charset'];
148 162
 
149 163
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
150
-	if (strpos($headers, "Content-Type: ") === false)
151
-		$type =
164
+	if (strpos($headers, "Content-Type: ") === false) {
165
+			$type =
152 166
 		"Content-Type: text/plain;charset=\"$charset\";\n".
153 167
 		"Content-Transfer-Encoding: 8bit\n";
154
-	else $type = '';
168
+	} else {
169
+	    $type = '';
170
+	}
155 171
 
156 172
 	// calculer un identifiant unique
157 173
 	preg_match('/@\S+/', $from, $domain);
@@ -181,7 +197,9 @@  discard block
 block discarded – undo
181 197
 
182 198
 	// Nettoyer les en-tetes envoyees
183 199
 	// Ajouter le \n final
184
-	if (strlen($headers = trim($headers))) $headers .= "\n";
200
+	if (strlen($headers = trim($headers))) {
201
+	    $headers .= "\n";
202
+	}
185 203
 
186 204
 	// Et mentionner l'indeboulonable nomenclature ratee 
187 205
 
Please login to merge, or discard this patch.
ecrire/inc/idna_convert.class.php 2 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * the constructor
89 89
      *
90 90
      * @param array $options
91
-     * @return boolean
91
+     * @return boolean|null
92 92
      * @since 0.5.2
93 93
      */
94 94
     public function __construct($options = false)
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
     /**
394 394
      * Use this method to get the last error ocurred
395 395
      * @param    void
396
-     * @return   string   The last error, that occured
396
+     * @return   boolean   The last error, that occured
397 397
      */
398 398
     public function get_last_error()
399 399
     {
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
     /**
404 404
      * The actual decoding algorithm
405 405
      * @param string
406
-     * @return mixed
406
+     * @return false|string
407 407
      */
408 408
     protected function _decode($encoded)
409 409
     {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
     /**
465 465
      * The actual encoding algorithm
466 466
      * @param  string
467
-     * @return mixed
467
+     * @return false|string
468 468
      */
469 469
     protected function _encode($decoded)
470 470
     {
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
      * Decomposes a Hangul syllable
700 700
      * (see http://www.unicode.org/unicode/reports/tr15/#Hangul
701 701
      * @param    integer  32bit UCS4 code point
702
-     * @return   array    Either Hangul Syllable decomposed or original 32bit value as one value array
702
+     * @return   integer[]    Either Hangul Syllable decomposed or original 32bit value as one value array
703 703
      */
704 704
     protected function _hangul_decompose($char)
705 705
     {
Please login to merge, or discard this patch.
Spacing   +43 added lines, -46 removed lines patch added patch discarded remove patch
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
     protected $_lcount = 19;
74 74
     protected $_vcount = 21;
75 75
     protected $_tcount = 28;
76
-    protected $_ncount = 588;   // _vcount * _tcount
76
+    protected $_ncount = 588; // _vcount * _tcount
77 77
     protected $_scount = 11172; // _lcount * _tcount * _vcount
78 78
     protected $_error = false;
79 79
     protected static $_mb_string_overload = null;
80 80
     // See {@link set_paramter()} for details of how to change the following
81 81
     // settings from within your script / application
82
-    protected $_api_encoding = 'utf8';   // Default input charset is UTF-8
83
-    protected $_allow_overlong = false;  // Overlong UTF-8 encodings are forbidden
84
-    protected $_strict_mode = false;     // Behave strict or not
85
-    protected $_idn_version = 2003;      // Can be either 2003 (old, default) or 2008
82
+    protected $_api_encoding = 'utf8'; // Default input charset is UTF-8
83
+    protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden
84
+    protected $_strict_mode = false; // Behave strict or not
85
+    protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008
86 86
 
87 87
     /**
88 88
      * the constructor
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                             $this->_api_encoding = $v;
141 141
                             break;
142 142
                         default:
143
-                            $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
143
+                            $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
144 144
                             return false;
145 145
                     }
146 146
                     break;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     if (in_array($v, array('2003', '2008'))) {
155 155
                         $this->_idn_version = $v;
156 156
                     } else {
157
-                        $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
157
+                        $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
158 158
                     }
159 159
                     break;
160 160
                 case 'encode_german_sz': // Deprecated
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                     }
166 166
                     break;
167 167
                 default:
168
-                    $this->_error('Set Parameter: Unknown option ' . $k);
168
+                    $this->_error('Set Parameter: Unknown option '.$k);
169 169
                     return false;
170 170
             }
171 171
         }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
                 case 'ucs4_array':
189 189
                     break;
190 190
                 default:
191
-                    $this->_error('Unknown encoding ' . $one_time_encoding);
191
+                    $this->_error('Unknown encoding '.$one_time_encoding);
192 192
                     return false;
193 193
             }
194 194
         }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             list ($email_pref, $input) = explode('@', $input, 2);
207 207
             $arr = explode('.', $input);
208 208
             foreach ($arr as $k => $v) {
209
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
209
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
210 210
                     $conv = $this->_decode($v);
211 211
                     if ($conv) {
212 212
                         $arr[$k] = $conv;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             $input = join('.', $arr);
217 217
             $arr = explode('.', $email_pref);
218 218
             foreach ($arr as $k => $v) {
219
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
219
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
220 220
                     $conv = $this->_decode($v);
221 221
                     if ($conv) {
222 222
                         $arr[$k] = $conv;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
                 }
225 225
             }
226 226
             $email_pref = join('.', $arr);
227
-            $return = $email_pref . '@' . $input;
227
+            $return = $email_pref.'@'.$input;
228 228
         } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters)
229 229
             // No no in strict mode
230 230
             if ($this->_strict_mode) {
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
                     }
242 242
                 }
243 243
                 $parsed['host'] = join('.', $arr);
244
-                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
245
-                        (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
244
+                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
245
+                        (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
246 246
                         $parsed['host'].
247
-                        (empty($parsed['port']) ? '' : ':' . $parsed['port']).
247
+                        (empty($parsed['port']) ? '' : ':'.$parsed['port']).
248 248
                         (empty($parsed['path']) ? '' : $parsed['path']).
249
-                        (empty($parsed['query']) ? '' : '?' . $parsed['query']).
250
-                        (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
249
+                        (empty($parsed['query']) ? '' : '?'.$parsed['query']).
250
+                        (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
251 251
             } else { // parse_url seems to have failed, try without it
252 252
                 $arr = explode('.', $input);
253 253
                 foreach ($arr as $k => $v) {
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
         // The output is UTF-8 by default, other output formats need conversion here
266 266
         // If one time encoding is given, use this, else the objects property
267 267
         switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
268
-            case 'utf8':        return $return; // break;
269
-            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));  // break;
268
+            case 'utf8' : return $return; // break;
269
+            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break;
270 270
             case 'ucs4_array':  return $this->_utf8_to_ucs4($return); // break;
271 271
             default:            $this->_error('Unsupported output format'); return false;
272 272
         }
@@ -283,15 +283,14 @@  discard block
 block discarded – undo
283 283
         // Forcing conversion of input to UCS4 array
284 284
         // If one time encoding is given, use this, else the objects property
285 285
         switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
286
-            case 'utf8':
287
-                $decoded = $this->_utf8_to_ucs4($decoded);
286
+            case 'utf8' : $decoded = $this->_utf8_to_ucs4($decoded);
288 287
                 break;
289 288
             case 'ucs4_string':
290 289
                 $decoded = $this->_ucs4_string_to_ucs4($decoded);
291 290
             case 'ucs4_array':
292 291
                 break;
293 292
             default:
294
-                $this->_error('Unsupported input format: ' . ($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
293
+                $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
295 294
                 return false;
296 295
         }
297 296
 
@@ -380,13 +379,13 @@  discard block
 block discarded – undo
380 379
             }
381 380
         }
382 381
         $parsed['host'] = join('.', $arr);
383
-        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
384
-                (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
382
+        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
383
+                (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
385 384
                 $parsed['host'].
386
-                (empty($parsed['port']) ? '' : ':' . $parsed['port']).
385
+                (empty($parsed['port']) ? '' : ':'.$parsed['port']).
387 386
                 (empty($parsed['path']) ? '' : $parsed['path']).
388
-                (empty($parsed['query']) ? '' : '?' . $parsed['query']).
389
-                (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
387
+                (empty($parsed['query']) ? '' : '?'.$parsed['query']).
388
+                (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
390 389
         return $return;
391 390
     }
392 391
 
@@ -409,11 +408,11 @@  discard block
 block discarded – undo
409 408
     {
410 409
         $decoded = array();
411 410
         // find the Punycode prefix
412
-        if (!preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $encoded)) {
411
+        if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) {
413 412
             $this->_error('This is not a punycode string');
414 413
             return false;
415 414
         }
416
-        $encode_test = preg_replace('!^' . preg_quote($this->_punycode_prefix, '!') . '!', '', $encoded);
415
+        $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded);
417 416
         // If nothing left after removing the prefix, it is hopeless
418 417
         if (!$encode_test) {
419 418
             $this->_error('The given encoded string was empty');
@@ -439,8 +438,7 @@  discard block
 block discarded – undo
439 438
             for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) {
440 439
                 $digit = $this->_decode_digit($encoded{$enco_idx++});
441 440
                 $idx += $digit * $w;
442
-                $t = ($k <= $bias) ? $this->_tmin :
443
-                        (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
441
+                $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
444 442
                 if ($digit < $t) {
445 443
                     break;
446 444
                 }
@@ -513,7 +511,7 @@  discard block
 block discarded – undo
513 511
             return $encoded; // All codepoints were basic ones
514 512
         }
515 513
         // Start with the prefix; copy it to output
516
-        $encoded = $this->_punycode_prefix . $encoded;
514
+        $encoded = $this->_punycode_prefix.$encoded;
517 515
         // If we have basic code points in output, add an hyphen to the end
518 516
         if ($codecount) {
519 517
             $encoded .= '-';
@@ -540,8 +538,7 @@  discard block
 block discarded – undo
540 538
                     $delta++;
541 539
                 } elseif ($decoded[$i] == $cur_code) {
542 540
                     for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) {
543
-                        $t = ($k <= $bias) ? $this->_tmin :
544
-                                (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
541
+                        $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
545 542
                         if ($q < $t) {
546 543
                             break;
547 544
                         }
@@ -628,12 +625,12 @@  discard block
 block discarded – undo
628 625
             }
629 626
             // Try to find prohibited input
630 627
             if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) {
631
-                $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
628
+                $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
632 629
                 return false;
633 630
             }
634 631
             foreach (self::$NP['prohibit_ranges'] as $range) {
635 632
                 if ($range[0] <= $v && $v <= $range[1]) {
636
-                    $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
633
+                    $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
637 634
                     return false;
638 635
                 }
639 636
             }
@@ -869,7 +866,7 @@  discard block
 block discarded – undo
869 866
                 $output[$out_len] = $v;
870 867
                 ++$out_len;
871 868
                 if ('add' == $mode) {
872
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
869
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
873 870
                     return false;
874 871
                 }
875 872
                 continue;
@@ -894,7 +891,7 @@  discard block
 block discarded – undo
894 891
                     $next_byte = 4;
895 892
                     $v = ($v - 252) << 30;
896 893
                 } else {
897
-                    $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k);
894
+                    $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k);
898 895
                     return false;
899 896
                 }
900 897
                 if ('add' == $mode) {
@@ -907,7 +904,7 @@  discard block
 block discarded – undo
907 904
                 if (!$this->_allow_overlong && $test == 'range') {
908 905
                     $test = 'none';
909 906
                     if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) {
910
-                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k);
907
+                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k);
911 908
                         return false;
912 909
                     }
913 910
                 }
@@ -916,7 +913,7 @@  discard block
 block discarded – undo
916 913
                     $output[($out_len - 1)] += $v;
917 914
                     --$next_byte;
918 915
                 } else {
919
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
916
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
920 917
                     return false;
921 918
                 }
922 919
                 if ($next_byte < 0) {
@@ -940,13 +937,13 @@  discard block
 block discarded – undo
940 937
             if ($v < 128) { // 7bit are transferred literally
941 938
                 $output .= chr($v);
942 939
             } elseif ($v < (1 << 11)) { // 2 bytes
943
-                $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
940
+                $output .= chr(192 + ($v >> 6)).chr(128 + ($v & 63));
944 941
             } elseif ($v < (1 << 16)) { // 3 bytes
945
-                $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
942
+                $output .= chr(224 + ($v >> 12)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
946 943
             } elseif ($v < (1 << 21)) { // 4 bytes
947
-                $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
944
+                $output .= chr(240 + ($v >> 18)).chr(128 + (($v >> 12) & 63)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
948 945
             } else {
949
-                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte ' . $k);
946
+                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k);
950 947
                 return false;
951 948
             }
952 949
         }
@@ -965,7 +962,7 @@  discard block
 block discarded – undo
965 962
         // Take array values and split output to 4 bytes per value
966 963
         // The bit mask is 255, which reads &11111111
967 964
         foreach ($input as $v) {
968
-            $output .= chr(($v >> 24) & 255) . chr(($v >> 16) & 255) . chr(($v >> 8) & 255) . chr($v & 255);
965
+            $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
969 966
         }
970 967
         return $output;
971 968
     }
@@ -995,7 +992,7 @@  discard block
 block discarded – undo
995 992
                 $out_len++;
996 993
                 $output[$out_len] = 0;
997 994
             }
998
-            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
995
+            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4)));
999 996
         }
1000 997
         return $output;
1001 998
     }
Please login to merge, or discard this patch.
ecrire/inc/lang.php 4 patches
Doc Comments   +8 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * 
31 31
  * @param string $lang
32 32
  *     La langue à utiliser
33
- * @return string|bool
33
+ * @return false|string
34 34
  *     string : La langue qui a été utilisée si trouvée
35 35
  *     false : aucune langue ne correspondait à la demande
36 36
 **/
@@ -154,6 +154,9 @@  discard block
 block discarded – undo
154 154
 // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax
155 155
 // 
156 156
 // http://doc.spip.org/@menu_langues
157
+/**
158
+ * @param string $nom_select
159
+ */
157 160
 function menu_langues($nom_select, $default='') {
158 161
 	include_spip('inc/actions');
159 162
 
@@ -184,6 +187,10 @@  discard block
 block discarded – undo
184 187
 }
185 188
 
186 189
 // http://doc.spip.org/@select_langues
190
+/**
191
+ * @param string $change
192
+ * @param string $options
193
+ */
187 194
 function select_langues($nom_select, $change, $options, $label="")
188 195
 {
189 196
 	static $cpt = 0;
Please login to merge, or discard this patch.
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -35,28 +35,28 @@  discard block
 block discarded – undo
35 35
  *     false : aucune langue ne correspondait à la demande
36 36
 **/
37 37
 function changer_langue($lang) {
38
-	global $spip_lang_rtl, $spip_lang_right, $spip_lang_left;
38
+    global $spip_lang_rtl, $spip_lang_right, $spip_lang_left;
39 39
 
40
-	$liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
-	. ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
40
+    $liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
+    . ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
42 42
 
43
-	// Si la langue demandee n'existe pas, on essaie d'autres variantes
44
-	// Exemple : 'pt-br' => 'pt_br' => 'pt'
45
-	$lang = str_replace('-', '_', trim($lang));
46
-	if (!$lang)
47
-		return false;
43
+    // Si la langue demandee n'existe pas, on essaie d'autres variantes
44
+    // Exemple : 'pt-br' => 'pt_br' => 'pt'
45
+    $lang = str_replace('-', '_', trim($lang));
46
+    if (!$lang)
47
+        return false;
48 48
 
49
-	if (strpos($liste_langues,",$lang,")!==false
50
-	OR ($lang = preg_replace(',_.*,', '', $lang)
51
-	AND strpos($liste_langues,",$lang,")!==false)) {
49
+    if (strpos($liste_langues,",$lang,")!==false
50
+    OR ($lang = preg_replace(',_.*,', '', $lang)
51
+    AND strpos($liste_langues,",$lang,")!==false)) {
52 52
 
53
-		$spip_lang_rtl =   lang_dir($lang, '', '_rtl');
54
-		$spip_lang_right = $spip_lang_rtl ? 'left' : 'right';
55
-		$spip_lang_left =  $spip_lang_rtl ? 'right' : 'left';
53
+        $spip_lang_rtl =   lang_dir($lang, '', '_rtl');
54
+        $spip_lang_right = $spip_lang_rtl ? 'left' : 'right';
55
+        $spip_lang_left =  $spip_lang_rtl ? 'right' : 'left';
56 56
 
57
-		return $GLOBALS['spip_lang'] = $lang;
58
-	} else
59
-		return false;
57
+        return $GLOBALS['spip_lang'] = $lang;
58
+    } else
59
+        return false;
60 60
 }
61 61
 
62 62
 //
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
70 70
 
71 71
 function choisir_traduction ($trads, $lang='') {
72
-	$k = approcher_langue($trads, $lang);
73
-	return $k ? $trads[$k] : array_shift($trads);
72
+    $k = approcher_langue($trads, $lang);
73
+    return $k ? $trads[$k] : array_shift($trads);
74 74
 }
75 75
 
76 76
 // retourne son 2e argument si c'est un index du premier
@@ -78,25 +78,25 @@  discard block
 block discarded – undo
78 78
 // la langue X etant consideree comme une approche de X_Y
79 79
 function approcher_langue ($trads, $lang='') {
80 80
 
81
-	if (!$lang) $lang = $GLOBALS['spip_lang']; 
82
-
83
-	if (isset($trads[$lang])) {
84
-		return $lang;
85
-	}
86
-	// cas des langues xx_yy
87
-	else {
88
-		$r = explode('_', $lang);
89
-		if (isset($trads[$r[0]]))
90
-			return $r[0];
91
-	}
92
-	return '';
81
+    if (!$lang) $lang = $GLOBALS['spip_lang']; 
82
+
83
+    if (isset($trads[$lang])) {
84
+        return $lang;
85
+    }
86
+    // cas des langues xx_yy
87
+    else {
88
+        $r = explode('_', $lang);
89
+        if (isset($trads[$r[0]]))
90
+            return $r[0];
91
+    }
92
+    return '';
93 93
 }
94 94
 
95 95
 // http://doc.spip.org/@traduire_nom_langue
96 96
 function traduire_nom_langue($lang) {
97
-	include_spip('inc/lang_liste');
98
-	include_spip('inc/charsets');
99
-	return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
97
+    include_spip('inc/lang_liste');
98
+    include_spip('inc/charsets');
99
+    return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
100 100
 }
101 101
 
102 102
 //
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
111 111
 // http://doc.spip.org/@lang_dir
112 112
 function lang_dir($lang='', $droitier='ltr', $gaucher='rtl') {
113
-	static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi');
113
+    static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi');
114 114
 
115
-	return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
116
-		$gaucher : $droitier;
115
+    return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
116
+        $gaucher : $droitier;
117 117
 }
118 118
 
119 119
 // typo francaise ou anglaise ?
@@ -123,28 +123,28 @@  discard block
 block discarded – undo
123 123
 
124 124
 // http://doc.spip.org/@lang_typo
125 125
 function lang_typo($lang='') {
126
-	if (!$lang) {
127
-		$lang = isset($GLOBALS['lang_objet'])
128
-			? $GLOBALS['lang_objet']
129
-			: $GLOBALS['spip_lang'];
130
-	}
131
-	if ($lang == 'eo'
132
-	  OR $lang == 'fr'
133
-	  OR strncmp($lang, 'fr_', 3)==0
134
-	  OR $lang == 'cpf')
135
-		return 'fr';
136
-	else
137
-		return 'en';
126
+    if (!$lang) {
127
+        $lang = isset($GLOBALS['lang_objet'])
128
+            ? $GLOBALS['lang_objet']
129
+            : $GLOBALS['spip_lang'];
130
+    }
131
+    if ($lang == 'eo'
132
+      OR $lang == 'fr'
133
+      OR strncmp($lang, 'fr_', 3)==0
134
+      OR $lang == 'cpf')
135
+        return 'fr';
136
+    else
137
+        return 'en';
138 138
 }
139 139
 
140 140
 // gestion de la globale $lang_objet pour que les textes soient affiches
141 141
 // avec les memes typo et direction dans l'espace prive que dans le public
142 142
 // http://doc.spip.org/@changer_typo
143 143
 function changer_typo($lang = '') {
144
-	if ($lang)
145
-		$GLOBALS['lang_objet'] = $lang;
146
-	else
147
-		unset($GLOBALS['lang_objet']);
144
+    if ($lang)
145
+        $GLOBALS['lang_objet'] = $lang;
146
+    else
147
+        unset($GLOBALS['lang_objet']);
148 148
 }
149 149
 
150 150
 //
@@ -155,51 +155,51 @@  discard block
 block discarded – undo
155 155
 // 
156 156
 // http://doc.spip.org/@menu_langues
157 157
 function menu_langues($nom_select, $default='') {
158
-	include_spip('inc/actions');
159
-
160
-	$langues = liste_options_langues($nom_select);
161
-	$ret = "";
162
-	if (!count($langues))
163
-		return '';
164
-
165
-	if (!$default) $default = $GLOBALS['spip_lang'];
166
-	foreach ($langues as $l) {
167
-		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
168
-		$ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n";
169
-	}
170
-
171
-	if (!test_espace_prive()) {
172
-		$cible = self();
173
-		$base = '';
174
-	} else {
175
-		$cible = self();
176
-		$base = spip_connect() ? 'base' : '';
177
-	}
178
-
179
-	$change = ' onchange="this.parentNode.parentNode.submit()"';
180
-	return generer_action_auteur('converser',$base, $cible,
181
-		(select_langues($nom_select, $change, $ret)
182
-		 . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='". _T('bouton_changer')."' /></div></noscript>"),
183
-				     " method='post'");
158
+    include_spip('inc/actions');
159
+
160
+    $langues = liste_options_langues($nom_select);
161
+    $ret = "";
162
+    if (!count($langues))
163
+        return '';
164
+
165
+    if (!$default) $default = $GLOBALS['spip_lang'];
166
+    foreach ($langues as $l) {
167
+        $selected = ($l == $default) ? ' selected=\'selected\'' : '';
168
+        $ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n";
169
+    }
170
+
171
+    if (!test_espace_prive()) {
172
+        $cible = self();
173
+        $base = '';
174
+    } else {
175
+        $cible = self();
176
+        $base = spip_connect() ? 'base' : '';
177
+    }
178
+
179
+    $change = ' onchange="this.parentNode.parentNode.submit()"';
180
+    return generer_action_auteur('converser',$base, $cible,
181
+        (select_langues($nom_select, $change, $ret)
182
+            . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='". _T('bouton_changer')."' /></div></noscript>"),
183
+                        " method='post'");
184 184
 }
185 185
 
186 186
 // http://doc.spip.org/@select_langues
187 187
 function select_langues($nom_select, $change, $options, $label="")
188 188
 {
189
-	static $cpt = 0;
190
-	$id = "menu_langues" . $cpt++;
191
-	return
192
-		"<label for='$id'>".($label?$label:_T('info_langues'))."</label> ".
193
-		"<select name='$nom_select' id='$id' "
194
-	  . ((!test_espace_prive()) ?
195
-	     ("class='forml menu_langues'") :
196
-	     (($nom_select == 'var_lang_ecrire')  ?
197
-	      ("class='lang_ecrire'") :
198
-	      "class='fondl'"))
199
-	  . $change
200
-	  . ">\n"
201
-	  . $options
202
-	  . "</select>";
189
+    static $cpt = 0;
190
+    $id = "menu_langues" . $cpt++;
191
+    return
192
+        "<label for='$id'>".($label?$label:_T('info_langues'))."</label> ".
193
+        "<select name='$nom_select' id='$id' "
194
+        . ((!test_espace_prive()) ?
195
+         ("class='forml menu_langues'") :
196
+         (($nom_select == 'var_lang_ecrire')  ?
197
+          ("class='lang_ecrire'") :
198
+          "class='fondl'"))
199
+        . $change
200
+        . ">\n"
201
+        . $options
202
+        . "</select>";
203 203
 }
204 204
 
205 205
 /**
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
  */
221 221
 function liste_options_langues($nom_select) {
222 222
 
223
-	switch($nom_select) {
224
-		# #MENU_LANG
225
-		case 'var_lang':
226
-		# menu de changement de la langue d'un article
227
-		# les langues selectionnees dans la configuration "multilinguisme"
228
-		case 'changer_lang':
229
-			$langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
230
-			break;
231
-	# menu de l'interface (privee, installation et panneau de login)
232
-	# les langues presentes sous forme de fichiers de langue
233
-	# on force la relecture du repertoire des langues pour etre synchrone.
234
-		case 'var_lang_ecrire':
235
-		default:
236
-			$GLOBALS['meta']['langues_proposees'] = '';
237
-			init_langues();
238
-			$langues = explode(',', $GLOBALS['meta']['langues_proposees']);
239
-			break;
223
+    switch($nom_select) {
224
+        # #MENU_LANG
225
+        case 'var_lang':
226
+        # menu de changement de la langue d'un article
227
+        # les langues selectionnees dans la configuration "multilinguisme"
228
+        case 'changer_lang':
229
+            $langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
230
+            break;
231
+    # menu de l'interface (privee, installation et panneau de login)
232
+    # les langues presentes sous forme de fichiers de langue
233
+    # on force la relecture du repertoire des langues pour etre synchrone.
234
+        case 'var_lang_ecrire':
235
+        default:
236
+            $GLOBALS['meta']['langues_proposees'] = '';
237
+            init_langues();
238
+            $langues = explode(',', $GLOBALS['meta']['langues_proposees']);
239
+            break;
240 240
 
241 241
 # dernier choix possible : toutes les langues = langues_proposees 
242 242
 # + langues_multilingues ; mais, ne sert pas
243 243
 #			$langues = explode(',', $GLOBALS['all_langs']);
244
-	}
245
-	if (count($langues) <= 1) return array();
246
-	sort($langues);
247
-	return $langues;
244
+    }
245
+    if (count($langues) <= 1) return array();
246
+    sort($langues);
247
+    return $langues;
248 248
 }
249 249
 
250 250
 
@@ -259,35 +259,35 @@  discard block
 block discarded – undo
259 259
  * @return void
260 260
 **/
261 261
 function verifier_lang_url() {
262
-	global $spip_lang;
263
-
264
-	// quelle langue est demandee ?
265
-	$lang_demandee = (test_espace_prive()?$GLOBALS['spip_lang']:$GLOBALS['meta']['langue_site']);
266
-	if (isset($_COOKIE['spip_lang_ecrire']))
267
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
268
-	if (!test_espace_prive() AND isset($_COOKIE['spip_lang']))
269
-		$lang_demandee = $_COOKIE['spip_lang'];
270
-	if (isset($_GET['lang']))
271
-		$lang_demandee = $_GET['lang'];
272
-
273
-	// Renvoyer si besoin (et si la langue demandee existe)
274
-	if ($spip_lang != $lang_demandee
275
-	AND changer_langue($lang_demandee)
276
-	AND $lang_demandee != @$_GET['lang']) {
277
-		$destination = parametre_url(self(),'lang', $lang_demandee, '&');
278
-		// ici on a besoin des var_truc
279
-		foreach ($_GET as $var => $val) {
280
-			if (!strncmp('var_', $var, 4))
281
-				$destination = parametre_url($destination, $var, $val, '&');
282
-		}
283
-		include_spip('inc/headers');
284
-		redirige_par_entete($destination);
285
-	}
286
-
287
-	// Subtilite : si la langue demandee par cookie est la bonne
288
-	// alors on fait comme si $lang etait passee dans l'URL
289
-	// (pour criteres {lang}).
290
-	$GLOBALS['lang'] = $_GET['lang'] = $spip_lang;
262
+    global $spip_lang;
263
+
264
+    // quelle langue est demandee ?
265
+    $lang_demandee = (test_espace_prive()?$GLOBALS['spip_lang']:$GLOBALS['meta']['langue_site']);
266
+    if (isset($_COOKIE['spip_lang_ecrire']))
267
+        $lang_demandee = $_COOKIE['spip_lang_ecrire'];
268
+    if (!test_espace_prive() AND isset($_COOKIE['spip_lang']))
269
+        $lang_demandee = $_COOKIE['spip_lang'];
270
+    if (isset($_GET['lang']))
271
+        $lang_demandee = $_GET['lang'];
272
+
273
+    // Renvoyer si besoin (et si la langue demandee existe)
274
+    if ($spip_lang != $lang_demandee
275
+    AND changer_langue($lang_demandee)
276
+    AND $lang_demandee != @$_GET['lang']) {
277
+        $destination = parametre_url(self(),'lang', $lang_demandee, '&');
278
+        // ici on a besoin des var_truc
279
+        foreach ($_GET as $var => $val) {
280
+            if (!strncmp('var_', $var, 4))
281
+                $destination = parametre_url($destination, $var, $val, '&');
282
+        }
283
+        include_spip('inc/headers');
284
+        redirige_par_entete($destination);
285
+    }
286
+
287
+    // Subtilite : si la langue demandee par cookie est la bonne
288
+    // alors on fait comme si $lang etait passee dans l'URL
289
+    // (pour criteres {lang}).
290
+    $GLOBALS['lang'] = $_GET['lang'] = $spip_lang;
291 291
 }
292 292
 
293 293
 
@@ -303,20 +303,20 @@  discard block
 block discarded – undo
303 303
  *     La langue sélectionnée
304 304
 **/
305 305
 function utiliser_langue_site() {
306
-	// s'il existe une langue du site (en gros tout le temps en théorie)
307
-	if (isset($GLOBALS['meta']['langue_site'])
308
-	  // et si spip_langue est pas encore définie (ce que va faire changer_langue())
309
-	  // ou qu'elle n'est pas identique à la langue du site
310
-	  AND (!isset($GLOBALS['spip_lang'])
311
-	    OR $GLOBALS['spip_lang']!=$GLOBALS['meta']['langue_site']))
312
-	{
313
-		return changer_langue($GLOBALS['meta']['langue_site']);//@:install
314
-	}
315
-	// en theorie là, la globale est définie, sinon c'est un problème.
316
-	if (!isset($GLOBALS['spip_lang'])) {
317
-		spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR);
318
-	}
319
-	return $GLOBALS['spip_lang'];
306
+    // s'il existe une langue du site (en gros tout le temps en théorie)
307
+    if (isset($GLOBALS['meta']['langue_site'])
308
+        // et si spip_langue est pas encore définie (ce que va faire changer_langue())
309
+        // ou qu'elle n'est pas identique à la langue du site
310
+      AND (!isset($GLOBALS['spip_lang'])
311
+        OR $GLOBALS['spip_lang']!=$GLOBALS['meta']['langue_site']))
312
+    {
313
+        return changer_langue($GLOBALS['meta']['langue_site']);//@:install
314
+    }
315
+    // en theorie là, la globale est définie, sinon c'est un problème.
316
+    if (!isset($GLOBALS['spip_lang'])) {
317
+        spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR);
318
+    }
319
+    return $GLOBALS['spip_lang'];
320 320
 }
321 321
 
322 322
 /**
@@ -333,23 +333,23 @@  discard block
 block discarded – undo
333 333
 **/
334 334
 function utiliser_langue_visiteur() {
335 335
 
336
-	$l = (!test_espace_prive()  ? 'spip_lang' : 'spip_lang_ecrire');
337
-	if (isset($_COOKIE[$l]))
338
-		if (changer_langue($l = $_COOKIE[$l]))
339
-			return $l;
336
+    $l = (!test_espace_prive()  ? 'spip_lang' : 'spip_lang_ecrire');
337
+    if (isset($_COOKIE[$l]))
338
+        if (changer_langue($l = $_COOKIE[$l]))
339
+            return $l;
340 340
 
341
-	if (isset($GLOBALS['visiteur_session']['lang']))
342
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang']))
343
-			return $l;
341
+    if (isset($GLOBALS['visiteur_session']['lang']))
342
+        if (changer_langue($l = $GLOBALS['visiteur_session']['lang']))
343
+            return $l;
344 344
 
345
-	foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s)  {
346
-		if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
347
-			if (changer_langue($l=strtolower($r[1])))
348
-				return $l;
349
-		}
350
-	}
345
+    foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s)  {
346
+        if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
347
+            if (changer_langue($l=strtolower($r[1])))
348
+                return $l;
349
+        }
350
+    }
351 351
 
352
-	return utiliser_langue_site();
352
+    return utiliser_langue_site();
353 353
 }
354 354
 
355 355
 
@@ -367,16 +367,16 @@  discard block
 block discarded – undo
367 367
  *     Retourne ecrire/lang/ s'il rien ne semble correspondre.
368 368
 **/
369 369
 function repertoire_lang($module='spip', $lang='fr') {
370
-	# valeur forcee (par ex.sur spip.net), old style, a faire disparaitre
371
-	if (defined('_DIR_LANG'))
372
-		return _DIR_LANG;
370
+    # valeur forcee (par ex.sur spip.net), old style, a faire disparaitre
371
+    if (defined('_DIR_LANG'))
372
+        return _DIR_LANG;
373 373
 
374
-	# regarder s'il existe une v.f. qq part
375
-	if ($f = find_in_path($module.'_'.$lang . '.php', 'lang/'))
376
-		return dirname($f).'/';
374
+    # regarder s'il existe une v.f. qq part
375
+    if ($f = find_in_path($module.'_'.$lang . '.php', 'lang/'))
376
+        return dirname($f).'/';
377 377
 
378
-	# sinon, je ne sais trop pas quoi dire...
379
-	return _DIR_RESTREINT . 'lang/';
378
+    # sinon, je ne sais trop pas quoi dire...
379
+    return _DIR_RESTREINT . 'lang/';
380 380
 }
381 381
 
382 382
 
@@ -395,34 +395,34 @@  discard block
 block discarded – undo
395 395
 **/
396 396
 function init_langues() {
397 397
 
398
-	// liste des langues dans les meta, sauf a l'install
399
-	$all_langs = @$GLOBALS['meta']['langues_proposees'];
400
-
401
-	$tout = array();
402
-	if (!$all_langs) {
403
-		if ($d = @opendir(repertoire_lang())) {
404
-			while (($f = readdir($d)) !== false) {
405
-				if (preg_match(',^spip_([a-z_]+)\.php[3]?$,', $f, $regs))
406
-					$tout[] = $regs[1];
407
-			}
408
-			closedir($d);
409
-			sort($tout);
410
-			$tout = join(',', $tout);
411
-			// Si les langues n'ont pas change, ne rien faire
412
-			if ($tout != $all_langs) {
413
-				$GLOBALS['meta']['langues_proposees'] =	$tout;
414
-				include_spip('inc/meta');
415
-				ecrire_meta('langues_proposees', $tout);
416
-			} else $tout = '';
417
-		}
418
-	}
419
-	if (!isset($GLOBALS['meta']['langue_site'])) {
420
-		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
421
-		$GLOBALS['meta']['langue_site'] = $tout =
422
-		(!$all_langs OR (strpos(','._LANGUE_PAR_DEFAUT.',',",$all_langs,")!==false))
423
-		  ? _LANGUE_PAR_DEFAUT :  substr($all_langs,0,strpos($all_langs,','));
424
-		ecrire_meta('langue_site', $tout);
425
-	}
398
+    // liste des langues dans les meta, sauf a l'install
399
+    $all_langs = @$GLOBALS['meta']['langues_proposees'];
400
+
401
+    $tout = array();
402
+    if (!$all_langs) {
403
+        if ($d = @opendir(repertoire_lang())) {
404
+            while (($f = readdir($d)) !== false) {
405
+                if (preg_match(',^spip_([a-z_]+)\.php[3]?$,', $f, $regs))
406
+                    $tout[] = $regs[1];
407
+            }
408
+            closedir($d);
409
+            sort($tout);
410
+            $tout = join(',', $tout);
411
+            // Si les langues n'ont pas change, ne rien faire
412
+            if ($tout != $all_langs) {
413
+                $GLOBALS['meta']['langues_proposees'] =	$tout;
414
+                include_spip('inc/meta');
415
+                ecrire_meta('langues_proposees', $tout);
416
+            } else $tout = '';
417
+        }
418
+    }
419
+    if (!isset($GLOBALS['meta']['langue_site'])) {
420
+        // Initialisation : le francais si dispo, sinon la premiere langue trouvee
421
+        $GLOBALS['meta']['langue_site'] = $tout =
422
+        (!$all_langs OR (strpos(','._LANGUE_PAR_DEFAUT.',',",$all_langs,")!==false))
423
+          ? _LANGUE_PAR_DEFAUT :  substr($all_langs,0,strpos($all_langs,','));
424
+        ecrire_meta('langue_site', $tout);
425
+    }
426 426
 }
427 427
 
428 428
 /**
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
 **/
438 438
 function html_lang_attributes()
439 439
 {
440
-	$lang = $GLOBALS['spip_lang'];
441
-	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
442
-	return  "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n" ;
440
+    $lang = $GLOBALS['spip_lang'];
441
+    $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
442
+    return  "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n" ;
443 443
 }
444 444
 
445 445
 // initialise les globales (liste des langue, langue du site, spip_lang...)
Please login to merge, or discard this patch.
Braces   +70 added lines, -44 removed lines patch added patch discarded remove patch
@@ -15,7 +15,9 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @package SPIP\Langue
17 17
 **/
18
-if (!defined('_ECRIRE_INC_VERSION')) return;
18
+if (!defined('_ECRIRE_INC_VERSION')) {
19
+    return;
20
+}
19 21
 
20 22
 
21 23
 
@@ -43,8 +45,9 @@  discard block
 block discarded – undo
43 45
 	// Si la langue demandee n'existe pas, on essaie d'autres variantes
44 46
 	// Exemple : 'pt-br' => 'pt_br' => 'pt'
45 47
 	$lang = str_replace('-', '_', trim($lang));
46
-	if (!$lang)
47
-		return false;
48
+	if (!$lang) {
49
+			return false;
50
+	}
48 51
 
49 52
 	if (strpos($liste_langues,",$lang,")!==false
50 53
 	OR ($lang = preg_replace(',_.*,', '', $lang)
@@ -55,9 +58,10 @@  discard block
 block discarded – undo
55 58
 		$spip_lang_left =  $spip_lang_rtl ? 'right' : 'left';
56 59
 
57 60
 		return $GLOBALS['spip_lang'] = $lang;
58
-	} else
59
-		return false;
60
-}
61
+	} else {
62
+			return false;
63
+	}
64
+	}
61 65
 
62 66
 //
63 67
 // Gestion des blocs multilingues
@@ -78,7 +82,9 @@  discard block
 block discarded – undo
78 82
 // la langue X etant consideree comme une approche de X_Y
79 83
 function approcher_langue ($trads, $lang='') {
80 84
 
81
-	if (!$lang) $lang = $GLOBALS['spip_lang']; 
85
+	if (!$lang) {
86
+	    $lang = $GLOBALS['spip_lang'];
87
+	}
82 88
 
83 89
 	if (isset($trads[$lang])) {
84 90
 		return $lang;
@@ -86,8 +92,9 @@  discard block
 block discarded – undo
86 92
 	// cas des langues xx_yy
87 93
 	else {
88 94
 		$r = explode('_', $lang);
89
-		if (isset($trads[$r[0]]))
90
-			return $r[0];
95
+		if (isset($trads[$r[0]])) {
96
+					return $r[0];
97
+		}
91 98
 	}
92 99
 	return '';
93 100
 }
@@ -131,21 +138,23 @@  discard block
 block discarded – undo
131 138
 	if ($lang == 'eo'
132 139
 	  OR $lang == 'fr'
133 140
 	  OR strncmp($lang, 'fr_', 3)==0
134
-	  OR $lang == 'cpf')
135
-		return 'fr';
136
-	else
137
-		return 'en';
138
-}
141
+	  OR $lang == 'cpf') {
142
+			return 'fr';
143
+	} else {
144
+			return 'en';
145
+	}
146
+	}
139 147
 
140 148
 // gestion de la globale $lang_objet pour que les textes soient affiches
141 149
 // avec les memes typo et direction dans l'espace prive que dans le public
142 150
 // http://doc.spip.org/@changer_typo
143 151
 function changer_typo($lang = '') {
144
-	if ($lang)
145
-		$GLOBALS['lang_objet'] = $lang;
146
-	else
147
-		unset($GLOBALS['lang_objet']);
148
-}
152
+	if ($lang) {
153
+			$GLOBALS['lang_objet'] = $lang;
154
+	} else {
155
+			unset($GLOBALS['lang_objet']);
156
+	}
157
+	}
149 158
 
150 159
 //
151 160
 // Afficher un menu de selection de langue
@@ -159,10 +168,13 @@  discard block
 block discarded – undo
159 168
 
160 169
 	$langues = liste_options_langues($nom_select);
161 170
 	$ret = "";
162
-	if (!count($langues))
163
-		return '';
171
+	if (!count($langues)) {
172
+			return '';
173
+	}
164 174
 
165
-	if (!$default) $default = $GLOBALS['spip_lang'];
175
+	if (!$default) {
176
+	    $default = $GLOBALS['spip_lang'];
177
+	}
166 178
 	foreach ($langues as $l) {
167 179
 		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
168 180
 		$ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n";
@@ -242,7 +254,9 @@  discard block
 block discarded – undo
242 254
 # + langues_multilingues ; mais, ne sert pas
243 255
 #			$langues = explode(',', $GLOBALS['all_langs']);
244 256
 	}
245
-	if (count($langues) <= 1) return array();
257
+	if (count($langues) <= 1) {
258
+	    return array();
259
+	}
246 260
 	sort($langues);
247 261
 	return $langues;
248 262
 }
@@ -263,12 +277,15 @@  discard block
 block discarded – undo
263 277
 
264 278
 	// quelle langue est demandee ?
265 279
 	$lang_demandee = (test_espace_prive()?$GLOBALS['spip_lang']:$GLOBALS['meta']['langue_site']);
266
-	if (isset($_COOKIE['spip_lang_ecrire']))
267
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
268
-	if (!test_espace_prive() AND isset($_COOKIE['spip_lang']))
269
-		$lang_demandee = $_COOKIE['spip_lang'];
270
-	if (isset($_GET['lang']))
271
-		$lang_demandee = $_GET['lang'];
280
+	if (isset($_COOKIE['spip_lang_ecrire'])) {
281
+			$lang_demandee = $_COOKIE['spip_lang_ecrire'];
282
+	}
283
+	if (!test_espace_prive() AND isset($_COOKIE['spip_lang'])) {
284
+			$lang_demandee = $_COOKIE['spip_lang'];
285
+	}
286
+	if (isset($_GET['lang'])) {
287
+			$lang_demandee = $_GET['lang'];
288
+	}
272 289
 
273 290
 	// Renvoyer si besoin (et si la langue demandee existe)
274 291
 	if ($spip_lang != $lang_demandee
@@ -277,8 +294,9 @@  discard block
 block discarded – undo
277 294
 		$destination = parametre_url(self(),'lang', $lang_demandee, '&');
278 295
 		// ici on a besoin des var_truc
279 296
 		foreach ($_GET as $var => $val) {
280
-			if (!strncmp('var_', $var, 4))
281
-				$destination = parametre_url($destination, $var, $val, '&');
297
+			if (!strncmp('var_', $var, 4)) {
298
+							$destination = parametre_url($destination, $var, $val, '&');
299
+			}
282 300
 		}
283 301
 		include_spip('inc/headers');
284 302
 		redirige_par_entete($destination);
@@ -334,18 +352,21 @@  discard block
 block discarded – undo
334 352
 function utiliser_langue_visiteur() {
335 353
 
336 354
 	$l = (!test_espace_prive()  ? 'spip_lang' : 'spip_lang_ecrire');
337
-	if (isset($_COOKIE[$l]))
338
-		if (changer_langue($l = $_COOKIE[$l]))
355
+	if (isset($_COOKIE[$l])) {
356
+			if (changer_langue($l = $_COOKIE[$l]))
339 357
 			return $l;
358
+	}
340 359
 
341
-	if (isset($GLOBALS['visiteur_session']['lang']))
342
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang']))
360
+	if (isset($GLOBALS['visiteur_session']['lang'])) {
361
+			if (changer_langue($l = $GLOBALS['visiteur_session']['lang']))
343 362
 			return $l;
363
+	}
344 364
 
345 365
 	foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s)  {
346 366
 		if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
347
-			if (changer_langue($l=strtolower($r[1])))
348
-				return $l;
367
+			if (changer_langue($l=strtolower($r[1]))) {
368
+							return $l;
369
+			}
349 370
 		}
350 371
 	}
351 372
 
@@ -368,12 +389,14 @@  discard block
 block discarded – undo
368 389
 **/
369 390
 function repertoire_lang($module='spip', $lang='fr') {
370 391
 	# valeur forcee (par ex.sur spip.net), old style, a faire disparaitre
371
-	if (defined('_DIR_LANG'))
372
-		return _DIR_LANG;
392
+	if (defined('_DIR_LANG')) {
393
+			return _DIR_LANG;
394
+	}
373 395
 
374 396
 	# regarder s'il existe une v.f. qq part
375
-	if ($f = find_in_path($module.'_'.$lang . '.php', 'lang/'))
376
-		return dirname($f).'/';
397
+	if ($f = find_in_path($module.'_'.$lang . '.php', 'lang/')) {
398
+			return dirname($f).'/';
399
+	}
377 400
 
378 401
 	# sinon, je ne sais trop pas quoi dire...
379 402
 	return _DIR_RESTREINT . 'lang/';
@@ -402,8 +425,9 @@  discard block
 block discarded – undo
402 425
 	if (!$all_langs) {
403 426
 		if ($d = @opendir(repertoire_lang())) {
404 427
 			while (($f = readdir($d)) !== false) {
405
-				if (preg_match(',^spip_([a-z_]+)\.php[3]?$,', $f, $regs))
406
-					$tout[] = $regs[1];
428
+				if (preg_match(',^spip_([a-z_]+)\.php[3]?$,', $f, $regs)) {
429
+									$tout[] = $regs[1];
430
+				}
407 431
 			}
408 432
 			closedir($d);
409 433
 			sort($tout);
@@ -413,7 +437,9 @@  discard block
 block discarded – undo
413 437
 				$GLOBALS['meta']['langues_proposees'] =	$tout;
414 438
 				include_spip('inc/meta');
415 439
 				ecrire_meta('langues_proposees', $tout);
416
-			} else $tout = '';
440
+			} else {
441
+			    $tout = '';
442
+			}
417 443
 		}
418 444
 	}
419 445
 	if (!isset($GLOBALS['meta']['langue_site'])) {
Please login to merge, or discard this patch.
Spacing   +34 added lines, -36 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 function changer_langue($lang) {
38 38
 	global $spip_lang_rtl, $spip_lang_right, $spip_lang_left;
39 39
 
40
-	$liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
-	. ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
40
+	$liste_langues = ','.@$GLOBALS['meta']['langues_proposees']
41
+	. ','.@$GLOBALS['meta']['langues_multilingue'].',';
42 42
 
43 43
 	// Si la langue demandee n'existe pas, on essaie d'autres variantes
44 44
 	// Exemple : 'pt-br' => 'pt_br' => 'pt'
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 	if (!$lang)
47 47
 		return false;
48 48
 
49
-	if (strpos($liste_langues,",$lang,")!==false
49
+	if (strpos($liste_langues, ",$lang,") !== false
50 50
 	OR ($lang = preg_replace(',_.*,', '', $lang)
51
-	AND strpos($liste_langues,",$lang,")!==false)) {
51
+	AND strpos($liste_langues, ",$lang,") !== false)) {
52 52
 
53
-		$spip_lang_rtl =   lang_dir($lang, '', '_rtl');
53
+		$spip_lang_rtl = lang_dir($lang, '', '_rtl');
54 54
 		$spip_lang_right = $spip_lang_rtl ? 'left' : 'right';
55
-		$spip_lang_left =  $spip_lang_rtl ? 'right' : 'left';
55
+		$spip_lang_left = $spip_lang_rtl ? 'right' : 'left';
56 56
 
57 57
 		return $GLOBALS['spip_lang'] = $lang;
58 58
 	} else
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 // ou permettre de choisir une langue "plus proche",
69 69
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
70 70
 
71
-function choisir_traduction ($trads, $lang='') {
71
+function choisir_traduction($trads, $lang = '') {
72 72
 	$k = approcher_langue($trads, $lang);
73 73
 	return $k ? $trads[$k] : array_shift($trads);
74 74
 }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 // retourne son 2e argument si c'est un index du premier
77 77
 // ou un index approchant sinon et si possible, 
78 78
 // la langue X etant consideree comme une approche de X_Y
79
-function approcher_langue ($trads, $lang='') {
79
+function approcher_langue($trads, $lang = '') {
80 80
 
81 81
 	if (!$lang) $lang = $GLOBALS['spip_lang']; 
82 82
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 // hebreu a priori), 'droitier' sinon.
110 110
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
111 111
 // http://doc.spip.org/@lang_dir
112
-function lang_dir($lang='', $droitier='ltr', $gaucher='rtl') {
112
+function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') {
113 113
 	static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi');
114 114
 
115 115
 	return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 // sinon determiner la typo en fonction de la langue courante
123 123
 
124 124
 // http://doc.spip.org/@lang_typo
125
-function lang_typo($lang='') {
125
+function lang_typo($lang = '') {
126 126
 	if (!$lang) {
127 127
 		$lang = isset($GLOBALS['lang_objet'])
128 128
 			? $GLOBALS['lang_objet']
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	}
131 131
 	if ($lang == 'eo'
132 132
 	  OR $lang == 'fr'
133
-	  OR strncmp($lang, 'fr_', 3)==0
133
+	  OR strncmp($lang, 'fr_', 3) == 0
134 134
 	  OR $lang == 'cpf')
135 135
 		return 'fr';
136 136
 	else
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax
155 155
 // 
156 156
 // http://doc.spip.org/@menu_langues
157
-function menu_langues($nom_select, $default='') {
157
+function menu_langues($nom_select, $default = '') {
158 158
 	include_spip('inc/actions');
159 159
 
160 160
 	$langues = liste_options_langues($nom_select);
@@ -177,25 +177,23 @@  discard block
 block discarded – undo
177 177
 	}
178 178
 
179 179
 	$change = ' onchange="this.parentNode.parentNode.submit()"';
180
-	return generer_action_auteur('converser',$base, $cible,
180
+	return generer_action_auteur('converser', $base, $cible,
181 181
 		(select_langues($nom_select, $change, $ret)
182
-		 . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='". _T('bouton_changer')."' /></div></noscript>"),
182
+		 . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"),
183 183
 				     " method='post'");
184 184
 }
185 185
 
186 186
 // http://doc.spip.org/@select_langues
187
-function select_langues($nom_select, $change, $options, $label="")
187
+function select_langues($nom_select, $change, $options, $label = "")
188 188
 {
189 189
 	static $cpt = 0;
190
-	$id = "menu_langues" . $cpt++;
190
+	$id = "menu_langues".$cpt++;
191 191
 	return
192
-		"<label for='$id'>".($label?$label:_T('info_langues'))."</label> ".
192
+		"<label for='$id'>".($label ? $label : _T('info_langues'))."</label> ".
193 193
 		"<select name='$nom_select' id='$id' "
194 194
 	  . ((!test_espace_prive()) ?
195
-	     ("class='forml menu_langues'") :
196
-	     (($nom_select == 'var_lang_ecrire')  ?
197
-	      ("class='lang_ecrire'") :
198
-	      "class='fondl'"))
195
+	     ("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ?
196
+	      ("class='lang_ecrire'") : "class='fondl'"))
199 197
 	  . $change
200 198
 	  . ">\n"
201 199
 	  . $options
@@ -220,7 +218,7 @@  discard block
 block discarded – undo
220 218
  */
221 219
 function liste_options_langues($nom_select) {
222 220
 
223
-	switch($nom_select) {
221
+	switch ($nom_select) {
224 222
 		# #MENU_LANG
225 223
 		case 'var_lang':
226 224
 		# menu de changement de la langue d'un article
@@ -262,7 +260,7 @@  discard block
 block discarded – undo
262 260
 	global $spip_lang;
263 261
 
264 262
 	// quelle langue est demandee ?
265
-	$lang_demandee = (test_espace_prive()?$GLOBALS['spip_lang']:$GLOBALS['meta']['langue_site']);
263
+	$lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
266 264
 	if (isset($_COOKIE['spip_lang_ecrire']))
267 265
 		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
268 266
 	if (!test_espace_prive() AND isset($_COOKIE['spip_lang']))
@@ -274,7 +272,7 @@  discard block
 block discarded – undo
274 272
 	if ($spip_lang != $lang_demandee
275 273
 	AND changer_langue($lang_demandee)
276 274
 	AND $lang_demandee != @$_GET['lang']) {
277
-		$destination = parametre_url(self(),'lang', $lang_demandee, '&');
275
+		$destination = parametre_url(self(), 'lang', $lang_demandee, '&');
278 276
 		// ici on a besoin des var_truc
279 277
 		foreach ($_GET as $var => $val) {
280 278
 			if (!strncmp('var_', $var, 4))
@@ -308,9 +306,9 @@  discard block
 block discarded – undo
308 306
 	  // et si spip_langue est pas encore définie (ce que va faire changer_langue())
309 307
 	  // ou qu'elle n'est pas identique à la langue du site
310 308
 	  AND (!isset($GLOBALS['spip_lang'])
311
-	    OR $GLOBALS['spip_lang']!=$GLOBALS['meta']['langue_site']))
309
+	    OR $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']))
312 310
 	{
313
-		return changer_langue($GLOBALS['meta']['langue_site']);//@:install
311
+		return changer_langue($GLOBALS['meta']['langue_site']); //@:install
314 312
 	}
315 313
 	// en theorie là, la globale est définie, sinon c'est un problème.
316 314
 	if (!isset($GLOBALS['spip_lang'])) {
@@ -333,7 +331,7 @@  discard block
 block discarded – undo
333 331
 **/
334 332
 function utiliser_langue_visiteur() {
335 333
 
336
-	$l = (!test_espace_prive()  ? 'spip_lang' : 'spip_lang_ecrire');
334
+	$l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
337 335
 	if (isset($_COOKIE[$l]))
338 336
 		if (changer_langue($l = $_COOKIE[$l]))
339 337
 			return $l;
@@ -342,9 +340,9 @@  discard block
 block discarded – undo
342 340
 		if (changer_langue($l = $GLOBALS['visiteur_session']['lang']))
343 341
 			return $l;
344 342
 
345
-	foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s)  {
343
+	foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
346 344
 		if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
347
-			if (changer_langue($l=strtolower($r[1])))
345
+			if (changer_langue($l = strtolower($r[1])))
348 346
 				return $l;
349 347
 		}
350 348
 	}
@@ -366,17 +364,17 @@  discard block
 block discarded – undo
366 364
  *     Adresse du répertoire contenant le module
367 365
  *     Retourne ecrire/lang/ s'il rien ne semble correspondre.
368 366
 **/
369
-function repertoire_lang($module='spip', $lang='fr') {
367
+function repertoire_lang($module = 'spip', $lang = 'fr') {
370 368
 	# valeur forcee (par ex.sur spip.net), old style, a faire disparaitre
371 369
 	if (defined('_DIR_LANG'))
372 370
 		return _DIR_LANG;
373 371
 
374 372
 	# regarder s'il existe une v.f. qq part
375
-	if ($f = find_in_path($module.'_'.$lang . '.php', 'lang/'))
373
+	if ($f = find_in_path($module.'_'.$lang.'.php', 'lang/'))
376 374
 		return dirname($f).'/';
377 375
 
378 376
 	# sinon, je ne sais trop pas quoi dire...
379
-	return _DIR_RESTREINT . 'lang/';
377
+	return _DIR_RESTREINT.'lang/';
380 378
 }
381 379
 
382 380
 
@@ -410,7 +408,7 @@  discard block
 block discarded – undo
410 408
 			$tout = join(',', $tout);
411 409
 			// Si les langues n'ont pas change, ne rien faire
412 410
 			if ($tout != $all_langs) {
413
-				$GLOBALS['meta']['langues_proposees'] =	$tout;
411
+				$GLOBALS['meta']['langues_proposees'] = $tout;
414 412
 				include_spip('inc/meta');
415 413
 				ecrire_meta('langues_proposees', $tout);
416 414
 			} else $tout = '';
@@ -419,8 +417,8 @@  discard block
 block discarded – undo
419 417
 	if (!isset($GLOBALS['meta']['langue_site'])) {
420 418
 		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
421 419
 		$GLOBALS['meta']['langue_site'] = $tout =
422
-		(!$all_langs OR (strpos(','._LANGUE_PAR_DEFAUT.',',",$all_langs,")!==false))
423
-		  ? _LANGUE_PAR_DEFAUT :  substr($all_langs,0,strpos($all_langs,','));
420
+		(!$all_langs OR (strpos(','._LANGUE_PAR_DEFAUT.',', ",$all_langs,") !== false))
421
+		  ? _LANGUE_PAR_DEFAUT :  substr($all_langs, 0, strpos($all_langs, ','));
424 422
 		ecrire_meta('langue_site', $tout);
425 423
 	}
426 424
 }
@@ -439,7 +437,7 @@  discard block
 block discarded – undo
439 437
 {
440 438
 	$lang = $GLOBALS['spip_lang'];
441 439
 	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
442
-	return  "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n" ;
440
+	return  "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
443 441
 }
444 442
 
445 443
 // initialise les globales (liste des langue, langue du site, spip_lang...)
Please login to merge, or discard this patch.
ecrire/inc/math.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -19,6 +19,9 @@
 block discarded – undo
19 19
 //
20 20
 
21 21
 // http://doc.spip.org/@image_math
22
+/**
23
+ * @param string $tex
24
+ */
22 25
 function produire_image_math($tex) {
23 26
 	global $traiter_math;
24 27
 	switch ($traiter_math) {
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,56 +20,56 @@  discard block
 block discarded – undo
20 20
 
21 21
 // http://doc.spip.org/@image_math
22 22
 function produire_image_math($tex) {
23
-	global $traiter_math;
24
-	switch ($traiter_math) {
25
-		// Attention: mathml desactiv'e pour l'instant
26
-		case 'mathml':
27
-			$ext = '.xhtml';
28
-			$server = $GLOBALS['mathml_server'];
29
-			break;
30
-		case 'tex':
31
-			$ext = '.png';
32
-			$server = $GLOBALS['tex_server'];
33
-			break;
34
-		default:
35
-			return $tex;
36
-	}
37
-
38
-	// Regarder dans le repertoire local des images TeX et blocs MathML
39
-	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/'))
40
-		@mkdir ($dir_tex, _SPIP_CHMOD);
41
-	$fichier = $dir_tex .md5(trim($tex)).$ext;
23
+    global $traiter_math;
24
+    switch ($traiter_math) {
25
+        // Attention: mathml desactiv'e pour l'instant
26
+        case 'mathml':
27
+            $ext = '.xhtml';
28
+            $server = $GLOBALS['mathml_server'];
29
+            break;
30
+        case 'tex':
31
+            $ext = '.png';
32
+            $server = $GLOBALS['tex_server'];
33
+            break;
34
+        default:
35
+            return $tex;
36
+    }
37
+
38
+    // Regarder dans le repertoire local des images TeX et blocs MathML
39
+    if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/'))
40
+        @mkdir ($dir_tex, _SPIP_CHMOD);
41
+    $fichier = $dir_tex .md5(trim($tex)).$ext;
42 42
 	
43 43
 
44
-	if (!@file_exists($fichier)) {
45
-		// Aller chercher l'image sur le serveur
46
-		if ($server) {
47
-			spip_log($url = $server.'?'.rawurlencode($tex));
48
-			include_spip('inc/distant');
49
-			recuperer_page($url,$fichier);
50
-		}
51
-	}
44
+    if (!@file_exists($fichier)) {
45
+        // Aller chercher l'image sur le serveur
46
+        if ($server) {
47
+            spip_log($url = $server.'?'.rawurlencode($tex));
48
+            include_spip('inc/distant');
49
+            recuperer_page($url,$fichier);
50
+        }
51
+    }
52 52
 
53 53
 
54
-	// Composer la reponse selon presence ou non de l'image
55
-	$tex = entites_html($tex);
56
-	if (@file_exists($fichier)) {
54
+    // Composer la reponse selon presence ou non de l'image
55
+    $tex = entites_html($tex);
56
+    if (@file_exists($fichier)) {
57 57
 
58
-		// MathML
59
-		if ($traiter_math == 'mathml') {
60
-			return join(file("$fichier"),"");
61
-		}
58
+        // MathML
59
+        if ($traiter_math == 'mathml') {
60
+            return join(file("$fichier"),"");
61
+        }
62 62
 
63
-		// TeX
64
-		else {
65
-			list(,,,$size) = @getimagesize($fichier);
66
-			$alt = "alt=\"$tex\" title=\"$tex\""; 
67
-			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
68
-		}
63
+        // TeX
64
+        else {
65
+            list(,,,$size) = @getimagesize($fichier);
66
+            $alt = "alt=\"$tex\" title=\"$tex\""; 
67
+            return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
68
+        }
69 69
 
70
-	}
71
-	else // pas de fichier
72
-		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
70
+    }
71
+    else // pas de fichier
72
+        return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
73 73
 
74 74
 }
75 75
 
@@ -78,39 +78,39 @@  discard block
 block discarded – undo
78 78
 // http://doc.spip.org/@traiter_math
79 79
 function traiter_math($letexte, $source='') {
80 80
 
81
-	$texte_a_voir = $letexte;
82
-	while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
83
-		if (!$fin = strpos($texte_a_voir,"</math>"))
84
-			$fin = strlen($texte_a_voir);
85
-
86
-		$texte_debut = substr($texte_a_voir, 0, $debut);
87
-		$texte_milieu = substr($texte_a_voir,
88
-			$debut+strlen("<math>"), $fin-$debut-strlen("<math>"));
89
-		$texte_fin = substr($texte_a_voir,
90
-			$fin+strlen("</math>"), strlen($texte_a_voir));
91
-
92
-		// Les doubles $$x^2$$ en mode 'div'
93
-		while((preg_match(",[$][$]([^$]+)[$][$],",$texte_milieu, $regs))) {
94
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($regs[1])."</p>\n";
95
-			$pos = strpos($texte_milieu, $regs[0]);
96
-			$texte_milieu = substr($texte_milieu,0,$pos)
97
-				. code_echappement($echap, $source)
98
-				. substr($texte_milieu,$pos+strlen($regs[0]));
99
-		}
100
-
101
-		// Les simples $x^2$ en mode 'span'
102
-		while((preg_match(",[$]([^$]+)[$],",$texte_milieu, $regs))) {
103
-			$echap = produire_image_math($regs[1]);
104
-			$pos = strpos($texte_milieu, $regs[0]);
105
-			$texte_milieu = substr($texte_milieu,0,$pos)
106
-				. code_echappement($echap, $source)
107
-				. substr($texte_milieu,$pos+strlen($regs[0]));
108
-		}
109
-
110
-		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
111
-	}
112
-
113
-	return $texte_a_voir;
81
+    $texte_a_voir = $letexte;
82
+    while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
83
+        if (!$fin = strpos($texte_a_voir,"</math>"))
84
+            $fin = strlen($texte_a_voir);
85
+
86
+        $texte_debut = substr($texte_a_voir, 0, $debut);
87
+        $texte_milieu = substr($texte_a_voir,
88
+            $debut+strlen("<math>"), $fin-$debut-strlen("<math>"));
89
+        $texte_fin = substr($texte_a_voir,
90
+            $fin+strlen("</math>"), strlen($texte_a_voir));
91
+
92
+        // Les doubles $$x^2$$ en mode 'div'
93
+        while((preg_match(",[$][$]([^$]+)[$][$],",$texte_milieu, $regs))) {
94
+            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($regs[1])."</p>\n";
95
+            $pos = strpos($texte_milieu, $regs[0]);
96
+            $texte_milieu = substr($texte_milieu,0,$pos)
97
+                . code_echappement($echap, $source)
98
+                . substr($texte_milieu,$pos+strlen($regs[0]));
99
+        }
100
+
101
+        // Les simples $x^2$ en mode 'span'
102
+        while((preg_match(",[$]([^$]+)[$],",$texte_milieu, $regs))) {
103
+            $echap = produire_image_math($regs[1]);
104
+            $pos = strpos($texte_milieu, $regs[0]);
105
+            $texte_milieu = substr($texte_milieu,0,$pos)
106
+                . code_echappement($echap, $source)
107
+                . substr($texte_milieu,$pos+strlen($regs[0]));
108
+        }
109
+
110
+        $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
111
+    }
112
+
113
+    return $texte_a_voir;
114 114
 }
115 115
 
116 116
 ?>
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
 	// Regarder dans le repertoire local des images TeX et blocs MathML
39 39
 	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/'))
40
-		@mkdir ($dir_tex, _SPIP_CHMOD);
41
-	$fichier = $dir_tex .md5(trim($tex)).$ext;
40
+		@mkdir($dir_tex, _SPIP_CHMOD);
41
+	$fichier = $dir_tex.md5(trim($tex)).$ext;
42 42
 	
43 43
 
44 44
 	if (!@file_exists($fichier)) {
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		if ($server) {
47 47
 			spip_log($url = $server.'?'.rawurlencode($tex));
48 48
 			include_spip('inc/distant');
49
-			recuperer_page($url,$fichier);
49
+			recuperer_page($url, $fichier);
50 50
 		}
51 51
 	}
52 52
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
 		// MathML
59 59
 		if ($traiter_math == 'mathml') {
60
-			return join(file("$fichier"),"");
60
+			return join(file("$fichier"), "");
61 61
 		}
62 62
 
63 63
 		// TeX
@@ -76,35 +76,35 @@  discard block
 block discarded – undo
76 76
 
77 77
 // Fonction appelee par propre() s'il repere un mode <math>
78 78
 // http://doc.spip.org/@traiter_math
79
-function traiter_math($letexte, $source='') {
79
+function traiter_math($letexte, $source = '') {
80 80
 
81 81
 	$texte_a_voir = $letexte;
82 82
 	while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
83
-		if (!$fin = strpos($texte_a_voir,"</math>"))
83
+		if (!$fin = strpos($texte_a_voir, "</math>"))
84 84
 			$fin = strlen($texte_a_voir);
85 85
 
86 86
 		$texte_debut = substr($texte_a_voir, 0, $debut);
87 87
 		$texte_milieu = substr($texte_a_voir,
88
-			$debut+strlen("<math>"), $fin-$debut-strlen("<math>"));
88
+			$debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
89 89
 		$texte_fin = substr($texte_a_voir,
90
-			$fin+strlen("</math>"), strlen($texte_a_voir));
90
+			$fin + strlen("</math>"), strlen($texte_a_voir));
91 91
 
92 92
 		// Les doubles $$x^2$$ en mode 'div'
93
-		while((preg_match(",[$][$]([^$]+)[$][$],",$texte_milieu, $regs))) {
93
+		while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) {
94 94
 			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($regs[1])."</p>\n";
95 95
 			$pos = strpos($texte_milieu, $regs[0]);
96
-			$texte_milieu = substr($texte_milieu,0,$pos)
96
+			$texte_milieu = substr($texte_milieu, 0, $pos)
97 97
 				. code_echappement($echap, $source)
98
-				. substr($texte_milieu,$pos+strlen($regs[0]));
98
+				. substr($texte_milieu, $pos + strlen($regs[0]));
99 99
 		}
100 100
 
101 101
 		// Les simples $x^2$ en mode 'span'
102
-		while((preg_match(",[$]([^$]+)[$],",$texte_milieu, $regs))) {
102
+		while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) {
103 103
 			$echap = produire_image_math($regs[1]);
104 104
 			$pos = strpos($texte_milieu, $regs[0]);
105
-			$texte_milieu = substr($texte_milieu,0,$pos)
105
+			$texte_milieu = substr($texte_milieu, 0, $pos)
106 106
 				. code_echappement($echap, $source)
107
-				. substr($texte_milieu,$pos+strlen($regs[0]));
107
+				. substr($texte_milieu, $pos + strlen($regs[0]));
108 108
 		}
109 109
 
110 110
 		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 //
15
-if (!defined('_ECRIRE_INC_VERSION')) return;
15
+if (!defined('_ECRIRE_INC_VERSION')) {
16
+    return;
17
+}
16 18
 
17 19
 //
18 20
 // Gestion du raccourci <math>...</math> en client-serveur
@@ -36,8 +38,9 @@  discard block
 block discarded – undo
36 38
 	}
37 39
 
38 40
 	// Regarder dans le repertoire local des images TeX et blocs MathML
39
-	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/'))
40
-		@mkdir ($dir_tex, _SPIP_CHMOD);
41
+	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) {
42
+			@mkdir ($dir_tex, _SPIP_CHMOD);
43
+	}
41 44
 	$fichier = $dir_tex .md5(trim($tex)).$ext;
42 45
 	
43 46
 
@@ -67,9 +70,10 @@  discard block
 block discarded – undo
67 70
 			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
68 71
 		}
69 72
 
70
-	}
71
-	else // pas de fichier
73
+	} else {
74
+	    // pas de fichier
72 75
 		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
76
+	}
73 77
 
74 78
 }
75 79
 
@@ -80,8 +84,9 @@  discard block
 block discarded – undo
80 84
 
81 85
 	$texte_a_voir = $letexte;
82 86
 	while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
83
-		if (!$fin = strpos($texte_a_voir,"</math>"))
84
-			$fin = strlen($texte_a_voir);
87
+		if (!$fin = strpos($texte_a_voir,"</math>")) {
88
+					$fin = strlen($texte_a_voir);
89
+		}
85 90
 
86 91
 		$texte_debut = substr($texte_a_voir, 0, $debut);
87 92
 		$texte_milieu = substr($texte_a_voir,
Please login to merge, or discard this patch.