Updated core

This commit is contained in:
markseu 2024-04-09 19:09:52 +02:00
parent 3d8f06aecd
commit 1aea895ea7
5 changed files with 121 additions and 76 deletions

View file

@ -1,6 +1,6 @@
<?php
// Core extension, https://github.com/annaesvensson/yellow-core
// This file is only needed for backwards compatibility with Datenstrom Yellow 0.8.23
// This file is only needed for backwards compatibility with Datenstrom Yellow 0.8
// Please note that the latest core can be found in file `system/workers/core.php`
class YellowCore {

View file

@ -74,14 +74,14 @@ Status: available
system/workers/breadcrumb.php: breadcrumb.php, create, update
Extension: Bundle
Version: 0.9.1
Version: 0.9.2
Description: Bundle website files.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-bundle/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-bundle
DocumentationLanguage: en, de, sv
Published: 2024-04-04 16:35:34
Published: 2024-04-09 17:07:13
Status: available
system/workers/bundle.php: bundle.php, create, update
@ -148,14 +148,14 @@ system/themes/copenhagen.css: copenhagen.css, create, update, careful
system/themes/copenhagen.png: copenhagen.png, create
Extension: Core
Version: 0.9.1
Version: 0.9.2
Description: Core functionality of your website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:38:12
Published: 2024-04-09 17:09:52
Status: available
system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update
@ -304,14 +304,14 @@ system/workers/gallery-default-skin.svg: gallery-default-skin.svg, create, updat
system/workers/gallery-preloader.gif: gallery-preloader.gif, create, update
Extension: Generate
Version: 0.9.1
Version: 0.9.2
Description: Generate a static website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-generate/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-generate
DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:55:02
Published: 2024-04-09 18:56:19
Status: available
system/workers/generate.php: generate.php, create, update
@ -513,14 +513,14 @@ Status: available
system/workers/markdown.php: markdown.php, create, update
Extension: Meta
Version: 0.9.1
Version: 0.9.2
Description: Meta data for humans and machines.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-meta/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-meta
DocumentationLanguage: en, de, sv
Published: 2024-04-04 20:54:52
Published: 2024-04-09 15:39:39
Status: available
system/workers/meta.php: meta.php, create, update

View file

@ -1,14 +1,14 @@
# Datenstrom Yellow extension settings
Extension: Core
Version: 0.9.1
Version: 0.9.2
Description: Core functionality of your website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:38:12
Published: 2024-04-09 17:09:52
Status: available
system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update
@ -36,14 +36,14 @@ system/workers/edit-stack.svg: edit-stack.svg, create, update
content/shared/page-new-default.md: page-new-default.md, create, optional
Extension: Generate
Version: 0.9.1
Version: 0.9.2
Description: Generate a static website.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-generate/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-generate
DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:55:02
Published: 2024-04-09 18:56:19
Status: available
system/workers/generate.php: generate.php, create, update

View file

@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore {
const VERSION = "0.9.1";
const VERSION = "0.9.2";
const RELEASE = "0.9";
public $content; // content files
public $media; // media files
@ -42,11 +42,11 @@ class YellowCore {
$this->system->setDefault("coreUserFile", "yellow-user.ini");
$this->system->setDefault("coreExtensionFile", "yellow-extension.ini");
$this->system->setDefault("coreWebsiteFile", "yellow-website.log");
$this->system->setDefault("coreAssetLocation", "/assets/");
$this->system->setDefault("coreMediaLocation", "/media/");
$this->system->setDefault("coreDownloadLocation", "/media/downloads/");
$this->system->setDefault("coreImageLocation", "/media/images/");
$this->system->setDefault("coreThumbnailLocation", "/media/thumbnails/");
$this->system->setDefault("coreExtensionLocation", "/media/extensions/");
$this->system->setDefault("coreMultiLanguageMode", "0");
$this->system->setDefault("coreDebugMode", "0");
}
@ -82,7 +82,8 @@ class YellowCore {
$this->system->set("coreServerInstallDirectory", $pathInstall);
$this->system->set("coreServerRootDirectory", $pathRoot);
$this->system->set("coreServerHomeDirectory", $pathHome);
$this->system->set("coreThemeLocation", "/media/extensions/"); // TODO: remove later, for backwards compatibility
$this->system->set("coreExtensionLocation", "/assets/"); // TODO: remove later, for backwards compatibility
$this->system->set("coreThemeLocation", "/assets/"); // TODO: remove later, for backwards compatibility
register_shutdown_function(array($this, "processFatalError"));
if ($this->system->get("coreDebugMode")>=1) {
ini_set("display_errors", 1);
@ -1289,18 +1290,8 @@ class YellowLookup {
// Return media location from file path
public function findMediaLocationFromFile($fileName) {
$location = "";
$themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory"));
$workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory"));
$mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory"));
if (substru($fileName, 0, $themeDirectoryLength)==$this->yellow->system->get("coreThemeDirectory")) {
if ($this->isSafeFile($fileName)) {
$location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $themeDirectoryLength);
}
} elseif (substru($fileName, 0, $workerDirectoryLength)==$this->yellow->system->get("coreWorkerDirectory")) {
if ($this->isSafeFile($fileName)) {
$location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $workerDirectoryLength);
}
} elseif (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) {
if (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) {
$location = "/".$fileName;
}
return $location;
@ -1309,15 +1300,8 @@ class YellowLookup {
// Return file path from media location
public function findFileFromMediaLocation($location) {
$fileName = "";
$extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation"));
$mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation"));
if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) {
if ($this->isSafeFile($location)) {
$fileNameOne = $this->yellow->system->get("coreThemeDirectory").substru($location, $extensionLocationLength);
$fileNameTwo = $this->yellow->system->get("coreWorkerDirectory").substru($location, $extensionLocationLength);
$fileName = is_file($fileNameOne) ? $fileNameOne : $fileNameTwo;
}
} elseif (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
if (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
$fileName = substru($location, 1);
}
return $fileName;
@ -1343,6 +1327,49 @@ class YellowLookup {
return substru($key, -8, 8)=="Location" ? $this->findFileFromMediaLocation($this->yellow->system->get($key)) : "";
}
// Return media location from file path
public function findSystemLocationFromFile($fileName) {
$location = "";
$layoutDirectoryLength = strlenu($this->yellow->system->get("coreLayoutDirectory"));
$themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory"));
$workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory"));
if (substru($fileName, 0, $layoutDirectoryLength)==$this->yellow->system->get("coreLayoutDirectory")) {
if ($this->isSafeFile($fileName)) {
$location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $layoutDirectoryLength);
}
} elseif (substru($fileName, 0, $themeDirectoryLength)==$this->yellow->system->get("coreThemeDirectory")) {
if ($this->isSafeFile($fileName)) {
$location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $themeDirectoryLength);
}
} elseif (substru($fileName, 0, $workerDirectoryLength)==$this->yellow->system->get("coreWorkerDirectory")) {
if ($this->isSafeFile($fileName)) {
$location = $this->yellow->system->get("coreAssetLocation").substru($fileName, $workerDirectoryLength);
}
}
return $location;
}
// Return file path from media location
public function findFileFromSystemLocation($location) {
$fileName = "";
$assetLocationLength = strlenu($this->yellow->system->get("coreAssetLocation"));
if (substru($location, 0, $assetLocationLength)==$this->yellow->system->get("coreAssetLocation")) {
if ($this->isSafeFile($location)) {
$fileNameLayout = $this->yellow->system->get("coreLayoutDirectory").substru($location, $assetLocationLength);
$fileNameTheme = $this->yellow->system->get("coreThemeDirectory").substru($location, $assetLocationLength);
$fileNameWorker = $this->yellow->system->get("coreWorkerDirectory").substru($location, $assetLocationLength);
if (is_file($fileNameLayout)) {
$fileName = $fileNameLayout;
} elseif (is_file($fileNameTheme)) {
$fileName = $fileNameTheme;
} elseif (is_file($fileNameWorker)) {
$fileName = $fileNameWorker;
}
}
}
return $fileName;
}
// Return file or directory that matches token
public function findFileDirectory($path, $token, $fileExtension, $directory, $default, &$found, &$invalid) {
if ($this->normaliseToken($token, $fileExtension)!=$token) $invalid = true;
@ -1613,6 +1640,7 @@ class YellowLookup {
}
$location = substru($this->yellow->toolbox->detectServerLocation(), strlenu($base));
$fileName = "";
if (is_string_empty($fileName)) $fileName = $this->findFileFromSystemLocation($location);
if (is_string_empty($fileName)) $fileName = $this->findFileFromMediaLocation($location);
if (is_string_empty($fileName)) $fileName = $this->findFileFromContentLocation($location);
return array($scheme, $address, $base, $location, $fileName);
@ -3305,20 +3333,20 @@ class YellowPage {
}
}
if ($name=="header") {
$extensionLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreExtensionLocation");
$assetLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreAssetLocation");
$fileNameTheme = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
if (is_file($fileNameTheme)) {
$fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".css";
$fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".css";
$output .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"$fileLocation\" />\n";
}
$fileNameScript = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".js";
if (is_file($fileNameScript)) {
$fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".js";
$fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".js";
$output .= "<script type=\"text/javascript\" src=\"$fileLocation\"></script>\n";
}
$fileNameFavicon = $this->yellow->system->get("coreThemeDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".png";
if (is_file($fileNameFavicon)) {
$fileLocation = $extensionLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".png";
$fileLocation = $assetLocation.$this->yellow->lookup->normaliseName($this->get("theme")).".png";
$output .= "<link rel=\"icon\" type=\"image/png\" href=\"$fileLocation\" />\n";
}
}

View file

@ -2,7 +2,7 @@
// Generate extension, https://github.com/annaesvensson/yellow-generate
class YellowGenerate {
const VERSION = "0.9.1";
const VERSION = "0.9.2";
public $yellow; // access to API
public $files; // number of files
public $errors; // number of errors
@ -74,6 +74,7 @@ class YellowGenerate {
}
$statusCode = max($statusCode, $this->generateStaticContent($path, $location, "\rGenerating static website", 5, 95));
$statusCode = max($statusCode, $this->generateStaticMedia($path, $location));
$statusCode = max($statusCode, $this->generateStaticSystem($path, $location));
echo "\rGenerating static website 100%... done\n";
return $statusCode;
}
@ -120,14 +121,22 @@ class YellowGenerate {
foreach ($this->getMediaLocations() as $location) {
$statusCode = max($statusCode, $this->generateStaticFile($path, $location));
}
foreach ($this->getExtraLocations($path) as $location) {
}
return $statusCode;
}
// Generate static system
public function generateStaticSystem($path, $locationFilter) {
$statusCode = 200;
if (is_string_empty($locationFilter)) {
foreach ($this->getSystemLocations($path) as $location) {
$statusCode = max($statusCode, $this->generateStaticFile($path, $location));
}
$statusCode = max($statusCode, $this->generateStaticFile($path, "/error/", false, false, true));
}
return $statusCode;
}
// Generate static file
public function generateStaticFile($path, $location, $analyse = false, $probe = false, $error = false) {
$this->yellow->content->pages = array();
@ -381,58 +390,66 @@ class YellowGenerate {
// Return media locations
public function getMediaLocations() {
$locations = array();
$mediaPath = $this->yellow->system->get("coreMediaDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($mediaPath, "/.*/", false, false);
$path = $this->yellow->system->get("coreMediaDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false);
foreach ($fileNames as $fileName) {
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
$location = $this->yellow->lookup->findMediaLocationFromFile($fileName);
if (!is_string_empty($location)) array_push($locations, $location);
}
$themePath = $this->yellow->system->get("coreThemeDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($themePath, "/.*/", false, false);
return $locations;
}
// Return system locations
public function getSystemLocations($pathIgnore) {
$locations = array();
$path = $this->yellow->system->get("coreWorkerDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false);
foreach ($fileNames as $fileName) {
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
$location = $this->yellow->lookup->findSystemLocationFromFile($fileName);
if (!is_string_empty($location)) array_push($locations, $location);
}
$workerPath = $this->yellow->system->get("coreWorkerDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($workerPath, "/.*/", false, false);
$path = $this->yellow->system->get("coreThemeDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false);
foreach ($fileNames as $fileName) {
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
$location = $this->yellow->lookup->findSystemLocationFromFile($fileName);
if (!is_string_empty($location)) array_push($locations, $location);
}
return array_diff($locations, $this->getMediaLocationsIgnore());
$path = $this->yellow->system->get("coreLayoutDirectory");
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false);
foreach ($fileNames as $fileName) {
$location = $this->yellow->lookup->findSystemLocationFromFile($fileName);
if (!is_string_empty($location)) array_push($locations, $location);
}
$regexIgnore = "#^(/".
$this->yellow->system->get("coreContentDirectory")."|/".
$this->yellow->system->get("coreMediaDirectory")."|/".
$this->yellow->system->get("coreSystemDirectory")."|/".
$this->yellow->system->get("generateStaticDirectory")."|/$pathIgnore/|/yellow.php)#";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive(".", "/.*/", false, false);
foreach ($fileNames as $fileName) {
$location = substru($fileName, 1);
if (!preg_match($regexIgnore, $location)) array_push($locations, $location);
}
return array_diff($locations, $this->getSystemLocationsIgnore());
}
// Return media locations to ignore
public function getMediaLocationsIgnore() {
$locations = array("");
$workerPath = $this->yellow->system->get("coreWorkerDirectory");
// Return system locations to ignore
public function getSystemLocationsIgnore() {
$locations = array();
$path = $this->yellow->system->get("coreWorkerDirectory");
$workerDirectoryLength = strlenu($this->yellow->system->get("coreWorkerDirectory"));
if ($this->yellow->extension->isExisting("bundle")) {
foreach ($this->yellow->toolbox->getDirectoryEntries($workerPath, "/^bundle-(.*)/", false, false) as $entry) {
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^bundle-(.*)/", false, false) as $entry) {
list($locationsBundle) = $this->yellow->extension->get("bundle")->getBundleInformation($entry);
$locations = array_merge($locations, $locationsBundle);
}
}
if ($this->yellow->extension->isExisting("edit")) {
foreach ($this->yellow->toolbox->getDirectoryEntries($workerPath, "/^edit\.(.*)/", false, false) as $entry) {
$location = $this->yellow->system->get("coreExtensionLocation").substru($entry, $workerDirectoryLength);
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^edit(\-|\.)(.*)/", false, false) as $entry) {
$location = $this->yellow->system->get("coreAssetLocation").substru($entry, $workerDirectoryLength);
array_push($locations, $location);
}
}
return array_unique($locations);
}
// Return extra locations
public function getExtraLocations($path) {
$locations = array();
$pathIgnore = "($path/|".
$this->yellow->system->get("generateStaticDirectory")."|".
$this->yellow->system->get("coreContentDirectory")."|".
$this->yellow->system->get("coreMediaDirectory")."|".
$this->yellow->system->get("coreSystemDirectory").")";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive(".", "/.*/", false, false);
foreach ($fileNames as $fileName) {
$fileName = substru($fileName, 2);
if (preg_match("#^$pathIgnore#", $fileName) || $fileName=="yellow.php") continue;
array_push($locations, "/".$fileName);
}
return $locations;
}
}