diff --git a/include/api.php b/include/api.php index d5cd270fc..cf7767757 100644 --- a/include/api.php +++ b/include/api.php @@ -486,9 +486,8 @@ function api_unique_id_to_nurl($id) * * @param object $a App * @param int|string $contact_id Contact ID or URL - * @param string $type Return type (for errors) */ -function api_get_user(App $a, $contact_id = null, $type = "json") +function api_get_user(App $a, $contact_id = null) { global $called_api; @@ -2019,6 +2018,13 @@ function api_statuses_mentions($type) api_register_func('api/statuses/mentions', 'api_statuses_mentions', true); api_register_func('api/statuses/replies', 'api_statuses_mentions', true); +/** + * @brief Returns a user's public timeline + * + * @param string $type Either "json" or "xml" + * @return string|array + * @throws ForbiddenException + */ function api_statuses_user_timeline($type) { $a = get_app(); @@ -2028,7 +2034,6 @@ function api_statuses_user_timeline($type) } $user_info = api_get_user($a); - // get last network messages logger( "api_statuses_user_timeline: api_user: ". api_user() . @@ -2037,18 +2042,18 @@ function api_statuses_user_timeline($type) LOGGER_DEBUG ); - // params - $count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20); - $page = (x($_REQUEST, 'page') ? $_REQUEST['page'] -1 : 0); - if ($page < 0) { - $page = 0; - } - $since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0); - //$since_id = 0;//$since_id = (x($_REQUEST, 'since_id')?$_REQUEST['since_id'] : 0); - $exclude_replies = (x($_REQUEST, 'exclude_replies') ? 1 : 0); - $conversation_id = (x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0); + $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0; + $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0; + $exclude_replies = x($_REQUEST, 'exclude_replies') ? 1 : 0; + $conversation_id = x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0; - $start = $page * $count; + // 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 ($user_info['self'] == 1) { @@ -2058,10 +2063,15 @@ function api_statuses_user_timeline($type) if ($exclude_replies > 0) { $sql_extra .= ' AND `item`.`parent` = `item`.`id`'; } + if ($conversation_id > 0) { $sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id); } + if ($max_id > 0) { + $sql_extra .= ' AND `item`.`id` <= ' . intval($max_id); + } + $r = q( "SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, @@ -2074,7 +2084,7 @@ function api_statuses_user_timeline($type) AND `item`.`contact-id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` $sql_extra - AND `item`.`id`>%d + AND `item`.`id` > %d ORDER BY `item`.`id` DESC LIMIT %d ,%d ", intval(api_user()), dbesc(ACTIVITY_POST), @@ -2901,11 +2911,16 @@ function api_lists_list($type) api_register_func('api/lists/list', 'api_lists_list', true); /** - * https://dev.twitter.com/docs/api/1/get/statuses/friends - * This function is deprecated by Twitter - * returns: json, xml + * @brief Returns either the friends of the follower list + * + * Note: Considers friends and followers lists to be private and won't return + * anything if any user_id parameter is passed. + * + * @param string $qtype Either "friends" or "followers" + * @return boolean|array + * @throws ForbiddenException */ -function api_statuses_f($type, $qtype) +function api_statuses_f($qtype) { $a = get_app(); @@ -2913,9 +2928,17 @@ function api_statuses_f($type, $qtype) throw new ForbiddenException(); } + // pagination + $count = x($_GET, 'count') ? $_GET['count'] : 20; + $page = x($_GET, 'page') ? $_GET['page'] : 1; + if ($page < 1) { + $page = 1; + } + $start = ($page - 1) * $count; + $user_info = api_get_user($a); - if (x($_GET, 'cursor') && $_GET['cursor']=='undefined') { + if (x($_GET, 'cursor') && $_GET['cursor'] == 'undefined') { /* this is to stop Hotot to load friends multiple times * I'm not sure if I'm missing return something or * is a bug in hotot. Workaround, meantime @@ -2939,8 +2962,17 @@ function api_statuses_f($type, $qtype) } $r = q( - "SELECT `nurl` FROM `contact` WHERE `uid` = %d AND NOT `self` AND (NOT `blocked` OR `pending`) $sql_extra ORDER BY `nick`", - intval(api_user()) + "SELECT `nurl` + FROM `contact` + WHERE `uid` = %d + AND NOT `self` + AND (NOT `blocked` OR `pending`) + $sql_extra + ORDER BY `nick` + LIMIT %d, %d", + intval(api_user()), + intval($start), + intval($count) ); $ret = array(); @@ -2956,21 +2988,37 @@ function api_statuses_f($type, $qtype) } return array('user' => $ret); - } + +/** + * @brief Returns the list of friends of the provided user + * + * @deprecated By Twitter API in favor of friends/list + * + * @param string $type Either "json" or "xml" + * @return boolean|string|array + */ function api_statuses_friends($type) { - $data = api_statuses_f($type, "friends"); + $data = api_statuses_f("friends"); if ($data === false) { return false; } return api_format_data("users", $type, $data); } +/** + * @brief Returns the list of friends of the provided user + * + * @deprecated By Twitter API in favor of friends/list + * + * @param string $type Either "json" or "xml" + * @return boolean|string|array + */ function api_statuses_followers($type) { - $data = api_statuses_f($type, "followers"); + $data = api_statuses_f("followers"); if ($data === false) { return false; } diff --git a/src/Model/Group.php b/src/Model/Group.php index 542827151..26bab7f45 100644 --- a/src/Model/Group.php +++ b/src/Model/Group.php @@ -57,15 +57,12 @@ class Group extends BaseObject /** * @brief Get a list of group ids a contact belongs to * - * @todo Get rid of $uid, the contact id already bears the information - * - * @param int $uid * @param int $cid * @return array */ - private static function getByContactIdForUserId($uid, $cid) + private static function getIdsByContactId($cid) { - $condition = ['uid' => $uid, 'contact-id' => $cid]; + $condition = ['contact-id' => $cid]; $stmt = dba::select('group_member', ['gid'], $condition); $return = []; @@ -369,7 +366,7 @@ class Group extends BaseObject $member_of = array(); if ($cid) { - $member_of = self::getByContactIdForUserId(local_user(), $cid); + $member_of = self::getIdsByContactId($cid); } while ($group = dba::fetch($stmt)) {