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