6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\System;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
14 use Friendica\Network\Probe;
15 use Friendica\Database\DBA;
16 use Friendica\Util\Strings;
18 function follow_post(App $a)
21 throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
24 if (isset($_REQUEST['cancel'])) {
25 DI::baseUrl()->redirect('contact');
29 $url = Strings::escapeTags(trim($_REQUEST['url']));
30 $return_path = 'follow?url=' . urlencode($url);
32 // Makes the connection request for friendica contacts easier
33 // This is just a precaution if maybe this page is called somewhere directly via POST
34 $_SESSION['fastlane'] = $url;
36 $result = Contact::createFromProbe($uid, $url, true);
38 if ($result['success'] == false) {
39 if ($result['message']) {
40 notice($result['message']);
42 DI::baseUrl()->redirect($return_path);
43 } elseif ($result['cid']) {
44 DI::baseUrl()->redirect('contact/' . $result['cid']);
47 info(L10n::t('The contact could not be added.'));
49 DI::baseUrl()->redirect($return_path);
53 function follow_content(App $a)
55 $return_path = 'contact';
58 notice(L10n::t('Permission denied.'));
59 DI::baseUrl()->redirect($return_path);
65 // Issue 4815: Silently removing a prefixing @
66 $url = ltrim(Strings::escapeTags(trim($_REQUEST['url'] ?? '')), '@!');
68 // Issue 6874: Allow remote following from Peertube
69 if (strpos($url, 'acct:') === 0) {
70 $url = str_replace('acct:', '', $url);
74 DI::baseUrl()->redirect($return_path);
77 $submit = L10n::t('Submit Request');
79 // Don't try to add a pending contact
80 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
81 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
82 `network` != '%s' LIMIT 1",
83 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
84 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
87 if ($r[0]['pending']) {
88 notice(L10n::t('You already added this contact.'));
90 //$a->internalRedirect($_SESSION['return_path']);
95 $ret = Probe::uri($url);
97 $protocol = Contact::getProtocol($ret['url'], $ret['network']);
99 if (($protocol == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
100 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
102 //$a->internalRedirect($_SESSION['return_path']);
106 if (($protocol == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
107 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
109 //$a->internalRedirect($_SESSION['return_path']);
113 if ($protocol == Protocol::PHANTOM) {
114 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
116 //$a->internalRedirect($_SESSION['return_path']);
120 if ($protocol == Protocol::MAIL) {
121 $ret['url'] = $ret['addr'];
124 if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
125 $request = $ret['request'];
126 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
128 $request = DI::baseUrl() . '/follow';
129 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
132 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
135 notice(L10n::t('Permission denied.'));
136 DI::baseUrl()->redirect($return_path);
140 $myaddr = $r[0]['url'];
143 // Makes the connection request for friendica contacts easier
144 $_SESSION['fastlane'] = $ret['url'];
146 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
147 Strings::normaliseLink($ret['url']));
150 $r = [['location' => '', 'about' => '', 'keywords' => '']];
152 $gcontact_id = $r[0]['id'];
155 if ($protocol === Protocol::DIASPORA) {
156 $r[0]['location'] = '';
160 $o = Renderer::replaceMacros($tpl, [
161 '$header' => L10n::t('Connect/Follow'),
163 '$pls_answer' => L10n::t('Please answer the following:'),
164 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
165 '$add_note' => L10n::t('Add a personal note:'),
171 '$your_address' => L10n::t('Your Identity Address:'),
172 '$invite_desc' => '',
174 '$submit' => $submit,
175 '$cancel' => L10n::t('Cancel'),
177 '$name' => $ret['name'],
178 '$url' => $ret['url'],
179 '$zrl' => Profile::zrl($ret['url']),
180 '$url_label' => L10n::t('Profile URL'),
181 '$myaddr' => $myaddr,
182 '$request' => $request,
183 '$keywords' => $r[0]['keywords'],
184 '$keywords_label'=> L10n::t('Tags:')
187 DI::page()['aside'] = '';
189 $profiledata = Contact::getDetailsByURL($ret['url']);
191 Profile::load($a, '', 0, $profiledata, false);
194 if ($gcontact_id <> 0) {
195 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
196 ['$title' => L10n::t('Status Messages and Posts')]
199 // Show last public posts
200 $o .= Contact::getPostsFromUrl($ret['url']);