From 2801efd795a6c4a1583f01120afb0b2df9b7372f Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 14 Feb 2020 06:31:12 +0100 Subject: [PATCH] API add events_show This PR is pripared via proxy by Marco R. See [this thread in the Developers forum](https://forum.friendi.ca/display/3e98eba8-215e-45b9-c311-c93505586413). --- include/api.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/api.php b/include/api.php index 567e3cc439..4317fd4252 100644 --- a/include/api.php +++ b/include/api.php @@ -426,6 +426,54 @@ function api_error($type, $e, App\Arguments $args) return $return; } +function api_events_show($type) +{ + $a = \get_app(); + + $user_info = api_get_user($a); + + if (api_user() === false || $user_info === false) + { + throw new ForbiddenException(); + } + + $since_id = $_REQUEST['since_id'] ?? 0; + $count = $_REQUEST['count'] ?? 20; + $condition = ["`id` > ? AND (`uid` = 0 OR (`uid` = ?))", $since_id, api_user()]; + $params = ['limit'=> $count]; + $terms = DBA::select('event',[] , $condition, $params); + + $events = []; + while ($term = DBA::fetch($terms)) + { + $events[] = [ + 'id' => intval($term['id']), + 'uid' => intval($term['uid']), + 'cid' => $term['cid'], + 'uri' => $term['uri'], + 'summary' => $term['summary'], + 'desc' => BBCode::convert($term['desc']), + 'start' => $term['start'], + 'finish' => $term['finish'], + 'type' => $term['type'], + 'nofinish' => $term['nofinish'], + 'location' => $term['location'], + 'adjust' => $term['adjust'], + 'ignore' => $term['ignore'], + 'allow_cid' => $term['allow_cid'], + 'allow_gid' => $term['allow_gid'], + 'deny_cid' => $term['deny_cid'], + 'deny_gid' => $term['deny_gid'] + ]; + } + + DBA::close($terms); + + return api_format_data('events', $type, ['events' => $events]); + } + + api_register_func('api/friendica/events/show', 'api_events_show', true); + /** * Set values for RSS template *