diff options
Diffstat (limited to 'include/channel.php')
-rw-r--r-- | include/channel.php | 366 |
1 files changed, 168 insertions, 198 deletions
diff --git a/include/channel.php b/include/channel.php index 71fad5222..2db0434ca 100644 --- a/include/channel.php +++ b/include/channel.php @@ -9,13 +9,13 @@ use Zotlabs\Access\PermissionRoles; use Zotlabs\Access\PermissionLimits; use Zotlabs\Access\Permissions; use Zotlabs\Daemon\Master; +use Zotlabs\Lib\Crypto; use Zotlabs\Lib\System; use Zotlabs\Render\Comanche; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Connect; use Zotlabs\Lib\Libsync; -require_once('include/zot.php'); require_once('include/crypto.php'); require_once('include/menu.php'); require_once('include/perm_upgrade.php'); @@ -107,7 +107,7 @@ function create_sys_channel() { if ((! get_config('system', 'pubkey')) && (! get_config('system', 'prvkey'))) { require_once('include/crypto.php'); - $hostkey = new_keypair(4096); + $hostkey = Crypto::new_keypair(4096); set_config('system', 'pubkey', $hostkey['pubkey']); set_config('system', 'prvkey', $hostkey['prvkey']); } @@ -232,11 +232,7 @@ function create_identity($arr) { } $guid = Libzot::new_uid($nick); - $key = new_keypair(4096); - - // legacy zot - $zsig = base64url_encode(rsa_sign($guid,$key['prvkey'])); - $zhash = make_xchan_hash($guid,$zsig); + $key = Crypto::new_keypair(4096); // zot6 $sig = Libzot::sign($guid,$key['prvkey']); @@ -274,7 +270,7 @@ function create_identity($arr) { 'channel_guid' => $guid, 'channel_guid_sig' => $sig, 'channel_hash' => $hash, - 'channel_portable_id' => $zhash, + 'channel_portable_id' => '', 'channel_prvkey' => $key['prvkey'], 'channel_pubkey' => $key['pubkey'], 'channel_pageflags' => intval($pageflags), @@ -302,8 +298,8 @@ function create_identity($arr) { $photo_type = null; $z = [ - 'account' => $a[0], - 'channel' => $r[0], + 'account' => $a[0] ?? [], + 'channel' => $r[0] ?? [], 'photo_url' => '' ]; /** @@ -339,26 +335,6 @@ function create_identity($arr) { $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $guid, - 'hubloc_guid_sig' => $zsig, - 'hubloc_hash' => $zhash, - 'hubloc_id_url' => channel_url($ret['channel']), - 'hubloc_addr' => channel_reddress($ret['channel']), - 'hubloc_primary' => intval($primary), - 'hubloc_url' => z_root(), - 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey'])), - 'hubloc_host' => App::get_hostname(), - 'hubloc_callback' => z_root() . '/post', - 'hubloc_sitekey' => get_config('system','pubkey'), - 'hubloc_network' => 'zot', - 'hubloc_updated' => datetime_convert() - ] - ); - if(! $r) - logger('Unable to store hub location (zot)'); - - $r = hubloc_store_lowlevel( - [ - 'hubloc_guid' => $guid, 'hubloc_guid_sig' => $sig, 'hubloc_hash' => $hash, 'hubloc_id_url' => channel_url($ret['channel']), @@ -382,30 +358,6 @@ function create_identity($arr) { $r = xchan_store_lowlevel( [ - 'xchan_hash' => $zhash, - 'xchan_guid' => $guid, - 'xchan_guid_sig' => $zsig, - 'xchan_pubkey' => $key['pubkey'], - 'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'), - 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}", - 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}", - 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}", - 'xchan_addr' => channel_reddress($ret['channel']), - 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'], - 'xchan_follow' => z_root() . '/follow?f=&url=%s', - 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'], - 'xchan_name' => $ret['channel']['channel_name'], - 'xchan_network' => 'zot', - 'xchan_photo_date' => datetime_convert(), - 'xchan_name_date' => datetime_convert(), - 'xchan_system' => $system - ] - ); - if(! $r) - logger('Unable to store xchan (zot)'); - - $r = xchan_store_lowlevel( - [ 'xchan_hash' => $hash, 'xchan_guid' => $guid, 'xchan_guid_sig' => $sig, @@ -502,23 +454,22 @@ function create_identity($arr) { // right away as a default group for new contacts. require_once('include/group.php'); - group_add($newuid, t('Friends')); - group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']); + $group_hash = group_add($newuid, t('Friends')); - // if our role_permissions indicate that we're using a default collection ACL, add it. + if($group_hash) { + group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']); - if(is_array($role_permissions) && $role_permissions['default_collection']) { - $r = q("select hash from pgrp where uid = %d and gname = '%s' limit 1", - intval($newuid), - dbesc( t('Friends') ) - ); - if($r) { - q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d", - dbesc($r[0]['hash']), - dbesc('<' . $r[0]['hash'] . '>'), - intval($newuid) - ); + $default_collection_str = ''; + // if our role_permissions indicate that we're using a default collection ACL, add it. + if(is_array($role_permissions) && $role_permissions['default_collection']) { + $default_collection_str = '<' . $group_hash . '>'; } + + q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d", + dbesc($group_hash), + dbesc($default_collection_str), + intval($newuid) + ); } if(! $system) { @@ -603,9 +554,9 @@ function change_channel_keys($channel) { $stored = []; - $key = new_keypair(4096); + $key = Crypto::new_keypair(4096); - $sig = base64url_encode(rsa_sign($channel['channel_guid'],$key['prvkey'])); + $sig = base64url_encode(Crypto::sign($channel['channel_guid'],$key['prvkey'])); $hash = make_xchan_hash($channel['channel_guid'],$sig); $stored['old_guid'] = $channel['channel_guid']; @@ -614,7 +565,7 @@ function change_channel_keys($channel) { $stored['old_hash'] = $channel['channel_hash']; $stored['new_key'] = $key['pubkey']; - $stored['new_sig'] = base64url_encode(rsa_sign($key['pubkey'],$channel['channel_prvkey'])); + $stored['new_sig'] = base64url_encode(Crypto::sign($key['pubkey'],$channel['channel_prvkey'])); // Save this info for the notifier to collect @@ -651,7 +602,7 @@ function change_channel_keys($channel) { foreach($h as $hv) { $hv['hubloc_guid_sig'] = $sig; $hv['hubloc_hash'] = $hash; - $hv['hubloc_url_sig'] = base64url_encode(rsa_sign(z_root(),$modifed['channel_prvkey'])); + $hv['hubloc_url_sig'] = base64url_encode(Crypto::sign(z_root(),$modified['channel_prvkey'])); hubloc_store_lowlevel($hv); } } @@ -819,7 +770,6 @@ function get_default_export_sections() { 'chatrooms', 'events', 'webpages', - 'mail', 'wikis' ]; @@ -852,7 +802,6 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals /* * basic channel export */ - if(! $sections) { $sections = get_default_export_sections(); } @@ -890,20 +839,27 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals unset($ret['channel']['channel_salt']); } if ($zap_compat) { - $channel['channel_guid_sig'] = 'sha256.' . $channel['channel_guid_sig']; - $channel['channel_hash'] = $channel['channel_portable_id']; - unset($channel['channel_portable_id']); + unset($ret['channel']['channel_portable_id']); } - - } if(in_array('channel',$sections) || in_array('profile',$sections)) { $r = q("select * from profile where uid = %d", intval($channel_id) ); - if($r) + if($r) { $ret['profile'] = $r; + if ($zap_compat) { + // zap only supports one profile + foreach ($r as $rv) { + if ($rv['is_default']) { + $ret['profile'] = [ $rv ]; + break; + } + } + } + } + $r = q("select mimetype, content, os_storage from photo where imgscale = 4 and photo_usage = %d and uid = %d limit 1", @@ -915,7 +871,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals $ret['photo'] = [ 'type' => $r[0]['mimetype'], 'data' => (($r[0]['os_storage']) - ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode(dbunescbin($r[0]['content']))) + ? base64url_encode(file_get_contents(dbunescbin($r[0]['content']))) : base64url_encode(dbunescbin($r[0]['content']))) ]; } } @@ -929,55 +885,60 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals $ret['abook'] = $r; for($x = 0; $x < count($ret['abook']); $x ++) { - + $xchans[] = $ret['abook'][$x]['abook_xchan']; $my_perms = []; $their_perms = []; $newconfig = []; $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']); - if($abconfig) { - foreach ($abconfig as $abc) { - if ($abc['cat'] === 'my_perms' && intval($abc['v'])) { - $my_perms[] = $abc['k']; - continue; - } - if ($abc['cat'] === 'their_perms' && intval($abc['v'])) { - $their_perms[] = $abc['k']; - continue; - } - if ($zap_compat && preg_match('|^a:[0-9]+:{.*}$|s', $abc['v'])) { - $abc['v'] = serialise(unserialize($abc['v'])); + if($abconfig) { + if ($zap_compat) { + foreach ($abconfig as $abc) { + + if ($abc['cat'] === 'my_perms') { + if (intval($abc['v'])) { + $my_perms[] = $abc['k']; + } + continue; + } + if ($abc['cat'] === 'their_perms') { + if (intval($abc['v'])) { + $their_perms[] = $abc['k']; + } + continue; + } + if (preg_match('|^a:[0-9]+:{.*}$|s', $abc['v'])) { + $abc['v'] = serialise(unserialize($abc['v'])); + } + $newconfig[] = $abc; } - $newconfig[] = $abc; + + $ret['abook'][$x]['abconfig'] = $newconfig; + + $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_xchan'], 'cat' => 'system', 'k' => 'my_perms', 'v' => implode(',',$my_perms) ]; + $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_xchan'], 'cat' => 'system', 'k' => 'their_perms', 'v' => implode(',',$their_perms) ]; + + } + else { + $ret['abook'][$x]['abconfig'] = $abconfig; } - - $ret['abook'][$x]['abconfig'] = $newconfig; - if ($zap_compat) { - $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_chan'], 'cat' => 'system', 'k' => 'my_perms', 'v' => implode(',',$my_perms) ]; - $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_chan'], 'cat' => 'system', 'k' => 'their_perms', 'v' => implode(',',$their_perms) ]; - } } + translate_abook_perms_outbound($ret['abook'][$x]); - - } - // pick up the zot6 xchan and hublocs also - - if($ret['channel']['channel_portable_id']) { - $xchans[] = $ret['channel']['channel_portable_id']; } - + stringify_array_elms($xchans); } if($xchans) { - $r = q("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) "); + $r = dbq("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) "); if($r) $ret['xchan'] = $r; - $r = q("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) "); + $r = dbq("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) "); if($r) $ret['hubloc'] = $r; } @@ -1076,13 +1037,24 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals } if(in_array('events',$sections)) { - $r = q("select * from event where uid = %d", + + // @fixme - Not totally certain how to handle $zot_compat for the event timezone which exists + // in Hubzilla but is stored with the item and not the event. In Zap, stored information is + // always UTC and localised on access as per standard conventions for working with global time data. + + // Older Zot (pre-Zot6) records aren't translated correctly w/r/t AS2 so only include events for the last year or so if + // migrating to Zap. + + $sqle = (($zap_compat) ? " and created > '2020-01-01 00:00:00' " : ''); + + $r = q("select * from event where uid = %d $sqle", intval($channel_id) ); - if($r) + if ($r) { $ret['event'] = $r; + } - $r = q("select * from item where resource_type = 'event' and uid = %d", + $r = q("select * from item where resource_type = 'event' and uid = %d $sqle", intval($channel_id) ); if($r) { @@ -1090,7 +1062,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['event_item'][] = encode_item($rr,true); + $ret['event_item'][] = encode_item($rr,true, $zap_compat); } } @@ -1113,31 +1085,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['webpages'][] = encode_item($rr,true); - } - } - - if(in_array('mail',$sections)) { - $r = q("select * from conv where uid = %d", - intval($channel_id) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject'])); - } - $ret['conv'] = $r; - } - - $r = q("select * from mail where channel_id = %d", - intval($channel_id) - ); - if($r) { - $m = array(); - foreach($r as $rr) { - xchan_mail_query($rr); - $m[] = encode_mail($rr,true); - } - $ret['mail'] = $m; + $ret['webpages'][] = encode_item($rr,true, $zap_compat); } } @@ -1150,7 +1098,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rv) { - $ret['wiki'][] = encode_item($rv,true); + $ret['wiki'][] = encode_item($rv,true, $zap_compat); } } } @@ -1168,14 +1116,14 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals and created > %s - INTERVAL %s and resource_type = '' order by created", intval($channel_id), db_utcnow(), - db_quoteinterval('3 MONTH') + db_quoteinterval('1 MONTH') ); if($r) { $ret['item'] = array(); xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['item'][] = encode_item($rr,true); + $ret['item'][] = encode_item($rr,true, $zap_compat); } } @@ -1208,7 +1156,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals * * \e array \b relocate - (optional) * * \e array \b item - array with items encoded_item() */ -function identity_export_year($channel_id, $year, $month = 0) { +function identity_export_year($channel_id, $year, $month = 0, $zap_compat = false) { if(! $year) return array(); @@ -1226,7 +1174,7 @@ function identity_export_year($channel_id, $year, $month = 0) { else $maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00'); - return channel_export_items_date($channel_id,$mindate,$maxdate); + return channel_export_items_date($channel_id,$mindate,$maxdate, $zap_compat); } @@ -1241,7 +1189,7 @@ function identity_export_year($channel_id, $year, $month = 0) { * @return array */ -function channel_export_items_date($channel_id, $start, $finish) { +function channel_export_items_date($channel_id, $start, $finish, $zap_compat = false) { if(! $start) return array(); @@ -1259,6 +1207,11 @@ function channel_export_items_date($channel_id, $start, $finish) { $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } + if ($zap_compat) { + $ret['compatibility']['codebase'] = 'zap'; + } + + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type != 'photo' order by created", intval(ITEM_TYPE_POST), intval($channel_id), @@ -1271,7 +1224,7 @@ function channel_export_items_date($channel_id, $start, $finish) { xchan_query($r); $r = fetch_post_tags($r, true); foreach($r as $rr) - $ret['item'][] = encode_item($rr, true); + $ret['item'][] = encode_item($rr, true, $zap_compat); } return $ret; @@ -1285,11 +1238,11 @@ function channel_export_items_date($channel_id, $start, $finish) { * * @param int $channel_id The channel ID * @param int $page - * @param int $limit (default 50) + * @param int $limit (default 10) * @return array */ -function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50) { +function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 10, $zap_compat = false) { if(intval($page) < 1) { $page = 0; @@ -1299,8 +1252,8 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim $limit = 1; } - if(intval($limit) > 5000) { - $limit = 5000; + if(intval($limit) > 1000) { + $limit = 1000; } if(! $start) @@ -1321,6 +1274,22 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } + if ($zap_compat) { + $ret['compatibility']['codebase'] = 'zap'; + } + + $r = q("select count(id) as total from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type != 'photo' and created >= '%s' and created <= '%s'", + intval(ITEM_TYPE_POST), + intval($channel_id), + dbesc($start), + dbesc($finish) + ); + + if ($r) { + $ret['items_total']= $r[0]['total']; + $ret['items_page']= $limit; + } + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type != 'photo' and created >= '%s' and created <= '%s' order by created limit %d offset %d", intval(ITEM_TYPE_POST), intval($channel_id), @@ -1335,7 +1304,7 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim xchan_query($r); $r = fetch_post_tags($r, true); foreach($r as $rr) - $ret['item'][] = encode_item($rr, true); + $ret['item'][] = encode_item($rr, true, $zap_compat); } return $ret; @@ -1368,7 +1337,7 @@ function profile_load($nickname, $profile = '') { if(! $user) { logger('profile error: ' . App::$query_string, LOGGER_DEBUG); - notice( t('Requested channel is not available.') . EOL ); + notice( t('Requested channel is not available') . EOL ); App::$error = 404; return; } @@ -1477,8 +1446,11 @@ function profile_load($nickname, $profile = '') { if($p[0]['keywords']) { $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$p[0]['keywords']); - if(strlen($keywords) && $can_view_profile) + if(strlen($keywords) && $can_view_profile) { + if(! isset(App::$page['htmlhead'])) + App::$page['htmlhead'] = ''; App::$page['htmlhead'] .= '<meta name="keywords" content="' . htmlentities($keywords,ENT_COMPAT,'UTF-8') . '" />' . "\r\n" ; + } } App::$profile = $p[0]; @@ -1801,7 +1773,7 @@ function advanced_profile() { $profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s')); } - if(App::$profile['keywords']) { + if(App::$profile['keywords']) { $keywords = str_replace(',',' ', App::$profile['keywords']); $keywords = str_replace(' ',' ', $keywords); $karr = explode(' ', $keywords); @@ -2483,23 +2455,23 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) { * - array with channel entry * - false if no channel with $nick was found */ -function channelx_by_nick($nick) { +function channelx_by_nick($nick, $removed = false) { // If we are provided a Unicode nickname convert to IDN $nick = punify($nick); - // return a cached copy if there is a cached copy and it's a match + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_address',App::$channel) && App::$channel['channel_address'] === $nick) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' $sql_extra LIMIT 1", dbesc($nick) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** @@ -2508,17 +2480,19 @@ function channelx_by_nick($nick) { * @param string $hash * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_hash($hash) { +function channelx_by_hash($hash, $removed = false) { - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_hash',App::$channel) && App::$channel['channel_hash'] === $hash) { - return App::$channel; + $sql_extra = ' AND channel_removed = 0 '; + + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' $sql_extra LIMIT 1", dbesc($hash) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } @@ -2528,17 +2502,19 @@ function channelx_by_hash($hash) { * @param string $hash * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_portid($hash) { +function channelx_by_portid($hash, $removed = false) { + + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_portable_id',App::$channel) && intval(App::$channel['channel_portable_id']) === intval($hash)) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_portable_id = xchan_hash WHERE channel_portable_id = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_portable_id = xchan_hash WHERE channel_portable_id = '%s' $sql_extra LIMIT 1", dbesc($hash) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** @@ -2547,17 +2523,19 @@ function channelx_by_portid($hash) { * @param int $id A channel ID * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_n($id) { +function channelx_by_n($id, $removed = false) { + + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_id',App::$channel) && intval(App::$channel['channel_id']) === intval($id)) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", - dbesc($id) + $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d $sql_extra LIMIT 1", + intval($id) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** @@ -2802,15 +2780,12 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { logger('deleting hublocs',LOGGER_DEBUG); - $r = q("UPDATE hubloc SET hubloc_deleted = 1 WHERE hubloc_hash = '%s' OR hubloc_hash = '%s'", - dbesc($channel['channel_hash']), - dbesc($channel['channel_portable_id']) - + $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' OR xchan_hash = '%s'", - dbesc($channel['channel_hash']), - dbesc($channel['channel_portable_id']) + $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s'", + dbesc($channel['channel_hash']) ); Master::Summon(array('Notifier','purge_all',$channel_id)); @@ -2837,7 +2812,6 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { q("DELETE FROM pgrp WHERE uid = %d", intval($channel_id)); q("DELETE FROM pgrp_member WHERE uid = %d", intval($channel_id)); q("DELETE FROM event WHERE uid = %d", intval($channel_id)); - q("DELETE FROM mail WHERE channel_id = %d", intval($channel_id)); q("DELETE FROM menu WHERE menu_channel_id = %d", intval($channel_id)); q("DELETE FROM menu_item WHERE mitem_channel_id = %d", intval($channel_id)); @@ -2856,13 +2830,6 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { attach_delete($channel_id,$rv['hash']); } } - - $r = q("select id from item where uid = %d", intval($channel_id)); - if($r) { - foreach($r as $rv) { - drop_item($rv['id'],false); - } - } q("delete from abook where abook_xchan = '%s' and abook_self = 1 ", dbesc($channel['channel_hash']) @@ -2873,6 +2840,9 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { intval($channel_id) ); + // remove items + Master::Summon([ 'Channel_purge', $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", @@ -2894,9 +2864,8 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { logger('deleting hublocs',LOGGER_DEBUG); - $r = q("UPDATE hubloc SET hubloc_deleted = 1 WHERE (hubloc_hash = '%s' OR hubloc_hash = '%s') AND hubloc_url = '%s' ", + $r = q("UPDATE hubloc SET hubloc_deleted = 1 WHERE hubloc_hash = '%s' AND hubloc_url = '%s' ", dbesc($channel['channel_hash']), - dbesc($channel['channel_portable_id']), dbesc(z_root()) ); @@ -2911,10 +2880,11 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { $hublocs = count($r); if(! $hublocs) { - $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s' OR xchan_hash = '%s'", - dbesc($channel['channel_hash']), - dbesc($channel['channel_portable_id']) + $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s'", + dbesc($channel['channel_hash']) ); + // send a cleanup message to other servers + Master::Summon([ 'Notifier', 'purge_all', $channel_id ]); } //remove from file system @@ -2939,7 +2909,7 @@ function channel_remove_final($channel_id) { q("delete from abook where abook_channel = %d", intval($channel_id)); q("delete from abconfig where chan = %d", intval($channel_id)); q("delete from pconfig where uid = %d", intval($channel_id)); - + } @@ -2999,7 +2969,7 @@ function anon_identity_init($reqvars) { } if(! validate_email($anon_email)) { - logger('enonymous email not valid'); + logger('anonymous email not valid'); return false; } |