Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+95 -32
View File
@@ -32,6 +32,7 @@ class _events extends \IPS\Content\Api\ItemController
* GET /calendar/events
* Get list of events
*
* @note For requests using an OAuth Access Token for a particular member, only events the authorized user can view will be included
* @apiparam string calendars Comma-delimited list of calendar IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only events started by those members are returned
* @apiparam int locked If 1, only events which are locked are returned, if 0 only unlocked
@@ -40,6 +41,7 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam string sortBy What to sort by. Can be 'date' for creation date, 'title' or leave unspecified for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event>
*/
public function GETindex()
@@ -56,7 +58,7 @@ class _events extends \IPS\Content\Api\ItemController
* View information about a specific event
*
* @param int $id ID Number
* @throws 1F294/1 INVALID_ID The event ID does not exist
* @throws 1F294/1 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\calendar\Event
*/
public function GETitem( $id )
@@ -75,10 +77,11 @@ class _events extends \IPS\Content\Api\ItemController
* POST /calendar/events
* Create an event
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock events).
* @reqapiparam int calendar The ID number of the calendar the event should be created in
* @reqapiparam int author The ID number of the member creating the event (0 for guest)
* @apiparam int author The ID number of the member creating the event (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
* @reqapiparam string title The event title
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>")
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
* @reqapiparam datetime start The event start date/time
* @apiparam datetime end The event end date/time
* @apiparam string recurrence If this event recurs, the ICS recurrence definition
@@ -87,8 +90,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam \IPS\GeoLocation location The location where the event is taking place
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam datetime date The date/time that should be used for the event/post post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the event/post. If not provided, will use the IP address from the API request
* @apiparam datetime date The date/time that should be used for the event/post post date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string ip_address The IP address that should be stored for the event/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam int locked 1/0 indicating if the event should be locked
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int featured 1/0 indicating if the event should be featured
@@ -98,6 +101,7 @@ class _events extends \IPS\Content\Api\ItemController
* @throws 1L296/9 NO_DESC No description was supplied
* @throws 1L296/A INVALID_START The start date is invalid
* @throws 1L296/B INVALID_END The end date is invalid
* @throws 2L296/C NO_PERMISSION The authorized user does not have permission to create an event in that calendar
* @return \IPS\calendar\Event
*/
public function POSTindex()
@@ -113,17 +117,28 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Get author */
if ( \IPS\Request::i()->author )
if ( $this->member )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
if ( !$calendar->can( 'add', $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L296/7', 400 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L296/C', 403 );
}
$author = $this->member;
}
else
{
$author = new \IPS\Member;
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L296/7', 400 );
}
}
else
{
$author = new \IPS\Member;
}
}
/* Check we have a title and a description */
@@ -158,17 +173,18 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Do it */
return new \IPS\Api\Response( 201, $this->_create( $calendar, $author )->apiOutput() );
return new \IPS\Api\Response( 201, $this->_create( $calendar, $author )->apiOutput( $this->member ) );
}
/**
* POST /calendar/events/{id}
* Edit an event
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock topics).
* @reqapiparam int calendar The ID number of the calendar the event should be created in
* @reqapiparam int author The ID number of the member creating the event (0 for guest)
* @reqapiparam int author The ID number of the member creating the event (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @reqapiparam string title The event title
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>")
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
* @reqapiparam datetime start The event start date/time
* @apiparam datetime end The event end date/time
* @apiparam string recurrence If this event recurs, the ICS recurrence definition
@@ -177,16 +193,17 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam \IPS\GeoLocation location The location where the event is taking place
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam datetime date The date/time that should be used for the event/post post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the event/post. If not provided, will use the IP address from the API request
* @apiparam datetime date The date/time that should be used for the event/post post date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string ip_address The IP address that should be stored for the event/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam int locked 1/0 indicating if the event should be locked
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int featured 1/0 indicating if the event should be featured
* @throws 1L296/I INVALID_ID The event ID is invalid
* @throws 1L296/D NO_CALENDAR The calendar ID does not exist
* @throws 1L296/I INVALID_ID The event ID is invalid or the authorized user does not have permission to view it
* @throws 1L296/D NO_CALENDAR The calendar ID does not exist or the authorized user does not have permission to post in it
* @throws 1L296/E NO_AUTHOR The author ID does not exist
* @throws 1L296/G INVALID_START The start date is invalid
* @throws 1L296/H INVALID_END The end date is invalid
* @throws 2L296/D NO_PERMISSION The authorized user does not have permission to edit the topic
* @return \IPS\calendar\Event
*/
public function POSTitem( $id )
@@ -194,13 +211,26 @@ class _events extends \IPS\Content\Api\ItemController
try
{
$event = \IPS\calendar\Event::load( $id );
if ( $this->member and !$event->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$event->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L296/D', 403 );
}
/* New calendar */
if ( isset( \IPS\Request::i()->calendar ) and \IPS\Request::i()->calendar != $event->forum_id )
if ( isset( \IPS\Request::i()->calendar ) and \IPS\Request::i()->calendar != $event->calendar_id and ( !$this->member or $event->canMove( $this->member ) ) )
{
try
{
$newCalendar = \IPS\calendar\Calendar::load( \IPS\Request::i()->calendar );
if ( $this->member and !$newCalendar->can( 'add', $this->member ) )
{
throw new \OutOfRangeException;
}
$event->move( $newCalendar );
}
catch ( \OutOfRangeException $e )
@@ -210,7 +240,7 @@ class _events extends \IPS\Content\Api\ItemController
}
/* New author */
if ( isset( \IPS\Request::i()->author ) )
if ( !$this->member and isset( \IPS\Request::i()->author ) )
{
try
{
@@ -253,11 +283,11 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Everything else */
$this->_createOrUpdate( $event );
$this->_createOrUpdate( $event, 'edit' );
/* Save and return */
$event->save();
return new \IPS\Api\Response( 200, $event->apiOutput() );
return new \IPS\Api\Response( 200, $event->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -273,7 +303,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only comments which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @throws 2L296/2 INVALID_ID The event ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 2L296/2 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event\Comment>
*/
public function GETitem_comments( $id )
@@ -296,7 +327,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only comments which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @throws 2L296/3 INVALID_ID The event ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 2L296/3 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event\Review>
*/
public function GETitem_reviews( $id )
@@ -316,7 +348,7 @@ class _events extends \IPS\Content\Api\ItemController
* Get RSVPs on an event
*
* @param int $id ID Number
* @throws 2L296/3 INVALID_ID The event ID does not exist
* @throws 2L296/3 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return array
* @apiresponse [\IPS\Member] attending Members that have confirmed they are attending the event
* @apiresponse [\IPS\Member] notAttending Members that have confirmed they are not attending the event
@@ -327,16 +359,21 @@ class _events extends \IPS\Content\Api\ItemController
try
{
$event = \IPS\calendar\Event::load( $id );
if ( $this->member and !$event->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
}
$attendees = $event->attendees();
return new \IPS\Api\Response( 200, array(
'attending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[1] ) ),
'notAttending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[0] ) ),
'maybeAttending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[2] ) ),
) );
}
@@ -350,10 +387,12 @@ class _events extends \IPS\Content\Api\ItemController
* PUT /calendar/events/{id}/rsvps/{member_id}
* RSVP a member to an event
*
* @note For requests using an OAuth Access Token for a particular member, the member ID must be the authorized member's ID
* @reqapiparam int response 0 = Not attending; 1 = attending; 2 = maybe attending
* @param int $id Event ID NUmber
* @param int $memberId Member ID NUmber
* @throws 2L296/J INVALID_ID The event ID does not exist
* @throws 2L296/K INVALID_MEMBER The member ID was not valid
* @return void
*/
public function PUTitem_rsvps( $id, $memberId )
@@ -363,6 +402,11 @@ class _events extends \IPS\Content\Api\ItemController
throw new \IPS\Api\Exception( 'INVALID_RESPONSE', '1L296/L', 400 );
}
if ( $this->member and $memberId != $this->member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '2L296/K', 404 );
}
try
{
$event = \IPS\calendar\Event::load( $id );
@@ -401,12 +445,19 @@ class _events extends \IPS\Content\Api\ItemController
* DELETE /calendar/events/{id}/rsvps/{member_id}
* Remove a member from RSVP list
*
* @note For requests using an OAuth Access Token for a particular member, the member ID must be the authorized member's ID
* @param int $id Event ID NUmber
* @param int $memberId Member ID NUmber
* @return void
* @throws 2L296/K INVALID_MEMBER The member ID was not valid
*/
public function DELETEitem_rsvps( $id, $memberId )
{
if ( $this->member and $memberId != $this->member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '2L296/K', 404 );
}
\IPS\Db::i()->delete( 'calendar_event_rsvp', array( 'rsvp_event_id=? AND rsvp_member_id=?', intval( $id ), intval( $memberId ) ) );
return new \IPS\Api\Response( 200, NULL );
}
@@ -415,9 +466,10 @@ class _events extends \IPS\Content\Api\ItemController
* Create or update event
*
* @param \IPS\Content\Item $item The item
* @param string $type add or edit
* @return \IPS\Content\Item
*/
protected function _createOrUpdate( \IPS\Content\Item $item )
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
{
/* Start/End date */
$startDate = new \IPS\DateTime( \IPS\Request::i()->start );
@@ -440,10 +492,15 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Description */
$item->content = \IPS\Request::i()->description;
$descriptionContents = \IPS\Request::i()->description;
if ( $this->member )
{
$descriptionContents = \IPS\Text\Parser::parseStatic( $descriptionContents, TRUE, NULL, $this->member, 'calendar_Calendar' );
}
$item->content = $descriptionContents;
/* RSVP */
if ( isset( \IPS\Request::i()->rsvp ) )
if ( isset( \IPS\Request::i()->rsvp ) and ( !$this->member or $item->container()->can( 'askrsvp', $this->member ) ) )
{
$item->rsvp = intval( \IPS\Request::i()->rsvp );
if ( $item->rsvp and isset( \IPS\Request::i()->rsvpLimit ) and \IPS\Request::i()->rsvpLimit )
@@ -475,7 +532,7 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Pass up */
return parent::_createOrUpdate( $item );
return parent::_createOrUpdate( $item, $type );
}
/**
@@ -490,7 +547,13 @@ class _events extends \IPS\Content\Api\ItemController
{
try
{
\IPS\calendar\Event::load( $id )->delete();
$item = \IPS\calendar\Event::load( $id );
if ( $this->member and !$item->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/B', 404 );
}
$item->delete();
return new \IPS\Api\Response( 200, NULL );
}