]> git.mxchange.org Git - friendica.git/blobdiff - mod/display.php
Apply suggestions from code review
[friendica.git] / mod / display.php
index b51768e8004099dab64b74fa2e76ab2f23b53b12..c0e72837af11ff07c4f95ebb565899759835767c 100644 (file)
@@ -32,6 +32,7 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
+use Friendica\Model\User;
 use Friendica\Module\ActivityPub\Objects;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\ActivityPub;
@@ -53,17 +54,17 @@ function display_init(App $a)
        $item = null;
        $item_user = local_user();
 
-       $fields = ['uri-id', 'parent-uri-id', 'author-id', 'body', 'uid', 'guid', 'gravity'];
+       $fields = ['uri-id', 'parent-uri-id', 'author-id', 'author-link', 'body', 'uid', 'guid', 'gravity'];
 
        // If there is only one parameter, then check if this parameter could be a guid
        if ($a->argc == 2) {
-               $nick = "";
+               $nick = '';
 
                // Does the local user have this item?
                if (local_user()) {
                        $item = Post::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'uid' => local_user()]);
                        if (DBA::isResult($item)) {
-                               $nick = $a->user["nickname"];
+                               $nick = $a->user['nickname'];
                        }
                }
 
@@ -109,41 +110,29 @@ function display_init(App $a)
                $item = $parent ?: $item;
        }
 
-       $profiledata = display_fetchauthor($a, $item);
-
-       if (strstr(Strings::normaliseLink($profiledata['url']), Strings::normaliseLink(DI::baseUrl()))) {
-               $nickname = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/profile/', '', Strings::normaliseLink($profiledata['url']));
-
-               if (!empty($a->user['nickname']) && $nickname != $a->user['nickname']) {
-                       $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname]);
-                       if (DBA::isResult($profile)) {
-                               $profiledata = $profile;
-                       }
-                       $profiledata["network"] = Protocol::DFRN;
-               } else {
-                       $profiledata = [];
-               }
-       }
+       $profiledata = display_fetchauthor($item);
 
        DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
 }
 
-function display_fetchauthor($a, $item)
+function display_fetchauthor($item)
 {
-       $author = DBA::selectFirst('contact', ['name', 'nick', 'photo', 'network', 'url'], ['id' => $item['author-id']]);
-
-       $profiledata = [];
-       $profiledata['uid'] = -1;
-       $profiledata['nickname'] = $author['nick'];
-       $profiledata['name'] = $author['name'];
-       $profiledata['picdate'] = '';
-       $profiledata['photo'] = $author['photo'];
-       $profiledata['url'] = $author['url'];
-       $profiledata['network'] = $author['network'];
+       $profiledata = Contact::getByURLForUser($item['author-link'], local_user());
 
        // Check for a repeated message
        $shared = Item::getShareArray($item);
        if (!empty($shared) && empty($shared['comment'])) {
+               $profiledata = [
+                       'uid' => -1,
+                       'id' => -1,
+                       'nickname' => '',
+                       'name' => '',
+                       'picdate' => '',
+                       'photo' => '',
+                       'url' => '',
+                       'network' => '',
+               ];
+
                if (!empty($shared['author'])) {
                        $profiledata['name'] = $shared['author'];
                }
@@ -156,17 +145,17 @@ function display_fetchauthor($a, $item)
                        $profiledata['photo'] = $shared['avatar'];
                }
 
-               $profiledata["nickname"] = $profiledata["name"];
-               $profiledata["network"] = Protocol::matchByProfileUrl($profiledata["url"]);
+               $profiledata['nickname'] = $profiledata['name'];
+               $profiledata['network'] = Protocol::matchByProfileUrl($profiledata['url']);
 
-               $profiledata["address"] = "";
-               $profiledata["about"] = "";
-       }
+               $profiledata['address'] = '';
+               $profiledata['about'] = '';
 
-       $profiledata = Contact::getByURLForUser($profiledata["url"], local_user()) ?: $profiledata;
+               $profiledata = Contact::getByURLForUser($profiledata['url'], local_user()) ?: $profiledata;
+       }
 
-       if (!empty($profiledata["photo"])) {
-               $profiledata["photo"] = DI::baseUrl()->remove($profiledata["photo"]);
+       if (!empty($profiledata['photo'])) {
+               $profiledata['photo'] = DI::baseUrl()->remove($profiledata['photo']);
        }
 
        return $profiledata;
@@ -189,9 +178,9 @@ function display_content(App $a, $update = false, $update_uid = 0)
                $item = Post::selectFirst(['uid', 'parent-uri-id'], ['uri-id' => $uri_id, 'uid' => $update_uid]);
                if (!empty($item)) {
                        if ($item['uid'] != 0) {
-                               $a->profile = ['uid' => intval($item['uid'])];
+                               $a->setProfileOwner($item['uid']);
                        } else {
-                               $a->profile = ['uid' => intval($update_uid)];
+                               $a->setProfileOwner($update_uid);
                        }
                        $parent_uri_id = $item['parent-uri-id'];
                }
@@ -273,14 +262,13 @@ function display_content(App $a, $update = false, $update_uid = 0)
                $page_uid = $item['uid'];
        }
 
-       $page_contact = DBA::selectFirst('contact', [], ['self' => true, 'uid' => $page_uid]);
-       if (DBA::isResult($page_contact)) {
-               $a->page_contact = $page_contact;
+       if (!empty($page_uid) && ($page_uid != local_user())) {
+               $page_user = User::getById($page_uid);
        }
 
-       $is_owner = (local_user() && (in_array($page_uid, [local_user(), 0])) ? true : false);
+       $is_owner = local_user() && (in_array($page_uid, [local_user(), 0]));
 
-       if (!empty($a->profile['hidewall']) && !$is_owner && !$is_remote_contact) {
+       if (!empty($page_user['hidewall']) && !$is_owner && !$is_remote_contact) {
                throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
        }
 
@@ -334,13 +322,13 @@ function display_content(App $a, $update = false, $update_uid = 0)
        $o .= conversation($a, [$item], 'display', $update_uid, false, 'commented', $item_uid);
 
        // Preparing the meta header
-       $description = trim(BBCode::toPlaintext($item["body"]));
-       $title = trim(BBCode::toPlaintext($item["title"]));
-       $author_name = $item["author-name"];
+       $description = trim(BBCode::toPlaintext($item['body']));
+       $title = trim(BBCode::toPlaintext($item['title']));
+       $author_name = $item['author-name'];
 
-       $image = DI::baseUrl()->remove($item["author-avatar"]);
+       $image = DI::baseUrl()->remove($item['author-avatar']);
 
-       if ($title == "") {
+       if ($title == '') {
                $title = $author_name;
        }