Version 4.7.6
This commit is contained in:
1 parent
8ba7d43898
commit
7b7404e741
1085 files changed
+30590
-7837
No files matched your search
@@ -147,7 +147,14 @@ class _Date extends \IPS\DateTime
|
||||
}
|
||||
|
||||
/* If the date is not valid, that means a bad value was supplied */
|
||||
if( !checkdate( $month, $day, $year ) )
|
||||
try
|
||||
{
|
||||
if( !checkdate( $month, $day, $year ) )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
}
|
||||
catch ( \TypeError $e )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
@@ -196,6 +203,22 @@ class _Date extends \IPS\DateTime
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the Root DateTime instance to a \IPS\calendar\Date instance
|
||||
*
|
||||
* @param \DateTime $dateTime
|
||||
* @return Date
|
||||
*/
|
||||
public static function dateTimeToCalendarDate( \DateTime $dateTime ): \IPS\calendar\Date
|
||||
{
|
||||
if( \in_array( \get_class( $dateTime ), [ 'DateTime', 'IPS\\DateTime'] ) )
|
||||
{
|
||||
return new static( $dateTime->format('c'), $dateTime->getTimezone() );
|
||||
}
|
||||
|
||||
return $dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time zone for the DateTime object
|
||||
*
|
||||
@@ -350,51 +373,6 @@ class _Date extends \IPS\DateTime
|
||||
return $dayNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief List of timezones and the PHP timezone IDs to utilize. Note that this is only used during submit.
|
||||
*/
|
||||
public static $timezones = array(
|
||||
'-12',
|
||||
'-11',
|
||||
'-10',
|
||||
'-9.5',
|
||||
'-9',
|
||||
'-8',
|
||||
'-7',
|
||||
'-6',
|
||||
'-5',
|
||||
'-4.5',
|
||||
'-4',
|
||||
'-3.5',
|
||||
'-3',
|
||||
'-2',
|
||||
'-1',
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'3.5',
|
||||
'4',
|
||||
'4.5',
|
||||
'5',
|
||||
'5.5',
|
||||
'5.75',
|
||||
'6',
|
||||
'6.5',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'9.5',
|
||||
'10',
|
||||
'10.5',
|
||||
'11',
|
||||
'11.5',
|
||||
'12',
|
||||
'12.75',
|
||||
'13',
|
||||
'14',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get an array of time zones with GMT offset information supplied in a user-friendly format
|
||||
*
|
||||
@@ -402,20 +380,19 @@ class _Date extends \IPS\DateTime
|
||||
*/
|
||||
public static function getTimezones()
|
||||
{
|
||||
$return = array();
|
||||
$zones = \DateTimeZone::listIdentifiers( \DateTimeZone::ALL );
|
||||
|
||||
if( \IPS\Member::loggedIn()->timezone )
|
||||
$timezones[\IPS\Member::loggedIn()->timezone] = \IPS\Member::loggedIn()->timezone;
|
||||
foreach($zones as $timezone)
|
||||
{
|
||||
$return[ \IPS\Member::loggedIn()->timezone ] = array( 'text' => \IPS\Member::loggedIn()->timezone, 'short' => \IPS\Member::loggedIn()->timezone );
|
||||
if( $timezone == \IPS\Member::loggedIn()->timezone )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$timezones[$timezone] = $timezone;
|
||||
}
|
||||
|
||||
foreach( static::$timezones as $_offset )
|
||||
{
|
||||
$sprintf = ( \strpos( $_offset, '-' ) === 0 ) ? '- ' . \substr( $_offset, 1 ) : '+ ' . $_offset;
|
||||
$return[ $_offset !== '0' ? $_offset : 'GMT' ] = array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('timezone_offset_' . $_offset ), 'short' => \IPS\Member::loggedIn()->language()->addToStack('timezone_offset_short', FALSE, array( 'sprintf' => array( $sprintf ) ) ) );
|
||||
}
|
||||
|
||||
return $return;
|
||||
return $timezones;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,42 +452,8 @@ class _Date extends \IPS\DateTime
|
||||
/* Avengers assemble! */
|
||||
$time = implode( ':', $_timeBits );
|
||||
}
|
||||
|
||||
/* Default timezone - fairly straightforward */
|
||||
if( \IPS\Member::loggedIn()->timezone AND $timezone == \IPS\Member::loggedIn()->timezone )
|
||||
{
|
||||
$dateObject = new static( $date . ( $time ? ' ' . $time : '' ), new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If time is supplied, we are going to create a date-time string containing timezone offset info, so reformat date since it might be m/d/yyyy for instance */
|
||||
$date = new static( $date, \IPS\Member::loggedIn()->timezone ? new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) : NULL );
|
||||
$date = $date->format( 'Y-m-d' );
|
||||
|
||||
/* Reformat the time to give us what we want */
|
||||
if( $time )
|
||||
{
|
||||
if( $timezone == 'GMT' )
|
||||
{
|
||||
$time = 'T' . $time . '+00:00';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Handle incrementals */
|
||||
$timezone = str_replace( array( '.5', '.75' ), array( ':30', ':45' ), $timezone );
|
||||
$timezone = explode( ':', $timezone );
|
||||
|
||||
$hours = ( mb_substr( $timezone[0], 0, 1 ) == '-' ) ? '-' . str_pad( ltrim( $timezone[0], "-" ), 2, '0', STR_PAD_LEFT ) : '+' . str_pad( $timezone[0], 2, '0', STR_PAD_LEFT );
|
||||
$time = 'T' . $time . $hours .':' . ( isset( $timezone[1] ) ? str_pad( $timezone[1], 2, '0', STR_PAD_LEFT ) : '00' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$time = 'T00:00:00+00:00';
|
||||
}
|
||||
|
||||
$dateObject = new static( $date . $time );
|
||||
}
|
||||
$dateObject = new static( $date . ( $time ? ' ' . $time : '' ), new \DateTimeZone( $timezone ) );
|
||||
|
||||
return $dateObject->setTimezone( new \DateTimeZone( 'UTC' ) );
|
||||
}
|
||||
@@ -585,105 +528,6 @@ 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 $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, $count=FALSE )
|
||||
{
|
||||
$birthdays = array();
|
||||
|
||||
/* Is the setting enabled? */
|
||||
if( !\IPS\Settings::i()->show_bday_calendar )
|
||||
{
|
||||
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)' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'bday_day=?', $this->mday );
|
||||
}
|
||||
}
|
||||
|
||||
/* Exclude banned users */
|
||||
$where[] = array( 'temp_ban=?', 0 );
|
||||
|
||||
/* Groups with 'g_view_board' off are also 'banned', so factor those in too */
|
||||
$goodGroups = array();
|
||||
|
||||
foreach( \IPS\Member\Group::groups() as $group )
|
||||
{
|
||||
if( $group->g_view_board )
|
||||
{
|
||||
$goodGroups[] = $group->g_id;
|
||||
}
|
||||
}
|
||||
|
||||
$where[] = array( "member_group_id IN(" . implode( ',', $goodGroups ) . ")" );
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to make retrieving certain data easier
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user