]> git.mxchange.org Git - friendica.git/blob - mod/unfollow.php
Add Contact Object
[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                                 $self = ""; // Unused parameter
43                                 terminate_friendship($r[0], $self, $contact);
44                         }
45                 }
46                 dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
47
48                 info(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(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 = t('Submit Request');
67
68         $condition = array("`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::select('contact', array('url', 'network', 'addr', 'name'), $condition, array('limit' => 1));
72
73         if (!DBM::is_result($contact)) {
74                 notice(t("You aren't a friend of this contact.").EOL);
75                 $submit = "";
76                 // NOTREACHED
77         }
78
79         if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
80                 notice(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(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 = t("Disconnect/Unfollow");
102
103         $o  = replace_macros($tpl,array(
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' => t('Your Identity Address:'),
115                         '$invite_desc' => "",
116                         '$emailnet' => "",
117                         '$submit' => $submit,
118                         '$cancel' => t('Cancel'),
119                         '$nickname' => "",
120                         '$name' => $contact["name"],
121                         '$url' => $contact["url"],
122                         '$zrl' => zrl($contact["url"]),
123                         '$url_label' => 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, get_contact_details_by_url($contact["url"]));
132
133         $o .= replace_macros(get_markup_template('section_title.tpl'),
134                                         array('$title' => t('Status Messages and Posts')
135         ));
136
137         // Show last public posts
138         $o .= posts_from_contact_url($a, $contact["url"]);
139
140         return $o;
141 }