Completed
Push — master ( 1dde8c...5a052b )
by cam
01:06
created
ecrire/public/styliser.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  **/
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 // Ce fichier doit imperativement definir la fonction ci-dessous:
@@ -39,59 +39,59 @@  discard block
 block discarded – undo
39 39
  * @return array
40 40
  */
41 41
 function public_styliser_dist($fond, $contexte, $lang = '', $connect = '') {
42
-	static $styliser_par_z;
43
-
44
-	// s'assurer que le fond est licite
45
-	// car il peut etre construit a partir d'une variable d'environnement
46
-	if (strpos($fond, "../") !== false or strncmp($fond, '/', 1) == 0) {
47
-		$fond = "404";
48
-	}
49
-
50
-	if (strncmp($fond, 'modeles/', 8) == 0) {
51
-		$modele = substr($fond, 8);
52
-		$modele = styliser_modele($modele, null, $contexte);
53
-		$fond = "modeles/$modele";
54
-	}
55
-
56
-	// Choisir entre $fond-dist.html, $fond=7.html, etc?
57
-	$id_rubrique = 0;
58
-	// Chercher le fond qui va servir de squelette
59
-	if ($r = quete_rubrique_fond($contexte)) {
60
-		list($id_rubrique, $lang) = $r;
61
-	}
62
-
63
-	// trouver un squelette du nom demande
64
-	// ne rien dire si on ne trouve pas, 
65
-	// c'est l'appelant qui sait comment gerer la situation
66
-	// ou les plugins qui feront mieux dans le pipeline
67
-	$squelette = trouver_fond($fond, "", true);
68
-	$ext = $squelette['extension'];
69
-
70
-	$flux = array(
71
-		'args' => array(
72
-			'id_rubrique' => $id_rubrique,
73
-			'ext' => $ext,
74
-			'fond' => $fond,
75
-			'lang' => $lang,
76
-			'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
-			'connect' => $connect
78
-		),
79
-		'data' => $squelette['fond'],
80
-	);
81
-
82
-	if (test_espace_prive() or defined('_ZPIP')) {
83
-		if (!$styliser_par_z) {
84
-			$styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
-		}
86
-		$flux = $styliser_par_z($flux);
87
-	}
88
-
89
-	$flux = styliser_par_objets($flux);
90
-
91
-	// pipeline styliser
92
-	$squelette = pipeline('styliser', $flux);
93
-
94
-	return array($squelette, $ext, $ext, "$squelette.$ext");
42
+    static $styliser_par_z;
43
+
44
+    // s'assurer que le fond est licite
45
+    // car il peut etre construit a partir d'une variable d'environnement
46
+    if (strpos($fond, "../") !== false or strncmp($fond, '/', 1) == 0) {
47
+        $fond = "404";
48
+    }
49
+
50
+    if (strncmp($fond, 'modeles/', 8) == 0) {
51
+        $modele = substr($fond, 8);
52
+        $modele = styliser_modele($modele, null, $contexte);
53
+        $fond = "modeles/$modele";
54
+    }
55
+
56
+    // Choisir entre $fond-dist.html, $fond=7.html, etc?
57
+    $id_rubrique = 0;
58
+    // Chercher le fond qui va servir de squelette
59
+    if ($r = quete_rubrique_fond($contexte)) {
60
+        list($id_rubrique, $lang) = $r;
61
+    }
62
+
63
+    // trouver un squelette du nom demande
64
+    // ne rien dire si on ne trouve pas, 
65
+    // c'est l'appelant qui sait comment gerer la situation
66
+    // ou les plugins qui feront mieux dans le pipeline
67
+    $squelette = trouver_fond($fond, "", true);
68
+    $ext = $squelette['extension'];
69
+
70
+    $flux = array(
71
+        'args' => array(
72
+            'id_rubrique' => $id_rubrique,
73
+            'ext' => $ext,
74
+            'fond' => $fond,
75
+            'lang' => $lang,
76
+            'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
+            'connect' => $connect
78
+        ),
79
+        'data' => $squelette['fond'],
80
+    );
81
+
82
+    if (test_espace_prive() or defined('_ZPIP')) {
83
+        if (!$styliser_par_z) {
84
+            $styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
+        }
86
+        $flux = $styliser_par_z($flux);
87
+    }
88
+
89
+    $flux = styliser_par_objets($flux);
90
+
91
+    // pipeline styliser
92
+    $squelette = pipeline('styliser', $flux);
93
+
94
+    return array($squelette, $ext, $ext, "$squelette.$ext");
95 95
 }
96 96
 
97 97
 /**
@@ -110,31 +110,31 @@  discard block
 block discarded – undo
110 110
  *     Données du pipeline styliser
111 111
  **/
112 112
 function styliser_par_objets($flux) {
113
-	if (test_espace_prive()
114
-		and !$squelette = $flux['data']
115
-		and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
116
-		and $echafauder = charger_fonction('echafauder', 'prive', true)
117
-	) {
118
-		if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
119
-			$table = table_objet(substr($flux['args']['fond'], 19));
120
-			$table_sql = table_objet_sql($table);
121
-			$objets = lister_tables_objets_sql();
122
-			if (isset($objets[$table_sql])) {
123
-				$flux['data'] = $echafauder($table, $table, $table_sql, "prive/objets/liste/objets", $flux['args']['ext']);
124
-			}
125
-		}
126
-		if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
127
-			$type = substr($flux['args']['fond'], 21);
128
-			$table = table_objet($type);
129
-			$table_sql = table_objet_sql($table);
130
-			$objets = lister_tables_objets_sql();
131
-			if (isset($objets[$table_sql])) {
132
-				$flux['data'] = $echafauder($type, $table, $table_sql, "prive/objets/contenu/objet", $flux['args']['ext']);
133
-			}
134
-		}
135
-	}
136
-
137
-	return $flux;
113
+    if (test_espace_prive()
114
+        and !$squelette = $flux['data']
115
+        and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
116
+        and $echafauder = charger_fonction('echafauder', 'prive', true)
117
+    ) {
118
+        if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
119
+            $table = table_objet(substr($flux['args']['fond'], 19));
120
+            $table_sql = table_objet_sql($table);
121
+            $objets = lister_tables_objets_sql();
122
+            if (isset($objets[$table_sql])) {
123
+                $flux['data'] = $echafauder($table, $table, $table_sql, "prive/objets/liste/objets", $flux['args']['ext']);
124
+            }
125
+        }
126
+        if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
127
+            $type = substr($flux['args']['fond'], 21);
128
+            $table = table_objet($type);
129
+            $table_sql = table_objet_sql($table);
130
+            $objets = lister_tables_objets_sql();
131
+            if (isset($objets[$table_sql])) {
132
+                $flux['data'] = $echafauder($type, $table, $table_sql, "prive/objets/contenu/objet", $flux['args']['ext']);
133
+            }
134
+        }
135
+    }
136
+
137
+    return $flux;
138 138
 }
139 139
 
140 140
 /**
@@ -150,49 +150,49 @@  discard block
 block discarded – undo
150 150
  * @return array
151 151
  */
152 152
 function quete_rubrique_fond($contexte) {
153
-	static $liste_objets = null;
154
-	static $quete = array();
155
-	if (is_null($liste_objets)) {
156
-		$liste_objets = array();
157
-		include_spip('inc/urls');
158
-		include_spip('public/quete');
159
-		$l = urls_liste_objets(false);
160
-		// placer la rubrique en tete des objets
161
-		$l = array_diff($l, array('rubrique'));
162
-		array_unshift($l, 'rubrique');
163
-		foreach ($l as $objet) {
164
-			$id = id_table_objet($objet);
165
-			if (!isset($liste_objets[$id])) {
166
-				$liste_objets[$id] = objet_type($objet, false);
167
-			}
168
-		}
169
-	}
170
-	$c = array_intersect_key($contexte, $liste_objets);
171
-	if (!count($c)) {
172
-		return false;
173
-	}
174
-
175
-	$c = array_map('intval', $c);
176
-	$s = serialize($c);
177
-	if (isset($quete[$s])) {
178
-		return $quete[$s];
179
-	}
180
-
181
-	if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
182
-		unset($c['id_rubrique']);
183
-		$c = array('id_rubrique' => $r) + $c;
184
-	}
185
-
186
-	foreach ($c as $_id => $id) {
187
-		if ($id
188
-			and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
189
-		) {
190
-			$lang = isset($row['lang']) ? $row['lang'] : '';
191
-			if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
192
-				return $quete[$s] = array($id, $lang);
193
-			}
194
-		}
195
-	}
196
-
197
-	return $quete[$s] = false;
153
+    static $liste_objets = null;
154
+    static $quete = array();
155
+    if (is_null($liste_objets)) {
156
+        $liste_objets = array();
157
+        include_spip('inc/urls');
158
+        include_spip('public/quete');
159
+        $l = urls_liste_objets(false);
160
+        // placer la rubrique en tete des objets
161
+        $l = array_diff($l, array('rubrique'));
162
+        array_unshift($l, 'rubrique');
163
+        foreach ($l as $objet) {
164
+            $id = id_table_objet($objet);
165
+            if (!isset($liste_objets[$id])) {
166
+                $liste_objets[$id] = objet_type($objet, false);
167
+            }
168
+        }
169
+    }
170
+    $c = array_intersect_key($contexte, $liste_objets);
171
+    if (!count($c)) {
172
+        return false;
173
+    }
174
+
175
+    $c = array_map('intval', $c);
176
+    $s = serialize($c);
177
+    if (isset($quete[$s])) {
178
+        return $quete[$s];
179
+    }
180
+
181
+    if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
182
+        unset($c['id_rubrique']);
183
+        $c = array('id_rubrique' => $r) + $c;
184
+    }
185
+
186
+    foreach ($c as $_id => $id) {
187
+        if ($id
188
+            and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
189
+        ) {
190
+            $lang = isset($row['lang']) ? $row['lang'] : '';
191
+            if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
192
+                return $quete[$s] = array($id, $lang);
193
+            }
194
+        }
195
+    }
196
+
197
+    return $quete[$s] = false;
198 198
 }
Please login to merge, or discard this patch.
ecrire/balise/logo_.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -54,84 +54,84 @@  discard block
 block discarded – undo
54 54
  */
55 55
 function balise_LOGO__dist($p) {
56 56
 
57
-	preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
-	$type = strtolower($regs[1]);
59
-	$suite_logo = $regs[2];
60
-
61
-	// cas de #LOGO_SITE_SPIP
62
-	if ($type == 'site_spip') {
63
-		$type = 'site';
64
-		$_id_objet = "\"'0'\"";
65
-	}
66
-
67
-	$id_objet = id_table_objet($type);
68
-	if (!isset($_id_objet)) {
69
-		$_id_objet = champ_sql($id_objet, $p);
70
-	}
71
-
72
-	$fichier = ($p->etoile === '**') ? -1 : 0;
73
-	$coord = array();
74
-	$align = $lien = '';
75
-	$mode_logo = '';
76
-
77
-	if ($p->param and !$p->param[0][0]) {
78
-		$params = $p->param[0];
79
-		array_shift($params);
80
-		foreach ($params as $a) {
81
-			if ($a[0]->type === 'texte') {
82
-				$n = $a[0]->texte;
83
-				if (is_numeric($n)) {
84
-					$coord[] = $n;
85
-				} elseif (in_array($n, array('top', 'left', 'right', 'center', 'bottom'))) {
86
-					$align = $n;
87
-				} elseif (in_array($n, array('auto', 'icone', 'apercu', 'vignette'))) {
88
-					$mode_logo = $n;
89
-				}
90
-			} else {
91
-				$lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
-			}
93
-		}
94
-	}
95
-
96
-	$coord_x = !$coord ? 0 : intval(array_shift($coord));
97
-	$coord_y = !$coord ? 0 : intval(array_shift($coord));
98
-
99
-	if ($p->etoile === '*') {
100
-		include_spip('balise/url_');
101
-		$lien = generer_generer_url_arg($type, $p, $_id_objet);
102
-	}
103
-
104
-	$connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
-	if ($type == 'document') {
106
-		$qconnect = _q($connect);
107
-		$doc = "quete_document($_id_objet, $qconnect)";
108
-		if ($fichier) {
109
-			$code = "quete_logo_file($doc, $qconnect)";
110
-		} else {
111
-			$code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
-		}
113
-		// (x=non-faux ? y : '') pour affecter x en retournant y
114
-		if ($p->descr['documents']) {
115
-			$code = '(($doublons["documents"] .= ",". '
116
-				. $_id_objet
117
-				. ") ? $code : '')";
118
-		}
119
-	} elseif ($connect) {
120
-		$code = "''";
121
-		spip_log('Les logos distants ne sont pas prevus');
122
-	} else {
123
-		$code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
-	}
125
-
126
-	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
-	if ($coord_x or $coord_y) {
128
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
-	}
130
-
131
-	$p->code = $code;
132
-	$p->interdire_scripts = false;
133
-
134
-	return $p;
57
+    preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
+    $type = strtolower($regs[1]);
59
+    $suite_logo = $regs[2];
60
+
61
+    // cas de #LOGO_SITE_SPIP
62
+    if ($type == 'site_spip') {
63
+        $type = 'site';
64
+        $_id_objet = "\"'0'\"";
65
+    }
66
+
67
+    $id_objet = id_table_objet($type);
68
+    if (!isset($_id_objet)) {
69
+        $_id_objet = champ_sql($id_objet, $p);
70
+    }
71
+
72
+    $fichier = ($p->etoile === '**') ? -1 : 0;
73
+    $coord = array();
74
+    $align = $lien = '';
75
+    $mode_logo = '';
76
+
77
+    if ($p->param and !$p->param[0][0]) {
78
+        $params = $p->param[0];
79
+        array_shift($params);
80
+        foreach ($params as $a) {
81
+            if ($a[0]->type === 'texte') {
82
+                $n = $a[0]->texte;
83
+                if (is_numeric($n)) {
84
+                    $coord[] = $n;
85
+                } elseif (in_array($n, array('top', 'left', 'right', 'center', 'bottom'))) {
86
+                    $align = $n;
87
+                } elseif (in_array($n, array('auto', 'icone', 'apercu', 'vignette'))) {
88
+                    $mode_logo = $n;
89
+                }
90
+            } else {
91
+                $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
+            }
93
+        }
94
+    }
95
+
96
+    $coord_x = !$coord ? 0 : intval(array_shift($coord));
97
+    $coord_y = !$coord ? 0 : intval(array_shift($coord));
98
+
99
+    if ($p->etoile === '*') {
100
+        include_spip('balise/url_');
101
+        $lien = generer_generer_url_arg($type, $p, $_id_objet);
102
+    }
103
+
104
+    $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
+    if ($type == 'document') {
106
+        $qconnect = _q($connect);
107
+        $doc = "quete_document($_id_objet, $qconnect)";
108
+        if ($fichier) {
109
+            $code = "quete_logo_file($doc, $qconnect)";
110
+        } else {
111
+            $code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
+        }
113
+        // (x=non-faux ? y : '') pour affecter x en retournant y
114
+        if ($p->descr['documents']) {
115
+            $code = '(($doublons["documents"] .= ",". '
116
+                . $_id_objet
117
+                . ") ? $code : '')";
118
+        }
119
+    } elseif ($connect) {
120
+        $code = "''";
121
+        spip_log('Les logos distants ne sont pas prevus');
122
+    } else {
123
+        $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
+    }
125
+
126
+    // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
+    if ($coord_x or $coord_y) {
128
+        $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
+    }
130
+
131
+    $p->code = $code;
132
+    $p->interdire_scripts = false;
133
+
134
+    return $p;
135 135
 }
136 136
 
137 137
 /**
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
159 159
  **/
160 160
 function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) {
161
-	$code = "quete_logo('$id_objet', '" .
162
-		(($suite == '_SURVOL') ? 'off' :
163
-			(($suite == '_NORMAL') ? 'on' : 'ON')) .
164
-		"', $_id_objet," .
165
-		(($suite == '_RUBRIQUE') ?
166
-			champ_sql('id_rubrique', $p) :
167
-			(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
-		', ' . intval($fichier) . ')';
169
-
170
-	if ($fichier) {
171
-		return $code;
172
-	}
173
-
174
-	$align = preg_replace(",\W,", "", $align);
175
-
176
-	return "quete_html_logo($code, '$align', " .($_lien ? $_lien : "''") .")";
161
+    $code = "quete_logo('$id_objet', '" .
162
+        (($suite == '_SURVOL') ? 'off' :
163
+            (($suite == '_NORMAL') ? 'on' : 'ON')) .
164
+        "', $_id_objet," .
165
+        (($suite == '_RUBRIQUE') ?
166
+            champ_sql('id_rubrique', $p) :
167
+            (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
+        ', ' . intval($fichier) . ')';
169
+
170
+    if ($fichier) {
171
+        return $code;
172
+    }
173
+
174
+    $align = preg_replace(",\W,", "", $align);
175
+
176
+    return "quete_html_logo($code, '$align', " .($_lien ? $_lien : "''") .")";
177 177
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -10 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		if ($fichier) {
109 109
 			$code = "quete_logo_file($doc, $qconnect)";
110 110
 		} else {
111
-			$code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
111
+			$code = "quete_logo_document($doc, ".($lien ? $lien : "''").", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112 112
 		}
113 113
 		// (x=non-faux ? y : '') pour affecter x en retournant y
114 114
 		if ($p->descr['documents']) {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127 127
 	if ($coord_x or $coord_y) {
128
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
128
+		$code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))";
129 129
 	}
130 130
 
131 131
 	$p->code = $code;
@@ -158,14 +158,12 @@  discard block
 block discarded – undo
158 158
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
159 159
  **/
160 160
 function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) {
161
-	$code = "quete_logo('$id_objet', '" .
162
-		(($suite == '_SURVOL') ? 'off' :
163
-			(($suite == '_NORMAL') ? 'on' : 'ON')) .
164
-		"', $_id_objet," .
161
+	$code = "quete_logo('$id_objet', '".
162
+		(($suite == '_SURVOL') ? 'off' : (($suite == '_NORMAL') ? 'on' : 'ON')).
163
+		"', $_id_objet,".
165 164
 		(($suite == '_RUBRIQUE') ?
166
-			champ_sql('id_rubrique', $p) :
167
-			(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
-		', ' . intval($fichier) . ')';
165
+			champ_sql('id_rubrique', $p) : (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")).
166
+		', '.intval($fichier).')';
169 167
 
170 168
 	if ($fichier) {
171 169
 		return $code;
@@ -173,5 +171,5 @@  discard block
 block discarded – undo
173 171
 
174 172
 	$align = preg_replace(",\W,", "", $align);
175 173
 
176
-	return "quete_html_logo($code, '$align', " .($_lien ? $_lien : "''") .")";
174
+	return "quete_html_logo($code, '$align', ".($_lien ? $_lien : "''").")";
177 175
 }
Please login to merge, or discard this patch.
ecrire/auth/spip.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -32,78 +32,78 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) {
34 34
 
35
-	// retrouver le login
36
-	$login = auth_spip_retrouver_login($login);
37
-	// login inconnu, n'allons pas plus loin
38
-	if (!$login) {
39
-		return array();
40
-	}
41
-
42
-	$md5pass = "";
43
-	$shapass = $shanext = "";
44
-
45
-	if (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i", $pass, $regs)) {
46
-		$shapass = $regs[1];
47
-		$shanext = $regs[2];
48
-	} // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash
49
-	elseif (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i", $pass, $regs)) {
50
-		$shapass = $regs[1];
51
-		$shanext = $regs[2];
52
-		$md5pass = $regs[3];
53
-		//$md5next = $regs[4];
54
-	} // si envoi non crypte, crypter maintenant
55
-	elseif ($pass) {
56
-		$row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '',
57
-			'', '', $serveur);
58
-
59
-		if ($row) {
60
-			include_spip('auth/sha256.inc');
61
-			$shapass = spip_sha256($row['alea_actuel'] . $pass);
62
-			$shanext = spip_sha256($row['alea_futur'] . $pass);
63
-			$md5pass = md5($row['alea_actuel'] . $pass);
64
-		}
65
-	}
66
-
67
-	// login inexistant ou mot de passe vide
68
-	if (!$shapass and !$md5pass) {
69
-		return array();
70
-	}
71
-
72
-	$row = sql_fetsel("*", "spip_auteurs",
73
-		"login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur,
74
-			'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
75
-
76
-	// compat avec les anciennes bases en md5
77
-	if (!$row and $md5pass) {
78
-		$row = sql_fetsel("*", "spip_auteurs",
79
-			"login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur,
80
-				'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
81
-	}
82
-
83
-	// login/mot de passe incorrect
84
-	if (!$row) {
85
-		return array();
86
-	}
87
-
88
-	// fait tourner le codage du pass dans la base
89
-	// sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action()
90
-	if ($shanext and !$phpauth) {
91
-
92
-		include_spip('inc/acces'); // pour creer_uniqid
93
-		@sql_update('spip_auteurs', array(
94
-			'alea_actuel' => 'alea_futur',
95
-			'pass' => sql_quote($shanext, $serveur, 'text'),
96
-			'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text')
97
-		), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur,
98
-				'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur);
99
-		// En profiter pour verifier la securite de tmp/
100
-		// Si elle ne fonctionne pas a l'installation, prevenir
101
-		if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) {
102
-			return false;
103
-		}
104
-	}
105
-
106
-	return $row;
35
+    // retrouver le login
36
+    $login = auth_spip_retrouver_login($login);
37
+    // login inconnu, n'allons pas plus loin
38
+    if (!$login) {
39
+        return array();
40
+    }
41
+
42
+    $md5pass = "";
43
+    $shapass = $shanext = "";
44
+
45
+    if (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i", $pass, $regs)) {
46
+        $shapass = $regs[1];
47
+        $shanext = $regs[2];
48
+    } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash
49
+    elseif (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i", $pass, $regs)) {
50
+        $shapass = $regs[1];
51
+        $shanext = $regs[2];
52
+        $md5pass = $regs[3];
53
+        //$md5next = $regs[4];
54
+    } // si envoi non crypte, crypter maintenant
55
+    elseif ($pass) {
56
+        $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '',
57
+            '', '', $serveur);
58
+
59
+        if ($row) {
60
+            include_spip('auth/sha256.inc');
61
+            $shapass = spip_sha256($row['alea_actuel'] . $pass);
62
+            $shanext = spip_sha256($row['alea_futur'] . $pass);
63
+            $md5pass = md5($row['alea_actuel'] . $pass);
64
+        }
65
+    }
66
+
67
+    // login inexistant ou mot de passe vide
68
+    if (!$shapass and !$md5pass) {
69
+        return array();
70
+    }
71
+
72
+    $row = sql_fetsel("*", "spip_auteurs",
73
+        "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur,
74
+            'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
75
+
76
+    // compat avec les anciennes bases en md5
77
+    if (!$row and $md5pass) {
78
+        $row = sql_fetsel("*", "spip_auteurs",
79
+            "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur,
80
+                'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
81
+    }
82
+
83
+    // login/mot de passe incorrect
84
+    if (!$row) {
85
+        return array();
86
+    }
87
+
88
+    // fait tourner le codage du pass dans la base
89
+    // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action()
90
+    if ($shanext and !$phpauth) {
91
+
92
+        include_spip('inc/acces'); // pour creer_uniqid
93
+        @sql_update('spip_auteurs', array(
94
+            'alea_actuel' => 'alea_futur',
95
+            'pass' => sql_quote($shanext, $serveur, 'text'),
96
+            'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text')
97
+        ), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur,
98
+                'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur);
99
+        // En profiter pour verifier la securite de tmp/
100
+        // Si elle ne fonctionne pas a l'installation, prevenir
101
+        if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) {
102
+            return false;
103
+        }
104
+    }
105
+
106
+    return $row;
107 107
 }
108 108
 
109 109
 /**
@@ -113,41 +113,41 @@  discard block
 block discarded – undo
113 113
  * @return array
114 114
  */
115 115
 function auth_spip_formulaire_login($flux) {
116
-	// faut il encore envoyer md5 ?
117
-	// on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle
118
-	// les hash md5 ont une longueur 32, les sha 64
119
-	// en evitant une requete sql a chaque affichage du formulaire login sans session
120
-	// (perf issue pour les sites qui mettent le formulaire de login sur la home)
121
-	$compat_md5 = false;
122
-	if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) {
123
-		$compat_md5 = sql_countsel("spip_auteurs", "length(pass)=32 AND statut<>'poubelle'");
124
-		if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) {
125
-			effacer_meta('sha_256_only');
126
-		}
127
-		if (!$compat_md5) {
128
-			ecrire_meta('sha_256_only', 'oui');
129
-		}
130
-	}
131
-
132
-	// javascript qui gere la securite du login en evitant de faire circuler le pass en clair
133
-	$flux['data'] .=
134
-		($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '')
135
-		. '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>'
136
-		. '<script type="text/javascript">/*<![CDATA[*/'
137
-		. "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "',"
138
-		. "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "',"
139
-		. "'login':'" . $flux['args']['contexte']['var_login'] . "',"
140
-		. "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
141
-		. "'informe_auteur_en_cours':false,"
142
-		. "'attente_informe':0,"
143
-		. "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};"
144
-		. "jQuery(function(){
116
+    // faut il encore envoyer md5 ?
117
+    // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle
118
+    // les hash md5 ont une longueur 32, les sha 64
119
+    // en evitant une requete sql a chaque affichage du formulaire login sans session
120
+    // (perf issue pour les sites qui mettent le formulaire de login sur la home)
121
+    $compat_md5 = false;
122
+    if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) {
123
+        $compat_md5 = sql_countsel("spip_auteurs", "length(pass)=32 AND statut<>'poubelle'");
124
+        if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) {
125
+            effacer_meta('sha_256_only');
126
+        }
127
+        if (!$compat_md5) {
128
+            ecrire_meta('sha_256_only', 'oui');
129
+        }
130
+    }
131
+
132
+    // javascript qui gere la securite du login en evitant de faire circuler le pass en clair
133
+    $flux['data'] .=
134
+        ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '')
135
+        . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>'
136
+        . '<script type="text/javascript">/*<![CDATA[*/'
137
+        . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "',"
138
+        . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "',"
139
+        . "'login':'" . $flux['args']['contexte']['var_login'] . "',"
140
+        . "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
141
+        . "'informe_auteur_en_cours':false,"
142
+        . "'attente_informe':0,"
143
+        . "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};"
144
+        . "jQuery(function(){
145 145
 	jQuery('#var_login').change(actualise_auteur);
146 146
 	jQuery('form#formulaire_login').submit(login_submit);
147 147
 });"
148
-		. "/*]]>*/</script>";
148
+        . "/*]]>*/</script>";
149 149
 
150
-	return $flux;
150
+    return $flux;
151 151
 }
152 152
 
153 153
 
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
  *   toujours true pour un auteur cree dans SPIP
160 160
  */
161 161
 function auth_spip_autoriser_modifier_login($serveur = '') {
162
-	if (strlen($serveur)) {
163
-		return false;
164
-	} // les fonctions d'ecriture sur base distante sont encore incompletes
165
-	return true;
162
+    if (strlen($serveur)) {
163
+        return false;
164
+    } // les fonctions d'ecriture sur base distante sont encore incompletes
165
+    return true;
166 166
 }
167 167
 
168 168
 /**
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
  *  message d'erreur si login non valide, chaine vide sinon
177 177
  */
178 178
 function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') {
179
-	// login et mot de passe
180
-	if (strlen($new_login)) {
181
-		if (strlen($new_login) < _LOGIN_TROP_COURT) {
182
-			return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT));
183
-		} else {
184
-			$n = sql_countsel('spip_auteurs',
185
-				"login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '',
186
-				$serveur);
187
-			if ($n) {
188
-				return _T('info_login_existant');
189
-			}
190
-		}
191
-	}
192
-
193
-	return '';
179
+    // login et mot de passe
180
+    if (strlen($new_login)) {
181
+        if (strlen($new_login) < _LOGIN_TROP_COURT) {
182
+            return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT));
183
+        } else {
184
+            $n = sql_countsel('spip_auteurs',
185
+                "login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '',
186
+                $serveur);
187
+            if ($n) {
188
+                return _T('info_login_existant');
189
+            }
190
+        }
191
+    }
192
+
193
+    return '';
194 194
 }
195 195
 
196 196
 /**
@@ -202,32 +202,32 @@  discard block
 block discarded – undo
202 202
  * @return bool
203 203
  */
204 204
 function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') {
205
-	if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') {
206
-		return false;
207
-	}
208
-	if (!$id_auteur = intval($id_auteur)
209
-		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
210
-	) {
211
-		return false;
212
-	}
213
-	if ($new_login == $auteur['login']) {
214
-		return true;
215
-	} // on a rien fait mais c'est bon !
216
-
217
-	include_spip('action/editer_auteur');
218
-
219
-	// vider le login des auteurs a la poubelle qui avaient ce meme login
220
-	if (strlen($new_login)) {
221
-		$anciens = sql_allfetsel('id_auteur', 'spip_auteurs',
222
-			'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur);
223
-		while ($row = array_pop($anciens)) {
224
-			auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur
225
-		}
226
-	}
227
-
228
-	auteur_modifier($id_auteur, array('login' => $new_login), true); // manque la gestion de $serveur
229
-
230
-	return true;
205
+    if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') {
206
+        return false;
207
+    }
208
+    if (!$id_auteur = intval($id_auteur)
209
+        or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
210
+    ) {
211
+        return false;
212
+    }
213
+    if ($new_login == $auteur['login']) {
214
+        return true;
215
+    } // on a rien fait mais c'est bon !
216
+
217
+    include_spip('action/editer_auteur');
218
+
219
+    // vider le login des auteurs a la poubelle qui avaient ce meme login
220
+    if (strlen($new_login)) {
221
+        $anciens = sql_allfetsel('id_auteur', 'spip_auteurs',
222
+            'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur);
223
+        while ($row = array_pop($anciens)) {
224
+            auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur
225
+        }
226
+    }
227
+
228
+    auteur_modifier($id_auteur, array('login' => $new_login), true); // manque la gestion de $serveur
229
+
230
+    return true;
231 231
 }
232 232
 
233 233
 /**
@@ -239,27 +239,27 @@  discard block
 block discarded – undo
239 239
  * @return string
240 240
  */
241 241
 function auth_spip_retrouver_login($login, $serveur = '') {
242
-	if (!strlen($login)) {
243
-		return null;
244
-	} // pas la peine de requeter
245
-	$l = sql_quote($login, $serveur, 'text');
246
-	if ($r = sql_getfetsel('login', 'spip_auteurs',
247
-		"statut<>'5poubelle'" .
248
-		" AND (length(pass)>0)" .
249
-		" AND (login=$l)", '', '', '', '', $serveur)
250
-	) {
251
-		return $r;
252
-	}
253
-	// Si pas d'auteur avec ce login
254
-	// regarder s'il a saisi son nom ou son mail.
255
-	// Ne pas fusionner avec la requete precedente
256
-	// car un nom peut etre homonyme d'un autre login
257
-	else {
258
-		return sql_getfetsel('login', 'spip_auteurs',
259
-			"statut<>'5poubelle'" .
260
-			" AND (length(pass)>0)" .
261
-			" AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur);
262
-	}
242
+    if (!strlen($login)) {
243
+        return null;
244
+    } // pas la peine de requeter
245
+    $l = sql_quote($login, $serveur, 'text');
246
+    if ($r = sql_getfetsel('login', 'spip_auteurs',
247
+        "statut<>'5poubelle'" .
248
+        " AND (length(pass)>0)" .
249
+        " AND (login=$l)", '', '', '', '', $serveur)
250
+    ) {
251
+        return $r;
252
+    }
253
+    // Si pas d'auteur avec ce login
254
+    // regarder s'il a saisi son nom ou son mail.
255
+    // Ne pas fusionner avec la requete precedente
256
+    // car un nom peut etre homonyme d'un autre login
257
+    else {
258
+        return sql_getfetsel('login', 'spip_auteurs',
259
+            "statut<>'5poubelle'" .
260
+            " AND (length(pass)>0)" .
261
+            " AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur);
262
+    }
263 263
 }
264 264
 
265 265
 
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function auth_spip_informer_login($infos, $row, $serveur = '') {
279 279
 
280
-	// pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec
281
-	$infos['alea_actuel'] = $row['alea_actuel'];
282
-	$infos['alea_futur'] = $row['alea_futur'];
280
+    // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec
281
+    $infos['alea_actuel'] = $row['alea_actuel'];
282
+    $infos['alea_futur'] = $row['alea_futur'];
283 283
 
284
-	return $infos;
284
+    return $infos;
285 285
 }
286 286
 
287 287
 /**
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
  *  toujours true pour un auteur cree dans SPIP
293 293
  */
294 294
 function auth_spip_autoriser_modifier_pass($serveur = '') {
295
-	if (strlen($serveur)) {
296
-		return false;
297
-	} // les fonctions d'ecriture sur base distante sont encore incompletes
298
-	return true;
295
+    if (strlen($serveur)) {
296
+        return false;
297
+    } // les fonctions d'ecriture sur base distante sont encore incompletes
298
+    return true;
299 299
 }
300 300
 
301 301
 
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
  *  message d'erreur si login non valide, chaine vide sinon
317 317
  */
318 318
 function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') {
319
-	// login et mot de passe
320
-	if (strlen($new_pass) < _PASS_LONGUEUR_MINI) {
321
-		return _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI));
322
-	}
319
+    // login et mot de passe
320
+    if (strlen($new_pass) < _PASS_LONGUEUR_MINI) {
321
+        return _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI));
322
+    }
323 323
 
324
-	return '';
324
+    return '';
325 325
 }
326 326
 
327 327
 /**
@@ -335,33 +335,33 @@  discard block
 block discarded – undo
335 335
  * @return bool
336 336
  */
337 337
 function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') {
338
-	if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
339
-		return false;
340
-	}
341
-
342
-	if (!$id_auteur = intval($id_auteur)
343
-		or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
344
-	) {
345
-		return false;
346
-	}
347
-
348
-	$c = array();
349
-	include_spip('inc/acces');
350
-	include_spip('auth/sha256.inc');
351
-	$htpass = generer_htpass($new_pass);
352
-	$alea_actuel = creer_uniqid();
353
-	$alea_futur = creer_uniqid();
354
-	$pass = spip_sha256($alea_actuel . $new_pass);
355
-	$c['pass'] = $pass;
356
-	$c['htpass'] = $htpass;
357
-	$c['alea_actuel'] = $alea_actuel;
358
-	$c['alea_futur'] = $alea_futur;
359
-	$c['low_sec'] = '';
360
-
361
-	include_spip('action/editer_auteur');
362
-	auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur
363
-
364
-	return true; // on a bien modifie le pass
338
+    if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
339
+        return false;
340
+    }
341
+
342
+    if (!$id_auteur = intval($id_auteur)
343
+        or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
344
+    ) {
345
+        return false;
346
+    }
347
+
348
+    $c = array();
349
+    include_spip('inc/acces');
350
+    include_spip('auth/sha256.inc');
351
+    $htpass = generer_htpass($new_pass);
352
+    $alea_actuel = creer_uniqid();
353
+    $alea_futur = creer_uniqid();
354
+    $pass = spip_sha256($alea_actuel . $new_pass);
355
+    $c['pass'] = $pass;
356
+    $c['htpass'] = $htpass;
357
+    $c['alea_actuel'] = $alea_actuel;
358
+    $c['alea_futur'] = $alea_futur;
359
+    $c['low_sec'] = '';
360
+
361
+    include_spip('action/editer_auteur');
362
+    auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur
363
+
364
+    return true; // on a bien modifie le pass
365 365
 }
366 366
 
367 367
 /**
@@ -375,54 +375,54 @@  discard block
 block discarded – undo
375 375
  * @return void
376 376
  */
377 377
 function auth_spip_synchroniser_distant($id_auteur, $champs, $options = array(), $serveur = '') {
378
-	// ne rien faire pour une base distante : on ne sait pas regenerer les htaccess
379
-	if (strlen($serveur)) {
380
-		return;
381
-	}
382
-	// si un login, pass ou statut a ete modifie
383
-	// regenerer les fichier htpass
384
-	if (isset($champs['login'])
385
-		or isset($champs['pass'])
386
-		or isset($champs['statut'])
387
-		or (isset($options['all']) and $options['all'])
388
-	) {
389
-
390
-		$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
391
-		$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
392
-
393
-		// Cette variable de configuration peut etre posee par un plugin
394
-		// par exemple acces_restreint ;
395
-		// si .htaccess existe, outrepasser spip_meta
396
-		if ((!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
397
-			and !@file_exists($htaccess)
398
-		) {
399
-			spip_unlink($htpasswd);
400
-			spip_unlink($htpasswd . "-admin");
401
-
402
-			return;
403
-		}
404
-
405
-		# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
406
-		# de devenir redacteur le cas echeant (auth http)... a nettoyer
407
-		// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
408
-
409
-		$p1 = ''; // login:htpass pour tous
410
-		$p2 = ''; // login:htpass pour les admins
411
-		$s = sql_select("login, htpass, statut", "spip_auteurs",
412
-			sql_in("statut", array('1comite', '0minirezo', 'nouveau')));
413
-		while ($t = sql_fetch($s)) {
414
-			if (strlen($t['login']) and strlen($t['htpass'])) {
415
-				$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
416
-				if ($t['statut'] == '0minirezo') {
417
-					$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
418
-				}
419
-			}
420
-		}
421
-		sql_free($s);
422
-		if ($p1) {
423
-			ecrire_fichier($htpasswd, $p1);
424
-			ecrire_fichier($htpasswd . '-admin', $p2);
425
-			spip_log("Ecriture de $htpasswd et $htpasswd-admin");
426
-		}
427
-	}
378
+    // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess
379
+    if (strlen($serveur)) {
380
+        return;
381
+    }
382
+    // si un login, pass ou statut a ete modifie
383
+    // regenerer les fichier htpass
384
+    if (isset($champs['login'])
385
+        or isset($champs['pass'])
386
+        or isset($champs['statut'])
387
+        or (isset($options['all']) and $options['all'])
388
+    ) {
389
+
390
+        $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
391
+        $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
392
+
393
+        // Cette variable de configuration peut etre posee par un plugin
394
+        // par exemple acces_restreint ;
395
+        // si .htaccess existe, outrepasser spip_meta
396
+        if ((!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
397
+            and !@file_exists($htaccess)
398
+        ) {
399
+            spip_unlink($htpasswd);
400
+            spip_unlink($htpasswd . "-admin");
401
+
402
+            return;
403
+        }
404
+
405
+        # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
406
+        # de devenir redacteur le cas echeant (auth http)... a nettoyer
407
+        // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
408
+
409
+        $p1 = ''; // login:htpass pour tous
410
+        $p2 = ''; // login:htpass pour les admins
411
+        $s = sql_select("login, htpass, statut", "spip_auteurs",
412
+            sql_in("statut", array('1comite', '0minirezo', 'nouveau')));
413
+        while ($t = sql_fetch($s)) {
414
+            if (strlen($t['login']) and strlen($t['htpass'])) {
415
+                $p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
416
+                if ($t['statut'] == '0minirezo') {
417
+                    $p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
418
+                }
419
+            }
420
+        }
421
+        sql_free($s);
422
+        if ($p1) {
423
+            ecrire_fichier($htpasswd, $p1);
424
+            ecrire_fichier($htpasswd . '-admin', $p2);
425
+            spip_log("Ecriture de $htpasswd et $htpasswd-admin");
426
+        }
427
+    }
428 428
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 		//$md5next = $regs[4];
54 54
 	} // si envoi non crypte, crypter maintenant
55 55
 	elseif ($pass) {
56
-		$row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '',
56
+		$row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=".sql_quote($login, $serveur, 'text'), '', '',
57 57
 			'', '', $serveur);
58 58
 
59 59
 		if ($row) {
60 60
 			include_spip('auth/sha256.inc');
61
-			$shapass = spip_sha256($row['alea_actuel'] . $pass);
62
-			$shanext = spip_sha256($row['alea_futur'] . $pass);
63
-			$md5pass = md5($row['alea_actuel'] . $pass);
61
+			$shapass = spip_sha256($row['alea_actuel'].$pass);
62
+			$shanext = spip_sha256($row['alea_futur'].$pass);
63
+			$md5pass = md5($row['alea_actuel'].$pass);
64 64
 		}
65 65
 	}
66 66
 
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 	}
71 71
 
72 72
 	$row = sql_fetsel("*", "spip_auteurs",
73
-		"login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur,
74
-			'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
73
+		"login=".sql_quote($login, $serveur, 'text')." AND pass=".sql_quote($shapass, $serveur,
74
+			'text')." AND statut<>'5poubelle'", '', '', '', '', $serveur);
75 75
 
76 76
 	// compat avec les anciennes bases en md5
77 77
 	if (!$row and $md5pass) {
78 78
 		$row = sql_fetsel("*", "spip_auteurs",
79
-			"login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur,
80
-				'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur);
79
+			"login=".sql_quote($login, $serveur, 'text')." AND pass=".sql_quote($md5pass, $serveur,
80
+				'text')." AND statut<>'5poubelle'", '', '', '', '', $serveur);
81 81
 	}
82 82
 
83 83
 	// login/mot de passe incorrect
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 			'alea_actuel' => 'alea_futur',
95 95
 			'pass' => sql_quote($shanext, $serveur, 'text'),
96 96
 			'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text')
97
-		), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur,
98
-				'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur);
97
+		), "id_auteur=".$row['id_auteur'].' AND pass IN ('.sql_quote($shapass, $serveur,
98
+				'text').', '.sql_quote($md5pass, $serveur, 'text').')', '', $serveur);
99 99
 		// En profiter pour verifier la securite de tmp/
100 100
 		// Si elle ne fonctionne pas a l'installation, prevenir
101 101
 		if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) {
@@ -131,16 +131,16 @@  discard block
 block discarded – undo
131 131
 
132 132
 	// javascript qui gere la securite du login en evitant de faire circuler le pass en clair
133 133
 	$flux['data'] .=
134
-		($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '')
135
-		. '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>'
134
+		($compat_md5 ? '<script type="text/javascript" src="'._DIR_JAVASCRIPT.'md5.js"></script>' : '')
135
+		. '<script type="text/javascript" src="'._DIR_JAVASCRIPT.'login-sha-min.js"></script>'
136 136
 		. '<script type="text/javascript">/*<![CDATA[*/'
137
-		. "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "',"
138
-		. "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "',"
139
-		. "'login':'" . $flux['args']['contexte']['var_login'] . "',"
140
-		. "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
137
+		. "var login_info={'alea_actuel':'".$flux['args']['contexte']['_alea_actuel']."',"
138
+		. "'alea_futur':'".$flux['args']['contexte']['_alea_futur']."',"
139
+		. "'login':'".$flux['args']['contexte']['var_login']."',"
140
+		. "'page_auteur': '".generer_url_public('informer_auteur')."',"
141 141
 		. "'informe_auteur_en_cours':false,"
142 142
 		. "'attente_informe':0,"
143
-		. "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};"
143
+		. "'compat_md5':".($compat_md5 ? "true" : "false")."};"
144 144
 		. "jQuery(function(){
145 145
 	jQuery('#var_login').change(actualise_auteur);
146 146
 	jQuery('form#formulaire_login').submit(login_submit);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT));
183 183
 		} else {
184 184
 			$n = sql_countsel('spip_auteurs',
185
-				"login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '',
185
+				"login=".sql_quote($new_login)." AND id_auteur!=".intval($id_auteur)." AND statut!='5poubelle'", '', '',
186 186
 				$serveur);
187 187
 			if ($n) {
188 188
 				return _T('info_login_existant');
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		return false;
207 207
 	}
208 208
 	if (!$id_auteur = intval($id_auteur)
209
-		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
209
+		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur)
210 210
 	) {
211 211
 		return false;
212 212
 	}
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	// vider le login des auteurs a la poubelle qui avaient ce meme login
220 220
 	if (strlen($new_login)) {
221 221
 		$anciens = sql_allfetsel('id_auteur', 'spip_auteurs',
222
-			'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur);
222
+			'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", '', '', '', '', $serveur);
223 223
 		while ($row = array_pop($anciens)) {
224 224
 			auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur
225 225
 		}
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	} // pas la peine de requeter
245 245
 	$l = sql_quote($login, $serveur, 'text');
246 246
 	if ($r = sql_getfetsel('login', 'spip_auteurs',
247
-		"statut<>'5poubelle'" .
248
-		" AND (length(pass)>0)" .
247
+		"statut<>'5poubelle'".
248
+		" AND (length(pass)>0)".
249 249
 		" AND (login=$l)", '', '', '', '', $serveur)
250 250
 	) {
251 251
 		return $r;
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 	// car un nom peut etre homonyme d'un autre login
257 257
 	else {
258 258
 		return sql_getfetsel('login', 'spip_auteurs',
259
-			"statut<>'5poubelle'" .
260
-			" AND (length(pass)>0)" .
259
+			"statut<>'5poubelle'".
260
+			" AND (length(pass)>0)".
261 261
 			" AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur);
262 262
 	}
263 263
 }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	}
341 341
 
342 342
 	if (!$id_auteur = intval($id_auteur)
343
-		or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
343
+		or !sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur)
344 344
 	) {
345 345
 		return false;
346 346
 	}
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	$htpass = generer_htpass($new_pass);
352 352
 	$alea_actuel = creer_uniqid();
353 353
 	$alea_futur = creer_uniqid();
354
-	$pass = spip_sha256($alea_actuel . $new_pass);
354
+	$pass = spip_sha256($alea_actuel.$new_pass);
355 355
 	$c['pass'] = $pass;
356 356
 	$c['htpass'] = $htpass;
357 357
 	$c['alea_actuel'] = $alea_actuel;
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 		or (isset($options['all']) and $options['all'])
388 388
 	) {
389 389
 
390
-		$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
391
-		$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
390
+		$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
391
+		$htpasswd = _DIR_TMP._AUTH_USER_FILE;
392 392
 
393 393
 		// Cette variable de configuration peut etre posee par un plugin
394 394
 		// par exemple acces_restreint ;
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 			and !@file_exists($htaccess)
398 398
 		) {
399 399
 			spip_unlink($htpasswd);
400
-			spip_unlink($htpasswd . "-admin");
400
+			spip_unlink($htpasswd."-admin");
401 401
 
402 402
 			return;
403 403
 		}
@@ -412,16 +412,16 @@  discard block
 block discarded – undo
412 412
 			sql_in("statut", array('1comite', '0minirezo', 'nouveau')));
413 413
 		while ($t = sql_fetch($s)) {
414 414
 			if (strlen($t['login']) and strlen($t['htpass'])) {
415
-				$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
415
+				$p1 .= $t['login'].':'.$t['htpass']."\n";
416 416
 				if ($t['statut'] == '0minirezo') {
417
-					$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
417
+					$p2 .= $t['login'].':'.$t['htpass']."\n";
418 418
 				}
419 419
 			}
420 420
 		}
421 421
 		sql_free($s);
422 422
 		if ($p1) {
423 423
 			ecrire_fichier($htpasswd, $p1);
424
-			ecrire_fichier($htpasswd . '-admin', $p2);
424
+			ecrire_fichier($htpasswd.'-admin', $p2);
425 425
 			spip_log("Ecriture de $htpasswd et $htpasswd-admin");
426 426
 		}
427 427
 	}
Please login to merge, or discard this patch.
ecrire/install/etape_3b.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -11,143 +11,143 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/headers');
18 18
 
19 19
 function install_etape_3b_dist() {
20
-	$login = _request('login');
21
-	$email = _request('email');
22
-	$nom = _request('nom');
23
-	$pass = _request('pass');
24
-	$pass_verif = _request('pass_verif');
25
-
26
-	$server_db = defined('_INSTALL_SERVER_DB')
27
-		? _INSTALL_SERVER_DB
28
-		: _request('server_db');
29
-
30
-	if (!defined('_PASS_LONGUEUR_MINI')) {
31
-		define('_PASS_LONGUEUR_MINI', 6);
32
-	}
33
-	if (!defined('_LOGIN_TROP_COURT')) {
34
-		define('_LOGIN_TROP_COURT', 4);
35
-	}
36
-	if ($login) {
37
-		$echec = ($pass != $pass_verif) ?
38
-			_T('info_passes_identiques')
39
-			: ((strlen($pass) < _PASS_LONGUEUR_MINI) ?
40
-				_T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI))
41
-				: ((strlen($login) < _LOGIN_TROP_COURT) ?
42
-					_T('info_login_trop_court')
43
-					: ''));
44
-		include_spip('inc/filtres');
45
-		if (!$echec and $email and !email_valide($email)) {
46
-			$echec = _T('form_email_non_valide');
47
-		}
48
-		if ($echec) {
49
-			echo minipres(
50
-				'AUTO',
51
-				info_progression_etape(3, 'etape_', 'install/', true) .
52
-				"<div class='error'><h3>$echec</h3>\n" .
53
-				'<p>' . _T('avis_connexion_echec_2') . '</p>' .
54
-				'</div>'
55
-			);
56
-			exit;
57
-		}
58
-	}
59
-
60
-	if (@file_exists(_FILE_CHMOD_TMP)) {
61
-		include(_FILE_CHMOD_TMP);
62
-	} else {
63
-		redirige_url_ecrire('install');
64
-	}
65
-
66
-	if (!@file_exists(_FILE_CONNECT_TMP)) {
67
-		redirige_url_ecrire('install');
68
-	}
69
-
70
-	# maintenant on connait le vrai charset du site s'il est deja configure
71
-	# sinon par defaut lire_meta reglera _DEFAULT_CHARSET
72
-	# (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET)
73
-
74
-	lire_metas();
75
-	if ($login) {
76
-		include_spip('inc/charsets');
77
-
78
-		$nom = (importer_charset($nom, _DEFAULT_CHARSET));
79
-		$login = (importer_charset($login, _DEFAULT_CHARSET));
80
-		$email = (importer_charset($email, _DEFAULT_CHARSET));
81
-		# pour le passwd, bizarrement il faut le convertir comme s'il avait
82
-		# ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js
83
-		$pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1');
84
-		include_spip('auth/sha256.inc');
85
-		include_spip('inc/acces');
86
-		$htpass = generer_htpass($pass);
87
-		$alea_actuel = creer_uniqid();
88
-		$alea_futur = creer_uniqid();
89
-		$shapass = spip_sha256($alea_actuel . $pass);
90
-		// prelablement, creer le champ webmestre si il n'existe pas (install neuve
91
-		// sur une vieille base
92
-		$t = sql_showtable('spip_auteurs', true);
93
-		if (!isset($t['field']['webmestre'])) {
94
-			@sql_alter("TABLE spip_auteurs ADD webmestre varchar(3)  DEFAULT 'non' NOT NULL");
95
-		}
96
-
97
-		$id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login));
98
-		if ($id_auteur !== null) {
99
-			sql_updateq('spip_auteurs', array(
100
-				'nom' => $nom,
101
-				'email' => $email,
102
-				'login' => $login,
103
-				'pass' => $shapass,
104
-				'alea_actuel' => $alea_actuel,
105
-				'alea_futur' => $alea_futur,
106
-				'htpass' => $htpass,
107
-				'statut' => '0minirezo'
108
-			), "id_auteur=$id_auteur");
109
-		} else {
110
-			$id_auteur = sql_insertq('spip_auteurs', array(
111
-				'nom' => $nom,
112
-				'email' => $email,
113
-				'login' => $login,
114
-				'pass' => $shapass,
115
-				'htpass' => $htpass,
116
-				'alea_actuel' => $alea_actuel,
117
-				'alea_futur' => $alea_futur,
118
-				'statut' => '0minirezo'
119
-			));
120
-		}
121
-		// le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne
122
-		@sql_updateq('spip_auteurs', array('webmestre' => 'oui'), "id_auteur=$id_auteur");
123
-
124
-		// inserer email comme email webmaster principal
125
-		// (sauf s'il est vide: cas de la re-installation)
126
-		if ($email) {
127
-			ecrire_meta('email_webmaster', $email);
128
-		}
129
-
130
-		// Connecter directement celui qui vient de (re)donner son login
131
-		// mais sans cookie d'admin ni connexion longue
132
-		include_spip('inc/auth');
133
-		if (!$auteur = auth_identifier_login($login, $pass)
134
-			or !auth_loger($auteur, true)
135
-		) {
136
-			spip_log("login automatique impossible $auth_spip $session" . count($row));
137
-		}
138
-	}
139
-
140
-	// installer les metas
141
-	$config = charger_fonction('config', 'inc');
142
-	$config();
143
-
144
-	// activer les plugins
145
-	// leur installation ne peut pas se faire sur le meme hit, il faudra donc
146
-	// poursuivre au hit suivant
147
-	include_spip('inc/plugin');
148
-	actualise_plugins_actifs();
149
-
150
-
151
-	include_spip('inc/distant');
152
-	redirige_par_entete(parametre_url(self(), 'etape', '4', '&'));
20
+    $login = _request('login');
21
+    $email = _request('email');
22
+    $nom = _request('nom');
23
+    $pass = _request('pass');
24
+    $pass_verif = _request('pass_verif');
25
+
26
+    $server_db = defined('_INSTALL_SERVER_DB')
27
+        ? _INSTALL_SERVER_DB
28
+        : _request('server_db');
29
+
30
+    if (!defined('_PASS_LONGUEUR_MINI')) {
31
+        define('_PASS_LONGUEUR_MINI', 6);
32
+    }
33
+    if (!defined('_LOGIN_TROP_COURT')) {
34
+        define('_LOGIN_TROP_COURT', 4);
35
+    }
36
+    if ($login) {
37
+        $echec = ($pass != $pass_verif) ?
38
+            _T('info_passes_identiques')
39
+            : ((strlen($pass) < _PASS_LONGUEUR_MINI) ?
40
+                _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI))
41
+                : ((strlen($login) < _LOGIN_TROP_COURT) ?
42
+                    _T('info_login_trop_court')
43
+                    : ''));
44
+        include_spip('inc/filtres');
45
+        if (!$echec and $email and !email_valide($email)) {
46
+            $echec = _T('form_email_non_valide');
47
+        }
48
+        if ($echec) {
49
+            echo minipres(
50
+                'AUTO',
51
+                info_progression_etape(3, 'etape_', 'install/', true) .
52
+                "<div class='error'><h3>$echec</h3>\n" .
53
+                '<p>' . _T('avis_connexion_echec_2') . '</p>' .
54
+                '</div>'
55
+            );
56
+            exit;
57
+        }
58
+    }
59
+
60
+    if (@file_exists(_FILE_CHMOD_TMP)) {
61
+        include(_FILE_CHMOD_TMP);
62
+    } else {
63
+        redirige_url_ecrire('install');
64
+    }
65
+
66
+    if (!@file_exists(_FILE_CONNECT_TMP)) {
67
+        redirige_url_ecrire('install');
68
+    }
69
+
70
+    # maintenant on connait le vrai charset du site s'il est deja configure
71
+    # sinon par defaut lire_meta reglera _DEFAULT_CHARSET
72
+    # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET)
73
+
74
+    lire_metas();
75
+    if ($login) {
76
+        include_spip('inc/charsets');
77
+
78
+        $nom = (importer_charset($nom, _DEFAULT_CHARSET));
79
+        $login = (importer_charset($login, _DEFAULT_CHARSET));
80
+        $email = (importer_charset($email, _DEFAULT_CHARSET));
81
+        # pour le passwd, bizarrement il faut le convertir comme s'il avait
82
+        # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js
83
+        $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1');
84
+        include_spip('auth/sha256.inc');
85
+        include_spip('inc/acces');
86
+        $htpass = generer_htpass($pass);
87
+        $alea_actuel = creer_uniqid();
88
+        $alea_futur = creer_uniqid();
89
+        $shapass = spip_sha256($alea_actuel . $pass);
90
+        // prelablement, creer le champ webmestre si il n'existe pas (install neuve
91
+        // sur une vieille base
92
+        $t = sql_showtable('spip_auteurs', true);
93
+        if (!isset($t['field']['webmestre'])) {
94
+            @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3)  DEFAULT 'non' NOT NULL");
95
+        }
96
+
97
+        $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login));
98
+        if ($id_auteur !== null) {
99
+            sql_updateq('spip_auteurs', array(
100
+                'nom' => $nom,
101
+                'email' => $email,
102
+                'login' => $login,
103
+                'pass' => $shapass,
104
+                'alea_actuel' => $alea_actuel,
105
+                'alea_futur' => $alea_futur,
106
+                'htpass' => $htpass,
107
+                'statut' => '0minirezo'
108
+            ), "id_auteur=$id_auteur");
109
+        } else {
110
+            $id_auteur = sql_insertq('spip_auteurs', array(
111
+                'nom' => $nom,
112
+                'email' => $email,
113
+                'login' => $login,
114
+                'pass' => $shapass,
115
+                'htpass' => $htpass,
116
+                'alea_actuel' => $alea_actuel,
117
+                'alea_futur' => $alea_futur,
118
+                'statut' => '0minirezo'
119
+            ));
120
+        }
121
+        // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne
122
+        @sql_updateq('spip_auteurs', array('webmestre' => 'oui'), "id_auteur=$id_auteur");
123
+
124
+        // inserer email comme email webmaster principal
125
+        // (sauf s'il est vide: cas de la re-installation)
126
+        if ($email) {
127
+            ecrire_meta('email_webmaster', $email);
128
+        }
129
+
130
+        // Connecter directement celui qui vient de (re)donner son login
131
+        // mais sans cookie d'admin ni connexion longue
132
+        include_spip('inc/auth');
133
+        if (!$auteur = auth_identifier_login($login, $pass)
134
+            or !auth_loger($auteur, true)
135
+        ) {
136
+            spip_log("login automatique impossible $auth_spip $session" . count($row));
137
+        }
138
+    }
139
+
140
+    // installer les metas
141
+    $config = charger_fonction('config', 'inc');
142
+    $config();
143
+
144
+    // activer les plugins
145
+    // leur installation ne peut pas se faire sur le meme hit, il faudra donc
146
+    // poursuivre au hit suivant
147
+    include_spip('inc/plugin');
148
+    actualise_plugins_actifs();
149
+
150
+
151
+    include_spip('inc/distant');
152
+    redirige_par_entete(parametre_url(self(), 'etape', '4', '&'));
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 		if ($echec) {
49 49
 			echo minipres(
50 50
 				'AUTO',
51
-				info_progression_etape(3, 'etape_', 'install/', true) .
52
-				"<div class='error'><h3>$echec</h3>\n" .
53
-				'<p>' . _T('avis_connexion_echec_2') . '</p>' .
51
+				info_progression_etape(3, 'etape_', 'install/', true).
52
+				"<div class='error'><h3>$echec</h3>\n".
53
+				'<p>'._T('avis_connexion_echec_2').'</p>'.
54 54
 				'</div>'
55 55
 			);
56 56
 			exit;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		$htpass = generer_htpass($pass);
87 87
 		$alea_actuel = creer_uniqid();
88 88
 		$alea_futur = creer_uniqid();
89
-		$shapass = spip_sha256($alea_actuel . $pass);
89
+		$shapass = spip_sha256($alea_actuel.$pass);
90 90
 		// prelablement, creer le champ webmestre si il n'existe pas (install neuve
91 91
 		// sur une vieille base
92 92
 		$t = sql_showtable('spip_auteurs', true);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			@sql_alter("TABLE spip_auteurs ADD webmestre varchar(3)  DEFAULT 'non' NOT NULL");
95 95
 		}
96 96
 
97
-		$id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login));
97
+		$id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login='.sql_quote($login));
98 98
 		if ($id_auteur !== null) {
99 99
 			sql_updateq('spip_auteurs', array(
100 100
 				'nom' => $nom,
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		if (!$auteur = auth_identifier_login($login, $pass)
134 134
 			or !auth_loger($auteur, true)
135 135
 		) {
136
-			spip_log("login automatique impossible $auth_spip $session" . count($row));
136
+			spip_log("login automatique impossible $auth_spip $session".count($row));
137 137
 		}
138 138
 	}
139 139
 
Please login to merge, or discard this patch.
ecrire/index.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 // Determiner l'action demandee
36 36
 //
37 37
 
38
-$exec = (string)_request('exec');
38
+$exec = (string) _request('exec');
39 39
 $reinstall = (!is_null(_request('reinstall'))) ? _request('reinstall') : ($exec == 'install' ? 'oui' : null);
40 40
 //
41 41
 // Les scripts d'insallation n'authentifient pas, forcement,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
 
66 66
 if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
67
-	if (!autoriser_sans_cookie($exec)){
67
+	if (!autoriser_sans_cookie($exec)) {
68 68
 		// Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69 69
 		include_spip('public/aiguiller');
70 70
 		if (
@@ -76,17 +76,17 @@  discard block
 block discarded – undo
76 76
 			or
77 77
 			// cas des formulaires charger/verifier/traiter
78 78
 			traiter_formulaires_dynamiques()
79
-		){
79
+		) {
80 80
 			exit;
81 81
 		} // le hit est fini !
82 82
 	}
83 83
 }
84 84
 // securiser les redirect du back-office
85 85
 if (_request('redirect')) {
86
-	if (!function_exists('securiser_redirect_action')){
86
+	if (!function_exists('securiser_redirect_action')) {
87 87
 		include_spip('public/aiguiller');
88 88
 	}
89
-	set_request('redirect',securiser_redirect_action(_request('redirect')));
89
+	set_request('redirect', securiser_redirect_action(_request('redirect')));
90 90
 }
91 91
 
92 92
 
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 			or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
120 120
 		)
121 121
 	) {
122
-		spip_log("Quand la meta admin vaut " .
123
-			$GLOBALS['meta']["admin"] .
124
-			" seul un admin peut se connecter et sans AJAX." .
122
+		spip_log("Quand la meta admin vaut ".
123
+			$GLOBALS['meta']["admin"].
124
+			" seul un admin peut se connecter et sans AJAX.".
125 125
 			" En cas de probleme, detruire cette meta.");
126 126
 		die(_T('info_travaux_texte'));
127 127
 	}
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 /** Drapeau indiquant que l'on est dans l'espace privé */
20 20
 define('_ESPACE_PRIVE', true);
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	include 'inc_version.php';
22
+    include 'inc_version.php';
23 23
 }
24 24
 
25 25
 // Verification anti magic_quotes_sybase, pour qui addslashes("'") = "''"
26 26
 // On prefere la faire ici plutot que dans inc_version, c'est moins souvent et
27 27
 // si le reglage est modifie sur un site en prod, ca fait moins mal
28 28
 if (addslashes("'") !== "\\'") {
29
-	die('SPIP incompatible magic_quotes_sybase');
29
+    die('SPIP incompatible magic_quotes_sybase');
30 30
 }
31 31
 
32 32
 include_spip('inc/cookie');
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
 // alors il faut blinder les variables d'URL
43 43
 //
44 44
 if (autoriser_sans_cookie($exec, false)) {
45
-	if (!isset($reinstall)) {
46
-		$reinstall = 'non';
47
-	}
48
-	$var_auth = true;
45
+    if (!isset($reinstall)) {
46
+        $reinstall = 'non';
47
+    }
48
+    $var_auth = true;
49 49
 } else {
50
-	// Authentification, redefinissable
51
-	$auth = charger_fonction('auth', 'inc');
52
-	$var_auth = $auth();
53
-	if ($var_auth) {
54
-		echo auth_echec($var_auth);
55
-		exit;
56
-	}
50
+    // Authentification, redefinissable
51
+    $auth = charger_fonction('auth', 'inc');
52
+    $var_auth = $auth();
53
+    if ($var_auth) {
54
+        echo auth_echec($var_auth);
55
+        exit;
56
+    }
57 57
 }
58 58
 
59 59
 // initialiser a la langue par defaut
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
 
65 65
 
66 66
 if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
67
-	if (!autoriser_sans_cookie($exec)){
68
-		// Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
-		include_spip('public/aiguiller');
70
-		if (
71
-			// cas des appels actions ?action=xxx
72
-			traiter_appels_actions()
73
-			or
74
-			// cas des hits ajax sur les inclusions ajax
75
-			traiter_appels_inclusions_ajax()
76
-			or
77
-			// cas des formulaires charger/verifier/traiter
78
-			traiter_formulaires_dynamiques()
79
-		){
80
-			exit;
81
-		} // le hit est fini !
82
-	}
67
+    if (!autoriser_sans_cookie($exec)){
68
+        // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires
69
+        include_spip('public/aiguiller');
70
+        if (
71
+            // cas des appels actions ?action=xxx
72
+            traiter_appels_actions()
73
+            or
74
+            // cas des hits ajax sur les inclusions ajax
75
+            traiter_appels_inclusions_ajax()
76
+            or
77
+            // cas des formulaires charger/verifier/traiter
78
+            traiter_formulaires_dynamiques()
79
+        ){
80
+            exit;
81
+        } // le hit est fini !
82
+    }
83 83
 }
84 84
 // securiser les redirect du back-office
85 85
 if (_request('redirect')) {
86
-	if (!function_exists('securiser_redirect_action')){
87
-		include_spip('public/aiguiller');
88
-	}
89
-	set_request('redirect',securiser_redirect_action(_request('redirect')));
86
+    if (!function_exists('securiser_redirect_action')){
87
+        include_spip('public/aiguiller');
88
+    }
89
+    set_request('redirect',securiser_redirect_action(_request('redirect')));
90 90
 }
91 91
 
92 92
 
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 
97 97
 // Controle de la version, sauf si on est deja en train de s'en occuper
98 98
 if (!$reinstall == 'oui'
99
-	and !_AJAX
100
-	and isset($GLOBALS['meta']['version_installee'])
101
-	and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
99
+    and !_AJAX
100
+    and isset($GLOBALS['meta']['version_installee'])
101
+    and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee'])))
102 102
 ) {
103
-	$exec = 'demande_mise_a_jour';
103
+    $exec = 'demande_mise_a_jour';
104 104
 }
105 105
 
106 106
 // Quand une action d'administration est en cours (meta "admin"),
@@ -110,44 +110,44 @@  discard block
 block discarded – undo
110 110
 // sinon c'est qu'elle a ete interrompue et il faut la reprendre
111 111
 
112 112
 elseif (isset($GLOBALS['meta']["admin"])) {
113
-	if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)) {
114
-		list(, $var_f, $n) = $l;
115
-	}
116
-	if (_AJAX
117
-		or !(
118
-			isset($_COOKIE['spip_admin'])
119
-			or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
120
-		)
121
-	) {
122
-		spip_log("Quand la meta admin vaut " .
123
-			$GLOBALS['meta']["admin"] .
124
-			" seul un admin peut se connecter et sans AJAX." .
125
-			" En cas de probleme, detruire cette meta.");
126
-		die(_T('info_travaux_texte'));
127
-	}
128
-	if ($n) {
129
-		list(, $var_f, $n) = $l;
130
-		if (tester_url_ecrire("base_$var_f")) {
131
-			$var_f = "base_$var_f";
132
-		}
133
-		if ($var_f != $exec) {
134
-			spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
135
-			$exec = $var_f;
136
-			set_request('exec', $exec);
137
-		}
138
-	}
113
+    if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']["admin"], $l)) {
114
+        list(, $var_f, $n) = $l;
115
+    }
116
+    if (_AJAX
117
+        or !(
118
+            isset($_COOKIE['spip_admin'])
119
+            or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo')
120
+        )
121
+    ) {
122
+        spip_log("Quand la meta admin vaut " .
123
+            $GLOBALS['meta']["admin"] .
124
+            " seul un admin peut se connecter et sans AJAX." .
125
+            " En cas de probleme, detruire cette meta.");
126
+        die(_T('info_travaux_texte'));
127
+    }
128
+    if ($n) {
129
+        list(, $var_f, $n) = $l;
130
+        if (tester_url_ecrire("base_$var_f")) {
131
+            $var_f = "base_$var_f";
132
+        }
133
+        if ($var_f != $exec) {
134
+            spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec");
135
+            $exec = $var_f;
136
+            set_request('exec', $exec);
137
+        }
138
+    }
139 139
 }
140 140
 // si nom pas plausible, prendre le script par defaut
141 141
 // attention aux deux cas 404/403 qui commencent par un 4 !
142 142
 elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) {
143
-	$exec = "accueil";
144
-	set_request('exec', $exec);
143
+    $exec = "accueil";
144
+    set_request('exec', $exec);
145 145
 }
146 146
 
147 147
 // compatibilite ascendante : obsolete, ne plus utiliser
148 148
 $GLOBALS['spip_display'] = isset($GLOBALS['visiteur_session']['prefs']['display'])
149
-	? (int) $GLOBALS['visiteur_session']['prefs']['display']
150
-	: 0;
149
+    ? (int) $GLOBALS['visiteur_session']['prefs']['display']
150
+    : 0;
151 151
 $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? preg_replace('/[^a-z0-9]/i', '', $_COOKIE['spip_ecran']) : "etroit";
152 152
 
153 153
 //  si la langue est specifiee par cookie et ne correspond pas
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
 // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie
156 156
 // si le cookie n'est pas pose correctement dans l'action
157 157
 if (!$var_auth and isset($_COOKIE['spip_lang_ecrire'])
158
-	and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
158
+    and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang']
159 159
 ) {
160
-	include_spip('action/converser');
161
-	action_converser_post($GLOBALS['visiteur_session']['lang'], true);
160
+    include_spip('action/converser');
161
+    action_converser_post($GLOBALS['visiteur_session']['lang'], true);
162 162
 }
163 163
 
164 164
 if ($var_f = tester_url_ecrire($exec)) {
165
-	$var_f = charger_fonction($var_f);
166
-	$var_f(); // at last
165
+    $var_f = charger_fonction($var_f);
166
+    $var_f(); // at last
167 167
 } else {
168
-	// Rien de connu: rerouter vers exec=404 au lieu d'echouer
169
-	// ce qui permet de laisser la main a un plugin
170
-	$var_f = charger_fonction('404');
171
-	$var_f($exec);
168
+    // Rien de connu: rerouter vers exec=404 au lieu d'echouer
169
+    // ce qui permet de laisser la main a un plugin
170
+    $var_f = charger_fonction('404');
171
+    $var_f($exec);
172 172
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
76
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
77 77
 		return $charset;
78 78
 	} else {
79 79
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	static $pcre_ok = 0;
160 160
 
161 161
 	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
162
+		$s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
163 163
 		if (preg_match(',\W...\W,u', $s)) {
164 164
 			$pcre_ok = 1;
165 165
 		} else {
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
 
261 261
 	if (!isset($trans[$charset][$charset_cible])) {
262 262
 		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
263
+			$p.chr(128) => "&#8364;",
264
+			$p.chr(129) => ' ', # pas affecte
265
+			$p.chr(130) => "&#8218;",
266
+			$p.chr(131) => "&#402;",
267
+			$p.chr(132) => "&#8222;",
268
+			$p.chr(133) => "&#8230;",
269
+			$p.chr(134) => "&#8224;",
270
+			$p.chr(135) => "&#8225;",
271
+			$p.chr(136) => "&#710;",
272
+			$p.chr(137) => "&#8240;",
273
+			$p.chr(138) => "&#352;",
274
+			$p.chr(139) => "&#8249;",
275
+			$p.chr(140) => "&#338;",
276
+			$p.chr(141) => ' ', # pas affecte
277
+			$p.chr(142) => "&#381;",
278
+			$p.chr(143) => ' ', # pas affecte
279
+			$p.chr(144) => ' ', # pas affecte
280
+			$p.chr(145) => "&#8216;",
281
+			$p.chr(146) => "&#8217;",
282
+			$p.chr(147) => "&#8220;",
283
+			$p.chr(148) => "&#8221;",
284
+			$p.chr(149) => "&#8226;",
285
+			$p.chr(150) => "&#8211;",
286
+			$p.chr(151) => "&#8212;",
287
+			$p.chr(152) => "&#732;",
288
+			$p.chr(153) => "&#8482;",
289
+			$p.chr(154) => "&#353;",
290
+			$p.chr(155) => "&#8250;",
291
+			$p.chr(156) => "&#339;",
292
+			$p.chr(157) => ' ', # pas affecte
293
+			$p.chr(158) => "&#382;",
294
+			$p.chr(159) => "&#376;",
295 295
 		);
296 296
 		if ($charset_cible != 'unicode') {
297 297
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 					and is_array($GLOBALS['CHARSET'][$cset])
422 422
 				) {
423 423
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
424
+						$trans[$charset][chr($key)] = '&#'.$val.';';
425 425
 					}
426 426
 				}
427 427
 			}
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 					$h = dechex($e);
489 489
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490 490
 						$s = $CHARSET_REVERSE[$charset][$e];
491
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
491
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
492
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
493 493
 					} else {
494
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
494
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
495
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
496 496
 					}
497 497
 				}
498 498
 			}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 				and is_array($GLOBALS['CHARSET'][$cset])
537 537
 			) {
538 538
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
539
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
540 540
 				}
541 541
 			}
542 542
 		}
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 				}
644 644
 				$thisPos++;
645 645
 			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
646
+			$encodedLetter = "&#".preg_replace('/^0+/', '', $decimalCode).';';
647 647
 			$encodedString .= $encodedLetter;
648 648
 		}
649 649
 	}
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687 687
 			else {
688 688
 				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
689
+					$texte .= '&#'.$word.';';
690 690
 				}
691 691
 			}
692 692
 		}
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
 		return chr($num);
716 716
 	}
717 717
 	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
718
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
719 719
 	}
720 720
 	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
721
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
722 722
 	}
723 723
 	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
724
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
725 725
 	}
726 726
 
727 727
 	return '';
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778 778
 		$num = $regs[1];
779 779
 		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
780
+		$s = '\u'.sprintf("%04x", $num);
781 781
 		$texte = str_replace($regs[0], $s, $texte);
782 782
 	}
783 783
 
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
796 796
 	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
797
+		$texte = str_replace($regs[0], "&#".hexdec($regs[1]).";", $texte);
798 798
 	}
799 799
 
800 800
 	return $texte;
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 		return $texte;
840 840
 	}
841 841
 
842
-	$table_translit = 'translit' . $complexe;
842
+	$table_translit = 'translit'.$complexe;
843 843
 
844 844
 	// 2. Translitterer grace a la table predefinie
845 845
 	if (!isset($trans[$complexe])) {
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
  *    true s'il a un BOM
931 931
  **/
932 932
 function bom_utf8($texte) {
933
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
934 934
 }
935 935
 
936 936
 /**
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126 1126
 		// (un caractere utf-8 prenant au maximum n bytes)
1127 1127
 		$n = 0;
1128
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1128
+		while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) {
1129 1129
 			;
1130 1130
 		}
1131 1131
 		$c = substr($c, 0, $n * $length);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 
1160 1160
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1161 1161
 
1162
-	return $lettre1 . spip_substr($c, 1);
1162
+	return $lettre1.spip_substr($c, 1);
1163 1163
 }
1164 1164
 
1165 1165
 /**
Please login to merge, or discard this patch.
Indentation   +704 added lines, -704 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = array();
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = array();
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = array();
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = array();
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (function_exists('mb_internal_encoding')
100
-			and function_exists('mb_detect_order')
101
-			and function_exists('mb_substr')
102
-			and function_exists('mb_strlen')
103
-			and function_exists('mb_strtolower')
104
-			and function_exists('mb_strtoupper')
105
-			and function_exists('mb_encode_mimeheader')
106
-			and function_exists('mb_encode_numericentity')
107
-			and function_exists('mb_decode_numericentity')
108
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
-		) {
110
-			mb_internal_encoding('utf-8');
111
-			$mb = 1;
112
-		} else {
113
-			$mb = -1;
114
-		}
115
-	}
116
-
117
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (function_exists('mb_internal_encoding')
100
+            and function_exists('mb_detect_order')
101
+            and function_exists('mb_substr')
102
+            and function_exists('mb_strlen')
103
+            and function_exists('mb_strtolower')
104
+            and function_exists('mb_strtoupper')
105
+            and function_exists('mb_encode_mimeheader')
106
+            and function_exists('mb_encode_numericentity')
107
+            and function_exists('mb_decode_numericentity')
108
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
+        ) {
110
+            mb_internal_encoding('utf-8');
111
+            $mb = 1;
112
+        } else {
113
+            $mb = -1;
114
+        }
115
+    }
116
+
117
+    return ($mb == 1);
118 118
 }
119 119
 
120 120
 /**
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
  *     true si iconv fonctionne correctement
130 130
  **/
131 131
 function test_iconv() {
132
-	static $iconv_ok;
133
-
134
-	if (!$iconv_ok) {
135
-		if (!function_exists('iconv')) {
136
-			$iconv_ok = -1;
137
-		} else {
138
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
-				$iconv_ok = 1;
140
-			} else {
141
-				$iconv_ok = -1;
142
-			}
143
-		}
144
-	}
145
-
146
-	return ($iconv_ok == 1);
132
+    static $iconv_ok;
133
+
134
+    if (!$iconv_ok) {
135
+        if (!function_exists('iconv')) {
136
+            $iconv_ok = -1;
137
+        } else {
138
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
+                $iconv_ok = 1;
140
+            } else {
141
+                $iconv_ok = -1;
142
+            }
143
+        }
144
+    }
145
+
146
+    return ($iconv_ok == 1);
147 147
 }
148 148
 
149 149
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
  *     true si PCRE supporte l'UTF-8 correctement
157 157
  **/
158 158
 function test_pcre_unicode() {
159
-	static $pcre_ok = 0;
160
-
161
-	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
-		if (preg_match(',\W...\W,u', $s)) {
164
-			$pcre_ok = 1;
165
-		} else {
166
-			$pcre_ok = -1;
167
-		}
168
-	}
169
-
170
-	return $pcre_ok == 1;
159
+    static $pcre_ok = 0;
160
+
161
+    if (!$pcre_ok) {
162
+        $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
+        if (preg_match(',\W...\W,u', $s)) {
164
+            $pcre_ok = 1;
165
+        } else {
166
+            $pcre_ok = -1;
167
+        }
168
+    }
169
+
170
+    return $pcre_ok == 1;
171 171
 }
172 172
 
173 173
 /**
@@ -183,22 +183,22 @@  discard block
 block discarded – undo
183 183
  *    Plage de caractères
184 184
  **/
185 185
 function pcre_lettres_unicode() {
186
-	static $plage_unicode;
187
-
188
-	if (!$plage_unicode) {
189
-		if (test_pcre_unicode()) {
190
-			// cf. http://www.unicode.org/charts/
191
-			$plage_unicode = '\w' // iso-latin
192
-				. '\x{100}-\x{24f}' // europeen etendu
193
-				. '\x{300}-\x{1cff}' // des tas de trucs
194
-			;
195
-		} else {
196
-			// fallback a trois sous
197
-			$plage_unicode = '\w';
198
-		}
199
-	}
200
-
201
-	return $plage_unicode;
186
+    static $plage_unicode;
187
+
188
+    if (!$plage_unicode) {
189
+        if (test_pcre_unicode()) {
190
+            // cf. http://www.unicode.org/charts/
191
+            $plage_unicode = '\w' // iso-latin
192
+                . '\x{100}-\x{24f}' // europeen etendu
193
+                . '\x{300}-\x{1cff}' // des tas de trucs
194
+            ;
195
+        } else {
196
+            // fallback a trois sous
197
+            $plage_unicode = '\w';
198
+        }
199
+    }
200
+
201
+    return $plage_unicode;
202 202
 }
203 203
 
204 204
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
  *    Plage de caractères
217 217
  **/
218 218
 function plage_punct_unicode() {
219
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
219
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220 220
 }
221 221
 
222 222
 /**
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
  *     Texte corrigé
237 237
  **/
238 238
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
239
-	static $trans;
240
-
241
-	if (is_array($texte)) {
242
-		return array_map('corriger_caracteres_windows', $texte);
243
-	}
244
-
245
-	if ($charset == 'AUTO') {
246
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
247
-	}
248
-	if ($charset == 'utf-8') {
249
-		$p = chr(194);
250
-		if (strpos($texte, $p) == false) {
251
-			return $texte;
252
-		}
253
-	} else {
254
-		if ($charset == 'iso-8859-1') {
255
-			$p = '';
256
-		} else {
257
-			return $texte;
258
-		}
259
-	}
260
-
261
-	if (!isset($trans[$charset][$charset_cible])) {
262
-		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
295
-		);
296
-		if ($charset_cible != 'unicode') {
297
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
-			}
300
-		}
301
-	}
302
-
303
-	return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
-		array_values($trans[$charset][$charset_cible]), $texte);
239
+    static $trans;
240
+
241
+    if (is_array($texte)) {
242
+        return array_map('corriger_caracteres_windows', $texte);
243
+    }
244
+
245
+    if ($charset == 'AUTO') {
246
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
247
+    }
248
+    if ($charset == 'utf-8') {
249
+        $p = chr(194);
250
+        if (strpos($texte, $p) == false) {
251
+            return $texte;
252
+        }
253
+    } else {
254
+        if ($charset == 'iso-8859-1') {
255
+            $p = '';
256
+        } else {
257
+            return $texte;
258
+        }
259
+    }
260
+
261
+    if (!isset($trans[$charset][$charset_cible])) {
262
+        $trans[$charset][$charset_cible] = array(
263
+            $p . chr(128) => "&#8364;",
264
+            $p . chr(129) => ' ', # pas affecte
265
+            $p . chr(130) => "&#8218;",
266
+            $p . chr(131) => "&#402;",
267
+            $p . chr(132) => "&#8222;",
268
+            $p . chr(133) => "&#8230;",
269
+            $p . chr(134) => "&#8224;",
270
+            $p . chr(135) => "&#8225;",
271
+            $p . chr(136) => "&#710;",
272
+            $p . chr(137) => "&#8240;",
273
+            $p . chr(138) => "&#352;",
274
+            $p . chr(139) => "&#8249;",
275
+            $p . chr(140) => "&#338;",
276
+            $p . chr(141) => ' ', # pas affecte
277
+            $p . chr(142) => "&#381;",
278
+            $p . chr(143) => ' ', # pas affecte
279
+            $p . chr(144) => ' ', # pas affecte
280
+            $p . chr(145) => "&#8216;",
281
+            $p . chr(146) => "&#8217;",
282
+            $p . chr(147) => "&#8220;",
283
+            $p . chr(148) => "&#8221;",
284
+            $p . chr(149) => "&#8226;",
285
+            $p . chr(150) => "&#8211;",
286
+            $p . chr(151) => "&#8212;",
287
+            $p . chr(152) => "&#732;",
288
+            $p . chr(153) => "&#8482;",
289
+            $p . chr(154) => "&#353;",
290
+            $p . chr(155) => "&#8250;",
291
+            $p . chr(156) => "&#339;",
292
+            $p . chr(157) => ' ', # pas affecte
293
+            $p . chr(158) => "&#382;",
294
+            $p . chr(159) => "&#376;",
295
+        );
296
+        if ($charset_cible != 'unicode') {
297
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
+            }
300
+        }
301
+    }
302
+
303
+    return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
+        array_values($trans[$charset][$charset_cible]), $texte);
305 305
 }
306 306
 
307 307
 
@@ -318,24 +318,24 @@  discard block
 block discarded – undo
318 318
  *     Texte converti
319 319
  **/
320 320
 function html2unicode($texte, $secure = false) {
321
-	if (strpos($texte, '&') === false) {
322
-		return $texte;
323
-	}
324
-	static $trans = array();
325
-	if (!$trans) {
326
-		load_charset('html');
327
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
-			$trans["&$key;"] = $val;
329
-		}
330
-	}
331
-
332
-	if ($secure) {
333
-		return str_replace(array_keys($trans), array_values($trans), $texte);
334
-	} else {
335
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
-			str_replace(array_keys($trans), array_values($trans), $texte)
337
-		);
338
-	}
321
+    if (strpos($texte, '&') === false) {
322
+        return $texte;
323
+    }
324
+    static $trans = array();
325
+    if (!$trans) {
326
+        load_charset('html');
327
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
+            $trans["&$key;"] = $val;
329
+        }
330
+    }
331
+
332
+    if ($secure) {
333
+        return str_replace(array_keys($trans), array_values($trans), $texte);
334
+    } else {
335
+        return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
+            str_replace(array_keys($trans), array_values($trans), $texte)
337
+        );
338
+    }
339 339
 }
340 340
 
341 341
 
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
  *     Texte converti
351 351
  **/
352 352
 function mathml2unicode($texte) {
353
-	static $trans;
354
-	if (!$trans) {
355
-		load_charset('mathml');
353
+    static $trans;
354
+    if (!$trans) {
355
+        load_charset('mathml');
356 356
 
357
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
-			$trans["&$key;"] = $val;
359
-		}
360
-	}
357
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
+            $trans["&$key;"] = $val;
359
+        }
360
+    }
361 361
 
362
-	return str_replace(array_keys($trans), array_values($trans), $texte);
362
+    return str_replace(array_keys($trans), array_values($trans), $texte);
363 363
 }
364 364
 
365 365
 
@@ -381,76 +381,76 @@  discard block
 block discarded – undo
381 381
  *     Texte converti en unicode
382 382
  **/
383 383
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
384
-	static $trans;
385
-
386
-	if ($charset == 'AUTO') {
387
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
388
-	}
389
-
390
-	if ($charset == '') {
391
-		$charset = 'iso-8859-1';
392
-	}
393
-	$charset = strtolower($charset);
394
-
395
-	switch ($charset) {
396
-		case 'utf-8':
397
-		case 'utf8':
398
-			return utf_8_to_unicode($texte);
399
-
400
-		case 'iso-8859-1':
401
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
-		// pas de break; ici, on suit sur default:
403
-
404
-		default:
405
-			// mbstring presente ?
406
-			if (init_mb_string()) {
407
-				$order = mb_detect_order();
408
-				try {
409
-					# mb_string connait-il $charset?
410
-					if ($order and mb_detect_order($charset)) {
411
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
412
-						if ($s && $s != $texte) {
413
-							return utf_8_to_unicode($s);
414
-						}
415
-					}
384
+    static $trans;
385
+
386
+    if ($charset == 'AUTO') {
387
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
388
+    }
389
+
390
+    if ($charset == '') {
391
+        $charset = 'iso-8859-1';
392
+    }
393
+    $charset = strtolower($charset);
394
+
395
+    switch ($charset) {
396
+        case 'utf-8':
397
+        case 'utf8':
398
+            return utf_8_to_unicode($texte);
399
+
400
+        case 'iso-8859-1':
401
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
+        // pas de break; ici, on suit sur default:
403
+
404
+        default:
405
+            // mbstring presente ?
406
+            if (init_mb_string()) {
407
+                $order = mb_detect_order();
408
+                try {
409
+                    # mb_string connait-il $charset?
410
+                    if ($order and mb_detect_order($charset)) {
411
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
412
+                        if ($s && $s != $texte) {
413
+                            return utf_8_to_unicode($s);
414
+                        }
415
+                    }
416 416
 					
417
-				} catch (\Error $e) {
418
-					// Le charset n'existe probablement pas
419
-				} finally {
420
-					mb_detect_order($order); # remettre comme precedemment
421
-				}
422
-			}
423
-
424
-			// Sinon, peut-etre connaissons-nous ce charset ?
425
-			if (!isset($trans[$charset])) {
426
-				if (
427
-					$cset = load_charset($charset)
428
-					and is_array($GLOBALS['CHARSET'][$cset])
429
-				) {
430
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
431
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
432
-					}
433
-				}
434
-			}
435
-			if (isset($trans[$charset]) and count($trans[$charset])) {
436
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
437
-			}
438
-
439
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
440
-			// caractere n'appartient pas au charset, mais c'est un probleme
441
-			// surtout en utf-8, gere ci-dessus)
442
-			if (test_iconv()) {
443
-				$s = iconv($charset, 'utf-32le', $texte);
444
-				if ($s) {
445
-					return utf_32_to_unicode($s);
446
-				}
447
-			}
448
-
449
-			// Au pire ne rien faire
450
-			spip_log("erreur charset '$charset' non supporte");
451
-
452
-			return $texte;
453
-	}
417
+                } catch (\Error $e) {
418
+                    // Le charset n'existe probablement pas
419
+                } finally {
420
+                    mb_detect_order($order); # remettre comme precedemment
421
+                }
422
+            }
423
+
424
+            // Sinon, peut-etre connaissons-nous ce charset ?
425
+            if (!isset($trans[$charset])) {
426
+                if (
427
+                    $cset = load_charset($charset)
428
+                    and is_array($GLOBALS['CHARSET'][$cset])
429
+                ) {
430
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
431
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
432
+                    }
433
+                }
434
+            }
435
+            if (isset($trans[$charset]) and count($trans[$charset])) {
436
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
437
+            }
438
+
439
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
440
+            // caractere n'appartient pas au charset, mais c'est un probleme
441
+            // surtout en utf-8, gere ci-dessus)
442
+            if (test_iconv()) {
443
+                $s = iconv($charset, 'utf-32le', $texte);
444
+                if ($s) {
445
+                    return utf_32_to_unicode($s);
446
+                }
447
+            }
448
+
449
+            // Au pire ne rien faire
450
+            spip_log("erreur charset '$charset' non supporte");
451
+
452
+            return $texte;
453
+    }
454 454
 }
455 455
 
456 456
 
@@ -469,44 +469,44 @@  discard block
 block discarded – undo
469 469
  *     Texte transformé dans le charset souhaité
470 470
  **/
471 471
 function unicode2charset($texte, $charset = 'AUTO') {
472
-	static $CHARSET_REVERSE = array();
473
-	static $trans = array();
474
-
475
-	if ($charset == 'AUTO') {
476
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
477
-	}
478
-
479
-	switch ($charset) {
480
-		case 'utf-8':
481
-			return unicode_to_utf_8($texte);
482
-			break;
483
-
484
-		default:
485
-			$charset = load_charset($charset);
486
-
487
-			if (empty($CHARSET_REVERSE[$charset])) {
488
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
489
-			}
490
-
491
-			if (!isset($trans[$charset])) {
492
-				$trans[$charset] = array();
493
-				$t = &$trans[$charset];
494
-				for ($e = 128; $e < 255; $e++) {
495
-					$h = dechex($e);
496
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
497
-						$s = $CHARSET_REVERSE[$charset][$e];
498
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
499
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
500
-					} else {
501
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
502
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
503
-					}
504
-				}
505
-			}
506
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
507
-
508
-			return $texte;
509
-	}
472
+    static $CHARSET_REVERSE = array();
473
+    static $trans = array();
474
+
475
+    if ($charset == 'AUTO') {
476
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
477
+    }
478
+
479
+    switch ($charset) {
480
+        case 'utf-8':
481
+            return unicode_to_utf_8($texte);
482
+            break;
483
+
484
+        default:
485
+            $charset = load_charset($charset);
486
+
487
+            if (empty($CHARSET_REVERSE[$charset])) {
488
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
489
+            }
490
+
491
+            if (!isset($trans[$charset])) {
492
+                $trans[$charset] = array();
493
+                $t = &$trans[$charset];
494
+                for ($e = 128; $e < 255; $e++) {
495
+                    $h = dechex($e);
496
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
497
+                        $s = $CHARSET_REVERSE[$charset][$e];
498
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
499
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
500
+                    } else {
501
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
502
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
503
+                    }
504
+                }
505
+            }
506
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
507
+
508
+            return $texte;
509
+    }
510 510
 }
511 511
 
512 512
 
@@ -524,37 +524,37 @@  discard block
 block discarded – undo
524 524
  *     Texte transformé dans le charset site
525 525
  **/
526 526
 function importer_charset($texte, $charset = 'AUTO') {
527
-	static $trans = array();
528
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
529
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
530
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
531
-		if (init_mb_string()) {
532
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
533
-				and mb_detect_order($charset)
534
-			) {
535
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
536
-			}
537
-			mb_detect_order($order); # remettre comme precedemment
538
-			return $s;
539
-		}
540
-		// Sinon, peut-etre connaissons-nous ce charset ?
541
-		if (!isset($trans[$charset])) {
542
-			if ($cset = load_charset($charset)
543
-				and is_array($GLOBALS['CHARSET'][$cset])
544
-			) {
545
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
546
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
547
-				}
548
-			}
549
-		}
550
-		if (count($trans[$charset])) {
551
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
552
-		}
553
-
554
-		return $texte;
555
-	}
556
-
557
-	return unicode2charset(charset2unicode($texte, $charset));
527
+    static $trans = array();
528
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
529
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
530
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
531
+        if (init_mb_string()) {
532
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
533
+                and mb_detect_order($charset)
534
+            ) {
535
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
536
+            }
537
+            mb_detect_order($order); # remettre comme precedemment
538
+            return $s;
539
+        }
540
+        // Sinon, peut-etre connaissons-nous ce charset ?
541
+        if (!isset($trans[$charset])) {
542
+            if ($cset = load_charset($charset)
543
+                and is_array($GLOBALS['CHARSET'][$cset])
544
+            ) {
545
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
546
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
547
+                }
548
+            }
549
+        }
550
+        if (count($trans[$charset])) {
551
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
552
+        }
553
+
554
+        return $texte;
555
+    }
556
+
557
+    return unicode2charset(charset2unicode($texte, $charset));
558 558
 }
559 559
 
560 560
 
@@ -570,92 +570,92 @@  discard block
 block discarded – undo
570 570
  **/
571 571
 function utf_8_to_unicode($source) {
572 572
 
573
-	// mb_string : methode rapide
574
-	if (init_mb_string()) {
575
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
576
-
577
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
578
-	}
579
-
580
-	// Sinon methode pas a pas
581
-	static $decrement;
582
-	static $shift;
583
-
584
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
585
-	if (!is_array($decrement)) {
586
-		// array used to figure what number to decrement from character order value
587
-		// according to number of characters used to map unicode to ascii by utf-8
588
-		$decrement[4] = 240;
589
-		$decrement[3] = 224;
590
-		$decrement[2] = 192;
591
-		$decrement[1] = 0;
592
-		// the number of bits to shift each charNum by
593
-		$shift[1][0] = 0;
594
-		$shift[2][0] = 6;
595
-		$shift[2][1] = 0;
596
-		$shift[3][0] = 12;
597
-		$shift[3][1] = 6;
598
-		$shift[3][2] = 0;
599
-		$shift[4][0] = 18;
600
-		$shift[4][1] = 12;
601
-		$shift[4][2] = 6;
602
-		$shift[4][3] = 0;
603
-	}
604
-
605
-	$pos = 0;
606
-	$len = strlen($source);
607
-	$encodedString = '';
608
-	while ($pos < $len) {
609
-		$char = '';
610
-		$ischar = false;
611
-		$asciiPos = ord(substr($source, $pos, 1));
612
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
613
-			// 4 chars representing one unicode character
614
-			$thisLetter = substr($source, $pos, 4);
615
-			$pos += 4;
616
-		} else {
617
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
618
-				// 3 chars representing one unicode character
619
-				$thisLetter = substr($source, $pos, 3);
620
-				$pos += 3;
621
-			} else {
622
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
623
-					// 2 chars representing one unicode character
624
-					$thisLetter = substr($source, $pos, 2);
625
-					$pos += 2;
626
-				} else {
627
-					// 1 char (lower ascii)
628
-					$thisLetter = substr($source, $pos, 1);
629
-					$pos += 1;
630
-					$char = $thisLetter;
631
-					$ischar = true;
632
-				}
633
-			}
634
-		}
635
-
636
-		if ($ischar) {
637
-			$encodedString .= $char;
638
-		} else {  // process the string representing the letter to a unicode entity
639
-			$thisLen = strlen($thisLetter);
640
-			$thisPos = 0;
641
-			$decimalCode = 0;
642
-			while ($thisPos < $thisLen) {
643
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
644
-				if ($thisPos == 0) {
645
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
646
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
647
-				} else {
648
-					$charNum = intval($thisCharOrd - 128);
649
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
650
-				}
651
-				$thisPos++;
652
-			}
653
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
654
-			$encodedString .= $encodedLetter;
655
-		}
656
-	}
657
-
658
-	return $encodedString;
573
+    // mb_string : methode rapide
574
+    if (init_mb_string()) {
575
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
576
+
577
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
578
+    }
579
+
580
+    // Sinon methode pas a pas
581
+    static $decrement;
582
+    static $shift;
583
+
584
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
585
+    if (!is_array($decrement)) {
586
+        // array used to figure what number to decrement from character order value
587
+        // according to number of characters used to map unicode to ascii by utf-8
588
+        $decrement[4] = 240;
589
+        $decrement[3] = 224;
590
+        $decrement[2] = 192;
591
+        $decrement[1] = 0;
592
+        // the number of bits to shift each charNum by
593
+        $shift[1][0] = 0;
594
+        $shift[2][0] = 6;
595
+        $shift[2][1] = 0;
596
+        $shift[3][0] = 12;
597
+        $shift[3][1] = 6;
598
+        $shift[3][2] = 0;
599
+        $shift[4][0] = 18;
600
+        $shift[4][1] = 12;
601
+        $shift[4][2] = 6;
602
+        $shift[4][3] = 0;
603
+    }
604
+
605
+    $pos = 0;
606
+    $len = strlen($source);
607
+    $encodedString = '';
608
+    while ($pos < $len) {
609
+        $char = '';
610
+        $ischar = false;
611
+        $asciiPos = ord(substr($source, $pos, 1));
612
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
613
+            // 4 chars representing one unicode character
614
+            $thisLetter = substr($source, $pos, 4);
615
+            $pos += 4;
616
+        } else {
617
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
618
+                // 3 chars representing one unicode character
619
+                $thisLetter = substr($source, $pos, 3);
620
+                $pos += 3;
621
+            } else {
622
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
623
+                    // 2 chars representing one unicode character
624
+                    $thisLetter = substr($source, $pos, 2);
625
+                    $pos += 2;
626
+                } else {
627
+                    // 1 char (lower ascii)
628
+                    $thisLetter = substr($source, $pos, 1);
629
+                    $pos += 1;
630
+                    $char = $thisLetter;
631
+                    $ischar = true;
632
+                }
633
+            }
634
+        }
635
+
636
+        if ($ischar) {
637
+            $encodedString .= $char;
638
+        } else {  // process the string representing the letter to a unicode entity
639
+            $thisLen = strlen($thisLetter);
640
+            $thisPos = 0;
641
+            $decimalCode = 0;
642
+            while ($thisPos < $thisLen) {
643
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
644
+                if ($thisPos == 0) {
645
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
646
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
647
+                } else {
648
+                    $charNum = intval($thisCharOrd - 128);
649
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
650
+                }
651
+                $thisPos++;
652
+            }
653
+            $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
654
+            $encodedString .= $encodedLetter;
655
+        }
656
+    }
657
+
658
+    return $encodedString;
659 659
 }
660 660
 
661 661
 /**
@@ -674,32 +674,32 @@  discard block
 block discarded – undo
674 674
  **/
675 675
 function utf_32_to_unicode($source) {
676 676
 
677
-	// mb_string : methode rapide
678
-	if (init_mb_string()) {
679
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
680
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
681
-
682
-		return str_replace(chr(0), '', $source);
683
-	}
684
-
685
-	// Sinon methode lente
686
-	$texte = '';
687
-	while ($source) {
688
-		$words = unpack("V*", substr($source, 0, 1024));
689
-		$source = substr($source, 1024);
690
-		foreach ($words as $word) {
691
-			if ($word < 128) {
692
-				$texte .= chr($word);
693
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
694
-			else {
695
-				if ($word != 65279) {
696
-					$texte .= '&#' . $word . ';';
697
-				}
698
-			}
699
-		}
700
-	}
701
-
702
-	return $texte;
677
+    // mb_string : methode rapide
678
+    if (init_mb_string()) {
679
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
680
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
681
+
682
+        return str_replace(chr(0), '', $source);
683
+    }
684
+
685
+    // Sinon methode lente
686
+    $texte = '';
687
+    while ($source) {
688
+        $words = unpack("V*", substr($source, 0, 1024));
689
+        $source = substr($source, 1024);
690
+        foreach ($words as $word) {
691
+            if ($word < 128) {
692
+                $texte .= chr($word);
693
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
694
+            else {
695
+                if ($word != 65279) {
696
+                    $texte .= '&#' . $word . ';';
697
+                }
698
+            }
699
+        }
700
+    }
701
+
702
+    return $texte;
703 703
 
704 704
 }
705 705
 
@@ -717,21 +717,21 @@  discard block
 block discarded – undo
717 717
  *    Caractère utf8 si trouvé, '' sinon
718 718
  **/
719 719
 function caractere_utf_8($num) {
720
-	$num = intval($num);
721
-	if ($num < 128) {
722
-		return chr($num);
723
-	}
724
-	if ($num < 2048) {
725
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
726
-	}
727
-	if ($num < 65536) {
728
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
729
-	}
730
-	if ($num < 1114112) {
731
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
732
-	}
733
-
734
-	return '';
720
+    $num = intval($num);
721
+    if ($num < 128) {
722
+        return chr($num);
723
+    }
724
+    if ($num < 2048) {
725
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
726
+    }
727
+    if ($num < 65536) {
728
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
729
+    }
730
+    if ($num < 1114112) {
731
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
732
+    }
733
+
734
+    return '';
735 735
 }
736 736
 
737 737
 /**
@@ -744,30 +744,30 @@  discard block
 block discarded – undo
744 744
  **/
745 745
 function unicode_to_utf_8($texte) {
746 746
 
747
-	// 1. Entites &#128; et suivantes
748
-	$vu = array();
749
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
750
-		$texte, $regs, PREG_SET_ORDER)) {
751
-		foreach ($regs as $reg) {
752
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
753
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
754
-			}
755
-		}
756
-	}
757
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
758
-
759
-	// 2. Entites > &#xFF;
760
-	//$vu = array();
761
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
762
-		$texte, $regs, PREG_SET_ORDER)) {
763
-		foreach ($regs as $reg) {
764
-			if (!isset($vu[$reg[0]])) {
765
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
766
-			}
767
-		}
768
-	}
769
-
770
-	return str_replace(array_keys($vu), array_values($vu), $texte);
747
+    // 1. Entites &#128; et suivantes
748
+    $vu = array();
749
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
750
+        $texte, $regs, PREG_SET_ORDER)) {
751
+        foreach ($regs as $reg) {
752
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
753
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
754
+            }
755
+        }
756
+    }
757
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
758
+
759
+    // 2. Entites > &#xFF;
760
+    //$vu = array();
761
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
762
+        $texte, $regs, PREG_SET_ORDER)) {
763
+        foreach ($regs as $reg) {
764
+            if (!isset($vu[$reg[0]])) {
765
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
766
+            }
767
+        }
768
+    }
769
+
770
+    return str_replace(array_keys($vu), array_values($vu), $texte);
771 771
 
772 772
 }
773 773
 
@@ -780,15 +780,15 @@  discard block
 block discarded – undo
780 780
  *     Texte converti
781 781
  **/
782 782
 function unicode_to_javascript($texte) {
783
-	$vu = array();
784
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
785
-		$num = $regs[1];
786
-		$vu[$num] = true;
787
-		$s = '\u' . sprintf("%04x", $num);
788
-		$texte = str_replace($regs[0], $s, $texte);
789
-	}
790
-
791
-	return $texte;
783
+    $vu = array();
784
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
785
+        $num = $regs[1];
786
+        $vu[$num] = true;
787
+        $s = '\u' . sprintf("%04x", $num);
788
+        $texte = str_replace($regs[0], $s, $texte);
789
+    }
790
+
791
+    return $texte;
792 792
 }
793 793
 
794 794
 /**
@@ -800,11 +800,11 @@  discard block
 block discarded – undo
800 800
  *     Texte converti
801 801
  **/
802 802
 function javascript_to_unicode($texte) {
803
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
804
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
805
-	}
803
+    while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
804
+        $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
805
+    }
806 806
 
807
-	return $texte;
807
+    return $texte;
808 808
 }
809 809
 
810 810
 /**
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
  *     Texte converti
817 817
  **/
818 818
 function javascript_to_binary($texte) {
819
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
820
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
821
-	}
819
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
820
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
821
+    }
822 822
 
823
-	return $texte;
823
+    return $texte;
824 824
 }
825 825
 
826 826
 
@@ -838,26 +838,26 @@  discard block
 block discarded – undo
838 838
  * @return string
839 839
  */
840 840
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
841
-	static $trans = [];
842
-	if ($charset == 'AUTO') {
843
-		$charset = $GLOBALS['meta']['charset'];
844
-	}
845
-	if (!strlen($texte)) {
846
-		return $texte;
847
-	}
848
-
849
-	$table_translit = 'translit' . $complexe;
850
-
851
-	// 2. Translitterer grace a la table predefinie
852
-	if (!isset($trans[$complexe])) {
853
-		$trans[$complexe] = [];
854
-		load_charset($table_translit);
855
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
856
-			$trans[$complexe][caractere_utf_8($key)] = $val;
857
-		}
858
-	}
859
-
860
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
841
+    static $trans = [];
842
+    if ($charset == 'AUTO') {
843
+        $charset = $GLOBALS['meta']['charset'];
844
+    }
845
+    if (!strlen($texte)) {
846
+        return $texte;
847
+    }
848
+
849
+    $table_translit = 'translit' . $complexe;
850
+
851
+    // 2. Translitterer grace a la table predefinie
852
+    if (!isset($trans[$complexe])) {
853
+        $trans[$complexe] = [];
854
+        load_charset($table_translit);
855
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
856
+            $trans[$complexe][caractere_utf_8($key)] = $val;
857
+        }
858
+    }
859
+
860
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
861 861
 }
862 862
 
863 863
 /**
@@ -880,14 +880,14 @@  discard block
 block discarded – undo
880 880
  * @return string
881 881
  */
882 882
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
883
-	// 0. Supprimer les caracteres illegaux
884
-	include_spip('inc/filtres');
885
-	$texte = corriger_caracteres($texte);
883
+    // 0. Supprimer les caracteres illegaux
884
+    include_spip('inc/filtres');
885
+    $texte = corriger_caracteres($texte);
886 886
 
887
-	// 1. Passer le charset et les &eacute en utf-8
888
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
887
+    // 1. Passer le charset et les &eacute en utf-8
888
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
889 889
 
890
-	return translitteration_rapide($texte, $charset, $complexe);
890
+    return translitteration_rapide($texte, $charset, $complexe);
891 891
 }
892 892
 
893 893
 /**
@@ -902,17 +902,17 @@  discard block
 block discarded – undo
902 902
  * @return string
903 903
  */
904 904
 function translitteration_complexe($texte, $chiffres = false) {
905
-	$texte = translitteration($texte, 'AUTO', 'complexe');
905
+    $texte = translitteration($texte, 'AUTO', 'complexe');
906 906
 
907
-	if ($chiffres) {
908
-		$texte = preg_replace_callback(
909
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
910
-			function($m) { return translitteration_chiffree($m[0]); },
911
-			$texte
912
-		);
913
-	}
907
+    if ($chiffres) {
908
+        $texte = preg_replace_callback(
909
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
910
+            function($m) { return translitteration_chiffree($m[0]); },
911
+            $texte
912
+        );
913
+    }
914 914
 
915
-	return $texte;
915
+    return $texte;
916 916
 }
917 917
 
918 918
 /**
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
  * @return string
925 925
  */
926 926
 function translitteration_chiffree($car) {
927
-	return strtr($car, "'`?~.^+(-", "123456789");
927
+    return strtr($car, "'`?~.^+(-", "123456789");
928 928
 }
929 929
 
930 930
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  *    true s'il a un BOM
938 938
  **/
939 939
 function bom_utf8($texte) {
940
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
940
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
941 941
 }
942 942
 
943 943
 /**
@@ -954,18 +954,18 @@  discard block
 block discarded – undo
954 954
  *     true si c'est le cas
955 955
  **/
956 956
 function is_utf8($string) {
957
-	return !strlen(
958
-		preg_replace(
959
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
960
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
961
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
962
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
963
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
964
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
965
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
966
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
967
-			. ',sS',
968
-			'', $string));
957
+    return !strlen(
958
+        preg_replace(
959
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
960
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
961
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
962
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
963
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
964
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
965
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
966
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
967
+            . ',sS',
968
+            '', $string));
969 969
 }
970 970
 
971 971
 /**
@@ -977,10 +977,10 @@  discard block
 block discarded – undo
977 977
  *     true si c'est le cas
978 978
  **/
979 979
 function is_ascii($string) {
980
-	return !strlen(
981
-		preg_replace(
982
-			',[\x09\x0A\x0D\x20-\x7E],sS',
983
-			'', $string));
980
+    return !strlen(
981
+        preg_replace(
982
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
983
+            '', $string));
984 984
 }
985 985
 
986 986
 /**
@@ -999,53 +999,53 @@  discard block
 block discarded – undo
999 999
  **/
1000 1000
 function transcoder_page($texte, $headers = '') {
1001 1001
 
1002
-	// Si tout est < 128 pas la peine d'aller plus loin
1003
-	if (is_ascii($texte)) {
1004
-		#spip_log('charset: ascii');
1005
-		return $texte;
1006
-	}
1007
-
1008
-	if (bom_utf8($texte)) {
1009
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1010
-		$charset = 'utf-8';
1011
-		$texte = substr($texte, 3);
1012
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1013
-		// charset precise par le contenu (xml)
1014
-		$charset = trim(strtolower($regs[1]));
1015
-	} elseif (
1016
-		// charset precise par le contenu (html)
1017
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1018
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1019
-		and false === strpos($regs[2], '#')
1020
-		and $tmp = trim(strtolower($regs[2]))
1021
-	) {
1022
-		$charset = $tmp;
1023
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1024
-		// charset de la reponse http
1025
-		$charset = trim(strtolower($regs[1]));
1026
-	} else {
1027
-		$charset = '';
1028
-	}
1029
-
1030
-
1031
-	// normaliser les noms du shif-jis japonais
1032
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1033
-		$charset = 'shift-jis';
1034
-	}
1035
-
1036
-	if ($charset) {
1037
-		spip_log("charset: $charset");
1038
-	} else {
1039
-		// valeur par defaut
1040
-		if (is_utf8($texte)) {
1041
-			$charset = 'utf-8';
1042
-		} else {
1043
-			$charset = 'iso-8859-1';
1044
-		}
1045
-		spip_log("charset probable: $charset");
1046
-	}
1047
-
1048
-	return importer_charset($texte, $charset);
1002
+    // Si tout est < 128 pas la peine d'aller plus loin
1003
+    if (is_ascii($texte)) {
1004
+        #spip_log('charset: ascii');
1005
+        return $texte;
1006
+    }
1007
+
1008
+    if (bom_utf8($texte)) {
1009
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1010
+        $charset = 'utf-8';
1011
+        $texte = substr($texte, 3);
1012
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1013
+        // charset precise par le contenu (xml)
1014
+        $charset = trim(strtolower($regs[1]));
1015
+    } elseif (
1016
+        // charset precise par le contenu (html)
1017
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1018
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1019
+        and false === strpos($regs[2], '#')
1020
+        and $tmp = trim(strtolower($regs[2]))
1021
+    ) {
1022
+        $charset = $tmp;
1023
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1024
+        // charset de la reponse http
1025
+        $charset = trim(strtolower($regs[1]));
1026
+    } else {
1027
+        $charset = '';
1028
+    }
1029
+
1030
+
1031
+    // normaliser les noms du shif-jis japonais
1032
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1033
+        $charset = 'shift-jis';
1034
+    }
1035
+
1036
+    if ($charset) {
1037
+        spip_log("charset: $charset");
1038
+    } else {
1039
+        // valeur par defaut
1040
+        if (is_utf8($texte)) {
1041
+            $charset = 'utf-8';
1042
+        } else {
1043
+            $charset = 'iso-8859-1';
1044
+        }
1045
+        spip_log("charset probable: $charset");
1046
+    }
1047
+
1048
+    return importer_charset($texte, $charset);
1049 1049
 }
1050 1050
 
1051 1051
 
@@ -1069,26 +1069,26 @@  discard block
 block discarded – undo
1069 1069
  *     Le texte coupé
1070 1070
  **/
1071 1071
 function spip_substr($c, $start = 0, $length = null) {
1072
-	// Si ce n'est pas utf-8, utiliser substr
1073
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1074
-		if ($length) {
1075
-			return substr($c, $start, $length);
1076
-		} else {
1077
-			substr($c, $start);
1078
-		}
1079
-	}
1080
-
1081
-	// Si utf-8, voir si on dispose de mb_string
1082
-	if (init_mb_string()) {
1083
-		if ($length) {
1084
-			return mb_substr($c, $start, $length);
1085
-		} else {
1086
-			return mb_substr($c, $start);
1087
-		}
1088
-	}
1089
-
1090
-	// Version manuelle (cf. ci-dessous)
1091
-	return spip_substr_manuelle($c, $start, $length);
1072
+    // Si ce n'est pas utf-8, utiliser substr
1073
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1074
+        if ($length) {
1075
+            return substr($c, $start, $length);
1076
+        } else {
1077
+            substr($c, $start);
1078
+        }
1079
+    }
1080
+
1081
+    // Si utf-8, voir si on dispose de mb_string
1082
+    if (init_mb_string()) {
1083
+        if ($length) {
1084
+            return mb_substr($c, $start, $length);
1085
+        } else {
1086
+            return mb_substr($c, $start);
1087
+        }
1088
+    }
1089
+
1090
+    // Version manuelle (cf. ci-dessous)
1091
+    return spip_substr_manuelle($c, $start, $length);
1092 1092
 }
1093 1093
 
1094 1094
 
@@ -1107,40 +1107,40 @@  discard block
 block discarded – undo
1107 1107
  **/
1108 1108
 function spip_substr_manuelle($c, $start, $length = null) {
1109 1109
 
1110
-	// Cas pathologique
1111
-	if ($length === 0) {
1112
-		return '';
1113
-	}
1114
-
1115
-	// S'il y a un demarrage, on se positionne
1116
-	if ($start > 0) {
1117
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1118
-	} elseif ($start < 0) {
1119
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1120
-	}
1121
-
1122
-	if (!$length) {
1123
-		return $c;
1124
-	}
1125
-
1126
-	if ($length > 0) {
1127
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1128
-		// (un caractere utf-8 prenant au maximum n bytes)
1129
-		$n = 0;
1130
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1131
-			;
1132
-		}
1133
-		$c = substr($c, 0, $n * $length);
1134
-		// puis, tant qu'on est trop long, on coupe...
1135
-		while (($l = spip_strlen($c)) > $length) {
1136
-			$c = substr($c, 0, $length - $l);
1137
-		}
1138
-
1139
-		return $c;
1140
-	}
1141
-
1142
-	// $length < 0
1143
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1110
+    // Cas pathologique
1111
+    if ($length === 0) {
1112
+        return '';
1113
+    }
1114
+
1115
+    // S'il y a un demarrage, on se positionne
1116
+    if ($start > 0) {
1117
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1118
+    } elseif ($start < 0) {
1119
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1120
+    }
1121
+
1122
+    if (!$length) {
1123
+        return $c;
1124
+    }
1125
+
1126
+    if ($length > 0) {
1127
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1128
+        // (un caractere utf-8 prenant au maximum n bytes)
1129
+        $n = 0;
1130
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1131
+            ;
1132
+        }
1133
+        $c = substr($c, 0, $n * $length);
1134
+        // puis, tant qu'on est trop long, on coupe...
1135
+        while (($l = spip_strlen($c)) > $length) {
1136
+            $c = substr($c, 0, $length - $l);
1137
+        }
1138
+
1139
+        return $c;
1140
+    }
1141
+
1142
+    // $length < 0
1143
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1144 1144
 }
1145 1145
 
1146 1146
 /**
@@ -1154,14 +1154,14 @@  discard block
 block discarded – undo
1154 1154
  *     La chaîne avec une majuscule sur le premier mot
1155 1155
  */
1156 1156
 function spip_ucfirst($c) {
1157
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1158
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1159
-		return ucfirst($c);
1160
-	}
1157
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1158
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1159
+        return ucfirst($c);
1160
+    }
1161 1161
 
1162
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1162
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1163 1163
 
1164
-	return $lettre1 . spip_substr($c, 1);
1164
+    return $lettre1 . spip_substr($c, 1);
1165 1165
 }
1166 1166
 
1167 1167
 /**
@@ -1175,12 +1175,12 @@  discard block
 block discarded – undo
1175 1175
  *     La chaîne en minuscules
1176 1176
  */
1177 1177
 function spip_strtolower($c) {
1178
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1179
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1180
-		return strtolower($c);
1181
-	}
1178
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1179
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1180
+        return strtolower($c);
1181
+    }
1182 1182
 
1183
-	return mb_strtolower($c);
1183
+    return mb_strtolower($c);
1184 1184
 }
1185 1185
 
1186 1186
 /**
@@ -1194,23 +1194,23 @@  discard block
 block discarded – undo
1194 1194
  *     Longueur de la chaîne
1195 1195
  */
1196 1196
 function spip_strlen($c) {
1197
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1198
-	$c = str_replace("\r\n", "\n", $c);
1199
-
1200
-	// Si ce n'est pas utf-8, utiliser strlen
1201
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1202
-		return strlen($c);
1203
-	}
1204
-
1205
-	// Sinon, utiliser mb_strlen() si disponible
1206
-	if (init_mb_string()) {
1207
-		return mb_strlen($c);
1208
-	}
1209
-
1210
-	// Methode manuelle : on supprime les bytes 10......,
1211
-	// on compte donc les ascii (0.......) et les demarrages
1212
-	// de caracteres utf-8 (11......)
1213
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1197
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1198
+    $c = str_replace("\r\n", "\n", $c);
1199
+
1200
+    // Si ce n'est pas utf-8, utiliser strlen
1201
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1202
+        return strlen($c);
1203
+    }
1204
+
1205
+    // Sinon, utiliser mb_strlen() si disponible
1206
+    if (init_mb_string()) {
1207
+        return mb_strlen($c);
1208
+    }
1209
+
1210
+    // Methode manuelle : on supprime les bytes 10......,
1211
+    // on compte donc les ascii (0.......) et les demarrages
1212
+    // de caracteres utf-8 (11......)
1213
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1214 1214
 }
1215 1215
 
1216 1216
 // Initialisation
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1221 1221
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1222 1222
 if (!isset($GLOBALS['meta']['pcre_u'])
1223
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1223
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1224 1224
 ) {
1225
-	include_spip('inc/meta');
1226
-	ecrire_meta('pcre_u',
1227
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1228
-			and test_pcre_unicode())
1229
-			? 'u' : ''
1230
-	);
1225
+    include_spip('inc/meta');
1226
+    ecrire_meta('pcre_u',
1227
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1228
+            and test_pcre_unicode())
1229
+            ? 'u' : ''
1230
+    );
1231 1231
 }
1232 1232
 
1233 1233
 
@@ -1243,17 +1243,17 @@  discard block
 block discarded – undo
1243 1243
  *     en unicode : &#128169;
1244 1244
  */
1245 1245
 function utf8_noplanes($x) {
1246
-	$regexp_utf8_4bytes = '/(
1246
+    $regexp_utf8_4bytes = '/(
1247 1247
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1248 1248
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1249 1249
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1250 1250
 )/xS';
1251
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1252
-		foreach ($z[0] as $k) {
1253
-			$ku = utf_8_to_unicode($k);
1254
-			$x = str_replace($k, $ku, $x);
1255
-		}
1256
-	}
1257
-
1258
-	return $x;
1251
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1252
+        foreach ($z[0] as $k) {
1253
+            $ku = utf_8_to_unicode($k);
1254
+            $x = str_replace($k, $ku, $x);
1255
+        }
1256
+    }
1257
+
1258
+    return $x;
1259 1259
 }
Please login to merge, or discard this patch.
ecrire/inc/idna_convert.class.php 1 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/rubriques.php 3 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	$id_pred = $id_rubrique;
106 106
 	while (true) {
107 107
 		sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
108
-			"id_rubrique=" . intval($id_rubrique));
109
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
108
+			"id_rubrique=".intval($id_rubrique));
109
+		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=".intval($id_rubrique));
110 110
 		if (!$id_parent) {
111 111
 			break;
112 112
 		}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			return $id_pred != $id_rubrique;
143 143
 		}
144 144
 		// passer au parent si on a depublie
145
-		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
145
+		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=".intval($id_pred));
146 146
 		$id_pred = $r['id_parent'];
147 147
 	}
148 148
 
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
 		$date = date('Y-m-d H:i:s');
168 168
 	}
169 169
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
170
-		" AND date <= " . sql_quote($date) : '';
170
+		" AND date <= ".sql_quote($date) : '';
171 171
 
172 172
 	if (!$id_rubrique = intval($id_rubrique)) {
173 173
 		return false;
174 174
 	}
175 175
 
176 176
 	// verifier qu'elle existe et est bien publiee
177
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
177
+	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=".intval($id_rubrique));
178 178
 	if (!$r or $r['statut'] !== 'publie') {
179 179
 		return false;
180 180
 	}
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	// Le type de l'objet est au pluriel
184 184
 	$compte = array(
185 185
 		'articles' => sql_countsel("spip_articles",
186
-			"id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
187
-		'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
186
+			"id_rubrique=".intval($id_rubrique)." AND statut='publie'$postdates"),
187
+		'rubriques' => sql_countsel("spip_rubriques", "id_parent=".intval($id_rubrique)." AND statut='publie'"),
188 188
 		'documents' => sql_countsel(
189 189
 			"spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
190
-			"L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
190
+			"L.id_objet=".intval($id_rubrique)." AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
191 191
 	);
192 192
 
193 193
 	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 	}
212 212
 
213
-	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
213
+	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=".intval($id_rubrique));
214 214
 
215 215
 #		spip_log("depublier_rubrique $id_pred");
216 216
 	return true;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 	// Afficher les articles post-dates ?
275 275
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
276
-		"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
276
+		"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
277 277
 
278 278
 	$r = sql_select(
279 279
 		"R.id_rubrique AS id, max(A.date) AS date_h",
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		"A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
282 282
 	while ($row = sql_fetch($r)) {
283 283
 		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
284
-			"id_rubrique=" . intval($row['id']));
284
+			"id_rubrique=".intval($row['id']));
285 285
 	}
286 286
 
287 287
 	// point d'entree pour permettre a des plugins de gerer le statut
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 			"(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
303 303
 		while ($row = sql_fetch($r)) {
304 304
 			sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
305
-				"id_rubrique=" . intval($row['id']));
305
+				"id_rubrique=".intval($row['id']));
306 306
 			$continuer = true;
307 307
 		}
308 308
 	} while ($continuer);
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			and $rows = sql_allfetsel(
354 354
 				"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
355 355
 				"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
356
-				"R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
356
+				"R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
357 357
 				"", "R.id_secteur", "0,100")) {
358 358
 
359 359
 			$id_secteur = null;
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 			and $rows = sql_allfetsel(
383 383
 				"id_rubrique as id",
384 384
 				"spip_rubriques",
385
-				"profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
386
-					"spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
385
+				"profondeur=".intval($prof + 1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique",
386
+					"spip_rubriques AS zzz", "zzz.profondeur=".intval($prof)).")", '', '', '0,100')) {
387 387
 			$rows = array_column($rows, 'id');
388 388
 			sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
389 389
 		}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
393 393
 		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
394 394
 		// on arrete les frais
395
-		if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
395
+		if (sql_countsel("spip_rubriques", "profondeur=".intval($prof + 1))) {
396 396
 			$prof++;
397 397
 			$continuer = true;
398 398
 		}
@@ -400,10 +400,10 @@  discard block
 block discarded – undo
400 400
 
401 401
 	// loger si la table des rubriques semble foireuse
402 402
 	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
403
-	if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
404
-		spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
403
+	if (sql_countsel("spip_rubriques", "profondeur>".intval($prof + 1))) {
404
+		spip_log("Les rubriques de profondeur>".($prof + 1)." semblent suspectes (branches morte ou reference circulaire dans les parents)",
405 405
 			_LOG_CRITIQUE);
406
-		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
406
+		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>".intval($prof + 1));
407 407
 	}
408 408
 
409 409
 	// reparer les articles
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 		"A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
412 412
 
413 413
 	while ($row = sql_fetch($r)) {
414
-		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
414
+		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=".intval($row['id']));
415 415
 	}
416 416
 
417 417
 	// avertir les plugins qui peuvent faire leur mises a jour egalement
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	while ($row = sql_fetch($s)) {
438 438
 		$id_rubrique = $row['id_rubrique'];
439 439
 		$t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
440
-			"id_rubrique=" . intval($id_rubrique));
440
+			"id_rubrique=".intval($id_rubrique));
441 441
 	}
442 442
 
443 443
 	return $t;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	while ($row = sql_fetch($s)) {
474 474
 		$id_article = $row['id_article'];
475 475
 		sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
476
-			"id_article=" . intval($id_article));
476
+			"id_article=".intval($id_article));
477 477
 	}
478 478
 
479 479
 	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
@@ -545,11 +545,11 @@  discard block
 block discarded – undo
545 545
 				);
546 546
 				// generer un nom de fonction "anonyme" unique
547 547
 				do {
548
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
548
+					$functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.rand();
549 549
 				} while (function_exists($functionname));
550 550
 				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
551
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
552
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
551
+				$code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code;
552
+				$code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();';
553 553
 				$res = '';
554 554
 				eval($code);
555 555
 				$res = explode(',', $res);
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
 	while ($maxiter-- and $filles = sql_allfetsel(
664 664
 			'id_rubrique',
665 665
 			'spip_rubriques',
666
-			sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
666
+			sql_in('id_parent', $r)." AND ".sql_in('id_rubrique', $r, 'NOT')
667 667
 		)) {
668 668
 		$r = join(',', array_column($filles, 'id_rubrique'));
669
-		$branche .= ',' . $r;
669
+		$branche .= ','.$r;
670 670
 	}
671 671
 
672 672
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 
707 707
 	if (isset($b[$id])) {
708 708
 		// Notre branche commence par la rubrique de depart si $tout=true
709
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
709
+		return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id];
710 710
 	}
711 711
 
712 712
 	$hier = "";
@@ -718,10 +718,10 @@  discard block
 block discarded – undo
718 718
 	while ($maxiter-- and $parents = sql_allfetsel(
719 719
 			'id_parent',
720 720
 			'spip_rubriques',
721
-			sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
721
+			sql_in('id_rubrique', $ids_nouveaux_parents)." AND ".sql_in('id_parent', $hier, 'NOT')
722 722
 		)) {
723 723
 		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
724
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
724
+		$hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : '');
725 725
 	}
726 726
 
727 727
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 	include_spip('base/abstract_sql');
754 754
 	if ($check) {
755 755
 		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
756
-			"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
756
+			"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
757 757
 
758 758
 		$r = sql_select("DISTINCT A.id_rubrique AS id",
759 759
 			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 		pipeline('trig_calculer_prochain_postdate', '');
766 766
 	}
767 767
 
768
-	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
768
+	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date",
769 769
 		"1");
770 770
 
771 771
 	if ($t) {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 		// retablir les </multi> et autres balises fermantes html
816 816
 		$titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
817 817
 		$r = sql_getfetsel("id_rubrique", "spip_rubriques",
818
-			"titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
818
+			"titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent),
819 819
 			$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
820 820
 		if ($r !== null) {
821 821
 			$id_parent = $r;
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 			}
837 837
 
838 838
 			sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
839
-				"id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
839
+				"id_rubrique=".intval($id_rubrique), $desc = '', $serveur);
840 840
 
841 841
 			// pour la recursion
842 842
 			$id_parent = $id_rubrique;
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,8 +77,7 @@  discard block
 block discarded – undo
77 77
 				break; // stop on a trouvé le bon champ
78 78
 			}
79 79
 		}
80
-	}
81
-	else {
80
+	} else {
82 81
 		$statuts_publies = array('publie');
83 82
 	}
84 83
 	
@@ -105,10 +104,12 @@  discard block
 block discarded – undo
105 104
 		}
106 105
 	}
107 106
 
108
-	if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
107
+	if ($neuf) {
108
+	    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
109 109
 	{
110 110
 		ecrire_meta("date_calcul_rubriques", date("U"));
111 111
 	}
112
+	}
112 113
 
113 114
 	$langues = calculer_langues_utilisees();
114 115
 	ecrire_meta('langues_utilisees', $langues);
Please login to merge, or discard this patch.
Indentation   +523 added lines, -523 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -54,64 +54,64 @@  discard block
 block discarded – undo
54 54
  *     true si le statut change effectivement
55 55
  **/
56 56
 function calculer_rubriques_if($id_rubrique, $modifs, $infos = array(), $postdate = false) {
57
-	$neuf = false;
57
+    $neuf = false;
58 58
 	
59
-	// Compat avec l'ancienne signature
60
-	if (is_string($infos)) {
61
-		$infos = array('statut_ancien' => $infos);
62
-	}
63
-	if (!isset($infos['statut_ancien'])) {
64
-		$infos['statut_ancien'] = '';
65
-	}
59
+    // Compat avec l'ancienne signature
60
+    if (is_string($infos)) {
61
+        $infos = array('statut_ancien' => $infos);
62
+    }
63
+    if (!isset($infos['statut_ancien'])) {
64
+        $infos['statut_ancien'] = '';
65
+    }
66 66
 	
67
-	// On recherche quels statuts tester
68
-	if (
69
-		isset($infos['objet'])
70
-		and include_spip('inc/filtres')
71
-		and $declaration_statut = objet_info($infos['objet'], 'statut')
72
-		and is_array($declaration_statut)
73
-	) {
74
-		foreach ($declaration_statut as $champ_statut) {
75
-			if ($champ_statut['champ'] == 'statut') {
76
-				$statuts_publies = array_map('trim', explode(',', $champ_statut['publie']));
77
-				break; // stop on a trouvé le bon champ
78
-			}
79
-		}
80
-	}
81
-	else {
82
-		$statuts_publies = array('publie');
83
-	}
67
+    // On recherche quels statuts tester
68
+    if (
69
+        isset($infos['objet'])
70
+        and include_spip('inc/filtres')
71
+        and $declaration_statut = objet_info($infos['objet'], 'statut')
72
+        and is_array($declaration_statut)
73
+    ) {
74
+        foreach ($declaration_statut as $champ_statut) {
75
+            if ($champ_statut['champ'] == 'statut') {
76
+                $statuts_publies = array_map('trim', explode(',', $champ_statut['publie']));
77
+                break; // stop on a trouvé le bon champ
78
+            }
79
+        }
80
+    }
81
+    else {
82
+        $statuts_publies = array('publie');
83
+    }
84 84
 	
85
-	if (in_array($infos['statut_ancien'], $statuts_publies)) {
86
-		if (isset($modifs['statut'])
87
-			or isset($modifs['id_rubrique'])
88
-			or ($postdate and strtotime($postdate) > time())
89
-		) {
90
-			$neuf |= depublier_branche_rubrique_if($id_rubrique);
91
-		}
92
-		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
93
-		if ($postdate) {
94
-			calculer_prochain_postdate(true);
95
-			$neuf |= (strtotime($postdate) <= time()); // par securite
96
-		} elseif (isset($modifs['id_rubrique'])) {
97
-			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
98
-		}
99
-	} elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) {
100
-		if ($postdate) {
101
-			calculer_prochain_postdate(true);
102
-			$neuf |= (strtotime($postdate) <= time()); // par securite
103
-		} else {
104
-			$neuf |= publier_branche_rubrique($id_rubrique);
105
-		}
106
-	}
107
-
108
-	if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
109
-	{
110
-		ecrire_meta("date_calcul_rubriques", date("U"));
111
-	}
112
-
113
-	$langues = calculer_langues_utilisees();
114
-	ecrire_meta('langues_utilisees', $langues);
85
+    if (in_array($infos['statut_ancien'], $statuts_publies)) {
86
+        if (isset($modifs['statut'])
87
+            or isset($modifs['id_rubrique'])
88
+            or ($postdate and strtotime($postdate) > time())
89
+        ) {
90
+            $neuf |= depublier_branche_rubrique_if($id_rubrique);
91
+        }
92
+        // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
93
+        if ($postdate) {
94
+            calculer_prochain_postdate(true);
95
+            $neuf |= (strtotime($postdate) <= time()); // par securite
96
+        } elseif (isset($modifs['id_rubrique'])) {
97
+            $neuf |= publier_branche_rubrique($modifs['id_rubrique']);
98
+        }
99
+    } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) {
100
+        if ($postdate) {
101
+            calculer_prochain_postdate(true);
102
+            $neuf |= (strtotime($postdate) <= time()); // par securite
103
+        } else {
104
+            $neuf |= publier_branche_rubrique($id_rubrique);
105
+        }
106
+    }
107
+
108
+    if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
109
+    {
110
+        ecrire_meta("date_calcul_rubriques", date("U"));
111
+    }
112
+
113
+    $langues = calculer_langues_utilisees();
114
+    ecrire_meta('langues_utilisees', $langues);
115 115
 }
116 116
 
117 117
 
@@ -129,19 +129,19 @@  discard block
 block discarded – undo
129 129
  *     true si le statut change effectivement
130 130
  */
131 131
 function publier_branche_rubrique($id_rubrique) {
132
-	$id_pred = $id_rubrique;
133
-	while (true) {
134
-		sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
135
-			"id_rubrique=" . intval($id_rubrique));
136
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
137
-		if (!$id_parent) {
138
-			break;
139
-		}
140
-		$id_rubrique = $id_parent;
141
-	}
132
+    $id_pred = $id_rubrique;
133
+    while (true) {
134
+        sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
135
+            "id_rubrique=" . intval($id_rubrique));
136
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
137
+        if (!$id_parent) {
138
+            break;
139
+        }
140
+        $id_rubrique = $id_parent;
141
+    }
142 142
 
143 143
 #	spip_log(" publier_branche_rubrique($id_rubrique $id_pred");
144
-	return $id_pred != $id_rubrique;
144
+    return $id_pred != $id_rubrique;
145 145
 }
146 146
 
147 147
 /**
@@ -159,21 +159,21 @@  discard block
 block discarded – undo
159 159
  *     true si le statut change effectivement
160 160
  */
161 161
 function depublier_branche_rubrique_if($id_rubrique) {
162
-	$date = date('Y-m-d H:i:s'); // figer la date
162
+    $date = date('Y-m-d H:i:s'); // figer la date
163 163
 
164
-	#	spip_log("depublier_branche_rubrique($id_rubrique ?");
165
-	$id_pred = $id_rubrique;
166
-	while ($id_pred) {
164
+    #	spip_log("depublier_branche_rubrique($id_rubrique ?");
165
+    $id_pred = $id_rubrique;
166
+    while ($id_pred) {
167 167
 
168
-		if (!depublier_rubrique_if($id_pred, $date)) {
169
-			return $id_pred != $id_rubrique;
170
-		}
171
-		// passer au parent si on a depublie
172
-		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
173
-		$id_pred = $r['id_parent'];
174
-	}
168
+        if (!depublier_rubrique_if($id_pred, $date)) {
169
+            return $id_pred != $id_rubrique;
170
+        }
171
+        // passer au parent si on a depublie
172
+        $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
173
+        $id_pred = $r['id_parent'];
174
+    }
175 175
 
176
-	return $id_pred != $id_rubrique;
176
+    return $id_pred != $id_rubrique;
177 177
 }
178 178
 
179 179
 /**
@@ -190,57 +190,57 @@  discard block
 block discarded – undo
190 190
  *    true si la rubrique a été dépubliée
191 191
  */
192 192
 function depublier_rubrique_if($id_rubrique, $date = null) {
193
-	if (is_null($date)) {
194
-		$date = date('Y-m-d H:i:s');
195
-	}
196
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
197
-		" AND date <= " . sql_quote($date) : '';
198
-
199
-	if (!$id_rubrique = intval($id_rubrique)) {
200
-		return false;
201
-	}
202
-
203
-	// verifier qu'elle existe et est bien publiee
204
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
205
-	if (!$r or $r['statut'] !== 'publie') {
206
-		return false;
207
-	}
208
-
209
-	// On met le nombre de chaque type d'enfants dans un tableau
210
-	// Le type de l'objet est au pluriel
211
-	$compte = array(
212
-		'articles' => sql_countsel("spip_articles",
213
-			"id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
214
-		'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
215
-		'documents' => sql_countsel(
216
-			"spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
217
-			"L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
218
-	);
219
-
220
-	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
221
-	$compte = pipeline('objet_compte_enfants',
222
-		array(
223
-			'args' => array(
224
-				'objet' => 'rubrique',
225
-				'id_objet' => $id_rubrique,
226
-				'statut' => 'publie',
227
-				'date' => $date
228
-			),
229
-			'data' => $compte
230
-		)
231
-	);
232
-
233
-	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
234
-	foreach ($compte as $objet => $n) {
235
-		if ($n) {
236
-			return false;
237
-		}
238
-	}
239
-
240
-	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
193
+    if (is_null($date)) {
194
+        $date = date('Y-m-d H:i:s');
195
+    }
196
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
197
+        " AND date <= " . sql_quote($date) : '';
198
+
199
+    if (!$id_rubrique = intval($id_rubrique)) {
200
+        return false;
201
+    }
202
+
203
+    // verifier qu'elle existe et est bien publiee
204
+    $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
205
+    if (!$r or $r['statut'] !== 'publie') {
206
+        return false;
207
+    }
208
+
209
+    // On met le nombre de chaque type d'enfants dans un tableau
210
+    // Le type de l'objet est au pluriel
211
+    $compte = array(
212
+        'articles' => sql_countsel("spip_articles",
213
+            "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
214
+        'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
215
+        'documents' => sql_countsel(
216
+            "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
217
+            "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
218
+    );
219
+
220
+    // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
221
+    $compte = pipeline('objet_compte_enfants',
222
+        array(
223
+            'args' => array(
224
+                'objet' => 'rubrique',
225
+                'id_objet' => $id_rubrique,
226
+                'statut' => 'publie',
227
+                'date' => $date
228
+            ),
229
+            'data' => $compte
230
+        )
231
+    );
232
+
233
+    // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
234
+    foreach ($compte as $objet => $n) {
235
+        if ($n) {
236
+            return false;
237
+        }
238
+    }
239
+
240
+    sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
241 241
 
242 242
 #		spip_log("depublier_rubrique $id_pred");
243
-	return true;
243
+    return true;
244 244
 }
245 245
 
246 246
 
@@ -263,18 +263,18 @@  discard block
 block discarded – undo
263 263
  **/
264 264
 function calculer_rubriques() {
265 265
 
266
-	calculer_rubriques_publiees();
266
+    calculer_rubriques_publiees();
267 267
 
268
-	// Apres chaque (de)publication 
269
-	// recalculer les langues utilisees sur le site
270
-	$langues = calculer_langues_utilisees();
271
-	ecrire_meta('langues_utilisees', $langues);
268
+    // Apres chaque (de)publication 
269
+    // recalculer les langues utilisees sur le site
270
+    $langues = calculer_langues_utilisees();
271
+    ecrire_meta('langues_utilisees', $langues);
272 272
 
273
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
274
-	ecrire_meta("date_calcul_rubriques", date("U"));
273
+    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
274
+    ecrire_meta("date_calcul_rubriques", date("U"));
275 275
 
276
-	// on calcule la date du prochain article post-date
277
-	calculer_prochain_postdate();
276
+    // on calcule la date du prochain article post-date
277
+    calculer_prochain_postdate();
278 278
 }
279 279
 
280 280
 
@@ -291,51 +291,51 @@  discard block
 block discarded – undo
291 291
  **/
292 292
 function calculer_rubriques_publiees() {
293 293
 
294
-	// Mettre les compteurs a zero
295
-	sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa'));
296
-
297
-	//
298
-	// Publier et dater les rubriques qui ont un article publie
299
-	//
300
-
301
-	// Afficher les articles post-dates ?
302
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
303
-		"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
304
-
305
-	$r = sql_select(
306
-		"R.id_rubrique AS id, max(A.date) AS date_h",
307
-		"spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique",
308
-		"A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
309
-	while ($row = sql_fetch($r)) {
310
-		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
311
-			"id_rubrique=" . intval($row['id']));
312
-	}
313
-
314
-	// point d'entree pour permettre a des plugins de gerer le statut
315
-	// autrement (par ex: toute rubrique est publiee des sa creation)
316
-	// Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
317
-	// c'est statut_tmp/date_tmp qu'il doit modifier
318
-	// [C'est un trigger... a renommer en trig_calculer_rubriques ?]
319
-	pipeline('calculer_rubriques', null);
320
-
321
-
322
-	// Les rubriques qui ont une rubrique fille plus recente
323
-	// on tourne tant que les donnees remontent vers la racine.
324
-	do {
325
-		$continuer = false;
326
-		$r = sql_select(
327
-			"R.id_rubrique AS id, max(SR.date_tmp) AS date_h",
328
-			"spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent",
329
-			"(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
330
-		while ($row = sql_fetch($r)) {
331
-			sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
332
-				"id_rubrique=" . intval($row['id']));
333
-			$continuer = true;
334
-		}
335
-	} while ($continuer);
336
-
337
-	// Enregistrement des modifs
338
-	sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp'));
294
+    // Mettre les compteurs a zero
295
+    sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa'));
296
+
297
+    //
298
+    // Publier et dater les rubriques qui ont un article publie
299
+    //
300
+
301
+    // Afficher les articles post-dates ?
302
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
303
+        "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
304
+
305
+    $r = sql_select(
306
+        "R.id_rubrique AS id, max(A.date) AS date_h",
307
+        "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique",
308
+        "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
309
+    while ($row = sql_fetch($r)) {
310
+        sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
311
+            "id_rubrique=" . intval($row['id']));
312
+    }
313
+
314
+    // point d'entree pour permettre a des plugins de gerer le statut
315
+    // autrement (par ex: toute rubrique est publiee des sa creation)
316
+    // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
317
+    // c'est statut_tmp/date_tmp qu'il doit modifier
318
+    // [C'est un trigger... a renommer en trig_calculer_rubriques ?]
319
+    pipeline('calculer_rubriques', null);
320
+
321
+
322
+    // Les rubriques qui ont une rubrique fille plus recente
323
+    // on tourne tant que les donnees remontent vers la racine.
324
+    do {
325
+        $continuer = false;
326
+        $r = sql_select(
327
+            "R.id_rubrique AS id, max(SR.date_tmp) AS date_h",
328
+            "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent",
329
+            "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
330
+        while ($row = sql_fetch($r)) {
331
+            sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
332
+                "id_rubrique=" . intval($row['id']));
333
+            $continuer = true;
334
+        }
335
+    } while ($continuer);
336
+
337
+    // Enregistrement des modifs
338
+    sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp'));
339 339
 }
340 340
 
341 341
 /**
@@ -350,99 +350,99 @@  discard block
 block discarded – undo
350 350
  * @return void
351 351
  **/
352 352
 function propager_les_secteurs() {
353
-	// Profondeur 0
354
-	// Toutes les rubriques racines sont de profondeur 0
355
-	// et fixer les id_secteur des rubriques racines
356
-	sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0");
357
-	// Toute rubrique non racine est de profondeur >0
358
-	sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0");
359
-
360
-	// securite : pas plus d'iteration que de rubriques dans la base
361
-	$maxiter = sql_countsel("spip_rubriques");
362
-
363
-	// reparer les rubriques qui n'ont pas l'id_secteur de leur parent
364
-	// on fait profondeur par profondeur
365
-
366
-	$prof = 0;
367
-	do {
368
-		$continuer = false;
369
-
370
-		// Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
371
-		// on fixe le profondeur $prof+1
372
-
373
-		// Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
374
-		// on teste A.profondeur > $prof+1 car :
375
-		// - toutes les rubriques de profondeur 0 à $prof sont bonnes
376
-		// - si A.profondeur = $prof+1 c'est bon
377
-		// - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
378
-		$maxiter2 = $maxiter;
379
-		while ($maxiter2--
380
-			and $rows = sql_allfetsel(
381
-				"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
382
-				"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
383
-				"R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
384
-				"", "R.id_secteur", "0,100")) {
385
-
386
-			$id_secteur = null;
387
-			$ids = array();
388
-			while ($row = array_shift($rows)) {
389
-				if ($row['id_secteur'] !== $id_secteur) {
390
-					if (count($ids)) {
391
-						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
392
-							sql_in('id_rubrique', $ids));
393
-					}
394
-					$id_secteur = $row['id_secteur'];
395
-					$ids = array();
396
-				}
397
-				$ids[] = $row['id'];
398
-			}
399
-			if (count($ids)) {
400
-				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
401
-					sql_in('id_rubrique', $ids));
402
-			}
403
-		}
404
-
405
-
406
-		// Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
407
-		$maxiter2 = $maxiter;
408
-		while ($maxiter2--
409
-			and $rows = sql_allfetsel(
410
-				"id_rubrique as id",
411
-				"spip_rubriques",
412
-				"profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
413
-					"spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
414
-			$rows = array_column($rows, 'id');
415
-			sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
416
-		}
417
-
418
-		// ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
419
-		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
420
-		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
421
-		// on arrete les frais
422
-		if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
423
-			$prof++;
424
-			$continuer = true;
425
-		}
426
-	} while ($continuer and $maxiter--);
427
-
428
-	// loger si la table des rubriques semble foireuse
429
-	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
430
-	if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
431
-		spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
432
-			_LOG_CRITIQUE);
433
-		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
434
-	}
435
-
436
-	// reparer les articles
437
-	$r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R",
438
-		"A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
439
-
440
-	while ($row = sql_fetch($r)) {
441
-		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
442
-	}
443
-
444
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
445
-	pipeline('trig_propager_les_secteurs', '');
353
+    // Profondeur 0
354
+    // Toutes les rubriques racines sont de profondeur 0
355
+    // et fixer les id_secteur des rubriques racines
356
+    sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0");
357
+    // Toute rubrique non racine est de profondeur >0
358
+    sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0");
359
+
360
+    // securite : pas plus d'iteration que de rubriques dans la base
361
+    $maxiter = sql_countsel("spip_rubriques");
362
+
363
+    // reparer les rubriques qui n'ont pas l'id_secteur de leur parent
364
+    // on fait profondeur par profondeur
365
+
366
+    $prof = 0;
367
+    do {
368
+        $continuer = false;
369
+
370
+        // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
371
+        // on fixe le profondeur $prof+1
372
+
373
+        // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
374
+        // on teste A.profondeur > $prof+1 car :
375
+        // - toutes les rubriques de profondeur 0 à $prof sont bonnes
376
+        // - si A.profondeur = $prof+1 c'est bon
377
+        // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
378
+        $maxiter2 = $maxiter;
379
+        while ($maxiter2--
380
+            and $rows = sql_allfetsel(
381
+                "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
382
+                "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
383
+                "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
384
+                "", "R.id_secteur", "0,100")) {
385
+
386
+            $id_secteur = null;
387
+            $ids = array();
388
+            while ($row = array_shift($rows)) {
389
+                if ($row['id_secteur'] !== $id_secteur) {
390
+                    if (count($ids)) {
391
+                        sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
392
+                            sql_in('id_rubrique', $ids));
393
+                    }
394
+                    $id_secteur = $row['id_secteur'];
395
+                    $ids = array();
396
+                }
397
+                $ids[] = $row['id'];
398
+            }
399
+            if (count($ids)) {
400
+                sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
401
+                    sql_in('id_rubrique', $ids));
402
+            }
403
+        }
404
+
405
+
406
+        // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
407
+        $maxiter2 = $maxiter;
408
+        while ($maxiter2--
409
+            and $rows = sql_allfetsel(
410
+                "id_rubrique as id",
411
+                "spip_rubriques",
412
+                "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
413
+                    "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
414
+            $rows = array_column($rows, 'id');
415
+            sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
416
+        }
417
+
418
+        // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
419
+        // si pas de rubrique a profondeur $prof+1 pas la peine de continuer
420
+        // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
421
+        // on arrete les frais
422
+        if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
423
+            $prof++;
424
+            $continuer = true;
425
+        }
426
+    } while ($continuer and $maxiter--);
427
+
428
+    // loger si la table des rubriques semble foireuse
429
+    // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
430
+    if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
431
+        spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
432
+            _LOG_CRITIQUE);
433
+        sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
434
+    }
435
+
436
+    // reparer les articles
437
+    $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R",
438
+        "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
439
+
440
+    while ($row = sql_fetch($r)) {
441
+        sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
442
+    }
443
+
444
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
445
+    pipeline('trig_propager_les_secteurs', '');
446 446
 }
447 447
 
448 448
 
@@ -457,17 +457,17 @@  discard block
 block discarded – undo
457 457
  *     true si un changement a eu lieu
458 458
  **/
459 459
 function calculer_langues_rubriques_etape() {
460
-	$s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R",
461
-		"A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
460
+    $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R",
461
+        "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
462 462
 
463
-	$t = false;
464
-	while ($row = sql_fetch($s)) {
465
-		$id_rubrique = $row['id_rubrique'];
466
-		$t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
467
-			"id_rubrique=" . intval($id_rubrique));
468
-	}
463
+    $t = false;
464
+    while ($row = sql_fetch($s)) {
465
+        $id_rubrique = $row['id_rubrique'];
466
+        $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
467
+            "id_rubrique=" . intval($id_rubrique));
468
+    }
469 469
 
470
-	return $t;
470
+    return $t;
471 471
 }
472 472
 
473 473
 /**
@@ -487,30 +487,30 @@  discard block
 block discarded – undo
487 487
  **/
488 488
 function calculer_langues_rubriques() {
489 489
 
490
-	// rubriques (recursivite)
491
-	sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'),
492
-		"id_parent=0 AND langue_choisie != 'oui'");
493
-	while (calculer_langues_rubriques_etape()) {
494
-		;
495
-	}
496
-
497
-	// articles
498
-	$s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R",
499
-		"A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
500
-	while ($row = sql_fetch($s)) {
501
-		$id_article = $row['id_article'];
502
-		sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
503
-			"id_article=" . intval($id_article));
504
-	}
505
-
506
-	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
507
-
508
-		$langues = calculer_langues_utilisees();
509
-		ecrire_meta('langues_utilisees', $langues);
510
-	}
511
-
512
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
513
-	pipeline('trig_calculer_langues_rubriques', '');
490
+    // rubriques (recursivite)
491
+    sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'),
492
+        "id_parent=0 AND langue_choisie != 'oui'");
493
+    while (calculer_langues_rubriques_etape()) {
494
+        ;
495
+    }
496
+
497
+    // articles
498
+    $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R",
499
+        "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
500
+    while ($row = sql_fetch($s)) {
501
+        $id_article = $row['id_article'];
502
+        sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
503
+            "id_article=" . intval($id_article));
504
+    }
505
+
506
+    if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
507
+
508
+        $langues = calculer_langues_utilisees();
509
+        ecrire_meta('langues_utilisees', $langues);
510
+    }
511
+
512
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
513
+    pipeline('trig_calculer_langues_rubriques', '');
514 514
 }
515 515
 
516 516
 
@@ -527,78 +527,78 @@  discard block
 block discarded – undo
527 527
  *    Liste des langues utilisées séparées par des virgules
528 528
  **/
529 529
 function calculer_langues_utilisees($serveur = '') {
530
-	include_spip('public/interfaces');
531
-	include_spip('public/compiler');
532
-	include_spip('public/composer');
533
-	include_spip('public/phraser_html');
534
-	$langues = array();
535
-
536
-	$langues[$GLOBALS['meta']['langue_site']] = 1;
537
-
538
-	include_spip('base/objets');
539
-	$tables = lister_tables_objets_sql();
540
-	$trouver_table = charger_fonction('trouver_table', 'base');
541
-
542
-	foreach (array_keys($tables) as $t) {
543
-		$desc = $trouver_table($t, $serveur);
544
-		// c'est une table avec des langues
545
-		if ($desc['exist']
546
-			and isset($desc['field']['lang'])
547
-			and isset($desc['field']['langue_choisie'])
548
-		) {
549
-
550
-			$boucle = new Boucle();
551
-			$boucle->show = $desc;
552
-			$boucle->nom = 'calculer_langues_utilisees';
553
-			$boucle->id_boucle = $desc['table_objet'];
554
-			$boucle->id_table = $desc['table_objet'];
555
-			$boucle->sql_serveur = $serveur;
556
-			$boucle->select[] = "DISTINCT lang";
557
-			$boucle->from[$desc['table_objet']] = $t;
558
-			$boucle->separateur[] = ',';
559
-			$boucle->return = '$Pile[$SP][\'lang\']';
560
-			$boucle->iterateur = 'sql';
561
-
562
-			$boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php
563
-			$boucle->descr['sourcefile'] = 'internal';
564
-			$boucle->descr['gram'] = 'html';
565
-
566
-			$boucle = pipeline('pre_boucle', $boucle);
567
-
568
-			if (isset($desc['statut'])
569
-				and $desc['statut']
570
-			) {
571
-				$boucles = array(
572
-					'calculer_langues_utilisees' => $boucle,
573
-				);
574
-				// generer un nom de fonction "anonyme" unique
575
-				do {
576
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
577
-				} while (function_exists($functionname));
578
-				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
579
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
580
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
581
-				$res = '';
582
-				eval($code);
583
-				$res = explode(',', $res);
584
-				foreach ($res as $lang) {
585
-					$langues[$lang] = 1;
586
-				}
587
-			} else {
588
-				$res = sql_select(implode(',', $boucle->select), $boucle->from);
589
-				while ($row = sql_fetch($res)) {
590
-					$langues[$row['lang']] = 1;
591
-				}
592
-			}
593
-		}
594
-	}
595
-
596
-	$langues = array_filter(array_keys($langues));
597
-	sort($langues);
598
-	$langues = join(',', $langues);
599
-	spip_log("langues utilisees: $langues");
600
-
601
-	return $langues;
530
+    include_spip('public/interfaces');
531
+    include_spip('public/compiler');
532
+    include_spip('public/composer');
533
+    include_spip('public/phraser_html');
534
+    $langues = array();
535
+
536
+    $langues[$GLOBALS['meta']['langue_site']] = 1;
537
+
538
+    include_spip('base/objets');
539
+    $tables = lister_tables_objets_sql();
540
+    $trouver_table = charger_fonction('trouver_table', 'base');
541
+
542
+    foreach (array_keys($tables) as $t) {
543
+        $desc = $trouver_table($t, $serveur);
544
+        // c'est une table avec des langues
545
+        if ($desc['exist']
546
+            and isset($desc['field']['lang'])
547
+            and isset($desc['field']['langue_choisie'])
548
+        ) {
549
+
550
+            $boucle = new Boucle();
551
+            $boucle->show = $desc;
552
+            $boucle->nom = 'calculer_langues_utilisees';
553
+            $boucle->id_boucle = $desc['table_objet'];
554
+            $boucle->id_table = $desc['table_objet'];
555
+            $boucle->sql_serveur = $serveur;
556
+            $boucle->select[] = "DISTINCT lang";
557
+            $boucle->from[$desc['table_objet']] = $t;
558
+            $boucle->separateur[] = ',';
559
+            $boucle->return = '$Pile[$SP][\'lang\']';
560
+            $boucle->iterateur = 'sql';
561
+
562
+            $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php
563
+            $boucle->descr['sourcefile'] = 'internal';
564
+            $boucle->descr['gram'] = 'html';
565
+
566
+            $boucle = pipeline('pre_boucle', $boucle);
567
+
568
+            if (isset($desc['statut'])
569
+                and $desc['statut']
570
+            ) {
571
+                $boucles = array(
572
+                    'calculer_langues_utilisees' => $boucle,
573
+                );
574
+                // generer un nom de fonction "anonyme" unique
575
+                do {
576
+                    $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
577
+                } while (function_exists($functionname));
578
+                $code = calculer_boucle('calculer_langues_utilisees', $boucles);
579
+                $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
580
+                $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
581
+                $res = '';
582
+                eval($code);
583
+                $res = explode(',', $res);
584
+                foreach ($res as $lang) {
585
+                    $langues[$lang] = 1;
586
+                }
587
+            } else {
588
+                $res = sql_select(implode(',', $boucle->select), $boucle->from);
589
+                while ($row = sql_fetch($res)) {
590
+                    $langues[$row['lang']] = 1;
591
+                }
592
+            }
593
+        }
594
+    }
595
+
596
+    $langues = array_filter(array_keys($langues));
597
+    sort($langues);
598
+    $langues = join(',', $langues);
599
+    spip_log("langues utilisees: $langues");
600
+
601
+    return $langues;
602 602
 }
603 603
 
604 604
 /**
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
  *     incluant les rubriques noeuds et toutes leurs descendances
629 629
  */
630 630
 function calcul_branche_in($id) {
631
-	$calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
631
+    $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
632 632
 
633
-	return $calcul_branche_in($id);
633
+    return $calcul_branche_in($id);
634 634
 }
635 635
 
636 636
 /**
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
  *     incluant les rubriques transmises et toutes leurs parentées
649 649
  */
650 650
 function calcul_hierarchie_in($id, $tout = true) {
651
-	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
651
+    $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
652 652
 
653
-	return $calcul_hierarchie_in($id, $tout);
653
+    return $calcul_hierarchie_in($id, $tout);
654 654
 }
655 655
 
656 656
 
@@ -671,38 +671,38 @@  discard block
 block discarded – undo
671 671
  *     incluant les rubriques noeuds et toutes leurs descendances
672 672
  */
673 673
 function inc_calcul_branche_in_dist($id) {
674
-	static $b = array();
675
-
676
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
677
-	if (!is_array($id)) {
678
-		$id = explode(',', $id);
679
-	}
680
-	$id = join(',', array_map('intval', $id));
681
-	if (isset($b[$id])) {
682
-		return $b[$id];
683
-	}
684
-
685
-	// Notre branche commence par la rubrique de depart
686
-	$branche = $r = $id;
687
-
688
-	// On ajoute une generation (les filles de la generation precedente)
689
-	// jusqu'a epuisement, en se protegeant des references circulaires
690
-	$maxiter = 10000;
691
-	while ($maxiter-- and $filles = sql_allfetsel(
692
-			'id_rubrique',
693
-			'spip_rubriques',
694
-			sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
695
-		)) {
696
-		$r = join(',', array_column($filles, 'id_rubrique'));
697
-		$branche .= ',' . $r;
698
-	}
699
-
700
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
701
-	if (strlen($branche) < 10000) {
702
-		$b[$id] = $branche;
703
-	}
704
-
705
-	return $branche;
674
+    static $b = array();
675
+
676
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
677
+    if (!is_array($id)) {
678
+        $id = explode(',', $id);
679
+    }
680
+    $id = join(',', array_map('intval', $id));
681
+    if (isset($b[$id])) {
682
+        return $b[$id];
683
+    }
684
+
685
+    // Notre branche commence par la rubrique de depart
686
+    $branche = $r = $id;
687
+
688
+    // On ajoute une generation (les filles de la generation precedente)
689
+    // jusqu'a epuisement, en se protegeant des references circulaires
690
+    $maxiter = 10000;
691
+    while ($maxiter-- and $filles = sql_allfetsel(
692
+            'id_rubrique',
693
+            'spip_rubriques',
694
+            sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
695
+        )) {
696
+        $r = join(',', array_column($filles, 'id_rubrique'));
697
+        $branche .= ',' . $r;
698
+    }
699
+
700
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
701
+    if (strlen($branche) < 10000) {
702
+        $b[$id] = $branche;
703
+    }
704
+
705
+    return $branche;
706 706
 }
707 707
 
708 708
 
@@ -724,43 +724,43 @@  discard block
 block discarded – undo
724 724
  *     incluant les rubriques transmises et toutes leurs parentées
725 725
  */
726 726
 function inc_calcul_hierarchie_in_dist($id, $tout = true) {
727
-	static $b = array();
728
-
729
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
730
-	if (!is_array($id)) {
731
-		$id = explode(',', $id);
732
-	}
733
-	$id = join(',', array_map('intval', $id));
734
-
735
-	if (isset($b[$id])) {
736
-		// Notre branche commence par la rubrique de depart si $tout=true
737
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
738
-	}
739
-
740
-	$hier = "";
741
-
742
-	// On ajoute une generation (les filles de la generation precedente)
743
-	// jusqu'a epuisement, en se protegeant des references circulaires
744
-	$ids_nouveaux_parents = $id;
745
-	$maxiter = 10000;
746
-	while ($maxiter-- and $parents = sql_allfetsel(
747
-			'id_parent',
748
-			'spip_rubriques',
749
-			sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
750
-		)) {
751
-		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
752
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
753
-	}
754
-
755
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
756
-	if (strlen($hier) < 10000) {
757
-		$b[$id] = $hier;
758
-	}
759
-
760
-	// Notre branche commence par la rubrique de depart si $tout=true
761
-	$hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
762
-
763
-	return $hier;
727
+    static $b = array();
728
+
729
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
730
+    if (!is_array($id)) {
731
+        $id = explode(',', $id);
732
+    }
733
+    $id = join(',', array_map('intval', $id));
734
+
735
+    if (isset($b[$id])) {
736
+        // Notre branche commence par la rubrique de depart si $tout=true
737
+        return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
738
+    }
739
+
740
+    $hier = "";
741
+
742
+    // On ajoute une generation (les filles de la generation precedente)
743
+    // jusqu'a epuisement, en se protegeant des references circulaires
744
+    $ids_nouveaux_parents = $id;
745
+    $maxiter = 10000;
746
+    while ($maxiter-- and $parents = sql_allfetsel(
747
+            'id_parent',
748
+            'spip_rubriques',
749
+            sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
750
+        )) {
751
+        $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
752
+        $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
753
+    }
754
+
755
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
756
+    if (strlen($hier) < 10000) {
757
+        $b[$id] = $hier;
758
+    }
759
+
760
+    // Notre branche commence par la rubrique de depart si $tout=true
761
+    $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
762
+
763
+    return $hier;
764 764
 }
765 765
 
766 766
 
@@ -778,38 +778,38 @@  discard block
 block discarded – undo
778 778
  * @return void
779 779
  **/
780 780
 function calculer_prochain_postdate($check = false) {
781
-	include_spip('base/abstract_sql');
782
-	if ($check) {
783
-		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
784
-			"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
785
-
786
-		$r = sql_select("DISTINCT A.id_rubrique AS id",
787
-			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
788
-			"R.statut != 'publie' AND A.statut='publie'$postdates");
789
-		while ($row = sql_fetch($r)) {
790
-			publier_branche_rubrique($row['id']);
791
-		}
792
-
793
-		pipeline('trig_calculer_prochain_postdate', '');
794
-	}
795
-
796
-	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
797
-		"1");
798
-
799
-	if ($t) {
800
-		$t = $t['date'];
801
-		if (!isset($GLOBALS['meta']['date_prochain_postdate'])
802
-			or $t <> $GLOBALS['meta']['date_prochain_postdate']
803
-		) {
804
-			ecrire_meta('date_prochain_postdate', strtotime($t));
805
-			ecrire_meta('derniere_modif', time());
806
-		}
807
-	} else {
808
-		effacer_meta('date_prochain_postdate');
809
-		ecrire_meta('derniere_modif', time());
810
-	}
811
-
812
-	spip_log("prochain postdate: $t");
781
+    include_spip('base/abstract_sql');
782
+    if ($check) {
783
+        $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
784
+            "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
785
+
786
+        $r = sql_select("DISTINCT A.id_rubrique AS id",
787
+            "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
788
+            "R.statut != 'publie' AND A.statut='publie'$postdates");
789
+        while ($row = sql_fetch($r)) {
790
+            publier_branche_rubrique($row['id']);
791
+        }
792
+
793
+        pipeline('trig_calculer_prochain_postdate', '');
794
+    }
795
+
796
+    $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
797
+        "1");
798
+
799
+    if ($t) {
800
+        $t = $t['date'];
801
+        if (!isset($GLOBALS['meta']['date_prochain_postdate'])
802
+            or $t <> $GLOBALS['meta']['date_prochain_postdate']
803
+        ) {
804
+            ecrire_meta('date_prochain_postdate', strtotime($t));
805
+            ecrire_meta('derniere_modif', time());
806
+        }
807
+    } else {
808
+        effacer_meta('date_prochain_postdate');
809
+        ecrire_meta('derniere_modif', time());
810
+    }
811
+
812
+    spip_log("prochain postdate: $t");
813 813
 }
814 814
 
815 815
 /**
@@ -834,42 +834,42 @@  discard block
 block discarded – undo
834 834
  */
835 835
 function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') {
836 836
 
837
-	// eclater l'arborescence demandee
838
-	// echapper les </multi> et autres balises fermantes html
839
-	$titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre);
840
-	$arbo = explode('/', preg_replace(',^/,', '', $titre));
841
-	include_spip('base/abstract_sql');
842
-	foreach ($arbo as $titre) {
843
-		// retablir les </multi> et autres balises fermantes html
844
-		$titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
845
-		$r = sql_getfetsel("id_rubrique", "spip_rubriques",
846
-			"titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
847
-			$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
848
-		if ($r !== null) {
849
-			$id_parent = $r;
850
-		} else {
851
-			$id_rubrique = sql_insertq('spip_rubriques', array(
852
-					'titre' => $titre,
853
-					'id_parent' => $id_parent,
854
-					'statut' => 'prepa'
855
-				), $desc = array(), $serveur);
856
-			if ($id_parent > 0) {
857
-				$data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
858
-					$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
859
-				$id_secteur = $data['id_secteur'];
860
-				$lang = $data['lang'];
861
-			} else {
862
-				$id_secteur = $id_rubrique;
863
-				$lang = $GLOBALS['meta']['langue_site'];
864
-			}
865
-
866
-			sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
867
-				"id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
868
-
869
-			// pour la recursion
870
-			$id_parent = $id_rubrique;
871
-		}
872
-	}
873
-
874
-	return intval($id_parent);
837
+    // eclater l'arborescence demandee
838
+    // echapper les </multi> et autres balises fermantes html
839
+    $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre);
840
+    $arbo = explode('/', preg_replace(',^/,', '', $titre));
841
+    include_spip('base/abstract_sql');
842
+    foreach ($arbo as $titre) {
843
+        // retablir les </multi> et autres balises fermantes html
844
+        $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
845
+        $r = sql_getfetsel("id_rubrique", "spip_rubriques",
846
+            "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
847
+            $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
848
+        if ($r !== null) {
849
+            $id_parent = $r;
850
+        } else {
851
+            $id_rubrique = sql_insertq('spip_rubriques', array(
852
+                    'titre' => $titre,
853
+                    'id_parent' => $id_parent,
854
+                    'statut' => 'prepa'
855
+                ), $desc = array(), $serveur);
856
+            if ($id_parent > 0) {
857
+                $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
858
+                    $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
859
+                $id_secteur = $data['id_secteur'];
860
+                $lang = $data['lang'];
861
+            } else {
862
+                $id_secteur = $id_rubrique;
863
+                $lang = $GLOBALS['meta']['langue_site'];
864
+            }
865
+
866
+            sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
867
+                "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
868
+
869
+            // pour la recursion
870
+            $id_parent = $id_rubrique;
871
+        }
872
+    }
873
+
874
+    return intval($id_parent);
875 875
 }
Please login to merge, or discard this patch.
ecrire/exec/403.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -27,40 +27,40 @@  discard block
 block discarded – undo
27 27
  */
28 28
 function exec_403_dist($message = '') {
29 29
 
30
-	$exec = _request('exec');
30
+    $exec = _request('exec');
31 31
 
32
-	$titre = "exec_$exec";
33
-	$navigation = '';
34
-	$extra = '';
32
+    $titre = "exec_$exec";
33
+    $navigation = '';
34
+    $extra = '';
35 35
 
36
-	if (!$message) {
37
-		$message = _T('avis_acces_interdit_prive', array('exec' => _request('exec')));
38
-	}
36
+    if (!$message) {
37
+        $message = _T('avis_acces_interdit_prive', array('exec' => _request('exec')));
38
+    }
39 39
 
40
-	$contenu = "<h1 class='grostitre'>" . _T('info_acces_interdit') . '</h1>' . $message;
40
+    $contenu = "<h1 class='grostitre'>" . _T('info_acces_interdit') . '</h1>' . $message;
41 41
 
42
-	if (_request('var_zajax')) {
43
-		include_spip('inc/actions');
44
-		ajax_retour($contenu);
45
-	} else {
46
-		include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini
42
+    if (_request('var_zajax')) {
43
+        include_spip('inc/actions');
44
+        ajax_retour($contenu);
45
+    } else {
46
+        include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini
47 47
 
48
-		$commencer_page = charger_fonction('commencer_page', 'inc');
49
-		echo $commencer_page($titre);
48
+        $commencer_page = charger_fonction('commencer_page', 'inc');
49
+        echo $commencer_page($titre);
50 50
 
51
-		echo debut_gauche("403_$exec", true);
52
-		echo recuperer_fond('prive/squelettes/navigation/dist', array());
53
-		echo pipeline('affiche_gauche', array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => ''));
51
+        echo debut_gauche("403_$exec", true);
52
+        echo recuperer_fond('prive/squelettes/navigation/dist', array());
53
+        echo pipeline('affiche_gauche', array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => ''));
54 54
 
55
-		echo creer_colonne_droite('403', true);
56
-		echo pipeline('affiche_droite', array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => ''));
55
+        echo creer_colonne_droite('403', true);
56
+        echo pipeline('affiche_droite', array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => ''));
57 57
 
58
-		echo debut_droite('403', true);
59
-		echo pipeline(
60
-			'affiche_milieu',
61
-			array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => $contenu)
62
-		);
58
+        echo debut_droite('403', true);
59
+        echo pipeline(
60
+            'affiche_milieu',
61
+            array('args' => array('exec' => '403', 'exec_erreur' => $exec), 'data' => $contenu)
62
+        );
63 63
 
64
-		echo fin_gauche(), fin_page();
65
-	}
64
+        echo fin_gauche(), fin_page();
65
+    }
66 66
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 		$message = _T('avis_acces_interdit_prive', array('exec' => _request('exec')));
38 38
 	}
39 39
 
40
-	$contenu = "<h1 class='grostitre'>" . _T('info_acces_interdit') . '</h1>' . $message;
40
+	$contenu = "<h1 class='grostitre'>"._T('info_acces_interdit').'</h1>'.$message;
41 41
 
42 42
 	if (_request('var_zajax')) {
43 43
 		include_spip('inc/actions');
Please login to merge, or discard this patch.