public function get_file() { $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : ''; if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) { die(__('Security check', 'wp_all_export_plugin')); } else { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $id = $this->input->get('id'); $export = new PMXE_Export_Record(); $filepath = ''; if (!$export->getById($id)->isEmpty()) { if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } if (@file_exists($filepath)) { switch ($export->options['export_to']) { case 'xml': PMXE_download::xml($filepath); break; case 'csv': PMXE_download::csv($filepath); break; default: wp_redirect(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'pmxe_plugin')), $this->baseUrl)); die; break; } } else { 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.', 'pmxe_plugin')), $this->baseUrl)); die; } } else { 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.', 'pmxe_plugin')), $this->baseUrl)); die; } } }
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(); }
public function download() { $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : ''; if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) { die(__('Security check', 'wp_all_export_plugin')); } else { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $id = $this->input->get('id'); $export = new PMXE_Export_Record(); $filepath = ''; if (!$export->getById($id)->isEmpty()) { if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } if (@file_exists($filepath)) { switch ($export['options']['export_to']) { case 'xml': PMXE_download::xml($filepath); break; case 'csv': PMXE_download::csv($filepath); break; default: break; } } } } }
public function download() { $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : ''; if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) { die(__('Security check', 'wp_all_export_plugin')); } else { $attch_url = PMXE_Plugin::$session->file; $export_type = PMXE_Plugin::$session->export_to; // clear import session PMXE_Plugin::$session->clean_session(); // clear session data (prevent from reimporting the same data on page refresh) switch ($export_type) { case 'xml': PMXE_download::xml($attch_url); break; case 'csv': PMXE_download::csv($attch_url); break; default: # code... break; } } }