mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit 4f7541ad6f34a2ac5301c654e925fd47d4bbc489
parent a7cc731d775a826ec621e8467645cd2b3b364982
Author: markseu <mark2011@mayberg.se>
Date:   Wed, 19 Mar 2014 16:36:30 +0100

Better location handling (yellow kiwi remix)

Diffstat:
Msystem/core/core-webinterface.php | 7+++----
Msystem/core/core.php | 36+++++++++++++++++++-----------------
2 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/system/core/core-webinterface.php b/system/core/core-webinterface.php @@ -5,7 +5,7 @@ // Web interface core plugin class YellowWebinterface { - const Version = "0.2.6"; + const Version = "0.2.7"; var $yellow; //access to API var $users; //web interface users var $activeLocation; //web interface location? (boolean) @@ -24,13 +24,12 @@ class YellowWebinterface } // Handle web interface location - function onRequest($serverName, $serverBase, $location, $fileName) + function onRequest($location) { $statusCode = 0; if($this->checkWebinterfaceLocation($location)) { - $serverBase .= rtrim($this->yellow->config->get("webinterfaceLocation"), '/'); - list($location, $fileName) = $this->yellow->getRequestLocationFile($serverBase); + list($serverName, $serverBase, $location, $fileName) = $this->yellow->getRequestInformation($this->yellow->config->get("webinterfaceLocation")); if($this->checkUser()) $statusCode = $this->processRequestAction($serverName, $serverBase, $location, $fileName); if($statusCode == 0) $statusCode = $this->yellow->processRequest($serverName, $serverBase, $location, $fileName, false, $this->activeUserFail ? 401 : 0); diff --git a/system/core/core.php b/system/core/core.php @@ -5,7 +5,7 @@ // Yellow main class class Yellow { - const Version = "0.2.11"; + const Version = "0.2.12"; var $page; //current page data var $pages; //current page tree from file system var $config; //configuration @@ -58,16 +58,14 @@ class Yellow $this->toolbox->timerStart($time); ob_start(); $statusCode = 0; - $serverName = $this->config->get("serverName"); - $serverBase = $this->config->get("serverBase"); - list($location, $fileName) = $this->getRequestLocationFile($serverBase); + list($serverName, $serverBase, $location, $fileName) = $this->getRequestInformation(); $this->page = new YellowPage($this, $location); foreach($this->plugins->plugins as $key=>$value) { if(method_exists($value["obj"], "onRequest")) { $this->pages->requestHandler = $key; - $statusCode = $value["obj"]->onRequest($serverName, $serverBase, $location, $fileName); + $statusCode = $value["obj"]->onRequest($location); if($statusCode != 0) break; } } @@ -171,11 +169,6 @@ class Yellow { $this->page->error(500, "Parser '".$this->page->get("parser")."' does not exist!"); } - list($contentType) = explode(';', $this->page->getHeader("Content-Type")); - if(!$this->toolbox->isValidContentType($contentType, $this->page->getLocation())) - { - $this->page->error(500, "Type '$contentType' does not match name!"); - } $statusCode = $this->page->statusCode; if($statusCode==200 && $this->getRequestHandler()=="core" && $this->page->isExisting("redirect")) { @@ -193,6 +186,12 @@ class Yellow if($this->page->isHeader("Cache-Control")) $responseHeader = "Cache-Control: ".$this->page->getHeader("Cache-Control"); $this->page->clean($statusCode, $responseHeader); } + list($contentType) = explode(';', $this->page->getHeader("Content-Type")); + if($statusCode==200 && !$this->toolbox->isValidContentType($contentType, $this->page->getLocation())) + { + $statusCode = 500; + $this->page->error($statusCode, "Type '$contentType' does not match name!"); + } if($this->page->isExisting("pageClean")) ob_clean(); if(PHP_SAPI != "cli") { @@ -219,9 +218,12 @@ class Yellow } } - // Return request location and file name, without server base - function getRequestLocationFile($serverBase) + // Return request information + function getRequestInformation($serverBaseLocation = "") { + $serverName = $this->config->get("serverName"); + $serverBase = $this->config->get("serverBase"); + if(!empty($serverBaseLocation)) $serverBase .= rtrim($serverBaseLocation, '/'); $location = $this->toolbox->getLocationNormalised(); $location = substru($location, strlenu($serverBase)); $fileName = $this->toolbox->findFileFromLocation($location, @@ -231,13 +233,13 @@ class Yellow { $location = rtrim($location, '/'); $fileName = $this->toolbox->findFileFromLocation($location, - $this->config->get("contentDir"), $this->config->get("contentHomeDir"), - $this->config->get("contentDefaultFile"), $this->config->get("contentExtension")); + $this->config->get("contentDir"), $this->config->get("contentHomeDir"), + $this->config->get("contentDefaultFile"), $this->config->get("contentExtension")); } - return array($location, $fileName); + return array($serverName, $serverBase, $location, $fileName); } - // Return name of request handler + // Return request handler function getRequestHandler() { return $this->pages->requestHandler; @@ -834,7 +836,7 @@ class YellowPages { var $yellow; //access to API var $pages; //scanned pages - var $requestHandler; //request handler + var $requestHandler; //request handler name var $serverBase; //requested server base var $snippetArgs; //requested snippet arguments