Completed
Push — master ( 607ad1...d6552d )
by cam
04:09
created
ecrire/inc/cookie.php 1 patch
Indentation   +102 added lines, -102 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,73 +52,73 @@  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
-
57
-	if (!is_array($options)) {
58
-		// anciens paramètres :
59
-		# spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
60
-		$opt = func_get_args();
61
-		$opt = array_slice($opt, 2);
62
-		$options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
63
-		if (isset($opt[0])) {
64
-			$options['expires'] = $opt[0];
65
-		}
66
-		if (isset($opt[1])) {
67
-			$options['path'] = $opt[1];
68
-		}
69
-		if (isset($opt[2])) {
70
-			$options['domain'] = $opt[2];
71
-		}
72
-		if (isset($opt[3])) {
73
-			$options['secure'] = $opt[3];
74
-		}
75
-	}
76
-
77
-	$name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name);
78
-
79
-	// expires
80
-	if (!isset($options['expires'])) {
81
-		$options['expires'] = 0;
82
-	}
83
-	if (!isset($options['path']) or $options['path'] === 'AUTO') {
84
-		if (defined('_COOKIE_PATH')) {
85
-			$options['path'] = _COOKIE_PATH;
86
-		} else {
87
-			$options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
88
-		}
89
-	}
90
-	if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
91
-		$options['domain'] = _COOKIE_DOMAIN;
92
-	}
93
-	if (in_array($name, $to_secure_list)) {
94
-		if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
95
-			$options['secure'] = true;
96
-		}
97
-		if (empty($options['httponly'])) {
98
-			$options['httponly'] = true;
99
-		}
100
-	}
101
-	if (empty($options['samesite'])) {
102
-		$options['samesite'] = 'Lax';
103
-	}
104
-
105
-	#spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
106
-	if (PHP_VERSION_ID < 70300) {
107
-		$options = [
108
-			isset($options['expires']) ? $options['expires'] : 0,
109
-			isset($options['path']) ? $options['path'] : '',
110
-			isset($options['domain']) ? $options['domain'] : '',
111
-			isset($options['secure']) ? $options['secure'] : false,
112
-			isset($options['httponly']) ? $options['httponly'] : false,
113
-		];
114
-		$a = @setcookie($name, $value, ...$options);
115
-	} else {
116
-		$a = @setcookie($name, $value, $options);
117
-	}
118
-
119
-	spip_cookie_envoye(true);
120
-
121
-	return $a;
55
+    static $to_secure_list = ['spip_session'];
56
+
57
+    if (!is_array($options)) {
58
+        // anciens paramètres :
59
+        # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
60
+        $opt = func_get_args();
61
+        $opt = array_slice($opt, 2);
62
+        $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
63
+        if (isset($opt[0])) {
64
+            $options['expires'] = $opt[0];
65
+        }
66
+        if (isset($opt[1])) {
67
+            $options['path'] = $opt[1];
68
+        }
69
+        if (isset($opt[2])) {
70
+            $options['domain'] = $opt[2];
71
+        }
72
+        if (isset($opt[3])) {
73
+            $options['secure'] = $opt[3];
74
+        }
75
+    }
76
+
77
+    $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name);
78
+
79
+    // expires
80
+    if (!isset($options['expires'])) {
81
+        $options['expires'] = 0;
82
+    }
83
+    if (!isset($options['path']) or $options['path'] === 'AUTO') {
84
+        if (defined('_COOKIE_PATH')) {
85
+            $options['path'] = _COOKIE_PATH;
86
+        } else {
87
+            $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
88
+        }
89
+    }
90
+    if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
91
+        $options['domain'] = _COOKIE_DOMAIN;
92
+    }
93
+    if (in_array($name, $to_secure_list)) {
94
+        if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
95
+            $options['secure'] = true;
96
+        }
97
+        if (empty($options['httponly'])) {
98
+            $options['httponly'] = true;
99
+        }
100
+    }
101
+    if (empty($options['samesite'])) {
102
+        $options['samesite'] = 'Lax';
103
+    }
104
+
105
+    #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
106
+    if (PHP_VERSION_ID < 70300) {
107
+        $options = [
108
+            isset($options['expires']) ? $options['expires'] : 0,
109
+            isset($options['path']) ? $options['path'] : '',
110
+            isset($options['domain']) ? $options['domain'] : '',
111
+            isset($options['secure']) ? $options['secure'] : false,
112
+            isset($options['httponly']) ? $options['httponly'] : false,
113
+        ];
114
+        $a = @setcookie($name, $value, ...$options);
115
+    } else {
116
+        $a = @setcookie($name, $value, $options);
117
+    }
118
+
119
+    spip_cookie_envoye(true);
120
+
121
+    return $a;
122 122
 }
123 123
 
124 124
 /**
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
  * @return bool
135 135
  **/
136 136
 function spip_cookie_envoye($set = '') {
137
-	static $envoye = false;
138
-	if ($set) {
139
-		$envoye = true;
140
-	}
137
+    static $envoye = false;
138
+    if ($set) {
139
+        $envoye = true;
140
+    }
141 141
 
142
-	return $envoye;
142
+    return $envoye;
143 143
 }
144 144
 
145 145
 /**
@@ -158,21 +158,21 @@  discard block
 block discarded – undo
158 158
  *     Préfixe des cookies de SPIP
159 159
  **/
160 160
 function recuperer_cookies_spip($cookie_prefix) {
161
-	$prefix_long = strlen($cookie_prefix);
162
-
163
-	foreach ($_COOKIE as $name => $value) {
164
-		if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
165
-			unset($_COOKIE[$name]);
166
-			unset($GLOBALS[$name]);
167
-		}
168
-	}
169
-	foreach ($_COOKIE as $name => $value) {
170
-		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
171
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
172
-			$_COOKIE[$spipname] = $value;
173
-			$GLOBALS[$spipname] = $value;
174
-		}
175
-	}
161
+    $prefix_long = strlen($cookie_prefix);
162
+
163
+    foreach ($_COOKIE as $name => $value) {
164
+        if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
165
+            unset($_COOKIE[$name]);
166
+            unset($GLOBALS[$name]);
167
+        }
168
+    }
169
+    foreach ($_COOKIE as $name => $value) {
170
+        if (substr($name, 0, $prefix_long) == $cookie_prefix) {
171
+            $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
172
+            $_COOKIE[$spipname] = $value;
173
+            $GLOBALS[$spipname] = $value;
174
+        }
175
+    }
176 176
 
177 177
 }
178 178
 
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
  *
193 193
  **/
194 194
 function exec_test_ajax_dist() {
195
-	switch (_request('js')) {
196
-		// on est appele par <noscript>
197
-		case -1:
198
-			spip_setcookie('spip_accepte_ajax', -1);
199
-			include_spip('inc/headers');
200
-			redirige_par_entete(chemin_image('puce-orange-anim.gif'));
201
-			break;
202
-
203
-		// ou par ajax
204
-		case 1:
205
-		default:
206
-			spip_setcookie('spip_accepte_ajax', 1);
207
-			break;
208
-	}
195
+    switch (_request('js')) {
196
+        // on est appele par <noscript>
197
+        case -1:
198
+            spip_setcookie('spip_accepte_ajax', -1);
199
+            include_spip('inc/headers');
200
+            redirige_par_entete(chemin_image('puce-orange-anim.gif'));
201
+            break;
202
+
203
+        // ou par ajax
204
+        case 1:
205
+        default:
206
+            spip_setcookie('spip_accepte_ajax', 1);
207
+            break;
208
+    }
209 209
 }
Please login to merge, or discard this patch.