xref: /plugin/autotooltip/renderer.php (revision adc8be0a3a03aa7ec5f85c9330fba39d6f1b66b7)
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';
54cbd2578SEli Fenton
64cbd2578SEli Fenton/**
74cbd2578SEli Fenton * Auto-Tooltip DokuWiki plugin
84cbd2578SEli Fenton *
94cbd2578SEli Fenton * @license    MIT
104cbd2578SEli Fenton * @author     Eli Fenton
114cbd2578SEli Fenton */
124cbd2578SEli Fentonclass renderer_plugin_autotooltip extends Doku_Renderer_xhtml {
134cbd2578SEli Fenton	/** @type helper_plugin_autotooltip m_helper */
144cbd2578SEli Fenton	private $m_helper;
15*adc8be0aSEli Fenton	private $m_exclude;
164cbd2578SEli Fenton
174cbd2578SEli Fenton	public function __construct() {
184cbd2578SEli Fenton		global $ID;
194cbd2578SEli Fenton		$this->m_helper = plugin_load('helper', 'autotooltip');
204cbd2578SEli Fenton
21*adc8be0aSEli Fenton		// Include and exclude pages.
22*adc8be0aSEli Fenton		$inclusions = $this->getConf('linkall_inclusions');
234cbd2578SEli Fenton		$exclusions = $this->getConf('linkall_exclusions');
24*adc8be0aSEli Fenton		$this->m_exclude =
25*adc8be0aSEli Fenton			(!empty($inclusions) && !preg_match("/$inclusions/", $ID)) ||
26*adc8be0aSEli Fenton			(!empty($exclusions) && preg_match("/$exclusions/", $ID));
274cbd2578SEli Fenton	}
284cbd2578SEli Fenton
294cbd2578SEli Fenton
304cbd2578SEli Fenton	/**
314cbd2578SEli Fenton	 * @param $format
324cbd2578SEli Fenton	 * @return bool
334cbd2578SEli Fenton	 */
344cbd2578SEli Fenton	function canRender($format) {
354cbd2578SEli Fenton		return $format == 'xhtml';
364cbd2578SEli Fenton	}
374cbd2578SEli Fenton
384cbd2578SEli Fenton
394cbd2578SEli Fenton	/**
404cbd2578SEli Fenton	 * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip!
414cbd2578SEli Fenton	 *
424cbd2578SEli Fenton	 * @param string $id
434cbd2578SEli Fenton	 * @param null $name
444cbd2578SEli Fenton	 * @param null $search
454cbd2578SEli Fenton	 * @param bool $returnonly
464cbd2578SEli Fenton	 * @param string $linktype
474cbd2578SEli Fenton	 * @return string
484cbd2578SEli Fenton	 */
494cbd2578SEli Fenton	function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
504cbd2578SEli Fenton		global $ID;
51*adc8be0aSEli Fenton		if (!$this->m_exclude && page_exists($id) && $id != $ID) {
524cbd2578SEli Fenton			$title = p_get_metadata($id, 'title');
534cbd2578SEli Fenton			$abstract = $this->m_helper->getAbstract($id, $title);
544cbd2578SEli Fenton
554cbd2578SEli Fenton			$link = parent::internallink($id, $name, $search, true, $linktype);
564cbd2578SEli Fenton			$link = $this->m_helper->stripNativeTooltip($link);
574cbd2578SEli Fenton			$link = $this->m_helper->forText($link, $abstract, $title);
584cbd2578SEli Fenton
594cbd2578SEli Fenton			if (!$returnonly) {
604cbd2578SEli Fenton				$this->doc .= $link;
614cbd2578SEli Fenton			}
624cbd2578SEli Fenton			return $link;
634cbd2578SEli Fenton		}
644cbd2578SEli Fenton		return parent::internallink($id, $name, $search, $returnonly, $linktype);
654cbd2578SEli Fenton	}
664cbd2578SEli Fenton}
67