xhr.php 844 Bytes
Newer Older
Peter Tönnies's avatar
Peter Tönnies committed
1 2
<?php

3
use Foodsharing\DI;
4 5
use Foodsharing\Lib\Cache\Caching;
use Foodsharing\Lib\Session\S;
6 7
use Foodsharing\Lib\Xhr\XhrMethods;
use Foodsharing\Modules\Core\Model;
8

Tilmann Becker's avatar
Tilmann Becker committed
9 10
require __DIR__ . '/includes/setup.php';

Raphael Wintrich's avatar
Raphael Wintrich committed
11
require_once 'config.inc.php';
Raphael Wintrich's avatar
Raphael Wintrich committed
12 13

S::init();
14 15 16 17
if (isset($g_page_cache)) {
	$cache = new Caching($g_page_cache);
	$cache->lookup();
}
Raphael Wintrich's avatar
Raphael Wintrich committed
18 19

require_once 'lang/DE/de.php';
Raphael Wintrich's avatar
Raphael Wintrich committed
20 21 22

$action = $_GET['f'];

Matthias Larisch's avatar
Matthias Larisch committed
23
$db = new Model();
24

25
$db->updateActivity(S::id());
Peter Tönnies's avatar
Peter Tönnies committed
26
if (isset($_GET['f'])) {
27
	$xhr = DI::$shared->get(XhrMethods::class);
Peter Tönnies's avatar
Peter Tönnies committed
28
	$func = 'xhr_' . $action;
29
	if (method_exists($xhr, $func)) {
Raphael Wintrich's avatar
Raphael Wintrich committed
30
		/*
31 32
		 * check for page caching
		*/
33
		if (isset($cache) && $cache->shouldCache()) {
Raphael Wintrich's avatar
Raphael Wintrich committed
34
			ob_start();
35
			echo $xhr->$func($_GET);
Raphael Wintrich's avatar
Raphael Wintrich committed
36
			$page = ob_get_contents();
37
			$cache->cache($page);
Peter Tönnies's avatar
Peter Tönnies committed
38

Raphael Wintrich's avatar
Raphael Wintrich committed
39
			ob_end_clean();
Peter Tönnies's avatar
Peter Tönnies committed
40

Raphael Wintrich's avatar
Raphael Wintrich committed
41
			echo $page;
Peter Tönnies's avatar
Peter Tönnies committed
42
		} else {
43
			echo $xhr->$func($_GET);
Raphael Wintrich's avatar
Raphael Wintrich committed
44 45
		}
	}
Raphael Wintrich's avatar
Raphael Wintrich committed
46
}