]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Merge remote-tracking branch 'upstream/develop' into unfollow
[friendica.git] / mod / unfollow.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5
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';
10
11 function unfollow_content(App $a) {
12
13         if (! local_user()) {
14                 notice(t('Permission denied.') . EOL);
15                 goaway($_SESSION['return_url']);
16                 // NOTREACHED
17         }
18
19         $uid = local_user();
20         $url = notags(trim($_REQUEST['url']));
21
22         $submit = t('Submit Request');
23
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));
28
29         if (!dbm::is_result($contact)) {
30                 notice(t("You aren't a friend of this contact.").EOL);
31                 $submit = "";
32                 // NOTREACHED
33         }
34
35         if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
36                 notice(t("Unfollowing is currently not supported by your network.").EOL);
37                 $submit = "";
38                 // NOTREACHED
39         }
40
41         $request = System::baseUrl()."/unfollow";
42         $tpl = get_markup_template('auto_request.tpl');
43
44         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
45
46         if (!$r) {
47                 notice(t('Permission denied.') . EOL);
48                 goaway($_SESSION['return_url']);
49                 // NOTREACHED
50         }
51
52         $myaddr = $r[0]["url"];
53
54         // Makes the connection request for friendica contacts easier
55         $_SESSION["fastlane"] = $contact["url"];
56
57         $header = $contact["name"];
58
59         if ($contact["addr"] != "") {
60                 $header .= " <".$contact["addr"].">";
61         }
62
63         $header = t("Disconnect/Unfollow");
64
65         $o  = replace_macros($tpl,array(
66                         '$header' => htmlentities($header),
67                         '$desc' => "",
68                         '$pls_answer' => "",
69                         '$does_know_you' => "",
70                         '$add_note' => "",
71                         '$page_desc' => "",
72                         '$friendica' => "",
73                         '$statusnet' => "",
74                         '$diaspora' => "",
75                         '$diasnote' => "",
76                         '$your_address' => t('Your Identity Address:'),
77                         '$invite_desc' => "",
78                         '$emailnet' => "",
79                         '$submit' => $submit,
80                         '$cancel' => t('Cancel'),
81                         '$nickname' => "",
82                         '$name' => $contact["name"],
83                         '$url' => $contact["url"],
84                         '$zrl' => zrl($contact["url"]),
85                         '$url_label' => t("Profile URL"),
86                         '$myaddr' => $myaddr,
87                         '$request' => $request,
88                         '$keywords' => "",
89                         '$keywords_label' => ""
90         ));
91
92         $a->page['aside'] = "";
93         profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
94
95         $o .= replace_macros(get_markup_template('section_title.tpl'),
96                                         array('$title' => t('Status Messages and Posts')
97         ));
98
99         // Show last public posts
100         $o .= posts_from_contact_url($a, $contact["url"]);
101
102         return $o;
103 }
104
105 function unfollow_post(App $a) {
106
107         if (!local_user()) {
108                 notice(t('Permission denied.') . EOL);
109                 goaway($_SESSION['return_url']);
110                 // NOTREACHED
111         }
112
113         if ($_REQUEST['cancel']) {
114                 goaway($_SESSION['return_url']);
115         }
116
117         $uid = local_user();
118         $url = notags(trim($_REQUEST['url']));
119         $return_url = $_SESSION['return_url'];
120
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));
125
126         if (!dbm::is_result($contact)) {
127                 notice(t("Contact wasn't found or can't be unfollowed."));
128         } else {
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",
132                                 intval($uid)
133                         );
134                         if (dbm::is_result($r)) {
135                                 $self = ""; // Unused parameter
136                                 terminate_friendship($r[0], $self, $contact);
137                         }
138                 }
139                 dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
140
141                 info(t('Contact unfollowed').EOL);
142                 goaway(System::baseUrl().'/contacts/'.$contact['id']);
143         }
144         goaway($return_url);
145         // NOTREACHED
146 }