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 plugin 8 * 9 * @license MIT 10 * @author Eli Fenton 11 */ 12class renderer_plugin_autotooltip extends Doku_Renderer_xhtml { 13 /** @type helper_plugin_autotooltip m_helper */ 14 private $m_helper; 15 private $m_exclude; 16 17 public function __construct() { 18 global $ID; 19 $this->m_helper = plugin_load('helper', 'autotooltip'); 20 21 // Include and exclude pages. 22 $inclusions = $this->getConf('linkall_inclusions'); 23 $exclusions = $this->getConf('linkall_exclusions'); 24 $this->m_exclude = 25 (!empty($inclusions) && !preg_match("/$inclusions/", $ID)) || 26 (!empty($exclusions) && preg_match("/$exclusions/", $ID)); 27 } 28 29 30 /** 31 * @param $format 32 * @return bool 33 */ 34 function canRender($format) { 35 return $format == 'xhtml'; 36 } 37 38 39 /** 40 * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip! 41 * 42 * @param string $id 43 * @param null $name 44 * @param null $search 45 * @param bool $returnonly 46 * @param string $linktype 47 * @return string 48 */ 49 function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { 50 global $ID; 51 $fullId = $id; 52 $id = preg_replace('/\#.*$/', '', $id); 53 54 if (!$this->m_exclude && page_exists($id) && $id != $ID) { 55 $meta = $this->m_helper->read_meta_fast($id); 56 $abstract = $meta['abstract']; 57 58 $link = parent::internallink($fullId, $name, $search, true, $linktype); 59 $link = $this->m_helper->stripNativeTooltip($link); 60 $link = $this->m_helper->forText($link, $abstract, $meta['title']); 61 62 if (!$returnonly) { 63 $this->doc .= $link; 64 } 65 return $link; 66 } 67 return parent::internallink($fullId, $name, $search, $returnonly, $linktype); 68 } 69} 70