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