Updated core and refactored code

This commit is contained in:
markseu 2022-04-19 20:47:10 +02:00
parent 74dfcfe7a0
commit d0c6106b84
4 changed files with 50 additions and 49 deletions

View file

@ -2,7 +2,7 @@
// Command extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/command
class YellowCommand {
const VERSION = "0.8.38";
const VERSION = "0.8.39";
public $yellow; // access to API
public $files; // number of files
public $links; // number of links
@ -555,33 +555,26 @@ class YellowCommand {
public function getMediaLocations() {
$locations = array();
$mediaPath = $this->yellow->system->get("coreMediaDirectory");
$mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory"));
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($mediaPath, "/.*/", false, false);
foreach ($fileNames as $fileName) {
$location = $this->yellow->system->get("coreMediaLocation").substru($fileName, $mediaDirectoryLength);
array_push($locations, $location);
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
}
$extensionPath = $this->yellow->system->get("coreExtensionDirectory");
$extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory"));
$regex = "/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($extensionPath, $regex, false, false);
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($extensionPath, "/.*/", false, false);
foreach ($fileNames as $fileName) {
$location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $extensionDirectoryLength);
array_push($locations, $location);
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
}
$themePath = $this->yellow->system->get("coreThemeDirectory");
$themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory"));
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($themePath, $regex, false, false);
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($themePath, "/.*/", false, false);
foreach ($fileNames as $fileName) {
$location = $this->yellow->system->get("coreThemeLocation").substru($fileName, $themeDirectoryLength);
array_push($locations, $location);
array_push($locations, $this->yellow->lookup->findMediaLocationFromFile($fileName));
}
return array_diff($locations, $this->getMediaLocationsIgnore());
}
// Return media locations to ignore
public function getMediaLocationsIgnore() {
$locations = array();
$locations = array("");
$extensionPath = $this->yellow->system->get("coreExtensionDirectory");
$extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory"));
if ($this->yellow->extension->isExisting("bundle")) {

View file

@ -2,7 +2,7 @@
// Core extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/core
class YellowCore {
const VERSION = "0.8.69";
const VERSION = "0.8.70";
const RELEASE = "0.8.19";
public $page; // current page
public $content; // content files
@ -76,7 +76,7 @@ class YellowCore {
$this->system->load("system/extensions/yellow-system.ini");
$this->system->set("coreSystemFile", "yellow-system.ini");
$this->system->set("coreContentDirectory", "content/");
$this->system->set("coreMediaDirectory", "media/");
$this->system->set("coreMediaDirectory", $this->lookup->findMediaDirectory("coreMediaLocation"));
$this->system->set("coreSystemDirectory", "system/");
$this->system->set("coreCacheDirectory", "system/cache/");
$this->system->set("coreExtensionDirectory", "system/extensions/");
@ -2165,9 +2165,20 @@ class YellowLookup {
// Return media location from file path
public function findMediaLocationFromFile($fileName) {
$location = "";
$regex = "/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/";
$extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory"));
$themeDirectoryLength = strlenu($this->yellow->system->get("coreThemeDirectory"));
$mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory"));
if (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) {
$location = $this->yellow->system->get("coreMediaLocation").substru($fileName, $mediaDirectoryLength);
if (substru($fileName, 0, $extensionDirectoryLength)==$this->yellow->system->get("coreExtensionDirectory")) {
if ($this->isFileLocation($fileName) && preg_match($regex, $fileName)) {
$location = $this->yellow->system->get("coreExtensionLocation").substru($fileName, $extensionDirectoryLength);
}
} elseif (substru($fileName, 0, $themeDirectoryLength)==$this->yellow->system->get("coreThemeDirectory")) {
if ($this->isFileLocation($fileName) && preg_match($regex, $fileName)) {
$location = $this->yellow->system->get("coreThemeLocation").substru($fileName, $themeDirectoryLength);
}
} elseif (substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory")) {
$location = "/".$fileName;
}
return $location;
}
@ -2175,27 +2186,20 @@ class YellowLookup {
// Return file path from media location
public function findFileFromMediaLocation($location) {
$fileName = "";
if ($this->isFileLocation($location)) {
$regex = "/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/";
$extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation"));
$themeLocationLength = strlenu($this->yellow->system->get("coreThemeLocation"));
$mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation"));
if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) {
if (preg_match($regex, $location)) {
$fileName = $this->yellow->system->get("coreExtensionDirectory").substru($location, $extensionLocationLength);
}
} elseif (substru($location, 0, $themeLocationLength)==$this->yellow->system->get("coreThemeLocation")) {
if (preg_match($regex, $location)) {
$fileName = $this->yellow->system->get("coreThemeDirectory").substru($location, $themeLocationLength);
}
} elseif (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
$fileName = $this->yellow->system->get("coreMediaDirectory").substru($location, $mediaLocationLength);
$regex = "/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/";
$extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation"));
$themeLocationLength = strlenu($this->yellow->system->get("coreThemeLocation"));
$mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation"));
if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) {
if ($this->isFileLocation($location) && preg_match($regex, $location)) {
$fileName = $this->yellow->system->get("coreExtensionDirectory").substru($location, $extensionLocationLength);
}
} else {
$mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation"));
if (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
$fileName = $this->yellow->system->get("coreMediaDirectory").substru($location, $mediaLocationLength);
} elseif (substru($location, 0, $themeLocationLength)==$this->yellow->system->get("coreThemeLocation")) {
if ($this->isFileLocation($location) && preg_match($regex, $location)) {
$fileName = $this->yellow->system->get("coreThemeDirectory").substru($location, $themeLocationLength);
}
} elseif (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
$fileName = substru($location, 1);
}
return $fileName;
}
@ -2215,6 +2219,11 @@ class YellowLookup {
return $fileNames;
}
// Return media directory from a well-known system setting
public function findMediaDirectory($key) {
return substru($key, -8, 8)=="Location" ? $this->findFileFromMediaLocation($this->yellow->system->get($key)) : "";
}
// 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;

View file

@ -2,7 +2,7 @@
// Image extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/image
class YellowImage {
const VERSION = "0.8.15";
const VERSION = "0.8.16";
public $yellow; // access to API
// Handle initialisation
@ -19,7 +19,7 @@ class YellowImage {
public function onUpdate($action) {
if ($action=="clean") {
$statusCode = 200;
$path = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreThumbnailLocation"));
$path = $this->yellow->lookup->findMediaDirectory("coreThumbnailLocation");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
@ -36,7 +36,7 @@ class YellowImage {
if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
if (empty($width)) $width = "100%";
if (empty($height)) $height = $width;
$path = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreImageLocation"));
$path = $this->yellow->lookup->findMediaDirectory("coreImageLocation");
list($src, $width, $height) = $this->getImageInformation($path.$name, $width, $height);
} else {
if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
@ -82,8 +82,7 @@ class YellowImage {
// Return image information, create thumbnail on demand
public function getImageInformation($fileName, $widthOutput, $heightOutput) {
$pathImage = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreImageLocation"));
$fileNameShort = substru($fileName, strlenu($pathImage));
$fileNameShort = substru($fileName, strlenu($this->yellow->lookup->findMediaDirectory("coreImageLocation")));
list($widthInput, $heightInput, $orientation, $type) = $this->yellow->toolbox->detectImageInformation($fileName);
$widthOutput = $this->convertValueAndUnit($widthOutput, $widthInput);
$heightOutput = $this->convertValueAndUnit($heightOutput, $heightInput);
@ -92,7 +91,7 @@ class YellowImage {
$width = $widthOutput;
$height = $heightOutput;
} else {
$pathThumb = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreThumbnailLocation"));
$pathThumb = $this->yellow->lookup->findMediaDirectory("coreThumbnailLocation");
$fileNameThumb = ltrim(str_replace(array("/", "\\", "."), "-", dirname($fileNameShort)."/".pathinfo($fileName, PATHINFO_FILENAME)), "-");
$fileNameThumb .= "-".$widthOutput."x".$heightOutput;
$fileNameThumb .= ".".pathinfo($fileName, PATHINFO_EXTENSION);

View file

@ -11,21 +11,21 @@ Tag: feature
system/extensions/bundle.php: bundle.php, create, update
Extension: Command
Version: 0.8.38
Version: 0.8.39
Description: Command line of the website.
DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/command
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/command.zip
Published: 2022-04-18 22:37:50
Published: 2022-04-19 18:00:05
Developer: Datenstrom
Tag: feature
system/extensions/command.php: command.php, create, update
Extension: Core
Version: 0.8.69
Version: 0.8.70
Description: Core functionality of the website.
DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/core
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/core.zip
Published: 2022-04-18 23:13:06
Published: 2022-04-19 19:43:28
Developer: Datenstrom
Tag: feature
system/extensions/core.php: core.php, create, update
@ -52,11 +52,11 @@ system/extensions/edit.woff: edit.woff, delete
content/shared/page-new-default.md: page-new-default.md, create, optional
Extension: Image
Version: 0.8.15
Version: 0.8.16
Description: Images and thumbnails.
DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/image
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/image.zip
Published: 2022-04-18 22:15:10
Published: 2022-04-19 17:02:35
Developer: Datenstrom
Tag: feature
system/extensions/image.php: image.php, create, update