3 * @copyright Copyright (C) 2020, Friendica
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\Core\Protocol;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Profile;
29 use Friendica\Model\User;
30 use Friendica\Util\Strings;
32 function unfollow_post(App $a)
34 $base_return_path = 'contact';
37 notice(DI::l10n()->t('Permission denied.'));
38 DI::baseUrl()->redirect('login');
43 $url = Strings::escapeTags(trim($_REQUEST['url'] ?? ''));
45 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
46 $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
47 Strings::normaliseLink($url), $url];
48 $contact = DBA::selectFirst('contact', [], $condition);
50 if (!DBA::isResult($contact)) {
51 notice(DI::l10n()->t("You aren't following this contact."));
52 DI::baseUrl()->redirect($base_return_path);
56 if (!empty($_REQUEST['cancel'])) {
57 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
60 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
61 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
62 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
66 $dissolve = ($contact['rel'] == Contact::SHARING);
68 $owner = User::getOwnerDataById($uid);
70 Contact::terminateFriendship($owner, $contact, $dissolve);
73 // Sharing-only contacts get deleted as there no relationship any more
75 Contact::remove($contact['id']);
76 $return_path = $base_return_path;
78 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
79 $return_path = $base_return_path . '/' . $contact['id'];
82 info(DI::l10n()->t('Contact unfollowed'));
83 DI::baseUrl()->redirect($return_path);
87 function unfollow_content(App $a)
89 $base_return_path = 'contact';
92 notice(DI::l10n()->t('Permission denied.'));
93 DI::baseUrl()->redirect('login');
98 $url = Strings::escapeTags(trim($_REQUEST['url']));
100 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
101 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
102 Strings::normaliseLink($url), $url];
104 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
106 if (!DBA::isResult($contact)) {
107 notice(DI::l10n()->t("You aren't following this contact."));
108 DI::baseUrl()->redirect($base_return_path);
112 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
113 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
114 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
118 $request = DI::baseUrl() . '/unfollow';
119 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
121 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
123 if (!DBA::isResult($self)) {
124 notice(DI::l10n()->t('Permission denied.'));
125 DI::baseUrl()->redirect($base_return_path);
129 // Makes the connection request for friendica contacts easier
130 $_SESSION['fastlane'] = $contact['url'];
132 $o = Renderer::replaceMacros($tpl, [
133 '$header' => DI::l10n()->t('Disconnect/Unfollow'),
135 '$your_address' => DI::l10n()->t('Your Identity Address:'),
136 '$invite_desc' => '',
137 '$submit' => DI::l10n()->t('Submit Request'),
138 '$cancel' => DI::l10n()->t('Cancel'),
139 '$url' => $contact['url'],
140 '$zrl' => Contact::magicLink($contact['url']),
141 '$url_label' => DI::l10n()->t('Profile URL'),
142 '$myaddr' => $self['url'],
143 '$request' => $request,
145 '$keywords_label'=> ''
148 DI::page()['aside'] = '';
149 Profile::load($a, '', Contact::getDetailsByURL($contact['url']));
151 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => DI::l10n()->t('Status Messages and Posts')]);
153 // Show last public posts
154 $o .= Contact::getPostsFromUrl($contact['url']);