PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.12
Import WP – CSV & XML Import Export for WordPress v2.7.12
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.12, at class/Common/Exporter/Mapper/AbstractMapper.php

133 lines 3.5 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 public $records = [];
10 public $items = [];
11
12 public function get_value($column, $template_data = null)
13 {
14 if (is_null($template_data)) {
15 $template_data = $this->record();
16 }
17
18 $parts = explode('.', $column);
19 if (count($parts) == 2) {
20
21 // handle looped data
22 if (isset($template_data[$parts[0]], $template_data[$parts[0]][0], $template_data[$parts[0]][0][$parts[1]])) {
23 return array_reduce($template_data[$parts[0]], function ($carry, $item) use ($parts) {
24 if (isset($item[$parts[1]])) {
25 $carry[] = $item[$parts[1]];
26 }
27 return $carry;
28 }, []);
29 }
30
31 // handled grouped data or single
32 return isset($template_data[$parts[0]], $template_data[$parts[0]][$parts[1]]) ? $template_data[$parts[0]][$parts[1]] : '';
33 }
34
35 return isset($template_data[$column]) ? $template_data[$column] : '';
36 }
37
38 public function set_filters($filters = [])
39 {
40 $this->filters = $filters;
41 }
42
43 /**
44 * Filter record
45 *
46 * @param array $post
47 * @return boolean
48 */
49 public function filter()
50 {
51 $result = false;
52
53 if (empty($this->filters)) {
54 return $result;
55 }
56
57 foreach ($this->filters as $group) {
58
59 $result = true;
60
61 if (empty($group)) {
62 continue;
63 }
64
65 foreach ($group as $row) {
66
67 $left = $this->get_value($row['left']);
68 $right = $row['right'];
69 $right_parts = array_map('trim', explode(',', $right));
70
71 switch ($row['condition']) {
72 case 'equal':
73 if ($left != $right) {
74 $result = false;
75 }
76 break;
77 case 'contains':
78 if (stripos($left, $right) === false) {
79 $result = false;
80 }
81 break;
82 case 'in':
83 if (!in_array($left, $right_parts)) {
84 $result = false;
85 }
86 break;
87 case 'not-equal':
88 if ($left == $right) {
89 $result = false;
90 }
91 break;
92 case 'not-contains':
93 if (stripos($left, $right) !== false) {
94 $result = false;
95 }
96 break;
97 case 'not-in':
98 if (in_array($left, $right_parts)) {
99 $result = false;
100 }
101 break;
102 }
103 }
104
105 if ($result) {
106 return true;
107 }
108 }
109
110
111 return $result;
112 }
113
114 public function record($index = 0)
115 {
116 if (isset($this->records[$index])) {
117 return $this->records[$index];
118 }
119
120 return $this->record;
121 }
122
123 public function get_records()
124 {
125 return $this->items;
126 }
127
128 public function set_records($records)
129 {
130 $this->items = $records;
131 }
132 }
133