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 $pharFile = \Phar::running();
34 if ($pharFile == '') {
35 $cfgFilePath = __DIR__ . '/../data/config.php';
37 //remove phar:// from the path
38 $cfgFilePath = substr($pharFile, 7) . '.config.php';
40 $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = false;
41 if (file_exists($cfgFilePath)) {
42 $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = true;
43 require_once $cfgFilePath;
46 if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) {
47 $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl();
50 // Set/Get git commit session variables
51 $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
52 if (!isset($_SESSION['name'])) {
53 $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName'];
55 if (!isset($_SESSION['email'])) {
56 $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail'];
59 \Twig_Autoloader::register();
61 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
62 $twig = new \Twig_Environment(
65 //'cache' => '/path/to/compilation_cache',
69 $twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
70 function ntext($value, $singular, $plural)
72 if (abs($value) == 1) {
73 return sprintf($singular, $value);
75 return sprintf($plural, $value);
77 //$twig->addExtension(new \Twig_Extension_Debug());
79 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
80 require __DIR__ . '/www-security.php';
83 function render($tplname, $vars = array())
85 $vars['baseurl'] = '/';
86 if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) {
87 $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl'];
89 $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
90 $vars['iconpng'] = $GLOBALS['phorkie']['cfg']['iconpng'];
91 $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
92 $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
93 if (isset($_SESSION['identity'])) {
94 $vars['identity'] = $_SESSION['identity'];
95 $vars['name'] = $_SESSION['name'];
96 $vars['email'] = $_SESSION['email'];
98 $vars['db'] = new Database();
99 if (!isset($vars['htmlhelper'])) {
100 $vars['htmlhelper'] = new HtmlHelper();
103 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
104 echo $template->render($vars);
106 function redirect($target)
108 header('Location: ' . $target);