X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=b649d224816a006a2c028fbc1c4b8438529bccd4;hb=8b9205a9a52805afaccbcb7e70a91786dc7e24ff;hp=86cda0b1bb688e915e150c6e14c7f27e555c108f;hpb=dd85f48e0de68aa71cb46ff067bd872f0f97ee1e;p=friendica.git diff --git a/include/api.php b/include/api.php index 86cda0b1bb..b649d22481 100644 --- a/include/api.php +++ b/include/api.php @@ -41,10 +41,11 @@ use Friendica\Model\Item; use Friendica\Model\Mail; use Friendica\Model\Notify; use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Model\UserItem; use Friendica\Model\Verb; -use Friendica\Network\FKOAuth1; +use Friendica\Security\FKOAuth1; use Friendica\Network\HTTPException; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\ExpectationFailedException; @@ -58,6 +59,8 @@ use Friendica\Network\HTTPException\UnauthorizedException; use Friendica\Object\Image; use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; +use Friendica\Security\OAuth1\OAuthRequest; +use Friendica\Security\OAuth1\OAuthUtil; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; use Friendica\Util\Network; @@ -65,7 +68,6 @@ use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; use Friendica\Util\XML; -require_once __DIR__ . '/../mod/share.php'; require_once __DIR__ . '/../mod/item.php'; require_once __DIR__ . '/../mod/wall_upload.php'; @@ -311,22 +313,22 @@ function api_call(App $a, App\Arguments $args = null) } $type = "json"; - if (strpos($args->getQueryString(), ".xml") > 0) { + if (strpos($args->getCommand(), ".xml") > 0) { $type = "xml"; } - if (strpos($args->getQueryString(), ".json") > 0) { + if (strpos($args->getCommand(), ".json") > 0) { $type = "json"; } - if (strpos($args->getQueryString(), ".rss") > 0) { + if (strpos($args->getCommand(), ".rss") > 0) { $type = "rss"; } - if (strpos($args->getQueryString(), ".atom") > 0) { + if (strpos($args->getCommand(), ".atom") > 0) { $type = "atom"; } try { foreach ($API as $p => $info) { - if (strpos($args->getQueryString(), $p) === 0) { + if (strpos($args->getCommand(), $p) === 0) { if (!api_check_method($info['method'])) { throw new MethodNotAllowedException(); } @@ -384,7 +386,7 @@ function api_call(App $a, App\Arguments $args = null) } Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]); - throw new NotImplementedException(); + throw new NotFoundException(); } catch (HTTPException $e) { header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}"); return api_error($type, $e, $args); @@ -1364,7 +1366,7 @@ function api_get_last_status($ownerId, $uid) */ function api_get_item(array $condition) { - $item = Item::selectFirst(Item::DISPLAY_FIELDLIST, $condition, ['order' => ['id' => true]]); + $item = Post::selectFirst(Item::DISPLAY_FIELDLIST, $condition, ['order' => ['id' => true]]); return $item; } @@ -1672,7 +1674,7 @@ function api_statuses_home_timeline($type) } if (!empty($idarray)) { - $unseen = Item::exists(['unseen' => true, 'id' => $idarray]); + $unseen = Post::exists(['unseen' => true, 'id' => $idarray]); if ($unseen) { Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]); } @@ -1879,12 +1881,12 @@ function api_statuses_show($type) $conversation = !empty($_REQUEST['conversation']); // try to fetch the item for the local user - or the public item, if there is no local one - $uri_item = Item::selectFirst(['uri'], ['id' => $id]); + $uri_item = Post::selectFirst(['uri'], ['id' => $id]); if (!DBA::isResult($uri_item)) { throw new BadRequestException("There is no status with this id."); } - $item = Item::selectFirst(['id'], ['uri' => $uri_item['uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); + $item = Post::selectFirst(['id'], ['uri' => $uri_item['uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { throw new BadRequestException("There is no status with this id."); } @@ -1962,12 +1964,12 @@ function api_conversation_show($type) Logger::info(API_LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]); // try to fetch the item for the local user - or the public item, if there is no local one - $item = Item::selectFirst(['parent-uri'], ['id' => $id]); + $item = Post::selectFirst(['parent-uri'], ['id' => $id]); if (!DBA::isResult($item)) { throw new BadRequestException("There is no status with this id."); } - $parent = Item::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); + $parent = Post::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); if (!DBA::isResult($parent)) { throw new BadRequestException("There is no status with this id."); } @@ -2038,35 +2040,40 @@ function api_statuses_repeat($type) Logger::log('API: api_statuses_repeat: '.$id); - $fields = ['uri-id', 'body', 'title', 'attach', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; + $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; $item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); if (DBA::isResult($item) && $item['body'] != "") { - if (strpos($item['body'], "[/share]") !== false) { - $pos = strpos($item['body'], "[share"); - $post = substr($item['body'], $pos); + if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) { + if (!Item::performActivity($id, 'announce', local_user())) { + throw new InternalServerErrorException(); + } + + $item_id = $id; } else { - $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); + if (strpos($item['body'], "[/share]") !== false) { + $pos = strpos($item['body'], "[share"); + $post = substr($item['body'], $pos); + } else { + $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); - if (!empty($item['title'])) { - $post .= '[h3]' . $item['title'] . "[/h3]\n"; + if (!empty($item['title'])) { + $post .= '[h3]' . $item['title'] . "[/h3]\n"; + } + + $post .= $item['body']; + $post .= "[/share]"; } + $_REQUEST['body'] = $post; + $_REQUEST['profile_uid'] = api_user(); + $_REQUEST['api_source'] = true; - $post .= $item['body']; - $post .= "[/share]"; - } - $_REQUEST['body'] = $post; - $_REQUEST['attach'] = $item['attach']; - $_REQUEST['profile_uid'] = api_user(); - $_REQUEST['api_source'] = true; + if (empty($_REQUEST['source'])) { + $_REQUEST["source"] = api_source(); + } - if (empty($_REQUEST['source'])) { - $_REQUEST["source"] = api_source(); + $item_id = item_post($a); } - - $item_id = item_post($a); - - /// @todo Copy tags from the original post to the new one } else { throw new ForbiddenException(); } @@ -2157,10 +2164,10 @@ function api_statuses_mentions($type) // get last network messages // params - $since_id = $_REQUEST['since_id'] ?? 0; - $max_id = $_REQUEST['max_id'] ?? 0; - $count = $_REQUEST['count'] ?? 20; - $page = $_REQUEST['page'] ?? 1; + $since_id = intval($_REQUEST['since_id'] ?? 0); + $max_id = intval($_REQUEST['max_id'] ?? 0); + $count = intval($_REQUEST['count'] ?? 20); + $page = intval($_REQUEST['page'] ?? 1); $start = max(0, ($page - 1) * $count); @@ -4213,7 +4220,7 @@ function api_fr_photo_create_update($type) $deny_cid = $_REQUEST['deny_cid' ] ?? null; $allow_gid = $_REQUEST['allow_gid'] ?? null; $deny_gid = $_REQUEST['deny_gid' ] ?? null; - $visibility = !empty($_REQUEST['visibility']) && $_REQUEST['visibility'] !== "false"; + $visibility = !$allow_cid && !$deny_cid && !$allow_gid && !$deny_gid; // do several checks on input parameters // we do not allow calls without album string @@ -4759,7 +4766,6 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f $arr['guid'] = System::createUUID(); $arr['uid'] = intval(api_user()); $arr['uri'] = $uri; - $arr['parent-uri'] = $uri; $arr['type'] = 'photo'; $arr['wall'] = 1; $arr['resource-id'] = $hash; @@ -4874,7 +4880,7 @@ function prepare_photo_data($type, $scale, $photo_id) // retrieve item element for getting activities (like, dislike etc.) related to photo $condition = ['uid' => api_user(), 'resource-id' => $photo_id, 'type' => 'photo']; - $item = Item::selectFirst(['id', 'uid', 'uri', 'parent', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'], $condition); + $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.'); } @@ -5070,7 +5076,7 @@ function api_share_as_retweet(&$item) } if (!empty($condition)) { - $original_item = Item::selectFirst([], $condition); + $original_item = Post::selectFirst([], $condition); if (DBA::isResult($original_item)) { $reshared_item = array_merge($reshared_item, $original_item); } @@ -5097,7 +5103,7 @@ function api_in_reply_to($item) $in_reply_to['screen_name'] = null; if (($item['thr-parent'] != $item['uri']) && ($item['gravity'] != GRAVITY_PARENT)) { - $parent = Item::selectFirst(['id'], ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); + $parent = Post::selectFirst(['id'], ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); if (DBA::isResult($parent)) { $in_reply_to['status_id'] = intval($parent['id']); } else { @@ -5107,7 +5113,7 @@ function api_in_reply_to($item) $in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']); $fields = ['author-nick', 'author-name', 'author-id', 'author-link']; - $parent = Item::selectFirst($fields, ['id' => $in_reply_to['status_id']]); + $parent = Post::selectFirst($fields, ['id' => $in_reply_to['status_id']]); if (DBA::isResult($parent)) { $in_reply_to['screen_name'] = (($parent['author-nick']) ? $parent['author-nick'] : $parent['author-name']); @@ -5271,7 +5277,7 @@ function api_friendica_group_show($type) // loop through all groups and retrieve all members for adding data in the user array $grps = []; foreach ($r as $rr) { - $members = Contact::getByGroupId($rr['id']); + $members = Contact\Group::getById($rr['id']); $users = []; if ($type == "xml") { @@ -5596,7 +5602,7 @@ function api_friendica_group_update($type) } // remove members - $members = Contact::getByGroupId($gid); + $members = Contact\Group::getById($gid); foreach ($members as $member) { $cid = $member['id']; foreach ($users as $user) { @@ -5710,7 +5716,7 @@ function api_friendica_activity($type) $id = $_REQUEST['id'] ?? 0; - $res = Item::performActivity($id, $verb); + $res = Item::performActivity($id, $verb, api_user()); if ($res) { if ($type == "xml") {