function channel_remove($channel_id, $local = true, $unset_session = false) { if (!$channel_id) { return; } $a = get_app(); 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, channel_r_stream = 0, channel_r_profile = 0,\n\t\t\tchannel_r_photos = 0, channel_r_abook = 0, channel_w_stream = 0, channel_w_wall = 0, channel_w_tagwall = 0,\n\t\t\tchannel_w_comment = 0, channel_w_mail = 0, channel_w_photos = 0, channel_w_chat = 0, channel_a_delegate = 0,\n\t\t\tchannel_r_storage = 0, channel_w_storage = 0, channel_r_pages = 0, channel_w_pages = 0, channel_a_republish = 0 \n\t\t\twhere channel_id = %d", dbesc(datetime_convert()), 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'])); proc_run('php', 'include/notifier.php', 'purge_all', $channel_id); } 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 `item_id` 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)); q("DELETE FROM `spam` 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); } } proc_run('php', 'include/directory.php', $channel_id); if ($channel_id == local_channel() && $unset_session) { \Zotlabs\Web\Session::nuke(); goaway(z_root()); } }
load_hooks(); call_hooks('init_1'); } App::$language = get_best_language(); load_translation_table(App::$language, App::$install); /** * * Important stuff we always need to do. * * The order of these may be important so use caution if you think they're all * intertwingled with no logical order and decide to sort it out. Some of the * dependencies have changed, but at least at one time in the recent past - the * order was critical to everything working properly * */ \Zotlabs\Web\Session::start(); /** * Language was set earlier, but we can over-ride it in the session. * We have to do it here because the session was just now opened. */ if (array_key_exists('system_language', $_POST)) { if (strlen($_POST['system_language'])) { $_SESSION['language'] = $_POST['system_language']; } else { unset($_SESSION['language']); } } if (x($_SESSION, 'language') && $_SESSION['language'] !== $lang) { App::$language = $_SESSION['language']; load_translation_table(App::$language); }