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 // 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());
57 function contact_remove($id) {
59 $r = q("select uid from contact where id = %d limit 1",
62 if((! count($r)) || (! intval($r[0]['uid'])))
65 $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
67 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d",
73 q("DELETE FROM `contact` WHERE `id` = %d",
76 q("DELETE FROM `item` WHERE `contact-id` = %d ",
79 q("DELETE FROM `photo` WHERE `contact-id` = %d ",
82 q("DELETE FROM `mail` WHERE `contact-id` = %d ",
85 q("DELETE FROM `event` WHERE `cid` = %d ",
88 q("DELETE FROM `queue` WHERE `cid` = %d ",
95 // sends an unfriend message. Does not remove the contact
97 function terminate_friendship($user,$self,$contact) {
102 require_once('include/datetime.php');
104 if($contact['network'] === NETWORK_OSTATUS) {
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(),
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"
121 if((x($contact,'notify')) && (strlen($contact['notify']))) {
122 require_once('include/salmon.php');
123 slapper($user,$contact['notify'],$slap);
126 elseif($contact['network'] === NETWORK_DIASPORA) {
127 require_once('include/diaspora.php');
128 diaspora_unshare($user,$contact);
130 elseif($contact['network'] === NETWORK_DFRN) {
131 require_once('include/items.php');
132 dfrn_deliver($user,$contact,'placeholder', 1);
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.
144 if(! function_exists('mark_for_death')) {
145 function mark_for_death($contact) {
147 if($contact['archive'])
150 if($contact['term-date'] == '0000-00-00 00:00:00') {
151 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
152 dbesc(datetime_convert()),
153 intval($contact['id'])
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
162 $expiry = $contact['term-date'] . ' + 32 days ';
163 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
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
169 q("update contact set `archive` = 1 where id = %d",
170 intval($contact['id'])
172 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact['id']), intval($contact['uid']));
174 //contact_remove($contact['id']);
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",
185 dbesc('0000-00-00 00:00:00'),
186 intval($contact['id'])
190 if(! function_exists('contact_photo_menu')){
191 function contact_photo_menu($contact) {
200 $contact_drop_link = "";
204 if($contact['network'] === NETWORK_DFRN) {
206 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
209 $profile_link = $contact['url'];
211 if($profile_link === 'mailbox')
215 $status_link = $profile_link . "?url=status";
216 $photos_link = $profile_link . "?url=photos";
217 $profile_link = $profile_link . "?url=profile";
218 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
221 $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id'];
222 $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
223 $posts_link = $a->get_baseurl() . '/network/0?nets=all&cid=' . $contact['id'];
224 $contact_drop_link = $a->get_baseurl() . "/contacts/" . $contact['id'] . '/drop?confirm=1';
228 'poke' => array(t("Poke"), $poke_link),
229 'status' => array(t("View Status"), $status_link),
230 'profile' => array(t("View Profile"), $profile_link),
231 'photos' => array(t("View Photos"), $photos_link),
232 'network' => array(t("Network Posts"), $posts_link),
233 'edit' => array(t("Edit Contact"), $contact_url),
234 'drop' => array(t("Drop Contact"), $contact_drop_link),
235 'pm' => array(t("Send PM"), $pm_url),
239 $args = array('contact' => $contact, 'menu' => &$menu);
241 call_hooks('contact_photo_menu', $args);
244 foreach($menu as $k=>$v){
246 if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
247 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
249 $o .= "<li><a href=\"$v\">$k</a></li>\n";
253 foreach($menu as $k=>$v){
255 if(($v[0] !== t("Network Posts")) && ($v[0] !== t("Send PM")) && ($v[0] !== t('Edit Contact')))
265 function random_profile() {
266 $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
268 return dirname($r[0]['url']);
273 function contacts_not_grouped($uid,$start = 0,$count = 0) {
276 $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) ",
286 $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",
296 function get_contact($url, $uid = 0) {
297 require_once("include/Scrape.php");
302 // is it an address in the format user@server.tld?
303 if (!strstr($url, "http") OR strstr($url, "@")) {
304 $data = probe_url($url);
310 $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
311 dbesc(normalise_link($url)),
315 $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d",
317 dbesc(normalise_link($url)),
321 $contactid = $contact[0]["id"];
323 // Update the contact every 7 days
324 $update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -7 days'));
325 //$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
332 $data = probe_url($url);
334 // Does this address belongs to a valid network?
335 if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
338 // tempory programming. Can be deleted after 2015-02-07
339 if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
340 $data["alias"] = normalise_link($url);
342 if ($contactid == 0) {
343 q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
344 `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
345 `batch`, `request`, `confirm`, `poco`,
346 `writable`, `blocked`, `readonly`, `pending`)
347 VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
349 dbesc(datetime_convert()),
351 dbesc(normalise_link($data["url"])),
352 dbesc($data["addr"]),
353 dbesc($data["alias"]),
354 dbesc($data["notify"]),
355 dbesc($data["poll"]),
356 dbesc($data["name"]),
357 dbesc($data["nick"]),
358 dbesc($data["photo"]),
359 dbesc($data["network"]),
360 dbesc($data["pubkey"]),
361 intval(CONTACT_IS_SHARING),
362 intval($data["priority"]),
363 dbesc($data["batch"]),
364 dbesc($data["request"]),
365 dbesc($data["confirm"]),
369 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
370 dbesc(normalise_link($data["url"])),
375 $contactid = $contact[0]["id"];
378 require_once("Photo.php");
380 $photos = import_profile_photo($data["photo"],$uid,$contactid);
382 q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s',
383 `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
384 `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
388 dbesc($data["addr"]),
389 dbesc($data["alias"]),
390 dbesc($data["name"]),
391 dbesc($data["nick"]),
392 dbesc(datetime_convert()),
393 dbesc(datetime_convert()),
394 dbesc(datetime_convert()),