From d460914f65254d201911a8346792d680218c8dc3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 12 Dec 2013 09:42:19 +0100 Subject: [PATCH] [add] download database if sqlite is on --- inc/poche/Tools.class.php | 24 ++++++++++++++++++++++++ index.php | 2 ++ themes/default/config.twig | 2 ++ 3 files changed, 28 insertions(+) diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 750553f1..9d8e1fd6 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -249,4 +249,28 @@ class Tools $lang = explode('.', $userlanguage); return str_replace('_', '-', $lang[0]); } + + public static function status($status_code) + { + if (strpos(php_sapi_name(), 'apache') !== false) { + + header('HTTP/1.0 '.$status_code); + } + else { + + header('Status: '.$status_code); + } + } + + + public static function download_db() { + header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); + self::status(200); + + header('Content-Transfer-Encoding: binary'); + header('Content-Type: application/octet-stream'); + echo gzencode(file_get_contents(STORAGE_SQLITE)); + + exit; + } } diff --git a/index.php b/index.php index 96f28a72..d2b363b0 100644 --- a/index.php +++ b/index.php @@ -64,6 +64,8 @@ if (isset($_GET['login'])) { $poche->updatePassword(); } elseif (isset($_GET['import'])) { $import = $poche->import($_GET['from']); +} elseif (isset($_GET['download'])) { + Tools::download_db();; } elseif (isset($_GET['export'])) { $poche->export(); } elseif (isset($_GET['updatetheme'])) { diff --git a/themes/default/config.twig b/themes/default/config.twig index 1d7fb562..a1f46b8b 100644 --- a/themes/default/config.twig +++ b/themes/default/config.twig @@ -109,5 +109,7 @@

{% trans "Export your poche datas" %}

+ {% if constant('STORAGE') == 'sqlite' %} +

{% trans "Click here" %} {% trans "to download your database." %}

{% endif %}

{% trans "Click here" %} {% trans "to export your poche datas." %}

{% endblock %} -- 2.41.0