6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\System;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Profile;
12 use Friendica\Network\Probe;
13 use Friendica\Database\DBA;
14 use Friendica\Util\Proxy as ProxyUtils;
16 function follow_post(App $a)
19 System::httpExit(403, ['title' => L10n::t('Access denied.')]);
22 if (isset($_REQUEST['cancel'])) {
23 goaway($_SESSION['return_url']);
27 $url = notags(trim($_REQUEST['url']));
28 $return_url = $_SESSION['return_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, Protocol::ACTIVITYPUB);
35 // $result = Contact::createFromProbe($uid, $url, true);
37 if ($result['success'] == false) {
38 if ($result['message']) {
39 notice($result['message']);
42 } elseif ($result['cid']) {
43 goaway(System::baseUrl() . '/contacts/' . $result['cid']);
46 info(L10n::t('The contact could not be added.'));
52 function follow_content(App $a)
55 notice(L10n::t('Permission denied.'));
56 goaway($_SESSION['return_url']);
61 $url = notags(trim($_REQUEST['url']));
63 $submit = L10n::t('Submit Request');
65 // Don't try to add a pending contact
66 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
67 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
68 `network` != '%s' LIMIT 1",
69 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(normalise_link($url)),
70 DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
73 if ($r[0]['pending']) {
74 notice(L10n::t('You already added this contact.'));
76 //goaway($_SESSION['return_url']);
81 $ret = Probe::uri($url);
83 if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
84 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
86 //goaway($_SESSION['return_url']);
90 if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
91 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
93 //goaway($_SESSION['return_url']);
97 if ($ret['network'] == Protocol::PHANTOM) {
98 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
100 //goaway($_SESSION['return_url']);
104 if ($ret['network'] == Protocol::MAIL) {
105 $ret['url'] = $ret['addr'];
108 if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
109 $request = $ret['request'];
110 $tpl = get_markup_template('dfrn_request.tpl');
112 $request = System::baseUrl() . '/follow';
113 $tpl = get_markup_template('auto_request.tpl');
116 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
119 notice(L10n::t('Permission denied.'));
120 goaway($_SESSION['return_url']);
124 $myaddr = $r[0]['url'];
127 // Makes the connection request for friendica contacts easier
128 $_SESSION['fastlane'] = $ret['url'];
130 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
131 normalise_link($ret['url']));
134 $r = [['location' => '', 'about' => '', 'keywords' => '']];
136 $gcontact_id = $r[0]['id'];
139 if ($ret['network'] === Protocol::DIASPORA) {
140 $r[0]['location'] = '';
144 $header = L10n::t('Connect/Follow');
146 $o = replace_macros($tpl, [
147 '$header' => htmlentities($header),
148 //'$photo' => ProxyUtils::proxifyUrl($ret['photo'], false, ProxyUtils::SIZE_SMALL),
150 '$pls_answer' => L10n::t('Please answer the following:'),
151 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
152 '$add_note' => L10n::t('Add a personal note:'),
158 '$your_address' => L10n::t('Your Identity Address:'),
159 '$invite_desc' => '',
161 '$submit' => $submit,
162 '$cancel' => L10n::t('Cancel'),
164 '$name' => $ret['name'],
165 '$url' => $ret['url'],
166 '$zrl' => Profile::zrl($ret['url']),
167 '$url_label' => L10n::t('Profile URL'),
168 '$myaddr' => $myaddr,
169 '$request' => $request,
171 * @TODO commented out?
172 '$location' => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
173 '$location_label'=> L10n::t('Location:'),
174 '$about' => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
175 '$about_label' => L10n::t('About:'),
177 '$keywords' => $r[0]['keywords'],
178 '$keywords_label'=> L10n::t('Tags:')
181 $a->page['aside'] = '';
183 $profiledata = Contact::getDetailsByURL($ret['url']);
185 Profile::load($a, '', 0, $profiledata, false);
188 if ($gcontact_id <> 0) {
189 $o .= replace_macros(get_markup_template('section_title.tpl'),
190 ['$title' => L10n::t('Status Messages and Posts')]
193 // Show last public posts
194 $o .= Contact::getPostsFromUrl($ret['url']);