| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* JCH Optimize - Performs several front-end optimizations for fast downloads |
| 5 |
* |
| 6 |
* @package jchoptimize/wordpress-platform |
| 7 |
* @author Samuel Marshall <samuel@jch-optimize.net> |
| 8 |
* @copyright Copyright (c) 2023 Samuel Marshall / JCH Optimize |
| 9 |
* @license GNU/GPLv3, or later. See LICENSE file |
| 10 |
* |
| 11 |
* If LICENSE file missing, see <http://www.gnu.org/licenses/>. |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace JchOptimize\WordPress\Controller; |
| 15 |
|
| 16 |
use _JchOptimizeVendor\V91\Joomla\Filesystem\File; |
| 17 |
use JchOptimize\Core\Mvc\Controller; |
| 18 |
use JchOptimize\WordPress\Model\BulkSettings; |
| 19 |
|
| 20 |
use function basename; |
| 21 |
use function check_admin_referer; |
| 22 |
use function file_exists; |
| 23 |
use function header; |
| 24 |
use function nocache_headers; |
| 25 |
|
| 26 |
class ExportSettings extends Controller |
| 27 |
{ |
| 28 |
use AuthorizesAdminRequestsTrait; |
| 29 |
|
| 30 |
public function __construct(private BulkSettings $bulkSettings) |
| 31 |
{ |
| 32 |
parent::__construct(); |
| 33 |
} |
| 34 |
|
| 35 |
#[NoReturn] public function execute(): bool |
| 36 |
{ |
| 37 |
$this->authorizeManageOptions(); |
| 38 |
check_admin_referer('jch_bulksettings'); |
| 39 |
|
| 40 |
$file = $this->bulkSettings->exportSettings(); |
| 41 |
|
| 42 |
if (file_exists($file)) { |
| 43 |
header('Content-Description: FileTransfer'); |
| 44 |
header('Content-Type: application/json'); |
| 45 |
header('Content-Disposition: attachment; filename="' . basename($file) . '"'); |
| 46 |
nocache_headers(); |
| 47 |
header('Content-Length: ' . filesize($file)); |
| 48 |
while (ob_get_level()) { |
| 49 |
ob_end_clean(); |
| 50 |
} |
| 51 |
readfile($file); |
| 52 |
|
| 53 |
File::delete($file); |
| 54 |
|
| 55 |
die(); |
| 56 |
} |
| 57 |
|
| 58 |
return true; |
| 59 |
} |
| 60 |
} |
| 61 |
|