use Friendica\Object\Image;
use Friendica\Protocol\Activity;
use Friendica\Security\BasicAuth;
-use Friendica\Security\OAuth;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
define('API_LOG_PREFIX', 'API {action} - ');
$API = [];
-$called_api = [];
/**
* Get source name from API client
*/
function api_call(App $a, App\Arguments $args = null)
{
- global $API, $called_api;
+ global $API;
if ($args == null) {
$args = DI::args();
throw new MethodNotAllowedException();
}
- $called_api = explode("/", $p);
-
if (!empty($info['auth']) && BaseApi::getCurrentUserID() === false) {
BasicAuth::getCurrentUserID(true);
Logger::info(API_LOG_PREFIX . 'nickname {nickname}', ['module' => 'api', 'action' => 'call', 'nickname' => $a->getLoggedInUserNickname()]);
*/
function api_get_user($contact_id = null)
{
- global $called_api;
-
$user = null;
$extra_query = "";
$url = "";
Logger::info(API_LOG_PREFIX . 'Fetching data for user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $contact_id]);
// Searching for contact URL
- if (!is_null($contact_id) && (intval($contact_id) == 0)) {
+ if (intval($contact_id) == 0) {
$user = Strings::normaliseLink($contact_id);
$url = $user;
$extra_query = "AND `contact`.`nurl` = ? ";
}
// Searching for contact id with uid = 0
- if (!is_null($contact_id) && (intval($contact_id) != 0)) {
+ if (intval($contact_id) != 0) {
$user = api_unique_id_to_nurl(intval($contact_id));
if ($user == "") {
}
}
- if (is_null($user) && !empty($_GET['user_id'])) {
- $user = api_unique_id_to_nurl($_GET['user_id']);
-
- if ($user == "") {
- throw new BadRequestException("User ID ".$_GET['user_id']." not found.");
- }
-
- $url = $user;
- $extra_query = "AND `contact`.`nurl` = ? ";
- if (BaseApi::getCurrentUserID() !== false) {
- $extra_query .= "AND `contact`.`uid`=" . intval(BaseApi::getCurrentUserID());
- }
- }
- if (is_null($user) && !empty($_GET['screen_name'])) {
- $user = $_GET['screen_name'];
- $extra_query = "AND `contact`.`nick` = ? ";
- if (BaseApi::getCurrentUserID() !== false) {
- $extra_query .= "AND `contact`.`uid`=".intval(BaseApi::getCurrentUserID());
- }
- }
-
- if (is_null($user) && !empty($_GET['profileurl'])) {
- $user = Strings::normaliseLink($_GET['profileurl']);
- $extra_query = "AND `contact`.`nurl` = ? ";
- if (BaseApi::getCurrentUserID() !== false) {
- $extra_query .= "AND `contact`.`uid`=".intval(BaseApi::getCurrentUserID());
- }
- }
-
- // $called_api is the API path exploded on / and is expected to have at least 2 elements
- if (is_null($user) && (DI::args()->getArgc() > (count($called_api) - 1)) && (count($called_api) > 0)) {
- $argid = count($called_api);
- if (!empty(DI::args()->getArgv()[$argid])) {
- $data = explode(".", DI::args()->getArgv()[$argid]);
- if (count($data) > 1) {
- [$user, $null] = $data;
- }
- }
- if (is_numeric($user)) {
- $user = api_unique_id_to_nurl(intval($user));
-
- if ($user != "") {
- $url = $user;
- $extra_query = "AND `contact`.`nurl` = ? ";
- if (BaseApi::getCurrentUserID() !== false) {
- $extra_query .= "AND `contact`.`uid`=" . intval(BaseApi::getCurrentUserID());
- }
- }
- } else {
- $extra_query = "AND `contact`.`nick` = ? ";
- if (BaseApi::getCurrentUserID() !== false) {
- $extra_query .= "AND `contact`.`uid`=" . intval(BaseApi::getCurrentUserID());
- }
- }
- }
-
Logger::info(API_LOG_PREFIX . 'getting user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user]);
if (!$user) {
- if (empty(BaseApi::getCurrentUserID())) {
- BasicAuth::getCurrentUserID(true);
- return false;
- } else {
- $user = BaseApi::getCurrentUserID();
- $extra_query = "AND `contact`.`uid` = ? AND `contact`.`self` ";
- }
+ return false;
}
Logger::info(API_LOG_PREFIX . 'found user {user}', ['module' => 'api', 'action' => 'get_user', 'user' => $user, 'extra_query' => $extra_query]);
*/
function api_statuses_repeat($type)
{
- global $called_api;
-
$a = DI::app();
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
}
// output the post that we just posted.
- $called_api = [];
return api_status_show($type, $item_id);
}
*/
function api_favorites($type)
{
- global $called_api;
-
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
- $called_api = [];
-
// in friendica starred item are private
// return favorites only for self
Logger::info(API_LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites', 'self' => $user_info['self']]);
use Friendica\Profile\ProfileField\Collection\ProfileFields;
use Friendica\Content\Text\BBCode;
use Friendica\DI;
-use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
$profiles[] = $profile;
}
- // return settings, authenticated user and profiles data
- $self = Contact::selectFirst(['nurl'], ['uid' => $uid, 'self' => true]);
-
$result = [
'multi_profiles' => false,
'global_dir' => $directory,
- 'friendica_owner' => self::getUser($self['nurl']),
+ 'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
'profiles' => $profiles
];
use Friendica\Network\HTTPException;
use Friendica\Security\BasicAuth;
use Friendica\Security\OAuth;
-use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData;
-use Friendica\Util\XML;
-
-require_once __DIR__ . '/../../include/api.php';
class BaseApi extends BaseModule
{
}
}
}
-
- /**
- * Get user info array.
- *
- * @param int|string $contact_id Contact ID or URL
- * @return array|bool
- * @throws HTTPException\BadRequestException
- * @throws HTTPException\InternalServerErrorException
- * @throws HTTPException\UnauthorizedException
- * @throws \ImagickException
- */
- protected static function getUser($contact_id = null)
- {
- return api_get_user($contact_id);
- }
}
*/
public function testApiGetUserWithGetId()
{
- // $_GET['user_id'] = $this->otherUser['id'];
// self::assertOtherUser(api_get_user());
}
public function testApiGetUserWithWrongGetId()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- // $_GET['user_id'] = $this->wrongUserId;
// self::assertOtherUser(api_get_user());
}
*/
public function testApiGetUserWithGetName()
{
- // $_GET['screen_name'] = $this->selfUser['nick'];
// self::assertSelfUser(api_get_user());
}
*/
public function testApiGetUserWithGetUrl()
{
- // $_GET['profileurl'] = $this->selfUser['nurl'];
// self::assertSelfUser(api_get_user());
}
public function testApiSearchWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_search('json');
}
public function testApiStatusesHomeTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_home_timeline('json');
}
public function testApiStatusesPublicTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_public_timeline('json');
}
public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_networkpublic_timeline('json');
}
public function testApiStatusesShowWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_show('json');
}
public function testApiConversationShowWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_conversation_show('json');
}
public function testApiStatusesMentionsWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_mentions('json');
}
public function testApiStatusesUserTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_statuses_user_timeline('json');
}
public function testApiFavoritesWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_favorites('json');
}
public function testApiListsStatusesWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_lists_statuses('json');
}
public function testApiDirectMessagesBoxWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- $_GET['screen_name'] = $this->selfUser['nick'];
BasicAuth::setCurrentUserID();
api_direct_messages_box('json', 'sentbox', 'false');
}