Completed
Push — master ( fb0017...92433c )
by cam
01:14
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   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -10,90 +10,90 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function install_etape_ldap2_dist() {
17
-	$minipage = new Spip\Afficher\Minipage\Installation();
18
-	echo $minipage->installDebutPage(['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 $minipage->installFinPage();
17
+    $minipage = new Spip\Afficher\Minipage\Installation();
18
+    echo $minipage->installDebutPage(['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 $minipage->installFinPage();
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 $minipage->installFinPage();
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.
Indentation   +1087 added lines, -1087 removed lines patch added patch discarded remove patch
@@ -17,32 +17,32 @@  discard block
 block discarded – undo
17 17
  * @package SPIP\Core\Distant
18 18
  **/
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
24
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
25 25
 }
26 26
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
27
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
28 28
 }
29 29
 if (!defined('_INC_DISTANT_USER_AGENT')) {
30
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
31 31
 }
32 32
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
33
-	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
33
+    define('_INC_DISTANT_MAX_SIZE', 2_097_152);
34 34
 }
35 35
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
36
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
37 37
 }
38 38
 
39 39
 define('_REGEXP_COPIE_LOCALE', ',' 	.
40
-	preg_replace(
41
-		'@^https?:@',
42
-		'https?:',
43
-		($GLOBALS['meta']['adresse_site'] ?? '')
44
-	)
45
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
40
+    preg_replace(
41
+        '@^https?:@',
42
+        'https?:',
43
+        ($GLOBALS['meta']['adresse_site'] ?? '')
44
+    )
45
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
46 46
 
47 47
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
48 48
 
@@ -71,107 +71,107 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) {
73 73
 
74
-	// si c'est la protection de soi-meme, retourner le path
75
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
77
-
78
-		return @file_exists($source) ? $source : false;
79
-	}
80
-
81
-	if (is_null($local)) {
82
-		$local = fichier_copie_locale($source);
83
-	} else {
84
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
85
-			$local = substr($local, strlen(_DIR_RACINE));
86
-		}
87
-	}
88
-
89
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
90
-	// par exemple un fichier qui ne figure pas dans nos documents ;
91
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
92
-	if (!$local) {
93
-		return false;
94
-	}
95
-
96
-	$localrac = _DIR_RACINE . $local;
97
-	$t = ($mode === 'force') ? false : @file_exists($localrac);
98
-
99
-	// test d'existence du fichier
100
-	if ($mode === 'test') {
101
-		return $t ? $local : '';
102
-	}
103
-
104
-	// sinon voir si on doit/peut le telecharger
105
-	if ($local === $source or !tester_url_absolue($source)) {
106
-		return $t ? $local : '';
107
-	}
108
-
109
-	if ($mode === 'modif' or !$t) {
110
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
111
-		// et des eventuelles recuperations concurantes
112
-		include_spip('inc/acces');
113
-		if (!$taille_max) {
114
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
115
-		}
116
-		$localrac_tmp = $localrac . '.tmp';
117
-		$res = recuperer_url(
118
-			$source,
119
-			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120
-		);
121
-
122
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
124
-			@unlink($localrac_tmp);
125
-		}
126
-		else {
127
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
128
-		}
129
-		if (!$res or !$res['length']) {
130
-			// si $t c'est sans doute juste un not-modified-since
131
-			return $t ? $local : false;
132
-		}
133
-
134
-		// si option valider url, verifions que l'URL finale est acceptable
135
-		if (
136
-			$callback_valider_url
137
-			and is_callable($callback_valider_url)
138
-			and !$callback_valider_url($res['url'])
139
-		) {
140
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
141
-			@unlink($localrac_tmp);
142
-			return $t ? $local : false;
143
-		}
144
-
145
-		// on peut renommer le fichier tmp
146
-		@rename($localrac_tmp, $localrac);
147
-
148
-		// si on retrouve l'extension
149
-		if (
150
-			!empty($res['headers'])
151
-			and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
152
-		) {
153
-			if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
154
-				$sanitizer($localrac);
155
-			}
156
-		}
157
-
158
-		// pour une eventuelle indexation
159
-		pipeline(
160
-			'post_edition',
161
-			[
162
-				'args' => [
163
-					'operation' => 'copie_locale',
164
-					'source' => $source,
165
-					'fichier' => $local,
166
-					'http_res' => $res['length'],
167
-					'url' => $res['url'],
168
-				],
169
-				'data' => null
170
-			]
171
-		);
172
-	}
173
-
174
-	return $local;
74
+    // si c'est la protection de soi-meme, retourner le path
75
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
77
+
78
+        return @file_exists($source) ? $source : false;
79
+    }
80
+
81
+    if (is_null($local)) {
82
+        $local = fichier_copie_locale($source);
83
+    } else {
84
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
85
+            $local = substr($local, strlen(_DIR_RACINE));
86
+        }
87
+    }
88
+
89
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
90
+    // par exemple un fichier qui ne figure pas dans nos documents ;
91
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
92
+    if (!$local) {
93
+        return false;
94
+    }
95
+
96
+    $localrac = _DIR_RACINE . $local;
97
+    $t = ($mode === 'force') ? false : @file_exists($localrac);
98
+
99
+    // test d'existence du fichier
100
+    if ($mode === 'test') {
101
+        return $t ? $local : '';
102
+    }
103
+
104
+    // sinon voir si on doit/peut le telecharger
105
+    if ($local === $source or !tester_url_absolue($source)) {
106
+        return $t ? $local : '';
107
+    }
108
+
109
+    if ($mode === 'modif' or !$t) {
110
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
111
+        // et des eventuelles recuperations concurantes
112
+        include_spip('inc/acces');
113
+        if (!$taille_max) {
114
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
115
+        }
116
+        $localrac_tmp = $localrac . '.tmp';
117
+        $res = recuperer_url(
118
+            $source,
119
+            ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120
+        );
121
+
122
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
+            spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
124
+            @unlink($localrac_tmp);
125
+        }
126
+        else {
127
+            spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
128
+        }
129
+        if (!$res or !$res['length']) {
130
+            // si $t c'est sans doute juste un not-modified-since
131
+            return $t ? $local : false;
132
+        }
133
+
134
+        // si option valider url, verifions que l'URL finale est acceptable
135
+        if (
136
+            $callback_valider_url
137
+            and is_callable($callback_valider_url)
138
+            and !$callback_valider_url($res['url'])
139
+        ) {
140
+            spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
141
+            @unlink($localrac_tmp);
142
+            return $t ? $local : false;
143
+        }
144
+
145
+        // on peut renommer le fichier tmp
146
+        @rename($localrac_tmp, $localrac);
147
+
148
+        // si on retrouve l'extension
149
+        if (
150
+            !empty($res['headers'])
151
+            and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
152
+        ) {
153
+            if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
154
+                $sanitizer($localrac);
155
+            }
156
+        }
157
+
158
+        // pour une eventuelle indexation
159
+        pipeline(
160
+            'post_edition',
161
+            [
162
+                'args' => [
163
+                    'operation' => 'copie_locale',
164
+                    'source' => $source,
165
+                    'fichier' => $local,
166
+                    'http_res' => $res['length'],
167
+                    'url' => $res['url'],
168
+                ],
169
+                'data' => null
170
+            ]
171
+        );
172
+    }
173
+
174
+    return $local;
175 175
 }
176 176
 
177 177
 /**
@@ -186,99 +186,99 @@  discard block
 block discarded – undo
186 186
  *   url ou false en cas d'echec
187 187
  */
188 188
 function valider_url_distante($url, $known_hosts = []) {
189
-	if (!function_exists('protocole_verifier')) {
190
-		include_spip('inc/filtres_mini');
191
-	}
192
-
193
-	if (!protocole_verifier($url, ['http', 'https'])) {
194
-		return false;
195
-	}
196
-
197
-	$parsed_url = parse_url($url);
198
-	if (!$parsed_url or empty($parsed_url['host'])) {
199
-		return false;
200
-	}
201
-
202
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
203
-		return false;
204
-	}
205
-
206
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
207
-		return false;
208
-	}
209
-
210
-	if (!is_array($known_hosts)) {
211
-		$known_hosts = [$known_hosts];
212
-	}
213
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
214
-	$known_hosts[] = url_de_base();
215
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
216
-
217
-	$is_known_host = false;
218
-	foreach ($known_hosts as $known_host) {
219
-		$parse_known = parse_url($known_host);
220
-		if (
221
-			$parse_known
222
-			and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
223
-		) {
224
-			$is_known_host = true;
225
-			break;
226
-		}
227
-	}
228
-
229
-	if (!$is_known_host) {
230
-		$host = trim($parsed_url['host'], '.');
231
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
232
-			$ip = gethostbyname($host);
233
-			if ($ip === $host) {
234
-				// Error condition for gethostbyname()
235
-				$ip = false;
236
-			}
237
-			if ($records = dns_get_record($host)) {
238
-				foreach ($records as $record) {
239
-					// il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
240
-					// se fasse sur la meme IP
241
-					if ($record['ttl'] < 10) {
242
-						$ip = false;
243
-						break;
244
-					}
245
-				}
246
-			}
247
-			else {
248
-				$ip = false;
249
-			}
250
-		}
251
-		if ($ip) {
252
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253
-				return false;
254
-			}
255
-		}
256
-	}
257
-
258
-	if (empty($parsed_url['port'])) {
259
-		return $url;
260
-	}
261
-
262
-	$port = $parsed_url['port'];
263
-	if ($port === 80  or $port === 443  or $port === 8080) {
264
-		return $url;
265
-	}
266
-
267
-	if ($is_known_host) {
268
-		foreach ($known_hosts as $known_host) {
269
-			$parse_known = parse_url($known_host);
270
-			if (
271
-				$parse_known
272
-				and !empty($parse_known['port'])
273
-				and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
274
-				and $parse_known['port'] == $port
275
-			) {
276
-				return $url;
277
-			}
278
-		}
279
-	}
280
-
281
-	return false;
189
+    if (!function_exists('protocole_verifier')) {
190
+        include_spip('inc/filtres_mini');
191
+    }
192
+
193
+    if (!protocole_verifier($url, ['http', 'https'])) {
194
+        return false;
195
+    }
196
+
197
+    $parsed_url = parse_url($url);
198
+    if (!$parsed_url or empty($parsed_url['host'])) {
199
+        return false;
200
+    }
201
+
202
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
203
+        return false;
204
+    }
205
+
206
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
207
+        return false;
208
+    }
209
+
210
+    if (!is_array($known_hosts)) {
211
+        $known_hosts = [$known_hosts];
212
+    }
213
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
214
+    $known_hosts[] = url_de_base();
215
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
216
+
217
+    $is_known_host = false;
218
+    foreach ($known_hosts as $known_host) {
219
+        $parse_known = parse_url($known_host);
220
+        if (
221
+            $parse_known
222
+            and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
223
+        ) {
224
+            $is_known_host = true;
225
+            break;
226
+        }
227
+    }
228
+
229
+    if (!$is_known_host) {
230
+        $host = trim($parsed_url['host'], '.');
231
+        if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
232
+            $ip = gethostbyname($host);
233
+            if ($ip === $host) {
234
+                // Error condition for gethostbyname()
235
+                $ip = false;
236
+            }
237
+            if ($records = dns_get_record($host)) {
238
+                foreach ($records as $record) {
239
+                    // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
240
+                    // se fasse sur la meme IP
241
+                    if ($record['ttl'] < 10) {
242
+                        $ip = false;
243
+                        break;
244
+                    }
245
+                }
246
+            }
247
+            else {
248
+                $ip = false;
249
+            }
250
+        }
251
+        if ($ip) {
252
+            if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253
+                return false;
254
+            }
255
+        }
256
+    }
257
+
258
+    if (empty($parsed_url['port'])) {
259
+        return $url;
260
+    }
261
+
262
+    $port = $parsed_url['port'];
263
+    if ($port === 80  or $port === 443  or $port === 8080) {
264
+        return $url;
265
+    }
266
+
267
+    if ($is_known_host) {
268
+        foreach ($known_hosts as $known_host) {
269
+            $parse_known = parse_url($known_host);
270
+            if (
271
+                $parse_known
272
+                and !empty($parse_known['port'])
273
+                and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
274
+                and $parse_known['port'] == $port
275
+            ) {
276
+                return $url;
277
+            }
278
+        }
279
+    }
280
+
281
+    return false;
282 282
 }
283 283
 
284 284
 /**
@@ -298,86 +298,86 @@  discard block
 block discarded – undo
298 298
  */
299 299
 function prepare_donnees_post($donnees, $boundary = '') {
300 300
 
301
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
302
-	// pour un appel soap par exemple
303
-	// l'entete est separe des donnees par un double retour a la ligne
304
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
305
-	if (is_string($donnees) && strlen($donnees)) {
306
-		$entete = '';
307
-		// on repasse tous les \r\n et \r en simples \n
308
-		$donnees = str_replace("\r\n", "\n", $donnees);
309
-		$donnees = str_replace("\r", "\n", $donnees);
310
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
311
-		$p = strpos($donnees, "\n\n");
312
-		if ($p !== false) {
313
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
314
-			$donnees = substr($donnees, $p + 2);
315
-		}
316
-		$chaine = str_replace("\n", "\r\n", $donnees);
317
-	} else {
318
-		/* boundary automatique */
319
-		// Si on a plus de 500 octects de donnees, on "boundarise"
320
-		if ($boundary === '') {
321
-			$taille = 0;
322
-			foreach ($donnees as $cle => $valeur) {
323
-				if (is_array($valeur)) {
324
-					foreach ($valeur as $val2) {
325
-						$taille += strlen($val2);
326
-					}
327
-				} else {
328
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
329
-					$taille += strlen($valeur);
330
-				}
331
-			}
332
-			if ($taille > 500) {
333
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
334
-			}
335
-		}
336
-
337
-		if (is_string($boundary) and strlen($boundary)) {
338
-			// fabrique une chaine HTTP pour un POST avec boundary
339
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
340
-			$chaine = '';
341
-			if (is_array($donnees)) {
342
-				foreach ($donnees as $cle => $valeur) {
343
-					if (is_array($valeur)) {
344
-						foreach ($valeur as $val2) {
345
-							$chaine .= "\r\n--$boundary\r\n";
346
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
347
-							$chaine .= "\r\n";
348
-							$chaine .= $val2;
349
-						}
350
-					} else {
351
-						$chaine .= "\r\n--$boundary\r\n";
352
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
353
-						$chaine .= "\r\n";
354
-						$chaine .= $valeur;
355
-					}
356
-				}
357
-				$chaine .= "\r\n--$boundary\r\n";
358
-			}
359
-		} else {
360
-			// fabrique une chaine HTTP simple pour un POST
361
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
362
-			$chaine = [];
363
-			if (is_array($donnees)) {
364
-				foreach ($donnees as $cle => $valeur) {
365
-					if (is_array($valeur)) {
366
-						foreach ($valeur as $val2) {
367
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
368
-						}
369
-					} else {
370
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
371
-					}
372
-				}
373
-				$chaine = implode('&', $chaine);
374
-			} else {
375
-				$chaine = $donnees;
376
-			}
377
-		}
378
-	}
379
-
380
-	return [$entete, $chaine];
301
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
302
+    // pour un appel soap par exemple
303
+    // l'entete est separe des donnees par un double retour a la ligne
304
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
305
+    if (is_string($donnees) && strlen($donnees)) {
306
+        $entete = '';
307
+        // on repasse tous les \r\n et \r en simples \n
308
+        $donnees = str_replace("\r\n", "\n", $donnees);
309
+        $donnees = str_replace("\r", "\n", $donnees);
310
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
311
+        $p = strpos($donnees, "\n\n");
312
+        if ($p !== false) {
313
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
314
+            $donnees = substr($donnees, $p + 2);
315
+        }
316
+        $chaine = str_replace("\n", "\r\n", $donnees);
317
+    } else {
318
+        /* boundary automatique */
319
+        // Si on a plus de 500 octects de donnees, on "boundarise"
320
+        if ($boundary === '') {
321
+            $taille = 0;
322
+            foreach ($donnees as $cle => $valeur) {
323
+                if (is_array($valeur)) {
324
+                    foreach ($valeur as $val2) {
325
+                        $taille += strlen($val2);
326
+                    }
327
+                } else {
328
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
329
+                    $taille += strlen($valeur);
330
+                }
331
+            }
332
+            if ($taille > 500) {
333
+                $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
334
+            }
335
+        }
336
+
337
+        if (is_string($boundary) and strlen($boundary)) {
338
+            // fabrique une chaine HTTP pour un POST avec boundary
339
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
340
+            $chaine = '';
341
+            if (is_array($donnees)) {
342
+                foreach ($donnees as $cle => $valeur) {
343
+                    if (is_array($valeur)) {
344
+                        foreach ($valeur as $val2) {
345
+                            $chaine .= "\r\n--$boundary\r\n";
346
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
347
+                            $chaine .= "\r\n";
348
+                            $chaine .= $val2;
349
+                        }
350
+                    } else {
351
+                        $chaine .= "\r\n--$boundary\r\n";
352
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
353
+                        $chaine .= "\r\n";
354
+                        $chaine .= $valeur;
355
+                    }
356
+                }
357
+                $chaine .= "\r\n--$boundary\r\n";
358
+            }
359
+        } else {
360
+            // fabrique une chaine HTTP simple pour un POST
361
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
362
+            $chaine = [];
363
+            if (is_array($donnees)) {
364
+                foreach ($donnees as $cle => $valeur) {
365
+                    if (is_array($valeur)) {
366
+                        foreach ($valeur as $val2) {
367
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
368
+                        }
369
+                    } else {
370
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
371
+                    }
372
+                }
373
+                $chaine = implode('&', $chaine);
374
+            } else {
375
+                $chaine = $donnees;
376
+            }
377
+        }
378
+    }
379
+
380
+    return [$entete, $chaine];
381 381
 }
382 382
 
383 383
 /**
@@ -388,19 +388,19 @@  discard block
 block discarded – undo
388 388
  */
389 389
 function url_to_ascii($url_idn) {
390 390
 
391
-	if ($parts = parse_url($url_idn)) {
392
-		$host = $parts['host'];
393
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
394
-			$converter = new ToIdn();
395
-			$host_ascii = $converter->convert($host);
396
-			$url_idn = explode($host, $url_idn, 2);
397
-			$url_idn = implode($host_ascii, $url_idn);
398
-		}
399
-		// et on urlencode les char utf si besoin dans le path
400
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
401
-	}
402
-
403
-	return $url_idn;
391
+    if ($parts = parse_url($url_idn)) {
392
+        $host = $parts['host'];
393
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
394
+            $converter = new ToIdn();
395
+            $host_ascii = $converter->convert($host);
396
+            $url_idn = explode($host, $url_idn, 2);
397
+            $url_idn = implode($host_ascii, $url_idn);
398
+        }
399
+        // et on urlencode les char utf si besoin dans le path
400
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
401
+    }
402
+
403
+    return $url_idn;
404 404
 }
405 405
 
406 406
 /**
@@ -441,209 +441,209 @@  discard block
 block discarded – undo
441 441
  *     string file : nom du fichier si enregistre dans un fichier
442 442
  */
443 443
 function recuperer_url($url, $options = []) {
444
-	// Conserve la mémoire de la méthode fournit éventuellement
445
-	$methode_demandee = $options['methode'] ?? '';
446
-	$default = [
447
-		'transcoder' => false,
448
-		'methode' => 'GET',
449
-		'taille_max' => null,
450
-		'headers' => [],
451
-		'datas' => '',
452
-		'boundary' => '',
453
-		'refuser_gz' => false,
454
-		'if_modified_since' => '',
455
-		'uri_referer' => '',
456
-		'file' => '',
457
-		'follow_location' => 10,
458
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
459
-	];
460
-	$options = array_merge($default, $options);
461
-	// copier directement dans un fichier ?
462
-	$copy = $options['file'];
463
-
464
-	if ($options['methode'] == 'HEAD') {
465
-		$options['taille_max'] = 0;
466
-	}
467
-	if (is_null($options['taille_max'])) {
468
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469
-	}
470
-
471
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
472
-
473
-	// Ajout des en-têtes spécifiques si besoin
474
-	$formatted_data = '';
475
-	if (!empty($options['headers'])) {
476
-		foreach ($options['headers'] as $champ => $valeur) {
477
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
478
-		}
479
-	}
480
-
481
-	if (!empty($options['datas'])) {
482
-		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483
-		$head .= $formatted_data;
484
-		if (stripos($head, 'Content-Length:') === false) {
485
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
486
-		}
487
-		$formatted_data = $head . "\r\n" . $postdata;
488
-		if (
489
-			strlen($postdata)
490
-			and !$methode_demandee
491
-		) {
492
-			$options['methode'] = 'POST';
493
-		}
494
-	} elseif ($formatted_data) {
495
-		$formatted_data .= "\r\n";
496
-	}
497
-
498
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499
-	$url = preg_replace(',^feed://,i', 'http://', $url);
500
-	if (!tester_url_absolue($url)) {
501
-		$url = 'http://' . $url;
502
-	} elseif (strncmp($url, '//', 2) == 0) {
503
-		$url = 'http:' . $url;
504
-	}
505
-
506
-	$url = url_to_ascii($url);
507
-
508
-	$result = [
509
-		'status' => 0,
510
-		'headers' => '',
511
-		'page' => '',
512
-		'length' => 0,
513
-		'last_modified' => '',
514
-		'location' => '',
515
-		'url' => $url
516
-	];
517
-
518
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
519
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
520
-
521
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
522
-	[$handle, $fopen] = init_http(
523
-		$options['methode'],
524
-		$url,
525
-		$refuser_gz,
526
-		$options['uri_referer'],
527
-		$formatted_data,
528
-		$options['version_http'],
529
-		$options['if_modified_since']
530
-	);
531
-	if (!$handle) {
532
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
533
-
534
-		return false;
535
-	}
536
-
537
-	// Sauf en fopen, envoyer le flux d'entree
538
-	// et recuperer les en-tetes de reponses
539
-	if (!$fopen) {
540
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
541
-		if (!$res) {
542
-			fclose($handle);
543
-			$t = @parse_url($url);
544
-			$host = $t['host'];
545
-			// Chinoisierie inexplicable pour contrer
546
-			// les actions liberticides de l'empire du milieu
547
-			if (
548
-				!need_proxy($host)
549
-				and $res = @file_get_contents($url)
550
-			) {
551
-				$result['length'] = strlen($res);
552
-				if ($copy) {
553
-					ecrire_fichier($copy, $res);
554
-					$result['file'] = $copy;
555
-				} else {
556
-					$result['page'] = $res;
557
-				}
558
-				$res = [
559
-					'status' => 200,
560
-				];
561
-			} else {
562
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
563
-				return false;
564
-			}
565
-		} elseif ($res['location'] and $options['follow_location']) {
566
-			$options['follow_location']--;
567
-			fclose($handle);
568
-			include_spip('inc/filtres');
569
-			$url = suivre_lien($url, $res['location']);
570
-
571
-			// une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
572
-			if ($options['methode'] !== 'GET') {
573
-				if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
574
-					$options['methode'] = 'GET';
575
-					$options['datas'] = '';
576
-				}
577
-			}
578
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
579
-
580
-			return recuperer_url($url, $options);
581
-		} elseif ($res['status'] !== 200) {
582
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
583
-		}
584
-		$result['status'] = $res['status'];
585
-		if (isset($res['headers'])) {
586
-			$result['headers'] = $res['headers'];
587
-		}
588
-		if (isset($res['last_modified'])) {
589
-			$result['last_modified'] = $res['last_modified'];
590
-		}
591
-		if (isset($res['location'])) {
592
-			$result['location'] = $res['location'];
593
-		}
594
-	}
595
-
596
-	// on ne veut que les entetes
597
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
599
-		return $result;
600
-	}
601
-
602
-
603
-	// s'il faut deballer, le faire via un fichier temporaire
604
-	// sinon la memoire explose pour les gros flux
605
-
606
-	$gz = false;
607
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
609
-	}
610
-
611
-	// si on a pas deja recuperer le contenu par une methode detournee
612
-	if (!$result['length']) {
613
-		$res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
614
-		fclose($handle);
615
-		if ($copy) {
616
-			$result['length'] = $res;
617
-			$result['file'] = $copy;
618
-		} elseif ($res) {
619
-			$result['page'] = &$res;
620
-			$result['length'] = strlen($result['page']);
621
-		}
622
-		if (!$result['status']) {
623
-			$result['status'] = 200; // on a reussi, donc !
624
-		}
625
-	}
626
-	if (!$result['page']) {
627
-		return $result;
628
-	}
629
-
630
-	// Decompresser au besoin
631
-	if ($gz) {
632
-		$result['page'] = implode('', gzfile($gz));
633
-		supprimer_fichier($gz);
634
-	}
635
-
636
-	// Faut-il l'importer dans notre charset local ?
637
-	if ($options['transcoder']) {
638
-		include_spip('inc/charsets');
639
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
640
-	}
641
-
642
-	$trace = json_decode(json_encode($result), true);
643
-	$trace['page'] = '...';
644
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
645
-
646
-	return $result;
444
+    // Conserve la mémoire de la méthode fournit éventuellement
445
+    $methode_demandee = $options['methode'] ?? '';
446
+    $default = [
447
+        'transcoder' => false,
448
+        'methode' => 'GET',
449
+        'taille_max' => null,
450
+        'headers' => [],
451
+        'datas' => '',
452
+        'boundary' => '',
453
+        'refuser_gz' => false,
454
+        'if_modified_since' => '',
455
+        'uri_referer' => '',
456
+        'file' => '',
457
+        'follow_location' => 10,
458
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
459
+    ];
460
+    $options = array_merge($default, $options);
461
+    // copier directement dans un fichier ?
462
+    $copy = $options['file'];
463
+
464
+    if ($options['methode'] == 'HEAD') {
465
+        $options['taille_max'] = 0;
466
+    }
467
+    if (is_null($options['taille_max'])) {
468
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469
+    }
470
+
471
+    spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
472
+
473
+    // Ajout des en-têtes spécifiques si besoin
474
+    $formatted_data = '';
475
+    if (!empty($options['headers'])) {
476
+        foreach ($options['headers'] as $champ => $valeur) {
477
+            $formatted_data .= $champ . ': ' . $valeur . "\r\n";
478
+        }
479
+    }
480
+
481
+    if (!empty($options['datas'])) {
482
+        [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483
+        $head .= $formatted_data;
484
+        if (stripos($head, 'Content-Length:') === false) {
485
+            $head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
486
+        }
487
+        $formatted_data = $head . "\r\n" . $postdata;
488
+        if (
489
+            strlen($postdata)
490
+            and !$methode_demandee
491
+        ) {
492
+            $options['methode'] = 'POST';
493
+        }
494
+    } elseif ($formatted_data) {
495
+        $formatted_data .= "\r\n";
496
+    }
497
+
498
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499
+    $url = preg_replace(',^feed://,i', 'http://', $url);
500
+    if (!tester_url_absolue($url)) {
501
+        $url = 'http://' . $url;
502
+    } elseif (strncmp($url, '//', 2) == 0) {
503
+        $url = 'http:' . $url;
504
+    }
505
+
506
+    $url = url_to_ascii($url);
507
+
508
+    $result = [
509
+        'status' => 0,
510
+        'headers' => '',
511
+        'page' => '',
512
+        'length' => 0,
513
+        'last_modified' => '',
514
+        'location' => '',
515
+        'url' => $url
516
+    ];
517
+
518
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
519
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
520
+
521
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
522
+    [$handle, $fopen] = init_http(
523
+        $options['methode'],
524
+        $url,
525
+        $refuser_gz,
526
+        $options['uri_referer'],
527
+        $formatted_data,
528
+        $options['version_http'],
529
+        $options['if_modified_since']
530
+    );
531
+    if (!$handle) {
532
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
533
+
534
+        return false;
535
+    }
536
+
537
+    // Sauf en fopen, envoyer le flux d'entree
538
+    // et recuperer les en-tetes de reponses
539
+    if (!$fopen) {
540
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
541
+        if (!$res) {
542
+            fclose($handle);
543
+            $t = @parse_url($url);
544
+            $host = $t['host'];
545
+            // Chinoisierie inexplicable pour contrer
546
+            // les actions liberticides de l'empire du milieu
547
+            if (
548
+                !need_proxy($host)
549
+                and $res = @file_get_contents($url)
550
+            ) {
551
+                $result['length'] = strlen($res);
552
+                if ($copy) {
553
+                    ecrire_fichier($copy, $res);
554
+                    $result['file'] = $copy;
555
+                } else {
556
+                    $result['page'] = $res;
557
+                }
558
+                $res = [
559
+                    'status' => 200,
560
+                ];
561
+            } else {
562
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
563
+                return false;
564
+            }
565
+        } elseif ($res['location'] and $options['follow_location']) {
566
+            $options['follow_location']--;
567
+            fclose($handle);
568
+            include_spip('inc/filtres');
569
+            $url = suivre_lien($url, $res['location']);
570
+
571
+            // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
572
+            if ($options['methode'] !== 'GET') {
573
+                if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
574
+                    $options['methode'] = 'GET';
575
+                    $options['datas'] = '';
576
+                }
577
+            }
578
+            spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
579
+
580
+            return recuperer_url($url, $options);
581
+        } elseif ($res['status'] !== 200) {
582
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
583
+        }
584
+        $result['status'] = $res['status'];
585
+        if (isset($res['headers'])) {
586
+            $result['headers'] = $res['headers'];
587
+        }
588
+        if (isset($res['last_modified'])) {
589
+            $result['last_modified'] = $res['last_modified'];
590
+        }
591
+        if (isset($res['location'])) {
592
+            $result['location'] = $res['location'];
593
+        }
594
+    }
595
+
596
+    // on ne veut que les entetes
597
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
+        spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
599
+        return $result;
600
+    }
601
+
602
+
603
+    // s'il faut deballer, le faire via un fichier temporaire
604
+    // sinon la memoire explose pour les gros flux
605
+
606
+    $gz = false;
607
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
+        $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
609
+    }
610
+
611
+    // si on a pas deja recuperer le contenu par une methode detournee
612
+    if (!$result['length']) {
613
+        $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
614
+        fclose($handle);
615
+        if ($copy) {
616
+            $result['length'] = $res;
617
+            $result['file'] = $copy;
618
+        } elseif ($res) {
619
+            $result['page'] = &$res;
620
+            $result['length'] = strlen($result['page']);
621
+        }
622
+        if (!$result['status']) {
623
+            $result['status'] = 200; // on a reussi, donc !
624
+        }
625
+    }
626
+    if (!$result['page']) {
627
+        return $result;
628
+    }
629
+
630
+    // Decompresser au besoin
631
+    if ($gz) {
632
+        $result['page'] = implode('', gzfile($gz));
633
+        supprimer_fichier($gz);
634
+    }
635
+
636
+    // Faut-il l'importer dans notre charset local ?
637
+    if ($options['transcoder']) {
638
+        include_spip('inc/charsets');
639
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
640
+    }
641
+
642
+    $trace = json_decode(json_encode($result), true);
643
+    $trace['page'] = '...';
644
+    spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
645
+
646
+    return $result;
647 647
 }
648 648
 
649 649
 /**
@@ -659,73 +659,73 @@  discard block
 block discarded – undo
659 659
  * @return array|bool|mixed
660 660
  */
661 661
 function recuperer_url_cache($url, $options = []) {
662
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
663
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
664
-	}
665
-	$default = [
666
-		'transcoder' => false,
667
-		'methode' => 'GET',
668
-		'taille_max' => null,
669
-		'datas' => '',
670
-		'boundary' => '',
671
-		'refuser_gz' => false,
672
-		'if_modified_since' => '',
673
-		'uri_referer' => '',
674
-		'file' => '',
675
-		'follow_location' => 10,
676
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
677
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
678
-	];
679
-	$options = array_merge($default, $options);
680
-
681
-	// cas ou il n'est pas possible de cacher
682
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
683
-		return recuperer_url($url, $options);
684
-	}
685
-
686
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
687
-	static $errors = [];
688
-	if (isset($errors[$url])) {
689
-		return $errors[$url];
690
-	}
691
-
692
-	$sig = $options;
693
-	unset($sig['if_modified_since']);
694
-	unset($sig['delai_cache']);
695
-	$sig['url'] = $url;
696
-
697
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
698
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
699
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
700
-	$cache = "$sub$cache";
701
-
702
-	$res = false;
703
-	$is_cached = file_exists($cache);
704
-	if (
705
-		$is_cached
706
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
707
-	) {
708
-		lire_fichier($cache, $res);
709
-		if ($res = unserialize($res)) {
710
-			// mettre le last_modified et le status=304 ?
711
-		}
712
-	}
713
-	if (!$res) {
714
-		$res = recuperer_url($url, $options);
715
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
716
-		if (!$res) {
717
-			if ($is_cached) {
718
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
719
-				lire_fichier($cache, $res);
720
-				$res = unserialize($res);
721
-			}
722
-
723
-			return $errors[$url] = $res;
724
-		}
725
-		ecrire_fichier($cache, serialize($res));
726
-	}
727
-
728
-	return $res;
662
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
663
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
664
+    }
665
+    $default = [
666
+        'transcoder' => false,
667
+        'methode' => 'GET',
668
+        'taille_max' => null,
669
+        'datas' => '',
670
+        'boundary' => '',
671
+        'refuser_gz' => false,
672
+        'if_modified_since' => '',
673
+        'uri_referer' => '',
674
+        'file' => '',
675
+        'follow_location' => 10,
676
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
677
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
678
+    ];
679
+    $options = array_merge($default, $options);
680
+
681
+    // cas ou il n'est pas possible de cacher
682
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
683
+        return recuperer_url($url, $options);
684
+    }
685
+
686
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
687
+    static $errors = [];
688
+    if (isset($errors[$url])) {
689
+        return $errors[$url];
690
+    }
691
+
692
+    $sig = $options;
693
+    unset($sig['if_modified_since']);
694
+    unset($sig['delai_cache']);
695
+    $sig['url'] = $url;
696
+
697
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
698
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
699
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
700
+    $cache = "$sub$cache";
701
+
702
+    $res = false;
703
+    $is_cached = file_exists($cache);
704
+    if (
705
+        $is_cached
706
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
707
+    ) {
708
+        lire_fichier($cache, $res);
709
+        if ($res = unserialize($res)) {
710
+            // mettre le last_modified et le status=304 ?
711
+        }
712
+    }
713
+    if (!$res) {
714
+        $res = recuperer_url($url, $options);
715
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
716
+        if (!$res) {
717
+            if ($is_cached) {
718
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
719
+                lire_fichier($cache, $res);
720
+                $res = unserialize($res);
721
+            }
722
+
723
+            return $errors[$url] = $res;
724
+        }
725
+        ecrire_fichier($cache, serialize($res));
726
+    }
727
+
728
+    return $res;
729 729
 }
730 730
 
731 731
 /**
@@ -743,42 +743,42 @@  discard block
 block discarded – undo
743 743
  *   string contenu de la resource
744 744
  */
745 745
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
746
-	$tmpfile = null;
747
-	$taille = 0;
748
-	$result = '';
749
-	$fp = false;
750
-	if ($fichier) {
751
-		include_spip('inc/acces');
752
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
753
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754
-		if (!$fp and file_exists($fichier)) {
755
-			return filesize($fichier);
756
-		}
757
-		if (!$fp) {
758
-			return false;
759
-		}
760
-		$result = 0; // on renvoie la taille du fichier
761
-	}
762
-	while (!feof($handle) and $taille < $taille_max) {
763
-		$res = fread($handle, 16384);
764
-		$taille += strlen($res);
765
-		if ($fp) {
766
-			fwrite($fp, $res);
767
-			$result = $taille;
768
-		} else {
769
-			$result .= $res;
770
-		}
771
-	}
772
-	if ($fp) {
773
-		spip_fclose_unlock($fp);
774
-		spip_unlink($fichier);
775
-		@rename($tmpfile, $fichier);
776
-		if (!file_exists($fichier)) {
777
-			return false;
778
-		}
779
-	}
780
-
781
-	return $result;
746
+    $tmpfile = null;
747
+    $taille = 0;
748
+    $result = '';
749
+    $fp = false;
750
+    if ($fichier) {
751
+        include_spip('inc/acces');
752
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
753
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754
+        if (!$fp and file_exists($fichier)) {
755
+            return filesize($fichier);
756
+        }
757
+        if (!$fp) {
758
+            return false;
759
+        }
760
+        $result = 0; // on renvoie la taille du fichier
761
+    }
762
+    while (!feof($handle) and $taille < $taille_max) {
763
+        $res = fread($handle, 16384);
764
+        $taille += strlen($res);
765
+        if ($fp) {
766
+            fwrite($fp, $res);
767
+            $result = $taille;
768
+        } else {
769
+            $result .= $res;
770
+        }
771
+    }
772
+    if ($fp) {
773
+        spip_fclose_unlock($fp);
774
+        spip_unlink($fichier);
775
+        @rename($tmpfile, $fichier);
776
+        if (!file_exists($fichier)) {
777
+            return false;
778
+        }
779
+    }
780
+
781
+    return $result;
782 782
 }
783 783
 
784 784
 /**
@@ -800,35 +800,35 @@  discard block
 block discarded – undo
800 800
  *   string location
801 801
  */
802 802
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
803
-	$result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
804
-
805
-	$s = @trim(fgets($handle, 16384));
806
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
807
-		return false;
808
-	}
809
-	$result['status'] = intval($r[1]);
810
-	while ($s = trim(fgets($handle, 16384))) {
811
-		$result['headers'][] = $s . "\n";
812
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813
-		[, $d, $v] = $r;
814
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
815
-			$result['location'] = $v;
816
-		} elseif ($d == 'Last-Modified') {
817
-			$result['last_modified'] = strtotime($v);
818
-		}
819
-	}
820
-	if (
821
-		$if_modified_since
822
-		and $result['last_modified']
823
-		and $if_modified_since > $result['last_modified']
824
-		and $result['status'] == 200
825
-	) {
826
-		$result['status'] = 304;
827
-	}
828
-
829
-	$result['headers'] = implode('', $result['headers']);
830
-
831
-	return $result;
803
+    $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
804
+
805
+    $s = @trim(fgets($handle, 16384));
806
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
807
+        return false;
808
+    }
809
+    $result['status'] = intval($r[1]);
810
+    while ($s = trim(fgets($handle, 16384))) {
811
+        $result['headers'][] = $s . "\n";
812
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813
+        [, $d, $v] = $r;
814
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
815
+            $result['location'] = $v;
816
+        } elseif ($d == 'Last-Modified') {
817
+            $result['last_modified'] = strtotime($v);
818
+        }
819
+    }
820
+    if (
821
+        $if_modified_since
822
+        and $result['last_modified']
823
+        and $if_modified_since > $result['last_modified']
824
+        and $result['status'] == 200
825
+    ) {
826
+        $result['status'] = 304;
827
+    }
828
+
829
+    $result['headers'] = implode('', $result['headers']);
830
+
831
+    return $result;
832 832
 }
833 833
 
834 834
 /**
@@ -850,22 +850,22 @@  discard block
 block discarded – undo
850 850
  *     Nom du fichier pour copie locale
851 851
  **/
852 852
 function nom_fichier_copie_locale($source, $extension) {
853
-	include_spip('inc/documents');
853
+    include_spip('inc/documents');
854 854
 
855
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
856
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
855
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
856
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
857 857
 
858
-	// on se place tout le temps comme si on etait a la racine
859
-	if (_DIR_RACINE) {
860
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
861
-	}
858
+    // on se place tout le temps comme si on etait a la racine
859
+    if (_DIR_RACINE) {
860
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
861
+    }
862 862
 
863
-	$m = md5($source);
863
+    $m = md5($source);
864 864
 
865
-	return $d
866
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
867
-	. substr($m, 0, 4)
868
-	. ".$extension";
865
+    return $d
866
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
867
+    . substr($m, 0, 4)
868
+    . ".$extension";
869 869
 }
870 870
 
871 871
 /**
@@ -884,72 +884,72 @@  discard block
 block discarded – undo
884 884
  *      - null: Copie locale impossible
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
-
951
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
952
-	return null;
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
+
951
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
952
+    return null;
953 953
 }
954 954
 
955 955
 
@@ -978,110 +978,110 @@  discard block
 block discarded – undo
978 978
  **/
979 979
 function recuperer_infos_distantes($source, $options = []) {
980 980
 
981
-	// pas la peine de perdre son temps
982
-	if (!tester_url_absolue($source)) {
983
-		return false;
984
-	}
985
-
986
-	$taille_max = $options['taille_max'] ?? 0;
987
-	$charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
988
-	$callback_valider_url = $options['callback_valider_url'] ?? null;
989
-
990
-	# charger les alias des types mime
991
-	include_spip('base/typedoc');
992
-
993
-	$a = [];
994
-	$mime_type = '';
995
-	// On va directement charger le debut des images et des fichiers html,
996
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
997
-	// ca echoue l'utilisateur devra les entrer...
998
-	$reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
999
-	if (
1000
-		$callback_valider_url
1001
-		and is_callable($callback_valider_url)
1002
-		and !$callback_valider_url($reponse['url'])
1003
-	) {
1004
-		return false;
1005
-	}
1006
-	$headers = $reponse['headers'] ?? '';
1007
-	$a['body'] = $reponse['page'] ?? '';
1008
-	if ($headers) {
1009
-		if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1010
-			return false;
1011
-		}
1012
-
1013
-		$a['extension'] = $extension;
1014
-
1015
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1016
-			$a['taille'] = intval($regs[1]);
1017
-		}
1018
-	}
1019
-
1020
-	// Echec avec HEAD, on tente avec GET
1021
-	if (!$a and !$taille_max) {
1022
-		spip_log("tenter GET $source", 'distant');
1023
-		$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1024
-		$a = recuperer_infos_distantes($source, $options);
1025
-	}
1026
-
1027
-	// si on a rien trouve pas la peine d'insister
1028
-	if (!$a) {
1029
-		return false;
1030
-	}
1031
-
1032
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1033
-	// recharger le document en GET et recuperer des donnees supplementaires...
1034
-	include_spip('inc/filtres_images_lib_mini');
1035
-	if (
1036
-		strpos($mime_type, 'image/') === 0
1037
-		and $extension = _image_trouver_extension_depuis_mime($mime_type)
1038
-	) {
1039
-		if (
1040
-			$taille_max == 0
1041
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1042
-			and in_array($extension, formats_image_acceptables())
1043
-			and $charger_si_petite_image
1044
-		) {
1045
-			$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1046
-			$a = recuperer_infos_distantes($source, $options);
1047
-		} else {
1048
-			if ($a['body']) {
1049
-				$a['extension'] = $extension;
1050
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1051
-				ecrire_fichier($a['fichier'], $a['body']);
1052
-				$size_image = @spip_getimagesize($a['fichier']);
1053
-				$a['largeur'] = intval($size_image[0]);
1054
-				$a['hauteur'] = intval($size_image[1]);
1055
-				$a['type_image'] = true;
1056
-			}
1057
-		}
1058
-	}
1059
-
1060
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1061
-	// ce sera mieux que 0x0
1062
-	// Flash is dead!
1063
-	if (
1064
-		$a and isset($a['extension']) and $a['extension'] == 'swf'
1065
-		and empty($a['largeur'])
1066
-	) {
1067
-		$a['largeur'] = 425;
1068
-		$a['hauteur'] = 350;
1069
-	}
1070
-
1071
-	if ($mime_type == 'text/html') {
1072
-		include_spip('inc/filtres');
1073
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1074
-		$page = $page['page'] ?? '';
1075
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1076
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1077
-		}
1078
-		if (!isset($a['taille']) or !$a['taille']) {
1079
-			$a['taille'] = strlen($page); # a peu pres
1080
-		}
1081
-	}
1082
-	$a['mime_type'] = $mime_type;
1083
-
1084
-	return $a;
981
+    // pas la peine de perdre son temps
982
+    if (!tester_url_absolue($source)) {
983
+        return false;
984
+    }
985
+
986
+    $taille_max = $options['taille_max'] ?? 0;
987
+    $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
988
+    $callback_valider_url = $options['callback_valider_url'] ?? null;
989
+
990
+    # charger les alias des types mime
991
+    include_spip('base/typedoc');
992
+
993
+    $a = [];
994
+    $mime_type = '';
995
+    // On va directement charger le debut des images et des fichiers html,
996
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
997
+    // ca echoue l'utilisateur devra les entrer...
998
+    $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
999
+    if (
1000
+        $callback_valider_url
1001
+        and is_callable($callback_valider_url)
1002
+        and !$callback_valider_url($reponse['url'])
1003
+    ) {
1004
+        return false;
1005
+    }
1006
+    $headers = $reponse['headers'] ?? '';
1007
+    $a['body'] = $reponse['page'] ?? '';
1008
+    if ($headers) {
1009
+        if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1010
+            return false;
1011
+        }
1012
+
1013
+        $a['extension'] = $extension;
1014
+
1015
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1016
+            $a['taille'] = intval($regs[1]);
1017
+        }
1018
+    }
1019
+
1020
+    // Echec avec HEAD, on tente avec GET
1021
+    if (!$a and !$taille_max) {
1022
+        spip_log("tenter GET $source", 'distant');
1023
+        $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1024
+        $a = recuperer_infos_distantes($source, $options);
1025
+    }
1026
+
1027
+    // si on a rien trouve pas la peine d'insister
1028
+    if (!$a) {
1029
+        return false;
1030
+    }
1031
+
1032
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1033
+    // recharger le document en GET et recuperer des donnees supplementaires...
1034
+    include_spip('inc/filtres_images_lib_mini');
1035
+    if (
1036
+        strpos($mime_type, 'image/') === 0
1037
+        and $extension = _image_trouver_extension_depuis_mime($mime_type)
1038
+    ) {
1039
+        if (
1040
+            $taille_max == 0
1041
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1042
+            and in_array($extension, formats_image_acceptables())
1043
+            and $charger_si_petite_image
1044
+        ) {
1045
+            $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1046
+            $a = recuperer_infos_distantes($source, $options);
1047
+        } else {
1048
+            if ($a['body']) {
1049
+                $a['extension'] = $extension;
1050
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1051
+                ecrire_fichier($a['fichier'], $a['body']);
1052
+                $size_image = @spip_getimagesize($a['fichier']);
1053
+                $a['largeur'] = intval($size_image[0]);
1054
+                $a['hauteur'] = intval($size_image[1]);
1055
+                $a['type_image'] = true;
1056
+            }
1057
+        }
1058
+    }
1059
+
1060
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1061
+    // ce sera mieux que 0x0
1062
+    // Flash is dead!
1063
+    if (
1064
+        $a and isset($a['extension']) and $a['extension'] == 'swf'
1065
+        and empty($a['largeur'])
1066
+    ) {
1067
+        $a['largeur'] = 425;
1068
+        $a['hauteur'] = 350;
1069
+    }
1070
+
1071
+    if ($mime_type == 'text/html') {
1072
+        include_spip('inc/filtres');
1073
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1074
+        $page = $page['page'] ?? '';
1075
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1076
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1077
+        }
1078
+        if (!isset($a['taille']) or !$a['taille']) {
1079
+            $a['taille'] = strlen($page); # a peu pres
1080
+        }
1081
+    }
1082
+    $a['mime_type'] = $mime_type;
1083
+
1084
+    return $a;
1085 1085
 }
1086 1086
 
1087 1087
 /**
@@ -1090,70 +1090,70 @@  discard block
 block discarded – undo
1090 1090
  * @return false|mixed
1091 1091
  */
1092 1092
 function distant_trouver_extension_selon_headers($source, $headers) {
1093
-	if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1094
-		$mime_type = (trim($regs[1]));
1095
-	} else {
1096
-		$mime_type = '';
1097
-	} // inconnu
1098
-
1099
-	// Appliquer les alias
1100
-	while (isset($GLOBALS['mime_alias'][$mime_type])) {
1101
-		$mime_type = $GLOBALS['mime_alias'][$mime_type];
1102
-	}
1103
-
1104
-	// pour corriger_extension()
1105
-	include_spip('inc/documents');
1106
-
1107
-	// Si on a un mime-type insignifiant
1108
-	// text/plain,application/octet-stream ou vide
1109
-	// c'est peut-etre que le serveur ne sait pas
1110
-	// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1111
-	// ou le Content-Disposition: attachment; filename=...
1112
-	$t = null;
1113
-	if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1114
-		if (
1115
-			!$t
1116
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117
-		) {
1118
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1119
-		}
1120
-		if (
1121
-			!$t
1122
-			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124
-		) {
1125
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1126
-		}
1127
-	}
1128
-
1129
-	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130
-	if (!$t) {
1131
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1132
-	}
1133
-
1134
-	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1135
-	// On essaie de nouveau avec l'extension
1136
-	if (
1137
-		!$t
1138
-		and $mime_type != 'text/plain'
1139
-		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140
-	) {
1141
-		# eviter xxx.3 => 3gp (> SPIP 3)
1142
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1143
-	}
1144
-
1145
-	if ($t) {
1146
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1147
-		return $t['extension'];
1148
-	} else {
1149
-		# par defaut on retombe sur '.bin' si c'est autorise
1150
-		spip_log("mime-type $mime_type inconnu", 'distant');
1151
-		$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1152
-		if (!$t) {
1153
-			return false;
1154
-		}
1155
-		return $t['extension'];
1156
-	}
1093
+    if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1094
+        $mime_type = (trim($regs[1]));
1095
+    } else {
1096
+        $mime_type = '';
1097
+    } // inconnu
1098
+
1099
+    // Appliquer les alias
1100
+    while (isset($GLOBALS['mime_alias'][$mime_type])) {
1101
+        $mime_type = $GLOBALS['mime_alias'][$mime_type];
1102
+    }
1103
+
1104
+    // pour corriger_extension()
1105
+    include_spip('inc/documents');
1106
+
1107
+    // Si on a un mime-type insignifiant
1108
+    // text/plain,application/octet-stream ou vide
1109
+    // c'est peut-etre que le serveur ne sait pas
1110
+    // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1111
+    // ou le Content-Disposition: attachment; filename=...
1112
+    $t = null;
1113
+    if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1114
+        if (
1115
+            !$t
1116
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117
+        ) {
1118
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1119
+        }
1120
+        if (
1121
+            !$t
1122
+            and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124
+        ) {
1125
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1126
+        }
1127
+    }
1128
+
1129
+    // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130
+    if (!$t) {
1131
+        $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1132
+    }
1133
+
1134
+    // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1135
+    // On essaie de nouveau avec l'extension
1136
+    if (
1137
+        !$t
1138
+        and $mime_type != 'text/plain'
1139
+        and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140
+    ) {
1141
+        # eviter xxx.3 => 3gp (> SPIP 3)
1142
+        $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1143
+    }
1144
+
1145
+    if ($t) {
1146
+        spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1147
+        return $t['extension'];
1148
+    } else {
1149
+        # par defaut on retombe sur '.bin' si c'est autorise
1150
+        spip_log("mime-type $mime_type inconnu", 'distant');
1151
+        $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1152
+        if (!$t) {
1153
+            return false;
1154
+        }
1155
+        return $t['extension'];
1156
+    }
1157 1157
 }
1158 1158
 
1159 1159
 /**
@@ -1169,45 +1169,45 @@  discard block
 block discarded – undo
1169 1169
  */
1170 1170
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1171 1171
 
1172
-	$http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1173
-
1174
-	// rien a faire si pas de proxy :)
1175
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1176
-		return '';
1177
-	}
1178
-
1179
-	if (is_null($http_noproxy)) {
1180
-		$http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1181
-	}
1182
-	// si pas d'exception, on retourne le proxy
1183
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1184
-		return $http_proxy;
1185
-	}
1186
-
1187
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1188
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1189
-	$http_noproxy = str_replace("\n", ' ', $http_noproxy);
1190
-	$http_noproxy = str_replace("\r", ' ', $http_noproxy);
1191
-	$http_noproxy = " $http_noproxy ";
1192
-	$domain = $host;
1193
-	// si le domaine exact www.example.org est dans les exceptions
1194
-	if (strpos($http_noproxy, (string) " $domain ") !== false) {
1195
-		return '';
1196
-	}
1197
-
1198
-	while (strpos($domain, '.') !== false) {
1199
-		$domain = explode('.', $domain);
1200
-		array_shift($domain);
1201
-		$domain = implode('.', $domain);
1202
-
1203
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1204
-		if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1205
-			return '';
1206
-		}
1207
-	}
1208
-
1209
-	// ok c'est pas une exception
1210
-	return $http_proxy;
1172
+    $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1173
+
1174
+    // rien a faire si pas de proxy :)
1175
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1176
+        return '';
1177
+    }
1178
+
1179
+    if (is_null($http_noproxy)) {
1180
+        $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1181
+    }
1182
+    // si pas d'exception, on retourne le proxy
1183
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1184
+        return $http_proxy;
1185
+    }
1186
+
1187
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1188
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1189
+    $http_noproxy = str_replace("\n", ' ', $http_noproxy);
1190
+    $http_noproxy = str_replace("\r", ' ', $http_noproxy);
1191
+    $http_noproxy = " $http_noproxy ";
1192
+    $domain = $host;
1193
+    // si le domaine exact www.example.org est dans les exceptions
1194
+    if (strpos($http_noproxy, (string) " $domain ") !== false) {
1195
+        return '';
1196
+    }
1197
+
1198
+    while (strpos($domain, '.') !== false) {
1199
+        $domain = explode('.', $domain);
1200
+        array_shift($domain);
1201
+        $domain = implode('.', $domain);
1202
+
1203
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1204
+        if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1205
+            return '';
1206
+        }
1207
+    }
1208
+
1209
+    // ok c'est pas une exception
1210
+    return $http_proxy;
1211 1211
 }
1212 1212
 
1213 1213
 
@@ -1230,59 +1230,59 @@  discard block
 block discarded – undo
1230 1230
  * @return array
1231 1231
  */
1232 1232
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1233
-	$user = $via_proxy = $proxy_user = '';
1234
-	$fopen = false;
1235
-
1236
-	$t = @parse_url($url);
1237
-	$host = $t['host'];
1238
-	if ($t['scheme'] == 'http') {
1239
-		$scheme = 'http';
1240
-		$noproxy = '';
1241
-	} elseif ($t['scheme'] == 'https') {
1242
-		$scheme = 'ssl';
1243
-		$noproxy = 'ssl://';
1244
-		if (!isset($t['port']) || !($port = $t['port'])) {
1245
-			$t['port'] = 443;
1246
-		}
1247
-	} else {
1248
-		$scheme = $t['scheme'];
1249
-		$noproxy = $scheme . '://';
1250
-	}
1251
-	if (isset($t['user'])) {
1252
-		$user = [$t['user'], $t['pass']];
1253
-	}
1254
-
1255
-	if (!isset($t['port']) || !($port = $t['port'])) {
1256
-		$port = 80;
1257
-	}
1258
-	if (!isset($t['path']) || !($path = $t['path'])) {
1259
-		$path = '/';
1260
-	}
1261
-
1262
-	if (!empty($t['query'])) {
1263
-		$path .= '?' . $t['query'];
1264
-	}
1265
-
1266
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1267
-	if (!$f or !is_resource($f)) {
1268
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1269
-		// ce qui correspond a $f===110
1270
-		if (
1271
-			$f !== 110
1272
-			and !need_proxy($host)
1273
-			and !_request('tester_proxy')
1274
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1275
-		) {
1276
-			$f = @fopen($url, 'rb');
1277
-			spip_log("connexion vers $url par simple fopen", 'distant');
1278
-			$fopen = true;
1279
-		} else {
1280
-			// echec total
1281
-			$f = false;
1282
-		}
1283
-	}
1284
-
1285
-	return [$f, $fopen];
1233
+    $user = $via_proxy = $proxy_user = '';
1234
+    $fopen = false;
1235
+
1236
+    $t = @parse_url($url);
1237
+    $host = $t['host'];
1238
+    if ($t['scheme'] == 'http') {
1239
+        $scheme = 'http';
1240
+        $noproxy = '';
1241
+    } elseif ($t['scheme'] == 'https') {
1242
+        $scheme = 'ssl';
1243
+        $noproxy = 'ssl://';
1244
+        if (!isset($t['port']) || !($port = $t['port'])) {
1245
+            $t['port'] = 443;
1246
+        }
1247
+    } else {
1248
+        $scheme = $t['scheme'];
1249
+        $noproxy = $scheme . '://';
1250
+    }
1251
+    if (isset($t['user'])) {
1252
+        $user = [$t['user'], $t['pass']];
1253
+    }
1254
+
1255
+    if (!isset($t['port']) || !($port = $t['port'])) {
1256
+        $port = 80;
1257
+    }
1258
+    if (!isset($t['path']) || !($path = $t['path'])) {
1259
+        $path = '/';
1260
+    }
1261
+
1262
+    if (!empty($t['query'])) {
1263
+        $path .= '?' . $t['query'];
1264
+    }
1265
+
1266
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1267
+    if (!$f or !is_resource($f)) {
1268
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1269
+        // ce qui correspond a $f===110
1270
+        if (
1271
+            $f !== 110
1272
+            and !need_proxy($host)
1273
+            and !_request('tester_proxy')
1274
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1275
+        ) {
1276
+            $f = @fopen($url, 'rb');
1277
+            spip_log("connexion vers $url par simple fopen", 'distant');
1278
+            $fopen = true;
1279
+        } else {
1280
+            // echec total
1281
+            $f = false;
1282
+        }
1283
+    }
1284
+
1285
+    return [$f, $fopen];
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1317,124 +1317,124 @@  discard block
 block discarded – undo
1317 1317
  *   resource socket vers l'url demandee
1318 1318
  */
1319 1319
 function lance_requete(
1320
-	$method,
1321
-	$scheme,
1322
-	$user,
1323
-	$host,
1324
-	$path,
1325
-	$port,
1326
-	$noproxy,
1327
-	$refuse_gz = false,
1328
-	$referer = '',
1329
-	$datas = '',
1330
-	$vers = 'HTTP/1.0',
1331
-	$date = ''
1320
+    $method,
1321
+    $scheme,
1322
+    $user,
1323
+    $host,
1324
+    $path,
1325
+    $port,
1326
+    $noproxy,
1327
+    $refuse_gz = false,
1328
+    $referer = '',
1329
+    $datas = '',
1330
+    $vers = 'HTTP/1.0',
1331
+    $date = ''
1332 1332
 ) {
1333 1333
 
1334
-	$proxy_user = '';
1335
-	$http_proxy = need_proxy($host);
1336
-	if ($user) {
1337
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1338
-	}
1339
-
1340
-	$connect = '';
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"
1345
-				. "Host: $path_host\r\n"
1346
-				. "Proxy-Connection: Keep-Alive\r\n";
1347
-		} else {
1348
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1349
-				. (!$user ? '' : "$user@")
1350
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1351
-		}
1352
-		$t2 = @parse_url($http_proxy);
1353
-		$first_host = $t2['host'];
1354
-		$first_port = ($t2['port'] ?? null) ?: 80;
1355
-		if ($t2['user'] ?? null) {
1356
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1357
-		}
1358
-	} else {
1359
-		$first_host = $noproxy . $host;
1360
-		$first_port = $port;
1361
-	}
1362
-
1363
-	if ($connect) {
1364
-		$streamContext = stream_context_create([
1365
-			'ssl' => [
1366
-				'verify_peer' => false,
1367
-				'allow_self_signed' => true,
1368
-				'SNI_enabled' => true,
1369
-				'peer_name' => $host,
1370
-			]
1371
-		]);
1372
-		$f = @stream_socket_client(
1373
-			"tcp://$first_host:$first_port",
1374
-			$errno,
1375
-			$errstr,
1376
-			_INC_DISTANT_CONNECT_TIMEOUT,
1377
-			STREAM_CLIENT_CONNECT,
1378
-			$streamContext
1379
-		);
1380
-		spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381
-		if (!$f) {
1382
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1383
-			return $errno;
1384
-		}
1385
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1386
-
1387
-		fputs($f, $connect);
1388
-		fputs($f, "\r\n");
1389
-		$res = fread($f, 1024);
1390
-		if (
1391
-			!$res
1392
-			or !count($res = explode(' ', $res))
1393
-			or $res[1] !== '200'
1394
-		) {
1395
-			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1396
-			fclose($f);
1397
-
1398
-			return false;
1399
-		}
1400
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1401
-		stream_set_blocking($f, true);
1402
-		// envoyer le handshake
1403
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1404
-		spip_log("OK CONNECT sur $first_host:$first_port", 'connect');
1405
-	} else {
1406
-		$ntry = 3;
1407
-		do {
1408
-			$f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1409
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410
-		spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411
-		if (!$f) {
1412
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1413
-
1414
-			return $errno;
1415
-		}
1416
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1417
-	}
1418
-
1419
-	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1420
-
1421
-	$host_port = $host;
1422
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1423
-		$host_port .= ":$port";
1424
-	}
1425
-	$req = "$method $path $vers\r\n"
1426
-		. "Host: $host_port\r\n"
1427
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1429
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1430
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1432
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1334
+    $proxy_user = '';
1335
+    $http_proxy = need_proxy($host);
1336
+    if ($user) {
1337
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1338
+    }
1339
+
1340
+    $connect = '';
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"
1345
+                . "Host: $path_host\r\n"
1346
+                . "Proxy-Connection: Keep-Alive\r\n";
1347
+        } else {
1348
+            $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1349
+                . (!$user ? '' : "$user@")
1350
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1351
+        }
1352
+        $t2 = @parse_url($http_proxy);
1353
+        $first_host = $t2['host'];
1354
+        $first_port = ($t2['port'] ?? null) ?: 80;
1355
+        if ($t2['user'] ?? null) {
1356
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1357
+        }
1358
+    } else {
1359
+        $first_host = $noproxy . $host;
1360
+        $first_port = $port;
1361
+    }
1362
+
1363
+    if ($connect) {
1364
+        $streamContext = stream_context_create([
1365
+            'ssl' => [
1366
+                'verify_peer' => false,
1367
+                'allow_self_signed' => true,
1368
+                'SNI_enabled' => true,
1369
+                'peer_name' => $host,
1370
+            ]
1371
+        ]);
1372
+        $f = @stream_socket_client(
1373
+            "tcp://$first_host:$first_port",
1374
+            $errno,
1375
+            $errstr,
1376
+            _INC_DISTANT_CONNECT_TIMEOUT,
1377
+            STREAM_CLIENT_CONNECT,
1378
+            $streamContext
1379
+        );
1380
+        spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381
+        if (!$f) {
1382
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1383
+            return $errno;
1384
+        }
1385
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1386
+
1387
+        fputs($f, $connect);
1388
+        fputs($f, "\r\n");
1389
+        $res = fread($f, 1024);
1390
+        if (
1391
+            !$res
1392
+            or !count($res = explode(' ', $res))
1393
+            or $res[1] !== '200'
1394
+        ) {
1395
+            spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1396
+            fclose($f);
1397
+
1398
+            return false;
1399
+        }
1400
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1401
+        stream_set_blocking($f, true);
1402
+        // envoyer le handshake
1403
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1404
+        spip_log("OK CONNECT sur $first_host:$first_port", 'connect');
1405
+    } else {
1406
+        $ntry = 3;
1407
+        do {
1408
+            $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1409
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410
+        spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411
+        if (!$f) {
1412
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1413
+
1414
+            return $errno;
1415
+        }
1416
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1417
+    }
1418
+
1419
+    $site = $GLOBALS['meta']['adresse_site'] ?? '';
1420
+
1421
+    $host_port = $host;
1422
+    if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1423
+        $host_port .= ":$port";
1424
+    }
1425
+    $req = "$method $path $vers\r\n"
1426
+        . "Host: $host_port\r\n"
1427
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1429
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1430
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1432
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1434 1434
 
1435 1435
 #	spip_log("Requete\n$req", 'distant');
1436
-	fputs($f, $req);
1437
-	fputs($f, $datas ?: "\r\n");
1436
+    fputs($f, $req);
1437
+    fputs($f, $datas ?: "\r\n");
1438 1438
 
1439
-	return $f;
1439
+    return $f;
1440 1440
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
28 28
 }
29 29
 if (!defined('_INC_DISTANT_USER_AGENT')) {
30
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
31 31
 }
32 32
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
33 33
 	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
37 37
 }
38 38
 
39
-define('_REGEXP_COPIE_LOCALE', ',' 	.
39
+define('_REGEXP_COPIE_LOCALE', ','.
40 40
 	preg_replace(
41 41
 		'@^https?:@',
42 42
 		'https?:',
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
 	// si c'est la protection de soi-meme, retourner le path
75 75
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
76
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
77 77
 
78 78
 		return @file_exists($source) ? $source : false;
79 79
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		return false;
94 94
 	}
95 95
 
96
-	$localrac = _DIR_RACINE . $local;
96
+	$localrac = _DIR_RACINE.$local;
97 97
 	$t = ($mode === 'force') ? false : @file_exists($localrac);
98 98
 
99 99
 	// test d'existence du fichier
@@ -113,18 +113,18 @@  discard block
 block discarded – undo
113 113
 		if (!$taille_max) {
114 114
 			$taille_max = _COPIE_LOCALE_MAX_SIZE;
115 115
 		}
116
-		$localrac_tmp = $localrac . '.tmp';
116
+		$localrac_tmp = $localrac.'.tmp';
117 117
 		$res = recuperer_url(
118 118
 			$source,
119 119
 			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120 120
 		);
121 121
 
122 122
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
123
+			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE);
124 124
 			@unlink($localrac_tmp);
125 125
 		}
126 126
 		else {
127
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
127
+			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille ".$res['length'].' status '.$res['status'], 'distant');
128 128
 		}
129 129
 		if (!$res or !$res['length']) {
130 130
 			// si $t c'est sans doute juste un not-modified-since
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			and is_callable($callback_valider_url)
138 138
 			and !$callback_valider_url($res['url'])
139 139
 		) {
140
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
140
+			spip_log('copie_locale : url finale '.$res['url']." non valide, on refuse le fichier $localrac_tmp", 'distant'._LOG_INFO_IMPORTANTE);
141 141
 			@unlink($localrac_tmp);
142 142
 			return $t ? $local : false;
143 143
 		}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 	if (!$is_known_host) {
230 230
 		$host = trim($parsed_url['host'], '.');
231
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
231
+		if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) {
232 232
 			$ip = gethostbyname($host);
233 233
 			if ($ip === $host) {
234 234
 				// Error condition for gethostbyname()
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			}
250 250
 		}
251 251
 		if ($ip) {
252
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
252
+			if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253 253
 				return false;
254 254
 			}
255 255
 		}
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	}
261 261
 
262 262
 	$port = $parsed_url['port'];
263
-	if ($port === 80  or $port === 443  or $port === 8080) {
263
+	if ($port === 80 or $port === 443 or $port === 8080) {
264 264
 		return $url;
265 265
 	}
266 266
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 				}
331 331
 			}
332 332
 			if ($taille > 500) {
333
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
333
+				$boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8);
334 334
 			}
335 335
 		}
336 336
 
@@ -358,16 +358,16 @@  discard block
 block discarded – undo
358 358
 			}
359 359
 		} else {
360 360
 			// fabrique une chaine HTTP simple pour un POST
361
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
361
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
362 362
 			$chaine = [];
363 363
 			if (is_array($donnees)) {
364 364
 				foreach ($donnees as $cle => $valeur) {
365 365
 					if (is_array($valeur)) {
366 366
 						foreach ($valeur as $val2) {
367
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
367
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
368 368
 						}
369 369
 					} else {
370
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
370
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
371 371
 					}
372 372
 				}
373 373
 				$chaine = implode('&', $chaine);
@@ -468,13 +468,13 @@  discard block
 block discarded – undo
468 468
 		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469 469
 	}
470 470
 
471
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
471
+	spip_log('recuperer_url '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
472 472
 
473 473
 	// Ajout des en-têtes spécifiques si besoin
474 474
 	$formatted_data = '';
475 475
 	if (!empty($options['headers'])) {
476 476
 		foreach ($options['headers'] as $champ => $valeur) {
477
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
477
+			$formatted_data .= $champ.': '.$valeur."\r\n";
478 478
 		}
479 479
 	}
480 480
 
@@ -482,9 +482,9 @@  discard block
 block discarded – undo
482 482
 		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483 483
 		$head .= $formatted_data;
484 484
 		if (stripos($head, 'Content-Length:') === false) {
485
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
485
+			$head .= 'Content-Length: '.strlen($postdata)."\r\n";
486 486
 		}
487
-		$formatted_data = $head . "\r\n" . $postdata;
487
+		$formatted_data = $head."\r\n".$postdata;
488 488
 		if (
489 489
 			strlen($postdata)
490 490
 			and !$methode_demandee
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499 499
 	$url = preg_replace(',^feed://,i', 'http://', $url);
500 500
 	if (!tester_url_absolue($url)) {
501
-		$url = 'http://' . $url;
501
+		$url = 'http://'.$url;
502 502
 	} elseif (strncmp($url, '//', 2) == 0) {
503
-		$url = 'http:' . $url;
503
+		$url = 'http:'.$url;
504 504
 	}
505 505
 
506 506
 	$url = url_to_ascii($url);
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 		$options['if_modified_since']
530 530
 	);
531 531
 	if (!$handle) {
532
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
532
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
533 533
 
534 534
 		return false;
535 535
 	}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 					'status' => 200,
560 560
 				];
561 561
 			} else {
562
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
562
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
563 563
 				return false;
564 564
 			}
565 565
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 					$options['datas'] = '';
576 576
 				}
577 577
 			}
578
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
578
+			spip_log('recuperer_url recommence '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
579 579
 
580 580
 			return recuperer_url($url, $options);
581 581
 		} elseif ($res['status'] !== 200) {
582
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
582
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
583 583
 		}
584 584
 		$result['status'] = $res['status'];
585 585
 		if (isset($res['headers'])) {
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 
596 596
 	// on ne veut que les entetes
597 597
 	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
598
+		spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG);
599 599
 		return $result;
600 600
 	}
601 601
 
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
 	$gz = false;
607 607
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
608
+		$gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz');
609 609
 	}
610 610
 
611 611
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 
642 642
 	$trace = json_decode(json_encode($result), true);
643 643
 	$trace['page'] = '...';
644
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
644
+	spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG);
645 645
 
646 646
 	return $result;
647 647
 }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	$sig['url'] = $url;
696 696
 
697 697
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
698
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
698
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
699 699
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
700 700
 	$cache = "$sub$cache";
701 701
 
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	$fp = false;
750 750
 	if ($fichier) {
751 751
 		include_spip('inc/acces');
752
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
752
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
753 753
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754 754
 		if (!$fp and file_exists($fichier)) {
755 755
 			return filesize($fichier);
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	}
809 809
 	$result['status'] = intval($r[1]);
810 810
 	while ($s = trim(fgets($handle, 16384))) {
811
-		$result['headers'][] = $s . "\n";
811
+		$result['headers'][] = $s."\n";
812 812
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813 813
 		[, $d, $v] = $r;
814 814
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -857,13 +857,13 @@  discard block
 block discarded – undo
857 857
 
858 858
 	// on se place tout le temps comme si on etait a la racine
859 859
 	if (_DIR_RACINE) {
860
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
860
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
861 861
 	}
862 862
 
863 863
 	$m = md5($source);
864 864
 
865 865
 	return $d
866
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
866
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
867 867
 	. substr($m, 0, 4)
868 868
 	. ".$extension";
869 869
 }
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	// Si c'est deja local pas de souci
888 888
 	if (!tester_url_absolue($source)) {
889 889
 		if (_DIR_RACINE) {
890
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
890
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
891 891
 		}
892 892
 
893 893
 		return $source;
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
 		$ext
906 906
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907 907
 		and $f = nom_fichier_copie_locale($source, $ext)
908
-		and file_exists(_DIR_RACINE . $f)
908
+		and file_exists(_DIR_RACINE.$f)
909 909
 	) {
910 910
 		return $f;
911 911
 	}
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
 
914 914
 	// Si c'est deja dans la table des documents,
915 915
 	// ramener le nom de sa copie potentielle
916
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
916
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
917 917
 
918 918
 	if ($ext) {
919 919
 		return nom_fichier_copie_locale($source, $ext);
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 
925 925
 	$ext = $path_parts ? $path_parts['extension'] : '';
926 926
 
927
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
927
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
928 928
 		$f = nom_fichier_copie_locale($source, $ext);
929
-		if (file_exists(_DIR_RACINE . $f)) {
929
+		if (file_exists(_DIR_RACINE.$f)) {
930 930
 			return $f;
931 931
 		}
932 932
 	}
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	// Ping  pour voir si son extension est connue et autorisee
935 935
 	// avec mise en cache du resultat du ping
936 936
 
937
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
937
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
938 938
 	if (
939 939
 		!@file_exists($cache)
940 940
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
@@ -944,11 +944,11 @@  discard block
 block discarded – undo
944 944
 		ecrire_fichier($cache, serialize($path_parts));
945 945
 	}
946 946
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
947
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
948 948
 		return nom_fichier_copie_locale($source, $ext);
949 949
 	}
950 950
 
951
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
951
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
952 952
 	return null;
953 953
 }
954 954
 
@@ -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
 		$first_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
 		$first_port = $port;
1361 1361
 	}
1362 1362
 
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
 		);
1380 1380
 		spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381 1381
 		if (!$f) {
1382
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1382
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1383 1383
 			return $errno;
1384 1384
 		}
1385 1385
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
 			or !count($res = explode(' ', $res))
1393 1393
 			or $res[1] !== '200'
1394 1394
 		) {
1395
-			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1395
+			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect'._LOG_INFO_IMPORTANTE);
1396 1396
 			fclose($f);
1397 1397
 
1398 1398
 			return false;
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410 1410
 		spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411 1411
 		if (!$f) {
1412
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1412
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1413 1413
 
1414 1414
 			return $errno;
1415 1415
 		}
@@ -1419,16 +1419,16 @@  discard block
 block discarded – undo
1419 1419
 	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1420 1420
 
1421 1421
 	$host_port = $host;
1422
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1422
+	if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) {
1423 1423
 		$host_port .= ":$port";
1424 1424
 	}
1425 1425
 	$req = "$method $path $vers\r\n"
1426 1426
 		. "Host: $host_port\r\n"
1427
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1427
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1428
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1429 1429
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1430
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1430
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1431
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1432 1432
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433 1433
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1434 1434
 
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   +216 added lines, -216 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,64 +80,64 @@  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
-	// Appeler une notification
119
-	if ($notifications = charger_fonction('notifications', 'inc')) {
120
-		$notifications(
121
-			'rubrique_inserer',
122
-			$id_rubrique,
123
-			[
124
-				'id_parent' => $id_parent,
125
-				'champs' => $champs,
126
-			]
127
-		);
128
-		$notifications(
129
-			'objet_inserer',
130
-			$id_rubrique,
131
-			[
132
-				'objet' => 'rubrique',
133
-				'id_objet' => $id_rubrique,
134
-				'id_parent' => $id_parent,
135
-				'champs' => $champs,
136
-			]
137
-		);
138
-	}
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
+    // Appeler une notification
119
+    if ($notifications = charger_fonction('notifications', 'inc')) {
120
+        $notifications(
121
+            'rubrique_inserer',
122
+            $id_rubrique,
123
+            [
124
+                'id_parent' => $id_parent,
125
+                'champs' => $champs,
126
+            ]
127
+        );
128
+        $notifications(
129
+            'objet_inserer',
130
+            $id_rubrique,
131
+            [
132
+                'objet' => 'rubrique',
133
+                'id_objet' => $id_rubrique,
134
+                'id_parent' => $id_parent,
135
+                'champs' => $champs,
136
+            ]
137
+        );
138
+    }
139 139
 	
140
-	return $id_rubrique;
140
+    return $id_rubrique;
141 141
 }
142 142
 
143 143
 /**
@@ -153,46 +153,46 @@  discard block
 block discarded – undo
153 153
  *     - chaîne : texte d'un message d'erreur
154 154
  */
155 155
 function rubrique_modifier($id_rubrique, $set = null) {
156
-	include_spip('inc/autoriser');
157
-	include_spip('inc/filtres');
158
-
159
-	include_spip('inc/modifier');
160
-	$c = collecter_requests(
161
-		// include list
162
-		objet_info('rubrique', 'champs_editables'),
163
-		// exclude list
164
-		['id_parent', 'confirme_deplace'],
165
-		// donnees eventuellement fournies
166
-		$set
167
-	);
168
-
169
-	if (
170
-		$err = objet_modifier_champs(
171
-			'rubrique',
172
-			$id_rubrique,
173
-			[
174
-			'data' => $set,
175
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
176
-			],
177
-			$c
178
-		)
179
-	) {
180
-		return $err;
181
-	}
182
-
183
-	$c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
184
-	// Deplacer la rubrique
185
-	if (isset($c['id_parent'])) {
186
-		$err = rubrique_instituer($id_rubrique, $c);
187
-	}
188
-
189
-	// invalider les caches marques de cette rubrique
190
-	include_spip('inc/invalideur');
191
-	suivre_invalideur("id='rubrique/$id_rubrique'");
192
-	// et celui de menu_rubriques
193
-	effacer_meta('date_calcul_rubriques');
194
-
195
-	return $err;
156
+    include_spip('inc/autoriser');
157
+    include_spip('inc/filtres');
158
+
159
+    include_spip('inc/modifier');
160
+    $c = collecter_requests(
161
+        // include list
162
+        objet_info('rubrique', 'champs_editables'),
163
+        // exclude list
164
+        ['id_parent', 'confirme_deplace'],
165
+        // donnees eventuellement fournies
166
+        $set
167
+    );
168
+
169
+    if (
170
+        $err = objet_modifier_champs(
171
+            'rubrique',
172
+            $id_rubrique,
173
+            [
174
+            'data' => $set,
175
+            'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
176
+            ],
177
+            $c
178
+        )
179
+    ) {
180
+        return $err;
181
+    }
182
+
183
+    $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
184
+    // Deplacer la rubrique
185
+    if (isset($c['id_parent'])) {
186
+        $err = rubrique_instituer($id_rubrique, $c);
187
+    }
188
+
189
+    // invalider les caches marques de cette rubrique
190
+    include_spip('inc/invalideur');
191
+    suivre_invalideur("id='rubrique/$id_rubrique'");
192
+    // et celui de menu_rubriques
193
+    effacer_meta('date_calcul_rubriques');
194
+
195
+    return $err;
196 196
 }
197 197
 
198 198
 /**
@@ -215,29 +215,29 @@  discard block
 block discarded – undo
215 215
  *     false si la confirmation du déplacement n'est pas présente
216 216
  */
217 217
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) {
218
-	if (!sql_table_exists('spip_breves')) {
219
-		return true;
220
-	}
221
-
222
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
223
-		return true;
224
-	}
225
-
226
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
227
-		return false;
228
-	}
229
-
230
-	if (
231
-		$id_secteur = sql_getfetsel(
232
-			'id_secteur',
233
-			'spip_rubriques',
234
-			"id_rubrique=$id_parent"
235
-		)
236
-	) {
237
-		sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
238
-	}
239
-
240
-	return true;
218
+    if (!sql_table_exists('spip_breves')) {
219
+        return true;
220
+    }
221
+
222
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
223
+        return true;
224
+    }
225
+
226
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
227
+        return false;
228
+    }
229
+
230
+    if (
231
+        $id_secteur = sql_getfetsel(
232
+            'id_secteur',
233
+            'spip_rubriques',
234
+            "id_rubrique=$id_parent"
235
+        )
236
+    ) {
237
+        sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
238
+    }
239
+
240
+    return true;
241 241
 }
242 242
 
243 243
 
@@ -259,72 +259,72 @@  discard block
 block discarded – undo
259 259
  *     Chaîne : texte du message d'erreur
260 260
  */
261 261
 function rubrique_instituer($id_rubrique, $c) {
262
-	// traitement de la rubrique parente
263
-	// interdiction de deplacer vers ou a partir d'une rubrique
264
-	// qu'on n'administre pas.
265
-
266
-	if (null !== ($id_parent = $c['id_parent'])) {
267
-		$id_parent = intval($id_parent);
268
-		$filles = calcul_branche_in($id_rubrique);
269
-		if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
270
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
271
-		} else {
272
-			$s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
273
-			$old_parent = $s['id_parent'];
274
-
275
-			if (
276
-				!($id_parent != $old_parent
277
-				and autoriser('publierdans', 'rubrique', $id_parent)
278
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
279
-				and autoriser('publierdans', 'rubrique', $old_parent)
280
-				)
281
-			) {
282
-				if ($s['statut'] != 'prepa') {
283
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
284
-				}
285
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
286
-				$statut_ancien = $s['statut'];
287
-				sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
288
-
289
-
290
-				propager_les_secteurs();
291
-
292
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
293
-				if ($statut_ancien == 'publie') {
294
-					calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
295
-				}
296
-				// Creation ou deplacement d'une rubrique non publiee
297
-				// invalider le cache de leur menu
298
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
299
-					effacer_meta('date_calcul_rubriques');
300
-				}
301
-
302
-				calculer_langues_rubriques();
262
+    // traitement de la rubrique parente
263
+    // interdiction de deplacer vers ou a partir d'une rubrique
264
+    // qu'on n'administre pas.
265
+
266
+    if (null !== ($id_parent = $c['id_parent'])) {
267
+        $id_parent = intval($id_parent);
268
+        $filles = calcul_branche_in($id_rubrique);
269
+        if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
270
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
271
+        } else {
272
+            $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
273
+            $old_parent = $s['id_parent'];
274
+
275
+            if (
276
+                !($id_parent != $old_parent
277
+                and autoriser('publierdans', 'rubrique', $id_parent)
278
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
279
+                and autoriser('publierdans', 'rubrique', $old_parent)
280
+                )
281
+            ) {
282
+                if ($s['statut'] != 'prepa') {
283
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
284
+                }
285
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
286
+                $statut_ancien = $s['statut'];
287
+                sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
288
+
289
+
290
+                propager_les_secteurs();
291
+
292
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
293
+                if ($statut_ancien == 'publie') {
294
+                    calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
295
+                }
296
+                // Creation ou deplacement d'une rubrique non publiee
297
+                // invalider le cache de leur menu
298
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
299
+                    effacer_meta('date_calcul_rubriques');
300
+                }
301
+
302
+                calculer_langues_rubriques();
303 303
 				
304
-				// Appeler une notification
305
-				if ($notifications = charger_fonction('notifications', 'inc')) {
306
-					$notifications(
307
-						'rubrique_instituer',
308
-						$id_rubrique,
309
-						[
310
-							'statut_ancien' => $statut_ancien,
311
-							'id_parent_ancien' => $old_parent,
312
-						]
313
-					);
314
-					$notifications(
315
-						'objet_instituer',
316
-						$id_rubrique,
317
-						[
318
-							'objet' => 'rubrique',
319
-							'id_objet' => $id_rubrique,
320
-							'statut_ancien' => $statut_ancien,
321
-							'id_parent_ancien' => $old_parent,
322
-						]
323
-					);
324
-				}
325
-			}
326
-		}
327
-	}
328
-
329
-	return ''; // pas d'erreur
304
+                // Appeler une notification
305
+                if ($notifications = charger_fonction('notifications', 'inc')) {
306
+                    $notifications(
307
+                        'rubrique_instituer',
308
+                        $id_rubrique,
309
+                        [
310
+                            'statut_ancien' => $statut_ancien,
311
+                            'id_parent_ancien' => $old_parent,
312
+                        ]
313
+                    );
314
+                    $notifications(
315
+                        'objet_instituer',
316
+                        $id_rubrique,
317
+                        [
318
+                            'objet' => 'rubrique',
319
+                            'id_objet' => $id_rubrique,
320
+                            'statut_ancien' => $statut_ancien,
321
+                            'id_parent_ancien' => $old_parent,
322
+                        ]
323
+                    );
324
+                }
325
+            }
326
+        }
327
+    }
328
+
329
+    return ''; // pas d'erreur
330 330
 }
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
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.
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -30,46 +30,46 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
34
-
35
-	mt_srand($seed);
36
-	$s = '';
37
-	$pass = '';
38
-	for ($i = 0; $i < $longueur; $i++) {
39
-		if (!$s) {
40
-			$s = random_int(0, mt_getrandmax());
41
-			if (!$s) {
42
-				$s = random_int(0, mt_getrandmax());
43
-			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
45
-		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
47
-		$x = $r['r'] & 63;
48
-		if ($x < 10) {
49
-			$x = chr($x + 48);
50
-		} else {
51
-			if ($x < 36) {
52
-				$x = chr($x + 55);
53
-			} else {
54
-				if ($x < 62) {
55
-					$x = chr($x + 61);
56
-				} else {
57
-					if ($x == 63) {
58
-						$x = '/';
59
-					} else {
60
-						$x = '.';
61
-					}
62
-				}
63
-			}
64
-		}
65
-		$pass .= $x;
66
-		$s = substr($s, 2);
67
-	}
68
-	$pass = preg_replace('@[./]@', 'a', $pass);
69
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
70
-	$pass = preg_replace('@[0O]@', 'o', $pass);
71
-
72
-	return $pass;
33
+    $seed = (int)round(((float)microtime() + 1) * time());
34
+
35
+    mt_srand($seed);
36
+    $s = '';
37
+    $pass = '';
38
+    for ($i = 0; $i < $longueur; $i++) {
39
+        if (!$s) {
40
+            $s = random_int(0, mt_getrandmax());
41
+            if (!$s) {
42
+                $s = random_int(0, mt_getrandmax());
43
+            }
44
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
45
+        }
46
+        $r = unpack('Cr', pack('H2', $s . $s));
47
+        $x = $r['r'] & 63;
48
+        if ($x < 10) {
49
+            $x = chr($x + 48);
50
+        } else {
51
+            if ($x < 36) {
52
+                $x = chr($x + 55);
53
+            } else {
54
+                if ($x < 62) {
55
+                    $x = chr($x + 61);
56
+                } else {
57
+                    if ($x == 63) {
58
+                        $x = '/';
59
+                    } else {
60
+                        $x = '.';
61
+                    }
62
+                }
63
+            }
64
+        }
65
+        $pass .= $x;
66
+        $s = substr($s, 2);
67
+    }
68
+    $pass = preg_replace('@[./]@', 'a', $pass);
69
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
70
+    $pass = preg_replace('@[0O]@', 'o', $pass);
71
+
72
+    return $pass;
73 73
 }
74 74
 
75 75
 /**
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
  * @return string Identifiant
79 79
  */
80 80
 function creer_uniqid() {
81
-	static $seeded;
81
+    static $seeded;
82 82
 
83
-	if (!$seeded) {
84
-		$seed = (int)round(((float)microtime() + 1) * time());
85
-		mt_srand($seed);
86
-		$seeded = true;
87
-	}
83
+    if (!$seeded) {
84
+        $seed = (int)round(((float)microtime() + 1) * time());
85
+        mt_srand($seed);
86
+        $seeded = true;
87
+    }
88 88
 
89
-	$s = random_int(0, mt_getrandmax());
90
-	if (!$s) {
91
-		$s = random_int(0, mt_getrandmax());
92
-	}
89
+    $s = random_int(0, mt_getrandmax());
90
+    if (!$s) {
91
+        $s = random_int(0, mt_getrandmax());
92
+    }
93 93
 
94
-	return uniqid($s, 1);
94
+    return uniqid($s, 1);
95 95
 }
96 96
 
97 97
 /**
@@ -105,42 +105,42 @@  discard block
 block discarded – undo
105 105
  * @return string Retourne l'alea éphemère actuel au passage
106 106
  */
107 107
 function charger_aleas() {
108
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
109
-		include_spip('base/abstract_sql');
110
-		$aleas = sql_allfetsel(
111
-			['nom', 'valeur'],
112
-			'spip_meta',
113
-			sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
114
-			'',
115
-			'',
116
-			'',
117
-			'',
118
-			'',
119
-			'continue'
120
-		);
121
-		if ($aleas) {
122
-			foreach ($aleas as $a) {
123
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
124
-			}
125
-			return $GLOBALS['meta']['alea_ephemere'];
126
-		} else {
127
-			spip_log('aleas indisponibles', 'session');
128
-			return '';
129
-		}
130
-	}
131
-	return $GLOBALS['meta']['alea_ephemere'];
108
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
109
+        include_spip('base/abstract_sql');
110
+        $aleas = sql_allfetsel(
111
+            ['nom', 'valeur'],
112
+            'spip_meta',
113
+            sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
114
+            '',
115
+            '',
116
+            '',
117
+            '',
118
+            '',
119
+            'continue'
120
+        );
121
+        if ($aleas) {
122
+            foreach ($aleas as $a) {
123
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
124
+            }
125
+            return $GLOBALS['meta']['alea_ephemere'];
126
+        } else {
127
+            spip_log('aleas indisponibles', 'session');
128
+            return '';
129
+        }
130
+    }
131
+    return $GLOBALS['meta']['alea_ephemere'];
132 132
 }
133 133
 
134 134
 /**
135 135
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
136 136
  **/
137 137
 function renouvelle_alea() {
138
-	charger_aleas();
139
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
140
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
141
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
142
-	ecrire_meta('alea_ephemere_date', time(), 'non');
143
-	spip_log("renouvellement de l'alea_ephemere");
138
+    charger_aleas();
139
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
140
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
141
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
142
+    ecrire_meta('alea_ephemere_date', time(), 'non');
143
+    spip_log("renouvellement de l'alea_ephemere");
144 144
 }
145 145
 
146 146
 
@@ -160,21 +160,21 @@  discard block
 block discarded – undo
160 160
  *     Clé de sécurité.
161 161
  **/
162 162
 function low_sec($id_auteur) {
163
-	// Pas d'id_auteur : low_sec
164
-	if (!$id_auteur = intval($id_auteur)) {
165
-		include_spip('inc/config');
166
-		if (!$low_sec = lire_config('low_sec')) {
167
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
168
-		}
169
-	} else {
170
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur));
171
-		if (!$low_sec) {
172
-			$low_sec = creer_pass_aleatoire();
173
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur));
174
-		}
175
-	}
176
-
177
-	return $low_sec;
163
+    // Pas d'id_auteur : low_sec
164
+    if (!$id_auteur = intval($id_auteur)) {
165
+        include_spip('inc/config');
166
+        if (!$low_sec = lire_config('low_sec')) {
167
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
168
+        }
169
+    } else {
170
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur));
171
+        if (!$low_sec) {
172
+            $low_sec = creer_pass_aleatoire();
173
+            sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur));
174
+        }
175
+    }
176
+
177
+    return $low_sec;
178 178
 }
179 179
 
180 180
 
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
  * @filtre
208 208
  */
209 209
 function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') {
210
-	if ($op) {
211
-		$dir .= " $op $args";
212
-	}
210
+    if ($op) {
211
+        $dir .= " $op $args";
212
+    }
213 213
 
214
-	return verifier_low_sec($id_auteur, $cle, $dir);
214
+    return verifier_low_sec($id_auteur, $cle, $dir);
215 215
 }
216 216
 
217 217
 /**
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  * @return string
227 227
  */
228 228
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
229
-	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
230
-	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
231
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
229
+    $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
230
+    $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
231
+    $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
232 232
 
233
-	return generer_url_api($script, $path, $args, $no_entities = false, $public);
233
+    return generer_url_api($script, $path, $args, $no_entities = false, $public);
234 234
 }
235 235
 
236 236
 
@@ -248,27 +248,27 @@  discard block
 block discarded – undo
248 248
  * @deprecated 4.1
249 249
  */
250 250
 function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') {
251
-	$a = $b = '';
252
-	foreach ($args as $val => $var) {
253
-		if ($var) {
254
-			if ($val <> 'statut') {
255
-				$a .= ':' . $val . '-' . $var;
256
-			}
257
-			$b .= $val . '=' . $var . '&';
258
-		}
259
-	}
260
-	$a = substr($a, 1);
261
-	$id = intval(@$GLOBALS['connect_id_auteur']);
262
-
263
-	return $b
264
-	. 'op='
265
-	. $op
266
-	. '&id='
267
-	. $id
268
-	. '&cle='
269
-	. afficher_low_sec($id, "$mime $op $a")
270
-	. (!$a ? '' : "&args=$a")
271
-	. (!$lang ? '' : "&lang=$lang");
251
+    $a = $b = '';
252
+    foreach ($args as $val => $var) {
253
+        if ($var) {
254
+            if ($val <> 'statut') {
255
+                $a .= ':' . $val . '-' . $var;
256
+            }
257
+            $b .= $val . '=' . $var . '&';
258
+        }
259
+    }
260
+    $a = substr($a, 1);
261
+    $id = intval(@$GLOBALS['connect_id_auteur']);
262
+
263
+    return $b
264
+    . 'op='
265
+    . $op
266
+    . '&id='
267
+    . $id
268
+    . '&cle='
269
+    . afficher_low_sec($id, "$mime $op $a")
270
+    . (!$a ? '' : "&args=$a")
271
+    . (!$lang ? '' : "&lang=$lang");
272 272
 }
273 273
 
274 274
 /**
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
  *     Clé
285 285
  **/
286 286
 function afficher_low_sec($id_auteur, $action = '') {
287
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
287
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
288 288
 }
289 289
 
290 290
 /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
  *     true si les clés corresponde, false sinon
303 303
  **/
304 304
 function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') {
305
-	return ($cle == afficher_low_sec($id_auteur, $action));
305
+    return ($cle == afficher_low_sec($id_auteur, $action));
306 306
 }
307 307
 
308 308
 /**
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
  *     Identifiant de l'auteur
313 313
  **/
314 314
 function effacer_low_sec($id_auteur) {
315
-	if (!$id_auteur = intval($id_auteur)) {
316
-		return;
317
-	} // jamais trop prudent ;)
318
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur));
315
+    if (!$id_auteur = intval($id_auteur)) {
316
+        return;
317
+    } // jamais trop prudent ;)
318
+    sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur));
319 319
 }
320 320
 
321 321
 
@@ -333,31 +333,31 @@  discard block
 block discarded – undo
333 333
  *     - void sinon.
334 334
  **/
335 335
 function ecrire_acces() {
336
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
337
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
338
-
339
-	// Cette variable de configuration peut etre posee par un plugin
340
-	// par exemple acces_restreint ;
341
-	// si .htaccess existe, outrepasser spip_meta
342
-	if (
343
-		(!isset($GLOBALS['meta']['creer_htpasswd'])
344
-			or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
345
-		and !@file_exists($htaccess)
346
-	) {
347
-		spip_unlink($htpasswd);
348
-		spip_unlink($htpasswd . '-admin');
349
-		return;
350
-	}
351
-
352
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
353
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
354
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
355
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
356
-	if (include_spip('auth/ldap') and auth_ldap_connect()) {
357
-		return;
358
-	}
359
-
360
-	generer_htpasswd_files($htpasswd, "$htpasswd-admin");
336
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
337
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
338
+
339
+    // Cette variable de configuration peut etre posee par un plugin
340
+    // par exemple acces_restreint ;
341
+    // si .htaccess existe, outrepasser spip_meta
342
+    if (
343
+        (!isset($GLOBALS['meta']['creer_htpasswd'])
344
+            or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
345
+        and !@file_exists($htaccess)
346
+    ) {
347
+        spip_unlink($htpasswd);
348
+        spip_unlink($htpasswd . '-admin');
349
+        return;
350
+    }
351
+
352
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
353
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
354
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
355
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
356
+    if (include_spip('auth/ldap') and auth_ldap_connect()) {
357
+        return;
358
+    }
359
+
360
+    generer_htpasswd_files($htpasswd, "$htpasswd-admin");
361 361
 }
362 362
 
363 363
 /**
@@ -366,29 +366,29 @@  discard block
 block discarded – undo
366 366
  * @param $htpasswd_admin
367 367
  */
368 368
 function generer_htpasswd_files($htpasswd, $htpasswd_admin) {
369
-	if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
370
-		$generer_htpasswd($htpasswd, $htpasswd_admin);
371
-	}
372
-
373
-	$pwd_all = ''; // login:htpass pour tous
374
-	$pwd_admin = ''; // login:htpass pour les admins
375
-
376
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
377
-	while ($row = sql_fetch($res)) {
378
-		if (strlen($row['login']) and strlen($row['htpass'])) {
379
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
380
-			$pwd_all .= $ligne;
381
-			if ($row['statut'] == '0minirezo') {
382
-				$pwd_admin .= $ligne;
383
-			}
384
-		}
385
-	}
386
-
387
-	if ($pwd_all) {
388
-		ecrire_fichier($htpasswd, $pwd_all);
389
-		ecrire_fichier($htpasswd_admin, $pwd_admin);
390
-		spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
391
-	}
369
+    if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
370
+        $generer_htpasswd($htpasswd, $htpasswd_admin);
371
+    }
372
+
373
+    $pwd_all = ''; // login:htpass pour tous
374
+    $pwd_admin = ''; // login:htpass pour les admins
375
+
376
+    $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
377
+    while ($row = sql_fetch($res)) {
378
+        if (strlen($row['login']) and strlen($row['htpass'])) {
379
+            $ligne = $row['login'] . ':' . $row['htpass'] . "\n";
380
+            $pwd_all .= $ligne;
381
+            if ($row['statut'] == '0minirezo') {
382
+                $pwd_admin .= $ligne;
383
+            }
384
+        }
385
+    }
386
+
387
+    if ($pwd_all) {
388
+        ecrire_fichier($htpasswd, $pwd_all);
389
+        ecrire_fichier($htpasswd_admin, $pwd_admin);
390
+        spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
391
+    }
392 392
 }
393 393
 
394 394
 /**
@@ -402,11 +402,11 @@  discard block
 block discarded – undo
402 402
  *  La chaîne hachée si fonction crypt présente, rien sinon.
403 403
  */
404 404
 function generer_htpass(#[\SensitiveParameter] $pass) {
405
-	if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
406
-		return $generer_htpass($pass);
407
-	}
405
+    if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
406
+        return $generer_htpass($pass);
407
+    }
408 408
 
409
-	return '';
409
+    return '';
410 410
 }
411 411
 
412 412
 /**
@@ -419,14 +419,14 @@  discard block
 block discarded – undo
419 419
  * @return boolean
420 420
  */
421 421
 function verifier_htaccess($rep, $force = false) {
422
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
423
-	if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
424
-		return true;
425
-	}
426
-
427
-	// directive deny compatible Apache 2.0+
428
-	$deny =
429
-		'# Deny all requests from Apache 2.4+.
422
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
423
+    if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) {
424
+        return true;
425
+    }
426
+
427
+    // directive deny compatible Apache 2.0+
428
+    $deny =
429
+        '# Deny all requests from Apache 2.4+.
430 430
 <IfModule mod_authz_core.c>
431 431
   Require all denied
432 432
 </IfModule>
@@ -435,32 +435,32 @@  discard block
 block discarded – undo
435 435
   Deny from all
436 436
 </IfModule>
437 437
 ';
438
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
439
-	if (
440
-		function_exists('apache_get_version')
441
-		and $v = apache_get_version()
442
-		and strncmp($v, 'Apache/1.', 9) == 0
443
-	) {
444
-		$deny = "deny from all\n";
445
-	}
446
-
447
-	if ($ht = @fopen($htaccess, 'w')) {
448
-		fputs($ht, $deny);
449
-		fclose($ht);
450
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
451
-		$t = rtrim($rep, '/') . '/.ok';
452
-		if ($ht = @fopen($t, 'w')) {
453
-			@fclose($ht);
454
-			include_spip('inc/distant');
455
-			$t = substr($t, strlen(_DIR_RACINE));
456
-			$t = url_de_base() . $t;
457
-			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
458
-			$ht = ($ht['status'] ?? null) === 403;
459
-		}
460
-	}
461
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
462
-
463
-	return $ht;
438
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
439
+    if (
440
+        function_exists('apache_get_version')
441
+        and $v = apache_get_version()
442
+        and strncmp($v, 'Apache/1.', 9) == 0
443
+    ) {
444
+        $deny = "deny from all\n";
445
+    }
446
+
447
+    if ($ht = @fopen($htaccess, 'w')) {
448
+        fputs($ht, $deny);
449
+        fclose($ht);
450
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
451
+        $t = rtrim($rep, '/') . '/.ok';
452
+        if ($ht = @fopen($t, 'w')) {
453
+            @fclose($ht);
454
+            include_spip('inc/distant');
455
+            $t = substr($t, strlen(_DIR_RACINE));
456
+            $t = url_de_base() . $t;
457
+            $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
458
+            $ht = ($ht['status'] ?? null) === 403;
459
+        }
460
+    }
461
+    spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
462
+
463
+    return $ht;
464 464
 }
465 465
 
466 466
 /**
@@ -478,20 +478,20 @@  discard block
 block discarded – undo
478 478
  *         Valeur de la configuration `creer_htaccess`
479 479
  */
480 480
 function gerer_htaccess() {
481
-	// Cette variable de configuration peut etre posee par un plugin
482
-	// par exemple acces_restreint
483
-	$f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui'));
484
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
485
-	$dirs[] = ['extension' => 'distant'];
486
-	foreach ($dirs as $e) {
487
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
488
-			if ($f) {
489
-				verifier_htaccess($dir);
490
-			} else {
491
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
492
-			}
493
-		}
494
-	}
495
-
496
-	return $GLOBALS['meta']['creer_htaccess'] ?? '';
481
+    // Cette variable de configuration peut etre posee par un plugin
482
+    // par exemple acces_restreint
483
+    $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui'));
484
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
485
+    $dirs[] = ['extension' => 'distant'];
486
+    foreach ($dirs as $e) {
487
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
488
+            if ($f) {
489
+                verifier_htaccess($dir);
490
+            } else {
491
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
492
+            }
493
+        }
494
+    }
495
+
496
+    return $GLOBALS['meta']['creer_htaccess'] ?? '';
497 497
 }
Please login to merge, or discard this patch.
ecrire/inc/config.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -312,8 +312,7 @@
 block discarded – undo
312 312
 					ecrire_meta($casier, $serialized_store, null, $table);
313 313
 				}
314 314
 			}
315
-		}
316
-		else {
315
+		} else {
317 316
 			ecrire_meta($casier, $store, null, $table);
318 317
 		}
319 318
 	}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -303,9 +303,9 @@
 block discarded – undo
303 303
 			// et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine
304 304
 			// car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4)
305 305
 			if ($has_planes) {
306
-				$check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier));
306
+				$check_store = sql_getfetsel('valeur', 'spip_'.$table, 'nom='.sql_quote($casier));
307 307
 				if ($check_store !== $serialized_store) {
308
-					array_walk_recursive($store, function (&$value, $key) {
308
+					array_walk_recursive($store, function(&$value, $key) {
309 309
 						if (is_string($value)) {
310 310
 							$value = utf8_noplanes($value);
311 311
 						}
Please login to merge, or discard this patch.
Indentation   +352 added lines, -352 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
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * @return void
29 29
  */
30 30
 function inc_config_dist() {
31
-	actualise_metas(liste_metas());
31
+    actualise_metas(liste_metas());
32 32
 }
33 33
 
34 34
 /**
@@ -45,34 +45,34 @@  discard block
 block discarded – undo
45 45
  *     Liste (table, casier, sous_casier)
46 46
  */
47 47
 function expliquer_config($cfg) {
48
-	// par defaut, sur la table des meta
49
-	$table = 'meta';
50
-	$casier = null;
51
-	$sous_casier = [];
52
-	$cfg = explode('/', $cfg);
53
-
54
-	// si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide ''
55
-	if (!reset($cfg) and count($cfg) > 1) {
56
-		array_shift($cfg);
57
-		$table = array_shift($cfg);
58
-		if (!isset($GLOBALS[$table])) {
59
-			lire_metas($table);
60
-		}
61
-	}
62
-
63
-	// si on a demande #CONFIG{/meta,'',0}
64
-	if (count($cfg)) {
65
-		// pas sur un appel vide ''
66
-		if ('' !== ($c = array_shift($cfg))) {
67
-			$casier = $c;
68
-		}
69
-	}
70
-
71
-	if (count($cfg)) {
72
-		$sous_casier = $cfg;
73
-	}
74
-
75
-	return [$table, $casier, $sous_casier];
48
+    // par defaut, sur la table des meta
49
+    $table = 'meta';
50
+    $casier = null;
51
+    $sous_casier = [];
52
+    $cfg = explode('/', $cfg);
53
+
54
+    // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide ''
55
+    if (!reset($cfg) and count($cfg) > 1) {
56
+        array_shift($cfg);
57
+        $table = array_shift($cfg);
58
+        if (!isset($GLOBALS[$table])) {
59
+            lire_metas($table);
60
+        }
61
+    }
62
+
63
+    // si on a demande #CONFIG{/meta,'',0}
64
+    if (count($cfg)) {
65
+        // pas sur un appel vide ''
66
+        if ('' !== ($c = array_shift($cfg))) {
67
+            $casier = $c;
68
+        }
69
+    }
70
+
71
+    if (count($cfg)) {
72
+        $sous_casier = $cfg;
73
+    }
74
+
75
+    return [$table, $casier, $sous_casier];
76 76
 }
77 77
 
78 78
 /**
@@ -100,65 +100,65 @@  discard block
 block discarded – undo
100 100
  *    Contenu de la configuration obtenue
101 101
  */
102 102
 function lire_config($cfg = '', $def = null, $unserialize = true) {
103
-	// lire le stockage sous la forme /table/valeur
104
-	// ou valeur qui est en fait implicitement /meta/valeur
105
-	// ou casier/valeur qui est en fait implicitement /meta/casier/valeur
106
-
107
-	// traiter en priorite le cas simple et frequent
108
-	// de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni :
109
-	if ($cfg and strpbrk($cfg, '/:') === false) {
110
-		$r = isset($GLOBALS['meta'][$cfg]) ?
111
-			((!$unserialize
112
-				// ne pas essayer de deserialiser autre chose qu'une chaine
113
-				or !is_string($GLOBALS['meta'][$cfg])
114
-				// ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee
115
-				or !str_contains($GLOBALS['meta'][$cfg], ':')
116
-				or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t)
117
-			: $def;
118
-
119
-		return $r;
120
-	}
121
-
122
-	// Brancher sur methodes externes si besoin
123
-	if ($cfg and $p = strpos($cfg, '::')) {
124
-		$methode = substr($cfg, 0, $p);
125
-		$lire_config = charger_fonction($methode, 'lire_config');
126
-
127
-		return $lire_config(substr($cfg, $p + 2), $def, $unserialize);
128
-	}
129
-
130
-	[$table, $casier, $sous_casier] = expliquer_config($cfg);
131
-
132
-	if (!isset($GLOBALS[$table])) {
133
-		return $def;
134
-	}
135
-
136
-	$r = $GLOBALS[$table];
137
-
138
-	// si on a demande #CONFIG{/meta,'',0}
139
-	if (!$casier) {
140
-		return $unserialize ? $r : serialize($r);
141
-	}
142
-
143
-	// casier principal :
144
-	// le deserializer si demande
145
-	// ou si on a besoin
146
-	// d'un sous casier
147
-	$r = $r[$casier] ?? null;
148
-	if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) {
149
-		$r = (($t = @unserialize($r)) === false ? $r : $t);
150
-	}
151
-
152
-	// aller chercher le sous_casier
153
-	while (!is_null($r) and $casier = array_shift($sous_casier)) {
154
-		$r = $r[$casier] ?? null;
155
-	}
156
-
157
-	if (is_null($r)) {
158
-		return $def;
159
-	}
160
-
161
-	return $r;
103
+    // lire le stockage sous la forme /table/valeur
104
+    // ou valeur qui est en fait implicitement /meta/valeur
105
+    // ou casier/valeur qui est en fait implicitement /meta/casier/valeur
106
+
107
+    // traiter en priorite le cas simple et frequent
108
+    // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni :
109
+    if ($cfg and strpbrk($cfg, '/:') === false) {
110
+        $r = isset($GLOBALS['meta'][$cfg]) ?
111
+            ((!$unserialize
112
+                // ne pas essayer de deserialiser autre chose qu'une chaine
113
+                or !is_string($GLOBALS['meta'][$cfg])
114
+                // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee
115
+                or !str_contains($GLOBALS['meta'][$cfg], ':')
116
+                or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t)
117
+            : $def;
118
+
119
+        return $r;
120
+    }
121
+
122
+    // Brancher sur methodes externes si besoin
123
+    if ($cfg and $p = strpos($cfg, '::')) {
124
+        $methode = substr($cfg, 0, $p);
125
+        $lire_config = charger_fonction($methode, 'lire_config');
126
+
127
+        return $lire_config(substr($cfg, $p + 2), $def, $unserialize);
128
+    }
129
+
130
+    [$table, $casier, $sous_casier] = expliquer_config($cfg);
131
+
132
+    if (!isset($GLOBALS[$table])) {
133
+        return $def;
134
+    }
135
+
136
+    $r = $GLOBALS[$table];
137
+
138
+    // si on a demande #CONFIG{/meta,'',0}
139
+    if (!$casier) {
140
+        return $unserialize ? $r : serialize($r);
141
+    }
142
+
143
+    // casier principal :
144
+    // le deserializer si demande
145
+    // ou si on a besoin
146
+    // d'un sous casier
147
+    $r = $r[$casier] ?? null;
148
+    if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) {
149
+        $r = (($t = @unserialize($r)) === false ? $r : $t);
150
+    }
151
+
152
+    // aller chercher le sous_casier
153
+    while (!is_null($r) and $casier = array_shift($sous_casier)) {
154
+        $r = $r[$casier] ?? null;
155
+    }
156
+
157
+    if (is_null($r)) {
158
+        return $def;
159
+    }
160
+
161
+    return $r;
162 162
 }
163 163
 
164 164
 /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
  * @return mixed
173 173
  */
174 174
 function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) {
175
-	return lire_config($cfg, $def, $unserialize);
175
+    return lire_config($cfg, $def, $unserialize);
176 176
 }
177 177
 
178 178
 
@@ -184,144 +184,144 @@  discard block
 block discarded – undo
184 184
  * @return bool
185 185
  */
186 186
 function ecrire_config($cfg, $store) {
187
-	// Brancher sur methodes externes si besoin
188
-	if ($cfg and $p = strpos($cfg, '::')) {
189
-		$methode = substr($cfg, 0, $p);
190
-		$ecrire_config = charger_fonction($methode, 'ecrire_config');
191
-
192
-		return $ecrire_config(substr($cfg, $p + 2), $store);
193
-	}
194
-
195
-	[$table, $casier, $sous_casier] = expliquer_config($cfg);
196
-	// il faut au moins un casier pour ecrire
197
-	if (!$casier) {
198
-		return false;
199
-	}
200
-
201
-	// trouvons ou creons le pointeur sur le casier
202
-	$st = $GLOBALS[$table][$casier] ?? null;
203
-	if (!is_array($st) and ($sous_casier or is_array($store))) {
204
-		if ($st === null) {
205
-			// ne rien creer si c'est une demande d'effacement
206
-			if ($store === null) {
207
-				return false;
208
-			}
209
-			$st = [];
210
-		} else {
211
-			$st = unserialize($st);
212
-			if ($st === false) {
213
-				// ne rien creer si c'est une demande d'effacement
214
-				if ($store === null) {
215
-					return false;
216
-				}
217
-				$st = [];
218
-			}
219
-		}
220
-	}
221
-
222
-	$has_planes = false;
223
-	// si on a affaire a un sous caiser
224
-	// il faut ecrire au bon endroit sans perdre les autres sous casier freres
225
-	if ($c = $sous_casier) {
226
-		$sc = &$st;
227
-		$pointeurs = [];
228
-		while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) {
229
-			// creer l'entree si elle n'existe pas
230
-			if (!isset($sc[$cc])) {
231
-				// si on essaye d'effacer une config qui n'existe pas
232
-				// ne rien creer mais sortir
233
-				if (is_null($store)) {
234
-					return false;
235
-				}
236
-				$sc[$cc] = [];
237
-			}
238
-			$pointeurs[$cc] = &$sc;
239
-			$sc = &$sc[$cc];
240
-		}
241
-
242
-		// si c'est une demande d'effacement
243
-		if (is_null($store)) {
244
-			$c = $sous_casier;
245
-			$sous = array_pop($c);
246
-			// effacer, et remonter pour effacer les parents vides
247
-			do {
248
-				unset($pointeurs[$sous][$sous]);
249
-			} while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0));
250
-
251
-			// si on a vide tous les sous casiers,
252
-			// et que le casier est vide
253
-			// vider aussi la meta
254
-			if (!$sous and !(is_countable($st) ? count($st) : 0)) {
255
-				$st = null;
256
-			}
257
-		} // dans tous les autres cas, on ecrase
258
-		else {
259
-			if (
260
-					defined('_MYSQL_NOPLANES')
261
-				and _MYSQL_NOPLANES
262
-				and !empty($GLOBALS['meta']['charset_sql_connexion'])
263
-				and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8'
264
-			) {
265
-				// detecter si la valeur qu'on veut ecrire a des planes
266
-				// @see utf8_noplanes
267
-				$serialized_store = (is_string($store) ? $store : serialize($store));
268
-				// un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes
269
-				if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) {
270
-					if (!function_exists('utf8_noplanes')) {
271
-						include_spip('inc/charsets');
272
-					}
273
-					if ($serialized_store !== utf8_noplanes($serialized_store)) {
274
-						$has_planes = true;
275
-					}
276
-				}
277
-			}
278
-
279
-			$sc = $store;
280
-		}
281
-
282
-		// Maintenant que $st est modifiee
283
-		// reprenons la comme valeur a stocker dans le casier principal
284
-		$store = $st;
285
-	}
286
-
287
-	if (is_null($store)) {
288
-		if (is_null($st) and !$sous_casier) {
289
-			return false;
290
-		} // la config n'existait deja pas !
291
-		effacer_meta($casier, $table);
292
-		supprimer_table_meta($table); // supprimons la table (si elle est bien vide)
293
-	} // les meta ne peuvent etre que des chaines : il faut serializer le reste
294
-	else {
295
-		if (!isset($GLOBALS[$table])) {
296
-			installer_table_meta($table);
297
-		}
298
-		// si ce n'est pas une chaine
299
-		// il faut serializer
300
-		if (!is_string($store)) {
301
-			$serialized_store = serialize($store);
302
-			ecrire_meta($casier, $serialized_store, null, $table);
303
-			// et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine
304
-			// car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4)
305
-			if ($has_planes) {
306
-				$check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier));
307
-				if ($check_store !== $serialized_store) {
308
-					array_walk_recursive($store, function (&$value, $key) {
309
-						if (is_string($value)) {
310
-							$value = utf8_noplanes($value);
311
-						}
312
-					});
313
-					$serialized_store = serialize($store);
314
-					ecrire_meta($casier, $serialized_store, null, $table);
315
-				}
316
-			}
317
-		}
318
-		else {
319
-			ecrire_meta($casier, $store, null, $table);
320
-		}
321
-	}
322
-
323
-	// verifier que lire_config($cfg)==$store ?
324
-	return true;
187
+    // Brancher sur methodes externes si besoin
188
+    if ($cfg and $p = strpos($cfg, '::')) {
189
+        $methode = substr($cfg, 0, $p);
190
+        $ecrire_config = charger_fonction($methode, 'ecrire_config');
191
+
192
+        return $ecrire_config(substr($cfg, $p + 2), $store);
193
+    }
194
+
195
+    [$table, $casier, $sous_casier] = expliquer_config($cfg);
196
+    // il faut au moins un casier pour ecrire
197
+    if (!$casier) {
198
+        return false;
199
+    }
200
+
201
+    // trouvons ou creons le pointeur sur le casier
202
+    $st = $GLOBALS[$table][$casier] ?? null;
203
+    if (!is_array($st) and ($sous_casier or is_array($store))) {
204
+        if ($st === null) {
205
+            // ne rien creer si c'est une demande d'effacement
206
+            if ($store === null) {
207
+                return false;
208
+            }
209
+            $st = [];
210
+        } else {
211
+            $st = unserialize($st);
212
+            if ($st === false) {
213
+                // ne rien creer si c'est une demande d'effacement
214
+                if ($store === null) {
215
+                    return false;
216
+                }
217
+                $st = [];
218
+            }
219
+        }
220
+    }
221
+
222
+    $has_planes = false;
223
+    // si on a affaire a un sous caiser
224
+    // il faut ecrire au bon endroit sans perdre les autres sous casier freres
225
+    if ($c = $sous_casier) {
226
+        $sc = &$st;
227
+        $pointeurs = [];
228
+        while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) {
229
+            // creer l'entree si elle n'existe pas
230
+            if (!isset($sc[$cc])) {
231
+                // si on essaye d'effacer une config qui n'existe pas
232
+                // ne rien creer mais sortir
233
+                if (is_null($store)) {
234
+                    return false;
235
+                }
236
+                $sc[$cc] = [];
237
+            }
238
+            $pointeurs[$cc] = &$sc;
239
+            $sc = &$sc[$cc];
240
+        }
241
+
242
+        // si c'est une demande d'effacement
243
+        if (is_null($store)) {
244
+            $c = $sous_casier;
245
+            $sous = array_pop($c);
246
+            // effacer, et remonter pour effacer les parents vides
247
+            do {
248
+                unset($pointeurs[$sous][$sous]);
249
+            } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0));
250
+
251
+            // si on a vide tous les sous casiers,
252
+            // et que le casier est vide
253
+            // vider aussi la meta
254
+            if (!$sous and !(is_countable($st) ? count($st) : 0)) {
255
+                $st = null;
256
+            }
257
+        } // dans tous les autres cas, on ecrase
258
+        else {
259
+            if (
260
+                    defined('_MYSQL_NOPLANES')
261
+                and _MYSQL_NOPLANES
262
+                and !empty($GLOBALS['meta']['charset_sql_connexion'])
263
+                and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8'
264
+            ) {
265
+                // detecter si la valeur qu'on veut ecrire a des planes
266
+                // @see utf8_noplanes
267
+                $serialized_store = (is_string($store) ? $store : serialize($store));
268
+                // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes
269
+                if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) {
270
+                    if (!function_exists('utf8_noplanes')) {
271
+                        include_spip('inc/charsets');
272
+                    }
273
+                    if ($serialized_store !== utf8_noplanes($serialized_store)) {
274
+                        $has_planes = true;
275
+                    }
276
+                }
277
+            }
278
+
279
+            $sc = $store;
280
+        }
281
+
282
+        // Maintenant que $st est modifiee
283
+        // reprenons la comme valeur a stocker dans le casier principal
284
+        $store = $st;
285
+    }
286
+
287
+    if (is_null($store)) {
288
+        if (is_null($st) and !$sous_casier) {
289
+            return false;
290
+        } // la config n'existait deja pas !
291
+        effacer_meta($casier, $table);
292
+        supprimer_table_meta($table); // supprimons la table (si elle est bien vide)
293
+    } // les meta ne peuvent etre que des chaines : il faut serializer le reste
294
+    else {
295
+        if (!isset($GLOBALS[$table])) {
296
+            installer_table_meta($table);
297
+        }
298
+        // si ce n'est pas une chaine
299
+        // il faut serializer
300
+        if (!is_string($store)) {
301
+            $serialized_store = serialize($store);
302
+            ecrire_meta($casier, $serialized_store, null, $table);
303
+            // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine
304
+            // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4)
305
+            if ($has_planes) {
306
+                $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier));
307
+                if ($check_store !== $serialized_store) {
308
+                    array_walk_recursive($store, function (&$value, $key) {
309
+                        if (is_string($value)) {
310
+                            $value = utf8_noplanes($value);
311
+                        }
312
+                    });
313
+                    $serialized_store = serialize($store);
314
+                    ecrire_meta($casier, $serialized_store, null, $table);
315
+                }
316
+            }
317
+        }
318
+        else {
319
+            ecrire_meta($casier, $store, null, $table);
320
+        }
321
+    }
322
+
323
+    // verifier que lire_config($cfg)==$store ?
324
+    return true;
325 325
 }
326 326
 
327 327
 
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
  * @return bool
336 336
  */
337 337
 function ecrire_config_metapack_dist($cfg, $store) {
338
-	// cas particulier en metapack::
339
-	// si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre
340
-	// intacte en sortie ...
341
-	if (is_string($store) and strpos($store, ':') and unserialize($store)) {
342
-		$store = serialize($store);
343
-	}
344
-
345
-	return ecrire_config($cfg, $store);
338
+    // cas particulier en metapack::
339
+    // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre
340
+    // intacte en sortie ...
341
+    if (is_string($store) and strpos($store, ':') and unserialize($store)) {
342
+        $store = serialize($store);
343
+    }
344
+
345
+    return ecrire_config($cfg, $store);
346 346
 }
347 347
 
348 348
 /**
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
  * @return bool
353 353
  */
354 354
 function effacer_config($cfg) {
355
-	ecrire_config($cfg, null);
355
+    ecrire_config($cfg, null);
356 356
 
357
-	return true;
357
+    return true;
358 358
 }
359 359
 
360 360
 /**
@@ -371,58 +371,58 @@  discard block
 block discarded – undo
371 371
  *    Couples nom de la `meta` => valeur par défaut
372 372
  */
373 373
 function liste_metas() {
374
-	return pipeline('configurer_liste_metas', [
375
-		'nom_site' => _T('info_mon_site_spip'),
376
-		'slogan_site' => '',
377
-		'adresse_site' => preg_replace(',/$,', '', url_de_base()),
378
-		'descriptif_site' => '',
379
-		'activer_logos' => 'oui',
380
-		'activer_logos_survol' => 'non',
381
-		'articles_surtitre' => 'non',
382
-		'articles_soustitre' => 'non',
383
-		'articles_descriptif' => 'non',
384
-		'articles_chapeau' => 'non',
385
-		'articles_texte' => 'oui',
386
-		'articles_ps' => 'non',
387
-		'articles_redac' => 'non',
388
-		'post_dates' => 'non',
389
-		'articles_urlref' => 'non',
390
-		'articles_redirection' => 'non',
391
-		'creer_preview' => 'non',
392
-		'taille_preview' => 150,
393
-		'articles_modif' => 'non',
394
-
395
-		'rubriques_descriptif' => 'non',
396
-		'rubriques_texte' => 'oui',
397
-
398
-		'accepter_inscriptions' => 'non',
399
-		'accepter_visiteurs' => 'non',
400
-		'prevenir_auteurs' => 'non',
401
-		'suivi_edito' => 'non',
402
-		'adresse_suivi' => '',
403
-		'adresse_suivi_inscription' => '',
404
-		'adresse_neuf' => '',
405
-		'jours_neuf' => '',
406
-		'quoi_de_neuf' => 'non',
407
-		'preview' => ',0minirezo,1comite,',
408
-
409
-		'syndication_integrale' => 'oui',
410
-		'charset' => _DEFAULT_CHARSET,
411
-		'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)),
412
-
413
-		'multi_rubriques' => 'non',
414
-		'multi_secteurs' => 'non',
415
-		'gerer_trad' => 'non',
416
-		'langues_multilingue' => '',
417
-
418
-		'version_html_max' => 'html4',
419
-
420
-		'type_urls' => 'page',
421
-
422
-		'email_envoi' => '',
423
-		'email_webmaster' => '',
424
-		'auto_compress_http' => 'non',
425
-	]);
374
+    return pipeline('configurer_liste_metas', [
375
+        'nom_site' => _T('info_mon_site_spip'),
376
+        'slogan_site' => '',
377
+        'adresse_site' => preg_replace(',/$,', '', url_de_base()),
378
+        'descriptif_site' => '',
379
+        'activer_logos' => 'oui',
380
+        'activer_logos_survol' => 'non',
381
+        'articles_surtitre' => 'non',
382
+        'articles_soustitre' => 'non',
383
+        'articles_descriptif' => 'non',
384
+        'articles_chapeau' => 'non',
385
+        'articles_texte' => 'oui',
386
+        'articles_ps' => 'non',
387
+        'articles_redac' => 'non',
388
+        'post_dates' => 'non',
389
+        'articles_urlref' => 'non',
390
+        'articles_redirection' => 'non',
391
+        'creer_preview' => 'non',
392
+        'taille_preview' => 150,
393
+        'articles_modif' => 'non',
394
+
395
+        'rubriques_descriptif' => 'non',
396
+        'rubriques_texte' => 'oui',
397
+
398
+        'accepter_inscriptions' => 'non',
399
+        'accepter_visiteurs' => 'non',
400
+        'prevenir_auteurs' => 'non',
401
+        'suivi_edito' => 'non',
402
+        'adresse_suivi' => '',
403
+        'adresse_suivi_inscription' => '',
404
+        'adresse_neuf' => '',
405
+        'jours_neuf' => '',
406
+        'quoi_de_neuf' => 'non',
407
+        'preview' => ',0minirezo,1comite,',
408
+
409
+        'syndication_integrale' => 'oui',
410
+        'charset' => _DEFAULT_CHARSET,
411
+        'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)),
412
+
413
+        'multi_rubriques' => 'non',
414
+        'multi_secteurs' => 'non',
415
+        'gerer_trad' => 'non',
416
+        'langues_multilingue' => '',
417
+
418
+        'version_html_max' => 'html4',
419
+
420
+        'type_urls' => 'page',
421
+
422
+        'email_envoi' => '',
423
+        'email_webmaster' => '',
424
+        'auto_compress_http' => 'non',
425
+    ]);
426 426
 }
427 427
 
428 428
 /**
@@ -433,43 +433,43 @@  discard block
 block discarded – undo
433 433
  * @return void
434 434
  */
435 435
 function actualise_metas($liste_meta) {
436
-	$meta_serveur =
437
-		[
438
-			'version_installee',
439
-			'adresse_site',
440
-			'alea_ephemere_ancien',
441
-			'alea_ephemere',
442
-			'alea_ephemere_date',
443
-			'langue_site',
444
-			'langues_proposees',
445
-			'date_calcul_rubriques',
446
-			'derniere_modif',
447
-			'optimiser_table',
448
-			'drapeau_edition',
449
-			'creer_preview',
450
-			'taille_preview',
451
-			'creer_htpasswd',
452
-			'creer_htaccess',
453
-			'gd_formats_read',
454
-			'gd_formats',
455
-			'netpbm_formats',
456
-			'formats_graphiques',
457
-			'image_process',
458
-			'plugin_header',
459
-			'plugin'
460
-		];
461
-	// verifier le impt=non
462
-	sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur));
463
-
464
-	foreach ($liste_meta as $nom => $valeur) {
465
-		if (empty($GLOBALS['meta'][$nom])) {
466
-			ecrire_meta($nom, $valeur);
467
-		}
468
-	}
469
-
470
-	include_spip('inc/rubriques');
471
-	$langues = calculer_langues_utilisees();
472
-	ecrire_meta('langues_utilisees', $langues);
436
+    $meta_serveur =
437
+        [
438
+            'version_installee',
439
+            'adresse_site',
440
+            'alea_ephemere_ancien',
441
+            'alea_ephemere',
442
+            'alea_ephemere_date',
443
+            'langue_site',
444
+            'langues_proposees',
445
+            'date_calcul_rubriques',
446
+            'derniere_modif',
447
+            'optimiser_table',
448
+            'drapeau_edition',
449
+            'creer_preview',
450
+            'taille_preview',
451
+            'creer_htpasswd',
452
+            'creer_htaccess',
453
+            'gd_formats_read',
454
+            'gd_formats',
455
+            'netpbm_formats',
456
+            'formats_graphiques',
457
+            'image_process',
458
+            'plugin_header',
459
+            'plugin'
460
+        ];
461
+    // verifier le impt=non
462
+    sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur));
463
+
464
+    foreach ($liste_meta as $nom => $valeur) {
465
+        if (empty($GLOBALS['meta'][$nom])) {
466
+            ecrire_meta($nom, $valeur);
467
+        }
468
+    }
469
+
470
+    include_spip('inc/rubriques');
471
+    $langues = calculer_langues_utilisees();
472
+    ecrire_meta('langues_utilisees', $langues);
473 473
 }
474 474
 
475 475
 
@@ -491,18 +491,18 @@  discard block
 block discarded – undo
491 491
  */
492 492
 function appliquer_modifs_config($purger_skel = false) {
493 493
 
494
-	foreach (liste_metas() as $i => $v) {
495
-		if (($x = _request($i)) !== null) {
496
-			ecrire_meta($i, $x);
497
-		} elseif (!isset($GLOBALS['meta'][$i])) {
498
-			ecrire_meta($i, $v);
499
-		}
500
-	}
501
-
502
-	if ($purger_skel) {
503
-		include_spip('inc/invalideur');
504
-		purger_repertoire(_DIR_SKELS);
505
-	}
494
+    foreach (liste_metas() as $i => $v) {
495
+        if (($x = _request($i)) !== null) {
496
+            ecrire_meta($i, $x);
497
+        } elseif (!isset($GLOBALS['meta'][$i])) {
498
+            ecrire_meta($i, $v);
499
+        }
500
+    }
501
+
502
+    if ($purger_skel) {
503
+        include_spip('inc/invalideur');
504
+        purger_repertoire(_DIR_SKELS);
505
+    }
506 506
 }
507 507
 
508 508
 /**
@@ -513,21 +513,21 @@  discard block
 block discarded – undo
513 513
  * @return string
514 514
  */
515 515
 function appliquer_adresse_site($adresse_site) {
516
-	if ($adresse_site !== null) {
517
-		if (!strlen($adresse_site)) {
518
-			$GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1;
519
-			$adresse_site = url_de_base();
520
-		}
521
-		$adresse_site = preg_replace(',/?\s*$,', '', $adresse_site);
516
+    if ($adresse_site !== null) {
517
+        if (!strlen($adresse_site)) {
518
+            $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1;
519
+            $adresse_site = url_de_base();
520
+        }
521
+        $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site);
522 522
 
523
-		if (!tester_url_absolue($adresse_site)) {
524
-			$adresse_site = "http://$adresse_site";
525
-		}
523
+        if (!tester_url_absolue($adresse_site)) {
524
+            $adresse_site = "http://$adresse_site";
525
+        }
526 526
 
527
-		$adresse_site = entites_html($adresse_site);
527
+        $adresse_site = entites_html($adresse_site);
528 528
 
529
-		ecrire_meta('adresse_site', $adresse_site);
530
-	}
529
+        ecrire_meta('adresse_site', $adresse_site);
530
+    }
531 531
 
532
-	return $adresse_site;
532
+    return $adresse_site;
533 533
 }
Please login to merge, or discard this patch.
prive/objets/liste/auteurs_fonctions.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Fonctions
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -29,29 +29,29 @@  discard block
 block discarded – undo
29 29
  * @param bool $left
30 30
  */
31 31
 function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) {
32
-	$boucle = &$boucles[$idb];
32
+    $boucle = &$boucles[$idb];
33 33
 
34
-	$_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent);
34
+    $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent);
35 35
 
36
-	$not = '';
37
-	if ($crit->not) {
38
-		$not = ", 'NOT'";
39
-	}
40
-	$boucle->from['LAA'] = 'spip_auteurs_liens';
41
-	$boucle->from_type['LAA'] = 'left';
42
-	$boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"];
36
+    $not = '';
37
+    if ($crit->not) {
38
+        $not = ", 'NOT'";
39
+    }
40
+    $boucle->from['LAA'] = 'spip_auteurs_liens';
41
+    $boucle->from_type['LAA'] = 'left';
42
+    $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"];
43 43
 
44
-	$boucle->from['articles'] = 'spip_articles';
45
-	$boucle->from_type['articles'] = 'left';
46
-	$boucle->join['articles'] = [
47
-		"'LAA'",
48
-		"'id_article'",
49
-		"'id_objet'",
50
-		"'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'"
51
-	];
44
+    $boucle->from['articles'] = 'spip_articles';
45
+    $boucle->from_type['articles'] = 'left';
46
+    $boucle->join['articles'] = [
47
+        "'LAA'",
48
+        "'id_article'",
49
+        "'id_objet'",
50
+        "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'"
51
+    ];
52 52
 
53
-	$boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles';
54
-	$boucle->group[] = 'auteurs.id_auteur';
53
+    $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles';
54
+    $boucle->group[] = 'auteurs.id_auteur';
55 55
 }
56 56
 
57 57
 /**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  *     Pile complétée par le code à générer
70 70
  */
71 71
 function balise_COMPTEUR_ARTICLES_dist($p) {
72
-	return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres');
72
+    return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres');
73 73
 }
74 74
 
75 75
 
@@ -85,44 +85,44 @@  discard block
 block discarded – undo
85 85
  * @return string
86 86
  */
87 87
 function afficher_initiale($url, $initiale, $compteur, $debut, $pas) {
88
-	static $memo = null;
89
-	static $res = [];
90
-	$out = '';
91
-	if (
92
-		!$memo
93
-		or (!$initiale and !$url)
94
-		or ($initiale !== $memo['initiale'])
95
-	) {
96
-		$newcompt = intval(floor(($compteur - 1) / $pas) * $pas);
97
-		// si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien
98
-		if (!$initiale and !$url and !$memo['compteur']) {
99
-			$memo = null;
100
-		}
101
-		if ($memo) {
102
-			$on = (($memo['compteur'] <= $debut)
103
-				and (
104
-					$newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur'])
105
-				));
106
-			$res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>';
107
-		}
108
-		if ($initiale) {
109
-			$memo = [
110
-				'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0,
111
-				'initiale' => $initiale,
112
-				'url' => parametre_url($url, 'i', $initiale),
113
-				'compteur' => $newcompt
114
-			];
115
-		}
116
-	}
117
-	if (!$initiale and !$url) {
118
-		if ((is_countable($res) ? count($res) : 0) > 1) {
119
-			$out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>';
120
-		}
121
-		$memo = null;
122
-		$res = [];
123
-	}
88
+    static $memo = null;
89
+    static $res = [];
90
+    $out = '';
91
+    if (
92
+        !$memo
93
+        or (!$initiale and !$url)
94
+        or ($initiale !== $memo['initiale'])
95
+    ) {
96
+        $newcompt = intval(floor(($compteur - 1) / $pas) * $pas);
97
+        // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien
98
+        if (!$initiale and !$url and !$memo['compteur']) {
99
+            $memo = null;
100
+        }
101
+        if ($memo) {
102
+            $on = (($memo['compteur'] <= $debut)
103
+                and (
104
+                    $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur'])
105
+                ));
106
+            $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>';
107
+        }
108
+        if ($initiale) {
109
+            $memo = [
110
+                'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0,
111
+                'initiale' => $initiale,
112
+                'url' => parametre_url($url, 'i', $initiale),
113
+                'compteur' => $newcompt
114
+            ];
115
+        }
116
+    }
117
+    if (!$initiale and !$url) {
118
+        if ((is_countable($res) ? count($res) : 0) > 1) {
119
+            $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>';
120
+        }
121
+        $memo = null;
122
+        $res = [];
123
+    }
124 124
 
125
-	return $out;
125
+    return $out;
126 126
 }
127 127
 
128 128
 /**
@@ -141,24 +141,24 @@  discard block
 block discarded – undo
141 141
  * @return string
142 142
  */
143 143
 function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') {
144
-	static $time = null;
145
-	if (!in_array($statut, ['0minirezo', '1comite'])) {
146
-		return '';
147
-	}
144
+    static $time = null;
145
+    if (!in_array($statut, ['0minirezo', '1comite'])) {
146
+        return '';
147
+    }
148 148
 
149
-	if (is_null($time)) {
150
-		$time = time();
151
-	}
152
-	$parti = (($time - strtotime($en_ligne)) > 15 * 60);
149
+    if (is_null($time)) {
150
+        $time = time();
151
+    }
152
+    $parti = (($time - strtotime($en_ligne)) > 15 * 60);
153 153
 
154
-	if (
155
-		$imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ?
156
-		and $GLOBALS['meta']['messagerie_agenda'] != 'non'
157
-	) {
158
-		return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
159
-	} elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
160
-		return 'mailto:' . $email;
161
-	} else {
162
-		return '';
163
-	}
154
+    if (
155
+        $imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ?
156
+        and $GLOBALS['meta']['messagerie_agenda'] != 'non'
157
+    ) {
158
+        return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
159
+    } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
160
+        return 'mailto:' . $email;
161
+    } else {
162
+        return '';
163
+    }
164 164
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 				and (
104 104
 					$newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur'])
105 105
 				));
106
-			$res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>';
106
+			$res[] = "<li class='pagination-item'>".lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination').'</li>';
107 107
 		}
108 108
 		if ($initiale) {
109 109
 			$memo = [
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 	if (!$initiale and !$url) {
118 118
 		if ((is_countable($res) ? count($res) : 0) > 1) {
119
-			$out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>';
119
+			$out = "<ul class='pagination-items'>".implode(' ', $res).'</ul>';
120 120
 		}
121 121
 		$memo = null;
122 122
 		$res = [];
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	) {
158 158
 		return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self());
159 159
 	} elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) {
160
-		return 'mailto:' . $email;
160
+		return 'mailto:'.$email;
161 161
 	} else {
162 162
 		return '';
163 163
 	}
Please login to merge, or discard this patch.
ecrire/exec/admin_plugin.php 2 patches
Indentation   +203 added lines, -203 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/config');
@@ -37,26 +37,26 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function exec_admin_plugin_dist($retour = '') {
39 39
 
40
-	if (!autoriser('configurer', '_plugins')) {
41
-		include_spip('inc/minipres');
42
-		echo minipres();
43
-	} else {
44
-		// on fait la verif du path avant tout,
45
-		// et l'installation des qu'on est dans la colonne principale
46
-		// si jamais la liste des plugins actifs change, il faut faire un refresh du hit
47
-		// pour etre sur que les bons fichiers seront charges lors de l'install
48
-		$new = actualise_plugins_actifs();
49
-		if ($new and _request('actualise') < 2) {
50
-			include_spip('inc/headers');
51
-			if (isset($GLOBALS['fichier_php_compile_recent'])) {
52
-				// attendre eventuellement l'invalidation du cache opcode
53
-				spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
54
-			}
55
-			redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&'));
56
-		} else {
57
-			admin_plug_args(_request('voir'), _request('erreur'), _request('format'));
58
-		}
59
-	}
40
+    if (!autoriser('configurer', '_plugins')) {
41
+        include_spip('inc/minipres');
42
+        echo minipres();
43
+    } else {
44
+        // on fait la verif du path avant tout,
45
+        // et l'installation des qu'on est dans la colonne principale
46
+        // si jamais la liste des plugins actifs change, il faut faire un refresh du hit
47
+        // pour etre sur que les bons fichiers seront charges lors de l'install
48
+        $new = actualise_plugins_actifs();
49
+        if ($new and _request('actualise') < 2) {
50
+            include_spip('inc/headers');
51
+            if (isset($GLOBALS['fichier_php_compile_recent'])) {
52
+                // attendre eventuellement l'invalidation du cache opcode
53
+                spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
54
+            }
55
+            redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&'));
56
+        } else {
57
+            admin_plug_args(_request('voir'), _request('erreur'), _request('format'));
58
+        }
59
+    }
60 60
 }
61 61
 
62 62
 /**
@@ -81,132 +81,132 @@  discard block
 block discarded – undo
81 81
  *     Format d'affichage (liste ou arborescence)
82 82
  **/
83 83
 function admin_plug_args($quoi, $erreur, $format) {
84
-	$lpf = null;
85
-	$lcpas = null;
86
-	$lcpaffichesup = null;
87
-	if (!$quoi) {
88
-		$quoi = 'actifs';
89
-	}
90
-	// empecher l'affichage des erreurs dans le bandeau, on le donne ensuite
91
-	// format brut par plugin
92
-	$GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false);
93
-	// format resume mis en forme
94
-	$erreur_activation = plugin_donne_erreurs();
95
-	$commencer_page = charger_fonction('commencer_page', 'inc');
96
-	echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin');
97
-
98
-	echo debut_gauche();
99
-	echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']);
100
-
101
-	echo pipeline(
102
-		'affiche_gauche',
103
-		[
104
-			'args' => ['exec' => 'admin_plugin'],
105
-			'data' => afficher_librairies()
106
-		]
107
-	);
108
-
109
-	echo debut_droite();
110
-	echo gros_titre(_T('icone_admin_plugin'), '');
111
-
112
-	// Barre d'onglets de premier niveau
113
-	echo barre_onglets('plugins', 'plugins_actifs');
114
-	// Barre d'onglets de second niveau
115
-	$onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin';
116
-	echo debut_onglet('onglets_simple second');
117
-	echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2);
118
-	echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2);
119
-	echo fin_onglet();
120
-
121
-	// message d'erreur au retour d'une operation
122
-	if ($erreur) {
123
-		echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>';
124
-	}
125
-	if ($erreur_activation) {
126
-		echo "<div class='error'>$erreur_activation</div>";
127
-	}
128
-
129
-	// la mise a jour de cette meta a ete faite par ecrire_plugin_actifs
130
-	$actifs = (array) unserialize($GLOBALS['meta']['plugin']);
131
-	$lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']);
132
-
133
-	// Les affichages se basent sur le repertoire, pas sur le nom
134
-	$actifs = liste_chemin_plugin($actifs, '');
135
-	if (defined('_DIR_PLUGINS_SUPPL')) {
136
-		$lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL);
137
-	}
138
-	$lcpa = liste_chemin_plugin($lcpa);
139
-
140
-	// on installe les plugins maintenant,
141
-	// cela permet aux scripts d'install de faire des affichages (moches...)
142
-	plugin_installes_meta();
143
-
144
-	echo "<div class='liste-plugins formulaire_spip'>";
145
-	echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins');
146
-
147
-	if ($quoi !== 'actifs') {
148
-		$lpf = liste_plugin_files();
149
-		if ($lpf) {
150
-			echo '<p>' . _T('texte_presente_plugin') . '</p>';
151
-		} else {
152
-			if (!@is_dir(_DIR_PLUGINS)) {
153
-				echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
-					. ' &mdash; ' . _T('plugin_info_automatique_creer') . '</p>';
155
-			}
156
-		}
157
-		$lcpaffiche = $lpf;
158
-		if (defined('_DIR_PLUGINS_SUPPL')) {
159
-			$lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL);
160
-		}
161
-	} else {
162
-		// la liste
163
-		// $quoi=='actifs'
164
-		$lcpaffiche = $lcpa;
165
-		if (defined('_DIR_PLUGINS_SUPPL')) {
166
-			$lcpaffichesup = $lcpas;
167
-		}
168
-	}
169
-
170
-	if ($quoi == 'actifs' or $lpf) {
171
-		$nb = is_countable($lcpa) ? count($lcpa) : 0;
172
-		if (defined('_DIR_PLUGINS_SUPPL')) {
173
-			$nb += is_countable($lcpas) ? count($lcpas) : 0;
174
-		}
175
-		echo '<h3>' . sinon(
176
-			singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'),
177
-			_T('plugins_actif_aucun')
178
-		) . '</h3>';
179
-	}
180
-
181
-	if (empty($format)) {
182
-		$format = 'liste';
183
-	} elseif (!in_array($format, ['liste', 'repertoires'])) {
184
-		$format = 'repertoires';
185
-	}
186
-
187
-	$afficher = charger_fonction("afficher_$format", 'plugins');
188
-	$corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs);
189
-	if (defined('_DIR_PLUGINS_SUPPL')) {
190
-		$corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL);
191
-	}
192
-
193
-	if ($corps) {
194
-		$corps .= "\n<div class='boutons' style='display:none;'>"
195
-			. "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer')
196
-			. "' />"
197
-			. '</div>';
198
-	}
199
-
200
-	echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps);
201
-
202
-	echo fin_cadre_trait_couleur();
203
-
204
-	if ($quoi == 'actifs') {
205
-		echo affiche_les_plugins_verrouilles($actifs);
206
-	}
207
-	echo '</div>';
208
-
209
-	echo http_script("
84
+    $lpf = null;
85
+    $lcpas = null;
86
+    $lcpaffichesup = null;
87
+    if (!$quoi) {
88
+        $quoi = 'actifs';
89
+    }
90
+    // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite
91
+    // format brut par plugin
92
+    $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false);
93
+    // format resume mis en forme
94
+    $erreur_activation = plugin_donne_erreurs();
95
+    $commencer_page = charger_fonction('commencer_page', 'inc');
96
+    echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin');
97
+
98
+    echo debut_gauche();
99
+    echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']);
100
+
101
+    echo pipeline(
102
+        'affiche_gauche',
103
+        [
104
+            'args' => ['exec' => 'admin_plugin'],
105
+            'data' => afficher_librairies()
106
+        ]
107
+    );
108
+
109
+    echo debut_droite();
110
+    echo gros_titre(_T('icone_admin_plugin'), '');
111
+
112
+    // Barre d'onglets de premier niveau
113
+    echo barre_onglets('plugins', 'plugins_actifs');
114
+    // Barre d'onglets de second niveau
115
+    $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin';
116
+    echo debut_onglet('onglets_simple second');
117
+    echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2);
118
+    echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2);
119
+    echo fin_onglet();
120
+
121
+    // message d'erreur au retour d'une operation
122
+    if ($erreur) {
123
+        echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>';
124
+    }
125
+    if ($erreur_activation) {
126
+        echo "<div class='error'>$erreur_activation</div>";
127
+    }
128
+
129
+    // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs
130
+    $actifs = (array) unserialize($GLOBALS['meta']['plugin']);
131
+    $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']);
132
+
133
+    // Les affichages se basent sur le repertoire, pas sur le nom
134
+    $actifs = liste_chemin_plugin($actifs, '');
135
+    if (defined('_DIR_PLUGINS_SUPPL')) {
136
+        $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL);
137
+    }
138
+    $lcpa = liste_chemin_plugin($lcpa);
139
+
140
+    // on installe les plugins maintenant,
141
+    // cela permet aux scripts d'install de faire des affichages (moches...)
142
+    plugin_installes_meta();
143
+
144
+    echo "<div class='liste-plugins formulaire_spip'>";
145
+    echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins');
146
+
147
+    if ($quoi !== 'actifs') {
148
+        $lpf = liste_plugin_files();
149
+        if ($lpf) {
150
+            echo '<p>' . _T('texte_presente_plugin') . '</p>';
151
+        } else {
152
+            if (!@is_dir(_DIR_PLUGINS)) {
153
+                echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
+                    . ' &mdash; ' . _T('plugin_info_automatique_creer') . '</p>';
155
+            }
156
+        }
157
+        $lcpaffiche = $lpf;
158
+        if (defined('_DIR_PLUGINS_SUPPL')) {
159
+            $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL);
160
+        }
161
+    } else {
162
+        // la liste
163
+        // $quoi=='actifs'
164
+        $lcpaffiche = $lcpa;
165
+        if (defined('_DIR_PLUGINS_SUPPL')) {
166
+            $lcpaffichesup = $lcpas;
167
+        }
168
+    }
169
+
170
+    if ($quoi == 'actifs' or $lpf) {
171
+        $nb = is_countable($lcpa) ? count($lcpa) : 0;
172
+        if (defined('_DIR_PLUGINS_SUPPL')) {
173
+            $nb += is_countable($lcpas) ? count($lcpas) : 0;
174
+        }
175
+        echo '<h3>' . sinon(
176
+            singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'),
177
+            _T('plugins_actif_aucun')
178
+        ) . '</h3>';
179
+    }
180
+
181
+    if (empty($format)) {
182
+        $format = 'liste';
183
+    } elseif (!in_array($format, ['liste', 'repertoires'])) {
184
+        $format = 'repertoires';
185
+    }
186
+
187
+    $afficher = charger_fonction("afficher_$format", 'plugins');
188
+    $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs);
189
+    if (defined('_DIR_PLUGINS_SUPPL')) {
190
+        $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL);
191
+    }
192
+
193
+    if ($corps) {
194
+        $corps .= "\n<div class='boutons' style='display:none;'>"
195
+            . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer')
196
+            . "' />"
197
+            . '</div>';
198
+    }
199
+
200
+    echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps);
201
+
202
+    echo fin_cadre_trait_couleur();
203
+
204
+    if ($quoi == 'actifs') {
205
+        echo affiche_les_plugins_verrouilles($actifs);
206
+    }
207
+    echo '</div>';
208
+
209
+    echo http_script("
210 210
 	jQuery(function(){
211 211
 		jQuery('.plugins li.item a[rel=info]').click(function(){
212 212
 			var li = jQuery(this).parents('li').eq(0);
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
 	});
233 233
 	");
234 234
 
235
-	echo pipeline(
236
-		'affiche_milieu',
237
-		[
238
-			'args' => ['exec' => 'admin_plugin'],
239
-			'data' => ''
240
-		]
241
-	);
235
+    echo pipeline(
236
+        'affiche_milieu',
237
+        [
238
+            'args' => ['exec' => 'admin_plugin'],
239
+            'data' => ''
240
+        ]
241
+    );
242 242
 
243
-	echo fin_gauche(), fin_page();
243
+    echo fin_gauche(), fin_page();
244 244
 }
245 245
 
246 246
 /**
@@ -254,23 +254,23 @@  discard block
 block discarded – undo
254 254
  *     Code HTML
255 255
  **/
256 256
 function affiche_les_plugins_verrouilles($actifs) {
257
-	if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) {
258
-		return '';
259
-	}
260
-
261
-	$afficher = charger_fonction('afficher_liste', 'plugins');
262
-	$liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST);
263
-
264
-	return
265
-		"<div id='plugins_dist'>"
266
-		. debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist')
267
-		. '<p>'
268
-		. _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)])
269
-		. '<br />' . _T('plugin_info_plugins_dist_2')
270
-		. '</p>'
271
-		. $liste
272
-		. fin_cadre_trait_couleur()
273
-		. "</div>\n";
257
+    if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) {
258
+        return '';
259
+    }
260
+
261
+    $afficher = charger_fonction('afficher_liste', 'plugins');
262
+    $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST);
263
+
264
+    return
265
+        "<div id='plugins_dist'>"
266
+        . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist')
267
+        . '<p>'
268
+        . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)])
269
+        . '<br />' . _T('plugin_info_plugins_dist_2')
270
+        . '</p>'
271
+        . $liste
272
+        . fin_cadre_trait_couleur()
273
+        . "</div>\n";
274 274
 }
275 275
 
276 276
 /**
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
  */
283 283
 function afficher_librairies() {
284 284
 
285
-	if (!$libs = liste_librairies()) {
286
-		return '';
287
-	}
288
-	ksort($libs);
289
-	$res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
290
-	$res .= '<dl>';
291
-	foreach ($libs as $lib => $rep) {
292
-		$res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n";
293
-	}
294
-	$res .= '</dl>';
295
-	$res .= fin_cadre_enfonce();
296
-
297
-	return $res;
285
+    if (!$libs = liste_librairies()) {
286
+        return '';
287
+    }
288
+    ksort($libs);
289
+    $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
290
+    $res .= '<dl>';
291
+    foreach ($libs as $lib => $rep) {
292
+        $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n";
293
+    }
294
+    $res .= '</dl>';
295
+    $res .= fin_cadre_enfonce();
296
+
297
+    return $res;
298 298
 }
299 299
 
300 300
 
@@ -305,22 +305,22 @@  discard block
 block discarded – undo
305 305
  *     Tableau (nom de la lib => repertoire , ...)
306 306
  */
307 307
 function liste_librairies() {
308
-	$libs = [];
309
-	foreach (array_reverse(creer_chemin()) as $d) {
310
-		if (
311
-			is_dir($dir = $d . 'lib/')
312
-			and $t = opendir($dir)
313
-		) {
314
-			while (($f = readdir($t)) !== false) {
315
-				if (
316
-					$f[0] != '.'
317
-					and is_dir("$dir/$f")
318
-				) {
319
-					$libs[$f] = $dir;
320
-				}
321
-			}
322
-		}
323
-	}
324
-
325
-	return $libs;
308
+    $libs = [];
309
+    foreach (array_reverse(creer_chemin()) as $d) {
310
+        if (
311
+            is_dir($dir = $d . 'lib/')
312
+            and $t = opendir($dir)
313
+        ) {
314
+            while (($f = readdir($t)) !== false) {
315
+                if (
316
+                    $f[0] != '.'
317
+                    and is_dir("$dir/$f")
318
+                ) {
319
+                    $libs[$f] = $dir;
320
+                }
321
+            }
322
+        }
323
+    }
324
+
325
+    return $libs;
326 326
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 	// message d'erreur au retour d'une operation
122 122
 	if ($erreur) {
123
-		echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>';
123
+		echo "<div class='error'>".spip_htmlspecialchars($erreur).'</div>';
124 124
 	}
125 125
 	if ($erreur_activation) {
126 126
 		echo "<div class='error'>$erreur_activation</div>";
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	if ($quoi !== 'actifs') {
148 148
 		$lpf = liste_plugin_files();
149 149
 		if ($lpf) {
150
-			echo '<p>' . _T('texte_presente_plugin') . '</p>';
150
+			echo '<p>'._T('texte_presente_plugin').'</p>';
151 151
 		} else {
152 152
 			if (!@is_dir(_DIR_PLUGINS)) {
153
-				echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
-					. ' &mdash; ' . _T('plugin_info_automatique_creer') . '</p>';
153
+				echo '<p>'._T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)])
154
+					. ' &mdash; '._T('plugin_info_automatique_creer').'</p>';
155 155
 			}
156 156
 		}
157 157
 		$lcpaffiche = $lpf;
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
 		if (defined('_DIR_PLUGINS_SUPPL')) {
173 173
 			$nb += is_countable($lcpas) ? count($lcpas) : 0;
174 174
 		}
175
-		echo '<h3>' . sinon(
175
+		echo '<h3>'.sinon(
176 176
 			singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'),
177 177
 			_T('plugins_actif_aucun')
178
-		) . '</h3>';
178
+		).'</h3>';
179 179
 	}
180 180
 
181 181
 	if (empty($format)) {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 	if ($corps) {
194 194
 		$corps .= "\n<div class='boutons' style='display:none;'>"
195
-			. "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer')
195
+			. "<input type='submit' class='submit save' value='"._T('bouton_enregistrer')
196 196
 			. "' />"
197 197
 			. '</div>';
198 198
 	}
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		. debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist')
267 267
 		. '<p>'
268 268
 		. _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)])
269
-		. '<br />' . _T('plugin_info_plugins_dist_2')
269
+		. '<br />'._T('plugin_info_plugins_dist_2')
270 270
 		. '</p>'
271 271
 		. $liste
272 272
 		. fin_cadre_trait_couleur()
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	$res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
290 290
 	$res .= '<dl>';
291 291
 	foreach ($libs as $lib => $rep) {
292
-		$res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n";
292
+		$res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>\n";
293 293
 	}
294 294
 	$res .= '</dl>';
295 295
 	$res .= fin_cadre_enfonce();
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	$libs = [];
309 309
 	foreach (array_reverse(creer_chemin()) as $d) {
310 310
 		if (
311
-			is_dir($dir = $d . 'lib/')
311
+			is_dir($dir = $d.'lib/')
312 312
 			and $t = opendir($dir)
313 313
 		) {
314 314
 			while (($f = readdir($t)) !== false) {
Please login to merge, or discard this patch.