3 * @file mod/unfollow.php
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;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Profile;
15 use Friendica\Model\User;
16 use Friendica\Util\Strings;
18 function unfollow_post(App $a)
20 $base_return_path = 'contact';
23 notice(L10n::t('Permission denied.'));
24 DI::baseUrl()->redirect('login');
29 $url = Strings::escapeTags(trim($_REQUEST['url'] ?? ''));
31 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
32 $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
33 Strings::normaliseLink($url), $url];
34 $contact = DBA::selectFirst('contact', [], $condition);
36 if (!DBA::isResult($contact)) {
37 notice(L10n::t("You aren't following this contact."));
38 DI::baseUrl()->redirect($base_return_path);
42 if (!empty($_REQUEST['cancel'])) {
43 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
46 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
47 notice(L10n::t('Unfollowing is currently not supported by your network.'));
48 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
52 $dissolve = ($contact['rel'] == Contact::SHARING);
54 $owner = User::getOwnerDataById($uid);
56 Contact::terminateFriendship($owner, $contact, $dissolve);
59 // Sharing-only contacts get deleted as there no relationship any more
61 Contact::remove($contact['id']);
62 $return_path = $base_return_path;
64 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
65 $return_path = $base_return_path . '/' . $contact['id'];
68 info(L10n::t('Contact unfollowed'));
69 DI::baseUrl()->redirect($return_path);
73 function unfollow_content(App $a)
75 $base_return_path = 'contact';
78 notice(L10n::t('Permission denied.'));
79 DI::baseUrl()->redirect('login');
84 $url = Strings::escapeTags(trim($_REQUEST['url']));
86 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
87 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
88 Strings::normaliseLink($url), $url];
90 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
92 if (!DBA::isResult($contact)) {
93 notice(L10n::t("You aren't following this contact."));
94 DI::baseUrl()->redirect($base_return_path);
98 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
99 notice(L10n::t('Unfollowing is currently not supported by your network.'));
100 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
104 $request = System::baseUrl() . '/unfollow';
105 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
107 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
109 if (!DBA::isResult($self)) {
110 notice(L10n::t('Permission denied.'));
111 DI::baseUrl()->redirect($base_return_path);
115 // Makes the connection request for friendica contacts easier
116 $_SESSION['fastlane'] = $contact['url'];
118 $o = Renderer::replaceMacros($tpl, [
119 '$header' => L10n::t('Disconnect/Unfollow'),
122 '$does_know_you' => '',
129 '$your_address' => L10n::t('Your Identity Address:'),
130 '$invite_desc' => '',
132 '$submit' => L10n::t('Submit Request'),
133 '$cancel' => L10n::t('Cancel'),
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,
142 '$keywords_label'=> ''
145 DI::page()['aside'] = '';
146 Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
148 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
150 // Show last public posts
151 $o .= Contact::getPostsFromUrl($contact['url']);