From fda8eba4d147a7624f64c03001df1d317804c0d4 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 9 Aug 2014 00:12:37 +0200 Subject: Add a test to check presence of Zip archive. A notification is shown if we cannot use ZipArchive. See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'app/Controllers') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 67c6eb867..ba4ca4eb0 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -339,7 +339,17 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $nb_files = count($export_files); if ($nb_files > 1) { // If there are more than 1 file to export, we need an .zip - $this->exportZip($export_files); + try { + $this->exportZip($export_files); + } catch (Exception $e) { + # Oops, there is no Zip extension! + $notif = array( + 'type' => 'bad', + 'content' => _t('export_no_zip_extension') + ); + Minz_Session::_param('notification', $notif); + Minz_Request::forward(array('c' => 'importExport'), true); + } } elseif ($nb_files === 1) { // Only one file? Guess its type and export it. $filename = key($export_files); @@ -351,6 +361,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $this->exportFile($filename, $export_files[$filename], $type); + } else { + Minz_Request::forward(array('c' => 'importExport'), true); } } } @@ -393,6 +405,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function exportZip($files) { + if (!extension_loaded('zip')) { + throw new Exception(); + } + // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly $zip_file = tempnam('tmp', 'zip'); $zip = new ZipArchive(); @@ -412,6 +428,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function exportFile($filename, $content, $type) { + if (is_null($type)) { + return; + } + header('Content-Type: ' . $type . '; charset=utf-8'); header('Content-disposition: attachment; filename=' . $filename); print($content); -- cgit v1.2.3