public function on_start() { $c = Page::getByPath('/dashboard/blocks/stacks'); $cp = new Permissions($c); if ($cp->canViewPage()) { $c = Page::getCurrentPage(); $pcp = new Permissions($c); if (!$pcp->canViewPageVersions() || $_GET['vtask'] != 'view_versions' && $_GET['vtask'] != 'compare') { $cID = $c->getCollectionID(); $this->redirect('/dashboard/blocks/stacks', 'view_details', $cID); } else { $this->theme = 'dashboard'; } } else { global $c; // ugh $v = View::getInstance(); $c = new Page(); $c->loadError(COLLECTION_NOT_FOUND); $v->setCollectionObject($c); $this->c = $c; $cont = Loader::controller("/page_not_found"); $v->setController($cont); $v->render('/page_not_found'); } }
/** * Is responsible for taking a method passed and ensuring that it is valid for the current request. You can't * 1. Pass a method that starts with "on_" * 2. Pass a method that's in the restrictedMethods array */ private function setupRequestTask() { $req = Request::get(); // we are already on the right page now // let's grab the right method as well. $task = substr('/' . $req->getRequestPath(), strlen($req->getRequestCollectionPath()) + 1); // remove legacy separaters $task = str_replace('-/', '', $task); // grab the whole shebang $taskparts = explode('/', $task); if (isset($taskparts[0]) && $taskparts[0] != '') { $method = $taskparts[0]; } if ($method == '') { if (is_object($this->c) && is_callable(array($this, $this->c->getCollectionHandle()))) { $method = $this->c->getCollectionHandle(); } else { $method = 'view'; } $this->parameters = array(); } $foundTask = false; try { $r = new ReflectionMethod(get_class($this), $method); $cl = $r->getDeclaringClass(); if (is_object($cl)) { if ($cl->getName() != 'Controller' && strpos($method, 'on_') !== 0 && strpos($method, '__') !== 0 && $r->isPublic()) { $foundTask = true; } } } catch(Exception $e) { } if ($foundTask) { $this->task = $method; if (!is_array($this->parameters)) { $this->parameters = array(); if (isset($taskparts[1])) { array_shift($taskparts); $this->parameters = $taskparts; } } } else { $this->task = 'view'; if (!is_array($this->parameters)) { $this->parameters = array(); if (isset($taskparts[0])) { $this->parameters = $taskparts; } } // finally we do a 404 check in this instance // if the particular controller does NOT have a view method but DOES have arguments passed // we call 404 $do404 = false; if (!is_object($this->c)) { // this means we're calling the render directly, so we never 404 $do404 = false; } else if (!is_callable(array($this, $this->task)) && count($this->parameters) > 0) { $do404 = true; } else if (is_callable(array($this, $this->task)) && (get_class($this) != 'PageForbiddenController')) { // we use reflection to see if the task itself, which now much exist, takes fewer arguments than // what is specified $r = new ReflectionMethod(get_class($this), $this->task); if ($r->getNumberOfParameters() < count($this->parameters)) { $do404 = true; } } if ($req->isIncludeRequest()) { $do404 = false; } if ($do404) { // this is hacky, the global part global $c; $v = View::getInstance(); $c = new Page(); $c->loadError(COLLECTION_NOT_FOUND); $v->setCollectionObject($c); $this->c = $c; $cont = Loader::controller("/page_not_found"); $v->setController($cont); $v->render('/page_not_found'); } } }
/** * Our new MVC way of doing things. Parses the collection path using like to find * where the path stops and the parameters start. Enables us to use urls without a * task/param separator in them * @return Page */ public function getRequestedPage() { $path = $this->getRequestCollectionPath(); $origPath = $path; $r = Cache::get('request_path_page', $path); if ($r == false) { $r = array(); $db = Loader::db(); $cID = false; while (!$cID && $path) { $cID = $db->GetOne('select cID from PagePaths where cPath = ?', $path); if ($cID) { $cPath = $path; break; } $path = substr($path, 0, strrpos($path, '/')); } /* // Get the longest path (viz most specific match) that is contained // within the request path $db = Loader::db(); $r = $db->Execute("select cID,cPath from PagePaths where ? LIKE CONCAT(replace(cPath, '_','\_'),'%') ORDER BY LENGTH(cPath) DESC LIMIT 0,1", array($this->getRequestCollectionPath())); $r = $r->FetchRow(); */ if ($cID && $cPath) { $r['cID'] = $cID; $r['cPath'] = $cPath; Cache::set('request_path_page', $origPath, $r); } } if (is_array($r)) { $req = Request::get(); $cPath = $r['cPath']; $cID = $r['cID']; $req->setCollectionPath($cPath); $c = Page::getByID($cID, 'ACTIVE'); } else { $c = new Page(); $c->loadError(COLLECTION_NOT_FOUND); } return $c; }
/** * our new MVC way of doing things. Parses the collection path using like to find * where the path stops and the parameters start. Enables us to use urls without a * task/param separator in them */ public function getRequestedPage() { $path = $this->getRequestCollectionPath(); $r = Cache::get('request_path_page', $path); if ($r == false) { // Get the longest path (viz most specific match) that is contained // within the request path $db = Loader::db(); $r = $db->Execute("select cID,cPath from PagePaths where ? LIKE CONCAT(replace(cPath, '_','\\_'),'%') ORDER BY LENGTH(cPath) DESC LIMIT 0,1", array($this->getRequestCollectionPath())); $r = $r->FetchRow(); if (is_array($r)) { Cache::set('request_path_page', $path, $r); } } if (is_array($r)) { $req = Request::get(); $cPath = $r['cPath']; $cID = $r['cID']; $req->setCollectionPath($cPath); $c = Page::getByID($cID); } else { $c = new Page(); $c->loadError(COLLECTION_NOT_FOUND); } return $c; }
/** * Our new MVC way of doing things. Parses the collection path using like to find * where the path stops and the parameters start. Enables us to use urls without a * task/param separator in them * @return Page */ public function getRequestedPage() { $path = $this->getRequestCollectionPath(); $origPath = $path; $r = array(); $db = Loader::db(); $cID = false; while (!$cID && $path) { $cID = $db->GetOne('select cID from PagePaths where cPath = ?', $path); if ($cID) { $cPath = $path; break; } $path = substr($path, 0, strrpos($path, '/')); } if ($cID && $cPath) { $req = Request::get(); $req->setCollectionPath($cPath); $c = Page::getByID($cID, 'ACTIVE'); } else { $c = new Page(); $c->loadError(COLLECTION_NOT_FOUND); } return $c; }