-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuExtItem.php
138 lines (124 loc) · 3.76 KB
/
MenuExtItem.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
131
132
133
134
135
136
137
138
<?php
namespace dokuwiki\plugin\menuext;
use dokuwiki\Menu\Item\AbstractItem;
use dokuwiki\Input\Input;
use dokuwiki\Utf8\PhpString;
/**
* Custom Menu Item
*/
class MenuExtItem extends AbstractItem
{
protected $link;
protected $attributes;
/**
* Intitialize a Menu Item with the given data
*
* @inheritDoc
* @param array $data
*/
public function __construct($data)
{
global $conf;
if (isset($data['label'][$conf['lang']])) $this->label = $data['label'][$conf['lang']];
if (isset($data['title'][$conf['lang']])) $this->title = $data['title'][$conf['lang']];
if (isset($data['link'])) $this->link = $data['link'];
if (isset($data['svg'])) $this->svg = $data['svg'];
if (isset($data['attr'])) $this->attributes = $data['attr'];
parent::__construct();
}
/** @inheritDoc */
public function getLink()
{
return $this->linkReplacements($this->link);
}
/**
* Auto-Download material design icons
* @inheritDoc
*/
public function getSvg()
{
if (file_exists($this->svg)) return $this->svg;
$file = mediaFN($this->svg);
if (file_exists($file)) return $file;
$base = 'https://raw.githubusercontent.com/Templarian/MaterialDesign/master/svg/';
$file = getCacheName($this->svg, '.svg');
if (!file_exists($file)) {
io_download($base . $this->svg, $file);
clearstatcache(true, $file);
}
if (file_exists($file)) return $file;
return DOKU_INC . 'lib/images/menu/00-default_checkbox-blank-circle-outline.svg';
}
/** @@inheritDoc */
public function getLinkAttributes($classprefix = 'menuitem ')
{
$attr = parent::getLinkAttributes($classprefix);
if (is_array($this->attributes)) {
$attr = array_merge($attr, $this->attributes);
}
return $attr;
}
/**
* Replace all placeholders in given link
*
* Basically the same as parsePageTemplate but does URL encoding
*
* @param string $link the link with placeholders
* @return string
* @see parsePageTemplate
*/
protected function linkReplacements($link)
{
global $ID;
global $USERINFO;
global $conf;
/* @var Input $INPUT */
global $INPUT;
// replace placeholders
$file = noNS($ID);
$page = strtr($file, $conf['sepchar'], ' ');
$link = strftime($link); // time first
$link = str_replace(
[
'@ID@',
'@NS@',
'@CURNS@',
'@!CURNS@',
'@!!CURNS@',
'@!CURNS!@',
'@FILE@',
'@!FILE@',
'@!FILE!@',
'@PAGE@',
'@!PAGE@',
'@!!PAGE@',
'@!PAGE!@',
'@USER@',
'@NAME@',
'@MAIL@',
'@DATE@',
],
array_map('rawurlencode', [
$ID,
getNS($ID),
curNS($ID),
PhpString::ucfirst(curNS($ID)),
PhpString::ucwords(curNS($ID)),
PhpString::strtoupper(curNS($ID)),
$file,
PhpString::ucfirst($file),
PhpString::strtoupper($file),
$page,
PhpString::ucfirst($page),
PhpString::ucwords($page),
PhpString::strtoupper($page),
$INPUT->server->str('REMOTE_USER'),
$USERINFO ? $USERINFO['name'] : '',
$USERINFO ? $USERINFO['mail'] : '',
$conf['dformat'],
]),
$link
);
return $link;
}
}