1<?php 2if (!defined('DOKU_INC')) die(); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once DOKU_INC . 'inc/parser/xhtml.php'; 5 6/** 7 * Auto-Tooltip DokuWiki renderer plugin. If the current renderer is ActionRenderer, the action 8 * plugin will be used instead. 9 * 10 * @license MIT 11 * @author Eli Fenton 12 */ 13class renderer_plugin_autotooltip extends Doku_Renderer_xhtml { 14 /** @type helper_plugin_autotooltip m_helper */ 15 private $m_helper; 16 private $m_exclude; 17 18 public function __construct() { 19 global $ID; 20 $this->m_helper = plugin_load('helper', 'autotooltip'); 21 $this->m_exclude = $this->m_helper->isExcluded($ID); 22 } 23 24 25 /** 26 * @param $format 27 * @return bool 28 */ 29 function canRender($format) { 30 return $format == 'xhtml'; 31 } 32 33 34 /** 35 * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip! 36 * 37 * @param string $id 38 * @param null $name 39 * @param null $search 40 * @param bool $returnonly 41 * @param string $linktype 42 * @return string 43 */ 44 function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { 45 global $ID; 46 $fullId = $id; 47 $id = preg_replace('/\#.*$/', '', $id); 48 49 if (!$this->m_exclude && page_exists($id) && $id != $ID) { 50 $link = parent::internallink($fullId, $name, $search, true, $linktype); 51 52 $meta = $this->m_helper->read_meta_fast($id); 53 $abstract = $meta['abstract']; 54 $link = $this->m_helper->stripNativeTooltip($link); 55 $link = $this->m_helper->forText($link, $abstract, $meta['title']); 56 57 if (!$returnonly) { 58 $this->doc .= $link; 59 } 60 return $link; 61 } 62 return parent::internallink($fullId, $name, $search, $returnonly, $linktype); 63 } 64} 65