index.php 2.47 KB
Newer Older
Peter Tönnies's avatar
Peter Tönnies committed
1
<?php
Raphael Wintrich's avatar
Raphael Wintrich committed
2 3 4 5 6
/*
if(isset($_GET['g_path']))
{
	$path = explode('/', $_GET['g_path']);
	//print_r($path);
Peter Tönnies's avatar
Peter Tönnies committed
7 8


Raphael Wintrich's avatar
Raphael Wintrich committed
9 10
	switch ($path[0])
	{
11 12 13 14 15
		case 'group' :
			$_GET['page'] = 'bezirk';
			$_GET['bid'] = $path[1];
			$_GET['sub'] = $path[2];
			break;
Peter Tönnies's avatar
Peter Tönnies committed
16

17 18
		default:
			break;
Raphael Wintrich's avatar
Raphael Wintrich committed
19
	}
Peter Tönnies's avatar
Peter Tönnies committed
20

Raphael Wintrich's avatar
Raphael Wintrich committed
21 22
}
*/
Raphael Wintrich's avatar
Raphael Wintrich committed
23

24
use Foodsharing\Debug\DebugBar;
Tilmann Becker's avatar
Tilmann Becker committed
25
use Foodsharing\Lib\Db\Mem;
26
use Foodsharing\Lib\Func;
27
use Foodsharing\Lib\Routing;
28
use Foodsharing\Lib\Session;
29
use Foodsharing\Lib\View\Utils;
30
use Symfony\Component\DependencyInjection\Container;
31
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
32

Tilmann Becker's avatar
Tilmann Becker committed
33
require __DIR__ . '/includes/setup.php';
34 35 36 37
require_once 'config.inc.php';

/* @var $container Container */
global $container;
Nick Sellen's avatar
Nick Sellen committed
38
$container = initializeContainer();
Tilmann Becker's avatar
Tilmann Becker committed
39

Raphael Wintrich's avatar
Raphael Wintrich committed
40
require_once 'lib/inc.php';
41

42 43 44
/* @var $mem Mem */
$mem = $container->get(Mem::class);

45
/* @var $view_utils Utils */
46
$view_utils = $container->get(Utils::class);
Nick Sellen's avatar
Nick Sellen committed
47

48
/* @var $func Func */
49
$func = $container->get(Func::class);
50

51
/* @var $session Session */
52
$session = $container->get(Session::class);
Raphael Wintrich's avatar
Raphael Wintrich committed
53

54 55
$g_broadcast_message = $db->qOne('SELECT `body` FROM fs_content WHERE `id` = 51');

56 57 58 59 60 61
if (DebugBar::isEnabled()) {
	$func->addHead(DebugBar::renderHead());
}

if (DebugBar::isEnabled()) {
	$func->addContent(DebugBar::renderContent(), CNT_BOTTOM);
62 63
}

64
if ($session->may()) {
Nick Sellen's avatar
Nick Sellen committed
65 66
	if (isset($_GET['uc'])) {
		if ($func->fsId() != $_GET['uc']) {
67
			$mem->logout($session->id());
Nick Sellen's avatar
Nick Sellen committed
68 69 70 71 72
			$func->goLogin();
		}
	}
}

73 74
$app = $func->getPage();

75
if (($class = $session->getRouteOverride()) === null) {
76
	$class = Routing::getClassName($app, 'Control');
77
	try {
78
		$obj = $container->get(ltrim($class, '\\'));
79 80 81
	} catch (ServiceNotFoundException $e) {
	}
} else {
82
	$obj = $container->get(ltrim($class, '\\'));
83
}
84

85
if (isset($obj)) {
86 87 88 89 90 91 92 93 94 95
	if (isset($_GET['a']) && is_callable(array($obj, $_GET['a']))) {
		$meth = $_GET['a'];
		$obj->$meth($request, $response);
	} else {
		$obj->index($request, $response);
	}
	$sub = $sub = $obj->getSubFunc();
	if ($sub !== false && is_callable(array($obj, $sub))) {
		$obj->$sub($request, $response);
	}
96 97 98
} else {
	$response->setStatusCode(404);
	$response->setContent('');
99 100
}

101 102 103 104
$page = $response->getContent();
$isUsingResponse = $page !== '--';
if ($isUsingResponse) {
	$response->send();
Peter Tönnies's avatar
Peter Tönnies committed
105
} else {
106
	/* @var $twig \Twig\Environment */
107
	$twig = $container->get(\Twig\Environment::class);
108
	$page = $twig->render('layouts/' . $g_template . '.twig', $func->generateAndGetGlobalViewData());
Raphael Wintrich's avatar
Raphael Wintrich committed
109
}
110

111 112
if (isset($cache) && $cache->shouldCache()) {
	$cache->cache($page);
Raphael Wintrich's avatar
Raphael Wintrich committed
113
}
114

115 116 117
if (!$isUsingResponse) {
	echo $page;
}