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;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
14 use Friendica\Model\User;
15 use Friendica\Util\Strings;
17 function unfollow_post(App $a)
19 $base_return_path = 'contact';
22 notice(L10n::t('Permission denied.'));
23 $a->internalRedirect('login');
28 $url = Strings::escapeTags(trim(defaults($_REQUEST, 'url', '')));
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);
35 if (!DBA::isResult($contact)) {
36 notice(L10n::t("You aren't following this contact."));
37 $a->internalRedirect($base_return_path);
41 if (!empty($_REQUEST['cancel'])) {
42 $a->internalRedirect($base_return_path . '/' . $contact['id']);
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']);
51 $dissolve = ($contact['rel'] == Contact::SHARING);
53 $owner = User::getOwnerDataById($uid);
55 Contact::terminateFriendship($owner, $contact, $dissolve);
58 // Sharing-only contacts get deleted as there no relationship any more
60 Contact::remove($contact['id']);
61 $return_path = $base_return_path;
63 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
64 $return_path = $base_return_path . '/' . $contact['id'];
67 info(L10n::t('Contact unfollowed'));
68 $a->internalRedirect($return_path);
72 function unfollow_content(App $a)
74 $base_return_path = 'contact';
77 notice(L10n::t('Permission denied.'));
78 $a->internalRedirect('login');
83 $url = Strings::escapeTags(trim($_REQUEST['url']));
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];
89 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
91 if (!DBA::isResult($contact)) {
92 notice(L10n::t("You aren't following this contact."));
93 $a->internalRedirect($base_return_path);
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']);
103 $request = System::baseUrl() . '/unfollow';
104 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
106 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
108 if (!DBA::isResult($self)) {
109 notice(L10n::t('Permission denied.'));
110 $a->internalRedirect($base_return_path);
114 // Makes the connection request for friendica contacts easier
115 $_SESSION['fastlane'] = $contact['url'];
117 $o = Renderer::replaceMacros($tpl, [
118 '$header' => L10n::t('Disconnect/Unfollow'),
121 '$does_know_you' => '',
128 '$your_address' => L10n::t('Your Identity Address:'),
129 '$invite_desc' => '',
131 '$submit' => L10n::t('Submit Request'),
132 '$cancel' => L10n::t('Cancel'),
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,
141 '$keywords_label'=> ''
144 $a->page['aside'] = '';
145 Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
147 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
149 // Show last public posts
150 $o .= Contact::getPostsFromUrl($contact['url']);