3 * @file mod/unfollow.php
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;
15 function unfollow_post()
17 $return_url = $_SESSION['return_url'];
20 notice(L10n::t('Permission denied.'));
25 if (!empty($_REQUEST['cancel'])) {
30 $url = notags(trim(defaults($_REQUEST, 'url', '')));
32 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
33 $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
34 normalise_link($url), $url];
35 $contact = DBA::selectFirst('contact', [], $condition);
37 if (!DBA::isResult($contact)) {
38 notice(L10n::t("You aren't following this contact."));
43 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
44 notice(L10n::t('Unfollowing is currently not supported by your network.'));
49 $dissolve = ($contact['rel'] == Contact::SHARING);
51 $owner = User::getOwnerDataById($uid);
53 Contact::terminateFriendship($owner, $contact, $dissolve);
56 // Sharing-only contacts get deleted as there no relationship any more
58 Contact::remove($contact['id']);
59 $return_path = 'contacts';
61 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
62 $return_path = 'contacts/' . $contact['id'];
65 info(L10n::t('Contact unfollowed'));
70 function unfollow_content(App $a)
73 notice(L10n::t('Permission denied.'));
74 goaway($_SESSION['return_url']);
79 $url = notags(trim($_REQUEST['url']));
81 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
82 local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
83 normalise_link($url), $url];
85 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
87 if (!DBA::isResult($contact)) {
88 notice(L10n::t("You aren't following this contact."));
93 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
94 notice(L10n::t('Unfollowing is currently not supported by your network.'));
95 goaway('contacts/' . $contact['id']);
99 $request = System::baseUrl() . '/unfollow';
100 $tpl = get_markup_template('auto_request.tpl');
102 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
104 if (!DBA::isResult($self)) {
105 notice(L10n::t('Permission denied.'));
106 goaway($_SESSION['return_url']);
110 // Makes the connection request for friendica contacts easier
111 $_SESSION['fastlane'] = $contact['url'];
113 $header = L10n::t('Disconnect/Unfollow');
115 $o = replace_macros($tpl, [
116 '$header' => htmlentities($header),
119 '$does_know_you' => '',
126 '$your_address' => L10n::t('Your Identity Address:'),
127 '$invite_desc' => '',
129 '$submit' => L10n::t('Submit Request'),
130 '$cancel' => L10n::t('Cancel'),
132 '$name' => $contact['name'],
133 '$url' => $contact['url'],
134 '$zrl' => Contact::magicLink($contact['url']),
135 '$url_label' => L10n::t('Profile URL'),
136 '$myaddr' => $self['url'],
137 '$request' => $request,
139 '$keywords_label'=> ''
142 $a->page['aside'] = '';
143 Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
145 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
147 // Show last public posts
148 $o .= Contact::getPostsFromUrl($contact['url']);