6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Model\Contact;
10 use Friendica\Model\Profile;
11 use Friendica\Network\Probe;
12 use Friendica\Database\DBM;
14 function follow_post(App $a)
17 notice(L10n::t('Permission denied.'));
18 goaway($_SESSION['return_url']);
22 if ($_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);
36 if ($result['success'] == false) {
37 if ($result['message']) {
38 notice($result['message']);
41 } elseif ($result['cid']) {
42 goaway(System::baseUrl() . '/contacts/' . $result['cid']);
45 info(L10n::t('The contact could not be added.'));
51 function follow_content(App $a)
54 notice(L10n::t('Permission denied.'));
55 goaway($_SESSION['return_url']);
60 $url = notags(trim($_REQUEST['url']));
62 $submit = L10n::t('Submit Request');
64 // Don't try to add a pending contact
65 $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
66 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
67 `network` != '%s' LIMIT 1",
68 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
69 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
72 if ($r[0]['pending']) {
73 notice(L10n::t('You already added this contact.'));
75 //goaway($_SESSION['return_url']);
80 $ret = Probe::uri($url);
82 if (($ret['network'] == NETWORK_DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
83 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
85 //goaway($_SESSION['return_url']);
89 if (($ret['network'] == NETWORK_OSTATUS) && Config::get('system', 'ostatus_disabled')) {
90 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
92 //goaway($_SESSION['return_url']);
96 if ($ret['network'] == NETWORK_PHANTOM) {
97 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
99 //goaway($_SESSION['return_url']);
103 if ($ret['network'] == NETWORK_MAIL) {
104 $ret['url'] = $ret['addr'];
107 if (($ret['network'] === NETWORK_DFRN) && !DBM::is_result($r)) {
108 $request = $ret['request'];
109 $tpl = get_markup_template('dfrn_request.tpl');
111 $request = System::baseUrl() . '/follow';
112 $tpl = get_markup_template('auto_request.tpl');
115 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
118 notice(L10n::t('Permission denied.'));
119 goaway($_SESSION['return_url']);
123 $myaddr = $r[0]['url'];
126 // Makes the connection request for friendica contacts easier
127 $_SESSION['fastlane'] = $ret['url'];
129 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
130 normalise_link($ret['url']));
133 $r = [['location' => '', 'about' => '', 'keywords' => '']];
135 $gcontact_id = $r[0]['id'];
138 if ($ret['network'] === NETWORK_DIASPORA) {
139 $r[0]['location'] = '';
143 $header = L10n::t('Connect/Follow');
145 $o = replace_macros($tpl, [
146 '$header' => htmlentities($header),
147 //'$photo' => proxy_url($ret['photo'], false, PROXY_SIZE_SMALL),
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 /*'$location' => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
170 '$location_label'=> L10n::t('Location:'),
171 '$about' => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
172 '$about_label' => L10n::t('About:'),*/
173 '$keywords' => $r[0]['keywords'],
174 '$keywords_label'=> L10n::t('Tags:')
177 $a->page['aside'] = '';
179 $profiledata = Contact::getDetailsByURL($ret['url']);
181 Profile::load($a, '', 0, $profiledata, false);
184 if ($gcontact_id <> 0) {
185 $o .= replace_macros(get_markup_template('section_title.tpl'),
186 ['$title' => L10n::t('Status Messages and Posts')]
189 // Show last public posts
190 $o .= Contact::getPostsFromUrl($ret['url']);