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/wordpres.../parsers
File: class-wxr-parser-regex.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 uses regular expressions. Fallback for installs without an XML parser.
[9] Fix | Delete
*/
[10] Fix | Delete
class WXR_Parser_Regex {
[11] Fix | Delete
public $authors = array();
[12] Fix | Delete
public $posts = array();
[13] Fix | Delete
public $categories = array();
[14] Fix | Delete
public $tags = array();
[15] Fix | Delete
public $terms = array();
[16] Fix | Delete
public $base_url = '';
[17] Fix | Delete
public $base_blog_url = '';
[18] Fix | Delete
public $has_gzip;
[19] Fix | Delete
[20] Fix | Delete
function __construct() {
[21] Fix | Delete
$this->has_gzip = is_callable( 'gzopen' );
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
function parse( $file ) {
[25] Fix | Delete
$wxr_version = false;
[26] Fix | Delete
$in_multiline = false;
[27] Fix | Delete
[28] Fix | Delete
$multiline_content = '';
[29] Fix | Delete
[30] Fix | Delete
$multiline_tags = array(
[31] Fix | Delete
'item' => array( 'posts', array( $this, 'process_post' ) ),
[32] Fix | Delete
'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
[33] Fix | Delete
'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
[34] Fix | Delete
'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
[35] Fix | Delete
);
[36] Fix | Delete
[37] Fix | Delete
$fp = $this->fopen( $file, 'r' );
[38] Fix | Delete
if ( $fp ) {
[39] Fix | Delete
while ( ! $this->feof( $fp ) ) {
[40] Fix | Delete
$is_tag_line = false;
[41] Fix | Delete
$importline = rtrim( $this->fgets( $fp ) );
[42] Fix | Delete
[43] Fix | Delete
if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) {
[44] Fix | Delete
$wxr_version = $version[1];
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
[48] Fix | Delete
preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
[49] Fix | Delete
$this->base_url = $url[1];
[50] Fix | Delete
continue;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
if ( false !== strpos( $importline, '<wp:base_blog_url>' ) ) {
[54] Fix | Delete
preg_match( '|<wp:base_blog_url>(.*?)</wp:base_blog_url>|is', $importline, $blog_url );
[55] Fix | Delete
$this->base_blog_url = $blog_url[1];
[56] Fix | Delete
continue;
[57] Fix | Delete
} elseif ( empty( $this->base_blog_url ) ) {
[58] Fix | Delete
$this->base_blog_url = $this->base_url;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
if ( false !== strpos( $importline, '<wp:author>' ) ) {
[62] Fix | Delete
preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
[63] Fix | Delete
$a = $this->process_author( $author[1] );
[64] Fix | Delete
$this->authors[ $a['author_login'] ] = $a;
[65] Fix | Delete
continue;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
foreach ( $multiline_tags as $tag => $handler ) {
[69] Fix | Delete
// Handle multi-line tags on a singular line
[70] Fix | Delete
$pos = strpos( $importline, "<$tag>" );
[71] Fix | Delete
$pos_closing = strpos( $importline, "</$tag>" );
[72] Fix | Delete
if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
[73] Fix | Delete
$this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );
[74] Fix | Delete
[75] Fix | Delete
} elseif ( false !== $pos ) {
[76] Fix | Delete
// Take note of any content after the opening tag
[77] Fix | Delete
$multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) );
[78] Fix | Delete
[79] Fix | Delete
// We don't want to have this line added to `$is_multiline` below.
[80] Fix | Delete
$in_multiline = $tag;
[81] Fix | Delete
$is_tag_line = true;
[82] Fix | Delete
[83] Fix | Delete
} elseif ( false !== $pos_closing ) {
[84] Fix | Delete
$in_multiline = false;
[85] Fix | Delete
$multiline_content .= trim( substr( $importline, 0, $pos_closing ) );
[86] Fix | Delete
[87] Fix | Delete
$this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content );
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $in_multiline && ! $is_tag_line ) {
[92] Fix | Delete
$multiline_content .= $importline . "\n";
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$this->fclose( $fp );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( ! $wxr_version ) {
[100] 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' ) );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
return array(
[104] Fix | Delete
'authors' => $this->authors,
[105] Fix | Delete
'posts' => $this->posts,
[106] Fix | Delete
'categories' => $this->categories,
[107] Fix | Delete
'tags' => $this->tags,
[108] Fix | Delete
'terms' => $this->terms,
[109] Fix | Delete
'base_url' => $this->base_url,
[110] Fix | Delete
'base_blog_url' => $this->base_blog_url,
[111] Fix | Delete
'version' => $wxr_version,
[112] Fix | Delete
);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
function get_tag( $string, $tag ) {
[116] Fix | Delete
preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
[117] Fix | Delete
if ( isset( $return[1] ) ) {
[118] Fix | Delete
if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
[119] Fix | Delete
if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
[120] Fix | Delete
preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
[121] Fix | Delete
$return = '';
[122] Fix | Delete
foreach ( $matches[1] as $match ) {
[123] Fix | Delete
$return .= $match;
[124] Fix | Delete
}
[125] Fix | Delete
} else {
[126] Fix | Delete
$return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
[127] Fix | Delete
}
[128] Fix | Delete
} else {
[129] Fix | Delete
$return = $return[1];
[130] Fix | Delete
}
[131] Fix | Delete
} else {
[132] Fix | Delete
$return = '';
[133] Fix | Delete
}
[134] Fix | Delete
return $return;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
function process_category( $c ) {
[138] Fix | Delete
$term = array(
[139] Fix | Delete
'term_id' => $this->get_tag( $c, 'wp:term_id' ),
[140] Fix | Delete
'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
[141] Fix | Delete
'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
[142] Fix | Delete
'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
[143] Fix | Delete
'category_description' => $this->get_tag( $c, 'wp:category_description' ),
[144] Fix | Delete
);
[145] Fix | Delete
[146] Fix | Delete
$term_meta = $this->process_meta( $c, 'wp:termmeta' );
[147] Fix | Delete
if ( ! empty( $term_meta ) ) {
[148] Fix | Delete
$term['termmeta'] = $term_meta;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
return $term;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
function process_tag( $t ) {
[155] Fix | Delete
$term = array(
[156] Fix | Delete
'term_id' => $this->get_tag( $t, 'wp:term_id' ),
[157] Fix | Delete
'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
[158] Fix | Delete
'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
[159] Fix | Delete
'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
[160] Fix | Delete
);
[161] Fix | Delete
[162] Fix | Delete
$term_meta = $this->process_meta( $t, 'wp:termmeta' );
[163] Fix | Delete
if ( ! empty( $term_meta ) ) {
[164] Fix | Delete
$term['termmeta'] = $term_meta;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
return $term;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
function process_term( $t ) {
[171] Fix | Delete
$term = array(
[172] Fix | Delete
'term_id' => $this->get_tag( $t, 'wp:term_id' ),
[173] Fix | Delete
'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
[174] Fix | Delete
'slug' => $this->get_tag( $t, 'wp:term_slug' ),
[175] Fix | Delete
'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
[176] Fix | Delete
'term_name' => $this->get_tag( $t, 'wp:term_name' ),
[177] Fix | Delete
'term_description' => $this->get_tag( $t, 'wp:term_description' ),
[178] Fix | Delete
);
[179] Fix | Delete
[180] Fix | Delete
$term_meta = $this->process_meta( $t, 'wp:termmeta' );
[181] Fix | Delete
if ( ! empty( $term_meta ) ) {
[182] Fix | Delete
$term['termmeta'] = $term_meta;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
return $term;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
function process_meta( $string, $tag ) {
[189] Fix | Delete
$parsed_meta = array();
[190] Fix | Delete
[191] Fix | Delete
preg_match_all( "|<$tag>(.+?)</$tag>|is", $string, $meta );
[192] Fix | Delete
[193] Fix | Delete
if ( ! isset( $meta[1] ) ) {
[194] Fix | Delete
return $parsed_meta;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
foreach ( $meta[1] as $m ) {
[198] Fix | Delete
$parsed_meta[] = array(
[199] Fix | Delete
'key' => $this->get_tag( $m, 'wp:meta_key' ),
[200] Fix | Delete
'value' => $this->get_tag( $m, 'wp:meta_value' ),
[201] Fix | Delete
);
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return $parsed_meta;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
function process_author( $a ) {
[208] Fix | Delete
return array(
[209] Fix | Delete
'author_id' => $this->get_tag( $a, 'wp:author_id' ),
[210] Fix | Delete
'author_login' => $this->get_tag( $a, 'wp:author_login' ),
[211] Fix | Delete
'author_email' => $this->get_tag( $a, 'wp:author_email' ),
[212] Fix | Delete
'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
[213] Fix | Delete
'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
[214] Fix | Delete
'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
[215] Fix | Delete
);
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
function process_post( $post ) {
[219] Fix | Delete
$post_id = $this->get_tag( $post, 'wp:post_id' );
[220] Fix | Delete
$post_title = $this->get_tag( $post, 'title' );
[221] Fix | Delete
$post_date = $this->get_tag( $post, 'wp:post_date' );
[222] Fix | Delete
$post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
[223] Fix | Delete
$comment_status = $this->get_tag( $post, 'wp:comment_status' );
[224] Fix | Delete
$ping_status = $this->get_tag( $post, 'wp:ping_status' );
[225] Fix | Delete
$status = $this->get_tag( $post, 'wp:status' );
[226] Fix | Delete
$post_name = $this->get_tag( $post, 'wp:post_name' );
[227] Fix | Delete
$post_parent = $this->get_tag( $post, 'wp:post_parent' );
[228] Fix | Delete
$menu_order = $this->get_tag( $post, 'wp:menu_order' );
[229] Fix | Delete
$post_type = $this->get_tag( $post, 'wp:post_type' );
[230] Fix | Delete
$post_password = $this->get_tag( $post, 'wp:post_password' );
[231] Fix | Delete
$is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
[232] Fix | Delete
$guid = $this->get_tag( $post, 'guid' );
[233] Fix | Delete
$post_author = $this->get_tag( $post, 'dc:creator' );
[234] Fix | Delete
[235] Fix | Delete
$post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
[236] Fix | Delete
$post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
[237] Fix | Delete
$post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
[238] Fix | Delete
$post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
[239] Fix | Delete
[240] Fix | Delete
$post_content = $this->get_tag( $post, 'content:encoded' );
[241] Fix | Delete
$post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
[242] Fix | Delete
$post_content = str_replace( '<br>', '<br />', $post_content );
[243] Fix | Delete
$post_content = str_replace( '<hr>', '<hr />', $post_content );
[244] Fix | Delete
[245] Fix | Delete
$postdata = compact(
[246] Fix | Delete
'post_id',
[247] Fix | Delete
'post_author',
[248] Fix | Delete
'post_date',
[249] Fix | Delete
'post_date_gmt',
[250] Fix | Delete
'post_content',
[251] Fix | Delete
'post_excerpt',
[252] Fix | Delete
'post_title',
[253] Fix | Delete
'status',
[254] Fix | Delete
'post_name',
[255] Fix | Delete
'comment_status',
[256] Fix | Delete
'ping_status',
[257] Fix | Delete
'guid',
[258] Fix | Delete
'post_parent',
[259] Fix | Delete
'menu_order',
[260] Fix | Delete
'post_type',
[261] Fix | Delete
'post_password',
[262] Fix | Delete
'is_sticky'
[263] Fix | Delete
);
[264] Fix | Delete
[265] Fix | Delete
$attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
[266] Fix | Delete
if ( $attachment_url ) {
[267] Fix | Delete
$postdata['attachment_url'] = $attachment_url;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
[271] Fix | Delete
foreach ( $terms as $t ) {
[272] Fix | Delete
$post_terms[] = array(
[273] Fix | Delete
'slug' => $t[2],
[274] Fix | Delete
'domain' => $t[1],
[275] Fix | Delete
'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
[276] Fix | Delete
);
[277] Fix | Delete
}
[278] Fix | Delete
if ( ! empty( $post_terms ) ) {
[279] Fix | Delete
$postdata['terms'] = $post_terms;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
[283] Fix | Delete
$comments = $comments[1];
[284] Fix | Delete
if ( $comments ) {
[285] Fix | Delete
foreach ( $comments as $comment ) {
[286] Fix | Delete
$post_comments[] = array(
[287] Fix | Delete
'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
[288] Fix | Delete
'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
[289] Fix | Delete
'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
[290] Fix | Delete
'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
[291] Fix | Delete
'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
[292] Fix | Delete
'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
[293] Fix | Delete
'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
[294] Fix | Delete
'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
[295] Fix | Delete
'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
[296] Fix | Delete
'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
[297] Fix | Delete
'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
[298] Fix | Delete
'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
[299] Fix | Delete
'commentmeta' => $this->process_meta( $comment, 'wp:commentmeta' ),
[300] Fix | Delete
);
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
if ( ! empty( $post_comments ) ) {
[304] Fix | Delete
$postdata['comments'] = $post_comments;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
$post_meta = $this->process_meta( $post, 'wp:postmeta' );
[308] Fix | Delete
if ( ! empty( $post_meta ) ) {
[309] Fix | Delete
$postdata['postmeta'] = $post_meta;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
return $postdata;
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
function _normalize_tag( $matches ) {
[316] Fix | Delete
return '<' . strtolower( $matches[1] );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
function fopen( $filename, $mode = 'r' ) {
[320] Fix | Delete
if ( $this->has_gzip ) {
[321] Fix | Delete
return gzopen( $filename, $mode );
[322] Fix | Delete
}
[323] Fix | Delete
return fopen( $filename, $mode );
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
function feof( $fp ) {
[327] Fix | Delete
if ( $this->has_gzip ) {
[328] Fix | Delete
return gzeof( $fp );
[329] Fix | Delete
}
[330] Fix | Delete
return feof( $fp );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
function fgets( $fp, $len = 8192 ) {
[334] Fix | Delete
if ( $this->has_gzip ) {
[335] Fix | Delete
return gzgets( $fp, $len );
[336] Fix | Delete
}
[337] Fix | Delete
return fgets( $fp, $len );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
function fclose( $fp ) {
[341] Fix | Delete
if ( $this->has_gzip ) {
[342] Fix | Delete
return gzclose( $fp );
[343] Fix | Delete
}
[344] Fix | Delete
return fclose( $fp );
[345] Fix | Delete
}
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function