public function __construct() { $this->app = App::getInstance(); $this->view = View::getInstance(); $this->config = $this->app->getConfig(); $this->input = InputData::getInstance(); $this->session = $this->app->getSession(); $this->db = new SimpleDB(); }
/** * @param Request $request * @param Response $response * @return bool */ public function run(Request $request, Response $response) { $routes = App::instance()->getConfig('routes'); $router = App::instance()->getService('router'); $router->setRoutes($routes); $controller = $router->getController($request); $actionData = $router->getAction($request); $request->setController($controller); $request->setAction($actionData['name']); $request->setParameters($actionData['params']); return true; }
<?php use mvc\App; define('PATH_ROOT', __DIR__ . '/../'); define('PATH_CONFIG', PATH_ROOT . "/config/"); require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../mvc/Bootstrap.php'; spl_autoload_register(['Bootstrap', 'loadClass']); App::instance()->run();
private function ValidateAuthorization($doc) { $doc = strtolower($doc); $notLoggedRegex = '/@notlogged/'; preg_match($notLoggedRegex, $doc, $matches); if ($matches) { if (App::getInstance()->getSession()->_login) { throw new \Exception("Already logged in!", 400); } } $authorizeRegex = '/@authorize(?:\\s+error:\\("(.+)"\\))?/'; preg_match($authorizeRegex, $doc, $matches); if ($matches) { $error = 'Unauthorized!'; if ($matches[1]) { $error = ucfirst($matches[1]); } if (!App::getInstance()->getSession()->_login) { throw new \Exception($error, 401); } } $adminRegex = '/@admin/'; preg_match($adminRegex, $doc, $matches); if ($matches) { if (!SimpleDB::isAdmin()) { throw new \Exception("Admin access only!", 401); } } $roleRegex = '/@role\\s*\\("(.+)"\\)/'; preg_match($roleRegex, $doc, $matches); if ($matches[1]) { $role = $matches[1]; if (!SimpleDB::hasRole($role) && !SimpleDB::isAdmin()) { $role = ucfirst($role); throw new \Exception("{$role} access only!", 401); } } }
?> </p> <?php } ?> <?php if (count($conference->getAdmins()) < 1) { ?> <p><i>No administrators registered at this point.</i></p> <?php } ?> </div> </div> <?php if (\Mvc\App::getInstance()->isLogged()) { ?> <?php \Mvc\FormViewHelper::init()->initLink()->setAttribute('href', "/conference/maxLectures/{$confId}")->setAttribute('class', 'margin-right float-right btn btn-info')->setValue('Max Lectures')->create()->render(); ?> <?php \Mvc\FormViewHelper::init()->initLink()->setAttribute('href', "/conference/lectures/{$confId}")->setAttribute('class', 'margin-right float-right btn btn-info')->setValue('Lectures')->create()->render(); ?> <?php } ?> </div> <?php } ?> </div>
public static function isAdmin() : bool { $statement = self::$database->prepare("SELECT u.id\n FROM user_roles ur\n JOIN users u\n ON u.id = ur.user_id\n WHERE (u.username = ? AND u.id = ?) AND ur.role_id = 2"); $statement->bindParam(1, App::getInstance()->getSession()->_username); $statement->bindParam(2, App::getInstance()->getSession()->_login); $statement->execute(); $response = $statement->fetch(\PDO::FETCH_ASSOC); if ($response) { $id = Normalizer::normalize($response['isAdmin'], 'bool'); return true; } return false; }
<div class="row"> <?php $lecture = $this->_viewBag['body']; if (true) { ?> <div class="blueish panel panel-default col-md-12 margin-right"> <div class="panel-body"> <?php if (\Mvc\App::getInstance()->isLogged() && $_SESSION['role'] == 'site administrator') { ?> <a class="margin-right float-right panel panel-danger col-sm-1 btn btn-default text-center" href="/lecture/editLecture/<?php echo $lecture->getId(); ?> /edit">Edit lecture</a> <?php if ($_SESSION['role'] == 'site administrator') { ?> <a class="margin-right float-right panel panel-danger col-sm-1 btn btn-default text-center" href="/lecture/removeLecture/<?php echo $lecture->getId(); ?> /remove">Remove</a> <?php } ?> <?php } ?> <div class="block"> <a class="panel panel-danger col-sm-4 btn btn-default text-center"
<div class="panel"> <h2 class="form-group">Username: <?php echo $this->_viewBag['body']->getUsername(); ?> <?php if ($_SESSION['role'] === 'site administrator') { ?> <h3 class="form-group">Email: <?php echo $this->_viewBag['body']->getEmail(); ?> <?php } ?> </h3> <?php if (strtolower($this->_viewBag['body']->getUsername()) === strtolower(\Mvc\App::getInstance()->getUsername())) { ?> <?php \Mvc\FormViewHelper::init()->initForm('/user/changePass', ['class' => 'form-group'], 'put')->initLabel()->setValue("Old Password")->setAttribute('for', 'oldPassword')->create()->initPasswordBox()->setAttribute('id', 'oldPassword')->setName('oldPassword')->setAttribute('class', 'form-control input-md')->create()->initLabel()->setValue("New Password")->setAttribute('for', 'newPassword')->create()->initPasswordBox()->setAttribute('id', 'newPassword')->setName('newPassword')->setAttribute('class', 'form-control input-md')->create()->initLabel()->setValue("Confirm Password")->setAttribute('for', 'conPassword')->create()->initPasswordBox()->setAttribute('id', 'conPassword')->setName('confirm')->setAttribute('class', 'form-control input-md')->create()->initSubmit()->setAttribute('value', 'Change password')->setAttribute('class', 'btn btn-default')->create()->render(); } ?> </div>
<?php ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); use Mvc\App; include '../../Mvc-Framework/App.php'; include '../Routers/DummyRouter.php'; $app = App::getInstance(); $app->run();
if ($check) { ?> <span class="orange"> You'll attend another lecture in this time </span> <?php } ?> <?php } ?> <?php } ?> <?php if (!(\Mvc\App::getInstance()->isLogged() && !in_array($lecture->getId(), $_SESSION['response1'])) && $lecture->getHallCount() > $lecture->getUsersRegistered()) { ?> <div class="block"></div> <?php } ?> <p class="float-right"> <i>Registered:</i> <?php echo $lecture->getUsersRegistered(); ?> /<?php echo $lecture->getHallCount(); ?> </p> </div> </div> </div>
</ul> <?php } else { ?> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo \Mvc\App::getInstance()->getUsername(); ?> <span class="caret"></span></a> <ul class="dropdown-menu"> <li><?php \Mvc\FormViewHelper::init()->initLink()->setAttribute('href', "/user/" . \Mvc\App::getInstance()->getUsername() . "/profile")->setValue('Profile')->create()->render(); ?> </li> <li><?php \Mvc\FormViewHelper::init()->initLink()->setAttribute('href', '/lecture/my')->setValue('My schedule')->create()->render(); ?> </li> <li><?php \Mvc\FormViewHelper::init()->initLink()->setAttribute('href', "/users/all/0/10")->setValue('All users')->create()->render(); ?> </li> <li role="separator" class="divider"></li> <li> <?php Mvc\FormViewHelper::init()->initLink()->setAttribute('href', '/user/logout')->setValue('Logout')->create()->render(); ?>
<?php include 'MVC/App.php'; $app = \MVC\App::getInstance(); $app->run(); //new \HHTH\THTHT\Test(); print_r(\MVC\Loader::getNamespaces());