From b78b0cd109b3d3bf7007ea68a344013fe5ea9dc3 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 29 Jun 2012 14:41:47 -0700 Subject: [PATCH] Plugin for including date in export filename --- adminer/include/adminer.inc.php | 11 ++++++++--- adminer/include/functions.inc.php | 4 ++++ editor/include/adminer.inc.php | 5 ++++- plugins/dump-date.php | 15 +++++++++++++++ plugins/dump-xml.php | 7 ++++--- plugins/plugin.php | 5 +++++ 6 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 plugins/dump-date.php diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index db651370..76103f89 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -716,6 +716,14 @@ DROP PROCEDURE adminer_alter; } } + /** Set export filename + * @param string + * @return string filename without extension + */ + function dumpFilename($identifier) { + return friendly_url($identifier != "" ? $identifier : (SERVER != "" ? SERVER : "localhost")); + } + /** Send headers for export * @param string * @param bool @@ -730,9 +738,6 @@ DROP PROCEDURE adminer_alter; ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8" )))); - if ($output != "text") { - header("Content-Disposition: attachment; filename=" . friendly_url($identifier != "" ? $identifier : (SERVER != "" ? SERVER : "localhost")) . ".$ext" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : "")); - } if ($output == "bz2") { ob_start('bzcompress', 1e6); } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 47651339..9e47557d 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -803,6 +803,10 @@ function search_tables() { function dump_headers($identifier, $multi_table = false) { global $adminer; $return = $adminer->dumpHeaders($identifier, $multi_table); + $output = $_POST["output"]; + if ($output != "text") { + header("Content-Disposition: attachment; filename=" . $adminer->dumpFilename($identifier) . ".$return" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : "")); + } session_write_close(); return $return; } diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index f99e45f2..d5210331 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -505,10 +505,13 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5 } } + function dumpFilename($identifier) { + return friendly_url($identifier); + } + function dumpHeaders($identifier, $multi_table = false) { $ext = "csv"; header("Content-Type: text/csv; charset=utf-8"); - header("Content-Disposition: attachment; filename=" . friendly_url($identifier) . ".$ext"); return $ext; } diff --git a/plugins/dump-date.php b/plugins/dump-date.php new file mode 100644 index 00000000..9f2857a5 --- /dev/null +++ b/plugins/dump-date.php @@ -0,0 +1,15 @@ +result("SELECT NOW()")); + } + +} diff --git a/plugins/dump-xml.php b/plugins/dump-xml.php index af39363f..4e469920 100644 --- a/plugins/dump-xml.php +++ b/plugins/dump-xml.php @@ -6,6 +6,8 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) */ class AdminerDumpXml { + /** @access protected */ + var $database = false; function dumpFormat() { return array('xml' => 'XML'); @@ -22,10 +24,9 @@ class AdminerDumpXml { } function dumpData($table, $style, $query) { - static $database = false; if ($_POST["format"] == "xml") { - if (!$database) { - $database = true; + if (!$this->database) { + $this->database = true; echo "\n"; register_shutdown_function(array($this, '_database')); } diff --git a/plugins/plugin.php b/plugins/plugin.php index 31f8e63a..1d602059 100644 --- a/plugins/plugin.php +++ b/plugins/plugin.php @@ -291,6 +291,11 @@ class AdminerPlugin extends Adminer { return $this->_applyPlugin(__FUNCTION__, $args); } + function dumpFilename() { + $args = func_get_args(); + return $this->_applyPlugin(__FUNCTION__, $args); + } + function dumpHeaders() { $args = func_get_args(); return $this->_applyPlugin(__FUNCTION__, $args);