PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.3
Import WP – CSV & XML Import Export for WordPress v2.7.3
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Exporter / Mapper / AbstractMapper.php

AbstractMapper.php in Import WP – CSV & XML Import Export for WordPress 2.7.3, at class/Common/Exporter/Mapper/AbstractMapper.php

117 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Exporter\Mapper;
4
5 abstract class AbstractMapper
6 {
7 protected $filters;
8 protected $record = [];
9
10 public function get_value($column, $template_data = null)
11 {
12 if (is_null($template_data)) {
13 $template_data = $this->record();
14 }
15
16 $parts = explode('.', $column);
17 if (count($parts) == 2) {
18
19 // handle looped data
20 if (isset($template_data[$parts[0]], $template_data[$parts[0]][0], $template_data[$parts[0]][0][$parts[1]])) {
21 return array_reduce($template_data[$parts[0]], function ($carry, $item) use ($parts) {
22 if (isset($item[$parts[1]])) {
23 $carry[] = $item[$parts[1]];
24 }
25 return $carry;
26 }, []);
27 }
28
29 // handled grouped data or single
30 return isset($template_data[$parts[0]], $template_data[$parts[0]][$parts[1]]) ? $template_data[$parts[0]][$parts[1]] : '';
31 }
32
33 return isset($template_data[$column]) ? $template_data[$column] : '';
34 }
35
36 public function set_filters($filters = [])
37 {
38 $this->filters = $filters;
39 }
40
41 /**
42 * Filter record
43 *
44 * @param array $post
45 * @return boolean
46 */
47 public function filter()
48 {
49 $result = false;
50
51 if (empty($this->filters)) {
52 return $result;
53 }
54
55 foreach ($this->filters as $group) {
56
57 $result = true;
58
59 if (empty($group)) {
60 continue;
61 }
62
63 foreach ($group as $row) {
64
65 $left = $this->get_value($row['left']);
66 $right = $row['right'];
67 $right_parts = array_map('trim', explode(',', $right));
68
69 switch ($row['condition']) {
70 case 'equal':
71 if ($left != $right) {
72 $result = false;
73 }
74 break;
75 case 'contains':
76 if (stripos($left, $right) === false) {
77 $result = false;
78 }
79 break;
80 case 'in':
81 if (!in_array($left, $right_parts)) {
82 $result = false;
83 }
84 break;
85 case 'not-equal':
86 if ($left == $right) {
87 $result = false;
88 }
89 break;
90 case 'not-contains':
91 if (stripos($left, $right) !== false) {
92 $result = false;
93 }
94 break;
95 case 'not-in':
96 if (in_array($left, $right_parts)) {
97 $result = false;
98 }
99 break;
100 }
101 }
102
103 if ($result) {
104 return true;
105 }
106 }
107
108
109 return $result;
110 }
111
112 public function record()
113 {
114 return $this->record;
115 }
116 }
117