diff --git a/doc/api.md b/doc/api.md index ca355eef6..159bc6991 100644 --- a/doc/api.md +++ b/doc/api.md @@ -338,6 +338,15 @@ Friendica doesn't allow showing the friends of other users. #### Unsupported parameters * trim_user +--- +### statuses/networkpublic_timeline (*; AUTH) +#### Parameters +* count: Items per page (default: 20) +* page: page number +* since_id: minimum id +* max_id: maximum id +* include_entities: "true" shows entities for pictures and links (Default: false) + --- ### statuses/replies (*; AUTH) #### Parameters diff --git a/include/api.php b/include/api.php index cf7767757..7256c1778 100644 --- a/include/api.php +++ b/include/api.php @@ -1660,6 +1660,71 @@ function api_statuses_public_timeline($type) /// @TODO move to top of file or somewhere better api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline', true); +/** + * @brief Returns the list of public federated posts this node knows about + * + * @param string $type Return format: json, xml, atom, rss + * @return array|string + * @throws ForbiddenException + */ +function api_statuses_networkpublic_timeline($type) +{ + $a = get_app(); + + if (api_user() === false) { + throw new ForbiddenException(); + } + + $user_info = api_get_user($a); + + $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0; + $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0; + + // pagination + $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 20; + $page = x($_REQUEST, 'page') ? $_REQUEST['page'] : 1; + if ($page < 1) { + $page = 1; + } + $start = ($page - 1) * $count; + + $sql_extra = ''; + if ($max_id > 0) { + $sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id); + } + + $r = dba::p("SELECT " . item_fieldlists() . " + FROM `thread` + INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + " . item_joins() . " + WHERE `thread`.`uid` = 0 + AND `verb` = ? + AND `item`.`id` > ? + $sql_extra + ORDER BY `thread`.`iid` DESC + LIMIT " . intval($start) . ", " . intval($count), + ACTIVITY_POST, + $since_id + ); + + $r = dba::inArray($r); + + $ret = api_format_items($r, $user_info, false, $type); + + $data = array('status' => $ret); + switch ($type) { + case "atom": + case "rss": + $data = api_rss_extra($a, $data, $user_info); + break; + } + + return api_format_data("statuses", $type, $data); +} + +/// @TODO move to top of file or somewhere better +api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpublic_timeline', true); + /** * @TODO nothing to say? */