From 30aad250df30a9c65192d8f2d952597b28676871 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 24 Jul 2021 11:49:11 +0000 Subject: [PATCH] App->contact is now removed --- mod/display.php | 9 ++----- mod/notes.php | 4 +-- mod/photos.php | 3 ++- mod/redir.php | 4 +-- src/App.php | 4 +-- src/Content/Nav.php | 2 +- src/Factory/Notification/Notification.php | 3 --- src/Model/Item.php | 2 +- src/Model/Profile.php | 4 +-- src/Model/User.php | 32 +++++++++++++++++++++++ src/Module/Contact/Poke.php | 3 ++- src/Module/Delegation.php | 2 +- src/Module/Item/Compose.php | 9 ++++--- src/Module/Magic.php | 2 +- src/Object/Post.php | 18 +++++-------- src/Security/Authentication.php | 18 +++---------- 16 files changed, 65 insertions(+), 54 deletions(-) diff --git a/mod/display.php b/mod/display.php index 3a93e504a..6abf4c019 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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.')); diff --git a/mod/notes.php b/mod/notes.php index 8b9da3969..2759164bc 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -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', diff --git a/mod/photos.php b/mod/photos.php index 37d3c467b..f999b29d8 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -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) { diff --git a/mod/redir.php b/mod/redir.php index 2f97911dc..ca0fe71a8 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -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; diff --git a/src/App.php b/src/App.php index 47d70db64..aba922804 100644 --- a/src/App.php +++ b/src/App.php @@ -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 diff --git a/src/Content/Nav.php b/src/Content/Nav.php index db3fa7863..20b3a9325 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -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')]; } diff --git a/src/Factory/Notification/Notification.php b/src/Factory/Notification/Notification.php index e69b2131e..9f833130a 100644 --- a/src/Factory/Notification/Notification.php +++ b/src/Factory/Notification/Notification.php @@ -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'] ?? ''; } /** diff --git a/src/Model/Item.php b/src/Model/Item.php index cbac14a11..477d8f3be 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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']); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index d81ecc239..980cd204e 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -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'])); diff --git a/src/Model/User.php b/src/Model/User.php index 3d76b0800..78ef3085a 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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 * diff --git a/src/Module/Contact/Poke.php b/src/Module/Contact/Poke.php index 6e8920c5c..f8f58fe48 100644 --- a/src/Module/Contact/Poke.php +++ b/src/Module/Contact/Poke.php @@ -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); diff --git a/src/Module/Delegation.php b/src/Module/Delegation.php index 70991c0d0..201f38990 100644 --- a/src/Module/Delegation.php +++ b/src/Module/Delegation.php @@ -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) { diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index c2bfba2dc..21dd5625c 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -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'), diff --git a/src/Module/Magic.php b/src/Module/Magic.php index c3a0168b4..81d6def33 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -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; diff --git a/src/Object/Post.php b/src/Object/Post.php index bd6e2299e..a56a73a26 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -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')); diff --git a/src/Security/Authentication.php b/src/Security/Authentication.php index 3945ac8fd..6c846e9dc 100644 --- a/src/Security/Authentication.php +++ b/src/Security/Authentication.php @@ -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']); }