]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Ops, one more left ...
[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\Protocol;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
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::FRIEND, normalise_link($url),
32                         normalise_link($url), $url, Protocol::STATUSNET];
33         $contact = DBA::selectFirst('contact', [], $condition);
34
35         if (!DBA::isResult($contact)) {
36                 notice(L10n::t("Contact wasn't found or can't be unfollowed."));
37         } else {
38                 if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::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 (DBA::isResult($r)) {
44                                 Contact::terminateFriendship($r[0], $contact);
45                         }
46                 }
47                 DBA::update('contact', ['rel' => Contact::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::FRIEND, normalise_link($url),
71                         normalise_link($url), $url, Protocol::STATUSNET];
72
73         $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
74
75         if (!DBA::isResult($contact)) {
76                 notice(L10n::t("You aren't a friend of this contact.").EOL);
77                 $submit = "";
78                 // NOTREACHED
79         }
80
81         if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) {
82                 notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
83                 $submit = "";
84                 // NOTREACHED
85         }
86
87         $request = System::baseUrl()."/unfollow";
88         $tpl = get_markup_template('auto_request.tpl');
89
90         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
91
92         if (!$r) {
93                 notice(L10n::t('Permission denied.') . EOL);
94                 goaway($_SESSION['return_url']);
95                 // NOTREACHED
96         }
97
98         $myaddr = $r[0]["url"];
99
100         // Makes the connection request for friendica contacts easier
101         $_SESSION["fastlane"] = $contact["url"];
102
103         $header = L10n::t("Disconnect/Unfollow");
104
105         $o  = replace_macros($tpl, [
106                         '$header' => htmlentities($header),
107                         '$desc' => "",
108                         '$pls_answer' => "",
109                         '$does_know_you' => "",
110                         '$add_note' => "",
111                         '$page_desc' => "",
112                         '$friendica' => "",
113                         '$statusnet' => "",
114                         '$diaspora' => "",
115                         '$diasnote' => "",
116                         '$your_address' => L10n::t('Your Identity Address:'),
117                         '$invite_desc' => "",
118                         '$emailnet' => "",
119                         '$submit' => $submit,
120                         '$cancel' => L10n::t('Cancel'),
121                         '$nickname' => "",
122                         '$name' => $contact["name"],
123                         '$url' => $contact["url"],
124                         '$zrl' => Contact::magicLink($contact["url"]),
125                         '$url_label' => L10n::t("Profile URL"),
126                         '$myaddr' => $myaddr,
127                         '$request' => $request,
128                         '$keywords' => "",
129                         '$keywords_label' => ""
130         ]);
131
132         $a->page['aside'] = "";
133         Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
134
135         $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
136
137         // Show last public posts
138         $o .= Contact::getPostsFromUrl($contact["url"]);
139
140         return $o;
141 }