1<?php 2if (!defined('DOKU_INC')) die(); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4//require_once DOKU_INC . 'inc/parser/xhtml.php'; 5 6/** 7 * Auto-Tooltip DokuWiki plugin, for use with the ActionRenderer plugin. This will run only if 8 * ActionRenderer is the current renderer plugin. For improved performance, use the AutoTooltip 9 * renderer plugin instead. 10 * 11 * @license MIT 12 * @author Eli Fenton 13 */ 14class action_plugin_autotooltip extends DokuWiki_Action_Plugin { 15 /** @type helper_plugin_autotooltip m_helper */ 16 private $m_helper; 17 private $m_disable; 18 19 public function __construct() { 20 $this->m_disable = !plugin_load('renderer', 'actionrenderer'); 21 if (!$this->m_disable) { 22 global $ID; 23 $this->m_helper = plugin_load('helper', 'autotooltip'); 24 } 25 } 26 27 public function register(Doku_Event_Handler $controller) { 28 if ($this->m_disable) { 29 return; 30 } 31 $controller->register_hook('PLUGIN_ACTIONRENDERER_METHOD_EXECUTE', 'BEFORE', $this, 'actionrenderer'); 32 } 33 34 /** 35 * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip! 36 * 37 * @param Doku_Event $event 38 * @param array $param 39 */ 40 function actionrenderer(Doku_Event $event, $param) { 41 $renderer = $event->data['renderer']; 42 43 if (is_a($renderer, 'renderer_plugin_dw2pdf')) { 44 // dw2pdf should not render expanded tooltips. 45 return; 46 } 47 48 if ($event->data['method'] == 'internallink') { 49 $args = $event->data['arguments']; 50 51 $id = $args[0]; 52 $name = $args[1] ?: 'null'; 53 $search = $args[2] ?: null; 54 $returnonly = $args[3] ?: false; 55 $linktype = $args[4] ?: 'content'; 56 57 global $ID; 58 if (!$this->m_helper->isExcluded($ID) && page_exists($id) && $id != $ID) { 59 $event->preventDefault(); 60 61 // If we call $renderer->internallink directly here, it will cause infinite recursion, 62 // so we need this call_user_func_array hack. 63 $link = call_user_func_array( 64 array($renderer, 'parent::internallink'), 65 array($id, $name, $search, true, $linktype) 66 ); 67 68 $meta = $this->m_helper->read_meta_fast($id); 69 $abstract = $meta['abstract']; 70 $link = $this->m_helper->stripNativeTooltip($link); 71 $link = $this->m_helper->forText($link, $abstract, $meta['title']); 72 73 if (!$returnonly) { 74 $renderer->doc .= $link; 75 } 76 return $link; 77 } 78 } 79 } 80} 81