?php // Check if current user is admin $isAdmin = function ($app) { return function () use ($app) { if (!isset($_SESSION['user'])) { $app->flash('error', 'Login required'); $app->redirect($app->urlFor('admin/login')); } }; }; // Try to install and create database tables if environment file not exist $app->hook('slim.before', function () use ($app) { if (file_exists(realpath('.env'))) { if (!getInstall()) { setInstall(); } } }); // Authorizing before dispatch $app->hook('slim.before.dispatch', function () use ($app) { try { if (preg_match('/(sleep|benchmark|outfile|load_file)\s*\(/', $_SERVER['QUERY_STRING'])) { throw new Exception('Hacking Attempt.'); } // if ( ! preg_match( '@admin@i', $_SERVER['SCRIPT_NAME'] ) ) { // $app->add(new CsrfGuard()); // } } catch (Exception $e) { $app->firephp->error($e); exit; } if (isset($_SESSION['user'])) { $user = $_SESSION['user']; $app->view()->appendData(array( 'session' => $user )); } // Get settings from database and put in configs $configs = getConfigs(); foreach ($configs as $key => $value) { $app->config('configs.' . $key, $value); } $app->view()->appendData(compact('configs')); $app->view()->appendData(getTranslate()); // Prevent load extra data on admin section if (!preg_match('/admin|fetch/', $_SERVER['REQUEST_URI'])) { try { $app->view()->appendData(getNewNavbar()); $app->view()->appendData(getSidebarCategories()); $app->view()->appendData(getSidebarAdverts()); $app->view()->appendData(getHotUserInfo()); $app->view()->appendData(getHotItemInfo()); $app->view()->appendData(getFreeItemInfo()); $app->view()->appendData(getHotUserItems()); $app->view()->appendData(getFeaturedItems()); // $app->view()->appendData(getPreviewItems()); $app->view()->appendData(getFootPages()); } catch (Exception $e) { $app->firephp->error($e); } } }); ?>