namespace Admin; use Parvula\Core\View; use Parvula\Core\Config; use Parvula\Core\Parvula; if (!defined('ROOT')) { exit; } $adminConf = (require DATA . 'admin.conf.php'); if ($adminConf['password'] === "_Your_Password_") { die('You MUST change the default password in `' . DATA . 'admin.conf.php`.'); } $view = new View(ADMIN . 'view'); $view->assign('baseUrl', Parvula::getRelativeURIToRoot()); $view->assign('templateUrl', Parvula::getRelativeURIToRoot() . TMPL . Config::get('template')); // Check password if (isset($_POST, $_POST['password'])) { if ($_POST['password'] === $adminConf['password']) { if (session_id() === '') { session_id(uniqid()); session_start(); } $_SESSION['id'] = uidSession(); $_SESSION['login'] = true; // Post/Redirect/Get pattern header("Location: ./", true, 303); } else { $view->assign('notice', true); } }
} // Check if template exists (must have index.html) $baseTemplate = TMPL . Config::get('template'); if (!is_readable($baseTemplate . '/index.html')) { die("Error - Template is not readable"); } Asset::setBasePath(Parvula::getRelativeURIToRoot() . $baseTemplate); $parvula = new Parvula(); $page = $parvula->getPage($pagename); // 404 if (false === $page) { header(' ', true, 404); // Set header to 404 $page = $parvula->getPage(Config::errorPage()); if (false === $page) { // Juste print simple 404 if there is no 404 page die('404 - Page ' . htmlspecialchars($page) . ' not found'); } } try { $view = new View(TMPL . Config::get('template')); // Assign some variables $view->assign(array('baseUrl' => Parvula::getRelativeURIToRoot(), 'templateUrl' => Asset::getBasePath(), 'parvula' => $parvula, 'pages' => function () use($parvula) { return $parvula->getPages(); }, 'site' => $config, 'meta' => $page, 'content' => $page->content)); // Show index template echo $view('index'); } catch (Exception $e) { exceptionHandler($e); } });
require $autoload; } else { require APP . 'Core/Parvula.php'; Parvula::registerAutoloader(); } require APP . 'helpers.php'; // Use custom exception handler set_exception_handler('exceptionHandler'); // Populate Config wrapper Config::populate(require APP . 'config.php'); // Display or not errors ini_set('display_errors', (bool) Config::get('debug')); // Load class aliases loadAliases(Config::get('aliases')); // Load user config $config = Parvula::getUserConfig(); // Append user config to Config wrapper (override if exists) Config::append((array) $config); // Auto set URLRewriting Config if (Config::get('URLRewriting') === 'auto') { $scriptName = $_SERVER['SCRIPT_NAME']; if (substr($_SERVER['REQUEST_URI'], 0, strlen($scriptName)) === $scriptName) { Config::set('URLRewriting', false); } else { Config::set('URLRewriting', true); } } // Load routes $router = new Router(Parvula::getURI()); require 'routes.php'; $router->run();
/** * Get user config * @return array */ public static function getUserConfig() { try { $confFs = new Files(DATA); $config = $confFs->read(Config::get('userConfig') . '.' . Config::get('fileExtension'), 'parseConfigData'); } catch (IOException $e) { exceptionHandler($e); } return $config; }