Improved Page lik handling
This commit is contained in:
@@ -133,7 +133,18 @@ class syntax_plugin_luxtools_image extends SyntaxPlugin
|
||||
}
|
||||
|
||||
try {
|
||||
$pathHelper = new Path($this->buildPathConfigWithBlobs());
|
||||
$blobsRoot = $this->resolveBlobsRoot();
|
||||
if ($blobsRoot === '' && $this->isBlobsPath($data['path'] ?? '')) {
|
||||
$this->renderPageNotLinked($renderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
$pathConfig = (string)$this->getConf('paths');
|
||||
if ($blobsRoot !== '') {
|
||||
$pathConfig = rtrim($pathConfig) . "\n" . $blobsRoot . "\nA> blobs";
|
||||
}
|
||||
|
||||
$pathHelper = new Path($pathConfig);
|
||||
// Use addTrailingSlash=false since this is a file path, not a directory
|
||||
$pathInfo = $pathHelper->getPathInfo($data['path'], false);
|
||||
} catch (\Exception $e) {
|
||||
@@ -216,16 +227,52 @@ class syntax_plugin_luxtools_image extends SyntaxPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a path configuration string, adding the blobs alias if available.
|
||||
* Check if the given path uses the blobs alias.
|
||||
*/
|
||||
protected function buildPathConfigWithBlobs(): string
|
||||
protected function isBlobsPath(string $path): bool
|
||||
{
|
||||
$pathConfig = (string)$this->getConf('paths');
|
||||
$blobsRoot = $this->resolveBlobsRoot();
|
||||
if ($blobsRoot !== '') {
|
||||
$pathConfig = rtrim($pathConfig) . "\n" . $blobsRoot . "\nA> blobs";
|
||||
$trimmed = ltrim($path, '/');
|
||||
return preg_match('/^blobs(\/|$)/', $trimmed) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the "Page not linked" message with copy ID affordance.
|
||||
*/
|
||||
protected function renderPageNotLinked(\Doku_Renderer $renderer): void
|
||||
{
|
||||
$uuid = $this->getPageUuidSafe();
|
||||
$text = (string)$this->getLang('pagelink_unlinked');
|
||||
|
||||
if ($renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$renderer->doc .= '<a href="#" class="luxtools-pagelink-copy" data-luxtools-pagelink-copy="1"'
|
||||
. ' data-uuid="' . hsc($uuid) . '"'
|
||||
. '>' . hsc($text) . '</a>';
|
||||
return;
|
||||
}
|
||||
return $pathConfig;
|
||||
|
||||
$renderer->cdata('[n/a: ' . $text . ']');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the current page UUID (if any).
|
||||
*/
|
||||
protected function getPageUuidSafe(): string
|
||||
{
|
||||
global $ID;
|
||||
$pageId = is_string($ID) ? $ID : '';
|
||||
if ($pageId === '') return '';
|
||||
|
||||
if (function_exists('cleanID')) {
|
||||
$pageId = (string)cleanID($pageId);
|
||||
}
|
||||
if ($pageId === '') return '';
|
||||
|
||||
$depth = (int)$this->getConf('pagelink_search_depth');
|
||||
if ($depth < 0) $depth = 0;
|
||||
|
||||
$pageLink = new PageLink((string)$this->getConf('paths'), $depth);
|
||||
$uuid = $pageLink->getPageUuid($pageId);
|
||||
return $uuid ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user