require_once ROOT_PATH . 'controller/login.php'; require_once ROOT_PATH . 'controller/account.php'; require_once ROOT_PATH . 'controller/chart/create.php'; require_once ROOT_PATH . 'controller/chart/edit.php'; require_once ROOT_PATH . 'controller/chart/upload.php'; require_once ROOT_PATH . 'controller/chart/describe.php'; require_once ROOT_PATH . 'controller/chart/visualize.php'; require_once ROOT_PATH . 'controller/chart/data.php'; require_once ROOT_PATH . 'controller/chart/preview.php'; require_once ROOT_PATH . 'controller/chart/embed.php'; require_once ROOT_PATH . 'controller/chart/publish.php'; require_once ROOT_PATH . 'controller/mycharts.php'; require_once ROOT_PATH . 'controller/xhr.php'; require_once ROOT_PATH . 'controller/admin.php'; $app->notFound(function () { error_not_found(); }); if ($dw_config['debug']) { $app->get('/phpinfo', function () use($app) { phpinfo(); }); } /* * before processing any other route we check if the * user is not logged in and if prevent_guest_access is activated. * if both is true we redirect to /login */ $app->hook('slim.before.router', function () use($app, $dw_config) { $user = DatawrapperSession::getUser(); // allow logged-in users if ($user->isLoggedIn()) {
function route() { $method = $_SERVER['REQUEST_METHOD']; $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1)); $pathParameters = array(); $pathName = array_shift($request); for ($x = 0; $x < count($request); $x += 2) { $v = isset($request[$x + 1]) ? $request[$x + 1] : NULL; $pathParameters[$request[$x]] = $v; } $params = array_merge($_GET, $_POST, $pathParameters); $actionName = ucfirst($pathName); $action = 'Action' . $actionName; try { $exists = class_exists($action); } catch (ClassNotFoundException $e) { error_not_found($actionName); } if ($exists && in_array('Rest', class_implements($action))) { $a = new $action(); $m = 'do' . $method; if (method_exists($a, $m)) { $a->parameters = $params; $a->headers = getallheaders(); try { $a->{$m}(); } catch (Exception $e) { error_internal_server_error($e->getMessage()); throw $e; } // after executed, we must be sure nothing else happen. exit; } else { error_method_not_allowed($method); } } else { error_not_found("Not found: " . $request[0]); } }