1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-18 03:31:54 +02:00

Closes #4619 - strftime() shim with intl locale support by @Deltik

This commit is contained in:
Cameron 2021-11-25 07:36:07 -08:00
parent 68c3b0649c
commit de25bdc898
3 changed files with 23 additions and 98 deletions

View File

@ -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;
}

View File

@ -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);
}
/**

View File

@ -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
{