]> git.mxchange.org Git - friendica.git/blob - include/Contact.php
Reset network when showing a contact's posts
[friendica.git] / include / Contact.php
1 <?php
2
3
4 // Included here for completeness, but this is a very dangerous operation.
5 // It is the caller's responsibility to confirm the requestor's intent and
6 // authorisation to do this.
7
8 function user_remove($uid) {
9         if(! $uid)
10                 return;
11         $a = get_app();
12         logger('Removing user: ' . $uid);
13
14         $r = q("select * from user where uid = %d limit 1", intval($uid));
15
16         call_hooks('remove_user',$r[0]);
17
18         // save username (actually the nickname as it is guaranteed 
19         // unique), so it cannot be re-registered in the future.
20
21         q("insert into userd ( username ) values ( '%s' )",
22                 $r[0]['nickname']
23         );
24
25         // don't delete yet, will be done later when contacts have deleted my stuff
26         // q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
27         q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
28         q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
29         q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
30         q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
31         q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
32         q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
33         q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
34         q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
35         q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
36         q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
37         q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
38         q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
39         q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
40         q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
41         q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
42         q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
43         q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
44         q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
45         // don't delete yet, will be done later when contacts have deleted my stuff
46         // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
47         q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
48         proc_run('php', "include/notifier.php", "removeme", $uid);
49         if($uid == local_user()) {
50                 unset($_SESSION['authenticated']);
51                 unset($_SESSION['uid']);
52                 goaway($a->get_baseurl());
53         }
54 }
55
56
57 function contact_remove($id) {
58
59         $r = q("select uid from contact where id = %d limit 1",
60                 intval($id)
61         );
62         if((! count($r)) || (! intval($r[0]['uid'])))
63                 return;
64
65         $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
66         if($archive) {
67                 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d limit 1",
68                         intval($id)
69                 );
70                 return;
71         }
72
73         q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
74                 intval($id)
75         );
76         q("DELETE FROM `item` WHERE `contact-id` = %d ",
77                 intval($id)
78         );
79         q("DELETE FROM `photo` WHERE `contact-id` = %d ",
80                 intval($id)
81         );
82         q("DELETE FROM `mail` WHERE `contact-id` = %d ",
83                 intval($id)
84         );
85         q("DELETE FROM `event` WHERE `cid` = %d ",
86                 intval($id)
87         );
88         q("DELETE FROM `queue` WHERE `cid` = %d ",
89                 intval($id)
90         );
91
92 }
93
94
95 // sends an unfriend message. Does not remove the contact
96
97 function terminate_friendship($user,$self,$contact) {
98
99
100         $a = get_app();
101
102         require_once('include/datetime.php');
103
104         if($contact['network'] === NETWORK_OSTATUS) {
105
106                 $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
107                         '$name' => $user['username'],
108                         '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
109                         '$photo' => $self['photo'],
110                         '$thumb' => $self['thumb'],
111                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
112                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
113                         '$title' => '',
114                         '$type' => 'text',
115                         '$content' => t('stopped following'),
116                         '$nick' => $user['nickname'],
117                         '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
118                         '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
119                 ));
120
121                 if((x($contact,'notify')) && (strlen($contact['notify']))) {
122                         require_once('include/salmon.php');
123                         slapper($user,$contact['notify'],$slap);
124                 }
125         }
126         elseif($contact['network'] === NETWORK_DIASPORA) {
127                 require_once('include/diaspora.php');
128                 diaspora_unshare($user,$contact);
129         }
130         elseif($contact['network'] === NETWORK_DFRN) {
131                 require_once('include/items.php');
132                 dfrn_deliver($user,$contact,'placeholder', 1);
133         }
134
135 }
136
137
138 // Contact has refused to recognise us as a friend. We will start a countdown.
139 // If they still don't recognise us in 32 days, the relationship is over,
140 // and we won't waste any more time trying to communicate with them.
141 // This provides for the possibility that their database is temporarily messed
142 // up or some other transient event and that there's a possibility we could recover from it.
143  
144 if(! function_exists('mark_for_death')) {
145 function mark_for_death($contact) {
146
147         if($contact['archive'])
148                 return;
149
150         if($contact['term-date'] == '0000-00-00 00:00:00') {
151                 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
152                                 dbesc(datetime_convert()),
153                                 intval($contact['id'])
154                 );
155         }
156         else {
157
158                 // TODO: We really should send a notification to the owner after 2-3 weeks
159                 // so they won't be surprised when the contact vanishes and can take
160                 // remedial action if this was a serious mistake or glitch
161
162                 $expiry = $contact['term-date'] . ' + 32 days ';
163                 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
164
165                         // relationship is really truly dead. 
166                         // archive them rather than delete
167                         // though if the owner tries to unarchive them we'll start the whole process over again
168
169                         q("update contact set `archive` = 1 where id = %d limit 1",
170                                 intval($contact['id'])
171                         );
172                         q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact['id']), intval($contact['uid']));
173
174                         //contact_remove($contact['id']);
175
176                 }
177         }
178
179 }}
180
181 if(! function_exists('unmark_for_death')) {
182 function unmark_for_death($contact) {
183         // It's a miracle. Our dead contact has inexplicably come back to life.
184         q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
185                 dbesc('0000-00-00 00:00:00'),
186                 intval($contact['id'])
187         );
188 }}
189
190 if(! function_exists('contact_photo_menu')){
191 function contact_photo_menu($contact) {
192
193         $a = get_app();
194         
195         $contact_url="";
196         $pm_url="";
197         $status_link="";
198         $photos_link="";
199         $posts_link="";
200         $poke_link="";
201
202         $sparkle = false;
203         if($contact['network'] === NETWORK_DFRN) {
204                 $sparkle = true;
205                 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
206         }
207         else
208                 $profile_link = $contact['url'];
209
210         if($profile_link === 'mailbox')
211                 $profile_link = '';
212
213         if($sparkle) {
214                 $status_link = $profile_link . "?url=status";
215                 $photos_link = $profile_link . "?url=photos";
216                 $profile_link = $profile_link . "?url=profile";
217                 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
218         }
219
220         $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id'];
221         $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
222         $posts_link = $a->get_baseurl() . '/network/0?nets=all&cid=' . $contact['id'];
223
224         $menu = Array(
225                 'poke' => array(t("Poke"), $poke_link),
226                 'status' => array(t("View Status"), $status_link),
227                 'profile' => array(t("View Profile"), $profile_link),
228                 'photos' => array(t("View Photos"), $photos_link),              
229                 'network' => array(t("Network Posts"), $posts_link), 
230                 'edit' => array(t("Edit Contact"), $contact_url),
231                 'pm' => array(t("Send PM"), $pm_url),
232         );
233         
234         
235         $args = array('contact' => $contact, 'menu' => &$menu);
236         
237         call_hooks('contact_photo_menu', $args);
238         
239 /*      $o = "";
240         foreach($menu as $k=>$v){
241                 if ($v!="") {
242                         if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
243                                 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
244                         else
245                                 $o .= "<li><a href=\"$v\">$k</a></li>\n";
246                 }
247         }
248         return $o;*/
249         foreach($menu as $k=>$v){
250                 if ($v[1]!="") {
251                         if(($v[0] !== t("Network Posts")) && ($v[0] !== t("Send PM")) && ($v[0] !== t('Edit Contact')))
252                                 $menu[$k][2] = 1;
253                         else
254                                 $menu[$k][2] = 0;
255                 }
256         }
257         return $menu;
258 }}
259
260
261 function random_profile() {
262         $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
263         if(count($r))
264                 return dirname($r[0]['url']);
265         return '';
266 }
267
268
269 function contacts_not_grouped($uid,$start = 0,$count = 0) {
270
271         if(! $count) {
272                 $r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
273                         intval($uid),
274                         intval($uid)
275                 );
276
277                 return $r;
278
279
280         }
281
282         $r = q("select * from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) and blocked = 0 and pending = 0 limit %d, %d",
283                 intval($uid),
284                 intval($uid),
285                 intval($start),
286                 intval($count)
287         );
288
289         return $r;
290 }
291