-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyntax.php
84 lines (68 loc) · 2.06 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
use dokuwiki\plugin\xref\Grok;
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <[email protected]>
*/
class syntax_plugin_xref extends DokuWiki_Syntax_Plugin
{
/** @inheritdoc */
public function getType()
{
return 'substition';
}
/** @inheritdoc */
public function getPType()
{
return 'normal';
}
/** @inheritdoc */
public function getSort()
{
return 150;
}
/** @inheritdoc */
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('\[\[xref>.+?\]\]', $mode, 'plugin_xref');
}
/** @inheritdoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
$match = trim(substr($match, 7, -2));
list($reference, $name) = explode('|', $match, 2);
list($reference, $anchor) = explode('#', $reference, 2);
if (!$name) $name = $reference;
if ($anchor) $reference = "#" . $anchor;
return array($reference, $name);
}
/** @inheritdoc */
public function render($format, Doku_Renderer $R, $data)
{
global $conf;
if ($format != 'xhtml') return false;
list($reference, $name) = $data;
$grok = new Grok($reference, $this->getConf('grokbaseurl'));
$count = $grok->getResultCount();
$link = [
'target' => $conf['target']['extern'],
'style' => '',
'pre' => '',
'suf' => '',
'more' => '',
'class' => 'interwiki plugin_xref',
'name' => hsc($name),
'url' => $grok->getSearchUrl(),
'title' => sprintf($this->getLang('view'), hsc($reference)),
];
if ($count === false || $count === 0) {
$link['title'] = $this->getLang('unknown');
$link['class'] .= ' plugin_xref_err';
}
if ($count > 1) {
$link['title'] = sprintf($this->getLang('search'), hsc($reference));
}
$R->doc .= $R->_formatLink($link);
return true;
}
}