1*4cbd2578SEli Fenton<?php 2*4cbd2578SEli Fentonif (!defined('DOKU_INC')) die(); 3*4cbd2578SEli Fentonif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4*4cbd2578SEli Fentonrequire_once DOKU_INC . 'inc/parser/xhtml.php'; 5*4cbd2578SEli Fenton 6*4cbd2578SEli Fenton/** 7*4cbd2578SEli Fenton * Auto-Tooltip DokuWiki plugin 8*4cbd2578SEli Fenton * 9*4cbd2578SEli Fenton * @license MIT 10*4cbd2578SEli Fenton * @author Eli Fenton 11*4cbd2578SEli Fenton */ 12*4cbd2578SEli Fentonclass renderer_plugin_autotooltip extends Doku_Renderer_xhtml { 13*4cbd2578SEli Fenton /** @type helper_plugin_autotooltip m_helper */ 14*4cbd2578SEli Fenton private $m_helper; 15*4cbd2578SEli Fenton private $m_disable; 16*4cbd2578SEli Fenton 17*4cbd2578SEli Fenton public function __construct() { 18*4cbd2578SEli Fenton global $ID; 19*4cbd2578SEli Fenton $this->m_helper = plugin_load('helper', 'autotooltip'); 20*4cbd2578SEli Fenton 21*4cbd2578SEli Fenton // Exclude some pages. 22*4cbd2578SEli Fenton $exclusions = $this->getConf('linkall_exclusions'); 23*4cbd2578SEli Fenton $this->m_disable = !empty($exclusions) && preg_match($exclusions, $ID); 24*4cbd2578SEli Fenton } 25*4cbd2578SEli Fenton 26*4cbd2578SEli Fenton 27*4cbd2578SEli Fenton /** 28*4cbd2578SEli Fenton * @param $format 29*4cbd2578SEli Fenton * @return bool 30*4cbd2578SEli Fenton */ 31*4cbd2578SEli Fenton function canRender($format) { 32*4cbd2578SEli Fenton return $format == 'xhtml'; 33*4cbd2578SEli Fenton } 34*4cbd2578SEli Fenton 35*4cbd2578SEli Fenton 36*4cbd2578SEli Fenton /** 37*4cbd2578SEli Fenton * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip! 38*4cbd2578SEli Fenton * 39*4cbd2578SEli Fenton * @param string $id 40*4cbd2578SEli Fenton * @param null $name 41*4cbd2578SEli Fenton * @param null $search 42*4cbd2578SEli Fenton * @param bool $returnonly 43*4cbd2578SEli Fenton * @param string $linktype 44*4cbd2578SEli Fenton * @return string 45*4cbd2578SEli Fenton */ 46*4cbd2578SEli Fenton function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { 47*4cbd2578SEli Fenton global $ID; 48*4cbd2578SEli Fenton if (!$this->m_disable && page_exists($id) && $id != $ID) { 49*4cbd2578SEli Fenton $title = p_get_metadata($id, 'title'); 50*4cbd2578SEli Fenton $abstract = $this->m_helper->getAbstract($id, $title); 51*4cbd2578SEli Fenton 52*4cbd2578SEli Fenton $link = parent::internallink($id, $name, $search, true, $linktype); 53*4cbd2578SEli Fenton $link = $this->m_helper->stripNativeTooltip($link); 54*4cbd2578SEli Fenton $link = $this->m_helper->forText($link, $abstract, $title); 55*4cbd2578SEli Fenton 56*4cbd2578SEli Fenton if (!$returnonly) { 57*4cbd2578SEli Fenton $this->doc .= $link; 58*4cbd2578SEli Fenton } 59*4cbd2578SEli Fenton return $link; 60*4cbd2578SEli Fenton } 61*4cbd2578SEli Fenton return parent::internallink($id, $name, $search, $returnonly, $linktype); 62*4cbd2578SEli Fenton } 63*4cbd2578SEli Fenton} 64