}
}
-/**
- * Set values for RSS template
- *
- * @param array $arr Array to be passed to template
- * @param array $user_info User info
- * @return array
- * @throws BadRequestException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- * @todo find proper type-hints
- */
-function api_rss_extra($arr, $user_info)
-{
- if (is_null($user_info)) {
- $uid = BaseApi::getCurrentUserID();
- if (empty($uid)) {
- throw new ForbiddenException();
- }
-
- $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
- }
-
- $arr['$user'] = $user_info;
- $arr['$rss'] = [
- 'alternate' => $user_info['url'],
- 'self' => DI::baseUrl() . "/" . DI::args()->getQueryString(),
- 'base' => DI::baseUrl(),
- 'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
- 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
- 'language' => $user_info['lang'],
- 'logo' => DI::baseUrl() . "/images/friendica-32.png",
- ];
-
- return $arr;
-}
-
/**
* TWITTER API
*/
function api_account_verify_credentials($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
unset($_REQUEST['user_id']);
unset($_GET['user_id']);
$skip_status = $_REQUEST['skip_status'] ?? false;
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();
// "verified" isn't used here in the standard
unset($user_info["verified"]);
}
// "uid" and "self" are only needed for some internal stuff, so remove it from here
- unset($user_info["uid"]);
- unset($user_info["self"]);
+ unset($user_info['uid']);
+ unset($user_info['self']);
return DI::apiResponse()->formatData("user", $type, ['user' => $user_info]);
}
*/
function api_statuses_mediap($type)
{
- $a = DI::app();
-
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
- $_REQUEST['profile_uid'] = BaseApi::getCurrentUserID();
+ $a = DI::app();
+
+ $_REQUEST['profile_uid'] = $uid;
$_REQUEST['api_source'] = true;
$txt = requestdata('status') ?? '';
*/
function api_statuses_update($type)
{
- $a = DI::app();
-
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
+
+ $a = DI::app();
// convert $_POST array items to the form we use for web posts.
if (requestdata('htmlstatus')) {
if (requestdata('lat') && requestdata('long')) {
$_REQUEST['coord'] = sprintf("%s %s", requestdata('lat'), requestdata('long'));
}
- $_REQUEST['profile_uid'] = BaseApi::getCurrentUserID();
+ $_REQUEST['profile_uid'] = $uid;
if (!$parent) {
// Check for throttling (maximum posts per day, week and month)
if ($throttle_day > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
- $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, BaseApi::getCurrentUserID(), $datefrom];
+ $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
$posts_day = Post::count($condition);
if ($posts_day > $throttle_day) {
- logger::info('Daily posting limit reached for user '.BaseApi::getCurrentUserID());
+ logger::info('Daily posting limit reached for user ' . $uid);
// die(api_error($type, DI::l10n()->t("Daily posting limit of %d posts reached. The post was rejected.", $throttle_day));
throw new TooManyRequestsException(DI::l10n()->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day));
}
if ($throttle_week > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
- $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, BaseApi::getCurrentUserID(), $datefrom];
+ $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
$posts_week = Post::count($condition);
if ($posts_week > $throttle_week) {
- logger::info('Weekly posting limit reached for user '.BaseApi::getCurrentUserID());
+ logger::info('Weekly posting limit reached for user ' . $uid);
// die(api_error($type, DI::l10n()->t("Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week)));
throw new TooManyRequestsException(DI::l10n()->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week));
}
if ($throttle_month > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
- $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, BaseApi::getCurrentUserID(), $datefrom];
+ $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
$posts_month = Post::count($condition);
if ($posts_month > $throttle_month) {
- logger::info('Monthly posting limit reached for user '.BaseApi::getCurrentUserID());
+ logger::info('Monthly posting limit reached for user ' . $uid);
// die(api_error($type, DI::l10n()->t("Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month));
throw new TooManyRequestsException(DI::l10n()->t("Monthly posting limit of %d post reached. The post was rejected.", "Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month));
}
$media = DBA::toArray(DBA::p("SELECT `resource-id`, `scale`, `nickname`, `type`, `desc`, `filename`, `datasize`, `width`, `height` FROM `photo`
INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN
(SELECT `resource-id` FROM `photo` WHERE `id` = ?) AND `photo`.`uid` = ?
- ORDER BY `photo`.`width` DESC LIMIT 2", $id, BaseApi::getCurrentUserID()));
+ ORDER BY `photo`.`width` DESC LIMIT 2", $id, $uid));
if (!empty($media)) {
$ressources[] = $media[0]['resource-id'];
if (!empty($ressources) && !empty($item_id)) {
$item = Post::selectFirst(['uri-id', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['id' => $item_id]);
foreach ($ressources as $ressource) {
- Photo::setPermissionForRessource($ressource, BaseApi::getCurrentUserID(), $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid']);
+ Photo::setPermissionForRessource($ressource, $uid, $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid']);
}
}
function api_media_metadata_create($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
$postdata = Network::postdata();
Logger::info('Updating metadata', ['media_id' => $data['media_id']]);
- $condition = ['id' => $data['media_id'], 'uid' => BaseApi::getCurrentUserID()];
+ $condition = ['id' => $data['media_id'], 'uid' => $uid];
$photo = DBA::selectFirst('photo', ['resource-id'], $condition);
if (!DBA::isResult($photo)) {
throw new BadRequestException("Metadata not found.");
function api_users_show($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
$item = api_get_last_status($user_info['pid'], $user_info['uid']);
if (!empty($item)) {
*/
function api_users_search($type)
{
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
+
$userlist = [];
if (!empty($_GET['q'])) {
if (DBA::isResult($contacts)) {
$k = 0;
foreach ($contacts as $contact) {
- $user_info = DI::twitterUser()->createFromContactId($contact['id'], BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromContactId($contact['id'], $uid)->toArray();
if ($type == 'xml') {
$userlist[$k++ . ':user'] = $user_info;
*/
function api_users_lookup($type)
{
+ BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
+
$users = [];
if (!empty($_REQUEST['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $cid) {
if (!empty($cid) && is_numeric($cid)) {
- $users[] = DI::twitterUser()->createFromContactId((int)$cid, BaseApi::getCurrentUserID())->toArray();
+ $users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid)->toArray();
}
}
}
function api_search($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
if (empty($_REQUEST['q'])) {
throw new BadRequestException('q parameter is required.');
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
$searchTerm = $matches[1];
- $condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, BaseApi::getCurrentUserID()];
+ $condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, $uid];
$tags = DBA::select('tag-search-view', ['uri-id'], $condition);
$uriids = [];
while ($tag = DBA::fetch($tags)) {
" . ($exclude_replies ? " AND `gravity` = " . GRAVITY_PARENT : ' ') . "
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `body` LIKE CONCAT('%',?,'%')",
- $since_id, BaseApi::getCurrentUserID(), $_REQUEST['q']];
+ $since_id, $uid, $_REQUEST['q']];
if ($max_id > 0) {
$condition[0] .= ' AND `id` <= ?';
$condition[] = $max_id;
$statuses = [];
if (parse_url($searchTerm, PHP_URL_SCHEME) != '') {
- $id = Item::fetchByLink($searchTerm, BaseApi::getCurrentUserID());
+ $id = Item::fetchByLink($searchTerm, $uid);
if (!$id) {
// Public post
$id = Item::fetchByLink($searchTerm);
}
}
- $statuses = $statuses ?: Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = $statuses ?: Post::selectForUser($uid, [], $condition, $params);
$data['status'] = api_format_items(Post::toArray($statuses), $type);
function api_statuses_home_timeline($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
unset($_REQUEST['user_id']);
unset($_GET['user_id']);
$start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ?",
- BaseApi::getCurrentUserID(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
+ $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) {
$condition[0] .= " AND `id` <= ?";
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$items = Post::toArray($statuses);
bindComments($ret);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
function api_statuses_public_timeline($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// get last network messages
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$r = Post::toArray($statuses);
} else {
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$r = Post::toArray($statuses);
}
bindComments($ret);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_statuses_networkpublic_timeline($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
- $since_id = $_REQUEST['since_id'] ?? 0;
- $max_id = $_REQUEST['max_id'] ?? 0;
+ $since_id = $_REQUEST['since_id'] ?? 0;
+ $max_id = $_REQUEST['max_id'] ?? 0;
// pagination
$count = $_REQUEST['count'] ?? 20;
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::toArray(Post::selectForUser(BaseApi::getCurrentUserID(), Item::DISPLAY_FIELDLIST, $condition, $params));
+ $statuses = Post::toArray(Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params));
$ret = api_format_items($statuses, $type);
bindComments($ret);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_statuses_show($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
-
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $uid = BaseApi::getCurrentUserID();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
throw new BadRequestException(sprintf("There is no status with the id %d", $id));
}
- $item = Post::selectFirst(['id'], ['uri-id' => $uri_item['uri-id'], 'uid' => [0, BaseApi::getCurrentUserID()]], ['order' => ['uid' => true]]);
+ $item = Post::selectFirst(['id'], ['uri-id' => $uri_item['uri-id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $uri_item['uri-id']));
}
$params = [];
}
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
/// @TODO How about copying this to above methods which don't check $r ?
if (!DBA::isResult($statuses)) {
function api_conversation_show($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
-
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $uid = BaseApi::getCurrentUserID();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
throw new BadRequestException("There is no status with the id $id.");
}
- $parent = Post::selectFirst(['id'], ['uri-id' => $item['parent-uri-id'], 'uid' => [0, BaseApi::getCurrentUserID()]], ['order' => ['uid' => true]]);
+ $parent = Post::selectFirst(['id'], ['uri-id' => $item['parent-uri-id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!DBA::isResult($parent)) {
throw new BadRequestException("There is no status with this id.");
}
$id = $parent['id'];
$condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `id` > ?",
- $id, BaseApi::getCurrentUserID(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
+ $id, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) {
$condition[0] .= " AND `id` <= ?";
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
if (!DBA::isResult($statuses)) {
throw new BadRequestException("There is no status with id $id.");
function api_statuses_repeat($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
if (DBA::isResult($item) && !empty($item['body'])) {
if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
- if (!Item::performActivity($id, 'announce', BaseApi::getCurrentUserID())) {
+ if (!Item::performActivity($id, 'announce', $uid)) {
throw new InternalServerErrorException();
}
$post .= "[/share]";
}
$_REQUEST['body'] = $post;
- $_REQUEST['profile_uid'] = BaseApi::getCurrentUserID();
+ $_REQUEST['profile_uid'] = $uid;
$_REQUEST['api_source'] = true;
if (empty($_REQUEST['source'])) {
function api_statuses_destroy($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
$id = intval(DI::args()->getArgv()[3] ?? 0);
$ret = api_statuses_show($type);
- Item::deleteForUser(['id' => $id], BaseApi::getCurrentUserID());
+ Item::deleteForUser(['id' => $id], $uid);
return $ret;
}
function api_statuses_mentions($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
unset($_REQUEST['user_id']);
unset($_GET['user_id']);
$condition = [
GRAVITY_PARENT, GRAVITY_COMMENT,
- BaseApi::getCurrentUserID(),
+ $uid,
Post\UserNotification::TYPE_EXPLICIT_TAGGED | Post\UserNotification::TYPE_IMPLICIT_TAGGED |
Post\UserNotification::TYPE_THREAD_COMMENT | Post\UserNotification::TYPE_DIRECT_COMMENT |
Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT,
- BaseApi::getCurrentUserID(), $since_id,
+ $uid, $since_id,
];
if ($max_id > 0) {
array_unshift($condition, $query);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$ret = api_format_items(Post::toArray($statuses), $type);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_statuses_user_timeline($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
-
$uid = BaseApi::getCurrentUserID();
Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $_REQUEST]);
bindComments($ret);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId($uid)->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_favorites_create_destroy($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// for versioned api.
/// @TODO We need a better global soluton
$itemid = intval($_REQUEST['id'] ?? 0);
}
- $item = Post::selectFirstForUser(BaseApi::getCurrentUserID(), [], ['id' => $itemid, 'uid' => BaseApi::getCurrentUserID()]);
+ $item = Post::selectFirstForUser($uid, [], ['id' => $itemid, 'uid' => $uid]);
if (!DBA::isResult($item)) {
throw new BadRequestException("Invalid item.");
$ret = api_format_item($item, $type);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("status", $type, $data);
+ return DI::apiResponse()->formatData("status", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_favorites($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// in friendica starred item are private
// return favorites only for self
$start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `starred`",
- BaseApi::getCurrentUserID(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
+ $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$condition[] = $max_id;
}
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$ret = api_format_items(Post::toArray($statuses), $type);
bindComments($ret);
- $data = ['status' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
//builtin_activity_puller($i, $activities);
// get user data and add it to the array of the activity
- $user = DI::twitterUser()->createFromContactId($parent_item['author-id'], BaseApi::getCurrentUserID())->toArray();
+ $user = DI::twitterUser()->createFromContactId($parent_item['author-id'], $item['uid'])->toArray();
switch ($parent_item['verb']) {
case Activity::LIKE:
$activities['like'][] = $user;
*/
function api_format_item($item, $type = "json")
{
- $author_user = DI::twitterUser()->createFromContactId($item['author-id'], BaseApi::getCurrentUserID())->toArray();
- $owner_user = DI::twitterUser()->createFromContactId($item['owner-id'], BaseApi::getCurrentUserID())->toArray();
+ $author_user = DI::twitterUser()->createFromContactId($item['author-id'], $item['uid'])->toArray();
+ $owner_user = DI::twitterUser()->createFromContactId($item['owner-id'], $item['uid'])->toArray();
DI::contentItem()->localize($item);
if (!empty($announce)) {
$retweeted_item = $item;
$item = $announce;
- $status['friendica_owner'] = DI::twitterUser()->createFromContactId($announce['author-id'], BaseApi::getCurrentUserID())->toArray();
+ $status['friendica_owner'] = DI::twitterUser()->createFromContactId($announce['author-id'], $item['uid'])->toArray();
}
}
$quoted_status['text'] = $conv_quoted['text'];
$quoted_status['statusnet_html'] = $conv_quoted['html'];
try {
- $quoted_status["user"] = DI::twitterUser()->createFromContactId($quoted_item['author-id'], BaseApi::getCurrentUserID())->toArray();
+ $quoted_status["user"] = DI::twitterUser()->createFromContactId($quoted_item['author-id'], $item['uid'])->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"] = DI::twitterUser()->createFromContactId($retweeted_item['author-id'], BaseApi::getCurrentUserID())->toArray();
+ $retweeted_status["user"] = DI::twitterUser()->createFromContactId($retweeted_item['author-id'], $item['uid'])->toArray();
} catch (BadRequestException $e) {
// user not found. should be found?
/// @todo check if the user should be always found
}
// "uid" and "self" are only needed for some internal stuff, so remove it from here
- unset($status["user"]["uid"]);
- unset($status["user"]["self"]);
+ unset($status["user"]['uid']);
+ unset($status["user"]['self']);
if ($item["coord"] != "") {
$coords = explode(' ', $item["coord"]);
function api_lists_ownerships($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
- $uid = $user_info['uid'];
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
$groups = DBA::select('group', [], ['deleted' => 0, 'uid' => $uid]);
function api_lists_statuses($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
unset($_REQUEST['user_id']);
unset($_GET['user_id']);
$groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]);
$gids = array_column($groups, 'contact-id');
- $condition = ['uid' => BaseApi::getCurrentUserID(), 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids];
+ $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids];
$condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
if ($max_id > 0) {
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition, $params);
+ $statuses = Post::selectForUser($uid, [], $condition, $params);
$items = api_format_items(Post::toArray($statuses), $type);
- $data = ['status' => $items];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
- break;
- }
-
- return DI::apiResponse()->formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, ['status' => $items], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_statuses_f($qtype)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// pagination
$count = $_GET['count'] ?? 20;
$start = max(0, ($page - 1) * $count);
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
if (!empty($_GET['cursor']) && $_GET['cursor'] == 'undefined') {
/* this is to stop Hotot to load friends multiple times
$sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(Contact::FOLLOWER), intval(Contact::FRIEND));
}
- // friends and followers only for self
- if ($user_info['self'] == 0) {
- $sql_extra = " AND false ";
- }
-
if ($qtype == 'blocks') {
$sql_filter = 'AND `blocked` AND NOT `pending`';
} elseif ($qtype == 'incoming') {
$sql_extra
ORDER BY `nick`
LIMIT ?, ?",
- BaseApi::getCurrentUserID(),
+ $uid,
$start,
$count
));
$ret = [];
foreach ($r as $cid) {
- $user = DI::twitterUser()->createFromContactId($cid['id'], BaseApi::getCurrentUserID())->toArray();
+ $user = DI::twitterUser()->createFromContactId($cid['id'], $uid)->toArray();
// "uid" and "self" are only needed for some internal stuff, so remove it from here
- unset($user["uid"]);
- unset($user["self"]);
+ unset($user['uid']);
+ unset($user['self']);
if ($user) {
$ret[] = $user;
function api_direct_messages_new($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
-
$uid = BaseApi::getCurrentUserID();
if (empty($_POST["text"]) || empty($_POST['screen_name']) && empty($_POST['user_id'])) {
$replyto = '';
if (!empty($_REQUEST['replyto'])) {
- $mail = DBA::selectFirst('mail', ['parent-uri', 'title'], ['uid' => BaseApi::getCurrentUserID(), 'id' => $_REQUEST['replyto']]);
+ $mail = DBA::selectFirst('mail', ['parent-uri', 'title'], ['uid' => $uid, 'id' => $_REQUEST['replyto']]);
$replyto = $mail['parent-uri'];
$sub = $mail['title'];
} else {
$ret = ["error" => $id];
}
- $data = ['direct_message'=>$ret];
-
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, $sender);
- break;
- }
-
- return DI::apiResponse()->formatData("direct-messages", $type, $data);
+ return DI::apiResponse()->formatData("direct-messages", $type, ['direct_message' => $ret], Contact::createSelfFromUserId($uid));
}
/// @TODO move to top of file or somewhere better
function api_direct_messages_destroy($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
- // params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
//required
$id = $_REQUEST['id'] ?? 0;
// optional
$verbose = (!empty($_GET['friendica_verbose']) ? strtolower($_GET['friendica_verbose']) : "false");
/// @todo optional parameter 'include_entities' from Twitter API not yet implemented
- $uid = $user_info['uid'];
// error if no id or parenturi specified (for clients posting parent-uri as well)
if ($verbose == "true" && ($id == 0 || $parenturi == "")) {
$answer = ['result' => 'error', 'message' => 'message id or parenturi not specified'];
function api_direct_messages_box($type, $box, $verbose)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// params
$count = $_GET['count'] ?? 20;
unset($_REQUEST['screen_name']);
unset($_GET['screen_name']);
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
$profile_url = $user_info["url"];
$r = DBA::toArray(DBA::p(
"SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid` = ? AND $sql_extra AND `mail`.`id` > ? ORDER BY `mail`.`id` DESC LIMIT ?,?",
- BaseApi::getCurrentUserID(),
+ $uid,
$since_id,
$start,
$count
foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info;
- $sender = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
- $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
$sender = $user_info;
}
}
}
-
- $data = ['direct_message' => $ret];
- switch ($type) {
- case "atom":
- break;
- case "rss":
- $data = api_rss_extra($data, $user_info);
- break;
- }
-
- return DI::apiResponse()->formatData("direct-messages", $type, $data);
+ return DI::apiResponse()->formatData("direct-messages", $type, ['direct_message' => $ret], Contact::createSelfFromUserId($uid));
}
/**
function api_fr_photos_list($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
$r = DBA::toArray(DBA::p(
"SELECT `resource-id`, MAX(scale) AS `scale`, `album`, `filename`, `type`, MAX(`created`) AS `created`,
MAX(`edited`) AS `edited`, MAX(`desc`) AS `desc` FROM `photo`
WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) GROUP BY `resource-id`, `album`, `filename`, `type`",
- BaseApi::getCurrentUserID(), Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER
+ $uid, Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER
));
$typetoext = [
'image/jpeg' => 'jpg',
function api_fr_photo_create_update($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// input params
$photo_id = $_REQUEST['photo_id'] ?? null;
$mode = "update";
// check if photo is existing in databasei
- if (!Photo::exists(['resource-id' => $photo_id, 'uid' => BaseApi::getCurrentUserID(), 'album' => $album])) {
+ if (!Photo::exists(['resource-id' => $photo_id, 'uid' => $uid, 'album' => $album])) {
throw new BadRequestException("photo not available");
}
}
// checks on acl strings provided by clients
$acl_input_error = false;
- $acl_input_error |= check_acl_input($allow_cid);
- $acl_input_error |= check_acl_input($deny_cid);
- $acl_input_error |= check_acl_input($allow_gid);
- $acl_input_error |= check_acl_input($deny_gid);
+ $acl_input_error |= check_acl_input($allow_cid, $uid);
+ $acl_input_error |= check_acl_input($deny_cid, $uid);
+ $acl_input_error |= check_acl_input($allow_gid, $uid);
+ $acl_input_error |= check_acl_input($deny_gid, $uid);
if ($acl_input_error) {
throw new BadRequestException("acl data invalid");
}
// now let's upload the new media in create-mode
if ($mode == "create") {
$media = $_FILES['media'];
- $data = save_media_to_database("photo", $media, $type, $album, trim($allow_cid), trim($deny_cid), trim($allow_gid), trim($deny_gid), $desc, Photo::DEFAULT, $visibility);
+ $data = save_media_to_database("photo", $media, $type, $album, trim($allow_cid), trim($deny_cid), trim($allow_gid), trim($deny_gid), $desc, Photo::DEFAULT, $visibility, null, $uid);
// return success of updating or error message
if (!is_null($data)) {
$result = false;
if (count($updated_fields) > 0) {
$nothingtodo = false;
- $result = Photo::update($updated_fields, ['uid' => BaseApi::getCurrentUserID(), 'resource-id' => $photo_id, 'album' => $album]);
+ $result = Photo::update($updated_fields, ['uid' => $uid, 'resource-id' => $photo_id, 'album' => $album]);
} else {
$nothingtodo = true;
}
if (!empty($_FILES['media'])) {
$nothingtodo = false;
$media = $_FILES['media'];
- $data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, Photo::DEFAULT, $visibility, $photo_id);
+ $data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, Photo::DEFAULT, $visibility, $photo_id, $uid);
if (!is_null($data)) {
return DI::apiResponse()->formatData("photo_update", $type, $data);
}
function api_account_update_profile_image($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// input params
$profile_id = $_REQUEST['profile_id'] ?? 0;
// check if specified profile id is valid
if ($profile_id != 0) {
- $profile = DBA::selectFirst('profile', ['is-default'], ['uid' => BaseApi::getCurrentUserID(), 'id' => $profile_id]);
+ $profile = DBA::selectFirst('profile', ['is-default'], ['uid' => $uid, 'id' => $profile_id]);
// error message if specified profile id is not in database
if (!DBA::isResult($profile)) {
throw new BadRequestException("profile_id not available");
$media = $_FILES['media'];
}
// save new profile image
- $data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t(Photo::PROFILE_PHOTOS), "", "", "", "", "", Photo::USER_AVATAR);
+ $data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t(Photo::PROFILE_PHOTOS), "", "", "", "", "", Photo::USER_AVATAR, false, null, $uid);
// get filetype
if (is_array($media['type'])) {
// change specified profile or all profiles to the new resource-id
if ($is_default_profile) {
- $condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], BaseApi::getCurrentUserID()];
+ $condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], $uid];
Photo::update(['profile' => false, 'photo-type' => Photo::DEFAULT], $condition);
} else {
$fields = ['photo' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext,
'thumb' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext];
- DBA::update('profile', $fields, ['id' => $_REQUEST['profile'], 'uid' => BaseApi::getCurrentUserID()]);
+ DBA::update('profile', $fields, ['id' => $_REQUEST['profile'], 'uid' => $uid]);
}
- Contact::updateSelfFromUserID(BaseApi::getCurrentUserID(), true);
+ Contact::updateSelfFromUserID($uid, true);
// Update global directory in background
- Profile::publishUpdate(BaseApi::getCurrentUserID());
+ Profile::publishUpdate($uid);
// output for client
if ($data) {
function api_account_update_profile($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
- $local_user = BaseApi::getCurrentUserID();
-
- $api_user = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $api_user = DI::twitterUser()->createFromUserId($uid)->toArray();
if (!empty($_POST['name'])) {
- DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]);
- DBA::update('user', ['username' => $_POST['name']], ['uid' => $local_user]);
- Contact::update(['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]);
+ DBA::update('profile', ['name' => $_POST['name']], ['uid' => $uid]);
+ DBA::update('user', ['username' => $_POST['name']], ['uid' => $uid]);
+ Contact::update(['name' => $_POST['name']], ['uid' => $uid, 'self' => 1]);
Contact::update(['name' => $_POST['name']], ['id' => $api_user['id']]);
}
if (isset($_POST['description'])) {
- DBA::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]);
- Contact::update(['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]);
+ DBA::update('profile', ['about' => $_POST['description']], ['uid' => $uid]);
+ Contact::update(['about' => $_POST['description']], ['uid' => $uid, 'self' => 1]);
Contact::update(['about' => $_POST['description']], ['id' => $api_user['id']]);
}
- Profile::publishUpdate($local_user);
+ Profile::publishUpdate($uid);
return api_account_verify_credentials($type);
}
/**
*
* @param string $acl_string
+ * @param int $uid
* @return bool
* @throws Exception
*/
-function check_acl_input($acl_string)
+function check_acl_input($acl_string, $uid)
{
if (empty($acl_string)) {
return false;
foreach ($cid_array as $cid) {
$cid = str_replace("<", "", $cid);
$cid = str_replace(">", "", $cid);
- $condition = ['id' => $cid, 'uid' => BaseApi::getCurrentUserID()];
+ $condition = ['id' => $cid, 'uid' => $uid];
$contact_not_found |= !DBA::exists('contact', $condition);
}
return $contact_not_found;
* @param integer $phototype
* @param boolean $visibility
* @param string $photo_id
+ * @param int $uid
* @return array
* @throws BadRequestException
* @throws ForbiddenException
* @throws NotFoundException
* @throws UnauthorizedException
*/
-function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $phototype = 0, $visibility = false, $photo_id = null)
+function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $phototype, $visibility, $photo_id, $uid)
{
$visitor = 0;
$src = "";
// upload normal image (scales 0, 1, 2)
logger::info("photo upload: starting new photo upload");
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 0, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 0, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: image upload with scale 0 (original size) failed");
}
if ($width > 640 || $height > 640) {
$Image->scaleDown(640);
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: image upload with scale 1 (640x640) failed");
}
if ($width > 320 || $height > 320) {
$Image->scaleDown(320);
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: image upload with scale 2 (320x320) failed");
}
if ($width > 300 || $height > 300) {
$Image->scaleDown(300);
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 4, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 4, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: profile image upload with scale 4 (300x300) failed");
}
if ($width > 80 || $height > 80) {
$Image->scaleDown(80);
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 5, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 5, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: profile image upload with scale 5 (80x80) failed");
}
if ($width > 48 || $height > 48) {
$Image->scaleDown(48);
- $r = Photo::store($Image, BaseApi::getCurrentUserID(), $visitor, $resource_id, $filename, $album, 6, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+ $r = Photo::store($Image, $uid, $visitor, $resource_id, $filename, $album, 6, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) {
logger::notice("photo upload: profile image upload with scale 6 (48x48) failed");
}
if (!empty($r)) {
// create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo
if ($photo_id == null && $mediatype == "photo") {
- post_photo_item($resource_id, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility);
+ post_photo_item($resource_id, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility, $uid);
}
// on success return image data in json/xml format (like /api/friendica/photo does when no scale is given)
return prepare_photo_data($type, false, $resource_id);
* @param string $deny_gid
* @param string $filetype
* @param boolean $visibility
+ * @param int $uid
* @throws InternalServerErrorException
*/
-function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility = false)
+function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility, $uid)
{
// get data about the api authenticated user
- $uri = Item::newURI(intval(BaseApi::getCurrentUserID()));
- $owner_record = DBA::selectFirst('contact', [], ['uid' => BaseApi::getCurrentUserID(), 'self' => true]);
+ $uri = Item::newURI(intval($uid));
+ $owner_record = DBA::selectFirst('contact', [], ['uid' => $uid, 'self' => true]);
$arr = [];
$arr['guid'] = System::createUUID();
- $arr['uid'] = intval(BaseApi::getCurrentUserID());
+ $arr['uid'] = intval($uid);
$arr['uri'] = $uri;
$arr['type'] = 'photo';
$arr['wall'] = 1;
function prepare_photo_data($type, $scale, $photo_id)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
-
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $uid = BaseApi::getCurrentUserID();
$scale_sql = ($scale === false ? "" : sprintf("AND scale=%d", intval($scale)));
$data_sql = ($scale === false ? "" : "data, ");
FROM `photo` WHERE `uid` = ? AND `resource-id` = ? $scale_sql GROUP BY
`resource-id`, `created`, `edited`, `title`, `desc`, `album`, `filename`,
`type`, `height`, `width`, `datasize`, `profile`, `allow_cid`, `deny_cid`, `allow_gid`, `deny_gid`",
- BaseApi::getCurrentUserID(),
+ $uid,
$photo_id
));
}
// retrieve item element for getting activities (like, dislike etc.) related to photo
- $condition = ['uid' => BaseApi::getCurrentUserID(), 'resource-id' => $photo_id];
+ $condition = ['uid' => $uid, 'resource-id' => $photo_id];
$item = Post::selectFirst(['id', 'uid', 'uri', 'parent', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'], $condition);
if (!DBA::isResult($item)) {
throw new NotFoundException('Photo-related item not found.');
// retrieve comments on photo
$condition = ["`parent` = ? AND `uid` = ? AND `gravity` IN (?, ?)",
- $item['parent'], BaseApi::getCurrentUserID(), GRAVITY_PARENT, GRAVITY_COMMENT];
+ $item['parent'], $uid, GRAVITY_PARENT, GRAVITY_COMMENT];
- $statuses = Post::selectForUser(BaseApi::getCurrentUserID(), [], $condition);
+ $statuses = Post::selectForUser($uid, [], $condition);
// prepare output of comments
$commentData = api_format_items(Post::toArray($statuses), $type);
function api_friendica_group_show($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['gid'] ?? 0;
- $uid = $user_info['uid'];
// get data of the specified group id or all groups if not specified
if ($gid != 0) {
$user_element = "users";
$k = 0;
foreach ($members as $member) {
- $user = DI::twitterUser()->createFromContactId($member['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid)->toArray();
$users[$k++.":user"] = $user;
}
} else {
$user_element = "user";
foreach ($members as $member) {
- $user = DI::twitterUser()->createFromContactId($member['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid)->toArray();
$users[] = $user;
}
}
function api_lists_destroy($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['list_id'] ?? 0;
- $uid = $user_info['uid'];
// error if no gid specified
if ($gid == 0) {
'name' => $group['name'],
'id' => intval($gid),
'id_str' => (string) $gid,
- 'user' => $user_info
+ 'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
];
return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
function api_friendica_group_create($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$name = $_REQUEST['name'] ?? '';
- $uid = $user_info['uid'];
$json = json_decode($_POST['json'], true);
$users = $json['user'];
function api_lists_create($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$name = $_REQUEST['name'] ?? '';
- $uid = $user_info['uid'];
$success = group_create($name, $uid);
if ($success['success']) {
'name' => $success['name'],
'id' => intval($success['gid']),
'id_str' => (string) $success['gid'],
- 'user' => $user_info
+ 'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
];
return DI::apiResponse()->formatData("lists", $type, ['lists' => $grp]);
function api_friendica_group_update($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
- $uid = $user_info['uid'];
$gid = $_REQUEST['gid'] ?? 0;
$name = $_REQUEST['name'] ?? '';
$json = json_decode($_POST['json'], true);
function api_lists_update($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
$gid = $_REQUEST['list_id'] ?? 0;
$name = $_REQUEST['name'] ?? '';
- $uid = $user_info['uid'];
// error if no gid specified
if ($gid == 0) {
'name' => $name,
'id' => intval($gid),
'id_str' => (string) $gid,
- 'user' => $user_info
+ 'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
];
return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
function api_friendica_notification_seen($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
-
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $uid = BaseApi::getCurrentUserID();
if (DI::args()->getArgc() !== 4) {
throw new BadRequestException('Invalid argument count');
try {
$Notify = DI::notify()->selectOneById($id);
- if ($Notify->uid !== BaseApi::getCurrentUserID()) {
+ if ($Notify->uid !== $uid) {
throw new NotFoundException();
}
DI::notify()->save($Notify);
if ($Notify->otype === Notification\ObjectType::ITEM) {
- $item = Post::selectFirstForUser(BaseApi::getCurrentUserID(), [], ['id' => $Notify->iid, 'uid' => BaseApi::getCurrentUserID()]);
+ $item = Post::selectFirstForUser($uid, [], ['id' => $Notify->iid, 'uid' => $uid]);
if (DBA::isResult($item)) {
// we found the item, return it to the user
$ret = api_format_items([$item], $type);
function api_friendica_direct_messages_search($type, $box = "")
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
+ $uid = BaseApi::getCurrentUserID();
// params
- $user_info = DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray();
+ $user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
$searchstring = $_REQUEST['searchstring'] ?? '';
- $uid = $user_info['uid'];
// error if no searchstring specified
if ($searchstring == "") {
foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info;
- $sender = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
- $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], BaseApi::getCurrentUserID())->toArray();
+ $recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
$sender = $user_info;
}