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