mirror of
https://github.com/friendica/friendica
synced 2025-04-26 19:10:11 +00:00
Merge pull request #4097 from Rudloff/feature/search_api
Implement search API (fixes #929)
This commit is contained in:
commit
7a6706b0f7
2 changed files with 77 additions and 0 deletions
|
@ -1485,6 +1485,65 @@ function api_users_search($type)
|
|||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/users/search', 'api_users_search');
|
||||
|
||||
/**
|
||||
* 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 UnauthorizedException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
function api_search($type)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
if (!x($_REQUEST, 'q')) {
|
||||
throw new BadRequestException("q parameter is required.");
|
||||
}
|
||||
|
||||
if (x($_REQUEST, 'rpp')) {
|
||||
$count = $_REQUEST['rpp'];
|
||||
} elseif (x($_REQUEST, 'count')) {
|
||||
$count = $_REQUEST['count'];
|
||||
} else {
|
||||
$count = 15;
|
||||
}
|
||||
|
||||
$since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
|
||||
$max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0);
|
||||
$page = (x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0);
|
||||
|
||||
$start = $page * $count;
|
||||
|
||||
if ($max_id > 0) {
|
||||
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
|
||||
}
|
||||
|
||||
$r = dba::p(
|
||||
"SELECT ".item_fieldlists()."
|
||||
FROM `item` ".item_joins()."
|
||||
WHERE ".item_condition()." AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))
|
||||
AND `item`.`body` LIKE CONCAT('%',?,'%')
|
||||
$sql_extra
|
||||
AND `item`.`id`>?
|
||||
ORDER BY `item`.`id` DESC LIMIT ".intval($start)." ,".intval($count)." ",
|
||||
api_user(),
|
||||
$_REQUEST['q'],
|
||||
$since_id
|
||||
);
|
||||
|
||||
$data['status'] = api_format_items(dba::inArray($r), api_get_user(get_app()));
|
||||
|
||||
return api_format_data("statuses", $type, $data);
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/search/tweets', 'api_search', true);
|
||||
api_register_func('api/search', 'api_search', true);
|
||||
|
||||
/**
|
||||
*
|
||||
* http://developer.twitter.com/doc/get/statuses/home_timeline
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue