Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,272 @@
<?php
/**
* @brief Calendar Node
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Calendar
* @since 18 Dec 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\calendar;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Calendar Node
*/
class _Calendar extends \IPS\Node\Model implements \IPS\Node\Permissions
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'calendar_calendars';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'cal_';
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'position';
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'calendars';
/**
* @brief [Node] ACP Restrictions
* @code
array(
'app' => 'core', // The application key which holds the restrictrions
'module' => 'foo', // The module key which holds the restrictions
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
'add' => 'foo_add',
'edit' => 'foo_edit',
'permissions' => 'foo_perms',
'delete' => 'foo_delete'
),
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
* @endcode
*/
protected static $restrictions = array(
'app' => 'calendar',
'module' => 'calendars',
'prefix' => 'calendars_'
);
/**
* @brief [Node] App for permission index
*/
public static $permApp = 'calendar';
/**
* @brief [Node] Type for permission index
*/
public static $permType = 'calendar';
/**
* @brief The map of permission columns
*/
public static $permissionMap = array(
'view' => 'view',
'read' => 2,
'add' => 3,
'reply' => 4,
'review' => 7,
'askrsvp' => 5,
'rsvp' => 6,
);
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
*/
public static $titleLangPrefix = 'calendar_calendar_';
/**
* @brief [Node] Moderator Permission
*/
public static $modPerm = 'calendar_calendars';
/**
* @brief Content Item Class
*/
public static $contentItemClass = 'IPS\calendar\Event';
/**
* @brief [Node] Prefix string that is automatically prepended to permission matrix language strings
*/
public static $permissionLangPrefix = 'calperm_';
/**
* [Node] Set whether or not this node is enabled
*
* @param bool|int $enabled Whether to set it enabled or disabled
* @return void
*/
protected function set__enabled( $enabled )
{
}
/**
* Get SEO name
*
* @return string
*/
public function get_title_seo()
{
if( !$this->_data['title_seo'] )
{
$this->title_seo = \IPS\Http\Url::seoTitle( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'calendar_calendar_' . $this->id ) );
$this->save();
}
return $this->_data['title_seo'] ?: \IPS\Http\Url::seoTitle( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'calendar_calendar_' . $this->id ) );
}
/**
* [Node] Add/Edit Form
*
* @param \IPS\Helpers\Form $form The form
* @return void
*/
public function form( &$form )
{
$form->add( new \IPS\Helpers\Form\Translatable( 'cal_title', NULL, TRUE, array( 'app' => 'calendar', 'key' => ( $this->id ? "calendar_calendar_{$this->id}" : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Color( 'cal_color', $this->id ? $this->color : $this->_generateColor(), TRUE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'cal_moderate', $this->id ? $this->moderate : FALSE, FALSE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'cal_allow_comments', $this->id ? $this->allow_comments : TRUE, FALSE, array( 'togglesOn' => array( 'cal_comment_moderate' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'cal_comment_moderate', $this->id ? $this->comment_moderate : FALSE, FALSE, array(), NULL, NULL, NULL, 'cal_comment_moderate' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'cal_allow_reviews', $this->id ? $this->allow_reviews : FALSE, FALSE, array( 'togglesOn' => array( 'cal_review_moderate' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'cal_review_moderate', $this->id ? $this->review_moderate : FALSE, FALSE, array(), NULL, NULL, NULL, 'cal_review_moderate' ) );
}
/**
* [Node] Format form values from add/edit form for save
*
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
{
if ( !$this->id )
{
$this->save();
}
if( isset( $values['cal_title'] ) )
{
\IPS\Lang::saveCustom( 'calendar', 'calendar_calendar_' . $this->id, $values['cal_title'] );
$values['title_seo'] = \IPS\Http\Url::seoTitle( $values['cal_title'][ \IPS\Lang::defaultLanguage() ] );
unset( $values['cal_title'] );
}
return $values;
}
/**
* @brief Cached URL
*/
protected $_url = NULL;
/**
* Get URL
*
* @return \IPS\Http\Url
*/
public function url()
{
if( $this->_url === NULL )
{
$this->_url = \IPS\Http\Url::internal( "app=calendar&module=calendar&controller=view&id={$this->_id}", 'front', 'calendar_calendar', $this->title_seo );
}
return $this->_url;
}
/**
* [ActiveRecord] Delete Record
*
* @return void
*/
public function delete()
{
\IPS\Db::i()->delete( 'calendar_import_feeds', array( 'feed_calendar_id=?', $this->id ) );
return parent::delete();
}
/**
* @brief Default colors
*/
protected static $colors = array(
'#6E4F99', // Purple
'#4F994F', // Green
'#4F7C99', // Blue
'#F3F781', // Yellow
'#DF013A', // Red
'#FFBF00', // Orange
);
/**
* Grab the next available color
*
* @return string
*/
public function _generateColor()
{
foreach( static::$colors as $color )
{
foreach( static::roots( NULL ) as $calendar )
{
if( mb_strtolower( $color ) == mb_strtolower( $calendar->color ) )
{
continue 2;
}
}
return $color;
}
/* If we're still here, all of our pre-defined codes are used...generate something random */
return '#' . str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT ) .
str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT ) .
str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT );
}
/**
* Add the appropriate CSS to the page output
*
* @return void
*/
public static function addCss()
{
$output = '';
foreach( static::roots() as $calendar )
{
$output .= "a.cEvents_style{$calendar->id}, .cEvents_style{$calendar->id} a, .cCalendarIcon.cEvents_style{$calendar->id} {
background-color: {$calendar->color};
}\n";
}
\IPS\Output::i()->headCss = \IPS\Output::i()->headCss . $output;
}
}
Whitespace-only changes.
+734
View File
@@ -0,0 +1,734 @@
<?php
/**
* @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.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Calendar
* @since 30 Dec 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\calendar;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Calendar-specific date functions
*/
class _Date extends \IPS\DateTime
{
/**
* @brief Data retrieved from get_date() with timezone accounted for
*/
protected $dateInformation = array();
/**
* @brief Information about the first day of the month we are working with
*/
protected $firstDayOfMonth = array();
/**
* @brief Information about the last day of the month we are working with
*/
protected $lastDayOfMonth = array();
/**
* @brief Information about the first day of the week we are working with
*/
protected $firstDayOfWeek = array();
/**
* @brief Information about the last day of the week we are working with
*/
protected $lastDayOfWeek = array();
/**
* @brief Information about the previous month
*/
protected $lastMonth = array();
/**
* @brief Information about the next month
*/
protected $nextMonth = array();
/**
* @brief Timezone offset for the current user
*/
public $offset = NULL;
/**
* @brief Custom date formatting options for calendar
*/
public static $dateFormats = array(
'locale' => "%x",
'd_sm_y' => "%d %b %Y",
'd_lm_y' => "%d %B %Y",
'sm_d_y' => "%b %d, %Y",
'lm_d_y' => "%B %d, %Y",
);
/**
* Creates a new object to represent the requested date
*
* @param int|NULL $year Year, or NULL for current year
* @param int|NULL $month Month, or NULL for current month
* @param int|NULL $day Day, or NULL for current day
* @param int $hour Hour (defaults to 0)
* @param int $minute Minutes (defaults to 0)
* @param int $second Seconds (defaults to 0)
* @param int $offset The offset from GMT (NULL to calculate automatically based on member's current time)
* @return \IPS\calendar\Date
* @throws \InvalidArgumentException
*/
public static function getDate( $year=NULL, $month=NULL, $day=NULL, $hour=0, $minute=0, $second=0, $offset=0 )
{
/* Get our time zone offset */
if ( !$offset and \IPS\Member::loggedIn()->timezone )
{
$offset = \IPS\DateTime::create()->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) )->getOffset();
}
/* Set appropriate defaults for values not supplied, which is normal */
if( $year === NULL )
{
$year = date( 'Y', time() + $offset );
}
if( $day === NULL )
{
$day = ( $month !== NULL ) ? 1 : date( 'd', time() + $offset );
}
if( $month === NULL )
{
$month = date( 'm', time() + $offset );
}
/* If the date is not valid, that means a bad value was supplied */
if( !checkdate( $month, $day, $year ) )
{
throw new \InvalidArgumentException;
}
/* Create the timestamp */
$timeStamp = gmmktime( $hour, $minute, $second, $month, $day, $year );
/* Store the information and return the object */
$obj = static::ts( $timeStamp - $offset );
$obj->dateInformation = getdate( $timeStamp );
$obj->offset = $offset;
return $obj;
}
/**
* Create a new datetime object
*
* @note We override to update dateInformation and stored offset
* @param string $time Time
* @param \DateTimeZone|null $timezone Timezone
* @return \IPS\calendar\Date
*/
public function __construct( $time="now", $timezone=NULL )
{
if ( $timezone )
{
$result = parent::__construct( $time, $timezone );
}
else
{
$result = parent::__construct( $time );
}
$this->dateInformation = getdate( $this->getTimestamp() );
$this->offset = $this->getOffset();
return $result;
}
/**
* Sets the time zone for the DateTime object
*
* @note We override to update dateInformation and stored offset
* @param \DateTimeZone $timezone New timezone
* @return \IPS\calendar\Date|FALSE
*/
public function setTimezone( $timezone )
{
$result = parent::setTimezone( $timezone );
$this->dateInformation = getdate( $this->getTimestamp() );
$this->offset = $this->getOffset();
return $result;
}
/**
* Returns a date object created based on an arbitrary string. Used for both relative time strings and SQL datetime values.
*
* @note Datetime values are stored in the database normalized to UTC
* @param string $datetime String-based date/time
* @param bool $forceUTC Force timezone to UTC (necessary when passing a datetime retrieved from the database)
* @return \IPS\calendar\Date
*/
public static function parseTime( $datetime, $forceUTC=FALSE )
{
/* Create an \IPS\DateTime object from the datetime value passed in */
$timezone = ( $forceUTC === TRUE ) ? new \DateTimeZone( 'UTC' ) : ( \IPS\Member::loggedIn()->timezone ? new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) : NULL );
$datetime = new \IPS\DateTime( $datetime, $timezone );
/* Now correct it back if necessary */
if( $forceUTC === TRUE AND \IPS\Member::loggedIn()->timezone )
{
$datetime->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
}
return static::getDate( $datetime->format('Y'), $datetime->format('m'), $datetime->format('d'), $datetime->format('H'), $datetime->format('i'), $datetime->format('s'), $datetime->getOffset() );
}
/**
* Adjusts the date and returns a new date object representing the adjustment
*
* @param string $adjustment String to turn into a \DateInterval object which will be applied to the current date/time (supports most strtotime adjustments)
* @return \IPS\calendar\Date
* @see <a href='http://www.php.net/manual/en/dateinterval.createfromdatestring.php'>DateInterval::createFromDateString() docs</a>
*/
public function adjust( $adjustment )
{
$datetime = \IPS\DateTime::ts( $this->dateInformation[0] )->setTimezone( new \DateTimeZone( "UTC" ) );
$datetime->add( \DateInterval::createFromDateString( $adjustment ) );
return static::getDate( gmdate( 'Y', $datetime->getTimestamp() ), gmdate( 'm', $datetime->getTimestamp() ), gmdate( 'd', $datetime->getTimestamp() ), gmdate( 'H', $datetime->getTimestamp() ), gmdate( 'i', $datetime->getTimestamp() ), gmdate( 's', $datetime->getTimestamp() ) );
}
/**
* Get the localized day names in correct order
*
* @return array
* @see <a href='http://stackoverflow.com/questions/7765469/retrieving-day-names-in-php'>Get localized day names in PHP</a>
*/
public static function getDayNames()
{
$dayNames = array();
$startDay = \IPS\Settings::i()->ipb_calendar_mon ? 'Monday' : 'Sunday';
for( $i = 0; $i < 7; $i++ )
{
$_time = strtotime( 'next ' . $startDay . ' +' . $i . ' days' );
$_abbr = \IPS\Member::loggedIn()->language()->convertString( strftime( '%a', $_time ) );
$dayNames[] = array( 'full' => \IPS\Member::loggedIn()->language()->convertString( strftime( '%A', $_time ) ), 'english' => date( 'l', $_time ), 'abbreviated' => $_abbr, 'letter' => mb_substr( $_abbr, 0, 1 ), 'ical' => mb_strtoupper( mb_substr( date( 'D', $_time ), 0, 2 ) ) );
}
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
*
* @return array
*/
public static function getTimezones()
{
$return = array();
if( \IPS\Member::loggedIn()->timezone )
{
$return[ \IPS\Member::loggedIn()->timezone ] = array( 'text' => \IPS\Member::loggedIn()->timezone, 'short' => \IPS\Member::loggedIn()->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 a date object based on supplied values, factoring in the timezone offset which could be in the "friendly" timezone format
*
* @param string $date Date as a textual string, from the date form helper
* @param string $time Time as a textual string
* @param string $timezone Timezone chosen
* @return \IPS\calendar\Date
*/
public static function createFromForm( $date, $time, $timezone )
{
/* Correct date */
$date = \IPS\Helpers\Form\Date::_convertDateFormat( $date );
/* Fix time inconsistencies */
if( $time )
{
$time = mb_strtolower( $time );
/* If they typed in 'am', convert '12' to 00, and then strip 'am' */
if( \strpos( $time, 'am' ) !== FALSE )
{
if( \strpos( $time, '12' ) === 0 )
{
$time = substr_replace( $time, '00', 0, 2 );
}
$time = str_replace( 'am', '', $time );
}
/* If they typed in 'pm', add 12 to anything other than 12 and strip 'pm' */
else if( \strpos( $time, 'pm' ) !== FALSE )
{
$_timeBits = explode( ':', $time );
$_timeBits[0] = $_timeBits[0] < 12 ? ( $_timeBits[0] + 12 ) : $_timeBits[0];
$time = implode( ':', $_timeBits );
$time = str_replace( 'pm', '', $time );
}
/* Make sure we have 3 pieces and that all are 2 digits */
$_timeBits = explode( ':', $time );
if ( count( $_timeBits ) < 3 )
{
while( count( $_timeBits ) < 3 )
{
$_timeBits[] = '00';
}
}
foreach( $_timeBits as $k => $v )
{
$_timeBits[ $k ] = str_pad( trim( $v ), 2, '0', STR_PAD_LEFT );
}
/* 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 );
}
return $dateObject->setTimezone( new \DateTimeZone( 'UTC' ) );
}
/**
* Modified version of ISO-8601 used by iCalendar - omits the timezone identifier and all dashes and colons
*
* @param bool $includeTime Whether to include time or not
* @param bool $includeIdentifier Whether to include 'Z' at the end or not
* @return string
* @see <a href='http://www.kanzaki.com/docs/ical/dateTime.html'>DateTime explanation</a>
*/
public function modifiedIso8601( $includeTime=TRUE, $includeIdentifier=FALSE )
{
if( $includeTime )
{
return date( 'Ymd', $this->getTimestamp() ) . 'T' . date( 'His', $this->getTimestamp() ) . ( $includeIdentifier ? 'Z' : '' );
}
else
{
return date( 'Ymd', $this->getTimestamp() );
}
}
/**
* Return the date for use in calendar (used instead of localeDate() to allow admin to configure)
*
* @return string
*/
public function calendarDate()
{
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->getTimezone()->getOffset( $this ) ) );
}
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->getTimezone()->getOffset( $this ) ) );
}
else
{
return static::localeDate();
}
}
/**
* Return the MySQL-style datetime value
*
* @param bool $includeTime Whether to include time or not
* @return string
*/
public function mysqlDatetime( $includeTime=TRUE )
{
if( $includeTime )
{
return date( 'Y-m-d H:i:s', isset( $this->dateInformation[0] ) ? $this->dateInformation[0] : $this->getTimestamp() );
}
else
{
return date( 'Y-m-d', isset( $this->dateInformation[0] ) ? $this->dateInformation[0] : $this->getTimestamp() );
}
}
/**
* Retrieve the birthdays for the date
*
* @param bool $day Whether to limit to the current day or not
* @return array
*/
public function getBirthdays( $day=FALSE )
{
$birthdays = array();
/* Is the setting enabled? */
if( !\IPS\Settings::i()->show_bday_calendar )
{
return $birthdays;
}
$where = array( array( 'bday_month=?', $this->mon ) );
if( $day === TRUE )
{
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 );
}
}
$members = \IPS\DB::i()->select( '*', 'core_members', $where );
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 );
$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;
}
}
}
return $birthdays;
}
/**
* Magic method to make retrieving certain data easier
*
* @param mixed $key Value we tried to retrieve
* @return mixed
*/
public function __get( $key )
{
return $this->_findValue( $key, $this->dateInformation );
}
/**
* Retrieve information about the first day of the month
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function firstDayOfMonth( $key )
{
if( !isset( $this->firstDayOfMonth[0] ) )
{
$this->firstDayOfMonth = getdate( gmmktime( 0, 0, 0, $this->mon, 1, $this->year ) );
}
return $this->_findValue( $key, $this->firstDayOfMonth );
}
/**
* Retrieve information about the last day of the month
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function lastDayOfMonth( $key )
{
if( !isset( $this->lastDayOfMonth[0] ) )
{
$this->lastDayOfMonth = getdate( gmmktime( 0, 0, 0, $this->mon + 1, 0, $this->year ) );
}
return $this->_findValue( $key, $this->lastDayOfMonth );
}
/**
* Retrieve information about the previous month
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function lastMonth( $key )
{
if( !isset( $this->lastMonth[0] ) )
{
$this->lastMonth = getdate( gmmktime( 0, 0, 0, $this->mon - 1, 1, $this->year ) );
}
return $this->_findValue( $key, $this->lastMonth );
}
/**
* Retrieve information about the next month
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function nextMonth( $key )
{
if( !isset( $this->nextMonth[0] ) )
{
$this->nextMonth = getdate( gmmktime( 0, 0, 0, $this->mon + 1, 1, $this->year ) );
}
return $this->_findValue( $key, $this->nextMonth );
}
/**
* Retrieve information about the first day of the week we are working with
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function firstDayOfWeek( $key )
{
if( !isset( $this->firstDayOfWeek[0] ) )
{
$this->firstDayOfWeek = getdate( gmmktime( 0, 0, 0, $this->mon, $this->mday - $this->wday, $this->year ) );
}
return $this->_findValue( $key, $this->firstDayOfWeek );
}
/**
* Retrieve information about the last day of the week we are working with
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @return mixed
*/
public function lastDayOfWeek( $key )
{
if( !isset( $this->lastDayOfWeek[0] ) )
{
$this->lastDayOfWeek = getdate( gmmktime( 0, 0, 0, $this->mon, $this->mday + ( 6 - $this->wday ), $this->year ) );
}
return $this->_findValue( $key, $this->lastDayOfWeek );
}
/**
* Returns whether the date falls in a leap year or not
*
* @return bool
*/
public function leapYear()
{
return (bool) gmdate( 'L', $this->dateInformation[0] );
}
/**
* Returns whether the current locale uses AM/PM or 24 hour format
*
* @return bool
* @link <a href='http://stackoverflow.com/questions/6871258/how-to-determine-if-current-locale-has-24-hour-or-12-hour-time-format-in-php'>Check for 24 hour locale use</a>
*/
public static function usesAmPm()
{
return ( \substr( gmstrftime( '%X', 57600 ), 0, 2) != 16 );
}
/**
* Get the 12 hour version of an hour value
*
* @param int Hour The hour value between 0 and 23
* @return int
*/
public static function getTwelveHour( $hour )
{
if( $hour == 0 )
{
return 12;
}
else if( $hour > 12 )
{
return $hour - 12;
}
else
{
return $hour;
}
}
/**
* Get the AM/PM value for the current locale
*
* @param int Hour The hour value between 0 and 23
* @return string
*/
public static function getAmPm( $hour )
{
return gmstrftime( '%p', $hour * 60 * 60 );
}
/**
* Find a value in the supplied array and return it. Also supports a few 'special' keys.
*
* @param mixed $key Key (from getdate()) we want to retrieve
* @param array $data Array to look for the key in
* @return mixed
*/
protected function _findValue( $key, $data )
{
if( isset( $data[ $key ] ) )
{
if( $key == 'wday' AND \IPS\Settings::i()->ipb_calendar_mon )
{
return ( $data[ $key ] == 0 ) ? 6: ( $data[ $key ] - 1 );
}
if( $key == 'mon' OR $key == 'mday' )
{
return str_pad( $data[ $key ], 2, '0', STR_PAD_LEFT );
}
return $data[ $key ];
}
if( $key == 'monthName' AND isset( $data[0] ) )
{
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( '%B', $data[0] ) ), MB_CASE_TITLE );
}
if( $key == 'monthNameShort' AND isset( $data[0] ) )
{
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( '%b', $data[0] ) ), MB_CASE_TITLE );
}
if( $key == 'dayName' AND isset( $data[0] ) )
{
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( '%A', $data[0] ) ), MB_CASE_TITLE );
}
if( $key == 'dayNameShort' AND isset( $data[0] ) )
{
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( '%a', $data[0] ) ), MB_CASE_TITLE );
}
return NULL;
}
}
Whitespace-only changes.
@@ -0,0 +1,108 @@
<?php
/**
* @brief Event Comment Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Calendar
* @since 7 Jan 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\calendar\Event;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Event Comment Model
*/
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\ReportCenter, \IPS\Content\Hideable, \IPS\Content\Reputation, \IPS\Content\Searchable, \IPS\Content\Embeddable
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\calendar\Event';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'calendar_event_comments';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'comment_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
'item' => 'eid',
'author' => 'mid',
'author_name' => 'author',
'content' => 'text',
'date' => 'date',
'ip_address' => 'ip_address',
'edit_time' => 'edit_time',
'edit_member_name' => 'edit_name',
'edit_show' => 'append_edit',
'approved' => 'approved'
);
/**
* @brief Application
*/
public static $application = 'calendar';
/**
* @brief Title
*/
public static $title = 'calendar_event_comment';
/**
* @brief Icon
*/
public static $icon = 'calendar';
/**
* @brief Reputation Type
*/
public static $reputationType = 'comment_id';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'calendar-events';
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
*/
public function url( $action=NULL )
{
return parent::url( $action )->setQueryString( 'tab', 'comments' );
}
/**
* Get template for content tables
*
* @return callable
*/
public static function contentTableTemplate()
{
return array( \IPS\Theme::i()->getTemplate( 'tables', 'core' ), 'commentRows' );
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,112 @@
<?php
/**
* @brief Event Review Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Calendar
* @since 7 Jan 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\calendar\Event;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Event Review Model
*/
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\ReportCenter, \IPS\Content\Hideable, \IPS\Content\Reputation, \IPS\Content\Searchable, \IPS\Content\Embeddable
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\calendar\Event';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'calendar_event_reviews';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'review_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
'item' => 'eid',
'author' => 'mid',
'author_name' => 'author_name',
'content' => 'text',
'date' => 'date',
'ip_address' => 'ip',
'edit_time' => 'edit_time',
'edit_member_name' => 'edit_name',
'edit_show' => 'append_edit',
'rating' => 'rating',
'votes_total' => 'votes',
'votes_helpful' => 'votes_helpful',
'votes_data' => 'votes_data',
'approved' => 'approved',
);
/**
* @brief Application
*/
public static $application = 'calendar';
/**
* @brief Title
*/
public static $title = 'calendar_event_review';
/**
* @brief Icon
*/
public static $icon = 'calendar';
/**
* @brief Reputation Type
*/
public static $reputationType = 'review_id';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'calendar-events-rev';
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
*/
public function url( $action=NULL )
{
return parent::url( $action )->setQueryString( 'tab', 'reviews' );
}
/**
* Get template for content tables
*
* @return callable
*/
public static function contentTableTemplate()
{
return array( \IPS\Theme::i()->getTemplate( 'tables', 'core' ), 'commentRows' );
}
}
Whitespace-only changes.
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,95 @@
<?php
/**
* @brief iCalendar active record
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Calendar
* @since 19 Dec 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\calendar;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* iCalendar active record
*/
class _Icalendar extends \IPS\Patterns\ActiveRecord
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'calendar_import_feeds';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'feed_';
/**
* Set Default Values
*
* @return void
*/
public function setDefaultValues()
{
$this->added = time();
$this->lastupdated = time();
$this->last_run = time();
}
/**
* Reimport iCalendar events
*
* @return int
* @throws \UnexpectedValueException
* @note PHP installs do not (at least typically) have stream wrappers for webcal://, so we have to change the scheme to http://
*/
public function refresh()
{
$this->last_run = time();
$this->save();
$icsParser = new \IPS\calendar\Icalendar\ICSParser;
return $icsParser->parse( \IPS\Http\Url::external( str_replace( array( 'webcal://', 'webcals://' ), array( 'http://', 'https://' ), $this->url ) )->request()->get(), $this->calendar_id, $this->member_id, $this->id );
}
/**
* Delete events imported from an iCalendar feed
*
* @return void
*/
public function deleteFeedEvents()
{
/* Looping over all event IDs this feed has imported, delete them */
foreach( \IPS\Db::i()->select( '*', 'calendar_import_map', array( 'import_feed_id=?', $this->id ) ) as $mappedEvent )
{
\IPS\calendar\Event::load( $mappedEvent['import_event_id'] )->delete();
}
}
/**
* [ActiveRecord] Delete Record
*
* @return void
*/
public function delete()
{
\IPS\Db::i()->delete( 'calendar_import_map', array( 'import_feed_id=?', $this->id ) );
return parent::delete();
}
}
Whitespace-only changes.
Whitespace-only changes.