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