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 DI::baseUrl()->redirect($return_path);
86 function unfollow_content(App $a)
88 $base_return_path = 'contact';
91 notice(DI::l10n()->t('Permission denied.'));
92 DI::baseUrl()->redirect('login');
97 $url = Strings::escapeTags(trim($_REQUEST['url']));
99 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
100 local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
101 Strings::normaliseLink($url), $url];
103 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
105 if (!DBA::isResult($contact)) {
106 notice(DI::l10n()->t("You aren't following this contact."));
107 DI::baseUrl()->redirect($base_return_path);
111 if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
112 notice(DI::l10n()->t('Unfollowing is currently not supported by your network.'));
113 DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']);
117 $request = DI::baseUrl() . '/unfollow';
118 $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
120 $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
122 if (!DBA::isResult($self)) {
123 notice(DI::l10n()->t('Permission denied.'));
124 DI::baseUrl()->redirect($base_return_path);
128 // Makes the connection request for friendica contacts easier
129 $_SESSION['fastlane'] = $contact['url'];
131 $o = Renderer::replaceMacros($tpl, [
132 '$header' => DI::l10n()->t('Disconnect/Unfollow'),
134 '$your_address' => DI::l10n()->t('Your Identity Address:'),
135 '$invite_desc' => '',
136 '$submit' => DI::l10n()->t('Submit Request'),
137 '$cancel' => DI::l10n()->t('Cancel'),
138 '$url' => $contact['url'],
139 '$zrl' => Contact::magicLink($contact['url']),
140 '$url_label' => DI::l10n()->t('Profile URL'),
141 '$myaddr' => $self['url'],
142 '$request' => $request,
144 '$keywords_label'=> ''
147 DI::page()['aside'] = '';
148 Profile::load($a, '', Contact::getByURL($contact['url'], false));
150 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), ['$title' => DI::l10n()->t('Status Messages and Posts')]);
152 // Show last public posts
153 $o .= Contact::getPostsFromUrl($contact['url']);