/// @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
$sql_extra = " AND false ";
}
+ if ($qtype == 'blocks') {
+ $sql_blocked = 'AND `blocked`';
+ } else {
+ $sql_blocked = 'AND NOT `blocked`';
+ }
+
$r = q(
"SELECT `nurl`
FROM `contact`
WHERE `uid` = %d
AND NOT `self`
- AND (NOT `blocked` OR `pending`)
+ $sql_blocked
+ AND NOT `pending`
$sql_extra
ORDER BY `nick`
LIMIT %d, %d",
api_register_func('api/statuses/friends', 'api_statuses_friends', true);
api_register_func('api/statuses/followers', 'api_statuses_followers', true);
+/**
+ * Returns the list of blocked users
+ *
+ * @see https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-blocks-list
+ *
+ * @param string $type Either "json" or "xml"
+ *
+ * @return boolean|string|array
+ * @throws UnauthorizedException
+ */
+function api_blocks_list($type)
+{
+ $data = api_statuses_f('blocks');
+ if ($data === false) {
+ return false;
+ }
+ return api_format_data("users", $type, $data);
+}
+
+/// @TODO move to top of file or somewhere better
+api_register_func('api/blocks/list', 'api_blocks_list', true);
+
function api_statusnet_config($type)
{
$a = get_app();