PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 All 201 releases
← All changes | includes/Admin/Importer/Parsers/WXR_Parser_XML.php +40 -33 3.4.2 → 4.9.3 View file →
@@ -157,11 +157,14 @@
157 157 xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
158 158 xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
159 159 xml_set_object( $xml, $this );
160 160
161 - xml_set_character_data_handler( $xml, function ( $parser, $cdata ) {
162 - $this->cdata( $cdata );
163 - } );
161 + xml_set_character_data_handler(
162 + $xml,
163 + function ( $parser, $cdata ) {
164 + $this->cdata( $cdata );
165 + }
166 + );
164 167
165 168 $tag_open_callback = function ( $parse, $tag, $attr ) {
166 169 $this->tag_open( $tag, $attr );
167 170 };
@@ -172,18 +175,22 @@
172 175
173 176 xml_set_element_handler( $xml, $tag_open_callback, $tag_close_callback );
174 177
175 178 if ( ! xml_parse( $xml, Utils::file_get_contents( $file ), true ) ) {
176 - $current_line = xml_get_current_line_number( $xml );
179 + $current_line = xml_get_current_line_number( $xml );
177 180 $current_column = xml_get_current_column_number( $xml );
178 - $error_code = xml_get_error_code( $xml );
179 - $error_string = xml_error_string( $error_code );
181 + $error_code = xml_get_error_code( $xml );
182 + $error_string = xml_error_string( $error_code );
180 183
181 - return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', [
182 - $current_line,
183 - $current_column,
184 - $error_string,
185 - ] );
184 + return new WP_Error(
185 + 'XML_parse_error',
186 + 'There was an error when reading this WXR file',
187 + [
188 + $current_line,
189 + $current_column,
190 + $error_string,
191 + ]
192 + );
186 193 }
187 194 xml_parser_free( $xml );
188 195
189 196 if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) {
@@ -190,16 +197,16 @@
190 197 return new WP_Error( 'WXR_parse_error', esc_html__( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'betterdocs' ) );
191 198 }
192 199
193 200 return array(
194 - 'authors' => $this->authors,
195 - 'posts' => $this->posts,
196 - 'categories' => $this->category,
197 - 'tags' => $this->tag,
198 - 'terms' => $this->term,
199 - 'base_url' => $this->base_url,
201 + 'authors' => $this->authors,
202 + 'posts' => $this->posts,
203 + 'categories' => $this->category,
204 + 'tags' => $this->tag,
205 + 'terms' => $this->term,
206 + 'base_url' => $this->base_url,
200 207 'base_blog_url' => $this->base_blog_url,
201 - 'version' => $this->wxr_version,
208 + 'version' => $this->wxr_version,
202 209 );
203 210 }
204 211
205 212 private function tag_open( $tag, $attr ) {
@@ -218,9 +225,9 @@
218 225 switch ( $tag ) {
219 226 case 'category':
220 227 if ( isset( $attr['domain'], $attr['nicename'] ) ) {
221 228 $this->sub_data['domain'] = $attr['domain'];
222 - $this->sub_data['slug'] = $attr['nicename'];
229 + $this->sub_data['slug'] = $attr['nicename'];
223 230 }
224 231 break;
225 232 case 'item':
226 233 $this->in_post = true;
@@ -277,9 +284,9 @@
277 284 $this->sub_data = [];
278 285 break;
279 286 case 'wp:commentmeta':
280 287 $this->sub_data['commentmeta'][] = [
281 - 'key' => $this->sub_data['key'],
288 + 'key' => $this->sub_data['key'],
282 289 'value' => $this->sub_data['value'],
283 290 ];
284 291 break;
285 292 case 'category':
@@ -284,9 +291,9 @@
284 291 break;
285 292 case 'category':
286 293 if ( ! empty( $this->sub_data ) ) {
287 294 $this->sub_data['name'] = $this->cdata;
288 - $this->data['terms'][] = $this->sub_data;
295 + $this->data['terms'][] = $this->sub_data;
289 296 }
290 297 $this->sub_data = [];
291 298 break;
292 299 case 'wp:postmeta':
@@ -296,9 +303,9 @@
296 303 $this->sub_data = [];
297 304 break;
298 305 case 'item':
299 306 $this->posts[] = $this->data;
300 - $this->data = [];
307 + $this->data = [];
301 308 break;
302 309 case 'wp:category':
303 310 case 'wp:tag':
304 311 case 'wp:term':
@@ -333,12 +340,12 @@
333 340
334 341 default:
335 342 if ( $this->in_sub_tag ) {
336 343 $this->sub_data[ $this->in_sub_tag ] = $this->cdata;
337 - $this->in_sub_tag = false;
338 - } else if ( $this->in_tag ) {
344 + $this->in_sub_tag = false;
345 + } elseif ( $this->in_tag ) {
339 346 $this->data[ $this->in_tag ] = $this->cdata;
340 - $this->in_tag = false;
347 + $this->in_tag = false;
341 348 }
342 349 }
343 350
344 351 $this->cdata = '';
@@ -346,19 +353,19 @@
346 353
347 354 private function clear() {
348 355 $this->wxr_version = '';
349 356
350 - $this->cdata = '';
351 - $this->data = [];
357 + $this->cdata = '';
358 + $this->data = [];
352 359 $this->sub_data = [];
353 360
354 - $this->in_post = false;
355 - $this->in_tag = false;
361 + $this->in_post = false;
362 + $this->in_tag = false;
356 363 $this->in_sub_tag = false;
357 364
358 - $this->authors = [];
359 - $this->posts = [];
360 - $this->term = [];
365 + $this->authors = [];
366 + $this->posts = [];
367 + $this->term = [];
361 368 $this->category = [];
362 - $this->tag = [];
369 + $this->tag = [];
363 370 }
364 371 }