From d3b3f716f82d312fb000b11fa6554580078b6bb8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 16 Feb 2020 11:20:17 -0500 Subject: [PATCH] [API] Add new endpoint api/friendica/events --- src/Module/Api/Friendica/Events/Index.php | 75 +++++++++++++++++++++++ static/routes.config.php | 1 + 2 files changed, 76 insertions(+) create mode 100644 src/Module/Api/Friendica/Events/Index.php diff --git a/src/Module/Api/Friendica/Events/Index.php b/src/Module/Api/Friendica/Events/Index.php new file mode 100644 index 0000000000..f5924e8a08 --- /dev/null +++ b/src/Module/Api/Friendica/Events/Index.php @@ -0,0 +1,75 @@ +. + * + */ + +namespace Friendica\Module\Api\Friendica\Events; + +use Friendica\Content\Text\BBCode; +use Friendica\Database\DBA; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException; + +/** + * api/friendica/events + * + * @package Friendica\Module\Api\Friendica\Events + */ +class Index extends BaseApi +{ + public static function rawContent(array $parameters = []) + { + if (self::login() === false) { + throw new HTTPException\ForbiddenException(); + } + + $since_id = $_REQUEST['since_id'] ?? 0; + $count = $_REQUEST['count'] ?? 20; + + $condition = ["`id` > ? AND `uid` = ?", $since_id, self::$current_user_id]; + $params = ['limit' => $count]; + $events = DBA::selectToArray('event', [], $condition, $params); + + $items = []; + foreach ($events as $event) { + $items[] = [ + 'id' => intval($event['id']), + 'uid' => intval($event['uid']), + 'cid' => $event['cid'], + 'uri' => $event['uri'], + 'name' => $event['summary'], + 'desc' => BBCode::convert($event['desc']), + 'startTime' => $event['start'], + 'endTime' => $event['finish'], + 'type' => $event['type'], + 'nofinish' => $event['nofinish'], + 'place' => $event['location'], + 'adjust' => $event['adjust'], + 'ignore' => $event['ignore'], + 'allow_cid' => $event['allow_cid'], + 'allow_gid' => $event['allow_gid'], + 'deny_cid' => $event['deny_cid'], + 'deny_gid' => $event['deny_gid'] + ]; + } + + echo self::format('events', ['events' => $items]); + exit; + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 489e99f48d..300503d19d 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -55,6 +55,7 @@ return [ ], '/friendica' => [ '/profile/show' => [Module\Api\Friendica\Profile\Show::class , [R::GET ]], + '/events' => [Module\Api\Friendica\Events\Index::class , [R::GET ]], ], ],