]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Remove unreliable ANY_VALUE from message list query
[friendica.git] / mod / unfollow.php
1 <?php
2 /**
3  * @file mod/unfollow.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
14 use Friendica\Model\User;
15 use Friendica\Util\Strings;
16
17 function unfollow_post(App $a)
18 {
19         $base_return_path = 'contact';
20
21         if (!local_user()) {
22                 notice(L10n::t('Permission denied.'));
23                 $a->internalRedirect('login');
24                 // NOTREACHED
25         }
26
27         $uid = local_user();
28         $url = Strings::escapeTags(trim(defaults($_REQUEST, 'url', '')));
29
30         $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
31                 $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
32                 Strings::normaliseLink($url), $url];
33         $contact = DBA::selectFirst('contact', [], $condition);
34
35         if (!DBA::isResult($contact)) {
36                 notice(L10n::t("You aren't following this contact."));
37                 $a->internalRedirect($base_return_path);
38                 // NOTREACHED
39         }
40
41         if (!empty($_REQUEST['cancel'])) {
42                 $a->internalRedirect($base_return_path . '/' . $contact['id']);
43         }
44
45         if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
46                 notice(L10n::t('Unfollowing is currently not supported by your network.'));
47                 $a->internalRedirect($base_return_path . '/' . $contact['id']);
48                 // NOTREACHED
49         }
50
51         $dissolve = ($contact['rel'] == Contact::SHARING);
52
53         $owner = User::getOwnerDataById($uid);
54         if ($owner) {
55                 Contact::terminateFriendship($owner, $contact, $dissolve);
56         }
57
58         // Sharing-only contacts get deleted as there no relationship any more
59         if ($dissolve) {
60                 Contact::remove($contact['id']);
61                 $return_path = $base_return_path;
62         } else {
63                 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
64                 $return_path = $base_return_path . '/' . $contact['id'];
65         }
66
67         info(L10n::t('Contact unfollowed'));
68         $a->internalRedirect($return_path);
69         // NOTREACHED
70 }
71
72 function unfollow_content(App $a)
73 {
74         $base_return_path = 'contact';
75
76         if (!local_user()) {
77                 notice(L10n::t('Permission denied.'));
78                 $a->internalRedirect('login');
79                 // NOTREACHED
80         }
81
82         $uid = local_user();
83         $url = Strings::escapeTags(trim($_REQUEST['url']));
84
85         $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
86                 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
87                 Strings::normaliseLink($url), $url];
88
89         $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
90
91         if (!DBA::isResult($contact)) {
92                 notice(L10n::t("You aren't following this contact."));
93                 $a->internalRedirect($base_return_path);
94                 // NOTREACHED
95         }
96
97         if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
98                 notice(L10n::t('Unfollowing is currently not supported by your network.'));
99                 $a->internalRedirect($base_return_path . '/' . $contact['id']);
100                 // NOTREACHED
101         }
102
103         $request = System::baseUrl() . '/unfollow';
104         $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
105
106         $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
107
108         if (!DBA::isResult($self)) {
109                 notice(L10n::t('Permission denied.'));
110                 $a->internalRedirect($base_return_path);
111                 // NOTREACHED
112         }
113
114         // Makes the connection request for friendica contacts easier
115         $_SESSION['fastlane'] = $contact['url'];
116
117         $header = L10n::t('Disconnect/Unfollow');
118
119         $o = Renderer::replaceMacros($tpl, [
120                 '$header'        => htmlentities($header),
121                 '$desc'          => '',
122                 '$pls_answer'    => '',
123                 '$does_know_you' => '',
124                 '$add_note'      => '',
125                 '$page_desc'     => '',
126                 '$friendica'     => '',
127                 '$statusnet'     => '',
128                 '$diaspora'      => '',
129                 '$diasnote'      => '',
130                 '$your_address'  => L10n::t('Your Identity Address:'),
131                 '$invite_desc'   => '',
132                 '$emailnet'      => '',
133                 '$submit'        => L10n::t('Submit Request'),
134                 '$cancel'        => L10n::t('Cancel'),
135                 '$nickname'      => '',
136                 '$name'          => $contact['name'],
137                 '$url'           => $contact['url'],
138                 '$zrl'           => Contact::magicLink($contact['url']),
139                 '$url_label'     => L10n::t('Profile URL'),
140                 '$myaddr'        => $self['url'],
141                 '$request'       => $request,
142                 '$keywords'      => '',
143                 '$keywords_label'=> ''
144         ]);
145
146         $a->page['aside'] = '';
147         Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
148
149         $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
150
151         // Show last public posts
152         $o .= Contact::getPostsFromUrl($contact['url']);
153
154         return $o;
155 }