localRenderer = new Doku_Renderer_xhtml; } /** * Return a simple tooltip. * * @param string $content - The on-page content. May contain HTML. * @param string $tooltip - Tooltip content. May contain HTML. * @param string $classes - CSS classes to add to this tooltip. * @return string */ function forText($content, $tooltip, $classes = '') { if (!$classes) { $classes = 'plugin-autotooltip__default'; } $textclass = 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 HTML. * @param string $classes - CSS classes to add to this tooltip. * @return string */ function forWikilink($id, $content, $classes = '') { 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 (page_exists($id)) { // Remove the title attribute, since we have a better tooltip. $link = preg_replace('/title="[^"]*"/', '', $link); return '
' . $link . '
plugin-autotooltip_big ' . $classes . '
' . '
' . '

' . $title . '

' . '
' . '

' . $this->_formatTT($abstract) . '

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