mikuli.cz

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

commit 352d232b8f79e9c21c74d3aa20410a7bdbce4631
parent 836c75f31ec2113cce51e0da9a9fa6c9413842c3
Author: markseu <mark2011@mayberg.se>
Date:   Sat, 31 May 2014 23:48:59 +0200

Core update (configuration summer remix)

Diffstat:
Asystem/config/default.txt | 5+++++
Msystem/config/text.ini | 2--
Msystem/core/core-webinterface.php | 30++++++++++++++++++++++--------
Msystem/core/core.php | 21++++++++++++---------
4 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/system/config/default.txt b/system/config/default.txt @@ -0,0 +1,4 @@ +--- +Title: New page +--- +Write text here +\ No newline at end of file diff --git a/system/config/text.ini b/system/config/text.ini @@ -13,7 +13,5 @@ webinterfaceSaveButton = Save webinterfaceCancelButton = Cancel webinterfaceEdit = Edit webinterfaceUserLogout = Logout -webinterface424Title = New page -webinterface424Text = Write text here paginationPrevious = ← Previous paginationNext = Next → 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.10"; + const Version = "0.2.11"; var $yellow; //access to API var $users; //web interface users var $active; //web interface is active? (boolean) @@ -16,6 +16,7 @@ class YellowWebinterface function onLoad($yellow) { $this->yellow = $yellow; + $this->yellow->config->setDefault("webinterfacePage", "default"); $this->yellow->config->setDefault("webinterfaceLocation", "/edit/"); $this->yellow->config->setDefault("webinterfaceUserFile", "user.ini"); $this->yellow->config->setDefault("webinterfaceUserHome", "/"); @@ -74,13 +75,7 @@ class YellowWebinterface { switch($page->statusCode) { - case 424: $language = $this->isUser() ? $this->users->getLanguage() : $page->get("language"); - $page->rawData = "---\r\n"; - $page->rawData .= "Title: ".$this->yellow->text->getText("webinterface424Title", $language)."\r\n"; - $page->rawData .= "Author: ".$this->users->getName()."\r\n"; - $page->rawData .= "---\r\n"; - $page->rawData .= $this->yellow->text->getText("webinterface424Text", $language); - break; + case 424: $page->rawData = $this->getPageData(); break; case 500: $page->rawData = $this->rawDataOriginal; break; } } @@ -296,6 +291,25 @@ class YellowWebinterface return $this->yellow->getRequestInformation($serverScheme, $serverName, $base); } + // Return content data for new page + function getPageData() + { + $fileData = ""; + $fileName = $this->yellow->toolbox->findFileFromLocation($this->yellow->page->location, + $this->yellow->config->get("contentDir"), $this->yellow->config->get("contentHomeDir"), + $this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension")); + $fileName = $this->yellow->toolbox->findNameFromFile($fileName, + $this->yellow->config->get("configDir"), $this->yellow->config->get("webinterfacePage"), + $this->yellow->config->get("contentExtension"), true); + $fileHandle = @fopen($fileName, "r"); + if($fileHandle) + { + $fileData = fread($fileHandle, filesize($fileName)); + fclose($fileHandle); + } + return $fileData; + } + // Return configuration data including information of current user function getConfigData() { 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.21"; + const Version = "0.2.22"; var $page; //current page var $pages; //pages from file system var $config; //configuration @@ -384,9 +384,10 @@ class YellowPage $this->set("sitename", $this->yellow->config->get("sitename")); $this->set("author", $this->yellow->config->get("author")); $this->set("language", $this->yellow->config->get("language")); - $this->set("template", $this->yellow->toolbox->findTemplateFromFile($this->fileName, - $this->yellow->config->get("templateDir"), $this->yellow->config->get("template"))); - $this->set("style", $this->yellow->config->get("style")); + $this->set("template", $this->yellow->toolbox->findNameFromFile($this->fileName, + $this->yellow->config->get("templateDir"), $this->yellow->config->get("template"), ".php")); + $this->set("style", $this->yellow->toolbox->findNameFromFile($this->fileName, + $this->yellow->config->get("styleDir"), $this->yellow->config->get("style"), ".css")); $this->set("parser", $this->yellow->config->get("parser")); if(preg_match("/^(\-\-\-[\r\n]+)(.+?)([\r\n]+\-\-\-[\r\n]+)/s", $this->rawData, $parsed)) @@ -1521,14 +1522,16 @@ class YellowToolbox return $fileNames; } - // Return template from file path - function findTemplateFromFile($fileName, $templateDir, $templateDefault) + // Return file/template/style name from file path + function findNameFromFile($fileName, $pathBase, $nameDefault, $fileExtension, $includeFileName = false) { - if(preg_match("/^.*\/(.+?)$/", dirname($fileName), $matches)) $templateFolder = $this->normaliseName($matches[1]); - return is_file("$templateDir$templateFolder.php") ? $templateFolder : $templateDefault; + $name = ""; + if(preg_match("/^.*\/(.+?)$/", dirname($fileName), $matches)) $name = $this->normaliseName($matches[1]); + if(!is_file("$pathBase$name$fileExtension")) $name = $this->normaliseName($nameDefault); + return $includeFileName ? "$pathBase$name$fileExtension" : $name; } - // Normalise directory/file/attribute name + // Normalise file/directory/attribute name function normaliseName($text, $removeExtension = false, $filterStrict = false) { if(preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches)) $text = $matches[1];