]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Make Two Factor Field numeric
[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\Renderer;
10 use Friendica\Core\System;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13 use Friendica\Network\Probe;
14 use Friendica\Database\DBA;
15 use Friendica\Util\Strings;
16
17 function follow_post(App $a)
18 {
19         if (!local_user()) {
20                 throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
21         }
22
23         if (isset($_REQUEST['cancel'])) {
24                 $a->internalRedirect('contact');
25         }
26
27         $uid = local_user();
28         $url = Strings::escapeTags(trim($_REQUEST['url']));
29         $return_path = 'follow?url=' . urlencode($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                 $a->internalRedirect($return_path);
42         } elseif ($result['cid']) {
43                 $a->internalRedirect('contact/' . $result['cid']);
44         }
45
46         info(L10n::t('The contact could not be added.'));
47
48         $a->internalRedirect($return_path);
49         // NOTREACHED
50 }
51
52 function follow_content(App $a)
53 {
54         $return_path = 'contact';
55
56         if (!local_user()) {
57                 notice(L10n::t('Permission denied.'));
58                 $a->internalRedirect($return_path);
59                 // NOTREACHED
60         }
61
62         $uid = local_user();
63
64         // Issue 4815: Silently removing a prefixing @
65         $url = ltrim(Strings::escapeTags(trim($_REQUEST['url'] ?? '')), '@!');
66
67         // Issue 6874: Allow remote following from Peertube
68         if (strpos($url, 'acct:') === 0) {
69                 $url = str_replace('acct:', '', $url);
70         }
71
72         if (!$url) {
73                 $a->internalRedirect($return_path);
74         }
75
76         $submit = L10n::t('Submit Request');
77
78         // Don't try to add a pending contact
79         $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
80                 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
81                 `network` != '%s' LIMIT 1",
82                 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
83                 DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
84
85         if ($r) {
86                 if ($r[0]['pending']) {
87                         notice(L10n::t('You already added this contact.'));
88                         $submit = '';
89                         //$a->internalRedirect($_SESSION['return_path']);
90                         // NOTREACHED
91                 }
92         }
93
94         $ret = Probe::uri($url);
95
96         $protocol = Contact::getProtocol($ret['url'], $ret['network']);
97
98         if (($protocol == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
99                 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
100                 $submit = '';
101                 //$a->internalRedirect($_SESSION['return_path']);
102                 // NOTREACHED
103         }
104
105         if (($protocol == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
106                 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
107                 $submit = '';
108                 //$a->internalRedirect($_SESSION['return_path']);
109                 // NOTREACHED
110         }
111
112         if ($protocol == Protocol::PHANTOM) {
113                 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
114                 $submit = '';
115                 //$a->internalRedirect($_SESSION['return_path']);
116                 // NOTREACHED
117         }
118
119         if ($protocol == Protocol::MAIL) {
120                 $ret['url'] = $ret['addr'];
121         }
122
123         if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
124                 $request = $ret['request'];
125                 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
126         } else {
127                 $request = System::baseUrl() . '/follow';
128                 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
129         }
130
131         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
132
133         if (!$r) {
134                 notice(L10n::t('Permission denied.'));
135                 $a->internalRedirect($return_path);
136                 // NOTREACHED
137         }
138
139         $myaddr = $r[0]['url'];
140         $gcontact_id = 0;
141
142         // Makes the connection request for friendica contacts easier
143         $_SESSION['fastlane'] = $ret['url'];
144
145         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
146                 Strings::normaliseLink($ret['url']));
147
148         if (!$r) {
149                 $r = [['location' => '', 'about' => '', 'keywords' => '']];
150         } else {
151                 $gcontact_id = $r[0]['id'];
152         }
153
154         if ($protocol === Protocol::DIASPORA) {
155                 $r[0]['location'] = '';
156                 $r[0]['about'] = '';
157         }
158
159         $o = Renderer::replaceMacros($tpl, [
160                 '$header'        => L10n::t('Connect/Follow'),
161                 '$desc'          => '',
162                 '$pls_answer'    => L10n::t('Please answer the following:'),
163                 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
164                 '$add_note'      => L10n::t('Add a personal note:'),
165                 '$page_desc'     => '',
166                 '$friendica'     => '',
167                 '$statusnet'     => '',
168                 '$diaspora'      => '',
169                 '$diasnote'      => '',
170                 '$your_address'  => L10n::t('Your Identity Address:'),
171                 '$invite_desc'   => '',
172                 '$emailnet'      => '',
173                 '$submit'        => $submit,
174                 '$cancel'        => L10n::t('Cancel'),
175                 '$nickname'      => '',
176                 '$name'          => $ret['name'],
177                 '$url'           => $ret['url'],
178                 '$zrl'           => Profile::zrl($ret['url']),
179                 '$url_label'     => L10n::t('Profile URL'),
180                 '$myaddr'        => $myaddr,
181                 '$request'       => $request,
182                 '$keywords'      => $r[0]['keywords'],
183                 '$keywords_label'=> L10n::t('Tags:')
184         ]);
185
186         $a->page['aside'] = '';
187
188         $profiledata = Contact::getDetailsByURL($ret['url']);
189         if ($profiledata) {
190                 Profile::load($a, '', 0, $profiledata, false);
191         }
192
193         if ($gcontact_id <> 0) {
194                 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
195                         ['$title' => L10n::t('Status Messages and Posts')]
196                 );
197
198                 // Show last public posts
199                 $o .= Contact::getPostsFromUrl($ret['url']);
200         }
201
202         return $o;
203 }