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;
16 function unfollow_post(App $a)
18 $return_path = 'contacts';
21 notice(L10n::t('Permission denied.'));
22 $a->internalRedirect('login');
27 $url = notags(trim(defaults($_REQUEST, 'url', '')));
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);
34 if (!DBA::isResult($contact)) {
35 notice(L10n::t("You aren't following this contact."));
36 $a->internalRedirect($return_path);
40 if (!empty($_REQUEST['cancel'])) {
41 $a->internalRedirect($return_path . '/' . $contact['id']);
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']);
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 = 'contacts';
62 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
63 $return_path = 'contact/' . $contact['id'];
66 info(L10n::t('Contact unfollowed'));
67 $a->internalRedirect($return_path);
71 function unfollow_content(App $a)
73 $return_path = 'contacts';
76 notice(L10n::t('Permission denied.'));
77 $a->internalRedirect('login');
82 $url = notags(trim($_REQUEST['url']));
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];
88 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
90 if (!DBA::isResult($contact)) {
91 notice(L10n::t("You aren't following this contact."));
92 $a->internalRedirect($return_path);
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']);
102 $request = System::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(L10n::t('Permission denied.'));
109 $a->internalRedirect($return_path);
113 // Makes the connection request for friendica contacts easier
114 $_SESSION['fastlane'] = $contact['url'];
116 $header = L10n::t('Disconnect/Unfollow');
118 $o = Renderer::replaceMacros($tpl, [
119 '$header' => htmlentities($header),
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 $a->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']);