getConf(self::CONF_DISABLE_LINK, false) && $mode !== PluginUtility::getModeFromPluginName(ThirdPartyPlugins::IMAGE_MAPPING_NAME) ) { $pattern = LinkUtility::ENTRY_PATTERN_SINGLE_LINE; $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); } } public function postConnect() { if (!$this->getConf(self::CONF_DISABLE_LINK, false)) { $this->Lexer->addExitPattern(LinkUtility::EXIT_PATTERN, PluginUtility::getModeFromTag($this->getPluginComponent())); } } /** * The handler for an internal link * based on `internallink` in {@link Doku_Handler} * The handler call the good renderer in {@link Doku_Renderer_xhtml} with * the parameters (ie for instance internallink) * @param string $match * @param int $state * @param int $pos * @param Doku_Handler $handler * @return array|bool */ function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: $tagAttributes = TagAttributes::createFromCallStackArray(LinkUtility::parse($match)); $callStack = CallStack::createFromHandler($handler); $parent = $callStack->moveToParent(); $parentName = ""; if ($parent != false) { /** * Button Link * Getting the attributes */ $parentName = $parent->getTagName(); if ($parentName == syntax_plugin_combo_button::TAG) { $tagAttributes->mergeWithCallStackArray($parent->getAttributes()); } /** * Searching Clickable parent */ $maxLevel = 3; $level = 0; while ( $parent != false && !$parent->hasAttribute(self::CLICKABLE_ATTRIBUTE) && $level < $maxLevel ) { $parent = $callStack->moveToParent(); $level++; } if ($parent != false) { if ($parent->getAttribute(self::CLICKABLE_ATTRIBUTE)) { $tagAttributes->addClassName("stretched-link"); $parent->addClassName("position-relative"); $parent->removeAttribute(self::CLICKABLE_ATTRIBUTE); } } } $callStackAttributes = $tagAttributes->toCallStackArray(); return array( PluginUtility::STATE => $state, PluginUtility::ATTRIBUTES => $callStackAttributes, PluginUtility::CONTEXT => $parentName ); case DOKU_LEXER_UNMATCHED: $data = PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); /** * Delete the separator `|` between the ref and the description if any */ $tag = CallStack::createFromHandler( $handler); $parent = $tag->moveToParent(); if ($parent->getTagName() == self::TAG) { if (strpos($match, '|') === 0) { $data[PluginUtility::PAYLOAD] = substr($match, 1); } } return $data; case DOKU_LEXER_EXIT: $callStack = CallStack::createFromHandler($handler); $openingTag = $callStack->moveToPreviousCorrespondingOpeningCall(); $openingAttributes = $openingTag->getAttributes(); $openingPosition = $openingTag->getKey(); $callStack->moveToEnd(); $previousCall = $callStack->previous(); $previousCallPosition = $previousCall->getKey(); $previousCallContent = $previousCall->getCapturedContent(); if ( $openingPosition == $previousCallPosition // ie [[id]] || ($openingPosition == $previousCallPosition - 1 && $previousCallContent == "|") // ie [[id|]] ) { // There is no name $link = new LinkUtility($openingAttributes[LinkUtility::ATTRIBUTE_REF]); $linkName = $link->getName(); } else { $linkName = ""; } return array( PluginUtility::STATE => $state, PluginUtility::ATTRIBUTES => $openingAttributes, PluginUtility::PAYLOAD => $linkName, PluginUtility::CONTEXT => $openingTag->getContext() ); } return true; } /** * Render the output * @param string $format * @param Doku_Renderer $renderer * @param array $data - what the function handle() return'ed * @return boolean - rendered correctly? (however, returned value is not used at the moment) * @see DokuWiki_Syntax_Plugin::render() * * */ function render($format, Doku_Renderer $renderer, $data) { // The data switch ($format) { case 'xhtml': /** @var Doku_Renderer_xhtml $renderer */ /** * Cache problem may occurs while releasing */ if (isset($data[PluginUtility::ATTRIBUTES])) { $callStackAttributes = $data[PluginUtility::ATTRIBUTES]; } else { $callStackAttributes = $data; } PluginUtility::getSnippetManager()->attachCssSnippetForBar(self::TAG); $state = $data[PluginUtility::STATE]; switch ($state) { case DOKU_LEXER_ENTER: $tagAttributes = TagAttributes::createFromCallStackArray($callStackAttributes, self::TAG); $ref = $tagAttributes->getValueAndRemove(LinkUtility::ATTRIBUTE_REF); $link = new LinkUtility($ref, $tagAttributes); /** * Extra styling */ $parentTag = $data[PluginUtility::CONTEXT]; switch ($parentTag) { /** * Button link */ case syntax_plugin_combo_button::TAG: $tagAttributes->addHtmlAttributeValue("role", "button"); syntax_plugin_combo_button::processButtonAttributesToHtmlAttributes($tagAttributes); $htmlLink = $link->renderOpenTag($renderer); break; case syntax_plugin_combo_badge::TAG: case syntax_plugin_combo_cite::TAG: case syntax_plugin_combo_contentlistitem::DOKU_TAG: case syntax_plugin_combo_preformatted::TAG: $htmlLink = $link->renderOpenTag($renderer); break; case syntax_plugin_combo_dropdown::TAG: $tagAttributes->addClassName("dropdown-item"); $htmlLink = $link->renderOpenTag($renderer); break; case syntax_plugin_combo_navbarcollapse::COMPONENT: $tagAttributes->addClassName("navbar-link"); $htmlLink = '
'; break; case syntax_plugin_combo_navbargroup::COMPONENT: $renderer->doc .= ''; break; } } return true; case 'metadata': $state = $data[PluginUtility::STATE]; if ($state == DOKU_LEXER_ENTER) { /** * Keep track of the backlinks ie meta['relation']['references'] * @var Doku_Renderer_metadata $renderer */ if (isset($data[PluginUtility::ATTRIBUTES])) { $tagAttributes = $data[PluginUtility::ATTRIBUTES]; } else { $tagAttributes = $data; } $ref = $tagAttributes[LinkUtility::ATTRIBUTE_REF]; $link = new LinkUtility($ref); $name = $tagAttributes[LinkUtility::ATTRIBUTE_NAME]; if ($name != null) { $link->setName($name); } $link->handleMetadata($renderer); return true; } break; case renderer_plugin_combo_analytics::RENDERER_FORMAT: $state = $data[PluginUtility::STATE]; if ($state == DOKU_LEXER_ENTER) { /** * * @var renderer_plugin_combo_analytics $renderer */ $tagAttributes = $data[PluginUtility::ATTRIBUTES]; $ref = $tagAttributes[LinkUtility::ATTRIBUTE_REF]; $link = new LinkUtility($ref); $link->processLinkStats($renderer->stats); break; } } // unsupported $mode return false; } }