diff options
Diffstat (limited to 'include/connections.php')
-rw-r--r-- | include/connections.php | 282 |
1 files changed, 35 insertions, 247 deletions
diff --git a/include/connections.php b/include/connections.php index e26943b68..60bce018e 100644 --- a/include/connections.php +++ b/include/connections.php @@ -23,6 +23,7 @@ function abook_store_lowlevel($arr) { 'abook_unconnected' => ((array_key_exists('abook_unconnected',$arr)) ? $arr['abook_unconnected'] : 0), 'abook_self' => ((array_key_exists('abook_self',$arr)) ? $arr['abook_self'] : 0), 'abook_feed' => ((array_key_exists('abook_feed',$arr)) ? $arr['abook_feed'] : 0), + 'abook_not_here' => ((array_key_exists('abook_not_here',$arr)) ? $arr['abook_not_here'] : 0), 'abook_profile' => ((array_key_exists('abook_profile',$arr)) ? $arr['abook_profile'] : ''), 'abook_incl' => ((array_key_exists('abook_incl',$arr)) ? $arr['abook_incl'] : ''), 'abook_excl' => ((array_key_exists('abook_excl',$arr)) ? $arr['abook_excl'] : ''), @@ -114,7 +115,7 @@ function vcard_from_xchan($xchan, $observer = null, $mode = '') { App::$profile_uid = $xchan['channel_id']; $url = (($observer) - ? z_root() . '/magic?f=&dest=' . $xchan['xchan_url'] . '&addr=' . $xchan['xchan_addr'] + ? z_root() . '/magic?f=&owa=1&dest=' . $xchan['xchan_url'] . '&addr=' . $xchan['xchan_addr'] : $xchan['xchan_url'] ); @@ -188,232 +189,6 @@ function abook_toggle_flag($abook,$flag) { } -// Included here for completeness, but this is a very dangerous operation. -// It is the caller's responsibility to confirm the requestor's intent and -// authorisation to do this. - -function user_remove($uid) { - -} - -function account_remove($account_id,$local = true,$unset_session=true) { - - logger('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) > 0", - 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) - ); - $account_email=$r[0]['account_email']; - - 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'],$local,false); - } - } - - $r = q("delete from account where account_id = %d", - intval($account_id) - ); - - - if ($unset_session) { - unset($_SESSION['authenticated']); - unset($_SESSION['uid']); - notice( sprintf(t("User '%s' deleted"),$account_email) . EOL); - goaway(z_root()); - } - return $r; - -} -// recursively delete a directory -function rrmdir($path) -{ - if (is_dir($path) === true) - { - $files = array_diff(scandir($path), array('.', '..')); - - foreach ($files as $file) - { - rrmdir(realpath($path) . '/' . $file); - } - - return rmdir($path); - } - - else if (is_file($path) === true) - { - return unlink($path); - } - - return false; -} - -function channel_remove($channel_id, $local = true, $unset_session=false) { - - if(! $channel_id) - return; - - logger('Removing channel: ' . $channel_id); - logger('channel_remove: local only: ' . intval($local)); - - $r = q("select * from channel where channel_id = %d limit 1", intval($channel_id)); - if(! $r) { - logger('channel_remove: channel not found: ' . $channel_id); - return; - } - - $channel = $r[0]; - - call_hooks('channel_remove',$r[0]); - - if(! $local) { - - $r = q("update channel set channel_deleted = '%s', channel_removed = 1 where channel_id = %d", - dbesc(datetime_convert()), - intval($channel_id) - ); - - q("delete from pconfig where uid = %d", - intval($channel_id) - ); - - logger('deleting hublocs',LOGGER_DEBUG); - - $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", - dbesc($channel['channel_hash']) - ); - - - $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", - dbesc($channel['channel_hash']) - ); - - Zotlabs\Daemon\Master::Summon(array('Notifier','purge_all',$channel_id)); - } - - - $r = q("select * from iconfig left join item on item.id = iconfig.iid - where item.uid = %d", - intval($channel_id) - ); - if($r) { - foreach($r as $rr) { - q("delete from iconfig where iid = %d", - intval($rr['iid']) - ); - } - } - - - q("DELETE FROM groups WHERE uid = %d", intval($channel_id)); - q("DELETE FROM group_member WHERE uid = %d", intval($channel_id)); - q("DELETE FROM event WHERE uid = %d", intval($channel_id)); - q("DELETE FROM item WHERE uid = %d", intval($channel_id)); - q("DELETE FROM mail WHERE channel_id = %d", intval($channel_id)); - q("DELETE FROM notify WHERE uid = %d", intval($channel_id)); - q("DELETE FROM photo WHERE uid = %d", intval($channel_id)); - q("DELETE FROM attach WHERE uid = %d", intval($channel_id)); - q("DELETE FROM profile WHERE uid = %d", intval($channel_id)); - q("DELETE FROM pconfig WHERE uid = %d", intval($channel_id)); - - // @FIXME At this stage we need to remove the file resources located under /store/$nickname - - - q("delete from abook where abook_xchan = '%s' and abook_self = 1 ", - dbesc($channel['channel_hash']) - ); - - $r = q("update channel set channel_deleted = '%s', channel_removed = 1 where channel_id = %d", - dbesc(datetime_convert()), - intval($channel_id) - ); - - // if this was the default channel, set another one as default - if(App::$account['account_default_channel'] == $channel_id) { - $r = q("select channel_id from channel where channel_account_id = %d and channel_removed = 0 limit 1", - intval(App::$account['account_id']), - intval(PAGE_REMOVED)); - if ($r) { - $rr = q("update account set account_default_channel = %d where account_id = %d", - intval($r[0]['channel_id']), - intval(App::$account['account_id'])); - logger("Default channel deleted, changing default to channel_id " . $r[0]['channel_id']); - } - else { - $rr = q("update account set account_default_channel = 0 where account_id = %d", - intval(App::$account['account_id']) - ); - } - } - - logger('deleting hublocs',LOGGER_DEBUG); - - $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s' and hubloc_url = '%s' ", - dbesc($channel['channel_hash']), - dbesc(z_root()) - ); - - // Do we have any valid hublocs remaining? - - $hublocs = 0; - - $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", - dbesc($channel['channel_hash']) - ); - if($r) - $hublocs = count($r); - - if(! $hublocs) { - $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s' ", - dbesc($channel['channel_hash']) - ); - } - - //remove from file system - $r = q("select channel_address from channel where channel_id = %d limit 1", - intval($channel_id) - ); - if($r) - $channel_address = $r[0]['channel_address'] ; - if ($channel_address !== '') { - $f = 'store/' . $channel_address.'/'; - logger ('delete '. $f); - if(is_dir($f)) - @rrmdir($f); - } - - Zotlabs\Daemon\Master::Summon(array('Directory',$channel_id)); - - if($channel_id == local_channel() && $unset_session) { - App::$session->nuke(); - goaway(z_root()); - } - -} /** * mark any hubs "offline" that haven't been heard from in more than 30 days @@ -430,10 +205,10 @@ function mark_orphan_hubsxchans() { if($dirmode == DIRECTORY_MODE_NORMAL) return; - $r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0 + $r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0 and hubloc_network = 'zot' and hubloc_connected < %s - interval %s", - db_utcnow(), db_quoteinterval('36 day') - ); + db_utcnow(), db_quoteinterval('36 day') + ); // $realm = get_directory_realm(); // if($realm == DIRECTORY_REALM) { @@ -547,13 +322,13 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) { // directory servers need to keep the record around for sync purposes - mark it deleted - $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", - dbesc($xchan) - ); + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", + dbesc($xchan) + ); - $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", - dbesc($xchan) - ); + $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", + dbesc($xchan) + ); } } } @@ -566,6 +341,11 @@ function contact_remove($channel_id, $abook_id) { logger('removing contact ' . $abook_id . ' for channel ' . $channel_id,LOGGER_DEBUG); + + $x = [ 'channel_id' => $channel_id, 'abook_id' => $abook_id ]; + call_hooks('connection_remove',$x); + + $archive = get_pconfig($channel_id, 'system','archive_removed_contacts'); if($archive) { q("update abook set abook_archived = 1 where abook_id = %d and abook_channel = %d", @@ -589,7 +369,8 @@ function contact_remove($channel_id, $abook_id) { return false; - $r = q("select * from item where author_xchan = '%s' and uid = %d", + $r = q("select * from item where (owner_xchan = '%s' or author_xchan = '%s') and uid = %d", + dbesc($abook['abook_xchan']), dbesc($abook['abook_xchan']), intval($channel_id) ); @@ -640,9 +421,9 @@ function random_profile() { for($i = 0; $i < $retryrandom; $i++) { - $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_addr not like '%s' and xchan_hidden = 0 and hubloc_connected > %s - interval %s order by $randfunc limit 1", - dbesc('sys@%'), - db_utcnow(), db_quoteinterval('30 day') + $r = q("select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_hidden = 0 and xchan_system = 0 and hubloc_connected > %s - interval %s order by $randfunc limit 1", + db_utcnow(), + db_quoteinterval('30 day') ); if(!$r) return ''; // Couldn't get a random channel @@ -650,12 +431,12 @@ function random_profile() { if($checkrandom) { $x = z_fetch_url($r[0]['xchan_url']); if($x['success']) - return $r[0]['xchan_url']; + return $r[0]['xchan_hash']; else logger('Random channel turned out to be bad.'); } else { - return $r[0]['xchan_url']; + return $r[0]['xchan_hash']; } } @@ -849,13 +630,20 @@ function get_vcard_array($vc,$id) { if($vc->ADR) { foreach($vc->ADR as $adr) { $type = (($adr['TYPE']) ? vcard_translate_type((string)$adr['TYPE']) : ''); - $adrs[] = [ + $entry = [ 'type' => $type, 'address' => $adr->getParts() ]; - $last_entry = end($adrs); - if($adrs[$last_entry]['address']) - array_walk($adrs[$last_entry]['address'],'array_escape_tags'); + + if(is_array($entry['address'])) { + array_walk($entry['address'],'array_escape_tags'); + } + else { + $entry['address'] = (string) escape_tags($entry['address']); + } + + $adrs[] = $entry; + } } @@ -937,4 +725,4 @@ function vcard_query(&$r) { } } } -}
\ No newline at end of file +} |