use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Model\Verb;
-use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
-use Friendica\Util\Proxy;
use Friendica\Util\Strings;
require_once __DIR__ . '/../mod/item.php';
/**
* Set values for RSS template
*
- * @param App $a
* @param array $arr Array to be passed to template
* @param array $user_info User info
* @return array
* @throws UnauthorizedException
* @todo find proper type-hints
*/
-function api_rss_extra(App $a, $arr, $user_info)
+function api_rss_extra($arr, $user_info)
{
if (is_null($user_info)) {
- $user_info = api_get_user();
+ $uid = BaseApi::getCurrentUserID();
+ if (empty($uid)) {
+ throw new ForbiddenException();
+ }
+
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
}
$arr['$user'] = $user_info;
*/
function api_item_get_user(App $a, $item)
{
- $status_user = api_get_user($item['author-id'] ?? null);
+ $status_user = DI::twitterUser()->createFromContactId($item['author-id'] ?? null, BaseApi::getCurrentUserID())->toArray();
$author_user = $status_user;
$status_user["protected"] = isset($item['private']) && ($item['private'] == Item::PRIVATE);
if (($item['thr-parent'] ?? '') == ($item['uri'] ?? '')) {
- $owner_user = api_get_user($item['owner-id'] ?? null);
+ $owner_user = DI::twitterUser()->createFromContactId($item['owner-id'] ?? null, BaseApi::getCurrentUserID())->toArray();
} else {
$owner_user = $author_user;
}
*/
function api_account_verify_credentials($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
unset($_REQUEST["user_id"]);
unset($_GET["user_id"]);
$skip_status = $_REQUEST['skip_status'] ?? false;
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
// "verified" isn't used here in the standard
unset($user_info["verified"]);
{
$a = DI::app();
- if (api_user() === false) {
- logger::notice('api_statuses_update: no user');
- throw new ForbiddenException();
- }
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+
$_REQUEST['profile_uid'] = api_user();
$_REQUEST['api_source'] = true;
$txt = requestdata('status') ?? '';
{
$a = DI::app();
- if (api_user() === false) {
- logger::notice('api_statuses_update: no user');
- throw new ForbiddenException();
- }
-
- api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// convert $_POST array items to the form we use for web posts.
if (requestdata('htmlstatus')) {
{
$a = DI::app();
- if (api_user() === false) {
- logger::notice('no user');
- throw new ForbiddenException();
- }
-
- api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
if (empty($_FILES['media'])) {
// Output error
*/
function api_media_metadata_create($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- Logger::info('no user');
- throw new ForbiddenException();
- }
-
- api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$postdata = Network::postdata();
*/
function api_users_show($type)
{
- $a = Friendica\DI::app();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$item = api_get_last_status($user_info['pid'], $user_info['uid']);
if (!empty($item)) {
*/
function api_users_search($type)
{
- $a = DI::app();
-
$userlist = [];
if (!empty($_GET['q'])) {
if (DBA::isResult($contacts)) {
$k = 0;
foreach ($contacts as $contact) {
- $user_info = api_get_user($contact['id']);
+ $user_info = DI::twitterUser()->createFromContactId($contact['id'], BaseApi::getCurrentUserID())->toArray();
if ($type == 'xml') {
$userlist[$k++ . ':user'] = $user_info;
*/
function api_search($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
if (empty($_REQUEST['q'])) {
throw new BadRequestException('q parameter is required.');
*/
function api_statuses_home_timeline($type)
{
- $a = DI::app();
- $user_info = api_get_user();
-
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
unset($_REQUEST["user_id"]);
unset($_GET["user_id"]);
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_statuses_public_timeline($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
// get last network messages
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_statuses_networkpublic_timeline($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$since_id = $_REQUEST['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0;
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_statuses_show($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
*/
function api_conversation_show($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
$a = DI::app();
- if (api_user() === false) {
- throw new ForbiddenException();
- }
-
- api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
*/
function api_statuses_destroy($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
-
- api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
*/
function api_statuses_mentions($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
unset($_REQUEST["user_id"]);
unset($_GET["user_id"]);
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_statuses_user_timeline($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
Logger::info('api_statuses_user_timeline', ['api_user' => api_user(), 'user_info' => $user_info, '_REQUEST' => $_REQUEST]);
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_favorites_create_destroy($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// for versioned api.
/// @TODO We need a better global soluton
throw new InternalServerErrorException("DB error");
}
-
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$rets = api_format_items([$item], $user_info, false, $type);
$ret = $rets[0];
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
{
global $called_api;
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$called_api = [];
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_format_items_activities($item, $type = "json")
{
- $a = DI::app();
-
$activities = [
'like' => [],
'dislike' => [],
//builtin_activity_puller($i, $activities);
// get user data and add it to the array of the activity
- $user = api_get_user($parent_item['author-id']);
+ $user = DI::twitterUser()->createFromContactId($parent_item['author-id'], BaseApi::getCurrentUserID())->toArray();
switch ($parent_item['verb']) {
case Activity::LIKE:
$activities['like'][] = $user;
*/
function api_format_items($items, $user_info, $filter_user = false, $type = "json")
{
- $a = Friendica\DI::app();
+ $a = DI::app();
$ret = [];
*/
function api_format_item($item, $type = "json", $status_user = null, $author_user = null, $owner_user = null)
{
- $a = Friendica\DI::app();
+ $a = DI::app();
if (empty($status_user) || empty($author_user) || empty($owner_user)) {
[$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
if (!empty($announce)) {
$retweeted_item = $item;
$item = $announce;
- $status['friendica_owner'] = api_get_user($announce['author-id']);
+ $status['friendica_owner'] = DI::twitterUser()->createFromContactId($announce['author-id'], BaseApi::getCurrentUserID())->toArray();
}
}
$quoted_status['text'] = $conv_quoted['text'];
$quoted_status['statusnet_html'] = $conv_quoted['html'];
try {
- $quoted_status["user"] = api_get_user($quoted_item["author-id"]);
+ $quoted_status["user"] = DI::twitterUser()->createFromContactId($quoted_item['author-id'], BaseApi::getCurrentUserID())->toArray();
} catch (BadRequestException $e) {
// user not found. should be found?
/// @todo check if the user should be always found
unset($retweeted_status['statusnet_conversation_id']);
$status['user'] = $status['friendica_owner'];
try {
- $retweeted_status["user"] = api_get_user($retweeted_item["author-id"]);
+ $retweeted_status["user"] = DI::twitterUser()->createFromContactId($retweeted_item['author-id'], BaseApi::getCurrentUserID())->toArray();
} catch (BadRequestException $e) {
// user not found. should be found?
/// @todo check if the user should be always found
*/
function api_lists_ownerships($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$uid = $user_info['uid'];
$groups = DBA::select('group', [], ['deleted' => 0, 'uid' => $uid]);
*/
function api_lists_statuses($type)
{
- $a = DI::app();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- $user_info = api_get_user();
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
unset($_REQUEST["user_id"]);
unset($_GET["user_id"]);
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_statuses_f($qtype)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
// pagination
$count = $_GET['count'] ?? 20;
$start = max(0, ($page - 1) * $count);
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
if (!empty($_GET['cursor']) && $_GET['cursor'] == 'undefined') {
/* this is to stop Hotot to load friends multiple times
// @todo This query most likely can be replaced with a Contact::select...
$r = DBA::toArray(DBA::p(
- "SELECT `nurl`
+ "SELECT `id`
FROM `contact`
WHERE `uid` = ?
AND NOT `self`
$ret = [];
foreach ($r as $cid) {
- $user = api_get_user($cid['nurl']);
+ $user = DI::twitterUser()->createFromContactId($cid['id'], BaseApi::getCurrentUserID())->toArray();
// "uid" and "self" are only needed for some internal stuff, so remove it from here
unset($user["uid"]);
unset($user["self"]);
*/
function api_direct_messages_new($type)
{
- $a = DI::app();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
- if (api_user() === false) {
+ $uid = BaseApi::getCurrentUserID();
+ if (empty($uid)) {
throw new ForbiddenException();
}
-
+
if (empty($_POST["text"]) || empty($_POST["screen_name"]) && empty($_POST["user_id"])) {
return;
}
- $sender = api_get_user();
+ $sender = DI::twitterUser()->createFromUserId($uid)->toArray();
$recipient = null;
if (!empty($_POST['screen_name'])) {
// Selecting the id by priority, friendica first
api_best_nickname($contacts);
- $recipient = api_get_user($contacts[0]['nurl']);
+ $recipient = DI::twitterUser()->createFromContactId($contacts[0]['id'], $uid)->toArray();
}
} else {
$recipient = api_get_user($_POST['user_id']);
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $sender);
+ $data = api_rss_extra($data, $sender);
break;
}
*/
function api_direct_messages_destroy($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
//required
$id = $_REQUEST['id'] ?? 0;
// optional
*/
function api_direct_messages_box($type, $box, $verbose)
{
- $a = DI::app();
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+
// params
$count = $_GET['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1;
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
- $user_info = api_get_user();
- if ($user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+
$profile_url = $user_info["url"];
// pagination
foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info;
- $sender = api_get_user(Strings::normaliseLink($item['contact-url']));
+ $sender = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
- $recipient = api_get_user(Strings::normaliseLink($item['contact-url']));
+ $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
$sender = $user_info;
}
case "atom":
break;
case "rss":
- $data = api_rss_extra($a, $data, $user_info);
+ $data = api_rss_extra($data, $user_info);
break;
}
*/
function api_account_update_profile($type)
{
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+
$local_user = api_user();
- $api_user = api_get_user();
+
+ $api_user = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
if (!empty($_POST['name'])) {
DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]);
*/
function prepare_photo_data($type, $scale, $photo_id)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
- if ($user_info === false) {
- throw new ForbiddenException();
- }
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$scale_sql = ($scale === false ? "" : sprintf("AND scale=%d", intval($scale)));
$data_sql = ($scale === false ? "" : "data, ");
*/
function api_friendica_group_show($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['gid'] ?? 0;
$uid = $user_info['uid'];
$user_element = "users";
$k = 0;
foreach ($members as $member) {
- $user = api_get_user($member['nurl']);
+ $user = DI::twitterUser()->createFromContactId($member['contact-id'], BaseApi::getCurrentUserID())->toArray();
$users[$k++.":user"] = $user;
}
} else {
$user_element = "user";
foreach ($members as $member) {
- $user = api_get_user($member['nurl']);
+ $user = DI::twitterUser()->createFromContactId($member['contact-id'], BaseApi::getCurrentUserID())->toArray();
$users[] = $user;
}
}
*/
function api_lists_destroy($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['list_id'] ?? 0;
$uid = $user_info['uid'];
*/
function api_friendica_group_create($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$name = $_REQUEST['name'] ?? '';
$uid = $user_info['uid'];
$json = json_decode($_POST['json'], true);
*/
function api_lists_create($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$name = $_REQUEST['name'] ?? '';
$uid = $user_info['uid'];
*/
function api_friendica_group_update($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$uid = $user_info['uid'];
$gid = $_REQUEST['gid'] ?? 0;
$name = $_REQUEST['name'] ?? '';
*/
function api_lists_update($type)
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['list_id'] ?? 0;
$name = $_REQUEST['name'] ?? '';
$uid = $user_info['uid'];
*/
function api_friendica_notification_seen($type)
{
- $a = DI::app();
- $user_info = api_get_user();
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
if (DI::args()->getArgc() !== 4) {
throw new BadRequestException('Invalid argument count');
}
*/
function api_friendica_direct_messages_search($type, $box = "")
{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
// params
- $user_info = api_get_user();
+ $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$searchstring = $_REQUEST['searchstring'] ?? '';
$uid = $user_info['uid'];
foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info;
- $sender = api_get_user(Strings::normaliseLink($item['contact-url']));
+ $sender = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
- $recipient = api_get_user(Strings::normaliseLink($item['contact-url']));
+ $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
$sender = $user_info;
}