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;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13 use Friendica\Network\Probe;
14 use Friendica\Database\DBA;
15 use Friendica\Util\Strings;
17 function follow_post(App $a)
20 throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
23 if (isset($_REQUEST['cancel'])) {
24 $a->internalRedirect('contact');
28 $url = Strings::escapeTags(trim($_REQUEST['url']));
29 $return_path = 'follow?url=' . urlencode($url);
31 // Makes the connection request for friendica contacts easier
32 // This is just a precaution if maybe this page is called somewhere directly via POST
33 $_SESSION['fastlane'] = $url;
35 $result = Contact::createFromProbe($uid, $url, true);
37 if ($result['success'] == false) {
38 if ($result['message']) {
39 notice($result['message']);
41 $a->internalRedirect($return_path);
42 } elseif ($result['cid']) {
43 $a->internalRedirect('contact/' . $result['cid']);
46 info(L10n::t('The contact could not be added.'));
48 $a->internalRedirect($return_path);
52 function follow_content(App $a)
54 $return_path = 'contact';
57 notice(L10n::t('Permission denied.'));
58 $a->internalRedirect($return_path);
64 // Issue 4815: Silently removing a prefixing @
65 $url = ltrim(Strings::escapeTags(trim(defaults($_REQUEST, 'url', ''))), '@!');
67 // Issue 6874: Allow remote following from Peertube
68 if (strpos($url, 'acct:') === 0) {
69 $url = str_replace('acct:', '', $url);
73 $a->internalRedirect($return_path);
76 $submit = L10n::t('Submit Request');
78 // Don't try to add a pending contact
79 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
80 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
81 `network` != '%s' LIMIT 1",
82 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
83 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
86 if ($r[0]['pending']) {
87 notice(L10n::t('You already added this contact.'));
89 //$a->internalRedirect($_SESSION['return_path']);
94 $ret = Probe::uri($url);
96 $protocol = Contact::getProtocol($ret['url'], $ret['network']);
98 if (($protocol == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
99 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
101 //$a->internalRedirect($_SESSION['return_path']);
105 if (($protocol == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
106 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
108 //$a->internalRedirect($_SESSION['return_path']);
112 if ($protocol == Protocol::PHANTOM) {
113 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
115 //$a->internalRedirect($_SESSION['return_path']);
119 if ($protocol == Protocol::MAIL) {
120 $ret['url'] = $ret['addr'];
123 if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
124 $request = $ret['request'];
125 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
127 $request = System::baseUrl() . '/follow';
128 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
131 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
134 notice(L10n::t('Permission denied.'));
135 $a->internalRedirect($return_path);
139 $myaddr = $r[0]['url'];
142 // Makes the connection request for friendica contacts easier
143 $_SESSION['fastlane'] = $ret['url'];
145 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
146 Strings::normaliseLink($ret['url']));
149 $r = [['location' => '', 'about' => '', 'keywords' => '']];
151 $gcontact_id = $r[0]['id'];
154 if ($protocol === Protocol::DIASPORA) {
155 $r[0]['location'] = '';
159 $o = Renderer::replaceMacros($tpl, [
160 '$header' => L10n::t('Connect/Follow'),
162 '$pls_answer' => L10n::t('Please answer the following:'),
163 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
164 '$add_note' => L10n::t('Add a personal note:'),
170 '$your_address' => L10n::t('Your Identity Address:'),
171 '$invite_desc' => '',
173 '$submit' => $submit,
174 '$cancel' => L10n::t('Cancel'),
176 '$name' => $ret['name'],
177 '$url' => $ret['url'],
178 '$zrl' => Profile::zrl($ret['url']),
179 '$url_label' => L10n::t('Profile URL'),
180 '$myaddr' => $myaddr,
181 '$request' => $request,
182 '$keywords' => $r[0]['keywords'],
183 '$keywords_label'=> L10n::t('Tags:')
186 $a->page['aside'] = '';
188 $profiledata = Contact::getDetailsByURL($ret['url']);
190 Profile::load($a, '', 0, $profiledata, false);
193 if ($gcontact_id <> 0) {
194 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
195 ['$title' => L10n::t('Status Messages and Posts')]
198 // Show last public posts
199 $o .= Contact::getPostsFromUrl($ret['url']);