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/clone/wp-conte.../plugins/popup-bu.../com/libs
File: parsers.php
<?php
[0] Fix | Delete
namespace sgpb;
[1] Fix | Delete
use \DOMDocument;
[2] Fix | Delete
/**
[3] Fix | Delete
* WordPress eXtended RSS file parser implementations
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Importer
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* WordPress Importer class for managing parsing of WXR files.
[11] Fix | Delete
*/
[12] Fix | Delete
class WXR_Parser {
[13] Fix | Delete
function parse( $file ) {
[14] Fix | Delete
// Attempt to use proper XML parsers first
[15] Fix | Delete
if ( extension_loaded( 'simplexml' ) ) {
[16] Fix | Delete
$parser = new WXR_Parser_SimpleXML;
[17] Fix | Delete
$result = $parser->parse( $file );
[18] Fix | Delete
[19] Fix | Delete
// If SimpleXML succeeds or this is an invalid WXR file then return the results
[20] Fix | Delete
if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
[21] Fix | Delete
return $result;
[22] Fix | Delete
} else if ( extension_loaded( 'xml' ) ) {
[23] Fix | Delete
$parser = new WXR_Parser_XML;
[24] Fix | Delete
$result = $parser->parse( $file );
[25] Fix | Delete
[26] Fix | Delete
// If XMLParser succeeds or this is an invalid WXR file then return the results
[27] Fix | Delete
if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
[28] Fix | Delete
return $result;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
// We have a malformed XML file, so display the error and fallthrough to regex
[32] Fix | Delete
if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
[33] Fix | Delete
echo '<pre>';
[34] Fix | Delete
if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
[35] Fix | Delete
foreach ( $result->get_error_data() as $error )
[36] Fix | Delete
echo esc_html($error->line) . ':' . esc_html($error->column) . ' ' . esc_html( $error->message ) . "\n";
[37] Fix | Delete
} else if ( 'XML_parse_error' == $result->get_error_code() ) {
[38] Fix | Delete
$error = $result->get_error_data();
[39] Fix | Delete
echo esc_html($error[0]) . ':' . esc_html($error[1]) . ' ' . esc_html( $error[2] );
[40] Fix | Delete
}
[41] Fix | Delete
echo '</pre>';
[42] Fix | Delete
echo '<p><strong>' . wp_kses_post(__( 'There was an error when reading this WXR file', 'popup-builder' ) ). '</strong><br />';
[43] Fix | Delete
echo wp_kses_post(__( 'Details are shown above. The importer will now try again with a different parser...', 'popup-builder' ) ) . '</p>';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
// use regular expressions if nothing else available or this is bad XML
[47] Fix | Delete
$parser = new WXR_Parser_Regex;
[48] Fix | Delete
return $parser->parse( $file );
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* WXR Parser that makes use of the SimpleXML PHP extension.
[54] Fix | Delete
*/
[55] Fix | Delete
class WXR_Parser_SimpleXML {
[56] Fix | Delete
function parse( $file ) {
[57] Fix | Delete
$authors = $posts = $categories = $tags = $terms = array();
[58] Fix | Delete
[59] Fix | Delete
$internal_errors = libxml_use_internal_errors(true);
[60] Fix | Delete
[61] Fix | Delete
$dom = new DOMDocument;
[62] Fix | Delete
$old_value = null;
[63] Fix | Delete
if ( function_exists( 'libxml_disable_entity_loader' ) ) {
[64] Fix | Delete
$old_value = libxml_disable_entity_loader( true );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$success = $dom->loadXML( file_get_contents( $file ) );// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
[68] Fix | Delete
if ( ! is_null( $old_value ) ) {
[69] Fix | Delete
libxml_disable_entity_loader( $old_value );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
if ( ! $success || isset( $dom->doctype ) ) {
[73] Fix | Delete
return new \WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'popup-builder' ), libxml_get_errors() );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$xml = simplexml_import_dom( $dom );
[77] Fix | Delete
unset( $dom );
[78] Fix | Delete
[79] Fix | Delete
// halt if loading produces an error
[80] Fix | Delete
if ( ! $xml )
[81] Fix | Delete
return new \WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'popup-builder' ), libxml_get_errors() );
[82] Fix | Delete
[83] Fix | Delete
$wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
[84] Fix | Delete
if ( ! $wxr_version )
[85] Fix | Delete
return new \WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'popup-builder' ) );
[86] Fix | Delete
[87] Fix | Delete
$wxr_version = (string) trim( $wxr_version[0] );
[88] Fix | Delete
// confirm that we are dealing with the correct file format
[89] Fix | Delete
if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
[90] Fix | Delete
return new \WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'popup-builder' ) );
[91] Fix | Delete
[92] Fix | Delete
$base_url = $xml->xpath('/rss/channel/wp:base_site_url');
[93] Fix | Delete
$base_url = (string) trim( $base_url[0] );
[94] Fix | Delete
[95] Fix | Delete
$namespaces = $xml->getDocNamespaces();
[96] Fix | Delete
if ( ! isset( $namespaces['wp'] ) )
[97] Fix | Delete
$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
[98] Fix | Delete
if ( ! isset( $namespaces['excerpt'] ) )
[99] Fix | Delete
$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
[100] Fix | Delete
[101] Fix | Delete
// grab authors
[102] Fix | Delete
foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
[103] Fix | Delete
$a = $author_arr->children( $namespaces['wp'] );
[104] Fix | Delete
$login = (string) $a->author_login;
[105] Fix | Delete
$authors[$login] = array(
[106] Fix | Delete
'author_id' => (int) $a->author_id,
[107] Fix | Delete
'author_login' => $login,
[108] Fix | Delete
'author_email' => (string) $a->author_email,
[109] Fix | Delete
'author_display_name' => (string) $a->author_display_name,
[110] Fix | Delete
'author_first_name' => (string) $a->author_first_name,
[111] Fix | Delete
'author_last_name' => (string) $a->author_last_name
[112] Fix | Delete
);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
// grab cats, tags and terms
[116] Fix | Delete
foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) {
[117] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[118] Fix | Delete
$category = array(
[119] Fix | Delete
'term_id' => (int) $t->term_id,
[120] Fix | Delete
'category_nicename' => (string) $t->category_nicename,
[121] Fix | Delete
'category_parent' => (string) $t->category_parent,
[122] Fix | Delete
'cat_name' => (string) $t->cat_name,
[123] Fix | Delete
'category_description' => (string) $t->category_description
[124] Fix | Delete
);
[125] Fix | Delete
[126] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[127] Fix | Delete
$category['termmeta'][] = array(
[128] Fix | Delete
'key' => (string) $meta->meta_key,
[129] Fix | Delete
'value' => (string) $meta->meta_value
[130] Fix | Delete
);
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
$categories[] = $category;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
[137] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[138] Fix | Delete
$tag = array(
[139] Fix | Delete
'term_id' => (int) $t->term_id,
[140] Fix | Delete
'tag_slug' => (string) $t->tag_slug,
[141] Fix | Delete
'tag_name' => (string) $t->tag_name,
[142] Fix | Delete
'tag_description' => (string) $t->tag_description
[143] Fix | Delete
);
[144] Fix | Delete
[145] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[146] Fix | Delete
$tag['termmeta'][] = array(
[147] Fix | Delete
'key' => (string) $meta->meta_key,
[148] Fix | Delete
'value' => (string) $meta->meta_value
[149] Fix | Delete
);
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
$tags[] = $tag;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
[156] Fix | Delete
$t = $term_arr->children( $namespaces['wp'] );
[157] Fix | Delete
$term = array(
[158] Fix | Delete
'term_id' => (int) $t->term_id,
[159] Fix | Delete
'term_taxonomy' => (string) $t->term_taxonomy,
[160] Fix | Delete
'slug' => (string) $t->term_slug,
[161] Fix | Delete
'term_parent' => (string) $t->term_parent,
[162] Fix | Delete
'term_name' => (string) $t->term_name,
[163] Fix | Delete
'term_description' => (string) $t->term_description
[164] Fix | Delete
);
[165] Fix | Delete
[166] Fix | Delete
foreach ( $t->termmeta as $meta ) {
[167] Fix | Delete
$term['termmeta'][] = array(
[168] Fix | Delete
'key' => (string) $meta->meta_key,
[169] Fix | Delete
'value' => (string) $meta->meta_value
[170] Fix | Delete
);
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$terms[] = $term;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
// grab posts
[177] Fix | Delete
foreach ( $xml->channel->item as $item ) {
[178] Fix | Delete
$post = array(
[179] Fix | Delete
'post_title' => (string) $item->title,
[180] Fix | Delete
'guid' => (string) $item->guid,
[181] Fix | Delete
);
[182] Fix | Delete
[183] Fix | Delete
$dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
[184] Fix | Delete
$post['post_author'] = (string) $dc->creator;
[185] Fix | Delete
[186] Fix | Delete
$content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
[187] Fix | Delete
$excerpt = $item->children( $namespaces['excerpt'] );
[188] Fix | Delete
$post['post_content'] = (string) $content->encoded;
[189] Fix | Delete
$post['post_excerpt'] = (string) $excerpt->encoded;
[190] Fix | Delete
[191] Fix | Delete
$wp = $item->children( $namespaces['wp'] );
[192] Fix | Delete
$post['post_id'] = (int) $wp->post_id;
[193] Fix | Delete
$post['post_date'] = (string) $wp->post_date;
[194] Fix | Delete
$post['post_date_gmt'] = (string) $wp->post_date_gmt;
[195] Fix | Delete
$post['comment_status'] = (string) $wp->comment_status;
[196] Fix | Delete
$post['ping_status'] = (string) $wp->ping_status;
[197] Fix | Delete
$post['post_name'] = (string) $wp->post_name;
[198] Fix | Delete
$post['status'] = (string) $wp->status;
[199] Fix | Delete
$post['post_parent'] = (int) $wp->post_parent;
[200] Fix | Delete
$post['menu_order'] = (int) $wp->menu_order;
[201] Fix | Delete
$post['post_type'] = (string) $wp->post_type;
[202] Fix | Delete
$post['post_password'] = (string) $wp->post_password;
[203] Fix | Delete
$post['is_sticky'] = (int) $wp->is_sticky;
[204] Fix | Delete
[205] Fix | Delete
if ( isset($wp->attachment_url) )
[206] Fix | Delete
$post['attachment_url'] = (string) $wp->attachment_url;
[207] Fix | Delete
[208] Fix | Delete
foreach ( $item->category as $c ) {
[209] Fix | Delete
$att = $c->attributes();
[210] Fix | Delete
if ( isset( $att['nicename'] ) )
[211] Fix | Delete
$post['terms'][] = array(
[212] Fix | Delete
'name' => (string) $c,
[213] Fix | Delete
'slug' => (string) $att['nicename'],
[214] Fix | Delete
'domain' => (string) $att['domain']
[215] Fix | Delete
);
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
foreach ( $wp->postmeta as $meta ) {
[219] Fix | Delete
$post['postmeta'][] = array(
[220] Fix | Delete
'key' => (string) $meta->meta_key,
[221] Fix | Delete
'value' => (string) $meta->meta_value
[222] Fix | Delete
);
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
foreach ( $wp->comment as $comment ) {
[226] Fix | Delete
$meta = array();
[227] Fix | Delete
if ( isset( $comment->commentmeta ) ) {
[228] Fix | Delete
foreach ( $comment->commentmeta as $m ) {
[229] Fix | Delete
$meta[] = array(
[230] Fix | Delete
'key' => (string) $m->meta_key,
[231] Fix | Delete
'value' => (string) $m->meta_value
[232] Fix | Delete
);
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
$post['comments'][] = array(
[237] Fix | Delete
'comment_id' => (int) $comment->comment_id,
[238] Fix | Delete
'comment_author' => (string) $comment->comment_author,
[239] Fix | Delete
'comment_author_email' => (string) $comment->comment_author_email,
[240] Fix | Delete
'comment_author_IP' => (string) $comment->comment_author_IP,
[241] Fix | Delete
'comment_author_url' => (string) $comment->comment_author_url,
[242] Fix | Delete
'comment_date' => (string) $comment->comment_date,
[243] Fix | Delete
'comment_date_gmt' => (string) $comment->comment_date_gmt,
[244] Fix | Delete
'comment_content' => (string) $comment->comment_content,
[245] Fix | Delete
'comment_approved' => (string) $comment->comment_approved,
[246] Fix | Delete
'comment_type' => (string) $comment->comment_type,
[247] Fix | Delete
'comment_parent' => (string) $comment->comment_parent,
[248] Fix | Delete
'comment_user_id' => (int) $comment->comment_user_id,
[249] Fix | Delete
'commentmeta' => $meta,
[250] Fix | Delete
);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$posts[] = $post;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
return array(
[257] Fix | Delete
'authors' => $authors,
[258] Fix | Delete
'posts' => $posts,
[259] Fix | Delete
'categories' => $categories,
[260] Fix | Delete
'tags' => $tags,
[261] Fix | Delete
'terms' => $terms,
[262] Fix | Delete
'base_url' => $base_url,
[263] Fix | Delete
'version' => $wxr_version
[264] Fix | Delete
);
[265] Fix | Delete
}
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* WXR Parser that makes use of the XML Parser PHP extension.
[270] Fix | Delete
*/
[271] Fix | Delete
class WXR_Parser_XML {
[272] Fix | Delete
public $wp_tags = array(
[273] Fix | Delete
'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
[274] Fix | Delete
'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
[275] Fix | Delete
'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
[276] Fix | Delete
'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
[277] Fix | Delete
'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
[278] Fix | Delete
'wp:author_first_name', 'wp:author_last_name',
[279] Fix | Delete
);
[280] Fix | Delete
public $wp_sub_tags = array(
[281] Fix | Delete
'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
[282] Fix | Delete
'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
[283] Fix | Delete
'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
[284] Fix | Delete
);
[285] Fix | Delete
public $wxr_version;
[286] Fix | Delete
public $in_post;
[287] Fix | Delete
public $cdata;
[288] Fix | Delete
public $data;
[289] Fix | Delete
public $sub_data;
[290] Fix | Delete
public $in_tag;
[291] Fix | Delete
public $in_sub_tag;
[292] Fix | Delete
public $authors;
[293] Fix | Delete
public $posts;
[294] Fix | Delete
public $term;
[295] Fix | Delete
public $category;
[296] Fix | Delete
public $tag;
[297] Fix | Delete
public $base_url;
[298] Fix | Delete
public $base_blog_url;
[299] Fix | Delete
function parse( $file ) {
[300] Fix | Delete
$this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
[301] Fix | Delete
$this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
[302] Fix | Delete
[303] Fix | Delete
$xml = xml_parser_create( 'UTF-8' );
[304] Fix | Delete
xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
[305] Fix | Delete
xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
[306] Fix | Delete
xml_set_object( $xml, $this );
[307] Fix | Delete
xml_set_character_data_handler( $xml, 'cdata' );
[308] Fix | Delete
xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
[309] Fix | Delete
[310] Fix | Delete
if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
[311] Fix | Delete
$current_line = xml_get_current_line_number( $xml );
[312] Fix | Delete
$current_column = xml_get_current_column_number( $xml );
[313] Fix | Delete
$error_code = xml_get_error_code( $xml );
[314] Fix | Delete
$error_string = xml_error_string( $error_code );
[315] Fix | Delete
return new \WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
[316] Fix | Delete
}
[317] Fix | Delete
xml_parser_free( $xml );
[318] Fix | Delete
[319] Fix | Delete
if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
[320] Fix | Delete
return new \WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'popup-builder' ) );
[321] Fix | Delete
[322] Fix | Delete
return array(
[323] Fix | Delete
'authors' => $this->authors,
[324] Fix | Delete
'posts' => $this->posts,
[325] Fix | Delete
'categories' => $this->category,
[326] Fix | Delete
'tags' => $this->tag,
[327] Fix | Delete
'terms' => $this->term,
[328] Fix | Delete
'base_url' => $this->base_url,
[329] Fix | Delete
'version' => $this->wxr_version
[330] Fix | Delete
);
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
function tag_open( $parse, $tag, $attr ) {
[334] Fix | Delete
if ( in_array( $tag, $this->wp_tags ) ) {
[335] Fix | Delete
$this->in_tag = substr( $tag, 3 );
[336] Fix | Delete
return;
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
if ( in_array( $tag, $this->wp_sub_tags ) ) {
[340] Fix | Delete
$this->in_sub_tag = substr( $tag, 3 );
[341] Fix | Delete
return;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
switch ( $tag ) {
[345] Fix | Delete
case 'category':
[346] Fix | Delete
if ( isset($attr['domain'], $attr['nicename']) ) {
[347] Fix | Delete
$this->sub_data['domain'] = $attr['domain'];
[348] Fix | Delete
$this->sub_data['slug'] = $attr['nicename'];
[349] Fix | Delete
}
[350] Fix | Delete
break;
[351] Fix | Delete
case 'item': $this->in_post = true;
[352] Fix | Delete
case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
[353] Fix | Delete
case 'guid': $this->in_tag = 'guid'; break;
[354] Fix | Delete
case 'dc:creator': $this->in_tag = 'post_author'; break;
[355] Fix | Delete
case 'content:encoded': $this->in_tag = 'post_content'; break;
[356] Fix | Delete
case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
[357] Fix | Delete
[358] Fix | Delete
case 'wp:term_slug': $this->in_tag = 'slug'; break;
[359] Fix | Delete
case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
[360] Fix | Delete
case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
function cdata( $parser, $cdata ) {
[365] Fix | Delete
if ( ! trim( $cdata ) )
[366] Fix | Delete
return;
[367] Fix | Delete
[368] Fix | Delete
if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
[369] Fix | Delete
$this->cdata .= $cdata;
[370] Fix | Delete
} else {
[371] Fix | Delete
$this->cdata .= trim( $cdata );
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
function tag_close( $parser, $tag ) {
[376] Fix | Delete
switch ( $tag ) {
[377] Fix | Delete
case 'wp:comment':
[378] Fix | Delete
unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
[379] Fix | Delete
if ( ! empty( $this->sub_data ) )
[380] Fix | Delete
$this->data['comments'][] = $this->sub_data;
[381] Fix | Delete
$this->sub_data = false;
[382] Fix | Delete
break;
[383] Fix | Delete
case 'wp:commentmeta':
[384] Fix | Delete
$this->sub_data['commentmeta'][] = array(
[385] Fix | Delete
'key' => $this->sub_data['key'],
[386] Fix | Delete
'value' => $this->sub_data['value']
[387] Fix | Delete
);
[388] Fix | Delete
break;
[389] Fix | Delete
case 'category':
[390] Fix | Delete
if ( ! empty( $this->sub_data ) ) {
[391] Fix | Delete
$this->sub_data['name'] = $this->cdata;
[392] Fix | Delete
$this->data['terms'][] = $this->sub_data;
[393] Fix | Delete
}
[394] Fix | Delete
$this->sub_data = false;
[395] Fix | Delete
break;
[396] Fix | Delete
case 'wp:postmeta':
[397] Fix | Delete
if ( ! empty( $this->sub_data ) )
[398] Fix | Delete
$this->data['postmeta'][] = $this->sub_data;
[399] Fix | Delete
$this->sub_data = false;
[400] Fix | Delete
break;
[401] Fix | Delete
case 'item':
[402] Fix | Delete
$this->posts[] = $this->data;
[403] Fix | Delete
$this->data = false;
[404] Fix | Delete
break;
[405] Fix | Delete
case 'wp:category':
[406] Fix | Delete
case 'wp:tag':
[407] Fix | Delete
case 'wp:term':
[408] Fix | Delete
$n = substr( $tag, 3 );
[409] Fix | Delete
array_push( $this->$n, $this->data );
[410] Fix | Delete
$this->data = false;
[411] Fix | Delete
break;
[412] Fix | Delete
case 'wp:author':
[413] Fix | Delete
if ( ! empty($this->data['author_login']) )
[414] Fix | Delete
$this->authors[$this->data['author_login']] = $this->data;
[415] Fix | Delete
$this->data = false;
[416] Fix | Delete
break;
[417] Fix | Delete
case 'wp:base_site_url':
[418] Fix | Delete
$this->base_url = $this->cdata;
[419] Fix | Delete
break;
[420] Fix | Delete
case 'wp:wxr_version':
[421] Fix | Delete
$this->wxr_version = $this->cdata;
[422] Fix | Delete
break;
[423] Fix | Delete
[424] Fix | Delete
default:
[425] Fix | Delete
if ( $this->in_sub_tag ) {
[426] Fix | Delete
$this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
[427] Fix | Delete
$this->in_sub_tag = false;
[428] Fix | Delete
} else if ( $this->in_tag ) {
[429] Fix | Delete
$this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
[430] Fix | Delete
$this->in_tag = false;
[431] Fix | Delete
}
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
$this->cdata = false;
[435] Fix | Delete
}
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
[440] Fix | Delete
*/
[441] Fix | Delete
class WXR_Parser_Regex {
[442] Fix | Delete
public $authors = array();
[443] Fix | Delete
public $posts = array();
[444] Fix | Delete
public $categories = array();
[445] Fix | Delete
public $tags = array();
[446] Fix | Delete
public $terms = array();
[447] Fix | Delete
public $base_url = '';
[448] Fix | Delete
public $base_blog_url = '';
[449] Fix | Delete
public $has_gzip;
[450] Fix | Delete
function __construct() {
[451] Fix | Delete
$this->has_gzip = is_callable( 'gzopen' );
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
function parse( $file ) {
[455] Fix | Delete
$wxr_version = $in_multiline = false;
[456] Fix | Delete
[457] Fix | Delete
$multiline_content = '';
[458] Fix | Delete
[459] Fix | Delete
$multiline_tags = array(
[460] Fix | Delete
'item' => array( 'posts', array( $this, 'process_post' ) ),
[461] Fix | Delete
'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
[462] Fix | Delete
'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
[463] Fix | Delete
'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
[464] Fix | Delete
);
[465] Fix | Delete
[466] Fix | Delete
$fp = $this->fopen( $file, 'r' );
[467] Fix | Delete
if ( $fp ) {
[468] Fix | Delete
while ( ! $this->feof( $fp ) ) {
[469] Fix | Delete
$importline = rtrim( $this->fgets( $fp ) );
[470] Fix | Delete
[471] Fix | Delete
if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
[472] Fix | Delete
$wxr_version = $version[1];
[473] Fix | Delete
[474] Fix | Delete
if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
[475] Fix | Delete
preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
[476] Fix | Delete
$this->base_url = $url[1];
[477] Fix | Delete
continue;
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
if ( false !== strpos( $importline, '<wp:base_blog_url>' ) ) {
[481] Fix | Delete
preg_match( '|<wp:base_blog_url>(.*?)</wp:base_blog_url>|is', $importline, $blog_url );
[482] Fix | Delete
$this->base_blog_url = $blog_url[1];
[483] Fix | Delete
continue;
[484] Fix | Delete
} elseif ( empty( $this->base_blog_url ) ) {
[485] Fix | Delete
$this->base_blog_url = $this->base_url;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
if ( false !== strpos( $importline, '<wp:author>' ) ) {
[489] Fix | Delete
preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
[490] Fix | Delete
$a = $this->process_author( $author[1] );
[491] Fix | Delete
$this->authors[$a['author_login']] = $a;
[492] Fix | Delete
continue;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
foreach ( $multiline_tags as $tag => $handler ) {
[496] Fix | Delete
// Handle multi-line tags on a singular line
[497] Fix | Delete
if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
[498] Fix | Delete
$this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function