-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.php
130 lines (116 loc) · 4.04 KB
/
action.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* DokuWiki Plugin DocNavigation (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Gerrit Uitslag <[email protected]>
*/
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler;
/**
* Add documentation navigation elements around page
*/
class action_plugin_docnavigation extends ActionPlugin
{
/**
* Register the events
*
* @param EventHandler $controller
*/
public function register(EventHandler $controller)
{
$controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'AFTER', $this, 'addtopnavigation');
}
/**
* Add navigation bar to top of content
*
* @param Event $event
*/
public function addtopnavigation(Event $event)
{
global $ACT;
if ($event->data[0] != 'xhtml' || !in_array($ACT, ['show', 'preview'])) return;
$event->data[1] = $this->htmlNavigationbar(false)
. $event->data[1]
. $this->htmlNavigationbar(true);
}
/**
* Return html of navigation elements
*
* @param bool $linktoToC if true, add referer to ToC
* @return string
*/
private function htmlNavigationbar($linktoToC)
{
global $ID;
global $ACT;
$data = null;
if ($ACT == 'preview') {
// the RENDERER_CONTENT_POSTPROCESS event is triggered just after rendering the instruction,
// so syntax instance will exists
/** @var syntax_plugin_docnavigation_pagenav $pagenav */
$pagenav = plugin_load('syntax', 'docnavigation_pagenav');
if ($pagenav instanceof syntax_plugin_docnavigation_pagenav) {
$data = $pagenav->getPageData($ID);
}
} else {
$data = p_get_metadata($ID, 'docnavigation');
}
$out = '';
if (!empty($data)) {
if ($linktoToC) {
$out .= '<div class="clearer"></div>';
}
$out .= '<div class="docnavbar' . ($linktoToC ? ' showtoc' : '') . '"><div class="leftnav">';
if ($data['previous']['link']) {
$out .= '← ' . $this->htmlLink($data['previous']);
}
$out .= ' </div>';
if ($linktoToC) {
$out .= '<div class="centernav">';
if ($data['toc']['link']) {
$out .= $this->htmlLink($data['toc']);
}
$out .= ' </div>';
}
$out .= '<div class="rightnav"> ';
if ($data['next']['link']) {
$out .= $this->htmlLink($data['next']) . ' →';
}
$out .= '</div></div>';
}
return $out;
}
/**
* Build nice url title, if no title given use original link with original not cleaned id
*
* @param array $link with: 'link' => string full page id, 'title' => null|string, 'rawlink' => string original not cleaned id, 'hash' => string
* @return string
*/
protected function htmlLink($link) {
/** @var Doku_Renderer_xhtml $Renderer */
static $Renderer = null;
if (is_null($Renderer)) {
$Renderer = p_get_renderer('xhtml');
}
$title = $this->getTitle($link, $Renderer);
$id = ':' . $link['link'] . '#' . $link['hash'];
return $Renderer->internallink($id, $title, null, true);
}
/**
* Build nice url title, if no title given use original link with original not cleaned id
*
* @param array $link with: 'link' => string full page id, 'title' => null|string, 'rawlink' => string original not cleaned id, 'hash' => string
* @param Doku_Renderer_xhtml $Renderer
* @return string
*/
protected function getTitle($link, $Renderer)
{
if ($link['title'] === null) {
$defaulttitle = $Renderer->_simpleTitle($link['rawlink']);
return $Renderer->_getLinkTitle(null, $defaulttitle, $isImage, $link['link']);
}
return $link['title'];
}
}