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;
14 function unfollow_post(App $a)
17 notice(L10n::t('Permission denied.') . EOL);
18 goaway($_SESSION['return_url']);
22 if ($_REQUEST['cancel']) {
23 goaway($_SESSION['return_url']);
27 $url = notags(trim($_REQUEST['url']));
28 $return_url = $_SESSION['return_url'];
30 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
31 $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
32 normalise_link($url), $url, Protocol::STATUSNET];
33 $contact = DBA::selectFirst('contact', [], $condition);
35 if (!DBA::isResult($contact)) {
36 notice(L10n::t("Contact wasn't found or can't be unfollowed."));
40 if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
41 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
42 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
45 if (DBA::isResult($r)) {
46 Contact::terminateFriendship($r[0], $contact);
50 // Sharing-only contacts get deleted as there no relationship any more
51 if ($contact['rel'] == Contact::SHARING) {
52 Contact::remove($contact['id']);
53 $return_path = 'contacts';
55 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
56 $return_path = 'contacts/' . $contact['id'];
59 info(L10n::t('Contact unfollowed'));
64 function unfollow_content(App $a)
67 notice(L10n::t('Permission denied.') . EOL);
68 goaway($_SESSION['return_url']);
73 $url = notags(trim($_REQUEST['url']));
75 $submit = L10n::t('Submit Request');
77 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
78 local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
79 normalise_link($url), $url, Protocol::STATUSNET];
81 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
83 if (!DBA::isResult($contact)) {
84 notice(L10n::t("You aren't a friend of this contact.").EOL);
89 if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) {
90 notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
95 $request = System::baseUrl()."/unfollow";
96 $tpl = get_markup_template('auto_request.tpl');
98 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
101 notice(L10n::t('Permission denied.') . EOL);
102 goaway($_SESSION['return_url']);
106 $myaddr = $r[0]["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' => $submit,
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' => $myaddr,
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"]);