add Stylesheet- and CssAgent and add it to HTML-layout
This commit is contained in:
parent
24f97d7c94
commit
b0a83f4cc9
9 changed files with 218 additions and 1 deletions
35
agents/intermediate/CssAgent.inc
Normal file
35
agents/intermediate/CssAgent.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CssAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
35
agents/toplevel/StylesheetAgent.inc
Normal file
35
agents/toplevel/StylesheetAgent.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StylesheetAgent extends \nre\agents\ToplevelAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
* @var array
|
||||
*/
|
||||
public static $routes = array(
|
||||
//array('<pattern>', '<replace>', '<is_last>')
|
||||
array('css/?(.*)', 'css/$1?layout=stylesheet', false)
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
103
controllers/CssController.inc
Normal file
103
controllers/CssController.inc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
37
controllers/StylesheetController.inc
Normal file
37
controllers/StylesheetController.inc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StylesheetController extends \nre\core\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Show the stylesheet-structure
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>The Legend of Z</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/css/desktop" media="all" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
0
views/stylesheet/css/desktop.tpl
Normal file
0
views/stylesheet/css/desktop.tpl
Normal file
1
views/stylesheet/error/index.tpl
Normal file
1
views/stylesheet/error/index.tpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fehler: <?=$code?> <?=$string?>
|
||||
4
views/stylesheet/stylesheet.tpl
Normal file
4
views/stylesheet/stylesheet.tpl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@charset "UTF-8";
|
||||
|
||||
|
||||
<?=$intermediate?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue