/** * executes all controllers and compile the final HTML Document. * * @return string finalHTML */ public function execute() { if (HANDHELD) { header('Pragma: public'); header("Expires: " . gmdate("Y-m-d\\TH:i:s\\Z", time() + 60 * 30)); header('Cache-Control: no-store, must-revalidate, post-check=0, pre-check=0, no-transform, max-age=1800'); } foreach ($this->mountPoints as $column => $controllers) { ${$column} = ""; foreach ($controllers as $c) { ${$column} .= $c->execute(); } } $pageTitle = $this->title; $pageDescription = $this->description; $bodyClass = $this->bodyClass; foreach (registry::getInstance() as $k => $v) { ${$k} = $v; } isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); ob_start(); require $this->file; // output is gzipped and minified (NO; PROBLEMS WITH CODE BLOCKS!). // ob_postprocess(trim(preg_replace('/\s+/', ' ', ob_get_clean()))); echo ob_get_clean(); }
/** * Compile the view * * @return $HTMLSource the compiled view */ public function compile() { $registry =& registry::getInstance(); $user =& user::getInstance(); foreach ($registry->fetchWhole() as $k => $v) { ${$k} = $v; } ob_start(); require $this->file; $body = ob_get_clean(); isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); if ($this->hasLayout) { ob_start(); require strchr($bodyid, 'admin') ? LAYOUT_ADMIN : LAYOUT; return ob_get_clean(); } else { return $body; } }
/** * Compile the view * * @return $HTMLSource the compiled view */ public function compile($registry = false) { if ($registry === false) { $registry =& registry::getInstance(); } $user =& user::getInstance(); foreach ($registry as $k => $v) { ${$k} = $v; } ob_start(); require $this->file; $body = ob_get_clean(); isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); $isFragment = isset($this->isFragment); if (defined('LAYOUT') && !$isFragment) { ob_start(); require LAYOUT; $body = ob_get_clean(); } return $body; }
<?php /** * do.login.php * * login script * @author Anders Ytterström <*****@*****.**> * @since 2007-08-13 */ require '../../../init.php'; $registry =& registry::getInstance(); $user =& user::getInstance(); $model = new model_photos(); $name = http_request::getString('id'); $alt = http_request::getString('alt'); $body = http_request::getString('body'); if (!$user->isOnline()) { http_response::redir('/login.php'); } if (!$alt || !$body) { form::setSF('editPhoto', array('alt' => $alt, 'body' => $body)); $_SESSION['msg'] = "badData"; http_response::redir('/admin/fotoalbum/redigera.php?id=' . $name); } $model->update($name, $alt, $body); form::clearSF('editPhoto'); $_SESSION['success'] = true; http_response::redir('/admin/fotoalbum/');
<?php /** * fotoalbum.php * * photoalbum admin page * @author Anders Ytterström <*****@*****.**> * @since 2007-12-29 */ require '../../../init.php'; if (!isset($_POST['delete'])) { http_response::redir('/admin/fotoalbum'); } $registry =& registry::getInstance(); $user =& user::getInstance(); $view = new view(ROOT . '/view/admin/photos/delete.phtml'); $model = new model_photos(); if (!$user->isOnline()) { http_response::redir('/login.php'); } $registry['sidebar'] = false; $registry['delete'] = $_POST['delete']; echo $view->compile();
function go($force = 0, $asis = 0) { #-- prepare parts $url = $this->prepare_url(); if (!$url && !$force) { return; } $BODY = $this->body($url); if ($BODY === false && !$force) { return; } $HEAD = $this->head($url); #-- open socket if (!$this->connect($url)) { return; } #-- send request data fwrite($this->socket, $HEAD); fwrite($this->socket, $BODY); $HEAD = false; $BODY = false; #-- read response, end connection while (!feof($this->socket) && strlen($DATA) <= 1 << 22) { $DATA .= fread($this->socket, 32 << 10); #echo "fread(".strlen($DATA).") "; } fclose($this->socket); unset($this->socket); #-- for raw http pings if ($asis) { return $DATA; } #-- decode response $r = new http_response(); $r->from($DATA); // should auto-unset $DATA #-- handle redirects if ($this->active_client) { $this->auto_actions($r); } #-- fin return $r; }
/** * parse the url and search for a matching rule. If match, return new controller object. If page, * add view object to controller. * * @return controller the resolved controller */ public function delegate($uri = false) { $reg = registry::getInstance(); $routes = $this->getSummary(); $isCrud = "/\\.do\$/"; // makes it possible to have the boot strap not in root, // ex http://site.com/project1/lolcat // found at http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/ $requestURI = explode('/', $_SERVER['REQUEST_URI']); $scriptName = explode('/', $_SERVER['SCRIPT_NAME']); for ($i = 0, $max = count($scriptName); $i < $max; $i++) { if ($requestURI[$i] == $scriptName[$i]) { unset($requestURI[$i]); } } $path = '/' . join('/', $requestURI); // login halts further execution. if ($path === '/login.do') { require LIBRARY . '/auth/login.php'; die; } if ($path === '/logout.do') { require LIBRARY . '/auth/logout.php'; die; } $action = preg_match($isCrud, $path) ? 'crud' : 'page'; $delegated = false; foreach ($routes as $route) { $matchCorrect = preg_match_all($route['pattern'], $path, $matches); $containsVars = false; $vars = explode(',', $route['args']); foreach ($vars as $v) { if (strlen($v) > 0 && !strpos($v, '=')) { $containVars = true; } } if ($containsVars) { // there is variables in the uri, check them $vars = explode(',', $route['args']); if (is_array($vars) && strlen($vars[0]) == 0) { unset($vars[0]); } $varsCorrect = count($matches) - 1 === count($vars); } else { // no vars in the uri, sign it ok $varsCorrect = true; } if ($matchCorrect != 0 && $varsCorrect) { for ($r = 0, $maxR = count($vars); $r < $maxR; $r++) { if ($vars[$r] != '') { if (strpos($vars[$r], '=')) { // fördefinierad, uri skippas $kv = explode('=', $vars[$r]); $_GET[$kv[0]] = $_REQUEST[$kv[0]] = $kv[1]; } else { // från uri $_GET[$vars[$r]] = $_REQUEST[$vars[$r]] = $matches[$r + 1][0]; } } } $controllers = $this->getEntity($route['id']); $reg['route'] = new page(); foreach ($controllers as $controller) { $reg['route']->addContent($controller['mpId'], new controller_page($controller['service'], $controller['action'])); } $reg['route']->execute(); $delegated = true; break; } } if ($delegated == false) { // try to resolve anonymous controller /* todo: här ska applikationen försöka hitta en ensam page controller. */ try { if ($action == 'crud') { preg_match("/^(.+?)\\/(.+?)\\.do\$/", $path, $matches); $service = $matches[1]; $controller = $matches[2]; $controller = new controller_crud($service, $controller); $controller->execute(); } else { http_response::redir('/'); } } catch (Exception $e) { throw $e; } } }
/** * parse the url and search for a matching rule. If match, return new controller object. If page, * add view object to controller. * * @return controller the resolved controller */ public function delegate($uri = false) { function removeEmpty($arr) { return !(strlen($arr) == 0); } $defaultPage = $this->rules[0]; $loginPage = $this->rules[1]; $registry =& registry::getInstance(); $user =& user::getInstance(); if ($uri == false) { $uri = parse_url(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/', PHP_URL_PATH); } $this->output = substr(strrchr($uri, '.'), 0); $this->task = explode('/', substr($uri, strpos($uri, '/'))); array_shift($this->task); $this->task = array_filter($this->task, 'removeEmpty'); // see if the uri pointt directly to a page $task = "/"; foreach ($this->task as $t) { $task .= $t . ' '; } $task = strtr(trim($task), ' ', '/'); $action_path = sprintf("%s/pages%s", CONTROLLER, $task); $template_path = sprintf("%s%s", VIEW, $task); $action_path .= is_dir($action_path) && file_exists($action_path . '/index.php') ? '/index.php' : '.php'; $template_path .= is_dir($template_path) && file_exists($template_path . '/index.phtml') ? '/index.phtml' : '.phtml'; if (is_file($action_path) || is_file($template_path)) { $requireUser = in_array($task, $this->closed); $userOnline = $user->isOnline(); if ($requireUser && !$userOnline) { http_response::redir('/login'); die; } $view = new view($template_path); $controller = file_exists($action_path) ? $action_path : false; return new controller($controller, $view); } // no easy way, search rules $rule = array(); foreach ($this->rules as $r) { if ($this->findRule($r)) { $rule += $r; } } if (count($rule) == 0) { throw new Exception('no request match'); } $requireUser = in_array($rule[0], $this->closed); $userOnline = $user->isOnline(); if ($requireUser && !$userOnline) { $rule = $loginPage; } foreach ($rule[2] as $k => $v) { $_GET[$v] = $_REQUEST[$v] = $this->task[$k]; } if ($this->output == '.do') { $action_path = sprintf('%s/%s/%s.php', CONTROLLER, isset($noscript) ? 'pages' : 'scripts', $rule[0]); if (!file_exists($action_path)) { throw new Exception(sprintf('controller file <em>%s</em> missing!', $action_path)); } $controller = new controller($action_path); } else { $action_path = CONTROLLER . '/pages' . $rule[0] . '.php'; if (!file_exists($action_path)) { $action_path = false; } $template_path = VIEW . $rule[0] . '.phtml'; if (!file_exists($template_path)) { throw new Exception('template file ' . $template_path . ' missing!'); } $view = new view($template_path); $controller = new controller($action_path, $view); } return $controller; }
<?php /** * */ $registry =& registry::getInstance(); $user = user::getInstance(); $name = http_request::getUserName('alias'); $password = http_request::getPassword('passwd'); $remember = isset($_POST['remember_me']) && $_POST['remember_me'] === 1 ? 1 : false; if (!$name || !$password) { throw new Exception('Either the alias was not a proper alias, or the password was not a proper password. given alias: ' . $name . '<br>given password: '******'Login failed: either no such user exists, or either of the password or the alias was wrong.'); } $groups = $user->getGroupsById($userdata['id']); $user->setOnline($userdata['id'], $userdata['name'], $groups, $remember); http_response::redir($_SERVER['HTTP_REFERER']);
<?php $modelLabel = http_request::getString('model'); $actionLabel = http_request::getString('action'); $validActions = array('new.do', 'edit.do'); if ($actionLabel == false || !in_array($actionLabel, $validActions)) { http_response::redir('/admin/index'); } // see if there is any controller actions and include the file if so. if ($actionLabel != false) { $controller = sprintf("%s/scripts/%s/%s.php", CONTROLLER, $modelLabel, substr($actionLabel, 0, strpos($actionLabel, '.'))); if (file_exists($controller)) { require $controller; } }
$returnPath = sprintf("/admin/model/%s/new", $registry['modelLabel']); } else { $formId = sprintf("%s%s", strtolower(substr($registry['actionRoute'], 0, strrpos($registry['actionRoute'], '.'))), ucfirst($registry['modelLabel'])); if (array_sum($checksum) == count($checksum) * 2) { $entityId = $model->append($values); file::renameTemp($registry['modelLabel'], $entityId); if ($registry['controls']['tags']) { tag::set($registry['modelLabel'], $entityId, $registry['controls']['tags']->validate()); } form::clearSF($formId); if (isset($_SESSION['changePasswd'])) { unset($_SESSION['changePasswd']); } $returnPath = sprintf("/admin/model/%s", $registry['modelLabel']); } else { form::setSF($formId, $sfvalues, $sferrors); } } } } else { if ($registry['actionRoute'] == "delete.do") { } } } logModelAction($entityId); // go! if ($returnPath == "") { http_response::back(); } else { http_response::redir($returnPath); }
<?php $registry =& registry::getInstance(); $user =& user::getInstance(); if (isLocked('login')) { throw new Exception('You are not allowed to log out!'); } else { $user->logout(); } http_response::back();
<?php /** * logout.php * * logout procedure * @author Anders Ytterström <*****@*****.**> * @since 2007-08-13 */ $registry =& registry::getInstance(); $user =& user::getInstance(); if (isLocked('login')) { throw new Exception('You are not allowed to log out!'); } else { $user->logout(); } http_response::redir('/admin');
$body = http_request::getString('body'); //$delete = http_request::getCheckboxes('delete',array('1')); $action = http_request::getString('action'); // conditions for further execution if (!$user->isOnline()) { http_response::redir('/login.php'); } if (!$alt || !$body || $action == "new" && count($_FILES) == 0) { echo $alt . "<br>"; echo $body . "<br>"; // redirect and tell user that input contained errors. die("sopa"); } // delete action is chosen, delete photo. //if($delete[0] == '1') { // $model->delete($name); // http_response::redir('/admin/fotoalbum.php?success=delete'); //} else { // new photo is uploaded, append to model. if ($action == 'new') { $names = $modeld->append("file", array('png', 'jpg'), 1024 * 1024); $modeld->createThumbnail($names[1], true, 150, 150); $name = $names[0]; $model->append($name, $alt, $body); http_response::redir('/admin/fotoalbum.php?success=new'); } else { // update of photo data, save changes. $model->update($name, $alt, $body); http_response::redir('/admin/fotoalbum.php?success=update'); } //}
<?php /** * do.login.php * * login script * @author Anders Ytterström <*****@*****.**> * @since 2007-08-13 */ require '../init.php'; $registry =& registry::getInstance(); $user =& user::getInstance(); $model = new model_content(); if (!$user->isOnline()) { http_response::redir('/login.php'); } $id = http_request::getString('id'); $body = http_request::getString('body'); $description = http_request::getString('description'); $title = http_request::getString('title'); $model->update($id, $title, $description, $body); http_response::redir('/admin/innehall.php');
<?php /** * do.login.php * * login script * @author Anders Ytterström <*****@*****.**> * @since 2007-08-13 */ require 'init.php'; //$registry =& registry::getInstance(); $user =& user::getInstance(); $user->logout(); http_response::redir('/');