Files
sld-blocknotes/pages/export_blocknote.php
2026-08-19 17:26:06 +01:00

28 lines
755 B
PHP

<?php
require_login();
$user = current_user();
$blocknote_id = $_GET['id'] ?? '';
$bn = get_blocknote_by_id($blocknote_id);
if (!$bn || !can_access_blocknote($bn, $user['username'], is_admin())) {
header("Location: index.php?page=home");
exit;
}
// Clean output buffer before outputting binary/file response
if (ob_get_level()) {
ob_end_clean();
}
$safe_title = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $bn['title']);
$filename = "blocknote_" . $safe_title . "_" . $bn['id'] . ".json";
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Pragma: no-cache');
header('Expires: 0');
echo json_encode($bn, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;