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 / controllers / admin / export.php
wp-all-export / controllers / admin Last commit date
export.php 3 weeks ago feedback.php 10 years ago help.php 12 years ago manage.php 3 weeks ago partners.php 3 weeks ago settings.php 3 weeks ago
export.php
602 lines
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5
6 /**
7 * Export configuration wizard
8 *
9 * @author Max Tsiplyakov <makstsiplyakov@gmail.com>
10 */
11 #[\AllowDynamicProperties]
12 class PMXE_Admin_Export extends PMXE_Controller_Admin
13 {
14
15 protected $isWizard = true; // indicates whether controller is in wizard mode (otherwise it called to be delegated an edit action)
16
17 protected function init()
18 {
19
20 parent::init();
21
22 if ('PMXE_Admin_Manage' == PMXE_Plugin::getInstance()->getAdminCurrentScreen()->base) { // prereqisites are not checked when flow control is deligated
23 $id = $this->input->get('id');
24 $this->data['export'] = $export = new PMXE_Export_Record();
25 if (!$id or $export->getById($id)->isEmpty()) { // specified import is not found
26 wp_safe_redirect(esc_url_raw(add_query_arg('page', 'pmxe-admin-manage', admin_url('admin.php'))));
27 die();
28 }
29 $this->isWizard = false;
30 $export->fix_template_options();
31 } else {
32 $action = PMXE_Plugin::getInstance()->getAdminCurrentScreen()->action;
33 $this->_step_ready($action);
34 }
35
36 // preserve id parameter as part of baseUrl
37 $id = $this->input->get('id') and $this->baseUrl = esc_url_raw(add_query_arg('id', $id, $this->baseUrl));
38
39 }
40
41 public function set($var, $val)
42 {
43 $this->{$var} = $val;
44 }
45
46 public function get($var)
47 {
48 return $this->{$var};
49 }
50
51 /**
52 * Checks whether corresponding step of wizard is complete
53 * @param string $action
54 * @return bool
55 */
56 protected function _step_ready($action)
57 {
58
59 // step #1: xml selction - has no prerequisites
60 if ('index' == $action) return true;
61
62 if ('element' == $action) return true;
63
64 $this->data['update_previous'] = $update_previous = new PMXE_Export_Record();
65
66 $update_previous->getById(PMXE_Plugin::$session->update_previous);
67
68 if (!$update_previous->isEmpty()) {
69 $update_previous->fix_template_options();
70 }
71
72 if ('options' == $action) return true;
73
74 if (!PMXE_Plugin::$session->has_session()) {
75 wp_redirect_or_javascript($this->baseUrl);
76 die();
77 }
78
79 if ('process' == $action) return true;
80
81 }
82
83 /**
84 * Step #1: Choose CPT
85 */
86 public function index()
87 {
88 if ($this->input->post('is_submitted')) {
89 check_admin_referer('choose-cpt', '_wpnonce_choose-cpt');
90 }
91
92 $action = $this->input->get('action');
93
94 $DefaultOptions = array(
95 'cpt' => '',
96 'export_to' => 'xml',
97 'export_type' => 'specific',
98 'wp_query' => '',
99 'filter_rules_hierarhy' => '',
100 'product_matching_mode' => 'strict',
101 'wp_query_selector' => 'wp_query',
102 'auto_generate' => 0,
103 'taxonomy_to_export' => '',
104 'sub_post_type_to_export' => '',
105 'created_at_version' => PMXE_VERSION
106 );
107
108 if (!in_array($action, array('index'))) {
109 PMXE_Plugin::$session->clean_session();
110 $this->data['preload'] = false;
111 } else {
112 $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $DefaultOptions;
113 $this->data['preload'] = true;
114 }
115
116 $this->data['post'] = $post = $this->input->post($DefaultOptions);
117
118 if (is_array($this->data['post']['cpt'])) $this->data['post']['cpt'] = $this->data['post']['cpt'][0];
119
120 // Delete history
121 if(is_dir(PMXE_ROOT_DIR.'/history')) {
122 $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH);
123 if (!empty($history_files)) {
124 foreach ($history_files as $filePath) {
125 @file_exists($filePath) and wp_delete_file($filePath);
126 }
127 }
128 }
129
130 if (!class_exists('XMLReader') or !class_exists('XMLWriter')) {
131 $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Export requires XMLReader, and XMLWriter PHP modules to be installed.<br/>These are standard features of PHP, and are necessary for WP All Export to write the files you are trying to export.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp-all-export'));
132 }
133
134 if ($this->input->post('is_submitted')) {
135
136 PMXE_Plugin::$session->set('export_type', $post['export_type']);
137 PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']);
138 PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']);
139 PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']);
140 PMXE_Plugin::$session->set('taxonomy_to_export', $post['taxonomy_to_export']);
141 PMXE_Plugin::$session->set('created_at_version', $post['created_at_version']);
142 PMXE_Plugin::$session->set('sub_post_type_to_export', $post['sub_post_type_to_export']);
143
144 if (!empty($post['auto_generate'])) {
145 $auto_generate = XmlCsvExport::auto_generate_export_fields($post, $this->errors);
146
147 foreach ($auto_generate as $key => $value) {
148 PMXE_Plugin::$session->set($key, $value);
149 }
150
151 PMXE_Plugin::$session->save_data();
152 } else {
153 $engine = new XmlExportEngine($post, $this->errors);
154 $engine->init_additional_data();
155 }
156 }
157
158 if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) {
159
160 PMXE_Plugin::$session->save_data();
161
162 if (!empty($post['auto_generate'])) {
163 wp_safe_redirect(esc_url_raw(add_query_arg(['action' => 'options','_wpnonce_options' => wp_create_nonce('options')], $this->baseUrl)));
164 die();
165 } else {
166 wp_safe_redirect(esc_url_raw(add_query_arg(['action' => 'template','_wpnonce_template' => wp_create_nonce('template')], $this->baseUrl)));
167 die();
168 }
169
170 }
171
172 $this->render();
173 }
174
175 /**
176 * Step #2: Export Template
177 */
178 public function template()
179 {
180
181 check_admin_referer( 'template', '_wpnonce_template' );
182
183
184 $template = new PMXE_Template_Record();
185
186 $default = PMXE_Plugin::get_default_import_options();
187
188 $this->data['dismiss_warnings'] = 0;
189
190 if ($this->isWizard) {
191 // New export
192 $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default;
193 $post = $this->input->post($DefaultOptions);
194 } else {
195 // Edit export
196 $DefaultOptions = $this->data['export']->options + $default;
197
198 if (empty($this->data['export']->options['export_variations'])) {
199 $DefaultOptions['export_variations'] = XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
200 }
201 if (empty($this->data['export']->options['export_variations_title'])) {
202 $DefaultOptions['export_variations_title'] = XmlExportEngine::VARIATION_USE_DEFAULT_TITLE;
203 }
204 $post = $this->input->post($DefaultOptions);
205 $post['scheduled'] = $this->data['export']->scheduled;
206
207 foreach ($post as $key => $value) {
208 PMXE_Plugin::$session->set($key, $value);
209 }
210 $this->data['dismiss_warnings'] = get_option('wpae_dismiss_warnings_' . $this->data['export']->id, 0);
211 }
212
213 $max_input_vars = @ini_get('max_input_vars');
214
215 if (ctype_digit($max_input_vars) && count($_POST, COUNT_RECURSIVE) >= $max_input_vars) {
216 /* translators: %d: max_input_vars limit value */
217 $this->errors->add('form-validation', sprintf(__('You\'ve reached your max_input_vars limit of %d. Please contact your web host to increase it.', 'wp-all-export'), $max_input_vars));
218 }
219
220 PMXE_Plugin::$session->save_data();
221
222 $this->data['post'] =& $post;
223
224 PMXE_Plugin::$session->set('is_loaded_template', '');
225
226 $this->data['engine'] = null;
227
228 XmlExportEngine::$exportQuery = PMXE_Plugin::$session->get('exportQuery');
229
230 if (($load_template = $this->input->post('load_template'))) { // init form with template selected
231 if (!$template->getById($load_template)->isEmpty()) {
232 $template_options = $template->options;
233 unset($template_options['cpt']);
234 unset($template_options['wp_query']);
235 unset($template_options['filter_rules_hierarhy']);
236 unset($template_options['product_matching_mode']);
237 unset($template_options['wp_query_selector']);
238 $this->data['post'] = array_merge($post, $template_options);
239 PMXE_Plugin::$session->set('is_loaded_template', $load_template);
240 }
241
242 } elseif ($this->input->post('is_submitted')) {
243
244 if (empty($post['cc_type'][0]) && !in_array($post['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
245 $this->errors->add('form-validation', __('You haven\'t selected any columns for export.', 'wp-all-export'));
246 }
247
248 if ('csv' == $post['export_to'] and '' == $post['delimiter']) {
249 $this->errors->add('form-validation', __('CSV delimiter must be specified.', 'wp-all-export'));
250 }
251
252 if ('xml' == $post['export_to'] && !in_array($post['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
253 $post['main_xml_tag'] = preg_replace('/[^a-z0-9_]/i', '', $post['main_xml_tag']);
254 if (empty($post['main_xml_tag'])) {
255 $this->errors->add('form-validation', __('Main XML Tag is required.', 'wp-all-export'));
256 }
257
258 $post['record_xml_tag'] = preg_replace('/[^a-z0-9_]/i', '', $post['record_xml_tag']);
259 if (empty($post['record_xml_tag'])) {
260 $this->errors->add('form-validation', __('Single Record XML Tag is required.', 'wp-all-export'));
261 }
262
263 if ($post['main_xml_tag'] == $post['record_xml_tag']) {
264 $this->errors->add('form-validation', __('Main XML Tag equals to Single Record XML Tag.', 'wp-all-export'));
265 }
266 }
267
268 if (($post['export_to'] == XmlExportEngine::EXPORT_TYPE_XML) && in_array($post['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
269
270 if (empty($post['custom_xml_template'])) {
271 $this->errors->add('form-validation', __('XML template is empty.', 'wp-all-export'));
272 }
273
274 // Convert Custom XML template to default
275 if (!empty($post['custom_xml_template'])) {
276
277 $post['custom_xml_template'] = str_replace('<ID>', '<id>', $post['custom_xml_template']);
278 $post['custom_xml_template'] = str_replace('</ID>', '</id>', $post['custom_xml_template']);
279
280 $post['custom_xml_template'] = str_replace("<!-- BEGIN POST LOOP -->", "<!-- BEGIN LOOP -->", $post['custom_xml_template']);
281 $post['custom_xml_template'] = str_replace("<!-- END POST LOOP -->", "<!-- END LOOP -->", $post['custom_xml_template']);
282
283 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
284
285 $this->data['engine']->init_additional_data();
286
287 $this->data = array_merge($this->data, $this->data['engine']->init_available_data());
288
289 $result = $this->data['engine']->parse_custom_xml_template();
290
291 if (!$this->errors->get_error_codes()) {
292 $post = array_merge($post, $result);
293 }
294 }
295 }
296
297 if (!$this->errors->get_error_codes()) {
298
299 if (!empty($post['name']) and !empty($post['save_template_as'])) { // save template in database
300 $template->getByName($post['name'])->set(array(
301 'name' => $post['name'],
302 'options' => $post
303 ))->save();
304 PMXE_Plugin::$session->set('saved_template', $template->id);
305 }
306
307 if ($this->isWizard) {
308 foreach ($this->data['post'] as $key => $value) {
309 PMXE_Plugin::$session->set($key, $value);
310 }
311 PMXE_Plugin::$session->save_data();
312 wp_safe_redirect(esc_url_raw(add_query_arg(['action' => 'options','_wpnonce_options' => wp_create_nonce('options')], $this->baseUrl)));
313 die();
314 } else {
315 $this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save(); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- DB timestamp must match local-timezone format used by Manage Exports UI readers (mysql2date / strtotime / human_time_diff)
316
317 if (!empty($post['friendly_name'])) {
318 $this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
319 }
320
321 wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'wp-all-export')),'_wpnonce_options' => wp_create_nonce('options')) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php'))));
322 die();
323 }
324 }
325 }
326
327 if (empty($this->data['engine'])) {
328
329 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
330
331 $this->data['engine']->init_additional_data();
332
333 $this->data = array_merge($this->data, $this->data['engine']->init_available_data());
334 }
335
336 $this->data['available_data_view'] = $this->data['engine']->render();
337
338 $this->data['available_fields_view'] = $this->data['engine']->render_new_field();
339
340 if (class_exists('SitePress')) {
341 global $sitepress;
342 $langs = $sitepress->get_active_languages();
343 if (!empty($langs)) {
344 // prepare active languages list
345 $language_list = array('all' => 'All');
346 foreach ($langs as $code => $langInfo) {
347 $language_list[$code] = "<img width='18' height='12' src='" . esc_attr($sitepress->get_flag_url($code)) . "' style='position:relative; top: 2px;'/> " . esc_html($langInfo['display_name']);
348 if(isset($this->default_language)){
349 if ($code == $this->default_language) $language_list[$code] .= ' ( <strong>default</strong> )';
350 }
351
352 }
353 }
354 $this->data['wpml_options'] = $language_list;
355 }
356
357 $this->render();
358 }
359
360 /**
361 * Step #3: Export Options
362 */
363 public function options()
364 {
365 check_admin_referer( 'options', '_wpnonce_options' );
366
367 $default = PMXE_Plugin::get_default_import_options();
368
369 if ($this->isWizard) {
370
371 $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default;
372 $post = $this->input->post($DefaultOptions);
373
374 if(isset($post['update_previous'])) {
375 $exportId = $post['update_previous'];
376 } else {
377 $exportId = false;
378 }
379
380 if(!$exportId) {
381 $export = $this->data['update_previous'];
382 $export->set(
383 array(
384 'triggered' => 0,
385 'processing' => 0,
386 'exported' => 0,
387 'executing' => 0,
388 'canceled' => 0,
389 'options' => $post,
390 'friendly_name' => $this->getFriendlyName($post),
391 'last_activity' => date('Y-m-d H:i:s') // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- DB timestamp must match local-timezone format used by Manage Exports UI readers (mysql2date / strtotime / human_time_diff)
392
393 )
394 )->save();
395
396 PMXE_Plugin::$session->set('update_previous', $export->id);
397 PMXE_Plugin::$session->set('friendly_name', $this->getFriendlyName($post));
398 PMXE_Plugin::$session->save_data();
399 $exportId = $export->id;
400 }
401 $this->data['export_id'] = $exportId;
402 $this->data['export'] = new PMXE_Export_Record();
403 $this->data['export'] = $this->data['export']->getBy('id', $exportId);
404
405 if(empty($post['friendly_name'])) {
406 $post['friendly_name'] = $this->getFriendlyName($post);
407 }
408 }
409 else {
410 $DefaultOptions = $this->data['export']->options + $default;
411 if (empty($this->data['export']->options['export_variations'])) {
412 $DefaultOptions['export_variations'] = XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
413 }
414 if (empty($this->data['export']->options['export_variations_title'])) {
415 $DefaultOptions['export_variations_title'] = XmlExportEngine::VARIATION_USE_DEFAULT_TITLE;
416 }
417 $post = $this->input->post($DefaultOptions);
418 $post['scheduled'] = $this->data['export']->scheduled;
419
420 foreach ($post as $key => $value) {
421 PMXE_Plugin::$session->set($key, $value);
422 }
423 PMXE_Plugin::$session->save_data();
424 $this->data['export_id'] = $this->data['export']->id;
425 }
426
427 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
428
429 $this->data['engine']->init_available_data();
430
431 $this->data['post'] =& $post;
432
433 if ($this->input->post('is_submitted')) {
434
435 if ($post['is_generate_templates'] and '' == $post['template_name']) {
436 $friendly_name = $this->getFriendlyName($post);
437 $post['template_name'] = $friendly_name;
438 }
439
440 if ($this->isWizard) {
441 if (!$this->errors->get_error_codes()) {
442 foreach ($this->data['post'] as $key => $value) {
443 PMXE_Plugin::$session->set($key, $value);
444 }
445 PMXE_Plugin::$session->save_data();
446 wp_safe_redirect(esc_url_raw(add_query_arg(array('action' => 'process', '_wpnonce_process' => wp_create_nonce('process')), $this->baseUrl)));
447 die();
448 }
449 } else {
450 $this->errors->remove('count-validation');
451 if (!$this->errors->get_error_codes()) {
452 $this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save(); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- DB timestamp must match local-timezone format used by Manage Exports UI readers (mysql2date / strtotime / human_time_diff)
453 if (!empty($post['friendly_name'])) {
454 $this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
455 }
456 wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'wp-all-export'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php'))));
457 die();
458 }
459 }
460 }
461
462 $this->render();
463 }
464
465 /**
466 * Step #4: Export Processing
467 */
468 public function process()
469 {
470 // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- intentional for long-running exports
471 @set_time_limit(0);
472
473 $export = $this->data['update_previous'];
474
475 if (!PMXE_Plugin::is_ajax()) {
476
477 // Accept the nonce from either flow that legitimately reaches this action: the export
478 // wizard (process) or the re-export confirmation delegated from Manage (update-export).
479 $nonce_ok =
480 (isset($_REQUEST['_wpnonce_process'])
481 && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wpnonce_process'])), 'process'))
482 || (isset($_REQUEST['_wpnonce_update-export'])
483 && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wpnonce_update-export'])), 'update-export'));
484 if (!$nonce_ok) {
485 wp_nonce_ays('process');
486 }
487
488 if ("" == PMXE_Plugin::$session->friendly_name) {
489
490 $post_types = PMXE_Plugin::$session->get('cpt');
491 if (!empty($post_types)) {
492 if (in_array('users', $post_types)) {
493 $friendly_name = 'Users Export - ' . wp_date("Y F d H:i");
494 } elseif (in_array('shop_customer', $post_types)) {
495 $friendly_name = 'Customers Export - ' . wp_date("Y F d H:i");
496 } elseif (in_array('comments', $post_types)) {
497 $friendly_name = 'Comments Export - ' . wp_date("Y F d H:i");
498 } elseif (in_array('taxonomies', $post_types)) {
499 $tx = get_taxonomy(PMXE_Plugin::$session->get('taxonomy_to_export'));
500 if (!empty($tx->labels->name)) {
501 $friendly_name = $tx->labels->name . ' Export - ' . wp_date("Y F d H:i");
502 } else {
503 $friendly_name = 'Taxonomy Terms Export - ' . wp_date("Y F d H:i");
504 }
505 } else {
506 $post_type_details = get_post_type_object(array_shift($post_types));
507 $friendly_name = $post_type_details->labels->name . ' Export - ' . wp_date("Y F d H:i");
508 }
509 } else {
510 $friendly_name = 'WP_Query Export - ' . wp_date("Y F d H:i");
511 }
512
513 PMXE_Plugin::$session->set('friendly_name', $friendly_name);
514 }
515
516 PMXE_Plugin::$session->set('file', '');
517 PMXE_Plugin::$session->save_data();
518
519 $export->set(
520 array(
521 'triggered' => 0,
522 'processing' => 0,
523 'exported' => 0,
524 'executing' => 1,
525 'canceled' => 0,
526 'options' => PMXE_Plugin::$session->get_clear_session_data(),
527 'friendly_name' => PMXE_Plugin::$session->friendly_name,
528 'scheduled' => (PMXE_Plugin::$session->is_scheduled) ? PMXE_Plugin::$session->scheduled_period : '',
529 //'registered_on' => date('Y-m-d H:i:s'), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- DB timestamp must match local-timezone format used by Manage Exports UI readers (mysql2date / strtotime / human_time_diff)
530 'last_activity' => date('Y-m-d H:i:s') // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- DB timestamp must match local-timezone format used by Manage Exports UI readers (mysql2date / strtotime / human_time_diff)
531 )
532 )->save();
533
534 // create an import for this export
535 if ($export->options['export_to'] == 'csv' || !in_array($export->options['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) PMXE_Wpallimport::create_an_import($export);
536 PMXE_Plugin::$session->set('update_previous', $export->id);
537 PMXE_Plugin::$session->save_data();
538
539 do_action('pmxe_before_export', $export->id);
540
541 }
542
543 $this->render();
544 }
545
546 /**
547 * @param $post
548 * @return string
549 */
550 protected function getFriendlyName($post)
551 {
552 $friendly_name = '';
553 $post_types = PMXE_Plugin::$session->get('cpt');
554 if (!empty($post_types)) {
555 if (in_array('users', $post_types)) {
556 $friendly_name = 'Users Export - ' . wp_date("Y F d H:i");
557 return $friendly_name;
558 } elseif (in_array('shop_customer', $post_types)) {
559 $friendly_name = 'Customers Export - ' . wp_date("Y F d H:i");
560 return $friendly_name;
561 } elseif (in_array('comments', $post_types)) {
562 $friendly_name = 'Comments Export - ' . wp_date("Y F d H:i");
563 return $friendly_name;
564 } elseif (in_array('taxonomies', $post_types)) {
565 $tx = get_taxonomy($post['taxonomy_to_export']);
566 if (!empty($tx->labels->name)) {
567 $friendly_name = $tx->labels->name . ' Export - ' . wp_date("Y F d H:i");
568 return $friendly_name;
569 } else {
570 $friendly_name = 'Taxonomy Terms Export - ' . wp_date("Y F d H:i");
571 return $friendly_name;
572 }
573 } else {
574 $is_rapid_add_on_export = PMXE_Helper::is_rapid_export_addon($post_types);
575 if($is_rapid_add_on_export) {
576 return 'Gravity Forms Entries Export - ' . wp_date("Y F d H:i");
577 }
578
579 $post_type_details = get_post_type_object(array_shift($post_types));
580 $friendly_name = $post_type_details->labels->name . ' Export - ' . wp_date("Y F d H:i");
581 return $friendly_name;
582 }
583 } else {
584 $friendly_name = 'WP_Query Export - ' . wp_date("Y F d H:i");
585 return $friendly_name;
586 }
587 }
588
589 function insertAfter($input, $index, $newKey, $element) {
590 if (!array_key_exists($index, $input)) {
591 throw new Exception("Index not found");
592 }
593 $tmpArray = array();
594 foreach ($input as $key => $value) {
595 $tmpArray[$key] = $value;
596 if ($key === $index) {
597 $tmpArray[$newKey] = $element;
598 }
599 }
600 return $tmpArray;
601 }
602 }