Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+96 -30
View File
@@ -11,7 +11,7 @@
namespace IPS;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -36,7 +36,7 @@ class _DateTime extends \DateTime
if ( !$bypassTimezone AND \IPS\Dispatcher::hasInstance() and \IPS\Member::loggedIn()->timezone )
{
$validTimezone = TRUE;
if( in_array( \IPS\Member::loggedIn()->timezone, static::getTimezoneIdentifiers() ) )
if( \in_array( \IPS\Member::loggedIn()->timezone, static::getTimezoneIdentifiers() ) )
{
try
{
@@ -138,7 +138,7 @@ class _DateTime extends \DateTime
}
/* If we don't have anything but seconds, return "less than a minute ago" */
if( !count($format) )
if( !\count($format) )
{
if( $diff->s !== 0 )
{
@@ -181,14 +181,15 @@ class _DateTime extends \DateTime
*/
public function __toString()
{
return (string) \IPS\Member::loggedIn()->language()->convertString( strftime( '%x ' . static::localeTimeFormat(), $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ) );
return (string) static::strftime( '%x ' . static::localeTimeFormat(), $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), \IPS\Member::loggedIn()->language() );
}
/**
* Get HTML output
*
* @param bool $capitalize TRUE if by itself, FALSE if in the middle of a sentence
* @param \IPS\Lang|\IPS\Member|NULL $memberOrLanguage The language or member to use, or NULL for currently logged in member
* @param bool $capitalize TRUE if by itself, FALSE if in the middle of a sentence
* @param bool $short Whether or not to use the short form
* @param \IPS\Lang|\IPS\Member|NULL $memberOrLanguage The language or member to use, or NULL for currently logged in member
* @return string
*/
public function html( $capitalize=TRUE, $short=FALSE, $memberOrLanguage=NULL )
@@ -206,7 +207,7 @@ class _DateTime extends \DateTime
*/
public function localeDate( $memberOrLanguage=NULL )
{
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( '%x', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ) );
return static::strftime( '%x', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), static::determineLanguage( $memberOrLanguage ) );
}
/**
@@ -217,13 +218,35 @@ class _DateTime extends \DateTime
*/
public function dayAndMonth( $memberOrLanguage=NULL )
{
return static::determineLanguage( $memberOrLanguage )->addToStack(
$language = static::determineLanguage( $memberOrLanguage );
return $language->addToStack(
'_date_day_and_month',
FALSE,
array(
'pluralize' => array(
strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
static::strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
static::strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
)
)
);
}
/**
* Format the date to return short month and day without a year
*
* @param \IPS\Lang|\IPS\Member|NULL $memberOrLanguage The language or member to use, or NULL for currently logged in member
* @return string
*/
public function dayAndShortMonth( $memberOrLanguage=NULL )
{
$language = static::determineLanguage( $memberOrLanguage );
return $language->addToStack(
'_date_this_year_short',
FALSE,
array(
'pluralize' => array(
static::strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
static::strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
)
)
);
@@ -237,14 +260,15 @@ class _DateTime extends \DateTime
*/
public function fullYearLocaleDate( $memberOrLanguage=NULL )
{
$timeStamp = $this->getTimestamp() + $this->getTimezone()->getOffset( $this );
$dateString = strftime( '%x', $timeStamp );
$twoDigitYear = strftime( '%y', $timeStamp );
$fourDigitYear = strftime( '%Y', $timeStamp );
$language = static::determineLanguage( $memberOrLanguage );
$timestamp = $this->getTimestamp() + $this->getTimezone()->getOffset( $this );
$dateString = static::strftime( '%x', $timestamp, $language );
$twoDigitYear = static::strftime( '%y', $timestamp, $language );
$fourDigitYear = static::strftime( '%Y', $timestamp, $language );
$dateString = preg_replace_callback( "/(\s|\/|,|-){$twoDigitYear}$/", function( $matches ) use ( $fourDigitYear ) {
return $matches[1] . $fourDigitYear;
}, $dateString );
return static::determineLanguage( $memberOrLanguage )->convertString( $dateString );
return $language->convertString( $dateString );
}
/**
@@ -261,7 +285,7 @@ class _DateTime extends \DateTime
*/
public static function localeTimeFormat( $seconds=FALSE, $minutes=TRUE, $memberOrLanguage=NULL )
{
if ( in_array( preg_replace( '/\.UTF-?8$/', '', static::determineLanguage( $memberOrLanguage )->short ), array(
if ( \in_array( preg_replace( '/\.UTF-?8$/', '', static::determineLanguage( $memberOrLanguage )->short ), array(
'sq_AL', // Albanian - Albania
'zh_SG', 'sgp', 'singapore', // Chinese - Singapore
'zh_TW', 'twn', 'taiwan', // Chinese - Taiwan
@@ -301,12 +325,23 @@ class _DateTime extends \DateTime
*/
public function localeTime( $seconds=TRUE, $minutes=TRUE, $memberOrLanguage=NULL )
{
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( static::localeTimeFormat( $seconds, $minutes, $memberOrLanguage ), $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ) );
return static::strftime( static::localeTimeFormat( $seconds, $minutes, $memberOrLanguage ), $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), static::determineLanguage( $memberOrLanguage ) );
}
const RELATIVE_FORMAT_NORMAL = 0; // Yesterday at 2pm
const RELATIVE_FORMAT_LOWER = 2; // yesterday at 2pm (e.g. "Edited yesterday at 2pm")
const RELATIVE_FORMAT_SHORT = 1; // 1dy (for mobile view)
/**
* @brief Normal relative format: Yesterday at 2pm
*/
const RELATIVE_FORMAT_NORMAL = 0;
/**
* @brief Lowercase relative format: yesterday at 2pm
*/
const RELATIVE_FORMAT_LOWER = 2;
/**
* @brief Short relative format: 1dy (for mobile view)
*/
const RELATIVE_FORMAT_SHORT = 1;
/**
* Format the date relative to the current date/time
@@ -337,8 +372,8 @@ class _DateTime extends \DateTime
FALSE,
array(
'pluralize' => array(
strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) )
static::strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
static::strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
)
)
);
@@ -356,8 +391,8 @@ class _DateTime extends \DateTime
FALSE,
array(
'pluralize' => array(
strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) )
static::strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
static::strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
)
)
);
@@ -380,7 +415,18 @@ class _DateTime extends \DateTime
/* Other: "Wednesday at 23:56" */
else
{
return $language->addToStack( "_date_this_week{$capitalKey}", FALSE, array( 'sprintf' => array( $this->strFormat( '%A', $language ), $this->localeTime( FALSE, TRUE, $language ) ) ) );
return $language->addToStack(
"_date_this_week{$capitalKey}",
FALSE,
array(
'sprintf' => array(
$this->localeTime( FALSE, TRUE, $language )
),
'pluralize' => array(
$this->strFormat( '%w', $language ),
)
)
);
}
}
/* Less than a day but more than an hour ago */
@@ -431,11 +477,11 @@ class _DateTime extends \DateTime
FALSE,
array(
'sprintf' => array(
strftime( '%Y', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) )
static::strftime( '%Y', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
),
'pluralize' => array(
strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ),
static::strftime( ( strftime( '%d' ) !== FALSE ) ? '%d' : '%e', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
static::strftime( '%m', $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), $language ),
)
)
);
@@ -456,7 +502,7 @@ class _DateTime extends \DateTime
$format = preg_replace( '#(?<!%)((?:%%)*)%e#', '\1%#d', $format );
}
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( $format, $this->getTimestamp() + $this->getTimezone()->getOffset( $this ) ) );
return static::strftime( $format, $this->getTimestamp() + $this->getTimezone()->getOffset( $this ), static::determineLanguage( $memberOrLanguage ) );
}
/**
@@ -479,7 +525,7 @@ class _DateTime extends \DateTime
}
/**
* Format the date for the datetime attribute HTML <time> tags
* Format the date for the datetime attribute HTML `<time>` tags
* This will always be in UTC (so offset is not included) and so should never be displayed normally to users
*
* @return string
@@ -524,4 +570,24 @@ class _DateTime extends \DateTime
throw new \UnexpectedValueException;
}
/**
* Run strftime() call using a given language object
*
* @param string $formatter Time format to be passed to stftime()
* @param int $time Timestamp
* @param \IPS\Lang $language Language to use
* @return string
*/
protected static function strftime( $formatter, $time, $language )
{
$curLocale = setlocale( LC_ALL, '0' );
$language->setLocale();
$result = $language->convertString( strftime( $formatter, $time ) );
\IPS\Lang::restoreLocale( $curLocale );
return $result;
}
}