2022-07-22 17:46:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2022-07-22 17:46:18 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Friendica\Events;
|
|
|
|
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Worker;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Event;
|
|
|
|
use Friendica\Model\Conversation;
|
|
|
|
use Friendica\Model\Item;
|
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\Network\HTTPException;
|
2022-12-30 21:20:28 +00:00
|
|
|
use Friendica\Protocol\Delivery;
|
2022-07-22 17:46:18 +00:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API endpoint: /api/friendica/event_create
|
|
|
|
*/
|
|
|
|
class Create extends BaseApi
|
|
|
|
{
|
|
|
|
protected function post(array $request = [])
|
|
|
|
{
|
|
|
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
|
|
|
$uid = BaseApi::getCurrentUserID();
|
|
|
|
|
|
|
|
// params
|
|
|
|
$request = $this->getRequest([
|
2022-07-24 09:49:18 +00:00
|
|
|
'id' => 0, //if provided, event will be amended
|
|
|
|
'name' => '', //summary of the event
|
|
|
|
'desc' => '', //description in BBCode
|
|
|
|
'start_time' => '', //start_time, required
|
|
|
|
'end_time' => '', //endtime, required if nofinish false
|
|
|
|
'place' => '', //location of the event
|
|
|
|
'publish' => 0, //publish message
|
|
|
|
'allow_cid' => '', //array of allowed person, if access restricted
|
2023-05-13 23:54:35 +00:00
|
|
|
'allow_gid' => '', //array of allowed circles, if access restricted
|
2022-07-24 09:49:18 +00:00
|
|
|
'deny_cid' => '', //array of denied person, if access restricted
|
2023-05-13 23:54:35 +00:00
|
|
|
'deny_gid' => '', //array of denied circles, if access restricted
|
2022-07-22 17:46:18 +00:00
|
|
|
], $request);
|
|
|
|
|
|
|
|
// error if no name specified
|
|
|
|
if (empty($request['name'])) {
|
|
|
|
throw new HTTPException\BadRequestException('event name not specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
// error startDate is not specified
|
2022-07-24 09:49:18 +00:00
|
|
|
if (empty($request['start_time'])) {
|
2022-07-22 17:46:18 +00:00
|
|
|
throw new HTTPException\BadRequestException('startDate not specified');
|
|
|
|
}
|
|
|
|
|
2022-07-24 09:49:18 +00:00
|
|
|
// nofinish if end_time is not specified
|
|
|
|
if (empty($request['end_time'])) {
|
2022-07-22 17:46:18 +00:00
|
|
|
$finish = DBA::NULL_DATETIME;
|
|
|
|
$nofinish = true;
|
|
|
|
} else {
|
2022-07-24 09:49:18 +00:00
|
|
|
$finish = DateTimeFormat::convert($request['end_time'], 'UTC', DI::app()->getTimeZone());
|
2022-07-22 17:46:18 +00:00
|
|
|
$nofinish = false;
|
|
|
|
}
|
|
|
|
|
2022-07-24 09:49:18 +00:00
|
|
|
$start = DateTimeFormat::convert($request['start_time'], 'UTC', DI::app()->getTimeZone());
|
2022-07-22 17:46:18 +00:00
|
|
|
|
|
|
|
// create event
|
|
|
|
$event = [];
|
|
|
|
|
2022-07-24 09:49:18 +00:00
|
|
|
$event['id'] = $request['id'];
|
|
|
|
$event['uid'] = $uid;
|
|
|
|
$event['type'] = 'event';
|
|
|
|
$event['summary'] = $request['name'];
|
|
|
|
$event['desc'] = $request['desc'];
|
|
|
|
$event['location'] = $request['place'];
|
2022-10-07 19:39:24 +00:00
|
|
|
$event['start'] = $start;
|
|
|
|
$event['finish'] = $finish;
|
2022-07-24 09:49:18 +00:00
|
|
|
$event['nofinish'] = $nofinish;
|
2022-07-22 17:46:18 +00:00
|
|
|
|
|
|
|
$event['allow_cid'] = $request['allow_cid'];
|
|
|
|
$event['allow_gid'] = $request['allow_gid'];
|
|
|
|
$event['deny_cid'] = $request['deny_cid'];
|
|
|
|
$event['deny_gid'] = $request['deny_gid'];
|
|
|
|
$event['publish'] = $request['publish'];
|
|
|
|
|
|
|
|
$event_id = Event::store($event);
|
|
|
|
|
|
|
|
if (!empty($request['publish'])) {
|
|
|
|
$item = ['network' => Protocol::DFRN, 'protocol' => Conversation::PARCEL_DIRECT, 'direction' => Conversation::PUSH];
|
|
|
|
$item = Event::getItemArrayForId($event_id, $item);
|
|
|
|
if (Item::insert($item)) {
|
2022-10-17 05:49:55 +00:00
|
|
|
Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$item['uri-id'], $uid);
|
2022-07-22 17:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = ['success' => true, 'event_id' => $event_id, 'event' => $event];
|
|
|
|
|
|
|
|
$this->response->exit('event_create', ['$result' => $result], $this->parameters['extension'] ?? null);
|
|
|
|
}
|
|
|
|
}
|