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.
8 function user_remove($uid) {
12 logger('Removing user: ' . $uid);
14 $r = q("select * from user where uid = %d limit 1", intval($uid));
16 call_hooks('remove_user',$r[0]);
18 // save username (actually the nickname as it is guaranteed
19 // unique), so it cannot be re-registered in the future.
21 q("insert into userd ( username ) values ( '%s' )",
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());
53 function contact_remove($id) {
54 q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
57 q("DELETE FROM `item` WHERE `contact-id` = %d ",
60 q("DELETE FROM `photo` WHERE `contact-id` = %d ",
63 q("DELETE FROM `mail` WHERE `contact-id` = %d ",
66 q("DELETE FROM `event` WHERE `cid` = %d ",
69 q("DELETE FROM `queue` WHERE `cid` = %d ",
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.
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'])
91 $expiry = $contact['term-date'] . ' + 32 days ';
92 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
94 // relationship is really truly dead.
96 contact_remove($contact['id']);
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'])
112 if(! function_exists('contact_photo_menu')){
113 function contact_photo_menu($contact) {
124 if($contact['network'] === NETWORK_DFRN) {
126 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
129 $profile_link = $contact['url'];
131 if($profile_link === 'mailbox')
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'];
141 $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
142 $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
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,
154 $args = array('contact' => $contact, 'menu' => $menu);
156 call_hooks('contact_photo_menu', $args);
159 foreach($menu as $k=>$v){
161 if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
162 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
164 $o .= "<li><a href=\"$v\">$k</a></li>\n";
171 function random_profile() {
172 $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
174 return dirname($r[0]['url']);
179 function contacts_not_grouped($uid,$start = 0,$count = 0) {
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) ",
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",