From de25bdc898f32f04748b55fd265a6ab5fb7fa998 Mon Sep 17 00:00:00 2001 From: Cameron <e107inc@gmail.com> Date: Thu, 25 Nov 2021 07:36:07 -0800 Subject: [PATCH] Closes #4619 - strftime() shim with intl locale support by @Deltik --- e107_handlers/Shims/InternalShimsTrait.php | 37 +++++----- e107_handlers/date_handler.php | 82 +--------------------- e107_handlers/sitelinks_class.php | 2 +- 3 files changed, 23 insertions(+), 98 deletions(-) diff --git a/e107_handlers/Shims/InternalShimsTrait.php b/e107_handlers/Shims/InternalShimsTrait.php index 38ede917c..308a890fc 100644 --- a/e107_handlers/Shims/InternalShimsTrait.php +++ b/e107_handlers/Shims/InternalShimsTrait.php @@ -1,19 +1,20 @@ -<?php -/** - * e107 website system - * - * Copyright (C) 2008-2020 e107 Inc (e107.org) - * Released under the terms and conditions of the - * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) - * - * Shims for PHP internal functions - */ - -namespace e107\Shims; - -trait InternalShimsTrait -{ - use Internal\GetParentClassTrait; - use Internal\ReadfileTrait; - use Internal\StrptimeTrait; +<?php +/** + * e107 website system + * + * Copyright (C) 2008-2020 e107 Inc (e107.org) + * Released under the terms and conditions of the + * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) + * + * Shims for PHP internal functions + */ + +namespace e107\Shims; + +trait InternalShimsTrait +{ + use Internal\GetParentClassTrait; + use Internal\ReadfileTrait; + use Internal\StrftimeTrait; + use Internal\StrptimeTrait; } \ No newline at end of file diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index dbf549b9d..e81b876ae 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -207,9 +207,9 @@ class e_date } /** - * Polyfill for {@see strftime()}, which was deprecated in PHP 8.1 + * Alias of {@see eShims::strftime()} * - * The implementation is an approximation that may be wrong for some obscure formatting characters. + * See {@see eShims::strftime()} for more information. * * @param string $format The old {@see strftime()} format string * @param int|null $timestamp A Unix epoch timestamp. If null, defaults to the value of {@see time()}. @@ -217,83 +217,7 @@ class e_date */ public static function strftime($format, $timestamp = null) { - if ($timestamp === null) $timestamp = time(); - $datetime = date_create("@$timestamp"); - $datetime->setTimezone(new DateTimeZone(date_default_timezone_get())); - - $formatMap = [ - '%a' => 'D', - '%A' => 'l', - '%d' => 'd', - '%e' => function($datetime) - { - return str_pad(date_format($datetime, 'n'), 2, " ", STR_PAD_LEFT); - }, - '%j' => function($datetime) - { - return str_pad(date_format($datetime, 'z'), 3, "0", STR_PAD_LEFT); - }, - '%u' => 'N', - '%w' => 'w', - '%U' => 'W', - '%V' => 'W', - '%W' => 'W', - '%b' => 'M', - '%B' => 'F', - '%h' => 'M', - '%m' => 'm', - '%C' => function($datetime) - { - return (string) ((int) date_format($datetime, 'Y') / 100); - }, - '%g' => 'y', - '%G' => 'Y', - '%y' => 'y', - '%Y' => 'Y', - '%H' => 'H', - '%k' => function($datetime) - { - return str_pad(date_format($datetime, 'G'), 2, " ", STR_PAD_LEFT); - }, - '%I' => 'h', - '%l' => function($datetime) - { - return str_pad(date_format($datetime, 'g'), 2, " ", STR_PAD_LEFT); - }, - '%M' => 'i', - '%p' => 'A', - '%P' => 'a', - '%r' => 'h:i:s A', - '%R' => 'H:i', - '%S' => 's', - '%T' => 'H:i:s', - '%X' => 'H:i:s', - '%z' => 'O', - '%Z' => 'T', - '%c' => 'r', - '%D' => 'm/d/y', - '%F' => 'Y-m-d', - '%s' => 'U', - '%x' => 'Y-m-d', - '%n' => "\n", - '%t' => "\t", - '%%' => '\%', - ]; - - foreach ($formatMap as $strftime_key => $date_format_key) - { - if (is_callable($date_format_key)) - { - $replacement = chunk_split($date_format_key($datetime), 1, "\\"); - } - else - { - $replacement = $date_format_key; - } - $format = str_replace($strftime_key, $replacement, $format); - } - - return date_format($datetime, $format); + return eShims::strftime($format, $timestamp); } /** diff --git a/e107_handlers/sitelinks_class.php b/e107_handlers/sitelinks_class.php index 7069bcdc7..e0bb0fd5b 100644 --- a/e107_handlers/sitelinks_class.php +++ b/e107_handlers/sitelinks_class.php @@ -1338,7 +1338,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; } || e_REQUEST_HTTP === varset($e107_vars[$act]['link']) ) { - $temp = varset($tmpl['button_active'.$kpost]); + $temp = isset($tmpl['button_active' . $kpost]) ? $tmpl['button_active' . $kpost] : ''; } else {