]> git.mxchange.org Git - friendica.git/blob - src/Module/RemoteFollow.php
Inverted condition
[friendica.git] / src / Module / RemoteFollow.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\DI;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Search;
30 use Friendica\Core\System;
31 use Friendica\Model\Contact;
32 use Friendica\Model\Profile;
33 use Friendica\Network\Probe;
34
35 /**
36  * Remotely follow the account on this system by the provided account
37  */
38 class RemoteFollow extends BaseModule
39 {
40         public static function init(array $parameters = [])
41         {
42                 Profile::load(DI::app(), $parameters['profile']);
43         }
44
45         public static function post(array $parameters = [])
46         {
47                 $a = DI::app();
48
49                 if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
50                         DI::baseUrl()->redirect();
51                 }
52         
53                 if (empty($a->profile['uid'])) {
54                         notice(DI::l10n()->t('Profile unavailable.'));
55                         return;
56                 }
57                 
58                 $url = Probe::cleanURI($_POST['dfrn_url']);
59                 if (!strlen($url)) {
60                         notice(DI::l10n()->t("Invalid locator"));
61                         return;
62                 }
63
64                 // Detect the network, make sure the provided URL is valid
65                 $data = Contact::getByURL($url);
66                 if (!$data) {
67                         notice(DI::l10n()->t("The provided profile link doesn't seem to be valid"));
68                         return;
69                 }
70
71                 if (empty($data['subscribe'])) {
72                         notice(DI::l10n()->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
73                         return;
74                 }
75
76                 Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $data['subscribe']]);
77                 
78                 // Substitute our user's feed URL into $data['subscribe']
79                 // Send the subscriber home to subscribe
80                 // Diaspora needs the uri in the format user@domain.tld
81                 if ($data['network'] == Protocol::DIASPORA) {
82                         $uri = urlencode($a->profile['addr']);
83                 } else {
84                         $uri = urlencode($a->profile['url']);
85                 }
86         
87                 $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
88                 System::externalRedirect($follow_link);
89         }
90
91         public static function content(array $parameters = [])
92         {
93                 $a = DI::app();
94
95                 if (empty($a->profile)) {
96                         return '';
97                 }
98         
99                 $target_addr = $a->profile['addr'];
100                 $target_url = $a->profile['url'];
101
102                 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
103                 $o = Renderer::replaceMacros($tpl, [
104                         '$header'        => DI::l10n()->t('Friend/Connection Request'),
105                         '$page_desc'     => DI::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),
106                         '$invite_desc'   => DI::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'),
107                         '$your_address'  => DI::l10n()->t('Your Webfinger address or profile URL:'),
108                         '$pls_answer'    => DI::l10n()->t('Please answer the following:'),
109                         '$submit'        => DI::l10n()->t('Submit Request'),
110                         '$cancel'        => DI::l10n()->t('Cancel'),
111
112                         '$request'       => 'remote_follow/' . $parameters['profile'],
113                         '$name'          => $a->profile['name'],
114                         '$myaddr'        => Profile::getMyURL(),
115                 ]);
116                 return $o;
117         }
118 }