commit d4ffdbef0ecd540b847b2e7f89285d9b3f54309c
parent db8385ed34f93ca19dd1f0fdcc914cfbedd5bba1
Author: markseu <mark2011@mayberg.se>
Date: Fri, 31 Jul 2020 08:53:39 +0200
Refactored code base
Diffstat:
4 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/system/extensions/command.php b/system/extensions/command.php
@@ -2,7 +2,7 @@
// Command extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/command
class YellowCommand {
- const VERSION = "0.8.18";
+ const VERSION = "0.8.19";
const PRIORITY = "3";
public $yellow; // access to API
public $files; // number of files
@@ -16,6 +16,11 @@ class YellowCommand {
$this->yellow = $yellow;
}
+ // Handle request
+ public function onRequest($scheme, $address, $base, $location, $fileName) {
+ return $this->processRequestCache($scheme, $address, $base, $location, $fileName);
+ }
+
// Handle command
public function onCommand($command, $text) {
switch ($command) {
@@ -73,7 +78,7 @@ class YellowCommand {
// Build static files
public function buildStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticBuildDirectory") : $path, "/");
$this->files = $this->errors = 0;
$this->locationsArguments = $this->locationsArgumentsPagination = array();
$statusCode = empty($locationFilter) ? $this->cleanStaticFiles($path, $locationFilter) : 200;
@@ -255,7 +260,7 @@ class YellowCommand {
// Check static files for broken links
public function checkStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticBuildDirectory") : $path, "/");
$this->links = $this->errors = 0;
$regex = "/^[^.]+$|".$this->yellow->system->get("coreStaticDefaultFile")."$/";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, $regex, false, false);
@@ -394,7 +399,7 @@ class YellowCommand {
// Clean static files and directories
public function cleanStaticFiles($path, $location) {
$statusCode = 200;
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticBuildDirectory") : $path, "/");
if (empty($location)) {
$statusCode = max($statusCode, $this->broadcastCommand("clean", "all"));
$statusCode = max($statusCode, $this->cleanStaticDirectory($path));
@@ -447,7 +452,9 @@ class YellowCommand {
// Process command to start built-in web server
public function processCommandServe($command, $text) {
list($path, $url) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($path) && is_dir($this->yellow->system->get("coreStaticDirectory"))) $path = $this->yellow->system->get("coreStaticDirectory");
+ if (empty($path) && is_dir($this->yellow->system->get("coreStaticBuildDirectory"))) {
+ $path = $this->yellow->system->get("coreStaticBuildDirectory");
+ }
if (empty($url)) $url = "http://localhost:8000";
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($url);
if ($scheme=="http" && !empty($address)) {
@@ -468,6 +475,18 @@ class YellowCommand {
return $statusCode;
}
+ // Process request for cached files
+ public function processRequestCache($scheme, $address, $base, $location, $fileName) {
+ $statusCode = 0;
+ $location .= $this->yellow->toolbox->getLocationArguments();
+ $fileName = rtrim($this->yellow->system->get("coreStaticCacheDirectory"), "/").$location;
+ if (!$this->yellow->lookup->isFileLocation($location)) $fileName .= $this->yellow->system->get("coreStaticDefaultFile");
+ if (is_file($fileName) && is_readable($fileName) && !$this->yellow->isCommandLine()) {
+ $statusCode = $this->yellow->sendFile(200, $fileName, true);
+ }
+ return $statusCode;
+ }
+
// Check static settings
public function checkStaticSettings() {
return !empty($this->yellow->system->get("coreStaticUrl"));
@@ -477,7 +496,7 @@ class YellowCommand {
public function checkStaticDirectory($path) {
$ok = false;
if (!empty($path)) {
- if ($path==rtrim($this->yellow->system->get("coreStaticDirectory"), "/")) $ok = true;
+ if ($path==rtrim($this->yellow->system->get("coreStaticBuildDirectory"), "/")) $ok = true;
if ($path==rtrim($this->yellow->system->get("coreTrashDirectory"), "/")) $ok = true;
if (is_file("$path/".$this->yellow->system->get("coreStaticDefaultFile"))) $ok = true;
if (is_file("$path/yellow.php")) $ok = false;
@@ -589,8 +608,8 @@ class YellowCommand {
public function getExtraLocations($path) {
$locations = array();
$pathIgnore = "($path/|".
- $this->yellow->system->get("coreStaticDirectory")."|".
- $this->yellow->system->get("coreCacheDirectory")."|".
+ $this->yellow->system->get("coreStaticBuildDirectory")."|".
+ $this->yellow->system->get("coreStaticCacheDirectory")."|".
$this->yellow->system->get("coreContentDirectory")."|".
$this->yellow->system->get("coreMediaDirectory")."|".
$this->yellow->system->get("coreSystemDirectory").")";
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -39,8 +39,8 @@ class YellowCore {
$this->system->setDefault("coreStaticUrl", "");
$this->system->setDefault("coreStaticDefaultFile", "index.html");
$this->system->setDefault("coreStaticErrorFile", "404.html");
- $this->system->setDefault("coreStaticDirectory", "public/");
- $this->system->setDefault("coreCacheDirectory", "cache/");
+ $this->system->setDefault("coreStaticBuildDirectory", "public/");
+ $this->system->setDefault("coreStaticCacheDirectory", "cache/");
$this->system->setDefault("coreTrashDirectory", "system/trash/");
$this->system->setDefault("coreServerUrl", "auto");
$this->system->setDefault("coreServerTimezone", "UTC");
@@ -151,7 +151,6 @@ class YellowCore {
}
}
if ($statusCode==0) {
- $fileName = $this->lookup->findFileFromCache($location, $fileName, $cacheable && !$this->isCommandLine());
if ($this->lookup->isContentFile($fileName) || !is_readable($fileName)) {
$fileName = $this->readPage($scheme, $address, $base, $location, $fileName, $cacheable,
max(is_readable($fileName) ? 200 : 404, $this->page->statusCode), $this->page->get("pageError"));
@@ -2338,17 +2337,6 @@ class YellowLookup {
return $fileName;
}
- // Return file path from cache if possible
- public function findFileFromCache($location, $fileName, $cacheable) {
- if ($cacheable) {
- $location .= $this->yellow->toolbox->getLocationArguments();
- $fileNameStatic = rtrim($this->yellow->system->get("coreCacheDirectory"), "/").$location;
- if (!$this->isFileLocation($location)) $fileNameStatic .= $this->yellow->system->get("coreStaticDefaultFile");
- if (is_readable($fileNameStatic)) $fileName = $fileNameStatic;
- }
- return $fileName;
- }
-
// Normalise file/directory token
public function normaliseToken($text, $fileExtension = "", $removeExtension = false) {
if (!empty($fileExtension)) $text = ($pos = strrposu($text, ".")) ? substru($text, 0, $pos) : $text;
diff --git a/system/extensions/edit.php b/system/extensions/edit.php
@@ -2,7 +2,7 @@
// Edit extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/edit
class YellowEdit {
- const VERSION = "0.8.31";
+ const VERSION = "0.8.32";
public $yellow; // access to API
public $response; // web response
public $merge; // text merge
@@ -1192,7 +1192,7 @@ class YellowEditResponse {
$data["coreVersion"] = "Datenstrom Yellow ".YellowCore::VERSION;
$data["coreExtensions"] = array();
foreach ($this->yellow->extension->data as $key=>$value) {
- $data["coreExtensions"][$key] = $value["type"];
+ $data["coreExtensions"][$key] = $value["class"];
}
$data["coreLanguages"] = array();
foreach ($this->yellow->system->getValues("language") as $language) {
diff --git a/system/settings/system.ini b/system/settings/system.ini
@@ -11,8 +11,8 @@ Status: public
CoreStaticUrl:
CoreStaticDefaultFile: index.html
CoreStaticErrorFile: 404.html
-CoreStaticDirectory: public/
-CoreCacheDirectory: cache/
+CoreStaticBuildDirectory: public/
+CoreStaticCacheDirectory: cache/
CoreTrashDirectory: system/trash/
CoreServerUrl: auto
CoreServerTimezone: UTC