Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From 43c894588777fa219440dea797a5460bb8e7e95a Mon Sep 17 00:00:00 2001
From: gagarine <simon@antistatique.net>
Date: Mon, 25 Feb 2013 15:25:32 +0100
Subject: [PATCH] make the export function works
---
wp/wp-content/plugins/surveys/export.php | 19 ++++++++++---------
wp/wp-content/plugins/surveys/export_choose.php | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/wp/wp-content/plugins/surveys/export.php b/wp/wp-content/plugins/surveys/export.php
index 5c80b9d..ec0dea7 100644
--- a/wp/wp-content/plugins/surveys/export.php
+++ b/wp/wp-content/plugins/surveys/export.php
@@ -1,5 +1,5 @@
<?php
-include('../../../wp-blog-header.php');
+include('../../../wp-load.php');
auth_redirect();
include('wpframe.php');
@@ -8,13 +8,14 @@
$all_results = $wpdb->get_results($wpdb->prepare("SELECT ID,added_on, name, email FROM {$wpdb->prefix}surveys_result WHERE survey_ID=%d ORDER BY added_on", $_REQUEST['survey']));
$questions = $wpdb->get_results($wpdb->prepare("SELECT ID, question FROM {$wpdb->prefix}surveys_question WHERE survey_ID=%d", $_REQUEST['survey']));
-$survey_name = preg_replace('/\W/', '_', $survey_name);
-$survey_name = preg_replace('/_{2,}/', '_', $survey_name);
+$survey_name = sanitize_file_name($survey_name);
// header("Content-type:text/octect-stream");
-// header("Content-Disposition:attachment;filename=$survey_name.csv");
-header("Content-type:text/plain");
-
+header("Cache-Control: must-revalidate");
+header("Pragma: must-revalidate");
+header('Content-disposition: attachment; filename="' . $survey_name . ' .csv"');
+header("Content-type: text/csv; charset=utf-8");
+//header("Content-type: application/vnd.ms-excel");
// Show the question at the top
$show_questions_in_header = get_option('surveys_insert_csv_header');
@@ -26,7 +27,7 @@
if(!empty($_REQUEST['email'])) $fields[] = "Email";
if(!empty($_REQUEST['answers'])) {
foreach($questions as $q)
- $fields[] = str_replace(array("\n", '"'), array('',"'"), stripslashes($q->question));
+ $fields[] = str_replace(array("\n", '"'), array('',"'"), stripslashes(mb_convert_encoding($q->question, "Windows-1252")));
}
print '"' . implode('","', $fields) . "\"\n";
}
@@ -49,8 +50,8 @@
//If this quesiton has multiple answers...
$selected_answers = array();
foreach($all_answers_for_question as $one_answer) {
- if($one_answer->answer_ID) $selected_answers[] = stripslashes($one_answer->answer);
- else $selected_answers[] = stripslashes($one_answer->user_answer); //Custom User answer.
+ if($one_answer->answer_ID) $selected_answers[] = stripslashes(mb_convert_encoding($one_answer->answer, "Windows-1252"));
+ else $selected_answers[] = stripslashes(mb_convert_encoding($one_answer->user_answer, "Windows-1252")); //Custom User answer.
}
$answers[] = implode('|', $selected_answers); //Custom answer.
}
diff --git a/wp/wp-content/plugins/surveys/export_choose.php b/wp/wp-content/plugins/surveys/export_choose.php
index e36b132..7b0ea37 100644
--- a/wp/wp-content/plugins/surveys/export_choose.php
+++ b/wp/wp-content/plugins/surveys/export_choose.php
@@ -4,7 +4,7 @@
<div class="wrap">
<h2><?php e("Export Data") ?></h2>
-<form action="<?php echo $GLOBALS['wpframe_plugin_folder'] ?>/export.php" method="post">
+<form action="<?php echo $GLOBALS['wpframe_plugin_folder'] ?>/export.php" method="get">
<p><?php e("Select the fields you want to export...") ?></p>
<?php
--
1.7.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.