]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Merge pull request #4237 from zeroadam/Profile-#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 use Friendica\Model\Profile;
10
11 function unfollow_post(App $a)
12 {
13         if (!local_user()) {
14                 notice(t('Permission denied.') . EOL);
15                 goaway($_SESSION['return_url']);
16                 // NOTREACHED
17         }
18
19         if ($_REQUEST['cancel']) {
20                 goaway($_SESSION['return_url']);
21         }
22
23         $uid = local_user();
24         $url = notags(trim($_REQUEST['url']));
25         $return_url = $_SESSION['return_url'];
26
27         $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
28                         $uid, CONTACT_IS_FRIEND, normalise_link($url),
29                         normalise_link($url), $url, NETWORK_STATUSNET];
30         $contact = dba::selectFirst('contact', [], $condition);
31
32         if (!DBM::is_result($contact)) {
33                 notice(t("Contact wasn't found or can't be unfollowed."));
34         } else {
35                 if (in_array($contact['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA))) {
36                         $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
37                                 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
38                                 intval($uid)
39                         );
40                         if (DBM::is_result($r)) {
41                                 Contact::terminateFriendship($r[0], $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 = ["`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::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
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' => Profile::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, Contact::getDetailsByURL($contact["url"]));
130
131         $o .= replace_macros(get_markup_template('section_title.tpl'), array('$title' => t('Status Messages and Posts')));
132
133         // Show last public posts
134         $o .= Contact::getPostsFromUrl($contact["url"]);
135
136         return $o;
137 }