]> git.mxchange.org Git - friendica.git/commitdiff
Use "getOwnerDataById" and "getOwnerDataByNick" to fetch owner data
authorMichael <heluecht@pirati.ca>
Sun, 4 Jul 2021 17:25:08 +0000 (17:25 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 4 Jul 2021 17:25:08 +0000 (17:25 +0000)
mod/cal.php
mod/photos.php
mod/videos.php
src/Model/Profile.php
src/Module/NoScrape.php
src/Protocol/ActivityPub/Transmitter.php

index f3ff80cf99b3239d4cd8d5689f548a63c3acbdf1..e1cf91aa685dd4cceeca4a36140e860777f00ce1 100644 (file)
@@ -34,7 +34,7 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
+use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
 use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
@@ -67,7 +67,7 @@ function cal_init(App $a)
                return;
        }
 
-       $a->profile = Profile::getByNickname($nick);
+       $a->profile = User::getOwnerDataByNick($nick);
        if (empty($a->profile)) {
                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
        }
index b0bd79b8f52afd17dfdf9034363d27f31c028821..a5a1faf2ac325855543009281ad26d7b9c9af88b 100644 (file)
@@ -37,7 +37,6 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
-use Friendica\Model\Profile;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
@@ -73,7 +72,7 @@ function photos_init(App $a) {
                $a->profile_uid = $user['uid'];
                $is_owner = (local_user() && (local_user() == $a->profile_uid));
 
-               $profile = Profile::getByNickname($nick);
+               $profile =      User::getOwnerDataByNick($nick);
 
                $account_type = Contact::getAccountType($profile);
 
index ccf1cba141a764c94b1aae18dd0ab84a5919c3e6..de421df181629fb3ab96ee5d74f24e3aae395c1f 100644 (file)
@@ -30,7 +30,6 @@ use Friendica\DI;
 use Friendica\Model\Attach;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
 use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
 use Friendica\Security\Security;
@@ -56,7 +55,7 @@ function videos_init(App $a)
                $a->data['user'] = $user[0];
                $a->profile_uid = $user[0]['uid'];
 
-               $profile = Profile::getByNickname($nick);
+               $profile =      User::getOwnerDataByNick($nick);
 
                $account_type = Contact::getAccountType($profile);
 
index a56aa05c0bd915f917c327f8f96d8177ecaddb00..4a0db9ecd8b0d4c0a942f38fc330bfa751a05572 100644 (file)
@@ -283,21 +283,6 @@ class Profile
                return;
        }
 
-       /**
-        * Get the profile for the given nick name
-        *
-        * Includes all available profile data
-        *
-        * @param string $nickname   nick
-        * @return array
-        * @throws \Exception
-        */
-       public static function getByNickname($nickname)
-       {
-               $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname]);
-               return $profile;
-       }
-
        /**
         * Formats a profile for display in the sidebar.
         *
index 94bc20db328c47eeb56a751c8f352e5c95896968..1b97d047f7c1a846722f22e4c3475f65f9055069 100644 (file)
@@ -27,7 +27,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
-use Friendica\Model\Profile;
 use Friendica\Model\User;
 
 /**
@@ -51,7 +50,7 @@ class NoScrape extends BaseModule
                        System::jsonError(403, 'Authentication required');
                }
 
-               $profile = Profile::getByNickname($which);
+               $profile = User::getOwnerDataByNick($which);
 
                if (empty($profile['uid'])) {
                        System::jsonError(404, 'Profile not found');
index 9ff3957c1e8eaedc93ca3c5f812d4b205ec4915b..0eac87f6a33a2965dd00248558f484837628fc88 100644 (file)
@@ -316,73 +316,48 @@ class Transmitter
         */
        public static function getProfile($uid)
        {
-               if ($uid != 0) {
-                       $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
-                               'account_removed' => false, 'verified' => true];
-                       $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags'];
-                       $user = DBA::selectFirst('user', $fields, $condition);
-                       if (!DBA::isResult($user)) {
-                               return [];
-                       }
-
-                       $fields = ['locality', 'region', 'country-name', 'net-publish'];
-                       $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
-                       if (!DBA::isResult($profile)) {
-                               return [];
-                       }
-
-                       $fields = ['id', 'name', 'url', 'location', 'about', 'avatar', 'photo', 'updated'];
-                       $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
-                       if (!DBA::isResult($contact)) {
-                               return [];
-                       }
-               } else {
-                       $contact = User::getSystemAccount();
-                       $user = ['guid' => '', 'nickname' => $contact['nick'], 'pubkey' => $contact['pubkey'],
-                               'account-type' => $contact['contact-type'], 'page-flags' => User::PAGE_FLAGS_NORMAL];
-                       $profile = ['locality' => '', 'region' => '', 'country-name' => '', 'net-publish' => false];
-               }
+               $owner = User::getOwnerDataById($uid);
 
                $data = ['@context' => ActivityPub::CONTEXT];
-               $data['id'] = $contact['url'];
+               $data['id'] = $owner['url'];
 
-               if (!empty($user['guid'])) {
-                       $data['diaspora:guid'] = $user['guid'];
+               if (!empty($owner['guid'])) {
+                       $data['diaspora:guid'] = $owner['guid'];
                }
 
-               $data['type'] = ActivityPub::ACCOUNT_TYPES[$user['account-type']];
+               $data['type'] = ActivityPub::ACCOUNT_TYPES[$owner['account-type']];
 
                if ($uid != 0) {
-                       $data['following'] = DI::baseUrl() . '/following/' . $user['nickname'];
-                       $data['followers'] = DI::baseUrl() . '/followers/' . $user['nickname'];
-                       $data['inbox'] = DI::baseUrl() . '/inbox/' . $user['nickname'];
-                       $data['outbox'] = DI::baseUrl() . '/outbox/' . $user['nickname'];
+                       $data['following'] = DI::baseUrl() . '/following/' . $owner['nick'];
+                       $data['followers'] = DI::baseUrl() . '/followers/' . $owner['nick'];
+                       $data['inbox'] = DI::baseUrl() . '/inbox/' . $owner['nick'];
+                       $data['outbox'] = DI::baseUrl() . '/outbox/' . $owner['nick'];
                } else {
                        $data['inbox'] = DI::baseUrl() . '/friendica/inbox';
                }
 
-               $data['preferredUsername'] = $user['nickname'];
-               $data['name'] = $contact['name'];
+               $data['preferredUsername'] = $owner['nick'];
+               $data['name'] = $owner['name'];
 
-               if (!empty($profile['country-name'] . $profile['region'] . $profile['locality'])) {
-                       $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'],
-                               'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
+               if (!empty($owner['country-name'] . $owner['region'] . $owner['locality'])) {
+                       $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $owner['country-name'],
+                               'vcard:region' => $owner['region'], 'vcard:locality' => $owner['locality']];
                }
 
-               if (!empty($contact['about'])) {
-                       $data['summary'] = BBCode::convert($contact['about'], false);
+               if (!empty($owner['about'])) {
+                       $data['summary'] = BBCode::convert($owner['about'], false);
                }
 
-               $data['url'] = $contact['url'];
-               $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
-               $data['discoverable'] = $profile['net-publish'];
-               $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
-                       'owner' => $contact['url'],
-                       'publicKeyPem' => $user['pubkey']];
+               $data['url'] = $owner['url'];
+               $data['manuallyApprovesFollowers'] = in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
+               $data['discoverable'] = $owner['net-publish'];
+               $data['publicKey'] = ['id' => $owner['url'] . '#main-key',
+                       'owner' => $owner['url'],
+                       'publicKeyPem' => $owner['pubkey']];
                $data['endpoints'] = ['sharedInbox' => DI::baseUrl() . '/inbox'];
-               $data['icon'] = ['type' => 'Image', 'url' => Contact::getAvatarUrlForId($contact['id'], '', $contact['updated'])];
+               $data['icon'] = ['type' => 'Image', 'url' => Contact::getAvatarUrlForId($owner['id'], '', $owner['updated'])];
 
-               $resourceid = Photo::ridFromURI($contact['photo']);
+               $resourceid = Photo::ridFromURI($owner['photo']);
                if (!empty($resourceid)) {
                        $photo = Photo::selectFirst(['type'], ["resource-id" => $resourceid]);
                        if (!empty($photo['type'])) {
@@ -390,10 +365,10 @@ class Transmitter
                        }
                }
 
-               if (!empty($contact['header'])) {
-                       $data['image'] = ['type' => 'Image', 'url' => Contact::getHeaderUrlForId($contact['id'], '', $contact['updated'])];
+               if (!empty($owner['header'])) {
+                       $data['image'] = ['type' => 'Image', 'url' => Contact::getHeaderUrlForId($owner['id'], '', $owner['updated'])];
 
-                       $resourceid = Photo::ridFromURI($contact['header']);
+                       $resourceid = Photo::ridFromURI($owner['header']);
                        if (!empty($resourceid)) {
                                $photo = Photo::selectFirst(['type'], ["resource-id" => $resourceid]);
                                if (!empty($photo['type'])) {
@@ -1302,7 +1277,7 @@ class Transmitter
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
                                        'name' => $attachment['description']];
-                               
+
                                if (!empty($attachment['height'])) {
                                        $attach['height'] = $attachment['height'];
                                }
@@ -1310,7 +1285,7 @@ class Transmitter
                                if (!empty($attachment['width'])) {
                                        $attach['width'] = $attachment['width'];
                                }
-       
+
                                if (!empty($attachment['preview'])) {
                                        $attach['image'] = $attachment['preview'];
                                }
@@ -1334,7 +1309,7 @@ class Transmitter
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
                                        'name' => $attachment['description']];
-                               
+
                                if (!empty($attachment['height'])) {
                                        $attach['height'] = $attachment['height'];
                                }
@@ -1347,7 +1322,7 @@ class Transmitter
                                        $attach['image'] = $attachment['preview'];
                                }
 
-                               $attachments[] = $attach;       
+                               $attachments[] = $attach;
                        }
                        // Currently deactivated, since it creates side effects on Mastodon and Pleroma.
                        // It will be activated, once this cleared.