]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Merge pull request #6053 from zeroadam/CoreRenderer
[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\Proxy as ProxyUtils;
16
17 function follow_post(App $a)
18 {
19         if (!local_user()) {
20                 System::httpExit(403, ['title' => L10n::t('Access denied.')]);
21         }
22
23         if (isset($_REQUEST['cancel'])) {
24                 $a->internalRedirect('contacts');
25         }
26
27         $uid = local_user();
28         $url = notags(trim($_REQUEST['url']));
29         $return_path = 'contacts';
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 = 'contacts';
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         $url = notags(trim($_REQUEST['url']));
64
65         $submit = L10n::t('Submit Request');
66
67         // Don't try to add a pending contact
68         $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
69                 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
70                 `network` != '%s' LIMIT 1",
71                 intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(normalise_link($url)),
72                 DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
73
74         if ($r) {
75                 if ($r[0]['pending']) {
76                         notice(L10n::t('You already added this contact.'));
77                         $submit = '';
78                         //$a->internalRedirect($_SESSION['return_path']);
79                         // NOTREACHED
80                 }
81         }
82
83         $ret = Probe::uri($url);
84
85         if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
86                 notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
87                 $submit = '';
88                 //$a->internalRedirect($_SESSION['return_path']);
89                 // NOTREACHED
90         }
91
92         if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
93                 notice(L10n::t("OStatus support is disabled. Contact can't be added."));
94                 $submit = '';
95                 //$a->internalRedirect($_SESSION['return_path']);
96                 // NOTREACHED
97         }
98
99         if ($ret['network'] == Protocol::PHANTOM) {
100                 notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
101                 $submit = '';
102                 //$a->internalRedirect($_SESSION['return_path']);
103                 // NOTREACHED
104         }
105
106         if ($ret['network'] == Protocol::MAIL) {
107                 $ret['url'] = $ret['addr'];
108         }
109
110         if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
111                 $request = $ret['request'];
112                 $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
113         } else {
114                 $request = System::baseUrl() . '/follow';
115                 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
116         }
117
118         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
119
120         if (!$r) {
121                 notice(L10n::t('Permission denied.'));
122                 $a->internalRedirect($return_path);
123                 // NOTREACHED
124         }
125
126         $myaddr = $r[0]['url'];
127         $gcontact_id = 0;
128
129         // Makes the connection request for friendica contacts easier
130         $_SESSION['fastlane'] = $ret['url'];
131
132         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
133                 normalise_link($ret['url']));
134
135         if (!$r) {
136                 $r = [['location' => '', 'about' => '', 'keywords' => '']];
137         } else {
138                 $gcontact_id = $r[0]['id'];
139         }
140
141         if ($ret['network'] === Protocol::DIASPORA) {
142                 $r[0]['location'] = '';
143                 $r[0]['about'] = '';
144         }
145
146         $header = L10n::t('Connect/Follow');
147
148         $o = Renderer::replaceMacros($tpl, [
149                 '$header'        => htmlentities($header),
150                 //'$photo'         => ProxyUtils::proxifyUrl($ret['photo'], false, ProxyUtils::SIZE_SMALL),
151                 '$desc'          => '',
152                 '$pls_answer'    => L10n::t('Please answer the following:'),
153                 '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
154                 '$add_note'      => L10n::t('Add a personal note:'),
155                 '$page_desc'     => '',
156                 '$friendica'     => '',
157                 '$statusnet'     => '',
158                 '$diaspora'      => '',
159                 '$diasnote'      => '',
160                 '$your_address'  => L10n::t('Your Identity Address:'),
161                 '$invite_desc'   => '',
162                 '$emailnet'      => '',
163                 '$submit'        => $submit,
164                 '$cancel'        => L10n::t('Cancel'),
165                 '$nickname'      => '',
166                 '$name'          => $ret['name'],
167                 '$url'           => $ret['url'],
168                 '$zrl'           => Profile::zrl($ret['url']),
169                 '$url_label'     => L10n::t('Profile URL'),
170                 '$myaddr'        => $myaddr,
171                 '$request'       => $request,
172                 /*
173                  * @TODO commented out?
174                 '$location'      => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
175                 '$location_label'=> L10n::t('Location:'),
176                 '$about'         => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
177                 '$about_label'   => L10n::t('About:'),
178                 */
179                 '$keywords'      => $r[0]['keywords'],
180                 '$keywords_label'=> L10n::t('Tags:')
181         ]);
182
183         $a->page['aside'] = '';
184
185         $profiledata = Contact::getDetailsByURL($ret['url']);
186         if ($profiledata) {
187                 Profile::load($a, '', 0, $profiledata, false);
188         }
189
190         if ($gcontact_id <> 0) {
191                 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
192                         ['$title' => L10n::t('Status Messages and Posts')]
193                 );
194
195                 // Show last public posts
196                 $o .= Contact::getPostsFromUrl($ret['url']);
197         }
198
199         return $o;
200 }