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