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