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