Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -13,44 +13,63 @@
|
||||
|
||||
namespace IPS\calendar;
|
||||
|
||||
use IPS\Application as SystemApplication;
|
||||
use IPS\calendar\Icalendar\ICSParser;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\DateTime;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use IPS\Xml\Rss;
|
||||
use OutOfRangeException;
|
||||
use function array_merge;
|
||||
use function in_array;
|
||||
use function mb_strlen;
|
||||
use function mb_substr;
|
||||
|
||||
/**
|
||||
* Core Application Class
|
||||
*/
|
||||
class _Application extends \IPS\Application
|
||||
class Application extends SystemApplication
|
||||
{
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init() : void
|
||||
{
|
||||
/* Requesting iCal/RSS Subscription, but guests are required to login */
|
||||
if( \IPS\Request::i()->module == 'calendar' and \IPS\Request::i()->controller == 'view' and \in_array( \IPS\Request::i()->do, array( 'rss', 'download' ) ) )
|
||||
if( Request::i()->module == 'calendar' and Request::i()->controller == 'view' and in_array( Request::i()->do, array( 'rss', 'download' ) ) )
|
||||
{
|
||||
/* Validate RSS/Download key */
|
||||
if( \IPS\Request::i()->member )
|
||||
if( Request::i()->member )
|
||||
{
|
||||
$member = \IPS\Member::load( \IPS\Request::i()->member );
|
||||
if( !\IPS\Login::compareHashes( $member->getUniqueMemberHash(), (string) \IPS\Request::i()->key ) )
|
||||
$member = Member::load( Request::i()->member );
|
||||
if( !Login::compareHashes( $member->getUniqueMemberHash(), (string) Request::i()->key ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2L217/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '2L217/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Output */
|
||||
if( \IPS\Request::i()->do == 'download' )
|
||||
if( Request::i()->do == 'download' )
|
||||
{
|
||||
$this->download( \IPS\Request::i()->member ? $member : NULL );
|
||||
$this->download( Request::i()->member ? $member : NULL );
|
||||
}
|
||||
|
||||
$this->rss( \IPS\Request::i()->member ? $member : NULL );
|
||||
$this->rss( Request::i()->member ? $member : NULL );
|
||||
}
|
||||
|
||||
/* Reset first day of week */
|
||||
if( \IPS\Settings::i()->ipb_calendar_mon )
|
||||
if( Settings::i()->ipb_calendar_mon )
|
||||
{
|
||||
\IPS\Output::i()->jsVars['date_first_day'] = 1;
|
||||
Output::i()->jsVars['date_first_day'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +77,9 @@ class _Application extends \IPS\Application
|
||||
* [Node] Get Icon for tree
|
||||
*
|
||||
* @note Return the class for the icon (e.g. 'globe')
|
||||
* @return string|null
|
||||
* @return string
|
||||
*/
|
||||
protected function get__icon()
|
||||
protected function get__icon(): string
|
||||
{
|
||||
return 'calendar';
|
||||
}
|
||||
@@ -68,30 +87,30 @@ class _Application extends \IPS\Application
|
||||
/**
|
||||
* Latest events RSS
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Member to generate feed for
|
||||
* @param Member|null $member Member to generate feed for
|
||||
* @return void
|
||||
* @note There is a hard limit of the most recent 500 events updated
|
||||
*/
|
||||
public function download( $member=NULL )
|
||||
public function download( Member $member=NULL ) : void
|
||||
{
|
||||
$feed = new \IPS\calendar\Icalendar\ICSParser;
|
||||
$feed = new ICSParser;
|
||||
$calendar = NULL;
|
||||
|
||||
/* Are we viewing a specific calendar only? */
|
||||
if( \IPS\Request::i()->id )
|
||||
if( Request::i()->id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$calendar = \IPS\calendar\Calendar::load( \IPS\Request::i()->id );
|
||||
$calendar = Calendar::load( Request::i()->id );
|
||||
|
||||
if ( !$calendar->can( 'view', $member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2L217/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2L217/3', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,58 +121,57 @@ class _Application extends \IPS\Application
|
||||
$where[] = array( 'event_calendar_id=?', $calendar->id );
|
||||
}
|
||||
|
||||
foreach( \IPS\calendar\Event::getItemsWithPermission( $where, 'event_lastupdated DESC', 500, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, $member ) as $event )
|
||||
foreach(Event::getItemsWithPermission( $where, 'event_lastupdated DESC', 500, 'read', Filter::FILTER_AUTOMATIC, 0, $member ) as $event )
|
||||
{
|
||||
$feed->addEvent( $event );
|
||||
}
|
||||
|
||||
$ics = $feed->buildICalendarFeed( $calendar );
|
||||
|
||||
\IPS\Output::i()->sendOutput( $ics, 200, 'text/calendar', [ 'Content-Disposition' => \IPS\Output::getContentDisposition( 'inline', "calendarEvents.ics" ) ], FALSE, FALSE, FALSE );
|
||||
exit;
|
||||
Output::i()->sendOutput( $ics, 200, 'text/calendar', [ 'Content-Disposition' => Output::getContentDisposition( 'inline', "calendarEvents.ics" ) ], FALSE, FALSE, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Latest events RSS
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Member to generate feed for
|
||||
* @param Member|null $member Member to generate feed for
|
||||
* @return void
|
||||
*/
|
||||
public function rss( $member=NULL )
|
||||
public function rss( Member $member=NULL ) : void
|
||||
{
|
||||
if( !\IPS\Settings::i()->calendar_rss_feed )
|
||||
if( !Settings::i()->calendar_rss_feed )
|
||||
{
|
||||
\IPS\Output::i()->error( 'event_rss_feed_off', '2L182/1', 404, 'event_rss_feed_off_admin' );
|
||||
Output::i()->error( 'event_rss_feed_off', '2L182/1', 404, 'event_rss_feed_off_admin' );
|
||||
}
|
||||
|
||||
/* Load member */
|
||||
if ( $member === NULL )
|
||||
{
|
||||
$member = \IPS\Member::loggedIn();
|
||||
$member = Member::loggedIn();
|
||||
}
|
||||
|
||||
$rssTitle = $member->language()->get('calendar_rss_title');
|
||||
$document = \IPS\Xml\Rss::newDocument( \IPS\Http\Url::internal( 'app=calendar&module=calendar&controller=view', 'front', 'calendar' ), $rssTitle, $rssTitle );
|
||||
$document = Rss::newDocument( Url::internal( 'app=calendar&module=calendar&controller=view', 'front', 'calendar' ), $rssTitle, $rssTitle );
|
||||
|
||||
$_today = \IPS\calendar\Date::getDate();
|
||||
$_today = Date::getDate();
|
||||
|
||||
$endDate = NULL;
|
||||
|
||||
if( \IPS\Settings::i()->calendar_rss_feed_days > 0 )
|
||||
if( Settings::i()->calendar_rss_feed_days > 0 )
|
||||
{
|
||||
$endDate = $_today->adjust( "+" . \IPS\Settings::i()->calendar_rss_feed_days . " days" );
|
||||
$endDate = $_today->adjust( "+" . Settings::i()->calendar_rss_feed_days . " days" );
|
||||
}
|
||||
|
||||
foreach ( \IPS\calendar\Event::retrieveEvents( $_today, $endDate, NULL, NULL, FALSE, $member ) as $event )
|
||||
foreach (Event::retrieveEvents( $_today, $endDate, NULL, NULL, FALSE, $member ) as $event )
|
||||
{
|
||||
$next = ( (int) \IPS\Settings::i()->calendar_rss_feed_order === 0 ) ? $event->nextOccurrence( $_today, 'startDate' ) : \IPS\DateTime::ts( $event->saved );
|
||||
$next = ( (int) Settings::i()->calendar_rss_feed_order === 0 ) ? $event->nextOccurrence( $_today, 'startDate' ) : DateTime::ts( $event->saved );
|
||||
$content = $event->content;
|
||||
\IPS\Output::i()->parseFileObjectUrls( $content );
|
||||
Output::i()->parseFileObjectUrls( $content );
|
||||
$document->addItem( $event->title, $event->url(), $content, $next, $event->id );
|
||||
}
|
||||
|
||||
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
|
||||
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml', array(), TRUE );
|
||||
Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +197,7 @@ class _Application extends \IPS\Application
|
||||
* @endcode
|
||||
* @return array
|
||||
*/
|
||||
public function defaultFrontNavigation()
|
||||
public function defaultFrontNavigation(): array
|
||||
{
|
||||
return array(
|
||||
'rootTabs' => array(),
|
||||
@@ -198,9 +216,9 @@ class _Application extends \IPS\Application
|
||||
{
|
||||
return array_merge( [
|
||||
'calendarEvent_rsvp' => [
|
||||
'event' => \IPS\calendar\Event::class,
|
||||
'action' => "string with the state ('no','yes','maybe','leave')",
|
||||
'attendee' => \IPS\Member::class
|
||||
'event' => Event::class,
|
||||
'action' => "string with the state (attending/etc..)",
|
||||
'attendee' => Member::class
|
||||
]
|
||||
],parent::getWebhooks());
|
||||
}
|
||||
@@ -210,22 +228,35 @@ class _Application extends \IPS\Application
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertLegacyParameters()
|
||||
public function convertLegacyParameters() : void
|
||||
{
|
||||
$url = \IPS\Request::i()->url();
|
||||
$baseUrl = parse_url( \IPS\Settings::i()->base_url );
|
||||
$url = Request::i()->url();
|
||||
$baseUrl = parse_url( Settings::i()->base_url );
|
||||
|
||||
/* We want to match /calendar/ if IC is not installed inside a directory, or if it is, the /path/calendar/ exactly */
|
||||
$strToCheck = ( ! empty( trim( $baseUrl['path'], '/' ) ) ) ? '/' . trim( $baseUrl['path'], '/' ) . '/calendar/' : '/calendar/';
|
||||
|
||||
|
||||
// once we use php8, we can use str_starts_with, right now here's the hacky way with substr
|
||||
if( \mb_substr($url->data[ \IPS\Http\Url::COMPONENT_PATH ], 0, \mb_strlen($strToCheck)) === $strToCheck )
|
||||
if( mb_substr($url->data[ Url::COMPONENT_PATH ], 0, mb_strlen($strToCheck)) === $strToCheck )
|
||||
{
|
||||
$newPath = str_replace( '/calendar/', '/events/', $url->data[ \IPS\Http\Url::COMPONENT_PATH ] );
|
||||
$newPath = str_replace( '/calendar/', '/events/', $url->data[ Url::COMPONENT_PATH ] );
|
||||
$url = $url->setPath( $newPath );
|
||||
|
||||
\IPS\Output::i()->redirect( $url, NULL, 301 );
|
||||
Output::i()->redirect( $url );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output CSS files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function outputCss() : void
|
||||
{
|
||||
if ( Dispatcher::hasInstance() and Dispatcher::i()->controllerLocation === 'front' )
|
||||
{
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'calendar.css', 'calendar', 'front' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user