3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Widget;
24 use Friendica\Core\Protocol;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Contact;
29 use Friendica\Model\User;
30 use Friendica\Util\Strings;
32 function unfollow_post(App $a)
35 notice(DI::l10n()->t('Permission denied.'));
36 DI::baseUrl()->redirect('login');
40 $url = Strings::escapeTags(trim($_REQUEST['url'] ?? ''));
42 unfollow_process($url);
45 function unfollow_content(App $a)
47 $base_return_path = 'contact';
50 notice(DI::l10n()->t('Permission denied.'));
51 DI::baseUrl()->redirect('login');
56 $url = Strings::escapeTags(trim($_REQUEST['url']));
58 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
59 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
60 Strings::normaliseLink($url), $url];
62 $contact = DBA::selectFirst('contact', ['url', 'id', 'uid', 'network', 'addr', 'name'], $condition);
64 if (!DBA::isResult($contact)) {
65 notice(DI::l10n()->t("You aren't following this contact."));
66 DI::baseUrl()->redirect($base_return_path);
70 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
71 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
72 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
76 $request = DI::baseUrl() . '/unfollow';
77 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
79 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
81 if (!DBA::isResult($self)) {
82 notice(DI::l10n()->t('Permission denied.'));
83 DI::baseUrl()->redirect($base_return_path);
87 if (!empty($_REQUEST['auto'])) {
88 unfollow_process($contact['url']);
91 $o = Renderer::replaceMacros($tpl, [
92 '$header' => DI::l10n()->t('Disconnect/Unfollow'),
94 '$your_address' => DI::l10n()->t('Your Identity Address:'),
96 '$submit' => DI::l10n()->t('Submit Request'),
97 '$cancel' => DI::l10n()->t('Cancel'),
98 '$url' => $contact['url'],
99 '$zrl' => Contact::magicLinkByContact($contact),
100 '$url_label' => DI::l10n()->t('Profile URL'),
101 '$myaddr' => $self['url'],
102 '$request' => $request,
104 '$keywords_label'=> ''
107 DI::page()['aside'] = Widget\VCard::getHTML(Contact::getByURL($contact['url'], false));
109 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => DI::l10n()->t('Status Messages and Posts')]);
111 // Show last public posts
112 $o .= Contact::getPostsFromUrl($contact['url']);
117 function unfollow_process(string $url)
119 $base_return_path = 'contact';
123 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
124 $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
125 Strings::normaliseLink($url), $url];
126 $contact = DBA::selectFirst('contact', [], $condition);
128 if (!DBA::isResult($contact)) {
129 notice(DI::l10n()->t("You aren't following this contact."));
130 DI::baseUrl()->redirect($base_return_path);
134 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
135 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
136 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
140 $dissolve = ($contact['rel'] == Contact::SHARING);
142 $owner = User::getOwnerDataById($uid);
144 Contact::terminateFriendship($owner, $contact, $dissolve);
147 // Sharing-only contacts get deleted as there no relationship any more
149 Contact::remove($contact['id']);
150 $return_path = $base_return_path;
152 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
153 $return_path = $base_return_path . '/' . $contact['id'];
156 DI::baseUrl()->redirect($return_path);