X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fheaders.php;fp=www%2Fecrire%2Finc%2Fheaders.php;h=ca484617f93b80a1f2ab734189c92ebe1ac3cd47;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/ecrire/inc/headers.php b/www/ecrire/inc/headers.php new file mode 100644 index 0000000..ca48461 --- /dev/null +++ b/www/ecrire/inc/headers.php @@ -0,0 +1,170 @@ +"; + } + include_spip('inc/lang'); + if ($status!=302) + http_status($status); + echo '',"\n", + html_lang_attributes(),' +', + $equiv,' +HTTP '.$status.' + + +

HTTP '.$status.'

+', + _T('navigateur_pas_redirige'), + ''; + + spip_log("redirige $status: $url"); + + exit; +} + +// http://doc.spip.org/@redirige_formulaire +function redirige_formulaire($url, $equiv = '', $format='message') { + if (!_AJAX + AND !headers_sent() + AND !_request('var_ajax')) { + redirige_par_entete(str_replace('&','&',$url), $equiv); + } + // si c'est une ancre, fixer simplement le window.location.hash + elseif($format=='ajaxform' AND preg_match(',^#[0-9a-z\-_]+$,i',$url)) { + return array( + // on renvoie un lien masque qui sera traite par ajaxCallback.js + "anchor", + // et rien dans le message ok + ''); + } + else { + // ne pas laisser passer n'importe quoi dans l'url + $url = str_replace(array('<','"'),array('<','"'),$url); + + $url = strtr($url, "\n\r", " "); + # en theorie on devrait faire ca tout le temps, mais quand la chaine + # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne + if ($url[0]=='?') + $url = url_de_base().(_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$url; + $url = str_replace('&','&',$url); + spip_log("redirige formulaire ajax: $url"); + include_spip('inc/filtres'); + if ($format=='ajaxform') + return array( + // on renvoie un lien masque qui sera traite par ajaxCallback.js + ''._T('navigateur_pas_redirige').'', + // et un message au cas ou + '
'._T('navigateur_pas_redirige').'' + ); + else // format message texte, tout en js inline + return + // ie poste les formulaires dans une iframe, il faut donc rediriger son parent + "" + . http_img_pack('searching.gif','') + . '
' + . ''._T('navigateur_pas_redirige').''; + } +} + +// http://doc.spip.org/@redirige_url_ecrire +function redirige_url_ecrire($script='', $args='', $equiv='') { + return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv); +} + +// http://doc.spip.org/@http_status +function http_status($status) { + global $REDIRECT_STATUS, $flag_sapi_name; + static $status_string = array( + 200 => '200 OK', + 204 => '204 No Content', + 301 => '301 Moved Permanently', + 302 => '302 Found', + 304 => '304 Not Modified', + 401 => '401 Unauthorized', + 403 => '403 Forbidden', + 404 => '404 Not Found' + ); + + if ($REDIRECT_STATUS && $REDIRECT_STATUS == $status) return; + + $php_cgi = ($flag_sapi_name AND preg_match(",cgi,i", @php_sapi_name())); + if ($php_cgi) + header("Status: ".$status_string[$status]); + else + header("HTTP/1.0 ".$status_string[$status]); +} + +// Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache +// http://doc.spip.org/@http_no_cache +function http_no_cache() { + if (headers_sent()) + { spip_log("http_no_cache arrive trop tard"); return;} + $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; + + // selon http://developer.apple.com/internet/safari/faq.html#anchor5 + // il faudrait aussi pour Safari + // header("Cache-Control: post-check=0, pre-check=0", false) + // mais ca ne respecte pas + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 + + header("Content-Type: text/html; charset=$charset"); + header("Expires: 0"); + header("Last-Modified: " .gmdate("D, d M Y H:i:s"). " GMT"); + header("Cache-Control: no-store, no-cache, must-revalidate"); + header("Pragma: no-cache"); +} + +?>