/** * 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(); }