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