PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / trunk
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets vtrunk
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / addon-api / classes / parser.php
wp-all-import / addon-api / classes Last commit date
admin.php 3 weeks ago base.php 3 weeks ago data-importer.php 3 weeks ago helpers.php 3 weeks ago importer.php 3 weeks ago manager.php 3 weeks ago parser.php 3 weeks ago post-data-importer.php 3 weeks ago rest.php 3 weeks ago updater.php 3 weeks ago view.php 3 weeks ago
parser.php
97 lines
1 <?php
2
3 namespace Wpai\AddonAPI;
4
5 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 class PMXI_Addon_Parser {
8 use Singleton;
9
10 public PMXI_Addon_Base $addon;
11 public array $options;
12 public array $data = [];
13 public array $defaults;
14
15 public function __construct(
16 $addon,
17 $options,
18 $defaults
19 ) {
20 $this->addon = $addon;
21 $this->options = $options;
22 $this->defaults = $defaults;
23 }
24
25 public function transformArray( $xml, $cxpath, $value ) {
26 $data = [];
27 foreach ( $value as $key => $v ) {
28 if ( is_string( $v ) && $v != "" ) {
29 $data[ $key ] = \XmlImportParser::factory( $xml, $cxpath, (string) $v, $file )->parse();
30 $tmp_files[] = $file;
31 } elseif ( is_array( $v ) ) {
32 $data[ $key ] = $this->transformArray( $xml, $cxpath, $v );
33 }
34 }
35
36 return $data;
37 }
38
39 /**
40 * Parse xpath variables to the specified variable in the import file if needed
41 * Extracted from https://github.com/soflyy/wp-all-import-rapid-addon/blob/master/rapid-addon.php#L985
42 */
43 public function transform() {
44 extract( $this->options );
45
46 $data = [];
47 $slug = $this->addon->slug;
48 $values = $import->options[ $slug ] ?? [];
49
50 if ( empty( $values ) ) {
51 return $this;
52 }
53
54 $cxpath = $xpath_prefix . $import->xpath;
55 $tmp_files = [];
56
57 foreach ( $this->defaults[ $slug ] as $option_name => $option_value ) {
58 if ( isset( $values[ $option_name ] ) and $values[ $option_name ] != '' ) {
59 $value = $values[ $option_name ];
60 if ( $value == "xpath" ) {
61 if ( $values['xpaths'][ $option_name ] == "" ) {
62 $count and $data[ $option_name ] = array_fill( 0, $count, "" );
63 } else {
64 $data[ $option_name ] = \XmlImportParser::factory( $xml, $cxpath, (string) $values['xpaths'][ $option_name ], $file )->parse();
65 $tmp_files[] = $file;
66 }
67 } else if ( is_array( $value ) ) {
68 $data[ $option_name ] = $this->transformArray( $xml, $cxpath, $value );
69 } else {
70 $data[ $option_name ] = \XmlImportParser::factory( $xml, $cxpath, (string) $value, $file )->parse();
71 $tmp_files[] = $file;
72 }
73 } else {
74 $data[ $option_name ] = array_fill( 0, $count, "" );
75 }
76 }
77
78 foreach ( $tmp_files as $file ) {
79 wp_delete_file( $file );
80 }
81
82 $this->data = $data;
83
84 return $this;
85 }
86
87 public function toArray() {
88 return $this->data;
89 }
90
91 public static function from( PMXI_Addon_Base $addon, array $data, array $defaults ) {
92 $parser = new static( $addon, $data, $defaults );
93
94 return $parser->transform()->toArray();
95 }
96 }
97