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