3 * @copyright Copyright (C) 2010-2021, 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;
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\System;
34 use Friendica\Model\Contact;
35 use Friendica\Model\Profile;
36 use Friendica\Model\User;
37 use Friendica\Network\HTTPException;
38 use Friendica\Network\Probe;
39 use Friendica\Util\Profiler;
40 use Psr\Log\LoggerInterface;
43 * Remotely follow the account on this system by the provided account
45 class RemoteFollow extends BaseModule
52 public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
54 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
56 $this->owner = User::getOwnerDataByNick($this->parameters['profile']);
58 throw new HTTPException\NotFoundException($this->t('User not found.'));
64 protected function post(array $request = [])
66 if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
67 $this->baseUrl->redirect();
70 if (empty($this->owner)) {
71 notice($this->t('Profile unavailable.'));
75 $url = Probe::cleanURI($_POST['dfrn_url']);
77 notice($this->t("Invalid locator"));
81 // Detect the network, make sure the provided URL is valid
82 $data = Contact::getByURL($url);
84 notice($this->t("The provided profile link doesn't seem to be valid"));
88 if (empty($data['subscribe'])) {
89 notice($this->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
93 Logger::notice('Remote request', ['url' => $url, 'follow' => $this->owner['url'], 'remote' => $data['subscribe']]);
95 // Substitute our user's feed URL into $data['subscribe']
96 // Send the subscriber home to subscribe
97 // Diaspora needs the uri in the format user@domain.tld
98 if ($data['network'] == Protocol::DIASPORA) {
99 $uri = urlencode($this->owner['addr']);
101 $uri = urlencode($this->owner['url']);
104 $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
105 System::externalRedirect($follow_link);
108 protected function content(array $request = []): string
110 if (empty($this->owner)) {
114 $this->page['aside'] = Widget\VCard::getHTML($this->owner);
116 $target_addr = $this->owner['addr'];
117 $target_url = $this->owner['url'];
119 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
120 $o = Renderer::replaceMacros($tpl, [
121 '$header' => $this->t('Friend/Connection Request'),
122 '$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),
123 '$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'),
124 '$your_address' => $this->t('Your Webfinger address or profile URL:'),
125 '$pls_answer' => $this->t('Please answer the following:'),
126 '$submit' => $this->t('Submit Request'),
127 '$cancel' => $this->t('Cancel'),
129 '$request' => 'remote_follow/' . $this->parameters['profile'],
130 '$name' => $this->owner['name'],
131 '$myaddr' => Profile::getMyURL(),