Mercurial > SimpleWebPresenter
diff Page.inc @ 86:b9654b9c4a66
Make headers a part of the content, rather than setting them directly.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 15 Oct 2012 18:32:56 +0200 |
| parents | 2a8e2f571b24 |
| children | 7a9c45b53866 |
line wrap: on
line diff
--- 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; }
