PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / full-site-import / Parsers / WXR_Parser.php

WXR_Parser.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/full-site-import/Parsers/WXR_Parser.php

53 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately\Modules\FullSiteImport\Parsers;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * WordPress extended RSS file parser implementations,
10 * Originally made by WordPress part of WordPress/Importer.
11 * https://plugins.trac.wordpress.org/browser/wordpress-importer/trunk/parsers/class-wxr-parser.php
12 *
13 * What was done (by Elementor):
14 * Reformat of the code.
15 * Changed text domain.
16 */
17
18 /**
19 * WordPress Importer class for managing parsing of WXR files.
20 */
21 class WXR_Parser {
22
23 public function parse( $file ) {
24 // Attempt to use proper XML parsers first.
25 // Note: WXR_Parser_SimpleXML relies on DOMDocument (the `dom` extension),
26 // which is DISTINCT from `simplexml` — a server can have one without the
27 // other. Require DOMDocument here so the chain falls through to the expat
28 // (`xml`) / always-available regex parser instead of fataling.
29 if ( extension_loaded( 'simplexml' ) && class_exists( 'DOMDocument' ) ) {
30 $parser = new WXR_Parser_SimpleXML();
31 $result = $parser->parse( $file );
32
33 // If SimpleXML succeeds or this is an invalid WXR file then return the results.
34 if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) {
35 return $result;
36 }
37 } elseif ( extension_loaded( 'xml' ) ) {
38 $parser = new WXR_Parser_XML();
39 $result = $parser->parse( $file );
40
41 // If XMLParser succeeds or this is an invalid WXR file then return the results.
42 if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) {
43 return $result;
44 }
45 }
46
47 // Use regular expressions if nothing else available or this is bad XML.
48 $parser = new WXR_Parser_Regex();
49
50 return $parser->parse( $file );
51 }
52 }
53