localRenderer = new Doku_Renderer_xhtml; } /** * Return a simple tooltip. * * @param string $content - The on-page content. May contain newlines. * @param string $tooltip - Tooltip content. May contain newlines. * @param string $classes - CSS classes to add to this tooltip. * @param string $textStyle - CSS styles for the linked content * @return string */ function forText($content, $tooltip, $classes = '', $textStyle = '') { if (!$classes) { $classes = 'plugin-autotooltip__default'; } $textClass = ''; if (empty($textStyle)) { $textClass = 'plugin-autotooltip_linked'; if (strstr($content, '' . $content . '' . $classes . '' . '' . $this->_formatTT($tooltip) . '' . ''; } /** * Render a tooltip, with the title and abstract of a page. * * @param string $id - A page id. * @param string $content - The on-page content. May contain newlines. * @param string $classes - CSS classes to add to this tooltip. * @param string $linkStyle - Style attribute for the link. * @return string */ function forWikilink($id, $content, $classes = '', $linkStyle = '') { if (!$classes) { $classes = 'plugin-autotooltip__default'; } $title = p_get_metadata($id, 'title'); $abstract = p_get_metadata($id, 'description abstract'); try { // By default, the abstract starts with the title. Remove it so it's not displayed twice, but still fetch // both pieces of metadata, in case another plugin rewrote the abstract. $abstract = preg_replace('/^' . preg_quote($title) . '(\r?\n)+/', '', $abstract); } catch(\Exception $e) { // Ignore. } $link = $this->localRenderer->internallink($id, $content ?: $title, null, true); if (!empty($linkStyle)) { $link = preg_replace('/' . $link . 'plugin-autotooltip_big ' . $classes . '' . '' . ' ' . $title . '' . ($abstract ? '

' . $this->_formatTT($abstract) . '' : '') . '
' . ''; } else { return $link; } } /** * Format tooltip text. * * @param string $tt - Tooltip text. * @return string */ private function _formatTT($tt) { $tt = preg_replace('/\r?\n/', '
', $tt); return preg_replace('/(
){3,}/', '

', $tt); } }