# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1350318776 -7200 # Node ID b9654b9c4a66018bcf9aac89644a54d0ba02ceb1 # Parent 590e6950fa7fe8273147155e39a0d6da5474ef38 Make headers a part of the content, rather than setting them directly. diff -r 590e6950fa7f -r b9654b9c4a66 Flag.inc --- a/Flag.inc Mon Oct 15 16:53:29 2012 +0200 +++ b/Flag.inc Mon Oct 15 18:32:56 2012 +0200 @@ -78,7 +78,8 @@ errorPage('Resource not found', 404); } else { - header("Content-Type: image/png"); + $flag = new PageContent($flag); + $flag->addHeader("Content-Type: image/png"); return $flag; } } diff -r 590e6950fa7f -r b9654b9c4a66 Page.inc --- a/Page.inc Mon Oct 15 16:53:29 2012 +0200 +++ b/Page.inc Mon Oct 15 18:32:56 2012 +0200 @@ -7,6 +7,27 @@ $cache->includeOnce('Options.inc', dirname(__FILE__)); /// @endcond +class PageContent +{ + public $headers = array(); + public $content; + + function __construct($content = "") + { + $this->content = $content; + } + + function addHeader($txt) + { + array_push($this->headers, $txt); + } + + function __toString() + { + return $this->content; + } +} + /** * Master class for generating a page */ @@ -59,6 +80,20 @@ } /** + * Decide wether or not this page may be validated. + * + * Normally this is a check for the option novalidate, but this may + * be overridden + * + * @return bool if this page may be validated + */ + function mayValidate() + { + return !$_GET['novalidate']; + } + + + /** * Turns on compression for this page * * @note This may not be reversed @@ -96,6 +131,22 @@ if ($this->mayCompress()) { $this->startCompression(); } + $t = gettype($res); + if ($t === "string") { + $res = new Content($res); + } + elseif (get_class($res) !== "PageContent") { + throw new InvalidArgumentException("generateContent returned an unexpected type"); + } + return $res; + } + + function display() + { + $res = $this->genPage(); + foreach ($res->headers as $header) { + header($header); + } print $res; } diff -r 590e6950fa7f -r b9654b9c4a66 Sitemap.inc --- a/Sitemap.inc Mon Oct 15 16:53:29 2012 +0200 +++ b/Sitemap.inc Mon Oct 15 18:32:56 2012 +0200 @@ -103,8 +103,9 @@ $out .= ''; - header('Content-type: application/xml'); - return $out; + $res = new PageContent($out); + $res->addHeader('Content-type: application/xml'); + return $res; } } ?> diff -r 590e6950fa7f -r b9654b9c4a66 flag.php --- a/flag.php Mon Oct 15 16:53:29 2012 +0200 +++ b/flag.php Mon Oct 15 18:32:56 2012 +0200 @@ -13,7 +13,7 @@ try { $flag = new Flag($scriptCache); - $flag->genPage(); + $flag->display(); } catch (Exception $e) { errorPage($e, StatusCodes::HTTP_INTERNAL_SERVER_ERROR); diff -r 590e6950fa7f -r b9654b9c4a66 sitemap.php --- a/sitemap.php Mon Oct 15 16:53:29 2012 +0200 +++ b/sitemap.php Mon Oct 15 18:32:56 2012 +0200 @@ -13,7 +13,7 @@ try { $sitemap = new Sitemap("master.xml"); - $sitemap->genPage(); + $sitemap->display(); } catch (Exception $e) { errorPage($e, StatusCodes::HTTP_INTERNAL_SERVER_ERROR);