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