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;
24 use Friendica\App\BaseURL;
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;
41 * Remotely follow the account on this system by the provided account
43 class RemoteFollow extends BaseModule
52 public function __construct(L10n $l10n, Page $page, BaseURL $baseUrl, array $parameters = [])
54 parent::__construct($l10n, $parameters);
56 $this->owner = User::getOwnerDataByNick($this->parameters['profile']);
58 throw new HTTPException\NotFoundException($this->l10n->t('User not found.'));
61 $this->baseUrl = $baseUrl;
63 $page['aside'] = Widget\VCard::getHTML($this->owner);
66 public function post()
68 if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
69 $this->baseUrl->redirect();
72 if (empty($this->owner)) {
73 notice($this->l10n->t('Profile unavailable.'));
77 $url = Probe::cleanURI($_POST['dfrn_url']);
79 notice($this->l10n->t("Invalid locator"));
83 // Detect the network, make sure the provided URL is valid
84 $data = Contact::getByURL($url);
86 notice($this->l10n->t("The provided profile link doesn't seem to be valid"));
90 if (empty($data['subscribe'])) {
91 notice($this->l10n->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
95 Logger::notice('Remote request', ['url' => $url, 'follow' => $this->owner['url'], 'remote' => $data['subscribe']]);
97 // Substitute our user's feed URL into $data['subscribe']
98 // Send the subscriber home to subscribe
99 // Diaspora needs the uri in the format user@domain.tld
100 if ($data['network'] == Protocol::DIASPORA) {
101 $uri = urlencode($this->owner['addr']);
103 $uri = urlencode($this->owner['url']);
106 $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
107 System::externalRedirect($follow_link);
110 public function content(): string
112 if (empty($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->l10n->t('Friend/Connection Request'),
122 '$page_desc' => $this->l10n->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->l10n->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->l10n->t('Your Webfinger address or profile URL:'),
125 '$pls_answer' => $this->l10n->t('Please answer the following:'),
126 '$submit' => $this->l10n->t('Submit Request'),
127 '$cancel' => $this->l10n->t('Cancel'),
129 '$request' => 'remote_follow/' . $this->parameters['profile'],
130 '$name' => $this->owner['name'],
131 '$myaddr' => Profile::getMyURL(),