Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../parsers
File: class-wxr-parser-simplexml.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress eXtended RSS file parser implementations
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Importer
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* WXR Parser that makes use of the SimpleXML PHP extension.
[9] Fix | Delete
*/
[10] Fix | Delete
class WXR_Parser_SimpleXML {
[11] Fix | Delete
function parse( $file ) {
[12] Fix | Delete
$authors = array();
[13] Fix | Delete
$posts = array();
[14] Fix | Delete
$categories = array();
[15] Fix | Delete
$tags = array();
[16] Fix | Delete
$terms = array();
[17] Fix | Delete
[18] Fix | Delete
$internal_errors = libxml_use_internal_errors( true );
[19] Fix | Delete
[20] Fix | Delete
$dom = new DOMDocument;
[21] Fix | Delete
$old_value = null;
[22] Fix | Delete
if ( function_exists( 'libxml_disable_entity_loader' ) && PHP_VERSION_ID < 80000 ) {
[23] Fix | Delete
$old_value = libxml_disable_entity_loader( true );
[24] Fix | Delete
}
[25] Fix | Delete
$success = $dom->loadXML( file_get_contents( $file ) );
[26] Fix | Delete
if ( ! is_null( $old_value ) ) {
[27] Fix | Delete
libxml_disable_entity_loader( $old_value );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
if ( ! $success || isset( $dom->doctype ) ) {
[31] Fix | Delete
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
$xml = simplexml_import_dom( $dom );
[35] Fix | Delete
unset( $dom );
[36] Fix | Delete
[37] Fix | Delete
// halt if loading produces an error
[38] Fix | Delete
if ( ! $xml ) {
[39] Fix | Delete
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$wxr_version = $xml->xpath( '/rss/channel/wp:wxr_version' );
[43] Fix | Delete
if ( ! $wxr_version ) {
[44] Fix | Delete
return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$wxr_version = (string) trim( $wxr_version[0] );
[48] Fix | Delete
// confirm that we are dealing with the correct file format
[49] Fix | Delete
if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) {
[50] Fix | Delete
return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$base_url = $xml->xpath( '/rss/channel/wp:base_site_url' );
[54] Fix | Delete
$base_url = (string) trim( isset( $base_url[0] ) ? $base_url[0] : '' );
[55] Fix | Delete
[56] Fix | Delete
$base_blog_url = $xml->xpath( '/rss/channel/wp:base_blog_url' );
[57] Fix | Delete
if ( $base_blog_url ) {
[58] Fix | Delete
$base_blog_url = (string) trim( $base_blog_url[0] );
[59] Fix | Delete
} else {
[60] Fix | Delete
$base_blog_url = $base_url;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$namespaces = $xml->getDocNamespaces();
[64] Fix | Delete
if ( ! isset( $namespaces['wp'] ) ) {
[65] Fix | Delete
$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
[66] Fix | Delete
}
[67] Fix | Delete
if ( ! isset( $namespaces['excerpt'] ) ) {
[68] Fix | Delete
$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// grab authors
[72] Fix | Delete
foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) {
[73] Fix | Delete
$a = $author_arr->children( $namespaces['wp'] );
[74] Fix | Delete
$login = (string) $a->author_login;
[75] Fix | Delete
$authors[ $login ] = array(
[76] Fix | Delete
'author_id' => (int) $a->author_id,
[77] Fix | Delete
'author_login' => $login,
[78] Fix | Delete
'author_email' => (string) $a->author_email,
[79] Fix | Delete
'author_display_name' => (string) $a->author_display_name,
[80] Fix | Delete
'author_first_name' => (string) $a->author_first_name,
[81] Fix | Delete
'author_last_name' => (string) $a->author_last_name,
[82] Fix | Delete
);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// grab cats, tags and terms
[86] Fix | Delete
foreach ( $xml->xpath( '/rss/channel/wp:category' ) as $term_arr ) {
[87] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[88] Fix | Delete
$category = array(
[89] Fix | Delete
'term_id' => (int) $t->term_id,
[90] Fix | Delete
'category_nicename' => (string) $t->category_nicename,
[91] Fix | Delete
'category_parent' => (string) $t->category_parent,
[92] Fix | Delete
'cat_name' => (string) $t->cat_name,
[93] Fix | Delete
'category_description' => (string) $t->category_description,
[94] Fix | Delete
);
[95] Fix | Delete
[96] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[97] Fix | Delete
$category['termmeta'][] = array(
[98] Fix | Delete
'key' => (string) $meta->meta_key,
[99] Fix | Delete
'value' => (string) $meta->meta_value,
[100] Fix | Delete
);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
$categories[] = $category;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
foreach ( $xml->xpath( '/rss/channel/wp:tag' ) as $term_arr ) {
[107] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[108] Fix | Delete
$tag = array(
[109] Fix | Delete
'term_id' => (int) $t->term_id,
[110] Fix | Delete
'tag_slug' => (string) $t->tag_slug,
[111] Fix | Delete
'tag_name' => (string) $t->tag_name,
[112] Fix | Delete
'tag_description' => (string) $t->tag_description,
[113] Fix | Delete
);
[114] Fix | Delete
[115] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[116] Fix | Delete
$tag['termmeta'][] = array(
[117] Fix | Delete
'key' => (string) $meta->meta_key,
[118] Fix | Delete
'value' => (string) $meta->meta_value,
[119] Fix | Delete
);
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$tags[] = $tag;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
foreach ( $xml->xpath( '/rss/channel/wp:term' ) as $term_arr ) {
[126] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[127] Fix | Delete
$term = array(
[128] Fix | Delete
'term_id' => (int) $t->term_id,
[129] Fix | Delete
'term_taxonomy' => (string) $t->term_taxonomy,
[130] Fix | Delete
'slug' => (string) $t->term_slug,
[131] Fix | Delete
'term_parent' => (string) $t->term_parent,
[132] Fix | Delete
'term_name' => (string) $t->term_name,
[133] Fix | Delete
'term_description' => (string) $t->term_description,
[134] Fix | Delete
);
[135] Fix | Delete
[136] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[137] Fix | Delete
$term['termmeta'][] = array(
[138] Fix | Delete
'key' => (string) $meta->meta_key,
[139] Fix | Delete
'value' => (string) $meta->meta_value,
[140] Fix | Delete
);
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
$terms[] = $term;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// grab posts
[147] Fix | Delete
foreach ( $xml->channel->item as $item ) {
[148] Fix | Delete
$post = array(
[149] Fix | Delete
'post_title' => (string) $item->title,
[150] Fix | Delete
'guid' => (string) $item->guid,
[151] Fix | Delete
);
[152] Fix | Delete
[153] Fix | Delete
$dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
[154] Fix | Delete
$post['post_author'] = (string) $dc->creator;
[155] Fix | Delete
[156] Fix | Delete
$content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
[157] Fix | Delete
$excerpt = $item->children( $namespaces['excerpt'] );
[158] Fix | Delete
$post['post_content'] = (string) $content->encoded;
[159] Fix | Delete
$post['post_excerpt'] = (string) $excerpt->encoded;
[160] Fix | Delete
[161] Fix | Delete
$wp = $item->children( $namespaces['wp'] );
[162] Fix | Delete
$post['post_id'] = (int) $wp->post_id;
[163] Fix | Delete
$post['post_date'] = (string) $wp->post_date;
[164] Fix | Delete
$post['post_date_gmt'] = (string) $wp->post_date_gmt;
[165] Fix | Delete
$post['comment_status'] = (string) $wp->comment_status;
[166] Fix | Delete
$post['ping_status'] = (string) $wp->ping_status;
[167] Fix | Delete
$post['post_name'] = (string) $wp->post_name;
[168] Fix | Delete
$post['status'] = (string) $wp->status;
[169] Fix | Delete
$post['post_parent'] = (int) $wp->post_parent;
[170] Fix | Delete
$post['menu_order'] = (int) $wp->menu_order;
[171] Fix | Delete
$post['post_type'] = (string) $wp->post_type;
[172] Fix | Delete
$post['post_password'] = (string) $wp->post_password;
[173] Fix | Delete
$post['is_sticky'] = (int) $wp->is_sticky;
[174] Fix | Delete
[175] Fix | Delete
if ( isset( $wp->attachment_url ) ) {
[176] Fix | Delete
$post['attachment_url'] = (string) $wp->attachment_url;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
foreach ( $item->category as $c ) {
[180] Fix | Delete
$att = $c->attributes();
[181] Fix | Delete
if ( isset( $att['nicename'] ) ) {
[182] Fix | Delete
$post['terms'][] = array(
[183] Fix | Delete
'name' => (string) $c,
[184] Fix | Delete
'slug' => (string) $att['nicename'],
[185] Fix | Delete
'domain' => (string) $att['domain'],
[186] Fix | Delete
);
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
foreach ( $wp->postmeta as $meta ) {
[191] Fix | Delete
$post['postmeta'][] = array(
[192] Fix | Delete
'key' => (string) $meta->meta_key,
[193] Fix | Delete
'value' => (string) $meta->meta_value,
[194] Fix | Delete
);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
foreach ( $wp->comment as $comment ) {
[198] Fix | Delete
$meta = array();
[199] Fix | Delete
if ( isset( $comment->commentmeta ) ) {
[200] Fix | Delete
foreach ( $comment->commentmeta as $m ) {
[201] Fix | Delete
$meta[] = array(
[202] Fix | Delete
'key' => (string) $m->meta_key,
[203] Fix | Delete
'value' => (string) $m->meta_value,
[204] Fix | Delete
);
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$post['comments'][] = array(
[209] Fix | Delete
'comment_id' => (int) $comment->comment_id,
[210] Fix | Delete
'comment_author' => (string) $comment->comment_author,
[211] Fix | Delete
'comment_author_email' => (string) $comment->comment_author_email,
[212] Fix | Delete
'comment_author_IP' => (string) $comment->comment_author_IP,
[213] Fix | Delete
'comment_author_url' => (string) $comment->comment_author_url,
[214] Fix | Delete
'comment_date' => (string) $comment->comment_date,
[215] Fix | Delete
'comment_date_gmt' => (string) $comment->comment_date_gmt,
[216] Fix | Delete
'comment_content' => (string) $comment->comment_content,
[217] Fix | Delete
'comment_approved' => (string) $comment->comment_approved,
[218] Fix | Delete
'comment_type' => (string) $comment->comment_type,
[219] Fix | Delete
'comment_parent' => (string) $comment->comment_parent,
[220] Fix | Delete
'comment_user_id' => (int) $comment->comment_user_id,
[221] Fix | Delete
'commentmeta' => $meta,
[222] Fix | Delete
);
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
$posts[] = $post;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
return array(
[229] Fix | Delete
'authors' => $authors,
[230] Fix | Delete
'posts' => $posts,
[231] Fix | Delete
'categories' => $categories,
[232] Fix | Delete
'tags' => $tags,
[233] Fix | Delete
'terms' => $terms,
[234] Fix | Delete
'base_url' => $base_url,
[235] Fix | Delete
'base_blog_url' => $base_blog_url,
[236] Fix | Delete
'version' => $wxr_version,
[237] Fix | Delete
);
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function