PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.5
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 8 years ago feedback.php 8 years ago help.php 8 years ago manage.php 8 years ago settings.php 8 years ago
manage.php
485 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-cron.php?export_hash=' . 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-cron.php?export_hash=' . 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-cron.php?export_hash=' . 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()) {
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 ?>
234 <script type="text/javascript">
235 window.location.href = "<?php echo add_query_arg('pmxe_nt', urlencode(__('Options updated', 'wp_all_export_plugin')), $this->baseUrl); ?>";
236 </script>
237 <?php
238 die();
239 }
240
241 }
242
243 $this->data['isWizard'] = false;
244 $this->data['engine'] = new XmlExportEngine($post, $this->errors);
245 $this->data['engine']->init_available_data();
246
247 $this->render();
248 }
249
250 /**
251 * Delete an import
252 */
253 public function delete() {
254 $id = $this->input->get('id');
255 $this->data['item'] = $item = new PMXE_Export_Record();
256 if ( ! $id or $item->getById($id)->isEmpty()) {
257 wp_redirect($this->baseUrl); die();
258 }
259
260 if ($this->input->post('is_confirmed')) {
261 check_admin_referer('delete-export', '_wpnonce_delete-export');
262 $item->delete();
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 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();
292 }
293 $this->render();
294 }
295
296 public function get_template(){
297 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
298 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_template' ) ) {
299 die( __('Security check', 'wp_all_export_plugin') );
300 } else {
301
302 $id = $this->input->get('id');
303
304 $export = new PMXE_Export_Record();
305
306 $filepath = '';
307
308 $export_data = array();
309
310 if ( ! $export->getById($id)->isEmpty()){
311
312 $export_data[] = $export->options['tpl_data'];
313 $uploads = wp_upload_dir();
314 $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY;
315
316 $export_file_name = "WP All Import Template - " . sanitize_file_name($export->friendly_name) . ".txt";
317
318 file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
319
320 PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
321
322 }
323 }
324 }
325
326 /*
327 * Download bundle for WP All Import
328 *
329 */
330 public function bundle()
331 {
332 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
333 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_bundle' ) ) {
334 die( __('Security check', 'wp_all_export_plugin') );
335 } else {
336
337 $uploads = wp_upload_dir();
338
339 $id = $this->input->get('id');
340
341 $export = new PMXE_Export_Record();
342
343 if ( ! $export->getById($id)->isEmpty())
344 {
345 if ( ! empty($export->options['bundlepath']) )
346 {
347 $bundle_path = wp_all_export_get_absolute_path($export->options['bundlepath']);
348
349 if ( @file_exists($bundle_path) )
350 {
351 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
352
353 PMXE_download::zip($bundle_path);
354 }
355 }
356 else
357 {
358 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();
359 }
360 }
361 else
362 {
363 wp_redirect(add_query_arg('pmxe_nt', urlencode(__('This export doesn\'t exist.', 'wp_all_export_plugin')), $this->baseUrl)); die();
364 }
365 }
366 }
367
368 public function split_bundle(){
369 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
370 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_split_bundle' ) ) {
371 die( __('Security check', 'wp_all_export_plugin') );
372 } else {
373
374 $uploads = wp_upload_dir();
375
376 $id = PMXE_Plugin::$session->update_previous;
377
378 if (empty($id))
379 $id = $this->input->get('id');
380
381 $export = new PMXE_Export_Record();
382
383 if ( ! $export->getById($id)->isEmpty())
384 {
385 if ( ! empty($export->options['split_files_list']))
386 {
387 $tmp_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5($export->id) . DIRECTORY_SEPARATOR;
388 $bundle_dir = $tmp_dir . 'split_files' . DIRECTORY_SEPARATOR;
389
390 wp_all_export_rrmdir($tmp_dir);
391
392 @mkdir($tmp_dir);
393 @mkdir($bundle_dir);
394
395 foreach ($export->options['split_files_list'] as $file) {
396 @copy( $file, $bundle_dir . basename($file) );
397 }
398
399 $friendly_name = sanitize_file_name($export->friendly_name);
400
401 $bundle_path = $tmp_dir . $friendly_name . '-split-files.zip';
402
403 PMXE_Zip::zipDir($bundle_dir, $bundle_path);
404
405 if (file_exists($bundle_path))
406 {
407 $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
408
409 PMXE_download::zip($bundle_path);
410 }
411 }
412 }
413 }
414 }
415
416 /*
417 * Download import log file
418 *
419 */
420 public function get_file(){
421
422 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
423 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) ) {
424 die( __('Security check', 'wp_all_export_plugin') );
425 } else {
426
427 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
428
429 $id = $this->input->get('id');
430
431 $export = new PMXE_Export_Record();
432
433 $filepath = '';
434
435 if ( ! $export->getById($id)->isEmpty())
436 {
437 if ( ! $is_secure_import)
438 {
439 $filepath = get_attached_file($export->attch_id);
440 }
441 else
442 {
443 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
444 }
445
446 if ( @file_exists($filepath) )
447 {
448 switch ($export->options['export_to'])
449 {
450 case 'xml':
451 if($export['options']['xml_template_type'] == XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS) {
452 PMXE_Download::txt($filepath);
453 } else {
454 PMXE_download::xml($filepath);
455 }
456
457 break;
458 case 'csv':
459 if (empty($export->options['export_to_sheet']) or $export->options['export_to_sheet'] == 'csv')
460 {
461 PMXE_download::csv($filepath);
462 }
463 else
464 {
465 PMXE_download::xls($filepath);
466 }
467 break;
468 default:
469 wp_redirect(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'wp_all_export_plugin')), $this->baseUrl)); die();
470 break;
471 }
472 }
473 else
474 {
475 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();
476 }
477 }
478 else
479 {
480 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();
481 }
482 }
483 }
484
485 }