public function index() { $this->data['post'] = $post = $this->input->post(PMXE_Plugin::getInstance()->getOption()); if ($this->input->post('is_settings_submitted')) { // save settings form check_admin_referer('edit-settings', '_wpnonce_edit-settings'); if (!$this->errors->get_error_codes()) { // no validation errors detected PMXE_Plugin::getInstance()->updateOption($post); wp_redirect(add_query_arg('pmxe_nt', urlencode(__('Settings saved', 'pmxe_plugin')), $this->baseUrl)); die; } } if ($this->input->post('is_templates_submitted')) { // delete templates form check_admin_referer('delete-templates', '_wpnonce_delete-templates'); if ($this->input->post('import_templates')) { if (!empty($_FILES)) { $file_name = $_FILES['template_file']['name']; $file_size = $_FILES['template_file']['size']; $tmp_name = $_FILES['template_file']['tmp_name']; if (isset($file_name)) { $filename = stripslashes($file_name); $extension = strtolower(pmxe_getExtension($filename)); if ($extension != "txt") { $this->errors->add('form-validation', __('Unknown File extension. Only txt files are permitted', 'wp_all_export_plugin')); } else { $import_data = @file_get_contents($tmp_name); if (!empty($import_data)) { $templates_data = json_decode($import_data, true); if (!empty($templates_data)) { $template = new PMXE_Template_Record(); foreach ($templates_data as $template_data) { unset($template_data['id']); $template->clear()->set($template_data)->insert(); } wp_redirect(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template imported', '%d templates imported', count($templates_data), 'wp_all_export_plugin'), count($templates_data))), $this->baseUrl)); die; } else { $this->errors->add('form-validation', __('Wrong imported data format', 'wp_all_export_plugin')); } } else { $this->errors->add('form-validation', __('File is empty or doesn\'t exests', 'wp_all_export_plugin')); } } } else { $this->errors->add('form-validation', __('Undefined entry!', 'wp_all_export_plugin')); } } else { $this->errors->add('form-validation', __('Please select file.', 'wp_all_export_plugin')); } } else { $templates_ids = $this->input->post('templates', array()); if (empty($templates_ids)) { $this->errors->add('form-validation', __('Templates must be selected', 'wp_all_export_plugin')); } if (!$this->errors->get_error_codes()) { // no validation errors detected if ($this->input->post('delete_templates')) { $template = new PMXE_Template_Record(); foreach ($templates_ids as $template_id) { $template->clear()->set('id', $template_id)->delete(); } wp_redirect(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'wp_all_export_plugin'), count($templates_ids))), $this->baseUrl)); die; } if ($this->input->post('export_templates')) { $export_data = array(); $template = new PMXE_Template_Record(); foreach ($templates_ids as $template_id) { $export_data[] = $template->clear()->getBy('id', $template_id)->toArray(TRUE); } $uploads = wp_upload_dir(); $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY; $export_file_name = "templates_" . uniqid() . ".txt"; file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data)); PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name); } } } } $this->render(); }
/** * Step #2: Export Template */ public function template() { $template = new PMXE_Template_Record(); $default = PMXE_Plugin::get_default_import_options(); $this->data['dismiss_warnings'] = 0; if ($this->isWizard) { $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default; $post = $this->input->post($DefaultOptions); } else { $DefaultOptions = $this->data['export']->options + $default; $post = $this->input->post($DefaultOptions); $post['scheduled'] = $this->data['export']->scheduled; foreach ($post as $key => $value) { PMXE_Plugin::$session->set($key, $value); } $this->data['dismiss_warnings'] = get_option('wpae_dismiss_warnings_' . $this->data['export']->id, 0); } $max_input_vars = @ini_get('max_input_vars'); if (ctype_digit($max_input_vars) && count($_POST, COUNT_RECURSIVE) >= $max_input_vars) { $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)); } PMXE_Plugin::$session->save_data(); $this->data['post'] =& $post; PMXE_Plugin::$session->set('is_loaded_template', ''); if ($load_template = $this->input->post('load_template')) { // init form with template selected if (!$template->getById($load_template)->isEmpty()) { $template_options = $template->options; unset($template_options['cpt']); unset($template_options['export_to']); unset($template_options['export_type']); unset($template_options['wp_query']); unset($template_options['filter_rules_hierarhy']); unset($template_options['product_matching_mode']); unset($template_options['wp_query_selector']); $this->data['post'] = array_merge($post, $template_options); PMXE_Plugin::$session->set('is_loaded_template', $load_template); //PMXE_Plugin::$session->set('options', $template_options); } } elseif ($this->input->post('is_submitted')) { check_admin_referer('template', '_wpnonce_template'); if (empty($post['cc_type'][0])) { $this->errors->add('form-validation', __('You haven\'t selected any columns for export.', 'wp_all_export_plugin')); } if ('csv' == $post['export_to'] and '' == $post['delimiter']) { $this->errors->add('form-validation', __('CSV delimiter must be specified.', 'wp_all_export_plugin')); } if ('xml' == $post['export_to']) { $post['main_xml_tag'] = preg_replace('/[^a-z0-9]/i', '', $post['main_xml_tag']); if (empty($post['main_xml_tag'])) { $this->errors->add('form-validation', __('Main XML Tag is required.', 'wp_all_export_plugin')); } $post['record_xml_tag'] = preg_replace('/[^a-z0-9]/i', '', $post['record_xml_tag']); if (empty($post['record_xml_tag'])) { $this->errors->add('form-validation', __('Single Record XML Tag is required.', 'wp_all_export_plugin')); } if ($post['main_xml_tag'] == $post['record_xml_tag']) { $this->errors->add('form-validation', __('Main XML Tag equals to Single Record XML Tag.', 'wp_all_export_plugin')); } } if (!$this->errors->get_error_codes()) { if (!empty($post['name']) and !empty($post['save_template_as'])) { // save template in database $template->getByName($post['name'])->set(array('name' => $post['name'], 'options' => $post))->save(); PMXE_Plugin::$session->set('saved_template', $template->id); } if ($this->isWizard) { foreach ($this->data['post'] as $key => $value) { PMXE_Plugin::$session->set($key, $value); } PMXE_Plugin::$session->save_data(); wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die; } else { $this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save(); if (!empty($post['friendly_name'])) { $this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => $post['is_scheduled'] ? $post['scheduled_period'] : ''))->save(); } 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'))); die; } } } $this->data['engine'] = new XmlExportEngine($post, $this->errors); $this->data['engine']->init_additional_data(); $this->data = array_merge($this->data, $this->data['engine']->init_available_data()); $this->data['available_data_view'] = $this->data['engine']->render(); $this->data['available_fields_view'] = $this->data['engine']->render_new_field(); $this->render(); }
/** * Step #2: Template */ public function template() { $template = new PMXE_Template_Record(); $default = PMXE_Plugin::get_default_import_options(); if ($this->isWizard) { $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default; $post = $this->input->post($DefaultOptions); } else { $DefaultOptions = $this->data['export']->options + $default; $post = $this->input->post($DefaultOptions); $post['scheduled'] = $this->data['export']->scheduled; foreach ($post as $key => $value) { PMXE_Plugin::$session->set($key, $value); } } PMXE_Plugin::$session->save_data(); $this->data['post'] =& $post; PMXE_Plugin::$session->set('is_loaded_template', ''); if ($load_template = $this->input->post('load_template')) { // init form with template selected if (!$template->getById($load_template)->isEmpty()) { $template_options = $template->options; unset($template_options['cpt']); unset($template_options['export_to']); unset($template_options['export_type']); unset($template_options['wp_query']); unset($template_options['filter_rules_hierarhy']); unset($template_options['product_matching_mode']); unset($template_options['wp_query_selector']); $this->data['post'] = array_merge($post, $template_options); PMXE_Plugin::$session->set('is_loaded_template', $load_template); } } elseif ($this->input->post('is_submitted')) { check_admin_referer('template', '_wpnonce_template'); if (empty($post['cc_type'][0])) { $this->errors->add('form-validation', __('You haven\'t selected any columns for export.', 'wp_all_export_plugin')); } if ('csv' == $post['export_to'] and '' == $post['delimiter']) { $this->errors->add('form-validation', __('CSV delimiter must be specified.', 'wp_all_export_plugin')); } if (!$this->errors->get_error_codes()) { if (!empty($post['name']) and !empty($post['save_template_as'])) { // save template in database $template->getByName($post['name'])->set(array('name' => $post['name'], 'options' => $post))->save(); PMXE_Plugin::$session->set('saved_template', $template->id); } if ($this->isWizard) { foreach ($this->data['post'] as $key => $value) { PMXE_Plugin::$session->set($key, $value); } PMXE_Plugin::$session->save_data(); wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die; } else { $this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save(); if (!empty($post['friendly_name'])) { $this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => $post['is_scheduled'] ? $post['scheduled_period'] : ''))->save(); } 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'))); die; } } } $engine = new XmlExportEngine($post, $this->errors); $engine->init_additional_data(); $this->data = array_merge($this->data, $engine->init_available_data()); $this->data['available_data_view'] = $engine->render(); $this->render(); }