Completed
Push — master ( 7bbe03...8295ac )
by cam
01:11
created
ecrire/install/etape_ldap2.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,8 +39,7 @@
 block discarded – undo
39 39
 		} else {
40 40
 			$tls = true;
41 41
 		}
42
-	}
43
-	else {
42
+	} else {
44 43
 		$tls_ldap == 'non';
45 44
 	}
46 45
 
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -11,89 +11,89 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function install_etape_ldap2_dist() {
18
-	echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
19
-
20
-	$adresse_ldap = _request('adresse_ldap');
21
-
22
-	$port_ldap = _request('port_ldap');
23
-
24
-	$tls_ldap = _request('tls_ldap');
25
-
26
-	$protocole_ldap = _request('protocole_ldap');
27
-
28
-	$login_ldap = _request('login_ldap');
29
-
30
-	$pass_ldap = _request('pass_ldap');
31
-
32
-	$port_ldap = intval($port_ldap);
33
-
34
-	$tls = false;
35
-
36
-	if ($tls_ldap == 'oui') {
37
-		if ($port_ldap == 636) {
38
-			$adresse_ldap = "ldaps://$adresse_ldap";
39
-		} else {
40
-			$tls = true;
41
-		}
42
-	}
43
-	else {
44
-		$tls_ldap == 'non';
45
-	}
46
-
47
-	// Verifions que l'adresse demandee est valide
48
-	$adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
-
50
-	$ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
-	$erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
-
53
-	if ($ldap_link) {
54
-		if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
-			$protocole_ldap = 2;
56
-			ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
-		}
58
-		if ($tls === true) {
59
-			if (!ldap_start_tls($ldap_link)) {
60
-				$erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
61
-					. ' ' . spip_htmlspecialchars($adresse_ldap)
62
-					. ', ' . spip_htmlspecialchars($port_ldap) . ')';
63
-				$ldap_link = false;
64
-			}
65
-		}
66
-		if ($ldap_link) {
67
-			$ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
68
-			$erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
69
-				. "', '" . spip_htmlspecialchars($login_ldap)
70
-				. "', '" . spip_htmlspecialchars($pass_ldap)
71
-				. "'): " . spip_htmlspecialchars($adresse_ldap)
72
-				. ', ' . spip_htmlspecialchars($port_ldap);
73
-		}
74
-	}
75
-
76
-	if ($ldap_link) {
77
-		echo info_etape(
78
-			_T('titre_connexion_ldap'),
79
-			info_progression_etape(2, 'etape_ldap', 'install/')
80
-		),  _T('info_connexion_ldap_ok');
81
-		echo generer_form_ecrire('install', (
82
-			"\n<input type='hidden' name='etape' value='ldap3' />"
83
-			. "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
84
-			. "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
85
-			. "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
86
-			. "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
87
-			. "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
88
-			. "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
89
-			. bouton_suivant()));
90
-	} else {
91
-		echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
92
-			"<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
93
-			'<p>' . _T('avis_connexion_ldap_echec_2') .
94
-			"<br />\n" . _T('avis_connexion_ldap_echec_3') .
95
-			'<br /><br />' . $erreur . '<b> ?</b></p></div>';
96
-	}
97
-
98
-	echo install_fin_html();
18
+    echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
19
+
20
+    $adresse_ldap = _request('adresse_ldap');
21
+
22
+    $port_ldap = _request('port_ldap');
23
+
24
+    $tls_ldap = _request('tls_ldap');
25
+
26
+    $protocole_ldap = _request('protocole_ldap');
27
+
28
+    $login_ldap = _request('login_ldap');
29
+
30
+    $pass_ldap = _request('pass_ldap');
31
+
32
+    $port_ldap = intval($port_ldap);
33
+
34
+    $tls = false;
35
+
36
+    if ($tls_ldap == 'oui') {
37
+        if ($port_ldap == 636) {
38
+            $adresse_ldap = "ldaps://$adresse_ldap";
39
+        } else {
40
+            $tls = true;
41
+        }
42
+    }
43
+    else {
44
+        $tls_ldap == 'non';
45
+    }
46
+
47
+    // Verifions que l'adresse demandee est valide
48
+    $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
+
50
+    $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
+    $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
+
53
+    if ($ldap_link) {
54
+        if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
+            $protocole_ldap = 2;
56
+            ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
+        }
58
+        if ($tls === true) {
59
+            if (!ldap_start_tls($ldap_link)) {
60
+                $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
61
+                    . ' ' . spip_htmlspecialchars($adresse_ldap)
62
+                    . ', ' . spip_htmlspecialchars($port_ldap) . ')';
63
+                $ldap_link = false;
64
+            }
65
+        }
66
+        if ($ldap_link) {
67
+            $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
68
+            $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
69
+                . "', '" . spip_htmlspecialchars($login_ldap)
70
+                . "', '" . spip_htmlspecialchars($pass_ldap)
71
+                . "'): " . spip_htmlspecialchars($adresse_ldap)
72
+                . ', ' . spip_htmlspecialchars($port_ldap);
73
+        }
74
+    }
75
+
76
+    if ($ldap_link) {
77
+        echo info_etape(
78
+            _T('titre_connexion_ldap'),
79
+            info_progression_etape(2, 'etape_ldap', 'install/')
80
+        ),  _T('info_connexion_ldap_ok');
81
+        echo generer_form_ecrire('install', (
82
+            "\n<input type='hidden' name='etape' value='ldap3' />"
83
+            . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
84
+            . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
85
+            . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
86
+            . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
87
+            . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
88
+            . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
89
+            . bouton_suivant()));
90
+    } else {
91
+        echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
92
+            "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
93
+            '<p>' . _T('avis_connexion_ldap_echec_2') .
94
+            "<br />\n" . _T('avis_connexion_ldap_echec_3') .
95
+            '<br /><br />' . $erreur . '<b> ?</b></p></div>';
96
+    }
97
+
98
+    echo install_fin_html();
99 99
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	$adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49 49
 
50 50
 	$ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
-	$erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
51
+	$erreur = 'ldap_connect('.spip_htmlspecialchars($adresse_ldap).', '.spip_htmlspecialchars($port_ldap).')';
52 52
 
53 53
 	if ($ldap_link) {
54 54
 		if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
@@ -57,19 +57,19 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($tls === true) {
59 59
 			if (!ldap_start_tls($ldap_link)) {
60
-				$erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
61
-					. ' ' . spip_htmlspecialchars($adresse_ldap)
62
-					. ', ' . spip_htmlspecialchars($port_ldap) . ')';
60
+				$erreur = 'ldap_start_tls('.spip_htmlspecialchars($ldap_link)
61
+					. ' '.spip_htmlspecialchars($adresse_ldap)
62
+					. ', '.spip_htmlspecialchars($port_ldap).')';
63 63
 				$ldap_link = false;
64 64
 			}
65 65
 		}
66 66
 		if ($ldap_link) {
67 67
 			$ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
68
-			$erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
69
-				. "', '" . spip_htmlspecialchars($login_ldap)
70
-				. "', '" . spip_htmlspecialchars($pass_ldap)
71
-				. "'): " . spip_htmlspecialchars($adresse_ldap)
72
-				. ', ' . spip_htmlspecialchars($port_ldap);
68
+			$erreur = "ldap_bind('".spip_htmlspecialchars($ldap_link)
69
+				. "', '".spip_htmlspecialchars($login_ldap)
70
+				. "', '".spip_htmlspecialchars($pass_ldap)
71
+				. "'): ".spip_htmlspecialchars($adresse_ldap)
72
+				. ', '.spip_htmlspecialchars($port_ldap);
73 73
 		}
74 74
 	}
75 75
 
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 		echo info_etape(
78 78
 			_T('titre_connexion_ldap'),
79 79
 			info_progression_etape(2, 'etape_ldap', 'install/')
80
-		),  _T('info_connexion_ldap_ok');
80
+		), _T('info_connexion_ldap_ok');
81 81
 		echo generer_form_ecrire('install', (
82 82
 			"\n<input type='hidden' name='etape' value='ldap3' />"
83
-			. "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
84
-			. "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
85
-			. "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
86
-			. "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
87
-			. "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
88
-			. "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
83
+			. "\n<input type='hidden' name='adresse_ldap' value=\"".spip_htmlspecialchars($adresse_ldap).'" />'
84
+			. "\n<input type='hidden' name='port_ldap' value=\"".spip_htmlspecialchars($port_ldap).'" />'
85
+			. "\n<input type='hidden' name='login_ldap' value=\"".spip_htmlspecialchars($login_ldap).'" />'
86
+			. "\n<input type='hidden' name='pass_ldap' value=\"".spip_htmlspecialchars($pass_ldap).'" />'
87
+			. "\n<input type='hidden' name='protocole_ldap' value=\"".spip_htmlspecialchars($protocole_ldap).'" />'
88
+			. "\n<input type='hidden' name='tls_ldap' value=\"".spip_htmlspecialchars($tls_ldap).'" />'
89 89
 			. bouton_suivant()));
90 90
 	} else {
91 91
 		echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
92
-			"<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
93
-			'<p>' . _T('avis_connexion_ldap_echec_2') .
94
-			"<br />\n" . _T('avis_connexion_ldap_echec_3') .
95
-			'<br /><br />' . $erreur . '<b> ?</b></p></div>';
92
+			"<div class='error'><p>"._T('avis_connexion_ldap_echec_1').'</p>',
93
+			'<p>'._T('avis_connexion_ldap_echec_2').
94
+			"<br />\n"._T('avis_connexion_ldap_echec_3').
95
+			'<br /><br />'.$erreur.'<b> ?</b></p></div>';
96 96
 	}
97 97
 
98 98
 	echo install_fin_html();
Please login to merge, or discard this patch.
ecrire/inc/cookie.php 2 patches
Indentation   +97 added lines, -97 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
 
@@ -52,68 +52,68 @@  discard block
 block discarded – undo
52 52
  *     cookie sécurisé ou non ?
53 53
  **/
54 54
 function spip_setcookie($name = '', $value = '', $options = []) {
55
-	static $to_secure_list = ['spip_session'];
56
-	if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) {
57
-		$to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST);
58
-	}
59
-
60
-	if (!is_array($options)) {
61
-		// anciens paramètres :
62
-		# spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
63
-		$opt = func_get_args();
64
-		$opt = array_slice($opt, 2);
65
-		$options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
66
-		if (isset($opt[0])) {
67
-			$options['expires'] = $opt[0];
68
-		}
69
-		if (isset($opt[1])) {
70
-			$options['path'] = $opt[1];
71
-		}
72
-		if (isset($opt[2])) {
73
-			$options['domain'] = $opt[2];
74
-		}
75
-		if (isset($opt[3])) {
76
-			$options['secure'] = $opt[3];
77
-		}
78
-	}
79
-
80
-	// expires
81
-	if (!isset($options['expires'])) {
82
-		$options['expires'] = 0;
83
-	}
84
-	if (!isset($options['path']) or $options['path'] === 'AUTO') {
85
-		if (defined('_COOKIE_PATH')) {
86
-			$options['path'] = _COOKIE_PATH;
87
-		} else {
88
-			$options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
89
-		}
90
-	}
91
-	if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
92
-		$options['domain'] = _COOKIE_DOMAIN;
93
-	}
94
-	if (in_array($name, $to_secure_list)) {
95
-		if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
96
-			$options['secure'] = true;
97
-		}
98
-		if (empty($options['httponly'])) {
99
-			$options['httponly'] = true;
100
-		}
101
-	}
102
-	if (empty($options['samesite'])) {
103
-		$options['samesite'] = 'Lax';
104
-	}
105
-
106
-	// in fine renommer le prefixe si besoin
107
-	if (strpos($name, 'spip_') === 0) {
108
-		$name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5);
109
-	}
110
-
111
-	#spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
112
-	$a = @setcookie($name, $value, $options);
113
-
114
-	spip_cookie_envoye(true);
115
-
116
-	return $a;
55
+    static $to_secure_list = ['spip_session'];
56
+    if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) {
57
+        $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST);
58
+    }
59
+
60
+    if (!is_array($options)) {
61
+        // anciens paramètres :
62
+        # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
63
+        $opt = func_get_args();
64
+        $opt = array_slice($opt, 2);
65
+        $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
66
+        if (isset($opt[0])) {
67
+            $options['expires'] = $opt[0];
68
+        }
69
+        if (isset($opt[1])) {
70
+            $options['path'] = $opt[1];
71
+        }
72
+        if (isset($opt[2])) {
73
+            $options['domain'] = $opt[2];
74
+        }
75
+        if (isset($opt[3])) {
76
+            $options['secure'] = $opt[3];
77
+        }
78
+    }
79
+
80
+    // expires
81
+    if (!isset($options['expires'])) {
82
+        $options['expires'] = 0;
83
+    }
84
+    if (!isset($options['path']) or $options['path'] === 'AUTO') {
85
+        if (defined('_COOKIE_PATH')) {
86
+            $options['path'] = _COOKIE_PATH;
87
+        } else {
88
+            $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
89
+        }
90
+    }
91
+    if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
92
+        $options['domain'] = _COOKIE_DOMAIN;
93
+    }
94
+    if (in_array($name, $to_secure_list)) {
95
+        if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
96
+            $options['secure'] = true;
97
+        }
98
+        if (empty($options['httponly'])) {
99
+            $options['httponly'] = true;
100
+        }
101
+    }
102
+    if (empty($options['samesite'])) {
103
+        $options['samesite'] = 'Lax';
104
+    }
105
+
106
+    // in fine renommer le prefixe si besoin
107
+    if (strpos($name, 'spip_') === 0) {
108
+        $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5);
109
+    }
110
+
111
+    #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
112
+    $a = @setcookie($name, $value, $options);
113
+
114
+    spip_cookie_envoye(true);
115
+
116
+    return $a;
117 117
 }
118 118
 
119 119
 /**
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
  * @return bool
130 130
  **/
131 131
 function spip_cookie_envoye($set = '') {
132
-	static $envoye = false;
133
-	if ($set) {
134
-		$envoye = true;
135
-	}
132
+    static $envoye = false;
133
+    if ($set) {
134
+        $envoye = true;
135
+    }
136 136
 
137
-	return $envoye;
137
+    return $envoye;
138 138
 }
139 139
 
140 140
 /**
@@ -153,21 +153,21 @@  discard block
 block discarded – undo
153 153
  *     Préfixe des cookies de SPIP
154 154
  **/
155 155
 function recuperer_cookies_spip($cookie_prefix) {
156
-	$prefix_long = strlen($cookie_prefix);
157
-
158
-	foreach ($_COOKIE as $name => $value) {
159
-		if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
160
-			unset($_COOKIE[$name]);
161
-			unset($GLOBALS[$name]);
162
-		}
163
-	}
164
-	foreach ($_COOKIE as $name => $value) {
165
-		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
166
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
167
-			$_COOKIE[$spipname] = $value;
168
-			$GLOBALS[$spipname] = $value;
169
-		}
170
-	}
156
+    $prefix_long = strlen($cookie_prefix);
157
+
158
+    foreach ($_COOKIE as $name => $value) {
159
+        if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
160
+            unset($_COOKIE[$name]);
161
+            unset($GLOBALS[$name]);
162
+        }
163
+    }
164
+    foreach ($_COOKIE as $name => $value) {
165
+        if (substr($name, 0, $prefix_long) == $cookie_prefix) {
166
+            $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
167
+            $_COOKIE[$spipname] = $value;
168
+            $GLOBALS[$spipname] = $value;
169
+        }
170
+    }
171 171
 }
172 172
 
173 173
 
@@ -186,18 +186,18 @@  discard block
 block discarded – undo
186 186
  *
187 187
  **/
188 188
 function exec_test_ajax_dist() {
189
-	switch (_request('js')) {
190
-		// on est appele par <noscript>
191
-		case -1:
192
-			spip_setcookie('spip_accepte_ajax', -1);
193
-			include_spip('inc/headers');
194
-			redirige_par_entete(chemin_image('erreur-xx.svg'));
195
-			break;
196
-
197
-		// ou par ajax
198
-		case 1:
199
-		default:
200
-			spip_setcookie('spip_accepte_ajax', 1);
201
-			break;
202
-	}
189
+    switch (_request('js')) {
190
+        // on est appele par <noscript>
191
+        case -1:
192
+            spip_setcookie('spip_accepte_ajax', -1);
193
+            include_spip('inc/headers');
194
+            redirige_par_entete(chemin_image('erreur-xx.svg'));
195
+            break;
196
+
197
+        // ou par ajax
198
+        case 1:
199
+        default:
200
+            spip_setcookie('spip_accepte_ajax', 1);
201
+            break;
202
+    }
203 203
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
 	// in fine renommer le prefixe si besoin
107 107
 	if (strpos($name, 'spip_') === 0) {
108
-		$name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5);
108
+		$name = $GLOBALS['cookie_prefix'].'_'.substr($name, 5);
109 109
 	}
110 110
 
111 111
 	#spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	}
164 164
 	foreach ($_COOKIE as $name => $value) {
165 165
 		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
166
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
166
+			$spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name);
167 167
 			$_COOKIE[$spipname] = $value;
168 168
 			$GLOBALS[$spipname] = $value;
169 169
 		}
Please login to merge, or discard this patch.
ecrire/inc/distant.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
122 122
 			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
123 123
 			@unlink($localrac_tmp);
124
-		}
125
-		else {
124
+		} else {
126 125
 			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
127 126
 		}
128 127
 		if (!$res or !$res['length']) {
@@ -240,8 +239,7 @@  discard block
 block discarded – undo
240 239
 						break;
241 240
 					}
242 241
 				}
243
-			}
244
-			else {
242
+			} else {
245 243
 				$ip = false;
246 244
 			}
247 245
 		}
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 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', 2_097_152);
@@ -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?:',
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
 	// si c'est la protection de soi-meme, retourner le path
74 74
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
75
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
75
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
76 76
 
77 77
 		return @file_exists($source) ? $source : false;
78 78
 	}
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		return false;
93 93
 	}
94 94
 
95
-	$localrac = _DIR_RACINE . $local;
95
+	$localrac = _DIR_RACINE.$local;
96 96
 	$t = ($mode === 'force') ? false : @file_exists($localrac);
97 97
 
98 98
 	// test d'existence du fichier
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
 		if (!$taille_max) {
113 113
 			$taille_max = _COPIE_LOCALE_MAX_SIZE;
114 114
 		}
115
-		$localrac_tmp = $localrac . '.tmp';
115
+		$localrac_tmp = $localrac.'.tmp';
116 116
 		$res = recuperer_url(
117 117
 			$source,
118 118
 			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
119 119
 		);
120 120
 
121 121
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
122
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
122
+			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE);
123 123
 			@unlink($localrac_tmp);
124 124
 		}
125 125
 		else {
126
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
126
+			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille ".$res['length'].' status '.$res['status'], 'distant');
127 127
 		}
128 128
 		if (!$res or !$res['length']) {
129 129
 			// si $t c'est sans doute juste un not-modified-since
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 			and is_callable($callback_valider_url)
137 137
 			and !$callback_valider_url($res['url'])
138 138
 		) {
139
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
139
+			spip_log('copie_locale : url finale '.$res['url']." non valide, on refuse le fichier $localrac_tmp", 'distant'._LOG_INFO_IMPORTANTE);
140 140
 			@unlink($localrac_tmp);
141 141
 			return $t ? $local : false;
142 142
 		}
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
 	if (!$is_known_host) {
229 229
 		$host = trim($parsed_url['host'], '.');
230
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
230
+		if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) {
231 231
 			$ip = gethostbyname($host);
232 232
 			if ($ip === $host) {
233 233
 				// Error condition for gethostbyname()
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 			}
249 249
 		}
250 250
 		if ($ip) {
251
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
251
+			if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
252 252
 				return false;
253 253
 			}
254 254
 		}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	}
260 260
 
261 261
 	$port = $parsed_url['port'];
262
-	if ($port === 80  or $port === 443  or $port === 8080) {
262
+	if ($port === 80 or $port === 443 or $port === 8080) {
263 263
 		return $url;
264 264
 	}
265 265
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 				}
330 330
 			}
331 331
 			if ($taille > 500) {
332
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
332
+				$boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8);
333 333
 			}
334 334
 		}
335 335
 
@@ -357,16 +357,16 @@  discard block
 block discarded – undo
357 357
 			}
358 358
 		} else {
359 359
 			// fabrique une chaine HTTP simple pour un POST
360
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
360
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
361 361
 			$chaine = [];
362 362
 			if (is_array($donnees)) {
363 363
 				foreach ($donnees as $cle => $valeur) {
364 364
 					if (is_array($valeur)) {
365 365
 						foreach ($valeur as $val2) {
366
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
366
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
367 367
 						}
368 368
 					} else {
369
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
369
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
370 370
 					}
371 371
 				}
372 372
 				$chaine = implode('&', $chaine);
@@ -471,13 +471,13 @@  discard block
 block discarded – undo
471 471
 		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
472 472
 	}
473 473
 
474
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
474
+	spip_log('recuperer_url '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
475 475
 
476 476
 	// Ajout des en-têtes spécifiques si besoin
477 477
 	$formatted_data = '';
478 478
 	if (!empty($options['headers'])) {
479 479
 		foreach ($options['headers'] as $champ => $valeur) {
480
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
480
+			$formatted_data .= $champ.': '.$valeur."\r\n";
481 481
 		}
482 482
 	}
483 483
 
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
486 486
 		$head .= $formatted_data;
487 487
 		if (stripos($head, 'Content-Length:') === false) {
488
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
488
+			$head .= 'Content-Length: '.strlen($postdata)."\r\n";
489 489
 		}
490
-		$formatted_data = $head . "\r\n" . $postdata;
490
+		$formatted_data = $head."\r\n".$postdata;
491 491
 		if (
492 492
 			strlen($postdata)
493 493
 			and !$methode_demandee
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
502 502
 	$url = preg_replace(',^feed://,i', 'http://', $url);
503 503
 	if (!tester_url_absolue($url)) {
504
-		$url = 'http://' . $url;
504
+		$url = 'http://'.$url;
505 505
 	} elseif (strncmp($url, '//', 2) == 0) {
506
-		$url = 'http:' . $url;
506
+		$url = 'http:'.$url;
507 507
 	}
508 508
 
509 509
 	$url = url_to_ascii($url);
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		$options['if_modified_since']
533 533
 	);
534 534
 	if (!$handle) {
535
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
535
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
536 536
 
537 537
 		return false;
538 538
 	}
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 					'status' => 200,
563 563
 				];
564 564
 			} else {
565
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
565
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
566 566
 				return false;
567 567
 			}
568 568
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -578,11 +578,11 @@  discard block
 block discarded – undo
578 578
 					$options['datas'] = '';
579 579
 				}
580 580
 			}
581
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
581
+			spip_log('recuperer_url recommence '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
582 582
 
583 583
 			return recuperer_url($url, $options);
584 584
 		} elseif ($res['status'] !== 200) {
585
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
585
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
586 586
 		}
587 587
 		$result['status'] = $res['status'];
588 588
 		if (isset($res['headers'])) {
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 
599 599
 	// on ne veut que les entetes
600 600
 	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
601
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
601
+		spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG);
602 602
 		return $result;
603 603
 	}
604 604
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 
609 609
 	$gz = false;
610 610
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
611
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
611
+		$gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz');
612 612
 	}
613 613
 
614 614
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 
645 645
 	$trace = json_decode(json_encode($result), true);
646 646
 	$trace['page'] = '...';
647
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
647
+	spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG);
648 648
 
649 649
 	return $result;
650 650
 }
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	$sig['url'] = $url;
699 699
 
700 700
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
701
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
701
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
702 702
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
703 703
 	$cache = "$sub$cache";
704 704
 
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	$fp = false;
753 753
 	if ($fichier) {
754 754
 		include_spip('inc/acces');
755
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
755
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
756 756
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
757 757
 		if (!$fp and file_exists($fichier)) {
758 758
 			return filesize($fichier);
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 	}
812 812
 	$result['status'] = intval($r[1]);
813 813
 	while ($s = trim(fgets($handle, 16384))) {
814
-		$result['headers'][] = $s . "\n";
814
+		$result['headers'][] = $s."\n";
815 815
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
816 816
 		[, $d, $v] = $r;
817 817
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -860,13 +860,13 @@  discard block
 block discarded – undo
860 860
 
861 861
 	// on se place tout le temps comme si on etait a la racine
862 862
 	if (_DIR_RACINE) {
863
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
863
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
864 864
 	}
865 865
 
866 866
 	$m = md5($source);
867 867
 
868 868
 	return $d
869
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
869
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
870 870
 	. substr($m, 0, 4)
871 871
 	. ".$extension";
872 872
 }
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 	// Si c'est deja local pas de souci
890 890
 	if (!tester_url_absolue($source)) {
891 891
 		if (_DIR_RACINE) {
892
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
892
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
893 893
 		}
894 894
 
895 895
 		return $source;
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 		$ext
908 908
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
909 909
 		and $f = nom_fichier_copie_locale($source, $ext)
910
-		and file_exists(_DIR_RACINE . $f)
910
+		and file_exists(_DIR_RACINE.$f)
911 911
 	) {
912 912
 		return $f;
913 913
 	}
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 
916 916
 	// Si c'est deja dans la table des documents,
917 917
 	// ramener le nom de sa copie potentielle
918
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
918
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
919 919
 
920 920
 	if ($ext) {
921 921
 		return nom_fichier_copie_locale($source, $ext);
@@ -926,9 +926,9 @@  discard block
 block discarded – undo
926 926
 
927 927
 	$ext = $path_parts ? $path_parts['extension'] : '';
928 928
 
929
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
929
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
930 930
 		$f = nom_fichier_copie_locale($source, $ext);
931
-		if (file_exists(_DIR_RACINE . $f)) {
931
+		if (file_exists(_DIR_RACINE.$f)) {
932 932
 			return $f;
933 933
 		}
934 934
 	}
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
 	// Ping  pour voir si son extension est connue et autorisee
937 937
 	// avec mise en cache du resultat du ping
938 938
 
939
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
939
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
940 940
 	if (
941 941
 		!@file_exists($cache)
942 942
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
@@ -946,10 +946,10 @@  discard block
 block discarded – undo
946 946
 		ecrire_fichier($cache, serialize($path_parts));
947 947
 	}
948 948
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
949
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
949
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
950 950
 		return nom_fichier_copie_locale($source, $ext);
951 951
 	}
952
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
952
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
953 953
 }
954 954
 
955 955
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 		} else {
1048 1048
 			if ($a['body']) {
1049 1049
 				$a['extension'] = $extension;
1050
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1050
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1051 1051
 				ecrire_fichier($a['fichier'], $a['body']);
1052 1052
 				$size_image = @spip_getimagesize($a['fichier']);
1053 1053
 				$a['largeur'] = intval($size_image[0]);
@@ -1115,20 +1115,20 @@  discard block
 block discarded – undo
1115 1115
 			!$t
1116 1116
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117 1117
 		) {
1118
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1118
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1119 1119
 		}
1120 1120
 		if (
1121 1121
 			!$t
1122 1122
 			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123 1123
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124 1124
 		) {
1125
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1125
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1126 1126
 		}
1127 1127
 	}
1128 1128
 
1129 1129
 	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130 1130
 	if (!$t) {
1131
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1131
+		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1132 1132
 	}
1133 1133
 
1134 1134
 	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1139,11 +1139,11 @@  discard block
 block discarded – undo
1139 1139
 		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140 1140
 	) {
1141 1141
 		# eviter xxx.3 => 3gp (> SPIP 3)
1142
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1142
+		$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1143 1143
 	}
1144 1144
 
1145 1145
 	if ($t) {
1146
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1146
+		spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1147 1147
 		return $t['extension'];
1148 1148
 	} else {
1149 1149
 		# par defaut on retombe sur '.bin' si c'est autorise
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 		}
1247 1247
 	} else {
1248 1248
 		$scheme = $t['scheme'];
1249
-		$noproxy = $scheme . '://';
1249
+		$noproxy = $scheme.'://';
1250 1250
 	}
1251 1251
 	if (isset($t['user'])) {
1252 1252
 		$user = [$t['user'], $t['pass']];
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 	}
1261 1261
 
1262 1262
 	if (!empty($t['query'])) {
1263
-		$path .= '?' . $t['query'];
1263
+		$path .= '?'.$t['query'];
1264 1264
 	}
1265 1265
 
1266 1266
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1334,29 +1334,29 @@  discard block
 block discarded – undo
1334 1334
 	$proxy_user = '';
1335 1335
 	$http_proxy = need_proxy($host);
1336 1336
 	if ($user) {
1337
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1337
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1338 1338
 	}
1339 1339
 
1340 1340
 	$connect = '';
1341 1341
 	if ($http_proxy) {
1342
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1343
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1344
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1342
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) {
1343
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1344
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1345 1345
 				. "Host: $path_host\r\n"
1346 1346
 				. "Proxy-Connection: Keep-Alive\r\n";
1347 1347
 		} else {
1348
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1348
+			$path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://")
1349 1349
 				. (!$user ? '' : "$user@")
1350
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1350
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1351 1351
 		}
1352 1352
 		$t2 = @parse_url($http_proxy);
1353 1353
 		$first_host = $t2['host'];
1354 1354
 		$port = ($t2['port'] ?? null) ?: 80;
1355 1355
 		if ($t2['user'] ?? null) {
1356
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1356
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1357 1357
 		}
1358 1358
 	} else {
1359
-		$first_host = $noproxy . $host;
1359
+		$first_host = $noproxy.$host;
1360 1360
 	}
1361 1361
 
1362 1362
 	if ($connect) {
@@ -1378,7 +1378,7 @@  discard block
 block discarded – undo
1378 1378
 		);
1379 1379
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1380 1380
 		if (!$f) {
1381
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1381
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1382 1382
 			return $errno;
1383 1383
 		}
1384 1384
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 			or !count($res = explode(' ', $res))
1392 1392
 			or $res[1] !== '200'
1393 1393
 		) {
1394
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1394
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1395 1395
 			fclose($f);
1396 1396
 
1397 1397
 			return false;
@@ -1408,7 +1408,7 @@  discard block
 block discarded – undo
1408 1408
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1409 1409
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1410 1410
 		if (!$f) {
1411
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1411
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1412 1412
 
1413 1413
 			return $errno;
1414 1414
 		}
@@ -1418,16 +1418,16 @@  discard block
 block discarded – undo
1418 1418
 	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1419 1419
 
1420 1420
 	$host_port = $host;
1421
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1421
+	if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) {
1422 1422
 		$host_port .= ":$port";
1423 1423
 	}
1424 1424
 	$req = "$method $path $vers\r\n"
1425 1425
 		. "Host: $host_port\r\n"
1426
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1427
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1426
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1427
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1428 1428
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1429
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1430
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1429
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1430
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1431 1431
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1432 1432
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1433 1433
 
Please login to merge, or discard this patch.
Indentation   +1084 added lines, -1084 removed lines patch added patch discarded remove patch
@@ -18,32 +18,32 @@  discard block
 block discarded – undo
18 18
  * @package SPIP\Core\Distant
19 19
  **/
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
25
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
25
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
26 26
 }
27 27
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
28
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
28
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
29 29
 }
30 30
 if (!defined('_INC_DISTANT_USER_AGENT')) {
31
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
31
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
32 32
 }
33 33
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
34
-	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
34
+    define('_INC_DISTANT_MAX_SIZE', 2_097_152);
35 35
 }
36 36
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
37
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
37
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
38 38
 }
39 39
 
40 40
 define('_REGEXP_COPIE_LOCALE', ',' 	.
41
-	preg_replace(
42
-		'@^https?:@',
43
-		'https?:',
44
-		($GLOBALS['meta']['adresse_site'] ?? '')
45
-	)
46
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
41
+    preg_replace(
42
+        '@^https?:@',
43
+        'https?:',
44
+        ($GLOBALS['meta']['adresse_site'] ?? '')
45
+    )
46
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
47 47
 
48 48
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
49 49
 
@@ -72,107 +72,107 @@  discard block
 block discarded – undo
72 72
  */
73 73
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) {
74 74
 
75
-	// si c'est la protection de soi-meme, retourner le path
76
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
77
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
78
-
79
-		return @file_exists($source) ? $source : false;
80
-	}
81
-
82
-	if (is_null($local)) {
83
-		$local = fichier_copie_locale($source);
84
-	} else {
85
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
86
-			$local = substr($local, strlen(_DIR_RACINE));
87
-		}
88
-	}
89
-
90
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
91
-	// par exemple un fichier qui ne figure pas dans nos documents ;
92
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
93
-	if (!$local) {
94
-		return false;
95
-	}
96
-
97
-	$localrac = _DIR_RACINE . $local;
98
-	$t = ($mode === 'force') ? false : @file_exists($localrac);
99
-
100
-	// test d'existence du fichier
101
-	if ($mode === 'test') {
102
-		return $t ? $local : '';
103
-	}
104
-
105
-	// sinon voir si on doit/peut le telecharger
106
-	if ($local === $source or !tester_url_absolue($source)) {
107
-		return $t ? $local : '';
108
-	}
109
-
110
-	if ($mode === 'modif' or !$t) {
111
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
112
-		// et des eventuelles recuperations concurantes
113
-		include_spip('inc/acces');
114
-		if (!$taille_max) {
115
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
116
-		}
117
-		$localrac_tmp = $localrac . '.tmp';
118
-		$res = recuperer_url(
119
-			$source,
120
-			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
121
-		);
122
-
123
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
124
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
125
-			@unlink($localrac_tmp);
126
-		}
127
-		else {
128
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
129
-		}
130
-		if (!$res or !$res['length']) {
131
-			// si $t c'est sans doute juste un not-modified-since
132
-			return $t ? $local : false;
133
-		}
134
-
135
-		// si option valider url, verifions que l'URL finale est acceptable
136
-		if (
137
-			$callback_valider_url
138
-			and is_callable($callback_valider_url)
139
-			and !$callback_valider_url($res['url'])
140
-		) {
141
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
142
-			@unlink($localrac_tmp);
143
-			return $t ? $local : false;
144
-		}
145
-
146
-		// on peut renommer le fichier tmp
147
-		@rename($localrac_tmp, $localrac);
148
-
149
-		// si on retrouve l'extension
150
-		if (
151
-			!empty($res['headers'])
152
-			and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
153
-		) {
154
-			if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
155
-				$sanitizer($localrac);
156
-			}
157
-		}
158
-
159
-		// pour une eventuelle indexation
160
-		pipeline(
161
-			'post_edition',
162
-			[
163
-				'args' => [
164
-					'operation' => 'copie_locale',
165
-					'source' => $source,
166
-					'fichier' => $local,
167
-					'http_res' => $res['length'],
168
-					'url' => $res['url'],
169
-				],
170
-				'data' => null
171
-			]
172
-		);
173
-	}
174
-
175
-	return $local;
75
+    // si c'est la protection de soi-meme, retourner le path
76
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
77
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
78
+
79
+        return @file_exists($source) ? $source : false;
80
+    }
81
+
82
+    if (is_null($local)) {
83
+        $local = fichier_copie_locale($source);
84
+    } else {
85
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
86
+            $local = substr($local, strlen(_DIR_RACINE));
87
+        }
88
+    }
89
+
90
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
91
+    // par exemple un fichier qui ne figure pas dans nos documents ;
92
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
93
+    if (!$local) {
94
+        return false;
95
+    }
96
+
97
+    $localrac = _DIR_RACINE . $local;
98
+    $t = ($mode === 'force') ? false : @file_exists($localrac);
99
+
100
+    // test d'existence du fichier
101
+    if ($mode === 'test') {
102
+        return $t ? $local : '';
103
+    }
104
+
105
+    // sinon voir si on doit/peut le telecharger
106
+    if ($local === $source or !tester_url_absolue($source)) {
107
+        return $t ? $local : '';
108
+    }
109
+
110
+    if ($mode === 'modif' or !$t) {
111
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
112
+        // et des eventuelles recuperations concurantes
113
+        include_spip('inc/acces');
114
+        if (!$taille_max) {
115
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
116
+        }
117
+        $localrac_tmp = $localrac . '.tmp';
118
+        $res = recuperer_url(
119
+            $source,
120
+            ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
121
+        );
122
+
123
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
124
+            spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
125
+            @unlink($localrac_tmp);
126
+        }
127
+        else {
128
+            spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
129
+        }
130
+        if (!$res or !$res['length']) {
131
+            // si $t c'est sans doute juste un not-modified-since
132
+            return $t ? $local : false;
133
+        }
134
+
135
+        // si option valider url, verifions que l'URL finale est acceptable
136
+        if (
137
+            $callback_valider_url
138
+            and is_callable($callback_valider_url)
139
+            and !$callback_valider_url($res['url'])
140
+        ) {
141
+            spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
142
+            @unlink($localrac_tmp);
143
+            return $t ? $local : false;
144
+        }
145
+
146
+        // on peut renommer le fichier tmp
147
+        @rename($localrac_tmp, $localrac);
148
+
149
+        // si on retrouve l'extension
150
+        if (
151
+            !empty($res['headers'])
152
+            and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
153
+        ) {
154
+            if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
155
+                $sanitizer($localrac);
156
+            }
157
+        }
158
+
159
+        // pour une eventuelle indexation
160
+        pipeline(
161
+            'post_edition',
162
+            [
163
+                'args' => [
164
+                    'operation' => 'copie_locale',
165
+                    'source' => $source,
166
+                    'fichier' => $local,
167
+                    'http_res' => $res['length'],
168
+                    'url' => $res['url'],
169
+                ],
170
+                'data' => null
171
+            ]
172
+        );
173
+    }
174
+
175
+    return $local;
176 176
 }
177 177
 
178 178
 /**
@@ -187,99 +187,99 @@  discard block
 block discarded – undo
187 187
  *   url ou false en cas d'echec
188 188
  */
189 189
 function valider_url_distante($url, $known_hosts = []) {
190
-	if (!function_exists('protocole_verifier')) {
191
-		include_spip('inc/filtres_mini');
192
-	}
193
-
194
-	if (!protocole_verifier($url, ['http', 'https'])) {
195
-		return false;
196
-	}
197
-
198
-	$parsed_url = parse_url($url);
199
-	if (!$parsed_url or empty($parsed_url['host'])) {
200
-		return false;
201
-	}
202
-
203
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
204
-		return false;
205
-	}
206
-
207
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
208
-		return false;
209
-	}
210
-
211
-	if (!is_array($known_hosts)) {
212
-		$known_hosts = [$known_hosts];
213
-	}
214
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
215
-	$known_hosts[] = url_de_base();
216
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
217
-
218
-	$is_known_host = false;
219
-	foreach ($known_hosts as $known_host) {
220
-		$parse_known = parse_url($known_host);
221
-		if (
222
-			$parse_known
223
-			and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
224
-		) {
225
-			$is_known_host = true;
226
-			break;
227
-		}
228
-	}
229
-
230
-	if (!$is_known_host) {
231
-		$host = trim($parsed_url['host'], '.');
232
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
233
-			$ip = gethostbyname($host);
234
-			if ($ip === $host) {
235
-				// Error condition for gethostbyname()
236
-				$ip = false;
237
-			}
238
-			if ($records = dns_get_record($host)) {
239
-				foreach ($records as $record) {
240
-					// il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
241
-					// se fasse sur la meme IP
242
-					if ($record['ttl'] < 10) {
243
-						$ip = false;
244
-						break;
245
-					}
246
-				}
247
-			}
248
-			else {
249
-				$ip = false;
250
-			}
251
-		}
252
-		if ($ip) {
253
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
254
-				return false;
255
-			}
256
-		}
257
-	}
258
-
259
-	if (empty($parsed_url['port'])) {
260
-		return $url;
261
-	}
262
-
263
-	$port = $parsed_url['port'];
264
-	if ($port === 80  or $port === 443  or $port === 8080) {
265
-		return $url;
266
-	}
267
-
268
-	if ($is_known_host) {
269
-		foreach ($known_hosts as $known_host) {
270
-			$parse_known = parse_url($known_host);
271
-			if (
272
-				$parse_known
273
-				and !empty($parse_known['port'])
274
-				and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
275
-				and $parse_known['port'] == $port
276
-			) {
277
-				return $url;
278
-			}
279
-		}
280
-	}
281
-
282
-	return false;
190
+    if (!function_exists('protocole_verifier')) {
191
+        include_spip('inc/filtres_mini');
192
+    }
193
+
194
+    if (!protocole_verifier($url, ['http', 'https'])) {
195
+        return false;
196
+    }
197
+
198
+    $parsed_url = parse_url($url);
199
+    if (!$parsed_url or empty($parsed_url['host'])) {
200
+        return false;
201
+    }
202
+
203
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
204
+        return false;
205
+    }
206
+
207
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
208
+        return false;
209
+    }
210
+
211
+    if (!is_array($known_hosts)) {
212
+        $known_hosts = [$known_hosts];
213
+    }
214
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
215
+    $known_hosts[] = url_de_base();
216
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
217
+
218
+    $is_known_host = false;
219
+    foreach ($known_hosts as $known_host) {
220
+        $parse_known = parse_url($known_host);
221
+        if (
222
+            $parse_known
223
+            and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
224
+        ) {
225
+            $is_known_host = true;
226
+            break;
227
+        }
228
+    }
229
+
230
+    if (!$is_known_host) {
231
+        $host = trim($parsed_url['host'], '.');
232
+        if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
233
+            $ip = gethostbyname($host);
234
+            if ($ip === $host) {
235
+                // Error condition for gethostbyname()
236
+                $ip = false;
237
+            }
238
+            if ($records = dns_get_record($host)) {
239
+                foreach ($records as $record) {
240
+                    // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
241
+                    // se fasse sur la meme IP
242
+                    if ($record['ttl'] < 10) {
243
+                        $ip = false;
244
+                        break;
245
+                    }
246
+                }
247
+            }
248
+            else {
249
+                $ip = false;
250
+            }
251
+        }
252
+        if ($ip) {
253
+            if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
254
+                return false;
255
+            }
256
+        }
257
+    }
258
+
259
+    if (empty($parsed_url['port'])) {
260
+        return $url;
261
+    }
262
+
263
+    $port = $parsed_url['port'];
264
+    if ($port === 80  or $port === 443  or $port === 8080) {
265
+        return $url;
266
+    }
267
+
268
+    if ($is_known_host) {
269
+        foreach ($known_hosts as $known_host) {
270
+            $parse_known = parse_url($known_host);
271
+            if (
272
+                $parse_known
273
+                and !empty($parse_known['port'])
274
+                and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
275
+                and $parse_known['port'] == $port
276
+            ) {
277
+                return $url;
278
+            }
279
+        }
280
+    }
281
+
282
+    return false;
283 283
 }
284 284
 
285 285
 /**
@@ -299,86 +299,86 @@  discard block
 block discarded – undo
299 299
  */
300 300
 function prepare_donnees_post($donnees, $boundary = '') {
301 301
 
302
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
303
-	// pour un appel soap par exemple
304
-	// l'entete est separe des donnees par un double retour a la ligne
305
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
306
-	if (is_string($donnees) && strlen($donnees)) {
307
-		$entete = '';
308
-		// on repasse tous les \r\n et \r en simples \n
309
-		$donnees = str_replace("\r\n", "\n", $donnees);
310
-		$donnees = str_replace("\r", "\n", $donnees);
311
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
312
-		$p = strpos($donnees, "\n\n");
313
-		if ($p !== false) {
314
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
315
-			$donnees = substr($donnees, $p + 2);
316
-		}
317
-		$chaine = str_replace("\n", "\r\n", $donnees);
318
-	} else {
319
-		/* boundary automatique */
320
-		// Si on a plus de 500 octects de donnees, on "boundarise"
321
-		if ($boundary === '') {
322
-			$taille = 0;
323
-			foreach ($donnees as $cle => $valeur) {
324
-				if (is_array($valeur)) {
325
-					foreach ($valeur as $val2) {
326
-						$taille += strlen($val2);
327
-					}
328
-				} else {
329
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
330
-					$taille += strlen($valeur);
331
-				}
332
-			}
333
-			if ($taille > 500) {
334
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
335
-			}
336
-		}
337
-
338
-		if (is_string($boundary) and strlen($boundary)) {
339
-			// fabrique une chaine HTTP pour un POST avec boundary
340
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
341
-			$chaine = '';
342
-			if (is_array($donnees)) {
343
-				foreach ($donnees as $cle => $valeur) {
344
-					if (is_array($valeur)) {
345
-						foreach ($valeur as $val2) {
346
-							$chaine .= "\r\n--$boundary\r\n";
347
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
348
-							$chaine .= "\r\n";
349
-							$chaine .= $val2;
350
-						}
351
-					} else {
352
-						$chaine .= "\r\n--$boundary\r\n";
353
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
354
-						$chaine .= "\r\n";
355
-						$chaine .= $valeur;
356
-					}
357
-				}
358
-				$chaine .= "\r\n--$boundary\r\n";
359
-			}
360
-		} else {
361
-			// fabrique une chaine HTTP simple pour un POST
362
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
363
-			$chaine = [];
364
-			if (is_array($donnees)) {
365
-				foreach ($donnees as $cle => $valeur) {
366
-					if (is_array($valeur)) {
367
-						foreach ($valeur as $val2) {
368
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
369
-						}
370
-					} else {
371
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
372
-					}
373
-				}
374
-				$chaine = implode('&', $chaine);
375
-			} else {
376
-				$chaine = $donnees;
377
-			}
378
-		}
379
-	}
380
-
381
-	return [$entete, $chaine];
302
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
303
+    // pour un appel soap par exemple
304
+    // l'entete est separe des donnees par un double retour a la ligne
305
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
306
+    if (is_string($donnees) && strlen($donnees)) {
307
+        $entete = '';
308
+        // on repasse tous les \r\n et \r en simples \n
309
+        $donnees = str_replace("\r\n", "\n", $donnees);
310
+        $donnees = str_replace("\r", "\n", $donnees);
311
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
312
+        $p = strpos($donnees, "\n\n");
313
+        if ($p !== false) {
314
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
315
+            $donnees = substr($donnees, $p + 2);
316
+        }
317
+        $chaine = str_replace("\n", "\r\n", $donnees);
318
+    } else {
319
+        /* boundary automatique */
320
+        // Si on a plus de 500 octects de donnees, on "boundarise"
321
+        if ($boundary === '') {
322
+            $taille = 0;
323
+            foreach ($donnees as $cle => $valeur) {
324
+                if (is_array($valeur)) {
325
+                    foreach ($valeur as $val2) {
326
+                        $taille += strlen($val2);
327
+                    }
328
+                } else {
329
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
330
+                    $taille += strlen($valeur);
331
+                }
332
+            }
333
+            if ($taille > 500) {
334
+                $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
335
+            }
336
+        }
337
+
338
+        if (is_string($boundary) and strlen($boundary)) {
339
+            // fabrique une chaine HTTP pour un POST avec boundary
340
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
341
+            $chaine = '';
342
+            if (is_array($donnees)) {
343
+                foreach ($donnees as $cle => $valeur) {
344
+                    if (is_array($valeur)) {
345
+                        foreach ($valeur as $val2) {
346
+                            $chaine .= "\r\n--$boundary\r\n";
347
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
348
+                            $chaine .= "\r\n";
349
+                            $chaine .= $val2;
350
+                        }
351
+                    } else {
352
+                        $chaine .= "\r\n--$boundary\r\n";
353
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
354
+                        $chaine .= "\r\n";
355
+                        $chaine .= $valeur;
356
+                    }
357
+                }
358
+                $chaine .= "\r\n--$boundary\r\n";
359
+            }
360
+        } else {
361
+            // fabrique une chaine HTTP simple pour un POST
362
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
363
+            $chaine = [];
364
+            if (is_array($donnees)) {
365
+                foreach ($donnees as $cle => $valeur) {
366
+                    if (is_array($valeur)) {
367
+                        foreach ($valeur as $val2) {
368
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
369
+                        }
370
+                    } else {
371
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
372
+                    }
373
+                }
374
+                $chaine = implode('&', $chaine);
375
+            } else {
376
+                $chaine = $donnees;
377
+            }
378
+        }
379
+    }
380
+
381
+    return [$entete, $chaine];
382 382
 }
383 383
 
384 384
 /**
@@ -389,19 +389,19 @@  discard block
 block discarded – undo
389 389
  */
390 390
 function url_to_ascii($url_idn) {
391 391
 
392
-	if ($parts = parse_url($url_idn)) {
393
-		$host = $parts['host'];
394
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
395
-			$converter = new ToIdn();
396
-			$host_ascii = $converter->convert($host);
397
-			$url_idn = explode($host, $url_idn, 2);
398
-			$url_idn = implode($host_ascii, $url_idn);
399
-		}
400
-		// et on urlencode les char utf si besoin dans le path
401
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
402
-	}
403
-
404
-	return $url_idn;
392
+    if ($parts = parse_url($url_idn)) {
393
+        $host = $parts['host'];
394
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
395
+            $converter = new ToIdn();
396
+            $host_ascii = $converter->convert($host);
397
+            $url_idn = explode($host, $url_idn, 2);
398
+            $url_idn = implode($host_ascii, $url_idn);
399
+        }
400
+        // et on urlencode les char utf si besoin dans le path
401
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
402
+    }
403
+
404
+    return $url_idn;
405 405
 }
406 406
 
407 407
 /**
@@ -442,209 +442,209 @@  discard block
 block discarded – undo
442 442
  *     string file : nom du fichier si enregistre dans un fichier
443 443
  */
444 444
 function recuperer_url($url, $options = []) {
445
-	// Conserve la mémoire de la méthode fournit éventuellement
446
-	$methode_demandee = $options['methode'] ?? '';
447
-	$default = [
448
-		'transcoder' => false,
449
-		'methode' => 'GET',
450
-		'taille_max' => null,
451
-		'headers' => [],
452
-		'datas' => '',
453
-		'boundary' => '',
454
-		'refuser_gz' => false,
455
-		'if_modified_since' => '',
456
-		'uri_referer' => '',
457
-		'file' => '',
458
-		'follow_location' => 10,
459
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
460
-	];
461
-	$options = array_merge($default, $options);
462
-	// copier directement dans un fichier ?
463
-	$copy = $options['file'];
464
-
465
-	if ($options['methode'] == 'HEAD') {
466
-		$options['taille_max'] = 0;
467
-	}
468
-	if (is_null($options['taille_max'])) {
469
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
470
-	}
471
-
472
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
473
-
474
-	// Ajout des en-têtes spécifiques si besoin
475
-	$formatted_data = '';
476
-	if (!empty($options['headers'])) {
477
-		foreach ($options['headers'] as $champ => $valeur) {
478
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
479
-		}
480
-	}
481
-
482
-	if (!empty($options['datas'])) {
483
-		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
484
-		$head .= $formatted_data;
485
-		if (stripos($head, 'Content-Length:') === false) {
486
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
487
-		}
488
-		$formatted_data = $head . "\r\n" . $postdata;
489
-		if (
490
-			strlen($postdata)
491
-			and !$methode_demandee
492
-		) {
493
-			$options['methode'] = 'POST';
494
-		}
495
-	} elseif ($formatted_data) {
496
-		$formatted_data .= "\r\n";
497
-	}
498
-
499
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
500
-	$url = preg_replace(',^feed://,i', 'http://', $url);
501
-	if (!tester_url_absolue($url)) {
502
-		$url = 'http://' . $url;
503
-	} elseif (strncmp($url, '//', 2) == 0) {
504
-		$url = 'http:' . $url;
505
-	}
506
-
507
-	$url = url_to_ascii($url);
508
-
509
-	$result = [
510
-		'status' => 0,
511
-		'headers' => '',
512
-		'page' => '',
513
-		'length' => 0,
514
-		'last_modified' => '',
515
-		'location' => '',
516
-		'url' => $url
517
-	];
518
-
519
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
520
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
521
-
522
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
523
-	[$handle, $fopen] = init_http(
524
-		$options['methode'],
525
-		$url,
526
-		$refuser_gz,
527
-		$options['uri_referer'],
528
-		$formatted_data,
529
-		$options['version_http'],
530
-		$options['if_modified_since']
531
-	);
532
-	if (!$handle) {
533
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
534
-
535
-		return false;
536
-	}
537
-
538
-	// Sauf en fopen, envoyer le flux d'entree
539
-	// et recuperer les en-tetes de reponses
540
-	if (!$fopen) {
541
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
542
-		if (!$res) {
543
-			fclose($handle);
544
-			$t = @parse_url($url);
545
-			$host = $t['host'];
546
-			// Chinoisierie inexplicable pour contrer
547
-			// les actions liberticides de l'empire du milieu
548
-			if (
549
-				!need_proxy($host)
550
-				and $res = @file_get_contents($url)
551
-			) {
552
-				$result['length'] = strlen($res);
553
-				if ($copy) {
554
-					ecrire_fichier($copy, $res);
555
-					$result['file'] = $copy;
556
-				} else {
557
-					$result['page'] = $res;
558
-				}
559
-				$res = [
560
-					'status' => 200,
561
-				];
562
-			} else {
563
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
564
-				return false;
565
-			}
566
-		} elseif ($res['location'] and $options['follow_location']) {
567
-			$options['follow_location']--;
568
-			fclose($handle);
569
-			include_spip('inc/filtres');
570
-			$url = suivre_lien($url, $res['location']);
571
-
572
-			// une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
573
-			if ($options['methode'] !== 'GET') {
574
-				if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
575
-					$options['methode'] = 'GET';
576
-					$options['datas'] = '';
577
-				}
578
-			}
579
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
580
-
581
-			return recuperer_url($url, $options);
582
-		} elseif ($res['status'] !== 200) {
583
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
584
-		}
585
-		$result['status'] = $res['status'];
586
-		if (isset($res['headers'])) {
587
-			$result['headers'] = $res['headers'];
588
-		}
589
-		if (isset($res['last_modified'])) {
590
-			$result['last_modified'] = $res['last_modified'];
591
-		}
592
-		if (isset($res['location'])) {
593
-			$result['location'] = $res['location'];
594
-		}
595
-	}
596
-
597
-	// on ne veut que les entetes
598
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
599
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
600
-		return $result;
601
-	}
602
-
603
-
604
-	// s'il faut deballer, le faire via un fichier temporaire
605
-	// sinon la memoire explose pour les gros flux
606
-
607
-	$gz = false;
608
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
609
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
610
-	}
611
-
612
-	// si on a pas deja recuperer le contenu par une methode detournee
613
-	if (!$result['length']) {
614
-		$res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
615
-		fclose($handle);
616
-		if ($copy) {
617
-			$result['length'] = $res;
618
-			$result['file'] = $copy;
619
-		} elseif ($res) {
620
-			$result['page'] = &$res;
621
-			$result['length'] = strlen($result['page']);
622
-		}
623
-		if (!$result['status']) {
624
-			$result['status'] = 200; // on a reussi, donc !
625
-		}
626
-	}
627
-	if (!$result['page']) {
628
-		return $result;
629
-	}
630
-
631
-	// Decompresser au besoin
632
-	if ($gz) {
633
-		$result['page'] = implode('', gzfile($gz));
634
-		supprimer_fichier($gz);
635
-	}
636
-
637
-	// Faut-il l'importer dans notre charset local ?
638
-	if ($options['transcoder']) {
639
-		include_spip('inc/charsets');
640
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
641
-	}
642
-
643
-	$trace = json_decode(json_encode($result), true);
644
-	$trace['page'] = '...';
645
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
646
-
647
-	return $result;
445
+    // Conserve la mémoire de la méthode fournit éventuellement
446
+    $methode_demandee = $options['methode'] ?? '';
447
+    $default = [
448
+        'transcoder' => false,
449
+        'methode' => 'GET',
450
+        'taille_max' => null,
451
+        'headers' => [],
452
+        'datas' => '',
453
+        'boundary' => '',
454
+        'refuser_gz' => false,
455
+        'if_modified_since' => '',
456
+        'uri_referer' => '',
457
+        'file' => '',
458
+        'follow_location' => 10,
459
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
460
+    ];
461
+    $options = array_merge($default, $options);
462
+    // copier directement dans un fichier ?
463
+    $copy = $options['file'];
464
+
465
+    if ($options['methode'] == 'HEAD') {
466
+        $options['taille_max'] = 0;
467
+    }
468
+    if (is_null($options['taille_max'])) {
469
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
470
+    }
471
+
472
+    spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
473
+
474
+    // Ajout des en-têtes spécifiques si besoin
475
+    $formatted_data = '';
476
+    if (!empty($options['headers'])) {
477
+        foreach ($options['headers'] as $champ => $valeur) {
478
+            $formatted_data .= $champ . ': ' . $valeur . "\r\n";
479
+        }
480
+    }
481
+
482
+    if (!empty($options['datas'])) {
483
+        [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
484
+        $head .= $formatted_data;
485
+        if (stripos($head, 'Content-Length:') === false) {
486
+            $head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
487
+        }
488
+        $formatted_data = $head . "\r\n" . $postdata;
489
+        if (
490
+            strlen($postdata)
491
+            and !$methode_demandee
492
+        ) {
493
+            $options['methode'] = 'POST';
494
+        }
495
+    } elseif ($formatted_data) {
496
+        $formatted_data .= "\r\n";
497
+    }
498
+
499
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
500
+    $url = preg_replace(',^feed://,i', 'http://', $url);
501
+    if (!tester_url_absolue($url)) {
502
+        $url = 'http://' . $url;
503
+    } elseif (strncmp($url, '//', 2) == 0) {
504
+        $url = 'http:' . $url;
505
+    }
506
+
507
+    $url = url_to_ascii($url);
508
+
509
+    $result = [
510
+        'status' => 0,
511
+        'headers' => '',
512
+        'page' => '',
513
+        'length' => 0,
514
+        'last_modified' => '',
515
+        'location' => '',
516
+        'url' => $url
517
+    ];
518
+
519
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
520
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
521
+
522
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
523
+    [$handle, $fopen] = init_http(
524
+        $options['methode'],
525
+        $url,
526
+        $refuser_gz,
527
+        $options['uri_referer'],
528
+        $formatted_data,
529
+        $options['version_http'],
530
+        $options['if_modified_since']
531
+    );
532
+    if (!$handle) {
533
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
534
+
535
+        return false;
536
+    }
537
+
538
+    // Sauf en fopen, envoyer le flux d'entree
539
+    // et recuperer les en-tetes de reponses
540
+    if (!$fopen) {
541
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
542
+        if (!$res) {
543
+            fclose($handle);
544
+            $t = @parse_url($url);
545
+            $host = $t['host'];
546
+            // Chinoisierie inexplicable pour contrer
547
+            // les actions liberticides de l'empire du milieu
548
+            if (
549
+                !need_proxy($host)
550
+                and $res = @file_get_contents($url)
551
+            ) {
552
+                $result['length'] = strlen($res);
553
+                if ($copy) {
554
+                    ecrire_fichier($copy, $res);
555
+                    $result['file'] = $copy;
556
+                } else {
557
+                    $result['page'] = $res;
558
+                }
559
+                $res = [
560
+                    'status' => 200,
561
+                ];
562
+            } else {
563
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
564
+                return false;
565
+            }
566
+        } elseif ($res['location'] and $options['follow_location']) {
567
+            $options['follow_location']--;
568
+            fclose($handle);
569
+            include_spip('inc/filtres');
570
+            $url = suivre_lien($url, $res['location']);
571
+
572
+            // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
573
+            if ($options['methode'] !== 'GET') {
574
+                if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
575
+                    $options['methode'] = 'GET';
576
+                    $options['datas'] = '';
577
+                }
578
+            }
579
+            spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
580
+
581
+            return recuperer_url($url, $options);
582
+        } elseif ($res['status'] !== 200) {
583
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
584
+        }
585
+        $result['status'] = $res['status'];
586
+        if (isset($res['headers'])) {
587
+            $result['headers'] = $res['headers'];
588
+        }
589
+        if (isset($res['last_modified'])) {
590
+            $result['last_modified'] = $res['last_modified'];
591
+        }
592
+        if (isset($res['location'])) {
593
+            $result['location'] = $res['location'];
594
+        }
595
+    }
596
+
597
+    // on ne veut que les entetes
598
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
599
+        spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
600
+        return $result;
601
+    }
602
+
603
+
604
+    // s'il faut deballer, le faire via un fichier temporaire
605
+    // sinon la memoire explose pour les gros flux
606
+
607
+    $gz = false;
608
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
609
+        $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
610
+    }
611
+
612
+    // si on a pas deja recuperer le contenu par une methode detournee
613
+    if (!$result['length']) {
614
+        $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
615
+        fclose($handle);
616
+        if ($copy) {
617
+            $result['length'] = $res;
618
+            $result['file'] = $copy;
619
+        } elseif ($res) {
620
+            $result['page'] = &$res;
621
+            $result['length'] = strlen($result['page']);
622
+        }
623
+        if (!$result['status']) {
624
+            $result['status'] = 200; // on a reussi, donc !
625
+        }
626
+    }
627
+    if (!$result['page']) {
628
+        return $result;
629
+    }
630
+
631
+    // Decompresser au besoin
632
+    if ($gz) {
633
+        $result['page'] = implode('', gzfile($gz));
634
+        supprimer_fichier($gz);
635
+    }
636
+
637
+    // Faut-il l'importer dans notre charset local ?
638
+    if ($options['transcoder']) {
639
+        include_spip('inc/charsets');
640
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
641
+    }
642
+
643
+    $trace = json_decode(json_encode($result), true);
644
+    $trace['page'] = '...';
645
+    spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
646
+
647
+    return $result;
648 648
 }
649 649
 
650 650
 /**
@@ -660,73 +660,73 @@  discard block
 block discarded – undo
660 660
  * @return array|bool|mixed
661 661
  */
662 662
 function recuperer_url_cache($url, $options = []) {
663
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
664
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
665
-	}
666
-	$default = [
667
-		'transcoder' => false,
668
-		'methode' => 'GET',
669
-		'taille_max' => null,
670
-		'datas' => '',
671
-		'boundary' => '',
672
-		'refuser_gz' => false,
673
-		'if_modified_since' => '',
674
-		'uri_referer' => '',
675
-		'file' => '',
676
-		'follow_location' => 10,
677
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
678
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
679
-	];
680
-	$options = array_merge($default, $options);
681
-
682
-	// cas ou il n'est pas possible de cacher
683
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
684
-		return recuperer_url($url, $options);
685
-	}
686
-
687
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
688
-	static $errors = [];
689
-	if (isset($errors[$url])) {
690
-		return $errors[$url];
691
-	}
692
-
693
-	$sig = $options;
694
-	unset($sig['if_modified_since']);
695
-	unset($sig['delai_cache']);
696
-	$sig['url'] = $url;
697
-
698
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
699
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
700
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
701
-	$cache = "$sub$cache";
702
-
703
-	$res = false;
704
-	$is_cached = file_exists($cache);
705
-	if (
706
-		$is_cached
707
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
708
-	) {
709
-		lire_fichier($cache, $res);
710
-		if ($res = unserialize($res)) {
711
-			// mettre le last_modified et le status=304 ?
712
-		}
713
-	}
714
-	if (!$res) {
715
-		$res = recuperer_url($url, $options);
716
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
717
-		if (!$res) {
718
-			if ($is_cached) {
719
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
720
-				lire_fichier($cache, $res);
721
-				$res = unserialize($res);
722
-			}
723
-
724
-			return $errors[$url] = $res;
725
-		}
726
-		ecrire_fichier($cache, serialize($res));
727
-	}
728
-
729
-	return $res;
663
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
664
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
665
+    }
666
+    $default = [
667
+        'transcoder' => false,
668
+        'methode' => 'GET',
669
+        'taille_max' => null,
670
+        'datas' => '',
671
+        'boundary' => '',
672
+        'refuser_gz' => false,
673
+        'if_modified_since' => '',
674
+        'uri_referer' => '',
675
+        'file' => '',
676
+        'follow_location' => 10,
677
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
678
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
679
+    ];
680
+    $options = array_merge($default, $options);
681
+
682
+    // cas ou il n'est pas possible de cacher
683
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
684
+        return recuperer_url($url, $options);
685
+    }
686
+
687
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
688
+    static $errors = [];
689
+    if (isset($errors[$url])) {
690
+        return $errors[$url];
691
+    }
692
+
693
+    $sig = $options;
694
+    unset($sig['if_modified_since']);
695
+    unset($sig['delai_cache']);
696
+    $sig['url'] = $url;
697
+
698
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
699
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
700
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
701
+    $cache = "$sub$cache";
702
+
703
+    $res = false;
704
+    $is_cached = file_exists($cache);
705
+    if (
706
+        $is_cached
707
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
708
+    ) {
709
+        lire_fichier($cache, $res);
710
+        if ($res = unserialize($res)) {
711
+            // mettre le last_modified et le status=304 ?
712
+        }
713
+    }
714
+    if (!$res) {
715
+        $res = recuperer_url($url, $options);
716
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
717
+        if (!$res) {
718
+            if ($is_cached) {
719
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
720
+                lire_fichier($cache, $res);
721
+                $res = unserialize($res);
722
+            }
723
+
724
+            return $errors[$url] = $res;
725
+        }
726
+        ecrire_fichier($cache, serialize($res));
727
+    }
728
+
729
+    return $res;
730 730
 }
731 731
 
732 732
 /**
@@ -744,42 +744,42 @@  discard block
 block discarded – undo
744 744
  *   string contenu de la resource
745 745
  */
746 746
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
747
-	$tmpfile = null;
748
-	$taille = 0;
749
-	$result = '';
750
-	$fp = false;
751
-	if ($fichier) {
752
-		include_spip('inc/acces');
753
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
754
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
755
-		if (!$fp and file_exists($fichier)) {
756
-			return filesize($fichier);
757
-		}
758
-		if (!$fp) {
759
-			return false;
760
-		}
761
-		$result = 0; // on renvoie la taille du fichier
762
-	}
763
-	while (!feof($handle) and $taille < $taille_max) {
764
-		$res = fread($handle, 16384);
765
-		$taille += strlen($res);
766
-		if ($fp) {
767
-			fwrite($fp, $res);
768
-			$result = $taille;
769
-		} else {
770
-			$result .= $res;
771
-		}
772
-	}
773
-	if ($fp) {
774
-		spip_fclose_unlock($fp);
775
-		spip_unlink($fichier);
776
-		@rename($tmpfile, $fichier);
777
-		if (!file_exists($fichier)) {
778
-			return false;
779
-		}
780
-	}
781
-
782
-	return $result;
747
+    $tmpfile = null;
748
+    $taille = 0;
749
+    $result = '';
750
+    $fp = false;
751
+    if ($fichier) {
752
+        include_spip('inc/acces');
753
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
754
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
755
+        if (!$fp and file_exists($fichier)) {
756
+            return filesize($fichier);
757
+        }
758
+        if (!$fp) {
759
+            return false;
760
+        }
761
+        $result = 0; // on renvoie la taille du fichier
762
+    }
763
+    while (!feof($handle) and $taille < $taille_max) {
764
+        $res = fread($handle, 16384);
765
+        $taille += strlen($res);
766
+        if ($fp) {
767
+            fwrite($fp, $res);
768
+            $result = $taille;
769
+        } else {
770
+            $result .= $res;
771
+        }
772
+    }
773
+    if ($fp) {
774
+        spip_fclose_unlock($fp);
775
+        spip_unlink($fichier);
776
+        @rename($tmpfile, $fichier);
777
+        if (!file_exists($fichier)) {
778
+            return false;
779
+        }
780
+    }
781
+
782
+    return $result;
783 783
 }
784 784
 
785 785
 /**
@@ -801,35 +801,35 @@  discard block
 block discarded – undo
801 801
  *   string location
802 802
  */
803 803
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
804
-	$result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
805
-
806
-	$s = @trim(fgets($handle, 16384));
807
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
808
-		return false;
809
-	}
810
-	$result['status'] = intval($r[1]);
811
-	while ($s = trim(fgets($handle, 16384))) {
812
-		$result['headers'][] = $s . "\n";
813
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
814
-		[, $d, $v] = $r;
815
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
816
-			$result['location'] = $v;
817
-		} elseif ($d == 'Last-Modified') {
818
-			$result['last_modified'] = strtotime($v);
819
-		}
820
-	}
821
-	if (
822
-		$if_modified_since
823
-		and $result['last_modified']
824
-		and $if_modified_since > $result['last_modified']
825
-		and $result['status'] == 200
826
-	) {
827
-		$result['status'] = 304;
828
-	}
829
-
830
-	$result['headers'] = implode('', $result['headers']);
831
-
832
-	return $result;
804
+    $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
805
+
806
+    $s = @trim(fgets($handle, 16384));
807
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
808
+        return false;
809
+    }
810
+    $result['status'] = intval($r[1]);
811
+    while ($s = trim(fgets($handle, 16384))) {
812
+        $result['headers'][] = $s . "\n";
813
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
814
+        [, $d, $v] = $r;
815
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
816
+            $result['location'] = $v;
817
+        } elseif ($d == 'Last-Modified') {
818
+            $result['last_modified'] = strtotime($v);
819
+        }
820
+    }
821
+    if (
822
+        $if_modified_since
823
+        and $result['last_modified']
824
+        and $if_modified_since > $result['last_modified']
825
+        and $result['status'] == 200
826
+    ) {
827
+        $result['status'] = 304;
828
+    }
829
+
830
+    $result['headers'] = implode('', $result['headers']);
831
+
832
+    return $result;
833 833
 }
834 834
 
835 835
 /**
@@ -851,22 +851,22 @@  discard block
 block discarded – undo
851 851
  *     Nom du fichier pour copie locale
852 852
  **/
853 853
 function nom_fichier_copie_locale($source, $extension) {
854
-	include_spip('inc/documents');
854
+    include_spip('inc/documents');
855 855
 
856
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
857
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
856
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
857
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
858 858
 
859
-	// on se place tout le temps comme si on etait a la racine
860
-	if (_DIR_RACINE) {
861
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
862
-	}
859
+    // on se place tout le temps comme si on etait a la racine
860
+    if (_DIR_RACINE) {
861
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
862
+    }
863 863
 
864
-	$m = md5($source);
864
+    $m = md5($source);
865 865
 
866
-	return $d
867
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
868
-	. substr($m, 0, 4)
869
-	. ".$extension";
866
+    return $d
867
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
868
+    . substr($m, 0, 4)
869
+    . ".$extension";
870 870
 }
871 871
 
872 872
 /**
@@ -884,70 +884,70 @@  discard block
 block discarded – undo
884 884
  *      Nom du fichier calculé
885 885
  **/
886 886
 function fichier_copie_locale($source) {
887
-	// Si c'est deja local pas de souci
888
-	if (!tester_url_absolue($source)) {
889
-		if (_DIR_RACINE) {
890
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
891
-		}
892
-
893
-		return $source;
894
-	}
895
-
896
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
897
-	// a deja ete copie en local avec cette extension
898
-	// dans ce cas elle est fiable, pas la peine de requeter en base
899
-	$path_parts = pathinfo($source);
900
-	if (!isset($path_parts['extension'])) {
901
-		$path_parts['extension'] = '';
902
-	}
903
-	$ext = $path_parts ? $path_parts['extension'] : '';
904
-	if (
905
-		$ext
906
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907
-		and $f = nom_fichier_copie_locale($source, $ext)
908
-		and file_exists(_DIR_RACINE . $f)
909
-	) {
910
-		return $f;
911
-	}
912
-
913
-
914
-	// Si c'est deja dans la table des documents,
915
-	// ramener le nom de sa copie potentielle
916
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
917
-
918
-	if ($ext) {
919
-		return nom_fichier_copie_locale($source, $ext);
920
-	}
921
-
922
-	// voir si l'extension indiquee dans le nom du fichier est ok
923
-	// et si il n'aurait pas deja ete rapatrie
924
-
925
-	$ext = $path_parts ? $path_parts['extension'] : '';
926
-
927
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
928
-		$f = nom_fichier_copie_locale($source, $ext);
929
-		if (file_exists(_DIR_RACINE . $f)) {
930
-			return $f;
931
-		}
932
-	}
933
-
934
-	// Ping  pour voir si son extension est connue et autorisee
935
-	// avec mise en cache du resultat du ping
936
-
937
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
938
-	if (
939
-		!@file_exists($cache)
940
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
941
-		or _request('var_mode') === 'recalcul'
942
-	) {
943
-		$path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]);
944
-		ecrire_fichier($cache, serialize($path_parts));
945
-	}
946
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
948
-		return nom_fichier_copie_locale($source, $ext);
949
-	}
950
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
887
+    // Si c'est deja local pas de souci
888
+    if (!tester_url_absolue($source)) {
889
+        if (_DIR_RACINE) {
890
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
891
+        }
892
+
893
+        return $source;
894
+    }
895
+
896
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
897
+    // a deja ete copie en local avec cette extension
898
+    // dans ce cas elle est fiable, pas la peine de requeter en base
899
+    $path_parts = pathinfo($source);
900
+    if (!isset($path_parts['extension'])) {
901
+        $path_parts['extension'] = '';
902
+    }
903
+    $ext = $path_parts ? $path_parts['extension'] : '';
904
+    if (
905
+        $ext
906
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907
+        and $f = nom_fichier_copie_locale($source, $ext)
908
+        and file_exists(_DIR_RACINE . $f)
909
+    ) {
910
+        return $f;
911
+    }
912
+
913
+
914
+    // Si c'est deja dans la table des documents,
915
+    // ramener le nom de sa copie potentielle
916
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
917
+
918
+    if ($ext) {
919
+        return nom_fichier_copie_locale($source, $ext);
920
+    }
921
+
922
+    // voir si l'extension indiquee dans le nom du fichier est ok
923
+    // et si il n'aurait pas deja ete rapatrie
924
+
925
+    $ext = $path_parts ? $path_parts['extension'] : '';
926
+
927
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
928
+        $f = nom_fichier_copie_locale($source, $ext);
929
+        if (file_exists(_DIR_RACINE . $f)) {
930
+            return $f;
931
+        }
932
+    }
933
+
934
+    // Ping  pour voir si son extension est connue et autorisee
935
+    // avec mise en cache du resultat du ping
936
+
937
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
938
+    if (
939
+        !@file_exists($cache)
940
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
941
+        or _request('var_mode') === 'recalcul'
942
+    ) {
943
+        $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]);
944
+        ecrire_fichier($cache, serialize($path_parts));
945
+    }
946
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
948
+        return nom_fichier_copie_locale($source, $ext);
949
+    }
950
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
951 951
 }
952 952
 
953 953
 
@@ -976,110 +976,110 @@  discard block
 block discarded – undo
976 976
  **/
977 977
 function recuperer_infos_distantes($source, $options = []) {
978 978
 
979
-	// pas la peine de perdre son temps
980
-	if (!tester_url_absolue($source)) {
981
-		return false;
982
-	}
983
-
984
-	$taille_max = $options['taille_max'] ?? 0;
985
-	$charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
986
-	$callback_valider_url = $options['callback_valider_url'] ?? null;
987
-
988
-	# charger les alias des types mime
989
-	include_spip('base/typedoc');
990
-
991
-	$a = [];
992
-	$mime_type = '';
993
-	// On va directement charger le debut des images et des fichiers html,
994
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
995
-	// ca echoue l'utilisateur devra les entrer...
996
-	$reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
997
-	if (
998
-		$callback_valider_url
999
-		and is_callable($callback_valider_url)
1000
-		and !$callback_valider_url($reponse['url'])
1001
-	) {
1002
-		return false;
1003
-	}
1004
-	$headers = $reponse['headers'] ?? '';
1005
-	$a['body'] = $reponse['page'] ?? '';
1006
-	if ($headers) {
1007
-		if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1008
-			return false;
1009
-		}
1010
-
1011
-		$a['extension'] = $extension;
1012
-
1013
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1014
-			$a['taille'] = intval($regs[1]);
1015
-		}
1016
-	}
1017
-
1018
-	// Echec avec HEAD, on tente avec GET
1019
-	if (!$a and !$taille_max) {
1020
-		spip_log("tenter GET $source", 'distant');
1021
-		$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1022
-		$a = recuperer_infos_distantes($source, $options);
1023
-	}
1024
-
1025
-	// si on a rien trouve pas la peine d'insister
1026
-	if (!$a) {
1027
-		return false;
1028
-	}
1029
-
1030
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1031
-	// recharger le document en GET et recuperer des donnees supplementaires...
1032
-	include_spip('inc/filtres_images_lib_mini');
1033
-	if (
1034
-		strpos($mime_type, 'image/') === 0
1035
-		and $extension = _image_trouver_extension_depuis_mime($mime_type)
1036
-	) {
1037
-		if (
1038
-			$taille_max == 0
1039
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1040
-			and in_array($extension, formats_image_acceptables())
1041
-			and $charger_si_petite_image
1042
-		) {
1043
-			$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1044
-			$a = recuperer_infos_distantes($source, $options);
1045
-		} else {
1046
-			if ($a['body']) {
1047
-				$a['extension'] = $extension;
1048
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1049
-				ecrire_fichier($a['fichier'], $a['body']);
1050
-				$size_image = @spip_getimagesize($a['fichier']);
1051
-				$a['largeur'] = intval($size_image[0]);
1052
-				$a['hauteur'] = intval($size_image[1]);
1053
-				$a['type_image'] = true;
1054
-			}
1055
-		}
1056
-	}
1057
-
1058
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1059
-	// ce sera mieux que 0x0
1060
-	// Flash is dead!
1061
-	if (
1062
-		$a and isset($a['extension']) and $a['extension'] == 'swf'
1063
-		and empty($a['largeur'])
1064
-	) {
1065
-		$a['largeur'] = 425;
1066
-		$a['hauteur'] = 350;
1067
-	}
1068
-
1069
-	if ($mime_type == 'text/html') {
1070
-		include_spip('inc/filtres');
1071
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1072
-		$page = $page['page'] ?? '';
1073
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1074
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1075
-		}
1076
-		if (!isset($a['taille']) or !$a['taille']) {
1077
-			$a['taille'] = strlen($page); # a peu pres
1078
-		}
1079
-	}
1080
-	$a['mime_type'] = $mime_type;
1081
-
1082
-	return $a;
979
+    // pas la peine de perdre son temps
980
+    if (!tester_url_absolue($source)) {
981
+        return false;
982
+    }
983
+
984
+    $taille_max = $options['taille_max'] ?? 0;
985
+    $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
986
+    $callback_valider_url = $options['callback_valider_url'] ?? null;
987
+
988
+    # charger les alias des types mime
989
+    include_spip('base/typedoc');
990
+
991
+    $a = [];
992
+    $mime_type = '';
993
+    // On va directement charger le debut des images et des fichiers html,
994
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
995
+    // ca echoue l'utilisateur devra les entrer...
996
+    $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
997
+    if (
998
+        $callback_valider_url
999
+        and is_callable($callback_valider_url)
1000
+        and !$callback_valider_url($reponse['url'])
1001
+    ) {
1002
+        return false;
1003
+    }
1004
+    $headers = $reponse['headers'] ?? '';
1005
+    $a['body'] = $reponse['page'] ?? '';
1006
+    if ($headers) {
1007
+        if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1008
+            return false;
1009
+        }
1010
+
1011
+        $a['extension'] = $extension;
1012
+
1013
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1014
+            $a['taille'] = intval($regs[1]);
1015
+        }
1016
+    }
1017
+
1018
+    // Echec avec HEAD, on tente avec GET
1019
+    if (!$a and !$taille_max) {
1020
+        spip_log("tenter GET $source", 'distant');
1021
+        $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1022
+        $a = recuperer_infos_distantes($source, $options);
1023
+    }
1024
+
1025
+    // si on a rien trouve pas la peine d'insister
1026
+    if (!$a) {
1027
+        return false;
1028
+    }
1029
+
1030
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1031
+    // recharger le document en GET et recuperer des donnees supplementaires...
1032
+    include_spip('inc/filtres_images_lib_mini');
1033
+    if (
1034
+        strpos($mime_type, 'image/') === 0
1035
+        and $extension = _image_trouver_extension_depuis_mime($mime_type)
1036
+    ) {
1037
+        if (
1038
+            $taille_max == 0
1039
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1040
+            and in_array($extension, formats_image_acceptables())
1041
+            and $charger_si_petite_image
1042
+        ) {
1043
+            $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1044
+            $a = recuperer_infos_distantes($source, $options);
1045
+        } else {
1046
+            if ($a['body']) {
1047
+                $a['extension'] = $extension;
1048
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1049
+                ecrire_fichier($a['fichier'], $a['body']);
1050
+                $size_image = @spip_getimagesize($a['fichier']);
1051
+                $a['largeur'] = intval($size_image[0]);
1052
+                $a['hauteur'] = intval($size_image[1]);
1053
+                $a['type_image'] = true;
1054
+            }
1055
+        }
1056
+    }
1057
+
1058
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1059
+    // ce sera mieux que 0x0
1060
+    // Flash is dead!
1061
+    if (
1062
+        $a and isset($a['extension']) and $a['extension'] == 'swf'
1063
+        and empty($a['largeur'])
1064
+    ) {
1065
+        $a['largeur'] = 425;
1066
+        $a['hauteur'] = 350;
1067
+    }
1068
+
1069
+    if ($mime_type == 'text/html') {
1070
+        include_spip('inc/filtres');
1071
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1072
+        $page = $page['page'] ?? '';
1073
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1074
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1075
+        }
1076
+        if (!isset($a['taille']) or !$a['taille']) {
1077
+            $a['taille'] = strlen($page); # a peu pres
1078
+        }
1079
+    }
1080
+    $a['mime_type'] = $mime_type;
1081
+
1082
+    return $a;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1088,70 +1088,70 @@  discard block
 block discarded – undo
1088 1088
  * @return false|mixed
1089 1089
  */
1090 1090
 function distant_trouver_extension_selon_headers($source, $headers) {
1091
-	if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1092
-		$mime_type = (trim($regs[1]));
1093
-	} else {
1094
-		$mime_type = '';
1095
-	} // inconnu
1096
-
1097
-	// Appliquer les alias
1098
-	while (isset($GLOBALS['mime_alias'][$mime_type])) {
1099
-		$mime_type = $GLOBALS['mime_alias'][$mime_type];
1100
-	}
1101
-
1102
-	// pour corriger_extension()
1103
-	include_spip('inc/documents');
1104
-
1105
-	// Si on a un mime-type insignifiant
1106
-	// text/plain,application/octet-stream ou vide
1107
-	// c'est peut-etre que le serveur ne sait pas
1108
-	// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1109
-	// ou le Content-Disposition: attachment; filename=...
1110
-	$t = null;
1111
-	if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1112
-		if (
1113
-			!$t
1114
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1115
-		) {
1116
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1117
-		}
1118
-		if (
1119
-			!$t
1120
-			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1121
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1122
-		) {
1123
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1124
-		}
1125
-	}
1126
-
1127
-	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1128
-	if (!$t) {
1129
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1130
-	}
1131
-
1132
-	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1133
-	// On essaie de nouveau avec l'extension
1134
-	if (
1135
-		!$t
1136
-		and $mime_type != 'text/plain'
1137
-		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1138
-	) {
1139
-		# eviter xxx.3 => 3gp (> SPIP 3)
1140
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1141
-	}
1142
-
1143
-	if ($t) {
1144
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1145
-		return $t['extension'];
1146
-	} else {
1147
-		# par defaut on retombe sur '.bin' si c'est autorise
1148
-		spip_log("mime-type $mime_type inconnu", 'distant');
1149
-		$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1150
-		if (!$t) {
1151
-			return false;
1152
-		}
1153
-		return $t['extension'];
1154
-	}
1091
+    if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1092
+        $mime_type = (trim($regs[1]));
1093
+    } else {
1094
+        $mime_type = '';
1095
+    } // inconnu
1096
+
1097
+    // Appliquer les alias
1098
+    while (isset($GLOBALS['mime_alias'][$mime_type])) {
1099
+        $mime_type = $GLOBALS['mime_alias'][$mime_type];
1100
+    }
1101
+
1102
+    // pour corriger_extension()
1103
+    include_spip('inc/documents');
1104
+
1105
+    // Si on a un mime-type insignifiant
1106
+    // text/plain,application/octet-stream ou vide
1107
+    // c'est peut-etre que le serveur ne sait pas
1108
+    // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1109
+    // ou le Content-Disposition: attachment; filename=...
1110
+    $t = null;
1111
+    if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1112
+        if (
1113
+            !$t
1114
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1115
+        ) {
1116
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1117
+        }
1118
+        if (
1119
+            !$t
1120
+            and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1121
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1122
+        ) {
1123
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1124
+        }
1125
+    }
1126
+
1127
+    // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1128
+    if (!$t) {
1129
+        $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1130
+    }
1131
+
1132
+    // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1133
+    // On essaie de nouveau avec l'extension
1134
+    if (
1135
+        !$t
1136
+        and $mime_type != 'text/plain'
1137
+        and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1138
+    ) {
1139
+        # eviter xxx.3 => 3gp (> SPIP 3)
1140
+        $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1141
+    }
1142
+
1143
+    if ($t) {
1144
+        spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1145
+        return $t['extension'];
1146
+    } else {
1147
+        # par defaut on retombe sur '.bin' si c'est autorise
1148
+        spip_log("mime-type $mime_type inconnu", 'distant');
1149
+        $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1150
+        if (!$t) {
1151
+            return false;
1152
+        }
1153
+        return $t['extension'];
1154
+    }
1155 1155
 }
1156 1156
 
1157 1157
 /**
@@ -1167,45 +1167,45 @@  discard block
 block discarded – undo
1167 1167
  */
1168 1168
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1169 1169
 
1170
-	$http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1171
-
1172
-	// rien a faire si pas de proxy :)
1173
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1174
-		return '';
1175
-	}
1176
-
1177
-	if (is_null($http_noproxy)) {
1178
-		$http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1179
-	}
1180
-	// si pas d'exception, on retourne le proxy
1181
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1182
-		return $http_proxy;
1183
-	}
1184
-
1185
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1186
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1187
-	$http_noproxy = str_replace("\n", ' ', $http_noproxy);
1188
-	$http_noproxy = str_replace("\r", ' ', $http_noproxy);
1189
-	$http_noproxy = " $http_noproxy ";
1190
-	$domain = $host;
1191
-	// si le domaine exact www.example.org est dans les exceptions
1192
-	if (strpos($http_noproxy, (string) " $domain ") !== false) {
1193
-		return '';
1194
-	}
1195
-
1196
-	while (strpos($domain, '.') !== false) {
1197
-		$domain = explode('.', $domain);
1198
-		array_shift($domain);
1199
-		$domain = implode('.', $domain);
1200
-
1201
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1202
-		if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1203
-			return '';
1204
-		}
1205
-	}
1206
-
1207
-	// ok c'est pas une exception
1208
-	return $http_proxy;
1170
+    $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1171
+
1172
+    // rien a faire si pas de proxy :)
1173
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1174
+        return '';
1175
+    }
1176
+
1177
+    if (is_null($http_noproxy)) {
1178
+        $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1179
+    }
1180
+    // si pas d'exception, on retourne le proxy
1181
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1182
+        return $http_proxy;
1183
+    }
1184
+
1185
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1186
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1187
+    $http_noproxy = str_replace("\n", ' ', $http_noproxy);
1188
+    $http_noproxy = str_replace("\r", ' ', $http_noproxy);
1189
+    $http_noproxy = " $http_noproxy ";
1190
+    $domain = $host;
1191
+    // si le domaine exact www.example.org est dans les exceptions
1192
+    if (strpos($http_noproxy, (string) " $domain ") !== false) {
1193
+        return '';
1194
+    }
1195
+
1196
+    while (strpos($domain, '.') !== false) {
1197
+        $domain = explode('.', $domain);
1198
+        array_shift($domain);
1199
+        $domain = implode('.', $domain);
1200
+
1201
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1202
+        if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1203
+            return '';
1204
+        }
1205
+    }
1206
+
1207
+    // ok c'est pas une exception
1208
+    return $http_proxy;
1209 1209
 }
1210 1210
 
1211 1211
 
@@ -1228,59 +1228,59 @@  discard block
 block discarded – undo
1228 1228
  * @return array
1229 1229
  */
1230 1230
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1231
-	$user = $via_proxy = $proxy_user = '';
1232
-	$fopen = false;
1233
-
1234
-	$t = @parse_url($url);
1235
-	$host = $t['host'];
1236
-	if ($t['scheme'] == 'http') {
1237
-		$scheme = 'http';
1238
-		$noproxy = '';
1239
-	} elseif ($t['scheme'] == 'https') {
1240
-		$scheme = 'ssl';
1241
-		$noproxy = 'ssl://';
1242
-		if (!isset($t['port']) || !($port = $t['port'])) {
1243
-			$t['port'] = 443;
1244
-		}
1245
-	} else {
1246
-		$scheme = $t['scheme'];
1247
-		$noproxy = $scheme . '://';
1248
-	}
1249
-	if (isset($t['user'])) {
1250
-		$user = [$t['user'], $t['pass']];
1251
-	}
1252
-
1253
-	if (!isset($t['port']) || !($port = $t['port'])) {
1254
-		$port = 80;
1255
-	}
1256
-	if (!isset($t['path']) || !($path = $t['path'])) {
1257
-		$path = '/';
1258
-	}
1259
-
1260
-	if (!empty($t['query'])) {
1261
-		$path .= '?' . $t['query'];
1262
-	}
1263
-
1264
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1265
-	if (!$f or !is_resource($f)) {
1266
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1267
-		// ce qui correspond a $f===110
1268
-		if (
1269
-			$f !== 110
1270
-			and !need_proxy($host)
1271
-			and !_request('tester_proxy')
1272
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1273
-		) {
1274
-			$f = @fopen($url, 'rb');
1275
-			spip_log("connexion vers $url par simple fopen", 'distant');
1276
-			$fopen = true;
1277
-		} else {
1278
-			// echec total
1279
-			$f = false;
1280
-		}
1281
-	}
1282
-
1283
-	return [$f, $fopen];
1231
+    $user = $via_proxy = $proxy_user = '';
1232
+    $fopen = false;
1233
+
1234
+    $t = @parse_url($url);
1235
+    $host = $t['host'];
1236
+    if ($t['scheme'] == 'http') {
1237
+        $scheme = 'http';
1238
+        $noproxy = '';
1239
+    } elseif ($t['scheme'] == 'https') {
1240
+        $scheme = 'ssl';
1241
+        $noproxy = 'ssl://';
1242
+        if (!isset($t['port']) || !($port = $t['port'])) {
1243
+            $t['port'] = 443;
1244
+        }
1245
+    } else {
1246
+        $scheme = $t['scheme'];
1247
+        $noproxy = $scheme . '://';
1248
+    }
1249
+    if (isset($t['user'])) {
1250
+        $user = [$t['user'], $t['pass']];
1251
+    }
1252
+
1253
+    if (!isset($t['port']) || !($port = $t['port'])) {
1254
+        $port = 80;
1255
+    }
1256
+    if (!isset($t['path']) || !($path = $t['path'])) {
1257
+        $path = '/';
1258
+    }
1259
+
1260
+    if (!empty($t['query'])) {
1261
+        $path .= '?' . $t['query'];
1262
+    }
1263
+
1264
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1265
+    if (!$f or !is_resource($f)) {
1266
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1267
+        // ce qui correspond a $f===110
1268
+        if (
1269
+            $f !== 110
1270
+            and !need_proxy($host)
1271
+            and !_request('tester_proxy')
1272
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1273
+        ) {
1274
+            $f = @fopen($url, 'rb');
1275
+            spip_log("connexion vers $url par simple fopen", 'distant');
1276
+            $fopen = true;
1277
+        } else {
1278
+            // echec total
1279
+            $f = false;
1280
+        }
1281
+    }
1282
+
1283
+    return [$f, $fopen];
1284 1284
 }
1285 1285
 
1286 1286
 /**
@@ -1315,123 +1315,123 @@  discard block
 block discarded – undo
1315 1315
  *   resource socket vers l'url demandee
1316 1316
  */
1317 1317
 function lance_requete(
1318
-	$method,
1319
-	$scheme,
1320
-	$user,
1321
-	$host,
1322
-	$path,
1323
-	$port,
1324
-	$noproxy,
1325
-	$refuse_gz = false,
1326
-	$referer = '',
1327
-	$datas = '',
1328
-	$vers = 'HTTP/1.0',
1329
-	$date = ''
1318
+    $method,
1319
+    $scheme,
1320
+    $user,
1321
+    $host,
1322
+    $path,
1323
+    $port,
1324
+    $noproxy,
1325
+    $refuse_gz = false,
1326
+    $referer = '',
1327
+    $datas = '',
1328
+    $vers = 'HTTP/1.0',
1329
+    $date = ''
1330 1330
 ) {
1331 1331
 
1332
-	$proxy_user = '';
1333
-	$http_proxy = need_proxy($host);
1334
-	if ($user) {
1335
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1336
-	}
1337
-
1338
-	$connect = '';
1339
-	if ($http_proxy) {
1340
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1341
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1342
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1343
-				. "Host: $path_host\r\n"
1344
-				. "Proxy-Connection: Keep-Alive\r\n";
1345
-		} else {
1346
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1347
-				. (!$user ? '' : "$user@")
1348
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1349
-		}
1350
-		$t2 = @parse_url($http_proxy);
1351
-		$first_host = $t2['host'];
1352
-		$port = ($t2['port'] ?? null) ?: 80;
1353
-		if ($t2['user'] ?? null) {
1354
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1355
-		}
1356
-	} else {
1357
-		$first_host = $noproxy . $host;
1358
-	}
1359
-
1360
-	if ($connect) {
1361
-		$streamContext = stream_context_create([
1362
-			'ssl' => [
1363
-				'verify_peer' => false,
1364
-				'allow_self_signed' => true,
1365
-				'SNI_enabled' => true,
1366
-				'peer_name' => $host,
1367
-			]
1368
-		]);
1369
-		$f = @stream_socket_client(
1370
-			"tcp://$first_host:$port",
1371
-			$errno,
1372
-			$errstr,
1373
-			_INC_DISTANT_CONNECT_TIMEOUT,
1374
-			STREAM_CLIENT_CONNECT,
1375
-			$streamContext
1376
-		);
1377
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1378
-		if (!$f) {
1379
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1380
-			return $errno;
1381
-		}
1382
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1383
-
1384
-		fputs($f, $connect);
1385
-		fputs($f, "\r\n");
1386
-		$res = fread($f, 1024);
1387
-		if (
1388
-			!$res
1389
-			or !count($res = explode(' ', $res))
1390
-			or $res[1] !== '200'
1391
-		) {
1392
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1393
-			fclose($f);
1394
-
1395
-			return false;
1396
-		}
1397
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1398
-		stream_set_blocking($f, true);
1399
-		// envoyer le handshake
1400
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1401
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1402
-	} else {
1403
-		$ntry = 3;
1404
-		do {
1405
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1406
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1407
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1408
-		if (!$f) {
1409
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1410
-
1411
-			return $errno;
1412
-		}
1413
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1414
-	}
1415
-
1416
-	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1417
-
1418
-	$host_port = $host;
1419
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1420
-		$host_port .= ":$port";
1421
-	}
1422
-	$req = "$method $path $vers\r\n"
1423
-		. "Host: $host_port\r\n"
1424
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1425
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1426
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1427
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1428
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1429
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1430
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1332
+    $proxy_user = '';
1333
+    $http_proxy = need_proxy($host);
1334
+    if ($user) {
1335
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1336
+    }
1337
+
1338
+    $connect = '';
1339
+    if ($http_proxy) {
1340
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1341
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1342
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1343
+                . "Host: $path_host\r\n"
1344
+                . "Proxy-Connection: Keep-Alive\r\n";
1345
+        } else {
1346
+            $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1347
+                . (!$user ? '' : "$user@")
1348
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1349
+        }
1350
+        $t2 = @parse_url($http_proxy);
1351
+        $first_host = $t2['host'];
1352
+        $port = ($t2['port'] ?? null) ?: 80;
1353
+        if ($t2['user'] ?? null) {
1354
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1355
+        }
1356
+    } else {
1357
+        $first_host = $noproxy . $host;
1358
+    }
1359
+
1360
+    if ($connect) {
1361
+        $streamContext = stream_context_create([
1362
+            'ssl' => [
1363
+                'verify_peer' => false,
1364
+                'allow_self_signed' => true,
1365
+                'SNI_enabled' => true,
1366
+                'peer_name' => $host,
1367
+            ]
1368
+        ]);
1369
+        $f = @stream_socket_client(
1370
+            "tcp://$first_host:$port",
1371
+            $errno,
1372
+            $errstr,
1373
+            _INC_DISTANT_CONNECT_TIMEOUT,
1374
+            STREAM_CLIENT_CONNECT,
1375
+            $streamContext
1376
+        );
1377
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1378
+        if (!$f) {
1379
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1380
+            return $errno;
1381
+        }
1382
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1383
+
1384
+        fputs($f, $connect);
1385
+        fputs($f, "\r\n");
1386
+        $res = fread($f, 1024);
1387
+        if (
1388
+            !$res
1389
+            or !count($res = explode(' ', $res))
1390
+            or $res[1] !== '200'
1391
+        ) {
1392
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1393
+            fclose($f);
1394
+
1395
+            return false;
1396
+        }
1397
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1398
+        stream_set_blocking($f, true);
1399
+        // envoyer le handshake
1400
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1401
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1402
+    } else {
1403
+        $ntry = 3;
1404
+        do {
1405
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1406
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1407
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1408
+        if (!$f) {
1409
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1410
+
1411
+            return $errno;
1412
+        }
1413
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1414
+    }
1415
+
1416
+    $site = $GLOBALS['meta']['adresse_site'] ?? '';
1417
+
1418
+    $host_port = $host;
1419
+    if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1420
+        $host_port .= ":$port";
1421
+    }
1422
+    $req = "$method $path $vers\r\n"
1423
+        . "Host: $host_port\r\n"
1424
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1425
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1426
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1427
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1428
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1429
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1430
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1431 1431
 
1432 1432
 #	spip_log("Requete\n$req", 'distant');
1433
-	fputs($f, $req);
1434
-	fputs($f, $datas ?: "\r\n");
1433
+    fputs($f, $req);
1434
+    fputs($f, $datas ?: "\r\n");
1435 1435
 
1436
-	return $f;
1436
+    return $f;
1437 1437
 }
Please login to merge, or discard this patch.
ecrire/inc/install.php 2 patches
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
46
+	$texte = '<'."?php\n"
47 47
 		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48 48
 		. $texte;
49 49
 
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 		return $regs;
113 113
 	} else {
114 114
 		$ar = '\s*\'([^\']*)\'';
115
-		$r = '\s*,' . $ar;
115
+		$r = '\s*,'.$ar;
116 116
 		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
117 117
 		if (preg_match($r, $s, $regs)) {
118
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
118
+			$regs[2] = $regs[1].(!$regs[2] ? '' : ':'.$regs[2].';');
119 119
 			array_shift($regs);
120 120
 			array_shift($regs);
121 121
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	// Si on n'a pas la bonne version de PHP, c'est la fin
181 181
 	if ($err) {
182 182
 		die("<div class='error'>"
183
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
183
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
184 184
 			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
185 185
 	}
186 186
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
 	if ($err) {
203 203
 		echo "<div class='error'>"
204
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
204
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
205 205
 		foreach ($err as $e) {
206 206
 			echo "<li><strong>$e</strong></li>\n";
207 207
 		}
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 function info_etape($titre, $complement = '') {
237
-	return '<h2>' . $titre . "</h2>\n" .
238
-	($complement ? '' . $complement . "\n" : '');
237
+	return '<h2>'.$titre."</h2>\n".
238
+	($complement ? ''.$complement."\n" : '');
239 239
 }
240 240
 
241 241
 /**
@@ -249,18 +249,18 @@  discard block
 block discarded – undo
249 249
 		$code = _T('bouton_suivant');
250 250
 	}
251 251
 	static $suivant = 0;
252
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
252
+	$id = 'suivant'.(($suivant > 0) ? strval($suivant) : '');
253 253
 	$suivant += 1;
254 254
 
255
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
256
-	$code .
255
+	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"".
256
+	$code.
257 257
 	" >>\" /></p>\n";
258 258
 }
259 259
 
260 260
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
261 261
 	$intitule_etat = [];
262 262
 	//$en_cours = _request('etape')?_request('etape'):"";
263
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
263
+	$liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$');
264 264
 	$debut = 1;
265 265
 	$etat = 'ok';
266 266
 	$last = count($liste);
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 
300 300
 			$aff_etapes .= "<li class='$class'><div class='fond'>";
301 301
 			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
302
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
302
+			$aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
303 303
 			$aff_etapes .= $intitule_etat["$phase"][$debut];
304 304
 			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
305 305
 			$aff_etapes .= '</div></li>';
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 
315 315
 
316 316
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
317
-	return "<fieldset>\n" .
318
-	$avant .
319
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
320
-	fieldset_champs($champs) .
321
-	$apres .
317
+	return "<fieldset>\n".
318
+	$avant.
319
+	($legend ? '<legend>'.$legend."</legend>\n" : '').
320
+	fieldset_champs($champs).
321
+	$apres.
322 322
 	"</fieldset>\n";
323 323
 }
324 324
 
@@ -328,18 +328,18 @@  discard block
 block discarded – undo
328 328
 		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
329 329
 		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
330 330
 		if (isset($contenu['alternatives'])) {
331
-			$fieldset .= $contenu['label'] . "\n";
331
+			$fieldset .= $contenu['label']."\n";
332 332
 			foreach ($contenu['alternatives'] as $valeur => $label) {
333
-				$fieldset .= "<input type='radio' name='" . $nom .
333
+				$fieldset .= "<input type='radio' name='".$nom.
334 334
 					"' id='$nom-$valeur' value='$valeur'"
335 335
 					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
336 336
 					. "/>\n";
337
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
337
+				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
338 338
 			}
339 339
 			$fieldset .= "<br />\n";
340 340
 		} else {
341
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
342
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
341
+			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
342
+			$fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'"
343 343
 				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
344 344
 				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
345 345
 				. " />\n";
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 
352 352
 function install_select_serveur() {
353 353
 	$options = [];
354
-	$dir = _DIR_RESTREINT . 'req/';
354
+	$dir = _DIR_RESTREINT.'req/';
355 355
 	$d = opendir($dir);
356 356
 	if (!$d) {
357 357
 		return [];
@@ -359,17 +359,17 @@  discard block
 block discarded – undo
359 359
 	while (($f = readdir($d)) !== false) {
360 360
 		if (
361 361
 			(preg_match('/^(.*)[.]php$/', $f, $s))
362
-			and is_readable($f = $dir . $f)
362
+			and is_readable($f = $dir.$f)
363 363
 		) {
364 364
 			require_once($f);
365 365
 			$s = $s[1];
366
-			$v = 'spip_versions_' . $s;
366
+			$v = 'spip_versions_'.$s;
367 367
 			if (function_exists($v) and $v()) {
368 368
 				$titre = _T("install_select_type_$s");
369 369
 				// proposer mysql par defaut si dispo
370 370
 				$checked = ($s == 'mysql' ? " checked='checked'" : '');
371 371
 				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
372
-					. "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
372
+					. "<label for='$s'>".($titre ?: $s).'</label></li>';
373 373
 			} else {
374 374
 				spip_log("$s: portage indisponible");
375 375
 			}
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 		"\n<input type='hidden' name='etape' value='$etape' />"
388 388
 		. $hidden
389 389
 		. (_request('echec') ?
390
-			('<p><b>' . _T('avis_connexion_echec_1') .
391
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
390
+			('<p><b>'._T('avis_connexion_echec_1').
391
+				'</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>')
392 392
 			: '')
393 393
 
394 394
 		. ($jquery ? http_script('', 'jquery.js') : '')
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 		});')
427 427
 
428 428
 		. ($server_db
429
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
429
+			? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
430 430
 			. (($predef[0])
431
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
431
+				? ('<h3>'._T('install_serveur_hebergeur').'</h3>')
432 432
 				: '')
433 433
 			: ('<fieldset><legend>'
434 434
 				. _T('install_select_type_db')
@@ -443,9 +443,9 @@  discard block
 block discarded – undo
443 443
 				. "\n</ul>\n</div></fieldset>")
444 444
 		)
445 445
 		. '<div id="install_adresse_base_hebergeur">'
446
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
446
+		. '<p>'._T('texte_connexion_mysql').'</p>'
447 447
 		. ($predef[1]
448
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
448
+			? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
449 449
 			: fieldset(
450 450
 				_T('entree_base_donnee_1'),
451 451
 				[
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 
461 461
 		. '<div id="install_login_base_hebergeur">'
462 462
 		. ($predef[2]
463
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
463
+			? '<h3>'._T('install_login_base_hebergeur').'</h3>'
464 464
 			: fieldset(
465 465
 				_T('entree_login_connexion_1'),
466 466
 				[
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
 		. '<div id="install_pass_base_hebergeur">'
477 477
 		. ($predef[3]
478
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
478
+			? '<h3>'._T('install_pass_base_hebergeur').'</h3>'
479 479
 			: fieldset(
480 480
 				_T('entree_mot_passe_1'),
481 481
 				[
@@ -497,20 +497,20 @@  discard block
 block discarded – undo
497 497
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
498 498
 	return ((defined('_INSTALL_HOST_DB'))
499 499
 		? ''
500
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
500
+		: "\n<input type='hidden' name='adresse_db'  value=\"".spip_htmlspecialchars($adresse_db).'" />'
501 501
 	)
502 502
 	. ((defined('_INSTALL_USER_DB'))
503 503
 		? ''
504
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
504
+		: "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />'
505 505
 	)
506 506
 	. ((defined('_INSTALL_PASS_DB'))
507 507
 		? ''
508
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
508
+		: "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />'
509 509
 	)
510 510
 
511 511
 	. ((defined('_INSTALL_SERVER_DB'))
512 512
 		? ''
513
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
513
+		: "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />'
514 514
 	);
515 515
 }
516 516
 
Please login to merge, or discard this patch.
Indentation   +364 added lines, -364 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,11 +43,11 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
47
-		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
-		. $texte;
46
+    $texte = '<' . "?php\n"
47
+        . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
+        . $texte;
49 49
 
50
-	ecrire_fichier($nom, $texte);
50
+    ecrire_fichier($nom, $texte);
51 51
 }
52 52
 
53 53
 
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
  *
77 77
  **/
78 78
 function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') {
79
-	$adr = addcslashes($adr, "'\\");
80
-	$port = addcslashes($port, "'\\");
81
-	$login = addcslashes($login, "'\\");
82
-	$pass = addcslashes($pass, "'\\");
83
-	$base = addcslashes($base, "'\\");
84
-	$type = addcslashes($type, "'\\");
85
-	$pref = addcslashes($pref, "'\\");
86
-	$ldap = addcslashes($ldap, "'\\");
87
-	$charset = addcslashes($charset, "'\\");
88
-
89
-	return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
90
-	. 'spip_connect_db('
91
-	. "'$adr','$port','$login','$pass','$base'"
92
-	. ",'$type', '$pref','$ldap','$charset');\n";
79
+    $adr = addcslashes($adr, "'\\");
80
+    $port = addcslashes($port, "'\\");
81
+    $login = addcslashes($login, "'\\");
82
+    $pass = addcslashes($pass, "'\\");
83
+    $base = addcslashes($base, "'\\");
84
+    $type = addcslashes($type, "'\\");
85
+    $pref = addcslashes($pref, "'\\");
86
+    $ldap = addcslashes($ldap, "'\\");
87
+    $charset = addcslashes($charset, "'\\");
88
+
89
+    return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
90
+    . 'spip_connect_db('
91
+    . "'$adr','$port','$login','$pass','$base'"
92
+    . ",'$type', '$pref','$ldap','$charset');\n";
93 93
 }
94 94
 
95 95
 
@@ -105,29 +105,29 @@  discard block
 block discarded – undo
105 105
  *     Tableau des informations sur la connexion
106 106
  **/
107 107
 function analyse_fichier_connection(string $file): array {
108
-	if (!file_exists($file)) {
109
-		return [];
110
-	}
111
-	$s = file_get_contents($file);
112
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
113
-		array_shift($regs);
114
-
115
-		return $regs;
116
-	} else {
117
-		$ar = '\s*\'([^\']*)\'';
118
-		$r = '\s*,' . $ar;
119
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
120
-		if (preg_match($r, $s, $regs)) {
121
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
122
-			array_shift($regs);
123
-			array_shift($regs);
124
-
125
-			return $regs;
126
-		}
127
-	}
128
-	spip_log("$file n'est pas un fichier de connexion");
129
-
130
-	return [];
108
+    if (!file_exists($file)) {
109
+        return [];
110
+    }
111
+    $s = file_get_contents($file);
112
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
113
+        array_shift($regs);
114
+
115
+        return $regs;
116
+    } else {
117
+        $ar = '\s*\'([^\']*)\'';
118
+        $r = '\s*,' . $ar;
119
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
120
+        if (preg_match($r, $s, $regs)) {
121
+            $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
122
+            array_shift($regs);
123
+            array_shift($regs);
124
+
125
+            return $regs;
126
+        }
127
+    }
128
+    spip_log("$file n'est pas un fichier de connexion");
129
+
130
+    return [];
131 131
 }
132 132
 
133 133
 /**
@@ -144,75 +144,75 @@  discard block
 block discarded – undo
144 144
  *     Liste des noms de connecteurs
145 145
  **/
146 146
 function bases_referencees($exclu = '') {
147
-	$tables = [];
148
-	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
149
-		if ($f != $exclu and analyse_fichier_connection($f)) {
150
-			$tables[] = basename($f, '.php');
151
-		}
152
-	}
153
-
154
-	return $tables;
147
+    $tables = [];
148
+    foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
149
+        if ($f != $exclu and analyse_fichier_connection($f)) {
150
+            $tables[] = basename($f, '.php');
151
+        }
152
+    }
153
+
154
+    return $tables;
155 155
 }
156 156
 
157 157
 
158 158
 function install_mode_appel($server_db, $tout = true) {
159
-	return ($server_db != 'mysql') ? ''
160
-		: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
161
-			. test_sql_mode_mysql($server_db));
159
+    return ($server_db != 'mysql') ? ''
160
+        : (($tout ? test_rappel_nom_base_mysql($server_db) : '')
161
+            . test_sql_mode_mysql($server_db));
162 162
 }
163 163
 
164 164
 //
165 165
 // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-)
166 166
 // (sert a l'etape 1 de l'installation)
167 167
 function tester_compatibilite_hebergement() {
168
-	$err = [];
169
-
170
-	$p = phpversion();
171
-	if (version_compare($p, _PHP_MIN, '<')) {
172
-		$err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
173
-	}
174
-	if (version_compare($p, _PHP_MAX, '>')) {
175
-		$err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]);
176
-	}
177
-
178
-	$diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions());
179
-	if (!empty($diff)) {
180
-		$err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]);
181
-	}
182
-
183
-	// Si on n'a pas la bonne version de PHP, c'est la fin
184
-	if ($err) {
185
-		die("<div class='error'>"
186
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
187
-			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
188
-	}
189
-
190
-	// Il faut une base de donnees tout de meme ...
191
-	$serveurs = install_select_serveur();
192
-	if (!$serveurs) {
193
-		$err[] = _T('install_extension_php_obligatoire')
194
-			. " <a href='http://www.php.net/mysql'>MYSQL</a>"
195
-			. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
196
-			. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
197
-	}
198
-
199
-	// et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0)
200
-	if ($a = @ini_get('mbstring.func_overload')) {
201
-		$err[] = _T('install_extension_mbstring')
202
-			. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
203
-	}
204
-
205
-	if ($err) {
206
-		echo "<div class='error'>"
207
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
208
-		foreach ($err as $e) {
209
-			echo "<li><strong>$e</strong></li>\n";
210
-		}
211
-
212
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
213
-		# de forcer malgre tout (pour tester, ou si bug de detection)
214
-		echo "</ul></div>\n";
215
-	}
168
+    $err = [];
169
+
170
+    $p = phpversion();
171
+    if (version_compare($p, _PHP_MIN, '<')) {
172
+        $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
173
+    }
174
+    if (version_compare($p, _PHP_MAX, '>')) {
175
+        $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]);
176
+    }
177
+
178
+    $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions());
179
+    if (!empty($diff)) {
180
+        $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]);
181
+    }
182
+
183
+    // Si on n'a pas la bonne version de PHP, c'est la fin
184
+    if ($err) {
185
+        die("<div class='error'>"
186
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
187
+            . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
188
+    }
189
+
190
+    // Il faut une base de donnees tout de meme ...
191
+    $serveurs = install_select_serveur();
192
+    if (!$serveurs) {
193
+        $err[] = _T('install_extension_php_obligatoire')
194
+            . " <a href='http://www.php.net/mysql'>MYSQL</a>"
195
+            . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
196
+            . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
197
+    }
198
+
199
+    // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0)
200
+    if ($a = @ini_get('mbstring.func_overload')) {
201
+        $err[] = _T('install_extension_mbstring')
202
+            . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
203
+    }
204
+
205
+    if ($err) {
206
+        echo "<div class='error'>"
207
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
208
+        foreach ($err as $e) {
209
+            echo "<li><strong>$e</strong></li>\n";
210
+        }
211
+
212
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
213
+        # de forcer malgre tout (pour tester, ou si bug de detection)
214
+        echo "</ul></div>\n";
215
+    }
216 216
 }
217 217
 
218 218
 
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
  * @note superflu ??
223 223
  */
224 224
 function login_hebergeur() {
225
-	$base_hebergeur = 'localhost'; # par defaut
225
+    $base_hebergeur = 'localhost'; # par defaut
226 226
 
227
-	// Free
228
-	if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
229
-		$base_hebergeur = 'sql.free.fr';
230
-		$login_hebergeur = $regs[1];
231
-	} else {
232
-		$login_hebergeur = '';
233
-	}
227
+    // Free
228
+    if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
229
+        $base_hebergeur = 'sql.free.fr';
230
+        $login_hebergeur = $regs[1];
231
+    } else {
232
+        $login_hebergeur = '';
233
+    }
234 234
 
235
-	return [$base_hebergeur, $login_hebergeur];
235
+    return [$base_hebergeur, $login_hebergeur];
236 236
 }
237 237
 
238 238
 
239 239
 function info_etape($titre, $complement = '') {
240
-	return '<h2>' . $titre . "</h2>\n" .
241
-	($complement ? '' . $complement . "\n" : '');
240
+    return '<h2>' . $titre . "</h2>\n" .
241
+    ($complement ? '' . $complement . "\n" : '');
242 242
 }
243 243
 
244 244
 /**
@@ -248,154 +248,154 @@  discard block
 block discarded – undo
248 248
  * @return string Code HTML du bouton
249 249
  **/
250 250
 function bouton_suivant($code = '') {
251
-	if ($code == '') {
252
-		$code = _T('bouton_suivant');
253
-	}
254
-	static $suivant = 0;
255
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
256
-	$suivant += 1;
257
-
258
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
259
-	$code .
260
-	" >>\" /></p>\n";
251
+    if ($code == '') {
252
+        $code = _T('bouton_suivant');
253
+    }
254
+    static $suivant = 0;
255
+    $id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
256
+    $suivant += 1;
257
+
258
+    return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
259
+    $code .
260
+    " >>\" /></p>\n";
261 261
 }
262 262
 
263 263
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
264
-	$intitule_etat = [];
265
-	//$en_cours = _request('etape')?_request('etape'):"";
266
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
267
-	$debut = 1;
268
-	$etat = 'ok';
269
-	$last = count($liste);
264
+    $intitule_etat = [];
265
+    //$en_cours = _request('etape')?_request('etape'):"";
266
+    $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
267
+    $debut = 1;
268
+    $etat = 'ok';
269
+    $last = count($liste);
270 270
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
271 271
 
272
-	$intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
273
-	$intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
274
-	$intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
275
-	$intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
272
+    $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
273
+    $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
274
+    $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
275
+    $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
276 276
 
277
-	$intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
278
-	$intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
279
-	$intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
280
-	$intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
281
-	$intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
277
+    $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
278
+    $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
279
+    $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
280
+    $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
281
+    $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
282 282
 
283 283
 //	$aff_etapes = "<span id='etapes'>";
284 284
 
285
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
286
-
287
-	foreach ($liste as $etape => $fichier) {
288
-		if ($debut < $last) {
289
-			if ($debut == $en_cours && $erreur) {
290
-				$class = 'on erreur';
291
-			} else {
292
-				if ($debut == $en_cours) {
293
-					$class = 'on';
294
-				} else {
295
-					if ($debut > $en_cours) {
296
-						$class = 'prochains';
297
-					} else {
298
-						$class = 'valides';
299
-					}
300
-				}
301
-			}
302
-
303
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
304
-			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
305
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
306
-			$aff_etapes .= $intitule_etat["$phase"][$debut];
307
-			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
308
-			$aff_etapes .= '</div></li>';
309
-		}
310
-		$debut++;
311
-	}
312
-	$aff_etapes .= '</ul>';
313
-	$aff_etapes .= "<br class='nettoyeur' />\n";
314
-
315
-	return $aff_etapes;
285
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
286
+
287
+    foreach ($liste as $etape => $fichier) {
288
+        if ($debut < $last) {
289
+            if ($debut == $en_cours && $erreur) {
290
+                $class = 'on erreur';
291
+            } else {
292
+                if ($debut == $en_cours) {
293
+                    $class = 'on';
294
+                } else {
295
+                    if ($debut > $en_cours) {
296
+                        $class = 'prochains';
297
+                    } else {
298
+                        $class = 'valides';
299
+                    }
300
+                }
301
+            }
302
+
303
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
304
+            $aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
305
+            $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
306
+            $aff_etapes .= $intitule_etat["$phase"][$debut];
307
+            $aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
308
+            $aff_etapes .= '</div></li>';
309
+        }
310
+        $debut++;
311
+    }
312
+    $aff_etapes .= '</ul>';
313
+    $aff_etapes .= "<br class='nettoyeur' />\n";
314
+
315
+    return $aff_etapes;
316 316
 }
317 317
 
318 318
 
319 319
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
320
-	return "<fieldset>\n" .
321
-	$avant .
322
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
323
-	fieldset_champs($champs) .
324
-	$apres .
325
-	"</fieldset>\n";
320
+    return "<fieldset>\n" .
321
+    $avant .
322
+    ($legend ? '<legend>' . $legend . "</legend>\n" : '') .
323
+    fieldset_champs($champs) .
324
+    $apres .
325
+    "</fieldset>\n";
326 326
 }
327 327
 
328 328
 function fieldset_champs($champs = []) {
329
-	$fieldset = '';
330
-	foreach ($champs as $nom => $contenu) {
331
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
332
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
333
-		if (isset($contenu['alternatives'])) {
334
-			$fieldset .= $contenu['label'] . "\n";
335
-			foreach ($contenu['alternatives'] as $valeur => $label) {
336
-				$fieldset .= "<input type='radio' name='" . $nom .
337
-					"' id='$nom-$valeur' value='$valeur'"
338
-					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
339
-					. "/>\n";
340
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
341
-			}
342
-			$fieldset .= "<br />\n";
343
-		} else {
344
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
345
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
346
-				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
347
-				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
348
-				. " />\n";
349
-		}
350
-	}
351
-
352
-	return $fieldset;
329
+    $fieldset = '';
330
+    foreach ($champs as $nom => $contenu) {
331
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
332
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
333
+        if (isset($contenu['alternatives'])) {
334
+            $fieldset .= $contenu['label'] . "\n";
335
+            foreach ($contenu['alternatives'] as $valeur => $label) {
336
+                $fieldset .= "<input type='radio' name='" . $nom .
337
+                    "' id='$nom-$valeur' value='$valeur'"
338
+                    . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
339
+                    . "/>\n";
340
+                $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
341
+            }
342
+            $fieldset .= "<br />\n";
343
+        } else {
344
+            $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
345
+            $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
346
+                . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
347
+                . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
348
+                . " />\n";
349
+        }
350
+    }
351
+
352
+    return $fieldset;
353 353
 }
354 354
 
355 355
 function install_select_serveur() {
356
-	$options = [];
357
-	$dir = _DIR_RESTREINT . 'req/';
358
-	$d = opendir($dir);
359
-	if (!$d) {
360
-		return [];
361
-	}
362
-	while (($f = readdir($d)) !== false) {
363
-		if (
364
-			(preg_match('/^(.*)[.]php$/', $f, $s))
365
-			and is_readable($f = $dir . $f)
366
-		) {
367
-			require_once($f);
368
-			$s = $s[1];
369
-			$v = 'spip_versions_' . $s;
370
-			if (function_exists($v) and $v()) {
371
-				$titre = _T("install_select_type_$s");
372
-				// proposer mysql par defaut si dispo
373
-				$checked = ($s == 'mysql' ? " checked='checked'" : '');
374
-				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
375
-					. "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
376
-			} else {
377
-				spip_log("$s: portage indisponible");
378
-			}
379
-		}
380
-	}
381
-	sort($options);
382
-
383
-	return $options;
356
+    $options = [];
357
+    $dir = _DIR_RESTREINT . 'req/';
358
+    $d = opendir($dir);
359
+    if (!$d) {
360
+        return [];
361
+    }
362
+    while (($f = readdir($d)) !== false) {
363
+        if (
364
+            (preg_match('/^(.*)[.]php$/', $f, $s))
365
+            and is_readable($f = $dir . $f)
366
+        ) {
367
+            require_once($f);
368
+            $s = $s[1];
369
+            $v = 'spip_versions_' . $s;
370
+            if (function_exists($v) and $v()) {
371
+                $titre = _T("install_select_type_$s");
372
+                // proposer mysql par defaut si dispo
373
+                $checked = ($s == 'mysql' ? " checked='checked'" : '');
374
+                $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
375
+                    . "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
376
+            } else {
377
+                spip_log("$s: portage indisponible");
378
+            }
379
+        }
380
+    }
381
+    sort($options);
382
+
383
+    return $options;
384 384
 }
385 385
 
386 386
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) {
387
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
388
-
389
-	return generer_form_ecrire('install', (
390
-		"\n<input type='hidden' name='etape' value='$etape' />"
391
-		. $hidden
392
-		. (_request('echec') ?
393
-			('<p><b>' . _T('avis_connexion_echec_1') .
394
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
-			: '')
396
-
397
-		. ($jquery ? http_script('', 'jquery.js') : '')
398
-		. http_script('
387
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
388
+
389
+    return generer_form_ecrire('install', (
390
+        "\n<input type='hidden' name='etape' value='$etape' />"
391
+        . $hidden
392
+        . (_request('echec') ?
393
+            ('<p><b>' . _T('avis_connexion_echec_1') .
394
+                '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
+            : '')
396
+
397
+        . ($jquery ? http_script('', 'jquery.js') : '')
398
+        . http_script('
399 399
 		jQuery(function($) {
400 400
 			$details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur");
401 401
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -428,145 +428,145 @@  discard block
 block discarded – undo
428 428
 			});
429 429
 		});')
430 430
 
431
-		. ($server_db
432
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
-			. (($predef[0])
434
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
-				: '')
436
-			: ('<fieldset><legend>'
437
-				. _T('install_select_type_db')
438
-				. '</legend>'
439
-				. '<p class="explication">'
440
-				. _T('install_types_db_connus')
441
-				// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
-				// . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
-				. '</p>'
444
-				. "\n<div class='p'>\n<ul>\n"
445
-				. join("\n", install_select_serveur())
446
-				. "\n</ul>\n</div></fieldset>")
447
-		)
448
-		. '<div id="install_adresse_base_hebergeur">'
449
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
450
-		. ($predef[1]
451
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
-			: fieldset(
453
-				_T('entree_base_donnee_1'),
454
-				[
455
-					'adresse_db' => [
456
-						'label' => $db[1],
457
-						'valeur' => $db[0]
458
-					],
459
-				]
460
-			)
461
-		)
462
-		. '</div>'
463
-
464
-		. '<div id="install_login_base_hebergeur">'
465
-		. ($predef[2]
466
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
-			: fieldset(
468
-				_T('entree_login_connexion_1'),
469
-				[
470
-					'login_db' => [
471
-						'label' => $login[1],
472
-						'valeur' => $login[0]
473
-					],
474
-				]
475
-			)
476
-		)
477
-		. '</div>'
478
-
479
-		. '<div id="install_pass_base_hebergeur">'
480
-		. ($predef[3]
481
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
-			: fieldset(
483
-				_T('entree_mot_passe_1'),
484
-				[
485
-					'pass_db' => [
486
-						'label' => $pass[1],
487
-						'valeur' => $pass[0]
488
-					],
489
-				]
490
-			)
491
-		)
492
-		. '</div>'
493
-
494
-		. bouton_suivant()));
431
+        . ($server_db
432
+            ? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
+            . (($predef[0])
434
+                ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
+                : '')
436
+            : ('<fieldset><legend>'
437
+                . _T('install_select_type_db')
438
+                . '</legend>'
439
+                . '<p class="explication">'
440
+                . _T('install_types_db_connus')
441
+                // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
+                // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
+                . '</p>'
444
+                . "\n<div class='p'>\n<ul>\n"
445
+                . join("\n", install_select_serveur())
446
+                . "\n</ul>\n</div></fieldset>")
447
+        )
448
+        . '<div id="install_adresse_base_hebergeur">'
449
+        . '<p>' . _T('texte_connexion_mysql') . '</p>'
450
+        . ($predef[1]
451
+            ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
+            : fieldset(
453
+                _T('entree_base_donnee_1'),
454
+                [
455
+                    'adresse_db' => [
456
+                        'label' => $db[1],
457
+                        'valeur' => $db[0]
458
+                    ],
459
+                ]
460
+            )
461
+        )
462
+        . '</div>'
463
+
464
+        . '<div id="install_login_base_hebergeur">'
465
+        . ($predef[2]
466
+            ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
+            : fieldset(
468
+                _T('entree_login_connexion_1'),
469
+                [
470
+                    'login_db' => [
471
+                        'label' => $login[1],
472
+                        'valeur' => $login[0]
473
+                    ],
474
+                ]
475
+            )
476
+        )
477
+        . '</div>'
478
+
479
+        . '<div id="install_pass_base_hebergeur">'
480
+        . ($predef[3]
481
+            ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
+            : fieldset(
483
+                _T('entree_mot_passe_1'),
484
+                [
485
+                    'pass_db' => [
486
+                        'label' => $pass[1],
487
+                        'valeur' => $pass[0]
488
+                    ],
489
+                ]
490
+            )
491
+        )
492
+        . '</div>'
493
+
494
+        . bouton_suivant()));
495 495
 }
496 496
 
497 497
 // 4 valeurs qu'on reconduit d'un script a l'autre
498 498
 // sauf s'ils sont predefinis.
499 499
 
500 500
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
501
-	return ((defined('_INSTALL_HOST_DB'))
502
-		? ''
503
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
504
-	)
505
-	. ((defined('_INSTALL_USER_DB'))
506
-		? ''
507
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
508
-	)
509
-	. ((defined('_INSTALL_PASS_DB'))
510
-		? ''
511
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
512
-	)
513
-
514
-	. ((defined('_INSTALL_SERVER_DB'))
515
-		? ''
516
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
517
-	);
501
+    return ((defined('_INSTALL_HOST_DB'))
502
+        ? ''
503
+        : "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
504
+    )
505
+    . ((defined('_INSTALL_USER_DB'))
506
+        ? ''
507
+        : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
508
+    )
509
+    . ((defined('_INSTALL_PASS_DB'))
510
+        ? ''
511
+        : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
512
+    )
513
+
514
+    . ((defined('_INSTALL_SERVER_DB'))
515
+        ? ''
516
+        : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
517
+    );
518 518
 }
519 519
 
520 520
 // presentation des bases existantes
521 521
 
522 522
 function install_etape_liste_bases($server_db, $login_db, $disabled = []) {
523
-	$bases = $checked = [];
524
-	$noms = sql_listdbs($server_db);
525
-	if (!$noms) {
526
-		return '';
527
-	}
528
-
529
-	foreach ($noms as $nom) {
530
-		$id = spip_htmlspecialchars($nom);
531
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
532
-		$base = ' name="choix_db" value="'
533
-			. $nom
534
-			. '"'
535
-			. $dis
536
-			. " type='radio' id='$id'";
537
-		$label = "<label for='$id'>"
538
-			. ($dis ? "<i>$nom</i>" : $nom)
539
-			. '</label>';
540
-
541
-		if (
542
-			!$checked and !$dis and
543
-			(($nom == $login_db) or
544
-				($GLOBALS['table_prefix'] == $nom))
545
-		) {
546
-			$checked = "<input$base checked='checked' />\n$label";
547
-		} else {
548
-			$bases[] = "<input$base />\n$label";
549
-		}
550
-	}
551
-
552
-	if (!$bases && !$checked) {
553
-		return false;
554
-	}
555
-
556
-	if ($checked) {
557
-		array_unshift($bases, $checked);
558
-		$checked = true;
559
-	}
560
-
561
-	return [$checked, $bases];
523
+    $bases = $checked = [];
524
+    $noms = sql_listdbs($server_db);
525
+    if (!$noms) {
526
+        return '';
527
+    }
528
+
529
+    foreach ($noms as $nom) {
530
+        $id = spip_htmlspecialchars($nom);
531
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
532
+        $base = ' name="choix_db" value="'
533
+            . $nom
534
+            . '"'
535
+            . $dis
536
+            . " type='radio' id='$id'";
537
+        $label = "<label for='$id'>"
538
+            . ($dis ? "<i>$nom</i>" : $nom)
539
+            . '</label>';
540
+
541
+        if (
542
+            !$checked and !$dis and
543
+            (($nom == $login_db) or
544
+                ($GLOBALS['table_prefix'] == $nom))
545
+        ) {
546
+            $checked = "<input$base checked='checked' />\n$label";
547
+        } else {
548
+            $bases[] = "<input$base />\n$label";
549
+        }
550
+    }
551
+
552
+    if (!$bases && !$checked) {
553
+        return false;
554
+    }
555
+
556
+    if ($checked) {
557
+        array_unshift($bases, $checked);
558
+        $checked = true;
559
+    }
560
+
561
+    return [$checked, $bases];
562 562
 }
563 563
 
564 564
 function install_propager($hidden) {
565
-	$res = '';
566
-	foreach ($hidden as $k) {
567
-		$v = spip_htmlentities(_request($k));
568
-		$res .= "<input type='hidden' name='$k' value='$v' />";
569
-	}
565
+    $res = '';
566
+    foreach ($hidden as $k) {
567
+        $v = spip_htmlentities(_request($k));
568
+        $res .= "<input type='hidden' name='$k' value='$v' />";
569
+    }
570 570
 
571
-	return $res;
571
+    return $res;
572 572
 }
Please login to merge, or discard this patch.
ecrire/action/editer_rubrique.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			$id_rubrique,
151 151
 			[
152 152
 			'data' => $set,
153
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
153
+			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique').' '._T('info_numero_abbreviation').$id_rubrique]
154 154
 			],
155 155
 			$c
156 156
 		)
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 				)
255 255
 			) {
256 256
 				if ($s['statut'] != 'prepa') {
257
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
257
+					spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']);
258 258
 				}
259 259
 			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260 260
 				$statut_ancien = $s['statut'];
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Rubriques\Edition
17 17
  */
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/rubriques');
@@ -38,34 +38,34 @@  discard block
 block discarded – undo
38 38
  */
39 39
 function action_editer_rubrique_dist($arg = null) {
40 40
 
41
-	if (is_null($arg)) {
42
-		$securiser_action = charger_fonction('securiser_action', 'inc');
43
-		$arg = $securiser_action();
44
-	}
45
-
46
-	if (!$id_rubrique = intval($arg)) {
47
-		if ($arg != 'oui') {
48
-			include_spip('inc/headers');
49
-			redirige_url_ecrire();
50
-		}
51
-		$id_rubrique = rubrique_inserer(_request('id_parent'));
52
-	}
53
-
54
-	$err = rubrique_modifier($id_rubrique);
55
-
56
-	if (_request('redirect')) {
57
-		$redirect = parametre_url(
58
-			urldecode(_request('redirect')),
59
-			'id_rubrique',
60
-			$id_rubrique,
61
-			'&'
62
-		);
63
-
64
-		include_spip('inc/headers');
65
-		redirige_par_entete($redirect);
66
-	}
67
-
68
-	return [$id_rubrique, $err];
41
+    if (is_null($arg)) {
42
+        $securiser_action = charger_fonction('securiser_action', 'inc');
43
+        $arg = $securiser_action();
44
+    }
45
+
46
+    if (!$id_rubrique = intval($arg)) {
47
+        if ($arg != 'oui') {
48
+            include_spip('inc/headers');
49
+            redirige_url_ecrire();
50
+        }
51
+        $id_rubrique = rubrique_inserer(_request('id_parent'));
52
+    }
53
+
54
+    $err = rubrique_modifier($id_rubrique);
55
+
56
+    if (_request('redirect')) {
57
+        $redirect = parametre_url(
58
+            urldecode(_request('redirect')),
59
+            'id_rubrique',
60
+            $id_rubrique,
61
+            '&'
62
+        );
63
+
64
+        include_spip('inc/headers');
65
+        redirige_par_entete($redirect);
66
+    }
67
+
68
+    return [$id_rubrique, $err];
69 69
 }
70 70
 
71 71
 
@@ -80,42 +80,42 @@  discard block
 block discarded – undo
80 80
  *     Identifiant de la rubrique crée
81 81
  */
82 82
 function rubrique_inserer($id_parent, $set = null) {
83
-	$champs = [
84
-		'titre' => _T('item_nouvelle_rubrique'),
85
-		'id_parent' => intval($id_parent),
86
-		'statut' => 'prepa'
87
-	];
88
-
89
-	if ($set) {
90
-		$champs = array_merge($champs, $set);
91
-	}
92
-
93
-	// Envoyer aux plugins
94
-	$champs = pipeline(
95
-		'pre_insertion',
96
-		[
97
-			'args' => [
98
-				'table' => 'spip_rubriques',
99
-			],
100
-			'data' => $champs
101
-		]
102
-	);
103
-
104
-	$id_rubrique = sql_insertq('spip_rubriques', $champs);
105
-	pipeline(
106
-		'post_insertion',
107
-		[
108
-			'args' => [
109
-				'table' => 'spip_rubriques',
110
-				'id_objet' => $id_rubrique
111
-			],
112
-			'data' => $champs
113
-		]
114
-	);
115
-	propager_les_secteurs();
116
-	calculer_langues_rubriques();
117
-
118
-	return $id_rubrique;
83
+    $champs = [
84
+        'titre' => _T('item_nouvelle_rubrique'),
85
+        'id_parent' => intval($id_parent),
86
+        'statut' => 'prepa'
87
+    ];
88
+
89
+    if ($set) {
90
+        $champs = array_merge($champs, $set);
91
+    }
92
+
93
+    // Envoyer aux plugins
94
+    $champs = pipeline(
95
+        'pre_insertion',
96
+        [
97
+            'args' => [
98
+                'table' => 'spip_rubriques',
99
+            ],
100
+            'data' => $champs
101
+        ]
102
+    );
103
+
104
+    $id_rubrique = sql_insertq('spip_rubriques', $champs);
105
+    pipeline(
106
+        'post_insertion',
107
+        [
108
+            'args' => [
109
+                'table' => 'spip_rubriques',
110
+                'id_objet' => $id_rubrique
111
+            ],
112
+            'data' => $champs
113
+        ]
114
+    );
115
+    propager_les_secteurs();
116
+    calculer_langues_rubriques();
117
+
118
+    return $id_rubrique;
119 119
 }
120 120
 
121 121
 /**
@@ -131,46 +131,46 @@  discard block
 block discarded – undo
131 131
  *     - chaîne : texte d'un message d'erreur
132 132
  */
133 133
 function rubrique_modifier($id_rubrique, $set = null) {
134
-	include_spip('inc/autoriser');
135
-	include_spip('inc/filtres');
136
-
137
-	include_spip('inc/modifier');
138
-	$c = collecter_requests(
139
-		// include list
140
-		objet_info('rubrique', 'champs_editables'),
141
-		// exclude list
142
-		['id_parent', 'confirme_deplace'],
143
-		// donnees eventuellement fournies
144
-		$set
145
-	);
146
-
147
-	if (
148
-		$err = objet_modifier_champs(
149
-			'rubrique',
150
-			$id_rubrique,
151
-			[
152
-			'data' => $set,
153
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
154
-			],
155
-			$c
156
-		)
157
-	) {
158
-		return $err;
159
-	}
160
-
161
-	$c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
162
-	// Deplacer la rubrique
163
-	if (isset($c['id_parent'])) {
164
-		$err = rubrique_instituer($id_rubrique, $c);
165
-	}
166
-
167
-	// invalider les caches marques de cette rubrique
168
-	include_spip('inc/invalideur');
169
-	suivre_invalideur("id='rubrique/$id_rubrique'");
170
-	// et celui de menu_rubriques
171
-	effacer_meta('date_calcul_rubriques');
172
-
173
-	return $err;
134
+    include_spip('inc/autoriser');
135
+    include_spip('inc/filtres');
136
+
137
+    include_spip('inc/modifier');
138
+    $c = collecter_requests(
139
+        // include list
140
+        objet_info('rubrique', 'champs_editables'),
141
+        // exclude list
142
+        ['id_parent', 'confirme_deplace'],
143
+        // donnees eventuellement fournies
144
+        $set
145
+    );
146
+
147
+    if (
148
+        $err = objet_modifier_champs(
149
+            'rubrique',
150
+            $id_rubrique,
151
+            [
152
+            'data' => $set,
153
+            'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
154
+            ],
155
+            $c
156
+        )
157
+    ) {
158
+        return $err;
159
+    }
160
+
161
+    $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
162
+    // Deplacer la rubrique
163
+    if (isset($c['id_parent'])) {
164
+        $err = rubrique_instituer($id_rubrique, $c);
165
+    }
166
+
167
+    // invalider les caches marques de cette rubrique
168
+    include_spip('inc/invalideur');
169
+    suivre_invalideur("id='rubrique/$id_rubrique'");
170
+    // et celui de menu_rubriques
171
+    effacer_meta('date_calcul_rubriques');
172
+
173
+    return $err;
174 174
 }
175 175
 
176 176
 /**
@@ -193,25 +193,25 @@  discard block
 block discarded – undo
193 193
  *     false si la confirmation du déplacement n'est pas présente
194 194
  */
195 195
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) {
196
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
197
-		return true;
198
-	}
199
-
200
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
201
-		return false;
202
-	}
203
-
204
-	if (
205
-		$id_secteur = sql_getfetsel(
206
-			'id_secteur',
207
-			'spip_rubriques',
208
-			"id_rubrique=$id_parent"
209
-		)
210
-	) {
211
-		sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
212
-	}
213
-
214
-	return true;
196
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
197
+        return true;
198
+    }
199
+
200
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
201
+        return false;
202
+    }
203
+
204
+    if (
205
+        $id_secteur = sql_getfetsel(
206
+            'id_secteur',
207
+            'spip_rubriques',
208
+            "id_rubrique=$id_parent"
209
+        )
210
+    ) {
211
+        sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
212
+    }
213
+
214
+    return true;
215 215
 }
216 216
 
217 217
 
@@ -233,50 +233,50 @@  discard block
 block discarded – undo
233 233
  *     Chaîne : texte du message d'erreur
234 234
  */
235 235
 function rubrique_instituer($id_rubrique, $c) {
236
-	// traitement de la rubrique parente
237
-	// interdiction de deplacer vers ou a partir d'une rubrique
238
-	// qu'on n'administre pas.
239
-
240
-	if (null !== ($id_parent = $c['id_parent'])) {
241
-		$id_parent = intval($id_parent);
242
-		$filles = calcul_branche_in($id_rubrique);
243
-		if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
244
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
245
-		} else {
246
-			$s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
247
-			$old_parent = $s['id_parent'];
248
-
249
-			if (
250
-				!($id_parent != $old_parent
251
-				and autoriser('publierdans', 'rubrique', $id_parent)
252
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
253
-				and autoriser('publierdans', 'rubrique', $old_parent)
254
-				)
255
-			) {
256
-				if ($s['statut'] != 'prepa') {
257
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
258
-				}
259
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260
-				$statut_ancien = $s['statut'];
261
-				sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
262
-
263
-
264
-				propager_les_secteurs();
265
-
266
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
267
-				if ($statut_ancien == 'publie') {
268
-					calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
269
-				}
270
-				// Creation ou deplacement d'une rubrique non publiee
271
-				// invalider le cache de leur menu
272
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
273
-					effacer_meta('date_calcul_rubriques');
274
-				}
275
-
276
-				calculer_langues_rubriques();
277
-			}
278
-		}
279
-	}
280
-
281
-	return ''; // pas d'erreur
236
+    // traitement de la rubrique parente
237
+    // interdiction de deplacer vers ou a partir d'une rubrique
238
+    // qu'on n'administre pas.
239
+
240
+    if (null !== ($id_parent = $c['id_parent'])) {
241
+        $id_parent = intval($id_parent);
242
+        $filles = calcul_branche_in($id_rubrique);
243
+        if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
244
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
245
+        } else {
246
+            $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
247
+            $old_parent = $s['id_parent'];
248
+
249
+            if (
250
+                !($id_parent != $old_parent
251
+                and autoriser('publierdans', 'rubrique', $id_parent)
252
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
253
+                and autoriser('publierdans', 'rubrique', $old_parent)
254
+                )
255
+            ) {
256
+                if ($s['statut'] != 'prepa') {
257
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
258
+                }
259
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260
+                $statut_ancien = $s['statut'];
261
+                sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
262
+
263
+
264
+                propager_les_secteurs();
265
+
266
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
267
+                if ($statut_ancien == 'publie') {
268
+                    calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
269
+                }
270
+                // Creation ou deplacement d'une rubrique non publiee
271
+                // invalider le cache de leur menu
272
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
273
+                    effacer_meta('date_calcul_rubriques');
274
+                }
275
+
276
+                calculer_langues_rubriques();
277
+            }
278
+        }
279
+    }
280
+
281
+    return ''; // pas d'erreur
282 282
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 function extraire_date($texte): string {
40 40
 	// format = 2001-08
41 41
 	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
+		return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01';
43 43
 	}
44 44
 	return '';
45 45
 }
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 		}
71 71
 		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72 72
 			$regs = array_pad($regs, 4, null); // eviter notice php
73
-			$date = $regs[1] . '-00-00' . $regs[3];
73
+			$date = $regs[1].'-00-00'.$regs[3];
74 74
 		} else {
75 75
 			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76 76
 				$regs = array_pad($regs, 4, null); // eviter notice php
77
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
77
+				$date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3];
78 78
 			} else {
79 79
 				$date = date('Y-m-d H:i:s', strtotime($date));
80 80
 			}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	$letexte ??= '';
102 102
 	if (
103 103
 		!$verif_format_date
104
-		or (in_array(strlen($letexte), [10,19]) and
104
+		or (in_array(strlen($letexte), [10, 19]) and
105 105
 			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106 106
 	) {
107 107
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
@@ -388,17 +388,17 @@  discard block
 block discarded – undo
388 388
 	if ($decal > 3600 * 24 * 30) {
389 389
 		$mois = floor($decal / (3600 * 24 * 30));
390 390
 		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
391
+			$delai = "$mois "._T('date_un_mois');
392 392
 		} else {
393
-			$delai = "$mois " . _T('date_mois');
393
+			$delai = "$mois "._T('date_mois');
394 394
 		}
395 395
 	} else {
396 396
 		if ($decal > 3600 * 24 * 7) {
397 397
 			$semaines = floor($decal / (3600 * 24 * 7));
398 398
 			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
399
+				$delai = "$semaines "._T('date_une_semaine');
400 400
 			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
401
+				$delai = "$semaines "._T('date_semaines');
402 402
 			}
403 403
 		} else {
404 404
 			if ($decal > 3600 * 24) {
@@ -406,30 +406,30 @@  discard block
 block discarded – undo
406 406
 				if ($jours < 2) {
407 407
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408 408
 				} else {
409
-					$delai = "$jours " . _T('date_jours');
409
+					$delai = "$jours "._T('date_jours');
410 410
 				}
411 411
 			} else {
412 412
 				if ($decal >= 3600) {
413 413
 					$heures = floor($decal / 3600);
414 414
 					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
415
+						$delai = "$heures "._T('date_une_heure');
416 416
 					} else {
417
-						$delai = "$heures " . _T('date_heures');
417
+						$delai = "$heures "._T('date_heures');
418 418
 					}
419 419
 				} else {
420 420
 					if ($decal >= 60) {
421 421
 						$minutes = floor($decal / 60);
422 422
 						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
423
+							$delai = "$minutes "._T('date_une_minute');
424 424
 						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
425
+							$delai = "$minutes "._T('date_minutes');
426 426
 						}
427 427
 					} else {
428 428
 						$secondes = ceil($decal);
429 429
 						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
430
+							$delai = "$secondes "._T('date_une_seconde');
431 431
 						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
432
+							$delai = "$secondes "._T('date_secondes');
433 433
 						}
434 434
 					}
435 435
 				}
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$njour = 0;
523 523
 	} else {
524 524
 		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
525
+		if ($jourth = _T('date_jnum'.$jour)) {
526 526
 			$jour = $jourth;
527 527
 		}
528 528
 	}
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
 	$mois = intval($mois);
531 531
 	if ($mois > 0 and $mois < 13) {
532 532
 		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
533
+		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : '');
534
+		$nommois = _T('date_mois_'.$mois.$param);
535 535
 		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
536
+			$jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]);
537 537
 		} else {
538 538
 			$jourmois = $nommois;
539 539
 		}
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 	}
544 544
 
545 545
 	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
546
+		$annee = -$annee.' '._T('date_avant_jc');
547 547
 		$avjc = true;
548 548
 	} else {
549 549
 		$avjc = false;
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 				}
570 570
 			}
571 571
 			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
572
+				return $saison ? _T('date_saison_'.$saison) : '';
573 573
 			} else {
574 574
 				return $saison ? trim(_T(
575 575
 					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
576
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
577 577
 				)) : '';
578 578
 			}
579 579
 
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 			}
651 651
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652 652
 			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
653
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
654 654
 
655
-			return _T('date_jour_' . $nom . $param);
655
+			return _T('date_jour_'.$nom.$param);
656 656
 
657 657
 		case 'mois_annee':
658 658
 			if ($avjc) {
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 	$dtstart = $dtend = $dtabbr = '';
1049 1049
 	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1050
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1051
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1052 1052
 		$dtabbr = '</abbr>';
1053 1053
 	}
1054 1054
 
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 			}
1097 1097
 		} else {
1098 1098
 			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1099
+				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1100 1100
 			} else {
1101 1101
 				$s = spip_ucfirst($s);
1102 1102
 			}
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120 1120
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121 1121
 			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1122
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1123
+			$date_fin = $dtend.$date_fin.$dtabbr;
1124 1124
 
1125 1125
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126 1126
 		} else {
@@ -1137,8 +1137,8 @@  discard block
 block discarded – undo
1137 1137
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138 1138
 			}
1139 1139
 
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1140
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1141
+			$date_fin = $dtend.$date_fin.$dtabbr;
1142 1142
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143 1143
 		}
1144 1144
 	}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 		$d = date('Y-m-d');
1243 1243
 	}
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 		$d = date('Y-m-d');
1263 1263
 	}
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+	return substr($d, 0, 4).substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
Please login to merge, or discard this patch.
Indentation   +580 added lines, -580 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
  *    Date au format SQL tel que `2008-04-01` sinon ''
38 38
  **/
39 39
 function extraire_date($texte): string {
40
-	// format = 2001-08
41
-	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
43
-	}
44
-	return '';
40
+    // format = 2001-08
41
+    if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
+        return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
43
+    }
44
+    return '';
45 45
 }
46 46
 
47 47
 
@@ -63,29 +63,29 @@  discard block
 block discarded – undo
63 63
  *     - une chaîne vide si la date est considérée nulle
64 64
  **/
65 65
 function normaliser_date($date, $forcer_jour = false): string {
66
-	$date = vider_date($date);
67
-	if ($date) {
68
-		if (preg_match('/^[0-9]{8,10}$/', $date)) {
69
-			$date = date('Y-m-d H:i:s', $date);
70
-		}
71
-		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72
-			$regs = array_pad($regs, 4, null); // eviter notice php
73
-			$date = $regs[1] . '-00-00' . $regs[3];
74
-		} else {
75
-			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76
-				$regs = array_pad($regs, 4, null); // eviter notice php
77
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
78
-			} else {
79
-				$date = date('Y-m-d H:i:s', strtotime($date));
80
-			}
81
-		}
82
-
83
-		if ($forcer_jour) {
84
-			$date = str_replace('-00', '-01', $date);
85
-		}
86
-	}
87
-
88
-	return $date;
66
+    $date = vider_date($date);
67
+    if ($date) {
68
+        if (preg_match('/^[0-9]{8,10}$/', $date)) {
69
+            $date = date('Y-m-d H:i:s', $date);
70
+        }
71
+        if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72
+            $regs = array_pad($regs, 4, null); // eviter notice php
73
+            $date = $regs[1] . '-00-00' . $regs[3];
74
+        } else {
75
+            if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76
+                $regs = array_pad($regs, 4, null); // eviter notice php
77
+                $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
78
+            } else {
79
+                $date = date('Y-m-d H:i:s', strtotime($date));
80
+            }
81
+        }
82
+
83
+        if ($forcer_jour) {
84
+            $date = str_replace('-00', '-01', $date);
85
+        }
86
+    }
87
+
88
+    return $date;
89 89
 }
90 90
 
91 91
 /**
@@ -98,23 +98,23 @@  discard block
 block discarded – undo
98 98
  *     - Une chaine vide
99 99
  **/
100 100
 function vider_date($letexte, $verif_format_date = false): string {
101
-	$letexte ??= '';
102
-	if (
103
-		!$verif_format_date
104
-		or (in_array(strlen($letexte), [10,19]) and
105
-			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106
-	) {
107
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
108
-			return '';
109
-		}
110
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
111
-			return '';
112
-		}
113
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
114
-			return '';
115
-		}  // eviter le bug GMT-1
116
-	}
117
-	return $letexte;
101
+    $letexte ??= '';
102
+    if (
103
+        !$verif_format_date
104
+        or (in_array(strlen($letexte), [10,19]) and
105
+              preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106
+    ) {
107
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
108
+            return '';
109
+        }
110
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
111
+            return '';
112
+        }
113
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
114
+            return '';
115
+        }  // eviter le bug GMT-1
116
+    }
117
+    return $letexte;
118 118
 }
119 119
 
120 120
 /**
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
  **/
131 131
 function recup_heure($date): array {
132 132
 
133
-	static $d = [0, 0, 0];
134
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
-		return $d;
136
-	}
133
+    static $d = [0, 0, 0];
134
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
+        return $d;
136
+    }
137 137
 
138
-	array_shift($r);
138
+    array_shift($r);
139 139
 
140
-	return $r;
140
+    return $r;
141 141
 }
142 142
 
143 143
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * @return string heures, sinon 0
152 152
  **/
153 153
 function heures($numdate): string {
154
-	$heures = null;
155
-	$date_array = recup_heure($numdate);
156
-	if ($date_array) {
157
-		[$heures, $minutes, $secondes] = $date_array;
158
-	}
154
+    $heures = null;
155
+    $date_array = recup_heure($numdate);
156
+    if ($date_array) {
157
+        [$heures, $minutes, $secondes] = $date_array;
158
+    }
159 159
 
160
-	return $heures;
160
+    return $heures;
161 161
 }
162 162
 
163 163
 /**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
  * @return string minutes, sinon 0
172 172
  **/
173 173
 function minutes($numdate): string {
174
-	$minutes = null;
175
-	$date_array = recup_heure($numdate);
176
-	if ($date_array) {
177
-		[$heures, $minutes, $secondes] = $date_array;
178
-	}
174
+    $minutes = null;
175
+    $date_array = recup_heure($numdate);
176
+    if ($date_array) {
177
+        [$heures, $minutes, $secondes] = $date_array;
178
+    }
179 179
 
180
-	return $minutes;
180
+    return $minutes;
181 181
 }
182 182
 
183 183
 /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @return string secondes, sinon 0
192 192
  **/
193 193
 function secondes($numdate): string {
194
-	$secondes = null;
195
-	$date_array = recup_heure($numdate);
196
-	if ($date_array) {
197
-		[$heures, $minutes, $secondes] = $date_array;
198
-	}
194
+    $secondes = null;
195
+    $date_array = recup_heure($numdate);
196
+    if ($date_array) {
197
+        [$heures, $minutes, $secondes] = $date_array;
198
+    }
199 199
 
200
-	return $secondes;
200
+    return $secondes;
201 201
 }
202 202
 
203 203
 /**
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
  * @return string L'heure formatée dans la langue en cours.
217 217
  **/
218 218
 function heures_minutes($numdate, $forme = ''): string {
219
-	if ($forme !== 'abbr') {
220
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
-	} else {
222
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
-	}
219
+    if ($forme !== 'abbr') {
220
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
+    } else {
222
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
+    }
224 224
 }
225 225
 
226 226
 /**
@@ -245,57 +245,57 @@  discard block
 block discarded – undo
245 245
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
246 246
  **/
247 247
 function recup_date($numdate, $forcer_jour = true): array {
248
-	if (!$numdate) {
249
-		return [];
250
-	}
251
-	$heures = $minutes = $secondes = 0;
252
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
-		$jour = $regs[1];
254
-		$mois = $regs[2];
255
-		$annee = $regs[3];
256
-		if ($annee < 90) {
257
-			$annee = 2000 + $annee;
258
-		} elseif ($annee < 100) {
259
-			$annee = 1900 + $annee;
260
-		}
261
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
262
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
-		$annee = $regs[1];
264
-		$mois = $regs[2];
265
-		$jour = $regs[3];
266
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
267
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
-		$annee = $regs[1];
269
-		$mois = $regs[2];
270
-		$jour = '';
271
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
272
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
-		$annee = $regs[1];
274
-		$mois = $regs[2];
275
-		$jour = $regs[3];
276
-		$heures = $regs[4];
277
-		$minutes = $regs[5];
278
-		$secondes = $regs[6];
279
-	} else {
280
-		$annee = $mois = $jour = '';
281
-	}
282
-	if ($annee > 4000) {
283
-		$annee -= 9000;
284
-	}
285
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
-		$jour = substr($jour, 1);
287
-	}
288
-
289
-	if ($forcer_jour and $jour == '0') {
290
-		$jour = '1';
291
-	}
292
-	if ($forcer_jour and $mois == '0') {
293
-		$mois = '1';
294
-	}
295
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
-	}
298
-	return [];
248
+    if (!$numdate) {
249
+        return [];
250
+    }
251
+    $heures = $minutes = $secondes = 0;
252
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
+        $jour = $regs[1];
254
+        $mois = $regs[2];
255
+        $annee = $regs[3];
256
+        if ($annee < 90) {
257
+            $annee = 2000 + $annee;
258
+        } elseif ($annee < 100) {
259
+            $annee = 1900 + $annee;
260
+        }
261
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
262
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
+        $annee = $regs[1];
264
+        $mois = $regs[2];
265
+        $jour = $regs[3];
266
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
267
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
+        $annee = $regs[1];
269
+        $mois = $regs[2];
270
+        $jour = '';
271
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
272
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
+        $annee = $regs[1];
274
+        $mois = $regs[2];
275
+        $jour = $regs[3];
276
+        $heures = $regs[4];
277
+        $minutes = $regs[5];
278
+        $secondes = $regs[6];
279
+    } else {
280
+        $annee = $mois = $jour = '';
281
+    }
282
+    if ($annee > 4000) {
283
+        $annee -= 9000;
284
+    }
285
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
+        $jour = substr($jour, 1);
287
+    }
288
+
289
+    if ($forcer_jour and $jour == '0') {
290
+        $jour = '1';
291
+    }
292
+    if ($forcer_jour and $mois == '0') {
293
+        $mois = '1';
294
+    }
295
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
+    }
298
+    return [];
299 299
 }
300 300
 
301 301
 /**
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
  *     La date relative ou complète
323 323
  **/
324 324
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
325
-	return sinon(
326
-		date_relative($date, $decalage_maxi),
327
-		affdate_heure($date)
328
-	);
325
+    return sinon(
326
+        date_relative($date, $decalage_maxi),
327
+        affdate_heure($date)
328
+    );
329 329
 }
330 330
 
331 331
 /**
@@ -358,86 +358,86 @@  discard block
 block discarded – undo
358 358
  **/
359 359
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
360 360
 
361
-	if (!$date) {
362
-		return '';
363
-	}
364
-
365
-	if (is_null($ref_date)) {
366
-		$ref_time = time();
367
-	} else {
368
-		$ref_time = strtotime($ref_date);
369
-	}
370
-
371
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
372
-
373
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
-		return '';
375
-	}
376
-
377
-	if ($decal < 0) {
378
-		$il_y_a = 'date_dans';
379
-		$decal = -1 * $decal;
380
-	} else {
381
-		$il_y_a = 'date_il_y_a';
382
-	}
383
-
384
-	if ($decal > 3600 * 24 * 30 * 6) {
385
-		return affdate_court($date);
386
-	}
387
-
388
-	if ($decal > 3600 * 24 * 30) {
389
-		$mois = floor($decal / (3600 * 24 * 30));
390
-		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
392
-		} else {
393
-			$delai = "$mois " . _T('date_mois');
394
-		}
395
-	} else {
396
-		if ($decal > 3600 * 24 * 7) {
397
-			$semaines = floor($decal / (3600 * 24 * 7));
398
-			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
400
-			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
402
-			}
403
-		} else {
404
-			if ($decal > 3600 * 24) {
405
-				$jours = floor($decal / (3600 * 24));
406
-				if ($jours < 2) {
407
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
-				} else {
409
-					$delai = "$jours " . _T('date_jours');
410
-				}
411
-			} else {
412
-				if ($decal >= 3600) {
413
-					$heures = floor($decal / 3600);
414
-					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
416
-					} else {
417
-						$delai = "$heures " . _T('date_heures');
418
-					}
419
-				} else {
420
-					if ($decal >= 60) {
421
-						$minutes = floor($decal / 60);
422
-						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
424
-						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
426
-						}
427
-					} else {
428
-						$secondes = ceil($decal);
429
-						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
431
-						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
433
-						}
434
-					}
435
-				}
436
-			}
437
-		}
438
-	}
439
-
440
-	return _T($il_y_a, ['delai' => $delai]);
361
+    if (!$date) {
362
+        return '';
363
+    }
364
+
365
+    if (is_null($ref_date)) {
366
+        $ref_time = time();
367
+    } else {
368
+        $ref_time = strtotime($ref_date);
369
+    }
370
+
371
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
372
+
373
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
+        return '';
375
+    }
376
+
377
+    if ($decal < 0) {
378
+        $il_y_a = 'date_dans';
379
+        $decal = -1 * $decal;
380
+    } else {
381
+        $il_y_a = 'date_il_y_a';
382
+    }
383
+
384
+    if ($decal > 3600 * 24 * 30 * 6) {
385
+        return affdate_court($date);
386
+    }
387
+
388
+    if ($decal > 3600 * 24 * 30) {
389
+        $mois = floor($decal / (3600 * 24 * 30));
390
+        if ($mois < 2) {
391
+            $delai = "$mois " . _T('date_un_mois');
392
+        } else {
393
+            $delai = "$mois " . _T('date_mois');
394
+        }
395
+    } else {
396
+        if ($decal > 3600 * 24 * 7) {
397
+            $semaines = floor($decal / (3600 * 24 * 7));
398
+            if ($semaines < 2) {
399
+                $delai = "$semaines " . _T('date_une_semaine');
400
+            } else {
401
+                $delai = "$semaines " . _T('date_semaines');
402
+            }
403
+        } else {
404
+            if ($decal > 3600 * 24) {
405
+                $jours = floor($decal / (3600 * 24));
406
+                if ($jours < 2) {
407
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
+                } else {
409
+                    $delai = "$jours " . _T('date_jours');
410
+                }
411
+            } else {
412
+                if ($decal >= 3600) {
413
+                    $heures = floor($decal / 3600);
414
+                    if ($heures < 2) {
415
+                        $delai = "$heures " . _T('date_une_heure');
416
+                    } else {
417
+                        $delai = "$heures " . _T('date_heures');
418
+                    }
419
+                } else {
420
+                    if ($decal >= 60) {
421
+                        $minutes = floor($decal / 60);
422
+                        if ($minutes < 2) {
423
+                            $delai = "$minutes " . _T('date_une_minute');
424
+                        } else {
425
+                            $delai = "$minutes " . _T('date_minutes');
426
+                        }
427
+                    } else {
428
+                        $secondes = ceil($decal);
429
+                        if ($secondes < 2) {
430
+                            $delai = "$secondes " . _T('date_une_seconde');
431
+                        } else {
432
+                            $delai = "$secondes " . _T('date_secondes');
433
+                        }
434
+                    }
435
+                }
436
+            }
437
+        }
438
+    }
439
+
440
+    return _T($il_y_a, ['delai' => $delai]);
441 441
 }
442 442
 
443 443
 
@@ -463,32 +463,32 @@  discard block
 block discarded – undo
463 463
  **/
464 464
 function date_relativecourt($date, $decalage_maxi = 0): string {
465 465
 
466
-	if (!$date) {
467
-		return '';
468
-	}
469
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
-
471
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
-		return '';
473
-	}
474
-
475
-	if ($decal < -24 * 3600) {
476
-		$retour = date_relative($date, $decalage_maxi);
477
-	} elseif ($decal < 0) {
478
-		$retour = _T('date_demain');
479
-	} else {
480
-		if ($decal < (3600 * 24)) {
481
-			$retour = _T('date_aujourdhui');
482
-		} else {
483
-			if ($decal < (3600 * 24 * 2)) {
484
-				$retour = _T('date_hier');
485
-			} else {
486
-				$retour = date_relative($date, $decalage_maxi);
487
-			}
488
-		}
489
-	}
490
-
491
-	return $retour;
466
+    if (!$date) {
467
+        return '';
468
+    }
469
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
+
471
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
+        return '';
473
+    }
474
+
475
+    if ($decal < -24 * 3600) {
476
+        $retour = date_relative($date, $decalage_maxi);
477
+    } elseif ($decal < 0) {
478
+        $retour = _T('date_demain');
479
+    } else {
480
+        if ($decal < (3600 * 24)) {
481
+            $retour = _T('date_aujourdhui');
482
+        } else {
483
+            if ($decal < (3600 * 24 * 2)) {
484
+                $retour = _T('date_hier');
485
+            } else {
486
+                $retour = date_relative($date, $decalage_maxi);
487
+            }
488
+        }
489
+    }
490
+
491
+    return $retour;
492 492
 }
493 493
 
494 494
 /**
@@ -505,174 +505,174 @@  discard block
 block discarded – undo
505 505
  * @return string
506 506
  */
507 507
 function affdate_base($numdate, $vue, $options = []): string {
508
-	if (is_string($options)) {
509
-		$options = ['param' => $options];
510
-	}
511
-	$date_array = recup_date($numdate, false);
512
-	if (!$date_array) {
513
-		return '';
514
-	}
515
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
-
517
-	// 1er, 21st, etc.
518
-	$journum = $jour;
519
-
520
-	if ($jour == 0) {
521
-		$jour = '';
522
-		$njour = 0;
523
-	} else {
524
-		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
526
-			$jour = $jourth;
527
-		}
528
-	}
529
-
530
-	$mois = intval($mois);
531
-	if ($mois > 0 and $mois < 13) {
532
-		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
535
-		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
-		} else {
538
-			$jourmois = $nommois;
539
-		}
540
-	} else {
541
-		$nommois = '';
542
-		$jourmois = '';
543
-	}
544
-
545
-	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
547
-		$avjc = true;
548
-	} else {
549
-		$avjc = false;
550
-	}
551
-
552
-	switch ($vue) {
553
-		case 'saison':
554
-		case 'saison_annee':
555
-			$saison = '';
556
-			if ($mois > 0) {
557
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
558
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
560
-				}
561
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
563
-				}
564
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
566
-				}
567
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
569
-				}
570
-			}
571
-			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
573
-			} else {
574
-				return $saison ? trim(_T(
575
-					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
-				)) : '';
578
-			}
579
-
580
-		case 'court':
581
-			if ($avjc) {
582
-				return $annee;
583
-			}
584
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
-				return $annee;
587
-			}
588
-			if ($annee != $a) {
589
-				return _T(
590
-					'date_fmt_mois_annee',
591
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
-				);
593
-			}
594
-
595
-			return _T(
596
-				'date_fmt_jour_mois',
597
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
-			);
599
-
600
-		case 'jourcourt':
601
-			if ($avjc) {
602
-				return $annee;
603
-			}
604
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
-				return $annee;
607
-			}
608
-			if ($annee != $a) {
609
-				return _T(
610
-					'date_fmt_jour_mois_annee',
611
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
-				);
613
-			}
614
-
615
-			return _T(
616
-				'date_fmt_jour_mois',
617
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
-			);
619
-
620
-		case 'entier':
621
-			if ($avjc) {
622
-				return $annee;
623
-			}
624
-			if ($jour) {
625
-				return _T(
626
-					'date_fmt_jour_mois_annee',
627
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
-				);
629
-			} elseif ($mois) {
630
-				return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
-			} else {
632
-				return $annee;
633
-			}
634
-
635
-		case 'nom_mois':
636
-			return $nommois;
637
-
638
-		case 'mois':
639
-			return sprintf('%02s', $mois);
640
-
641
-		case 'jour':
642
-			return $jour;
643
-
644
-		case 'journum':
645
-			return $journum;
646
-
647
-		case 'nom_jour':
648
-			if (!$mois or !$njour) {
649
-				return '';
650
-			}
651
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
-			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
-
655
-			return _T('date_jour_' . $nom . $param);
656
-
657
-		case 'mois_annee':
658
-			if ($avjc) {
659
-				return $annee;
660
-			}
661
-
662
-			return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
-
664
-		case 'annee':
665
-			return $annee;
666
-
667
-		// Cas d'une vue non definie : retomber sur le format
668
-		// de date propose par http://www.php.net/date
669
-		default:
670
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
-				$time = strtotime($numdate);
673
-			}
674
-			return date($vue, $time);
675
-	}
508
+    if (is_string($options)) {
509
+        $options = ['param' => $options];
510
+    }
511
+    $date_array = recup_date($numdate, false);
512
+    if (!$date_array) {
513
+        return '';
514
+    }
515
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
+
517
+    // 1er, 21st, etc.
518
+    $journum = $jour;
519
+
520
+    if ($jour == 0) {
521
+        $jour = '';
522
+        $njour = 0;
523
+    } else {
524
+        $njour = intval($jour);
525
+        if ($jourth = _T('date_jnum' . $jour)) {
526
+            $jour = $jourth;
527
+        }
528
+    }
529
+
530
+    $mois = intval($mois);
531
+    if ($mois > 0 and $mois < 13) {
532
+        /* Traiter le cas "abbr" pour les noms de mois */
533
+        $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
+        $nommois = _T('date_mois_' . $mois . $param);
535
+        if ($jour) {
536
+            $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
+        } else {
538
+            $jourmois = $nommois;
539
+        }
540
+    } else {
541
+        $nommois = '';
542
+        $jourmois = '';
543
+    }
544
+
545
+    if ($annee < 0) {
546
+        $annee = -$annee . ' ' . _T('date_avant_jc');
547
+        $avjc = true;
548
+    } else {
549
+        $avjc = false;
550
+    }
551
+
552
+    switch ($vue) {
553
+        case 'saison':
554
+        case 'saison_annee':
555
+            $saison = '';
556
+            if ($mois > 0) {
557
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
558
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
560
+                }
561
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
563
+                }
564
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
566
+                }
567
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
569
+                }
570
+            }
571
+            if ($vue == 'saison') {
572
+                return $saison ? _T('date_saison_' . $saison) : '';
573
+            } else {
574
+                return $saison ? trim(_T(
575
+                    'date_fmt_saison_annee',
576
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
+                )) : '';
578
+            }
579
+
580
+        case 'court':
581
+            if ($avjc) {
582
+                return $annee;
583
+            }
584
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
+                return $annee;
587
+            }
588
+            if ($annee != $a) {
589
+                return _T(
590
+                    'date_fmt_mois_annee',
591
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
+                );
593
+            }
594
+
595
+            return _T(
596
+                'date_fmt_jour_mois',
597
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
+            );
599
+
600
+        case 'jourcourt':
601
+            if ($avjc) {
602
+                return $annee;
603
+            }
604
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
+                return $annee;
607
+            }
608
+            if ($annee != $a) {
609
+                return _T(
610
+                    'date_fmt_jour_mois_annee',
611
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
+                );
613
+            }
614
+
615
+            return _T(
616
+                'date_fmt_jour_mois',
617
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
+            );
619
+
620
+        case 'entier':
621
+            if ($avjc) {
622
+                return $annee;
623
+            }
624
+            if ($jour) {
625
+                return _T(
626
+                    'date_fmt_jour_mois_annee',
627
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
+                );
629
+            } elseif ($mois) {
630
+                return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
+            } else {
632
+                return $annee;
633
+            }
634
+
635
+        case 'nom_mois':
636
+            return $nommois;
637
+
638
+        case 'mois':
639
+            return sprintf('%02s', $mois);
640
+
641
+        case 'jour':
642
+            return $jour;
643
+
644
+        case 'journum':
645
+            return $journum;
646
+
647
+        case 'nom_jour':
648
+            if (!$mois or !$njour) {
649
+                return '';
650
+            }
651
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
+            $nom = 1 + (int) date('w', $nom);
653
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
+
655
+            return _T('date_jour_' . $nom . $param);
656
+
657
+        case 'mois_annee':
658
+            if ($avjc) {
659
+                return $annee;
660
+            }
661
+
662
+            return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
+
664
+        case 'annee':
665
+            return $annee;
666
+
667
+        // Cas d'une vue non definie : retomber sur le format
668
+        // de date propose par http://www.php.net/date
669
+        default:
670
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
+                $time = strtotime($numdate);
673
+            }
674
+            return date($vue, $time);
675
+    }
676 676
 }
677 677
 
678 678
 
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
699 699
  *     Nom du jour
700 700
  **/
701 701
 function nom_jour($numdate, $forme = ''): string {
702
-	if (!($forme === 'abbr' or $forme === 'initiale')) {
703
-		$forme = '';
704
-	}
702
+    if (!($forme === 'abbr' or $forme === 'initiale')) {
703
+        $forme = '';
704
+    }
705 705
 
706
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
706
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
707 707
 }
708 708
 
709 709
 /**
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
  *     Numéro du jour
726 726
  **/
727 727
 function jour($numdate): string {
728
-	return affdate_base($numdate, 'jour');
728
+    return affdate_base($numdate, 'jour');
729 729
 }
730 730
 
731 731
 /**
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
  *     Numéro du jour
744 744
  **/
745 745
 function journum($numdate): string {
746
-	return affdate_base($numdate, 'journum');
746
+    return affdate_base($numdate, 'journum');
747 747
 }
748 748
 
749 749
 /**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
  *     Numéro du mois (sur 2 chiffres)
762 762
  **/
763 763
 function mois($numdate): string {
764
-	return  affdate_base($numdate, 'mois');
764
+    return  affdate_base($numdate, 'mois');
765 765
 }
766 766
 
767 767
 /**
@@ -785,11 +785,11 @@  discard block
 block discarded – undo
785 785
  *     Nom du mois
786 786
  **/
787 787
 function nom_mois($numdate, $forme = ''): string {
788
-	if (!($forme === 'abbr')) {
789
-		$forme = '';
790
-	}
788
+    if (!($forme === 'abbr')) {
789
+        $forme = '';
790
+    }
791 791
 
792
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
792
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
793 793
 }
794 794
 
795 795
 /**
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
  *     Année (sur 4 chiffres)
808 808
  **/
809 809
 function annee($numdate): string {
810
-	return affdate_base($numdate, 'annee');
810
+    return affdate_base($numdate, 'annee');
811 811
 }
812 812
 
813 813
 
@@ -837,11 +837,11 @@  discard block
 block discarded – undo
837 837
  *     La date formatée
838 838
  **/
839 839
 function saison($numdate, $hemisphere = 'nord'): string {
840
-	if ($hemisphere !== 'sud') {
841
-		$hemisphere = 'nord';
842
-	}
840
+    if ($hemisphere !== 'sud') {
841
+        $hemisphere = 'nord';
842
+    }
843 843
 
844
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
844
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
845 845
 }
846 846
 
847 847
 
@@ -870,11 +870,11 @@  discard block
 block discarded – undo
870 870
  *     La date formatée
871 871
  **/
872 872
 function saison_annee($numdate, $hemisphere = 'nord'): string {
873
-	if ($hemisphere !== 'sud') {
874
-		$hemisphere = 'nord';
875
-	}
873
+    if ($hemisphere !== 'sud') {
874
+        $hemisphere = 'nord';
875
+    }
876 876
 
877
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
877
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
878 878
 }
879 879
 
880 880
 /**
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
  *     La date formatée
903 903
  **/
904 904
 function affdate($numdate, $format = 'entier'): string {
905
-	return affdate_base($numdate, $format);
905
+    return affdate_base($numdate, $format);
906 906
 }
907 907
 
908 908
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  *     La date formatée
930 930
  **/
931 931
 function affdate_court($numdate, $annee_courante = null): string {
932
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
932
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
933 933
 }
934 934
 
935 935
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *     La date formatée
957 957
  **/
958 958
 function affdate_jourcourt($numdate, $annee_courante = null): string {
959
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
959
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
960 960
 }
961 961
 
962 962
 /**
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  *     La date formatée
975 975
  **/
976 976
 function affdate_mois_annee($numdate): string {
977
-	return affdate_base($numdate, 'mois_annee');
977
+    return affdate_base($numdate, 'mois_annee');
978 978
 }
979 979
 
980 980
 /**
@@ -992,16 +992,16 @@  discard block
 block discarded – undo
992 992
  *     La date formatée, sinon ''
993 993
  **/
994 994
 function affdate_heure($numdate): string {
995
-	$date_array = recup_date($numdate);
996
-	if (!$date_array) {
997
-		return '';
998
-	}
999
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
-
1001
-	return _T('date_fmt_jour_heure', [
1002
-		'jour' => affdate($numdate),
1003
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
-	]);
995
+    $date_array = recup_date($numdate);
996
+    if (!$date_array) {
997
+        return '';
998
+    }
999
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
+
1001
+    return _T('date_fmt_jour_heure', [
1002
+        'jour' => affdate($numdate),
1003
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
+    ]);
1005 1005
 }
1006 1006
 
1007 1007
 /**
@@ -1033,117 +1033,117 @@  discard block
 block discarded – undo
1033 1033
  *     texte de la date
1034 1034
  */
1035 1035
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
1036
-	$abbr = $jour = '';
1037
-	$affdate = 'affdate_jourcourt';
1038
-	if (strpos($forme, 'abbr') !== false) {
1039
-		$abbr = 'abbr';
1040
-	}
1041
-	if (strpos($forme, 'annee') !== false) {
1042
-		$affdate = 'affdate';
1043
-	}
1044
-	if (strpos($forme, 'jour') !== false) {
1045
-		$jour = 'jour';
1046
-	}
1047
-
1048
-	$dtstart = $dtend = $dtabbr = '';
1049
-	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
-		$dtabbr = '</abbr>';
1053
-	}
1054
-
1055
-	$date_debut = strtotime($date_debut);
1056
-	$date_fin = strtotime($date_fin);
1057
-	$d = date('Y-m-d', $date_debut);
1058
-	$f = date('Y-m-d', $date_fin);
1059
-	$h = ($horaire === 'oui' or $horaire === true);
1060
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
-
1063
-	if ($d == $f) { // meme jour
1064
-		$nomjour = nom_jour($d, $abbr);
1065
-		$s = $affdate($d);
1066
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
-		if ($h) {
1068
-			if ($hd == $hf) {
1069
-				// Lundi 20 fevrier a 18h25
1070
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
-				$s = "$dtstart$s$dtabbr";
1072
-			} else {
1073
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
-				if ($dtabbr && $dtstart && $dtend) {
1075
-					$s = _T(
1076
-						'date_fmt_jour_heure_debut_fin_abbr',
1077
-						[
1078
-						'jour' => spip_ucfirst($s),
1079
-						'heure_debut' => $hd,
1080
-						'heure_fin' => $hf,
1081
-						'dtstart' => $dtstart,
1082
-						'dtend' => $dtend,
1083
-						'dtabbr' => $dtabbr
1084
-						],
1085
-						[
1086
-							'sanitize' => false
1087
-						]
1088
-					);
1089
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1090
-				else {
1091
-					$s = spip_ucfirst(_T(
1092
-						'date_fmt_jour_heure_debut_fin',
1093
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
-					));
1095
-				}
1096
-			}
1097
-		} else {
1098
-			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
-			} else {
1101
-				$s = spip_ucfirst($s);
1102
-			}
1103
-		}
1104
-	} else {
1105
-		if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
-			if (!$h) {
1107
-				$date_debut = jour($d);
1108
-			} else {
1109
-				$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
-			}
1111
-			$date_fin = $affdate($f);
1112
-			if ($jour) {
1113
-				$nomjour_debut = nom_jour($d, $abbr);
1114
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
-				$nomjour_fin = nom_jour($f, $abbr);
1116
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
-			}
1118
-			if ($h) {
1119
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
-			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1124
-
1125
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
-		} else {
1127
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
-			$date_fin = $affdate($f);
1129
-			if ($jour) {
1130
-				$nomjour_debut = nom_jour($d, $abbr);
1131
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
-				$nomjour_fin = nom_jour($f, $abbr);
1133
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
-			}
1135
-			if ($h) {
1136
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
-			}
1139
-
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1142
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
-		}
1144
-	}
1145
-
1146
-	return $s;
1036
+    $abbr = $jour = '';
1037
+    $affdate = 'affdate_jourcourt';
1038
+    if (strpos($forme, 'abbr') !== false) {
1039
+        $abbr = 'abbr';
1040
+    }
1041
+    if (strpos($forme, 'annee') !== false) {
1042
+        $affdate = 'affdate';
1043
+    }
1044
+    if (strpos($forme, 'jour') !== false) {
1045
+        $jour = 'jour';
1046
+    }
1047
+
1048
+    $dtstart = $dtend = $dtabbr = '';
1049
+    if (strpos($forme, 'hcal') !== false) {
1050
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
+        $dtabbr = '</abbr>';
1053
+    }
1054
+
1055
+    $date_debut = strtotime($date_debut);
1056
+    $date_fin = strtotime($date_fin);
1057
+    $d = date('Y-m-d', $date_debut);
1058
+    $f = date('Y-m-d', $date_fin);
1059
+    $h = ($horaire === 'oui' or $horaire === true);
1060
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
+
1063
+    if ($d == $f) { // meme jour
1064
+        $nomjour = nom_jour($d, $abbr);
1065
+        $s = $affdate($d);
1066
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
+        if ($h) {
1068
+            if ($hd == $hf) {
1069
+                // Lundi 20 fevrier a 18h25
1070
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
+                $s = "$dtstart$s$dtabbr";
1072
+            } else {
1073
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
+                if ($dtabbr && $dtstart && $dtend) {
1075
+                    $s = _T(
1076
+                        'date_fmt_jour_heure_debut_fin_abbr',
1077
+                        [
1078
+                        'jour' => spip_ucfirst($s),
1079
+                        'heure_debut' => $hd,
1080
+                        'heure_fin' => $hf,
1081
+                        'dtstart' => $dtstart,
1082
+                        'dtend' => $dtend,
1083
+                        'dtabbr' => $dtabbr
1084
+                        ],
1085
+                        [
1086
+                            'sanitize' => false
1087
+                        ]
1088
+                    );
1089
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1090
+                else {
1091
+                    $s = spip_ucfirst(_T(
1092
+                        'date_fmt_jour_heure_debut_fin',
1093
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
+                    ));
1095
+                }
1096
+            }
1097
+        } else {
1098
+            if ($dtabbr && $dtstart) {
1099
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
+            } else {
1101
+                $s = spip_ucfirst($s);
1102
+            }
1103
+        }
1104
+    } else {
1105
+        if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
+            if (!$h) {
1107
+                $date_debut = jour($d);
1108
+            } else {
1109
+                $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
+            }
1111
+            $date_fin = $affdate($f);
1112
+            if ($jour) {
1113
+                $nomjour_debut = nom_jour($d, $abbr);
1114
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
+                $nomjour_fin = nom_jour($f, $abbr);
1116
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
+            }
1118
+            if ($h) {
1119
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
+            }
1122
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1123
+            $date_fin = $dtend . $date_fin . $dtabbr;
1124
+
1125
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
+        } else {
1127
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
+            $date_fin = $affdate($f);
1129
+            if ($jour) {
1130
+                $nomjour_debut = nom_jour($d, $abbr);
1131
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
+                $nomjour_fin = nom_jour($f, $abbr);
1133
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
+            }
1135
+            if ($h) {
1136
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
+            }
1139
+
1140
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1141
+            $date_fin = $dtend . $date_fin . $dtabbr;
1142
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
+        }
1144
+    }
1145
+
1146
+    return $s;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1164,10 +1164,10 @@  discard block
 block discarded – undo
1164 1164
  *     Date au format ical
1165 1165
  **/
1166 1166
 function date_ical($date, $addminutes = 0): string {
1167
-	[$heures, $minutes, $secondes] = recup_heure($date);
1168
-	[$annee, $mois, $jour] = recup_date($date);
1167
+    [$heures, $minutes, $secondes] = recup_heure($date);
1168
+    [$annee, $mois, $jour] = recup_date($date);
1169 1169
 
1170
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1170
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1171 1171
 }
1172 1172
 
1173 1173
 
@@ -1191,11 +1191,11 @@  discard block
 block discarded – undo
1191 1191
  *     La date formatée
1192 1192
  **/
1193 1193
 function date_iso($date_heure): string {
1194
-	[$annee, $mois, $jour] = recup_date($date_heure);
1195
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1194
+    [$annee, $mois, $jour] = recup_date($date_heure);
1195
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1197 1197
 
1198
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1198
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1199 1199
 }
1200 1200
 
1201 1201
 /**
@@ -1218,11 +1218,11 @@  discard block
 block discarded – undo
1218 1218
  *     La date formatée
1219 1219
  **/
1220 1220
 function date_822($date_heure): string {
1221
-	[$annee, $mois, $jour] = recup_date($date_heure);
1222
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1221
+    [$annee, $mois, $jour] = recup_date($date_heure);
1222
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1224 1224
 
1225
-	return date('r', $time);
1225
+    return date('r', $time);
1226 1226
 }
1227 1227
 
1228 1228
 /**
@@ -1238,11 +1238,11 @@  discard block
 block discarded – undo
1238 1238
  *     Date au format `Ymd`
1239 1239
  **/
1240 1240
 function date_anneemoisjour($d): string {
1241
-	if (!$d) {
1242
-		$d = date('Y-m-d');
1243
-	}
1241
+    if (!$d) {
1242
+        $d = date('Y-m-d');
1243
+    }
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
  *     Date au format `Ym`
1259 1259
  **/
1260 1260
 function date_anneemois($d): string {
1261
-	if (!$d) {
1262
-		$d = date('Y-m-d');
1263
-	}
1261
+    if (!$d) {
1262
+        $d = date('Y-m-d');
1263
+    }
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+    return substr($d, 0, 4) . substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
@@ -1278,13 +1278,13 @@  discard block
 block discarded – undo
1278 1278
  *     Date au lundi de la même semaine au format `Ymd`
1279 1279
  **/
1280 1280
 function date_debut_semaine($annee, $mois, $jour): string {
1281
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
-	if ($w_day == 0) {
1283
-		$w_day = 7;
1284
-	} // Gaffe: le dimanche est zero
1285
-	$debut = $jour - $w_day + 1;
1281
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
+    if ($w_day == 0) {
1283
+        $w_day = 7;
1284
+    } // Gaffe: le dimanche est zero
1285
+    $debut = $jour - $w_day + 1;
1286 1286
 
1287
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1287
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1288 1288
 }
1289 1289
 
1290 1290
 /**
@@ -1300,11 +1300,11 @@  discard block
 block discarded – undo
1300 1300
  *     Date au dimanche de la même semaine au format `Ymd`
1301 1301
  **/
1302 1302
 function date_fin_semaine($annee, $mois, $jour): string {
1303
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
-	if ($w_day == 0) {
1305
-		$w_day = 7;
1306
-	} // Gaffe: le dimanche est zero
1307
-	$debut = $jour - $w_day + 1;
1303
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
+    if ($w_day == 0) {
1305
+        $w_day = 7;
1306
+    } // Gaffe: le dimanche est zero
1307
+    $debut = $jour - $w_day + 1;
1308 1308
 
1309
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1309
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1310 1310
 }
Please login to merge, or discard this patch.
prive/formulaires/editer_article.php 1 patch
Indentation   +96 added lines, -96 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
 include_spip('inc/actions');
@@ -46,33 +46,33 @@  discard block
 block discarded – undo
46 46
  *     Environnement du formulaire
47 47
  **/
48 48
 function formulaires_editer_article_charger_dist(
49
-	$id_article = 'new',
50
-	$id_rubrique = 0,
51
-	$retour = '',
52
-	$lier_trad = 0,
53
-	$config_fonc = 'articles_edit_config',
54
-	$row = [],
55
-	$hidden = ''
49
+    $id_article = 'new',
50
+    $id_rubrique = 0,
51
+    $retour = '',
52
+    $lier_trad = 0,
53
+    $config_fonc = 'articles_edit_config',
54
+    $row = [],
55
+    $hidden = ''
56 56
 ) {
57
-	$valeurs = formulaires_editer_objet_charger(
58
-		'article',
59
-		$id_article,
60
-		$id_rubrique,
61
-		$lier_trad,
62
-		$retour,
63
-		$config_fonc,
64
-		$row,
65
-		$hidden
66
-	);
57
+    $valeurs = formulaires_editer_objet_charger(
58
+        'article',
59
+        $id_article,
60
+        $id_rubrique,
61
+        $lier_trad,
62
+        $retour,
63
+        $config_fonc,
64
+        $row,
65
+        $hidden
66
+    );
67 67
 
68
-	if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) {
69
-		$valeurs['editable'] = '';
70
-	}
68
+    if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) {
69
+        $valeurs['editable'] = '';
70
+    }
71 71
 
72
-	// il faut enlever l'id_rubrique car la saisie se fait sur id_parent
73
-	// et id_rubrique peut etre passe dans l'url comme rubrique parent initiale
74
-	// et sera perdue si elle est supposee saisie
75
-	return $valeurs;
72
+    // il faut enlever l'id_rubrique car la saisie se fait sur id_parent
73
+    // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale
74
+    // et sera perdue si elle est supposee saisie
75
+    return $valeurs;
76 76
 }
77 77
 
78 78
 /**
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
  *     Hash du formulaire
98 98
  */
99 99
 function formulaires_editer_article_identifier_dist(
100
-	$id_article = 'new',
101
-	$id_rubrique = 0,
102
-	$retour = '',
103
-	$lier_trad = 0,
104
-	$config_fonc = 'articles_edit_config',
105
-	$row = [],
106
-	$hidden = ''
100
+    $id_article = 'new',
101
+    $id_rubrique = 0,
102
+    $retour = '',
103
+    $lier_trad = 0,
104
+    $config_fonc = 'articles_edit_config',
105
+    $row = [],
106
+    $hidden = ''
107 107
 ) {
108
-	return serialize([intval($id_article), $lier_trad]);
108
+    return serialize([intval($id_article), $lier_trad]);
109 109
 }
110 110
 
111 111
 /**
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
  */
119 119
 function articles_edit_config(array $row): array {
120 120
 
121
-	$config = [];
122
-	$config['lignes'] = 8;
123
-	$config['langue'] = $GLOBALS['spip_lang'];
124
-	$config['restreint'] = ($row['statut'] === 'publie');
121
+    $config = [];
122
+    $config['lignes'] = 8;
123
+    $config['langue'] = $GLOBALS['spip_lang'];
124
+    $config['restreint'] = ($row['statut'] === 'publie');
125 125
 
126
-	return $config;
126
+    return $config;
127 127
 }
128 128
 
129 129
 /**
@@ -149,43 +149,43 @@  discard block
 block discarded – undo
149 149
  *     Erreurs du formulaire
150 150
  **/
151 151
 function formulaires_editer_article_verifier_dist(
152
-	$id_article = 'new',
153
-	$id_rubrique = 0,
154
-	$retour = '',
155
-	$lier_trad = 0,
156
-	$config_fonc = 'articles_edit_config',
157
-	$row = [],
158
-	$hidden = ''
152
+    $id_article = 'new',
153
+    $id_rubrique = 0,
154
+    $retour = '',
155
+    $lier_trad = 0,
156
+    $config_fonc = 'articles_edit_config',
157
+    $row = [],
158
+    $hidden = ''
159 159
 ) {
160
-	// auto-renseigner le titre si il n'existe pas
161
-	titre_automatique('titre', ['descriptif', 'chapo', 'texte']);
162
-	if (!_request('id_parent') and !intval($id_article)) {
163
-		$valeurs = formulaires_editer_objet_charger(
164
-			'article',
165
-			$id_article,
166
-			$id_rubrique,
167
-			$lier_trad,
168
-			$retour,
169
-			$config_fonc,
170
-			$row,
171
-			$hidden
172
-		);
173
-		set_request('id_parent', $valeurs['id_parent']);
174
-	}
175
-	// on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide
176
-	$erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']);
177
-	// si on utilise le formulaire dans le public
178
-	if (!function_exists('autoriser')) {
179
-		include_spip('inc/autoriser');
180
-	}
181
-	if (
182
-		!isset($erreurs['id_parent'])
183
-		and !autoriser('creerarticledans', 'rubrique', _request('id_parent'))
184
-	) {
185
-		$erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise');
186
-	}
160
+    // auto-renseigner le titre si il n'existe pas
161
+    titre_automatique('titre', ['descriptif', 'chapo', 'texte']);
162
+    if (!_request('id_parent') and !intval($id_article)) {
163
+        $valeurs = formulaires_editer_objet_charger(
164
+            'article',
165
+            $id_article,
166
+            $id_rubrique,
167
+            $lier_trad,
168
+            $retour,
169
+            $config_fonc,
170
+            $row,
171
+            $hidden
172
+        );
173
+        set_request('id_parent', $valeurs['id_parent']);
174
+    }
175
+    // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide
176
+    $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']);
177
+    // si on utilise le formulaire dans le public
178
+    if (!function_exists('autoriser')) {
179
+        include_spip('inc/autoriser');
180
+    }
181
+    if (
182
+        !isset($erreurs['id_parent'])
183
+        and !autoriser('creerarticledans', 'rubrique', _request('id_parent'))
184
+    ) {
185
+        $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise');
186
+    }
187 187
 
188
-	return $erreurs;
188
+    return $erreurs;
189 189
 }
190 190
 
191 191
 /**
@@ -211,29 +211,29 @@  discard block
 block discarded – undo
211 211
  *     Retours des traitements
212 212
  **/
213 213
 function formulaires_editer_article_traiter_dist(
214
-	$id_article = 'new',
215
-	$id_rubrique = 0,
216
-	$retour = '',
217
-	$lier_trad = 0,
218
-	$config_fonc = 'articles_edit_config',
219
-	$row = [],
220
-	$hidden = ''
214
+    $id_article = 'new',
215
+    $id_rubrique = 0,
216
+    $retour = '',
217
+    $lier_trad = 0,
218
+    $config_fonc = 'articles_edit_config',
219
+    $row = [],
220
+    $hidden = ''
221 221
 ) {
222
-	// ici on ignore changer_lang qui est poste en cas de trad,
223
-	// car l'heuristique du choix de la langue est pris en charge par article_inserer
224
-	// en fonction de la config du site et de la rubrique choisie
225
-	if (!$lier_trad) {
226
-		set_request('changer_lang');
227
-	}
222
+    // ici on ignore changer_lang qui est poste en cas de trad,
223
+    // car l'heuristique du choix de la langue est pris en charge par article_inserer
224
+    // en fonction de la config du site et de la rubrique choisie
225
+    if (!$lier_trad) {
226
+        set_request('changer_lang');
227
+    }
228 228
 
229
-	return formulaires_editer_objet_traiter(
230
-		'article',
231
-		$id_article,
232
-		$id_rubrique,
233
-		$lier_trad,
234
-		$retour,
235
-		$config_fonc,
236
-		$row,
237
-		$hidden
238
-	);
229
+    return formulaires_editer_objet_traiter(
230
+        'article',
231
+        $id_article,
232
+        $id_rubrique,
233
+        $lier_trad,
234
+        $retour,
235
+        $config_fonc,
236
+        $row,
237
+        $hidden
238
+    );
239 239
 }
Please login to merge, or discard this patch.
prive/formulaires/editer_rubrique.php 1 patch
Indentation   +81 added lines, -81 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
 include_spip('inc/actions');
@@ -47,30 +47,30 @@  discard block
 block discarded – undo
47 47
  *     Environnement du formulaire
48 48
  **/
49 49
 function formulaires_editer_rubrique_charger_dist(
50
-	$id_rubrique = 'new',
51
-	$id_parent = 0,
52
-	$retour = '',
53
-	$lier_trad = 0,
54
-	$config_fonc = 'rubriques_edit_config',
55
-	$row = [],
56
-	$hidden = ''
50
+    $id_rubrique = 'new',
51
+    $id_parent = 0,
52
+    $retour = '',
53
+    $lier_trad = 0,
54
+    $config_fonc = 'rubriques_edit_config',
55
+    $row = [],
56
+    $hidden = ''
57 57
 ) {
58
-	$valeurs = formulaires_editer_objet_charger(
59
-		'rubrique',
60
-		$id_rubrique,
61
-		$id_parent,
62
-		$lier_trad,
63
-		$retour,
64
-		$config_fonc,
65
-		$row,
66
-		$hidden
67
-	);
68
-
69
-	if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) {
70
-		$valeurs['editable'] = '';
71
-	}
72
-
73
-	return $valeurs;
58
+    $valeurs = formulaires_editer_objet_charger(
59
+        'rubrique',
60
+        $id_rubrique,
61
+        $id_parent,
62
+        $lier_trad,
63
+        $retour,
64
+        $config_fonc,
65
+        $row,
66
+        $hidden
67
+    );
68
+
69
+    if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) {
70
+        $valeurs['editable'] = '';
71
+    }
72
+
73
+    return $valeurs;
74 74
 }
75 75
 
76 76
 /**
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
  */
84 84
 function rubriques_edit_config(array $row): array {
85 85
 
86
-	$config = [];
87
-	$config['lignes'] = 8;
88
-	$config['langue'] = $GLOBALS['spip_lang'];
89
-	$config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']);
86
+    $config = [];
87
+    $config['lignes'] = 8;
88
+    $config['langue'] = $GLOBALS['spip_lang'];
89
+    $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']);
90 90
 
91
-	return $config;
91
+    return $config;
92 92
 }
93 93
 
94 94
 /**
@@ -113,15 +113,15 @@  discard block
 block discarded – undo
113 113
  *     Hash du formulaire
114 114
  */
115 115
 function formulaires_editer_rubrique_identifier_dist(
116
-	$id_rubrique = 'new',
117
-	$id_parent = 0,
118
-	$retour = '',
119
-	$lier_trad = 0,
120
-	$config_fonc = 'rubriques_edit_config',
121
-	$row = [],
122
-	$hidden = ''
116
+    $id_rubrique = 'new',
117
+    $id_parent = 0,
118
+    $retour = '',
119
+    $lier_trad = 0,
120
+    $config_fonc = 'rubriques_edit_config',
121
+    $row = [],
122
+    $hidden = ''
123 123
 ) {
124
-	return serialize([intval($id_rubrique), $lier_trad]);
124
+    return serialize([intval($id_rubrique), $lier_trad]);
125 125
 }
126 126
 
127 127
 /**
@@ -147,34 +147,34 @@  discard block
 block discarded – undo
147 147
  *     Erreurs du formulaire
148 148
  **/
149 149
 function formulaires_editer_rubrique_verifier_dist(
150
-	$id_rubrique = 'new',
151
-	$id_parent = 0,
152
-	$retour = '',
153
-	$lier_trad = 0,
154
-	$config_fonc = 'rubriques_edit_config',
155
-	$row = [],
156
-	$hidden = ''
150
+    $id_rubrique = 'new',
151
+    $id_parent = 0,
152
+    $retour = '',
153
+    $lier_trad = 0,
154
+    $config_fonc = 'rubriques_edit_config',
155
+    $row = [],
156
+    $hidden = ''
157 157
 ) {
158
-	// auto-renseigner le titre si il n'existe pas
159
-	titre_automatique('titre', ['descriptif', 'texte']);
160
-	// on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide
161
-	$erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []);
162
-
163
-	// s'assurer qu'on ne s'auto-designe pas comme parent !
164
-	if (
165
-		intval($id_rubrique)
166
-		and empty($erreurs['id_parent'])
167
-		and $id_parent = _request('id_parent')
168
-	) {
169
-		include_spip('inc/rubriques');
170
-		$branche = calcul_branche_in($id_rubrique);
171
-		$branche = explode(',', $branche);
172
-		if (in_array($id_parent, $branche)) {
173
-			$erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !');
174
-		}
175
-	}
176
-
177
-	return $erreurs;
158
+    // auto-renseigner le titre si il n'existe pas
159
+    titre_automatique('titre', ['descriptif', 'texte']);
160
+    // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide
161
+    $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []);
162
+
163
+    // s'assurer qu'on ne s'auto-designe pas comme parent !
164
+    if (
165
+        intval($id_rubrique)
166
+        and empty($erreurs['id_parent'])
167
+        and $id_parent = _request('id_parent')
168
+    ) {
169
+        include_spip('inc/rubriques');
170
+        $branche = calcul_branche_in($id_rubrique);
171
+        $branche = explode(',', $branche);
172
+        if (in_array($id_parent, $branche)) {
173
+            $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !');
174
+        }
175
+    }
176
+
177
+    return $erreurs;
178 178
 }
179 179
 
180 180
 /**
@@ -200,22 +200,22 @@  discard block
 block discarded – undo
200 200
  *     Retour des traitements
201 201
  **/
202 202
 function formulaires_editer_rubrique_traiter_dist(
203
-	$id_rubrique = 'new',
204
-	$id_parent = 0,
205
-	$retour = '',
206
-	$lier_trad = 0,
207
-	$config_fonc = 'rubriques_edit_config',
208
-	$row = [],
209
-	$hidden = ''
203
+    $id_rubrique = 'new',
204
+    $id_parent = 0,
205
+    $retour = '',
206
+    $lier_trad = 0,
207
+    $config_fonc = 'rubriques_edit_config',
208
+    $row = [],
209
+    $hidden = ''
210 210
 ) {
211
-	return formulaires_editer_objet_traiter(
212
-		'rubrique',
213
-		$id_rubrique,
214
-		$id_parent,
215
-		$lier_trad,
216
-		$retour,
217
-		$config_fonc,
218
-		$row,
219
-		$hidden
220
-	);
211
+    return formulaires_editer_objet_traiter(
212
+        'rubrique',
213
+        $id_rubrique,
214
+        $id_parent,
215
+        $lier_trad,
216
+        $retour,
217
+        $config_fonc,
218
+        $row,
219
+        $hidden
220
+    );
221 221
 }
Please login to merge, or discard this patch.
ecrire/inc/acces.php 2 patches
Indentation   +234 added lines, -234 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,46 +31,46 @@  discard block
 block discarded – undo
31 31
  *     Mot de passe
32 32
  **/
33 33
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
34
-	$seed = (int)round(((float)microtime() + 1) * time());
35
-
36
-	mt_srand($seed);
37
-	$s = '';
38
-	$pass = '';
39
-	for ($i = 0; $i < $longueur; $i++) {
40
-		if (!$s) {
41
-			$s = random_int(0, mt_getrandmax());
42
-			if (!$s) {
43
-				$s = random_int(0, mt_getrandmax());
44
-			}
45
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
46
-		}
47
-		$r = unpack('Cr', pack('H2', $s . $s));
48
-		$x = $r['r'] & 63;
49
-		if ($x < 10) {
50
-			$x = chr($x + 48);
51
-		} else {
52
-			if ($x < 36) {
53
-				$x = chr($x + 55);
54
-			} else {
55
-				if ($x < 62) {
56
-					$x = chr($x + 61);
57
-				} else {
58
-					if ($x == 63) {
59
-						$x = '/';
60
-					} else {
61
-						$x = '.';
62
-					}
63
-				}
64
-			}
65
-		}
66
-		$pass .= $x;
67
-		$s = substr($s, 2);
68
-	}
69
-	$pass = preg_replace('@[./]@', 'a', $pass);
70
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
71
-	$pass = preg_replace('@[0O]@', 'o', $pass);
72
-
73
-	return $pass;
34
+    $seed = (int)round(((float)microtime() + 1) * time());
35
+
36
+    mt_srand($seed);
37
+    $s = '';
38
+    $pass = '';
39
+    for ($i = 0; $i < $longueur; $i++) {
40
+        if (!$s) {
41
+            $s = random_int(0, mt_getrandmax());
42
+            if (!$s) {
43
+                $s = random_int(0, mt_getrandmax());
44
+            }
45
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
46
+        }
47
+        $r = unpack('Cr', pack('H2', $s . $s));
48
+        $x = $r['r'] & 63;
49
+        if ($x < 10) {
50
+            $x = chr($x + 48);
51
+        } else {
52
+            if ($x < 36) {
53
+                $x = chr($x + 55);
54
+            } else {
55
+                if ($x < 62) {
56
+                    $x = chr($x + 61);
57
+                } else {
58
+                    if ($x == 63) {
59
+                        $x = '/';
60
+                    } else {
61
+                        $x = '.';
62
+                    }
63
+                }
64
+            }
65
+        }
66
+        $pass .= $x;
67
+        $s = substr($s, 2);
68
+    }
69
+    $pass = preg_replace('@[./]@', 'a', $pass);
70
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
71
+    $pass = preg_replace('@[0O]@', 'o', $pass);
72
+
73
+    return $pass;
74 74
 }
75 75
 
76 76
 /**
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
  * @return string Identifiant
80 80
  */
81 81
 function creer_uniqid() {
82
-	static $seeded;
82
+    static $seeded;
83 83
 
84
-	if (!$seeded) {
85
-		$seed = (int)round(((float)microtime() + 1) * time());
86
-		mt_srand($seed);
87
-		$seeded = true;
88
-	}
84
+    if (!$seeded) {
85
+        $seed = (int)round(((float)microtime() + 1) * time());
86
+        mt_srand($seed);
87
+        $seeded = true;
88
+    }
89 89
 
90
-	$s = random_int(0, mt_getrandmax());
91
-	if (!$s) {
92
-		$s = random_int(0, mt_getrandmax());
93
-	}
90
+    $s = random_int(0, mt_getrandmax());
91
+    if (!$s) {
92
+        $s = random_int(0, mt_getrandmax());
93
+    }
94 94
 
95
-	return uniqid($s, 1);
95
+    return uniqid($s, 1);
96 96
 }
97 97
 
98 98
 /**
@@ -106,42 +106,42 @@  discard block
 block discarded – undo
106 106
  * @return string Retourne l'alea éphemère actuel au passage
107 107
  */
108 108
 function charger_aleas() {
109
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
110
-		include_spip('base/abstract_sql');
111
-		$aleas = sql_allfetsel(
112
-			['nom', 'valeur'],
113
-			'spip_meta',
114
-			sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
115
-			'',
116
-			'',
117
-			'',
118
-			'',
119
-			'',
120
-			'continue'
121
-		);
122
-		if ($aleas) {
123
-			foreach ($aleas as $a) {
124
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
125
-			}
126
-			return $GLOBALS['meta']['alea_ephemere'];
127
-		} else {
128
-			spip_log('aleas indisponibles', 'session');
129
-			return '';
130
-		}
131
-	}
132
-	return $GLOBALS['meta']['alea_ephemere'];
109
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
110
+        include_spip('base/abstract_sql');
111
+        $aleas = sql_allfetsel(
112
+            ['nom', 'valeur'],
113
+            'spip_meta',
114
+            sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
115
+            '',
116
+            '',
117
+            '',
118
+            '',
119
+            '',
120
+            'continue'
121
+        );
122
+        if ($aleas) {
123
+            foreach ($aleas as $a) {
124
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
125
+            }
126
+            return $GLOBALS['meta']['alea_ephemere'];
127
+        } else {
128
+            spip_log('aleas indisponibles', 'session');
129
+            return '';
130
+        }
131
+    }
132
+    return $GLOBALS['meta']['alea_ephemere'];
133 133
 }
134 134
 
135 135
 /**
136 136
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
137 137
  **/
138 138
 function renouvelle_alea() {
139
-	charger_aleas();
140
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
141
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
142
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
143
-	ecrire_meta('alea_ephemere_date', time(), 'non');
144
-	spip_log("renouvellement de l'alea_ephemere");
139
+    charger_aleas();
140
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
141
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
142
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
143
+    ecrire_meta('alea_ephemere_date', time(), 'non');
144
+    spip_log("renouvellement de l'alea_ephemere");
145 145
 }
146 146
 
147 147
 
@@ -161,21 +161,21 @@  discard block
 block discarded – undo
161 161
  *     Clé de sécurité.
162 162
  **/
163 163
 function low_sec($id_auteur) {
164
-	// Pas d'id_auteur : low_sec
165
-	if (!$id_auteur = intval($id_auteur)) {
166
-		include_spip('inc/config');
167
-		if (!$low_sec = lire_config('low_sec')) {
168
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
169
-		}
170
-	} else {
171
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur));
172
-		if (!$low_sec) {
173
-			$low_sec = creer_pass_aleatoire();
174
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur));
175
-		}
176
-	}
177
-
178
-	return $low_sec;
164
+    // Pas d'id_auteur : low_sec
165
+    if (!$id_auteur = intval($id_auteur)) {
166
+        include_spip('inc/config');
167
+        if (!$low_sec = lire_config('low_sec')) {
168
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
169
+        }
170
+    } else {
171
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur));
172
+        if (!$low_sec) {
173
+            $low_sec = creer_pass_aleatoire();
174
+            sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur));
175
+        }
176
+    }
177
+
178
+    return $low_sec;
179 179
 }
180 180
 
181 181
 
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
  * @filtre
209 209
  */
210 210
 function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') {
211
-	if ($op) {
212
-		$dir .= " $op $args";
213
-	}
211
+    if ($op) {
212
+        $dir .= " $op $args";
213
+    }
214 214
 
215
-	return verifier_low_sec($id_auteur, $cle, $dir);
215
+    return verifier_low_sec($id_auteur, $cle, $dir);
216 216
 }
217 217
 
218 218
 /**
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
  * @return string
228 228
  */
229 229
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
230
-	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
231
-	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
232
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
230
+    $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
231
+    $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
232
+    $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
233 233
 
234
-	return generer_url_api($script, $path, $args, $no_entities = false, $public);
234
+    return generer_url_api($script, $path, $args, $no_entities = false, $public);
235 235
 }
236 236
 
237 237
 
@@ -249,27 +249,27 @@  discard block
 block discarded – undo
249 249
  * @deprecated 4.1
250 250
  */
251 251
 function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') {
252
-	$a = $b = '';
253
-	foreach ($args as $val => $var) {
254
-		if ($var) {
255
-			if ($val <> 'statut') {
256
-				$a .= ':' . $val . '-' . $var;
257
-			}
258
-			$b .= $val . '=' . $var . '&';
259
-		}
260
-	}
261
-	$a = substr($a, 1);
262
-	$id = intval(@$GLOBALS['connect_id_auteur']);
263
-
264
-	return $b
265
-	. 'op='
266
-	. $op
267
-	. '&id='
268
-	. $id
269
-	. '&cle='
270
-	. afficher_low_sec($id, "$mime $op $a")
271
-	. (!$a ? '' : "&args=$a")
272
-	. (!$lang ? '' : "&lang=$lang");
252
+    $a = $b = '';
253
+    foreach ($args as $val => $var) {
254
+        if ($var) {
255
+            if ($val <> 'statut') {
256
+                $a .= ':' . $val . '-' . $var;
257
+            }
258
+            $b .= $val . '=' . $var . '&';
259
+        }
260
+    }
261
+    $a = substr($a, 1);
262
+    $id = intval(@$GLOBALS['connect_id_auteur']);
263
+
264
+    return $b
265
+    . 'op='
266
+    . $op
267
+    . '&id='
268
+    . $id
269
+    . '&cle='
270
+    . afficher_low_sec($id, "$mime $op $a")
271
+    . (!$a ? '' : "&args=$a")
272
+    . (!$lang ? '' : "&lang=$lang");
273 273
 }
274 274
 
275 275
 /**
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
  *     Clé
286 286
  **/
287 287
 function afficher_low_sec($id_auteur, $action = '') {
288
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
288
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
289 289
 }
290 290
 
291 291
 /**
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
  *     true si les clés corresponde, false sinon
304 304
  **/
305 305
 function verifier_low_sec($id_auteur, $cle, $action = '') {
306
-	return ($cle == afficher_low_sec($id_auteur, $action));
306
+    return ($cle == afficher_low_sec($id_auteur, $action));
307 307
 }
308 308
 
309 309
 /**
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
  *     Identifiant de l'auteur
314 314
  **/
315 315
 function effacer_low_sec($id_auteur) {
316
-	if (!$id_auteur = intval($id_auteur)) {
317
-		return;
318
-	} // jamais trop prudent ;)
319
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur));
316
+    if (!$id_auteur = intval($id_auteur)) {
317
+        return;
318
+    } // jamais trop prudent ;)
319
+    sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur));
320 320
 }
321 321
 
322 322
 
@@ -334,31 +334,31 @@  discard block
 block discarded – undo
334 334
  *     - void sinon.
335 335
  **/
336 336
 function ecrire_acces() {
337
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
338
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
339
-
340
-	// Cette variable de configuration peut etre posee par un plugin
341
-	// par exemple acces_restreint ;
342
-	// si .htaccess existe, outrepasser spip_meta
343
-	if (
344
-		(!isset($GLOBALS['meta']['creer_htpasswd'])
345
-			or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
346
-		and !@file_exists($htaccess)
347
-	) {
348
-		spip_unlink($htpasswd);
349
-		spip_unlink($htpasswd . '-admin');
350
-		return;
351
-	}
352
-
353
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
354
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
355
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
356
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
357
-	if (include_spip('auth/ldap') and auth_ldap_connect()) {
358
-		return;
359
-	}
360
-
361
-	generer_htpasswd_files($htpasswd, "$htpasswd-admin");
337
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
338
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
339
+
340
+    // Cette variable de configuration peut etre posee par un plugin
341
+    // par exemple acces_restreint ;
342
+    // si .htaccess existe, outrepasser spip_meta
343
+    if (
344
+        (!isset($GLOBALS['meta']['creer_htpasswd'])
345
+            or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
346
+        and !@file_exists($htaccess)
347
+    ) {
348
+        spip_unlink($htpasswd);
349
+        spip_unlink($htpasswd . '-admin');
350
+        return;
351
+    }
352
+
353
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
354
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
355
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
356
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
357
+    if (include_spip('auth/ldap') and auth_ldap_connect()) {
358
+        return;
359
+    }
360
+
361
+    generer_htpasswd_files($htpasswd, "$htpasswd-admin");
362 362
 }
363 363
 
364 364
 /**
@@ -367,29 +367,29 @@  discard block
 block discarded – undo
367 367
  * @param $htpasswd_admin
368 368
  */
369 369
 function generer_htpasswd_files($htpasswd, $htpasswd_admin) {
370
-	if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
371
-		$generer_htpasswd($htpasswd, $htpasswd_admin);
372
-	}
373
-
374
-	$pwd_all = ''; // login:htpass pour tous
375
-	$pwd_admin = ''; // login:htpass pour les admins
376
-
377
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
378
-	while ($row = sql_fetch($res)) {
379
-		if (strlen($row['login']) and strlen($row['htpass'])) {
380
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
381
-			$pwd_all .= $ligne;
382
-			if ($row['statut'] == '0minirezo') {
383
-				$pwd_admin .= $ligne;
384
-			}
385
-		}
386
-	}
387
-
388
-	if ($pwd_all) {
389
-		ecrire_fichier($htpasswd, $pwd_all);
390
-		ecrire_fichier($htpasswd_admin, $pwd_admin);
391
-		spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
392
-	}
370
+    if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
371
+        $generer_htpasswd($htpasswd, $htpasswd_admin);
372
+    }
373
+
374
+    $pwd_all = ''; // login:htpass pour tous
375
+    $pwd_admin = ''; // login:htpass pour les admins
376
+
377
+    $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
378
+    while ($row = sql_fetch($res)) {
379
+        if (strlen($row['login']) and strlen($row['htpass'])) {
380
+            $ligne = $row['login'] . ':' . $row['htpass'] . "\n";
381
+            $pwd_all .= $ligne;
382
+            if ($row['statut'] == '0minirezo') {
383
+                $pwd_admin .= $ligne;
384
+            }
385
+        }
386
+    }
387
+
388
+    if ($pwd_all) {
389
+        ecrire_fichier($htpasswd, $pwd_all);
390
+        ecrire_fichier($htpasswd_admin, $pwd_admin);
391
+        spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
392
+    }
393 393
 }
394 394
 
395 395
 /**
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
  *  La chaîne hachée si fonction crypt présente, rien sinon.
404 404
  */
405 405
 function generer_htpass($pass) {
406
-	if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
407
-		return $generer_htpass($pass);
408
-	}
406
+    if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
407
+        return $generer_htpass($pass);
408
+    }
409 409
 
410
-	return '';
410
+    return '';
411 411
 }
412 412
 
413 413
 /**
@@ -420,14 +420,14 @@  discard block
 block discarded – undo
420 420
  * @return boolean
421 421
  */
422 422
 function verifier_htaccess($rep, $force = false) {
423
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
424
-	if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
425
-		return true;
426
-	}
427
-
428
-	// directive deny compatible Apache 2.0+
429
-	$deny =
430
-		'# Deny all requests from Apache 2.4+.
423
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
424
+    if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
425
+        return true;
426
+    }
427
+
428
+    // directive deny compatible Apache 2.0+
429
+    $deny =
430
+        '# Deny all requests from Apache 2.4+.
431 431
 <IfModule mod_authz_core.c>
432 432
   Require all denied
433 433
 </IfModule>
@@ -436,32 +436,32 @@  discard block
 block discarded – undo
436 436
   Deny from all
437 437
 </IfModule>
438 438
 ';
439
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
440
-	if (
441
-		function_exists('apache_get_version')
442
-		and $v = apache_get_version()
443
-		and strncmp($v, 'Apache/1.', 9) == 0
444
-	) {
445
-		$deny = "deny from all\n";
446
-	}
447
-
448
-	if ($ht = @fopen($htaccess, 'w')) {
449
-		fputs($ht, $deny);
450
-		fclose($ht);
451
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
452
-		$t = rtrim($rep, '/') . '/.ok';
453
-		if ($ht = @fopen($t, 'w')) {
454
-			@fclose($ht);
455
-			include_spip('inc/distant');
456
-			$t = substr($t, strlen(_DIR_RACINE));
457
-			$t = url_de_base() . $t;
458
-			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
459
-			$ht = ($ht['status'] ?? null) === 403;
460
-		}
461
-	}
462
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
463
-
464
-	return $ht;
439
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
440
+    if (
441
+        function_exists('apache_get_version')
442
+        and $v = apache_get_version()
443
+        and strncmp($v, 'Apache/1.', 9) == 0
444
+    ) {
445
+        $deny = "deny from all\n";
446
+    }
447
+
448
+    if ($ht = @fopen($htaccess, 'w')) {
449
+        fputs($ht, $deny);
450
+        fclose($ht);
451
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
452
+        $t = rtrim($rep, '/') . '/.ok';
453
+        if ($ht = @fopen($t, 'w')) {
454
+            @fclose($ht);
455
+            include_spip('inc/distant');
456
+            $t = substr($t, strlen(_DIR_RACINE));
457
+            $t = url_de_base() . $t;
458
+            $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
459
+            $ht = ($ht['status'] ?? null) === 403;
460
+        }
461
+    }
462
+    spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
463
+
464
+    return $ht;
465 465
 }
466 466
 
467 467
 /**
@@ -479,20 +479,20 @@  discard block
 block discarded – undo
479 479
  *         Valeur de la configuration `creer_htaccess`
480 480
  */
481 481
 function gerer_htaccess() {
482
-	// Cette variable de configuration peut etre posee par un plugin
483
-	// par exemple acces_restreint
484
-	$f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui'));
485
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
486
-	$dirs[] = ['extension' => 'distant'];
487
-	foreach ($dirs as $e) {
488
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
489
-			if ($f) {
490
-				verifier_htaccess($dir);
491
-			} else {
492
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
493
-			}
494
-		}
495
-	}
496
-
497
-	return $GLOBALS['meta']['creer_htaccess'] ?? '';
482
+    // Cette variable de configuration peut etre posee par un plugin
483
+    // par exemple acces_restreint
484
+    $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui'));
485
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
486
+    $dirs[] = ['extension' => 'distant'];
487
+    foreach ($dirs as $e) {
488
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
489
+            if ($f) {
490
+                verifier_htaccess($dir);
491
+            } else {
492
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
493
+            }
494
+        }
495
+    }
496
+
497
+    return $GLOBALS['meta']['creer_htaccess'] ?? '';
498 498
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 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 = 16, $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
 	$s = '';
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 			if (!$s) {
43 43
 				$s = random_int(0, mt_getrandmax());
44 44
 			}
45
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
45
+			$s = substr(md5(uniqid($s).$sel), 0, 16);
46 46
 		}
47
-		$r = unpack('Cr', pack('H2', $s . $s));
47
+		$r = unpack('Cr', pack('H2', $s.$s));
48 48
 		$x = $r['r'] & 63;
49 49
 		if ($x < 10) {
50 50
 			$x = chr($x + 48);
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	static $seeded;
83 83
 
84 84
 	if (!$seeded) {
85
-		$seed = (int)round(((float)microtime() + 1) * time());
85
+		$seed = (int) round(((float) microtime() + 1) * time());
86 86
 		mt_srand($seed);
87 87
 		$seeded = true;
88 88
 	}
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
169 169
 		}
170 170
 	} else {
171
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur));
171
+		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur));
172 172
 		if (!$low_sec) {
173 173
 			$low_sec = creer_pass_aleatoire();
174
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur));
174
+			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.intval($id_auteur));
175 175
 		}
176 176
 	}
177 177
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
230 230
 	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
231 231
 	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
232
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
232
+	$path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : '');
233 233
 
234 234
 	return generer_url_api($script, $path, $args, $no_entities = false, $public);
235 235
 }
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 	foreach ($args as $val => $var) {
254 254
 		if ($var) {
255 255
 			if ($val <> 'statut') {
256
-				$a .= ':' . $val . '-' . $var;
256
+				$a .= ':'.$val.'-'.$var;
257 257
 			}
258
-			$b .= $val . '=' . $var . '&';
258
+			$b .= $val.'='.$var.'&';
259 259
 		}
260 260
 	}
261 261
 	$a = substr($a, 1);
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
  *     Clé
286 286
  **/
287 287
 function afficher_low_sec($id_auteur, $action = '') {
288
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
288
+	return substr(md5($action.low_sec($id_auteur)), 0, 8);
289 289
 }
290 290
 
291 291
 /**
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	if (!$id_auteur = intval($id_auteur)) {
317 317
 		return;
318 318
 	} // jamais trop prudent ;)
319
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur));
319
+	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.intval($id_auteur));
320 320
 }
321 321
 
322 322
 
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
  *     - void sinon.
335 335
  **/
336 336
 function ecrire_acces() {
337
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
338
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
337
+	$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
338
+	$htpasswd = _DIR_TMP._AUTH_USER_FILE;
339 339
 
340 340
 	// Cette variable de configuration peut etre posee par un plugin
341 341
 	// par exemple acces_restreint ;
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 		and !@file_exists($htaccess)
347 347
 	) {
348 348
 		spip_unlink($htpasswd);
349
-		spip_unlink($htpasswd . '-admin');
349
+		spip_unlink($htpasswd.'-admin');
350 350
 		return;
351 351
 	}
352 352
 
@@ -374,10 +374,10 @@  discard block
 block discarded – undo
374 374
 	$pwd_all = ''; // login:htpass pour tous
375 375
 	$pwd_admin = ''; // login:htpass pour les admins
376 376
 
377
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
377
+	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
378 378
 	while ($row = sql_fetch($res)) {
379 379
 		if (strlen($row['login']) and strlen($row['htpass'])) {
380
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
380
+			$ligne = $row['login'].':'.$row['htpass']."\n";
381 381
 			$pwd_all .= $ligne;
382 382
 			if ($row['statut'] == '0minirezo') {
383 383
 				$pwd_admin .= $ligne;
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
  * @return boolean
421 421
  */
422 422
 function verifier_htaccess($rep, $force = false) {
423
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
423
+	$htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME;
424 424
 	if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
425 425
 		return true;
426 426
 	}
@@ -449,17 +449,17 @@  discard block
 block discarded – undo
449 449
 		fputs($ht, $deny);
450 450
 		fclose($ht);
451 451
 		@chmod($htaccess, _SPIP_CHMOD & 0666);
452
-		$t = rtrim($rep, '/') . '/.ok';
452
+		$t = rtrim($rep, '/').'/.ok';
453 453
 		if ($ht = @fopen($t, 'w')) {
454 454
 			@fclose($ht);
455 455
 			include_spip('inc/distant');
456 456
 			$t = substr($t, strlen(_DIR_RACINE));
457
-			$t = url_de_base() . $t;
457
+			$t = url_de_base().$t;
458 458
 			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
459 459
 			$ht = ($ht['status'] ?? null) === 403;
460 460
 		}
461 461
 	}
462
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
462
+	spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee'));
463 463
 
464 464
 	return $ht;
465 465
 }
@@ -485,11 +485,11 @@  discard block
 block discarded – undo
485 485
 	$dirs = sql_allfetsel('extension', 'spip_types_documents');
486 486
 	$dirs[] = ['extension' => 'distant'];
487 487
 	foreach ($dirs as $e) {
488
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
488
+		if (is_dir($dir = _DIR_IMG.$e['extension'])) {
489 489
 			if ($f) {
490 490
 				verifier_htaccess($dir);
491 491
 			} else {
492
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
492
+				spip_unlink($dir.'/'._ACCESS_FILE_NAME);
493 493
 			}
494 494
 		}
495 495
 	}
Please login to merge, or discard this patch.