3 * @file mod/unfollow.php
7 use Friendica\Core\Protocol;
8 use Friendica\Core\Renderer;
9 use Friendica\Database\DBA;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13 use Friendica\Model\User;
14 use Friendica\Util\Strings;
16 function unfollow_post(App $a)
18 $base_return_path = 'contact';
21 notice(DI::l10n()->t('Permission denied.'));
22 DI::baseUrl()->redirect('login');
27 $url = Strings::escapeTags(trim($_REQUEST['url'] ?? ''));
29 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
30 $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
31 Strings::normaliseLink($url), $url];
32 $contact = DBA::selectFirst('contact', [], $condition);
34 if (!DBA::isResult($contact)) {
35 notice(DI::l10n()->t("You aren't following this contact."));
36 DI::baseUrl()->redirect($base_return_path);
40 if (!empty($_REQUEST['cancel'])) {
41 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
44 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
45 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
46 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
50 $dissolve = ($contact['rel'] == Contact::SHARING);
52 $owner = User::getOwnerDataById($uid);
54 Contact::terminateFriendship($owner, $contact, $dissolve);
57 // Sharing-only contacts get deleted as there no relationship any more
59 Contact::remove($contact['id']);
60 $return_path = $base_return_path;
62 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
63 $return_path = $base_return_path . '/' . $contact['id'];
66 info(DI::l10n()->t('Contact unfollowed'));
67 DI::baseUrl()->redirect($return_path);
71 function unfollow_content(App $a)
73 $base_return_path = 'contact';
76 notice(DI::l10n()->t('Permission denied.'));
77 DI::baseUrl()->redirect('login');
82 $url = Strings::escapeTags(trim($_REQUEST['url']));
84 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
85 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
86 Strings::normaliseLink($url), $url];
88 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
90 if (!DBA::isResult($contact)) {
91 notice(DI::l10n()->t("You aren't following this contact."));
92 DI::baseUrl()->redirect($base_return_path);
96 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
97 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
98 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
102 $request = DI::baseUrl() . '/unfollow';
103 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
105 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
107 if (!DBA::isResult($self)) {
108 notice(DI::l10n()->t('Permission denied.'));
109 DI::baseUrl()->redirect($base_return_path);
113 // Makes the connection request for friendica contacts easier
114 $_SESSION['fastlane'] = $contact['url'];
116 $o = Renderer::replaceMacros($tpl, [
117 '$header' => DI::l10n()->t('Disconnect/Unfollow'),
120 '$does_know_you' => '',
127 '$your_address' => DI::l10n()->t('Your Identity Address:'),
128 '$invite_desc' => '',
130 '$submit' => DI::l10n()->t('Submit Request'),
131 '$cancel' => DI::l10n()->t('Cancel'),
133 '$name' => $contact['name'],
134 '$url' => $contact['url'],
135 '$zrl' => Contact::magicLink($contact['url']),
136 '$url_label' => DI::l10n()->t('Profile URL'),
137 '$myaddr' => $self['url'],
138 '$request' => $request,
140 '$keywords_label'=> ''
143 DI::page()['aside'] = '';
144 Profile::load($a, '', Contact::getDetailsByURL($contact['url']));
146 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => DI::l10n()->t('Status Messages and Posts')]);
148 // Show last public posts
149 $o .= Contact::getPostsFromUrl($contact['url']);