V1
This commit is contained in:
85
action.php
85
action.php
@@ -3,6 +3,9 @@
|
||||
use dokuwiki\Extension\ActionPlugin;
|
||||
use dokuwiki\Extension\Event;
|
||||
use dokuwiki\Extension\EventHandler;
|
||||
use dokuwiki\plugin\luxtools\PageLink;
|
||||
|
||||
require_once(__DIR__ . '/autoload.php');
|
||||
|
||||
/**
|
||||
* luxtools action plugin: register JS assets.
|
||||
@@ -18,6 +21,12 @@ class action_plugin_luxtools extends ActionPlugin
|
||||
$this,
|
||||
"addScripts",
|
||||
);
|
||||
$controller->register_hook(
|
||||
"TPL_CONTENT_DISPLAY",
|
||||
"BEFORE",
|
||||
$this,
|
||||
"addPageLinkStatus",
|
||||
);
|
||||
$controller->register_hook(
|
||||
"CSS_STYLES_INCLUDED",
|
||||
"BEFORE",
|
||||
@@ -49,6 +58,7 @@ class action_plugin_luxtools extends ActionPlugin
|
||||
"open-service.js",
|
||||
"scratchpads.js",
|
||||
"date-fix.js",
|
||||
"page-link.js",
|
||||
"linkfavicon.js",
|
||||
"main.js",
|
||||
];
|
||||
@@ -118,5 +128,80 @@ class action_plugin_luxtools extends ActionPlugin
|
||||
"icon" => "../../plugins/luxtools/images/date-fix-all.svg",
|
||||
"block" => false,
|
||||
];
|
||||
|
||||
// Page Link: create a page-scoped UUID for .pagelink linking
|
||||
$event->data[] = [
|
||||
"type" => "LuxtoolsPageLink",
|
||||
"title" => $this->getLang("toolbar_pagelink_title"),
|
||||
"icon" => "../../plugins/luxtools/images/pagelink.svg",
|
||||
"block" => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject page link status above the page content.
|
||||
*
|
||||
* @param Event $event
|
||||
* @param mixed $param
|
||||
* @return void
|
||||
*/
|
||||
public function addPageLinkStatus(Event $event, $param)
|
||||
{
|
||||
global $ACT, $ID;
|
||||
|
||||
if (!is_string($ACT) || $ACT !== 'show') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($ID) || $ID === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$pageId = $ID;
|
||||
if (function_exists('cleanID')) {
|
||||
$pageId = (string)cleanID($pageId);
|
||||
}
|
||||
if ($pageId === '') return;
|
||||
|
||||
$pathConfig = (string)$this->getConf('paths');
|
||||
$depth = (int)$this->getConf('pagelink_search_depth');
|
||||
if ($depth < 0) $depth = 0;
|
||||
|
||||
$pageLink = new PageLink($pathConfig, $depth);
|
||||
$uuid = $pageLink->getPageUuid($pageId);
|
||||
if ($uuid === null) return;
|
||||
|
||||
$linkInfo = $pageLink->resolveUuid($uuid);
|
||||
$folder = $linkInfo['folder'] ?? null;
|
||||
$multiple = !empty($linkInfo['multiple']);
|
||||
|
||||
$statusText = '';
|
||||
$copyable = false;
|
||||
$title = '';
|
||||
if (is_string($folder) && $folder !== '') {
|
||||
$trimmed = rtrim($folder, '/\\');
|
||||
$statusText = basename($trimmed);
|
||||
$title = $trimmed;
|
||||
} else {
|
||||
$statusText = (string)$this->getLang('pagelink_unlinked');
|
||||
$copyable = true;
|
||||
}
|
||||
|
||||
$warning = '';
|
||||
if ($multiple) {
|
||||
$warning = '<span class="luxtools-pagelink-warning" title="' . hsc((string)$this->getLang('pagelink_multi_warning')) . '" aria-hidden="true">⚠</span>';
|
||||
}
|
||||
|
||||
$html = '<span class="luxtools-pagelink-status" data-luxtools-pagelink="1"'
|
||||
. ' data-uuid="' . hsc($uuid) . '"'
|
||||
. ' data-copy="' . ($copyable ? '1' : '0') . '"'
|
||||
. ' data-multiple="' . ($multiple ? '1' : '0') . '"'
|
||||
. ($title !== '' ? ' title="' . hsc($title) . '"' : '')
|
||||
. '>'
|
||||
. hsc($statusText)
|
||||
. $warning
|
||||
. '</span>';
|
||||
|
||||
$event->data = $html . $event->data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user