+/**
+ * Return user objects
+ *
+ * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup
+ *
+ * @param string $type Return format: json or xml
+ *
+ * @return array|string
+ * @throws UnauthorizedException
+ * @throws NotFoundException
+ */
+function api_users_lookup($type)
+{
+ $users = array();
+
+ if (x($_REQUEST['user_id'])) {
+ foreach (explode(',', $_REQUEST['user_id']) as $id) {
+ if (!empty($id)) {
+ $users[] = api_get_user(get_app(), $id);
+ }
+ }
+ }
+
+ if (empty($users)) {
+ throw new NotFoundException;
+ }
+
+ return api_format_data("users", $type, array('users' => $users));
+}
+
+/// @TODO move to top of file or somewhere better
+api_register_func('api/users/lookup', 'api_users_lookup', true);
+
+/**
+ * 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);
+