summaryrefslogtreecommitdiff
path: root/src/index.php
blob: 41ca88966fdbdf084dca9d62585be67c7e402a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 = trim(preg_replace('/\?$/', '', $url), '/');
  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');

?>