Clean up unused syntax
This commit is contained in:
@@ -10,6 +10,7 @@ require_once(__DIR__ . '/AbstractSyntax.php');
|
||||
*
|
||||
* Lists the direct children (folders and files) of a given path.
|
||||
* Always renders as a table.
|
||||
* Also accepts the 'files' keyword for backwards compatibility with glob patterns.
|
||||
*/
|
||||
class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
|
||||
{
|
||||
@@ -28,38 +29,101 @@ class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
|
||||
return 'directory';
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function connectTo($mode)
|
||||
{
|
||||
// Accept both {{directory>...}} and {{files>...}} for backwards compatibility
|
||||
$this->Lexer->addSpecialPattern('\{\{directory>.+?\}\}', $mode, 'plugin_luxtools_directory');
|
||||
$this->Lexer->addSpecialPattern('\{\{files>.+?\}\}', $mode, 'plugin_luxtools_directory');
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function handle($match, $state, $pos, Doku_Handler $handler)
|
||||
{
|
||||
// Detect which keyword was used
|
||||
$keyword = 'directory';
|
||||
if (str_starts_with($match, '{{files>')) {
|
||||
$keyword = 'files';
|
||||
}
|
||||
|
||||
$match = substr($match, strlen('{{' . $keyword . '>'), -2);
|
||||
[$path, $flags] = array_pad(explode('&', $match, 2), 2, '');
|
||||
|
||||
$params = $this->parseFlags($flags);
|
||||
$pathData = $this->processPath($path);
|
||||
|
||||
// Store the original keyword to determine processing mode
|
||||
$pathData['isGlobPattern'] = ($keyword === 'files');
|
||||
|
||||
return ['pathData' => $pathData, 'params' => $params];
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
protected function processPath(string $path): array
|
||||
{
|
||||
// Directory path (no glob/pattern)
|
||||
$path = Path::cleanPath($path, true);
|
||||
return ['path' => $path];
|
||||
// Check if path contains glob characters (*, ?, [, ])
|
||||
$hasGlob = (str_contains($path, '*') || str_contains($path, '?') ||
|
||||
str_contains($path, '[') || str_contains($path, ']'));
|
||||
|
||||
if ($hasGlob) {
|
||||
// Process as glob pattern (old files syntax)
|
||||
[$base, $pattern] = $this->separatePathAndPattern($path);
|
||||
return ['base' => $base, 'pattern' => $pattern, 'isGlobPattern' => true];
|
||||
} else {
|
||||
// Process as directory path
|
||||
$path = Path::cleanPath($path, true);
|
||||
return ['path' => $path, 'isGlobPattern' => false];
|
||||
}
|
||||
}
|
||||
|
||||
/** @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;
|
||||
$isGlobPattern = $pathData['isGlobPattern'] ?? false;
|
||||
|
||||
if ($isGlobPattern && isset($pathData['base'], $pathData['pattern'])) {
|
||||
// Old files syntax behavior: crawl with glob pattern
|
||||
$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']
|
||||
);
|
||||
|
||||
// Pass the base directory as openlocation so the "Open Location" link is displayed.
|
||||
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
|
||||
|
||||
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $result, $this);
|
||||
$output->renderAsTable($params);
|
||||
} else {
|
||||
// Normal directory listing behavior
|
||||
$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']
|
||||
);
|
||||
|
||||
// Render the table even if empty so the "Open Location" link is displayed.
|
||||
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items, $this);
|
||||
$output->renderAsFlatTable($params);
|
||||
}
|
||||
|
||||
// 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']
|
||||
);
|
||||
|
||||
// Always render as table style
|
||||
$params['style'] = 'table';
|
||||
|
||||
// Render the table even if empty so the "Open Location" link is displayed.
|
||||
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items);
|
||||
$output->renderAsFlatTable($params);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user