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 // sends an unfriend message. Does not remove the contact
78 function terminate_friendship($user,$self,$contact) {
83 require_once('include/datetime.php');
85 if($contact['network'] === NETWORK_OSTATUS) {
87 $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
88 '$name' => $user['username'],
89 '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
90 '$photo' => $self['photo'],
91 '$thumb' => $self['thumb'],
92 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
93 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
96 '$content' => t('stopped following'),
97 '$nick' => $user['nickname'],
98 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
99 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
102 if((x($contact,'notify')) && (strlen($contact['notify']))) {
103 require_once('include/salmon.php');
104 slapper($user,$contact['notify'],$slap);
107 elseif($contact['network'] === NETWORK_DIASPORA) {
108 require_once('include/diaspora.php');
109 diaspora_unshare($user,$contact);
111 elseif($contact['network'] === NETWORK_DFRN) {
112 require_once('include/items.php');
113 dfrn_deliver($user,$contact,'placeholder', 1);
119 // Contact has refused to recognise us as a friend. We will start a countdown.
120 // If they still don't recognise us in 32 days, the relationship is over,
121 // and we won't waste any more time trying to communicate with them.
122 // This provides for the possibility that their database is temporarily messed
123 // up or some other transient event and that there's a possibility we could recover from it.
125 if(! function_exists('mark_for_death')) {
126 function mark_for_death($contact) {
127 if($contact['term-date'] == '0000-00-00 00:00:00') {
128 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
129 dbesc(datetime_convert()),
130 intval($contact['id'])
134 $expiry = $contact['term-date'] . ' + 32 days ';
135 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
137 // relationship is really truly dead.
139 contact_remove($contact['id']);
146 if(! function_exists('unmark_for_death')) {
147 function unmark_for_death($contact) {
148 // It's a miracle. Our dead contact has inexplicably come back to life.
149 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
150 dbesc('0000-00-00 00:00:00'),
151 intval($contact['id'])
155 if(! function_exists('contact_photo_menu')){
156 function contact_photo_menu($contact) {
167 if($contact['network'] === NETWORK_DFRN) {
169 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
172 $profile_link = $contact['url'];
174 if($profile_link === 'mailbox')
178 $status_link = $profile_link . "?url=status";
179 $photos_link = $profile_link . "?url=photos";
180 $profile_link = $profile_link . "?url=profile";
181 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
184 $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
185 $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
188 t("View Status") => $status_link,
189 t("View Profile") => $profile_link,
190 t("View Photos") => $photos_link,
191 t("Network Posts") => $posts_link,
192 t("Edit Contact") => $contact_url,
193 t("Send PM") => $pm_url,
197 $args = array('contact' => $contact, 'menu' => $menu);
199 call_hooks('contact_photo_menu', $args);
202 foreach($menu as $k=>$v){
204 if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
205 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
207 $o .= "<li><a href=\"$v\">$k</a></li>\n";
214 function random_profile() {
215 $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
217 return dirname($r[0]['url']);
222 function contacts_not_grouped($uid,$start = 0,$count = 0) {
225 $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) ",
235 $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",