xref: /plugin/autotooltip/renderer.php (revision 4cbd2578e15d5abe799472d234291cb1237d1880)
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_disable;
16
17	public function __construct() {
18		global $ID;
19		$this->m_helper = plugin_load('helper', 'autotooltip');
20
21		// Exclude some pages.
22		$exclusions = $this->getConf('linkall_exclusions');
23		$this->m_disable = !empty($exclusions) && preg_match($exclusions, $ID);
24	}
25
26
27	/**
28	 * @param $format
29	 * @return bool
30	 */
31	function canRender($format) {
32		return $format == 'xhtml';
33	}
34
35
36	/**
37	 * Intercept Doku_Renderer_xhtml:internallink to give every wikilink a tooltip!
38	 *
39	 * @param string $id
40	 * @param null $name
41	 * @param null $search
42	 * @param bool $returnonly
43	 * @param string $linktype
44	 * @return string
45	 */
46	function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
47		global $ID;
48		if (!$this->m_disable && page_exists($id) && $id != $ID) {
49			$title = p_get_metadata($id, 'title');
50			$abstract = $this->m_helper->getAbstract($id, $title);
51
52			$link = parent::internallink($id, $name, $search, true, $linktype);
53			$link = $this->m_helper->stripNativeTooltip($link);
54			$link = $this->m_helper->forText($link, $abstract, $title);
55
56			if (!$returnonly) {
57				$this->doc .= $link;
58			}
59			return $link;
60		}
61		return parent::internallink($id, $name, $search, $returnonly, $linktype);
62	}
63}
64