mikuli.cz

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

commit edad970a0a075f3d83d173b71292f8063d6aff5e
parent 9ce484a9476e56539856f5b21530fe3c9e61f33d
Author: markseu <mark2011@mayberg.se>
Date:   Sat, 17 May 2014 21:46:23 +0200

Better location handling (icecream remix)

Diffstat:
Msystem/core/core-markdownextra.php | 11+++++++----
Msystem/core/core.php | 29+++++++++++++++++++++--------
2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/system/core/core-markdownextra.php b/system/core/core-markdownextra.php @@ -5,7 +5,7 @@ // Markdown extra core plugin class YellowMarkdownExtra { - const Version = "0.2.9"; + const Version = "0.2.10"; var $yellow; //access to API // Initialise plugin @@ -38,12 +38,15 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser // Transform page text function transformPage($page, $text) { - $location = $this->yellow->toolbox->getDirectoryLocation($page->getLocation()); $text = preg_replace("/@pageRead/i", $page->get("pageRead"), $text); $text = preg_replace("/@pageEdit/i", $page->get("pageEdit"), $text); $text = preg_replace("/@pageError/i", $page->get("pageError"), $text); - return preg_replace("/<a(.*?)href=\"(?!javascript:)([^\/\"]+)\"(.*?)>/i", - "<a$1href=\"$location$2\"$3>", $this->transform($text)); + $callback = function($matches) use ($page) + { + $matches[2] = $page->yellow->toolbox->normaliseLocation($matches[2], $page->base, $page->location); + return "<a$matches[1]href=\"$matches[2]\"$matches[3]>"; + }; + return preg_replace_callback("/<a(.*?)href=\"([^\"]+)\"(.*?)>/i", $callback, $this->transform($text)); } // Return unique id attribute 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.19"; + const Version = "0.2.20"; var $page; //current page var $pages; //pages from file system var $config; //configuration @@ -175,11 +175,7 @@ class Yellow if($statusCode==200 && $this->getRequestHandler()=="core" && $this->page->isExisting("redirect")) { $statusCode = 301; - $location = $this->page->get("redirect"); - if(preg_match("/^[^\/]+$/", $location)) - { - $location = $this->toolbox->getDirectoryLocation($this->page->getLocation()).$location; - } + $location = $this->toolbox->normaliseLocation($this->page->get("redirect"), $this->page->base, $this->page->location); $locationHeader = $this->toolbox->getLocationHeader($this->page->serverScheme, $this->page->serverName, "", $location); $this->page->clean($statusCode, $locationHeader); $this->page->setHeader("Last-Modified", $this->page->getModified(true)); @@ -230,7 +226,7 @@ class Yellow $serverScheme = empty($serverScheme) ? $this->config->get("serverScheme") : $serverScheme; $serverName = empty($serverName) ? $this->config->get("serverName") : $serverName; $base = empty($base) ? $this->config->get("serverBase") : $base; - $location = $this->toolbox->getLocationNormalised(); + $location = $this->toolbox->getLocationClean(); $location = substru($location, strlenu($base)); $fileName = $this->toolbox->findFileFromLocation($location, $this->config->get("contentDir"), $this->config->get("contentHomeDir"), @@ -1229,7 +1225,7 @@ class YellowToolbox } // Return location from current HTTP request, remove unwanted path tokens - function getLocationNormalised() + function getLocationClean() { $string = $this->getLocation(); $location = ($string[0]=='/') ? '' : '/'; @@ -1535,6 +1531,23 @@ class YellowToolbox return preg_replace("/[^\pL\d\-\_\.]/u", "-", $text); } + // Normalise location, make absolute page location + function normaliseLocation($location, $pageBase, $pageLocation) + { + if(!preg_match("/^\w+:/", $location)) + { + if(preg_match("/^[^\/]+$/", $location)) + { + $location = $this->getDirectoryLocation($pageBase.$pageLocation).$location; + } + else if(!preg_match("#^$pageBase#", $location)) + { + $location = $pageBase.$location; + } + } + return $location; + } + // Normalise location arguments function normaliseArgs($text, $appendSlash = true, $filterStrict = true) {