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];
33 $contact = DBA::selectFirst('contact', [], $condition);
35 if (!DBA::isResult($contact)) {
36 notice(L10n::t("You aren't following this contact."));
41 if ($contact['network'] == Protocol::STATUSNET) {
42 notice(L10n::t('Unfollowing is currently not supported by your network.'));
47 if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
48 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
49 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
52 if (DBA::isResult($r)) {
53 Contact::terminateFriendship($r[0], $contact);
57 // Sharing-only contacts get deleted as there no relationship any more
58 if ($contact['rel'] == Contact::SHARING) {
59 Contact::remove($contact['id']);
60 $return_path = 'contacts';
62 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
63 $return_path = 'contacts/' . $contact['id'];
66 info(L10n::t('Contact unfollowed'));
71 function unfollow_content(App $a)
74 notice(L10n::t('Permission denied.') . EOL);
75 goaway($_SESSION['return_url']);
80 $url = notags(trim($_REQUEST['url']));
82 $submit = L10n::t('Submit Request');
84 $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
85 local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
86 normalise_link($url), $url];
88 $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
90 if (!DBA::isResult($contact)) {
91 notice(L10n::t("You aren't following this contact."));
96 if ($contact['network'] == Protocol::STATUSNET) {
97 notice(L10n::t('Unfollowing is currently not supported by your network.'));
98 goaway('contacts/' . $contact['id']);
102 $request = System::baseUrl()."/unfollow";
103 $tpl = get_markup_template('auto_request.tpl');
105 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
108 notice(L10n::t('Permission denied.') . EOL);
109 goaway($_SESSION['return_url']);
113 $myaddr = $r[0]["url"];
115 // Makes the connection request for friendica contacts easier
116 $_SESSION["fastlane"] = $contact["url"];
118 $header = L10n::t("Disconnect/Unfollow");
120 $o = replace_macros($tpl, [
121 '$header' => htmlentities($header),
124 '$does_know_you' => "",
131 '$your_address' => L10n::t('Your Identity Address:'),
132 '$invite_desc' => "",
134 '$submit' => $submit,
135 '$cancel' => L10n::t('Cancel'),
137 '$name' => $contact["name"],
138 '$url' => $contact["url"],
139 '$zrl' => Contact::magicLink($contact["url"]),
140 '$url_label' => L10n::t("Profile URL"),
141 '$myaddr' => $myaddr,
142 '$request' => $request,
144 '$keywords_label' => ""
147 $a->page['aside'] = "";
148 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
150 $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
152 // Show last public posts
153 $o .= Contact::getPostsFromUrl($contact["url"]);