]> git.mxchange.org Git - friendica.git/commitdiff
Removed unused code
authorMichael <heluecht@pirati.ca>
Thu, 18 Nov 2021 14:49:12 +0000 (14:49 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 18 Nov 2021 14:49:12 +0000 (14:49 +0000)
include/api.php
src/Module/Api/Friendica/Profile/Show.php
src/Module/BaseApi.php
tests/legacy/ApiTest.php

index c43632d2df04032a639b1c21ef016a52cbb2ae2e..554293ea05761afdb3159ae1f9b9f19bf1139375 100644 (file)
@@ -54,7 +54,6 @@ use Friendica\Network\HTTPException\UnauthorizedException;
 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;
@@ -71,7 +70,6 @@ define('API_METHOD_DELETE', 'POST,DELETE');
 define('API_LOG_PREFIX', 'API {action} - ');
 
 $API = [];
-$called_api = [];
 
 /**
  * Get source name from API client
@@ -178,7 +176,7 @@ function api_check_method($method)
  */
 function api_call(App $a, App\Arguments $args = null)
 {
-       global $API, $called_api;
+       global $API;
 
        if ($args == null) {
                $args = DI::args();
@@ -205,8 +203,6 @@ function api_call(App $a, App\Arguments $args = null)
                                        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()]);
@@ -334,8 +330,6 @@ function api_unique_id_to_nurl($id)
  */
 function api_get_user($contact_id = null)
 {
-       global $called_api;
-
        $user = null;
        $extra_query = "";
        $url = "";
@@ -343,7 +337,7 @@ function api_get_user($contact_id = null)
        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` = ? ";
@@ -353,7 +347,7 @@ function api_get_user($contact_id = null)
        }
 
        // 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 == "") {
@@ -367,72 +361,10 @@ function api_get_user($contact_id = null)
                }
        }
 
-       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]);
@@ -1579,8 +1511,6 @@ api_register_func('api/statusnet/conversation', 'api_conversation_show', true);
  */
 function api_statuses_repeat($type)
 {
-       global $called_api;
-
        $a = DI::app();
 
        BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -1638,7 +1568,6 @@ function api_statuses_repeat($type)
        }
 
        // output the post that we just posted.
-       $called_api = [];
        return api_status_show($type, $item_id);
 }
 
@@ -1928,14 +1857,10 @@ api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true,
  */
 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']]);
index e388405effa042ec3c25d4486061bc20897f5dba..551b0d3b9d007c74ad120d173c64febac84c255e 100644 (file)
@@ -24,7 +24,6 @@ namespace Friendica\Module\Api\Friendica\Profile;
 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;
@@ -55,13 +54,10 @@ class Show extends BaseApi
                        $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
                ];
 
index a0a94c336f0cf8e9b83bc848f0cdc2b0ec83acf8..b90db36dcfe53b5b17db5a9d5faf0015f581ff1a 100644 (file)
@@ -29,12 +29,8 @@ use Friendica\Model\Post;
 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
 {
@@ -295,19 +291,4 @@ 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);
-       }
 }
index a46d346b9a45463cf9c6d16cf714aa65ce8e29e2..f91bf701df73b64856e40fa7b980dd7bd61ce5e0 100644 (file)
@@ -725,7 +725,6 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetId()
        {
-               // $_GET['user_id'] = $this->otherUser['id'];
                // self::assertOtherUser(api_get_user());
        }
 
@@ -737,7 +736,6 @@ class ApiTest extends FixtureTest
        public function testApiGetUserWithWrongGetId()
        {
                // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               // $_GET['user_id'] = $this->wrongUserId;
                // self::assertOtherUser(api_get_user());
        }
 
@@ -748,7 +746,6 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetName()
        {
-               // $_GET['screen_name'] = $this->selfUser['nick'];
                // self::assertSelfUser(api_get_user());
        }
 
@@ -759,7 +756,6 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetUrl()
        {
-               // $_GET['profileurl'] = $this->selfUser['nurl'];
                // self::assertSelfUser(api_get_user());
        }
 
@@ -1429,7 +1425,6 @@ class ApiTest extends FixtureTest
        public function testApiSearchWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_search('json');
        }
@@ -1485,7 +1480,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesHomeTimelineWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_home_timeline('json');
        }
@@ -1556,7 +1550,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesPublicTimelineWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_public_timeline('json');
        }
@@ -1610,7 +1603,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_networkpublic_timeline('json');
        }
@@ -1673,7 +1665,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesShowWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_show('json');
        }
@@ -1714,7 +1705,6 @@ class ApiTest extends FixtureTest
        public function testApiConversationShowWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_conversation_show('json');
        }
@@ -1830,7 +1820,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesMentionsWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_mentions('json');
        }
@@ -1897,7 +1886,6 @@ class ApiTest extends FixtureTest
        public function testApiStatusesUserTimelineWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_statuses_user_timeline('json');
        }
@@ -2026,7 +2014,6 @@ class ApiTest extends FixtureTest
        public function testApiFavoritesWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_favorites('json');
        }
@@ -2452,7 +2439,6 @@ class ApiTest extends FixtureTest
        public function testApiListsStatusesWithUnallowedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               $_GET['screen_name']   = $this->selfUser['nick'];
                BasicAuth::setCurrentUserID();
                api_lists_statuses('json');
        }
@@ -2880,7 +2866,6 @@ class ApiTest extends FixtureTest
        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');
        }