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