From 168ebde8c8598f79d7c73acfa15d37985514f77e Mon Sep 17 00:00:00 2001 From: coderkun Date: Fri, 17 Jan 2014 02:37:08 +0100 Subject: [PATCH] add Stylesheet- and CssAgent and add it to HTML-layout --- agents/intermediate/CssAgent.inc | 35 +++++++++ agents/toplevel/StylesheetAgent.inc | 35 +++++++++ configs/AppConfig.inc | 2 +- controllers/CssController.inc | 103 +++++++++++++++++++++++++++ controllers/StylesheetController.inc | 37 ++++++++++ views/html/html.tpl | 2 + views/stylesheet/css/desktop.tpl | 0 views/stylesheet/error/index.tpl | 1 + views/stylesheet/stylesheet.tpl | 4 ++ 9 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 agents/intermediate/CssAgent.inc create mode 100644 agents/toplevel/StylesheetAgent.inc create mode 100644 controllers/CssController.inc create mode 100644 controllers/StylesheetController.inc create mode 100644 views/stylesheet/css/desktop.tpl create mode 100644 views/stylesheet/error/index.tpl create mode 100644 views/stylesheet/stylesheet.tpl diff --git a/agents/intermediate/CssAgent.inc b/agents/intermediate/CssAgent.inc new file mode 100644 index 00000000..8d8de32f --- /dev/null +++ b/agents/intermediate/CssAgent.inc @@ -0,0 +1,35 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\intermediate; + + + /** + * Agent to show CSS-stylesheets. + * + * @author Oliver Hanraths + */ + class CssAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + */ + public function index() + { + } + + } + +?> diff --git a/agents/toplevel/StylesheetAgent.inc b/agents/toplevel/StylesheetAgent.inc new file mode 100644 index 00000000..07eefea0 --- /dev/null +++ b/agents/toplevel/StylesheetAgent.inc @@ -0,0 +1,35 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\toplevel; + + + /** + * Agent to display stylesheets. + * + * @author Oliver Hanraths + */ + class StylesheetAgent extends \nre\agents\ToplevelAgent + { + + + + + /** + * Action: index. + */ + public function index() + { + } + + } + +?> diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 7524f7b2..599b4cac 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -56,7 +56,7 @@ * @var array */ public static $routes = array( - //array('', '', '') + array('css/?(.*)', 'css/$1?layout=stylesheet', false) ); diff --git a/controllers/CssController.inc b/controllers/CssController.inc new file mode 100644 index 00000000..38e4a474 --- /dev/null +++ b/controllers/CssController.inc @@ -0,0 +1,103 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the CssAgent to show CSS-stylesheets. + * + * @author Oliver Hanraths + */ + class CssController extends \hhu\z\Controller + { + + + + /** + * Prefilter that is executed before running the Controller. + * + * @param Request $request Current request + * @param Response $response Current response + */ + public function preFilter(\nre\core\Request $request, \nre\core\Response $response) + { + parent::preFilter($request, $response); + + // Set content-type for CSS-stylesheets + $response->addHeader('Content-type: text/css'); + + // Set expires-header for caching + $response->addHeader("Pragma: public"); + $response->addHeader("Expires: ".gmdate('r', time()+(60*60*24))); + $response->addHeader("Date: ".gmdate(\DateTime::RFC822)); + } + + + /** + * Action: desktop. + * + * Show CSS for desktops. + */ + public function desktop() + { + // Set HTTP-header + $this->setHeader(); + } + + + /** + * Action: adds. + * + * Show additional CSS for desktops. + */ + public function desktop_adds() + { + // Set HTTP-header + $this->setHeader(); + } + + + + + /** + * Set HTTP-header for caching. + */ + private function setHeader() + { + // Determine filename of template + $templateFilename = $this->getView()->getTemplateFilename(); + + // Determine date of last change + $templateLastModified = gmdate('r', filemtime($templateFilename)); + + // Create E-tag + $templateEtag = hash('sha256', $templateLastModified.$templateFilename); + + + // Set header + $this->response->addHeader("Last-Modified: ".$templateLastModified); + $this->response->addHeader("Etag: ".$templateEtag); + // HTTP-status + $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE'); + $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH'); + if( + !is_null($headerModifiedSince) && $templateLastModified < strtotime($headerModifiedSince) && + !is_null($headerNoneMatch) && $headerNoneMatch == $templateEtag + ) { + $this->response->setExit(true); + $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304)); + } + } + + } + +?> diff --git a/controllers/StylesheetController.inc b/controllers/StylesheetController.inc new file mode 100644 index 00000000..d9bbfc3d --- /dev/null +++ b/controllers/StylesheetController.inc @@ -0,0 +1,37 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the StylesheetAgent to display stylesheets. + * + * @author Oliver Hanraths + */ + class StylesheetController extends \nre\core\Controller + { + + + + + /** + * Action: index. + * + * Show the stylesheet-structure + */ + public function index() + { + } + + } + +?> diff --git a/views/html/html.tpl b/views/html/html.tpl index 307b772d..6adf05e5 100644 --- a/views/html/html.tpl +++ b/views/html/html.tpl @@ -4,6 +4,8 @@ The Legend of Z + + diff --git a/views/stylesheet/css/desktop.tpl b/views/stylesheet/css/desktop.tpl new file mode 100644 index 00000000..e69de29b diff --git a/views/stylesheet/error/index.tpl b/views/stylesheet/error/index.tpl new file mode 100644 index 00000000..f6ceec9b --- /dev/null +++ b/views/stylesheet/error/index.tpl @@ -0,0 +1 @@ +Fehler: diff --git a/views/stylesheet/stylesheet.tpl b/views/stylesheet/stylesheet.tpl new file mode 100644 index 00000000..c796c127 --- /dev/null +++ b/views/stylesheet/stylesheet.tpl @@ -0,0 +1,4 @@ +@charset "UTF-8"; + + +