protected function _view($params) { $pageId = (int) $params['page']; $itemId = (int) $params['id']; $sql = "SELECT * FROM news WHERE page_id = {$pageId} AND id = {$itemId}"; $db =& $this->kobros->getPDO(); $stmt = $db->prepare($sql); $stmt->bindValue(1, $pageId, \PDO::PARAM_INT); $stmt->bindValue(2, $itemId, \PDO::PARAM_INT); $stmt->execute(); $news = array(); while ($res = $stmt->fetch(\PDO::FETCH_OBJ)) { $news[] = $res; } if (!sizeof($news)) { throw new Exception('No news be here'); } $view = new Core\View(); $view->item = $news[0]; $comments = array(); $sql = "SELECT * FROM news_comments WHERE news_id = ? ORDER BY created DESC"; $db =& $this->kobros->getPDO(); $stmt = $db->prepare($sql); $stmt->bindValue(1, $view->item->id, \PDO::PARAM_INT); $stmt->execute(); while ($res = $stmt->fetch(\PDO::FETCH_OBJ)) { $comments[] = $res; } $view->comments = $comments; return $view->render(ROOT . '/../templates/data/news/view.phtml'); }
protected function _search($params) { // @todo Dem actual search be missing on purpose! $view = new Core\View(); $view->page = $this->kobros->page; // If we has seartch string we poop it to template! $view->s = isset($params['s']) ? $params['s'] : ''; return $view->render(ROOT . '/../templates/data/search/search.phtml'); }
protected function _default($params) { $view = new Core\View(); $view->page = $this->kobros->page; $view->error = false; $sql = "SELECT * FROM question WHERE id = {$params['question_id']}"; $q = $this->kobros->db->query($sql); $question = $q->fetch(\PDO::FETCH_OBJ); $sql = "SELECT * FROM answer WHERE question_id = {$question->id}"; $q = $this->kobros->db->query($sql); $answers = array(); while ($res = $q->fetch(\PDO::FETCH_OBJ)) { $answers[] = $res; } // We put view $view = new Core\View(); $view->question = $question; $view->answers = $answers; $view->forward = $params['forward']; return $view->render(ROOT . '/../templates/data/poll/default.phtml'); }
protected function _edit($params) { // Uh oh our application may not work like we mean. // Well we fix later kludge for now so look better 4 customer than really are! ob_get_clean(); // If we want html from different page we get it if (isset($params['page']) && $params['page']) { $page = $this->kobros->getPage($params['page']); } else { // We not get it $page = $this->kobros->page; } // We fetch all from da base. $sql = "SELECT * FROM html WHERE block_id = {$params['block_id']} AND page_id = {$page->id}"; $q = $this->kobros->db->query($sql); // We put view $view = new View(); $view->html = $q->fetch(PDO::FETCH_OBJ); // User is needed because he has maybe admin right $view->user = $_SESSION['user']; return $view->render(ROOT . '/../templates/data/html/edit.phtml'); // die(); }
protected function _login($params) { $sql = "SELECT * FROM user WHERE login = :login AND password = :password"; $db =& $this->kobros->getPDO(); $stmt = $db->prepare($sql); $stmt->bindValue(':login', $params['login']); $stmt->bindValue(':password', $params['password']); $stmt->execute(); $res = $stmt->fetch(); if ($res) { session_regenerate_id(true); // We find user, we set dem sessions users. Rock on! $user = new \stdClass(); $user->login = $res->login; $user->role = $res->role; $_SESSION['user'] = $user; // Redirect if ($params['redirect']) { // If we have param redirect we use dat to redirect. $redirect = $params['redirect']; } elseif (isset($_SERVER['HTTP_REFERER'])) { // We know dem referes. We can go back there. $redirect = $_SERVER['HTTP_REFERER']; } else { $redirect = 'http://' . $_SERVER['HTTP_HOST'] . '/'; } $redirectHeader = "Location: {$redirect}"; header($redirectHeader); } else { $error = "Invalid username or password."; $view = new View(); $view->error = $error; $view->user = $_SESSION['user']; return $view->render(ROOT . '/../templates/data/user/default.phtml'); } }
/** * Main runner kobros * * @return string Html response to give user */ public function run() { // Init user $this->user = User::getInstance(); // Init view $this->view = new View(); // Fetch page. If no page use start page. $pageId = isset($_GET['page']) ? $_GET['page'] : $this->config['page_default']; $this->page = $page = $this->getPage($pageId); // If invalid page we throw exception if (!$this->page) { $this->page->title = 'Not found'; $this->view->innertpl = $this->view->render(__DIR__ . '/../templates/inner/404.phtml'); return $this->view->render(__DIR__ . '/../templates/outer/default.phtml'); } else { // Render inner-template $this->view->innertpl = $this->view->render(__DIR__ . '/../templates/inner/' . $page->innertpl . '.phtml'); } // If user request template we use it $tpl = isset($_GET['tpl']) ? $_GET['tpl'] : $page->tpl; // HTML TITLE is always page titel. $this->view->title = $this->page->title; // If admin role we include the admin scripts. $this->view->includeAdminScripts = false; if (isset($this->user->obj)) { $this->view->user = $this->user->obj; if ($this->user->obj->role == 'admin') { $this->view->includeAdminScripts = true; } } $tpl = preg_replace("/\\W/", '', $tpl); // Check if template exists $tpls = glob(__DIR__ . '/../templates/outer/*'); $template = $page->tpl; foreach ($tpls as $path) { if (basename($tpl, '.phtml')) { $template = $tpl; } } // We render outer template, inject inner teplate to it return $this->view->render(__DIR__ . '/../templates/outer/' . $template . '.phtml'); // All is good. }
protected function _thanks($params) { $view = new View(); return $view->render(ROOT . '/../templates/data/employ/thanks.phtml'); }