3 * @file mod/unfollow.php
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Contact;
10 function unfollow_post(App $a) {
13 notice(t('Permission denied.') . EOL);
14 goaway($_SESSION['return_url']);
18 if ($_REQUEST['cancel']) {
19 goaway($_SESSION['return_url']);
23 $url = notags(trim($_REQUEST['url']));
24 $return_url = $_SESSION['return_url'];
26 $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
27 $uid, CONTACT_IS_FRIEND, normalise_link($url),
28 normalise_link($url), $url, NETWORK_STATUSNET];
29 $contact = dba::selectFirst('contact', [], $condition);
31 if (!DBM::is_result($contact)) {
32 notice(t("Contact wasn't found or can't be unfollowed."));
34 if (in_array($contact['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA))) {
35 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
36 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
39 if (DBM::is_result($r)) {
40 Contact::terminateFriendship($r[0], $contact);
43 dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
45 info(t('Contact unfollowed').EOL);
46 goaway(System::baseUrl().'/contacts/'.$contact['id']);
52 function unfollow_content(App $a) {
55 notice(t('Permission denied.') . EOL);
56 goaway($_SESSION['return_url']);
61 $url = notags(trim($_REQUEST['url']));
63 $submit = t('Submit Request');
65 $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
66 local_user(), CONTACT_IS_FRIEND, normalise_link($url),
67 normalise_link($url), $url, NETWORK_STATUSNET];
68 $contact = dba::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
70 if (!DBM::is_result($contact)) {
71 notice(t("You aren't a friend of this contact.").EOL);
76 if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
77 notice(t("Unfollowing is currently not supported by your network.").EOL);
82 $request = System::baseUrl()."/unfollow";
83 $tpl = get_markup_template('auto_request.tpl');
85 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
88 notice(t('Permission denied.') . EOL);
89 goaway($_SESSION['return_url']);
93 $myaddr = $r[0]["url"];
95 // Makes the connection request for friendica contacts easier
96 $_SESSION["fastlane"] = $contact["url"];
98 $header = t("Disconnect/Unfollow");
100 $o = replace_macros($tpl,array(
101 '$header' => htmlentities($header),
104 '$does_know_you' => "",
111 '$your_address' => t('Your Identity Address:'),
112 '$invite_desc' => "",
114 '$submit' => $submit,
115 '$cancel' => t('Cancel'),
117 '$name' => $contact["name"],
118 '$url' => $contact["url"],
119 '$zrl' => zrl($contact["url"]),
120 '$url_label' => t("Profile URL"),
121 '$myaddr' => $myaddr,
122 '$request' => $request,
124 '$keywords_label' => ""
127 $a->page['aside'] = "";
128 profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
130 $o .= replace_macros(get_markup_template('section_title.tpl'),
131 array('$title' => t('Status Messages and Posts')
134 // Show last public posts
135 $o .= Contact::getPostsFromUrl($contact["url"]);