mikuli.cz

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

commit e844a259545009857390bad65e5527fea1fa3d81
parent a37a18d7bd20e88523ee6b6f8b2e7b78a310ea23
Author: markseu <mark2011@mayberg.se>
Date:   Sun, 23 Oct 2022 23:45:08 +0200

Updated API, new way of loading translations

Diffstat:
Msystem/extensions/core.php | 280+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msystem/extensions/edit.php | 5++---
Msystem/extensions/image.php | 3+--
Msystem/extensions/install-blog.bin | 0
Msystem/extensions/install-language.bin | 0
Msystem/extensions/install-wiki.bin | 0
Msystem/extensions/install.php | 20++++++++------------
Msystem/extensions/stockholm.php | 5++---
Msystem/extensions/update-current.ini | 24++++++++++++------------
Msystem/extensions/update.php | 264++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
10 files changed, 311 insertions(+), 290 deletions(-)

diff --git a/system/extensions/core.php b/system/extensions/core.php @@ -2,14 +2,14 @@ // Core extension, https://github.com/annaesvensson/yellow-core class YellowCore { - const VERSION = "0.8.94"; + const VERSION = "0.8.95"; const RELEASE = "0.8.21"; public $page; // current page public $content; // content files public $media; // media files public $system; // system settings - public $user; // user settings public $language; // language settings + public $user; // user settings public $extension; // extensions public $lookup; // location and file lookup public $toolbox; // toolbox with helper functions @@ -19,8 +19,8 @@ class YellowCore { $this->content = new YellowContent($this); $this->media = new YellowMedia($this); $this->system = new YellowSystem($this); - $this->user = new YellowUser($this); $this->language = new YellowLanguage($this); + $this->user = new YellowUser($this); $this->extension = new YellowExtension($this); $this->lookup = new YellowLookup($this); $this->toolbox = new YellowToolbox(); @@ -50,9 +50,6 @@ class YellowCore { $this->system->setDefault("coreThemeLocation", "/media/themes/"); $this->system->setDefault("coreMultiLanguageMode", "0"); $this->system->setDefault("coreDebugMode", "0"); - $this->language->setDefault("coreDateFormatShort"); - $this->language->setDefault("coreDateFormatMedium"); - $this->language->setDefault("coreDateFormatLong"); } public function __destruct() { @@ -91,10 +88,9 @@ class YellowCore { 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")); $this->extension->load($this->system->get("coreExtensionDirectory")); + $this->language->load($this->system->get("coreExtensionDirectory").$this->system->get("coreLanguageFile")); + $this->user->load($this->system->get("coreExtensionDirectory").$this->system->get("coreUserFile")); $this->startup(); } @@ -1602,23 +1598,15 @@ class YellowSystem { return htmlspecialchars($this->get($key)); } - // Return system settings - public function getSettings($filterStart = "", $filterEnd = "") { - $settings = array(); - if (empty($filterStart) && empty($filterEnd)) { - $settings = array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy()); - } else { - foreach (array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy()) as $key=>$value) { - if (!empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value; - if (!empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value; - } - } - return $settings; + // Return different value for system setting + public function getDifferent($key) { + return reset(array_diff($this->getAvailable($key), array($this->get($key)))); } - - // Return supported values for system setting, empty if not known - public function getValues($key) { + + // Return available values for system setting + public function getAvailable($key) { $values = array(); + $valueDefault = isset($this->settingsDefaults[$key]) ? $this->settingsDefaults[$key] : ""; if ($key=="email") { foreach ($this->yellow->user->settings as $userKey=>$userValue) { array_push($values, $userKey); @@ -1638,110 +1626,32 @@ class YellowSystem { array_push($values, lcfirst(substru($entry, 0, -4))); } } - return $values; - } - - // Return system settings modification date, Unix time or HTTP format - public function getModified($httpFormat = false) { - return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified; - } - - // Check if system setting exists - public function isExisting($key) { - return isset($this->settings[$key]); + return count($values) ? $values : array($valueDefault); } -} - -class YellowUser { - public $yellow; // access to API - public $modified; // user modification date - public $settings; // user settings - public $email; // current email + public function getValues($key) { return $this->getAvailable($key); } //TODO: remove later, for backwards compatibility - public function __construct($yellow) { - $this->yellow = $yellow; - $this->modified = 0; - $this->settings = new YellowArray(); - $this->email = ""; - } - - // Load user settings from file - public function load($fileName) { - $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 - public function save($fileName, $email, $settings) { - $this->modified = time(); - $settingsNew = new YellowArray(); - $settingsNew["email"] = $email; - foreach ($settings as $key=>$value) { - if (!empty($key) && !strempty($value)) { - $this->setUser($key, $value, $email); - $settingsNew[$key] = $value; + // Return system settings + public function getSettings($filterStart = "", $filterEnd = "") { + $settings = array(); + if (empty($filterStart) && empty($filterEnd)) { + $settings = array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy()); + } else { + foreach (array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy()) as $key=>$value) { + if (!empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value; + if (!empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value; } } - $fileData = $this->yellow->toolbox->readFile($fileName); - $fileData = $this->yellow->toolbox->setTextSettings($fileData, "email", $email, $settingsNew); - return $this->yellow->toolbox->createFile($fileName, $fileData); - } - - // Remove user settings from file - public function remove($fileName, $email) { - $this->modified = time(); - if (isset($this->settings[$email])) unset($this->settings[$email]); - $fileData = $this->yellow->toolbox->readFile($fileName); - $fileData = $this->yellow->toolbox->unsetTextSettings($fileData, "email", $email); - return $this->yellow->toolbox->createFile($fileName, $fileData); - } - - // Set current email - public function set($email) { - $this->email = $email; - } - - // Set user setting - public function setUser($key, $value, $email) { - if (!isset($this->settings[$email])) $this->settings[$email] = new YellowArray(); - $this->settings[$email][$key] = $value; - } - - // Return user setting - public function getUser($key, $email = "") { - if (empty($email)) $email = $this->email; - return isset($this->settings[$email]) && isset($this->settings[$email][$key]) ? $this->settings[$email][$key] : ""; - } - - // Return user setting, HTML encoded - public function getUserHtml($key, $email = "") { - return htmlspecialchars($this->getUser($key, $email)); - } - - // Return user settings - public function getSettings($email = "") { - $settings = array(); - if (empty($email)) $email = $this->email; - if (isset($this->settings[$email])) $settings = $this->settings[$email]->getArrayCopy(); return $settings; } - // Return user settings modification date, Unix time or HTTP format + // Return system settings modification date, Unix time or HTTP format public function getModified($httpFormat = false) { return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified; } - // Check if user setting exists - public function isUser($key, $email = "") { - if (empty($email)) $email = $this->email; - return isset($this->settings[$email]) && isset($this->settings[$email][$key]); - } - - // Check if user exists - public function isExisting($email) { - return isset($this->settings[$email]); + // Check if system setting exists + public function isExisting($key) { + return isset($this->settings[$key]); } } @@ -1760,30 +1670,18 @@ class YellowLanguage { $this->language = ""; } - // Load language settings from file or directory + // Load language settings from file public function load($fileName) { - if (substru($fileName, -1, 1)!="/") { - $path = dirname($fileName); - $regex = "/^".basename($fileName)."$/"; - } else { - $path = $fileName; - $regex = "/^.*\.txt$/"; - } - foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry) { - $this->modified = max($this->modified, filemtime($entry)); - $fileData = $this->yellow->toolbox->readFile($entry); - $settings = $this->yellow->toolbox->getTextSettings($fileData, "language"); - foreach ($settings as $language=>$block) { - if (!isset($this->settings[$language])) { - $this->settings[$language] = $block; - } else { - foreach ($block as $key=>$value) { - $this->settings[$language][$key] = $value; - } - } + $this->modified = $this->yellow->toolbox->getFileModified($fileName); + $fileData = $this->yellow->toolbox->readFile($fileName); + $settings = $this->yellow->toolbox->getTextSettings($fileData, "language"); + foreach ($settings as $language=>$block) { + if (!isset($this->settings[$language])) $this->settings[$language] = new YellowArray(); + foreach ($block as $key=>$value) { + $this->settings[$language][$key] = $value; } - if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowLanguage::load file:$entry<br/>\n"; } + if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowLanguage::load file:$fileName<br/>\n"; foreach ($this->settings->getArrayCopy() as $key=>$value) { if (!isset($this->settings[$key]["languageDescription"])) { unset($this->settings[$key]); @@ -1800,9 +1698,16 @@ class YellowLanguage { $this->language = $language; } - // Set default language setting - public function setDefault($key) { - $this->settingsDefaults[$key] = true; + // Set default language settings + public function setDefault($text) { + $settings = $this->yellow->toolbox->getTextSettings($text, "language"); + foreach ($settings as $language=>$block) { + if (!isset($this->settings[$language])) $this->settings[$language] = new YellowArray(); + foreach ($block as $key=>$value) { + $this->settings[$language][$key] = $value; + $this->settingsDefaults[$key] = true; + } + } } // Set language setting @@ -1923,6 +1828,99 @@ class YellowLanguage { } } +class YellowUser { + public $yellow; // access to API + public $modified; // user modification date + public $settings; // user settings + public $email; // current email + + public function __construct($yellow) { + $this->yellow = $yellow; + $this->modified = 0; + $this->settings = new YellowArray(); + $this->email = ""; + } + + // Load user settings from file + public function load($fileName) { + $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 + public function save($fileName, $email, $settings) { + $this->modified = time(); + $settingsNew = new YellowArray(); + $settingsNew["email"] = $email; + foreach ($settings as $key=>$value) { + if (!empty($key) && !strempty($value)) { + $this->setUser($key, $value, $email); + $settingsNew[$key] = $value; + } + } + $fileData = $this->yellow->toolbox->readFile($fileName); + $fileData = $this->yellow->toolbox->setTextSettings($fileData, "email", $email, $settingsNew); + return $this->yellow->toolbox->createFile($fileName, $fileData); + } + + // Remove user settings from file + public function remove($fileName, $email) { + $this->modified = time(); + if (isset($this->settings[$email])) unset($this->settings[$email]); + $fileData = $this->yellow->toolbox->readFile($fileName); + $fileData = $this->yellow->toolbox->unsetTextSettings($fileData, "email", $email); + return $this->yellow->toolbox->createFile($fileName, $fileData); + } + + // Set current email + public function set($email) { + $this->email = $email; + } + + // Set user setting + public function setUser($key, $value, $email) { + if (!isset($this->settings[$email])) $this->settings[$email] = new YellowArray(); + $this->settings[$email][$key] = $value; + } + + // Return user setting + public function getUser($key, $email = "") { + if (empty($email)) $email = $this->email; + return isset($this->settings[$email]) && isset($this->settings[$email][$key]) ? $this->settings[$email][$key] : ""; + } + + // Return user setting, HTML encoded + public function getUserHtml($key, $email = "") { + return htmlspecialchars($this->getUser($key, $email)); + } + + // Return user settings + public function getSettings($email = "") { + $settings = array(); + if (empty($email)) $email = $this->email; + if (isset($this->settings[$email])) $settings = $this->settings[$email]->getArrayCopy(); + return $settings; + } + + // Return user settings modification date, Unix time or HTTP format + public function getModified($httpFormat = false) { + return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified; + } + + // Check if user setting exists + public function isUser($key, $email = "") { + if (empty($email)) $email = $this->email; + return isset($this->settings[$email]) && isset($this->settings[$email][$key]); + } + + // Check if user exists + public function isExisting($email) { + return isset($this->settings[$email]); + } +} + class YellowExtension { public $yellow; // access to API public $modified; // extension modification date diff --git a/system/extensions/edit.php b/system/extensions/edit.php @@ -2,7 +2,7 @@ // Edit extension, https://github.com/annaesvensson/yellow-edit class YellowEdit { - const VERSION = "0.8.64"; + const VERSION = "0.8.65"; public $yellow; // access to API public $response; // web response public $merge; // text merge @@ -29,7 +29,6 @@ class YellowEdit { $this->yellow->system->setDefault("editLoginRestriction", "0"); $this->yellow->system->setDefault("editLoginSessionTimeout", "2592000"); $this->yellow->system->setDefault("editBruteForceProtection", "25"); - $this->yellow->language->setDefault("editMailFooter"); } // Handle update @@ -1242,7 +1241,7 @@ class YellowEditResponse { $data["coreExtensions"][$key] = $value["class"]; } $data["coreLanguages"] = array(); - foreach ($this->yellow->system->getValues("language") as $language) { + foreach ($this->yellow->system->getAvailable("language") as $language) { $data["coreLanguages"][$language] = $this->yellow->language->getTextHtml("languageDescription", $language); } $data["editSettingsActions"] = $this->getSettingsActions(); diff --git a/system/extensions/image.php b/system/extensions/image.php @@ -2,7 +2,7 @@ // Image extension, https://github.com/annaesvensson/yellow-image class YellowImage { - const VERSION = "0.8.16"; + const VERSION = "0.8.17"; public $yellow; // access to API // Handle initialisation @@ -12,7 +12,6 @@ class YellowImage { $this->yellow->system->setDefault("imageUploadHeightMax", "1280"); $this->yellow->system->setDefault("imageUploadJpgQuality", "80"); $this->yellow->system->setDefault("imageThumbnailJpgQuality", "80"); - $this->yellow->language->setDefault("imageDefaultAlt"); } // Handle update diff --git a/system/extensions/install-blog.bin b/system/extensions/install-blog.bin Binary files differ. diff --git a/system/extensions/install-language.bin b/system/extensions/install-language.bin Binary files differ. diff --git a/system/extensions/install-wiki.bin b/system/extensions/install-wiki.bin Binary files differ. diff --git a/system/extensions/install.php b/system/extensions/install.php @@ -2,7 +2,7 @@ // Install extension, https://github.com/annaesvensson/yellow-install class YellowInstall { - const VERSION = "0.8.80"; + const VERSION = "0.8.81"; const PRIORITY = "1"; public $yellow; // access to API @@ -134,12 +134,11 @@ class YellowInstall { $fileData = $zip->getFromName($pathBase.$this->yellow->system->get("updateExtensionFile")); foreach ($this->getExtensionsRequired($fileData) as $extension) { $fileDataPhp = $zip->getFromName($pathBase."translations/$extension/$extension.php"); - $fileDataTxt = $zip->getFromName($pathBase."translations/$extension/$extension.txt"); $fileDataIni = $zip->getFromName($pathBase."translations/$extension/extension.ini"); - $statusCode = max($statusCode, $this->updateLanguageArchive($fileDataPhp, $fileDataTxt, $fileDataIni, $pathBase, "install")); + $statusCode = max($statusCode, $this->updateLanguageArchive($fileDataPhp, $fileDataIni, $pathBase, "install")); } - $this->yellow->language->load($this->yellow->system->get("coreExtensionDirectory")); $this->yellow->extension->load($this->yellow->system->get("coreExtensionDirectory")); + $this->yellow->language->load($this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile")); $zip->close(); } else { $statusCode = 500; @@ -150,7 +149,7 @@ class YellowInstall { } // Update language archive - public function updateLanguageArchive($fileDataPhp, $fileDataTxt, $fileDataIni, $pathBase, $action) { + public function updateLanguageArchive($fileDataPhp, $fileDataIni, $pathBase, $action) { $statusCode = 200; if ($this->yellow->extension->isExisting("update")) { $settings = $this->yellow->toolbox->getTextSettings($fileDataIni, ""); @@ -158,13 +157,10 @@ class YellowInstall { $version = $settings->get("version"); $modified = strtotime($settings->get("published")); $fileNamePhp = $this->yellow->system->get("coreExtensionDirectory").$extension.".php"; - $fileNameTxt = $this->yellow->system->get("coreExtensionDirectory").$extension.".txt"; if (!empty($extension) && !empty($version) && !is_file($fileNamePhp)) { - $statusCode = $this->yellow->extension->get("update")->updateExtensionSettings($extension, $settings, $action); - if ($statusCode==200) $statusCode = $this->yellow->extension->get("update")->updateExtensionFile( - $fileNamePhp, $fileDataPhp, $modified, 0, 0, "create", $extension); - if ($statusCode==200) $statusCode = $this->yellow->extension->get("update")->updateExtensionFile( - $fileNameTxt, $fileDataTxt, $modified, 0, 0, "create", $extension); + $statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionSettings($extension, $action, $settings)); + $statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionFile( + $fileNamePhp, $fileDataPhp, $modified, 0, 0, "create", $extension)); $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'"); } } @@ -404,7 +400,7 @@ class YellowInstall { // Return raw data for install page public function getRawDataInstall() { - $languages = $this->yellow->system->getValues("language"); + $languages = $this->yellow->system->getAvailable("language"); $language = $this->yellow->toolbox->detectBrowserLanguage($languages, $this->yellow->system->get("language")); $this->yellow->language->set($language); $rawData = "---\nTitle:".$this->yellow->language->getText("installTitle")."\nLanguage:$language\nNavigation:navigation\nHeader:none\nFooter:none\nSidebar:none\n---\n"; diff --git a/system/extensions/stockholm.php b/system/extensions/stockholm.php @@ -2,7 +2,7 @@ // Stockholm extension, https://github.com/annaesvensson/yellow-stockholm class YellowStockholm { - const VERSION = "0.8.13"; + const VERSION = "0.8.14"; public $yellow; // access to API // Handle initialisation @@ -16,8 +16,7 @@ class YellowStockholm { if ($action=="install") { $this->yellow->system->save($fileName, array("theme" => "stockholm")); } elseif ($action=="uninstall" && $this->yellow->system->get("theme")=="stockholm") { - $theme = reset(array_diff($this->yellow->system->getValues("theme"), array("stockholm"))); - $this->yellow->system->save($fileName, array("theme" => $theme)); + $this->yellow->system->save($fileName, array("theme" => $this->yellow->system->getDifferent("theme"))); } } } diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini @@ -11,11 +11,11 @@ Tag: feature system/extensions/command.php: command.php, create, update Extension: Core -Version: 0.8.94 +Version: 0.8.95 Description: Core functionality of the website. DocumentationUrl: https://github.com/annaesvensson/yellow-core DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip -Published: 2022-10-19 10:46:26 +Published: 2022-10-23 22:44:50 Developer: Mark Seuffert, David Fehrmann Tag: feature system/extensions/core.php: core.php, create, update @@ -27,11 +27,11 @@ system/layouts/navigation.html: navigation.html, create, update, careful system/layouts/pagination.html: pagination.html, create, update, careful Extension: Edit -Version: 0.8.64 +Version: 0.8.65 Description: Edit your website in a web browser. DocumentationUrl: https://github.com/annaesvensson/yellow-edit DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/edit.zip -Published: 2022-10-02 18:41:45 +Published: 2022-10-20 20:50:00 Developer: Anna Svensson Tag: feature system/extensions/edit.php: edit.php, create, update @@ -42,11 +42,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.16 +Version: 0.8.17 Description: Images and thumbnails. DocumentationUrl: https://github.com/annaesvensson/yellow-image DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/image.zip -Published: 2022-04-19 17:02:35 +Published: 2022-10-20 20:50:25 Developer: Anna Svensson Tag: feature system/extensions/image.php: image.php, create, update @@ -54,11 +54,11 @@ media/images/photo.jpg: photo.jpg, create, optional media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional Extension: Install -Version: 0.8.80 +Version: 0.8.81 Description: Install a brand new, shiny website. DocumentationUrl: https://github.com/annaesvensson/yellow-install DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/install.zip -Published: 2022-10-18 21:28:48 +Published: 2022-10-20 13:37:18 Developer: Anna Svensson Status: unlisted system/extensions/install.php: install.php, create @@ -106,11 +106,11 @@ Tag: feature system/extensions/serve.php: serve.php, create, update Extension: Stockholm -Version: 0.8.13 +Version: 0.8.14 Description: Stockholm is a clean theme. DocumentationUrl: https://github.com/annaesvensson/yellow-stockholm DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/stockholm.zip -Published: 2022-06-15 16:03:38 +Published: 2022-10-20 12:44:02 Designer: Anna Svensson Tag: theme system/extensions/stockholm.php: stockholm.php, create, update @@ -121,11 +121,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.84 +Version: 0.8.85 Description: Keep your website up to date. DocumentationUrl: https://github.com/annaesvensson/yellow-update DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/update.zip -Published: 2022-10-14 10:56:05 +Published: 2022-10-23 21:06:48 Developer: Anna Svensson 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/annaesvensson/yellow-update class YellowUpdate { - const VERSION = "0.8.84"; + const VERSION = "0.8.85"; const PRIORITY = "2"; public $yellow; // access to API public $extensions; // number of extensions @@ -278,35 +278,32 @@ class YellowUpdate { $settings = $this->yellow->toolbox->getTextSettings($fileData, ""); list($extension, $version, $newModified, $oldModified) = $this->getExtensionInformation($settings); if (!empty($extension) && !empty($version)) { - $statusCode = $this->updateExtensionSettings($extension, $settings, $action); - if ($statusCode==200) { - $paths = $this->getExtensionDirectories($zip, $pathBase); - foreach ($this->getExtensionFileNames($settings) as $fileName) { - list($entry, $flags) = $this->yellow->toolbox->getTextList($settings[$fileName], ",", 2); - if (!$this->yellow->lookup->isContentFile($fileName)) { - if (preg_match("/^@base/i", $entry)) { - $fileNameSource = preg_replace("/@base/i", rtrim($pathBase, "/"), $entry); - } else { - $fileNameSource = $pathBase.$entry; - } - $fileData = $zip->getFromName($fileNameSource); - $lastModified = $this->yellow->toolbox->getFileModified($fileName); - $statusCode = $this->updateExtensionFile($fileName, $fileData, - $newModified, $oldModified, $lastModified, $flags, $extension); + $statusCode = max($statusCode, $this->updateExtensionSettings($extension, $action, $settings)); + $paths = $this->getExtensionDirectories($zip, $pathBase); + foreach ($this->getExtensionFileNames($settings) as $fileName) { + list($entry, $flags) = $this->yellow->toolbox->getTextList($settings[$fileName], ",", 2); + if (!$this->yellow->lookup->isContentFile($fileName)) { + if (preg_match("/^@base/i", $entry)) { + $fileNameSource = preg_replace("/@base/i", rtrim($pathBase, "/"), $entry); } else { - foreach ($this->getExtensionContentRootPages() as $page) { - list($fileNameSource, $fileNameDestination) = $this->getExtensionContentFileNames( - $fileName, $pathBase, $entry, $flags, $paths, $page); - $fileData = $zip->getFromName($fileNameSource); - $lastModified = $this->yellow->toolbox->getFileModified($fileNameDestination); - $statusCode = $this->updateExtensionFile($fileNameDestination, $fileData, - $newModified, $oldModified, $lastModified, $flags, $extension); - } + $fileNameSource = $pathBase.$entry; + } + $fileData = $zip->getFromName($fileNameSource); + $lastModified = $this->yellow->toolbox->getFileModified($fileName); + $statusCode = max($statusCode, $this->updateExtensionFile($fileName, $fileData, + $newModified, $oldModified, $lastModified, $flags, $extension)); + } else { + foreach ($this->getExtensionContentRootPages() as $page) { + list($fileNameSource, $fileNameDestination) = $this->getExtensionContentFileNames( + $fileName, $pathBase, $entry, $flags, $paths, $page); + $fileData = $zip->getFromName($fileNameSource); + $lastModified = $this->yellow->toolbox->getFileModified($fileNameDestination); + $statusCode = max($statusCode, $this->updateExtensionFile($fileNameDestination, $fileData, + $newModified, $oldModified, $lastModified, $flags, $extension)); } - if ($statusCode!=200) break; } - $statusCode = max($statusCode, $this->updateExtensionNotification($extension, $action)); } + $statusCode = max($statusCode, $this->updateExtensionNotification($extension, $action)); $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'"); ++$this->extensions; } else { @@ -387,20 +384,30 @@ class YellowUpdate { // Update pending events public function updateEventPending() { if ($this->yellow->system->get("updateCurrentRelease")!="none") { + if ($this->yellow->system->get("updateCurrentRelease")!=YellowCore::RELEASE) { + $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile"); + if (!$this->yellow->system->save($fileName, array("updateCurrentRelease" => YellowCore::RELEASE))) { + $this->yellow->log("error", "Can't write file '$fileName'!"); + } else { + list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation(); + $product = "Datenstrom Yellow ".YellowCore::RELEASE; + $this->yellow->log("info", "Update $product, PHP ".PHP_VERSION.", $name $version, $os"); + } + } if ($this->yellow->system->get("updateEventPending")!="none") { foreach (explode(",", $this->yellow->system->get("updateEventPending")) as $token) { list($extension, $action) = $this->yellow->toolbox->getTextList($token, "/", 2); - if ($this->yellow->extension->isExisting($extension) && ($action!="ready" && $action!="uninstall")) { + if ($this->yellow->extension->isExisting($extension) && $action!="uninstall") { $value = $this->yellow->extension->data[$extension]; if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate($action); } } + $this->updateSystemSettings("all", $action); + $this->updateLanguageSettings("all", $action); $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile"); if (!$this->yellow->system->save($fileName, array("updateEventPending" => "none"))) { $this->yellow->log("error", "Can't write file '$fileName'!"); } - $this->updateSystemSettings(); - $this->updateLanguageSettings(); } if ($this->yellow->system->get("updateEventDaily")<=time()) { foreach ($this->yellow->extension->data as $key=>$value) { @@ -431,93 +438,11 @@ class YellowUpdate { return $statusCode; } - // Update system settings - public function updateSystemSettings() { - $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile"); - $fileData = $this->yellow->toolbox->readFile($fileName); - $fileDataStart = $fileDataSettings = $fileDataComments = ""; - $settings = new YellowArray(); - $settings->exchangeArray($this->yellow->system->settingsDefaults->getArrayCopy()); - foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { - preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); - if (empty($fileDataStart) && preg_match("/^\#/", $line)) { - $fileDataStart = $line; - } elseif (!empty($matches[1]) && isset($settings[$matches[1]])) { - $settings[$matches[1]] = $matches[2]; - } elseif (!empty($matches[1]) && substru($matches[1], 0, 1)!="#") { - $fileDataComments .= "# $line"; - } elseif (!empty($matches[1])) { - $fileDataComments .= $line; - } - } - foreach ($settings as $key=>$value) { - $fileDataSettings .= ucfirst($key).(strempty($value) ? ":\n" : ": $value\n"); - } - if (!empty($fileDataStart)) $fileDataStart .= "\n"; - if (!empty($fileDataComments)) $fileDataSettings .= "\n"; - $fileDataNew = $fileDataStart.$fileDataSettings.$fileDataComments; - if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) { - $this->yellow->log("error", "Can't write file '$fileName'!"); - } - if ($this->yellow->system->get("updateCurrentRelease")!=YellowCore::RELEASE) { - if (!$this->yellow->system->save($fileName, array("updateCurrentRelease" => YellowCore::RELEASE))) { - $this->yellow->log("error", "Can't write file '$fileName'!"); - } else { - list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation(); - $product = "Datenstrom Yellow ".YellowCore::RELEASE; - $this->yellow->log("info", "Update $product, PHP ".PHP_VERSION.", $name $version, $os"); - } - } - } - - // Update language settings - public function updateLanguageSettings() { - $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile"); - $fileData = $this->yellow->toolbox->readFile($fileName); - $fileDataStart = $fileDataSettings = $language = ""; - $settings = new YellowArray(); - foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { - preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); - if (empty($fileDataStart) && preg_match("/^\#/", $line)) { - $fileDataStart = $line; - } elseif (!empty($matches[1]) && !empty($matches[2])) { - if (lcfirst($matches[1])=="language" && !strempty($matches[2])) { - if (!empty($settings)) { - if (!empty($fileDataSettings)) $fileDataSettings .= "\n"; - foreach ($settings as $key=>$value) { - $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n"; - } - } - $language = $matches[2]; - $settings = new YellowArray(); - $settings["language"] = $language; - foreach ($this->yellow->language->settingsDefaults as $key=>$value) { - if ($this->yellow->language->isText($key, $language)) { - $settings[$key] = $this->yellow->language->getText($key, $language); - } - } - } - if (!empty($language)) { - $settings[$matches[1]] = $matches[2]; - } - } - } - if (!empty($fileDataStart)) $fileDataStart .= "\n"; - if (!empty($fileDataSettings)) $fileDataSettings .= "\n"; - foreach ($settings as $key=>$value) { - $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n"; - } - $fileDataNew = $fileDataStart.$fileDataSettings; - if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) { - $this->yellow->log("error", "Can't write file '$fileName'!"); - } - } - // Update extension settings - public function updateExtensionSettings($extension, $settings, $action) { + public function updateExtensionSettings($extension, $action, $settings) { $statusCode = 200; $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("updateCurrentFile"); - $fileData = $this->yellow->toolbox->readFile($fileName); + $fileData = $fileDataNew = $this->yellow->toolbox->readFile($fileName); if ($action=="install" || $action=="update") { $settingsCurrent = $this->yellow->toolbox->getTextSettings($fileData, "extension"); $settingsCurrent[$extension] = new YellowArray(); @@ -534,7 +459,7 @@ class YellowUpdate { $fileDataNew .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n"; } } - } else { + } elseif ($action=="uninstall") { $fileDataNew = $this->yellow->toolbox->unsetTextSettings($fileData, "extension", $extension); } if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) { @@ -544,6 +469,107 @@ class YellowUpdate { return $statusCode; } + // Update system settings + public function updateSystemSettings($extension, $action) { + $statusCode = 200; + $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile"); + $fileData = $fileDataNew = $this->yellow->toolbox->readFile($fileName); + if ($action=="install" || $action=="update") { + $fileDataStart = $fileDataSettings = ""; + $settings = new YellowArray(); + $settings->exchangeArray($this->yellow->system->settingsDefaults->getArrayCopy()); + foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { + preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); + if (empty($fileDataStart) && preg_match("/^\#/", $line)) { + $fileDataStart = $line."\n"; + } elseif (!empty($matches[1]) && !strempty($matches[2])) { + $settings[$matches[1]] = $matches[2]; + } + } + foreach ($settings as $key=>$value) { + $fileDataSettings .= ucfirst($key).(strempty($value) ? ":\n" : ": $value\n"); + } + $fileDataNew = $fileDataStart.$fileDataSettings; + } elseif ($action=="uninstall") { + if (!empty($extension)) { + $fileDataNew = ""; + $regex = "/^".ucfirst($extension)."[A-Z]+/"; + foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { + preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); + if (!empty($matches[1]) && preg_match($regex, $matches[1])) continue; + $fileDataNew .= $line; + } + } + } + if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) { + $statusCode = 500; + $this->yellow->page->error($statusCode, "Can't write file '$fileName'!"); + } + return $statusCode; + } + + // Update language settings + public function updateLanguageSettings($extension, $action) { + $statusCode = 200; + $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile"); + $fileData = $fileDataNew = $this->yellow->toolbox->readFile($fileName); + if ($action=="install" || $action=="update") { + $fileDataStart = $fileDataSettings = $language = ""; + $settings = new YellowArray(); + foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { + preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); + if (empty($fileDataStart) && preg_match("/^\#/", $line)) { + $fileDataStart = $line."\n"; + } elseif (!empty($matches[1]) && !strempty($matches[2])) { + if (lcfirst($matches[1])=="language") { + if (!empty($settings)) { + if (!empty($fileDataSettings)) $fileDataSettings .= "\n"; + foreach ($settings as $key=>$value) { + $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n"; + } + } + $language = $matches[2]; + $settings = new YellowArray(); + $settings["language"] = $language; + foreach ($this->yellow->language->settingsDefaults as $key=>$value) { + $require = preg_match("/^([a-z]*)[A-Z]+/", $key, $tokens) ? $tokens[1] : "core"; + if ($require=="language") $require = "core"; + if ($this->yellow->extension->isExisting($require) && + $this->yellow->language->isText($key, $language)) { + $settings[$key] = $this->yellow->language->getText($key, $language); + } + } + } + if (!empty($language)) { + $settings[$matches[1]] = $matches[2]; + } + } + } + if (!empty($settings)) { + if (!empty($fileDataSettings)) $fileDataSettings .= "\n"; + foreach ($settings as $key=>$value) { + $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n"; + } + } + $fileDataNew = $fileDataStart.$fileDataSettings; + } elseif ($action=="uninstall") { + if (!empty($extension) && ucfirst($extension)!="Language") { + $fileDataNew = ""; + $regex = "/^".ucfirst($extension)."[A-Z]+/"; + foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) { + preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches); + if (!empty($matches[1]) && preg_match($regex, $matches[1])) continue; + $fileDataNew .= $line; + } + } + } + if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) { + $statusCode = 500; + $this->yellow->page->error($statusCode, "Can't write file '$fileName'!"); + } + return $statusCode; + } + // Update extension notification public function updateExtensionNotification($extension, $action) { $statusCode = 200; @@ -568,13 +594,13 @@ class YellowUpdate { $statusCode = 200; if (function_exists("opcache_reset")) opcache_reset(); foreach ($settings as $extension=>$block) { - $statusCode = max($statusCode, $this->removeExtensionArchive($extension, $block, "uninstall")); + $statusCode = max($statusCode, $this->removeExtensionArchive($extension, "uninstall", $block)); } return $statusCode; } // Remove extension archive - public function removeExtensionArchive($extension, $settings, $action) { + public function removeExtensionArchive($extension, $action, $settings) { $statusCode = 200; $fileNames = $this->getExtensionFileNames($settings, true); if (count($fileNames)) { @@ -582,7 +608,11 @@ class YellowUpdate { foreach ($fileNames as $fileName) { $statusCode = max($statusCode, $this->removeExtensionFile($fileName)); } - if ($statusCode==200) $statusCode = $this->updateExtensionSettings($extension, $settings, $action); + if ($statusCode==200) { + $statusCode = max($statusCode, $this->updateExtensionSettings($extension, $action, $settings)); + $statusCode = max($statusCode, $this->updateSystemSettings($extension, $action)); + $statusCode = max($statusCode, $this->updateLanguageSettings($extension, $action)); + } $version = $settings->get("version"); $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'"); ++$this->extensions;