5 require_once __DIR__ . '/../src/phorkie/autoload.php';
8 if ($e instanceof Exception) {
9 header('HTTP/1.0 ' . $e->httpStatusCode);
11 header('HTTP/1.0 500 Internal server error');
14 if (!isset($GLOBALS['twig'])) {
15 echo '<h1>Exception</h1>';
16 echo '<p>' . $e->getMessage() . '</p>';
25 'debug' => $GLOBALS['phorkie']['cfg']['debug']
32 require_once __DIR__ . '/../data/config.default.php';
33 if (file_exists(__DIR__ . '/../data/config.php')) {
34 require_once __DIR__ . '/../data/config.php';
37 // Set/Get git commit session variables
38 $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
39 if (!isset($_SESSION['name'])) {
40 $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName'];
42 if (!isset($_SESSION['email'])) {
43 $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail'];
46 \Twig_Autoloader::register();
48 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
49 $twig = new \Twig_Environment(
52 //'cache' => '/path/to/compilation_cache',
56 $twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
57 function ntext($value, $singular, $plural)
59 if (abs($value) == 1) {
60 return sprintf($singular, $value);
62 return sprintf($plural, $value);
64 //$twig->addExtension(new \Twig_Extension_Debug());
66 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
67 require __DIR__ . '/www-security.php';
70 function render($tplname, $vars = array())
72 $vars['baseurl'] = '/';
73 if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) {
74 $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl'];
76 $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
77 $vars['iconpng'] = $GLOBALS['phorkie']['cfg']['iconpng'];
78 $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
79 $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
80 if (isset($_SESSION['identity'])) {
81 $vars['identity'] = $_SESSION['identity'];
82 $vars['name'] = $_SESSION['name'];
83 $vars['email'] = $_SESSION['email'];
85 $vars['db'] = new Database();
86 if (!isset($vars['htmlhelper'])) {
87 $vars['htmlhelper'] = new HtmlHelper();
90 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
91 echo $template->render($vars);
93 function redirect($target)
95 header('Location: ' . $target);