mikuli.cz

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

commit 3cf4a360d5c91ce0979a5233288dacaab952e8df
parent dd6cb86ccf385c9a935e77462f5da3aa017ab518
Author: markseu <mark2011@mayberg.se>
Date:   Mon, 28 Jan 2019 14:58:26 +0100

added support for multi language error pages

Diffstat:
Rsystem/config/page-new-default.md -> content/shared/page-new-default.md | 0
Msystem/config/config.ini | 1-
Dsystem/config/page-error-404.md | 5-----
Dsystem/config/page-error-430.md | 5-----
Dsystem/config/page-error-434.md | 5-----
Dsystem/config/page-error-500.md | 5-----
Msystem/plugins/core.php | 13++++++++-----
Msystem/plugins/edit.php | 54++++++++++++++++++++++++++++++++----------------------
Msystem/plugins/install-blog.zip | 0
Msystem/plugins/install-language.zip | 0
Msystem/plugins/install-wiki.zip | 0
Msystem/plugins/update.php | 26+++++++++++++++++++++++++-
Asystem/themes/templates/error.html | 8++++++++
13 files changed, 73 insertions(+), 49 deletions(-)

diff --git a/system/config/page-new-default.md b/content/shared/page-new-default.md diff --git a/system/config/config.ini b/system/config/config.ini @@ -39,7 +39,6 @@ ContentExtension: .md ConfigExtension: .ini DownloadExtension: .download TextFile: text.ini -ErrorFile: page-error-(.*).md NewFile: page-new-(.*).md LanguageFile: language-(.*).txt ServerUrl: diff --git a/system/config/page-error-404.md b/system/config/page-error-404.md @@ -1,4 +0,0 @@ ---- -Title: File not found ---- -The requested file was not found. Oh no... -\ No newline at end of file diff --git a/system/config/page-error-430.md b/system/config/page-error-430.md @@ -1,4 +0,0 @@ ---- -Title: Login failed ---- -The email or password is incorrect. [Please try again](javascript:yellow.action('login');). -\ No newline at end of file diff --git a/system/config/page-error-434.md b/system/config/page-error-434.md @@ -1,4 +0,0 @@ ---- -Title: File not found ---- -The requested file was not found. [You can create this page](javascript:yellow.action('edit');). -\ No newline at end of file diff --git a/system/config/page-error-500.md b/system/config/page-error-500.md @@ -1,4 +0,0 @@ ---- -Title: Server error ---- -Something went wrong. [yellow error] -\ No newline at end of file diff --git a/system/plugins/core.php b/system/plugins/core.php @@ -64,7 +64,6 @@ class YellowCore { $this->config->setDefault("downloadExtension", ".download"); $this->config->setDefault("configFile", "config.ini"); $this->config->setDefault("textFile", "text.ini"); - $this->config->setDefault("errorFile", "page-error-(.*).md"); $this->config->setDefault("newFile", "page-new-(.*).md"); $this->config->setDefault("languageFile", "language-(.*).txt"); $this->config->setDefault("serverUrl", ""); @@ -180,11 +179,15 @@ class YellowCore { // Read page public function readPage($scheme, $address, $base, $location, $fileName, $cacheable, $statusCode, $pageError) { if ($statusCode>=400) { + $language = $this->lookup->findLanguageFromFile($fileName, $this->config->get("language")); + if ($this->text->isExisting("error${statusCode}Title", $language)) { + $rawData = "---\nTitle:".$this->text->getText("error${statusCode}Title", $language)."\n"; + $rawData .= "Template:error\nLanguage:$language\n---\n".$this->text->getText("error${statusCode}Text", $language); + } else { + $rawData = "---\nTitle:".$this->toolbox->getHttpStatusFormatted($statusCode, true)."\n"; + $rawData .= "Template:error\nLanguage:en\n---\n"; + } $cacheable = false; - $fileName = $this->config->get("configDir").$this->config->get("errorFile"); - $fileName = strreplaceu("(.*)", $statusCode, $fileName); - $rawData = $this->toolbox->readFile($fileName); - if (empty($rawData)) $rawData = "---\nTitle:".$this->toolbox->getHttpStatusFormatted($statusCode, true)."\n---\n"; } else { $rawData = $this->toolbox->readFile($fileName); } diff --git a/system/plugins/edit.php b/system/plugins/edit.php @@ -1,10 +1,10 @@ <?php // Edit plugin, https://github.com/datenstrom/yellow-plugins/tree/master/edit -// Copyright (c) 2013-2018 Datenstrom, https://datenstrom.se +// Copyright (c) 2013-2019 Datenstrom, https://datenstrom.se // This file may be used and distributed under the terms of the public license. class YellowEdit { - const VERSION = "0.7.32"; + const VERSION = "0.7.33"; public $yellow; //access to API public $response; //web response public $users; //user accounts @@ -80,7 +80,7 @@ class YellowEdit { if (empty($this->response->rawDataSource)) $this->response->rawDataSource = $page->rawData; if (empty($this->response->rawDataEdit)) $this->response->rawDataEdit = $page->rawData; if (empty($this->response->rawDataEndOfLine)) $this->response->rawDataEndOfLine = $this->response->getEndOfLine($page->rawData); - if ($page->statusCode==434) $this->response->rawDataEdit = $this->response->getRawDataNew($page->location); + if ($page->statusCode==434) $this->response->rawDataEdit = $this->response->getRawDataNew($page, true); } if (empty($this->response->language)) $this->response->language = $page->get("language"); if (empty($this->response->action)) $this->response->action = $this->response->isUser() ? "none" : "login"; @@ -109,7 +109,7 @@ class YellowEdit { $output .= "<script type=\"text/javascript\" data-bundle=\"none\" src=\"{$pluginLocation}edit.js\"></script>\n"; $output .= "<script type=\"text/javascript\">\n"; $output .= "// <![CDATA[\n"; - $output .= "yellow.page = ".json_encode($this->response->getPageData()).";\n"; + $output .= "yellow.page = ".json_encode($this->response->getPageData($page)).";\n"; $output .= "yellow.config = ".json_encode($this->response->getConfigData()).";\n"; $output .= "yellow.text = ".json_encode($this->response->getTextData()).";\n"; $output .= "// ]]>\n"; @@ -260,6 +260,7 @@ class YellowEdit { case "remove": $statusCode = $this->processRequestRemove($scheme, $address, $base, $location, $fileName); break; } } + if ($statusCode==0) $statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false); $this->checkUserFailed($scheme, $address, $base, $location, $fileName); return $statusCode; } @@ -1048,13 +1049,13 @@ class YellowResponse { } // Return page data including status information - public function getPageData() { + public function getPageData($page) { $data = array(); if ($this->isUser()) { $data["title"] = $this->yellow->toolbox->getMetaData($this->rawDataEdit, "title"); $data["rawDataSource"] = $this->rawDataSource; $data["rawDataEdit"] = $this->rawDataEdit; - $data["rawDataNew"] = $this->getRawDataNew(); + $data["rawDataNew"] = $this->getRawDataNew($page); $data["rawDataOutput"] = strval($this->rawDataOutput); $data["rawDataEndOfLine"] = $this->rawDataEndOfLine; $data["scheme"] = $this->yellow->page->scheme; @@ -1155,27 +1156,36 @@ class YellowResponse { } // Return raw data for new page - public function getRawDataNew($location = "") { - foreach ($this->yellow->pages->path($this->yellow->page->location)->reverse() as $page) { - if ($page->isExisting("templateNew")) { - $name = $this->yellow->lookup->normaliseName($page->get("templateNew")); - $fileName = strreplaceu("(.*)", $name, $this->yellow->config->get("configDir").$this->yellow->config->get("newFile")); + public function getRawDataNew($page, $customTitle = false) { + foreach ($this->yellow->pages->path($page->location)->reverse() as $ancestor) { + if ($ancestor->isExisting("templateNew")) { + $name = $this->yellow->lookup->normaliseName($ancestor->get("templateNew")); + $location = $this->yellow->pages->getHomeLocation($page->location).$this->yellow->config->get("contentSharedDir"); + $fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->config->get("newFile"); + $fileName = strreplaceu("(.*)", $name, $fileName); if (is_file($fileName)) break; } } if (!is_file($fileName)) { $name = $this->yellow->lookup->normaliseName($this->yellow->config->get("template")); - $fileName = strreplaceu("(.*)", $name, $this->yellow->config->get("configDir").$this->yellow->config->get("newFile")); - } - $rawData = $this->yellow->toolbox->readFile($fileName); - $rawData = preg_replace("/@timestamp/i", time(), $rawData); - $rawData = preg_replace("/@datetime/i", date("Y-m-d H:i:s"), $rawData); - $rawData = preg_replace("/@date/i", date("Y-m-d"), $rawData); - $rawData = preg_replace("/@usershort/i", strtok($this->plugin->users->getName($this->userEmail), " "), $rawData); - $rawData = preg_replace("/@username/i", $this->plugin->users->getName($this->userEmail), $rawData); - $rawData = preg_replace("/@userlanguage/i", $this->plugin->users->getLanguage($this->userEmail), $rawData); - if (!empty($location)) { - $rawData = $this->yellow->toolbox->setMetaData($rawData, "title", $this->yellow->toolbox->createTextTitle($location)); + $location = $this->yellow->pages->getHomeLocation($page->location).$this->yellow->config->get("contentSharedDir"); + $fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->config->get("newFile"); + $fileName = strreplaceu("(.*)", $name, $fileName); + } + if (is_file($fileName)) { + $rawData = $this->yellow->toolbox->readFile($fileName); + $rawData = preg_replace("/@timestamp/i", time(), $rawData); + $rawData = preg_replace("/@datetime/i", date("Y-m-d H:i:s"), $rawData); + $rawData = preg_replace("/@date/i", date("Y-m-d"), $rawData); + $rawData = preg_replace("/@usershort/i", strtok($this->plugin->users->getName($this->userEmail), " "), $rawData); + $rawData = preg_replace("/@username/i", $this->plugin->users->getName($this->userEmail), $rawData); + $rawData = preg_replace("/@userlanguage/i", $this->plugin->users->getLanguage($this->userEmail), $rawData); + } else { + $rawData = "---\nTitle: Page\n---\n"; + } + if ($customTitle) { + $title = $this->yellow->toolbox->createTextTitle($page->location); + $rawData = $this->yellow->toolbox->setMetaData($rawData, "title", $title); } return $rawData; } diff --git a/system/plugins/install-blog.zip b/system/plugins/install-blog.zip Binary files differ. diff --git a/system/plugins/install-language.zip b/system/plugins/install-language.zip Binary files differ. diff --git a/system/plugins/install-wiki.zip b/system/plugins/install-wiki.zip Binary files differ. diff --git a/system/plugins/update.php b/system/plugins/update.php @@ -4,7 +4,7 @@ // This file may be used and distributed under the terms of the public license. class YellowUpdate { - const VERSION = "0.7.25"; + const VERSION = "0.7.26"; const PRIORITY = "2"; public $yellow; //access to API public $updates; //number of updates @@ -67,6 +67,30 @@ class YellowUpdate { $_GET["clean-url"] = "system-updated"; } } + if ($update) { //TODO: remove later, converts old error/new pages + $fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile"); + $fileNameError = $this->yellow->config->get("configDir")."system-error.log"; + $path = $this->yellow->config->get("configDir"); + if (count($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false))>3) { + $regex = "/^page-error-(.*)\.md$/"; + foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry) { + if (!$this->yellow->toolbox->deleteFile($entry, $this->yellow->config->get("trashDir"))) { + $fileDataError .= "ERROR deleting file '$entry'!\n"; + } + } + $regex = "/^page-new-(.*)\.md$/"; + $pathDestination = $this->yellow->config->get("contentDir").$this->yellow->config->get("contentSharedDir"); + foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry) { + if (!$this->yellow->toolbox->renameFile($entry, str_replace($path, $pathDestination, $entry), true)) { + $fileDataError .= "ERROR renaming file '$entry'!\n"; + } + } + $this->updateSoftwareMultiLanguage("shared-pages"); + if (!empty($fileDataError)) { + $this->yellow->toolbox->createFile($fileNameError, $fileDataError); + } + } + } if ($update) { $fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile"); $fileData = $this->yellow->toolbox->readFile($fileNameConfig); diff --git a/system/themes/templates/error.html b/system/themes/templates/error.html @@ -0,0 +1,8 @@ +<?php $yellow->snippet("header") ?> +<div class="content"> +<div class="main" role="main"> +<h1><?php echo $yellow->page->getHtml("titleContent") ?></h1> +<?php echo $yellow->page->getContent() ?> +</div> +</div> +<?php $yellow->snippet("footer") ?>