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->t('User not found.'));
61 $this->baseUrl = $baseUrl;
65 public function post()
67 if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
68 $this->baseUrl->redirect();
71 if (empty($this->owner)) {
72 notice($this->t('Profile unavailable.'));
76 $url = Probe::cleanURI($_POST['dfrn_url']);
78 notice($this->t("Invalid locator"));
82 // Detect the network, make sure the provided URL is valid
83 $data = Contact::getByURL($url);
85 notice($this->t("The provided profile link doesn't seem to be valid"));
89 if (empty($data['subscribe'])) {
90 notice($this->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
94 Logger::notice('Remote request', ['url' => $url, 'follow' => $this->owner['url'], 'remote' => $data['subscribe']]);
96 // Substitute our user's feed URL into $data['subscribe']
97 // Send the subscriber home to subscribe
98 // Diaspora needs the uri in the format user@domain.tld
99 if ($data['network'] == Protocol::DIASPORA) {
100 $uri = urlencode($this->owner['addr']);
102 $uri = urlencode($this->owner['url']);
105 $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
106 System::externalRedirect($follow_link);
109 public function content(): string
111 if (empty($this->owner)) {
115 $this->page['aside'] = Widget\VCard::getHTML($this->owner);
117 $target_addr = $this->owner['addr'];
118 $target_url = $this->owner['url'];
120 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
121 $o = Renderer::replaceMacros($tpl, [
122 '$header' => $this->t('Friend/Connection Request'),
123 '$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),
124 '$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'),
125 '$your_address' => $this->t('Your Webfinger address or profile URL:'),
126 '$pls_answer' => $this->t('Please answer the following:'),
127 '$submit' => $this->t('Submit Request'),
128 '$cancel' => $this->t('Cancel'),
130 '$request' => 'remote_follow/' . $this->parameters['profile'],
131 '$name' => $this->owner['name'],
132 '$myaddr' => Profile::getMyURL(),