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
@@ -12,47 +12,61 @@
|
||||
namespace IPS\calendar\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateTimeZone;
|
||||
use IPS\Application\Module;
|
||||
use IPS\calendar\Date;
|
||||
use IPS\calendar\Event;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\PermissionCache;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* upcomingEvents Widget
|
||||
*/
|
||||
class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
class upcomingEvents extends PermissionCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'upcomingEvents';
|
||||
public string $key = 'upcomingEvents';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'calendar';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
public string $app = 'calendar';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $uniqueKey Unique key for this specific instance
|
||||
* @param String $uniqueKey Unique key for this specific instance
|
||||
* @param array $configuration Widget custom configuration
|
||||
* @param null|string|array $access Array/JSON string of executable apps (core=sidebar only, content=IP.Content only, etc)
|
||||
* @param null|string $orientation Orientation (top, bottom, right, left)
|
||||
* @param array|string|null $access Array/JSON string of executable apps (core=sidebar only, content=IP.Content only, etc)
|
||||
* @param string|null $orientation Orientation (top, bottom, right, left)
|
||||
* @param string $layout
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $uniqueKey, array $configuration, $access=null, $orientation=null )
|
||||
public function __construct(string $uniqueKey, array $configuration, array|string $access=null, string $orientation=null, string $layout='table' )
|
||||
{
|
||||
parent::__construct( $uniqueKey, $configuration, $access, $orientation );
|
||||
parent::__construct( $uniqueKey, $configuration, $access, $orientation, $layout );
|
||||
|
||||
/* We need to adjust for timezone too */
|
||||
$this->cacheKey = "widget_{$this->key}_" . $this->uniqueKey . '_' . md5( json_encode( $configuration ) . "_" . \IPS\Member::loggedIn()->language()->id . "_" . \IPS\Member::loggedIn()->skin . "_" . json_encode( \IPS\Member::loggedIn()->groups ) . "_" . $orientation . \IPS\Member::loggedIn()->timezone );
|
||||
$this->cacheKey = "widget_{$this->key}_" . $this->uniqueKey . '_' . md5( json_encode( $configuration ) . "_" . Member::loggedIn()->language()->id . "_" . Member::loggedIn()->skin . "_" . json_encode( Member::loggedIn()->groups ) . "_" . $orientation . Member::loggedIn()->timezone );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +74,9 @@ class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'calendar.css', 'calendar' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'calendar.css', 'calendar' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
@@ -70,24 +84,24 @@ class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param null|Form $form Form object
|
||||
* @return Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
public function configuration( Form &$form=null ): Form
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
|
||||
/* Container */
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'widget_calendar', isset( $this->configuration['widget_calendar'] ) ? $this->configuration['widget_calendar'] : 0, FALSE, array(
|
||||
$form->add( new Node( 'widget_calendar', $this->configuration['widget_calendar'] ?? 0, FALSE, array(
|
||||
'class' => '\IPS\calendar\Calendar',
|
||||
'zeroVal' => 'all',
|
||||
'permissionCheck' => 'view',
|
||||
'multiple' => true
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'auto_hide', isset( $this->configuration['auto_hide'] ) ? $this->configuration['auto_hide'] : FALSE, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'days_ahead', isset( $this->configuration['days_ahead'] ) ? $this->configuration['days_ahead'] : 7, TRUE, array( 'unlimited' => -1 ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'maximum_count', isset( $this->configuration['maximum_count'] ) ? $this->configuration['maximum_count'] : 5, TRUE, array( 'unlimited' => -1 ) ) );
|
||||
$form->add( new YesNo( 'auto_hide', $this->configuration['auto_hide'] ?? FALSE, FALSE ) );
|
||||
$form->add( new Number( 'days_ahead', $this->configuration['days_ahead'] ?? 7, TRUE, array( 'unlimited' => -1 ) ) );
|
||||
$form->add( new Number( 'maximum_count', $this->configuration['maximum_count'] ?? 5, TRUE, array( 'unlimited' => -1 ) ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -97,9 +111,9 @@ class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
* @param array $values Values from form
|
||||
* @return array
|
||||
*/
|
||||
public function preConfig( $values )
|
||||
public function preConfig( array $values ): array
|
||||
{
|
||||
if ( \is_array( $values['widget_calendar'] ) )
|
||||
if ( is_array( $values['widget_calendar'] ) )
|
||||
{
|
||||
$values['widget_calendar'] = array_keys( $values['widget_calendar'] );
|
||||
}
|
||||
@@ -112,14 +126,14 @@ class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'calendar', 'calendar' ) ) )
|
||||
if( !Member::loggedIn()->canAccessModule( Module::get( 'calendar', 'calendar' ) ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$_today = new \IPS\calendar\Date( "now", \IPS\Member::loggedIn()->timezone ? new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) : NULL );
|
||||
$_today = new Date( "now", Member::loggedIn()->timezone ? new DateTimeZone( Member::loggedIn()->timezone ) : NULL );
|
||||
|
||||
/* Do we have a days ahead cutoff? */
|
||||
$endDate = NULL;
|
||||
@@ -156,10 +170,10 @@ class _upcomingEvents extends \IPS\Widget\PermissionCache
|
||||
$noneClubCalendars = \IPS\calendar\Calendar::roots();
|
||||
}
|
||||
|
||||
$events = \IPS\calendar\Event::retrieveEvents( $_today, $endDate, ( $calendars === NULL ? array_keys($noneClubCalendars ) : ( !\is_array( $calendars ) ? array( $calendars ) : $calendars ) ), $count, FALSE );
|
||||
|
||||
$events = Event::retrieveEvents( $_today, $endDate, ( $calendars === NULL ? array_keys( $noneClubCalendars ) : ( !\is_array( $calendars ) ? array( $calendars ) : $calendars ) ), $count, FALSE );
|
||||
|
||||
/* Auto hiding? */
|
||||
if( !\count($events) AND isset( $this->configuration['auto_hide'] ) AND $this->configuration['auto_hide'] )
|
||||
if( !count($events) AND isset( $this->configuration['auto_hide'] ) AND $this->configuration['auto_hide'] )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user