mikuli.cz

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

commit 6a071c1c5fa513d9233ae70c48388678ad868118
parent fede941163cfb845a09b0215e0274566e556a889
Author: markseu <mark2011@mayberg.se>
Date:   Mon, 27 Jan 2014 12:30:39 +0100

Better location handling

Diffstat:
Msystem/core/core-markdownextra.php | 20+++++++++++---------
Msystem/core/core-webinterface.php | 29++++++++++++++++++++++-------
Msystem/core/core.php | 27+++++++++++++++------------
Msystem/snippets/footer.php | 2+-
Msystem/snippets/header.php | 2+-
5 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/system/core/core-markdownextra.php b/system/core/core-markdownextra.php @@ -1,11 +1,11 @@ <?php -// Copyright (c) 2013 Datenstrom, http://datenstrom.se +// Copyright (c) 2013-2014 Datenstrom, http://datenstrom.se // This file may be used and distributed under the terms of the public license. // Markdown extra core plugin class YellowMarkdownExtra { - const Version = "0.2.5"; + const Version = "0.2.6"; var $yellow; //access to API var $textHtml; //generated text (HTML format) @@ -16,10 +16,10 @@ class YellowMarkdownExtra } // Handle text parsing - function onParse($text) + function onParse($page, $text) { $markdown = new YellowMarkdownExtraParser($this->yellow); - return $this->textHtml = $markdown->transform($text); + $this->textHtml = $markdown->transform($page, $text); } } @@ -35,12 +35,14 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser } // Transform text - function transform($text) + function transform($page, $text) { - $text = preg_replace("/@pageRead/i", $this->yellow->page->get("pageRead"), $text); - $text = preg_replace("/@pageEdit/i", $this->yellow->page->get("pageEdit"), $text); - $text = preg_replace("/@pageError/i", $this->yellow->page->get("pageError"), $text); - return parent::transform($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>", parent::transform($text)); } // Handle links diff --git a/system/core/core-webinterface.php b/system/core/core-webinterface.php @@ -1,11 +1,11 @@ <?php -// Copyright (c) 2013 Datenstrom, http://datenstrom.se +// Copyright (c) 2013-2014 Datenstrom, http://datenstrom.se // This file may be used and distributed under the terms of the public license. // Web interface core plugin class YellowWebinterface { - const Version = "0.2.4"; + const Version = "0.2.5"; var $yellow; //access to API var $users; //web interface users var $activeLocation; //web interface location? (boolean) @@ -45,19 +45,26 @@ class YellowWebinterface return $statusCode; } + // Handle page meta data parsing + function onParseMeta($page, $text) + { + if($this->isWebinterfaceLocation() && $this->isUser()) + { + if($page == $this->yellow->page) + { + if(empty($this->rawDataOriginal)) $this->rawDataOriginal = $page->rawData; + } + } + } + // Handle page content parsing function onParseContent($page, $text) { $output = NULL; if($this->isWebinterfaceLocation() && $this->isUser()) { - $serverBase = $this->yellow->config->get("serverBase"); - $webinterfaceLocation = trim($this->yellow->config->get("webinterfaceLocation"), '/'); - $output = preg_replace("#<a(.*?)href=\"$serverBase/(?!$webinterfaceLocation)(.*?)\"(.*?)>#", - "<a$1href=\"$serverBase/$webinterfaceLocation/$2\"$3>", $text); if($page == $this->yellow->page) { - if(empty($this->rawDataOriginal)) $this->rawDataOriginal = $page->rawData; switch($page->statusCode) { case 424: $language = $this->isUser() ? $this->users->getLanguage($this->activeUserEmail) : $page->get("language"); @@ -70,6 +77,14 @@ class YellowWebinterface case 500: $page->rawData = $this->rawDataOriginal; break; } } + $serverBase = $this->yellow->config->get("serverBase"); + $location = trim($this->yellow->config->get("webinterfaceLocation"), '/'); + $callback = function($matches) use ($serverBase, $location) + { + $matches[2] = preg_replace("#^$serverBase/(?!$location)(.*)$#", "$serverBase/$location/$1", $matches[2]); + return "<a$matches[1]href=\"$matches[2]\"$matches[3]>"; + }; + $output = preg_replace_callback("/<a(.*?)href=\"([^\"]+)\"(.*?)>/i", $callback, $text); } return $output; } 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.6"; + const Version = "0.2.7"; var $page; //current page data var $pages; //current page tree from file system var $config; //configuration @@ -224,8 +224,7 @@ class Yellow $fileName = $this->toolbox->findFileFromLocation($location, $this->config->get("contentDir"), $this->config->get("contentHomeDir"), $this->config->get("contentDefaultFile"), $this->config->get("contentExtension")); - if(!$this->toolbox->isFileLocation($location) && !is_file($fileName) && - preg_match("/[^\/]+:.*/", rawurldecode($this->toolbox->getLocation()))) + if(!is_file($fileName) && $this->toolbox->isLocationArgs($this->toolbox->getLocation())) { $location = rtrim($location, '/'); $fileName = $this->toolbox->findFileFromLocation($location, @@ -446,10 +445,7 @@ class YellowPage if(method_exists($plugin["obj"], "onParse")) { $this->parser = $plugin["obj"]; - $this->parser->onParse($this->getContent(true)); - $location = $this->yellow->toolbox->getDirectoryLocation($this->getLocation()); - $this->parser->textHtml = preg_replace("#<a(.*?)href=\"(?!javascript:)([^\/\"]+)\"(.*?)>#", - "<a$1href=\"$location$2\"$3>", $this->parser->textHtml); + $this->parser->onParse($this, $this->getContent(true)); foreach($this->yellow->plugins->plugins as $key=>$value) { if(method_exists($value["obj"], "onParseContent")) @@ -466,7 +462,7 @@ class YellowPage { $this->set("keywords", $this->yellow->toolbox->createTextKeywords($this->get("title"), 10)); } - } + } } if(defined("DEBUG") && DEBUG>=2) echo "YellowPage::parseContent location:".$this->location."<br/>\n"; } @@ -1207,13 +1203,13 @@ class YellowToolbox function getLocation() { $uri = $_SERVER["REQUEST_URI"]; - return ($pos = strposu($uri, '?')) ? substru($uri, 0, $pos) : $uri; + return rawurldecode(($pos = strposu($uri, '?')) ? substru($uri, 0, $pos) : $uri); } - // Return location from current HTTP request, remove unwanted path tokens and location arguments + // Return location from current HTTP request, remove unwanted path tokens function getLocationNormalised() { - $string = rawurldecode($this->getLocation()); + $string = $this->getLocation(); $location = ($string[0]=='/') ? '' : '/'; for($pos=0; $pos<strlenb($string); ++$pos) { @@ -1246,6 +1242,7 @@ class YellowToolbox } } } + if(!preg_match("/^HTTP\//", $_SERVER["SERVER_PROTOCOL"])) $_SERVER["SERVER_PROTOCOL"] = "HTTP/1.1"; return $location; } @@ -1253,7 +1250,7 @@ class YellowToolbox function getLocationArgs($location, $arg = "") { preg_match("/^(.*?):(.*)$/", $arg, $args); - if(preg_match("/^(.*?\/)([^\/]+:.*)$/", rawurldecode($this->getLocation()), $matches)) + if(preg_match("/^(.*?\/)([^\/]+:.*)$/", $this->getLocation(), $matches)) { foreach(explode('/', $matches[2]) as $token) { @@ -1299,6 +1296,12 @@ class YellowToolbox } return $locationArgs; } + + // Check if location contains location arguments + function isLocationArgs($location) + { + return preg_match("/[^\/]+:.*$/", $location); + } // Check if file is unmodified since last HTTP request function isFileNotModified($lastModified) diff --git a/system/snippets/footer.php b/system/snippets/footer.php @@ -1,5 +1,5 @@ <div class="footer"> -&copy; 2014 <?php echo $yellow->page->getHtml("sitename") ?>. Built with <a href="https://github.com/markseu/yellowcms">Yellow</a> +&copy; 2014 <?php echo $yellow->page->getHtml("sitename") ?>. <a href="https://github.com/markseu/yellowcms">Built with Yellow</a> </div> </div> </body> diff --git a/system/snippets/header.php b/system/snippets/header.php @@ -12,5 +12,5 @@ </head> <body> <div class="page"> -<div class="header"><h1><a href="<?php echo $yellow->config->get("serverBase")."/" ?>"><?php echo $yellow->page->getHtml("sitename") ?></a></h1></div> +<div class="header"><h1><a href="<?php echo $yellow->pages->serverBase."/" ?>"><?php echo $yellow->page->getHtml("sitename") ?></a></h1></div> <div class="header-banner"></div>