summaryrefslogtreecommitdiff
path: root/src/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.php')
-rw-r--r--src/index.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/index.php b/src/index.php
new file mode 100644
index 0000000..9fb3b24
--- /dev/null
+++ b/src/index.php
@@ -0,0 +1,58 @@
+<?php
+
+require_once('../include/setup.php');
+
+if (isset($_GET['lang'])) {
+ Env::setLang($_GET['lang']);
+ header('Location: '.str_replace('lang='.$_GET['lang'], '', $_SERVER['REQUEST_URI']));
+ die();
+}
+
+$page = new MySmarty();
+$page->assign('langs', Env::get('locale', 'languages'));
+
+$content = new MySmarty();
+$content->assign('lang', Env::lang());
+try {
+ $url = ($_SERVER['QUERY_STRING']) ? substr($_SERVER['REQUEST_URI'], 0, -strlen($_SERVER['QUERY_STRING'])) : $_SERVER['REQUEST_URI'];
+ $pageID = explode('/', preg_replace('/\?$/', '', $url))[1];
+ if (!strlen($pageID)) {
+ $pageID = 'main';
+ }
+ try {
+ $title = Env::get('titles', $pageID);
+ $page->assign('title', $title);
+ } catch(EnvNoSuchEntryException $e) {}
+ try {
+ $scripts = Env::get('resources', 'scripts');
+ $page->assign('scripts', $scripts);
+ } catch(EnvNoSuchEntryException $e) {}
+ try {
+ $sheets = Env::get('resources', 'sheets');
+ $page->assign('sheets', $sheets);
+ } catch(EnvNoSuchEntryException $e) {}
+ $menu = new MySmarty();
+ try {
+ $items = Menu::getItems();
+ $activeContent = Menu::getActiveLink($pageID);
+ $menu->assign('items', $items);
+ $menu->assign('content', $activeContent);
+ } catch(EnvNoSuchEntryException $e) {}
+ $page->assign('menu', $menu->fetch('menu.tpl'));
+ $page->assign('content', $content->fetch('content/'.$pageID.'.tpl'));
+}
+catch (Exception $e) {
+ if ($e instanceof SmartyException && preg_match('/^Unable to load template file/', $e->getMessage())) {
+ header('HTTP/1.0 404 Not Found');
+ $page->assign('content', $content->fetch('404.tpl'));
+ }
+ else {
+ throw $e;
+ }
+}
+if ($_GET['theme']) {
+ $page->assign('theme', $_GET['theme']);
+}
+$page->display('index.tpl');
+
+?>