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'])) {
27 $url = notags(trim($_REQUEST['url']));
28 $return_url = 'contacts';
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);
36 if ($result['success'] == false) {
37 if ($result['message']) {
38 notice($result['message']);
41 } elseif ($result['cid']) {
42 goaway('contact/' . $result['cid']);
45 info(L10n::t('The contact could not be added.'));
51 function follow_content(App $a)
53 $return_url = 'contacts';
56 notice(L10n::t('Permission denied.'));
62 $url = notags(trim($_REQUEST['url']));
64 $submit = L10n::t('Submit Request');
66 // Don't try to add a pending contact
67 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
68 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
69 `network` != '%s' LIMIT 1",
70 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(normalise_link($url)),
71 DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
74 if ($r[0]['pending']) {
75 notice(L10n::t('You already added this contact.'));
77 //goaway($_SESSION['return_url']);
82 $ret = Probe::uri($url);
84 if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
85 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
87 //goaway($_SESSION['return_url']);
91 if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
92 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
94 //goaway($_SESSION['return_url']);
98 if ($ret['network'] == Protocol::PHANTOM) {
99 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
101 //goaway($_SESSION['return_url']);
105 if ($ret['network'] == Protocol::MAIL) {
106 $ret['url'] = $ret['addr'];
109 if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
110 $request = $ret['request'];
111 $tpl = get_markup_template('dfrn_request.tpl');
113 $request = System::baseUrl() . '/follow';
114 $tpl = get_markup_template('auto_request.tpl');
117 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
120 notice(L10n::t('Permission denied.'));
125 $myaddr = $r[0]['url'];
128 // Makes the connection request for friendica contacts easier
129 $_SESSION['fastlane'] = $ret['url'];
131 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
132 normalise_link($ret['url']));
135 $r = [['location' => '', 'about' => '', 'keywords' => '']];
137 $gcontact_id = $r[0]['id'];
140 if ($ret['network'] === Protocol::DIASPORA) {
141 $r[0]['location'] = '';
145 $header = L10n::t('Connect/Follow');
147 $o = replace_macros($tpl, [
148 '$header' => htmlentities($header),
149 //'$photo' => ProxyUtils::proxifyUrl($ret['photo'], false, ProxyUtils::SIZE_SMALL),
151 '$pls_answer' => L10n::t('Please answer the following:'),
152 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
153 '$add_note' => L10n::t('Add a personal note:'),
159 '$your_address' => L10n::t('Your Identity Address:'),
160 '$invite_desc' => '',
162 '$submit' => $submit,
163 '$cancel' => L10n::t('Cancel'),
165 '$name' => $ret['name'],
166 '$url' => $ret['url'],
167 '$zrl' => Profile::zrl($ret['url']),
168 '$url_label' => L10n::t('Profile URL'),
169 '$myaddr' => $myaddr,
170 '$request' => $request,
172 * @TODO commented out?
173 '$location' => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
174 '$location_label'=> L10n::t('Location:'),
175 '$about' => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
176 '$about_label' => L10n::t('About:'),
178 '$keywords' => $r[0]['keywords'],
179 '$keywords_label'=> L10n::t('Tags:')
182 $a->page['aside'] = '';
184 $profiledata = Contact::getDetailsByURL($ret['url']);
186 Profile::load($a, '', 0, $profiledata, false);
189 if ($gcontact_id <> 0) {
190 $o .= replace_macros(get_markup_template('section_title.tpl'),
191 ['$title' => L10n::t('Status Messages and Posts')]
194 // Show last public posts
195 $o .= Contact::getPostsFromUrl($ret['url']);