Completed
Push — master ( 5f9f27...f0ca20 )
by cam
01:12
created
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.