4 use Friendica\Core\System;
6 require_once 'include/probe.php';
7 require_once 'include/follow.php';
8 require_once 'include/Contact.php';
9 require_once 'include/contact_selectors.php';
11 function unfollow_content(App $a) {
14 notice(t('Permission denied.') . EOL);
15 goaway($_SESSION['return_url']);
20 $url = notags(trim($_REQUEST['url']));
22 $submit = t('Submit Request');
24 $condition = array("`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
25 local_user(), CONTACT_IS_FRIEND, normalise_link($url),
26 normalise_link($url), $url, NETWORK_STATUSNET);
27 $contact = dba::select('contact', array('url', 'network', 'addr', 'name'), $condition, array('limit' => 1));
29 if (!dbm::is_result($contact)) {
30 notice(t("You aren't a friend of this contact.").EOL);
35 if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
36 notice(t("Unfollowing is currently not supported by your network.").EOL);
41 $request = System::baseUrl()."/unfollow";
42 $tpl = get_markup_template('auto_request.tpl');
44 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
47 notice(t('Permission denied.') . EOL);
48 goaway($_SESSION['return_url']);
52 $myaddr = $r[0]["url"];
54 // Makes the connection request for friendica contacts easier
55 $_SESSION["fastlane"] = $contact["url"];
57 $header = $contact["name"];
59 if ($contact["addr"] != "") {
60 $header .= " <".$contact["addr"].">";
63 $header = t("Disconnect/Unfollow");
65 $o = replace_macros($tpl,array(
66 '$header' => htmlentities($header),
69 '$does_know_you' => "",
76 '$your_address' => t('Your Identity Address:'),
80 '$cancel' => t('Cancel'),
82 '$name' => $contact["name"],
83 '$url' => $contact["url"],
84 '$zrl' => zrl($contact["url"]),
85 '$url_label' => t("Profile URL"),
87 '$request' => $request,
89 '$keywords_label' => ""
92 $a->page['aside'] = "";
93 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
95 $o .= replace_macros(get_markup_template('section_title.tpl'),
96 array('$title' => t('Status Messages and Posts')
99 // Show last public posts
100 $o .= posts_from_contact_url($a, $contact["url"]);
105 function unfollow_post(App $a) {
108 notice(t('Permission denied.') . EOL);
109 goaway($_SESSION['return_url']);
113 if ($_REQUEST['cancel']) {
114 goaway($_SESSION['return_url']);
118 $url = notags(trim($_REQUEST['url']));
119 $return_url = $_SESSION['return_url'];
121 $condition = array("`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
122 $uid, CONTACT_IS_FRIEND, normalise_link($url),
123 normalise_link($url), $url, NETWORK_STATUSNET);
124 $contact = dba::select('contact', array(), $condition, array('limit' => 1));
126 if (!dbm::is_result($contact)) {
127 notice(t("Contact wasn't found or can't be unfollowed."));
129 if (in_array($contact['network'], array(NETWORK_OSTATUS))) {
130 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
131 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
134 if (dbm::is_result($r)) {
135 $self = ""; // Unused parameter
136 terminate_friendship($r[0], $self, $contact);
139 dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
141 info(t('Contact unfollowed').EOL);
142 goaway(System::baseUrl().'/contacts/'.$contact['id']);