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` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
31 $uid, 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."));
38 if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::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 (DBA::isResult($r)) {
44 Contact::terminateFriendship($r[0], $contact);
47 DBA::update('contact', ['rel' => Contact::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::FRIEND, normalise_link($url),
71 normalise_link($url), $url, Protocol::STATUSNET];
73 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
75 if (!DBA::isResult($contact)) {
76 notice(L10n::t("You aren't a friend of this contact.").EOL);
81 if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) {
82 notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
87 $request = System::baseUrl()."/unfollow";
88 $tpl = get_markup_template('auto_request.tpl');
90 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
93 notice(L10n::t('Permission denied.') . EOL);
94 goaway($_SESSION['return_url']);
98 $myaddr = $r[0]["url"];
100 // Makes the connection request for friendica contacts easier
101 $_SESSION["fastlane"] = $contact["url"];
103 $header = L10n::t("Disconnect/Unfollow");
105 $o = replace_macros($tpl, [
106 '$header' => htmlentities($header),
109 '$does_know_you' => "",
116 '$your_address' => L10n::t('Your Identity Address:'),
117 '$invite_desc' => "",
119 '$submit' => $submit,
120 '$cancel' => L10n::t('Cancel'),
122 '$name' => $contact["name"],
123 '$url' => $contact["url"],
124 '$zrl' => Contact::magicLink($contact["url"]),
125 '$url_label' => L10n::t("Profile URL"),
126 '$myaddr' => $myaddr,
127 '$request' => $request,
129 '$keywords_label' => ""
132 $a->page['aside'] = "";
133 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
135 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
137 // Show last public posts
138 $o .= Contact::getPostsFromUrl($contact["url"]);