mikuli.cz

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

commit 830928e8f75b120d56950105f2c378783a81244d
parent 768d8988ace634f401360a0c42810a3f81b61c80
Author: markseu <mark2011@mayberg.se>
Date:   Mon, 13 Aug 2018 15:39:50 +0200

Refactored some plugins

Diffstat:
Msystem/plugins/command.php | 56++++++++++++++++++++++++++++++++++----------------------
Msystem/plugins/update-blog.installation | 0
Msystem/plugins/update-wiki.installation | 0
3 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/system/plugins/command.php b/system/plugins/command.php @@ -124,31 +124,11 @@ class YellowCommand { $statusCode = $this->requestStaticFile($scheme, $address, $base, $location); if ($statusCode<400 || $error) { $fileData = ob_get_contents(); - $modified = strtotime($this->yellow->page->getHeader("Last-Modified")); - if ($modified==0) $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); - if ($statusCode>=301 && $statusCode<=303) { - $fileData = $this->getStaticRedirect($this->yellow->page->getHeader("Location")); - $modified = time(); - } - $fileName = $this->getStaticFile($path, $location, $statusCode); - if (!$this->yellow->toolbox->createFile($fileName, $fileData, true) || - !$this->yellow->toolbox->modifyFile($fileName, $modified)) { - $statusCode = 500; - $this->yellow->page->statusCode = $statusCode; - $this->yellow->page->set("pageError", "Can't write file '$fileName'!"); - } + $statusCode = $this->saveStaticFile($path, $location, $fileData, $statusCode); } ob_end_clean(); } else { - $statusCode = 200; - $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); - $fileName = $this->getStaticFile($path, $location, $statusCode); - if (!$this->yellow->toolbox->copyFile($this->yellow->page->fileName, $fileName, true) || - !$this->yellow->toolbox->modifyFile($fileName, $modified)) { - $statusCode = 500; - $this->yellow->page->statusCode = $statusCode; - $this->yellow->page->set("pageError", "Can't write file '$fileName'!"); - } + $statusCode = $this->copyStaticFile($path, $location); } if ($statusCode==200 && $analyse) $this->analyseStaticFile($scheme, $address, $base, $fileData); if ($statusCode==404 && $probe) $statusCode = 100; @@ -178,6 +158,38 @@ class YellowCommand { return $this->yellow->request(); } + // Save static file + public function saveStaticFile($path, $location, $fileData, $statusCode) { + $modified = strtotime($this->yellow->page->getHeader("Last-Modified")); + if ($modified==0) $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); + if ($statusCode>=301 && $statusCode<=303) { + $fileData = $this->getStaticRedirect($this->yellow->page->getHeader("Location")); + $modified = time(); + } + $fileName = $this->getStaticFile($path, $location, $statusCode); + if (!$this->yellow->toolbox->createFile($fileName, $fileData, true) || + !$this->yellow->toolbox->modifyFile($fileName, $modified)) { + $statusCode = 500; + $this->yellow->page->statusCode = $statusCode; + $this->yellow->page->set("pageError", "Can't write file '$fileName'!"); + } + return $statusCode; + } + + // Copy static file + public function copyStaticFile($path, $location) { + $statusCode = 200; + $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); + $fileName = $this->getStaticFile($path, $location, $statusCode); + if (!$this->yellow->toolbox->copyFile($this->yellow->page->fileName, $fileName, true) || + !$this->yellow->toolbox->modifyFile($fileName, $modified)) { + $statusCode = 500; + $this->yellow->page->statusCode = $statusCode; + $this->yellow->page->set("pageError", "Can't write file '$fileName'!"); + } + return $statusCode; + } + // Analyse static file, detect locations with arguments public function analyseStaticFile($scheme, $address, $base, $rawData) { $pagination = $this->yellow->config->get("contentPagination"); diff --git a/system/plugins/update-blog.installation b/system/plugins/update-blog.installation Binary files differ. diff --git a/system/plugins/update-wiki.installation b/system/plugins/update-wiki.installation Binary files differ.