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\Proxy as ProxyUtils;
16 use Friendica\Util\Strings;
18 function follow_post(App $a)
21 System::httpExit(403, ['title' => L10n::t('Access denied.')]);
24 if (isset($_REQUEST['cancel'])) {
25 $a->internalRedirect('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 $a->internalRedirect($return_path);
43 } elseif ($result['cid']) {
44 $a->internalRedirect('contact/' . $result['cid']);
47 info(L10n::t('The contact could not be added.'));
49 $a->internalRedirect($return_path);
53 function follow_content(App $a)
55 $return_path = 'contact';
58 notice(L10n::t('Permission denied.'));
59 $a->internalRedirect($return_path);
64 $url = Strings::escapeTags(trim($_REQUEST['url']));
66 $submit = L10n::t('Submit Request');
68 // Don't try to add a pending contact
69 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
70 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
71 `network` != '%s' LIMIT 1",
72 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
73 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
76 if ($r[0]['pending']) {
77 notice(L10n::t('You already added this contact.'));
79 //$a->internalRedirect($_SESSION['return_path']);
84 $ret = Probe::uri($url);
86 if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
87 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
89 //$a->internalRedirect($_SESSION['return_path']);
93 if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
94 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
96 //$a->internalRedirect($_SESSION['return_path']);
100 if ($ret['network'] == Protocol::PHANTOM) {
101 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
103 //$a->internalRedirect($_SESSION['return_path']);
107 if ($ret['network'] == Protocol::MAIL) {
108 $ret['url'] = $ret['addr'];
111 if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
112 $request = $ret['request'];
113 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
115 $request = System::baseUrl() . '/follow';
116 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
119 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
122 notice(L10n::t('Permission denied.'));
123 $a->internalRedirect($return_path);
127 $myaddr = $r[0]['url'];
130 // Makes the connection request for friendica contacts easier
131 $_SESSION['fastlane'] = $ret['url'];
133 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
134 Strings::normaliseLink($ret['url']));
137 $r = [['location' => '', 'about' => '', 'keywords' => '']];
139 $gcontact_id = $r[0]['id'];
142 if ($ret['network'] === Protocol::DIASPORA) {
143 $r[0]['location'] = '';
147 $header = L10n::t('Connect/Follow');
149 $o = Renderer::replaceMacros($tpl, [
150 '$header' => htmlentities($header),
151 //'$photo' => ProxyUtils::proxifyUrl($ret['photo'], false, ProxyUtils::SIZE_SMALL),
153 '$pls_answer' => L10n::t('Please answer the following:'),
154 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
155 '$add_note' => L10n::t('Add a personal note:'),
161 '$your_address' => L10n::t('Your Identity Address:'),
162 '$invite_desc' => '',
164 '$submit' => $submit,
165 '$cancel' => L10n::t('Cancel'),
167 '$name' => $ret['name'],
168 '$url' => $ret['url'],
169 '$zrl' => Profile::zrl($ret['url']),
170 '$url_label' => L10n::t('Profile URL'),
171 '$myaddr' => $myaddr,
172 '$request' => $request,
174 * @TODO commented out?
175 '$location' => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
176 '$location_label'=> L10n::t('Location:'),
177 '$about' => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
178 '$about_label' => L10n::t('About:'),
180 '$keywords' => $r[0]['keywords'],
181 '$keywords_label'=> L10n::t('Tags:')
184 $a->page['aside'] = '';
186 $profiledata = Contact::getDetailsByURL($ret['url']);
188 Profile::load($a, '', 0, $profiledata, false);
191 if ($gcontact_id <> 0) {
192 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
193 ['$title' => L10n::t('Status Messages and Posts')]
196 // Show last public posts
197 $o .= Contact::getPostsFromUrl($ret['url']);