| Conditions | 19 |
| Paths | 192 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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('<', '"'), $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 ((!$equiv and !spip_cookie_envoye()) or ( |
||
| 73 | (strncmp("Apache", $_SERVER['SERVER_SOFTWARE'], 6) == 0) |
||
| 74 | or (isset($_SERVER['SERVER_SIGNATURE']) and stripos($_SERVER['SERVER_SIGNATURE'], 'Apache') !== false) |
||
| 75 | or function_exists('apache_getenv') |
||
| 76 | or defined('_SERVER_APACHE') |
||
| 77 | ) |
||
| 78 | ) { |
||
| 79 | @header("Location: " . $url); |
||
|
|
|||
| 80 | $equiv = ""; |
||
| 81 | } else { |
||
| 82 | @header("Refresh: 0; url=" . $url); |
||
| 83 | if (isset($GLOBALS['meta']['charset'])) { |
||
| 84 | @header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']); |
||
| 85 | } |
||
| 86 | $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
||
| 87 | } |
||
| 88 | include_spip('inc/lang'); |
||
| 89 | if ($status != 302) { |
||
| 90 | http_status($status); |
||
| 91 | } |
||
| 92 | echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n", |
||
| 93 | html_lang_attributes(), ' |
||
| 94 | <head>', |
||
| 95 | $equiv, ' |
||
| 96 | <title>HTTP ' . $status . '</title> |
||
| 97 | ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . ' |
||
| 98 | </head> |
||
| 99 | <body> |
||
| 100 | <h1>HTTP ' . $status . '</h1> |
||
| 101 | <a href="', |
||
| 102 | quote_amp($url), |
||
| 103 | '">', |
||
| 104 | _T('navigateur_pas_redirige'), |
||
| 105 | '</a></body></html>'; |
||
| 106 | |||
| 107 | spip_log("redirige $status: $url"); |
||
| 108 | |||
| 109 | exit; |
||
| 110 | } |
||
| 111 | |||
| 238 |
If you suppress an error, we recommend checking for the error condition explicitly: