diff options
author | emkael <emkael@tlen.pl> | 2016-10-11 14:01:29 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-10-11 14:01:29 +0200 |
commit | 51609351f2c4b5082b7e6f0744cd3811c325303f (patch) | |
tree | 739015e9ec69bc185ebe30db21369ae0b8b692ce /src/index.php | |
parent | 8d1b0dad63e3906efa9393ef01d08b77d83417b5 (diff) |
* initial template
Diffstat (limited to 'src/index.php')
-rw-r--r-- | src/index.php | 58 |
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'); + +?> |