index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. //include_once '../debug.php';
  3. include_once 'pquery.config.php';
  4. include_once PQUERY_ROOT.'pquery.php';
  5. // Config
  6. __p::require_plugins('template', 'sql', 'url', 'js', 'css');
  7. __p::load_utils('minify_html', 'jshrink', 'CssParser');
  8. __tpl::set_root('templates');
  9. // URL rewriting
  10. __url::add_handlers(array(
  11. 'css/(.*)' => 'css_handler',
  12. 'js/(.*)' => 'js_handler',
  13. '' => 'layout',
  14. '(.*)' => 'content'
  15. ));
  16. // Call content handler
  17. header('Vary: Accept-Encoding');
  18. $handler = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false ? 'ob_gzhandler' : '';
  19. ob_start($handler);
  20. _url($_SERVER['QUERY_STRING'])->handler();
  21. ob_end_flush();
  22. // Cache handlers
  23. function js_handler($files) {
  24. $prepend_folder = create_function('$x', 'return "js/$x";');
  25. _js(array_map($prepend_folder, explode(',', $files)))->output();
  26. }
  27. function css_handler($files) {
  28. $prepend_folder = create_function('$x', 'return "css/$x";');
  29. _css(array_map($prepend_folder, explode(',', $files)))->output();
  30. }
  31. // HTML handlers
  32. function content() {
  33. html('content');
  34. }
  35. function layout() {
  36. $menu = array(
  37. array('Pagina\'s', 'pages'),
  38. array('Nieuws', 'news'),
  39. array('Foto\'s', 'photos'),
  40. array('Accounts', 'accounts'),
  41. array('Instellingen', 'settings'),
  42. array('Uitloggen', 'logout')
  43. );
  44. $layout = _tpl('layout');
  45. foreach( $menu as $i => $item ) {
  46. list($title, $icon) = $item;
  47. $item = $layout->data->add('menu')->set(array('title' => $title, 'icon' => $icon));
  48. $i || $item->set('active', 'active');
  49. }
  50. html($layout->parse());
  51. }
  52. // HTML wrapper handler, minifies HTML and sets Content-Type header
  53. function html($html) {
  54. header('Content-Type: text/html; charset=utf-8');
  55. echo Minify_HTML::minify($html, array(
  56. 'cssMinifier' => 'CssParser::minify',
  57. 'jsMinifier' => 'JShrink::minify'
  58. ));
  59. }
  60. ?>