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) {
55 $r = q("select uid from contact where id = %d limit 1",
58 if((! count($r)) || (! intval($r[0]['uid'])))
61 $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
63 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d limit 1",
69 q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
72 q("DELETE FROM `item` WHERE `contact-id` = %d ",
75 q("DELETE FROM `photo` WHERE `contact-id` = %d ",
78 q("DELETE FROM `mail` WHERE `contact-id` = %d ",
81 q("DELETE FROM `event` WHERE `cid` = %d ",
84 q("DELETE FROM `queue` WHERE `cid` = %d ",
91 // sends an unfriend message. Does not remove the contact
93 function terminate_friendship($user,$self,$contact) {
98 require_once('include/datetime.php');
100 if($contact['network'] === NETWORK_OSTATUS) {
102 $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
103 '$name' => $user['username'],
104 '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
105 '$photo' => $self['photo'],
106 '$thumb' => $self['thumb'],
107 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
108 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
111 '$content' => t('stopped following'),
112 '$nick' => $user['nickname'],
113 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
114 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
117 if((x($contact,'notify')) && (strlen($contact['notify']))) {
118 require_once('include/salmon.php');
119 slapper($user,$contact['notify'],$slap);
122 elseif($contact['network'] === NETWORK_DIASPORA) {
123 require_once('include/diaspora.php');
124 diaspora_unshare($user,$contact);
126 elseif($contact['network'] === NETWORK_DFRN) {
127 require_once('include/items.php');
128 dfrn_deliver($user,$contact,'placeholder', 1);
134 // Contact has refused to recognise us as a friend. We will start a countdown.
135 // If they still don't recognise us in 32 days, the relationship is over,
136 // and we won't waste any more time trying to communicate with them.
137 // This provides for the possibility that their database is temporarily messed
138 // up or some other transient event and that there's a possibility we could recover from it.
140 if(! function_exists('mark_for_death')) {
141 function mark_for_death($contact) {
143 if($contact['archive'])
146 if($contact['term-date'] == '0000-00-00 00:00:00') {
147 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
148 dbesc(datetime_convert()),
149 intval($contact['id'])
154 // TODO: We really should send a notification to the owner after 2-3 weeks
155 // so they won't be surprised when the contact vanishes and can take
156 // remedial action if this was a serious mistake or glitch
158 $expiry = $contact['term-date'] . ' + 32 days ';
159 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
161 // relationship is really truly dead.
162 // archive them rather than delete
163 // though if the owner tries to unarchive them we'll start the whole process over again
165 q("update contact set `archive` = 1 where id = %d limit 1",
166 intval($contact['id'])
169 //contact_remove($contact['id']);
176 if(! function_exists('unmark_for_death')) {
177 function unmark_for_death($contact) {
178 // It's a miracle. Our dead contact has inexplicably come back to life.
179 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
180 dbesc('0000-00-00 00:00:00'),
181 intval($contact['id'])
185 if(! function_exists('contact_photo_menu')){
186 function contact_photo_menu($contact) {
197 if($contact['network'] === NETWORK_DFRN) {
199 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
202 $profile_link = $contact['url'];
204 if($profile_link === 'mailbox')
208 $status_link = $profile_link . "?url=status";
209 $photos_link = $profile_link . "?url=photos";
210 $profile_link = $profile_link . "?url=profile";
211 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
214 $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
215 $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
218 t("View Status") => $status_link,
219 t("View Profile") => $profile_link,
220 t("View Photos") => $photos_link,
221 t("Network Posts") => $posts_link,
222 t("Edit Contact") => $contact_url,
223 t("Send PM") => $pm_url,
227 $args = array('contact' => $contact, 'menu' => &$menu);
229 call_hooks('contact_photo_menu', $args);
232 foreach($menu as $k=>$v){
234 if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
235 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
237 $o .= "<li><a href=\"$v\">$k</a></li>\n";
244 function random_profile() {
245 $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
247 return dirname($r[0]['url']);
252 function contacts_not_grouped($uid,$start = 0,$count = 0) {
255 $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) ",
265 $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",