Allow downloading the pagelink file directly
This commit is contained in:
37
pagelink.php
37
pagelink.php
@@ -46,12 +46,19 @@ if ($cmd === '' || $pageId === '') {
|
||||
luxtools_pagelink_json(400, ['ok' => false, 'error' => 'missing parameters']);
|
||||
}
|
||||
|
||||
if (!function_exists('auth_quickaclcheck') || !defined('AUTH_EDIT')) {
|
||||
if (!function_exists('auth_quickaclcheck')) {
|
||||
luxtools_pagelink_json(403, ['ok' => false, 'error' => 'forbidden']);
|
||||
}
|
||||
|
||||
if (auth_quickaclcheck($pageId) < AUTH_EDIT) {
|
||||
luxtools_pagelink_json(403, ['ok' => false, 'error' => 'forbidden']);
|
||||
$acl = auth_quickaclcheck($pageId);
|
||||
if ($cmd === 'info' || $cmd === 'download') {
|
||||
if (!defined('AUTH_READ') || $acl < AUTH_READ) {
|
||||
luxtools_pagelink_json(403, ['ok' => false, 'error' => 'forbidden']);
|
||||
}
|
||||
} else {
|
||||
if (!defined('AUTH_EDIT') || $acl < AUTH_EDIT) {
|
||||
luxtools_pagelink_json(403, ['ok' => false, 'error' => 'forbidden']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($cmd === 'info') {
|
||||
@@ -83,6 +90,30 @@ if ($cmd === 'info') {
|
||||
]);
|
||||
}
|
||||
|
||||
if ($cmd === 'download') {
|
||||
$depth = (int)$syntax->getConf('pagelink_search_depth');
|
||||
if ($depth < 0) $depth = 0;
|
||||
|
||||
$pageLink = new PageLink((string)$syntax->getConf('paths'), $depth);
|
||||
$uuid = $pageLink->getPageUuid($pageId);
|
||||
if ($uuid === null || $uuid === '') {
|
||||
http_status(404);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
echo 'not linked';
|
||||
exit;
|
||||
}
|
||||
|
||||
http_status(200);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename=".pagelink"');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
echo $uuid;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($cmd === 'ensure') {
|
||||
if (strtoupper($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
|
||||
luxtools_pagelink_json(405, ['ok' => false, 'error' => 'method not allowed']);
|
||||
|
||||
Reference in New Issue
Block a user