3 error_reporting(error_reporting() & ~E_STRICT);
4 session_set_cookie_params(14 * 86400);//2 weeks session expiry time
7 require_once __DIR__ . '/../src/phorkie/autoload.php';
10 if ($e instanceof Exception) {
11 header('HTTP/1.0 ' . $e->httpStatusCode);
13 header('HTTP/1.0 500 Internal server error');
16 if (!isset($GLOBALS['twig'])) {
17 echo '<h1>Exception</h1>';
18 echo '<p>' . $e->getMessage() . '</p>';
27 'debug' => $GLOBALS['phorkie']['cfg']['debug']
34 require_once __DIR__ . '/../data/config.default.php';
35 $pharFile = \Phar::running();
36 if ($pharFile == '') {
37 $cfgFilePath = __DIR__ . '/../data/config.php';
39 //remove phar:// from the path
40 $cfgFilePath = substr($pharFile, 7) . '.config.php';
42 $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = false;
43 $GLOBALS['phorkie']['suggestSetupCheck'] = false;
44 if (file_exists($cfgFilePath)) {
45 $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = true;
46 require_once $cfgFilePath;
47 } else if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
48 $GLOBALS['phorkie']['suggestSetupCheck'] = true;
51 if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) {
52 $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl();
55 // Set/Get git commit session variables
56 $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
57 if (!isset($_SESSION['name'])) {
58 $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName'];
60 if (!isset($_SESSION['email'])) {
61 $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail'];
64 \Twig_Autoloader::register();
66 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
67 $twig = new \Twig_Environment(
70 //'cache' => '/path/to/compilation_cache',
74 $twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
75 function ntext($value, $singular, $plural)
77 if (abs($value) == 1) {
78 return sprintf($singular, $value);
80 return sprintf($plural, $value);
82 //$twig->addExtension(new \Twig_Extension_Debug());
84 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
85 require __DIR__ . '/www-security.php';
88 function render($tplname, $vars = array())
90 $vars['baseurl'] = '/';
91 if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) {
92 $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl'];
94 $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
95 $vars['iconpng'] = $GLOBALS['phorkie']['cfg']['iconpng'];
96 $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
97 $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
98 if (isset($_SESSION['identity'])) {
99 $vars['identity'] = $_SESSION['identity'];
100 $vars['name'] = $_SESSION['name'];
101 $vars['email'] = $_SESSION['email'];
103 $vars['db'] = new Database();
104 if (!isset($vars['htmlhelper'])) {
105 $vars['htmlhelper'] = new HtmlHelper();
107 $vars['suggestSetupCheck'] = $GLOBALS['phorkie']['suggestSetupCheck'];
109 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
110 echo $template->render($vars);
112 function redirect($target)
114 header('Location: ' . $target);