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