mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 05:37:32 +02:00
Closes #4619 - strftime() shim with intl locale support by @Deltik
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* e107 website system
|
* e107 website system
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||||
* Released under the terms and conditions of the
|
* Released under the terms and conditions of the
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
*
|
*
|
||||||
* Shims for PHP internal functions
|
* Shims for PHP internal functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace e107\Shims;
|
namespace e107\Shims;
|
||||||
|
|
||||||
trait InternalShimsTrait
|
trait InternalShimsTrait
|
||||||
{
|
{
|
||||||
use Internal\GetParentClassTrait;
|
use Internal\GetParentClassTrait;
|
||||||
use Internal\ReadfileTrait;
|
use Internal\ReadfileTrait;
|
||||||
use Internal\StrptimeTrait;
|
use Internal\StrftimeTrait;
|
||||||
|
use Internal\StrptimeTrait;
|
||||||
}
|
}
|
@@ -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 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()}.
|
* @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)
|
public static function strftime($format, $timestamp = null)
|
||||||
{
|
{
|
||||||
if ($timestamp === null) $timestamp = time();
|
return eShims::strftime($format, $timestamp);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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'])
|
|| 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
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user