]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Change called method names
[friendica.git] / mod / unfollow.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
6 use Friendica\Object\Contact;
7
8 require_once 'include/follow.php';
9 require_once 'include/Contact.php';
10 require_once 'include/contact_selectors.php';
11
12 function unfollow_post(App $a) {
13
14         if (!local_user()) {
15                 notice(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 = array("`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::select('contact', array(), $condition, array('limit' => 1));
32
33         if (!DBM::is_result($contact)) {
34                 notice(t("Contact wasn't found or can't be unfollowed."));
35         } else {
36                 if (in_array($contact['network'], array(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', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
46
47                 info(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(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 = t('Submit Request');
66
67         $condition = array("`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::select('contact', array('url', 'network', 'addr', 'name'), $condition, array('limit' => 1));
71
72         if (!DBM::is_result($contact)) {
73                 notice(t("You aren't a friend of this contact.").EOL);
74                 $submit = "";
75                 // NOTREACHED
76         }
77
78         if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
79                 notice(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(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 = t("Disconnect/Unfollow");
101
102         $o  = replace_macros($tpl,array(
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' => t('Your Identity Address:'),
114                         '$invite_desc' => "",
115                         '$emailnet' => "",
116                         '$submit' => $submit,
117                         '$cancel' => t('Cancel'),
118                         '$nickname' => "",
119                         '$name' => $contact["name"],
120                         '$url' => $contact["url"],
121                         '$zrl' => zrl($contact["url"]),
122                         '$url_label' => 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'),
133                                         array('$title' => t('Status Messages and Posts')
134         ));
135
136         // Show last public posts
137         $o .= Contact::getPostsFromUrl($contact["url"]);
138
139         return $o;
140 }