$userlist = [];
if (!empty($_GET['q'])) {
- $r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", DBA::escape($_GET["q"]));
-
- if (!DBA::isResult($r)) {
- $r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", DBA::escape($_GET["q"]));
- }
+ $contacts = Contact::selectToArray(
+ ['id'],
+ [
+ '`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)',
+ $_GET['q'],
+ $_GET['q'],
+ $_GET['q'],
+ $_GET['q'],
+ ]
+ );
- if (DBA::isResult($r)) {
+ if (DBA::isResult($contacts)) {
$k = 0;
- foreach ($r as $user) {
- $user_info = api_get_user($a, $user["id"]);
+ foreach ($contacts as $contact) {
+ $user_info = api_get_user($a, $contact['id']);
- if ($type == "xml") {
- $userlist[$k++.":user"] = $user_info;
+ if ($type == 'xml') {
+ $userlist[$k++ . ':user'] = $user_info;
} else {
$userlist[] = $user_info;
}
}
- $userlist = ["users" => $userlist];
+ $userlist = ['users' => $userlist];
} else {
- throw new BadRequestException("User ".$_GET["q"]." not found.");
+ throw new NotFoundException('User ' . $_GET['q'] . ' not found.');
}
} else {
- throw new BadRequestException("No user specified.");
+ throw new BadRequestException('No search term specified.');
}
- return api_format_data("users", $type, $userlist);
+ return api_format_data('users', $type, $userlist);
}
/// @TODO move to top of file or somewhere better
$a = \get_app();
$user_info = api_get_user($a);
- if (api_user() === false || $user_info === false) { throw new ForbiddenException(); }
+ if (api_user() === false || $user_info === false) {
+ throw new ForbiddenException();
+ }
if (empty($_REQUEST['q'])) {
throw new BadRequestException('q parameter is required.');
}
}
- $statuses = Item::selectForUser(api_user(), [], $condition, $params);
+ $statuses = [];
+
+ if (parse_url($searchTerm, PHP_URL_SCHEME) != '') {
+ $id = Item::fetchByLink($searchTerm, api_user());
+ if (!$id) {
+ // Public post
+ $id = Item::fetchByLink($searchTerm);
+ }
+
+ if (!empty($id)) {
+ $statuses = Item::select([], ['id' => $id]);
+ }
+ }
+
+ $statuses = $statuses ?: Item::selectForUser(api_user(), [], $condition, $params);
$data['status'] = api_format_items(Item::inArray($statuses), $user_info);
$start = max(0, ($page - 1) * $count);
- $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ?
- AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND `thread`.`mention` AND NOT `thread`.`ignored`)",
+ $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ? AND `mention`
+ AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND NOT `thread`.`ignored`)",
api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['pid'], api_user()];
if ($max_id > 0) {
'attendyes' => [],
'attendno' => [],
'attendmaybe' => [],
+ 'announce' => [],
];
- $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
+ $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY];
$ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
while ($parent_item = Item::fetch($ret)) {
case Activity::ATTENDMAYBE:
$activities['attendmaybe'][] = $user;
break;
+ case Activity::ANNOUNCE:
+ $activities['announce'][] = $user;
+ break;
default:
break;
}
*
* @param string $type Return type (atom, rss, xml, json)
*
+ * @param int $rel A contact relationship constant
* @return array|string|void
* @throws BadRequestException
* @throws ForbiddenException
* @throws UnauthorizedException
* @todo use api_format_data() to return data
*/
-function api_ff_ids($type)
+function api_ff_ids($type, int $rel)
{
if (!api_user()) {
throw new ForbiddenException();
$stringify_ids = $_REQUEST['stringify_ids'] ?? false;
- $r = q(
- "SELECT `pcontact`.`id` FROM `contact`
- INNER JOIN `contact` AS `pcontact` ON `contact`.`nurl` = `pcontact`.`nurl` AND `pcontact`.`uid` = 0
- WHERE `contact`.`uid` = %s AND NOT `contact`.`self`",
- intval(api_user())
+ $contacts = DBA::p("SELECT `pcontact`.`id`
+ FROM `contact`
+ INNER JOIN `contact` AS `pcontact`
+ ON `contact`.`nurl` = `pcontact`.`nurl`
+ AND `pcontact`.`uid` = 0
+ WHERE `contact`.`uid` = ?
+ AND NOT `contact`.`self`
+ AND `contact`.`rel` IN (?, ?)",
+ api_user(),
+ $rel,
+ Contact::FRIEND
);
- if (!DBA::isResult($r)) {
- return;
- }
$ids = [];
- foreach ($r as $rr) {
+ foreach (DBA::toArray($contacts) as $contact) {
if ($stringify_ids) {
- $ids[] = $rr['id'];
+ $ids[] = $contact['id'];
} else {
- $ids[] = intval($rr['id']);
+ $ids[] = intval($contact['id']);
}
}
- return api_format_data("ids", $type, ['id' => $ids]);
+ return api_format_data('ids', $type, ['id' => $ids]);
}
/**
* @return array|string
* @throws BadRequestException
* @throws ForbiddenException
+ * @throws ImagickException
+ * @throws InternalServerErrorException
+ * @throws UnauthorizedException
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
*/
function api_friends_ids($type)
{
- return api_ff_ids($type);
+ return api_ff_ids($type, Contact::SHARING);
}
/**
* @return array|string
* @throws BadRequestException
* @throws ForbiddenException
+ * @throws ImagickException
+ * @throws InternalServerErrorException
+ * @throws UnauthorizedException
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids
*/
function api_followers_ids($type)
{
- return api_ff_ids($type);
+ return api_ff_ids($type, Contact::FOLLOWER);
}
/// @TODO move to top of file or somewhere better
// traditional DFRN
$contact = DBA::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
-
- if (!DBA::isResult($contact) || ($contact['network'] !== Protocol::DFRN)) {
+ if (!DBA::isResult($contact)) {
throw new BadRequestException("Unknown contact");
}
$cid = $contact['id'];
- $dfrn_id = $contact['issued-id'] ?? $contact['dfrn-id'];
+ $dfrn_id = $contact['issued-id'] ?: $contact['dfrn-id'];
+
+ if (($contact['network'] !== Protocol::DFRN) || empty($dfrn_id)) {
+ System::externalRedirect($url ?: $c_url);
+ }
if ($contact['duplex'] && $contact['issued-id']) {
$orig_id = $contact['issued-id'];