mirror of
https://github.com/friendica/friendica
synced 2025-04-25 13:50:10 +00:00
More functions moved
This commit is contained in:
parent
97719ca207
commit
44555cddb8
9 changed files with 464 additions and 395 deletions
74
src/Module/Api/Twitter/Users/Search.php
Normal file
74
src/Module/Api/Twitter/Users/Search.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Twitter\Users;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException\BadRequestException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
|
||||
/**
|
||||
* Search a public user account.
|
||||
*
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search
|
||||
*/
|
||||
class Search extends BaseApi
|
||||
{
|
||||
public function rawContent()
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$userlist = [];
|
||||
|
||||
if (!empty($_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($contacts)) {
|
||||
$k = 0;
|
||||
foreach ($contacts as $contact) {
|
||||
$user_info = DI::twitterUser()->createFromContactId($contact['id'], $uid, false)->toArray();
|
||||
|
||||
$userlist[] = $user_info;
|
||||
}
|
||||
$userlist = ['users' => $userlist];
|
||||
} else {
|
||||
throw new NotFoundException('User ' . $_GET['q'] . ' not found.');
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException('No search term specified.');
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('users', ['user' => $userlist], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue