3 * @file mod/unfollow.php
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Database\DBM;
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` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
31 $uid, CONTACT_IS_FRIEND, normalise_link($url),
32 normalise_link($url), $url, NETWORK_STATUSNET];
33 $contact = DBA::selectFirst('contact', [], $condition);
35 if (!DBM::is_result($contact)) {
36 notice(L10n::t("Contact wasn't found or can't be unfollowed."));
38 if (in_array($contact['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN])) {
39 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
40 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
43 if (DBM::is_result($r)) {
44 Contact::terminateFriendship($r[0], $contact);
47 DBA::update('contact', ['rel' => CONTACT_IS_FOLLOWER], ['id' => $contact['id']]);
49 info(L10n::t('Contact unfollowed').EOL);
50 goaway(System::baseUrl().'/contacts/'.$contact['id']);
56 function unfollow_content(App $a)
59 notice(L10n::t('Permission denied.') . EOL);
60 goaway($_SESSION['return_url']);
65 $url = notags(trim($_REQUEST['url']));
67 $submit = L10n::t('Submit Request');
69 $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
70 local_user(), CONTACT_IS_FRIEND, normalise_link($url),
71 normalise_link($url), $url, NETWORK_STATUSNET];
72 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
74 if (!DBM::is_result($contact)) {
75 notice(L10n::t("You aren't a friend of this contact.").EOL);
80 if (!in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_DFRN])) {
81 notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
86 $request = System::baseUrl()."/unfollow";
87 $tpl = get_markup_template('auto_request.tpl');
89 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
92 notice(L10n::t('Permission denied.') . EOL);
93 goaway($_SESSION['return_url']);
97 $myaddr = $r[0]["url"];
99 // Makes the connection request for friendica contacts easier
100 $_SESSION["fastlane"] = $contact["url"];
102 $header = L10n::t("Disconnect/Unfollow");
104 $o = replace_macros($tpl, [
105 '$header' => htmlentities($header),
108 '$does_know_you' => "",
115 '$your_address' => L10n::t('Your Identity Address:'),
116 '$invite_desc' => "",
118 '$submit' => $submit,
119 '$cancel' => L10n::t('Cancel'),
121 '$name' => $contact["name"],
122 '$url' => $contact["url"],
123 '$zrl' => Contact::magicLink($contact["url"]),
124 '$url_label' => L10n::t("Profile URL"),
125 '$myaddr' => $myaddr,
126 '$request' => $request,
128 '$keywords_label' => ""
131 $a->page['aside'] = "";
132 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
134 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
136 // Show last public posts
137 $o .= Contact::getPostsFromUrl($contact["url"]);