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 System::httpExit(403, ['title' => 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);
63 $url = Strings::escapeTags(trim($_REQUEST['url']));
65 $submit = L10n::t('Submit Request');
67 // Don't try to add a pending contact
68 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
69 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
70 `network` != '%s' LIMIT 1",
71 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
72 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
75 if ($r[0]['pending']) {
76 notice(L10n::t('You already added this contact.'));
78 //$a->internalRedirect($_SESSION['return_path']);
83 $ret = Probe::uri($url);
85 if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
86 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
88 //$a->internalRedirect($_SESSION['return_path']);
92 if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
93 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
95 //$a->internalRedirect($_SESSION['return_path']);
99 if ($ret['network'] == Protocol::PHANTOM) {
100 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
102 //$a->internalRedirect($_SESSION['return_path']);
106 if ($ret['network'] == Protocol::MAIL) {
107 $ret['url'] = $ret['addr'];
110 if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
111 $request = $ret['request'];
112 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
114 $request = System::baseUrl() . '/follow';
115 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
118 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
121 notice(L10n::t('Permission denied.'));
122 $a->internalRedirect($return_path);
126 $myaddr = $r[0]['url'];
129 // Makes the connection request for friendica contacts easier
130 $_SESSION['fastlane'] = $ret['url'];
132 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
133 Strings::normaliseLink($ret['url']));
136 $r = [['location' => '', 'about' => '', 'keywords' => '']];
138 $gcontact_id = $r[0]['id'];
141 if ($ret['network'] === Protocol::DIASPORA) {
142 $r[0]['location'] = '';
146 $o = Renderer::replaceMacros($tpl, [
147 '$header' => L10n::t('Connect/Follow'),
149 '$pls_answer' => L10n::t('Please answer the following:'),
150 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
151 '$add_note' => L10n::t('Add a personal note:'),
157 '$your_address' => L10n::t('Your Identity Address:'),
158 '$invite_desc' => '',
160 '$submit' => $submit,
161 '$cancel' => L10n::t('Cancel'),
163 '$name' => $ret['name'],
164 '$url' => $ret['url'],
165 '$zrl' => Profile::zrl($ret['url']),
166 '$url_label' => L10n::t('Profile URL'),
167 '$myaddr' => $myaddr,
168 '$request' => $request,
169 '$keywords' => $r[0]['keywords'],
170 '$keywords_label'=> L10n::t('Tags:')
173 $a->page['aside'] = '';
175 $profiledata = Contact::getDetailsByURL($ret['url']);
177 Profile::load($a, '', 0, $profiledata, false);
180 if ($gcontact_id <> 0) {
181 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
182 ['$title' => L10n::t('Status Messages and Posts')]
185 // Show last public posts
186 $o .= Contact::getPostsFromUrl($ret['url']);