mikuli.cz

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

commit 74dfcfe7a05eb2b0ce8bac03c471d4b8b712c701
parent dabdf94a3d8dfd9a28db577a3a5a10f3556492d2
Author: markseu <mark2011@mayberg.se>
Date:   Tue, 19 Apr 2022 01:14:42 +0200

Updated API, removed some directory settings

Diffstat:
Msystem/extensions/bundle.php | 4++--
Msystem/extensions/command.php | 26++++++++++----------------
Msystem/extensions/core.php | 305++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msystem/extensions/edit.php | 25+++++++++++++++----------
Msystem/extensions/image.php | 17+++++++++--------
Msystem/extensions/install.php | 4++--
Msystem/extensions/update-current.ini | 28++++++++++++++--------------
Msystem/extensions/update.php | 3+--
8 files changed, 216 insertions(+), 196 deletions(-)

diff --git a/system/extensions/bundle.php b/system/extensions/bundle.php @@ -2,7 +2,7 @@ // Bundle extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/bundle class YellowBundle { - const VERSION = "0.8.25"; + const VERSION = "0.8.26"; public $yellow; // access to API // Handle initialisation @@ -76,7 +76,7 @@ class YellowBundle { if (preg_match("/data-bundle=\"exclude\"/i", $value)) continue; if (substru($key, 0, strlenu($base))!=$base) continue; $location = substru($key, strlenu($base)); - $fileName = $this->yellow->lookup->findFileFromSystem($location); + $fileName = $this->yellow->lookup->findFileFromMediaLocation($location); $modified = max($modified, $this->yellow->toolbox->getFileModified($fileName)); if (is_readable($fileName)) { array_push($fileNames, $fileName); 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.37"; + const VERSION = "0.8.38"; public $yellow; // access to API public $files; // number of files public $links; // number of links @@ -123,9 +123,6 @@ class YellowCommand { foreach ($this->getMediaLocations() as $location) { $statusCode = max($statusCode, $this->buildStaticFile($path, $location)); } - foreach ($this->getSystemLocations() as $location) { - $statusCode = max($statusCode, $this->buildStaticFile($path, $location)); - } foreach ($this->getExtraLocations($path) as $location) { $statusCode = max($statusCode, $this->buildStaticFile($path, $location)); } @@ -557,17 +554,13 @@ class YellowCommand { // Return media locations public function getMediaLocations() { $locations = array(); - $path = $this->yellow->system->get("coreMediaDirectory"); - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/.*/", false, false); + $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) { - array_push($locations, "/".$fileName); + $location = $this->yellow->system->get("coreMediaLocation").substru($fileName, $mediaDirectoryLength); + array_push($locations, $location); } - return $locations; - } - - // Return system locations - public function getSystemLocations() { - $locations = array(); $extensionPath = $this->yellow->system->get("coreExtensionDirectory"); $extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory")); $regex = "/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/"; @@ -583,11 +576,11 @@ class YellowCommand { $location = $this->yellow->system->get("coreThemeLocation").substru($fileName, $themeDirectoryLength); array_push($locations, $location); } - return array_diff($locations, $this->getSystemLocationsIgnore()); + return array_diff($locations, $this->getMediaLocationsIgnore()); } - // Return system locations to ignore - public function getSystemLocationsIgnore() { + // Return media locations to ignore + public function getMediaLocationsIgnore() { $locations = array(); $extensionPath = $this->yellow->system->get("coreExtensionDirectory"); $extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory")); @@ -635,6 +628,7 @@ class YellowCommand { curl_exec($curlHandle); $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); curl_close($curlHandle); + if ($statusCode<200) $statusCode = 404; if ($this->yellow->system->get("coreDebugMode")>=2) { echo "YellowCommand::getLinkStatus status:$statusCode url:$url<br/>\n"; } diff --git a/system/extensions/core.php b/system/extensions/core.php @@ -2,7 +2,7 @@ // Core extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/core class YellowCore { - const VERSION = "0.8.68"; + const VERSION = "0.8.69"; const RELEASE = "0.8.19"; public $page; // current page public $content; // content files @@ -39,30 +39,17 @@ class YellowCore { $this->system->setDefault("coreContentExtension", ".md"); $this->system->setDefault("coreContentDefaultFile", "page.md"); $this->system->setDefault("coreContentErrorFile", "page-error-(.*).md"); - $this->system->setDefault("coreSystemFile", "yellow-system.ini"); $this->system->setDefault("coreUserFile", "yellow-user.ini"); $this->system->setDefault("coreLanguageFile", "yellow-language.ini"); $this->system->setDefault("coreWebsiteFile", "yellow-website.log"); $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("coreThemeLocation", "/media/themes/"); $this->system->setDefault("coreMultiLanguageMode", "0"); $this->system->setDefault("coreDebugMode", "0"); - $this->system->setDefault("coreMediaDirectory", "media/"); - $this->system->setDefault("coreDownloadDirectory", "media/downloads/"); - $this->system->setDefault("coreImageDirectory", "media/images/"); - $this->system->setDefault("coreSystemDirectory", "system/"); - $this->system->setDefault("coreCacheDirectory", "system/cache/"); - $this->system->setDefault("coreExtensionDirectory", "system/extensions/"); - $this->system->setDefault("coreLayoutDirectory", "system/layouts/"); - $this->system->setDefault("coreThemeDirectory", "system/themes/"); - $this->system->setDefault("coreTrashDirectory", "system/trash/"); - $this->system->setDefault("coreContentDirectory", "content/"); - $this->system->setDefault("coreContentRootDirectory", "default/"); - $this->system->setDefault("coreContentHomeDirectory", "home/"); - $this->system->setDefault("coreContentSharedDirectory", "shared/"); $this->language->setDefault("coreDateFormatShort"); $this->language->setDefault("coreDateFormatMedium"); $this->language->setDefault("coreDateFormatLong"); @@ -86,12 +73,26 @@ class YellowCore { // Handle initialisation public function load() { - $this->system->load($this->system->get("coreExtensionDirectory").$this->system->get("coreSystemFile")); + $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("coreSystemDirectory", "system/"); + $this->system->set("coreCacheDirectory", "system/cache/"); + $this->system->set("coreExtensionDirectory", "system/extensions/"); + $this->system->set("coreLayoutDirectory", "system/layouts/"); + $this->system->set("coreThemeDirectory", "system/themes/"); + $this->system->set("coreTrashDirectory", "system/trash/"); + list($pathInstall, $pathRoot, $pathHome) = $this->lookup->findFileSystemInformation(); + $this->system->set("coreServerInstallDirectory", $pathInstall); + $this->system->set("coreServerRootDirectory", $pathRoot); + $this->system->set("coreServerHomeDirectory", $pathHome); register_shutdown_function(array($this, "processFatalError")); if ($this->system->get("coreDebugMode")>=1) { ini_set("display_errors", 1); error_reporting(E_ALL); } + date_default_timezone_set($this->system->get("coreTimezone")); $this->user->load($this->system->get("coreExtensionDirectory").$this->system->get("coreUserFile")); $this->language->load($this->system->get("coreExtensionDirectory")); $this->language->load($this->system->get("coreExtensionDirectory").$this->system->get("coreLanguageFile")); @@ -185,10 +186,10 @@ class YellowCore { // Read page public function readPage($scheme, $address, $base, $location, $fileName, $cacheable, $statusCode, $pageError) { if ($statusCode>=400) { - $locationError = $this->content->getHomeLocation($this->page->location).$this->system->get("coreContentSharedDirectory"); - $fileNameError = $this->lookup->findFileFromLocation($locationError, true).$this->system->get("coreContentErrorFile"); + $locationError = $this->content->getHomeLocation($this->page->location)."shared/"; + $fileNameError = $this->lookup->findFileFromContentLocation($locationError, true).$this->system->get("coreContentErrorFile"); $fileNameError = str_replace("(.*)", $statusCode, $fileNameError); - $languageError = $this->lookup->findLanguageFromFile($fileName, $this->system->get("language")); + $languageError = $this->lookup->findContentLanguage($fileName, $this->system->get("language")); if (is_file($fileNameError)) { $rawData = $this->toolbox->readFile($fileNameError); } elseif ($this->language->isText("coreError${statusCode}Title", $languageError)) { @@ -375,9 +376,8 @@ class YellowCore { } } $location = substru($this->toolbox->detectServerLocation(), strlenu($base)); - if (empty($fileName)) $fileName = $this->lookup->findFileFromSystem($location); - if (empty($fileName)) $fileName = $this->lookup->findFileFromMedia($location); - if (empty($fileName)) $fileName = $this->lookup->findFileFromLocation($location); + if (empty($fileName)) $fileName = $this->lookup->findFileFromMediaLocation($location); + if (empty($fileName)) $fileName = $this->lookup->findFileFromContentLocation($location); return array($scheme, $address, $base, $location, $fileName); } @@ -496,7 +496,7 @@ class YellowPage { $this->metaData = new YellowArray(); if (!is_null($this->rawData)) { $this->set("title", $this->yellow->toolbox->createTextTitle($this->location)); - $this->set("language", $this->yellow->lookup->findLanguageFromFile($this->fileName, $this->yellow->system->get("language"))); + $this->set("language", $this->yellow->lookup->findContentLanguage($this->fileName, $this->yellow->system->get("language"))); $this->set("modified", date("Y-m-d H:i:s", $this->yellow->toolbox->getFileModified($this->fileName))); $this->parseMetaRaw(array("sitename", "author", "layout", "theme", "parser", "status")); $titleHeader = ($this->location==$this->yellow->content->getHomeLocation($this->location)) ? @@ -1005,11 +1005,11 @@ class YellowPageCollection extends ArrayObject { return $this; } - // Filter page collection by file name + // Filter page collection by location public function match($regex = "/.*/") { $array = array(); foreach ($this->getArrayCopy() as $page) { - if (preg_match($regex, $page->fileName)) array_push($array, $page); + if (preg_match($regex, $page->location)) array_push($array, $page); } $this->exchangeArray($array); return $this; @@ -1227,26 +1227,25 @@ class YellowContent { // Scan file system on demand public function scanLocation($location) { if (!isset($this->pages[$location])) { - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowContent::scanLocation location:$location<br/>\n"; $this->pages[$location] = array(); $scheme = $this->yellow->page->scheme; $address = $this->yellow->page->address; $base = $this->yellow->page->base; if (empty($location)) { - $rootLocations = $this->yellow->lookup->findRootLocations(); - foreach ($rootLocations as $rootLocation) { - list($rootLocation, $fileName) = $this->yellow->toolbox->getTextList($rootLocation, " ", 2); + $rootLocations = $this->yellow->lookup->findContentRootLocations(); + foreach ($rootLocations as $rootLocation=>$rootFileName) { $page = new YellowPage($this->yellow); - $page->setRequestInformation($scheme, $address, $base, $rootLocation, $fileName); + $page->setRequestInformation($scheme, $address, $base, $rootLocation, $rootFileName); $page->parseData("", false, 0); array_push($this->pages[$location], $page); } } else { - $fileNames = $this->yellow->lookup->findChildrenFromLocation($location); + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowContent::scanLocation location:$location<br/>\n"; + $fileNames = $this->yellow->lookup->findChildrenFromContentLocation($location); foreach ($fileNames as $fileName) { $page = new YellowPage($this->yellow); $page->setRequestInformation($scheme, $address, $base, - $this->yellow->lookup->findLocationFromFile($fileName), $fileName); + $this->yellow->lookup->findContentLocationFromFile($fileName), $fileName); $page->parseData($this->yellow->toolbox->readFile($fileName, 4096), false, 0); if (strlenb($page->rawData)<4096) $page->statusCode = 200; array_push($this->pages[$location], $page); @@ -1337,8 +1336,10 @@ class YellowContent { // Return languages in multi language mode public function getLanguages($showInvisible = false) { $languages = array(); - foreach ($this->scanLocation("") as $page) { - if ($page->isAvailable() && ($page->isVisible() || $showInvisible)) array_push($languages, $page->get("language")); + if ($this->yellow->system->get("coreMultiLanguageMode")) { + foreach ($this->scanLocation("") as $page) { + if ($page->isAvailable() && ($page->isVisible() || $showInvisible)) array_push($languages, $page->get("language")); + } } return $languages; } @@ -1372,7 +1373,7 @@ class YellowContent { // Return shared pages public function getShared($location) { $pages = new YellowPageCollection($this->yellow); - $location = $this->getHomeLocation($location).$this->yellow->system->get("coreContentSharedDirectory"); + $location = $this->getHomeLocation($location)."shared/"; foreach ($this->scanLocation($location) as $page) { if ($page->get("status")=="shared") $pages->append($page); } @@ -1430,7 +1431,6 @@ class YellowMedia { // Scan file system on demand public function scanLocation($location) { if (!isset($this->files[$location])) { - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowMedia::scanLocation location:$location<br/>\n"; $this->files[$location] = array(); $scheme = $this->yellow->page->scheme; $address = $this->yellow->page->address; @@ -1438,18 +1438,13 @@ class YellowMedia { if (empty($location)) { $fileNames = array($this->yellow->system->get("coreMediaDirectory")); } else { - $fileNames = array(); - $path = substru($location, 1); - foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, true) as $entry) { - array_push($fileNames, $entry."/"); - } - foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, false, true) as $entry) { - array_push($fileNames, $entry); - } + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowMedia::scanLocation location:$location<br/>\n"; + $fileNames = $this->yellow->lookup->findChildrenFromMediaLocation($location); } foreach ($fileNames as $fileName) { $file = new YellowPage($this->yellow); - $file->setRequestInformation($scheme, $address, $base, "/".$fileName, $fileName); + $file->setRequestInformation($scheme, $address, $base, + $this->yellow->lookup->findMediaLocationFromFile($fileName), $fileName); $file->parseData(null, false, 0); array_push($this->files[$location], $file); } @@ -1547,20 +1542,15 @@ class YellowSystem { // Load system settings from file public function load($fileName) { - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowSystem::load file:$fileName<br/>\n"; $this->modified = $this->yellow->toolbox->getFileModified($fileName); $fileData = $this->yellow->toolbox->readFile($fileName); $this->settings = $this->yellow->toolbox->getTextSettings($fileData, ""); + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowSystem::load file:$fileName<br/>\n"; if ($this->yellow->system->get("coreDebugMode")>=3) { foreach ($this->settings as $key=>$value) { echo "YellowSystem::load ".ucfirst($key).":$value<br/>\n"; } } - list($pathInstall, $pathRoot, $pathHome) = $this->yellow->lookup->findFileSystemInformation(); - $this->yellow->system->set("coreServerInstallDirectory", $pathInstall); - $this->yellow->system->set("coreContentRootDirectory", $pathRoot); - $this->yellow->system->set("coreContentHomeDirectory", $pathHome); - date_default_timezone_set($this->yellow->system->get("coreTimezone")); } // Save system settings to file @@ -1668,10 +1658,10 @@ class YellowUser { // Load user settings from file public function load($fileName) { - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowUser::load file:$fileName<br/>\n"; $this->modified = $this->yellow->toolbox->getFileModified($fileName); $fileData = $this->yellow->toolbox->readFile($fileName); $this->settings = $this->yellow->toolbox->getTextSettings($fileData, "email"); + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowUser::load file:$fileName<br/>\n"; } // Save user settings to file @@ -1771,7 +1761,6 @@ class YellowLanguage { $regex = "/^.*\.txt$/"; } foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry) { - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowLanguage::load file:$entry<br/>\n"; $this->modified = max($this->modified, filemtime($entry)); $fileData = $this->yellow->toolbox->readFile($entry); $settings = $this->yellow->toolbox->getTextSettings($fileData, "language"); @@ -1784,6 +1773,7 @@ class YellowLanguage { } } } + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowLanguage::load file:$entry<br/>\n"; } foreach ($this->settings->getArrayCopy() as $key=>$value) { if (!isset($this->settings[$key]["languageDescription"])) { @@ -1938,11 +1928,11 @@ class YellowExtension { // Load extensions public function load($path) { foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.php$/", true, false) as $entry) { - if ($this->yellow->system->get("coreDebugMode")>=3) echo "YellowExtension::load file:$entry<br/>\n"; $this->modified = max($this->modified, filemtime($entry)); require_once($entry); $name = $this->yellow->lookup->normaliseName(basename($entry), true, true); $this->register(lcfirst($name), "Yellow".ucfirst($name)); + if ($this->yellow->system->get("coreDebugMode")>=3) echo "YellowExtension::load file:$entry<br/>\n"; } $callback = function ($a, $b) { return $a["priority"] - $b["priority"]; @@ -1994,10 +1984,10 @@ class YellowLookup { public function findFileSystemInformation() { $pathInstall = substru(__DIR__, 0, 1-strlenu($this->yellow->system->get("coreExtensionDirectory"))); $pathBase = $this->yellow->system->get("coreContentDirectory"); - $pathRoot = $this->yellow->system->get("coreContentRootDirectory"); - $pathHome = $this->yellow->system->get("coreContentHomeDirectory"); - if (!$this->yellow->system->get("coreMultiLanguageMode")) $pathRoot = ""; + $pathRoot = $this->yellow->system->get("coreMultiLanguageMode") ? "default/" : ""; + $pathHome = "home/"; if (!empty($pathRoot)) { + $firstRoot = ""; $token = $root = rtrim($pathRoot, "/"); foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) { if (empty($firstRoot)) $firstRoot = $token = $entry; @@ -2010,6 +2000,7 @@ class YellowLookup { $pathBase .= "$firstRoot/"; } if (!empty($pathHome)) { + $firstHome = ""; $token = $home = rtrim($pathHome, "/"); foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) { if (empty($firstHome)) $firstHome = $token = $entry; @@ -2022,32 +2013,51 @@ class YellowLookup { } return array($pathInstall, $pathRoot, $pathHome); } + + // Return content language + public function findContentLanguage($fileName, $languageDefault) { + $language = $languageDefault; + $pathBase = $this->yellow->system->get("coreContentDirectory"); + $pathRoot = $this->yellow->system->get("coreServerRootDirectory"); + if (!empty($pathRoot)) { + $fileName = substru($fileName, strlenu($pathBase)); + if (preg_match("/^(.+?)\//", $fileName, $matches)) { + $name = $this->normaliseToken($matches[1]); + if (strlenu($name)==2) $language = $name; + } + } + return $language; + } - // Return root locations - public function findRootLocations($includePath = true) { - $locations = array(); + // Return content root locations + public function findContentRootLocations() { + $rootLocations = array(); $pathBase = $this->yellow->system->get("coreContentDirectory"); - $pathRoot = $this->yellow->system->get("coreContentRootDirectory"); + $pathRoot = $this->yellow->system->get("coreServerRootDirectory"); if (!empty($pathRoot)) { foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) { $token = $this->normaliseToken($entry)."/"; if ($token==$pathRoot) $token = ""; - array_push($locations, $includePath ? "root/$token $pathBase$entry/" : "root/$token"); - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowLookup::findRootLocations root/$token<br/>\n"; + $rootLocations["root/$token"] = "$pathBase$entry/"; } } else { - array_push($locations, $includePath ? "root/ $pathBase" : "root/"); + $rootLocations["root/"] = "$pathBase"; + } + if ($this->yellow->system->get("coreDebugMode")>=3) { + foreach ($rootLocations as $key=>$key) { + echo "YellowLookup::findContentRootLocations $key -> $value<br/>\n"; + } } - return $locations; + return $rootLocations; } - // Return location from file path - public function findLocationFromFile($fileName) { + // Return content location from file path + public function findContentLocationFromFile($fileName) { $invalid = false; $location = "/"; $pathBase = $this->yellow->system->get("coreContentDirectory"); - $pathRoot = $this->yellow->system->get("coreContentRootDirectory"); - $pathHome = $this->yellow->system->get("coreContentHomeDirectory"); + $pathRoot = $this->yellow->system->get("coreServerRootDirectory"); + $pathHome = $this->yellow->system->get("coreServerHomeDirectory"); $fileDefault = $this->yellow->system->get("coreContentDefaultFile"); $fileExtension = $this->yellow->system->get("coreContentExtension"); if (substru($fileName, 0, strlenu($pathBase))==$pathBase && mb_check_encoding($fileName, "UTF-8")) { @@ -2073,17 +2083,17 @@ class YellowLookup { } if ($this->yellow->system->get("coreDebugMode")>=2) { $debug = ($invalid ? "INVALID" : $location)." <- $pathBase$fileName"; - echo "YellowLookup::findLocationFromFile $debug<br/>\n"; + echo "YellowLookup::findContentLocationFromFile $debug<br/>\n"; } return $invalid ? "" : $location; } - // Return file path from location - public function findFileFromLocation($location, $directory = false) { + // Return file path from content location + public function findFileFromContentLocation($location, $directory = false) { $found = $invalid = false; $path = $this->yellow->system->get("coreContentDirectory"); - $pathRoot = $this->yellow->system->get("coreContentRootDirectory"); - $pathHome = $this->yellow->system->get("coreContentHomeDirectory"); + $pathRoot = $this->yellow->system->get("coreServerRootDirectory"); + $pathHome = $this->yellow->system->get("coreServerHomeDirectory"); $fileDefault = $this->yellow->system->get("coreContentDefaultFile"); $fileExtension = $this->yellow->system->get("coreContentExtension"); $tokens = explode("/", $location); @@ -2123,52 +2133,20 @@ class YellowLookup { } if ($this->yellow->system->get("coreDebugMode")>=2) { $debug = "$location -> ".($invalid ? "INVALID" : $path); - echo "YellowLookup::findFileFromLocation $debug<br/>\n"; + echo "YellowLookup::findFileFromContentLocation $debug<br/>\n"; } } } return $invalid ? "" : $path; } - // 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; - if (!$invalid) { - $regex = "/^[\d\-\_\.]*".str_replace("-", ".", $token)."$/"; - foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, false, $directory, false) as $entry) { - if ($this->normaliseToken($entry, $fileExtension)==$token) { - $token = $entry; - $found = true; - break; - } - } - } - if ($directory) $token .= "/"; - return ($default || $found) ? $token : ""; - } - - // Return default file in directory - public function findFileDefault($path, $fileDefault, $fileExtension, $includePath = true) { - $token = $fileDefault; - if (!is_file($path."/".$fileDefault)) { - $regex = "/^[\d\-\_\.]*($fileDefault)$/"; - foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false, false) as $entry) { - if ($this->normaliseToken($entry, $fileExtension)==$fileDefault) { - $token = $entry; - break; - } - } - } - return $includePath ? "$path/$token" : $token; - } - - // Return children from location - public function findChildrenFromLocation($location) { + // Return children from content location + public function findChildrenFromContentLocation($location) { $fileNames = array(); - $fileDefault = $this->yellow->system->get("coreContentDefaultFile"); - $fileExtension = $this->yellow->system->get("coreContentExtension"); if (!$this->isFileLocation($location)) { - $path = $this->findFileFromLocation($location, true); + $path = $this->findFileFromContentLocation($location, true); + $fileDefault = $this->yellow->system->get("coreContentDefaultFile"); + $fileExtension = $this->yellow->system->get("coreContentExtension"); foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, false) as $entry) { $token = $this->findFileDefault($path.$entry, $fileDefault, $fileExtension, false); array_push($fileNames, $path.$entry."/".$token); @@ -2183,47 +2161,90 @@ class YellowLookup { } return $fileNames; } - - // Return language from file path - public function findLanguageFromFile($fileName, $languageDefault) { - $language = $languageDefault; - $pathBase = $this->yellow->system->get("coreContentDirectory"); - $pathRoot = $this->yellow->system->get("coreContentRootDirectory"); - if (!empty($pathRoot)) { - $fileName = substru($fileName, strlenu($pathBase)); - if (preg_match("/^(.+?)\//", $fileName, $matches)) { - $name = $this->normaliseToken($matches[1]); - if (strlenu($name)==2) $language = $name; - } + + // Return media location from file path + public function findMediaLocationFromFile($fileName) { + $location = ""; + $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); } - return $language; + return $location; } // Return file path from media location - public function findFileFromMedia($location) { - $fileName = null; + 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); + } + } 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, 7); + $fileName = $this->yellow->system->get("coreMediaDirectory").substru($location, $mediaLocationLength); } } return $fileName; } - // Return file path from system location - public function findFileFromSystem($location) { - $fileName = null; - if (preg_match("/\.(css|gif|ico|js|jpg|png|svg|woff|woff2)$/", $location)) { - $extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation")); - $themeLocationLength = strlenu($this->yellow->system->get("coreThemeLocation")); - if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) { - $fileName = $this->yellow->system->get("coreExtensionDirectory").substru($location, $extensionLocationLength); - } elseif (substru($location, 0, $themeLocationLength)==$this->yellow->system->get("coreThemeLocation")) { - $fileName = $this->yellow->system->get("coreThemeDirectory").substru($location, $themeLocationLength); + // Return children from media location + public function findChildrenFromMediaLocation($location) { + $fileNames = array(); + if (!$this->isFileLocation($location)) { + $path = $this->findFileFromMediaLocation($location); + foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, true) as $entry) { + array_push($fileNames, $entry."/"); + } + foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, false, true) as $entry) { + array_push($fileNames, $entry); } } - return $fileName; + return $fileNames; + } + + // 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; + if (!$invalid) { + $regex = "/^[\d\-\_\.]*".str_replace("-", ".", $token)."$/"; + foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, false, $directory, false) as $entry) { + if ($this->normaliseToken($entry, $fileExtension)==$token) { + $token = $entry; + $found = true; + break; + } + } + } + if ($directory) $token .= "/"; + return ($default || $found) ? $token : ""; + } + + // Return default file in directory + public function findFileDefault($path, $fileDefault, $fileExtension, $includePath = true) { + $token = $fileDefault; + if (!is_file($path."/".$fileDefault)) { + $regex = "/^[\d\-\_\.]*($fileDefault)$/"; + foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false, false) as $entry) { + if ($this->normaliseToken($entry, $fileExtension)==$fileDefault) { + $token = $entry; + break; + } + } + } + return $includePath ? "$path/$token" : $token; } // Normalise file/directory token @@ -2345,7 +2366,7 @@ class YellowLookup { public function isRedirectLocation($location) { $redirect = false; if ($this->isFileLocation($location)) { - $redirect = is_dir($this->findFileFromLocation("$location/", true)); + $redirect = is_dir($this->findFileFromContentLocation("$location/", true)); } elseif ($location=="/") { $redirect = $this->yellow->system->get("coreMultiLanguageMode"); } @@ -2367,7 +2388,7 @@ class YellowLookup { $available = true; $pathBase = $this->yellow->system->get("coreContentDirectory"); if (substru($fileName, 0, strlenu($pathBase))==$pathBase) { - $sharedLocation = $this->yellow->content->getHomeLocation($location).$this->yellow->system->get("coreContentSharedDirectory"); + $sharedLocation = $this->yellow->content->getHomeLocation($location)."shared/"; if (substru($location, 0, strlenu($sharedLocation))==$sharedLocation) $available = false; } return $available; @@ -3257,7 +3278,7 @@ class YellowToolbox { return $languageFound; } - // Detect image width, height, orientation and type for gif/jpg/png/svg + // Detect image width, height, orientation and type for GIF/JPG/PNG/SVG public function detectImageInformation($fileName, $fileType = "") { $width = $height = $orientation = 0; $type = ""; 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.56"; + const VERSION = "0.8.57"; public $yellow; // access to API public $response; // web response public $merge; // text merge @@ -351,7 +351,7 @@ class YellowEdit { $fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile"); $settings = array( "name" => $name, - "language" => $this->yellow->lookup->findLanguageFromFile($fileName, $this->yellow->system->get("language")), + "language" => $this->yellow->lookup->findContentLanguage($fileName, $this->yellow->system->get("language")), "home" => $this->yellow->system->get("editUserHome"), "access" => $this->yellow->system->get("editUserAccess"), "hash" => $this->response->createHash($password), @@ -1356,16 +1356,16 @@ class YellowEditResponse { foreach ($this->yellow->content->path($page->location)->reverse() as $ancestor) { if ($ancestor->isExisting("layoutNew")) { $name = $this->yellow->lookup->normaliseName($ancestor->get("layoutNew")); - $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDirectory"); - $fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->system->get("editNewFile"); + $location = $this->yellow->content->getHomeLocation($page->location)."shared/"; + $fileName = $this->yellow->lookup->findFileFromContentLocation($location, true).$this->yellow->system->get("editNewFile"); $fileName = str_replace("(.*)", $name, $fileName); if (is_file($fileName)) break; } } if (!is_file($fileName)) { $name = $this->yellow->lookup->normaliseName($this->yellow->system->get("layout")); - $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDirectory"); - $fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->system->get("editNewFile"); + $location = $this->yellow->content->getHomeLocation($page->location)."shared/"; + $fileName = $this->yellow->lookup->findFileFromContentLocation($location, true).$this->yellow->system->get("editNewFile"); $fileName = str_replace("(.*)", $name, $fileName); } if (is_file($fileName)) { @@ -1431,7 +1431,7 @@ class YellowEditResponse { // Return file name for new/modified page public function getPageNewFile($location, $pageFileName = "", $pagePrefix = "") { - $fileName = $this->yellow->lookup->findFileFromLocation($location); + $fileName = $this->yellow->lookup->findFileFromContentLocation($location); if (!empty($fileName)) { if (!is_dir(dirname($fileName))) { $path = ""; @@ -1503,10 +1503,15 @@ class YellowEditResponse { // Return group for new file public function getFileNewGroup($fileNameShort) { $group = "none"; - $path = $this->yellow->system->get("coreMediaDirectory"); $fileType = $this->yellow->toolbox->getFileType($fileNameShort); - $fileName = $this->yellow->system->get(preg_match("/(gif|jpg|png|svg)$/", $fileType) ? "coreImageDirectory" : "coreDownloadDirectory").$fileNameShort; - if (preg_match("#^$path(.+?)\/#", $fileName, $matches)) $group = strtoloweru($matches[1]); + $locationMedia = $this->yellow->system->get("coreMediaLocation"); + $locationGroup = $this->yellow->system->get("coreDownloadLocation"); + if (preg_match("/(gif|jpg|png|svg)$/", $fileType)) { + $locationGroup = $this->yellow->system->get("coreImageLocation"); + } + if (preg_match("#^$locationMedia(.+?)\/#", $locationGroup, $matches)) { + $group = strtoloweru($matches[1]); + } return $group; } diff --git a/system/extensions/image.php b/system/extensions/image.php @@ -2,7 +2,7 @@ // Image extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/image class YellowImage { - const VERSION = "0.8.14"; + const VERSION = "0.8.15"; public $yellow; // access to API // Handle initialisation @@ -11,8 +11,6 @@ class YellowImage { $this->yellow->system->setDefault("imageUploadWidthMax", "1280"); $this->yellow->system->setDefault("imageUploadHeightMax", "1280"); $this->yellow->system->setDefault("imageUploadJpgQuality", "80"); - $this->yellow->system->setDefault("imageThumbnailLocation", "/media/thumbnails/"); - $this->yellow->system->setDefault("imageThumbnailDirectory", "media/thumbnails/"); $this->yellow->system->setDefault("imageThumbnailJpgQuality", "80"); $this->yellow->language->setDefault("imageDefaultAlt"); } @@ -21,7 +19,7 @@ class YellowImage { public function onUpdate($action) { if ($action=="clean") { $statusCode = 200; - $path = $this->yellow->system->get("imageThumbnailDirectory"); + $path = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreThumbnailLocation")); foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) { if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500; } @@ -38,7 +36,8 @@ class YellowImage { if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt"); if (empty($width)) $width = "100%"; if (empty($height)) $height = $width; - list($src, $width, $height) = $this->getImageInformation($this->yellow->system->get("coreImageDirectory").$name, $width, $height); + $path = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreImageLocation")); + list($src, $width, $height) = $this->getImageInformation($path.$name, $width, $height); } else { if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt"); $src = $this->yellow->lookup->normaliseUrl("", "", "", $name); @@ -83,7 +82,8 @@ class YellowImage { // Return image information, create thumbnail on demand public function getImageInformation($fileName, $widthOutput, $heightOutput) { - $fileNameShort = substru($fileName, strlenu($this->yellow->system->get("coreImageDirectory"))); + $pathImage = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreImageLocation")); + $fileNameShort = substru($fileName, strlenu($pathImage)); list($widthInput, $heightInput, $orientation, $type) = $this->yellow->toolbox->detectImageInformation($fileName); $widthOutput = $this->convertValueAndUnit($widthOutput, $widthInput); $heightOutput = $this->convertValueAndUnit($heightOutput, $heightInput); @@ -92,10 +92,11 @@ class YellowImage { $width = $widthOutput; $height = $heightOutput; } else { + $pathThumb = $this->yellow->lookup->findFileFromMediaLocation($this->yellow->system->get("coreThumbnailLocation")); $fileNameThumb = ltrim(str_replace(array("/", "\\", "."), "-", dirname($fileNameShort)."/".pathinfo($fileName, PATHINFO_FILENAME)), "-"); $fileNameThumb .= "-".$widthOutput."x".$heightOutput; $fileNameThumb .= ".".pathinfo($fileName, PATHINFO_EXTENSION); - $fileNameOutput = $this->yellow->system->get("imageThumbnailDirectory").$fileNameThumb; + $fileNameOutput = $pathThumb.$fileNameThumb; if ($this->isFileNotUpdated($fileName, $fileNameOutput)) { $image = $this->loadImage($fileName, $type); $image = $this->resizeImage($image, $widthInput, $heightInput, $widthOutput, $heightOutput); @@ -106,7 +107,7 @@ class YellowImage { $this->yellow->page->error(500, "Can't write file '$fileNameOutput'!"); } } - $src = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("imageThumbnailLocation").$fileNameThumb; + $src = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreThumbnailLocation").$fileNameThumb; list($width, $height) = $this->yellow->toolbox->detectImageInformation($fileNameOutput); } return array($src, $width, $height); diff --git a/system/extensions/install.php b/system/extensions/install.php @@ -2,7 +2,7 @@ // Install extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/install class YellowInstall { - const VERSION = "0.8.68"; + const VERSION = "0.8.69"; const PRIORITY = "1"; public $yellow; // access to API @@ -216,7 +216,7 @@ class YellowInstall { // Update content public function updateContent($language, $name, $location) { $statusCode = 200; - $fileName = $this->yellow->lookup->findFileFromLocation($location); + $fileName = $this->yellow->lookup->findFileFromContentLocation($location); $fileData = str_replace("\r\n", "\n", $this->yellow->toolbox->readFile($fileName)); if (!empty($fileData) && $language!="en") { $titleOld = "Title: ".$this->yellow->language->getText("{$name}Title", "en")."\n"; diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini @@ -1,31 +1,31 @@ # Datenstrom Yellow update settings Extension: Bundle -Version: 0.8.25 +Version: 0.8.26 Description: Bundle website files. DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/bundle DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/bundle.zip -Published: 2022-04-13 18:41:53 +Published: 2022-04-18 17:44:11 Developer: Datenstrom Tag: feature system/extensions/bundle.php: bundle.php, create, update Extension: Command -Version: 0.8.37 +Version: 0.8.38 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-17 02:25:54 +Published: 2022-04-18 22:37:50 Developer: Datenstrom Tag: feature system/extensions/command.php: command.php, create, update Extension: Core -Version: 0.8.68 +Version: 0.8.69 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-17 02:00:23 +Published: 2022-04-18 23:13:06 Developer: Datenstrom Tag: feature system/extensions/core.php: core.php, create, update @@ -37,11 +37,11 @@ system/layouts/navigation.html: navigation.html, create, update, careful system/layouts/pagination.html: pagination.html, create, update, careful Extension: Edit -Version: 0.8.56 +Version: 0.8.57 Description: Edit your website in a web browser. DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/edit DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/edit.zip -Published: 2022-03-11 00:51:13 +Published: 2022-04-18 23:11:04 Developer: Datenstrom Tag: feature system/extensions/edit.php: edit.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.14 +Version: 0.8.15 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-13 18:42:22 +Published: 2022-04-18 22:15:10 Developer: Datenstrom Tag: feature system/extensions/image.php: image.php, create, update @@ -64,11 +64,11 @@ media/images/photo.jpg: photo.jpg, create, optional media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional Extension: Install -Version: 0.8.68 +Version: 0.8.69 Description: Install a brand new, shiny website. DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/install DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/install.zip -Published: 2022-04-17 01:09:22 +Published: 2022-04-18 23:25:29 Developer: Datenstrom Status: unlisted system/extensions/install.php: install.php, create @@ -131,11 +131,11 @@ system/themes/stockholm-opensans-light.woff: stockholm-opensans-light.woff, crea system/themes/stockholm-opensans-regular.woff: stockholm-opensans-regular.woff, create, update, careful Extension: Update -Version: 0.8.70 +Version: 0.8.71 Description: Keep your website up to date. DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/update DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/update.zip -Published: 2022-04-17 02:29:57 +Published: 2022-04-18 17:44:30 Developer: Datenstrom Tag: feature system/extensions/update.php: update.php, create, update diff --git a/system/extensions/update.php b/system/extensions/update.php @@ -2,7 +2,7 @@ // Update extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/update class YellowUpdate { - const VERSION = "0.8.70"; + const VERSION = "0.8.71"; const PRIORITY = "2"; public $yellow; // access to API public $extensions; // number of extensions @@ -496,7 +496,6 @@ class YellowUpdate { $fileDataComments .= $line; } } - unset($settings["coreSystemFile"]); foreach ($settings as $key=>$value) { $fileDataSettings .= ucfirst($key).(strempty($value) ? ":\n" : ": $value\n"); }