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 / manage.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
manage.php
541 lines
1 <?php
2 /**
3 * Manage Imports
4 *
5 * @author Pavel Kulbakin <p.kulbakin@gmail.com>
6 */
7 class PMXE_Admin_Manage extends PMXE_Controller_Admin {
8
9 public function init() {
10 parent::init();
11
12 if ('update' == PMXE_Plugin::getInstance()->getAdminCurrentScreen()->action) {
13 $this->isInline = true;
14 }
15 }
16
17 /**
18 * Previous Imports list
19 */
20 public function index() {
21
22 $get = $this->input->get(array(
23 's' => '',
24 'order_by' => 'id',
25 'order' => 'DESC',
26 'pagenum' => 1,
27 'perPage' => 25,
28 ));
29 $get['pagenum'] = absint($get['pagenum']);
30 extract($get);
31 $this->data += $get;
32
33 if ( ! in_array($order_by, array('registered_on', 'id', 'friendly_name'))){
34 $order_by = 'registered_on';
35 }
36
37 if ( ! in_array($order, array('DESC', 'ASC'))){
38 $order = 'DESC';
39 }
40
41 $list = new PMXE_Export_List();
42 $by = array('parent_id' => 0);
43 if ('' != $s) {
44 $like = '%' . preg_replace('%\s+%', '%', preg_replace('/[%?]/', '\\\\$0', $s)) . '%';
45 $by[] = array(array('friendly_name LIKE' => $like, 'registered_on LIKE' => $like), 'OR');
46 }
47
48 $this->data['list'] = $list->setColumns(
49 $list->getTable() . '.*'
50 )->getBy($by, "$order_by $order", $pagenum, $perPage, $list->getTable() . '.id');
51
52 $this->data['page_links'] = paginate_links(array(
53 'base' => esc_url_raw(add_query_arg('pagenum', '%#%', $this->baseUrl)),
54 'add_args' => array('page' => 'pmxe-admin-manage'),
55 'format' => '',
56 'prev_text' => __('&laquo;', 'wp-all-export'),
57 'next_text' => __('&raquo;', 'wp-all-export'),
58 'total' => ceil($list->total() / $perPage),
59 'current' => $pagenum,
60 ));
61
62 PMXE_Plugin::$session->clean_session();
63
64 $this->render();
65 }
66
67 /**
68 * Edit Options
69 */
70 public function options() {
71
72 // deligate operation to other controller
73 $controller = new PMXE_Admin_Export();
74 $controller->set('isTemplateEdit', true);
75 $controller->options();
76 }
77
78 /**
79 * Edit Template
80 */
81 public function template() {
82
83 // deligate operation to other controller
84 $controller = new PMXE_Admin_Export();
85 $controller->set('isTemplateEdit', true);
86 $controller->template();
87 }
88
89 /**
90 * Cron Scheduling
91 */
92 public function scheduling() {
93 $this->data['id'] = $id = $this->input->get('id');
94 $this->data['cron_job_key'] = PMXE_Plugin::getInstance()->getOption('cron_job_key');
95 $this->data['item'] = $item = new PMXE_Export_Record();
96 if ( ! $id or $item->getById($id)->isEmpty()) {
97 wp_safe_redirect($this->baseUrl); die();
98 }
99
100 $wp_uploads = wp_upload_dir();
101
102 $this->data['file_path'] = site_url() . '/wp-load.php?security_token=' . substr(md5($this->data['cron_job_key'] . $item['id']), 0, 16) . '&export_id=' . $item['id'] . '&action=get_data';
103
104 $this->data['bundle_url'] = '';
105
106 if ( ! empty($item['options']['bundlepath']) )
107 {
108 $this->data['bundle_url'] = site_url() . '/wp-load.php?security_token=' . substr(md5($this->data['cron_job_key'] . $item['id']), 0, 16) . '&export_id=' . $item['id'] . '&action=get_bundle&t=zip';
109 }
110
111 $this->render();
112 }
113
114 /**
115 * Google merchants info
116 */
117 public function google_merchants_info() {
118
119 $this->data['id'] = $id = $this->input->get('id');
120 $this->data['cron_job_key'] = PMXE_Plugin::getInstance()->getOption('cron_job_key');
121 $this->data['item'] = $item = new PMXE_Export_Record();
122 if ( ! $id or $item->getById($id)->isEmpty()) {
123 wp_safe_redirect($this->baseUrl); die();
124 }
125
126 $this->data['file_path'] = site_url() . '/wp-load.php?security_token=' . substr(md5($this->data['cron_job_key'] . $item['id']), 0, 16) . '&export_id=' . $item['id'] . '&action=get_data';
127
128 $this->render();
129 }
130
131 /**
132 * Download import templates
133 */
134 public function templates() {
135 $this->data['id'] = $id = $this->input->get('id');
136 $this->data['item'] = $item = new PMXE_Export_Record();
137 if ( ! $id or $item->getById($id)->isEmpty()) {
138 wp_safe_redirect($this->baseUrl); die();
139 }
140
141 $this->render();
142 }
143
144 /**
145 * Cancel import processing
146 */
147 public function cancel(){
148
149 check_admin_referer('cancel-export', '_wpnonce_cancel-export');
150
151 $id = $this->input->get('id');
152
153 PMXE_Plugin::$session->clean_session( $id );
154
155 $item = new PMXE_Export_Record();
156 if ( ! $id or $item->getById($id)->isEmpty()) {
157 wp_safe_redirect($this->baseUrl); die();
158 }
159 $item->set(array(
160 'triggered' => 0,
161 'processing' => 0,
162 'executing' => 0,
163 'canceled' => 1,
164 'canceled_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)
165 ))->update();
166
167 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export canceled', 'wp-all-export')), $this->baseUrl)));
168 die();
169 }
170
171 /**
172 * Reexport
173 */
174 public function update() {
175
176 $id = $this->input->get('id');
177
178 PMXE_Plugin::$session->clean_session($id);
179
180 $action_type = $this->input->get('type');
181
182 $this->data['item'] = $item = new PMXE_Export_Record();
183 if ( ! $id or $item->getById($id)->isEmpty()) {
184 wp_safe_redirect($this->baseUrl); die();
185 }
186
187 $item->fix_template_options();
188
189 $default = PMXE_Plugin::get_default_import_options();
190 $DefaultOptions = $item->options + $default;
191 if (empty($item->options['export_variations'])){
192 $DefaultOptions['export_variations'] = XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
193 }
194 if (empty($item->options['export_variations_title'])){
195 $DefaultOptions['export_variations_title'] = XmlExportEngine::VARIATION_USE_DEFAULT_TITLE;
196 }
197 $this->data['post'] = $post = $this->input->post($DefaultOptions);
198 $this->data['iteration'] = $item->iteration;
199
200 if ($this->input->post('is_confirmed')) {
201
202 check_admin_referer('update-export', '_wpnonce_update-export');
203
204 $iteration = ( empty($item->options['creata_a_new_export_file']) && ! empty($post['creata_a_new_export_file'])) ? 0 : $item->iteration;
205
206 $item->set(array( 'options' => $post, 'iteration' => $iteration))->save();
207 if ( ! empty($post['friendly_name']) ) {
208 $item->set( array( 'friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '') ) )->save();
209 }
210
211 // compose data to look like result of wizard steps
212 $sesson_data = $post + array('update_previous' => $item->id ) + $default;
213
214 foreach ($sesson_data as $key => $value) {
215 PMXE_Plugin::$session->set($key, $value);
216 }
217
218 $this->data['engine'] = new XmlExportEngine($sesson_data, $this->errors);
219 $this->data['engine']->init_additional_data();
220 $this->data['engine']->init_available_data();
221
222 PMXE_Plugin::$session->save_data();
223
224 if ( ! $this->errors->get_error_codes() && $this->input->post('record-count')) {
225
226 // deligate operation to other controller
227 $controller = new PMXE_Admin_Export();
228 $controller->data['update_previous'] = $item;
229 $controller->process();
230 return;
231
232 }
233
234 $this->errors->remove('count-validation');
235 if ( ! $this->errors->get_error_codes()) {
236 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Options updated', 'wp-all-export')), $this->baseUrl)));
237 die();
238 }
239
240 }
241
242 $this->data['isWizard'] = false;
243 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
244 $this->data['engine']->init_available_data();
245
246 $this->render();
247 }
248
249 /**
250 * Delete an export
251 */
252 public function delete() {
253 $id = $this->input->get('id');
254 $this->data['item'] = $item = new PMXE_Export_Record();
255 if ( ! $id or $item->getById($id)->isEmpty()) {
256 wp_safe_redirect($this->baseUrl); die();
257 }
258
259 if ($this->input->post('is_confirmed')) {
260 check_admin_referer('delete-export', '_wpnonce_delete-export');
261 $item->delete();
262
263 $scheduling = \Wpae\Scheduling\Scheduling::create();
264 $scheduling->deleteScheduleIfExists($id);
265
266 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export deleted', 'wp-all-export')), $this->baseUrl))); die();
267 }
268
269 $this->render();
270 }
271
272 /**
273 * Bulk actions
274 */
275 public function bulk() {
276 check_admin_referer('bulk-exports', '_wpnonce_bulk-exports');
277 if ($this->input->post('doaction2')) {
278 $this->data['action'] = $action = $this->input->post('bulk-action2');
279 } else {
280 $this->data['action'] = $action = $this->input->post('bulk-action');
281 }
282 $this->data['ids'] = $ids = $this->input->post('items');
283 $this->data['items'] = $items = new PMXE_Export_List();
284 if (empty($action) or ! in_array($action, array('delete')) or empty($ids) or $items->getBy('id', $ids)->isEmpty()) {
285 wp_safe_redirect($this->baseUrl); die();
286 }
287 if ($this->input->post('is_confirmed')) {
288 foreach($items->convertRecords() as $item) {
289
290 if ($item->attch_id) wp_delete_attachment($item->attch_id, true);
291
292 $item->delete();
293
294 $scheduling = \Wpae\Scheduling\Scheduling::create();
295 $scheduling->deleteScheduleIfExists($item->id);
296 }
297 /* translators: 1: count, 2: singular/plural noun */
298 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(__('%1$d %2$s deleted', 'wp-all-export'), $items->count(), _n('export', 'exports', $items->count(), 'wp-all-export'))), $this->baseUrl)));
299 die();
300 }
301 $this->render();
302 }
303
304 public function get_template(){
305 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on next line
306 $nonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
307 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_template' ) ) {
308 die( esc_html__('Security check', 'wp-all-export') );
309 } else {
310
311 $id = $this->input->get('id');
312
313 $export = new PMXE_Export_Record();
314
315 $filepath = '';
316
317 $export_data = array();
318
319 if ( ! $export->getById($id)->isEmpty()){
320
321 $export_data[] = $export->options['tpl_data'];
322 $uploads = wp_upload_dir();
323 $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY;
324
325 $export_file_name = "WP All Import Template - " . sanitize_file_name($export->friendly_name) . ".txt";
326
327 file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
328
329 PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
330
331 }
332 }
333 }
334
335 /*
336 * Download bundle for WP All Import
337 *
338 */
339 public function bundle()
340 {
341 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on next line
342 $nonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
343 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_bundle' ) ) {
344 die( esc_html__('Security check', 'wp-all-export') );
345 } else {
346
347 $uploads = wp_upload_dir();
348
349 $id = $this->input->get('id');
350
351 $export = new PMXE_Export_Record();
352
353 if ( ! $export->getById($id)->isEmpty())
354 {
355 if ( ! empty($export->options['bundlepath']) )
356 {
357 $bundle_path = wp_all_export_get_absolute_path($export->options['bundlepath']);
358
359 if ( @file_exists($bundle_path) )
360 {
361 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
362
363 PMXE_download::zip($bundle_path);
364 }
365 }
366 else
367 {
368 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported bundle is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp-all-export')), $this->baseUrl)));
369 die();
370 }
371 }
372 else
373 {
374 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('This export doesn\'t exist.', 'wp-all-export')), $this->baseUrl))); die();
375 }
376 }
377 }
378
379 public function split_bundle(){
380 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on next line
381 $nonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
382 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_split_bundle' ) ) {
383 die( esc_html__('Security check', 'wp-all-export') );
384 } else {
385
386 $uploads = wp_upload_dir();
387
388 $id = PMXE_Plugin::$session->update_previous;
389
390 if (empty($id))
391 $id = $this->input->get('id');
392
393 $export = new PMXE_Export_Record();
394
395 if ( ! $export->getById($id)->isEmpty())
396 {
397 if ( ! empty($export->options['split_files_list']))
398 {
399 $tmp_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5($export->id) . DIRECTORY_SEPARATOR;
400 $bundle_dir = $tmp_dir . 'split_files' . DIRECTORY_SEPARATOR;
401
402 wp_all_export_rrmdir($tmp_dir);
403
404 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir -- export plugin reads/writes its own files in uploads dir, WP_Filesystem not viable for streamed CSV/XML output
405 @mkdir($tmp_dir);
406 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir -- export plugin reads/writes its own files in uploads dir, WP_Filesystem not viable for streamed CSV/XML output
407 @mkdir($bundle_dir);
408
409 foreach ($export->options['split_files_list'] as $file) {
410 @copy( $file, $bundle_dir . basename($file) );
411 }
412
413 $friendly_name = sanitize_file_name($export->friendly_name);
414
415 $bundle_path = $tmp_dir . $friendly_name . '-split-files.zip';
416
417 PMXE_Zip::zipDir($bundle_dir, $bundle_path);
418
419 if (file_exists($bundle_path))
420 {
421 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
422
423 PMXE_download::zip($bundle_path);
424 }
425 }
426 }
427 }
428 }
429
430 /*
431 * Download import log file
432 *
433 */
434 public function get_file(){
435
436 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on next line
437 $nonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
438 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) ) {
439 die( esc_html__('Security check', 'wp-all-export') );
440 } else {
441
442 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
443
444 $id = $this->input->get('id');
445
446 $export = new PMXE_Export_Record();
447
448 $filepath = '';
449
450 if ( ! $export->getById($id)->isEmpty())
451 {
452 if ( ! $is_secure_import)
453 {
454 $filepath = get_attached_file($export->attch_id);
455 }
456 else
457 {
458 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
459 }
460
461 if ( @file_exists($filepath) )
462 {
463 switch ($export->options['export_to'])
464 {
465 case 'xml':
466 if($export['options']['xml_template_type'] == XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS) {
467 PMXE_Download::txt($filepath);
468 } else {
469 PMXE_download::xml($filepath);
470 }
471
472 break;
473 case 'csv':
474 if (empty($export->options['export_to_sheet']) or $export->options['export_to_sheet'] == 'csv')
475 {
476 PMXE_download::csv($filepath);
477 }
478 else
479 {
480 PMXE_download::xls($filepath);
481 }
482 break;
483 default:
484 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'wp-all-export')), $this->baseUrl)));
485 die();
486 break;
487 }
488 }
489 else
490 {
491 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp-all-export')), $this->baseUrl)));
492 die();
493 }
494 }
495 else
496 {
497 wp_safe_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp-all-export')), $this->baseUrl)));
498 die();
499 }
500 }
501 }
502
503 /**
504 * @param $post
505 * @return string
506 */
507 protected function getFriendlyName($post)
508 {
509 $friendly_name = '';
510 $post_types = PMXE_Plugin::$session->get('cpt');
511 if (!empty($post_types)) {
512 if (in_array('users', $post_types)) {
513 $friendly_name = 'Users Export - ' . wp_date("Y F d H:i");
514 return $friendly_name;
515 } elseif (in_array('shop_customer', $post_types)) {
516 $friendly_name = 'Customers Export - ' . wp_date("Y F d H:i");
517 return $friendly_name;
518 } elseif (in_array('comments', $post_types)) {
519 $friendly_name = 'Comments Export - ' . wp_date("Y F d H:i");
520 return $friendly_name;
521 } elseif (in_array('taxonomies', $post_types)) {
522 $tx = get_taxonomy($post['taxonomy_to_export']);
523 if (!empty($tx->labels->name)) {
524 $friendly_name = $tx->labels->name . ' Export - ' . wp_date("Y F d H:i");
525 return $friendly_name;
526 } else {
527 $friendly_name = 'Taxonomy Terms Export - ' . wp_date("Y F d H:i");
528 return $friendly_name;
529 }
530 } else {
531 $post_type_details = get_post_type_object(array_shift($post_types));
532 $friendly_name = $post_type_details->labels->name . ' Export - ' . wp_date("Y F d H:i");
533 return $friendly_name;
534 }
535 } else {
536 $friendly_name = 'WP_Query Export - ' . wp_date("Y F d H:i");
537 return $friendly_name;
538 }
539 }
540
541 }