mikuli.cz

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

commit 8bbb46ddda8a8c62bac4bdf1f1b063a288046daa
parent 8dc1d2961fa850b2cc43753be72eaca8e995deda
Author: markseu <mark2011@mayberg.se>
Date:   Thu, 26 Oct 2023 16:42:18 +0200

Updated API

Diffstat:
Msystem/extensions/core.php | 104++++++++++++++++++++++++++++++++++----------------------------------------------
Msystem/extensions/install-blog.bin | 0
Msystem/extensions/install-wiki.bin | 0
Msystem/extensions/update-current.ini | 4++--
4 files changed, 46 insertions(+), 62 deletions(-)

diff --git a/system/extensions/core.php b/system/extensions/core.php @@ -2,7 +2,7 @@ // Core extension, https://github.com/annaesvensson/yellow-core class YellowCore { - const VERSION = "0.8.123"; + const VERSION = "0.8.124"; const RELEASE = "0.8.23"; public $content; // content files public $media; // media files @@ -857,28 +857,24 @@ class YellowLanguage { return htmlspecialchars($this->getText($key, $language)); } - // Return human readable date - public function getDateFormatted($timestamp, $format, $language = "") { - $dateMonthsNominative = preg_split("/\s*,\s*/", $this->getText("coreDateMonthsNominative", $language)); - $dateMonthsGenitive = preg_split("/\s*,\s*/", $this->getText("coreDateMonthsGenitive", $language)); - $dateWeekdays = preg_split("/\s*,\s*/", $this->getText("coreDateWeekdays", $language)); - $monthNominative = $dateMonthsNominative[date("n", $timestamp) - 1]; - $monthGenitive = $dateMonthsGenitive[date("n", $timestamp) - 1]; - $weekday = $dateWeekdays[date("N", $timestamp) - 1]; - $timeZone = $this->yellow->system->get("coreTimezone"); - $timeZoneHelper = new DateTime("now", new DateTimeZone($timeZone)); - $timeZoneOffset = $timeZoneHelper->getOffset(); - $timeZoneAbbreviation = "GMT".($timeZoneOffset<0 ? "-" : "+").abs(intval($timeZoneOffset/3600)); - $format = preg_replace("/(?<!\\\)F/", addcslashes($monthNominative, "A..Za..z"), $format); - $format = preg_replace("/(?<!\\\)V/", addcslashes($monthGenitive, "A..Za..z"), $format); - $format = preg_replace("/(?<!\\\)M/", addcslashes(substru($monthNominative, 0, 3), "A..Za..z"), $format); - $format = preg_replace("/(?<!\\\)D/", addcslashes(substru($weekday, 0, 3), "A..Za..z"), $format); - $format = preg_replace("/(?<!\\\)l/", addcslashes($weekday, "A..Za..z"), $format); - $format = preg_replace("/(?<!\\\)T/", addcslashes($timeZoneAbbreviation, "A..Za..z"), $format); - return date($format, $timestamp); + // Return text as language specific date, convert to one of the standard formats + public function getDateStandard($text, $language = "") { + if (preg_match("/^\d+$/", $text)) { + $output = $text; + } elseif (preg_match("/^\d+\-\d+$/", $text)) { + $format = $this->getText("coreDateFormatShort", $language); + $output = $this->getDateFormatted(strtotime($text), $format, $language); + } elseif (preg_match("/^\d+\-\d+\-\d+$/", $text)) { + $format = $this->getText("coreDateFormatMedium", $language); + $output = $this->getDateFormatted(strtotime($text), $format, $language); + } else { + $format = $this->getText("coreDateFormatLong", $language); + $output = $this->getDateFormatted(strtotime($text), $format, $language); + } + return $output; } - // Return human readable date, relative to today + // Return timestamp as date, relative to today public function getDateRelative($timestamp, $format, $daysLimit, $language = "") { $timeDifference = time() - $timestamp; $days = abs(intval($timeDifference/86400)); @@ -910,6 +906,27 @@ class YellowLanguage { return $output; } + // Return timestamp as date + public function getDateFormatted($timestamp, $format, $language = "") { + $dateMonthsNominative = preg_split("/\s*,\s*/", $this->getText("coreDateMonthsNominative", $language)); + $dateMonthsGenitive = preg_split("/\s*,\s*/", $this->getText("coreDateMonthsGenitive", $language)); + $dateWeekdays = preg_split("/\s*,\s*/", $this->getText("coreDateWeekdays", $language)); + $monthNominative = $dateMonthsNominative[date("n", $timestamp) - 1]; + $monthGenitive = $dateMonthsGenitive[date("n", $timestamp) - 1]; + $weekday = $dateWeekdays[date("N", $timestamp) - 1]; + $timeZone = $this->yellow->system->get("coreTimezone"); + $timeZoneHelper = new DateTime("now", new DateTimeZone($timeZone)); + $timeZoneOffset = $timeZoneHelper->getOffset(); + $timeZoneAbbreviation = "GMT".($timeZoneOffset<0 ? "-" : "+").abs(intval($timeZoneOffset/3600)); + $format = preg_replace("/(?<!\\\)F/", addcslashes($monthNominative, "A..Za..z"), $format); + $format = preg_replace("/(?<!\\\)V/", addcslashes($monthGenitive, "A..Za..z"), $format); + $format = preg_replace("/(?<!\\\)M/", addcslashes(substru($monthNominative, 0, 3), "A..Za..z"), $format); + $format = preg_replace("/(?<!\\\)D/", addcslashes(substru($weekday, 0, 3), "A..Za..z"), $format); + $format = preg_replace("/(?<!\\\)l/", addcslashes($weekday, "A..Za..z"), $format); + $format = preg_replace("/(?<!\\\)T/", addcslashes($timeZoneAbbreviation, "A..Za..z"), $format); + return date($format, $timestamp); + } + // Return language settings public function getSettings($filterStart = "", $filterEnd = "", $language = "") { $settings = array(); @@ -1488,41 +1505,6 @@ class YellowLookup { return $output; } - // Normalise array, make keys with same upper/lower case - public function normaliseArray($input) { - $array = array(); - foreach ($input as $key=>$value) { - if (is_string_empty($key) || is_string_empty($value)) continue; - $keySearch = strtoloweru($key); - foreach ($array as $keyFound=>$valueFound) { - if (strtoloweru($keyFound)==$keySearch) { - $key = $keyFound; - break; - } - } - if (!isset($array[$key])) $array[$key] = 0; - $array[$key] += $value; - } - return $array; - } - - // Normalise date, make language specific short/medium/long format - public function normaliseDate($text, $language = "") { - if (preg_match("/^\d+\-\d+$/", $text)) { - $format = $this->yellow->language->getText("coreDateFormatShort", $language); - $output = $this->yellow->language->getDateFormatted(strtotime($text), $format, $language); - } elseif (preg_match("/^\d+\-\d+\-\d+$/", $text)) { - $format = $this->yellow->language->getText("coreDateFormatMedium", $language); - $output = $this->yellow->language->getDateFormatted(strtotime($text), $format, $language); - } elseif (preg_match("/^\d+\-\d+\-\d+ \d+\:\d+$/", $text)) { - $format = $this->yellow->language->getText("coreDateFormatLong", $language); - $output = $this->yellow->language->getDateFormatted(strtotime($text), $format, $language); - } else { - $output = $text; - } - return $output; - } - // Normalise relative path tokens public function normalisePath($text) { $textFiltered = ""; @@ -2917,7 +2899,6 @@ class YellowToolbox { } // TODO: remove later, for backwards compatibility - public function normaliseUpperLower($input) { return $this->yellow->lookup->normaliseArray($input); } public function normaliseArguments($text, $appendSlash = true, $filterStrict = true) { return $this->yellow->lookup->normaliseArguments($text, $appendSlash, $filterStrict); } public function normalisePath($text) { return $this->yellow->lookup->normalisePath($text); } } @@ -3610,12 +3591,15 @@ class YellowPageCollection extends ArrayObject { // Group page collection by page setting, return array with multiple collections public function group($key, $ascendingOrder = true, $format = ""): array { $array = array(); - $groupByDate = !is_string_empty($format) && $format!="count"; + $groupByInitial = $format=="initial"; + $groupByDate = !is_string_empty($format) && $format!="count" && $format!="initial"; foreach ($this->getIterator() as $page) { if ($page->isExisting($key)) { foreach (preg_split("/\s*,\s*/", $page->get($key)) as $group) { - if ($groupByDate) { - $group = $this->yellow->language->getDateFormatted(strtotime($group), $format); + if ($groupByInitial) { + $group = strtoupperu(substru($group, 0, 1)); + } elseif ($groupByDate) { + $group = $this->yellow->language->getDateFormatted(strtotime($group), $format); } if (!is_string_empty($group)) { if (!isset($array[$group])) { diff --git a/system/extensions/install-blog.bin b/system/extensions/install-blog.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/update-current.ini b/system/extensions/update-current.ini @@ -1,11 +1,11 @@ # Datenstrom Yellow update settings Extension: Core -Version: 0.8.123 +Version: 0.8.124 Description: Core functionality of your website. DocumentationUrl: https://github.com/annaesvensson/yellow-core DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip -Published: 2023-10-24 10:16:57 +Published: 2023-10-26 16:26:57 Developer: Anna Svensson Tag: feature system/extensions/core.php: core.php, create, update