14cbd2578SEli Fenton<?php 24cbd2578SEli Fentonif (!defined('DOKU_INC')) die(); 34cbd2578SEli Fentonif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 44cbd2578SEli Fentonrequire_once DOKU_INC . 'inc/parser/xhtml.php'; 5*4e75257fSZiothuse dokuwiki\File\PageResolver; 64cbd2578SEli Fenton 74cbd2578SEli Fenton/** 8e2969550SEli Fenton * Auto-Tooltip DokuWiki renderer plugin. If the current renderer is ActionRenderer, the action 9e2969550SEli Fenton * plugin will be used instead. 104cbd2578SEli Fenton * 114cbd2578SEli Fenton * @license MIT 124cbd2578SEli Fenton * @author Eli Fenton 134cbd2578SEli Fenton */ 144cbd2578SEli Fentonclass renderer_plugin_autotooltip extends Doku_Renderer_xhtml { 154cbd2578SEli Fenton /** @type helper_plugin_autotooltip m_helper */ 164cbd2578SEli Fenton private $m_helper; 17adc8be0aSEli Fenton private $m_exclude; 184cbd2578SEli Fenton 194cbd2578SEli Fenton public function __construct() { 204cbd2578SEli Fenton global $ID; 214cbd2578SEli Fenton $this->m_helper = plugin_load('helper', 'autotooltip'); 22e2969550SEli Fenton $this->m_exclude = $this->m_helper->isExcluded($ID); 234cbd2578SEli Fenton } 244cbd2578SEli Fenton 254cbd2578SEli Fenton 264cbd2578SEli Fenton /** 274cbd2578SEli Fenton * @param $format 284cbd2578SEli Fenton * @return bool 294cbd2578SEli Fenton */ 304cbd2578SEli Fenton function canRender($format) { 314cbd2578SEli Fenton return $format == 'xhtml'; 324cbd2578SEli Fenton } 334cbd2578SEli Fenton 344cbd2578SEli Fenton 354cbd2578SEli Fenton /** 364cbd2578SEli Fenton * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip! 374cbd2578SEli Fenton * 384cbd2578SEli Fenton * @param string $id 394cbd2578SEli Fenton * @param null $name 404cbd2578SEli Fenton * @param null $search 414cbd2578SEli Fenton * @param bool $returnonly 424cbd2578SEli Fenton * @param string $linktype 434cbd2578SEli Fenton * @return string 444cbd2578SEli Fenton */ 454cbd2578SEli Fenton function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { 464cbd2578SEli Fenton global $ID; 47dd27e4fbSEli Fenton $fullId = $id; 48*4e75257fSZioth 49*4e75257fSZioth $id = explode('?', $id, 2)[0]; 50dd27e4fbSEli Fenton $id = preg_replace('/\#.*$/', '', $id); 51*4e75257fSZioth $id = preg_replace('/\?.*$/', '', $id); 52*4e75257fSZioth $id = $id === '' ? $ID : $id; 53*4e75257fSZioth $id = (new PageResolver($ID))->resolveId($id, $this->date_at, true); 54dd27e4fbSEli Fenton 55adc8be0aSEli Fenton if (!$this->m_exclude && page_exists($id) && $id != $ID) { 56e2969550SEli Fenton $link = parent::internallink($fullId, $name, $search, true, $linktype); 57e2969550SEli Fenton 58d39942acSEli Fenton $meta = $this->m_helper->read_meta_fast($id); 59d39942acSEli Fenton $abstract = $meta['abstract']; 604cbd2578SEli Fenton $link = $this->m_helper->stripNativeTooltip($link); 61d39942acSEli Fenton $link = $this->m_helper->forText($link, $abstract, $meta['title']); 624cbd2578SEli Fenton 634cbd2578SEli Fenton if (!$returnonly) { 644cbd2578SEli Fenton $this->doc .= $link; 654cbd2578SEli Fenton } 664cbd2578SEli Fenton return $link; 674cbd2578SEli Fenton } 6882191fd0SEli Fenton return parent::internallink($fullId, $name, $search, $returnonly, $linktype); 694cbd2578SEli Fenton } 704cbd2578SEli Fenton} 71