PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.15.0
Import WP – CSV & XML Import Export for WordPress v2.15.0
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
← All changes | class/Common/Exporter/Mapper/AbstractMapper.php +100 -1 2.7.1 → 2.15.0 View file →
@@ -5,11 +5,15 @@
5 5 abstract class AbstractMapper
6 6 {
7 7 protected $filters;
8 8 protected $record = [];
9 + public $records = [];
10 + public $items = [];
9 11
10 12 public function get_value($column, $template_data = null)
11 13 {
14 + // TODO: template_data should be class with arrayaccess to load data on demand.
15 +
12 16 if (is_null($template_data)) {
13 17 $template_data = $this->record();
14 18 }
15 19
@@ -62,8 +66,14 @@
62 66
63 67 foreach ($group as $row) {
64 68
65 69 $left = $this->get_value($row['left']);
70 +
71 + // left should always be a string
72 + if (is_array($left)) {
73 + $left = implode(',', $left);
74 + }
75 +
66 76 $right = $row['right'];
67 77 $right_parts = array_map('trim', explode(',', $right));
68 78
69 79 switch ($row['condition']) {
@@ -108,9 +118,98 @@
108 118
109 119 return $result;
110 120 }
111 121
112 - public function record()
122 + public function record($index = 0)
113 123 {
124 + if (isset($this->records[$index])) {
125 + return $this->records[$index];
126 + }
127 +
114 128 return $this->record;
129 + }
130 +
131 + public function get_records()
132 + {
133 + return $this->items;
134 + }
135 +
136 + public function set_records($records)
137 + {
138 + $this->items = $records;
139 + }
140 +
141 + public function modify_custom_field_data($custom_fields, $type)
142 + {
143 + $custom_file_fields = apply_filters('iwp/exporter/' . $type . '/custom_file_id_fields', []);
144 + if (!empty($custom_file_fields)) {
145 + foreach ($custom_file_fields as $custom_field) {
146 +
147 + if (!isset($custom_fields[$custom_field]) && !empty($custom_fields[$custom_field])) {
148 + continue;
149 + }
150 +
151 + $data = [
152 + 'id' => [],
153 + 'url' => [],
154 + 'title' => [],
155 + 'alt' => [],
156 + 'caption' => [],
157 + 'description' => [],
158 + ];
159 +
160 + foreach ($custom_fields[$custom_field] as $custom_field_value) {
161 +
162 + $custom_field_data = maybe_unserialize($custom_field_value);
163 + if (is_string($custom_field_data)) {
164 + $custom_field_data = explode(',', $custom_field_data);
165 + }
166 +
167 + if (empty($custom_field_data)) {
168 + continue;
169 + }
170 +
171 + foreach ($custom_field_data as $possible_attachment_id) {
172 +
173 + $attachment_id = intval($possible_attachment_id);
174 + if ($attachment_id === 0) {
175 + continue;
176 + }
177 +
178 + $attachment = get_post($attachment_id, ARRAY_A);
179 + $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
180 +
181 + $data['id'][] = $attachment_id;
182 + $data['url'][] = wp_get_attachment_url($attachment_id);
183 + $data['title'][] = $attachment['post_title'];
184 + $data['alt'][] = $alt;
185 + $data['caption'][] = $attachment['post_excerpt'];
186 + $data['description'][] = $attachment['post_content'];
187 + }
188 + }
189 +
190 + $custom_fields[$custom_field . '::id'] = $data['id'];
191 + $custom_fields[$custom_field . '::url'] = $data['url'];
192 + $custom_fields[$custom_field . '::title'] = $data['title'];
193 + $custom_fields[$custom_field . '::alt'] = $data['alt'];
194 + $custom_fields[$custom_field . '::caption'] = $data['caption'];
195 + $custom_fields[$custom_field . '::description'] = $data['description'];
196 + }
197 + }
198 +
199 + return $custom_fields;
200 + }
201 +
202 + public function parse_fields($fields)
203 + {
204 + $fields['fields'] = isset($fields['fields']) ? array_values($fields['fields']) : [];
205 +
206 + if (isset($fields['children']) && !empty($fields['fields'])) {
207 +
208 + foreach ($fields['children'] as $child_id => $child_data) {
209 + $fields['children'][$child_id] = $this->parse_fields($child_data);
210 + }
211 + }
212 +
213 + return $fields;
115 214 }
116 215 }