3 * @file mod/unfollow.php
6 use Friendica\Core\L10n;
7 use Friendica\Core\System;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Contact;
10 use Friendica\Model\Profile;
12 function unfollow_post(App $a)
15 notice(L10n::t('Permission denied.') . EOL);
16 goaway($_SESSION['return_url']);
20 if ($_REQUEST['cancel']) {
21 goaway($_SESSION['return_url']);
25 $url = notags(trim($_REQUEST['url']));
26 $return_url = $_SESSION['return_url'];
28 $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
29 $uid, CONTACT_IS_FRIEND, normalise_link($url),
30 normalise_link($url), $url, NETWORK_STATUSNET];
31 $contact = dba::selectFirst('contact', [], $condition);
33 if (!DBM::is_result($contact)) {
34 notice(L10n::t("Contact wasn't found or can't be unfollowed."));
36 if (in_array($contact['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA])) {
37 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
38 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
41 if (DBM::is_result($r)) {
42 Contact::terminateFriendship($r[0], $contact);
45 dba::update('contact', ['rel' => CONTACT_IS_FOLLOWER], ['id' => $contact['id']]);
47 info(L10n::t('Contact unfollowed').EOL);
48 goaway(System::baseUrl().'/contacts/'.$contact['id']);
54 function unfollow_content(App $a)
57 notice(L10n::t('Permission denied.') . EOL);
58 goaway($_SESSION['return_url']);
63 $url = notags(trim($_REQUEST['url']));
65 $submit = L10n::t('Submit Request');
67 $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
68 local_user(), CONTACT_IS_FRIEND, normalise_link($url),
69 normalise_link($url), $url, NETWORK_STATUSNET];
70 $contact = dba::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
72 if (!DBM::is_result($contact)) {
73 notice(L10n::t("You aren't a friend of this contact.").EOL);
78 if (!in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS])) {
79 notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
84 $request = System::baseUrl()."/unfollow";
85 $tpl = get_markup_template('auto_request.tpl');
87 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
90 notice(L10n::t('Permission denied.') . EOL);
91 goaway($_SESSION['return_url']);
95 $myaddr = $r[0]["url"];
97 // Makes the connection request for friendica contacts easier
98 $_SESSION["fastlane"] = $contact["url"];
100 $header = L10n::t("Disconnect/Unfollow");
102 $o = replace_macros($tpl, [
103 '$header' => htmlentities($header),
106 '$does_know_you' => "",
113 '$your_address' => L10n::t('Your Identity Address:'),
114 '$invite_desc' => "",
116 '$submit' => $submit,
117 '$cancel' => L10n::t('Cancel'),
119 '$name' => $contact["name"],
120 '$url' => $contact["url"],
121 '$zrl' => Profile::zrl($contact["url"]),
122 '$url_label' => L10n::t("Profile URL"),
123 '$myaddr' => $myaddr,
124 '$request' => $request,
126 '$keywords_label' => ""
129 $a->page['aside'] = "";
130 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
132 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
134 // Show last public posts
135 $o .= Contact::getPostsFromUrl($contact["url"]);