3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Profile;
25 use Friendica\App\Page;
26 use Friendica\BaseModule;
27 use Friendica\Content\Widget;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Logger;
30 use Friendica\Core\Protocol;
31 use Friendica\Core\Renderer;
32 use Friendica\Core\Search;
33 use Friendica\Core\Session\Capability\IHandleUserSessions;
34 use Friendica\Core\System;
36 use Friendica\Model\Contact;
37 use Friendica\Model\Profile;
38 use Friendica\Model\User;
39 use Friendica\Module\Response;
40 use Friendica\Navigation\SystemMessages;
41 use Friendica\Network\HTTPException;
42 use Friendica\Network\Probe;
43 use Friendica\Util\Profiler;
44 use Psr\Log\LoggerInterface;
47 * Remotely follow the account on this system by the provided account
49 class RemoteFollow extends BaseModule
51 /** @var SystemMessages */
52 private $systemMessages;
55 /** @var IHandleUserSessions */
61 public function __construct(IHandleUserSessions $userSession, SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
63 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
65 $this->systemMessages = $systemMessages;
67 $this->userSession = $userSession;
69 $this->owner = User::getOwnerDataByNick($this->parameters['nickname']);
71 throw new HTTPException\NotFoundException($this->t('User not found.'));
75 protected function post(array $request = [])
77 if (!empty($request['cancel']) || empty($request['dfrn_url'])) {
78 $this->baseUrl->redirect('profile/' . $this->parameters['nickname']);
81 if (empty($this->owner)) {
82 $this->systemMessages->addNotice($this->t('Profile unavailable.'));
86 $url = Probe::cleanURI($request['dfrn_url']);
88 $this->systemMessages->addNotice($this->t('Invalid locator'));
92 // Detect the network, make sure the provided URL is valid
93 $data = Contact::getByURL($url);
95 $this->systemMessages->addNotice($this->t("The provided profile link doesn't seem to be valid"));
99 if (empty($data['subscribe'])) {
100 $this->systemMessages->addNotice($this->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
104 $this->logger->notice('Remote request', ['url' => $url, 'follow' => $this->owner['url'], 'remote' => $data['subscribe']]);
106 // Substitute our user's feed URL into $data['subscribe']
107 // Send the subscriber home to subscribe
108 // Diaspora needs the uri in the format user@domain.tld
109 if ($data['network'] == Protocol::DIASPORA) {
110 $uri = urlencode($this->owner['addr']);
112 $uri = urlencode($this->owner['url']);
115 $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
116 System::externalRedirect($follow_link);
119 protected function content(array $request = []): string
121 $this->page['aside'] = Widget\VCard::getHTML($this->owner);
123 $target_addr = $this->owner['addr'];
124 $target_url = $this->owner['url'];
126 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
127 return Renderer::replaceMacros($tpl, [
128 '$header' => $this->t('Friend/Connection Request'),
129 '$page_desc' => $this->t('Enter your Webfinger address (user@domain.tld) or profile URL here. If this isn\'t supported by your system, you have to subscribe to <strong>%s</strong> or <strong>%s</strong> directly on your system.', $target_addr, $target_url),
130 '$invite_desc' => $this->t('If you are not yet a member of the free social web, <a href="%s">follow this link to find a public Friendica node and join us today</a>.', Search::getGlobalDirectory() . '/servers'),
131 '$your_address' => $this->t('Your Webfinger address or profile URL:'),
132 '$pls_answer' => $this->t('Please answer the following:'),
133 '$submit' => $this->t('Submit Request'),
134 '$cancel' => $this->t('Cancel'),
136 '$action' => 'profile/' . $this->parameters['nickname'] . '/remote_follow',
137 '$name' => $this->owner['name'],
138 '$myaddr' => $this->userSession->getMyUrl(),