]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Merge pull request #5419 from annando/fixes
[friendica.git] / mod / follow.php
1 <?php
2 /**
3  * @file mod/follow.php
4  */
5 use Friendica\App;
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;
13
14 function follow_post(App $a)
15 {
16         if (!local_user()) {
17                 notice(L10n::t('Permission denied.'));
18                 goaway($_SESSION['return_url']);
19                 // NOTREACHED
20         }
21
22         if (isset($_REQUEST['cancel'])) {
23                 goaway($_SESSION['return_url']);
24         }
25
26         $uid = local_user();
27         $url = notags(trim($_REQUEST['url']));
28         $return_url = $_SESSION['return_url'];
29
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;
33
34         $result = Contact::createFromProbe($uid, $url, true);
35
36         if ($result['success'] == false) {
37                 if ($result['message']) {
38                         notice($result['message']);
39                 }
40                 goaway($return_url);
41         } elseif ($result['cid']) {
42                 goaway(System::baseUrl() . '/contacts/' . $result['cid']);
43         }
44
45         info(L10n::t('The contact could not be added.'));
46
47         goaway($return_url);
48         // NOTREACHED
49 }
50
51 function follow_content(App $a)
52 {
53         if (!local_user()) {
54                 notice(L10n::t('Permission denied.'));
55                 goaway($_SESSION['return_url']);
56                 // NOTREACHED
57         }
58
59         $uid = local_user();
60         $url = notags(trim($_REQUEST['url']));
61
62         $submit = L10n::t('Submit Request');
63
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));
70
71         if ($r) {
72                 if ($r[0]['pending']) {
73                         notice(L10n::t('You already added this contact.'));
74                         $submit = '';
75                         //goaway($_SESSION['return_url']);
76                         // NOTREACHED
77                 }
78         }
79
80         $ret = Probe::uri($url);
81
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."));
84                 $submit = '';
85                 //goaway($_SESSION['return_url']);
86                 // NOTREACHED
87         }
88
89         if (($ret['network'] == NETWORK_OSTATUS) && Config::get('system', 'ostatus_disabled')) {
90                 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
91                 $submit = '';
92                 //goaway($_SESSION['return_url']);
93                 // NOTREACHED
94         }
95
96         if ($ret['network'] == NETWORK_PHANTOM) {
97                 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
98                 $submit = '';
99                 //goaway($_SESSION['return_url']);
100                 // NOTREACHED
101         }
102
103         if ($ret['network'] == NETWORK_MAIL) {
104                 $ret['url'] = $ret['addr'];
105         }
106
107         if (($ret['network'] === NETWORK_DFRN) && !DBM::is_result($r)) {
108                 $request = $ret['request'];
109                 $tpl = get_markup_template('dfrn_request.tpl');
110         } else {
111                 $request = System::baseUrl() . '/follow';
112                 $tpl = get_markup_template('auto_request.tpl');
113         }
114
115         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
116
117         if (!$r) {
118                 notice(L10n::t('Permission denied.'));
119                 goaway($_SESSION['return_url']);
120                 // NOTREACHED
121         }
122
123         $myaddr = $r[0]['url'];
124         $gcontact_id = 0;
125
126         // Makes the connection request for friendica contacts easier
127         $_SESSION['fastlane'] = $ret['url'];
128
129         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
130                 normalise_link($ret['url']));
131
132         if (!$r) {
133                 $r = [['location' => '', 'about' => '', 'keywords' => '']];
134         } else {
135                 $gcontact_id = $r[0]['id'];
136         }
137
138         if ($ret['network'] === NETWORK_DIASPORA) {
139                 $r[0]['location'] = '';
140                 $r[0]['about'] = '';
141         }
142
143         $header = L10n::t('Connect/Follow');
144
145         $o = replace_macros($tpl, [
146                 '$header'        => htmlentities($header),
147                 //'$photo' => proxy_url($ret['photo'], false, PROXY_SIZE_SMALL),
148                 '$desc'          => '',
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:'),
152                 '$page_desc'     => '',
153                 '$friendica'     => '',
154                 '$statusnet'     => '',
155                 '$diaspora'      => '',
156                 '$diasnote'      => '',
157                 '$your_address'  => L10n::t('Your Identity Address:'),
158                 '$invite_desc'   => '',
159                 '$emailnet'      => '',
160                 '$submit'        => $submit,
161                 '$cancel'        => L10n::t('Cancel'),
162                 '$nickname'      => '',
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                 /*
170                  * @TODO commented out?
171                 '$location'      => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
172                 '$location_label'=> L10n::t('Location:'),
173                 '$about'         => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
174                 '$about_label'   => L10n::t('About:'),
175                 */
176                 '$keywords'      => $r[0]['keywords'],
177                 '$keywords_label'=> L10n::t('Tags:')
178         ]);
179
180         $a->page['aside'] = '';
181
182         $profiledata = Contact::getDetailsByURL($ret['url']);
183         if ($profiledata) {
184                 Profile::load($a, '', 0, $profiledata, false);
185         }
186
187         if ($gcontact_id <> 0) {
188                 $o .= replace_macros(get_markup_template('section_title.tpl'),
189                         ['$title' => L10n::t('Status Messages and Posts')]
190                 );
191
192                 // Show last public posts
193                 $o .= Contact::getPostsFromUrl($ret['url']);
194         }
195
196         return $o;
197 }