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