deleting files works now
[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('exception', array('exception' => $e));
25         exit();
26     }
27 );
28
29 require_once __DIR__ . '/../data/config.default.php';
30 if (file_exists(__DIR__ . '/../data/config.php')) {
31     require_once __DIR__ . '/../data/config.php';
32 }
33 require_once 'VersionControl/Git.php';
34 require_once 'Twig/Autoloader.php';
35 \Twig_Autoloader::register();
36
37 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
38 $twig = new \Twig_Environment(
39     $loader,
40     array(
41         //'cache' => '/path/to/compilation_cache',
42         'debug' => true
43     )
44 );
45
46 function render($tplname, $vars)
47 {
48     $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
49     $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
50     echo $template->render($vars);
51 }
52 function redirect($target)
53 {
54     header('Location: ' . $target);
55     exit();
56 }
57 ?>