PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.3.6
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.3.6
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 4 years ago feedback.php 10 years ago help.php 12 years ago manage.php 4 years ago settings.php 4 years ago
manage.php
532 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;', 'PMXE_plugin'),
57 'next_text' => __('&raquo;', 'PMXE_plugin'),
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_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_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_redirect($this->baseUrl); die();
139 }
140
141 $this->render();
142 }
143
144 /**
145 * Cancel import processing
146 */
147 public function cancel(){
148
149 $id = $this->input->get('id');
150
151 PMXE_Plugin::$session->clean_session( $id );
152
153 $item = new PMXE_Export_Record();
154 if ( ! $id or $item->getById($id)->isEmpty()) {
155 wp_redirect($this->baseUrl); die();
156 }
157 $item->set(array(
158 'triggered' => 0,
159 'processing' => 0,
160 'executing' => 0,
161 'canceled' => 1,
162 'canceled_on' => date('Y-m-d H:i:s')
163 ))->update();
164
165 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export canceled', 'wp_all_import_plugin')), $this->baseUrl)));
166 die();
167 }
168
169 /**
170 * Reexport
171 */
172 public function update() {
173
174 $id = $this->input->get('id');
175
176 PMXE_Plugin::$session->clean_session($id);
177
178 $action_type = $this->input->get('type');
179
180 $this->data['item'] = $item = new PMXE_Export_Record();
181 if ( ! $id or $item->getById($id)->isEmpty()) {
182 wp_redirect($this->baseUrl); die();
183 }
184
185 $item->fix_template_options();
186
187 $default = PMXE_Plugin::get_default_import_options();
188 $DefaultOptions = $item->options + $default;
189 if (empty($item->options['export_variations'])){
190 $DefaultOptions['export_variations'] = XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
191 }
192 if (empty($item->options['export_variations_title'])){
193 $DefaultOptions['export_variations_title'] = XmlExportEngine::VARIATION_USE_DEFAULT_TITLE;
194 }
195 $this->data['post'] = $post = $this->input->post($DefaultOptions);
196 $this->data['iteration'] = $item->iteration;
197
198 if ($this->input->post('is_confirmed')) {
199
200 check_admin_referer('update-export', '_wpnonce_update-export');
201
202 $iteration = ( empty($item->options['creata_a_new_export_file']) && ! empty($post['creata_a_new_export_file'])) ? 0 : $item->iteration;
203
204 $item->set(array( 'options' => $post, 'iteration' => $iteration))->save();
205 if ( ! empty($post['friendly_name']) ) {
206 $item->set( array( 'friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '') ) )->save();
207 }
208
209 // compose data to look like result of wizard steps
210 $sesson_data = $post + array('update_previous' => $item->id ) + $default;
211
212 foreach ($sesson_data as $key => $value) {
213 PMXE_Plugin::$session->set($key, $value);
214 }
215
216 $this->data['engine'] = new XmlExportEngine($sesson_data, $this->errors);
217 $this->data['engine']->init_additional_data();
218 $this->data['engine']->init_available_data();
219
220 PMXE_Plugin::$session->save_data();
221
222 if ( ! $this->errors->get_error_codes() && $this->input->post('record-count')) {
223
224 // deligate operation to other controller
225 $controller = new PMXE_Admin_Export();
226 $controller->data['update_previous'] = $item;
227 $controller->process();
228 return;
229
230 }
231
232 $this->errors->remove('count-validation');
233 if ( ! $this->errors->get_error_codes()) {
234 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Options updated', 'wp_all_export_plugin')), $this->baseUrl)));
235 die();
236 }
237
238 }
239
240 $this->data['isWizard'] = false;
241 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
242 $this->data['engine']->init_available_data();
243
244 $this->render();
245 }
246
247 /**
248 * Delete an export
249 */
250 public function delete() {
251 $id = $this->input->get('id');
252 $this->data['item'] = $item = new PMXE_Export_Record();
253 if ( ! $id or $item->getById($id)->isEmpty()) {
254 wp_redirect($this->baseUrl); die();
255 }
256
257 if ($this->input->post('is_confirmed')) {
258 check_admin_referer('delete-export', '_wpnonce_delete-export');
259 $item->delete();
260
261 $scheduling = \Wpae\Scheduling\Scheduling::create();
262 $scheduling->deleteScheduleIfExists($id);
263
264 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export deleted', 'wp_all_export_plugin')), $this->baseUrl))); die();
265 }
266
267 $this->render();
268 }
269
270 /**
271 * Bulk actions
272 */
273 public function bulk() {
274 check_admin_referer('bulk-exports', '_wpnonce_bulk-exports');
275 if ($this->input->post('doaction2')) {
276 $this->data['action'] = $action = $this->input->post('bulk-action2');
277 } else {
278 $this->data['action'] = $action = $this->input->post('bulk-action');
279 }
280 $this->data['ids'] = $ids = $this->input->post('items');
281 $this->data['items'] = $items = new PMXE_Export_List();
282 if (empty($action) or ! in_array($action, array('delete')) or empty($ids) or $items->getBy('id', $ids)->isEmpty()) {
283 wp_redirect($this->baseUrl); die();
284 }
285 if ($this->input->post('is_confirmed')) {
286 foreach($items->convertRecords() as $item) {
287
288 if ($item->attch_id) wp_delete_attachment($item->attch_id, true);
289
290 $item->delete();
291
292 $scheduling = \Wpae\Scheduling\Scheduling::create();
293 $scheduling->deleteScheduleIfExists($item->id);
294 }
295 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(__('%d %s deleted', 'wp_all_export_plugin'), $items->count(), _n('export', 'exports', $items->count(), 'wp_all_export_plugin'))), $this->baseUrl)));
296 die();
297 }
298 $this->render();
299 }
300
301 public function get_template(){
302 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
303 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_template' ) ) {
304 die( __('Security check', 'wp_all_export_plugin') );
305 } else {
306
307 $id = $this->input->get('id');
308
309 $export = new PMXE_Export_Record();
310
311 $filepath = '';
312
313 $export_data = array();
314
315 if ( ! $export->getById($id)->isEmpty()){
316
317 $export_data[] = $export->options['tpl_data'];
318 $uploads = wp_upload_dir();
319 $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY;
320
321 $export_file_name = "WP All Import Template - " . sanitize_file_name($export->friendly_name) . ".txt";
322
323 file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
324
325 PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
326
327 }
328 }
329 }
330
331 /*
332 * Download bundle for WP All Import
333 *
334 */
335 public function bundle()
336 {
337 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
338 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_bundle' ) ) {
339 die( __('Security check', 'wp_all_export_plugin') );
340 } else {
341
342 $uploads = wp_upload_dir();
343
344 $id = $this->input->get('id');
345
346 $export = new PMXE_Export_Record();
347
348 if ( ! $export->getById($id)->isEmpty())
349 {
350 if ( ! empty($export->options['bundlepath']) )
351 {
352 $bundle_path = wp_all_export_get_absolute_path($export->options['bundlepath']);
353
354 if ( @file_exists($bundle_path) )
355 {
356 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
357
358 PMXE_download::zip($bundle_path);
359 }
360 }
361 else
362 {
363 wp_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_plugin')), $this->baseUrl)));
364 die();
365 }
366 }
367 else
368 {
369 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('This export doesn\'t exist.', 'wp_all_export_plugin')), $this->baseUrl))); die();
370 }
371 }
372 }
373
374 public function split_bundle(){
375 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
376 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_split_bundle' ) ) {
377 die( __('Security check', 'wp_all_export_plugin') );
378 } else {
379
380 $uploads = wp_upload_dir();
381
382 $id = PMXE_Plugin::$session->update_previous;
383
384 if (empty($id))
385 $id = $this->input->get('id');
386
387 $export = new PMXE_Export_Record();
388
389 if ( ! $export->getById($id)->isEmpty())
390 {
391 if ( ! empty($export->options['split_files_list']))
392 {
393 $tmp_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5($export->id) . DIRECTORY_SEPARATOR;
394 $bundle_dir = $tmp_dir . 'split_files' . DIRECTORY_SEPARATOR;
395
396 wp_all_export_rrmdir($tmp_dir);
397
398 @mkdir($tmp_dir);
399 @mkdir($bundle_dir);
400
401 foreach ($export->options['split_files_list'] as $file) {
402 @copy( $file, $bundle_dir . basename($file) );
403 }
404
405 $friendly_name = sanitize_file_name($export->friendly_name);
406
407 $bundle_path = $tmp_dir . $friendly_name . '-split-files.zip';
408
409 PMXE_Zip::zipDir($bundle_dir, $bundle_path);
410
411 if (file_exists($bundle_path))
412 {
413 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
414
415 PMXE_download::zip($bundle_path);
416 }
417 }
418 }
419 }
420 }
421
422 /*
423 * Download import log file
424 *
425 */
426 public function get_file(){
427
428 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
429 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) ) {
430 die( __('Security check', 'wp_all_export_plugin') );
431 } else {
432
433 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
434
435 $id = $this->input->get('id');
436
437 $export = new PMXE_Export_Record();
438
439 $filepath = '';
440
441 if ( ! $export->getById($id)->isEmpty())
442 {
443 if ( ! $is_secure_import)
444 {
445 $filepath = get_attached_file($export->attch_id);
446 }
447 else
448 {
449 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
450 }
451
452 if ( @file_exists($filepath) )
453 {
454 switch ($export->options['export_to'])
455 {
456 case 'xml':
457 if($export['options']['xml_template_type'] == XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS) {
458 PMXE_Download::txt($filepath);
459 } else {
460 PMXE_download::xml($filepath);
461 }
462
463 break;
464 case 'csv':
465 if (empty($export->options['export_to_sheet']) or $export->options['export_to_sheet'] == 'csv')
466 {
467 PMXE_download::csv($filepath);
468 }
469 else
470 {
471 PMXE_download::xls($filepath);
472 }
473 break;
474 default:
475 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'wp_all_export_plugin')), $this->baseUrl)));
476 die();
477 break;
478 }
479 }
480 else
481 {
482 wp_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_plugin')), $this->baseUrl)));
483 die();
484 }
485 }
486 else
487 {
488 wp_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_plugin')), $this->baseUrl)));
489 die();
490 }
491 }
492 }
493
494 /**
495 * @param $post
496 * @return string
497 */
498 protected function getFriendlyName($post)
499 {
500 $friendly_name = '';
501 $post_types = PMXE_Plugin::$session->get('cpt');
502 if (!empty($post_types)) {
503 if (in_array('users', $post_types)) {
504 $friendly_name = 'Users Export - ' . date("Y F d H:i");
505 return $friendly_name;
506 } elseif (in_array('shop_customer', $post_types)) {
507 $friendly_name = 'Customers Export - ' . date("Y F d H:i");
508 return $friendly_name;
509 } elseif (in_array('comments', $post_types)) {
510 $friendly_name = 'Comments Export - ' . date("Y F d H:i");
511 return $friendly_name;
512 } elseif (in_array('taxonomies', $post_types)) {
513 $tx = get_taxonomy($post['taxonomy_to_export']);
514 if (!empty($tx->labels->name)) {
515 $friendly_name = $tx->labels->name . ' Export - ' . date("Y F d H:i");
516 return $friendly_name;
517 } else {
518 $friendly_name = 'Taxonomy Terms Export - ' . date("Y F d H:i");
519 return $friendly_name;
520 }
521 } else {
522 $post_type_details = get_post_type_object(array_shift($post_types));
523 $friendly_name = $post_type_details->labels->name . ' Export - ' . date("Y F d H:i");
524 return $friendly_name;
525 }
526 } else {
527 $friendly_name = 'WP_Query Export - ' . date("Y F d H:i");
528 return $friendly_name;
529 }
530 }
531
532 }