]> git.mxchange.org Git - friendica.git/commitdiff
App->contact is now removed
authorMichael <heluecht@pirati.ca>
Sat, 24 Jul 2021 11:49:11 +0000 (11:49 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 24 Jul 2021 11:49:11 +0000 (11:49 +0000)
16 files changed:
mod/display.php
mod/notes.php
mod/photos.php
mod/redir.php
src/App.php
src/Content/Nav.php
src/Factory/Notification/Notification.php
src/Model/Item.php
src/Model/Profile.php
src/Model/User.php
src/Module/Contact/Poke.php
src/Module/Delegation.php
src/Module/Item/Compose.php
src/Module/Magic.php
src/Object/Post.php
src/Security/Authentication.php

index 3a93e504aed36d20d30179b0dc2855922b7c5e12..6abf4c019dcb4b760c474e60674feb5fe074dd6d 100644 (file)
@@ -261,16 +261,11 @@ function display_content(App $a, $update = false, $update_uid = 0)
                $page_uid = $item['uid'];
        }
 
-       $page_contact = DBA::selectFirst('contact', ['id', 'url', 'network', 'name'], ['self' => true, 'uid' => $page_uid]);
-       if (DBA::isResult($page_contact)) {
-               // "$a->page_contact" is only used in "checkWallToWall" in Post.php.
-               // It is used for the wall post feature that has its issues.
-               // It can't work with AP or Diaspora since the creator can't sign the post with their private key.
-               $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($page_user['hidewall']) && !$is_owner && !$is_remote_contact) {
                throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
index 8b9da39696d81485701678f7d034a1915f62639b..2759164bc49eb903d6becfb3255229715049b2c7 100644 (file)
@@ -64,11 +64,11 @@ function notes_content(App $a, $update = false)
                        'acl_data' => '',
                ];
 
-               $o .= status_editor($a, $x, $a->contact['id']);
+               $o .= status_editor($a, $x, $a->contact_id);
        }
 
        $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
-               'contact-id'=> $a->contact['id']];
+               'contact-id'=> $a->contact_id];
 
        if (DI::mode()->isMobile()) {
                $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
index 37d3c467b402078fe87ff1c7d1862b518bf501e9..f999b29d8e287a2dfb81feda91b5cb4c35552de0 100644 (file)
@@ -890,7 +890,8 @@ function photos_content(App $a)
 
        if (!$remote_contact && local_user()) {
                $contact_id = $_SESSION['cid'];
-               $contact = $a->contact;
+
+               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
        }
 
        if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
index 2f97911dc3c9662385e5d83d9016897ce17eaab7..ca0fe71a829de221b6b634f7825ddcf204b9b438 100644 (file)
@@ -58,7 +58,7 @@ function redir_init(App $a) {
 
        $contact_url = $contact['url'];
 
-       if (!empty($a->contact['id']) && $a->contact['id'] == $cid) {
+       if (!empty($a->contact_id) && $a->contact_id == $cid) {
                // Local user is already authenticated.
                redir_check_url($contact_url, $url);
                $a->redirect($url ?: $contact_url);
@@ -73,7 +73,7 @@ function redir_init(App $a) {
                        $cid = $contact['id'];
                }
 
-               if (!empty($a->contact['id']) && $a->contact['id'] == $cid) {
+               if (!empty($a->contact_id) && $a->contact_id == $cid) {
                        // Local user is already authenticated.
                        redir_check_url($contact_url, $url);
                        $target_url = $url ?: $contact_url;
index 47d70db64acd51c1bf1b192b1272a2c6e67d3363..aba922804c3fc2ef9c08ef9b6e3b1826fb7cf62c 100644 (file)
@@ -57,16 +57,14 @@ use Psr\Log\LoggerInterface;
 class App
 {
        public $profile_owner;
+       public $contact_id;
        public $user;
-       public $contact;
-       public $page_contact;
        public $data = [];
        /** @deprecated 2019.09 - use App\Arguments->getArgv() or Arguments->get() */
        public $argv;
        /** @deprecated 2019.09 - use App\Arguments->getArgc() */
        public $argc;
        public $timezone;
-       public $identities;
        public $theme_info = [];
        // Allow themes to control internal parameters
        // by changing App values in theme.php
index db3fa7863ac246f1071cc796215395d5664d4445..20b3a93258636582eb8db614b9cf6b9dacb37de7 100644 (file)
@@ -289,7 +289,7 @@ class Nav
                        $nav['messages']['outbox'] = ['message/sent', DI::l10n()->t('Outbox'), '', DI::l10n()->t('Outbox')];
                        $nav['messages']['new'] = ['message/new', DI::l10n()->t('New Message'), '', DI::l10n()->t('New Message')];
 
-                       if (is_array($a->identities) && count($a->identities) > 1) {
+                       if (User::hasIdentities(DI::session()->get('submanage') ?: local_user())) {
                                $nav['delegation'] = ['delegation', DI::l10n()->t('Accounts'), '', DI::l10n()->t('Manage other pages')];
                        }
 
index e69b2131e4c1474931d5240ae123edb2005bfa90..9f833130aaae81611121fe84f702d63fc962fa64 100644 (file)
@@ -63,8 +63,6 @@ class Notification extends BaseFactory
        private $baseUrl;
        /** @var L10n */
        private $l10n;
-       /** @var string */
-       private $nurl;
 
        public function __construct(LoggerInterface $logger, Database $dba, Repository\Notification $notification, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
        {
@@ -74,7 +72,6 @@ class Notification extends BaseFactory
                $this->notification = $notification;
                $this->baseUrl      = $baseUrl;
                $this->l10n         = $l10n;
-               $this->nurl         = $app->contact['nurl'] ?? '';
        }
 
        /**
index cbac14a11b7c15e3312ff212ce1d74ca688fa65b..477d8f3bea8c9daf3f77a040af5a58db3ec5463d 100644 (file)
@@ -2685,7 +2685,7 @@ class Item
                                        continue;
                                }
 
-                               if ((local_user() == $item['uid']) && ($item['private'] == self::PRIVATE) && ($item['contact-id'] != $app->contact['id']) && ($item['network'] == Protocol::DFRN)) {
+                               if ((local_user() == $item['uid']) && ($item['private'] == self::PRIVATE) && ($item['contact-id'] != $app->contact_id) && ($item['network'] == Protocol::DFRN)) {
                                        $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
                                        $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
                                }
index d81ecc239ec1ae63f04064abd634936277f61402..980cd204e343209876179c77a900e186122ed8b6 100644 (file)
@@ -768,7 +768,7 @@ class Profile
 
                Session::setVisitorsContacts();
 
-               $a->contact = $visitor;
+               $a->contact_id = $visitor['id'];
 
                Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
 
@@ -829,7 +829,7 @@ class Profile
                 */
                Hook::callAll('magic_auth_success', $arr);
 
-               $a->contact = $arr['visitor'];
+               $a->contact_id = $arr['visitor']['id'];
 
                info(DI::l10n()->t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name']));
 
index 3d76b080032139a1e14830ca0f1d8215bba69044..78ef3085a6056f37efb6fc9bd60ba89f73d6cfc9 100644 (file)
@@ -1569,6 +1569,38 @@ class User
                return $identities;
        }
 
+       /**
+        * Check if the given user id has delegations or is delegated
+        *
+        * @param int $uid 
+        * @return bool 
+        */
+       public static function hasIdentities(int $uid):bool
+       {
+               if (empty($uid)) {
+                       return false;
+               }
+
+               $user = DBA::selectFirst('user', ['parent-uid'], ['uid' => $uid, 'account_removed' => false]);
+               if (!DBA::isResult($user)) {
+                       return false;
+               }
+
+               if ($user['parent-uid'] != 0) {
+                       return true;
+               }
+
+               if (DBA::exists('user', ['parent-uid' => $uid, 'account_removed' => false])) {
+                       return true;
+               }
+
+               if (DBA::exists('manage', ['muid' => $uid])) {
+                       return true;
+               }
+
+               return false;
+       }
+
        /**
         * Returns statistical information about the current users of this node
         *
index 6e8920c5cf36cfd13ea402b4b69568587af798d3..f8f58fe48ceb6ba7ccf627c2096c30e1827d1dd2 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\Contact;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Util\XML;
@@ -59,7 +60,7 @@ class Poke extends BaseModule
                $deny_cid      = ($private ? '' : $a->user['deny_cid']);
                $deny_gid      = ($private ? '' : $a->user['deny_gid']);
 
-               $actor = $a->contact;
+               $actor = Contact::getById($a->contact_id);
 
                $uri = Model\Item::newURI($uid);
 
index 70991c0d0faaf3d704af3ee28c4b2efe46712c4b..201f38990c4b6023e4995b897c87852681c0916c 100644 (file)
@@ -118,7 +118,7 @@ class Delegation extends BaseModule
                        throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
                }
 
-               $identities = DI::app()->identities;
+               $identities = User::identities(DI::session()->get('submanage') ?: local_user());
 
                //getting additinal information for each identity
                foreach ($identities as $key => $identity) {
index c2bfba2dc447499892d697602808adc97272112b..21dd5625c147a7acfd4c4cbd5d981f30220b1ce2 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\Renderer;
 use Friendica\Core\Theme;
 use Friendica\DI;
+use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\Security\Login;
@@ -86,7 +87,7 @@ class Compose extends BaseModule
                                $compose_title = DI::l10n()->t('Compose new personal note');
                                $type = 'note';
                                $doesFederate = false;
-                               $contact_allow_list = [$a->contact['id']];
+                               $contact_allow_list = [$a->contact_id];
                                $group_allow_list = [];
                                $contact_deny_list = [];
                                $group_deny_list = [];
@@ -129,6 +130,8 @@ class Compose extends BaseModule
                DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
                DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
 
+               $contact = Contact::getById($a->contact_id);
+
                $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
                return Renderer::replaceMacros($tpl, [
                        '$compose_title'=> $compose_title,
@@ -138,9 +141,9 @@ class Compose extends BaseModule
                        '$type'         => $type,
                        '$wall'         => $wall,
                        '$default'      => '',
-                       '$mylink'       => DI::baseUrl()->remove($a->contact['url']),
+                       '$mylink'       => DI::baseUrl()->remove($contact['url']),
                        '$mytitle'      => DI::l10n()->t('This is you'),
-                       '$myphoto'      => DI::baseUrl()->remove($a->contact['thumb']),
+                       '$myphoto'      => DI::baseUrl()->remove($contact['thumb']),
                        '$submit'       => DI::l10n()->t('Submit'),
                        '$edbold'       => DI::l10n()->t('Bold'),
                        '$editalic'     => DI::l10n()->t('Italic'),
index c3a0168b457078920acc17e08658f4b5c938263b..81d6def33855c719a3c0109b24e9fb002973eda5 100644 (file)
@@ -65,7 +65,7 @@ class Magic extends BaseModule
                $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
 
                // Redirect if the contact is already authenticated on this site.
-               if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
+               if (!empty($a->contact_id) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
                        if ($test) {
                                $ret['success'] = true;
                                $ret['message'] .= 'Local site - you are already authenticated.' . EOL;
index bd6e2299e3766a99ec5884489e092773729b4592..a56a73a266410a4b72590e931c4083874b6306bf 100644 (file)
@@ -187,7 +187,7 @@ class Post
                $edpost = false;
 
                if (local_user()) {
-                       if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
+                       if (Strings::compareLink(Session::get('my_url'), $item['author-link'])) {
                                if ($item["event-id"] != 0) {
                                        $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
                                } else {
@@ -936,6 +936,8 @@ class Post
                        $uid = $conv->getProfileOwner();
                        $parent_uid = $this->getDataValue('uid');
 
+                       $contact = Contact::getById($a->contact_id);
+
                        $default_text = $this->getDefaultText();
 
                        if (!is_null($parent_uid) && ($uid != $parent_uid)) {
@@ -953,9 +955,9 @@ class Post
                                '$qcomment'    => $qcomment,
                                '$default'     => $default_text,
                                '$profile_uid' => $uid,
-                               '$mylink'      => DI::baseUrl()->remove($a->contact['url'] ?? ''),
+                               '$mylink'      => DI::baseUrl()->remove($contact['url'] ?? ''),
                                '$mytitle'     => DI::l10n()->t('This is you'),
-                               '$myphoto'     => DI::baseUrl()->remove($a->contact['thumb'] ?? ''),
+                               '$myphoto'     => DI::baseUrl()->remove($contact['thumb'] ?? ''),
                                '$comment'     => DI::l10n()->t('Comment'),
                                '$submit'      => DI::l10n()->t('Submit'),
                                '$loading'     => DI::l10n()->t('Loading...'),
@@ -999,15 +1001,7 @@ class Post
 
                if ($this->isToplevel()) {
                        if ($conv->getMode() !== 'profile') {
-                               if ($this->getDataValue('wall') && !$this->getDataValue('self') && !empty($a->page_contact)) {
-                                       // On the network page, I am the owner. On the display page it will be the profile owner.
-                                       // This will have been stored in $a->page_contact by our calling page.
-                                       // Put this person as the wall owner of the wall-to-wall notice.
-
-                                       $this->owner_url = Contact::magicLinkByContact($a->page_contact);
-                                       $this->owner_name = $a->page_contact['name'];
-                                       $this->wall_to_wall = true;
-                               } elseif ($this->getDataValue('owner-link')) {
+                               if ($this->getDataValue('owner-link')) {
                                        $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
                                        $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
                                        $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
index 3945ac8fdb7ffe05b206070984cac6265eb85223..6c846e9dc1ca303a9e7709e8d2b903e27ffcf1db 100644 (file)
@@ -142,9 +142,9 @@ class Authentication
 
                if ($this->session->get('authenticated')) {
                        if ($this->session->get('visitor_id') && !$this->session->get('uid')) {
-                               $contact = $this->dba->selectFirst('contact', [], ['id' => $this->session->get('visitor_id')]);
+                               $contact = $this->dba->selectFirst('contact', ['id'], ['id' => $this->session->get('visitor_id')]);
                                if ($this->dba->isResult($contact)) {
-                                       $a->contact = $contact;
+                                       $a->contact_id = $contact['id'];
                                }
                        }
 
@@ -319,19 +319,9 @@ class Authentication
                        }
                }
 
-               $a->identities = User::identities($masterUid);
-
-               if ($login_initial) {
-                       $this->logger->info('auth_identities: ' . print_r($a->identities, true));
-               }
-
-               if ($login_refresh) {
-                       $this->logger->info('auth_identities refresh: ' . print_r($a->identities, true));
-               }
-
-               $contact = $this->dba->selectFirst('contact', [], ['uid' => $user_record['uid'], 'self' => true]);
+               $contact = $this->dba->selectFirst('contact', ['id'], ['uid' => $user_record['uid'], 'self' => true]);
                if ($this->dba->isResult($contact)) {
-                       $a->contact = $contact;
+                       $a->contact_id = $contact['id'];
                        $this->session->set('cid', $contact['id']);
                }