Major Refactoring (will need some cleanup)
This refactors the plugin from one mega syntax file into multiple classes. The plugin now focuses on one usecase: listing files that are external to the wiki and making them downloadable. All other usecases have been dropped. Also a bunch of other options have been dropped. A new dispatcher makes it possible to deliver files without the need to have the webserver pointing at them.
This commit is contained in:
40
file.php
Normal file
40
file.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\plugin\filelist\Path;
|
||||
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
global $INPUT;
|
||||
|
||||
$syntax = plugin_load('syntax', 'filelist');
|
||||
if (!$syntax) die('plugin disabled?');
|
||||
|
||||
$pathUtil = new Path($syntax->getConf('paths'));
|
||||
$path = $INPUT->str('root') . $INPUT->str('file');
|
||||
|
||||
try {
|
||||
$pathInfo = $pathUtil->getPathInfo($path, false);
|
||||
if (!is_readable($pathInfo['path'])) {
|
||||
header('Content-Type: text/plain');
|
||||
http_status(404);
|
||||
echo 'Path not readable: ' . $pathInfo['path'];
|
||||
exit;
|
||||
}
|
||||
[$ext, $mime, $download] = mimetype($pathInfo['path'], false);
|
||||
$basename = basename($pathInfo['path']);
|
||||
header('Content-Type: ' . $mime);
|
||||
if ($download) {
|
||||
header('Content-Disposition: attachment; filename="' . $basename . '"');
|
||||
}
|
||||
http_sendfile($pathInfo['path']);
|
||||
readfile($pathInfo['path']);
|
||||
} catch (Exception $e) {
|
||||
header('Content-Type: text/plain');
|
||||
http_status(403);
|
||||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user