3 namespace Friendica\Module;
5 use Friendica\BaseModule;
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;
16 * Remotely follow the account on this system by the provided account
18 class RemoteFollow extends BaseModule
20 public static function init(array $parameters = [])
22 Profile::load(DI::app(), $parameters['profile']);
25 public static function post(array $parameters = [])
29 if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
30 DI::baseUrl()->redirect();
33 if (empty($a->profile['uid'])) {
34 notice(DI::l10n()->t('Profile unavailable.'));
38 $url = trim($_POST['dfrn_url']);
40 notice(DI::l10n()->t("Invalid locator"));
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"));
51 // Fetch link for the "remote follow" functionality of the given profile
52 $follow_link_template = Probe::getRemoteFollowLink($url);
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."));
59 Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $follow_link_template]);
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']);
67 $uri = urlencode($a->profile['url']);
70 $follow_link = str_replace('{uri}', $uri, $follow_link_template);
71 System::externalRedirect($follow_link);
74 public static function content(array $parameters = [])
78 if (empty($a->profile)) {
82 $target_addr = $a->profile['addr'];
83 $target_url = $a->profile['url'];
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'),
95 '$request' => 'remote_follow/' . $parameters['profile'],
96 '$name' => $a->profile['name'],
97 '$myaddr' => Profile::getMyURL(),