Completed
Push — master ( e4a2f2...86bb13 )
by cam
01:11
created
ecrire/inc/cookie.php 1 patch
Indentation   +91 added lines, -91 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,62 +52,62 @@  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
-	$a = @setcookie($name, $value, $options);
107
-
108
-	spip_cookie_envoye(true);
109
-
110
-	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
+    $a = @setcookie($name, $value, $options);
107
+
108
+    spip_cookie_envoye(true);
109
+
110
+    return $a;
111 111
 }
112 112
 
113 113
 /**
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
  * @return bool
124 124
  **/
125 125
 function spip_cookie_envoye($set = '') {
126
-	static $envoye = false;
127
-	if ($set) {
128
-		$envoye = true;
129
-	}
126
+    static $envoye = false;
127
+    if ($set) {
128
+        $envoye = true;
129
+    }
130 130
 
131
-	return $envoye;
131
+    return $envoye;
132 132
 }
133 133
 
134 134
 /**
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
  *     Préfixe des cookies de SPIP
148 148
  **/
149 149
 function recuperer_cookies_spip($cookie_prefix) {
150
-	$prefix_long = strlen($cookie_prefix);
151
-
152
-	foreach ($_COOKIE as $name => $value) {
153
-		if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
154
-			unset($_COOKIE[$name]);
155
-			unset($GLOBALS[$name]);
156
-		}
157
-	}
158
-	foreach ($_COOKIE as $name => $value) {
159
-		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
160
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
161
-			$_COOKIE[$spipname] = $value;
162
-			$GLOBALS[$spipname] = $value;
163
-		}
164
-	}
150
+    $prefix_long = strlen($cookie_prefix);
151
+
152
+    foreach ($_COOKIE as $name => $value) {
153
+        if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
154
+            unset($_COOKIE[$name]);
155
+            unset($GLOBALS[$name]);
156
+        }
157
+    }
158
+    foreach ($_COOKIE as $name => $value) {
159
+        if (substr($name, 0, $prefix_long) == $cookie_prefix) {
160
+            $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
161
+            $_COOKIE[$spipname] = $value;
162
+            $GLOBALS[$spipname] = $value;
163
+        }
164
+    }
165 165
 
166 166
 }
167 167
 
@@ -181,18 +181,18 @@  discard block
 block discarded – undo
181 181
  *
182 182
  **/
183 183
 function exec_test_ajax_dist() {
184
-	switch (_request('js')) {
185
-		// on est appele par <noscript>
186
-		case -1:
187
-			spip_setcookie('spip_accepte_ajax', -1);
188
-			include_spip('inc/headers');
189
-			redirige_par_entete(chemin_image('erreur-xx.svg'));
190
-			break;
191
-
192
-		// ou par ajax
193
-		case 1:
194
-		default:
195
-			spip_setcookie('spip_accepte_ajax', 1);
196
-			break;
197
-	}
184
+    switch (_request('js')) {
185
+        // on est appele par <noscript>
186
+        case -1:
187
+            spip_setcookie('spip_accepte_ajax', -1);
188
+            include_spip('inc/headers');
189
+            redirige_par_entete(chemin_image('erreur-xx.svg'));
190
+            break;
191
+
192
+        // ou par ajax
193
+        case 1:
194
+        default:
195
+            spip_setcookie('spip_accepte_ajax', 1);
196
+            break;
197
+    }
198 198
 }
Please login to merge, or discard this patch.