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