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 if (empty($parameters['profile'])) {
26 Profile::load(DI::app(), $parameters['profile']);
29 public static function post(array $parameters = [])
33 if (empty($parameters['profile']) || !empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
34 DI::baseUrl()->redirect();
37 if (empty($a->profile['uid'])) {
38 notice(DI::l10n()->t('Profile unavailable.') . EOL);
42 $url = trim($_POST['dfrn_url']);
44 notice(DI::l10n()->t("Invalid locator") . EOL);
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"));
55 // Fetch link for the "remote follow" functionality of the given profile
56 $follow_link_template = Probe::getRemoteFollowLink($url);
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."));
63 Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $follow_link_template]);
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']);
71 $uri = urlencode($a->profile['url']);
74 $follow_link = str_replace('{uri}', $uri, $follow_link_template);
75 System::externalRedirect($follow_link);
78 public static function content(array $parameters = [])
82 if (empty($parameters['profile']) || empty($a->profile)) {
86 $target_addr = $a->profile['addr'];
87 $target_url = $a->profile['url'];
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'),
99 '$request' => 'remote_follow/' . $parameters['profile'],
100 '$name' => $a->profile['name'],
101 '$myaddr' => '', //Profile::getMyURL(),