' . __( 'Sorry, there has been an error.', 'anno' ) . '
';
echo __( 'The file does not exist, please try again.', 'anno' ) . '';
$this->footer();
die();
}
$import_data = $this->parse( $file );
if ( is_wp_error( $import_data ) ) {
echo '' . __( 'Sorry, there has been an error.', 'anno' ) . '
';
echo esc_html( $import_data->get_error_message() ) . '
';
$this->footer();
die();
}
$this->version = $import_data['version'];
$this->get_authors_from_import( $import_data );
$this->posts = $import_data['posts'];
$this->terms = $import_data['terms'];
$this->categories = $import_data['categories'];
$this->tags = $import_data['tags'];
$this->base_url = esc_url( $import_data['base_url'] );
wp_defer_term_counting( true );
wp_defer_comment_counting( true );
do_action( 'import_start' );
}
/**
* Retrieve authors and author meta from parse XML file. Process meta data.
*
* @param array $import_data Data returned by the parser
*/
function get_authors_from_import($import_data) {
// No fallback options available
if (!empty($import_data['authors'])) {
$this->authors = $import_data['authors'];
}
if (!empty($import_data['authors_meta'])) {
$this->authors_meta = $import_data['authors_meta'];
$this->process_user_meta();
}
}
/**
* Process post meta for created users
*
*/
function process_user_meta() {
// Only perform on newly created users
foreach ($this->created_users as $old_id => $wp_id) {
if (!empty($this->authors_meta[$old_id]) && is_array($this->authors_meta[$old_id])) {
foreach ($this->authors_meta[$old_id] as $key => $value) {
$value = trim($value);
if (!empty($value)) {
if ($key == 'bio') {
$key == 'descriptions';
}
else {
$key = '_anno_'.$key;
}
// We only have single rows per key
update_user_meta($wp_id, $key, $value);
}
}
}
}
}
/**
* Parse a WXR file
*
* @param string $file Path to WXR file for parsing
* @return array Information gathered from the WXR file
*/
function parse($file) {
$parser = new Kipling_DTD_Parser();
return $parser->parse( $file );
}
// Display import page title
function header() {
echo '';
screen_icon();
echo '
' . __( 'Kipling DTD XML Import', 'anno' ) . '
';
}
// Close div.wrap
function footer() {
echo '';
}
/**
* Display introductory text and file upload form
*/
function greet() {
echo '';
echo '
'.__( 'Howdy! Upload your Kipling DTD XML file and we’ll import the articles, keywords, subjects, and users into this site.', 'anno' ).'
';
echo '
'.__( 'Choose a Kipling DTD XML (.xml) file to upload, then click Upload file and import.', 'anno' ).'
';
wp_import_upload_form( 'admin.php?import=kipling_dtd_xml&step=1' );
echo '
';
}
}
}
function anno_dtd_importer_init() {
/**
* Knol Importer object for registering the import callback
* @global DTD_Import $dtd_import
*/
$GLOBALS['dtd_import'] = new DTD_Import();
register_importer('kipling_dtd_xml', 'Kipling DTD XML', __('Import articles, keywords, subjects and users from a Kipling DTD XML file.', 'anno'), array( $GLOBALS['dtd_import'], 'dispatch') );
}
add_action('admin_init', 'anno_dtd_importer_init');
?>