3 error_reporting(error_reporting() & ~E_STRICT & ~E_DEPRECATED);
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();
53 if (substr($GLOBALS['phorkie']['cfg']['git']['public'], 0, 9) == '%BASEURL%') {
54 //make autoconfig work
55 $GLOBALS['phorkie']['cfg']['git']['public'] = Tools::fullUrlNoPhar(
56 substr($GLOBALS['phorkie']['cfg']['git']['public'], 9)
61 // Set/Get git commit session variables
62 $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
63 if (!isset($_SESSION['name'])) {
64 $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName'];
66 if (!isset($_SESSION['email'])) {
67 $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail'];
70 \Twig_Autoloader::register();
72 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
73 $twig = new \Twig_Environment(
76 //'cache' => '/path/to/compilation_cache',
80 $twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
81 function ntext($value, $singular, $plural)
83 if (abs($value) == 1) {
84 return sprintf($singular, $value);
86 return sprintf($plural, $value);
88 //$twig->addExtension(new \Twig_Extension_Debug());
90 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
91 require __DIR__ . '/www-security.php';
94 function render($tplname, $vars = array(), $return = false)
96 $vars['baseurl'] = '/';
97 if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) {
98 $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl'];
100 $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
101 $vars['iconpng'] = $GLOBALS['phorkie']['cfg']['iconpng'];
102 $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
103 $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
104 if (isset($_SESSION['identity'])) {
105 $vars['identity'] = $_SESSION['identity'];
106 $vars['name'] = $_SESSION['name'];
107 $vars['email'] = $_SESSION['email'];
108 } else if (isset($_COOKIE['lastopenid'])
109 && !isset($_COOKIE['tried-autologin'])
111 $vars['autologin'] = true;
113 $vars['db'] = new Database();
114 if (!isset($vars['htmlhelper'])) {
115 $vars['htmlhelper'] = new HtmlHelper();
117 $vars['suggestSetupCheck'] = $GLOBALS['phorkie']['suggestSetupCheck'];
119 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
122 return $template->render($vars);
124 echo $template->render($vars);
128 function redirect($target)
130 header('Location: ' . $target);