aboutsummaryrefslogtreecommitdiffstats
path: root/include/Contact.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/Contact.php')
-rw-r--r--include/Contact.php93
1 files changed, 74 insertions, 19 deletions
diff --git a/include/Contact.php b/include/Contact.php
index 36f4cbcf7..b9ad1e4cb 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -1,4 +1,4 @@
-<?php
+<?php /** @file */
function abook_connections($channel_id, $sql_conditions = '') {
@@ -43,6 +43,8 @@ function channelx_by_n($id) {
function vcard_from_xchan($xchan, $observer = null, $mode = '') {
+ $a = get_app();
+
$connect = false;
if(local_user()) {
$r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
@@ -53,6 +55,9 @@ function vcard_from_xchan($xchan, $observer = null, $mode = '') {
$connect = t('Connect');
}
+ if(array_key_exists('channel_id',$xchan))
+ $a->profile_uid = $xchan['channel_id'];
+
$url = (($observer)
? z_root() . '/magic?f=&dest=' . $xchan['xchan_url'] . '&addr=' . $xchan['xchan_addr']
: $xchan['xchan_url']
@@ -76,6 +81,9 @@ function abook_toggle_flag($abook,$flag) {
intval($abook['abook_id']),
intval($abook['abook_channel'])
);
+ $a = get_app();
+ if($a->data['abook'])
+ $a->data['abook']['abook_flags'] = $a->data['abook']['abook_flags'] ^ $flag;
return $r;
}
@@ -107,6 +115,49 @@ function user_remove($uid) {
}
+function account_remove($account_id) {
+
+ if(! intval($account_id)) {
+ logger('account_remove: no account.');
+ return false;
+ }
+
+ // Don't let anybody nuke the only admin account.
+
+ $r = q("select account_id from account where (account_roles & %d)",
+ intval(ACCOUNT_ROLE_ADMIN)
+ );
+
+ if($r !== false && count($r) == 1 && $r[0]['account_id'] == $account_id) {
+ logger("Unable to remove the only remaining admin account");
+ return false;
+ }
+
+ $r = q("select * from account where account_id = %d limit 1",
+ intval($account_id)
+ );
+
+ if(! $r) {
+ logger('account_remove: No account with id: ' . $account_id);
+ return false;
+ }
+
+ $x = q("select channel_id from channel where channel_account_id = %d",
+ intval($account_id)
+ );
+ if($x) {
+ foreach($x as $xx) {
+ channel_remove($xx['channel_id']);
+ }
+ }
+
+ $r = q("delete from account where account_id = %d limit 1",
+ intval($account_id)
+ );
+
+ return $r;
+
+}
function channel_remove($channel_id) {
@@ -212,8 +263,6 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) {
}
-
-
function contact_remove($channel_id, $abook_id) {
if((! $channel_id) || (! $abook_id))
@@ -242,31 +291,37 @@ function contact_remove($channel_id, $abook_id) {
if($abook['abook_flags'] & ABOOK_FLAG_SELF)
return false;
- q("delete from item where author_xchan = '%s' and uid = %d",
+
+ $r = q("select * from item where author_xchan = '%s' and uid = %d",
dbesc($abook['abook_xchan']),
intval($channel_id)
);
+ if($r) {
+ foreach($r as $rr) {
+ drop_item($rr,false);
+ }
+ }
- q("delete from abook where abook_id = %d and channel_id = %d limit 1",
+ q("delete from abook where abook_id = %d and abook_channel = %d limit 1",
intval($abook['abook_id']),
intval($channel_id)
);
-/*
-// FIXME
- q("DELETE FROM `photo` WHERE `contact-id` = %d ",
- intval($id)
- );
- q("DELETE FROM `mail` WHERE `contact-id` = %d ",
- intval($id)
+ $r = q("delete from event where event_xchan = '%s' and uid = %d",
+ dbesc($abook['abook_xchan']),
+ intval($channel_id)
);
- q("DELETE FROM `event` WHERE `cid` = %d ",
- intval($id)
+
+ $r = q("delete from group_member where xchan = '%s' and uid = %d",
+ dbesc($abook['abook_xchan']),
+ intval($channel_id)
);
- q("DELETE FROM `queue` WHERE `cid` = %d ",
- intval($id)
+
+ $r = q("delete from mail where ( from_xchan = '%s' or to_xchan = '%s' ) and channel_id = %d ",
+ dbesc($abook['abook_xchan']),
+ dbesc($abook['abook_xchan']),
+ intval($channel_id)
);
-*/
return true;
}
@@ -397,8 +452,8 @@ function contact_photo_menu($contact) {
function random_profile() {
- $r = q("select xchan_url from xchan where xchan_network = 'zot' order by rand() limit 1");
- if($r && count($r))
+ $r = q("select xchan_url from xchan where 1 order by rand() limit 1");
+ if($r)
return $r[0]['xchan_url'];
return '';
}