Commit e1b53a4e authored by Taddeus Kroes's avatar Taddeus Kroes

Added HTML minifier and some comments.

parent 3bd59aff
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
include_once 'pquery.config.php'; include_once 'pquery.config.php';
include_once PQUERY_ROOT.'pquery.php'; include_once PQUERY_ROOT.'pquery.php';
// Config
__p::require_plugins('template', 'sql', 'url', 'js', 'css'); __p::require_plugins('template', 'sql', 'url', 'js', 'css');
__p::load_util('minify_html', 'jshrink', 'CssParser');
__tpl::set_root('templates'); __tpl::set_root('templates');
// URL rewriting
__url::add_handlers(array( __url::add_handlers(array(
'css/(.*)' => 'css_handler', 'css/(.*)' => 'css_handler',
'js/(.*)' => 'js_handler', 'js/(.*)' => 'js_handler',
...@@ -15,6 +17,7 @@ __url::add_handlers(array( ...@@ -15,6 +17,7 @@ __url::add_handlers(array(
'(.*)' => 'content' '(.*)' => 'content'
)); ));
// Call content handler
header('Vary: Accept-Encoding'); header('Vary: Accept-Encoding');
$handler = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false ? 'ob_gzhandler' : ''; $handler = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false ? 'ob_gzhandler' : '';
...@@ -23,11 +26,8 @@ ob_start($handler); ...@@ -23,11 +26,8 @@ ob_start($handler);
_url($_SERVER['QUERY_STRING'])->handler(); _url($_SERVER['QUERY_STRING'])->handler();
ob_end_flush(); ob_end_flush();
/** // Cache handlers
*
*
* @param string $files One or more scripts separated by commas (',').
*/
function js_handler($files) { function js_handler($files) {
$prepend_folder = create_function('$x', 'return "js/$x";'); $prepend_folder = create_function('$x', 'return "js/$x";');
_js(array_map($prepend_folder, explode(',', $files)))->output(); _js(array_map($prepend_folder, explode(',', $files)))->output();
...@@ -38,15 +38,13 @@ function css_handler($files) { ...@@ -38,15 +38,13 @@ function css_handler($files) {
_css(array_map($prepend_folder, explode(',', $files)))->output(); _css(array_map($prepend_folder, explode(',', $files)))->output();
} }
// HTML handlers
function content() { function content() {
header('Content-Type: text/html; charset=utf-8'); html('content');
echo 'content';
} }
function layout() { function layout() {
header('Content-Type: text/html; charset=utf-8');
$menu = array( $menu = array(
array('Pagina\'s', 'pages'), array('Pagina\'s', 'pages'),
array('Nieuws', 'news'), array('Nieuws', 'news'),
...@@ -63,7 +61,18 @@ function layout() { ...@@ -63,7 +61,18 @@ function layout() {
$i || $item->set('active', 'active'); $i || $item->set('active', 'active');
} }
echo $layout->parse(); html($layout->parse());
}
// HTML wrapper handler, minifies HTML and sets Content-Type header
function html($html) {
header('Content-Type: text/html; charset=utf-8');
echo Minify_HTML::minify($html, array(
'cssMinifier' => 'CssParser::minify',
'jsMinifier' => 'JShrink::minify'
));
} }
?> ?>
\ No newline at end of file
...@@ -2,8 +2,13 @@ ...@@ -2,8 +2,13 @@
<html> <html>
<head> <head>
<title>Tcms</title> <title>Tcms</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="robots" content="index,nofollow" />
<base href="http://localhost/tcms/" />
<link href="css/main" rel="stylesheet" /> <link href="css/main" rel="stylesheet" />
<script async type="text/javascript" src="js/jquery-1.7.min,menu,list"></script> <script async type="text/javascript" src="js/jquery-1.7.min,menu,list"></script>
<!-- <!--
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment