7 . PATH_SEPARATOR . get_include_path()
11 $file = str_replace(array('\\', '_'), '/', $class) . '.php';
12 if (stream_resolve_include_path($file)) {
17 set_exception_handler(
19 if ($e instanceof Exception) {
20 header('HTTP/1.0 ' . $e->httpStatusCode);
22 header('HTTP/1.0 500 Internal server error');
25 if (!isset($GLOBALS['twig'])) {
26 echo '<h1>Exception</h1>';
27 echo '<p>' . $e->getMessage() . '</p>';
36 'debug' => $GLOBALS['phorkie']['cfg']['debug']
43 require_once __DIR__ . '/../data/config.default.php';
44 if (file_exists(__DIR__ . '/../data/config.php')) {
45 require_once __DIR__ . '/../data/config.php';
48 // Set/Get git commit session variables
49 $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
50 if (!isset($_SESSION['name'])) {
51 $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName'];
53 if (!isset($_SESSION['email'])) {
54 $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail'];
57 \Twig_Autoloader::register();
59 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
60 $twig = new \Twig_Environment(
63 //'cache' => '/path/to/compilation_cache',
67 $twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
68 function ntext($value, $singular, $plural)
70 if (abs($value) == 1) {
71 return sprintf($singular, $value);
73 return sprintf($plural, $value);
75 //$twig->addExtension(new \Twig_Extension_Debug());
77 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
78 require __DIR__ . '/www-security.php';
81 function render($tplname, $vars = array())
83 $vars['baseurl'] = '/';
84 if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) {
85 $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl'];
87 $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
88 $vars['iconpng'] = $GLOBALS['phorkie']['cfg']['iconpng'];
89 $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
90 $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
91 if (isset($_SESSION['identity'])) {
92 $vars['identity'] = $_SESSION['identity'];
93 $vars['name'] = $_SESSION['name'];
94 $vars['email'] = $_SESSION['email'];
96 $vars['db'] = new Database();
97 if (!isset($vars['htmlhelper'])) {
98 $vars['htmlhelper'] = new HtmlHelper();
101 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
102 echo $template->render($vars);
104 function redirect($target)
106 header('Location: ' . $target);