]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Merge remote-tracking branch 'upstream/develop' into item-thread
[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\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;
15
16 function follow_post(App $a)
17 {
18         if (!local_user()) {
19                 System::httpExit(403, ['title' => L10n::t('Access denied.')]);
20         }
21
22         if (isset($_REQUEST['cancel'])) {
23                 goaway('contacts');
24         }
25
26         $uid = local_user();
27         $url = notags(trim($_REQUEST['url']));
28         $return_url = 'contacts';
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('contact/' . $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         $return_url = 'contacts';
54
55         if (!local_user()) {
56                 notice(L10n::t('Permission denied.'));
57                 goaway($return_url);
58                 // NOTREACHED
59         }
60
61         $uid = local_user();
62         $url = notags(trim($_REQUEST['url']));
63
64         $submit = L10n::t('Submit Request');
65
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));
72
73         if ($r) {
74                 if ($r[0]['pending']) {
75                         notice(L10n::t('You already added this contact.'));
76                         $submit = '';
77                         //goaway($_SESSION['return_url']);
78                         // NOTREACHED
79                 }
80         }
81
82         $ret = Probe::uri($url);
83
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."));
86                 $submit = '';
87                 //goaway($_SESSION['return_url']);
88                 // NOTREACHED
89         }
90
91         if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
92                 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
93                 $submit = '';
94                 //goaway($_SESSION['return_url']);
95                 // NOTREACHED
96         }
97
98         if ($ret['network'] == Protocol::PHANTOM) {
99                 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
100                 $submit = '';
101                 //goaway($_SESSION['return_url']);
102                 // NOTREACHED
103         }
104
105         if ($ret['network'] == Protocol::MAIL) {
106                 $ret['url'] = $ret['addr'];
107         }
108
109         if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
110                 $request = $ret['request'];
111                 $tpl = get_markup_template('dfrn_request.tpl');
112         } else {
113                 $request = System::baseUrl() . '/follow';
114                 $tpl = get_markup_template('auto_request.tpl');
115         }
116
117         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
118
119         if (!$r) {
120                 notice(L10n::t('Permission denied.'));
121                 goaway($return_url);
122                 // NOTREACHED
123         }
124
125         $myaddr = $r[0]['url'];
126         $gcontact_id = 0;
127
128         // Makes the connection request for friendica contacts easier
129         $_SESSION['fastlane'] = $ret['url'];
130
131         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
132                 normalise_link($ret['url']));
133
134         if (!$r) {
135                 $r = [['location' => '', 'about' => '', 'keywords' => '']];
136         } else {
137                 $gcontact_id = $r[0]['id'];
138         }
139
140         if ($ret['network'] === Protocol::DIASPORA) {
141                 $r[0]['location'] = '';
142                 $r[0]['about'] = '';
143         }
144
145         $header = L10n::t('Connect/Follow');
146
147         $o = replace_macros($tpl, [
148                 '$header'        => htmlentities($header),
149                 //'$photo'         => ProxyUtils::proxifyUrl($ret['photo'], false, ProxyUtils::SIZE_SMALL),
150                 '$desc'          => '',
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:'),
154                 '$page_desc'     => '',
155                 '$friendica'     => '',
156                 '$statusnet'     => '',
157                 '$diaspora'      => '',
158                 '$diasnote'      => '',
159                 '$your_address'  => L10n::t('Your Identity Address:'),
160                 '$invite_desc'   => '',
161                 '$emailnet'      => '',
162                 '$submit'        => $submit,
163                 '$cancel'        => L10n::t('Cancel'),
164                 '$nickname'      => '',
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,
171                 /*
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:'),
177                 */
178                 '$keywords'      => $r[0]['keywords'],
179                 '$keywords_label'=> L10n::t('Tags:')
180         ]);
181
182         $a->page['aside'] = '';
183
184         $profiledata = Contact::getDetailsByURL($ret['url']);
185         if ($profiledata) {
186                 Profile::load($a, '', 0, $profiledata, false);
187         }
188
189         if ($gcontact_id <> 0) {
190                 $o .= replace_macros(get_markup_template('section_title.tpl'),
191                         ['$title' => L10n::t('Status Messages and Posts')]
192                 );
193
194                 // Show last public posts
195                 $o .= Contact::getPostsFromUrl($ret['url']);
196         }
197
198         return $o;
199 }