Files
luxtools-plugin/syntax/files.php
luxick f83248d605
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
Optical rendering of file and image listings
2026-01-06 14:34:05 +01:00

63 lines
1.6 KiB
PHP

<?php
use dokuwiki\plugin\luxtools\Output;
require_once(__DIR__ . '/AbstractSyntax.php');
/**
* LuxTools Plugin: Files syntax.
*
* Lists files matching a given glob pattern.
*/
class syntax_plugin_luxtools_files extends syntax_plugin_luxtools_abstract
{
/** @inheritdoc */
protected function getSyntaxKeyword(): string
{
return 'files';
}
/** @inheritdoc */
protected function processPath(string $path): array
{
[$base, $pattern] = $this->separatePathAndPattern($path);
return ['base' => $base, 'pattern' => $pattern];
}
/** @inheritdoc */
protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool
{
$pathInfo = $this->getPathInfoSafe($pathData['base'], $renderer);
if ($pathInfo === false) {
return true;
}
$crawler = $this->createCrawler($params);
$result = $crawler->crawl(
$pathInfo['root'],
$pathInfo['local'],
$pathData['pattern'],
$params['recursive'],
$params['titlefile']
);
if ($result == []) {
$this->renderEmptyState($renderer, 'empty_files');
return true;
}
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $result);
switch ($params['style']) {
case 'list':
case 'olist':
$output->renderAsList($params);
break;
case 'table':
$output->renderAsTable($params);
break;
}
return true;
}
}