$nonce = wp_create_nonce('cctm_download_definition');
        $save_me = CCTM_ImportExport::get_payload_from_data(CCTM::$data);
        $save_me = json_encode($save_me);
        $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', sprintf(__('Your Custom Content Type definition %s should begin downloading shortly.  If there is a problem downloading, you can copy the text below into a text editor and save it with a <code>.cctm.json</code> extension.', CCTM_TXTDOMAIN), '<strong>' . CCTM_ImportExport::get_download_title($sanitized['title']) . '</strong>'));
        $data['msg'] .= "<textarea rows='10' cols='100'>{$save_me}</textarea>";
        // Save the options: anything that's in the form is considered a valid "info" key.
        self::$data['export_info'] = $sanitized;
        update_option(self::db_key, self::$data);
        // Fire off a request to download the file:
        //$data['msg'] .= sprintf('<script type="text/javascript" src="%s"></script>', CCTM_URL.'/js/download_def.js');
        $data['msg'] .= sprintf('<script type="text/javascript">window.location="%s"</script>', CCTM_URL . '/ajax-controllers/download_def.php');
    } elseif ($_POST['export_type'] == 'to_library') {
        // Save the options: anything that's in the form is considered a valid "info" key.
        self::$data['export_info'] = $sanitized;
        update_option(self::db_key, self::$data);
        if (CCTM_ImportExport::export_to_local_webserver()) {
            $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('Your Custom Content Type definition has been saved to your library. <a href="?page=cctm_tools&a=import_def">Click here</a> to view your library.', CCTM_TXTDOMAIN));
        } else {
            $data['msg'] = CCTM::format_errors();
        }
    }
}
// Populate the values
$data['title'] = CCTM::get_value(self::$data['export_info'], 'title');
$data['author'] = CCTM::get_value(self::$data['export_info'], 'author');
$data['url'] = CCTM::get_value(self::$data['export_info'], 'url');
$data['description'] = CCTM::get_value(self::$data['export_info'], 'description');
$data['template_url'] = CCTM::get_value(self::$data['export_info'], 'template_url');
$data['content'] = CCTM::load_view('export.php', $data);
print CCTM::load_view('templates/default.php', $data);
/*EOF*/
// Make sure a file was specified
$filename = CCTM::get_value($_REQUEST, 'file');
if (empty($filename)) {
    print CCTM::format_error_msg(__('Definition file not specified.', CCTM_TXTDOMAIN));
    exit;
}
// Make sure the filename is legit
if (!CCTM_ImportExport::is_valid_basename($filename)) {
    print CCTM::format_error_msg(__('Invalid filename: the definition filename should not contain spaces and should use an extension of <code>.cctm.json</code>.', CCTM_TXTDOMAIN));
    exit;
}
// Load up this thing... errors will be thrown
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'] . '/' . CCTM::base_storage_dir . '/' . CCTM::def_dir . '/';
$data = CCTM_ImportExport::load_def_file($dir . $filename);
$data['filename'] = $filename;
// Bail if there were errors
if (!empty(CCTM::$errors)) {
    print CCTM::format_errors();
    exit;
}
// Check encoding, warn if it differs (warn only: it may not be a problem for the importer)
// See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=322
$this_charset = get_bloginfo('charset');
if (isset($data['export_info']['_charset']) && $data['export_info']['_charset'] != $this_charset) {
    CCTM::$errors['encoding'] = sprintf(__("Your site's encoding differs from the encoding used to create this definition file.  This may create problems if the post-type and field definitions use foreign characters.  Adding the following to your wp-config.php file may alleviate problems with character encoding: <code>define('DB_CHARSET', '%s');</code>", CCTM_TXTDOMAIN), $data['export_info']['_charset']);
}
print CCTM::format_errors();
// but do NOT exit.  It's only a warning, so we continue.
print CCTM::load_view('preview_def.php', $data);
/*EOF*/