Completed
Push — master ( d7ea4e...026ff7 )
by cam
04:35
created
ecrire/inc/headers.php 2 patches
Indentation   +155 added lines, -155 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
 
@@ -38,132 +38,132 @@  discard block
 block discarded – undo
38 38
  * @param int $status Code de redirection (301 ou 302)
39 39
  **/
40 40
 function redirige_par_entete($url, $equiv = '', $status = 302) {
41
-	if (!in_array($status, array(301, 302))) {
42
-		$status = 302;
43
-	}
44
-
45
-	$url = trim(strtr($url, "\n\r", "  "));
46
-	# si l'url de redirection est relative, on la passe en absolue
47
-	if (!preg_match(",^(\w+:)?//,", $url)) {
48
-		include_spip("inc/filtres_mini");
49
-		$url = url_absolue($url);
50
-	}
51
-
52
-	if (defined('_AJAX') and _AJAX) {
53
-		$url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
-	}
55
-
56
-	// ne pas laisser passer n'importe quoi dans l'url
57
-	$url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
58
-	$url = str_replace(array("\r", "\n", ' '), array('%0D', '%0A', '%20'), $url);
59
-	while (strpos($url, '%0A') !== false) {
60
-		$url = str_replace('%0A', '', $url);
61
-	}
62
-	// interdire les url inline avec des pseudo-protocoles :
63
-	if (
64
-		(preg_match(",data:,i", $url) and preg_match("/base64\s*,/i", $url))
65
-		or preg_match(",(javascript|mailto):,i", $url)
66
-	) {
67
-		$url = "./";
68
-	}
69
-
70
-	// Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
-	include_spip('inc/cookie');
72
-	if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
-		define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
-	}
75
-	if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
-		define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
-	}
78
-	if ((!$equiv and !spip_cookie_envoye()) or (
79
-			   (!empty($_SERVER['SERVER_SOFTWARE'])
80
-				   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
81
-				   and preg_match("/"._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SOFTWARE']))
82
-			or (!empty($_SERVER['SERVER_SIGNATURE'])
83
-				   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
84
-				   and preg_match("/"._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SIGNATURE']))
85
-			or function_exists('apache_getenv')
86
-			or defined('_SERVER_APACHE')
87
-		)
88
-	) {
89
-		@header("Location: " . $url);
90
-		$equiv = "";
91
-	} else {
92
-		@header("Refresh: 0; url=" . $url);
93
-		if (isset($GLOBALS['meta']['charset'])) {
94
-			@header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']);
95
-		}
96
-		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
97
-	}
98
-	include_spip('inc/lang');
99
-	if ($status != 302) {
100
-		http_status($status);
101
-	}
102
-	echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
103
-	html_lang_attributes(), '
41
+    if (!in_array($status, array(301, 302))) {
42
+        $status = 302;
43
+    }
44
+
45
+    $url = trim(strtr($url, "\n\r", "  "));
46
+    # si l'url de redirection est relative, on la passe en absolue
47
+    if (!preg_match(",^(\w+:)?//,", $url)) {
48
+        include_spip("inc/filtres_mini");
49
+        $url = url_absolue($url);
50
+    }
51
+
52
+    if (defined('_AJAX') and _AJAX) {
53
+        $url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
+    }
55
+
56
+    // ne pas laisser passer n'importe quoi dans l'url
57
+    $url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
58
+    $url = str_replace(array("\r", "\n", ' '), array('%0D', '%0A', '%20'), $url);
59
+    while (strpos($url, '%0A') !== false) {
60
+        $url = str_replace('%0A', '', $url);
61
+    }
62
+    // interdire les url inline avec des pseudo-protocoles :
63
+    if (
64
+        (preg_match(",data:,i", $url) and preg_match("/base64\s*,/i", $url))
65
+        or preg_match(",(javascript|mailto):,i", $url)
66
+    ) {
67
+        $url = "./";
68
+    }
69
+
70
+    // Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
+    include_spip('inc/cookie');
72
+    if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
+        define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
+    }
75
+    if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
+        define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
+    }
78
+    if ((!$equiv and !spip_cookie_envoye()) or (
79
+                (!empty($_SERVER['SERVER_SOFTWARE'])
80
+                   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
81
+                   and preg_match("/"._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SOFTWARE']))
82
+            or (!empty($_SERVER['SERVER_SIGNATURE'])
83
+                   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
84
+                   and preg_match("/"._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SIGNATURE']))
85
+            or function_exists('apache_getenv')
86
+            or defined('_SERVER_APACHE')
87
+        )
88
+    ) {
89
+        @header("Location: " . $url);
90
+        $equiv = "";
91
+    } else {
92
+        @header("Refresh: 0; url=" . $url);
93
+        if (isset($GLOBALS['meta']['charset'])) {
94
+            @header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']);
95
+        }
96
+        $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
97
+    }
98
+    include_spip('inc/lang');
99
+    if ($status != 302) {
100
+        http_status($status);
101
+    }
102
+    echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
103
+    html_lang_attributes(), '
104 104
 <head>',
105
-	$equiv, '
105
+    $equiv, '
106 106
 <title>HTTP ' . $status . '</title>
107 107
 ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
108 108
 </head>
109 109
 <body>
110 110
 <h1>HTTP ' . $status . '</h1>
111 111
 <a href="',
112
-	quote_amp($url),
113
-	'">',
114
-	_T('navigateur_pas_redirige'),
115
-	'</a></body></html>';
112
+    quote_amp($url),
113
+    '">',
114
+    _T('navigateur_pas_redirige'),
115
+    '</a></body></html>';
116 116
 
117
-	spip_log("redirige $status: $url");
117
+    spip_log("redirige $status: $url");
118 118
 
119
-	exit;
119
+    exit;
120 120
 }
121 121
 
122 122
 // https://code.spip.net/@redirige_formulaire
123 123
 function redirige_formulaire($url, $equiv = '', $format = 'message') {
124
-	if (!_AJAX
125
-		and !headers_sent()
126
-		and !_request('var_ajax')
127
-	) {
128
-		redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
129
-	} // si c'est une ancre, fixer simplement le window.location.hash
130
-	elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
131
-		return array(
132
-			// on renvoie un lien masque qui sera traite par ajaxCallback.js
133
-			"<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
134
-			// et rien dans le message ok
135
-			''
136
-		);
137
-	} else {
138
-		// ne pas laisser passer n'importe quoi dans l'url
139
-		$url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
140
-
141
-		$url = strtr($url, "\n\r", "  ");
142
-		# en theorie on devrait faire ca tout le temps, mais quand la chaine
143
-		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
144
-		if ($url[0] == '?') {
145
-			$url = url_de_base() . $url;
146
-		}
147
-		$url = str_replace('&amp;', '&', $url);
148
-		spip_log("redirige formulaire ajax: $url");
149
-		include_spip('inc/filtres');
150
-		if ($format == 'ajaxform') {
151
-			return array(
152
-				// on renvoie un lien masque qui sera traite par ajaxCallback.js
153
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
154
-				// et un message au cas ou
155
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
156
-			);
157
-		} else // format message texte, tout en js inline
158
-		{
159
-			return
160
-				// ie poste les formulaires dans une iframe, il faut donc rediriger son parent
161
-				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
162
-				. http_img_pack('searching.gif', '')
163
-				. '<br />'
164
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
165
-		}
166
-	}
124
+    if (!_AJAX
125
+        and !headers_sent()
126
+        and !_request('var_ajax')
127
+    ) {
128
+        redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
129
+    } // si c'est une ancre, fixer simplement le window.location.hash
130
+    elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
131
+        return array(
132
+            // on renvoie un lien masque qui sera traite par ajaxCallback.js
133
+            "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
134
+            // et rien dans le message ok
135
+            ''
136
+        );
137
+    } else {
138
+        // ne pas laisser passer n'importe quoi dans l'url
139
+        $url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
140
+
141
+        $url = strtr($url, "\n\r", "  ");
142
+        # en theorie on devrait faire ca tout le temps, mais quand la chaine
143
+        # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
144
+        if ($url[0] == '?') {
145
+            $url = url_de_base() . $url;
146
+        }
147
+        $url = str_replace('&amp;', '&', $url);
148
+        spip_log("redirige formulaire ajax: $url");
149
+        include_spip('inc/filtres');
150
+        if ($format == 'ajaxform') {
151
+            return array(
152
+                // on renvoie un lien masque qui sera traite par ajaxCallback.js
153
+                '<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
154
+                // et un message au cas ou
155
+                '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
156
+            );
157
+        } else // format message texte, tout en js inline
158
+        {
159
+            return
160
+                // ie poste les formulaires dans une iframe, il faut donc rediriger son parent
161
+                "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
162
+                . http_img_pack('searching.gif', '')
163
+                . '<br />'
164
+                . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
165
+        }
166
+    }
167 167
 }
168 168
 
169 169
 /**
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
  * @return void
185 185
  **/
186 186
 function redirige_url_ecrire($script = '', $args = '', $equiv = '') {
187
-	return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
187
+    return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
188 188
 }
189 189
 
190 190
 /**
@@ -199,49 +199,49 @@  discard block
 block discarded – undo
199 199
  **/
200 200
 function http_status($status) {
201 201
 
202
-	static $status_string = array(
203
-		200 => '200 OK',
204
-		204 => '204 No Content',
205
-		301 => '301 Moved Permanently',
206
-		302 => '302 Found',
207
-		304 => '304 Not Modified',
208
-		401 => '401 Unauthorized',
209
-		403 => '403 Forbidden',
210
-		404 => '404 Not Found',
211
-		503 => '503 Service Unavailable'
212
-	);
213
-
214
-	if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
215
-		return;
216
-	}
217
-
218
-	$php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(",cgi,i", @php_sapi_name()));
219
-	if ($php_cgi) {
220
-		header("Status: " . $status_string[$status]);
221
-	} else {
222
-		header("HTTP/1.0 " . $status_string[$status]);
223
-	}
202
+    static $status_string = array(
203
+        200 => '200 OK',
204
+        204 => '204 No Content',
205
+        301 => '301 Moved Permanently',
206
+        302 => '302 Found',
207
+        304 => '304 Not Modified',
208
+        401 => '401 Unauthorized',
209
+        403 => '403 Forbidden',
210
+        404 => '404 Not Found',
211
+        503 => '503 Service Unavailable'
212
+    );
213
+
214
+    if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
215
+        return;
216
+    }
217
+
218
+    $php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(",cgi,i", @php_sapi_name()));
219
+    if ($php_cgi) {
220
+        header("Status: " . $status_string[$status]);
221
+    } else {
222
+        header("HTTP/1.0 " . $status_string[$status]);
223
+    }
224 224
 }
225 225
 
226 226
 // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache
227 227
 // https://code.spip.net/@http_no_cache
228 228
 function http_no_cache() {
229
-	if (headers_sent()) {
230
-		spip_log("http_no_cache arrive trop tard");
231
-
232
-		return;
233
-	}
234
-	$charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
235
-
236
-	// selon http://developer.apple.com/internet/safari/faq.html#anchor5
237
-	// il faudrait aussi pour Safari
238
-	// header("Cache-Control: post-check=0, pre-check=0", false)
239
-	// mais ca ne respecte pas
240
-	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
241
-
242
-	header("Content-Type: text/html; charset=$charset");
243
-	header("Expires: 0");
244
-	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
245
-	header("Cache-Control: no-cache, must-revalidate");
246
-	header("Pragma: no-cache");
229
+    if (headers_sent()) {
230
+        spip_log("http_no_cache arrive trop tard");
231
+
232
+        return;
233
+    }
234
+    $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
235
+
236
+    // selon http://developer.apple.com/internet/safari/faq.html#anchor5
237
+    // il faudrait aussi pour Safari
238
+    // header("Cache-Control: post-check=0, pre-check=0", false)
239
+    // mais ca ne respecte pas
240
+    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
241
+
242
+    header("Content-Type: text/html; charset=$charset");
243
+    header("Expires: 0");
244
+    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
245
+    header("Cache-Control: no-cache, must-revalidate");
246
+    header("Pragma: no-cache");
247 247
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
 	if ((!$equiv and !spip_cookie_envoye()) or (
79 79
 			   (!empty($_SERVER['SERVER_SOFTWARE'])
80 80
 				   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
81
-				   and preg_match("/"._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SOFTWARE']))
81
+				   and preg_match("/"._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE."/i", $_SERVER['SERVER_SOFTWARE']))
82 82
 			or (!empty($_SERVER['SERVER_SIGNATURE'])
83 83
 				   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
84
-				   and preg_match("/"._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE."/i",$_SERVER['SERVER_SIGNATURE']))
84
+				   and preg_match("/"._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE."/i", $_SERVER['SERVER_SIGNATURE']))
85 85
 			or function_exists('apache_getenv')
86 86
 			or defined('_SERVER_APACHE')
87 87
 		)
88 88
 	) {
89
-		@header("Location: " . $url);
89
+		@header("Location: ".$url);
90 90
 		$equiv = "";
91 91
 	} else {
92
-		@header("Refresh: 0; url=" . $url);
92
+		@header("Refresh: 0; url=".$url);
93 93
 		if (isset($GLOBALS['meta']['charset'])) {
94
-			@header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']);
94
+			@header("Content-Type: text/html; charset=".$GLOBALS['meta']['charset']);
95 95
 		}
96 96
 		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
97 97
 	}
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 	html_lang_attributes(), '
104 104
 <head>',
105 105
 	$equiv, '
106
-<title>HTTP ' . $status . '</title>
107
-' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
106
+<title>HTTP ' . $status.'</title>
107
+' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset='.$GLOBALS['meta']['charset'].'">' : '').'
108 108
 </head>
109 109
 <body>
110
-<h1>HTTP ' . $status . '</h1>
110
+<h1>HTTP ' . $status.'</h1>
111 111
 <a href="',
112 112
 	quote_amp($url),
113 113
 	'">',
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		# en theorie on devrait faire ca tout le temps, mais quand la chaine
143 143
 		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
144 144
 		if ($url[0] == '?') {
145
-			$url = url_de_base() . $url;
145
+			$url = url_de_base().$url;
146 146
 		}
147 147
 		$url = str_replace('&amp;', '&', $url);
148 148
 		spip_log("redirige formulaire ajax: $url");
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 		if ($format == 'ajaxform') {
151 151
 			return array(
152 152
 				// on renvoie un lien masque qui sera traite par ajaxCallback.js
153
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
153
+				'<a href="'.quote_amp($url).'" name="ajax_redirect"  style="display:none;">'._T('navigateur_pas_redirige').'</a>',
154 154
 				// et un message au cas ou
155
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
155
+				'<br /><a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>'
156 156
 			);
157 157
 		} else // format message texte, tout en js inline
158 158
 		{
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
162 162
 				. http_img_pack('searching.gif', '')
163 163
 				. '<br />'
164
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
164
+				. '<a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>';
165 165
 		}
166 166
 	}
167 167
 }
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 
218 218
 	$php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(",cgi,i", @php_sapi_name()));
219 219
 	if ($php_cgi) {
220
-		header("Status: " . $status_string[$status]);
220
+		header("Status: ".$status_string[$status]);
221 221
 	} else {
222
-		header("HTTP/1.0 " . $status_string[$status]);
222
+		header("HTTP/1.0 ".$status_string[$status]);
223 223
 	}
224 224
 }
225 225
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
 	header("Content-Type: text/html; charset=$charset");
243 243
 	header("Expires: 0");
244
-	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
244
+	header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
245 245
 	header("Cache-Control: no-cache, must-revalidate");
246 246
 	header("Pragma: no-cache");
247 247
 }
Please login to merge, or discard this patch.