Completed
Pull Request — master (#40)
by
unknown
04:13
created
ecrire/exec/rechercher.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
  *
53 53
  * @param int $id
54 54
  * @param string $type
55
- * @param string|int|array $exclus
55
+ * @param integer $exclus
56 56
  * @param string|bool $rac
57 57
  * @param string $do
58 58
  * @return string
Please login to merge, or discard this patch.
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 include_spip('inc/actions');
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
  * @uses ajax_retour()
32 32
  **/
33 33
 function exec_rechercher_dist() {
34
-	$id = intval(_request('id'));
35
-	$exclus = intval(_request('exclus'));
36
-	$rac = spip_htmlentities(_request('rac'));
37
-	$type = _request('type');
38
-	$do = _request('do');
39
-	if (preg_match('/^\w*$/', $do)) {
40
-		$r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
41
-	} else {
42
-		$r = '';
43
-	}
44
-	ajax_retour($r);
34
+    $id = intval(_request('id'));
35
+    $exclus = intval(_request('exclus'));
36
+    $rac = spip_htmlentities(_request('rac'));
37
+    $type = _request('type');
38
+    $do = _request('do');
39
+    if (preg_match('/^\w*$/', $do)) {
40
+        $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
41
+    } else {
42
+        $r = '';
43
+    }
44
+    ajax_retour($r);
45 45
 }
46 46
 
47 47
 /**
@@ -58,59 +58,59 @@  discard block
 block discarded – undo
58 58
  * @return string
59 59
  **/
60 60
 function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
61
-	if (!$do) {
62
-		$do = 'aff';
63
-	}
64
-
65
-	$points = $rub = array();
66
-
67
-	$where = preg_split(",\s+,", $type);
68
-	if ($where) {
69
-		foreach ($where as $k => $v) {
70
-			$where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
71
-		}
72
-		$where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
-		$where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
-		$where_id = ("(id_rubrique = " . intval($type) . ")");
75
-
76
-		if ($exclus) {
77
-			include_spip('inc/rubriques');
78
-			$where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79
-		} else {
80
-			$where_exclus = '';
81
-		}
82
-
83
-		foreach (array(
84
-			3 => $where_titre,
85
-			2 => $where_desc,
86
-			1 => $where_id,
87
-		) as $point => $recherche) {
88
-			$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
89
-			while ($row = sql_fetch($res)) {
90
-				$id_rubrique = $row["id_rubrique"];
91
-				if (!isset($rub[$id_rubrique])) {
92
-					$rub[$id_rubrique] = array();
93
-				}
94
-				$rub[$id_rubrique]["titre"] = typo($row["titre"]);
95
-				$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
96
-				if (!isset($points[$id_rubrique])) {
97
-					$points[$id_rubrique] = 0;
98
-				}
99
-				$points[$id_rubrique] = $points[$id_rubrique] + $point;
100
-			}
101
-		}
102
-	}
103
-
104
-	if ($points) {
105
-		arsort($points);
106
-		$style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
107
-		foreach ($rub as $k => $v) {
108
-			$rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109
-				. " class='petite-rubrique'";
110
-		}
111
-	}
112
-
113
-	return (proposer_item($points, $rub, $rac, $type, $do));
61
+    if (!$do) {
62
+        $do = 'aff';
63
+    }
64
+
65
+    $points = $rub = array();
66
+
67
+    $where = preg_split(",\s+,", $type);
68
+    if ($where) {
69
+        foreach ($where as $k => $v) {
70
+            $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
71
+        }
72
+        $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
+        $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
+        $where_id = ("(id_rubrique = " . intval($type) . ")");
75
+
76
+        if ($exclus) {
77
+            include_spip('inc/rubriques');
78
+            $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79
+        } else {
80
+            $where_exclus = '';
81
+        }
82
+
83
+        foreach (array(
84
+            3 => $where_titre,
85
+            2 => $where_desc,
86
+            1 => $where_id,
87
+        ) as $point => $recherche) {
88
+            $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
89
+            while ($row = sql_fetch($res)) {
90
+                $id_rubrique = $row["id_rubrique"];
91
+                if (!isset($rub[$id_rubrique])) {
92
+                    $rub[$id_rubrique] = array();
93
+                }
94
+                $rub[$id_rubrique]["titre"] = typo($row["titre"]);
95
+                $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
96
+                if (!isset($points[$id_rubrique])) {
97
+                    $points[$id_rubrique] = 0;
98
+                }
99
+                $points[$id_rubrique] = $points[$id_rubrique] + $point;
100
+            }
101
+        }
102
+    }
103
+
104
+    if ($points) {
105
+        arsort($points);
106
+        $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
107
+        foreach ($rub as $k => $v) {
108
+            $rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109
+                . " class='petite-rubrique'";
110
+        }
111
+    }
112
+
113
+    return (proposer_item($points, $rub, $rac, $type, $do));
114 114
 }
115 115
 
116 116
 
@@ -133,35 +133,35 @@  discard block
 block discarded – undo
133 133
  **/
134 134
 function proposer_item($ids, $titles, $rac, $type, $do) {
135 135
 
136
-	if (!$ids) {
137
-		return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138
-		. spip_htmlentities($type)
139
-		. "</b> :  " . _T('avis_aucun_resultat') . "</div>";
140
-	}
136
+    if (!$ids) {
137
+        return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138
+        . spip_htmlentities($type)
139
+        . "</b> :  " . _T('avis_aucun_resultat') . "</div>";
140
+    }
141 141
 
142
-	$ret = '';
143
-	$info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
142
+    $ret = '';
143
+    $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
144 144
 
145
-	$onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
145
+    $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
146 146
 
147
-	$ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
147
+    $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
148 148
 
149
-	foreach ($ids as $id => $bof) {
149
+    foreach ($ids as $id => $bof) {
150 150
 
151
-		$titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r",
152
-			"  ");
151
+        $titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r",
152
+            "  ");
153 153
 
154
-		$ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
155
-			. $onClick
156
-			. "\"\nondblclick=\""
157
-			. $ondbClick
158
-			. $onClick
159
-			. " \"><div"
160
-			. $titles[$id]["atts"]
161
-			. " title='$id'>&nbsp; "
162
-			. $titre
163
-			. "</div></div>";
164
-	}
154
+        $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
155
+            . $onClick
156
+            . "\"\nondblclick=\""
157
+            . $ondbClick
158
+            . $onClick
159
+            . " \"><div"
160
+            . $titles[$id]["atts"]
161
+            . " title='$id'>&nbsp; "
162
+            . $titre
163
+            . "</div></div>";
164
+    }
165 165
 
166
-	return $ret;
166
+    return $ret;
167 167
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
 	$where = preg_split(",\s+,", $type);
68 68
 	if ($where) {
69 69
 		foreach ($where as $k => $v) {
70
-			$where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
70
+			$where[$k] = "'%".substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1)."%'";
71 71
 		}
72
-		$where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
-		$where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
-		$where_id = ("(id_rubrique = " . intval($type) . ")");
72
+		$where_titre = ("(titre LIKE ".join(" AND titre LIKE ", $where).")");
73
+		$where_desc = ("(descriptif LIKE ".join(" AND descriptif LIKE ", $where).")");
74
+		$where_id = ("(id_rubrique = ".intval($type).")");
75 75
 
76 76
 		if ($exclus) {
77 77
 			include_spip('inc/rubriques');
78
-			$where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
78
+			$where_exclus = " AND ".sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79 79
 		} else {
80 80
 			$where_exclus = '';
81 81
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 	if ($points) {
105 105
 		arsort($points);
106
-		$style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
106
+		$style = " style='background-image: url(".chemin_image('secteur-12.png').")'";
107 107
 		foreach ($rub as $k => $v) {
108 108
 			$rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109 109
 				. " class='petite-rubrique'";
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	if (!$ids) {
137 137
 		return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138 138
 		. spip_htmlentities($type)
139
-		. "</b> :  " . _T('avis_aucun_resultat') . "</div>";
139
+		. "</b> :  "._T('avis_aucun_resultat')."</div>";
140 140
 	}
141 141
 
142 142
 	$ret = '';
143 143
 	$info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
144 144
 
145
-	$onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
145
+	$onClick = "aff_selection(this.firstChild.title,'$rac"."_selection','$info', event)";
146 146
 
147 147
 	$ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
148 148
 
Please login to merge, or discard this patch.
ecrire/genie/maintenance.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
  * @uses verifier_crash_tables()
32 32
  *
33 33
  * @param object $t
34
- * @return bool Toujours à true.
34
+ * @return integer Toujours à true.
35 35
  */
36 36
 function genie_maintenance_dist($t) {
37 37
 
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 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
 /**
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function genie_maintenance_dist($t) {
37 37
 
38
-	// (re)mettre .htaccess avec deny from all
39
-	// dans les deux repertoires dits inaccessibles par http
40
-	include_spip('inc/acces');
41
-	verifier_htaccess(_DIR_ETC);
42
-	verifier_htaccess(_DIR_TMP);
38
+    // (re)mettre .htaccess avec deny from all
39
+    // dans les deux repertoires dits inaccessibles par http
40
+    include_spip('inc/acces');
41
+    verifier_htaccess(_DIR_ETC);
42
+    verifier_htaccess(_DIR_TMP);
43 43
 
44
-	// Verifier qu'aucune table n'est crashee
45
-	if (!_request('reinstall')) {
46
-		verifier_crash_tables();
47
-	}
44
+    // Verifier qu'aucune table n'est crashee
45
+    if (!_request('reinstall')) {
46
+        verifier_crash_tables();
47
+    }
48 48
 
49
-	return 1;
49
+    return 1;
50 50
 }
51 51
 
52 52
 
@@ -63,33 +63,33 @@  discard block
 block discarded – undo
63 63
  *     des tables qui ont crashé.
64 64
  */
65 65
 function verifier_crash_tables() {
66
-	if (spip_connect()) {
67
-		include_spip('base/serial');
68
-		include_spip('base/auxiliaires');
69
-		$crash = array();
70
-		foreach (array('tables_principales', 'tables_auxiliaires') as $com) {
71
-			foreach ($GLOBALS[$com] as $table => $desc) {
72
-				if (!sql_select('*', $table, '', '', '', 1)
73
-					and !defined('spip_interdire_cache')
74
-				) # cas "LOST CONNECTION"
75
-				{
76
-					$crash[] = $table;
77
-				}
78
-			}
79
-		}
80
-		#$crash[] = 'test';
81
-		if ($crash) {
82
-			ecrire_meta('message_crash_tables', serialize($crash));
83
-			spip_log('crash des tables', 'err');
84
-			spip_log($crash, 'err');
85
-		} else {
86
-			effacer_meta('message_crash_tables');
87
-		}
66
+    if (spip_connect()) {
67
+        include_spip('base/serial');
68
+        include_spip('base/auxiliaires');
69
+        $crash = array();
70
+        foreach (array('tables_principales', 'tables_auxiliaires') as $com) {
71
+            foreach ($GLOBALS[$com] as $table => $desc) {
72
+                if (!sql_select('*', $table, '', '', '', 1)
73
+                    and !defined('spip_interdire_cache')
74
+                ) # cas "LOST CONNECTION"
75
+                {
76
+                    $crash[] = $table;
77
+                }
78
+            }
79
+        }
80
+        #$crash[] = 'test';
81
+        if ($crash) {
82
+            ecrire_meta('message_crash_tables', serialize($crash));
83
+            spip_log('crash des tables', 'err');
84
+            spip_log($crash, 'err');
85
+        } else {
86
+            effacer_meta('message_crash_tables');
87
+        }
88 88
 
89
-		return $crash;
90
-	}
89
+        return $crash;
90
+    }
91 91
 
92
-	return false;
92
+    return false;
93 93
 }
94 94
 
95 95
 /**
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  * @return string
106 106
  */
107 107
 function message_crash_tables() {
108
-	if ($crash = verifier_crash_tables()) {
109
-		return
110
-			'<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
-			. ' <tt>' . join(', ', $crash) . '</tt><br />'
112
-			. generer_form_ecrire('base_repair',
113
-				_T('texte_crash_base'), '',
114
-				_T('bouton_tenter_recuperation'));
115
-	}
108
+    if ($crash = verifier_crash_tables()) {
109
+        return
110
+            '<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
+            . ' <tt>' . join(', ', $crash) . '</tt><br />'
112
+            . generer_form_ecrire('base_repair',
113
+                _T('texte_crash_base'), '',
114
+                _T('bouton_tenter_recuperation'));
115
+    }
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -107,8 +107,8 @@
 block discarded – undo
107 107
 function message_crash_tables() {
108 108
 	if ($crash = verifier_crash_tables()) {
109 109
 		return
110
-			'<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
-			. ' <tt>' . join(', ', $crash) . '</tt><br />'
110
+			'<strong>'._T('texte_recuperer_base').'</strong><br />'
111
+			. ' <tt>'.join(', ', $crash).'</tt><br />'
112 112
 			. generer_form_ecrire('base_repair',
113 113
 				_T('texte_crash_base'), '',
114 114
 				_T('bouton_tenter_recuperation'));
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,10 +71,12 @@
 block discarded – undo
71 71
 			foreach ($GLOBALS[$com] as $table => $desc) {
72 72
 				if (!sql_select('*', $table, '', '', '', 1)
73 73
 					and !defined('spip_interdire_cache')
74
-				) # cas "LOST CONNECTION"
74
+				) {
75
+				    # cas "LOST CONNECTION"
75 76
 				{
76 77
 					$crash[] = $table;
77 78
 				}
79
+				}
78 80
 			}
79 81
 		}
80 82
 		#$crash[] = 'test';
Please login to merge, or discard this patch.
ecrire/inc/acces.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -261,7 +261,7 @@
 block discarded – undo
261 261
 /**
262 262
  * Initialiser la globale htsalt si cela n'a pas déjà été fait.
263 263
  *
264
- * @return void|bool
264
+ * @return null|string
265 265
  */
266 266
 function initialiser_sel() {
267 267
 	if (CRYPT_MD5) {
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 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
 /**
@@ -31,47 +31,47 @@  discard block
 block discarded – undo
31 31
  *     Mot de passe
32 32
  **/
33 33
 function creer_pass_aleatoire($longueur = 8, $sel = '') {
34
-	$seed = (int)round(((float)microtime() + 1) * time());
35
-
36
-	mt_srand($seed);
37
-	srand($seed);
38
-	$s = '';
39
-	$pass = '';
40
-	for ($i = 0; $i < $longueur; $i++) {
41
-		if (!$s) {
42
-			$s = mt_rand();
43
-			if (!$s) {
44
-				$s = rand();
45
-			}
46
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
47
-		}
48
-		$r = unpack('Cr', pack('H2', $s . $s));
49
-		$x = $r['r'] & 63;
50
-		if ($x < 10) {
51
-			$x = chr($x + 48);
52
-		} else {
53
-			if ($x < 36) {
54
-				$x = chr($x + 55);
55
-			} else {
56
-				if ($x < 62) {
57
-					$x = chr($x + 61);
58
-				} else {
59
-					if ($x == 63) {
60
-						$x = '/';
61
-					} else {
62
-						$x = '.';
63
-					}
64
-				}
65
-			}
66
-		}
67
-		$pass .= $x;
68
-		$s = substr($s, 2);
69
-	}
70
-	$pass = preg_replace('@[./]@', 'a', $pass);
71
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
72
-	$pass = preg_replace('@[0O]@', 'o', $pass);
73
-
74
-	return $pass;
34
+    $seed = (int)round(((float)microtime() + 1) * time());
35
+
36
+    mt_srand($seed);
37
+    srand($seed);
38
+    $s = '';
39
+    $pass = '';
40
+    for ($i = 0; $i < $longueur; $i++) {
41
+        if (!$s) {
42
+            $s = mt_rand();
43
+            if (!$s) {
44
+                $s = rand();
45
+            }
46
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
47
+        }
48
+        $r = unpack('Cr', pack('H2', $s . $s));
49
+        $x = $r['r'] & 63;
50
+        if ($x < 10) {
51
+            $x = chr($x + 48);
52
+        } else {
53
+            if ($x < 36) {
54
+                $x = chr($x + 55);
55
+            } else {
56
+                if ($x < 62) {
57
+                    $x = chr($x + 61);
58
+                } else {
59
+                    if ($x == 63) {
60
+                        $x = '/';
61
+                    } else {
62
+                        $x = '.';
63
+                    }
64
+                }
65
+            }
66
+        }
67
+        $pass .= $x;
68
+        $s = substr($s, 2);
69
+    }
70
+    $pass = preg_replace('@[./]@', 'a', $pass);
71
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
72
+    $pass = preg_replace('@[0O]@', 'o', $pass);
73
+
74
+    return $pass;
75 75
 }
76 76
 
77 77
 /**
@@ -80,21 +80,21 @@  discard block
 block discarded – undo
80 80
  * @return string Identifiant
81 81
  */
82 82
 function creer_uniqid() {
83
-	static $seeded;
83
+    static $seeded;
84 84
 
85
-	if (!$seeded) {
86
-		$seed = (int)round(((float)microtime() + 1) * time());
87
-		mt_srand($seed);
88
-		srand($seed);
89
-		$seeded = true;
90
-	}
85
+    if (!$seeded) {
86
+        $seed = (int)round(((float)microtime() + 1) * time());
87
+        mt_srand($seed);
88
+        srand($seed);
89
+        $seeded = true;
90
+    }
91 91
 
92
-	$s = mt_rand();
93
-	if (!$s) {
94
-		$s = rand();
95
-	}
92
+    $s = mt_rand();
93
+    if (!$s) {
94
+        $s = rand();
95
+    }
96 96
 
97
-	return uniqid($s, 1);
97
+    return uniqid($s, 1);
98 98
 }
99 99
 
100 100
 /**
@@ -108,38 +108,38 @@  discard block
 block discarded – undo
108 108
  * @return string Retourne l'alea éphemère actuel au passage
109 109
  */
110 110
 function charger_aleas() {
111
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
112
-		include_spip('base/abstract_sql');
113
-		$aleas = sql_allfetsel(
114
-			array('nom', 'valeur'),
115
-			'spip_meta',
116
-			sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')),
117
-			'', '', '', '', '',
118
-			'continue'
119
-		);
120
-		if ($aleas) {
121
-			foreach ($aleas as $a) {
122
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
123
-			}
124
-			return $GLOBALS['meta']['alea_ephemere'];
125
-		} else {
126
-			spip_log("aleas indisponibles", "session");
127
-			return "";
128
-		}
129
-	}
130
-	return $GLOBALS['meta']['alea_ephemere'];
111
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
112
+        include_spip('base/abstract_sql');
113
+        $aleas = sql_allfetsel(
114
+            array('nom', 'valeur'),
115
+            'spip_meta',
116
+            sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')),
117
+            '', '', '', '', '',
118
+            'continue'
119
+        );
120
+        if ($aleas) {
121
+            foreach ($aleas as $a) {
122
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
123
+            }
124
+            return $GLOBALS['meta']['alea_ephemere'];
125
+        } else {
126
+            spip_log("aleas indisponibles", "session");
127
+            return "";
128
+        }
129
+    }
130
+    return $GLOBALS['meta']['alea_ephemere'];
131 131
 }
132 132
 
133 133
 /**
134 134
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
135 135
  **/
136 136
 function renouvelle_alea() {
137
-	charger_aleas();
138
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
139
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
140
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
141
-	ecrire_meta('alea_ephemere_date', time(), 'non');
142
-	spip_log("renouvellement de l'alea_ephemere");
137
+    charger_aleas();
138
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
139
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
140
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
141
+    ecrire_meta('alea_ephemere_date', time(), 'non');
142
+    spip_log("renouvellement de l'alea_ephemere");
143 143
 }
144 144
 
145 145
 
@@ -159,20 +159,20 @@  discard block
 block discarded – undo
159 159
  *     Clé de sécurité.
160 160
  **/
161 161
 function low_sec($id_auteur) {
162
-	// Pas d'id_auteur : low_sec
163
-	if (!$id_auteur = intval($id_auteur)) {
164
-		if (!$low_sec = $GLOBALS['meta']['low_sec']) {
165
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
166
-		}
167
-	} else {
168
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur));
169
-		if (!$low_sec) {
170
-			$low_sec = creer_pass_aleatoire();
171
-			sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur));
172
-		}
173
-	}
174
-
175
-	return $low_sec;
162
+    // Pas d'id_auteur : low_sec
163
+    if (!$id_auteur = intval($id_auteur)) {
164
+        if (!$low_sec = $GLOBALS['meta']['low_sec']) {
165
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
166
+        }
167
+    } else {
168
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur));
169
+        if (!$low_sec) {
170
+            $low_sec = creer_pass_aleatoire();
171
+            sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur));
172
+        }
173
+    }
174
+
175
+    return $low_sec;
176 176
 }
177 177
 
178 178
 /**
@@ -188,27 +188,27 @@  discard block
 block discarded – undo
188 188
  * @return string
189 189
  */
190 190
 function param_low_sec($op, $args = array(), $lang = '', $mime = 'rss') {
191
-	$a = $b = '';
192
-	foreach ($args as $val => $var) {
193
-		if ($var) {
194
-			if ($val <> 'statut') {
195
-				$a .= ':' . $val . '-' . $var;
196
-			}
197
-			$b .= $val . '=' . $var . '&';
198
-		}
199
-	}
200
-	$a = substr($a, 1);
201
-	$id = intval(@$GLOBALS['connect_id_auteur']);
202
-
203
-	return $b
204
-	. 'op='
205
-	. $op
206
-	. '&id='
207
-	. $id
208
-	. '&cle='
209
-	. afficher_low_sec($id, "$mime $op $a")
210
-	. (!$a ? '' : "&args=$a")
211
-	. (!$lang ? '' : "&lang=$lang");
191
+    $a = $b = '';
192
+    foreach ($args as $val => $var) {
193
+        if ($var) {
194
+            if ($val <> 'statut') {
195
+                $a .= ':' . $val . '-' . $var;
196
+            }
197
+            $b .= $val . '=' . $var . '&';
198
+        }
199
+    }
200
+    $a = substr($a, 1);
201
+    $id = intval(@$GLOBALS['connect_id_auteur']);
202
+
203
+    return $b
204
+    . 'op='
205
+    . $op
206
+    . '&id='
207
+    . $id
208
+    . '&cle='
209
+    . afficher_low_sec($id, "$mime $op $a")
210
+    . (!$a ? '' : "&args=$a")
211
+    . (!$lang ? '' : "&lang=$lang");
212 212
 }
213 213
 
214 214
 /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
  *     Clé
225 225
  **/
226 226
 function afficher_low_sec($id_auteur, $action = '') {
227
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
227
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
228 228
 }
229 229
 
230 230
 /**
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  *     true si les clés corresponde, false sinon
243 243
  **/
244 244
 function verifier_low_sec($id_auteur, $cle, $action = '') {
245
-	return ($cle == afficher_low_sec($id_auteur, $action));
245
+    return ($cle == afficher_low_sec($id_auteur, $action));
246 246
 }
247 247
 
248 248
 /**
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
  *     Identifiant de l'auteur
253 253
  **/
254 254
 function effacer_low_sec($id_auteur) {
255
-	if (!$id_auteur = intval($id_auteur)) {
256
-		return;
257
-	} // jamais trop prudent ;)
258
-	sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur));
255
+    if (!$id_auteur = intval($id_auteur)) {
256
+        return;
257
+    } // jamais trop prudent ;)
258
+    sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur));
259 259
 }
260 260
 
261 261
 /**
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
  * @return void|bool
265 265
  */
266 266
 function initialiser_sel() {
267
-	if (CRYPT_MD5) {
268
-		$GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire();
269
-	} else {
270
-		return '';
271
-	}
267
+    if (CRYPT_MD5) {
268
+        $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire();
269
+    } else {
270
+        return '';
271
+    }
272 272
 }
273 273
 
274 274
 /**
@@ -285,45 +285,45 @@  discard block
 block discarded – undo
285 285
  *     - void sinon.
286 286
  **/
287 287
 function ecrire_acces() {
288
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
289
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
290
-
291
-	// Cette variable de configuration peut etre posee par un plugin
292
-	// par exemple acces_restreint ;
293
-	// si .htaccess existe, outrepasser spip_meta
294
-	if ((!isset($GLOBALS['meta']['creer_htpasswd'])
295
-			or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
296
-		and !@file_exists($htaccess)
297
-	) {
298
-		spip_unlink($htpasswd);
299
-		spip_unlink($htpasswd . '-admin');
300
-		return;
301
-	}
302
-
303
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
304
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
305
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
306
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap()
307
-
308
-	if (spip_connect_ldap()) {
309
-		return;
310
-	}
311
-	$p1 = ''; // login:htpass pour tous
312
-	$p2 = ''; // login:htpass pour les admins
313
-	$s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau')));
314
-	while ($t = sql_fetch($s)) {
315
-		if (strlen($t['login']) and strlen($t['htpass'])) {
316
-			$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
317
-			if ($t['statut'] == '0minirezo') {
318
-				$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
319
-			}
320
-		}
321
-	}
322
-	if ($p1) {
323
-		ecrire_fichier($htpasswd, $p1);
324
-		ecrire_fichier($htpasswd . '-admin', $p2);
325
-		spip_log("Ecriture de $htpasswd et $htpasswd-admin");
326
-	}
288
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
289
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
290
+
291
+    // Cette variable de configuration peut etre posee par un plugin
292
+    // par exemple acces_restreint ;
293
+    // si .htaccess existe, outrepasser spip_meta
294
+    if ((!isset($GLOBALS['meta']['creer_htpasswd'])
295
+            or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
296
+        and !@file_exists($htaccess)
297
+    ) {
298
+        spip_unlink($htpasswd);
299
+        spip_unlink($htpasswd . '-admin');
300
+        return;
301
+    }
302
+
303
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
304
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
305
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
306
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap()
307
+
308
+    if (spip_connect_ldap()) {
309
+        return;
310
+    }
311
+    $p1 = ''; // login:htpass pour tous
312
+    $p2 = ''; // login:htpass pour les admins
313
+    $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau')));
314
+    while ($t = sql_fetch($s)) {
315
+        if (strlen($t['login']) and strlen($t['htpass'])) {
316
+            $p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
317
+            if ($t['statut'] == '0minirezo') {
318
+                $p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
319
+            }
320
+        }
321
+    }
322
+    if ($p1) {
323
+        ecrire_fichier($htpasswd, $p1);
324
+        ecrire_fichier($htpasswd . '-admin', $p2);
325
+        spip_log("Ecriture de $htpasswd et $htpasswd-admin");
326
+    }
327 327
 }
328 328
 
329 329
 /**
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
  *  La chaîne hachée si fonction crypt présente, rien sinon.
340 340
  */
341 341
 function generer_htpass($pass) {
342
-	if (function_exists('crypt')) {
343
-		return crypt($pass, $GLOBALS['htsalt']);
344
-	}
342
+    if (function_exists('crypt')) {
343
+        return crypt($pass, $GLOBALS['htsalt']);
344
+    }
345 345
 }
346 346
 
347 347
 /**
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
  * @return boolean
355 355
  */
356 356
 function verifier_htaccess($rep, $force = false) {
357
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
358
-	if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
359
-		return true;
360
-	}
361
-
362
-	// directive deny compatible Apache 2.0+
363
-	$deny =
364
-		'# Deny all requests from Apache 2.4+.
357
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
358
+    if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
359
+        return true;
360
+    }
361
+
362
+    // directive deny compatible Apache 2.0+
363
+    $deny =
364
+        '# Deny all requests from Apache 2.4+.
365 365
 <IfModule mod_authz_core.c>
366 366
   Require all denied
367 367
 </IfModule>
@@ -370,32 +370,32 @@  discard block
 block discarded – undo
370 370
   Deny from all
371 371
 </IfModule>
372 372
 ';
373
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
374
-	if (function_exists('apache_get_version')
375
-		and $v = apache_get_version()
376
-		and strncmp($v, 'Apache/1.', 9) == 0) {
377
-		$deny = "deny from all\n";
378
-	}
379
-
380
-	if ($ht = @fopen($htaccess, 'w')) {
381
-		fputs($ht, $deny);
382
-		fclose($ht);
383
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
384
-		$t = rtrim($rep, '/') . '/.ok';
385
-		if ($ht = @fopen($t, 'w')) {
386
-			@fclose($ht);
387
-			include_spip('inc/distant');
388
-			$t = substr($t, strlen(_DIR_RACINE));
389
-			$t = url_de_base() . $t;
390
-			$ht = recuperer_lapage($t, false, 'HEAD', 0);
391
-			// htaccess inoperant si on a recupere des entetes HTTP
392
-			// (ignorer la reussite si connexion par fopen)
393
-			$ht = !(isset($ht[0]) and $ht[0]);
394
-		}
395
-	}
396
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
397
-
398
-	return $ht;
373
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
374
+    if (function_exists('apache_get_version')
375
+        and $v = apache_get_version()
376
+        and strncmp($v, 'Apache/1.', 9) == 0) {
377
+        $deny = "deny from all\n";
378
+    }
379
+
380
+    if ($ht = @fopen($htaccess, 'w')) {
381
+        fputs($ht, $deny);
382
+        fclose($ht);
383
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
384
+        $t = rtrim($rep, '/') . '/.ok';
385
+        if ($ht = @fopen($t, 'w')) {
386
+            @fclose($ht);
387
+            include_spip('inc/distant');
388
+            $t = substr($t, strlen(_DIR_RACINE));
389
+            $t = url_de_base() . $t;
390
+            $ht = recuperer_lapage($t, false, 'HEAD', 0);
391
+            // htaccess inoperant si on a recupere des entetes HTTP
392
+            // (ignorer la reussite si connexion par fopen)
393
+            $ht = !(isset($ht[0]) and $ht[0]);
394
+        }
395
+    }
396
+    spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
397
+
398
+    return $ht;
399 399
 }
400 400
 
401 401
 /**
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
  *         Valeur de la configuration `creer_htaccess`
414 414
  */
415 415
 function gerer_htaccess() {
416
-	// Cette variable de configuration peut etre posee par un plugin
417
-	// par exemple acces_restreint
418
-	$f = isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui');
419
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
420
-	$dirs[] = array('extension' => 'distant');
421
-	foreach ($dirs as $e) {
422
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
423
-			if ($f) {
424
-				verifier_htaccess($dir);
425
-			} else {
426
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
427
-			}
428
-		}
429
-	}
430
-
431
-	return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : '';
416
+    // Cette variable de configuration peut etre posee par un plugin
417
+    // par exemple acces_restreint
418
+    $f = isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui');
419
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
420
+    $dirs[] = array('extension' => 'distant');
421
+    foreach ($dirs as $e) {
422
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
423
+            if ($f) {
424
+                verifier_htaccess($dir);
425
+            } else {
426
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
427
+            }
428
+        }
429
+    }
430
+
431
+    return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : '';
432 432
 }
433 433
 
434 434
 initialiser_sel();
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  *     Mot de passe
32 32
  **/
33 33
 function creer_pass_aleatoire($longueur = 8, $sel = '') {
34
-	$seed = (int)round(((float)microtime() + 1) * time());
34
+	$seed = (int) round(((float) microtime() + 1) * time());
35 35
 
36 36
 	mt_srand($seed);
37 37
 	srand($seed);
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 			if (!$s) {
44 44
 				$s = rand();
45 45
 			}
46
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
46
+			$s = substr(md5(uniqid($s).$sel), 0, 16);
47 47
 		}
48
-		$r = unpack('Cr', pack('H2', $s . $s));
48
+		$r = unpack('Cr', pack('H2', $s.$s));
49 49
 		$x = $r['r'] & 63;
50 50
 		if ($x < 10) {
51 51
 			$x = chr($x + 48);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	static $seeded;
84 84
 
85 85
 	if (!$seeded) {
86
-		$seed = (int)round(((float)microtime() + 1) * time());
86
+		$seed = (int) round(((float) microtime() + 1) * time());
87 87
 		mt_srand($seed);
88 88
 		srand($seed);
89 89
 		$seeded = true;
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
 	foreach ($args as $val => $var) {
193 193
 		if ($var) {
194 194
 			if ($val <> 'statut') {
195
-				$a .= ':' . $val . '-' . $var;
195
+				$a .= ':'.$val.'-'.$var;
196 196
 			}
197
-			$b .= $val . '=' . $var . '&';
197
+			$b .= $val.'='.$var.'&';
198 198
 		}
199 199
 	}
200 200
 	$a = substr($a, 1);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
  *     Clé
225 225
  **/
226 226
 function afficher_low_sec($id_auteur, $action = '') {
227
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
227
+	return substr(md5($action.low_sec($id_auteur)), 0, 8);
228 228
 }
229 229
 
230 230
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  */
266 266
 function initialiser_sel() {
267 267
 	if (CRYPT_MD5) {
268
-		$GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire();
268
+		$GLOBALS['htsalt'] = '$1$'.creer_pass_aleatoire();
269 269
 	} else {
270 270
 		return '';
271 271
 	}
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
  *     - void sinon.
286 286
  **/
287 287
 function ecrire_acces() {
288
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
289
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
288
+	$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
289
+	$htpasswd = _DIR_TMP._AUTH_USER_FILE;
290 290
 
291 291
 	// Cette variable de configuration peut etre posee par un plugin
292 292
 	// par exemple acces_restreint ;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 		and !@file_exists($htaccess)
297 297
 	) {
298 298
 		spip_unlink($htpasswd);
299
-		spip_unlink($htpasswd . '-admin');
299
+		spip_unlink($htpasswd.'-admin');
300 300
 		return;
301 301
 	}
302 302
 
@@ -313,15 +313,15 @@  discard block
 block discarded – undo
313 313
 	$s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau')));
314 314
 	while ($t = sql_fetch($s)) {
315 315
 		if (strlen($t['login']) and strlen($t['htpass'])) {
316
-			$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
316
+			$p1 .= $t['login'].':'.$t['htpass']."\n";
317 317
 			if ($t['statut'] == '0minirezo') {
318
-				$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
318
+				$p2 .= $t['login'].':'.$t['htpass']."\n";
319 319
 			}
320 320
 		}
321 321
 	}
322 322
 	if ($p1) {
323 323
 		ecrire_fichier($htpasswd, $p1);
324
-		ecrire_fichier($htpasswd . '-admin', $p2);
324
+		ecrire_fichier($htpasswd.'-admin', $p2);
325 325
 		spip_log("Ecriture de $htpasswd et $htpasswd-admin");
326 326
 	}
327 327
 }
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
  * @return boolean
355 355
  */
356 356
 function verifier_htaccess($rep, $force = false) {
357
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
357
+	$htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME;
358 358
 	if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
359 359
 		return true;
360 360
 	}
@@ -381,19 +381,19 @@  discard block
 block discarded – undo
381 381
 		fputs($ht, $deny);
382 382
 		fclose($ht);
383 383
 		@chmod($htaccess, _SPIP_CHMOD & 0666);
384
-		$t = rtrim($rep, '/') . '/.ok';
384
+		$t = rtrim($rep, '/').'/.ok';
385 385
 		if ($ht = @fopen($t, 'w')) {
386 386
 			@fclose($ht);
387 387
 			include_spip('inc/distant');
388 388
 			$t = substr($t, strlen(_DIR_RACINE));
389
-			$t = url_de_base() . $t;
389
+			$t = url_de_base().$t;
390 390
 			$ht = recuperer_lapage($t, false, 'HEAD', 0);
391 391
 			// htaccess inoperant si on a recupere des entetes HTTP
392 392
 			// (ignorer la reussite si connexion par fopen)
393 393
 			$ht = !(isset($ht[0]) and $ht[0]);
394 394
 		}
395 395
 	}
396
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
396
+	spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee'));
397 397
 
398 398
 	return $ht;
399 399
 }
@@ -419,11 +419,11 @@  discard block
 block discarded – undo
419 419
 	$dirs = sql_allfetsel('extension', 'spip_types_documents');
420 420
 	$dirs[] = array('extension' => 'distant');
421 421
 	foreach ($dirs as $e) {
422
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
422
+		if (is_dir($dir = _DIR_IMG.$e['extension'])) {
423 423
 			if ($f) {
424 424
 				verifier_htaccess($dir);
425 425
 			} else {
426
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
426
+				spip_unlink($dir.'/'._ACCESS_FILE_NAME);
427 427
 			}
428 428
 		}
429 429
 	}
Please login to merge, or discard this patch.
ecrire/inc/actions.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
  *     - -1 : renvoyer action, arg et hash sous forme de array()
36 36
  *     - true ou false : renvoyer une url, avec `&amp;` (false) ou `&` (true)
37 37
  *     - string : renvoyer un formulaire
38
- * @param string|int $att
38
+ * @param string $att
39 39
  *     - id_auteur pour lequel générer l'action en mode url ou array()
40 40
  *     - attributs du formulaire en mode formulaire
41 41
  * @param bool $public
42
- * @return array|string
42
+ * @return string
43 43
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
44 44
  */
45 45
 function generer_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) {
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
  *     que l'on peut récupérer dans une fonction d'action par `_request('redirect')`
67 67
  * @param string $gra
68 68
  *     Arguments transmis au script exec de retour `arg1=yy&arg2=zz`
69
- * @param bool|string|int $mode
69
+ * @param boolean $mode
70 70
  *     - -1 : renvoyer action, arg et hash sous forme de array()
71 71
  *     - true ou false : renvoyer une url, avec `&amp;` (false) ou `&` (true)
72 72
  *     - string : renvoyer un formulaire
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
44 44
  */
45 45
 function generer_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) {
46
-	$securiser_action = charger_fonction('securiser_action', 'inc');
46
+    $securiser_action = charger_fonction('securiser_action', 'inc');
47 47
 
48
-	return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
48
+    return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
49 49
 }
50 50
 
51 51
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  *     Code HTML du formulaire
79 79
  */
80 80
 function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) {
81
-	$r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
81
+    $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
82 82
 
83
-	return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
83
+    return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
84 84
 }
85 85
 
86 86
 /**
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
106 106
  */
107 107
 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') {
108
-	$r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
108
+    $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
109 109
 
110
-	return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
110
+    return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
111 111
 }
112 112
 
113 113
 
@@ -122,25 +122,25 @@  discard block
 block discarded – undo
122 122
  *   passer "text/html" comme $content_type
123 123
  */
124 124
 function ajax_retour($corps, $content_type = null) {
125
-	$xml = false;
126
-	if (is_null($content_type) or $content_type === true) {
127
-		$xml = true;
128
-		$content_type = 'text/html';
129
-	} elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) {
130
-		$content_type = 'text/html';
131
-	}
125
+    $xml = false;
126
+    if (is_null($content_type) or $content_type === true) {
127
+        $xml = true;
128
+        $content_type = 'text/html';
129
+    } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) {
130
+        $content_type = 'text/html';
131
+    }
132 132
 
133
-	$e = '';
134
-	if (isset($_COOKIE['spip_admin'])
135
-		and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
136
-	) {
137
-		$e = erreur_squelette();
138
-	}
133
+    $e = '';
134
+    if (isset($_COOKIE['spip_admin'])
135
+        and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
136
+    ) {
137
+        $e = erreur_squelette();
138
+    }
139 139
 
140
-	$c = $GLOBALS['meta']['charset'];
141
-	header('Content-Type: ' . $content_type . '; charset=' . $c);
142
-	$debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
143
-	$fin = '';
140
+    $c = $GLOBALS['meta']['charset'];
141
+    header('Content-Type: ' . $content_type . '; charset=' . $c);
142
+    $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
143
+    $fin = '';
144 144
 
145
-	echo $debut, $corps, $fin, $e;
145
+    echo $debut, $corps, $fin, $e;
146 146
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
  *     Code HTML du formulaire
79 79
  */
80 80
 function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) {
81
-	$r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
81
+	$r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT).generer_url_ecrire($ret, $gra, true, true);
82 82
 
83 83
 	return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
84 84
 }
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
106 106
  */
107 107
 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') {
108
-	$r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
108
+	$r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true);
109 109
 
110
-	return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
110
+	return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'");
111 111
 }
112 112
 
113 113
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	}
139 139
 
140 140
 	$c = $GLOBALS['meta']['charset'];
141
-	header('Content-Type: ' . $content_type . '; charset=' . $c);
142
-	$debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
141
+	header('Content-Type: '.$content_type.'; charset='.$c);
142
+	$debut = (($xml and strlen(trim($corps))) ? '<'."?xml version='1.0' encoding='".$c."'?".">\n" : '');
143 143
 	$fin = '';
144 144
 
145 145
 	echo $debut, $corps, $fin, $e;
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1654,7 +1654,7 @@
 block discarded – undo
1654 1654
  *
1655 1655
  * @param string $objet
1656 1656
  * @param int $id_objet
1657
- * @param string|array $cond
1657
+ * @param string $cond
1658 1658
  *     Condition(s) supplémentaire(s) pour le where de la requête
1659 1659
  * @return int[]
1660 1660
  *     Identifiants d'auteurs
Please login to merge, or discard this patch.
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Autorisations
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('base/abstract_sql');
@@ -38,83 +38,83 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 if (!function_exists('autoriser')) {
41
-	/**
42
-	 * Autoriser une action
43
-	 *
44
-	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
-	 * une certaine action. Cette fonction est le point d'entrée de toutes
46
-	 * les autorisations.
47
-	 *
48
-	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
-	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
-	 * dans cet ordre :
51
-	 *
52
-	 * - autoriser_{type}_{faire}, sinon avec _dist
53
-	 * - autoriser_{type}, sinon avec _dist
54
-	 * - autoriser_{faire}, sinon avec _dist
55
-	 * - autoriser_{defaut}, sinon avec _dist
56
-	 *
57
-	 * Seul le premier argument est obligatoire.
58
-	 *
59
-	 * @note
60
-	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
-	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
-	 *     cette valeur.
63
-	 *
64
-	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
-	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
-	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
-	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
-	 *
69
-	 * @note
70
-	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
-	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
-	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
-	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
-	 *     quel serait le type, quel serait l'action ?
75
-	 *
76
-	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
-	 *     la fonction d'autorisation correspondante ne l'aura pas.
78
-	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
-	 *
80
-	 * @api
81
-	 * @see autoriser_dist()
82
-	 *
83
-	 * @param string $faire
84
-	 *   une action ('modifier', 'publier'...)
85
-	 * @param string $type
86
-	 *   type d'objet ou nom de table ('article')
87
-	 * @param int $id
88
-	 *   id de l'objet sur lequel on veut agir
89
-	 * @param null|int|array $qui
90
-	 *   - si null on prend alors visiteur_session
91
-	 *   - un id_auteur (on regarde dans la base)
92
-	 *   - un tableau auteur complet, y compris [restreint]
93
-	 * @param null|array $opt
94
-	 *   options sous forme de tableau associatif
95
-	 * @return bool
96
-	 *   true si la personne peut effectuer l'action
97
-	 */
98
-	function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
-		// Charger les fonctions d'autorisation supplementaires
100
-		static $pipe;
101
-		if (!isset($pipe)) {
102
-			$pipe = 1;
103
-			pipeline('autoriser');
104
-		}
105
-
106
-		$args = func_get_args();
107
-
108
-		return call_user_func_array('autoriser_dist', $args);
109
-	}
41
+    /**
42
+     * Autoriser une action
43
+     *
44
+     * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
+     * une certaine action. Cette fonction est le point d'entrée de toutes
46
+     * les autorisations.
47
+     *
48
+     * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
+     * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
+     * dans cet ordre :
51
+     *
52
+     * - autoriser_{type}_{faire}, sinon avec _dist
53
+     * - autoriser_{type}, sinon avec _dist
54
+     * - autoriser_{faire}, sinon avec _dist
55
+     * - autoriser_{defaut}, sinon avec _dist
56
+     *
57
+     * Seul le premier argument est obligatoire.
58
+     *
59
+     * @note
60
+     *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
+     *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
+     *     cette valeur.
63
+     *
64
+     *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
+     *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
+     *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
+     *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
+     *
69
+     * @note
70
+     *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
+     *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
+     *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
+     *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
+     *     quel serait le type, quel serait l'action ?
75
+     *
76
+     *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
+     *     la fonction d'autorisation correspondante ne l'aura pas.
78
+     *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
+     *
80
+     * @api
81
+     * @see autoriser_dist()
82
+     *
83
+     * @param string $faire
84
+     *   une action ('modifier', 'publier'...)
85
+     * @param string $type
86
+     *   type d'objet ou nom de table ('article')
87
+     * @param int $id
88
+     *   id de l'objet sur lequel on veut agir
89
+     * @param null|int|array $qui
90
+     *   - si null on prend alors visiteur_session
91
+     *   - un id_auteur (on regarde dans la base)
92
+     *   - un tableau auteur complet, y compris [restreint]
93
+     * @param null|array $opt
94
+     *   options sous forme de tableau associatif
95
+     * @return bool
96
+     *   true si la personne peut effectuer l'action
97
+     */
98
+    function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
+        // Charger les fonctions d'autorisation supplementaires
100
+        static $pipe;
101
+        if (!isset($pipe)) {
102
+            $pipe = 1;
103
+            pipeline('autoriser');
104
+        }
105
+
106
+        $args = func_get_args();
107
+
108
+        return call_user_func_array('autoriser_dist', $args);
109
+    }
110 110
 }
111 111
 
112 112
 
113 113
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
114 114
 // mais apres la fonction autoriser()
115 115
 if ($f = find_in_path('mes_fonctions.php')) {
116
-	global $dossier_squelettes;
117
-	include_once(_ROOT_CWD . $f);
116
+    global $dossier_squelettes;
117
+    include_once(_ROOT_CWD . $f);
118 118
 }
119 119
 
120 120
 
@@ -142,72 +142,72 @@  discard block
 block discarded – undo
142 142
  */
143 143
 function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) {
144 144
 
145
-	// Qui ? visiteur_session ?
146
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
-	if ($qui === null or $qui === '') {
148
-		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
-		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
-	} elseif (is_numeric($qui)) {
151
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
-	}
153
-
154
-	// Admins restreints, on construit ici (pas generique mais...)
155
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
-	if (_ADMINS_RESTREINTS and is_array($qui)) {
157
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
-	}
159
-
160
-	spip_log(
161
-		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
-		'autoriser' . _LOG_DEBUG
163
-	);
164
-
165
-	// passer par objet_type pour avoir les alias
166
-	// et supprimer les _
167
-	$type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
-
169
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
170
-	if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171
-		and autoriser_exception($faire, $type, $id, 'verifier')
172
-	) {
173
-		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
-		return true;
175
-	}
176
-
177
-	// Chercher une fonction d'autorisation
178
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
180
-	$fonctions = $type
181
-		? array(
182
-			'autoriser_' . $type . '_' . $faire,
183
-			'autoriser_' . $type . '_' . $faire . '_dist',
184
-			'autoriser_' . $type,
185
-			'autoriser_' . $type . '_dist',
186
-			'autoriser_' . $faire,
187
-			'autoriser_' . $faire . '_dist',
188
-			'autoriser_defaut',
189
-			'autoriser_defaut_dist'
190
-		)
191
-		: array(
192
-			'autoriser_' . $faire,
193
-			'autoriser_' . $faire . '_dist',
194
-			'autoriser_defaut',
195
-			'autoriser_defaut_dist'
196
-		);
197
-
198
-	foreach ($fonctions as $f) {
199
-		if (function_exists($f)) {
200
-			$a = $f($faire, $type, $id, $qui, $opt);
201
-			break;
202
-		}
203
-	}
204
-
205
-	spip_log(
206
-		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
-		'autoriser' . _LOG_DEBUG
208
-	);
209
-
210
-	return $a;
145
+    // Qui ? visiteur_session ?
146
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
+    if ($qui === null or $qui === '') {
148
+        $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
+        $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
+    } elseif (is_numeric($qui)) {
151
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
+    }
153
+
154
+    // Admins restreints, on construit ici (pas generique mais...)
155
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
+    if (_ADMINS_RESTREINTS and is_array($qui)) {
157
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
+    }
159
+
160
+    spip_log(
161
+        "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
+        'autoriser' . _LOG_DEBUG
163
+    );
164
+
165
+    // passer par objet_type pour avoir les alias
166
+    // et supprimer les _
167
+    $type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
+
169
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
170
+    if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171
+        and autoriser_exception($faire, $type, $id, 'verifier')
172
+    ) {
173
+        spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
+        return true;
175
+    }
176
+
177
+    // Chercher une fonction d'autorisation
178
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
180
+    $fonctions = $type
181
+        ? array(
182
+            'autoriser_' . $type . '_' . $faire,
183
+            'autoriser_' . $type . '_' . $faire . '_dist',
184
+            'autoriser_' . $type,
185
+            'autoriser_' . $type . '_dist',
186
+            'autoriser_' . $faire,
187
+            'autoriser_' . $faire . '_dist',
188
+            'autoriser_defaut',
189
+            'autoriser_defaut_dist'
190
+        )
191
+        : array(
192
+            'autoriser_' . $faire,
193
+            'autoriser_' . $faire . '_dist',
194
+            'autoriser_defaut',
195
+            'autoriser_defaut_dist'
196
+        );
197
+
198
+    foreach ($fonctions as $f) {
199
+        if (function_exists($f)) {
200
+            $a = $f($faire, $type, $id, $qui, $opt);
201
+            break;
202
+        }
203
+    }
204
+
205
+    spip_log(
206
+        "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
+        'autoriser' . _LOG_DEBUG
208
+    );
209
+
210
+    return $a;
211 211
 }
212 212
 
213 213
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
  * @return bool
226 226
  */
227 227
 function autoriser_exception($faire, $type, $id, $autoriser = true) {
228
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
-	static $autorisation;
230
-	if ($autoriser === 'verifier') {
231
-		return isset($autorisation[$faire][$type][$id]);
232
-	}
233
-	if ($autoriser === true) {
234
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
-	}
236
-	if ($autoriser === false) {
237
-		unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
238
-		unset($autorisation[$faire][$type][$id]);
239
-	}
228
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
+    static $autorisation;
230
+    if ($autoriser === 'verifier') {
231
+        return isset($autorisation[$faire][$type][$id]);
232
+    }
233
+    if ($autoriser === true) {
234
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
+    }
236
+    if ($autoriser === false) {
237
+        unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
238
+        unset($autorisation[$faire][$type][$id]);
239
+    }
240 240
 
241
-	return false;
241
+    return false;
242 242
 }
243 243
 
244 244
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
  * @return bool          true s'il a le droit, false sinon
256 256
  **/
257 257
 function autoriser_defaut_dist($faire, $type, $id, $qui, $opt) {
258
-	return
259
-		$qui['statut'] == '0minirezo'
260
-		and !$qui['restreint'];
258
+    return
259
+        $qui['statut'] == '0minirezo'
260
+        and !$qui['restreint'];
261 261
 }
262 262
 
263 263
 /**
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
  * @return bool
274 274
  */
275 275
 function autoriser_loger_dist($faire, $type, $id, $qui, $opt) {
276
-	if ($qui['statut'] == '5poubelle') {
277
-		return false;
278
-	}
279
-	return true;
276
+    if ($qui['statut'] == '5poubelle') {
277
+        return false;
278
+    }
279
+    return true;
280 280
 }
281 281
 
282 282
 /**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
  * @return bool          true s'il a le droit, false sinon
291 291
  **/
292 292
 function autoriser_ecrire_dist($faire, $type, $id, $qui, $opt) {
293
-	return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
293
+    return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
294 294
 }
295 295
 
296 296
 /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
  * @return bool          true s'il a le droit, false sinon
308 308
  **/
309 309
 function autoriser_creer_dist($faire, $type, $id, $qui, $opt) {
310
-	return in_array($qui['statut'], array('0minirezo', '1comite'));
310
+    return in_array($qui['statut'], array('0minirezo', '1comite'));
311 311
 }
312 312
 
313 313
 /**
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
  **/
326 326
 function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
327 327
 
328
-	// Le visiteur a-t-il un statut prevu par la config ?
329
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
330
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331
-	}
328
+    // Le visiteur a-t-il un statut prevu par la config ?
329
+    if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
330
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331
+    }
332 332
 
333
-	// A-t-on un token de prévisualisation valable ?
334
-	include_spip('inc/securiser_action');
335
-	if (decrire_token_previsu()) {
336
-		return true;
337
-	}
333
+    // A-t-on un token de prévisualisation valable ?
334
+    include_spip('inc/securiser_action');
335
+    if (decrire_token_previsu()) {
336
+        return true;
337
+    }
338 338
 
339
-	return false;
339
+    return false;
340 340
 }
341 341
 
342 342
 /**
@@ -364,57 +364,57 @@  discard block
 block discarded – undo
364 364
  */
365 365
 function test_previsualiser_objet_champ($type = null, $id = 0, $qui = array(), $opt = array()) {
366 366
 
367
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
368
-	if (!$type) {
369
-		return true;
370
-	}
371
-
372
-	include_spip('base/objets');
373
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
374
-	if (isset($infos['statut'])) {
375
-		foreach ($infos['statut'] as $c) {
376
-			if (isset($c['publie'])) {
377
-				if (!isset($c['previsu'])) {
378
-					return false;
379
-				} // pas de previsu definie => NIET
380
-				$champ = $c['champ'];
381
-				if (!isset($opt[$champ])) {
382
-					return false;
383
-				} // pas de champ passe a la demande => NIET
384
-				$previsu = explode(',', $c['previsu']);
385
-				// regarder si ce statut est autorise pour l'auteur
386
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
387
-
388
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389
-					// sinon l’auteur en session
390
-					include_spip('inc/securiser_action');
391
-					if ($desc = decrire_token_previsu()) {
392
-						$id_auteur = $desc['id_auteur'];
393
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
394
-						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
395
-					} else {
396
-						$id_auteur = null;
397
-					}
398
-
399
-					if (!$id_auteur) {
400
-						return false;
401
-					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
402
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
403
-					} elseif (!sql_countsel(
404
-						'spip_auteurs_liens',
405
-						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
406
-					)) {
407
-						return false;
408
-					} // pas auteur de cet objet => NIET
409
-				} elseif (!in_array($opt[$champ], $previsu)) {
410
-					// le statut n'est pas dans ceux definis par la previsu => NIET
411
-					return false;
412
-				}
413
-			}
414
-		}
415
-	}
416
-
417
-	return true;
367
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
368
+    if (!$type) {
369
+        return true;
370
+    }
371
+
372
+    include_spip('base/objets');
373
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
374
+    if (isset($infos['statut'])) {
375
+        foreach ($infos['statut'] as $c) {
376
+            if (isset($c['publie'])) {
377
+                if (!isset($c['previsu'])) {
378
+                    return false;
379
+                } // pas de previsu definie => NIET
380
+                $champ = $c['champ'];
381
+                if (!isset($opt[$champ])) {
382
+                    return false;
383
+                } // pas de champ passe a la demande => NIET
384
+                $previsu = explode(',', $c['previsu']);
385
+                // regarder si ce statut est autorise pour l'auteur
386
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
387
+
388
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389
+                    // sinon l’auteur en session
390
+                    include_spip('inc/securiser_action');
391
+                    if ($desc = decrire_token_previsu()) {
392
+                        $id_auteur = $desc['id_auteur'];
393
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
394
+                        $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
395
+                    } else {
396
+                        $id_auteur = null;
397
+                    }
398
+
399
+                    if (!$id_auteur) {
400
+                        return false;
401
+                    } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
402
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
403
+                    } elseif (!sql_countsel(
404
+                        'spip_auteurs_liens',
405
+                        'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
406
+                    )) {
407
+                        return false;
408
+                    } // pas auteur de cet objet => NIET
409
+                } elseif (!in_array($opt[$champ], $previsu)) {
410
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
411
+                    return false;
412
+                }
413
+            }
414
+        }
415
+    }
416
+
417
+    return true;
418 418
 }
419 419
 
420 420
 /**
@@ -428,47 +428,47 @@  discard block
 block discarded – undo
428 428
  * @return bool          true s'il a le droit, false sinon
429 429
  **/
430 430
 function autoriser_changerlangue_dist($faire, $type, $id, $qui, $opt) {
431
-	$multi_objets = explode(',', lire_config('multi_objets'));
432
-	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
433
-	$table = table_objet_sql($type);
434
-	if (in_array($table, $multi_objets)
435
-		or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
436
-		$multi_secteurs = lire_config('multi_secteurs');
437
-		$champs = objet_info($type, 'field');
438
-		if ($multi_secteurs == 'oui'
439
-			and array_key_exists('id_rubrique', $champs)) {
440
-			// multilinguisme par secteur et objet rattaché à une rubrique
441
-			$primary = id_table_objet($type);
442
-			if ($table != 'spip_rubriques') {
443
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
444
-			} else {
445
-				$id_rubrique = $id;
446
-			}
447
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
448
-			if (!$id_secteur > 0) {
449
-				$id_secteur = $id_rubrique;
450
-			}
451
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
453
-			if ($langue_secteur != $langue_objet) {
454
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
455
-				return true;
456
-			}
457
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458
-				return false;
459
-			} else {
460
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
461
-				if ($id_parent != 0) {
462
-					// sous-rubriques : pas de choix de langue
463
-					return false;
464
-				}
465
-			}
466
-		}
467
-	} else {
468
-		return false;
469
-	}
470
-
471
-	return autoriser('modifier', $type, $id, $qui, $opt);
431
+    $multi_objets = explode(',', lire_config('multi_objets'));
432
+    $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
433
+    $table = table_objet_sql($type);
434
+    if (in_array($table, $multi_objets)
435
+        or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
436
+        $multi_secteurs = lire_config('multi_secteurs');
437
+        $champs = objet_info($type, 'field');
438
+        if ($multi_secteurs == 'oui'
439
+            and array_key_exists('id_rubrique', $champs)) {
440
+            // multilinguisme par secteur et objet rattaché à une rubrique
441
+            $primary = id_table_objet($type);
442
+            if ($table != 'spip_rubriques') {
443
+                $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
444
+            } else {
445
+                $id_rubrique = $id;
446
+            }
447
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
448
+            if (!$id_secteur > 0) {
449
+                $id_secteur = $id_rubrique;
450
+            }
451
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
453
+            if ($langue_secteur != $langue_objet) {
454
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
455
+                return true;
456
+            }
457
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458
+                return false;
459
+            } else {
460
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
461
+                if ($id_parent != 0) {
462
+                    // sous-rubriques : pas de choix de langue
463
+                    return false;
464
+                }
465
+            }
466
+        }
467
+    } else {
468
+        return false;
469
+    }
470
+
471
+    return autoriser('modifier', $type, $id, $qui, $opt);
472 472
 }
473 473
 
474 474
 /**
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
  * @return bool          true s'il a le droit, false sinon
483 483
  **/
484 484
 function autoriser_changertraduction_dist($faire, $type, $id, $qui, $opt) {
485
-	return autoriser('modifier', $type, $id, $qui, $opt);
485
+    return autoriser('modifier', $type, $id, $qui, $opt);
486 486
 }
487 487
 
488 488
 /**
@@ -496,41 +496,41 @@  discard block
 block discarded – undo
496 496
  * @return bool          true s'il a le droit, false sinon
497 497
  **/
498 498
 function autoriser_dater_dist($faire, $type, $id, $qui, $opt) {
499
-	$table = table_objet($type);
500
-	$trouver_table = charger_fonction('trouver_table', 'base');
501
-	$desc = $trouver_table($table);
502
-	if (!$desc) {
503
-		return false;
504
-	}
499
+    $table = table_objet($type);
500
+    $trouver_table = charger_fonction('trouver_table', 'base');
501
+    $desc = $trouver_table($table);
502
+    if (!$desc) {
503
+        return false;
504
+    }
505 505
 	
506
-	if (!isset($opt['statut'])) {
507
-		if (isset($desc['field']['statut'])) {
508
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
509
-		} else {
510
-			$statut = 'publie';
511
-		} // pas de statut => publie
512
-	} else {
513
-		$statut = $opt['statut'];
514
-	}
506
+    if (!isset($opt['statut'])) {
507
+        if (isset($desc['field']['statut'])) {
508
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
509
+        } else {
510
+            $statut = 'publie';
511
+        } // pas de statut => publie
512
+    } else {
513
+        $statut = $opt['statut'];
514
+    }
515 515
 	
516
-	// Liste des statuts publiés pour cet objet
517
-	if (isset($desc['statut'][0]['publie'])) {
518
-		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
519
-	}
520
-	// Sinon en dur le statut "publie"
521
-	else {
522
-		$statuts_publies = array('publie');
523
-	}
516
+    // Liste des statuts publiés pour cet objet
517
+    if (isset($desc['statut'][0]['publie'])) {
518
+        $statuts_publies = explode(',', $desc['statut'][0]['publie']);
519
+    }
520
+    // Sinon en dur le statut "publie"
521
+    else {
522
+        $statuts_publies = array('publie');
523
+    }
524 524
 	
525
-	if (
526
-		in_array($statut, $statuts_publies)
527
-		// Ou cas particulier géré en dur ici pour les articles
528
-		or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
529
-	) {
530
-		return autoriser('modifier', $type, $id);
531
-	}
525
+    if (
526
+        in_array($statut, $statuts_publies)
527
+        // Ou cas particulier géré en dur ici pour les articles
528
+        or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
529
+    ) {
530
+        return autoriser('modifier', $type, $id);
531
+    }
532 532
 
533
-	return false;
533
+    return false;
534 534
 }
535 535
 
536 536
 /**
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
  * @return bool          true s'il a le droit, false sinon
548 548
  **/
549 549
 function autoriser_instituer_dist($faire, $type, $id, $qui, $opt) {
550
-	return autoriser('modifier', $type, $id, $qui, $opt);
550
+    return autoriser('modifier', $type, $id, $qui, $opt);
551 551
 }
552 552
 
553 553
 /**
@@ -563,12 +563,12 @@  discard block
 block discarded – undo
563 563
  * @return bool          true s'il a le droit, false sinon
564 564
  **/
565 565
 function autoriser_rubrique_publierdans_dist($faire, $type, $id, $qui, $opt) {
566
-	return
567
-		($qui['statut'] == '0minirezo')
568
-		and (
569
-			!$qui['restreint'] or !$id
570
-			or in_array($id, $qui['restreint'])
571
-		);
566
+    return
567
+        ($qui['statut'] == '0minirezo')
568
+        and (
569
+            !$qui['restreint'] or !$id
570
+            or in_array($id, $qui['restreint'])
571
+        );
572 572
 }
573 573
 
574 574
 /**
@@ -584,10 +584,10 @@  discard block
 block discarded – undo
584 584
  * @return bool          true s'il a le droit, false sinon
585 585
  **/
586 586
 function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) {
587
-	return
588
-		((!$id and autoriser('defaut', null, null, $qui, $opt))
589
-			or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
590
-		);
587
+    return
588
+        ((!$id and autoriser('defaut', null, null, $qui, $opt))
589
+            or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
590
+        );
591 591
 }
592 592
 
593 593
 /**
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
  * @return bool          true s'il a le droit, false sinon
604 604
  **/
605 605
 function autoriser_rubrique_creerrubriquedans_dist($faire, $type, $id, $qui, $opt) {
606
-	return
607
-		($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
608
-		and autoriser('voir', 'rubrique', $id)
609
-		and autoriser('publierdans', 'rubrique', $id);
606
+    return
607
+        ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
608
+        and autoriser('voir', 'rubrique', $id)
609
+        and autoriser('publierdans', 'rubrique', $id);
610 610
 }
611 611
 
612 612
 /**
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
  * @return bool          true s'il a le droit, false sinon
623 623
  **/
624 624
 function autoriser_rubrique_creerarticledans_dist($faire, $type, $id, $qui, $opt) {
625
-	return
626
-		$id
627
-		and autoriser('voir', 'rubrique', $id)
628
-		and autoriser('creer', 'article');
625
+    return
626
+        $id
627
+        and autoriser('voir', 'rubrique', $id)
628
+        and autoriser('creer', 'article');
629 629
 }
630 630
 
631 631
 
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
  * @return bool          true s'il a le droit, false sinon
643 643
  **/
644 644
 function autoriser_rubrique_modifier_dist($faire, $type, $id, $qui, $opt) {
645
-	return
646
-		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
645
+    return
646
+        autoriser('publierdans', 'rubrique', $id, $qui, $opt);
647 647
 }
648 648
 
649 649
 /**
@@ -659,29 +659,29 @@  discard block
 block discarded – undo
659 659
  * @return bool          true s'il a le droit, false sinon
660 660
  **/
661 661
 function autoriser_rubrique_supprimer_dist($faire, $type, $id, $qui, $opt) {
662
-	if (!$id = intval($id)) {
663
-		return false;
664
-	}
662
+    if (!$id = intval($id)) {
663
+        return false;
664
+    }
665 665
 
666
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
667
-		return false;
668
-	}
666
+    if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
667
+        return false;
668
+    }
669 669
 
670
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
671
-		return false;
672
-	}
670
+    if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
671
+        return false;
672
+    }
673 673
 
674
-	$compte = pipeline(
675
-		'objet_compte_enfants',
676
-		array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
677
-	);
678
-	foreach ($compte as $objet => $n) {
679
-		if ($n) {
680
-			return false;
681
-		}
682
-	}
674
+    $compte = pipeline(
675
+        'objet_compte_enfants',
676
+        array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
677
+    );
678
+    foreach ($compte as $objet => $n) {
679
+        if ($n) {
680
+            return false;
681
+        }
682
+    }
683 683
 
684
-	return autoriser('modifier', 'rubrique', $id);
684
+    return autoriser('modifier', 'rubrique', $id);
685 685
 }
686 686
 
687 687
 
@@ -699,20 +699,20 @@  discard block
 block discarded – undo
699 699
  * @return bool          true s'il a le droit, false sinon
700 700
  **/
701 701
 function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
702
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
702
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
703 703
 
704
-	return
705
-		$r
706
-		and
707
-		(
708
-			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
709
-			or (
710
-				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
711
-				and in_array($qui['statut'], array('0minirezo', '1comite'))
712
-				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
714
-			)
715
-		);
704
+    return
705
+        $r
706
+        and
707
+        (
708
+            autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
709
+            or (
710
+                (!isset($opt['statut']) or $opt['statut'] !== 'publie')
711
+                and in_array($qui['statut'], array('0minirezo', '1comite'))
712
+                and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
+                and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
714
+            )
715
+        );
716 716
 }
717 717
 
718 718
 /**
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
  * @return bool          true s'il a le droit, false sinon
729 729
  **/
730 730
 function autoriser_article_creer_dist($faire, $type, $id, $qui, $opt) {
731
-	return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
731
+    return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
732 732
 }
733 733
 
734 734
 /**
@@ -748,28 +748,28 @@  discard block
 block discarded – undo
748 748
  * @return bool          true s'il a le droit, false sinon
749 749
  */
750 750
 function autoriser_article_voir_dist($faire, $type, $id, $qui, $opt) {
751
-	if ($qui['statut'] == '0minirezo') {
752
-		return true;
753
-	}
754
-	// cas des articles : depend du statut de l'article et de l'auteur
755
-	if (isset($opt['statut'])) {
756
-		$statut = $opt['statut'];
757
-	} else {
758
-		if (!$id) {
759
-			return false;
760
-		}
761
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
762
-	}
763
-
764
-	return
765
-		// si on est pas auteur de l'article,
766
-		// seuls les propose et publies sont visibles
767
-		in_array($statut, array('prop', 'publie'))
768
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
769
-		or
770
-		($id
771
-			and $qui['id_auteur']
772
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
751
+    if ($qui['statut'] == '0minirezo') {
752
+        return true;
753
+    }
754
+    // cas des articles : depend du statut de l'article et de l'auteur
755
+    if (isset($opt['statut'])) {
756
+        $statut = $opt['statut'];
757
+    } else {
758
+        if (!$id) {
759
+            return false;
760
+        }
761
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
762
+    }
763
+
764
+    return
765
+        // si on est pas auteur de l'article,
766
+        // seuls les propose et publies sont visibles
767
+        in_array($statut, array('prop', 'publie'))
768
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
769
+        or
770
+        ($id
771
+            and $qui['id_auteur']
772
+            and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
773 773
 }
774 774
 
775 775
 
@@ -786,22 +786,22 @@  discard block
 block discarded – undo
786 786
  * @return bool          true s'il a le droit, false sinon
787 787
  **/
788 788
 function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
789
-	# securite, mais on aurait pas du arriver ici !
790
-	if (function_exists($f = 'autoriser_' . $type . '_voir')
791
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
792
-		return $f($faire, $type, $id, $qui, $opt);
793
-	}
789
+    # securite, mais on aurait pas du arriver ici !
790
+    if (function_exists($f = 'autoriser_' . $type . '_voir')
791
+        or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
792
+        return $f($faire, $type, $id, $qui, $opt);
793
+    }
794 794
 
795
-	if ($qui['statut'] == '0minirezo') {
796
-		return true;
797
-	}
798
-	// admins et redacteurs peuvent voir un auteur
799
-	if ($type == 'auteur') {
800
-		return in_array($qui['statut'], array('0minirezo', '1comite'));
801
-	}
802
-	// sinon par defaut tout est visible
803
-	// sauf cas particuliers traites separemment (ie article)
804
-	return true;
795
+    if ($qui['statut'] == '0minirezo') {
796
+        return true;
797
+    }
798
+    // admins et redacteurs peuvent voir un auteur
799
+    if ($type == 'auteur') {
800
+        return in_array($qui['statut'], array('0minirezo', '1comite'));
801
+    }
802
+    // sinon par defaut tout est visible
803
+    // sauf cas particuliers traites separemment (ie article)
804
+    return true;
805 805
 }
806 806
 
807 807
 
@@ -822,12 +822,12 @@  discard block
 block discarded – undo
822 822
  * @return bool          true s'il a le droit, false sinon
823 823
  **/
824 824
 function autoriser_webmestre_dist($faire, $type, $id, $qui, $opt) {
825
-	return
826
-		(defined('_ID_WEBMESTRES') ?
827
-			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
828
-			: $qui['webmestre'] == 'oui')
829
-		and $qui['statut'] == '0minirezo'
830
-		and !$qui['restreint'];
825
+    return
826
+        (defined('_ID_WEBMESTRES') ?
827
+            in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
828
+            : $qui['webmestre'] == 'oui')
829
+        and $qui['statut'] == '0minirezo'
830
+        and !$qui['restreint'];
831 831
 }
832 832
 
833 833
 /**
@@ -843,9 +843,9 @@  discard block
 block discarded – undo
843 843
  * @return bool          true s'il a le droit, false sinon
844 844
  **/
845 845
 function autoriser_configurer_dist($faire, $type, $id, $qui, $opt) {
846
-	return
847
-		$qui['statut'] == '0minirezo'
848
-		and !$qui['restreint'];
846
+    return
847
+        $qui['statut'] == '0minirezo'
848
+        and !$qui['restreint'];
849 849
 }
850 850
 
851 851
 /**
@@ -861,8 +861,8 @@  discard block
 block discarded – undo
861 861
  * @return bool          true s'il a le droit, false sinon
862 862
  **/
863 863
 function autoriser_sauvegarder_dist($faire, $type, $id, $qui, $opt) {
864
-	return
865
-		$qui['statut'] == '0minirezo';
864
+    return
865
+        $qui['statut'] == '0minirezo';
866 866
 }
867 867
 
868 868
 /**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
  * @return bool          true s'il a le droit, false sinon
879 879
  **/
880 880
 function autoriser_detruire_dist($faire, $type, $id, $qui, $opt) {
881
-	return
882
-		autoriser('webmestre', null, null, $qui, $opt);
881
+    return
882
+        autoriser('webmestre', null, null, $qui, $opt);
883 883
 }
884 884
 
885 885
 /**
@@ -896,20 +896,20 @@  discard block
 block discarded – undo
896 896
  * @return bool          true s'il a le droit, false sinon
897 897
  **/
898 898
 function autoriser_auteur_previsualiser_dist($faire, $type, $id, $qui, $opt) {
899
-	// les admins peuvent "previsualiser" une page auteur
900
-	if ($qui['statut'] == '0minirezo'
901
-		and !$qui['restreint']
902
-	) {
903
-		return true;
904
-	}
905
-	// "Voir en ligne" si l'auteur a un article publie
906
-	$n = sql_fetsel(
907
-		'A.id_article',
908
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
910
-	);
899
+    // les admins peuvent "previsualiser" une page auteur
900
+    if ($qui['statut'] == '0minirezo'
901
+        and !$qui['restreint']
902
+    ) {
903
+        return true;
904
+    }
905
+    // "Voir en ligne" si l'auteur a un article publie
906
+    $n = sql_fetsel(
907
+        'A.id_article',
908
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
910
+    );
911 911
 
912
-	return $n ? true : false;
912
+    return $n ? true : false;
913 913
 }
914 914
 
915 915
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @return bool          true s'il a le droit, false sinon
938 938
  **/
939 939
 function autoriser_auteur_creer_dist($faire, $type, $id, $qui, $opt) {
940
-	return ($qui['statut'] == '0minirezo');
940
+    return ($qui['statut'] == '0minirezo');
941 941
 }
942 942
 
943 943
 
@@ -957,78 +957,78 @@  discard block
 block discarded – undo
957 957
  **/
958 958
 function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) {
959 959
 
960
-	// Ni admin ni redacteur => non
961
-	if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
962
-		return false;
963
-	}
964
-
965
-	// Un redacteur peut modifier ses propres donnees mais ni son login/email
966
-	// ni son statut (qui sont le cas echeant passes comme option)
967
-	if ($qui['statut'] == '1comite') {
968
-		if (!empty($opt['webmestre'])) {
969
-			return false;
970
-		} elseif (
971
-			!empty($opt['statut'])
972
-			or !empty($opt['restreintes'])
973
-			or !empty($opt['email'])
974
-		) {
975
-			return false;
976
-		} elseif ($id == $qui['id_auteur']) {
977
-			return true;
978
-		} else {
979
-			return false;
980
-		}
981
-	}
982
-
983
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
984
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
985
-	if ($qui['restreint']) {
986
-		if (isset($opt['webmestre']) and $opt['webmestre']) {
987
-			return false;
988
-		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
989
-			or (isset($opt['restreintes']) and $opt['restreintes'])
990
-		) {
991
-			return false;
992
-		} else {
993
-			if ($id == $qui['id_auteur']) {
994
-				if (isset($opt['statut']) and $opt['statut']) {
995
-					return false;
996
-				} else {
997
-					return true;
998
-				}
999
-			} else {
1000
-				if ($id_auteur = intval($id)) {
1001
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1002
-					if ($t and $t['statut'] != '0minirezo') {
1003
-						return true;
1004
-					} else {
1005
-						return false;
1006
-					}
1007
-				} // id = 0 => creation
1008
-				else {
1009
-					return true;
1010
-				}
1011
-			}
1012
-		}
1013
-	}
1014
-
1015
-	// Un admin complet fait ce qu'il veut
1016
-	// sauf se degrader
1017
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1018
-		return false;
1019
-	} elseif (isset($opt['webmestre'])
1020
-				and $opt['webmestre']
1021
-				and (defined('_ID_WEBMESTRES')
1022
-				or !autoriser('webmestre'))) {
1023
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1024
-		// ou si les webmestres sont fixes par constante (securite)
1025
-		return false;
1026
-	} // et modifier un webmestre si il ne l'est pas lui meme
1027
-	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1028
-		return false;
1029
-	} else {
1030
-		return true;
1031
-	}
960
+    // Ni admin ni redacteur => non
961
+    if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
962
+        return false;
963
+    }
964
+
965
+    // Un redacteur peut modifier ses propres donnees mais ni son login/email
966
+    // ni son statut (qui sont le cas echeant passes comme option)
967
+    if ($qui['statut'] == '1comite') {
968
+        if (!empty($opt['webmestre'])) {
969
+            return false;
970
+        } elseif (
971
+            !empty($opt['statut'])
972
+            or !empty($opt['restreintes'])
973
+            or !empty($opt['email'])
974
+        ) {
975
+            return false;
976
+        } elseif ($id == $qui['id_auteur']) {
977
+            return true;
978
+        } else {
979
+            return false;
980
+        }
981
+    }
982
+
983
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
984
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
985
+    if ($qui['restreint']) {
986
+        if (isset($opt['webmestre']) and $opt['webmestre']) {
987
+            return false;
988
+        } elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
989
+            or (isset($opt['restreintes']) and $opt['restreintes'])
990
+        ) {
991
+            return false;
992
+        } else {
993
+            if ($id == $qui['id_auteur']) {
994
+                if (isset($opt['statut']) and $opt['statut']) {
995
+                    return false;
996
+                } else {
997
+                    return true;
998
+                }
999
+            } else {
1000
+                if ($id_auteur = intval($id)) {
1001
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1002
+                    if ($t and $t['statut'] != '0minirezo') {
1003
+                        return true;
1004
+                    } else {
1005
+                        return false;
1006
+                    }
1007
+                } // id = 0 => creation
1008
+                else {
1009
+                    return true;
1010
+                }
1011
+            }
1012
+        }
1013
+    }
1014
+
1015
+    // Un admin complet fait ce qu'il veut
1016
+    // sauf se degrader
1017
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1018
+        return false;
1019
+    } elseif (isset($opt['webmestre'])
1020
+                and $opt['webmestre']
1021
+                and (defined('_ID_WEBMESTRES')
1022
+                or !autoriser('webmestre'))) {
1023
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1024
+        // ou si les webmestres sont fixes par constante (securite)
1025
+        return false;
1026
+    } // et modifier un webmestre si il ne l'est pas lui meme
1027
+    elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1028
+        return false;
1029
+    } else {
1030
+        return true;
1031
+    }
1032 1032
 }
1033 1033
 
1034 1034
 
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
  * @return bool          true s'il a le droit, false sinon
1046 1046
  **/
1047 1047
 function autoriser_associerauteurs_dist($faire, $type, $id, $qui, $opt) {
1048
-	return autoriser('modifier', $type, $id, $qui, $opt);
1048
+    return autoriser('modifier', $type, $id, $qui, $opt);
1049 1049
 }
1050 1050
 
1051 1051
 
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
  * @return bool          true s'il a le droit, false sinon
1063 1063
  **/
1064 1064
 function autoriser_chargerftp_dist($faire, $type, $id, $qui, $opt) {
1065
-	return $qui['statut'] == '0minirezo';
1065
+    return $qui['statut'] == '0minirezo';
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
  * @return bool          true s'il a le droit, false sinon
1079 1079
  **/
1080 1080
 function autoriser_debug_dist($faire, $type, $id, $qui, $opt) {
1081
-	return $qui['statut'] == '0minirezo';
1081
+    return $qui['statut'] == '0minirezo';
1082 1082
 }
1083 1083
 
1084 1084
 /**
@@ -1095,52 +1095,52 @@  discard block
 block discarded – undo
1095 1095
  * @return array          Liste des rubriques
1096 1096
  **/
1097 1097
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1098
-	static $restreint = array();
1099
-
1100
-	if (!$id_auteur = intval($id_auteur)) {
1101
-		return array();
1102
-	}
1103
-	if ($raz) {
1104
-		unset($restreint[$id_auteur]);
1105
-	} elseif (isset($restreint[$id_auteur])) {
1106
-		return $restreint[$id_auteur];
1107
-	}
1108
-
1109
-	$rubriques = array();
1110
-	if ((!isset($GLOBALS['meta']['version_installee'])
1111
-		or $GLOBALS['meta']['version_installee'] > 16428)
1112
-		and $r = sql_allfetsel(
1113
-			'id_objet',
1114
-			'spip_auteurs_liens',
1115
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1116
-		)
1117
-		and count($r)
1118
-	) {
1119
-		$r = array_column($r, 'id_objet');
1120
-
1121
-		// recuperer toute la branche, au format chaine enumeration
1122
-		include_spip('inc/rubriques');
1123
-		$r = calcul_branche_in($r);
1124
-		$r = explode(',', $r);
1125
-
1126
-		// passer les rubriques en index, elimine les doublons
1127
-		$r = array_flip($r);
1128
-		// recuperer les index seuls
1129
-		$r = array_keys($r);
1130
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1131
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1132
-		$rubriques = array_combine($r, $r);
1133
-	}
1134
-
1135
-	// Affecter l'auteur session le cas echeant
1136
-	if (isset($GLOBALS['visiteur_session']['id_auteur'])
1137
-		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1138
-	) {
1139
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1140
-	}
1141
-
1142
-
1143
-	return $restreint[$id_auteur] = $rubriques;
1098
+    static $restreint = array();
1099
+
1100
+    if (!$id_auteur = intval($id_auteur)) {
1101
+        return array();
1102
+    }
1103
+    if ($raz) {
1104
+        unset($restreint[$id_auteur]);
1105
+    } elseif (isset($restreint[$id_auteur])) {
1106
+        return $restreint[$id_auteur];
1107
+    }
1108
+
1109
+    $rubriques = array();
1110
+    if ((!isset($GLOBALS['meta']['version_installee'])
1111
+        or $GLOBALS['meta']['version_installee'] > 16428)
1112
+        and $r = sql_allfetsel(
1113
+            'id_objet',
1114
+            'spip_auteurs_liens',
1115
+            'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1116
+        )
1117
+        and count($r)
1118
+    ) {
1119
+        $r = array_column($r, 'id_objet');
1120
+
1121
+        // recuperer toute la branche, au format chaine enumeration
1122
+        include_spip('inc/rubriques');
1123
+        $r = calcul_branche_in($r);
1124
+        $r = explode(',', $r);
1125
+
1126
+        // passer les rubriques en index, elimine les doublons
1127
+        $r = array_flip($r);
1128
+        // recuperer les index seuls
1129
+        $r = array_keys($r);
1130
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1131
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1132
+        $rubriques = array_combine($r, $r);
1133
+    }
1134
+
1135
+    // Affecter l'auteur session le cas echeant
1136
+    if (isset($GLOBALS['visiteur_session']['id_auteur'])
1137
+        and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1138
+    ) {
1139
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1140
+    }
1141
+
1142
+
1143
+    return $restreint[$id_auteur] = $rubriques;
1144 1144
 }
1145 1145
 
1146 1146
 /**
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
  * @return bool          true s'il a le droit, false sinon
1157 1157
  **/
1158 1158
 function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) {
1159
-	return autoriser('previsualiser');
1159
+    return autoriser('previsualiser');
1160 1160
 }
1161 1161
 
1162 1162
 /**
@@ -1172,7 +1172,7 @@  discard block
 block discarded – undo
1172 1172
  * @return bool          true s'il a le droit, false sinon
1173 1173
  **/
1174 1174
 function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) {
1175
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1175
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1188,8 +1188,8 @@  discard block
 block discarded – undo
1188 1188
  * @return bool          true s'il a le droit, false sinon
1189 1189
  **/
1190 1190
 function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) {
1191
-	return (($id == $qui['id_auteur']) or
1192
-		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1191
+    return (($id == $qui['id_auteur']) or
1192
+        (($qui['statut'] == '0minirezo') and !$qui['restreint']));
1193 1193
 }
1194 1194
 
1195 1195
 /**
@@ -1205,8 +1205,8 @@  discard block
 block discarded – undo
1205 1205
  * @return bool          true s'il a le droit, false sinon
1206 1206
  **/
1207 1207
 function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) {
1208
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1209
-	return autoriser('modifier', $type, $id, $qui, $opt);
1208
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1209
+    return autoriser('modifier', $type, $id, $qui, $opt);
1210 1210
 }
1211 1211
 
1212 1212
 
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
  * @return bool          true
1225 1225
  **/
1226 1226
 function autoriser_ok_dist($faire, $type, $id, $qui, $opt) {
1227
-	return true;
1227
+    return true;
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
  * @return bool          false
1242 1242
  **/
1243 1243
 function autoriser_niet_dist($faire, $type, $id, $qui, $opt) {
1244
-	return false;
1244
+    return false;
1245 1245
 }
1246 1246
 
1247 1247
 /**
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  * @return bool          false
1258 1258
  **/
1259 1259
 function autoriser_base_reparer_dist($faire, $type, $id, $qui, $opt) {
1260
-	if (!autoriser('detruire') or _request('reinstall')) {
1261
-		return false;
1262
-	}
1260
+    if (!autoriser('detruire') or _request('reinstall')) {
1261
+        return false;
1262
+    }
1263 1263
 
1264
-	return true;
1264
+    return true;
1265 1265
 }
1266 1266
 
1267 1267
 /**
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
  * @return bool          true s'il a le droit, false sinon
1278 1278
  **/
1279 1279
 function autoriser_infosperso_dist($faire, $type, $id, $qui, $opt) {
1280
-	return true;
1280
+    return true;
1281 1281
 }
1282 1282
 
1283 1283
 /**
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
  * @return bool          true s'il a le droit, false sinon
1294 1294
  **/
1295 1295
 function autoriser_langage_configurer_dist($faire, $type, $id, $qui, $opt) {
1296
-	return true;
1296
+    return true;
1297 1297
 }
1298 1298
 
1299 1299
 /**
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
  * @return bool          true s'il a le droit, false sinon
1310 1310
  **/
1311 1311
 function autoriser_configurerlangage_dist($faire, $type, $id, $qui, $opt) {
1312
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1312
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1313 1313
 }
1314 1314
 
1315 1315
 /**
@@ -1325,7 +1325,7 @@  discard block
 block discarded – undo
1325 1325
  * @return bool          true s'il a le droit, false sinon
1326 1326
  **/
1327 1327
 function autoriser_preferences_configurer_dist($faire, $type, $id, $qui, $opt) {
1328
-	return true;
1328
+    return true;
1329 1329
 }
1330 1330
 
1331 1331
 /**
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
  * @return bool          true s'il a le droit, false sinon
1342 1342
  **/
1343 1343
 function autoriser_configurerpreferences_dist($faire, $type, $id, $qui, $opt) {
1344
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1344
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1345 1345
 }
1346 1346
 
1347 1347
 /**
@@ -1357,8 +1357,8 @@  discard block
 block discarded – undo
1357 1357
  * @return bool          true s'il a le droit, false sinon
1358 1358
  **/
1359 1359
 function autoriser_menudeveloppement_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1360
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1361
-		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1360
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1361
+        and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1362 1362
 }
1363 1363
 
1364 1364
 /**
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
  * @return bool          true s'il a le droit, false sinon
1376 1376
  **/
1377 1377
 function autoriser_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1378
-	return true;
1378
+    return true;
1379 1379
 }
1380 1380
 
1381 1381
 /**
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
  * @return bool          true s'il a le droit, false sinon
1392 1392
  **/
1393 1393
 function autoriser_auteurs_voir_dist($faire, $type, $id, $qui, $opt) {
1394
-	return true;
1394
+    return true;
1395 1395
 }
1396 1396
 
1397 1397
 /**
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
  * @return bool          true s'il a le droit, false sinon
1408 1408
  **/
1409 1409
 function autoriser_auteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1410
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1410
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1411 1411
 }
1412 1412
 
1413 1413
 /**
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
  * @return bool          true s'il a le droit, false sinon
1424 1424
  **/
1425 1425
 function autoriser_articles_voir_dist($faire, $type, $id, $qui, $opt) {
1426
-	return true;
1426
+    return true;
1427 1427
 }
1428 1428
 
1429 1429
 /**
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
  * @return bool          true s'il a le droit, false sinon
1440 1440
  **/
1441 1441
 function autoriser_articles_menu_dist($faire, $type, $id, $qui, $opt) {
1442
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1442
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1443 1443
 }
1444 1444
 
1445 1445
 /**
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
  * @return bool          true s'il a le droit, false sinon
1456 1456
  **/
1457 1457
 function autoriser_rubriques_voir_dist($faire, $type, $id, $qui, $opt) {
1458
-	return true;
1458
+    return true;
1459 1459
 }
1460 1460
 
1461 1461
 /**
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
  * @return bool          true s'il a le droit, false sinon
1472 1472
  **/
1473 1473
 function autoriser_rubriques_menu_dist($faire, $type, $id, $qui, $opt) {
1474
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1474
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1475 1475
 }
1476 1476
 
1477 1477
 /**
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
  * @return bool          true s'il a le droit, false sinon
1488 1488
  **/
1489 1489
 function autoriser_articlecreer_menu_dist($faire, $type, $id, $qui, $opt) {
1490
-	return verifier_table_non_vide();
1490
+    return verifier_table_non_vide();
1491 1491
 }
1492 1492
 
1493 1493
 
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
  * @return bool          true s'il a le droit, false sinon
1507 1507
  **/
1508 1508
 function autoriser_auteurcreer_menu_dist($faire, $type, $id, $qui, $opt) {
1509
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1509
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1510 1510
 }
1511 1511
 
1512 1512
 /**
@@ -1522,13 +1522,13 @@  discard block
 block discarded – undo
1522 1522
  * @return bool          true s'il a le droit, false sinon
1523 1523
  **/
1524 1524
 function autoriser_visiteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1525
-	include_spip('base/abstract_sql');
1526
-	return 
1527
-		$qui['statut'] == '0minirezo' and !$qui['restreint']
1528
-		and (
1529
-			$GLOBALS['meta']["accepter_visiteurs"] != 'non'
1530
-			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1531
-		);
1525
+    include_spip('base/abstract_sql');
1526
+    return 
1527
+        $qui['statut'] == '0minirezo' and !$qui['restreint']
1528
+        and (
1529
+            $GLOBALS['meta']["accepter_visiteurs"] != 'non'
1530
+            or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1531
+        );
1532 1532
 }
1533 1533
 
1534 1534
 /**
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
  * @return bool          true s'il a le droit, false sinon
1545 1545
  **/
1546 1546
 function autoriser_suiviedito_menu_dist($faire, $type, $id, $qui, $opt) {
1547
-	return $qui['statut'] == '0minirezo';
1547
+    return $qui['statut'] == '0minirezo';
1548 1548
 }
1549 1549
 
1550 1550
 /**
@@ -1560,7 +1560,7 @@  discard block
 block discarded – undo
1560 1560
  * @return bool          true s'il a le droit, false sinon
1561 1561
  **/
1562 1562
 function autoriser_synchro_menu_dist($faire, $type, $id, $qui, $opt) {
1563
-	return $qui['statut'] == '0minirezo';
1563
+    return $qui['statut'] == '0minirezo';
1564 1564
 }
1565 1565
 
1566 1566
 /**
@@ -1688,7 +1688,7 @@  discard block
 block discarded – undo
1688 1688
  * @return bool          true s'il a le droit, false sinon
1689 1689
  **/
1690 1690
 function autoriser_queue_purger_dist($faire, $type, $id, $qui, $opt) {
1691
-	return autoriser('webmestre');
1691
+    return autoriser('webmestre');
1692 1692
 }
1693 1693
 
1694 1694
 
@@ -1706,11 +1706,11 @@  discard block
 block discarded – undo
1706 1706
  * @return bool          true s'il a le droit, false sinon
1707 1707
  **/
1708 1708
 function autoriser_echafauder_dist($faire, $type, $id, $qui, $opt) {
1709
-	if (test_espace_prive()) {
1710
-		return intval($qui['id_auteur']) ? true : false;
1711
-	} else {
1712
-		return autoriser('webmestre', '', $id, $qui, $opt);
1713
-	}
1709
+    if (test_espace_prive()) {
1710
+        return intval($qui['id_auteur']) ? true : false;
1711
+    } else {
1712
+        return autoriser('webmestre', '', $id, $qui, $opt);
1713
+    }
1714 1714
 }
1715 1715
 
1716 1716
 
@@ -1725,27 +1725,27 @@  discard block
 block discarded – undo
1725 1725
  *     Identifiants d'auteurs
1726 1726
  */
1727 1727
 function auteurs_objet($objet, $id_objet, $cond = '') {
1728
-	$objet = objet_type($objet);
1729
-	$where = array(
1730
-		'objet=' . sql_quote($objet),
1731
-		'id_objet=' . intval($id_objet)
1732
-	);
1733
-	if (!empty($cond)) {
1734
-		if (is_array($cond)) {
1735
-			$where = array_merge($where, $cond);
1736
-		} else {
1737
-			$where[] = $cond;
1738
-		}
1739
-	}
1740
-	$auteurs = sql_allfetsel(
1741
-		'id_auteur',
1742
-		'spip_auteurs_liens',
1743
-		$where
1744
-	);
1745
-	if (is_array($auteurs)) {
1746
-		return array_column($auteurs, 'id_auteur');
1747
-	}
1748
-	return array();
1728
+    $objet = objet_type($objet);
1729
+    $where = array(
1730
+        'objet=' . sql_quote($objet),
1731
+        'id_objet=' . intval($id_objet)
1732
+    );
1733
+    if (!empty($cond)) {
1734
+        if (is_array($cond)) {
1735
+            $where = array_merge($where, $cond);
1736
+        } else {
1737
+            $where[] = $cond;
1738
+        }
1739
+    }
1740
+    $auteurs = sql_allfetsel(
1741
+        'id_auteur',
1742
+        'spip_auteurs_liens',
1743
+        $where
1744
+    );
1745
+    if (is_array($auteurs)) {
1746
+        return array_column($auteurs, 'id_auteur');
1747
+    }
1748
+    return array();
1749 1749
 }
1750 1750
 
1751 1751
 /**
@@ -1759,11 +1759,11 @@  discard block
 block discarded – undo
1759 1759
  *     - false : serveur SQL indisponible
1760 1760
  */
1761 1761
 function auteurs_article($id_article, $cond = '') {
1762
-	return sql_allfetsel(
1763
-		'id_auteur',
1764
-		'spip_auteurs_liens',
1765
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1766
-	);
1762
+    return sql_allfetsel(
1763
+        'id_auteur',
1764
+        'spip_auteurs_liens',
1765
+        "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1766
+    );
1767 1767
 }
1768 1768
 
1769 1769
 
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
  */
1778 1778
 function acces_restreint_rubrique($id_rubrique) {
1779 1779
 
1780
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1780
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1781 1781
 }
1782 1782
 
1783 1783
 
@@ -1790,12 +1790,12 @@  discard block
 block discarded – undo
1790 1790
  * @return bool             true si un parent existe
1791 1791
  */
1792 1792
 function verifier_table_non_vide($table = 'spip_rubriques') {
1793
-	static $done = array();
1794
-	if (!isset($done[$table])) {
1795
-		$done[$table] = sql_countsel($table) > 0;
1796
-	}
1793
+    static $done = array();
1794
+    if (!isset($done[$table])) {
1795
+        $done[$table] = sql_countsel($table) > 0;
1796
+    }
1797 1797
 
1798
-	return $done[$table];
1798
+    return $done[$table];
1799 1799
 }
1800 1800
 
1801 1801
 /**
@@ -1820,15 +1820,15 @@  discard block
 block discarded – undo
1820 1820
  */
1821 1821
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
1822 1822
 
1823
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1824
-	switch ($s) {
1825
-		case 'info_redacteurs':
1826
-			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1827
-		case 'info_visiteurs':
1828
-			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1829
-	}
1823
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1824
+    switch ($s) {
1825
+        case 'info_redacteurs':
1826
+            return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1827
+        case 'info_visiteurs':
1828
+            return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1829
+    }
1830 1830
 
1831
-	return false;
1831
+    return false;
1832 1832
 }
1833 1833
 
1834 1834
 
@@ -1845,5 +1845,5 @@  discard block
 block discarded – undo
1845 1845
  * @return bool          true s'il a le droit, false sinon
1846 1846
  **/
1847 1847
 function autoriser_phpinfos($faire, $type, $id, $qui, $opt) {
1848
-	return autoriser('webmestre');
1848
+    return autoriser('webmestre');
1849 1849
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 // mais apres la fonction autoriser()
115 115
 if ($f = find_in_path('mes_fonctions.php')) {
116 116
 	global $dossier_squelettes;
117
-	include_once(_ROOT_CWD . $f);
117
+	include_once(_ROOT_CWD.$f);
118 118
 }
119 119
 
120 120
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149 149
 		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150 150
 	} elseif (is_numeric($qui)) {
151
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
151
+		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui);
152 152
 	}
153 153
 
154 154
 	// Admins restreints, on construit ici (pas generique mais...)
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	}
159 159
 
160 160
 	spip_log(
161
-		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
-		'autoriser' . _LOG_DEBUG
161
+		"autoriser $faire $type $id (".(isset($qui['nom']) ? $qui['nom'] : '').') ?',
162
+		'autoriser'._LOG_DEBUG
163 163
 	);
164 164
 
165 165
 	// passer par objet_type pour avoir les alias
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171 171
 		and autoriser_exception($faire, $type, $id, 'verifier')
172 172
 	) {
173
-		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
173
+		spip_log("autoriser ($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : OK Exception', 'autoriser'._LOG_DEBUG);
174 174
 		return true;
175 175
 	}
176 176
 
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
 	// autoriser_faire[_dist], autoriser_defaut[_dist]
180 180
 	$fonctions = $type
181 181
 		? array(
182
-			'autoriser_' . $type . '_' . $faire,
183
-			'autoriser_' . $type . '_' . $faire . '_dist',
184
-			'autoriser_' . $type,
185
-			'autoriser_' . $type . '_dist',
186
-			'autoriser_' . $faire,
187
-			'autoriser_' . $faire . '_dist',
182
+			'autoriser_'.$type.'_'.$faire,
183
+			'autoriser_'.$type.'_'.$faire.'_dist',
184
+			'autoriser_'.$type,
185
+			'autoriser_'.$type.'_dist',
186
+			'autoriser_'.$faire,
187
+			'autoriser_'.$faire.'_dist',
188 188
 			'autoriser_defaut',
189 189
 			'autoriser_defaut_dist'
190 190
 		)
191 191
 		: array(
192
-			'autoriser_' . $faire,
193
-			'autoriser_' . $faire . '_dist',
192
+			'autoriser_'.$faire,
193
+			'autoriser_'.$faire.'_dist',
194 194
 			'autoriser_defaut',
195 195
 			'autoriser_defaut_dist'
196 196
 		);
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 	}
204 204
 
205 205
 	spip_log(
206
-		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
-		'autoriser' . _LOG_DEBUG
206
+		"$f($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : '.($a ? 'OK' : 'niet'),
207
+		'autoriser'._LOG_DEBUG
208 208
 	);
209 209
 
210 210
 	return $a;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
327 327
 
328 328
 	// Le visiteur a-t-il un statut prevu par la config ?
329
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
329
+	if (strpos($GLOBALS['meta']['preview'], ','.$qui['statut'].',') !== false) {
330 330
 		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331 331
 	}
332 332
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				} // pas de champ passe a la demande => NIET
384 384
 				$previsu = explode(',', $c['previsu']);
385 385
 				// regarder si ce statut est autorise pour l'auteur
386
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
386
+				if (in_array($opt[$champ].'/auteur', $previsu)) {
387 387
 
388 388
 					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389 389
 					// sinon l’auteur en session
@@ -398,11 +398,11 @@  discard block
 block discarded – undo
398 398
 
399 399
 					if (!$id_auteur) {
400 400
 						return false;
401
-					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
401
+					} elseif (autoriser('previsualiser'.$opt[$champ], $type, '', $id_auteur)) {
402 402
 						// dans ce cas (admin en general), pas de filtrage sur ce statut
403 403
 					} elseif (!sql_countsel(
404 404
 						'spip_auteurs_liens',
405
-						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
405
+						'id_auteur='.intval($id_auteur).' AND objet='.sql_quote($type).' AND id_objet='.intval($id)
406 406
 					)) {
407 407
 						return false;
408 408
 					} // pas auteur de cet objet => NIET
@@ -440,16 +440,16 @@  discard block
 block discarded – undo
440 440
 			// multilinguisme par secteur et objet rattaché à une rubrique
441 441
 			$primary = id_table_objet($type);
442 442
 			if ($table != 'spip_rubriques') {
443
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
443
+				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=".intval($id));
444 444
 			} else {
445 445
 				$id_rubrique = $id;
446 446
 			}
447
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
447
+			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique));
448 448
 			if (!$id_secteur > 0) {
449 449
 				$id_secteur = $id_rubrique;
450 450
 			}
451
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
451
+			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.intval($id_secteur));
452
+			$langue_objet = sql_getfetsel('lang', "$table", "$primary=".intval($id));
453 453
 			if ($langue_secteur != $langue_objet) {
454 454
 				// configuration incohérente, on laisse l'utilisateur corriger la situation
455 455
 				return true;
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458 458
 				return false;
459 459
 			} else {
460
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
460
+				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id));
461 461
 				if ($id_parent != 0) {
462 462
 					// sous-rubriques : pas de choix de langue
463 463
 					return false;
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 	
506 506
 	if (!isset($opt['statut'])) {
507 507
 		if (isset($desc['field']['statut'])) {
508
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
508
+			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.intval($id));
509 509
 		} else {
510 510
 			$statut = 'publie';
511 511
 		} // pas de statut => publie
@@ -663,11 +663,11 @@  discard block
 block discarded – undo
663 663
 		return false;
664 664
 	}
665 665
 
666
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
666
+	if (sql_countsel('spip_rubriques', 'id_parent='.intval($id))) {
667 667
 		return false;
668 668
 	}
669 669
 
670
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
670
+	if (sql_countsel('spip_articles', 'id_rubrique='.intval($id)." AND (statut<>'poubelle')")) {
671 671
 		return false;
672 672
 	}
673 673
 
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
  * @return bool          true s'il a le droit, false sinon
700 700
  **/
701 701
 function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
702
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
702
+	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id));
703 703
 
704 704
 	return
705 705
 		$r
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
711 711
 				and in_array($qui['statut'], array('0minirezo', '1comite'))
712 712
 				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
713
+				and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])
714 714
 			)
715 715
 		);
716 716
 }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 		if (!$id) {
759 759
 			return false;
760 760
 		}
761
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
761
+		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id));
762 762
 	}
763 763
 
764 764
 	return
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 		or
770 770
 		($id
771 771
 			and $qui['id_auteur']
772
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
772
+			and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']));
773 773
 }
774 774
 
775 775
 
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
  **/
788 788
 function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
789 789
 	# securite, mais on aurait pas du arriver ici !
790
-	if (function_exists($f = 'autoriser_' . $type . '_voir')
791
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
790
+	if (function_exists($f = 'autoriser_'.$type.'_voir')
791
+		or function_exists($f = 'autoriser_'.$type.'_voir_dist')) {
792 792
 		return $f($faire, $type, $id, $qui, $opt);
793 793
 	}
794 794
 
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 	$n = sql_fetsel(
907 907
 		'A.id_article',
908 908
 		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
909
+		"A.statut='publie' AND L.id_auteur=".sql_quote($id)
910 910
 	);
911 911
 
912 912
 	return $n ? true : false;
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 		and $r = sql_allfetsel(
1113 1113
 			'id_objet',
1114 1114
 			'spip_auteurs_liens',
1115
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1115
+			'id_auteur='.intval($id_auteur)." AND objet='rubrique' AND id_objet!=0"
1116 1116
 		)
1117 1117
 		and count($r)
1118 1118
 	) {
@@ -1727,8 +1727,8 @@  discard block
 block discarded – undo
1727 1727
 function auteurs_objet($objet, $id_objet, $cond = '') {
1728 1728
 	$objet = objet_type($objet);
1729 1729
 	$where = array(
1730
-		'objet=' . sql_quote($objet),
1731
-		'id_objet=' . intval($id_objet)
1730
+		'objet='.sql_quote($objet),
1731
+		'id_objet='.intval($id_objet)
1732 1732
 	);
1733 1733
 	if (!empty($cond)) {
1734 1734
 		if (is_array($cond)) {
@@ -1762,7 +1762,7 @@  discard block
 block discarded – undo
1762 1762
 	return sql_allfetsel(
1763 1763
 		'id_auteur',
1764 1764
 		'spip_auteurs_liens',
1765
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1765
+		"objet='article' AND id_objet=".intval($id_article).($cond ? " AND $cond" : '')
1766 1766
 	);
1767 1767
 }
1768 1768
 
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  * @param string $charset
38 38
  *     Charset à charger.
39 39
  *     Par défaut (AUTO), utilise le charset du site
40
- * @return string|bool
40
+ * @return string|false
41 41
  *     - Nom du charset
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
  *
707 707
  * @param int $num
708 708
  *    Numéro de l'entité unicode
709
- * @return char
709
+ * @return string
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
Please login to merge, or discard this patch.
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 (!$trans[$complexe]) {
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
  *    true s'il a un BOM
927 927
  **/
928 928
 function bom_utf8($texte) {
929
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
929
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
930 930
 }
931 931
 
932 932
 /**
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1122 1122
 		// (un caractere utf-8 prenant au maximum n bytes)
1123 1123
 		$n = 0;
1124
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1124
+		while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) {
1125 1125
 			;
1126 1126
 		}
1127 1127
 		$c = substr($c, 0, $n * $length);
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 
1156 1156
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1157 1157
 
1158
-	return $lettre1 . spip_substr($c, 1);
1158
+	return $lettre1.spip_substr($c, 1);
1159 1159
 }
1160 1160
 
1161 1161
 /**
Please login to merge, or discard this patch.
Indentation   +702 added lines, -702 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,69 +381,69 @@  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
-				if ($order = mb_detect_order() # mb_string connait-il $charset?
408
-					and mb_detect_order($charset)
409
-				) {
410
-					$s = mb_convert_encoding($texte, 'utf-8', $charset);
411
-					if ($s && $s != $texte) {
412
-						return utf_8_to_unicode($s);
413
-					}
414
-				}
415
-				mb_detect_order($order); # remettre comme precedemment
416
-			}
417
-
418
-			// Sinon, peut-etre connaissons-nous ce charset ?
419
-			if (!isset($trans[$charset])) {
420
-				if ($cset = load_charset($charset)
421
-					and is_array($GLOBALS['CHARSET'][$cset])
422
-				) {
423
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
425
-					}
426
-				}
427
-			}
428
-			if (count($trans[$charset])) {
429
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
-			}
431
-
432
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
-			// caractere n'appartient pas au charset, mais c'est un probleme
434
-			// surtout en utf-8, gere ci-dessus)
435
-			if (test_iconv()) {
436
-				$s = iconv($charset, 'utf-32le', $texte);
437
-				if ($s) {
438
-					return utf_32_to_unicode($s);
439
-				}
440
-			}
441
-
442
-			// Au pire ne rien faire
443
-			spip_log("erreur charset '$charset' non supporte");
444
-
445
-			return $texte;
446
-	}
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
+                if ($order = mb_detect_order() # mb_string connait-il $charset?
408
+                    and mb_detect_order($charset)
409
+                ) {
410
+                    $s = mb_convert_encoding($texte, 'utf-8', $charset);
411
+                    if ($s && $s != $texte) {
412
+                        return utf_8_to_unicode($s);
413
+                    }
414
+                }
415
+                mb_detect_order($order); # remettre comme precedemment
416
+            }
417
+
418
+            // Sinon, peut-etre connaissons-nous ce charset ?
419
+            if (!isset($trans[$charset])) {
420
+                if ($cset = load_charset($charset)
421
+                    and is_array($GLOBALS['CHARSET'][$cset])
422
+                ) {
423
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
425
+                    }
426
+                }
427
+            }
428
+            if (count($trans[$charset])) {
429
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
+            }
431
+
432
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
+            // caractere n'appartient pas au charset, mais c'est un probleme
434
+            // surtout en utf-8, gere ci-dessus)
435
+            if (test_iconv()) {
436
+                $s = iconv($charset, 'utf-32le', $texte);
437
+                if ($s) {
438
+                    return utf_32_to_unicode($s);
439
+                }
440
+            }
441
+
442
+            // Au pire ne rien faire
443
+            spip_log("erreur charset '$charset' non supporte");
444
+
445
+            return $texte;
446
+    }
447 447
 }
448 448
 
449 449
 
@@ -462,44 +462,44 @@  discard block
 block discarded – undo
462 462
  *     Texte transformé dans le charset souhaité
463 463
  **/
464 464
 function unicode2charset($texte, $charset = 'AUTO') {
465
-	static $CHARSET_REVERSE;
466
-	static $trans = array();
467
-
468
-	if ($charset == 'AUTO') {
469
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
470
-	}
471
-
472
-	switch ($charset) {
473
-		case 'utf-8':
474
-			return unicode_to_utf_8($texte);
475
-			break;
476
-
477
-		default:
478
-			$charset = load_charset($charset);
479
-
480
-			if (!is_array($CHARSET_REVERSE[$charset])) {
481
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
-			}
483
-
484
-			if (!isset($trans[$charset])) {
485
-				$trans[$charset] = array();
486
-				$t = &$trans[$charset];
487
-				for ($e = 128; $e < 255; $e++) {
488
-					$h = dechex($e);
489
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
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);
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);
496
-					}
497
-				}
498
-			}
499
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
-
501
-			return $texte;
502
-	}
465
+    static $CHARSET_REVERSE;
466
+    static $trans = array();
467
+
468
+    if ($charset == 'AUTO') {
469
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
470
+    }
471
+
472
+    switch ($charset) {
473
+        case 'utf-8':
474
+            return unicode_to_utf_8($texte);
475
+            break;
476
+
477
+        default:
478
+            $charset = load_charset($charset);
479
+
480
+            if (!is_array($CHARSET_REVERSE[$charset])) {
481
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
+            }
483
+
484
+            if (!isset($trans[$charset])) {
485
+                $trans[$charset] = array();
486
+                $t = &$trans[$charset];
487
+                for ($e = 128; $e < 255; $e++) {
488
+                    $h = dechex($e);
489
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
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);
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);
496
+                    }
497
+                }
498
+            }
499
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
+
501
+            return $texte;
502
+    }
503 503
 }
504 504
 
505 505
 
@@ -517,37 +517,37 @@  discard block
 block discarded – undo
517 517
  *     Texte transformé dans le charset site
518 518
  **/
519 519
 function importer_charset($texte, $charset = 'AUTO') {
520
-	static $trans = array();
521
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
-		if (init_mb_string()) {
525
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
526
-				and mb_detect_order($charset)
527
-			) {
528
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
529
-			}
530
-			mb_detect_order($order); # remettre comme precedemment
531
-			return $s;
532
-		}
533
-		// Sinon, peut-etre connaissons-nous ce charset ?
534
-		if (!isset($trans[$charset])) {
535
-			if ($cset = load_charset($charset)
536
-				and is_array($GLOBALS['CHARSET'][$cset])
537
-			) {
538
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
-				}
541
-			}
542
-		}
543
-		if (count($trans[$charset])) {
544
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
-		}
546
-
547
-		return $texte;
548
-	}
549
-
550
-	return unicode2charset(charset2unicode($texte, $charset));
520
+    static $trans = array();
521
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
+        if (init_mb_string()) {
525
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
526
+                and mb_detect_order($charset)
527
+            ) {
528
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
529
+            }
530
+            mb_detect_order($order); # remettre comme precedemment
531
+            return $s;
532
+        }
533
+        // Sinon, peut-etre connaissons-nous ce charset ?
534
+        if (!isset($trans[$charset])) {
535
+            if ($cset = load_charset($charset)
536
+                and is_array($GLOBALS['CHARSET'][$cset])
537
+            ) {
538
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
+                }
541
+            }
542
+        }
543
+        if (count($trans[$charset])) {
544
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
+        }
546
+
547
+        return $texte;
548
+    }
549
+
550
+    return unicode2charset(charset2unicode($texte, $charset));
551 551
 }
552 552
 
553 553
 
@@ -563,92 +563,92 @@  discard block
 block discarded – undo
563 563
  **/
564 564
 function utf_8_to_unicode($source) {
565 565
 
566
-	// mb_string : methode rapide
567
-	if (init_mb_string()) {
568
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
-
570
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
-	}
572
-
573
-	// Sinon methode pas a pas
574
-	static $decrement;
575
-	static $shift;
576
-
577
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
-	if (!is_array($decrement)) {
579
-		// array used to figure what number to decrement from character order value
580
-		// according to number of characters used to map unicode to ascii by utf-8
581
-		$decrement[4] = 240;
582
-		$decrement[3] = 224;
583
-		$decrement[2] = 192;
584
-		$decrement[1] = 0;
585
-		// the number of bits to shift each charNum by
586
-		$shift[1][0] = 0;
587
-		$shift[2][0] = 6;
588
-		$shift[2][1] = 0;
589
-		$shift[3][0] = 12;
590
-		$shift[3][1] = 6;
591
-		$shift[3][2] = 0;
592
-		$shift[4][0] = 18;
593
-		$shift[4][1] = 12;
594
-		$shift[4][2] = 6;
595
-		$shift[4][3] = 0;
596
-	}
597
-
598
-	$pos = 0;
599
-	$len = strlen($source);
600
-	$encodedString = '';
601
-	while ($pos < $len) {
602
-		$char = '';
603
-		$ischar = false;
604
-		$asciiPos = ord(substr($source, $pos, 1));
605
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
-			// 4 chars representing one unicode character
607
-			$thisLetter = substr($source, $pos, 4);
608
-			$pos += 4;
609
-		} else {
610
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
-				// 3 chars representing one unicode character
612
-				$thisLetter = substr($source, $pos, 3);
613
-				$pos += 3;
614
-			} else {
615
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
-					// 2 chars representing one unicode character
617
-					$thisLetter = substr($source, $pos, 2);
618
-					$pos += 2;
619
-				} else {
620
-					// 1 char (lower ascii)
621
-					$thisLetter = substr($source, $pos, 1);
622
-					$pos += 1;
623
-					$char = $thisLetter;
624
-					$ischar = true;
625
-				}
626
-			}
627
-		}
628
-
629
-		if ($ischar) {
630
-			$encodedString .= $char;
631
-		} else {  // process the string representing the letter to a unicode entity
632
-			$thisLen = strlen($thisLetter);
633
-			$thisPos = 0;
634
-			$decimalCode = 0;
635
-			while ($thisPos < $thisLen) {
636
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
-				if ($thisPos == 0) {
638
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
-				} else {
641
-					$charNum = intval($thisCharOrd - 128);
642
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
-				}
644
-				$thisPos++;
645
-			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
-			$encodedString .= $encodedLetter;
648
-		}
649
-	}
650
-
651
-	return $encodedString;
566
+    // mb_string : methode rapide
567
+    if (init_mb_string()) {
568
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
+
570
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
+    }
572
+
573
+    // Sinon methode pas a pas
574
+    static $decrement;
575
+    static $shift;
576
+
577
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
+    if (!is_array($decrement)) {
579
+        // array used to figure what number to decrement from character order value
580
+        // according to number of characters used to map unicode to ascii by utf-8
581
+        $decrement[4] = 240;
582
+        $decrement[3] = 224;
583
+        $decrement[2] = 192;
584
+        $decrement[1] = 0;
585
+        // the number of bits to shift each charNum by
586
+        $shift[1][0] = 0;
587
+        $shift[2][0] = 6;
588
+        $shift[2][1] = 0;
589
+        $shift[3][0] = 12;
590
+        $shift[3][1] = 6;
591
+        $shift[3][2] = 0;
592
+        $shift[4][0] = 18;
593
+        $shift[4][1] = 12;
594
+        $shift[4][2] = 6;
595
+        $shift[4][3] = 0;
596
+    }
597
+
598
+    $pos = 0;
599
+    $len = strlen($source);
600
+    $encodedString = '';
601
+    while ($pos < $len) {
602
+        $char = '';
603
+        $ischar = false;
604
+        $asciiPos = ord(substr($source, $pos, 1));
605
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
+            // 4 chars representing one unicode character
607
+            $thisLetter = substr($source, $pos, 4);
608
+            $pos += 4;
609
+        } else {
610
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
+                // 3 chars representing one unicode character
612
+                $thisLetter = substr($source, $pos, 3);
613
+                $pos += 3;
614
+            } else {
615
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
+                    // 2 chars representing one unicode character
617
+                    $thisLetter = substr($source, $pos, 2);
618
+                    $pos += 2;
619
+                } else {
620
+                    // 1 char (lower ascii)
621
+                    $thisLetter = substr($source, $pos, 1);
622
+                    $pos += 1;
623
+                    $char = $thisLetter;
624
+                    $ischar = true;
625
+                }
626
+            }
627
+        }
628
+
629
+        if ($ischar) {
630
+            $encodedString .= $char;
631
+        } else {  // process the string representing the letter to a unicode entity
632
+            $thisLen = strlen($thisLetter);
633
+            $thisPos = 0;
634
+            $decimalCode = 0;
635
+            while ($thisPos < $thisLen) {
636
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
+                if ($thisPos == 0) {
638
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
+                } else {
641
+                    $charNum = intval($thisCharOrd - 128);
642
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
+                }
644
+                $thisPos++;
645
+            }
646
+            $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
+            $encodedString .= $encodedLetter;
648
+        }
649
+    }
650
+
651
+    return $encodedString;
652 652
 }
653 653
 
654 654
 /**
@@ -667,32 +667,32 @@  discard block
 block discarded – undo
667 667
  **/
668 668
 function utf_32_to_unicode($source) {
669 669
 
670
-	// mb_string : methode rapide
671
-	if (init_mb_string()) {
672
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
-
675
-		return str_replace(chr(0), '', $source);
676
-	}
677
-
678
-	// Sinon methode lente
679
-	$texte = '';
680
-	while ($source) {
681
-		$words = unpack("V*", substr($source, 0, 1024));
682
-		$source = substr($source, 1024);
683
-		foreach ($words as $word) {
684
-			if ($word < 128) {
685
-				$texte .= chr($word);
686
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
-			else {
688
-				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
690
-				}
691
-			}
692
-		}
693
-	}
694
-
695
-	return $texte;
670
+    // mb_string : methode rapide
671
+    if (init_mb_string()) {
672
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
+
675
+        return str_replace(chr(0), '', $source);
676
+    }
677
+
678
+    // Sinon methode lente
679
+    $texte = '';
680
+    while ($source) {
681
+        $words = unpack("V*", substr($source, 0, 1024));
682
+        $source = substr($source, 1024);
683
+        foreach ($words as $word) {
684
+            if ($word < 128) {
685
+                $texte .= chr($word);
686
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
+            else {
688
+                if ($word != 65279) {
689
+                    $texte .= '&#' . $word . ';';
690
+                }
691
+            }
692
+        }
693
+    }
694
+
695
+    return $texte;
696 696
 
697 697
 }
698 698
 
@@ -710,21 +710,21 @@  discard block
 block discarded – undo
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
713
-	$num = intval($num);
714
-	if ($num < 128) {
715
-		return chr($num);
716
-	}
717
-	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
-	}
720
-	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
-	}
723
-	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
-	}
726
-
727
-	return '';
713
+    $num = intval($num);
714
+    if ($num < 128) {
715
+        return chr($num);
716
+    }
717
+    if ($num < 2048) {
718
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
+    }
720
+    if ($num < 65536) {
721
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
+    }
723
+    if ($num < 1114112) {
724
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
+    }
726
+
727
+    return '';
728 728
 }
729 729
 
730 730
 /**
@@ -737,30 +737,30 @@  discard block
 block discarded – undo
737 737
  **/
738 738
 function unicode_to_utf_8($texte) {
739 739
 
740
-	// 1. Entites &#128; et suivantes
741
-	$vu = array();
742
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
-		$texte, $regs, PREG_SET_ORDER)) {
744
-		foreach ($regs as $reg) {
745
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
747
-			}
748
-		}
749
-	}
750
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
-
752
-	// 2. Entites > &#xFF;
753
-	//$vu = array();
754
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
-		$texte, $regs, PREG_SET_ORDER)) {
756
-		foreach ($regs as $reg) {
757
-			if (!isset($vu[$reg[0]])) {
758
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
-			}
760
-		}
761
-	}
762
-
763
-	return str_replace(array_keys($vu), array_values($vu), $texte);
740
+    // 1. Entites &#128; et suivantes
741
+    $vu = array();
742
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
+        $texte, $regs, PREG_SET_ORDER)) {
744
+        foreach ($regs as $reg) {
745
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
747
+            }
748
+        }
749
+    }
750
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
+
752
+    // 2. Entites > &#xFF;
753
+    //$vu = array();
754
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
+        $texte, $regs, PREG_SET_ORDER)) {
756
+        foreach ($regs as $reg) {
757
+            if (!isset($vu[$reg[0]])) {
758
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
+            }
760
+        }
761
+    }
762
+
763
+    return str_replace(array_keys($vu), array_values($vu), $texte);
764 764
 
765 765
 }
766 766
 
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
  *     Texte converti
774 774
  **/
775 775
 function unicode_to_javascript($texte) {
776
-	$vu = array();
777
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
-		$num = $regs[1];
779
-		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
781
-		$texte = str_replace($regs[0], $s, $texte);
782
-	}
783
-
784
-	return $texte;
776
+    $vu = array();
777
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
+        $num = $regs[1];
779
+        $vu[$num] = true;
780
+        $s = '\u' . sprintf("%04x", $num);
781
+        $texte = str_replace($regs[0], $s, $texte);
782
+    }
783
+
784
+    return $texte;
785 785
 }
786 786
 
787 787
 /**
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
  *     Texte converti
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
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);
798
-	}
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);
798
+    }
799 799
 
800
-	return $texte;
800
+    return $texte;
801 801
 }
802 802
 
803 803
 /**
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
  *     Texte converti
810 810
  **/
811 811
 function javascript_to_binary($texte) {
812
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
-	}
812
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
+    }
815 815
 
816
-	return $texte;
816
+    return $texte;
817 817
 }
818 818
 
819 819
 
@@ -831,25 +831,25 @@  discard block
 block discarded – undo
831 831
  * @return string
832 832
  */
833 833
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
834
-	static $trans;
835
-	if ($charset == 'AUTO') {
836
-		$charset = $GLOBALS['meta']['charset'];
837
-	}
838
-	if (!strlen($texte)) {
839
-		return $texte;
840
-	}
841
-
842
-	$table_translit = 'translit' . $complexe;
843
-
844
-	// 2. Translitterer grace a la table predefinie
845
-	if (!$trans[$complexe]) {
846
-		load_charset($table_translit);
847
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
848
-			$trans[$complexe][caractere_utf_8($key)] = $val;
849
-		}
850
-	}
851
-
852
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
834
+    static $trans;
835
+    if ($charset == 'AUTO') {
836
+        $charset = $GLOBALS['meta']['charset'];
837
+    }
838
+    if (!strlen($texte)) {
839
+        return $texte;
840
+    }
841
+
842
+    $table_translit = 'translit' . $complexe;
843
+
844
+    // 2. Translitterer grace a la table predefinie
845
+    if (!$trans[$complexe]) {
846
+        load_charset($table_translit);
847
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
848
+            $trans[$complexe][caractere_utf_8($key)] = $val;
849
+        }
850
+    }
851
+
852
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
853 853
 }
854 854
 
855 855
 /**
@@ -872,14 +872,14 @@  discard block
 block discarded – undo
872 872
  * @return string
873 873
  */
874 874
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
875
-	// 0. Supprimer les caracteres illegaux
876
-	include_spip('inc/filtres');
877
-	$texte = corriger_caracteres($texte);
875
+    // 0. Supprimer les caracteres illegaux
876
+    include_spip('inc/filtres');
877
+    $texte = corriger_caracteres($texte);
878 878
 
879
-	// 1. Passer le charset et les &eacute en utf-8
880
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
879
+    // 1. Passer le charset et les &eacute en utf-8
880
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
881 881
 
882
-	return translitteration_rapide($texte, $charset, $complexe);
882
+    return translitteration_rapide($texte, $charset, $complexe);
883 883
 }
884 884
 
885 885
 /**
@@ -894,17 +894,17 @@  discard block
 block discarded – undo
894 894
  * @return string
895 895
  */
896 896
 function translitteration_complexe($texte, $chiffres = false) {
897
-	$texte = translitteration($texte, 'AUTO', 'complexe');
897
+    $texte = translitteration($texte, 'AUTO', 'complexe');
898 898
 
899
-	if ($chiffres) {
900
-		$texte = preg_replace_callback(
901
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
902
-			function($m) { return translitteration_chiffree($m[0]); },
903
-			$texte
904
-		);
905
-	}
899
+    if ($chiffres) {
900
+        $texte = preg_replace_callback(
901
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
902
+            function($m) { return translitteration_chiffree($m[0]); },
903
+            $texte
904
+        );
905
+    }
906 906
 
907
-	return $texte;
907
+    return $texte;
908 908
 }
909 909
 
910 910
 /**
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
  * @return string
917 917
  */
918 918
 function translitteration_chiffree($car) {
919
-	return strtr($car, "'`?~.^+(-", "123456789");
919
+    return strtr($car, "'`?~.^+(-", "123456789");
920 920
 }
921 921
 
922 922
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  *    true s'il a un BOM
930 930
  **/
931 931
 function bom_utf8($texte) {
932
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
932
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933 933
 }
934 934
 
935 935
 /**
@@ -946,18 +946,18 @@  discard block
 block discarded – undo
946 946
  *     true si c'est le cas
947 947
  **/
948 948
 function is_utf8($string) {
949
-	return !strlen(
950
-		preg_replace(
951
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
952
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
953
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
954
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
955
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
956
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
957
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
958
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
959
-			. ',sS',
960
-			'', $string));
949
+    return !strlen(
950
+        preg_replace(
951
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
952
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
953
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
954
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
955
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
956
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
957
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
958
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
959
+            . ',sS',
960
+            '', $string));
961 961
 }
962 962
 
963 963
 /**
@@ -969,10 +969,10 @@  discard block
 block discarded – undo
969 969
  *     true si c'est le cas
970 970
  **/
971 971
 function is_ascii($string) {
972
-	return !strlen(
973
-		preg_replace(
974
-			',[\x09\x0A\x0D\x20-\x7E],sS',
975
-			'', $string));
972
+    return !strlen(
973
+        preg_replace(
974
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
975
+            '', $string));
976 976
 }
977 977
 
978 978
 /**
@@ -991,58 +991,58 @@  discard block
 block discarded – undo
991 991
  **/
992 992
 function transcoder_page($texte, $headers = '') {
993 993
 
994
-	// Si tout est < 128 pas la peine d'aller plus loin
995
-	if (is_ascii($texte)) {
996
-		#spip_log('charset: ascii');
997
-		return $texte;
998
-	}
999
-
1000
-	// Reconnaitre le BOM utf-8 (0xEFBBBF)
1001
-	if (bom_utf8($texte)) {
1002
-		$charset = 'utf-8';
1003
-		$texte = substr($texte, 3);
1004
-	} // charset precise par le contenu (xml)
1005
-	else {
1006
-		if (preg_match(
1007
-			',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1008
-			$charset = trim(strtolower($regs[1]));
1009
-		} // charset precise par le contenu (html)
1010
-		else {
1011
-			if (preg_match(
1012
-					',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1013
-					$texte, $regs)
1014
-				# eviter #CHARSET des squelettes
1015
-				and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1016
-			) {
1017
-				$charset = $tmp;
1018
-			} // charset de la reponse http
1019
-			else {
1020
-				if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1021
-					$charset = trim(strtolower($regs[1]));
1022
-				} else {
1023
-					$charset = '';
1024
-				}
1025
-			}
1026
-		}
1027
-	}
1028
-	// normaliser les noms du shif-jis japonais
1029
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1030
-		$charset = 'shift-jis';
1031
-	}
1032
-
1033
-	if ($charset) {
1034
-		spip_log("charset: $charset");
1035
-	} else {
1036
-		// valeur par defaut
1037
-		if (is_utf8($texte)) {
1038
-			$charset = 'utf-8';
1039
-		} else {
1040
-			$charset = 'iso-8859-1';
1041
-		}
1042
-		spip_log("charset probable: $charset");
1043
-	}
1044
-
1045
-	return importer_charset($texte, $charset);
994
+    // Si tout est < 128 pas la peine d'aller plus loin
995
+    if (is_ascii($texte)) {
996
+        #spip_log('charset: ascii');
997
+        return $texte;
998
+    }
999
+
1000
+    // Reconnaitre le BOM utf-8 (0xEFBBBF)
1001
+    if (bom_utf8($texte)) {
1002
+        $charset = 'utf-8';
1003
+        $texte = substr($texte, 3);
1004
+    } // charset precise par le contenu (xml)
1005
+    else {
1006
+        if (preg_match(
1007
+            ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1008
+            $charset = trim(strtolower($regs[1]));
1009
+        } // charset precise par le contenu (html)
1010
+        else {
1011
+            if (preg_match(
1012
+                    ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1013
+                    $texte, $regs)
1014
+                # eviter #CHARSET des squelettes
1015
+                and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1016
+            ) {
1017
+                $charset = $tmp;
1018
+            } // charset de la reponse http
1019
+            else {
1020
+                if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1021
+                    $charset = trim(strtolower($regs[1]));
1022
+                } else {
1023
+                    $charset = '';
1024
+                }
1025
+            }
1026
+        }
1027
+    }
1028
+    // normaliser les noms du shif-jis japonais
1029
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1030
+        $charset = 'shift-jis';
1031
+    }
1032
+
1033
+    if ($charset) {
1034
+        spip_log("charset: $charset");
1035
+    } else {
1036
+        // valeur par defaut
1037
+        if (is_utf8($texte)) {
1038
+            $charset = 'utf-8';
1039
+        } else {
1040
+            $charset = 'iso-8859-1';
1041
+        }
1042
+        spip_log("charset probable: $charset");
1043
+    }
1044
+
1045
+    return importer_charset($texte, $charset);
1046 1046
 }
1047 1047
 
1048 1048
 
@@ -1066,26 +1066,26 @@  discard block
 block discarded – undo
1066 1066
  *     Le texte coupé
1067 1067
  **/
1068 1068
 function spip_substr($c, $start = 0, $length = null) {
1069
-	// Si ce n'est pas utf-8, utiliser substr
1070
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1071
-		if ($length) {
1072
-			return substr($c, $start, $length);
1073
-		} else {
1074
-			substr($c, $start);
1075
-		}
1076
-	}
1077
-
1078
-	// Si utf-8, voir si on dispose de mb_string
1079
-	if (init_mb_string()) {
1080
-		if ($length) {
1081
-			return mb_substr($c, $start, $length);
1082
-		} else {
1083
-			return mb_substr($c, $start);
1084
-		}
1085
-	}
1086
-
1087
-	// Version manuelle (cf. ci-dessous)
1088
-	return spip_substr_manuelle($c, $start, $length);
1069
+    // Si ce n'est pas utf-8, utiliser substr
1070
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1071
+        if ($length) {
1072
+            return substr($c, $start, $length);
1073
+        } else {
1074
+            substr($c, $start);
1075
+        }
1076
+    }
1077
+
1078
+    // Si utf-8, voir si on dispose de mb_string
1079
+    if (init_mb_string()) {
1080
+        if ($length) {
1081
+            return mb_substr($c, $start, $length);
1082
+        } else {
1083
+            return mb_substr($c, $start);
1084
+        }
1085
+    }
1086
+
1087
+    // Version manuelle (cf. ci-dessous)
1088
+    return spip_substr_manuelle($c, $start, $length);
1089 1089
 }
1090 1090
 
1091 1091
 
@@ -1104,40 +1104,40 @@  discard block
 block discarded – undo
1104 1104
  **/
1105 1105
 function spip_substr_manuelle($c, $start, $length = null) {
1106 1106
 
1107
-	// Cas pathologique
1108
-	if ($length === 0) {
1109
-		return '';
1110
-	}
1111
-
1112
-	// S'il y a un demarrage, on se positionne
1113
-	if ($start > 0) {
1114
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1115
-	} elseif ($start < 0) {
1116
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1117
-	}
1118
-
1119
-	if (!$length) {
1120
-		return $c;
1121
-	}
1122
-
1123
-	if ($length > 0) {
1124
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1125
-		// (un caractere utf-8 prenant au maximum n bytes)
1126
-		$n = 0;
1127
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1128
-			;
1129
-		}
1130
-		$c = substr($c, 0, $n * $length);
1131
-		// puis, tant qu'on est trop long, on coupe...
1132
-		while (($l = spip_strlen($c)) > $length) {
1133
-			$c = substr($c, 0, $length - $l);
1134
-		}
1135
-
1136
-		return $c;
1137
-	}
1138
-
1139
-	// $length < 0
1140
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1107
+    // Cas pathologique
1108
+    if ($length === 0) {
1109
+        return '';
1110
+    }
1111
+
1112
+    // S'il y a un demarrage, on se positionne
1113
+    if ($start > 0) {
1114
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1115
+    } elseif ($start < 0) {
1116
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1117
+    }
1118
+
1119
+    if (!$length) {
1120
+        return $c;
1121
+    }
1122
+
1123
+    if ($length > 0) {
1124
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1125
+        // (un caractere utf-8 prenant au maximum n bytes)
1126
+        $n = 0;
1127
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1128
+            ;
1129
+        }
1130
+        $c = substr($c, 0, $n * $length);
1131
+        // puis, tant qu'on est trop long, on coupe...
1132
+        while (($l = spip_strlen($c)) > $length) {
1133
+            $c = substr($c, 0, $length - $l);
1134
+        }
1135
+
1136
+        return $c;
1137
+    }
1138
+
1139
+    // $length < 0
1140
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1141 1141
 }
1142 1142
 
1143 1143
 /**
@@ -1151,14 +1151,14 @@  discard block
 block discarded – undo
1151 1151
  *     La chaîne avec une majuscule sur le premier mot
1152 1152
  */
1153 1153
 function spip_ucfirst($c) {
1154
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1155
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1156
-		return ucfirst($c);
1157
-	}
1154
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1155
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1156
+        return ucfirst($c);
1157
+    }
1158 1158
 
1159
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1159
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1160 1160
 
1161
-	return $lettre1 . spip_substr($c, 1);
1161
+    return $lettre1 . spip_substr($c, 1);
1162 1162
 }
1163 1163
 
1164 1164
 /**
@@ -1172,12 +1172,12 @@  discard block
 block discarded – undo
1172 1172
  *     La chaîne en minuscules
1173 1173
  */
1174 1174
 function spip_strtolower($c) {
1175
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1176
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1177
-		return strtolower($c);
1178
-	}
1175
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1176
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1177
+        return strtolower($c);
1178
+    }
1179 1179
 
1180
-	return mb_strtolower($c);
1180
+    return mb_strtolower($c);
1181 1181
 }
1182 1182
 
1183 1183
 /**
@@ -1191,23 +1191,23 @@  discard block
 block discarded – undo
1191 1191
  *     Longueur de la chaîne
1192 1192
  */
1193 1193
 function spip_strlen($c) {
1194
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1195
-	$c = str_replace("\r\n", "\n", $c);
1196
-
1197
-	// Si ce n'est pas utf-8, utiliser strlen
1198
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1199
-		return strlen($c);
1200
-	}
1201
-
1202
-	// Sinon, utiliser mb_strlen() si disponible
1203
-	if (init_mb_string()) {
1204
-		return mb_strlen($c);
1205
-	}
1206
-
1207
-	// Methode manuelle : on supprime les bytes 10......,
1208
-	// on compte donc les ascii (0.......) et les demarrages
1209
-	// de caracteres utf-8 (11......)
1210
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1194
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1195
+    $c = str_replace("\r\n", "\n", $c);
1196
+
1197
+    // Si ce n'est pas utf-8, utiliser strlen
1198
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1199
+        return strlen($c);
1200
+    }
1201
+
1202
+    // Sinon, utiliser mb_strlen() si disponible
1203
+    if (init_mb_string()) {
1204
+        return mb_strlen($c);
1205
+    }
1206
+
1207
+    // Methode manuelle : on supprime les bytes 10......,
1208
+    // on compte donc les ascii (0.......) et les demarrages
1209
+    // de caracteres utf-8 (11......)
1210
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1211 1211
 }
1212 1212
 
1213 1213
 // Initialisation
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1218 1218
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1219 1219
 if (!isset($GLOBALS['meta']['pcre_u'])
1220
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1220
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1221 1221
 ) {
1222
-	include_spip('inc/meta');
1223
-	ecrire_meta('pcre_u',
1224
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1225
-			and test_pcre_unicode())
1226
-			? 'u' : ''
1227
-	);
1222
+    include_spip('inc/meta');
1223
+    ecrire_meta('pcre_u',
1224
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1225
+            and test_pcre_unicode())
1226
+            ? 'u' : ''
1227
+    );
1228 1228
 }
1229 1229
 
1230 1230
 
@@ -1240,17 +1240,17 @@  discard block
 block discarded – undo
1240 1240
  *     en unicode : &#128169;
1241 1241
  */
1242 1242
 function utf8_noplanes($x) {
1243
-	$regexp_utf8_4bytes = '/(
1243
+    $regexp_utf8_4bytes = '/(
1244 1244
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1245 1245
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1246 1246
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1247 1247
 )/xS';
1248
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1249
-		foreach ($z[0] as $k) {
1250
-			$ku = utf_8_to_unicode($k);
1251
-			$x = str_replace($k, $ku, $x);
1252
-		}
1253
-	}
1254
-
1255
-	return $x;
1248
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1249
+        foreach ($z[0] as $k) {
1250
+            $ku = utf_8_to_unicode($k);
1251
+            $x = str_replace($k, $ku, $x);
1252
+        }
1253
+    }
1254
+
1255
+    return $x;
1256 1256
 }
Please login to merge, or discard this patch.
ecrire/inc/cvt_autosave.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 /**
24 24
  * Nettoyer les échappements
25 25
  *
26
- * @param $val
26
+ * @param string $val
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 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,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
30
-	return stripslashes(urldecode($val));
30
+    return stripslashes(urldecode($val));
31 31
 }
32 32
 
33 33
 /**
@@ -38,42 +38,42 @@  discard block
 block discarded – undo
38 38
  * @return array
39 39
  */
40 40
 function cvtautosave_formulaire_charger($flux) {
41
-	if (is_array($flux['data'])
42
-		and isset($flux['data']['_autosave_id'])
43
-		and $cle_autosave = $flux['data']['_autosave_id']
44
-	) {
41
+    if (is_array($flux['data'])
42
+        and isset($flux['data']['_autosave_id'])
43
+        and $cle_autosave = $flux['data']['_autosave_id']
44
+    ) {
45 45
 
46
-		$form = $flux['args']['form'];
47
-		$je_suis_poste = $flux['args']['je_suis_poste'];
46
+        $form = $flux['args']['form'];
47
+        $je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49
-		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
49
+        $cle_autosave = serialize($cle_autosave);
50
+        $cle_autosave = $form . "_" . md5($cle_autosave);
51 51
 
52
-		// si on a un backup en session et qu'on est au premier chargement, non poste
53
-		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
-			and !$je_suis_poste
56
-		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
-			foreach ($vars as $key => $val) {
59
-				if (isset($flux['data'][$key])) {
60
-					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
-						$val));
62
-				}
63
-			}
64
-		}
52
+        // si on a un backup en session et qu'on est au premier chargement, non poste
53
+        // on restitue les donnees
54
+        if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
+            and !$je_suis_poste
56
+        ) {
57
+            parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
+            foreach ($vars as $key => $val) {
59
+                if (isset($flux['data'][$key])) {
60
+                    $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
+                        $val));
62
+                }
63
+            }
64
+        }
65 65
 
66
-		/**
67
-		 * Envoyer le input hidden et le bout de js qui l'utilisera
68
-		 */
69
-		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
-			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
66
+        /**
67
+         * Envoyer le input hidden et le bout de js qui l'utilisera
68
+         */
69
+        $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
+            . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71 71
 		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74
-	}
74
+    }
75 75
 
76
-	return $flux;
76
+    return $flux;
77 77
 }
78 78
 
79 79
 /**
@@ -87,33 +87,33 @@  discard block
 block discarded – undo
87 87
  * @return array
88 88
  */
89 89
 function cvtautosave_formulaire_traiter($flux) {
90
-	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
-	// on elimine les donnees de la session
92
-	if ($cle_autosave = _request('autosave')) {
93
-		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
95
-	}
90
+    // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
+    // on elimine les donnees de la session
92
+    if ($cle_autosave = _request('autosave')) {
93
+        include_spip('inc/session');
94
+        session_set('session_autosave_' . $cle_autosave, null);
95
+    }
96 96
 
97
-	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
-		// delai par defaut avant purge d'un backup de form : 72H
99
-		if (!defined('_AUTOSAVE_GB_DELAY')) {
100
-			define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
-		}
102
-		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
-		// purger aussi toutes les vieilles autosave
104
-		$session = $GLOBALS['visiteur_session'];
105
-		foreach ($session as $k => $v) {
106
-			if (strncmp($k, 'session_autosave_', 17) == 0) {
107
-				$timestamp = 0;
108
-				if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
-					$timestamp = intval($m[1]);
110
-				}
111
-				if ($timestamp < $time_too_old) {
112
-					session_set($k, null);
113
-				}
114
-			}
115
-		}
116
-	}
97
+    if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
+        // delai par defaut avant purge d'un backup de form : 72H
99
+        if (!defined('_AUTOSAVE_GB_DELAY')) {
100
+            define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
+        }
102
+        $time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
+        // purger aussi toutes les vieilles autosave
104
+        $session = $GLOBALS['visiteur_session'];
105
+        foreach ($session as $k => $v) {
106
+            if (strncmp($k, 'session_autosave_', 17) == 0) {
107
+                $timestamp = 0;
108
+                if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
+                    $timestamp = intval($m[1]);
110
+                }
111
+                if ($timestamp < $time_too_old) {
112
+                    session_set($k, null);
113
+                }
114
+            }
115
+        }
116
+    }
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 		$je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49 49
 		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
50
+		$cle_autosave = $form."_".md5($cle_autosave);
51 51
 
52 52
 		// si on a un backup en session et qu'on est au premier chargement, non poste
53 53
 		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
54
+		if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
55 55
 			and !$je_suis_poste
56 56
 		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
57
+			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
58 58
 			foreach ($vars as $key => $val) {
59 59
 				if (isset($flux['data'][$key])) {
60 60
 					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 */
69 69
 		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70 70
 			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71
-		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
71
+		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74 74
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	// on elimine les donnees de la session
92 92
 	if ($cle_autosave = _request('autosave')) {
93 93
 		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
94
+		session_set('session_autosave_'.$cle_autosave, null);
95 95
 	}
96 96
 
97 97
 	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
Please login to merge, or discard this patch.
ecrire/inc/distant.php 4 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
  *   permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG)
65 65
  * @param int $taille_max
66 66
  *   taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE
67
- * @return bool|string
67
+ * @return string|false
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible
247 247
  *
248 248
  * @param string $url_idn
249
- * @return array|string
249
+ * @return string|boolean
250 250
  */
251 251
 function url_to_ascii($url_idn) {
252 252
 
@@ -642,13 +642,13 @@  discard block
 block discarded – undo
642 642
  *
643 643
  * @param string $url
644 644
  *     URL de la page à récupérer
645
- * @param bool|null|string $trans
645
+ * @param boolean $trans
646 646
  *     - chaîne longue : c'est un nom de fichier (nom pour sa copie locale)
647 647
  *     - true : demande d'encodage/charset
648 648
  *     - null : ne retourner que les headers
649 649
  * @param string $get
650 650
  *     Type de requête HTTP à faire (HEAD, GET ou POST)
651
- * @param int|bool $taille_max
651
+ * @param integer $taille_max
652 652
  *     Arrêter le contenu au-delà (0 = seulement les entetes ==> requête HEAD).
653 653
  *     Par defaut taille_max = 1Mo.
654 654
  * @param string|array $datas
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  *
775 775
  * @param resource $handle
776 776
  * @param int|bool $if_modified_since
777
- * @return bool|array
777
+ * @return string
778 778
  *   int status
779 779
  *   string headers
780 780
  *   int last_modified
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
  *   donnees postees
1252 1252
  * @param string $vers
1253 1253
  *   version HTTP
1254
- * @param int|string $date
1254
+ * @param string $date
1255 1255
  *   timestamp pour entente If-Modified-Since
1256
- * @return bool|resource
1256
+ * @return string
1257 1257
  *   false|int si echec
1258 1258
  *   resource socket vers l'url demandee
1259 1259
  */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1256,8 +1256,9 @@
 block discarded – undo
1256 1256
 	$http_noproxy = " $http_noproxy ";
1257 1257
 	$domain = $host;
1258 1258
 	// si le domaine exact www.example.org est dans les exceptions
1259
-	if (strpos($http_noproxy, " $domain ") !== false)
1260
-		return '';
1259
+	if (strpos($http_noproxy, " $domain ") !== false) {
1260
+			return '';
1261
+	}
1261 1262
 
1262 1263
 	while (strpos($domain, '.') !== false) {
1263 1264
 		$domain = explode('.', $domain);
Please login to merge, or discard this patch.
Indentation   +1070 added lines, -1070 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2097152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2097152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		(isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,77 +68,77 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode == 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode == 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local == $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode == 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE);
119
-		}
120
-		if (!$res['length']) {
121
-			// si $t c'est sans doute juste un not-modified-since
122
-			return $t ? $local : false;
123
-		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK');
125
-
126
-		// pour une eventuelle indexation
127
-		pipeline(
128
-			'post_edition',
129
-			array(
130
-				'args' => array(
131
-					'operation' => 'copie_locale',
132
-					'source' => $source,
133
-					'fichier' => $local,
134
-					'http_res' => $res['length'],
135
-				),
136
-				'data' => null
137
-			)
138
-		);
139
-	}
140
-
141
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode == 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode == 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local == $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode == 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE);
119
+        }
120
+        if (!$res['length']) {
121
+            // si $t c'est sans doute juste un not-modified-since
122
+            return $t ? $local : false;
123
+        }
124
+        spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK');
125
+
126
+        // pour une eventuelle indexation
127
+        pipeline(
128
+            'post_edition',
129
+            array(
130
+                'args' => array(
131
+                    'operation' => 'copie_locale',
132
+                    'source' => $source,
133
+                    'fichier' => $local,
134
+                    'http_res' => $res['length'],
135
+                ),
136
+                'data' => null
137
+            )
138
+        );
139
+    }
140
+
141
+    return $local;
142 142
 }
143 143
 
144 144
 /**
@@ -153,88 +153,88 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
157
-		include_spip('inc/filtres_mini');
158
-	}
156
+    if (!function_exists('protocole_verifier')){
157
+        include_spip('inc/filtres_mini');
158
+    }
159 159
 
160
-	if (!protocole_verifier($url, array('http', 'https'))) {
161
-		return false;
162
-	}
160
+    if (!protocole_verifier($url, array('http', 'https'))) {
161
+        return false;
162
+    }
163 163
 	
164
-	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
166
-		return false;
167
-	}
168
-
169
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
-		return false;
171
-	}
172
-
173
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
-		return false;
175
-	}
176
-
177
-	if (!is_array($known_hosts)) {
178
-		$known_hosts = array($known_hosts);
179
-	}
180
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
-	$known_hosts[] = url_de_base();
182
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
-
184
-	$is_known_host = false;
185
-	foreach ($known_hosts as $known_host) {
186
-		$parse_known = parse_url($known_host);
187
-		if ($parse_known
188
-		  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
-			$is_known_host = true;
190
-			break;
191
-		}
192
-	}
193
-
194
-	if (!$is_known_host) {
195
-		$host = trim($parsed_url['host'], '.');
196
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
-			$ip = $host;
198
-		} else {
199
-			$ip = gethostbyname($host);
200
-			if ($ip === $host) {
201
-				// Error condition for gethostbyname()
202
-				$ip = false;
203
-			}
204
-		}
205
-		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
207
-			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
210
-			) {
211
-				return false;
212
-			}
213
-		}
214
-	}
215
-
216
-	if (empty($parsed_url['port'])) {
217
-		return $url;
218
-	}
219
-
220
-	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
222
-		return $url;
223
-	}
224
-
225
-	if ($is_known_host) {
226
-		foreach ($known_hosts as $known_host) {
227
-			$parse_known = parse_url($known_host);
228
-			if ($parse_known
229
-				and !empty($parse_known['port'])
230
-			  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
-			  and $parse_known['port'] == $port) {
232
-				return $url;
233
-			}
234
-		}
235
-	}
236
-
237
-	return false;
164
+    $parsed_url = parse_url($url);
165
+    if (!$parsed_url or empty($parsed_url['host']) ) {
166
+        return false;
167
+    }
168
+
169
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
+        return false;
171
+    }
172
+
173
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
+        return false;
175
+    }
176
+
177
+    if (!is_array($known_hosts)) {
178
+        $known_hosts = array($known_hosts);
179
+    }
180
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
+    $known_hosts[] = url_de_base();
182
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
+
184
+    $is_known_host = false;
185
+    foreach ($known_hosts as $known_host) {
186
+        $parse_known = parse_url($known_host);
187
+        if ($parse_known
188
+          and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
+            $is_known_host = true;
190
+            break;
191
+        }
192
+    }
193
+
194
+    if (!$is_known_host) {
195
+        $host = trim($parsed_url['host'], '.');
196
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
+            $ip = $host;
198
+        } else {
199
+            $ip = gethostbyname($host);
200
+            if ($ip === $host) {
201
+                // Error condition for gethostbyname()
202
+                $ip = false;
203
+            }
204
+        }
205
+        if ($ip) {
206
+            $parts = array_map('intval', explode( '.', $ip ));
207
+            if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
+              or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
+              or ( 192 === $parts[0] && 168 === $parts[1] )
210
+            ) {
211
+                return false;
212
+            }
213
+        }
214
+    }
215
+
216
+    if (empty($parsed_url['port'])) {
217
+        return $url;
218
+    }
219
+
220
+    $port = $parsed_url['port'];
221
+    if ($port === 80  or $port === 443  or $port === 8080) {
222
+        return $url;
223
+    }
224
+
225
+    if ($is_known_host) {
226
+        foreach ($known_hosts as $known_host) {
227
+            $parse_known = parse_url($known_host);
228
+            if ($parse_known
229
+                and !empty($parse_known['port'])
230
+              and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
+              and $parse_known['port'] == $port) {
232
+                return $url;
233
+            }
234
+        }
235
+    }
236
+
237
+    return false;
238 238
 }
239 239
 
240 240
 /**
@@ -253,86 +253,86 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function prepare_donnees_post($donnees, $boundary = '') {
255 255
 
256
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
-	// pour un appel soap par exemple
258
-	// l'entete est separe des donnees par un double retour a la ligne
259
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
-	if (is_string($donnees) && strlen($donnees)) {
261
-		$entete = '';
262
-		// on repasse tous les \r\n et \r en simples \n
263
-		$donnees = str_replace("\r\n", "\n", $donnees);
264
-		$donnees = str_replace("\r", "\n", $donnees);
265
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
-		$p = strpos($donnees, "\n\n");
267
-		if ($p !== false) {
268
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
-			$donnees = substr($donnees, $p + 2);
270
-		}
271
-		$chaine = str_replace("\n", "\r\n", $donnees);
272
-	} else {
273
-		/* boundary automatique */
274
-		// Si on a plus de 500 octects de donnees, on "boundarise"
275
-		if ($boundary === '') {
276
-			$taille = 0;
277
-			foreach ($donnees as $cle => $valeur) {
278
-				if (is_array($valeur)) {
279
-					foreach ($valeur as $val2) {
280
-						$taille += strlen($val2);
281
-					}
282
-				} else {
283
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
284
-					$taille += strlen($valeur);
285
-				}
286
-			}
287
-			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
289
-			}
290
-		}
291
-
292
-		if (is_string($boundary) and strlen($boundary)) {
293
-			// fabrique une chaine HTTP pour un POST avec boundary
294
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
-			$chaine = '';
296
-			if (is_array($donnees)) {
297
-				foreach ($donnees as $cle => $valeur) {
298
-					if (is_array($valeur)) {
299
-						foreach ($valeur as $val2) {
300
-							$chaine .= "\r\n--$boundary\r\n";
301
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
-							$chaine .= "\r\n";
303
-							$chaine .= $val2;
304
-						}
305
-					} else {
306
-						$chaine .= "\r\n--$boundary\r\n";
307
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
-						$chaine .= "\r\n";
309
-						$chaine .= $valeur;
310
-					}
311
-				}
312
-				$chaine .= "\r\n--$boundary\r\n";
313
-			}
314
-		} else {
315
-			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
-			$chaine = array();
318
-			if (is_array($donnees)) {
319
-				foreach ($donnees as $cle => $valeur) {
320
-					if (is_array($valeur)) {
321
-						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
-						}
324
-					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
-					}
327
-				}
328
-				$chaine = implode('&', $chaine);
329
-			} else {
330
-				$chaine = $donnees;
331
-			}
332
-		}
333
-	}
334
-
335
-	return array($entete, $chaine);
256
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
+    // pour un appel soap par exemple
258
+    // l'entete est separe des donnees par un double retour a la ligne
259
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
+    if (is_string($donnees) && strlen($donnees)) {
261
+        $entete = '';
262
+        // on repasse tous les \r\n et \r en simples \n
263
+        $donnees = str_replace("\r\n", "\n", $donnees);
264
+        $donnees = str_replace("\r", "\n", $donnees);
265
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
+        $p = strpos($donnees, "\n\n");
267
+        if ($p !== false) {
268
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
+            $donnees = substr($donnees, $p + 2);
270
+        }
271
+        $chaine = str_replace("\n", "\r\n", $donnees);
272
+    } else {
273
+        /* boundary automatique */
274
+        // Si on a plus de 500 octects de donnees, on "boundarise"
275
+        if ($boundary === '') {
276
+            $taille = 0;
277
+            foreach ($donnees as $cle => $valeur) {
278
+                if (is_array($valeur)) {
279
+                    foreach ($valeur as $val2) {
280
+                        $taille += strlen($val2);
281
+                    }
282
+                } else {
283
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
284
+                    $taille += strlen($valeur);
285
+                }
286
+            }
287
+            if ($taille > 500) {
288
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
289
+            }
290
+        }
291
+
292
+        if (is_string($boundary) and strlen($boundary)) {
293
+            // fabrique une chaine HTTP pour un POST avec boundary
294
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
+            $chaine = '';
296
+            if (is_array($donnees)) {
297
+                foreach ($donnees as $cle => $valeur) {
298
+                    if (is_array($valeur)) {
299
+                        foreach ($valeur as $val2) {
300
+                            $chaine .= "\r\n--$boundary\r\n";
301
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
+                            $chaine .= "\r\n";
303
+                            $chaine .= $val2;
304
+                        }
305
+                    } else {
306
+                        $chaine .= "\r\n--$boundary\r\n";
307
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
+                        $chaine .= "\r\n";
309
+                        $chaine .= $valeur;
310
+                    }
311
+                }
312
+                $chaine .= "\r\n--$boundary\r\n";
313
+            }
314
+        } else {
315
+            // fabrique une chaine HTTP simple pour un POST
316
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
+            $chaine = array();
318
+            if (is_array($donnees)) {
319
+                foreach ($donnees as $cle => $valeur) {
320
+                    if (is_array($valeur)) {
321
+                        foreach ($valeur as $val2) {
322
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
+                        }
324
+                    } else {
325
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
+                    }
327
+                }
328
+                $chaine = implode('&', $chaine);
329
+            } else {
330
+                $chaine = $donnees;
331
+            }
332
+        }
333
+    }
334
+
335
+    return array($entete, $chaine);
336 336
 }
337 337
 
338 338
 /**
@@ -346,18 +346,18 @@  discard block
 block discarded – undo
346 346
  */
347 347
 function url_to_ascii($url_idn) {
348 348
 
349
-	if ($parts = parse_url($url_idn)) {
350
-		$host = $parts['host'];
351
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
-			include_spip('inc/idna_convert.class');
353
-			$IDN = new idna_convert();
354
-			$host_ascii = $IDN->encode($host);
355
-			$url_idn = explode($host, $url_idn, 2);
356
-			$url_idn = implode($host_ascii, $url_idn);
357
-		}
358
-	}
359
-
360
-	return $url_idn;
349
+    if ($parts = parse_url($url_idn)) {
350
+        $host = $parts['host'];
351
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
+            include_spip('inc/idna_convert.class');
353
+            $IDN = new idna_convert();
354
+            $host_ascii = $IDN->encode($host);
355
+            $url_idn = explode($host, $url_idn, 2);
356
+            $url_idn = implode($host_ascii, $url_idn);
357
+        }
358
+    }
359
+
360
+    return $url_idn;
361 361
 }
362 362
 
363 363
 /**
@@ -396,175 +396,175 @@  discard block
 block discarded – undo
396 396
  *     string file : nom du fichier si enregistre dans un fichier
397 397
  */
398 398
 function recuperer_url($url, $options = array()) {
399
-	$default = array(
400
-		'transcoder' => false,
401
-		'methode' => 'GET',
402
-		'taille_max' => null,
403
-		'datas' => '',
404
-		'boundary' => '',
405
-		'refuser_gz' => false,
406
-		'if_modified_since' => '',
407
-		'uri_referer' => '',
408
-		'file' => '',
409
-		'follow_location' => 10,
410
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
411
-	);
412
-	$options = array_merge($default, $options);
413
-	// copier directement dans un fichier ?
414
-	$copy = $options['file'];
415
-
416
-	if ($options['methode'] == 'HEAD') {
417
-		$options['taille_max'] = 0;
418
-	}
419
-	if (is_null($options['taille_max'])) {
420
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
-	}
422
-
423
-	if (!empty($options['datas'])) {
424
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
-		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
427
-		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
429
-		if (strlen($postdata)) {
430
-			$options['methode'] = 'POST';
431
-		}
432
-	}
433
-
434
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
-	$url = preg_replace(',^feed://,i', 'http://', $url);
436
-	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
438
-	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
440
-	}
441
-
442
-	$url = url_to_ascii($url);
443
-
444
-	$result = array(
445
-		'status' => 0,
446
-		'headers' => '',
447
-		'page' => '',
448
-		'length' => 0,
449
-		'last_modified' => '',
450
-		'location' => '',
451
-		'url' => $url
452
-	);
453
-
454
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
-
457
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
458
-	list($handle, $fopen) = init_http(
459
-		$options['methode'],
460
-		$url,
461
-		$refuser_gz,
462
-		$options['uri_referer'],
463
-		$options['datas'],
464
-		$options['version_http'],
465
-		$options['if_modified_since']
466
-	);
467
-	if (!$handle) {
468
-		spip_log("ECHEC init_http $url");
469
-
470
-		return false;
471
-	}
472
-
473
-	// Sauf en fopen, envoyer le flux d'entree
474
-	// et recuperer les en-tetes de reponses
475
-	if (!$fopen) {
476
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
-		if (!$res) {
478
-			fclose($handle);
479
-			$t = @parse_url($url);
480
-			$host = $t['host'];
481
-			// Chinoisierie inexplicable pour contrer
482
-			// les actions liberticides de l'empire du milieu
483
-			if (!need_proxy($host)
484
-				and $res = @file_get_contents($url)
485
-			) {
486
-				$result['length'] = strlen($res);
487
-				if ($copy) {
488
-					ecrire_fichier($copy, $res);
489
-					$result['file'] = $copy;
490
-				} else {
491
-					$result['page'] = $res;
492
-				}
493
-				$res = array(
494
-					'status' => 200,
495
-				);
496
-			} else {
497
-				return false;
498
-			}
499
-		} elseif ($res['location'] and $options['follow_location']) {
500
-			$options['follow_location']--;
501
-			fclose($handle);
502
-			include_spip('inc/filtres');
503
-			$url = suivre_lien($url, $res['location']);
504
-			spip_log("recuperer_url recommence sur $url");
505
-
506
-			return recuperer_url($url, $options);
507
-		} elseif ($res['status'] !== 200) {
508
-			spip_log('HTTP status ' . $res['status'] . " pour $url");
509
-		}
510
-		$result['status'] = $res['status'];
511
-		if (isset($res['headers'])) {
512
-			$result['headers'] = $res['headers'];
513
-		}
514
-		if (isset($res['last_modified'])) {
515
-			$result['last_modified'] = $res['last_modified'];
516
-		}
517
-		if (isset($res['location'])) {
518
-			$result['location'] = $res['location'];
519
-		}
520
-	}
521
-
522
-	// on ne veut que les entetes
523
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
524
-		return $result;
525
-	}
526
-
527
-
528
-	// s'il faut deballer, le faire via un fichier temporaire
529
-	// sinon la memoire explose pour les gros flux
530
-
531
-	$gz = false;
532
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
-	}
535
-
536
-	// si on a pas deja recuperer le contenu par une methode detournee
537
-	if (!$result['length']) {
538
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
539
-		fclose($handle);
540
-		if ($copy) {
541
-			$result['length'] = $res;
542
-			$result['file'] = $copy;
543
-		} elseif ($res) {
544
-			$result['page'] = &$res;
545
-			$result['length'] = strlen($result['page']);
546
-		}
547
-		if (!$result['status']) {
548
-			$result['status'] = 200; // on a reussi, donc !
549
-		}
550
-	}
551
-	if (!$result['page']) {
552
-		return $result;
553
-	}
554
-
555
-	// Decompresser au besoin
556
-	if ($gz) {
557
-		$result['page'] = implode('', gzfile($gz));
558
-		supprimer_fichier($gz);
559
-	}
560
-
561
-	// Faut-il l'importer dans notre charset local ?
562
-	if ($options['transcoder']) {
563
-		include_spip('inc/charsets');
564
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
565
-	}
566
-
567
-	return $result;
399
+    $default = array(
400
+        'transcoder' => false,
401
+        'methode' => 'GET',
402
+        'taille_max' => null,
403
+        'datas' => '',
404
+        'boundary' => '',
405
+        'refuser_gz' => false,
406
+        'if_modified_since' => '',
407
+        'uri_referer' => '',
408
+        'file' => '',
409
+        'follow_location' => 10,
410
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
411
+    );
412
+    $options = array_merge($default, $options);
413
+    // copier directement dans un fichier ?
414
+    $copy = $options['file'];
415
+
416
+    if ($options['methode'] == 'HEAD') {
417
+        $options['taille_max'] = 0;
418
+    }
419
+    if (is_null($options['taille_max'])) {
420
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
+    }
422
+
423
+    if (!empty($options['datas'])) {
424
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
+        if (stripos($head, 'Content-Length:') === false) {
426
+            $head .= 'Content-Length: ' . strlen($postdata);
427
+        }
428
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
429
+        if (strlen($postdata)) {
430
+            $options['methode'] = 'POST';
431
+        }
432
+    }
433
+
434
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
+    $url = preg_replace(',^feed://,i', 'http://', $url);
436
+    if (!tester_url_absolue($url)) {
437
+        $url = 'http://' . $url;
438
+    } elseif (strncmp($url, '//', 2) == 0) {
439
+        $url = 'http:' . $url;
440
+    }
441
+
442
+    $url = url_to_ascii($url);
443
+
444
+    $result = array(
445
+        'status' => 0,
446
+        'headers' => '',
447
+        'page' => '',
448
+        'length' => 0,
449
+        'last_modified' => '',
450
+        'location' => '',
451
+        'url' => $url
452
+    );
453
+
454
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
+
457
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
458
+    list($handle, $fopen) = init_http(
459
+        $options['methode'],
460
+        $url,
461
+        $refuser_gz,
462
+        $options['uri_referer'],
463
+        $options['datas'],
464
+        $options['version_http'],
465
+        $options['if_modified_since']
466
+    );
467
+    if (!$handle) {
468
+        spip_log("ECHEC init_http $url");
469
+
470
+        return false;
471
+    }
472
+
473
+    // Sauf en fopen, envoyer le flux d'entree
474
+    // et recuperer les en-tetes de reponses
475
+    if (!$fopen) {
476
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
+        if (!$res) {
478
+            fclose($handle);
479
+            $t = @parse_url($url);
480
+            $host = $t['host'];
481
+            // Chinoisierie inexplicable pour contrer
482
+            // les actions liberticides de l'empire du milieu
483
+            if (!need_proxy($host)
484
+                and $res = @file_get_contents($url)
485
+            ) {
486
+                $result['length'] = strlen($res);
487
+                if ($copy) {
488
+                    ecrire_fichier($copy, $res);
489
+                    $result['file'] = $copy;
490
+                } else {
491
+                    $result['page'] = $res;
492
+                }
493
+                $res = array(
494
+                    'status' => 200,
495
+                );
496
+            } else {
497
+                return false;
498
+            }
499
+        } elseif ($res['location'] and $options['follow_location']) {
500
+            $options['follow_location']--;
501
+            fclose($handle);
502
+            include_spip('inc/filtres');
503
+            $url = suivre_lien($url, $res['location']);
504
+            spip_log("recuperer_url recommence sur $url");
505
+
506
+            return recuperer_url($url, $options);
507
+        } elseif ($res['status'] !== 200) {
508
+            spip_log('HTTP status ' . $res['status'] . " pour $url");
509
+        }
510
+        $result['status'] = $res['status'];
511
+        if (isset($res['headers'])) {
512
+            $result['headers'] = $res['headers'];
513
+        }
514
+        if (isset($res['last_modified'])) {
515
+            $result['last_modified'] = $res['last_modified'];
516
+        }
517
+        if (isset($res['location'])) {
518
+            $result['location'] = $res['location'];
519
+        }
520
+    }
521
+
522
+    // on ne veut que les entetes
523
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
524
+        return $result;
525
+    }
526
+
527
+
528
+    // s'il faut deballer, le faire via un fichier temporaire
529
+    // sinon la memoire explose pour les gros flux
530
+
531
+    $gz = false;
532
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
+    }
535
+
536
+    // si on a pas deja recuperer le contenu par une methode detournee
537
+    if (!$result['length']) {
538
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
539
+        fclose($handle);
540
+        if ($copy) {
541
+            $result['length'] = $res;
542
+            $result['file'] = $copy;
543
+        } elseif ($res) {
544
+            $result['page'] = &$res;
545
+            $result['length'] = strlen($result['page']);
546
+        }
547
+        if (!$result['status']) {
548
+            $result['status'] = 200; // on a reussi, donc !
549
+        }
550
+    }
551
+    if (!$result['page']) {
552
+        return $result;
553
+    }
554
+
555
+    // Decompresser au besoin
556
+    if ($gz) {
557
+        $result['page'] = implode('', gzfile($gz));
558
+        supprimer_fichier($gz);
559
+    }
560
+
561
+    // Faut-il l'importer dans notre charset local ?
562
+    if ($options['transcoder']) {
563
+        include_spip('inc/charsets');
564
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
565
+    }
566
+
567
+    return $result;
568 568
 }
569 569
 
570 570
 /**
@@ -580,72 +580,72 @@  discard block
 block discarded – undo
580 580
  * @return array|bool|mixed
581 581
  */
582 582
 function recuperer_url_cache($url, $options = array()) {
583
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
584
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
585
-	}
586
-	$default = array(
587
-		'transcoder' => false,
588
-		'methode' => 'GET',
589
-		'taille_max' => null,
590
-		'datas' => '',
591
-		'boundary' => '',
592
-		'refuser_gz' => false,
593
-		'if_modified_since' => '',
594
-		'uri_referer' => '',
595
-		'file' => '',
596
-		'follow_location' => 10,
597
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
598
-		'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
599
-	);
600
-	$options = array_merge($default, $options);
601
-
602
-	// cas ou il n'est pas possible de cacher
603
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
604
-		return recuperer_url($url, $options);
605
-	}
606
-
607
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
608
-	static $errors = array();
609
-	if (isset($errors[$url])) {
610
-		return $errors[$url];
611
-	}
612
-
613
-	$sig = $options;
614
-	unset($sig['if_modified_since']);
615
-	unset($sig['delai_cache']);
616
-	$sig['url'] = $url;
617
-
618
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
619
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
621
-	$cache = "$sub$cache";
622
-
623
-	$res = false;
624
-	$is_cached = file_exists($cache);
625
-	if ($is_cached
626
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
627
-	) {
628
-		lire_fichier($cache, $res);
629
-		if ($res = unserialize($res)) {
630
-			// mettre le last_modified et le status=304 ?
631
-		}
632
-	}
633
-	if (!$res) {
634
-		$res = recuperer_url($url, $options);
635
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
636
-		if (!$res) {
637
-			if ($is_cached) {
638
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
639
-				lire_fichier($cache, $res);
640
-				$res = unserialize($res);
641
-			}
642
-
643
-			return $errors[$url] = $res;
644
-		}
645
-		ecrire_fichier($cache, serialize($res));
646
-	}
647
-
648
-	return $res;
583
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
584
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
585
+    }
586
+    $default = array(
587
+        'transcoder' => false,
588
+        'methode' => 'GET',
589
+        'taille_max' => null,
590
+        'datas' => '',
591
+        'boundary' => '',
592
+        'refuser_gz' => false,
593
+        'if_modified_since' => '',
594
+        'uri_referer' => '',
595
+        'file' => '',
596
+        'follow_location' => 10,
597
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
598
+        'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
599
+    );
600
+    $options = array_merge($default, $options);
601
+
602
+    // cas ou il n'est pas possible de cacher
603
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
604
+        return recuperer_url($url, $options);
605
+    }
606
+
607
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
608
+    static $errors = array();
609
+    if (isset($errors[$url])) {
610
+        return $errors[$url];
611
+    }
612
+
613
+    $sig = $options;
614
+    unset($sig['if_modified_since']);
615
+    unset($sig['delai_cache']);
616
+    $sig['url'] = $url;
617
+
618
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
619
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
621
+    $cache = "$sub$cache";
622
+
623
+    $res = false;
624
+    $is_cached = file_exists($cache);
625
+    if ($is_cached
626
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
627
+    ) {
628
+        lire_fichier($cache, $res);
629
+        if ($res = unserialize($res)) {
630
+            // mettre le last_modified et le status=304 ?
631
+        }
632
+    }
633
+    if (!$res) {
634
+        $res = recuperer_url($url, $options);
635
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
636
+        if (!$res) {
637
+            if ($is_cached) {
638
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
639
+                lire_fichier($cache, $res);
640
+                $res = unserialize($res);
641
+            }
642
+
643
+            return $errors[$url] = $res;
644
+        }
645
+        ecrire_fichier($cache, serialize($res));
646
+    }
647
+
648
+    return $res;
649 649
 }
650 650
 
651 651
 /**
@@ -683,52 +683,52 @@  discard block
 block discarded – undo
683 683
  *     - false si la page n'a pu être récupérée (status different de 200)
684 684
  **/
685 685
 function recuperer_page(
686
-	$url,
687
-	$trans = false,
688
-	$get_headers = false,
689
-	$taille_max = null,
690
-	$datas = '',
691
-	$boundary = '',
692
-	$refuser_gz = false,
693
-	$date_verif = '',
694
-	$uri_referer = ''
686
+    $url,
687
+    $trans = false,
688
+    $get_headers = false,
689
+    $taille_max = null,
690
+    $datas = '',
691
+    $boundary = '',
692
+    $refuser_gz = false,
693
+    $date_verif = '',
694
+    $uri_referer = ''
695 695
 ) {
696
-	// $copy = copier le fichier ?
697
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
698
-
699
-	if (!is_null($taille_max) and ($taille_max == 0)) {
700
-		$get = 'HEAD';
701
-	} else {
702
-		$get = 'GET';
703
-	}
704
-
705
-	$options = array(
706
-		'transcoder' => $trans === true,
707
-		'methode' => $get,
708
-		'datas' => $datas,
709
-		'boundary' => $boundary,
710
-		'refuser_gz' => $refuser_gz,
711
-		'if_modified_since' => $date_verif,
712
-		'uri_referer' => $uri_referer,
713
-		'file' => $copy ? $trans : '',
714
-		'follow_location' => 10,
715
-	);
716
-	if (!is_null($taille_max)) {
717
-		$options['taille_max'] = $taille_max;
718
-	}
719
-	// dix tentatives maximum en cas d'entetes 301...
720
-	$res = recuperer_url($url, $options);
721
-	if (!$res) {
722
-		return false;
723
-	}
724
-	if ($res['status'] !== 200) {
725
-		return false;
726
-	}
727
-	if ($get_headers) {
728
-		return $res['headers'] . "\n" . $res['page'];
729
-	}
730
-
731
-	return $res['page'];
696
+    // $copy = copier le fichier ?
697
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
698
+
699
+    if (!is_null($taille_max) and ($taille_max == 0)) {
700
+        $get = 'HEAD';
701
+    } else {
702
+        $get = 'GET';
703
+    }
704
+
705
+    $options = array(
706
+        'transcoder' => $trans === true,
707
+        'methode' => $get,
708
+        'datas' => $datas,
709
+        'boundary' => $boundary,
710
+        'refuser_gz' => $refuser_gz,
711
+        'if_modified_since' => $date_verif,
712
+        'uri_referer' => $uri_referer,
713
+        'file' => $copy ? $trans : '',
714
+        'follow_location' => 10,
715
+    );
716
+    if (!is_null($taille_max)) {
717
+        $options['taille_max'] = $taille_max;
718
+    }
719
+    // dix tentatives maximum en cas d'entetes 301...
720
+    $res = recuperer_url($url, $options);
721
+    if (!$res) {
722
+        return false;
723
+    }
724
+    if ($res['status'] !== 200) {
725
+        return false;
726
+    }
727
+    if ($get_headers) {
728
+        return $res['headers'] . "\n" . $res['page'];
729
+    }
730
+
731
+    return $res['page'];
732 732
 }
733 733
 
734 734
 
@@ -765,48 +765,48 @@  discard block
 block discarded – undo
765 765
  *     - false sinon
766 766
  **/
767 767
 function recuperer_lapage(
768
-	$url,
769
-	$trans = false,
770
-	$get = 'GET',
771
-	$taille_max = 1048576,
772
-	$datas = '',
773
-	$refuser_gz = false,
774
-	$date_verif = '',
775
-	$uri_referer = ''
768
+    $url,
769
+    $trans = false,
770
+    $get = 'GET',
771
+    $taille_max = 1048576,
772
+    $datas = '',
773
+    $refuser_gz = false,
774
+    $date_verif = '',
775
+    $uri_referer = ''
776 776
 ) {
777
-	// $copy = copier le fichier ?
778
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
779
-
780
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
781
-	// en memoire refuser gz
782
-	if ($copy) {
783
-		$refuser_gz = true;
784
-	}
785
-
786
-	$options = array(
787
-		'transcoder' => $trans === true,
788
-		'methode' => $get,
789
-		'datas' => $datas,
790
-		'refuser_gz' => $refuser_gz,
791
-		'if_modified_since' => $date_verif,
792
-		'uri_referer' => $uri_referer,
793
-		'file' => $copy ? $trans : '',
794
-		'follow_location' => false,
795
-	);
796
-	if (!is_null($taille_max)) {
797
-		$options['taille_max'] = $taille_max;
798
-	}
799
-	// dix tentatives maximum en cas d'entetes 301...
800
-	$res = recuperer_url($url, $options);
801
-
802
-	if (!$res) {
803
-		return false;
804
-	}
805
-	if ($res['status'] !== 200) {
806
-		return false;
807
-	}
808
-
809
-	return array($res['headers'], $res['page']);
777
+    // $copy = copier le fichier ?
778
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
779
+
780
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
781
+    // en memoire refuser gz
782
+    if ($copy) {
783
+        $refuser_gz = true;
784
+    }
785
+
786
+    $options = array(
787
+        'transcoder' => $trans === true,
788
+        'methode' => $get,
789
+        'datas' => $datas,
790
+        'refuser_gz' => $refuser_gz,
791
+        'if_modified_since' => $date_verif,
792
+        'uri_referer' => $uri_referer,
793
+        'file' => $copy ? $trans : '',
794
+        'follow_location' => false,
795
+    );
796
+    if (!is_null($taille_max)) {
797
+        $options['taille_max'] = $taille_max;
798
+    }
799
+    // dix tentatives maximum en cas d'entetes 301...
800
+    $res = recuperer_url($url, $options);
801
+
802
+    if (!$res) {
803
+        return false;
804
+    }
805
+    if ($res['status'] !== 200) {
806
+        return false;
807
+    }
808
+
809
+    return array($res['headers'], $res['page']);
810 810
 }
811 811
 
812 812
 /**
@@ -824,41 +824,41 @@  discard block
 block discarded – undo
824 824
  *   string contenu de la resource
825 825
  */
826 826
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
827
-	$taille = 0;
828
-	$result = '';
829
-	$fp = false;
830
-	if ($fichier) {
831
-		include_spip('inc/acces');
832
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834
-		if (!$fp and file_exists($fichier)) {
835
-			return filesize($fichier);
836
-		}
837
-		if (!$fp) {
838
-			return false;
839
-		}
840
-		$result = 0; // on renvoie la taille du fichier
841
-	}
842
-	while (!feof($handle) and $taille < $taille_max) {
843
-		$res = fread($handle, 16384);
844
-		$taille += strlen($res);
845
-		if ($fp) {
846
-			fwrite($fp, $res);
847
-			$result = $taille;
848
-		} else {
849
-			$result .= $res;
850
-		}
851
-	}
852
-	if ($fp) {
853
-		spip_fclose_unlock($fp);
854
-		spip_unlink($fichier);
855
-		@rename($tmpfile, $fichier);
856
-		if (!file_exists($fichier)) {
857
-			return false;
858
-		}
859
-	}
860
-
861
-	return $result;
827
+    $taille = 0;
828
+    $result = '';
829
+    $fp = false;
830
+    if ($fichier) {
831
+        include_spip('inc/acces');
832
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834
+        if (!$fp and file_exists($fichier)) {
835
+            return filesize($fichier);
836
+        }
837
+        if (!$fp) {
838
+            return false;
839
+        }
840
+        $result = 0; // on renvoie la taille du fichier
841
+    }
842
+    while (!feof($handle) and $taille < $taille_max) {
843
+        $res = fread($handle, 16384);
844
+        $taille += strlen($res);
845
+        if ($fp) {
846
+            fwrite($fp, $res);
847
+            $result = $taille;
848
+        } else {
849
+            $result .= $res;
850
+        }
851
+    }
852
+    if ($fp) {
853
+        spip_fclose_unlock($fp);
854
+        spip_unlink($fichier);
855
+        @rename($tmpfile, $fichier);
856
+        if (!file_exists($fichier)) {
857
+            return false;
858
+        }
859
+    }
860
+
861
+    return $result;
862 862
 }
863 863
 
864 864
 /**
@@ -880,34 +880,34 @@  discard block
 block discarded – undo
880 880
  *   string location
881 881
  */
882 882
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
883
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
884
-
885
-	$s = @trim(fgets($handle, 16384));
886
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
887
-		return false;
888
-	}
889
-	$result['status'] = intval($r[1]);
890
-	while ($s = trim(fgets($handle, 16384))) {
891
-		$result['headers'][] = $s . "\n";
892
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893
-		list(, $d, $v) = $r;
894
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
895
-			$result['location'] = $v;
896
-		} elseif ($d == 'Last-Modified') {
897
-			$result['last_modified'] = strtotime($v);
898
-		}
899
-	}
900
-	if ($if_modified_since
901
-		and $result['last_modified']
902
-		and $if_modified_since > $result['last_modified']
903
-		and $result['status'] == 200
904
-	) {
905
-		$result['status'] = 304;
906
-	}
907
-
908
-	$result['headers'] = implode('', $result['headers']);
909
-
910
-	return $result;
883
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
884
+
885
+    $s = @trim(fgets($handle, 16384));
886
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
887
+        return false;
888
+    }
889
+    $result['status'] = intval($r[1]);
890
+    while ($s = trim(fgets($handle, 16384))) {
891
+        $result['headers'][] = $s . "\n";
892
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893
+        list(, $d, $v) = $r;
894
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
895
+            $result['location'] = $v;
896
+        } elseif ($d == 'Last-Modified') {
897
+            $result['last_modified'] = strtotime($v);
898
+        }
899
+    }
900
+    if ($if_modified_since
901
+        and $result['last_modified']
902
+        and $if_modified_since > $result['last_modified']
903
+        and $result['status'] == 200
904
+    ) {
905
+        $result['status'] = 304;
906
+    }
907
+
908
+    $result['headers'] = implode('', $result['headers']);
909
+
910
+    return $result;
911 911
 }
912 912
 
913 913
 /**
@@ -929,20 +929,20 @@  discard block
 block discarded – undo
929 929
  *     - le tableau des entetes dans tous les autres cas
930 930
  **/
931 931
 function recuperer_entetes($f, $date_verif = '') {
932
-	//Cas ou la page distante n'a pas bouge depuis
933
-	//la derniere visite
934
-	$res = recuperer_entetes_complets($f, $date_verif);
935
-	if (!$res) {
936
-		return false;
937
-	}
938
-	if ($res['location']) {
939
-		return $res['location'];
940
-	}
941
-	if ($res['status'] != 200) {
942
-		return $res['status'];
943
-	}
944
-
945
-	return explode("\n", $res['headers']);
932
+    //Cas ou la page distante n'a pas bouge depuis
933
+    //la derniere visite
934
+    $res = recuperer_entetes_complets($f, $date_verif);
935
+    if (!$res) {
936
+        return false;
937
+    }
938
+    if ($res['location']) {
939
+        return $res['location'];
940
+    }
941
+    if ($res['status'] != 200) {
942
+        return $res['status'];
943
+    }
944
+
945
+    return explode("\n", $res['headers']);
946 946
 }
947 947
 
948 948
 /**
@@ -964,22 +964,22 @@  discard block
 block discarded – undo
964 964
  *     Nom du fichier pour copie locale
965 965
  **/
966 966
 function nom_fichier_copie_locale($source, $extension) {
967
-	include_spip('inc/documents');
967
+    include_spip('inc/documents');
968 968
 
969
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
970
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
969
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
970
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
971 971
 
972
-	// on se place tout le temps comme si on etait a la racine
973
-	if (_DIR_RACINE) {
974
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
-	}
972
+    // on se place tout le temps comme si on etait a la racine
973
+    if (_DIR_RACINE) {
974
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
+    }
976 976
 
977
-	$m = md5($source);
977
+    $m = md5($source);
978 978
 
979
-	return $d
980
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
-	. substr($m, 0, 4)
982
-	. ".$extension";
979
+    return $d
980
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
+    . substr($m, 0, 4)
982
+    . ".$extension";
983 983
 }
984 984
 
985 985
 /**
@@ -997,68 +997,68 @@  discard block
 block discarded – undo
997 997
  *      Nom du fichier calculé
998 998
  **/
999 999
 function fichier_copie_locale($source) {
1000
-	// Si c'est deja local pas de souci
1001
-	if (!tester_url_absolue($source)) {
1002
-		if (_DIR_RACINE) {
1003
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
-		}
1005
-
1006
-		return $source;
1007
-	}
1008
-
1009
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1010
-	// a deja ete copie en local avec cette extension
1011
-	// dans ce cas elle est fiable, pas la peine de requeter en base
1012
-	$path_parts = pathinfo($source);
1013
-	if (!isset($path_parts['extension'])) {
1014
-		$path_parts['extension'] = '';
1015
-	}
1016
-	$ext = $path_parts ? $path_parts['extension'] : '';
1017
-	if ($ext
1018
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019
-		and $f = nom_fichier_copie_locale($source, $ext)
1020
-		and file_exists(_DIR_RACINE . $f)
1021
-	) {
1022
-		return $f;
1023
-	}
1024
-
1025
-
1026
-	// Si c'est deja dans la table des documents,
1027
-	// ramener le nom de sa copie potentielle
1028
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
-
1030
-	if ($ext) {
1031
-		return nom_fichier_copie_locale($source, $ext);
1032
-	}
1033
-
1034
-	// voir si l'extension indiquee dans le nom du fichier est ok
1035
-	// et si il n'aurait pas deja ete rapatrie
1036
-
1037
-	$ext = $path_parts ? $path_parts['extension'] : '';
1038
-
1039
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
-		$f = nom_fichier_copie_locale($source, $ext);
1041
-		if (file_exists(_DIR_RACINE . $f)) {
1042
-			return $f;
1043
-		}
1044
-	}
1045
-
1046
-	// Ping  pour voir si son extension est connue et autorisee
1047
-	// avec mise en cache du resultat du ping
1048
-
1049
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
-	if (!@file_exists($cache)
1051
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052
-		or _request('var_mode') == 'recalcul'
1053
-	) {
1054
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1055
-		ecrire_fichier($cache, serialize($path_parts));
1056
-	}
1057
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
-		return nom_fichier_copie_locale($source, $ext);
1060
-	}
1061
-	spip_log("pas de copie locale pour $source");
1000
+    // Si c'est deja local pas de souci
1001
+    if (!tester_url_absolue($source)) {
1002
+        if (_DIR_RACINE) {
1003
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
+        }
1005
+
1006
+        return $source;
1007
+    }
1008
+
1009
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1010
+    // a deja ete copie en local avec cette extension
1011
+    // dans ce cas elle est fiable, pas la peine de requeter en base
1012
+    $path_parts = pathinfo($source);
1013
+    if (!isset($path_parts['extension'])) {
1014
+        $path_parts['extension'] = '';
1015
+    }
1016
+    $ext = $path_parts ? $path_parts['extension'] : '';
1017
+    if ($ext
1018
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019
+        and $f = nom_fichier_copie_locale($source, $ext)
1020
+        and file_exists(_DIR_RACINE . $f)
1021
+    ) {
1022
+        return $f;
1023
+    }
1024
+
1025
+
1026
+    // Si c'est deja dans la table des documents,
1027
+    // ramener le nom de sa copie potentielle
1028
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
+
1030
+    if ($ext) {
1031
+        return nom_fichier_copie_locale($source, $ext);
1032
+    }
1033
+
1034
+    // voir si l'extension indiquee dans le nom du fichier est ok
1035
+    // et si il n'aurait pas deja ete rapatrie
1036
+
1037
+    $ext = $path_parts ? $path_parts['extension'] : '';
1038
+
1039
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
+        $f = nom_fichier_copie_locale($source, $ext);
1041
+        if (file_exists(_DIR_RACINE . $f)) {
1042
+            return $f;
1043
+        }
1044
+    }
1045
+
1046
+    // Ping  pour voir si son extension est connue et autorisee
1047
+    // avec mise en cache du resultat du ping
1048
+
1049
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
+    if (!@file_exists($cache)
1051
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052
+        or _request('var_mode') == 'recalcul'
1053
+    ) {
1054
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1055
+        ecrire_fichier($cache, serialize($path_parts));
1056
+    }
1057
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
+        return nom_fichier_copie_locale($source, $ext);
1060
+    }
1061
+    spip_log("pas de copie locale pour $source");
1062 1062
 }
1063 1063
 
1064 1064
 
@@ -1086,140 +1086,140 @@  discard block
 block discarded – undo
1086 1086
  **/
1087 1087
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1088 1088
 
1089
-	// pas la peine de perdre son temps
1090
-	if (!tester_url_absolue($source)) {
1091
-		return false;
1092
-	}
1093
-
1094
-	# charger les alias des types mime
1095
-	include_spip('base/typedoc');
1096
-
1097
-	$a = array();
1098
-	$mime_type = '';
1099
-	// On va directement charger le debut des images et des fichiers html,
1100
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1101
-	// ca echoue l'utilisateur devra les entrer...
1102
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1103
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1104
-
1105
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1106
-			$mime_type = (trim($regs[1]));
1107
-		} else {
1108
-			$mime_type = '';
1109
-		} // inconnu
1110
-
1111
-		// Appliquer les alias
1112
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1113
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1114
-		}
1115
-
1116
-		// Si on a un mime-type insignifiant
1117
-		// text/plain,application/octet-stream ou vide
1118
-		// c'est peut-etre que le serveur ne sait pas
1119
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1120
-		// ou le Content-Disposition: attachment; filename=...
1121
-		$t = null;
1122
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1123
-			if (!$t
1124
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125
-			) {
1126
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
-			}
1128
-			if (!$t
1129
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131
-			) {
1132
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
-			}
1134
-		}
1135
-
1136
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137
-		if (!$t) {
1138
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
-		}
1140
-
1141
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1142
-		// On essaie de nouveau avec l'extension
1143
-		if (!$t
1144
-			and $mime_type != 'text/plain'
1145
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146
-		) {
1147
-			# eviter xxx.3 => 3gp (> SPIP 3)
1148
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
-		}
1150
-
1151
-		if ($t) {
1152
-			spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1153
-			$a['extension'] = $t['extension'];
1154
-		} else {
1155
-			# par defaut on retombe sur '.bin' si c'est autorise
1156
-			spip_log("mime-type $mime_type inconnu");
1157
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1158
-			if (!$t) {
1159
-				return false;
1160
-			}
1161
-			$a['extension'] = $t['extension'];
1162
-		}
1163
-
1164
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1165
-			$a['taille'] = intval($regs[1]);
1166
-		}
1167
-	}
1168
-
1169
-	// Echec avec HEAD, on tente avec GET
1170
-	if (!$a and !$max) {
1171
-		spip_log("tenter GET $source");
1172
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1173
-	}
1174
-
1175
-	// si on a rien trouve pas la peine d'insister
1176
-	if (!$a) {
1177
-		return false;
1178
-	}
1179
-
1180
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1181
-	// recharger le document en GET et recuperer des donnees supplementaires...
1182
-	if (preg_match(',^image/(jpeg|gif|png|swf|svg),', $mime_type)) {
1183
-		if ($max == 0
1184
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1185
-			and in_array($a['extension'], formats_image_acceptables())
1186
-			and $charger_si_petite_image
1187
-		) {
1188
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189
-		} else {
1190
-			if ($a['body']) {
1191
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1192
-				ecrire_fichier($a['fichier'], $a['body']);
1193
-				$size_image = @spip_getimagesize($a['fichier']);
1194
-				$a['largeur'] = intval($size_image[0]);
1195
-				$a['hauteur'] = intval($size_image[1]);
1196
-				$a['type_image'] = true;
1197
-			}
1198
-		}
1199
-	}
1200
-
1201
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1202
-	// ce sera mieux que 0x0
1203
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1204
-		and empty($a['largeur'])
1205
-	) {
1206
-		$a['largeur'] = 425;
1207
-		$a['hauteur'] = 350;
1208
-	}
1209
-
1210
-	if ($mime_type == 'text/html') {
1211
-		include_spip('inc/filtres');
1212
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1213
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1214
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1215
-		}
1216
-		if (!isset($a['taille']) or !$a['taille']) {
1217
-			$a['taille'] = strlen($page); # a peu pres
1218
-		}
1219
-	}
1220
-	$a['mime_type'] = $mime_type;
1221
-
1222
-	return $a;
1089
+    // pas la peine de perdre son temps
1090
+    if (!tester_url_absolue($source)) {
1091
+        return false;
1092
+    }
1093
+
1094
+    # charger les alias des types mime
1095
+    include_spip('base/typedoc');
1096
+
1097
+    $a = array();
1098
+    $mime_type = '';
1099
+    // On va directement charger le debut des images et des fichiers html,
1100
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1101
+    // ca echoue l'utilisateur devra les entrer...
1102
+    if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1103
+        list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1104
+
1105
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1106
+            $mime_type = (trim($regs[1]));
1107
+        } else {
1108
+            $mime_type = '';
1109
+        } // inconnu
1110
+
1111
+        // Appliquer les alias
1112
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1113
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1114
+        }
1115
+
1116
+        // Si on a un mime-type insignifiant
1117
+        // text/plain,application/octet-stream ou vide
1118
+        // c'est peut-etre que le serveur ne sait pas
1119
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1120
+        // ou le Content-Disposition: attachment; filename=...
1121
+        $t = null;
1122
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1123
+            if (!$t
1124
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125
+            ) {
1126
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
+            }
1128
+            if (!$t
1129
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131
+            ) {
1132
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
+            }
1134
+        }
1135
+
1136
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137
+        if (!$t) {
1138
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
+        }
1140
+
1141
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1142
+        // On essaie de nouveau avec l'extension
1143
+        if (!$t
1144
+            and $mime_type != 'text/plain'
1145
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146
+        ) {
1147
+            # eviter xxx.3 => 3gp (> SPIP 3)
1148
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
+        }
1150
+
1151
+        if ($t) {
1152
+            spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1153
+            $a['extension'] = $t['extension'];
1154
+        } else {
1155
+            # par defaut on retombe sur '.bin' si c'est autorise
1156
+            spip_log("mime-type $mime_type inconnu");
1157
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1158
+            if (!$t) {
1159
+                return false;
1160
+            }
1161
+            $a['extension'] = $t['extension'];
1162
+        }
1163
+
1164
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1165
+            $a['taille'] = intval($regs[1]);
1166
+        }
1167
+    }
1168
+
1169
+    // Echec avec HEAD, on tente avec GET
1170
+    if (!$a and !$max) {
1171
+        spip_log("tenter GET $source");
1172
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1173
+    }
1174
+
1175
+    // si on a rien trouve pas la peine d'insister
1176
+    if (!$a) {
1177
+        return false;
1178
+    }
1179
+
1180
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1181
+    // recharger le document en GET et recuperer des donnees supplementaires...
1182
+    if (preg_match(',^image/(jpeg|gif|png|swf|svg),', $mime_type)) {
1183
+        if ($max == 0
1184
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1185
+            and in_array($a['extension'], formats_image_acceptables())
1186
+            and $charger_si_petite_image
1187
+        ) {
1188
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189
+        } else {
1190
+            if ($a['body']) {
1191
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1192
+                ecrire_fichier($a['fichier'], $a['body']);
1193
+                $size_image = @spip_getimagesize($a['fichier']);
1194
+                $a['largeur'] = intval($size_image[0]);
1195
+                $a['hauteur'] = intval($size_image[1]);
1196
+                $a['type_image'] = true;
1197
+            }
1198
+        }
1199
+    }
1200
+
1201
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1202
+    // ce sera mieux que 0x0
1203
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1204
+        and empty($a['largeur'])
1205
+    ) {
1206
+        $a['largeur'] = 425;
1207
+        $a['hauteur'] = 350;
1208
+    }
1209
+
1210
+    if ($mime_type == 'text/html') {
1211
+        include_spip('inc/filtres');
1212
+        $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1213
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1214
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1215
+        }
1216
+        if (!isset($a['taille']) or !$a['taille']) {
1217
+            $a['taille'] = strlen($page); # a peu pres
1218
+        }
1219
+    }
1220
+    $a['mime_type'] = $mime_type;
1221
+
1222
+    return $a;
1223 1223
 }
1224 1224
 
1225 1225
 
@@ -1235,45 +1235,45 @@  discard block
 block discarded – undo
1235 1235
  * @return string
1236 1236
  */
1237 1237
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1238
-	if (is_null($http_proxy)) {
1239
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1240
-	}
1241
-	// rien a faire si pas de proxy :)
1242
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1243
-		return '';
1244
-	}
1245
-
1246
-	if (is_null($http_noproxy)) {
1247
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1248
-	}
1249
-	// si pas d'exception, on retourne le proxy
1250
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1251
-		return $http_proxy;
1252
-	}
1253
-
1254
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1255
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1256
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1257
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1258
-	$http_noproxy = " $http_noproxy ";
1259
-	$domain = $host;
1260
-	// si le domaine exact www.example.org est dans les exceptions
1261
-	if (strpos($http_noproxy, " $domain ") !== false)
1262
-		return '';
1263
-
1264
-	while (strpos($domain, '.') !== false) {
1265
-		$domain = explode('.', $domain);
1266
-		array_shift($domain);
1267
-		$domain = implode('.', $domain);
1268
-
1269
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1270
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1271
-			return '';
1272
-		}
1273
-	}
1274
-
1275
-	// ok c'est pas une exception
1276
-	return $http_proxy;
1238
+    if (is_null($http_proxy)) {
1239
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1240
+    }
1241
+    // rien a faire si pas de proxy :)
1242
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1243
+        return '';
1244
+    }
1245
+
1246
+    if (is_null($http_noproxy)) {
1247
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1248
+    }
1249
+    // si pas d'exception, on retourne le proxy
1250
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1251
+        return $http_proxy;
1252
+    }
1253
+
1254
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1255
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1256
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1257
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1258
+    $http_noproxy = " $http_noproxy ";
1259
+    $domain = $host;
1260
+    // si le domaine exact www.example.org est dans les exceptions
1261
+    if (strpos($http_noproxy, " $domain ") !== false)
1262
+        return '';
1263
+
1264
+    while (strpos($domain, '.') !== false) {
1265
+        $domain = explode('.', $domain);
1266
+        array_shift($domain);
1267
+        $domain = implode('.', $domain);
1268
+
1269
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1270
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1271
+            return '';
1272
+        }
1273
+    }
1274
+
1275
+    // ok c'est pas une exception
1276
+    return $http_proxy;
1277 1277
 }
1278 1278
 
1279 1279
 
@@ -1296,58 +1296,58 @@  discard block
 block discarded – undo
1296 1296
  * @return array
1297 1297
  */
1298 1298
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1299
-	$user = $via_proxy = $proxy_user = '';
1300
-	$fopen = false;
1301
-
1302
-	$t = @parse_url($url);
1303
-	$host = $t['host'];
1304
-	if ($t['scheme'] == 'http') {
1305
-		$scheme = 'http';
1306
-		$noproxy = '';
1307
-	} elseif ($t['scheme'] == 'https') {
1308
-		$scheme = 'ssl';
1309
-		$noproxy = 'ssl://';
1310
-		if (!isset($t['port']) || !($port = $t['port'])) {
1311
-			$t['port'] = 443;
1312
-		}
1313
-	} else {
1314
-		$scheme = $t['scheme'];
1315
-		$noproxy = $scheme . '://';
1316
-	}
1317
-	if (isset($t['user'])) {
1318
-		$user = array($t['user'], $t['pass']);
1319
-	}
1320
-
1321
-	if (!isset($t['port']) || !($port = $t['port'])) {
1322
-		$port = 80;
1323
-	}
1324
-	if (!isset($t['path']) || !($path = $t['path'])) {
1325
-		$path = '/';
1326
-	}
1327
-
1328
-	if (!empty($t['query'])) {
1329
-		$path .= '?' . $t['query'];
1330
-	}
1331
-
1332
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1333
-	if (!$f or !is_resource($f)) {
1334
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1335
-		// ce qui correspond a $f===110
1336
-		if ($f !== 110
1337
-			and !need_proxy($host)
1338
-			and !_request('tester_proxy')
1339
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1340
-		) {
1341
-			$f = @fopen($url, 'rb');
1342
-			spip_log("connexion vers $url par simple fopen");
1343
-			$fopen = true;
1344
-		} else {
1345
-			// echec total
1346
-			$f = false;
1347
-		}
1348
-	}
1349
-
1350
-	return array($f, $fopen);
1299
+    $user = $via_proxy = $proxy_user = '';
1300
+    $fopen = false;
1301
+
1302
+    $t = @parse_url($url);
1303
+    $host = $t['host'];
1304
+    if ($t['scheme'] == 'http') {
1305
+        $scheme = 'http';
1306
+        $noproxy = '';
1307
+    } elseif ($t['scheme'] == 'https') {
1308
+        $scheme = 'ssl';
1309
+        $noproxy = 'ssl://';
1310
+        if (!isset($t['port']) || !($port = $t['port'])) {
1311
+            $t['port'] = 443;
1312
+        }
1313
+    } else {
1314
+        $scheme = $t['scheme'];
1315
+        $noproxy = $scheme . '://';
1316
+    }
1317
+    if (isset($t['user'])) {
1318
+        $user = array($t['user'], $t['pass']);
1319
+    }
1320
+
1321
+    if (!isset($t['port']) || !($port = $t['port'])) {
1322
+        $port = 80;
1323
+    }
1324
+    if (!isset($t['path']) || !($path = $t['path'])) {
1325
+        $path = '/';
1326
+    }
1327
+
1328
+    if (!empty($t['query'])) {
1329
+        $path .= '?' . $t['query'];
1330
+    }
1331
+
1332
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1333
+    if (!$f or !is_resource($f)) {
1334
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1335
+        // ce qui correspond a $f===110
1336
+        if ($f !== 110
1337
+            and !need_proxy($host)
1338
+            and !_request('tester_proxy')
1339
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1340
+        ) {
1341
+            $f = @fopen($url, 'rb');
1342
+            spip_log("connexion vers $url par simple fopen");
1343
+            $fopen = true;
1344
+        } else {
1345
+            // echec total
1346
+            $f = false;
1347
+        }
1348
+    }
1349
+
1350
+    return array($f, $fopen);
1351 1351
 }
1352 1352
 
1353 1353
 /**
@@ -1382,127 +1382,127 @@  discard block
 block discarded – undo
1382 1382
  *   resource socket vers l'url demandee
1383 1383
  */
1384 1384
 function lance_requete(
1385
-	$method,
1386
-	$scheme,
1387
-	$user,
1388
-	$host,
1389
-	$path,
1390
-	$port,
1391
-	$noproxy,
1392
-	$refuse_gz = false,
1393
-	$referer = '',
1394
-	$datas = '',
1395
-	$vers = 'HTTP/1.0',
1396
-	$date = ''
1385
+    $method,
1386
+    $scheme,
1387
+    $user,
1388
+    $host,
1389
+    $path,
1390
+    $port,
1391
+    $noproxy,
1392
+    $refuse_gz = false,
1393
+    $referer = '',
1394
+    $datas = '',
1395
+    $vers = 'HTTP/1.0',
1396
+    $date = ''
1397 1397
 ) {
1398 1398
 
1399
-	$proxy_user = '';
1400
-	$http_proxy = need_proxy($host);
1401
-	if ($user) {
1402
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1403
-	}
1404
-
1405
-	$connect = '';
1406
-	if ($http_proxy) {
1407
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1410
-				. "Host: $path_host\r\n"
1411
-				. "Proxy-Connection: Keep-Alive\r\n";
1412
-		} else {
1413
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1414
-				. (!$user ? '' : "$user@")
1415
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1416
-		}
1417
-		$t2 = @parse_url($http_proxy);
1418
-		$first_host = $t2['host'];
1419
-		if (!($port = $t2['port'])) {
1420
-			$port = 80;
1421
-		}
1422
-		if ($t2['user']) {
1423
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1424
-		}
1425
-	} else {
1426
-		$first_host = $noproxy . $host;
1427
-	}
1428
-
1429
-	if ($connect) {
1430
-		$streamContext = stream_context_create(array(
1431
-			'ssl' => array(
1432
-				'verify_peer' => false,
1433
-				'allow_self_signed' => true,
1434
-				'SNI_enabled' => true,
1435
-				'peer_name' => $host,
1436
-			)
1437
-		));
1438
-		if (version_compare(phpversion(), '5.6', '<')) {
1439
-			stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1440
-		}
1441
-		$f = @stream_socket_client(
1442
-			"tcp://$first_host:$port",
1443
-			$errno,
1444
-			$errstr,
1445
-			_INC_DISTANT_CONNECT_TIMEOUT,
1446
-			STREAM_CLIENT_CONNECT,
1447
-			$streamContext
1448
-		);
1449
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1450
-		if (!$f) {
1451
-			spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1452
-			return $errno;
1453
-		}
1454
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1455
-
1456
-		fputs($f, $connect);
1457
-		fputs($f, "\r\n");
1458
-		$res = fread($f, 1024);
1459
-		if (!$res
1460
-			or !count($res = explode(' ', $res))
1461
-			or $res[1] !== '200'
1462
-		) {
1463
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1464
-			fclose($f);
1465
-
1466
-			return false;
1467
-		}
1468
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1469
-		stream_set_blocking($f, true);
1470
-		// envoyer le handshake
1471
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1472
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1473
-	} else {
1474
-		$ntry = 3;
1475
-		do {
1476
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1477
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1478
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1479
-		if (!$f) {
1480
-			spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1481
-
1482
-			return $errno;
1483
-		}
1484
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1485
-	}
1486
-
1487
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488
-
1489
-	$host_port = $host;
1490
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1491
-		$host_port .= ":$port";
1492
-	}
1493
-	$req = "$method $path $vers\r\n"
1494
-		. "Host: $host_port\r\n"
1495
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1497
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1498
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1500
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1399
+    $proxy_user = '';
1400
+    $http_proxy = need_proxy($host);
1401
+    if ($user) {
1402
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1403
+    }
1404
+
1405
+    $connect = '';
1406
+    if ($http_proxy) {
1407
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1410
+                . "Host: $path_host\r\n"
1411
+                . "Proxy-Connection: Keep-Alive\r\n";
1412
+        } else {
1413
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1414
+                . (!$user ? '' : "$user@")
1415
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1416
+        }
1417
+        $t2 = @parse_url($http_proxy);
1418
+        $first_host = $t2['host'];
1419
+        if (!($port = $t2['port'])) {
1420
+            $port = 80;
1421
+        }
1422
+        if ($t2['user']) {
1423
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1424
+        }
1425
+    } else {
1426
+        $first_host = $noproxy . $host;
1427
+    }
1428
+
1429
+    if ($connect) {
1430
+        $streamContext = stream_context_create(array(
1431
+            'ssl' => array(
1432
+                'verify_peer' => false,
1433
+                'allow_self_signed' => true,
1434
+                'SNI_enabled' => true,
1435
+                'peer_name' => $host,
1436
+            )
1437
+        ));
1438
+        if (version_compare(phpversion(), '5.6', '<')) {
1439
+            stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1440
+        }
1441
+        $f = @stream_socket_client(
1442
+            "tcp://$first_host:$port",
1443
+            $errno,
1444
+            $errstr,
1445
+            _INC_DISTANT_CONNECT_TIMEOUT,
1446
+            STREAM_CLIENT_CONNECT,
1447
+            $streamContext
1448
+        );
1449
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1450
+        if (!$f) {
1451
+            spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1452
+            return $errno;
1453
+        }
1454
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1455
+
1456
+        fputs($f, $connect);
1457
+        fputs($f, "\r\n");
1458
+        $res = fread($f, 1024);
1459
+        if (!$res
1460
+            or !count($res = explode(' ', $res))
1461
+            or $res[1] !== '200'
1462
+        ) {
1463
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1464
+            fclose($f);
1465
+
1466
+            return false;
1467
+        }
1468
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1469
+        stream_set_blocking($f, true);
1470
+        // envoyer le handshake
1471
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1472
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1473
+    } else {
1474
+        $ntry = 3;
1475
+        do {
1476
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1477
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1478
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1479
+        if (!$f) {
1480
+            spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1481
+
1482
+            return $errno;
1483
+        }
1484
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1485
+    }
1486
+
1487
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488
+
1489
+    $host_port = $host;
1490
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1491
+        $host_port .= ":$port";
1492
+    }
1493
+    $req = "$method $path $vers\r\n"
1494
+        . "Host: $host_port\r\n"
1495
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1497
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1498
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1500
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1502 1502
 
1503 1503
 #	spip_log("Requete\n$req");
1504
-	fputs($f, $req);
1505
-	fputs($f, $datas ? $datas : "\r\n");
1504
+    fputs($f, $req);
1505
+    fputs($f, $datas ? $datas : "\r\n");
1506 1506
 
1507
-	return $f;
1507
+    return $f;
1508 1508
 }
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32 32
 	define('_INC_DISTANT_MAX_SIZE', 2097152);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38
-define('_REGEXP_COPIE_LOCALE', ',' 	.
38
+define('_REGEXP_COPIE_LOCALE', ','.
39 39
 	preg_replace(
40 40
 		'@^https?:@',
41 41
 		'https?:',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// si c'est la protection de soi-meme, retourner le path
72 72
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
73
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
74 74
 
75 75
 		return @file_exists($source) ? $source : false;
76 76
 	}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		return false;
91 91
 	}
92 92
 
93
-	$localrac = _DIR_RACINE . $local;
93
+	$localrac = _DIR_RACINE.$local;
94 94
 	$t = ($mode == 'force') ? false : @file_exists($localrac);
95 95
 
96 96
 	// test d'existence du fichier
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116 116
 		);
117 117
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], _LOG_INFO_IMPORTANTE);
119 119
 		}
120 120
 		if (!$res['length']) {
121 121
 			// si $t c'est sans doute juste un not-modified-since
122 122
 			return $t ? $local : false;
123 123
 		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK');
124
+		spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK');
125 125
 
126 126
 		// pour une eventuelle indexation
127 127
 		pipeline(
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
156
+	if (!function_exists('protocole_verifier')) {
157 157
 		include_spip('inc/filtres_mini');
158 158
 	}
159 159
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 	
164 164
 	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
165
+	if (!$parsed_url or empty($parsed_url['host'])) {
166 166
 		return false;
167 167
 	}
168 168
 
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 			}
204 204
 		}
205 205
 		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
206
+			$parts = array_map('intval', explode('.', $ip));
207 207
 			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
208
+			  or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1])
209
+			  or (192 === $parts[0] && 168 === $parts[1])
210 210
 			) {
211 211
 				return false;
212 212
 			}
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
221
+	if ($port === 80 or $port === 443 or $port === 8080) {
222 222
 		return $url;
223 223
 	}
224 224
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				}
286 286
 			}
287 287
 			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
288
+				$boundary = substr(md5(rand().'spip'), 0, 8);
289 289
 			}
290 290
 		}
291 291
 
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 			}
314 314
 		} else {
315 315
 			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
316
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
317 317
 			$chaine = array();
318 318
 			if (is_array($donnees)) {
319 319
 				foreach ($donnees as $cle => $valeur) {
320 320
 					if (is_array($valeur)) {
321 321
 						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
322
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
323 323
 						}
324 324
 					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
325
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
326 326
 					}
327 327
 				}
328 328
 				$chaine = implode('&', $chaine);
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	if (!empty($options['datas'])) {
424 424
 		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425 425
 		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
426
+			$head .= 'Content-Length: '.strlen($postdata);
427 427
 		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
428
+		$options['datas'] = $head."\r\n\r\n".$postdata;
429 429
 		if (strlen($postdata)) {
430 430
 			$options['methode'] = 'POST';
431 431
 		}
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435 435
 	$url = preg_replace(',^feed://,i', 'http://', $url);
436 436
 	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
437
+		$url = 'http://'.$url;
438 438
 	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
439
+		$url = 'http:'.$url;
440 440
 	}
441 441
 
442 442
 	$url = url_to_ascii($url);
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 
506 506
 			return recuperer_url($url, $options);
507 507
 		} elseif ($res['status'] !== 200) {
508
-			spip_log('HTTP status ' . $res['status'] . " pour $url");
508
+			spip_log('HTTP status '.$res['status']." pour $url");
509 509
 		}
510 510
 		$result['status'] = $res['status'];
511 511
 		if (isset($res['headers'])) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 
531 531
 	$gz = false;
532 532
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
533
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
534 534
 	}
535 535
 
536 536
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 	$sig['url'] = $url;
617 617
 
618 618
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
619
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
619
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
620 620
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
621 621
 	$cache = "$sub$cache";
622 622
 
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 		return false;
726 726
 	}
727 727
 	if ($get_headers) {
728
-		return $res['headers'] . "\n" . $res['page'];
728
+		return $res['headers']."\n".$res['page'];
729 729
 	}
730 730
 
731 731
 	return $res['page'];
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 	$fp = false;
830 830
 	if ($fichier) {
831 831
 		include_spip('inc/acces');
832
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
832
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
833 833
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834 834
 		if (!$fp and file_exists($fichier)) {
835 835
 			return filesize($fichier);
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 	}
889 889
 	$result['status'] = intval($r[1]);
890 890
 	while ($s = trim(fgets($handle, 16384))) {
891
-		$result['headers'][] = $s . "\n";
891
+		$result['headers'][] = $s."\n";
892 892
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893 893
 		list(, $d, $v) = $r;
894 894
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -971,13 +971,13 @@  discard block
 block discarded – undo
971 971
 
972 972
 	// on se place tout le temps comme si on etait a la racine
973 973
 	if (_DIR_RACINE) {
974
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
974
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
975 975
 	}
976 976
 
977 977
 	$m = md5($source);
978 978
 
979 979
 	return $d
980
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
980
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
981 981
 	. substr($m, 0, 4)
982 982
 	. ".$extension";
983 983
 }
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 	// Si c'est deja local pas de souci
1001 1001
 	if (!tester_url_absolue($source)) {
1002 1002
 		if (_DIR_RACINE) {
1003
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1003
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
1004 1004
 		}
1005 1005
 
1006 1006
 		return $source;
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 	if ($ext
1018 1018
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019 1019
 		and $f = nom_fichier_copie_locale($source, $ext)
1020
-		and file_exists(_DIR_RACINE . $f)
1020
+		and file_exists(_DIR_RACINE.$f)
1021 1021
 	) {
1022 1022
 		return $f;
1023 1023
 	}
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 
1026 1026
 	// Si c'est deja dans la table des documents,
1027 1027
 	// ramener le nom de sa copie potentielle
1028
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1028
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
1029 1029
 
1030 1030
 	if ($ext) {
1031 1031
 		return nom_fichier_copie_locale($source, $ext);
@@ -1036,9 +1036,9 @@  discard block
 block discarded – undo
1036 1036
 
1037 1037
 	$ext = $path_parts ? $path_parts['extension'] : '';
1038 1038
 
1039
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1039
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1040 1040
 		$f = nom_fichier_copie_locale($source, $ext);
1041
-		if (file_exists(_DIR_RACINE . $f)) {
1041
+		if (file_exists(_DIR_RACINE.$f)) {
1042 1042
 			return $f;
1043 1043
 		}
1044 1044
 	}
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 	// Ping  pour voir si son extension est connue et autorisee
1047 1047
 	// avec mise en cache du resultat du ping
1048 1048
 
1049
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1049
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
1050 1050
 	if (!@file_exists($cache)
1051 1051
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052 1052
 		or _request('var_mode') == 'recalcul'
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 		ecrire_fichier($cache, serialize($path_parts));
1056 1056
 	}
1057 1057
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1058
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1059 1059
 		return nom_fichier_copie_locale($source, $ext);
1060 1060
 	}
1061 1061
 	spip_log("pas de copie locale pour $source");
@@ -1123,19 +1123,19 @@  discard block
 block discarded – undo
1123 1123
 			if (!$t
1124 1124
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125 1125
 			) {
1126
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1126
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1127 1127
 			}
1128 1128
 			if (!$t
1129 1129
 				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130 1130
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131 1131
 			) {
1132
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1132
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1133 1133
 			}
1134 1134
 		}
1135 1135
 
1136 1136
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137 1137
 		if (!$t) {
1138
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1138
+			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1139 1139
 		}
1140 1140
 
1141 1141
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1145,11 +1145,11 @@  discard block
 block discarded – undo
1145 1145
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146 1146
 		) {
1147 1147
 			# eviter xxx.3 => 3gp (> SPIP 3)
1148
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1148
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1149 1149
 		}
1150 1150
 
1151 1151
 		if ($t) {
1152
-			spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1152
+			spip_log("mime-type $mime_type ok, extension ".$t['extension']);
1153 1153
 			$a['extension'] = $t['extension'];
1154 1154
 		} else {
1155 1155
 			# par defaut on retombe sur '.bin' si c'est autorise
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189 1189
 		} else {
1190 1190
 			if ($a['body']) {
1191
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1191
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $a['extension']);
1192 1192
 				ecrire_fichier($a['fichier'], $a['body']);
1193 1193
 				$size_image = @spip_getimagesize($a['fichier']);
1194 1194
 				$a['largeur'] = intval($size_image[0]);
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
 		}
1313 1313
 	} else {
1314 1314
 		$scheme = $t['scheme'];
1315
-		$noproxy = $scheme . '://';
1315
+		$noproxy = $scheme.'://';
1316 1316
 	}
1317 1317
 	if (isset($t['user'])) {
1318 1318
 		$user = array($t['user'], $t['pass']);
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 	}
1327 1327
 
1328 1328
 	if (!empty($t['query'])) {
1329
-		$path .= '?' . $t['query'];
1329
+		$path .= '?'.$t['query'];
1330 1330
 	}
1331 1331
 
1332 1332
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1399,20 +1399,20 @@  discard block
 block discarded – undo
1399 1399
 	$proxy_user = '';
1400 1400
 	$http_proxy = need_proxy($host);
1401 1401
 	if ($user) {
1402
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1402
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1403 1403
 	}
1404 1404
 
1405 1405
 	$connect = '';
1406 1406
 	if ($http_proxy) {
1407
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1407
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) {
1408
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1409
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1410 1410
 				. "Host: $path_host\r\n"
1411 1411
 				. "Proxy-Connection: Keep-Alive\r\n";
1412 1412
 		} else {
1413
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1413
+			$path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://")
1414 1414
 				. (!$user ? '' : "$user@")
1415
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1415
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1416 1416
 		}
1417 1417
 		$t2 = @parse_url($http_proxy);
1418 1418
 		$first_host = $t2['host'];
@@ -1420,10 +1420,10 @@  discard block
 block discarded – undo
1420 1420
 			$port = 80;
1421 1421
 		}
1422 1422
 		if ($t2['user']) {
1423
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1423
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1424 1424
 		}
1425 1425
 	} else {
1426
-		$first_host = $noproxy . $host;
1426
+		$first_host = $noproxy.$host;
1427 1427
 	}
1428 1428
 
1429 1429
 	if ($connect) {
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
 			or !count($res = explode(' ', $res))
1461 1461
 			or $res[1] !== '200'
1462 1462
 		) {
1463
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1463
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1464 1464
 			fclose($f);
1465 1465
 
1466 1466
 			return false;
@@ -1487,16 +1487,16 @@  discard block
 block discarded – undo
1487 1487
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488 1488
 
1489 1489
 	$host_port = $host;
1490
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1490
+	if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) {
1491 1491
 		$host_port .= ":$port";
1492 1492
 	}
1493 1493
 	$req = "$method $path $vers\r\n"
1494 1494
 		. "Host: $host_port\r\n"
1495
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1495
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1496
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1497 1497
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1498
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1498
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1499
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1500 1500
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501 1501
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1502 1502
 
Please login to merge, or discard this patch.
ecrire/inc/editer.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
  * utile pour les textes > 32ko
315 315
  *
316 316
  * @param  string $texte
317
- * @return array
317
+ * @return string[]
318 318
  */
319 319
 function coupe_trop_long($texte) {
320 320
 	$aider = charger_fonction('aider', 'inc');
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
  *
348 348
  * @param string $texte
349 349
  * @param string $att_text
350
- * @return array
350
+ * @return string[]
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353 353
 	if ((strlen($texte) < 29 * 1024)
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 /**
374 374
  * auto-renseigner le titre si il n'existe pas
375 375
  *
376
- * @param $champ_titre
377
- * @param $champs_contenu
376
+ * @param string $champ_titre
377
+ * @param string[] $champs_contenu
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
Please login to merge, or discard this patch.
Indentation   +457 added lines, -457 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
 include_spip('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = array(),
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = array(),
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = array();
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = array();
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) {
135
-	$erreurs = array();
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = array();
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -198,115 +198,115 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = array(),
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = array(),
208
+    $hidden = ''
209 209
 ) {
210
-	$table_objet = table_objet($type);
211
-	$table_objet_sql = table_objet_sql($type);
212
-	$id_table_objet = id_table_objet($type);
213
-	$new = !is_numeric($id);
214
-	// Appel direct dans un squelette
215
-	if (!$row) {
216
-		if (!$new or $lier_trad) {
217
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
218
-				$row = $select($id, $id_parent, $lier_trad);
219
-			} else {
220
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
221
-			}
222
-			if (!$new) {
223
-				$md5 = controles_md5($row);
224
-			}
225
-		}
226
-		if (!$row) {
227
-			$row = array();
228
-			$trouver_table = charger_fonction('trouver_table', 'base');
229
-			if ($desc = $trouver_table($table_objet)) {
230
-				foreach ($desc['field'] as $k => $v) {
231
-					$row[$k] = '';
232
-				}
233
-			}
234
-		}
235
-	}
236
-
237
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
238
-	// (et donc: pas de lien de traduction)
239
-	$id = ($new or $lier_trad)
240
-		? 'oui'
241
-		: $row[$id_table_objet];
242
-	$row[$id_table_objet] = $id;
243
-
244
-	$contexte = $row;
245
-	if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
246
-		if (!isset($contexte['id_parent'])) {
247
-			unset($contexte['id_rubrique']);
248
-		}
249
-		$contexte['id_parent'] = $id_parent;
250
-	} elseif (!isset($contexte['id_parent'])) {
251
-		// id_rubrique dans id_parent si possible
252
-		if (isset($contexte['id_rubrique'])) {
253
-			$contexte['id_parent'] = $contexte['id_rubrique'];
254
-			unset($contexte['id_rubrique']);
255
-		} else {
256
-			$contexte['id_parent'] = '';
257
-		}
258
-		if (!$contexte['id_parent']
259
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
260
-		) {
261
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
262
-		}
263
-	}
264
-
265
-	$config = array();
266
-	if ($config_fonc) {
267
-		$contexte['config'] = $config = $config_fonc($contexte);
268
-	}
269
-	$config = $config + array(
270
-		'lignes' => 0,
271
-		'langue' => '',
272
-	);
273
-
274
-	$att_text = " class='textarea' "
275
-		. " rows='"
276
-		. ($config['lignes'] + 15)
277
-		. "' cols='40'";
278
-	if (isset($contexte['texte'])) {
279
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
280
-	}
281
-
282
-	// on veut conserver la langue de l'interface ;
283
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
284
-	// voudrait l'exploiter
285
-	if (isset($contexte['lang'])) {
286
-		$contexte['langue'] = $contexte['lang'];
287
-		unset($contexte['lang']);
288
-	}
289
-
290
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
-		(!$lier_trad ? '' :
292
-			("\n<input type='hidden' name='lier_trad' value='" .
293
-				$lier_trad .
294
-				"' />" .
295
-				"\n<input type='hidden' name='changer_lang' value='" .
296
-				$config['langue'] .
297
-				"' />"))
298
-		. $hidden
299
-		. (isset($md5) ? $md5 : '');
300
-
301
-	// preciser que le formulaire doit passer dans un pipeline
302
-	$contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
303
-
304
-	// preciser que le formulaire doit etre securise auteur/action
305
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
306
-	// on le garde pour compat
307
-	$contexte['_action'] = array("editer_$type", $id);
308
-
309
-	return $contexte;
210
+    $table_objet = table_objet($type);
211
+    $table_objet_sql = table_objet_sql($type);
212
+    $id_table_objet = id_table_objet($type);
213
+    $new = !is_numeric($id);
214
+    // Appel direct dans un squelette
215
+    if (!$row) {
216
+        if (!$new or $lier_trad) {
217
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
218
+                $row = $select($id, $id_parent, $lier_trad);
219
+            } else {
220
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
221
+            }
222
+            if (!$new) {
223
+                $md5 = controles_md5($row);
224
+            }
225
+        }
226
+        if (!$row) {
227
+            $row = array();
228
+            $trouver_table = charger_fonction('trouver_table', 'base');
229
+            if ($desc = $trouver_table($table_objet)) {
230
+                foreach ($desc['field'] as $k => $v) {
231
+                    $row[$k] = '';
232
+                }
233
+            }
234
+        }
235
+    }
236
+
237
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
238
+    // (et donc: pas de lien de traduction)
239
+    $id = ($new or $lier_trad)
240
+        ? 'oui'
241
+        : $row[$id_table_objet];
242
+    $row[$id_table_objet] = $id;
243
+
244
+    $contexte = $row;
245
+    if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
246
+        if (!isset($contexte['id_parent'])) {
247
+            unset($contexte['id_rubrique']);
248
+        }
249
+        $contexte['id_parent'] = $id_parent;
250
+    } elseif (!isset($contexte['id_parent'])) {
251
+        // id_rubrique dans id_parent si possible
252
+        if (isset($contexte['id_rubrique'])) {
253
+            $contexte['id_parent'] = $contexte['id_rubrique'];
254
+            unset($contexte['id_rubrique']);
255
+        } else {
256
+            $contexte['id_parent'] = '';
257
+        }
258
+        if (!$contexte['id_parent']
259
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
260
+        ) {
261
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
262
+        }
263
+    }
264
+
265
+    $config = array();
266
+    if ($config_fonc) {
267
+        $contexte['config'] = $config = $config_fonc($contexte);
268
+    }
269
+    $config = $config + array(
270
+        'lignes' => 0,
271
+        'langue' => '',
272
+    );
273
+
274
+    $att_text = " class='textarea' "
275
+        . " rows='"
276
+        . ($config['lignes'] + 15)
277
+        . "' cols='40'";
278
+    if (isset($contexte['texte'])) {
279
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
280
+    }
281
+
282
+    // on veut conserver la langue de l'interface ;
283
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
284
+    // voudrait l'exploiter
285
+    if (isset($contexte['lang'])) {
286
+        $contexte['langue'] = $contexte['lang'];
287
+        unset($contexte['lang']);
288
+    }
289
+
290
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
+        (!$lier_trad ? '' :
292
+            ("\n<input type='hidden' name='lier_trad' value='" .
293
+                $lier_trad .
294
+                "' />" .
295
+                "\n<input type='hidden' name='changer_lang' value='" .
296
+                $config['langue'] .
297
+                "' />"))
298
+        . $hidden
299
+        . (isset($md5) ? $md5 : '');
300
+
301
+    // preciser que le formulaire doit passer dans un pipeline
302
+    $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
303
+
304
+    // preciser que le formulaire doit etre securise auteur/action
305
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
306
+    // on le garde pour compat
307
+    $contexte['_action'] = array("editer_$type", $id);
308
+
309
+    return $contexte;
310 310
 }
311 311
 
312 312
 /**
@@ -317,29 +317,29 @@  discard block
 block discarded – undo
317 317
  * @return array
318 318
  */
319 319
 function coupe_trop_long($texte) {
320
-	$aider = charger_fonction('aider', 'inc');
321
-	if (strlen($texte) > 28 * 1024) {
322
-		$texte = str_replace("\r\n", "\n", $texte);
323
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
324
-		if ($pos > 0 and $pos < 32 * 1024) {
325
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
326
-			$suite = substr($texte, $pos + 2);
327
-		} else {
328
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
329
-			if (!($pos > 0 and $pos < 32 * 1024)) {
330
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
331
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332
-			} else {
333
-				$decalage = 1;
334
-			}
335
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
336
-			$suite = substr($texte, $pos + $decalage);
337
-		}
338
-
339
-		return (array($debut, $suite));
340
-	} else {
341
-		return (array($texte, ''));
342
-	}
320
+    $aider = charger_fonction('aider', 'inc');
321
+    if (strlen($texte) > 28 * 1024) {
322
+        $texte = str_replace("\r\n", "\n", $texte);
323
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
324
+        if ($pos > 0 and $pos < 32 * 1024) {
325
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
326
+            $suite = substr($texte, $pos + 2);
327
+        } else {
328
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
329
+            if (!($pos > 0 and $pos < 32 * 1024)) {
330
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
331
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332
+            } else {
333
+                $decalage = 1;
334
+            }
335
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
336
+            $suite = substr($texte, $pos + $decalage);
337
+        }
338
+
339
+        return (array($debut, $suite));
340
+    } else {
341
+        return (array($texte, ''));
342
+    }
343 343
 }
344 344
 
345 345
 /**
@@ -350,24 +350,24 @@  discard block
 block discarded – undo
350 350
  * @return array
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353
-	if ((strlen($texte) < 29 * 1024)
354
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
355
-	) {
356
-		return array($texte, '');
357
-	}
358
-
359
-	include_spip('inc/barre');
360
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
361
-	$nombre = 0;
362
-
363
-	while (strlen($texte) > 29 * 1024) {
364
-		$nombre++;
365
-		list($texte1, $texte) = coupe_trop_long($texte);
366
-		$textes_supplement .= '<br />' .
367
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368
-	}
369
-
370
-	return array($texte, $textes_supplement);
353
+    if ((strlen($texte) < 29 * 1024)
354
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
355
+    ) {
356
+        return array($texte, '');
357
+    }
358
+
359
+    include_spip('inc/barre');
360
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
361
+    $nombre = 0;
362
+
363
+    while (strlen($texte) > 29 * 1024) {
364
+        $nombre++;
365
+        list($texte1, $texte) = coupe_trop_long($texte);
366
+        $textes_supplement .= '<br />' .
367
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368
+    }
369
+
370
+    return array($texte, $textes_supplement);
371 371
 }
372 372
 
373 373
 /**
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
381
-	if (!_request($champ_titre)) {
382
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
383
-		if (!is_null($longueur)) {
384
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
385
-		} else {
386
-			$t = $titrer_contenu($champs_contenu);
387
-		}
388
-		if ($t) {
389
-			set_request($champ_titre, $t);
390
-		}
391
-	}
381
+    if (!_request($champ_titre)) {
382
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
383
+        if (!is_null($longueur)) {
384
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
385
+        } else {
386
+            $t = $titrer_contenu($champs_contenu);
387
+        }
388
+        if ($t) {
389
+            set_request($champ_titre, $t);
390
+        }
391
+    }
392 392
 }
393 393
 
394 394
 /**
@@ -408,20 +408,20 @@  discard block
 block discarded – undo
408 408
  * @return string
409 409
  */
410 410
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
411
-	// trouver un champ texte non vide
412
-	$t = '';
413
-	foreach ($champs_contenu as $champ) {
414
-		if ($t = _request($champ, $c)) {
415
-			break;
416
-		}
417
-	}
418
-
419
-	if ($t) {
420
-		include_spip('inc/texte_mini');
421
-		$t = couper($t, $longueur, '...');
422
-	}
423
-
424
-	return $t;
411
+    // trouver un champ texte non vide
412
+    $t = '';
413
+    foreach ($champs_contenu as $champ) {
414
+        if ($t = _request($champ, $c)) {
415
+            break;
416
+        }
417
+    }
418
+
419
+    if ($t) {
420
+        include_spip('inc/texte_mini');
421
+        $t = couper($t, $longueur, '...');
422
+    }
423
+
424
+    return $t;
425 425
 }
426 426
 
427 427
 /**
@@ -444,30 +444,30 @@  discard block
 block discarded – undo
444 444
  *      - array sinon couples ('$prefixe$colonne => md5)
445 445
  **/
446 446
 function controles_md5($data, $prefixe = 'ctr_', $format = 'html') {
447
-	if (!is_array($data)) {
448
-		return false;
449
-	}
450
-
451
-	$ctr = array();
452
-	foreach ($data as $key => $val) {
453
-		$m = md5($val);
454
-		$k = $prefixe . $key;
455
-
456
-		switch ($format) {
457
-			case 'html':
458
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
459
-				break;
460
-			default:
461
-				$ctr[$k] = $m;
462
-				break;
463
-		}
464
-	}
465
-
466
-	if ($format == 'html') {
467
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
468
-	} else {
469
-		return $ctr;
470
-	}
447
+    if (!is_array($data)) {
448
+        return false;
449
+    }
450
+
451
+    $ctr = array();
452
+    foreach ($data as $key => $val) {
453
+        $m = md5($val);
454
+        $k = $prefixe . $key;
455
+
456
+        switch ($format) {
457
+            case 'html':
458
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
459
+                break;
460
+            default:
461
+                $ctr[$k] = $m;
462
+                break;
463
+        }
464
+    }
465
+
466
+    if ($format == 'html') {
467
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
468
+    } else {
469
+        return $ctr;
470
+    }
471 471
 }
472 472
 
473 473
 /**
@@ -506,79 +506,79 @@  discard block
 block discarded – undo
506 506
  *     - post : le contenu posté
507 507
  **/
508 508
 function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') {
509
-	include_spip('inc/filtres');
510
-
511
-	$table_objet = table_objet($type);
512
-	$spip_table_objet = table_objet_sql($type);
513
-	$trouver_table = charger_fonction('trouver_table', 'base');
514
-	$desc = $trouver_table($table_objet, $serveur);
515
-
516
-	// Appels incomplets (sans $c)
517
-	if (!is_array($c)) {
518
-		foreach ($desc['field'] as $champ => $ignore) {
519
-			if (_request($champ)) {
520
-				$c[$champ] = _request($champ);
521
-			}
522
-		}
523
-	}
524
-
525
-	// Securite : certaines variables ne sont jamais acceptees ici
526
-	// car elles ne relevent pas de autoriser(article, modifier) ;
527
-	// il faut passer par instituer_XX()
528
-	// TODO: faut-il passer ces variables interdites
529
-	// dans un fichier de description separe ?
530
-	unset($c['statut']);
531
-	unset($c['id_parent']);
532
-	unset($c['id_rubrique']);
533
-	unset($c['id_secteur']);
534
-
535
-	// Gerer les champs non vides
536
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
537
-		foreach ($options['nonvide'] as $champ => $sinon) {
538
-			if ($c[$champ] === '') {
539
-				$c[$champ] = $sinon;
540
-			}
541
-		}
542
-	}
543
-
544
-	// N'accepter que les champs qui existent
545
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
546
-	$champs = array();
547
-	foreach ($desc['field'] as $champ => $ignore) {
548
-		if (isset($c[$champ])) {
549
-			$champs[$champ] = $c[$champ];
550
-		}
551
-	}
552
-
553
-	// Nettoyer les valeurs
554
-	$champs = array_map('corriger_caracteres', $champs);
555
-
556
-	// Envoyer aux plugins
557
-	$champs = pipeline(
558
-		'pre_edition',
559
-		array(
560
-			'args' => array(
561
-				'table' => $spip_table_objet, // compatibilite
562
-				'table_objet' => $table_objet,
563
-				'spip_table_objet' => $spip_table_objet,
564
-				'type' => $type,
565
-				'id_objet' => $id,
566
-				'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
567
-				'action' => 'controler',
568
-				'serveur' => $serveur,
569
-			),
570
-			'data' => $champs
571
-		)
572
-	);
573
-
574
-	if (!$champs) {
575
-		return false;
576
-	}
577
-
578
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
579
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
580
-
581
-	return $conflits;
509
+    include_spip('inc/filtres');
510
+
511
+    $table_objet = table_objet($type);
512
+    $spip_table_objet = table_objet_sql($type);
513
+    $trouver_table = charger_fonction('trouver_table', 'base');
514
+    $desc = $trouver_table($table_objet, $serveur);
515
+
516
+    // Appels incomplets (sans $c)
517
+    if (!is_array($c)) {
518
+        foreach ($desc['field'] as $champ => $ignore) {
519
+            if (_request($champ)) {
520
+                $c[$champ] = _request($champ);
521
+            }
522
+        }
523
+    }
524
+
525
+    // Securite : certaines variables ne sont jamais acceptees ici
526
+    // car elles ne relevent pas de autoriser(article, modifier) ;
527
+    // il faut passer par instituer_XX()
528
+    // TODO: faut-il passer ces variables interdites
529
+    // dans un fichier de description separe ?
530
+    unset($c['statut']);
531
+    unset($c['id_parent']);
532
+    unset($c['id_rubrique']);
533
+    unset($c['id_secteur']);
534
+
535
+    // Gerer les champs non vides
536
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
537
+        foreach ($options['nonvide'] as $champ => $sinon) {
538
+            if ($c[$champ] === '') {
539
+                $c[$champ] = $sinon;
540
+            }
541
+        }
542
+    }
543
+
544
+    // N'accepter que les champs qui existent
545
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
546
+    $champs = array();
547
+    foreach ($desc['field'] as $champ => $ignore) {
548
+        if (isset($c[$champ])) {
549
+            $champs[$champ] = $c[$champ];
550
+        }
551
+    }
552
+
553
+    // Nettoyer les valeurs
554
+    $champs = array_map('corriger_caracteres', $champs);
555
+
556
+    // Envoyer aux plugins
557
+    $champs = pipeline(
558
+        'pre_edition',
559
+        array(
560
+            'args' => array(
561
+                'table' => $spip_table_objet, // compatibilite
562
+                'table_objet' => $table_objet,
563
+                'spip_table_objet' => $spip_table_objet,
564
+                'type' => $type,
565
+                'id_objet' => $id,
566
+                'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
567
+                'action' => 'controler',
568
+                'serveur' => $serveur,
569
+            ),
570
+            'data' => $champs
571
+        )
572
+    );
573
+
574
+    if (!$champs) {
575
+        return false;
576
+    }
577
+
578
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
579
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
580
+
581
+    return $conflits;
582 582
 }
583 583
 
584 584
 
@@ -608,63 +608,63 @@  discard block
 block discarded – undo
608 608
  *     - post : le contenu posté
609 609
  **/
610 610
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
611
-	$spip_table_objet = table_objet_sql($type);
612
-	$id_table_objet = id_table_objet($type);
613
-
614
-	// Controle des MD5 envoyes
615
-	// On elimine les donnees non modifiees par le formulaire (mais
616
-	// potentiellement modifiees entre temps par un autre utilisateur)
617
-	foreach ($champs as $key => $val) {
618
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
619
-			if (is_scalar($val) and $m == md5($val)) {
620
-				unset($champs[$key]);
621
-			}
622
-		}
623
-	}
624
-	if (!$champs) {
625
-		return;
626
-	}
627
-
628
-	// On veut savoir si notre modif va avoir un impact
629
-	// par rapport aux donnees contenues dans la base
630
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
631
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
632
-	$intact = true;
633
-	foreach ($champs as $ch => $val) {
634
-		$intact &= ($s[$ch] == $val);
635
-	}
636
-	if ($intact) {
637
-		return;
638
-	}
639
-
640
-	// Detection de conflits :
641
-	// On verifie si notre modif ne provient pas d'un formulaire
642
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
643
-	// on compare a ce qui est dans la base, et on bloque en cas
644
-	// de conflit.
645
-	$ctrh = $ctrq = $conflits = array();
646
-	foreach (array_keys($champs) as $key) {
647
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
648
-			$ctrh[$key] = $m;
649
-			$ctrq[] = $key;
650
-		}
651
-	}
652
-	if ($ctrq) {
653
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
654
-		foreach ($ctrh as $key => $m) {
655
-			if ($m != md5($ctrq[$key])
656
-				and $champs[$key] !== $ctrq[$key]
657
-			) {
658
-				$conflits[$key] = array(
659
-					'base' => $ctrq[$key],
660
-					'post' => $champs[$key]
661
-				);
662
-				unset($champs[$key]); # stocker quand meme les modifs ?
663
-			}
664
-		}
665
-	}
666
-
667
-	return $conflits;
611
+    $spip_table_objet = table_objet_sql($type);
612
+    $id_table_objet = id_table_objet($type);
613
+
614
+    // Controle des MD5 envoyes
615
+    // On elimine les donnees non modifiees par le formulaire (mais
616
+    // potentiellement modifiees entre temps par un autre utilisateur)
617
+    foreach ($champs as $key => $val) {
618
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
619
+            if (is_scalar($val) and $m == md5($val)) {
620
+                unset($champs[$key]);
621
+            }
622
+        }
623
+    }
624
+    if (!$champs) {
625
+        return;
626
+    }
627
+
628
+    // On veut savoir si notre modif va avoir un impact
629
+    // par rapport aux donnees contenues dans la base
630
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
631
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
632
+    $intact = true;
633
+    foreach ($champs as $ch => $val) {
634
+        $intact &= ($s[$ch] == $val);
635
+    }
636
+    if ($intact) {
637
+        return;
638
+    }
639
+
640
+    // Detection de conflits :
641
+    // On verifie si notre modif ne provient pas d'un formulaire
642
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
643
+    // on compare a ce qui est dans la base, et on bloque en cas
644
+    // de conflit.
645
+    $ctrh = $ctrq = $conflits = array();
646
+    foreach (array_keys($champs) as $key) {
647
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
648
+            $ctrh[$key] = $m;
649
+            $ctrq[] = $key;
650
+        }
651
+    }
652
+    if ($ctrq) {
653
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
654
+        foreach ($ctrh as $key => $m) {
655
+            if ($m != md5($ctrq[$key])
656
+                and $champs[$key] !== $ctrq[$key]
657
+            ) {
658
+                $conflits[$key] = array(
659
+                    'base' => $ctrq[$key],
660
+                    'post' => $champs[$key]
661
+                );
662
+                unset($champs[$key]); # stocker quand meme les modifs ?
663
+            }
664
+        }
665
+    }
666
+
667
+    return $conflits;
668 668
 }
669 669
 
670 670
 /**
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
  * @return string
677 677
  */
678 678
 function display_conflit_champ($x) {
679
-	if (strstr($x, "\n") or strlen($x) > 80) {
680
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
681
-	} else {
682
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
683
-	}
679
+    if (strstr($x, "\n") or strlen($x) > 80) {
680
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
681
+    } else {
682
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
683
+    }
684 684
 }
685 685
 
686 686
 /**
@@ -698,57 +698,57 @@  discard block
 block discarded – undo
698 698
  * @return string
699 699
  */
700 700
 function signaler_conflits_edition($conflits, $redirect = '') {
701
-	include_spip('inc/minipres');
702
-	include_spip('inc/revisions');
703
-	include_spip('afficher_diff/champ');
704
-	include_spip('inc/suivi_versions');
705
-	include_spip('inc/diff');
706
-	$diffs = array();
707
-	foreach ($conflits as $champ => $a) {
708
-		// probleme de stockage ou conflit d'edition ?
709
-		$base = isset($a['save']) ? $a['save'] : $a['base'];
710
-
711
-		$diff = new Diff(new DiffTexte);
712
-		$n = preparer_diff($a['post']);
713
-		$o = preparer_diff($base);
714
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
715
-
716
-		$titre = isset($a['save']) ? _L(
717
-			'Echec lors de l\'enregistrement du champ @champ@',
718
-			array('champ' => $champ)
719
-		) : $champ;
720
-
721
-		$diffs[] = "<h2>$titre</h2>\n"
722
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
725
-			. display_conflit_champ($a['post'])
726
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
727
-			. display_conflit_champ($base);
728
-	}
729
-
730
-	if ($redirect) {
731
-		$id = uniqid(rand());
732
-		$redirect = "<form action='$redirect' method='get'
701
+    include_spip('inc/minipres');
702
+    include_spip('inc/revisions');
703
+    include_spip('afficher_diff/champ');
704
+    include_spip('inc/suivi_versions');
705
+    include_spip('inc/diff');
706
+    $diffs = array();
707
+    foreach ($conflits as $champ => $a) {
708
+        // probleme de stockage ou conflit d'edition ?
709
+        $base = isset($a['save']) ? $a['save'] : $a['base'];
710
+
711
+        $diff = new Diff(new DiffTexte);
712
+        $n = preparer_diff($a['post']);
713
+        $o = preparer_diff($base);
714
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
715
+
716
+        $titre = isset($a['save']) ? _L(
717
+            'Echec lors de l\'enregistrement du champ @champ@',
718
+            array('champ' => $champ)
719
+        ) : $champ;
720
+
721
+        $diffs[] = "<h2>$titre</h2>\n"
722
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
725
+            . display_conflit_champ($a['post'])
726
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
727
+            . display_conflit_champ($base);
728
+    }
729
+
730
+    if ($redirect) {
731
+        $id = uniqid(rand());
732
+        $redirect = "<form action='$redirect' method='get'
733 733
 			id='$id'
734 734
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
735
-			. form_hidden($redirect)
736
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
735
+            . form_hidden($redirect)
736
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
737 737
 		</form>\n";
738 738
 
739
-		// pour les documents, on est probablement en ajax : il faut ajaxer
740
-		if (_AJAX) {
741
-			$redirect .= '<script type="text/javascript">'
742
-				. 'setTimeout(function(){$("#' . $id . '")
739
+        // pour les documents, on est probablement en ajax : il faut ajaxer
740
+        if (_AJAX) {
741
+            $redirect .= '<script type="text/javascript">'
742
+                . 'setTimeout(function(){$("#' . $id . '")
743 743
 			.ajaxForm({target:$("#' . $id . '").parent()});
744 744
 			}, 200);'
745
-				. "</script>\n";
746
-		}
747
-	}
745
+                . "</script>\n";
746
+        }
747
+    }
748 748
 
749
-	echo minipres(
750
-		_T('titre_conflit_edition'),
751
-		'<style>
749
+    echo minipres(
750
+        _T('titre_conflit_edition'),
751
+        '<style>
752 752
 .diff-para-deplace { background: #e8e8ff; }
753 753
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
754 754
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -759,12 +759,12 @@  discard block
 block discarded – undo
759 759
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
760 760
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
761 761
 </style>'
762
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
765
-		. join("\n", $diffs)
766
-		. "</div>\n"
767
-
768
-		. $redirect
769
-	);
762
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
765
+        . join("\n", $diffs)
766
+        . "</div>\n"
767
+
768
+        . $redirect
769
+    );
770 770
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -34 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".$conflit['base'].'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 	// Appel direct dans un squelette
215 215
 	if (!$row) {
216 216
 		if (!$new or $lier_trad) {
217
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
217
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
218 218
 				$row = $select($id, $id_parent, $lier_trad);
219 219
 			} else {
220
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
220
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
221 221
 			}
222 222
 			if (!$new) {
223 223
 				$md5 = controles_md5($row);
@@ -287,13 +287,12 @@  discard block
 block discarded – undo
287 287
 		unset($contexte['lang']);
288 288
 	}
289 289
 
290
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
-		(!$lier_trad ? '' :
292
-			("\n<input type='hidden' name='lier_trad' value='" .
293
-				$lier_trad .
294
-				"' />" .
295
-				"\n<input type='hidden' name='changer_lang' value='" .
296
-				$config['langue'] .
290
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
291
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
292
+				$lier_trad.
293
+				"' />".
294
+				"\n<input type='hidden' name='changer_lang' value='".
295
+				$config['langue'].
297 296
 				"' />"))
298 297
 		. $hidden
299 298
 		. (isset($md5) ? $md5 : '');
@@ -320,14 +319,14 @@  discard block
 block discarded – undo
320 319
 	$aider = charger_fonction('aider', 'inc');
321 320
 	if (strlen($texte) > 28 * 1024) {
322 321
 		$texte = str_replace("\r\n", "\n", $texte);
323
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
322
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
324 323
 		if ($pos > 0 and $pos < 32 * 1024) {
325
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
324
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
326 325
 			$suite = substr($texte, $pos + 2);
327 326
 		} else {
328
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
327
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
329 328
 			if (!($pos > 0 and $pos < 32 * 1024)) {
330
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
329
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
331 330
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332 331
 			} else {
333 332
 				$decalage = 1;
@@ -357,13 +356,13 @@  discard block
 block discarded – undo
357 356
 	}
358 357
 
359 358
 	include_spip('inc/barre');
360
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
359
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
361 360
 	$nombre = 0;
362 361
 
363 362
 	while (strlen($texte) > 29 * 1024) {
364 363
 		$nombre++;
365 364
 		list($texte1, $texte) = coupe_trop_long($texte);
366
-		$textes_supplement .= '<br />' .
365
+		$textes_supplement .= '<br />'.
367 366
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368 367
 	}
369 368
 
@@ -451,7 +450,7 @@  discard block
 block discarded – undo
451 450
 	$ctr = array();
452 451
 	foreach ($data as $key => $val) {
453 452
 		$m = md5($val);
454
-		$k = $prefixe . $key;
453
+		$k = $prefixe.$key;
455 454
 
456 455
 		switch ($format) {
457 456
 			case 'html':
@@ -464,7 +463,7 @@  discard block
 block discarded – undo
464 463
 	}
465 464
 
466 465
 	if ($format == 'html') {
467
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
466
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
468 467
 	} else {
469 468
 		return $ctr;
470 469
 	}
@@ -615,7 +614,7 @@  discard block
 block discarded – undo
615 614
 	// On elimine les donnees non modifiees par le formulaire (mais
616 615
 	// potentiellement modifiees entre temps par un autre utilisateur)
617 616
 	foreach ($champs as $key => $val) {
618
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
617
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
619 618
 			if (is_scalar($val) and $m == md5($val)) {
620 619
 				unset($champs[$key]);
621 620
 			}
@@ -644,7 +643,7 @@  discard block
 block discarded – undo
644 643
 	// de conflit.
645 644
 	$ctrh = $ctrq = $conflits = array();
646 645
 	foreach (array_keys($champs) as $key) {
647
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
646
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
648 647
 			$ctrh[$key] = $m;
649 648
 			$ctrq[] = $key;
650 649
 		}
@@ -677,9 +676,9 @@  discard block
 block discarded – undo
677 676
  */
678 677
 function display_conflit_champ($x) {
679 678
 	if (strstr($x, "\n") or strlen($x) > 80) {
680
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
679
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
681 680
 	} else {
682
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
681
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
683 682
 	}
684 683
 }
685 684
 
@@ -719,11 +718,11 @@  discard block
 block discarded – undo
719 718
 		) : $champ;
720 719
 
721 720
 		$diffs[] = "<h2>$titre</h2>\n"
722
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
721
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
722
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
723
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
725 724
 			. display_conflit_champ($a['post'])
726
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
725
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
727 726
 			. display_conflit_champ($base);
728 727
 	}
729 728
 
@@ -731,16 +730,16 @@  discard block
 block discarded – undo
731 730
 		$id = uniqid(rand());
732 731
 		$redirect = "<form action='$redirect' method='get'
733 732
 			id='$id'
734
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
733
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
735 734
 			. form_hidden($redirect)
736
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
735
+			. "<input type='submit' value='"._T('icone_retour')."' />
737 736
 		</form>\n";
738 737
 
739 738
 		// pour les documents, on est probablement en ajax : il faut ajaxer
740 739
 		if (_AJAX) {
741 740
 			$redirect .= '<script type="text/javascript">'
742
-				. 'setTimeout(function(){$("#' . $id . '")
743
-			.ajaxForm({target:$("#' . $id . '").parent()});
741
+				. 'setTimeout(function(){$("#'.$id.'")
742
+			.ajaxForm({target:$("#' . $id.'").parent()});
744 743
 			}, 200);'
745 744
 				. "</script>\n";
746 745
 		}
@@ -759,9 +758,9 @@  discard block
 block discarded – undo
759 758
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
760 759
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
761 760
 </style>'
762
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
761
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
762
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
763
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
765 764
 		. join("\n", $diffs)
766 765
 		. "</div>\n"
767 766
 
Please login to merge, or discard this patch.