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 ($_REQUEST['cancel']) {
30 $url = notags(trim(defaults($_REQUEST, 'url', '')));
32 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
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 $owner = User::getOwnerDataById($uid);
51 Contact::terminateFriendship($owner, $contact);
54 // Sharing-only contacts get deleted as there no relationship any more
55 if ($contact['rel'] == Contact::SHARING) {
56 Contact::remove($contact['id']);
57 $return_path = 'contacts';
59 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
60 $return_path = 'contacts/' . $contact['id'];
63 info(L10n::t('Contact unfollowed'));
68 function unfollow_content(App $a)
71 notice(L10n::t('Permission denied.'));
72 goaway($_SESSION['return_url']);
77 $url = notags(trim($_REQUEST['url']));
79 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
80 local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
81 normalise_link($url), $url];
83 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
85 if (!DBA::isResult($contact)) {
86 notice(L10n::t("You aren't following this contact."));
91 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
92 notice(L10n::t('Unfollowing is currently not supported by your network.'));
93 goaway('contacts/' . $contact['id']);
97 $request = System::baseUrl() . '/unfollow';
98 $tpl = get_markup_template('auto_request.tpl');
100 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
102 if (!DBA::isResult($self)) {
103 notice(L10n::t('Permission denied.'));
104 goaway($_SESSION['return_url']);
108 // Makes the connection request for friendica contacts easier
109 $_SESSION['fastlane'] = $contact['url'];
111 $header = L10n::t('Disconnect/Unfollow');
113 $o = replace_macros($tpl, [
114 '$header' => htmlentities($header),
117 '$does_know_you' => '',
124 '$your_address' => L10n::t('Your Identity Address:'),
125 '$invite_desc' => '',
127 '$submit' => L10n::t('Submit Request'),
128 '$cancel' => L10n::t('Cancel'),
130 '$name' => $contact['name'],
131 '$url' => $contact['url'],
132 '$zrl' => Contact::magicLink($contact['url']),
133 '$url_label' => L10n::t('Profile URL'),
134 '$myaddr' => $self['url'],
135 '$request' => $request,
137 '$keywords_label'=> ''
140 $a->page['aside'] = '';
141 Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
143 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
145 // Show last public posts
146 $o .= Contact::getPostsFromUrl($contact['url']);