63 lines
1.6 KiB
PHP
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;
|
|
}
|
|
}
|