mirror of
https://github.com/friendica/friendica
synced 2025-04-23 10:30:11 +00:00
Lists and tweet search moved
This commit is contained in:
parent
d696c8d101
commit
9c61bd3ffc
6 changed files with 225 additions and 184 deletions
172
include/api.php
172
include/api.php
|
@ -1014,112 +1014,6 @@ function api_media_metadata_create($type)
|
|||
|
||||
api_register_func('api/media/metadata/create', 'api_media_metadata_create', true, API_METHOD_POST);
|
||||
|
||||
/**
|
||||
* Returns statuses that match a specified query.
|
||||
*
|
||||
* @see https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
|
||||
*
|
||||
* @param string $type Return format: json, xml, atom, rss
|
||||
*
|
||||
* @return array|string
|
||||
* @throws BadRequestException if the "q" parameter is missing.
|
||||
* @throws ForbiddenException
|
||||
* @throws ImagickException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
function api_search($type)
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($_REQUEST['q'])) {
|
||||
throw new BadRequestException('q parameter is required.');
|
||||
}
|
||||
|
||||
$searchTerm = trim(rawurldecode($_REQUEST['q']));
|
||||
|
||||
$data = [];
|
||||
$data['status'] = [];
|
||||
$count = 15;
|
||||
$exclude_replies = !empty($_REQUEST['exclude_replies']);
|
||||
if (!empty($_REQUEST['rpp'])) {
|
||||
$count = $_REQUEST['rpp'];
|
||||
} elseif (!empty($_REQUEST['count'])) {
|
||||
$count = $_REQUEST['count'];
|
||||
}
|
||||
|
||||
$since_id = $_REQUEST['since_id'] ?? 0;
|
||||
$max_id = $_REQUEST['max_id'] ?? 0;
|
||||
$page = $_REQUEST['page'] ?? 1;
|
||||
|
||||
$start = max(0, ($page - 1) * $count);
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||
if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
|
||||
$searchTerm = $matches[1];
|
||||
$condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, $uid];
|
||||
$tags = DBA::select('tag-search-view', ['uri-id'], $condition);
|
||||
$uriids = [];
|
||||
while ($tag = DBA::fetch($tags)) {
|
||||
$uriids[] = $tag['uri-id'];
|
||||
}
|
||||
DBA::close($tags);
|
||||
|
||||
if (empty($uriids)) {
|
||||
return DI::apiResponse()->formatData('statuses', $type, $data);
|
||||
}
|
||||
|
||||
$condition = ['uri-id' => $uriids];
|
||||
if ($exclude_replies) {
|
||||
$condition['gravity'] = GRAVITY_PARENT;
|
||||
}
|
||||
|
||||
$params['group_by'] = ['uri-id'];
|
||||
} else {
|
||||
$condition = ["`id` > ?
|
||||
" . ($exclude_replies ? " AND `gravity` = " . GRAVITY_PARENT : ' ') . "
|
||||
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
||||
AND `body` LIKE CONCAT('%',?,'%')",
|
||||
$since_id, $uid, $_REQUEST['q']];
|
||||
if ($max_id > 0) {
|
||||
$condition[0] .= ' AND `id` <= ?';
|
||||
$condition[] = $max_id;
|
||||
}
|
||||
}
|
||||
|
||||
$statuses = [];
|
||||
|
||||
if (parse_url($searchTerm, PHP_URL_SCHEME) != '') {
|
||||
$id = Item::fetchByLink($searchTerm, $uid);
|
||||
if (!$id) {
|
||||
// Public post
|
||||
$id = Item::fetchByLink($searchTerm);
|
||||
}
|
||||
|
||||
if (!empty($id)) {
|
||||
$statuses = Post::select([], ['id' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
$statuses = $statuses ?: Post::selectForUser($uid, [], $condition, $params);
|
||||
|
||||
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
|
||||
|
||||
$ret = [];
|
||||
while ($status = DBA::fetch($statuses)) {
|
||||
$ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
|
||||
}
|
||||
DBA::close($statuses);
|
||||
|
||||
$data['status'] = $ret;
|
||||
|
||||
return DI::apiResponse()->formatData('statuses', $type, $data);
|
||||
}
|
||||
|
||||
api_register_func('api/search/tweets', 'api_search', true);
|
||||
api_register_func('api/search', 'api_search', true);
|
||||
|
||||
/**
|
||||
* Repeats a status.
|
||||
*
|
||||
|
@ -1330,72 +1224,6 @@ function api_lists_ownerships($type)
|
|||
|
||||
api_register_func('api/lists/ownerships', 'api_lists_ownerships', true);
|
||||
|
||||
/**
|
||||
* Returns recent statuses from users in the specified group.
|
||||
*
|
||||
* @param string $type Return type (atom, rss, xml, json)
|
||||
*
|
||||
* @return array|string
|
||||
* @throws BadRequestException
|
||||
* @throws ForbiddenException
|
||||
* @throws ImagickException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws UnauthorizedException
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships
|
||||
*/
|
||||
function api_lists_statuses($type)
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
if (empty($_REQUEST['list_id'])) {
|
||||
throw new BadRequestException('list_id not specified');
|
||||
}
|
||||
|
||||
// params
|
||||
$count = $_REQUEST['count'] ?? 20;
|
||||
$page = $_REQUEST['page'] ?? 1;
|
||||
$since_id = $_REQUEST['since_id'] ?? 0;
|
||||
$max_id = $_REQUEST['max_id'] ?? 0;
|
||||
$exclude_replies = (!empty($_REQUEST['exclude_replies']) ? 1 : 0);
|
||||
$conversation_id = $_REQUEST['conversation_id'] ?? 0;
|
||||
|
||||
$start = max(0, ($page - 1) * $count);
|
||||
|
||||
$groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]);
|
||||
$gids = array_column($groups, 'contact-id');
|
||||
$condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids];
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
|
||||
|
||||
if ($max_id > 0) {
|
||||
$condition[0] .= " AND `id` <= ?";
|
||||
$condition[] = $max_id;
|
||||
}
|
||||
if ($exclude_replies > 0) {
|
||||
$condition[0] .= ' AND `gravity` = ?';
|
||||
$condition[] = GRAVITY_PARENT;
|
||||
}
|
||||
if ($conversation_id > 0) {
|
||||
$condition[0] .= " AND `parent` = ?";
|
||||
$condition[] = $conversation_id;
|
||||
}
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||
$statuses = Post::selectForUser($uid, [], $condition, $params);
|
||||
|
||||
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
|
||||
|
||||
$items = [];
|
||||
while ($status = DBA::fetch($statuses)) {
|
||||
$items[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
|
||||
}
|
||||
DBA::close($statuses);
|
||||
|
||||
return DI::apiResponse()->formatData("statuses", $type, ['status' => $items], Contact::getPublicIdByUserId($uid));
|
||||
}
|
||||
|
||||
api_register_func('api/lists/statuses', 'api_lists_statuses', true);
|
||||
|
||||
/**
|
||||
* Returns either the friends of the follower list
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue