footer with phorkie homepage link
[phorkie.git] / www / www-header.php
1 <?php
2 namespace phorkie;
3 set_include_path(
4     __DIR__ . '/../src/'
5     . PATH_SEPARATOR . get_include_path()
6 );
7 spl_autoload_register(
8     function ($class) {
9         $file = str_replace(array('\\', '_'), '/', $class) . '.php';
10         $hdl = @fopen($file, 'r', true);
11         if ($hdl !== false) {
12             fclose($hdl);
13             require $file;
14         }
15     }
16 );
17 set_exception_handler(
18     function ($e) {
19         if ($e instanceof Exception) {
20             header('HTTP/1.0 ' . $e->httpStatusCode);
21         } else {
22             header('HTTP/1.0 500 Internal server error');
23         }
24         render(
25             'exception',
26             array(
27                 'exception' => $e,
28                 'debug'     => $GLOBALS['phorkie']['cfg']['debug']
29             )
30         );
31         exit();
32     }
33 );
34
35 require_once __DIR__ . '/../data/config.default.php';
36 if (file_exists(__DIR__ . '/../data/config.php')) {
37     require_once __DIR__ . '/../data/config.php';
38 }
39 require_once 'VersionControl/Git.php';
40 require_once 'Twig/Autoloader.php';
41 \Twig_Autoloader::register();
42
43 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
44 $twig = new \Twig_Environment(
45     $loader,
46     array(
47         //'cache' => '/path/to/compilation_cache',
48         'debug' => true
49     )
50 );
51
52 function render($tplname, $vars)
53 {
54     $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
55     $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
56     echo $template->render($vars);
57 }
58 function redirect($target)
59 {
60     header('Location: ' . $target);
61     exit();
62 }
63 ?>