6 use Friendica\Core\Protocol;
7 use Friendica\Core\Renderer;
9 use Friendica\Model\Contact;
10 use Friendica\Model\Profile;
11 use Friendica\Model\Item;
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 // Possibly it is a remote item and not an account
38 follow_remote_item($url);
40 if ($result['message']) {
41 notice($result['message']);
43 DI::baseUrl()->redirect($return_path);
44 } elseif ($result['cid']) {
45 DI::baseUrl()->redirect('contact/' . $result['cid']);
48 info(DI::l10n()->t('The contact could not be added.'));
50 DI::baseUrl()->redirect($return_path);
54 function follow_content(App $a)
56 $return_path = 'contact';
59 notice(DI::l10n()->t('Permission denied.'));
60 DI::baseUrl()->redirect($return_path);
66 // Issue 4815: Silently removing a prefixing @
67 $url = ltrim(Strings::escapeTags(trim($_REQUEST['url'] ?? '')), '@!');
69 // Issue 6874: Allow remote following from Peertube
70 if (strpos($url, 'acct:') === 0) {
71 $url = str_replace('acct:', '', $url);
75 DI::baseUrl()->redirect($return_path);
78 $submit = DI::l10n()->t('Submit Request');
80 // Don't try to add a pending contact
81 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
82 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
83 `network` != '%s' LIMIT 1",
84 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
85 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
88 if ($r[0]['pending']) {
89 notice(DI::l10n()->t('You already added this contact.'));
91 //$a->internalRedirect($_SESSION['return_path']);
96 $ret = Probe::uri($url);
98 $protocol = Contact::getProtocol($ret['url'], $ret['network']);
100 if (($protocol == Protocol::DIASPORA) && !DI::config()->get('system', 'diaspora_enabled')) {
101 notice(DI::l10n()->t("Diaspora support isn't enabled. Contact can't be added."));
103 //$a->internalRedirect($_SESSION['return_path']);
107 if (($protocol == Protocol::OSTATUS) && DI::config()->get('system', 'ostatus_disabled')) {
108 notice(DI::l10n()->t("OStatus support is disabled. Contact can't be added."));
110 //$a->internalRedirect($_SESSION['return_path']);
114 if ($protocol == Protocol::PHANTOM) {
115 // Possibly it is a remote item and not an account
116 follow_remote_item($url);
118 notice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added."));
120 //$a->internalRedirect($_SESSION['return_path']);
124 if ($protocol == Protocol::MAIL) {
125 $ret['url'] = $ret['addr'];
128 if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
129 $request = $ret['request'];
130 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
132 $request = DI::baseUrl() . '/follow';
133 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
136 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
139 notice(DI::l10n()->t('Permission denied.'));
140 DI::baseUrl()->redirect($return_path);
144 $myaddr = $r[0]['url'];
147 // Makes the connection request for friendica contacts easier
148 $_SESSION['fastlane'] = $ret['url'];
150 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
151 Strings::normaliseLink($ret['url']));
154 $r = [['location' => '', 'about' => '', 'keywords' => '']];
156 $gcontact_id = $r[0]['id'];
159 if ($protocol === Protocol::DIASPORA) {
160 $r[0]['location'] = '';
164 $o = Renderer::replaceMacros($tpl, [
165 '$header' => DI::l10n()->t('Connect/Follow'),
167 '$pls_answer' => DI::l10n()->t('Please answer the following:'),
168 '$does_know_you' => ['knowyou', DI::l10n()->t('Does %s know you?', $ret['name']), false, '', [DI::l10n()->t('No'), DI::l10n()->t('Yes')]],
169 '$add_note' => DI::l10n()->t('Add a personal note:'),
175 '$your_address' => DI::l10n()->t('Your Identity Address:'),
176 '$invite_desc' => '',
178 '$submit' => $submit,
179 '$cancel' => DI::l10n()->t('Cancel'),
181 '$name' => $ret['name'],
182 '$url' => $ret['url'],
183 '$zrl' => Profile::zrl($ret['url']),
184 '$url_label' => DI::l10n()->t('Profile URL'),
185 '$myaddr' => $myaddr,
186 '$request' => $request,
187 '$keywords' => $r[0]['keywords'],
188 '$keywords_label'=> DI::l10n()->t('Tags:')
191 DI::page()['aside'] = '';
193 $profiledata = Contact::getDetailsByURL($ret['url']);
195 Profile::load($a, '', 0, $profiledata, false);
198 if ($gcontact_id <> 0) {
199 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
200 ['$title' => DI::l10n()->t('Status Messages and Posts')]
203 // Show last public posts
204 $o .= Contact::getPostsFromUrl($ret['url']);
210 function follow_remote_item($url)
212 $item_id = Item::fetchByLink($url, local_user());
214 // If the user-specific search failed, we search and probe a public post
215 $item_id = Item::fetchByLink($url);
218 if (!empty($item_id)) {
219 $item = Item::selectFirst(['guid'], ['id' => $item_id]);
220 if (DBA::isResult($item)) {
221 DI::baseUrl()->redirect('display/' . $item['guid']);