]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
4bc64e4fc30be2f73062ba1958c24b7d60afec8c
[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` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
31                 $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
32                 normalise_link($url), $url];
33         $contact = DBA::selectFirst('contact', [], $condition);
34
35         if (!DBA::isResult($contact)) {
36                 notice(L10n::t("You aren't following this contact."));
37                 goaway($return_url);
38                 // NOTREACHED
39         }
40
41         if ($contact['network'] == Protocol::STATUSNET) {
42                 notice(L10n::t('Unfollowing is currently not supported by your network.'));
43                 goaway($return_url);
44                 // NOTREACHED
45         }
46
47         if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
48                 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
49                         WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
50                         intval($uid)
51                 );
52                 if (DBA::isResult($r)) {
53                         Contact::terminateFriendship($r[0], $contact);
54                 }
55         }
56
57         // Sharing-only contacts get deleted as there no relationship any more
58         if ($contact['rel'] == Contact::SHARING) {
59                 Contact::remove($contact['id']);
60                 $return_path = 'contacts';
61         } else {
62                 DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
63                 $return_path = 'contacts/' . $contact['id'];
64         }
65
66         info(L10n::t('Contact unfollowed'));
67         goaway($return_path);
68         // NOTREACHED
69 }
70
71 function unfollow_content(App $a)
72 {
73         if (! local_user()) {
74                 notice(L10n::t('Permission denied.') . EOL);
75                 goaway($_SESSION['return_url']);
76                 // NOTREACHED
77         }
78
79         $uid = local_user();
80         $url = notags(trim($_REQUEST['url']));
81
82         $submit = L10n::t('Submit Request');
83
84         $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
85                 local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
86                 normalise_link($url), $url];
87
88         $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
89
90         if (!DBA::isResult($contact)) {
91                 notice(L10n::t("You aren't following this contact."));
92                 goaway('contacts');
93                 // NOTREACHED
94         }
95
96         if ($contact['network'] == Protocol::STATUSNET) {
97                 notice(L10n::t('Unfollowing is currently not supported by your network.'));
98                 goaway('contacts/' . $contact['id']);
99                 // NOTREACHED
100         }
101
102         $request = System::baseUrl()."/unfollow";
103         $tpl = get_markup_template('auto_request.tpl');
104
105         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
106
107         if (!$r) {
108                 notice(L10n::t('Permission denied.') . EOL);
109                 goaway($_SESSION['return_url']);
110                 // NOTREACHED
111         }
112
113         $myaddr = $r[0]["url"];
114
115         // Makes the connection request for friendica contacts easier
116         $_SESSION["fastlane"] = $contact["url"];
117
118         $header = L10n::t("Disconnect/Unfollow");
119
120         $o  = replace_macros($tpl, [
121                         '$header' => htmlentities($header),
122                         '$desc' => "",
123                         '$pls_answer' => "",
124                         '$does_know_you' => "",
125                         '$add_note' => "",
126                         '$page_desc' => "",
127                         '$friendica' => "",
128                         '$statusnet' => "",
129                         '$diaspora' => "",
130                         '$diasnote' => "",
131                         '$your_address' => L10n::t('Your Identity Address:'),
132                         '$invite_desc' => "",
133                         '$emailnet' => "",
134                         '$submit' => $submit,
135                         '$cancel' => L10n::t('Cancel'),
136                         '$nickname' => "",
137                         '$name' => $contact["name"],
138                         '$url' => $contact["url"],
139                         '$zrl' => Contact::magicLink($contact["url"]),
140                         '$url_label' => L10n::t("Profile URL"),
141                         '$myaddr' => $myaddr,
142                         '$request' => $request,
143                         '$keywords' => "",
144                         '$keywords_label' => ""
145         ]);
146
147         $a->page['aside'] = "";
148         Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
149
150         $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
151
152         // Show last public posts
153         $o .= Contact::getPostsFromUrl($contact["url"]);
154
155         return $o;
156 }