]> git.mxchange.org Git - friendica.git/blob - include/Contact.php
Merge remote-tracking branch 'friendica/master'
[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         q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
26         q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
27         q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
28         q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
29         q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
30         q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
31         q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
32         q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
33         q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
34         q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
35         q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
36         q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
37         q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
38         q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
39         q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
40         q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
41         q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
42         q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
43         q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
44         q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
45         if($uid == local_user()) {
46                 unset($_SESSION['authenticated']);
47                 unset($_SESSION['uid']);
48                 goaway($a->get_baseurl());
49         }
50 }
51
52
53 function contact_remove($id) {
54         q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
55                 intval($id)
56         );
57         q("DELETE FROM `item` WHERE `contact-id` = %d ",
58                 intval($id)
59         );
60         q("DELETE FROM `photo` WHERE `contact-id` = %d ",
61                 intval($id)
62         );
63         q("DELETE FROM `mail` WHERE `contact-id` = %d ",
64                 intval($id)
65         );
66         q("DELETE FROM `event` WHERE `cid` = %d ",
67                 intval($id)
68         );
69         q("DELETE FROM `queue` WHERE `cid` = %d ",
70                 intval($id)
71         );
72
73 }
74
75
76 // Contact has refused to recognise us as a friend. We will start a countdown.
77 // If they still don't recognise us in 32 days, the relationship is over,
78 // and we won't waste any more time trying to communicate with them.
79 // This provides for the possibility that their database is temporarily messed
80 // up or some other transient event and that there's a possibility we could recover from it.
81  
82 if(! function_exists('mark_for_death')) {
83 function mark_for_death($contact) {
84         if($contact['term-date'] == '0000-00-00 00:00:00') {
85                 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
86                                 dbesc(datetime_convert()),
87                                 intval($contact['id'])
88                 );
89         }
90         else {
91                 $expiry = $contact['term-date'] . ' + 32 days ';
92                 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
93
94                         // relationship is really truly dead. 
95
96                         contact_remove($contact['id']);
97
98                 }
99         }
100
101 }}
102
103 if(! function_exists('unmark_for_death')) {
104 function unmark_for_death($contact) {
105         // It's a miracle. Our dead contact has inexplicably come back to life.
106         q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
107                 dbesc('0000-00-00 00:00:00'),
108                 intval($contact['id'])
109         );
110 }}
111
112 if(! function_exists('contact_photo_menu')){
113 function contact_photo_menu($contact) {
114
115         $a = get_app();
116         
117         $contact_url="";
118         $pm_url="";
119         $status_link="";
120         $photos_link="";
121         $posts_link="";
122
123         $sparkle = false;
124         if($contact['network'] === NETWORK_DFRN) {
125                 $sparkle = true;
126                 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
127         }
128         else
129                 $profile_link = $contact['url'];
130
131         if($profile_link === 'mailbox')
132                 $profile_link = '';
133
134         if($sparkle) {
135                 $status_link = $profile_link . "?url=status";
136                 $photos_link = $profile_link . "?url=photos";
137                 $profile_link = $profile_link . "?url=profile";
138                 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
139         }
140
141         $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
142         $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
143
144         $menu = Array(
145                 t("View Status") => $status_link,
146                 t("View Profile") => $profile_link,
147                 t("View Photos") => $photos_link,               
148                 t("Network Posts") => $posts_link, 
149                 t("Edit Contact") => $contact_url,
150                 t("Send PM") => $pm_url,
151         );
152         
153         
154         $args = array('contact' => $contact, 'menu' => $menu);
155         
156         call_hooks('contact_photo_menu', $args);
157         
158         $o = "";
159         foreach($menu as $k=>$v){
160                 if ($v!="") {
161                         if(($k !== t("Network Posts")) && ($k !== t("Send PM")))
162                                 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
163                         else
164                                 $o .= "<li><a href=\"$v\">$k</a></li>\n";
165                 }
166         }
167         return $o;
168 }}
169
170
171 function random_profile() {
172         $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
173         if(count($r))
174                 return dirname($r[0]['url']);
175         return '';
176 }
177
178
179 function contacts_not_grouped($uid,$start = 0,$count = 0) {
180
181         if(! $count) {
182                 $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) ",
183                         intval($uid),
184                         intval($uid)
185                 );
186
187                 return $r;
188
189
190         }
191
192         $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",
193                 intval($uid),
194                 intval($uid),
195                 intval($start),
196                 intval($count)
197         );
198
199         return $r;
200 }
201