70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
use dokuwiki\plugin\luxtools\Output;
|
|
use dokuwiki\plugin\luxtools\Path;
|
|
|
|
require_once(__DIR__ . '/AbstractSyntax.php');
|
|
|
|
/**
|
|
* LuxTools Plugin: Directory syntax.
|
|
*
|
|
* Lists the direct children (folders and files) of a given path.
|
|
* Always renders as a table.
|
|
*/
|
|
class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
|
|
{
|
|
/** @inheritdoc */
|
|
protected function getDefaultParams(): array
|
|
{
|
|
return [
|
|
// Directory listings should group folders before files by default.
|
|
'foldersfirst' => 1,
|
|
];
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
protected function getSyntaxKeyword(): string
|
|
{
|
|
return 'directory';
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
protected function processPath(string $path): array
|
|
{
|
|
// Directory path (no glob/pattern)
|
|
$path = Path::cleanPath($path, true);
|
|
return ['path' => $path];
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool
|
|
{
|
|
$pathInfo = $this->getPathInfoSafe($pathData['path'], $renderer);
|
|
if ($pathInfo === false) {
|
|
return true;
|
|
}
|
|
|
|
// Provide the current directory path so Output can render the "Open Location" link.
|
|
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
|
|
|
|
$crawler = $this->createCrawler($params);
|
|
$items = $crawler->listDirectory(
|
|
$pathInfo['root'],
|
|
$pathInfo['local'],
|
|
$params['titlefile']
|
|
);
|
|
|
|
if ($items == []) {
|
|
$this->renderError($renderer, 'error_nomatch');
|
|
return true;
|
|
}
|
|
|
|
// Always render as table style
|
|
$params['style'] = 'table';
|
|
|
|
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items);
|
|
$output->renderAsFlatTable($params);
|
|
return true;
|
|
}
|
|
}
|