From 8e6f676719c027c6288b8ffa5ec6842c899c62dd Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 30 Oct 2022 01:31:26 +0200 Subject: [PATCH 01/12] Move mod/follow to src/Modules --- mod/follow.php | 210 ---------------------------------- src/Module/Follow.php | 240 +++++++++++++++++++++++++++++++++++++++ static/routes.config.php | 1 + 3 files changed, 241 insertions(+), 210 deletions(-) delete mode 100644 mod/follow.php create mode 100644 src/Module/Follow.php diff --git a/mod/follow.php b/mod/follow.php deleted file mode 100644 index cd39d4dda7..0000000000 --- a/mod/follow.php +++ /dev/null @@ -1,210 +0,0 @@ -. - * - */ - -use Friendica\App; -use Friendica\Content\Widget; -use Friendica\Core\Protocol; -use Friendica\Core\Renderer; -use Friendica\DI; -use Friendica\Model\Contact; -use Friendica\Model\Profile; -use Friendica\Model\Item; -use Friendica\Network\Probe; -use Friendica\Database\DBA; -use Friendica\Model\Post; -use Friendica\Model\User; -use Friendica\Util\Strings; - -function follow_post(App $a) -{ - if (!DI::userSession()->getLocalUserId()) { - throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); - } - - if (isset($_REQUEST['cancel'])) { - DI::baseUrl()->redirect('contact'); - } - - $url = Probe::cleanURI($_REQUEST['url']); - - follow_process($a, $url); -} - -function follow_content(App $a) -{ - $return_path = 'contact'; - - if (!DI::userSession()->getLocalUserId()) { - DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); - DI::baseUrl()->redirect($return_path); - // NOTREACHED - } - - $uid = DI::userSession()->getLocalUserId(); - - $url = Probe::cleanURI(trim($_REQUEST['url'] ?? '')); - - // Issue 6874: Allow remote following from Peertube - if (strpos($url, 'acct:') === 0) { - $url = str_replace('acct:', '', $url); - } - - if (!$url) { - DI::baseUrl()->redirect($return_path); - } - - $submit = DI::l10n()->t('Submit Request'); - - // Don't try to add a pending contact - $user_contact = DBA::selectFirst('contact', ['pending'], ["`uid` = ? AND ((`rel` != ?) OR (`network` = ?)) AND - (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - $uid, Contact::FOLLOWER, Protocol::DFRN, Strings::normaliseLink($url), - Strings::normaliseLink($url), $url, Protocol::STATUSNET]); - - if (DBA::isResult($user_contact)) { - if ($user_contact['pending']) { - DI::sysmsg()->addNotice(DI::l10n()->t('You already added this contact.')); - $submit = ''; - } - } - - $contact = Contact::getByURL($url, true); - - // Possibly it is a mail contact - if (empty($contact)) { - $contact = Probe::uri($url, Protocol::MAIL, $uid); - } - - if (empty($contact) || ($contact['network'] == Protocol::PHANTOM)) { - // Possibly it is a remote item and not an account - follow_remote_item($url); - - DI::sysmsg()->addNotice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added.")); - $submit = ''; - $contact = ['url' => $url, 'network' => Protocol::PHANTOM, 'name' => $url, 'keywords' => '']; - } - - $protocol = Contact::getProtocol($contact['url'], $contact['network']); - - if (($protocol == Protocol::DIASPORA) && !DI::config()->get('system', 'diaspora_enabled')) { - DI::sysmsg()->addNotice(DI::l10n()->t("Diaspora support isn't enabled. Contact can't be added.")); - $submit = ''; - } - - if (($protocol == Protocol::OSTATUS) && DI::config()->get('system', 'ostatus_disabled')) { - DI::sysmsg()->addNotice(DI::l10n()->t("OStatus support is disabled. Contact can't be added.")); - $submit = ''; - } - - if ($protocol == Protocol::MAIL) { - $contact['url'] = $contact['addr']; - } - - if (!empty($_REQUEST['auto'])) { - follow_process($a, $contact['url']); - } - - $request = DI::baseUrl() . '/follow'; - $tpl = Renderer::getMarkupTemplate('auto_request.tpl'); - - $owner = User::getOwnerDataById($uid); - if (empty($owner)) { - DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); - DI::baseUrl()->redirect($return_path); - // NOTREACHED - } - - $myaddr = $owner['url']; - - $o = Renderer::replaceMacros($tpl, [ - '$header' => DI::l10n()->t('Connect/Follow'), - '$pls_answer' => DI::l10n()->t('Please answer the following:'), - '$your_address' => DI::l10n()->t('Your Identity Address:'), - '$url_label' => DI::l10n()->t('Profile URL'), - '$keywords_label'=> DI::l10n()->t('Tags:'), - '$submit' => $submit, - '$cancel' => DI::l10n()->t('Cancel'), - - '$action' => $request, - '$name' => $contact['name'], - '$url' => $contact['url'], - '$zrl' => Profile::zrl($contact['url']), - '$myaddr' => $myaddr, - '$keywords' => $contact['keywords'], - - '$does_know_you' => ['knowyou', DI::l10n()->t('%s knows you', $contact['name'])], - '$addnote_field' => ['dfrn-request-message', DI::l10n()->t('Add a personal note:')], - ]); - - DI::page()['aside'] = ''; - - if (!in_array($protocol, [Protocol::PHANTOM, Protocol::MAIL])) { - DI::page()['aside'] = Widget\VCard::getHTML($contact); - - $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), - ['$title' => DI::l10n()->t('Status Messages and Posts')] - ); - - // Show last public posts - $o .= Contact::getPostsFromUrl($contact['url']); - } - - return $o; -} - -function follow_process(App $a, string $url) -{ - $return_path = 'follow?url=' . urlencode($url); - - $result = Contact::createFromProbeForUser($a->getLoggedInUserId(), $url); - - if ($result['success'] == false) { - // Possibly it is a remote item and not an account - follow_remote_item($url); - - if ($result['message']) { - DI::sysmsg()->addNotice($result['message']); - } - DI::baseUrl()->redirect($return_path); - } elseif ($result['cid']) { - DI::baseUrl()->redirect('contact/' . $result['cid']); - } - - DI::sysmsg()->addNotice(DI::l10n()->t('The contact could not be added.')); - - DI::baseUrl()->redirect($return_path); -} - -function follow_remote_item($url) -{ - $item_id = Item::fetchByLink($url, DI::userSession()->getLocalUserId()); - if (!$item_id) { - // If the user-specific search failed, we search and probe a public post - $item_id = Item::fetchByLink($url); - } - - if (!empty($item_id)) { - $item = Post::selectFirst(['guid'], ['id' => $item_id]); - if (DBA::isResult($item)) { - DI::baseUrl()->redirect('display/' . $item['guid']); - } - } -} diff --git a/src/Module/Follow.php b/src/Module/Follow.php new file mode 100644 index 0000000000..2844e40bf2 --- /dev/null +++ b/src/Module/Follow.php @@ -0,0 +1,240 @@ +. + * + */ + +namespace Friendica\Module; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Content\Widget\VCard; +use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\L10n; +use Friendica\Core\Protocol; +use Friendica\Core\Renderer; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Model\Contact; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Model\Profile; +use Friendica\Model\User; +use Friendica\Navigation\SystemMessages; +use Friendica\Network\HTTPException\ForbiddenException; +use Friendica\Network\Probe; +use Friendica\Util\Profiler; +use Friendica\Util\Strings; +use Psr\Log\LoggerInterface; + +class Follow extends BaseModule +{ + /** @var IHandleUserSessions */ + protected $session; + /** @var SystemMessages */ + protected $sysMessages; + /** @var App */ + protected $app; + /** @var IManageConfigValues */ + protected $config; + /** @var App\Page */ + protected $page; + + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, App $app, IManageConfigValues $config, App\Page $page, array $server, array $parameters = []) + { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->session = $session; + $this->sysMessages = $sysMessages; + $this->app = $app; + $this->config = $config; + $this->page = $page; + } + + protected function post(array $request = []) + { + parent::post($request); + + if (!$this->session->getLocalUserId()) { + throw new ForbiddenException($this->t('Access denied.')); + } + + if (!empty($request['url'])) { + $this->baseUrl->redirect($request['url']); + } + + $url = Probe::cleanURI($this->session->get('url')); + } + + protected function content(array $request = []): string + { + $returnPath = 'contact'; + + if (!$this->session->getLocalUserId()) { + $this->sysMessages->addNotice($this->t('Permission denied.')); + $this->baseUrl->redirect($returnPath); + } + + $uid = $this->session->getLocalUserId(); + $url = Probe::cleanURI(trim($request['url'] ?? '')); + + // Issue 6874: Allow remote following from Peertube + if (strpos($url, 'acct:') === 0) { + $url = str_replace('acct:', '', $url); + } + + if (empty($url)) { + $this->baseUrl->redirect($returnPath); + } + + $submit = $this->t('Submit Request'); + + // Don't try to add a pending contact + $userContact = Contact::selectFirst(['pending'], [ + "`uid` = ? AND ((`rel` != ?) OR (`network` = ?)) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", + $uid, Contact::FOLLOWER, Protocol::DFRN, + Strings::normaliseLink($url), + Strings::normaliseLink($url), $url, + Protocol::STATUSNET]); + + if (!empty($userContact['pending'])) { + $this->sysMessages->addNotice($this->t('You already added this contact.')); + $submit = ''; + } + + $contact = Contact::getByURL($url, true); + + // Possibly it is a mail contact + if (empty($contact)) { + $contact = Probe::uri($url, Protocol::MAIL, $uid); + } + + if (empty($contact) || ($contact['network'] == Protocol::PHANTOM)) { + // Possibly it is a remote item and not an account + $this->followRemoteItem($url); + + $this->sysMessages->addNotice($this->t('The network type couldn\'t be detected. Contact can\'t be added.')); + $submit = ''; + $contact = ['url' => $url, 'network' => Protocol::PHANTOM, 'name' => $url, 'keywords' => '']; + } + + $protocol = Contact::getProtocol($contact['url'], $contact['network']); + + if (($protocol == Protocol::DIASPORA) && !$this->config->get('system', 'diaspora_enabled')) { + $this->sysMessages->addNotice($this->t('Diaspora support isn\'t enabled. Contact can\'t be added.')); + $submit = ''; + } + + if (($protocol == Protocol::OSTATUS) && $this->config->get('system', 'ostatus_disabled')) { + $this->sysMessages->addNotice($this->t("OStatus support is disabled. Contact can't be added.")); + $submit = ''; + } + + if ($protocol == Protocol::MAIL) { + $contact['url'] = $contact['addr']; + } + + if (!empty($request['auto'])) { + $this->process($contact['url']); + } + + $request = $this->baseUrl . '/follow'; + $tpl = Renderer::getMarkupTemplate('auto_request.tpl'); + + $owner = User::getOwnerDataById($uid); + if (empty($owner)) { + $this->sysMessages->addNotice($this->t('Permission denied.')); + $this->baseUrl->redirect($returnPath); + } + + $myaddr = $owner['url']; + + $output = Renderer::replaceMacros($tpl, [ + '$header' => $this->t('Connect/Follow'), + '$pls_answer' => $this->t('Please answer the following:'), + '$your_address' => $this->t('Your Identity Address:'), + '$url_label' => $this->t('Profile URL'), + '$keywords_label' => $this->t('Tags:'), + '$submit' => $submit, + '$cancel' => $this->t('Cancel'), + + '$request' => $request, + '$name' => $contact['name'], + '$url' => $contact['url'], + '$zrl' => Profile::zrl($contact['url']), + '$myaddr' => $myaddr, + '$keywords' => $contact['keywords'], + + '$does_know_you' => ['knowyou', $this->t('%s knows you', $contact['name'])], + '$addnote_field' => ['dfrn-request-message', $this->t('Add a personal note:')], + ]); + + $this['aside'] = ''; + + if (!in_array($protocol, [Protocol::PHANTOM, Protocol::MAIL])) { + $this['aside'] = VCard::getHTML($contact); + + $output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), + ['$title' => $this->t('Status Messages and Posts')] + ); + + // Show last public posts + $output .= Contact::getPostsFromUrl($contact['url']); + } + + return $output; + } + + protected function process(string $url) + { + $returnPath = 'follow?rul=' . urlencode($url); + + $result = Contact::createFromProbeForUser($this->app->getLoggedInUserId(), $url); + + if (!$result['success']) { + // Possibly it is a remote item and not an account + $this->followRemoteItem($url); + + if (!empty($result['message'])) { + $this->sysMessages->addNotice($result['message']); + } + + $this->baseUrl->redirect($returnPath); + } else if (!empty($result['cid'])) { + $this->baseUrl->redirect('contact/' . $result['cid']); + } + + $this->sysMessages->addNotice($this->t('The contact could not be added.')); + $this->baseUrl->redirect($returnPath); + } + + protected function followRemoteItem(string $url) + { + $itemId = Item::fetchByLink($url, $this->session->getLocalUserId()); + if (!$itemId) { + // If the user-specific search failed, we search and probe a public post + $itemId = Item::fetchByLink($url); + } + + if (!empty($itemId)) { + $item = Post::selectFirst(['guid'], ['id' => $itemId]); + if (!empty($item['guid'])) { + $this->baseUrl->redirect('display/' . $item['guid']); + } + } + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 62742b6593..a478ff05bb 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -418,6 +418,7 @@ return [ '/filed' => [Module\Search\Filed::class, [R::GET]], '/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]], '/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET, R::POST]], + '/follow[/{url}]' => [Module\Follow::class, [R::GET, R::POST]], '/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]], '/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]], '/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]], From 0e47d5b0aa518529447122040d3b1aa0def18d4e Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 30 Oct 2022 01:34:52 +0200 Subject: [PATCH 02/12] make CS happy --- src/Module/Follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Follow.php b/src/Module/Follow.php index 2844e40bf2..95ad2c9ae7 100644 --- a/src/Module/Follow.php +++ b/src/Module/Follow.php @@ -214,7 +214,7 @@ class Follow extends BaseModule } $this->baseUrl->redirect($returnPath); - } else if (!empty($result['cid'])) { + } elseif (!empty($result['cid'])) { $this->baseUrl->redirect('contact/' . $result['cid']); } From 437472d0a6914d7c01887f2f6c840bbba2193cc1 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 12:51:51 +0100 Subject: [PATCH 03/12] Move Follow to Contact namespace --- src/Module/{ => Contact}/Follow.php | 3 ++- static/routes.config.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename src/Module/{ => Contact}/Follow.php (99%) diff --git a/src/Module/Follow.php b/src/Module/Contact/Follow.php similarity index 99% rename from src/Module/Follow.php rename to src/Module/Contact/Follow.php index 95ad2c9ae7..08585d26f9 100644 --- a/src/Module/Follow.php +++ b/src/Module/Contact/Follow.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\Contact; use Friendica\App; use Friendica\BaseModule; @@ -34,6 +34,7 @@ use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Model\User; +use Friendica\Module\Response; use Friendica\Navigation\SystemMessages; use Friendica\Network\HTTPException\ForbiddenException; use Friendica\Network\Probe; diff --git a/static/routes.config.php b/static/routes.config.php index a478ff05bb..072ee93878 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -418,7 +418,7 @@ return [ '/filed' => [Module\Search\Filed::class, [R::GET]], '/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]], '/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET, R::POST]], - '/follow[/{url}]' => [Module\Follow::class, [R::GET, R::POST]], + '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], '/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]], '/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]], '/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]], From 355489457769e5358a10b92c4a7de1224fb581d9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 12:53:48 +0100 Subject: [PATCH 04/12] Fixup post --- src/Module/Contact/Follow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index 08585d26f9..7504501d41 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -68,8 +68,6 @@ class Follow extends BaseModule protected function post(array $request = []) { - parent::post($request); - if (!$this->session->getLocalUserId()) { throw new ForbiddenException($this->t('Access denied.')); } @@ -79,6 +77,8 @@ class Follow extends BaseModule } $url = Probe::cleanURI($this->session->get('url')); + + $this->process($url); } protected function content(array $request = []): string From b5d01337d9ef3f616829956b059ba55a4642798f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 17:58:04 +0100 Subject: [PATCH 05/12] Move Follow to `/contact` namespace --- src/Model/APContact.php | 2 +- src/Model/Profile.php | 2 +- src/Module/Contact/Follow.php | 2 +- src/Module/Xrd.php | 6 +++--- src/Network/Probe.php | 2 +- static/routes.config.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 7b49bab8ab..742efcf190 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -62,7 +62,7 @@ class APContact 'addr' => $local_owner['addr'], 'baseurl' => $local_owner['baseurl'], 'url' => $local_owner['url'], - 'subscribe' => $local_owner['baseurl'] . '/follow?url={uri}']; + 'subscribe' => $local_owner['baseurl'] . '/contact/follow?url={uri}']; if (!empty($local_owner['alias']) && ($local_owner['url'] != $local_owner['alias'])) { $data['alias'] = $local_owner['alias']; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index b73b235385..29f6b29376 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -341,7 +341,7 @@ class Profile if ($visitor_is_following) { $unfollow_link = $visitor_base_path . '/contact/unfollow?url=' . urlencode($profile_url) . '&auto=1'; } else { - $follow_link = $visitor_base_path . '/follow?url=' . urlencode($profile_url) . '&auto=1'; + $follow_link = $visitor_base_path .'/contact/follow?url=' . urlencode($profile_url) . '&auto=1'; } } diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index 7504501d41..fe523f491e 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -202,7 +202,7 @@ class Follow extends BaseModule protected function process(string $url) { - $returnPath = 'follow?rul=' . urlencode($url); + $returnPath = 'follow?url=' . urlencode($url); $result = Contact::createFromProbeForUser($this->app->getLoggedInUserId(), $url); diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 098c1574ea..4e4603fbdb 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -122,7 +122,7 @@ class Xrd extends BaseModule ], [ 'rel' => 'http://ostatus.org/schema/1.0/subscribe', - 'template' => $baseURL . '/follow?url={uri}', + 'template' => $baseURL . '/contact/follow?url={uri}', ], [ 'rel' => ActivityNamespace::FEED, @@ -212,7 +212,7 @@ class Xrd extends BaseModule ], [ 'rel' => 'http://ostatus.org/schema/1.0/subscribe', - 'template' => $baseURL . '/follow?url={uri}', + 'template' => $baseURL . '/contact/follow?url={uri}', ], [ 'rel' => 'magic-public-key', @@ -312,7 +312,7 @@ class Xrd extends BaseModule '11:link' => [ '@attributes' => [ 'rel' => 'http://ostatus.org/schema/1.0/subscribe', - 'template' => $baseURL . '/follow?url={uri}' + 'template' => $baseURL . '/contact/follow?url={uri}' ] ], '12:link' => [ diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 43f1dca66f..45b838da21 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -2185,7 +2185,7 @@ class Probe 'xmpp' => $owner['xmpp'], 'matrix' => $owner['matrix'], 'hide' => !$owner['net-publish'], 'batch' => '', 'notify' => $owner['notify'], 'poll' => $owner['poll'], 'request' => $owner['request'], 'confirm' => $owner['confirm'], - 'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $owner['poco'], + 'subscribe' => $approfile['generator']['url'] . '/contact/follow?url={uri}', 'poco' => $owner['poco'], 'following' => $approfile['following'], 'followers' => $approfile['followers'], 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'], 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN, diff --git a/static/routes.config.php b/static/routes.config.php index 072ee93878..d21e9efae5 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -387,6 +387,7 @@ return [ '/hidden' => [Module\Contact::class, [R::GET]], '/ignored' => [Module\Contact::class, [R::GET]], '/hovercard' => [Module\Contact\Hovercard::class, [R::GET]], + '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], '/unfollow' => [Module\Contact\Unfollow::class, [R::GET, R::POST]], ], @@ -418,7 +419,6 @@ return [ '/filed' => [Module\Search\Filed::class, [R::GET]], '/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]], '/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET, R::POST]], - '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], '/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]], '/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]], '/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]], From 87291e30a45e660b47a9ea95326200c88cc642dd Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 19:10:30 +0100 Subject: [PATCH 06/12] Found some more follow-links --- src/Content/Item.php | 2 +- src/Content/Widget/VCard.php | 2 +- src/Model/Contact.php | 2 +- src/Module/Contact/Follow.php | 9 +++------ static/routes.config.php | 2 +- view/theme/vier/theme.php | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Content/Item.php b/src/Content/Item.php index 3d6443fe3f..c867582b94 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -401,7 +401,7 @@ class Item if ((($cid == 0) || ($rel == Contact::FOLLOWER)) && in_array($item['network'], Protocol::FEDERATED)) { - $menu[$this->l10n->t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']) . '&auto=1'; + $menu[$this->l10n->t('Connect/Follow')] = 'contact/follow?url=' . urlencode($item['author-link']) . '&auto=1'; } } else { $menu = [$this->l10n->t('View Profile') => $item['author-link']]; diff --git a/src/Content/Widget/VCard.php b/src/Content/Widget/VCard.php index 1edbf63c8c..adb77319c0 100644 --- a/src/Content/Widget/VCard.php +++ b/src/Content/Widget/VCard.php @@ -85,7 +85,7 @@ class VCard if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) { $unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1'; } elseif (!$pending) { - $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1'; + $follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1'; } } diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 0ae7003f05..7c83e03511 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1178,7 +1178,7 @@ class Contact if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) { $unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1'; } elseif(!$contact['pending']) { - $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1'; + $follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1'; } } diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index fe523f491e..0e1e129e92 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -48,20 +48,17 @@ class Follow extends BaseModule protected $session; /** @var SystemMessages */ protected $sysMessages; - /** @var App */ - protected $app; /** @var IManageConfigValues */ protected $config; /** @var App\Page */ protected $page; - public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, App $app, IManageConfigValues $config, App\Page $page, array $server, array $parameters = []) + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, IManageConfigValues $config, App\Page $page, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); $this->session = $session; $this->sysMessages = $sysMessages; - $this->app = $app; $this->config = $config; $this->page = $page; } @@ -202,9 +199,9 @@ class Follow extends BaseModule protected function process(string $url) { - $returnPath = 'follow?url=' . urlencode($url); + $returnPath = 'contact/follow?url=' . urlencode($url); - $result = Contact::createFromProbeForUser($this->app->getLoggedInUserId(), $url); + $result = Contact::createFromProbeForUser($this->session->getLocalUserId(), $url); if (!$result['success']) { // Possibly it is a remote item and not an account diff --git a/static/routes.config.php b/static/routes.config.php index d21e9efae5..2b7f5b98da 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -387,7 +387,7 @@ return [ '/hidden' => [Module\Contact::class, [R::GET]], '/ignored' => [Module\Contact::class, [R::GET]], '/hovercard' => [Module\Contact\Hovercard::class, [R::GET]], - '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], + '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], '/unfollow' => [Module\Contact\Unfollow::class, [R::GET, R::POST]], ], diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index 2d313cb29e..bb647bc638 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -154,7 +154,7 @@ function vier_community_info() foreach ($contacts as $contact) { $entry = Renderer::replaceMacros($tpl, [ '$id' => $contact['id'], - '$profile_link' => 'follow/?url='.urlencode($contact['url']), + '$profile_link' => 'contact/follow/?url='.urlencode($contact['url']), '$photo' => Contact::getMicro($contact), '$alt_text' => $contact['name'], ]); From eb9da2967e8b441e8d2f9df08ef7280e348bd1fb Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 20:26:52 +0100 Subject: [PATCH 07/12] Fixups ... hopefully the last one :-/ --- src/Module/Contact/Follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index 0e1e129e92..e9373afa56 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -73,7 +73,7 @@ class Follow extends BaseModule $this->baseUrl->redirect($request['url']); } - $url = Probe::cleanURI($this->session->get('url')); + $url = Probe::cleanURI($request['url']); $this->process($url); } From 82cd6ff91d144240f3f9872c2450931b47e40d8f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 20:51:13 +0100 Subject: [PATCH 08/12] Fixing the non-auto follow process ... --- src/Module/Contact/Follow.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index e9373afa56..f3d4a386f8 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -69,8 +69,8 @@ class Follow extends BaseModule throw new ForbiddenException($this->t('Access denied.')); } - if (!empty($request['url'])) { - $this->baseUrl->redirect($request['url']); + if (isset($request['cancel']) || empty($request['url'])) { + $this->baseUrl->redirect('contact'); } $url = Probe::cleanURI($request['url']); @@ -150,7 +150,7 @@ class Follow extends BaseModule $this->process($contact['url']); } - $request = $this->baseUrl . '/follow'; + $requestUrl = $this->baseUrl . '/contact/follow'; $tpl = Renderer::getMarkupTemplate('auto_request.tpl'); $owner = User::getOwnerDataById($uid); @@ -170,7 +170,7 @@ class Follow extends BaseModule '$submit' => $submit, '$cancel' => $this->t('Cancel'), - '$request' => $request, + '$request' => $requestUrl, '$name' => $contact['name'], '$url' => $contact['url'], '$zrl' => Profile::zrl($contact['url']), @@ -181,10 +181,10 @@ class Follow extends BaseModule '$addnote_field' => ['dfrn-request-message', $this->t('Add a personal note:')], ]); - $this['aside'] = ''; + $this->page['aside'] = ''; if (!in_array($protocol, [Protocol::PHANTOM, Protocol::MAIL])) { - $this['aside'] = VCard::getHTML($contact); + $this->page['aside'] = VCard::getHTML($contact); $output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => $this->t('Status Messages and Posts')] From 8f62278703638626900638931d24d961a326cbf0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 21:00:23 +0100 Subject: [PATCH 09/12] Rename $action because of PR before --- src/Module/Contact/Follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index f3d4a386f8..e240a72204 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -170,7 +170,7 @@ class Follow extends BaseModule '$submit' => $submit, '$cancel' => $this->t('Cancel'), - '$request' => $requestUrl, + '$action' => $requestUrl, '$name' => $contact['name'], '$url' => $contact['url'], '$zrl' => Profile::zrl($contact['url']), From 94d615fbb79ad914cbe23adb0158515c3b7ee48c Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 21:00:30 +0100 Subject: [PATCH 10/12] Update messages.po --- view/lang/C/messages.po | 168 ++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 3fabe28c6c..581632207f 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2022.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-10-31 15:34-0400\n" +"POT-Creation-Date: 2022-10-31 19:59+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,8 +18,8 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" -#: mod/cal.php:45 mod/cal.php:49 mod/follow.php:39 mod/redir.php:35 -#: mod/redir.php:176 src/Module/Conversation/Community.php:193 +#: mod/cal.php:45 mod/cal.php:49 mod/redir.php:35 mod/redir.php:176 +#: src/Module/Contact/Follow.php:69 src/Module/Conversation/Community.php:193 #: src/Module/Debug/ItemBody.php:38 src/Module/Diaspora/Receive.php:57 #: src/Module/Item/Follow.php:41 src/Module/Item/Ignore.php:41 #: src/Module/Item/Pin.php:41 src/Module/Item/Pin.php:56 @@ -119,19 +119,19 @@ msgstr "" msgid "The feed for this item is unavailable." msgstr "" -#: mod/editpost.php:38 mod/events.php:218 mod/follow.php:56 mod/follow.php:130 -#: mod/item.php:181 mod/item.php:186 mod/item.php:870 mod/message.php:69 -#: mod/message.php:114 mod/notes.php:44 mod/ostatus_subscribe.php:33 -#: mod/photos.php:159 mod/photos.php:886 mod/repair_ostatus.php:31 -#: mod/settings.php:40 mod/settings.php:50 mod/settings.php:156 -#: mod/suggest.php:34 mod/uimport.php:33 src/Module/Attach.php:56 -#: src/Module/BaseApi.php:94 src/Module/BaseNotifications.php:98 -#: src/Module/Contact/Advanced.php:60 src/Module/Contact/Unfollow.php:66 -#: src/Module/Contact/Unfollow.php:80 src/Module/Contact/Unfollow.php:112 -#: src/Module/Delegation.php:118 src/Module/FollowConfirm.php:38 -#: src/Module/FriendSuggest.php:57 src/Module/Group.php:40 -#: src/Module/Group.php:83 src/Module/Invite.php:42 src/Module/Invite.php:131 -#: src/Module/Notifications/Notification.php:76 +#: mod/editpost.php:38 mod/events.php:218 mod/item.php:181 mod/item.php:186 +#: mod/item.php:870 mod/message.php:69 mod/message.php:114 mod/notes.php:44 +#: mod/ostatus_subscribe.php:33 mod/photos.php:159 mod/photos.php:886 +#: mod/repair_ostatus.php:31 mod/settings.php:40 mod/settings.php:50 +#: mod/settings.php:156 mod/suggest.php:34 mod/uimport.php:33 +#: src/Module/Attach.php:56 src/Module/BaseApi.php:94 +#: src/Module/BaseNotifications.php:98 src/Module/Contact/Advanced.php:60 +#: src/Module/Contact/Follow.php:86 src/Module/Contact/Follow.php:158 +#: src/Module/Contact/Unfollow.php:66 src/Module/Contact/Unfollow.php:80 +#: src/Module/Contact/Unfollow.php:112 src/Module/Delegation.php:118 +#: src/Module/FollowConfirm.php:38 src/Module/FriendSuggest.php:57 +#: src/Module/Group.php:40 src/Module/Group.php:83 src/Module/Invite.php:42 +#: src/Module/Invite.php:131 src/Module/Notifications/Notification.php:76 #: src/Module/Notifications/Notification.php:107 #: src/Module/Profile/Attachment/Upload.php:97 src/Module/Profile/Common.php:55 #: src/Module/Profile/Contacts.php:55 src/Module/Profile/Photos/Upload.php:108 @@ -269,8 +269,8 @@ msgid "Preview" msgstr "" #: mod/editpost.php:130 mod/fbrowser.php:119 mod/fbrowser.php:146 -#: mod/follow.php:144 mod/photos.php:999 mod/photos.php:1100 mod/tagrm.php:35 -#: mod/tagrm.php:127 src/Content/Conversation.php:389 +#: mod/photos.php:999 mod/photos.php:1100 mod/tagrm.php:35 mod/tagrm.php:127 +#: src/Content/Conversation.php:389 src/Module/Contact/Follow.php:171 #: src/Module/Contact/Revoke.php:109 src/Module/Contact/Unfollow.php:126 #: src/Module/Profile/RemoteFollow.php:134 #: src/Module/Security/TwoFactor/SignOut.php:125 @@ -452,72 +452,6 @@ msgstr "" msgid "Files" msgstr "" -#: mod/follow.php:74 src/Module/Contact/Unfollow.php:125 -#: src/Module/Profile/RemoteFollow.php:133 -msgid "Submit Request" -msgstr "" - -#: mod/follow.php:84 -msgid "You already added this contact." -msgstr "" - -#: mod/follow.php:100 -msgid "The network type couldn't be detected. Contact can't be added." -msgstr "" - -#: mod/follow.php:108 -msgid "Diaspora support isn't enabled. Contact can't be added." -msgstr "" - -#: mod/follow.php:113 -msgid "OStatus support is disabled. Contact can't be added." -msgstr "" - -#: mod/follow.php:138 src/Content/Item.php:404 src/Content/Widget.php:80 -#: src/Model/Contact.php:1194 src/Model/Contact.php:1205 -#: view/theme/vier/theme.php:198 -msgid "Connect/Follow" -msgstr "" - -#: mod/follow.php:139 src/Module/Profile/RemoteFollow.php:132 -msgid "Please answer the following:" -msgstr "" - -#: mod/follow.php:140 src/Module/Contact/Unfollow.php:123 -msgid "Your Identity Address:" -msgstr "" - -#: mod/follow.php:141 src/Module/Admin/Blocklist/Contact.php:116 -#: src/Module/Contact/Profile.php:366 src/Module/Contact/Unfollow.php:129 -#: src/Module/Notifications/Introductions.php:129 -#: src/Module/Notifications/Introductions.php:198 -msgid "Profile URL" -msgstr "" - -#: mod/follow.php:142 src/Module/Contact/Profile.php:378 -#: src/Module/Notifications/Introductions.php:191 -#: src/Module/Profile/Profile.php:206 -msgid "Tags:" -msgstr "" - -#: mod/follow.php:153 -#, php-format -msgid "%s knows you" -msgstr "" - -#: mod/follow.php:154 -msgid "Add a personal note:" -msgstr "" - -#: mod/follow.php:163 src/Module/BaseProfile.php:59 src/Module/Contact.php:447 -#: src/Module/Contact/Unfollow.php:138 -msgid "Status Messages and Posts" -msgstr "" - -#: mod/follow.php:191 -msgid "The contact could not be added." -msgstr "" - #: mod/item.php:131 mod/item.php:135 msgid "Unable to locate original post." msgstr "" @@ -2284,6 +2218,12 @@ msgstr "" msgid "Languages" msgstr "" +#: src/Content/Item.php:404 src/Content/Widget.php:80 +#: src/Model/Contact.php:1194 src/Model/Contact.php:1205 +#: src/Module/Contact/Follow.php:165 view/theme/vier/theme.php:198 +msgid "Connect/Follow" +msgstr "" + #: src/Content/Nav.php:90 msgid "Nothing new here" msgstr "" @@ -4417,6 +4357,13 @@ msgid_plural "%s total blocked contacts" msgstr[0] "" msgstr[1] "" +#: src/Module/Admin/Blocklist/Contact.php:116 src/Module/Contact/Follow.php:168 +#: src/Module/Contact/Profile.php:366 src/Module/Contact/Unfollow.php:129 +#: src/Module/Notifications/Introductions.php:129 +#: src/Module/Notifications/Introductions.php:198 +msgid "Profile URL" +msgstr "" + #: src/Module/Admin/Blocklist/Contact.php:116 msgid "URL of the remote contact to block." msgstr "" @@ -6662,6 +6609,11 @@ msgstr[1] "" msgid "Profile Details" msgstr "" +#: src/Module/BaseProfile.php:59 src/Module/Contact.php:447 +#: src/Module/Contact/Follow.php:190 src/Module/Contact/Unfollow.php:138 +msgid "Status Messages and Posts" +msgstr "" + #: src/Module/BaseProfile.php:109 msgid "Only You Can See This" msgstr "" @@ -6924,6 +6876,54 @@ msgid_plural "Contacts (%s)" msgstr[0] "" msgstr[1] "" +#: src/Module/Contact/Follow.php:102 src/Module/Contact/Unfollow.php:125 +#: src/Module/Profile/RemoteFollow.php:133 +msgid "Submit Request" +msgstr "" + +#: src/Module/Contact/Follow.php:113 +msgid "You already added this contact." +msgstr "" + +#: src/Module/Contact/Follow.php:128 +msgid "The network type couldn't be detected. Contact can't be added." +msgstr "" + +#: src/Module/Contact/Follow.php:136 +msgid "Diaspora support isn't enabled. Contact can't be added." +msgstr "" + +#: src/Module/Contact/Follow.php:141 +msgid "OStatus support is disabled. Contact can't be added." +msgstr "" + +#: src/Module/Contact/Follow.php:166 src/Module/Profile/RemoteFollow.php:132 +msgid "Please answer the following:" +msgstr "" + +#: src/Module/Contact/Follow.php:167 src/Module/Contact/Unfollow.php:123 +msgid "Your Identity Address:" +msgstr "" + +#: src/Module/Contact/Follow.php:169 src/Module/Contact/Profile.php:378 +#: src/Module/Notifications/Introductions.php:191 +#: src/Module/Profile/Profile.php:206 +msgid "Tags:" +msgstr "" + +#: src/Module/Contact/Follow.php:180 +#, php-format +msgid "%s knows you" +msgstr "" + +#: src/Module/Contact/Follow.php:181 +msgid "Add a personal note:" +msgstr "" + +#: src/Module/Contact/Follow.php:219 +msgid "The contact could not be added." +msgstr "" + #: src/Module/Contact/Profile.php:128 msgid "Failed to update contact record." msgstr "" From 41565326e36421af596e5520e4ce4000d11d2768 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 31 Oct 2022 21:03:58 +0100 Subject: [PATCH 11/12] Make CS happy --- src/Module/Contact/Follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Contact/Follow.php b/src/Module/Contact/Follow.php index e240a72204..c274769402 100644 --- a/src/Module/Contact/Follow.php +++ b/src/Module/Contact/Follow.php @@ -151,7 +151,7 @@ class Follow extends BaseModule } $requestUrl = $this->baseUrl . '/contact/follow'; - $tpl = Renderer::getMarkupTemplate('auto_request.tpl'); + $tpl = Renderer::getMarkupTemplate('auto_request.tpl'); $owner = User::getOwnerDataById($uid); if (empty($owner)) { From baa97febef3d324980b5f60d8512aab6ca4e07a8 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Nov 2022 00:09:30 +0100 Subject: [PATCH 12/12] hopefully last feedback :) --- src/Model/Profile.php | 2 +- static/routes.config.php | 2 +- view/theme/vier/theme.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 29f6b29376..367680c42c 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -341,7 +341,7 @@ class Profile if ($visitor_is_following) { $unfollow_link = $visitor_base_path . '/contact/unfollow?url=' . urlencode($profile_url) . '&auto=1'; } else { - $follow_link = $visitor_base_path .'/contact/follow?url=' . urlencode($profile_url) . '&auto=1'; + $follow_link = $visitor_base_path . '/contact/follow?url=' . urlencode($profile_url) . '&auto=1'; } } diff --git a/static/routes.config.php b/static/routes.config.php index 2b7f5b98da..6f05faee2d 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -387,7 +387,7 @@ return [ '/hidden' => [Module\Contact::class, [R::GET]], '/ignored' => [Module\Contact::class, [R::GET]], '/hovercard' => [Module\Contact\Hovercard::class, [R::GET]], - '/follow[/{url}]' => [Module\Contact\Follow::class, [R::GET, R::POST]], + '/follow' => [Module\Contact\Follow::class, [R::GET, R::POST]], '/unfollow' => [Module\Contact\Unfollow::class, [R::GET, R::POST]], ], diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index bb647bc638..28c5c3e863 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -154,7 +154,7 @@ function vier_community_info() foreach ($contacts as $contact) { $entry = Renderer::replaceMacros($tpl, [ '$id' => $contact['id'], - '$profile_link' => 'contact/follow/?url='.urlencode($contact['url']), + '$profile_link' => 'contact/follow?url=' . urlencode($contact['url']), '$photo' => Contact::getMicro($contact), '$alt_text' => $contact['name'], ]);