From: Hypolite Petovan Date: Sun, 16 Feb 2020 16:20:17 +0000 (-0500) Subject: [API] Add new endpoint api/friendica/events X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d3b3f716f82d312fb000b11fa6554580078b6bb8;p=friendica.git [API] Add new endpoint api/friendica/events --- 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 ]], ], ],