Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+81 -44
View File
@@ -2,9 +2,9 @@
/**
* @brief Calendar-specific date functions
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Calendar
* @since 30 Dec 2013
* @version SVN_VERSION_NUMBER
@@ -75,6 +75,11 @@ class _Date extends \IPS\DateTime
'lm_d_y' => "%B %d, %Y",
);
/**
* @brief Cache date objects we've created through getDate()
*/
protected static $dateObjects = array();
/**
* Creates a new object to represent the requested date
*
@@ -88,10 +93,10 @@ class _Date extends \IPS\DateTime
* @return \IPS\calendar\Date
* @throws \InvalidArgumentException
*/
public static function getDate( $year=NULL, $month=NULL, $day=NULL, $hour=0, $minute=0, $second=0, $offset=0 )
public static function getDate( $year=NULL, $month=NULL, $day=NULL, $hour=0, $minute=0, $second=0, $offset=NULL )
{
/* Get our time zone offset */
if ( !$offset and \IPS\Member::loggedIn()->timezone )
if ( $offset === NULL and \IPS\Member::loggedIn()->timezone )
{
$offset = \IPS\DateTime::create()->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) )->getOffset();
}
@@ -419,17 +424,18 @@ class _Date extends \IPS\DateTime
/**
* Return the date for use in calendar (used instead of localeDate() to allow admin to configure)
*
* @param \IPS\Lang|\IPS\Member|NULL $memberOrLanguage The language or member to use, or NULL for currently logged in member
* @return string
*/
public function calendarDate()
public function calendarDate( $memberOrLanguage=NULL )
{
if( \IPS\Settings::i()->calendar_date_format == -1 AND \IPS\Settings::i()->calendar_date_format_custom )
{
return \IPS\Member::loggedIn()->language()->convertString( strftime( \IPS\Settings::i()->calendar_date_format_custom, $this->getTimestamp() + $this->offset ) );
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( \IPS\Settings::i()->calendar_date_format_custom, $this->getTimestamp() + $this->offset ) );
}
elseif( isset( static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ] ) )
{
return \IPS\Member::loggedIn()->language()->convertString( strftime( static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ], $this->getTimestamp() + $this->offset ) );
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ], $this->getTimestamp() + $this->offset ) );
}
else
{
@@ -458,10 +464,12 @@ class _Date extends \IPS\DateTime
/**
* Retrieve the birthdays for the date
*
* @param bool $day Whether to limit to the current day or not
* @param bool $day Whether to limit to the current day or not
* @param bool $count Flag to indicate we only need the count
* @note When $count is TRUE we return an array of dates => integers (counts), when it is FALSE we return an array of dates => array( member objects )
* @return array
*/
public function getBirthdays( $day=FALSE )
public function getBirthdays( $day=FALSE, $count=FALSE )
{
$birthdays = array();
@@ -471,10 +479,58 @@ class _Date extends \IPS\DateTime
return $birthdays;
}
/* Get where clause */
$where = $this->getBirthdaysWhere( $day );
/* Now, do we just want the count? */
if( $count )
{
$members = \IPS\Db::i()->select( 'COUNT(*) as total, bday_month, bday_day', 'core_members', $where, NULL, NULL, array( 'bday_month', 'bday_day' ) );
foreach( $members as $member )
{
$birthdays[ str_pad( $member['bday_month'], 2, 0, STR_PAD_LEFT ) . str_pad( $member['bday_day'], 2, 0, STR_PAD_LEFT ) ] = $member['total'];
}
}
else
{
$members = \IPS\Db::i()->select( '*', 'core_members', $where, 'name ASC', array( 0, 5 ) );
if( $members->count() )
{
foreach( $members as $member )
{
/* If it's not leap year we do the nice thing and show Feb 29th birthdays on Feb 28th */
if( $this->mon == 2 AND !$this->leapYear() AND $member['bday_month'] == 2 AND $member['bday_day'] == 29 )
{
$member['bday_day'] = 28;
}
$member = \IPS\Member::constructFromData( $member );
$birthdays[ str_pad( $member->bday_month, 2, 0, STR_PAD_LEFT ) . str_pad( $member->bday_day, 2, 0, STR_PAD_LEFT ) ][] = $member;
}
}
}
return $birthdays;
}
/**
* Return the where clause to fetch birthdays
*
* @param bool $day Whether to limit to the current day or not
* @return array
*/
public function getBirthdaysWhere( $day=FALSE )
{
/* We always limit by month */
$where = array( array( 'bday_month=?', $this->mon ) );
/* Are we also limiting by day? */
if( $day === TRUE )
{
/* February 29th is special */
if( $this->mon == 2 AND $this->mday == 28 AND !$this->leapYear() )
{
$where[] = array( 'bday_day IN(28,29)' );
@@ -485,43 +541,23 @@ class _Date extends \IPS\DateTime
}
}
$members = \IPS\DB::i()->select( '*', 'core_members', $where );
/* Exclude banned users */
$where[] = array( 'temp_ban=?', 0 );
if( $members->count() )
/* Groups with 'g_view_board' off are also 'banned', so factor those in too */
$goodGroups = array();
foreach( \IPS\Member\Group::groups() as $group )
{
foreach( $members as $member )
if( $group->g_view_board )
{
/* If it's not leap year we do the nice thing and show Feb 29th birthdays on Feb 28th */
if( $this->mon == 2 AND !$this->leapYear() AND $member['bday_month'] == 2 AND $member['bday_day'] == 29 )
{
$member['bday_day'] = 28;
}
$member = \IPS\Member::constructFromData( $member );
$banned = FALSE;
if ( $member->temp_ban != 0 )
{
if ( $member->temp_ban > 0 OR $member->temp_ban == -1 )
{
$banned = TRUE;
}
}
if( !$member->group['g_view_board'] )
{
$banned = TRUE;
}
if ( !$banned )
{
$birthdays[ str_pad( $member->bday_month, 2, 0, STR_PAD_LEFT ) . str_pad( $member->bday_day, 2, 0, STR_PAD_LEFT ) ][] = $member;
}
$goodGroups[] = $group->g_id;
}
}
return $birthdays;
$where[] = array( "member_group_id IN(" . implode( ',', $goodGroups ) . ")" );
return $where;
}
/**
@@ -735,12 +771,13 @@ class _Date extends \IPS\DateTime
/**
* Format the time according to the user's locale (without the date)
*
* @param bool $seconds If TRUE, will include seconds
* @param bool $minutes If TRUE, will include minutes
* @param bool $seconds If TRUE, will include seconds
* @param bool $minutes If TRUE, will include minutes
* @param \IPS\Lang|\IPS\Member|NULL $memberOrLanguage The language or member to use, or NULL for currently logged in member
* @return string
*/
public function localeTime( $seconds=TRUE, $minutes=TRUE )
public function localeTime( $seconds=TRUE, $minutes=TRUE, $memberOrLanguage=NULL )
{
return \IPS\Member::loggedIn()->language()->convertString( strftime( $this->localeTimeFormat( $seconds, $minutes ), $this->getTimestamp() + $this->offset ) );
return static::determineLanguage( $memberOrLanguage )->convertString( strftime( $this->localeTimeFormat( $seconds, $minutes, $memberOrLanguage ), $this->getTimestamp() + $this->offset ) );
}
}