PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.4.11
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.4.11
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / libraries / XmlExportCustomRecord.php
wp-all-export / libraries Last commit date
VariableProductTitle 9 years ago .gitkeep 11 years ago WpaeInvalidPhpException.php 9 years ago WpaeInvalidStringException.php 9 years ago WpaeMethodNotFoundException.php 9 years ago WpaePhpInterpreterErrorHandler.php 2 years ago WpaeString.php 9 years ago WpaeTooMuchRecursionException.php 9 years ago XmlCsvExport.php 2 years ago XmlExportCpt.php 1 year ago XmlExportCustomRecord.php 1 year ago XmlExportEngine.php 2 years ago XmlExportFiltering.php 4 years ago XmlExportMediaGallery.php 3 years ago XmlExportTaxonomy.php 4 years ago
XmlExportCustomRecord.php
326 lines
1 <?php
2
3 if (!class_exists('XmlExportCustomRecord')) {
4 final class XmlExportCustomRecord {
5
6 private $default_fields = [];
7
8 private $author_fields = [];
9
10 private $other_fields = [];
11
12 private $parent_fields = [];
13
14 private $advanced_fields = [];
15
16 public static $is_active = true;
17
18 public function __construct() {
19 if (XmlExportEngine::$exportOptions['export_type'] == 'specific' and strpos(XmlExportEngine::$exportOptions['cpt'][0], 'custom_') !== 0) {
20 self::$is_active = false;
21 return;
22 }
23
24 do_action('pmxe_custom_record_export', XmlExportEngine::$exportOptions);
25 }
26
27
28 // [\FILTERS]
29
30 public function init(& $existing_meta_keys = array()) {
31 if (!self::$is_active) return;
32
33 if(PMXE_Plugin::$session->get('exportQuery') && !XmlExportEngine::$exportQuery) {
34 XmlExportEngine::$exportQuery = PMXE_Plugin::$session->get('exportQuery');
35 }
36 }
37
38 public static function prepare_data($record, $exportOptions, $xmlWriter, $implode_delimiter, $preview) {
39 $article = array();
40
41 if (wp_all_export_is_compatible() && isset($exportOptions['is_generate_import']) && $exportOptions['is_generate_import'] && $exportOptions['import_id']) {
42 $postRecord = new PMXI_Post_Record();
43 $postRecord->clear();
44 $postRecord->getBy(array(
45 'post_id' => $record->id,
46 'import_id' => $exportOptions['import_id'],
47 ));
48
49 if ($postRecord->isEmpty()) {
50 $postRecord->set(array(
51 'post_id' => $record->id,
52 'import_id' => $exportOptions['import_id'],
53 'unique_key' => $record->id
54 ))->save();
55 }
56 unset($postRecord);
57 }
58
59 $is_xml_export = false;
60
61 if (
62 !empty($xmlWriter) &&
63 isset($exportOptions['export_to']) &&
64 $exportOptions['export_to'] == 'xml' &&
65 !in_array($exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')))
66 {
67 $is_xml_export = true;
68 }
69
70 foreach ($exportOptions['ids'] as $ID => $value) {
71 $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name($exportOptions['cc_name'][$ID]), $ID);
72 $fieldValue = $exportOptions['cc_value'][$ID];
73 $fieldLabel = $exportOptions['cc_label'][$ID];
74 $fieldSql = $exportOptions['cc_sql'][$ID];
75 $fieldPhp = $exportOptions['cc_php'][$ID];
76 $fieldCode = $exportOptions['cc_code'][$ID];
77 $fieldType = $exportOptions['cc_type'][$ID];
78 $fieldOptions = isset($exportOptions['cc_options']) ? $exportOptions['cc_options'][$ID] : [];
79 $fieldSettings = empty($exportOptions['cc_settings'][$ID]) ? $fieldOptions : $exportOptions['cc_settings'][$ID];
80
81 if (empty($fieldName) or empty($fieldType) or !is_numeric($ID)) continue;
82
83 $element_name = (!empty($fieldName)) ? $fieldName : 'untitled_' . $ID;
84
85 $element_name_ns = '';
86
87 if ($is_xml_export) {
88 //$element_name = (!empty($fieldName)) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID;
89
90 if (strpos($element_name, ":") !== false) {
91 $element_name_parts = explode(":", $element_name);
92 $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0];
93 $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]);
94 }
95 }
96
97 $fieldSnipped = (!empty($fieldPhp) and !empty($fieldCode)) ? $fieldCode : false;
98
99 if (isset($exportOptions['cc_combine_multiple_fields'][$ID]) && $exportOptions['cc_combine_multiple_fields'][$ID]) {
100
101 } else {
102
103 $addon = GF_Export_Add_On::get_instance();
104 $addon->add_on->handle_element($article, $element_name, $fieldValue, $record, $fieldSnipped, $preview);
105
106 }
107
108 if ($is_xml_export and isset($article[$element_name])) {
109
110 $element_name_in_file = XmlCsvExport::_get_valid_header_name($element_name);
111
112 $element_name_in_file = str_replace(' ', '', $element_name_in_file);
113 $element_name_in_file = str_replace('-', '_', $element_name_in_file);
114 $element_name_in_file = str_replace('/', '_', $element_name_in_file);
115
116 if(is_numeric(substr($element_name_in_file, 0, 1))){
117 $element_name_in_file = 'prepend_' . $element_name_in_file;
118 }
119
120 $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $record->id);
121
122 $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null);
123 $xmlWriter->writeData($article[$element_name], $element_name_in_file);
124 $xmlWriter->closeElement();
125
126 $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $record->id);
127
128 }
129 }
130
131 return $article;
132 }
133
134 public static function prepare_import_template( $exportOptions, &$templateOptions, $element_name, $ID) {
135
136 $rapid_addon = \GF_Export_Add_On::get_instance()->add_on;
137
138 $element_slug = $exportOptions['cc_label'][$ID];
139
140 $element_location = $rapid_addon->get_element_location($element_slug);
141
142 $element_data = $rapid_addon->get_data_element_by_slug($element_slug);
143
144 if($element_location === 'meta') {
145
146 if(isset($element_data['consent']) && $element_data['consent']) {
147
148 $element_name_in_file = $element_data['element_meta_key'];
149 $element_name_in_file = explode(".", $element_name_in_file);
150 $element_name_in_file = $element_name_in_file[0];
151
152 if($exportOptions['export_to'] === 'csv') {
153 $templateOptions['pmgi']['fields'][$element_name_in_file] = '{consentconsent[1]}';
154 $templateOptions['pmgi']['is_multiple_field_value'][$element_name_in_file] = 'no';
155 }
156 else {
157 $templateOptions['pmgi']['fields'][$element_name_in_file] = '{Consent_Consent[1]}';
158 $templateOptions['pmgi']['is_multiple_field_value'][$element_name_in_file] = 'no';
159 }
160 } else {
161 if ($exportOptions['export_to'] === 'csv') {
162
163 $element_value = '{' . $element_name . '[1]}';
164
165 if (isset($templateOptions['pmgi']['fields']) && is_array($templateOptions['pmgi']['fields']) && in_array($element_value, $templateOptions['pmgi']['fields'])) {
166 $field_order = 2;
167
168 while (in_array('{' . $element_name . '_' . $field_order . '[1]}', $templateOptions['pmgi']['fields'])) {
169 $field_order++;
170 }
171
172 $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = '{' . $element_name . '_' . $field_order . '[1]}';
173 } else {
174 $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = $element_value;
175 }
176
177 $templateOptions['pmgi']['is_multiple_field_value'][$element_data['element_meta_key']] = 'no';
178
179 } else {
180
181
182 $element_name = str_replace(' ', '', $element_data['element_label']);
183
184 $element_name = str_replace(['-', '/'], '-', $element_name);
185
186 $i = 1;
187
188 if(isset($templateOptions['pmgi']['fields']) && is_array($templateOptions['pmgi']['fields'])) {
189 while (in_array('{' . $element_name . '[' . $i . ']}', $templateOptions['pmgi']['fields'])) {
190 $i++;
191 }
192 }
193
194 $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = '{' . str_replace('-', '_', $element_name) . '[' . $i . ']}';
195 $templateOptions['pmgi']['is_multiple_field_value'][$element_data['element_meta_key']] = 'no';
196
197 }
198 }
199
200
201 } else if ($element_location === 'related_table') {
202
203 switch ($element_slug) {
204
205 case 'user_name':
206 $templateOptions['pmgi']['notes'][0]['username'] = '{' . $element_name . '[1]}';
207 break;
208
209 case 'value':
210 $templateOptions['pmgi']['notes'][0]['note_text'] = '{' . $element_name . '[1]}';
211 break;
212
213 case 'note_type':
214 $templateOptions['pmgi']['notes'][0]['note_type'] = '{' . $element_name . '[1]}';
215 break;
216
217 case 'sub_type':
218 $templateOptions['pmgi']['notes'][0]['note_sub_type'] = '{' . $element_name . '[1]}';
219 break;
220
221 }
222
223 if(strpos($element_slug, 'date_created') === 0) {
224 $templateOptions['pmgi']['notes'][0]['date'] = '{' . $element_name . '[1]}';
225
226 }
227
228 } else if ($element_location === 'main_table') {
229
230 if($exportOptions['export_to'] === 'csv') {
231
232 $other_entry_data = [
233 'datecreated',
234 'dateupdated',
235 'starred',
236 'read',
237 'ip',
238 'sourceurl',
239 'useragent',
240 'createdbyuserid',
241 'status'
242 ];
243 } else {
244 $other_entry_data = [
245 'DateCreated',
246 'DateUpdated',
247 'Starred',
248 'Read',
249 'IP',
250 'SourceURL',
251 'UserAgent',
252 'CreatedByUserID',
253 'Status'
254 ];
255 }
256
257 if(in_array($element_name, $other_entry_data)) {
258
259 if($element_name === 'sourceurl' || $element_name === 'SourceURL') {
260 $wpai_element_name = 'source_url';
261 } else if ($element_name === 'useragent' || $element_name === 'UserAgent') {
262 $wpai_element_name = 'user_agent';
263 } else if ($element_name === 'createdbyuserid' || $element_name === 'CreatedByUserID') {
264 $wpai_element_name = 'created_by';
265 }
266 else if ($element_name === 'datecreated' || $element_name === 'DateCreated') {
267 $wpai_element_name = 'date_created';
268 }
269 else if ($element_name === 'dateupdated' || $element_name === 'DateUpdated') {
270 $wpai_element_name = 'date_updated';
271 }
272
273 else {
274 $wpai_element_name = str_replace('_', '', strtolower($element_name));
275 }
276
277 if(in_array($element_name, ['starred', 'read', 'status']) || in_array($element_name, ['Starred', 'Read', 'Status'])) {
278 $templateOptions['pmgi'][strtolower($wpai_element_name)] = 'xpath';
279 $templateOptions['pmgi'][strtolower($element_name). "_xpath"] = '{' . $element_name . '[1]}';
280 } else {
281 $templateOptions['pmgi'][strtolower($wpai_element_name)] = '{' . $element_name . '[1]}';
282 $templateOptions['is_update_' . $exportOptions['cc_type'][$ID]] = 1;
283 }
284
285 }
286
287 if ($element_name === 'id'){
288
289 if ($element_name == 'ID' && !$ID && $exportOptions['export_to'] == 'csv' && $exportOptions['export_to_sheet'] != 'csv') {
290 $element_name = 'id';
291 }
292
293 $templateOptions['unique_key'] = '{' . $element_name . '[1]}';
294 $templateOptions['tmp_unique_key'] = '{' . $element_name . '[1]}';
295 $templateOptions['single_product_id'] = '{' . $element_name . '[1]}';
296 }
297 }
298
299 return;
300 }
301
302 /**
303 * __get function.
304 *
305 * @access public
306 * @param mixed $key
307 * @return mixed
308 */
309 public function __get($key) {
310 return $this->get($key);
311 }
312
313 /**
314 * Get a session variable
315 *
316 * @param string $key
317 * @param mixed $default used if the session variable isn't set
318 * @return mixed value of session variable
319 */
320 public function get($key, $default = null) {
321 return isset($this->{$key}) ? $this->{$key} : $default;
322 }
323
324 }
325 }
326