In
function get_blogs_of_user( $id, $all = false ) {
preg_match('/wp_(\d+)_capabilities/', $key, $match);
totally breaks every wpmu which doesn't have wp_ as the DB prefix.
Replace with
preg_match('/'.$wpmuBaseTablePrefix.'(\d+)_capabilities/', $key, $match);