6 use Friendica\Core\Config;
7 use Friendica\Core\Protocol;
8 use Friendica\Core\Renderer;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Profile;
12 use Friendica\Network\Probe;
13 use Friendica\Database\DBA;
14 use Friendica\Util\Strings;
16 function follow_post(App $a)
19 throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
22 if (isset($_REQUEST['cancel'])) {
23 DI::baseUrl()->redirect('contact');
27 $url = Strings::escapeTags(trim($_REQUEST['url']));
28 $return_path = 'follow?url=' . urlencode($url);
30 // Makes the connection request for friendica contacts easier
31 // This is just a precaution if maybe this page is called somewhere directly via POST
32 $_SESSION['fastlane'] = $url;
34 $result = Contact::createFromProbe($uid, $url, true);
36 if ($result['success'] == false) {
37 if ($result['message']) {
38 notice($result['message']);
40 DI::baseUrl()->redirect($return_path);
41 } elseif ($result['cid']) {
42 DI::baseUrl()->redirect('contact/' . $result['cid']);
45 info(DI::l10n()->t('The contact could not be added.'));
47 DI::baseUrl()->redirect($return_path);
51 function follow_content(App $a)
53 $return_path = 'contact';
56 notice(DI::l10n()->t('Permission denied.'));
57 DI::baseUrl()->redirect($return_path);
63 // Issue 4815: Silently removing a prefixing @
64 $url = ltrim(Strings::escapeTags(trim($_REQUEST['url'] ?? '')), '@!');
66 // Issue 6874: Allow remote following from Peertube
67 if (strpos($url, 'acct:') === 0) {
68 $url = str_replace('acct:', '', $url);
72 DI::baseUrl()->redirect($return_path);
75 $submit = DI::l10n()->t('Submit Request');
77 // Don't try to add a pending contact
78 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
79 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
80 `network` != '%s' LIMIT 1",
81 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
82 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
85 if ($r[0]['pending']) {
86 notice(DI::l10n()->t('You already added this contact.'));
88 //$a->internalRedirect($_SESSION['return_path']);
93 $ret = Probe::uri($url);
95 $protocol = Contact::getProtocol($ret['url'], $ret['network']);
97 if (($protocol == Protocol::DIASPORA) && !DI::config()->get('system', 'diaspora_enabled')) {
98 notice(DI::l10n()->t("Diaspora support isn't enabled. Contact can't be added."));
100 //$a->internalRedirect($_SESSION['return_path']);
104 if (($protocol == Protocol::OSTATUS) && DI::config()->get('system', 'ostatus_disabled')) {
105 notice(DI::l10n()->t("OStatus support is disabled. Contact can't be added."));
107 //$a->internalRedirect($_SESSION['return_path']);
111 if ($protocol == Protocol::PHANTOM) {
112 notice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added."));
114 //$a->internalRedirect($_SESSION['return_path']);
118 if ($protocol == Protocol::MAIL) {
119 $ret['url'] = $ret['addr'];
122 if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
123 $request = $ret['request'];
124 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
126 $request = DI::baseUrl() . '/follow';
127 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
130 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
133 notice(DI::l10n()->t('Permission denied.'));
134 DI::baseUrl()->redirect($return_path);
138 $myaddr = $r[0]['url'];
141 // Makes the connection request for friendica contacts easier
142 $_SESSION['fastlane'] = $ret['url'];
144 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
145 Strings::normaliseLink($ret['url']));
148 $r = [['location' => '', 'about' => '', 'keywords' => '']];
150 $gcontact_id = $r[0]['id'];
153 if ($protocol === Protocol::DIASPORA) {
154 $r[0]['location'] = '';
158 $o = Renderer::replaceMacros($tpl, [
159 '$header' => DI::l10n()->t('Connect/Follow'),
161 '$pls_answer' => DI::l10n()->t('Please answer the following:'),
162 '$does_know_you' => ['knowyou', DI::l10n()->t('Does %s know you?', $ret['name']), false, '', [DI::l10n()->t('No'), DI::l10n()->t('Yes')]],
163 '$add_note' => DI::l10n()->t('Add a personal note:'),
169 '$your_address' => DI::l10n()->t('Your Identity Address:'),
170 '$invite_desc' => '',
172 '$submit' => $submit,
173 '$cancel' => DI::l10n()->t('Cancel'),
175 '$name' => $ret['name'],
176 '$url' => $ret['url'],
177 '$zrl' => Profile::zrl($ret['url']),
178 '$url_label' => DI::l10n()->t('Profile URL'),
179 '$myaddr' => $myaddr,
180 '$request' => $request,
181 '$keywords' => $r[0]['keywords'],
182 '$keywords_label'=> DI::l10n()->t('Tags:')
185 DI::page()['aside'] = '';
187 $profiledata = Contact::getDetailsByURL($ret['url']);
189 Profile::load($a, '', 0, $profiledata, false);
192 if ($gcontact_id <> 0) {
193 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
194 ['$title' => DI::l10n()->t('Status Messages and Posts')]
197 // Show last public posts
198 $o .= Contact::getPostsFromUrl($ret['url']);