1<?php
2/**
3 * Template Functions
4 *
5 * This file provides template specific custom functions that are
6 * not provided by the DokuWiki core.
7 * It is common practice to start each function with an underscore
8 * to make sure it won't interfere with future core functions.
9 */
10
11// Must be run within DokuWiki
12if (!defined('DOKU_INC')) die();
13
14/**
15 * Font-family stack and @font-face stylesheet for the template font setting (conf/metadata.php).
16 *
17 * @return array{sheet:string,stack:string}
18 */
19function _tpl_font_config() {
20	$key = tpl_getConf('font');
21	$configs = array(
22		'0xproto' => array(
23			'sheet' => '0xproto.css',
24			'stack' => '"0xProto Nerd Font Mono", "0xProto Nerd Font", monospace',
25		),
26		'3270' => array(
27			'sheet' => '3270.css',
28			'stack' => '"3270 Nerd Font Mono", "3270 Nerd Font", monospace',
29		),
30		'agave' => array(
31			'sheet' => 'agave.css',
32			'stack' => '"Agave Nerd Font Mono", "Agave Nerd Font", monospace',
33		),
34		'anonymouspro' => array(
35			'sheet' => 'anonymouspro.css',
36			'stack' => '"AnonymousPro Nerd Font Mono", "AnonymousPro Nerd Font", monospace',
37		),
38		'arimo' => array(
39			'sheet' => 'arimo.css',
40			'stack' => '"Arimo Nerd Font Mono", "Arimo Nerd Font", monospace',
41		),
42		'aurulentsansmono' => array(
43			'sheet' => 'aurulentsansmono.css',
44			'stack' => '"AurulentSansMono Nerd Font Mono", "AurulentSansMono Nerd Font", monospace',
45		),
46		'bigblueterminal' => array(
47			'sheet' => 'bigblueterminal.css',
48			'stack' => '"BigBlueTermPlus Nerd Font Mono", "BigBlueTermPlus Nerd Font", monospace',
49		),
50		'bigblueterminal437' => array(
51			'sheet' => 'bigblueterm437-nerd-font.css',
52			'stack' => '"BigBlueTerm437 Nerd Font Mono", "BigBlueTerm437 Nerd Font", monospace',
53		),
54		'bitstreamverasansmono' => array(
55			'sheet' => 'bitstreamverasansmono.css',
56			'stack' => '"BitstromWera Nerd Font Mono", "BitstromWera Nerd Font", monospace',
57		),
58		'blexmono' => array(
59			'sheet' => 'blexmono-nerd-font-mono.css',
60			'stack' => '"BlexMono Nerd Font", "BlexMono Nerd Font", monospace',
61		),
62		'cascadiacode' => array(
63			'sheet' => 'cascadiacode.css',
64			'stack' => '"CaskaydiaCove NF", monospace',
65		),
66		'cascadiamono' => array(
67			'sheet' => 'cascadiamono.css',
68			'stack' => '"CaskaydiaMono NF", monospace',
69		),
70		'codenewroman' => array(
71			'sheet' => 'codenewroman.css',
72			'stack' => '"CodeNewRoman Nerd Font Mono", "CodeNewRoman Nerd Font", monospace',
73		),
74		'comicshannsmono' => array(
75			'sheet' => 'comicshannsmono.css',
76			'stack' => '"ComicShannsMono Nerd Font Mono", "ComicShannsMono Nerd Font", monospace',
77		),
78		'commitmono' => array(
79			'sheet' => 'commitmono.css',
80			'stack' => '"CommitMono Nerd Font Mono", "CommitMono Nerd Font", monospace',
81		),
82		'cousine' => array(
83			'sheet' => 'cousine.css',
84			'stack' => '"Cousine Nerd Font Mono", "Cousine Nerd Font", monospace',
85		),
86		'd2coding' => array(
87			'sheet' => 'd2coding.css',
88			'stack' => '"D2CodingLigature Nerd Font Mono", "D2CodingLigature Nerd Font", monospace',
89		),
90		'daddytimemono' => array(
91			'sheet' => 'daddytimemono.css',
92			'stack' => '"DaddyTimeMono Nerd Font Mono", "DaddyTimeMono Nerd Font", monospace',
93		),
94		'dejavusansmono' => array(
95			'sheet' => 'dejavusansmono.css',
96			'stack' => '"DejaVuSansM Nerd Font Mono", "DejaVuSansM Nerd Font", monospace',
97		),
98		'departuremono' => array(
99			'sheet' => 'departuremono.css',
100			'stack' => '"DepartureMono Nerd Font Mono", "DepartureMono Nerd Font", monospace',
101		),
102		'droidsansmono' => array(
103			'sheet' => 'droidsansmono.css',
104			'stack' => '"DroidSansM Nerd Font Mono", "DroidSansM Nerd Font", monospace',
105		),
106		'envycoder' => array(
107			'sheet' => 'envycoder.css',
108			'stack' => '"EnvyCodeR Nerd Font Mono", "EnvyCodeR Nerd Font", monospace',
109		),
110		'fantasquesansmono' => array(
111			'sheet' => 'fantasquesansmono.css',
112			'stack' => '"FantasqueSansM Nerd Font Mono", "FantasqueSansM Nerd Font", monospace',
113		),
114		'firacode' => array(
115			'sheet' => 'firacode.css',
116			'stack' => '"FiraCode Nerd Font Mono", "FiraCode Nerd Font", monospace',
117		),
118		'firamono' => array(
119			'sheet' => 'firamono.css',
120			'stack' => '"FiraMono Nerd Font Mono", "FiraMono Nerd Font", monospace',
121		),
122		'geistmono' => array(
123			'sheet' => 'geistmono.css',
124			'stack' => '"GeistMono Nerd Font Mono", "GeistMono Nerd Font", monospace',
125		),
126		'gohu' => array(
127			'sheet' => 'gohu.css',
128			'stack' => '"GohuFont 11 Nerd Font Mono", "GohuFont 11 Nerd Font", monospace',
129		),
130		'go-mono' => array(
131			'sheet' => 'go-mono.css',
132			'stack' => '"Go-Mono Nerd Font Mono", "Go-Mono Nerd Font", monospace',
133		),
134		'hack' => array(
135			'sheet' => 'hack.css',
136			'stack' => '"Hack Nerd Font Mono", "Hack Nerd Font", monospace',
137		),
138		'hasklig' => array(
139			'sheet' => 'hasklig.css',
140			'stack' => '"Hasklug Nerd Font Mono", "Hasklug Nerd Font", monospace',
141		),
142		'heavydata' => array(
143			'sheet' => 'heavydata.css',
144			'stack' => '"HeavyData Nerd Font", fantasy',
145		),
146		'hermit' => array(
147			'sheet' => 'hermit.css',
148			'stack' => '"Hurmit Nerd Font Mono", "Hurmit Nerd Font", monospace',
149		),
150		'ia-writer' => array(
151			'sheet' => 'ia-writer.css',
152			'stack' => '"iMWritingDuo Nerd Font Mono", "iMWritingDuo Nerd Font", monospace',
153		),
154		'ibmplexmono' => array(
155			'sheet' => 'ibmplexmono.css',
156			'stack' => '"BlexMono Nerd Font Mono", "BlexMono Nerd Font", monospace',
157		),
158		'inconsolata' => array(
159			'sheet' => 'inconsolata.css',
160			'stack' => '"Inconsolata Nerd Font Mono", "Inconsolata Nerd Font", monospace',
161		),
162		'inconsolatago' => array(
163			'sheet' => 'inconsolatago.css',
164			'stack' => '"InconsolataGo Nerd Font Mono", "InconsolataGo Nerd Font", monospace',
165		),
166		'inconsolatalgc' => array(
167			'sheet' => 'inconsolatalgc.css',
168			'stack' => '"Inconsolata LGC Nerd Font Mono", "Inconsolata LGC Nerd Font", monospace',
169		),
170		'intelonemono' => array(
171			'sheet' => 'intelonemono.css',
172			'stack' => '"IntoneMono NF", monospace',
173		),
174		'iosevka' => array(
175			'sheet' => 'iosevka.css',
176			'stack' => '"Iosevka NFM", "Iosevka NF", monospace',
177		),
178		'iosevkaterm' => array(
179			'sheet' => 'iosevkaterm.css',
180			'stack' => '"IosevkaTerm NFM", "IosevkaTerm NF", monospace',
181		),
182		'iosevkatermslab' => array(
183			'sheet' => 'iosevkatermslab.css',
184			'stack' => '"IosevkaTermSlab NFM", "IosevkaTermSlab NF", monospace',
185		),
186		'jetbrainsmono' => array(
187			'sheet' => 'jetbrainsmono.css',
188			'stack' => '"JetBrainsMonoNL NFM", "JetBrainsMonoNL NF", monospace',
189		),
190		'lekton' => array(
191			'sheet' => 'lekton.css',
192			'stack' => '"Lekton Nerd Font Mono", "Lekton Nerd Font", monospace',
193		),
194		'liberationmono' => array(
195			'sheet' => 'liberationmono.css',
196			'stack' => '"LiberationMono Nerd Font Mono", "LiberationMono Nerd Font", monospace',
197		),
198		'lilex' => array(
199			'sheet' => 'lilex.css',
200			'stack' => '"Lilex Nerd Font Mono", "Lilex Nerd Font", monospace',
201		),
202		'mplus' => array(
203			'sheet' => 'mplus.css',
204			'stack' => '"M+1Code Nerd Font Mono", "M+1Code Nerd Font", monospace',
205		),
206		'martianmono' => array(
207			'sheet' => 'martianmono.css',
208			'stack' => '"MartianMono NFM", "MartianMono NF", monospace',
209		),
210		'meslo' => array(
211			'sheet' => 'meslo.css',
212			'stack' => '"MesloLGLDZ Nerd Font Mono", "MesloLGLDZ Nerd Font Font", monospace',
213		),
214		'monaspace' => array(
215			'sheet' => 'monaspace.css',
216			'stack' => '"MonaspiceAr Nerd Font Mono", "MonaspiceAr Nerd Font", monospace',
217		),
218		'monofur' => array(
219			'sheet' => 'monofur.css',
220			'stack' => '"Monofur Nerd Font Mono", "Monofur Nerd Font", monospace',
221		),
222		'monoid' => array(
223			'sheet' => 'monoid.css',
224			'stack' => '"Monoid Nerd Font Mono", "Monoid Nerd Font", monospace',
225		),
226		'mononoki' => array(
227			'sheet' => 'mononoki.css',
228			'stack' => '"Mononoki Nerd Font Mono", "Mononoki Nerd Font", monospace',
229		),
230		'nerdfontssymbolsonly' => array(
231			'sheet' => 'nerdfontssymbolsonly.css',
232			'stack' => '"Symbols Nerd Font Mono", "Symbols Nerd Font", monospace',
233		),
234		'noto' => array(
235			'sheet' => 'noto.css',
236			'stack' => '"NotoMono NFM", "NotoMono NF", monospace',
237		),
238		'opendyslexic' => array(
239			'sheet' => 'opendyslexic.css',
240			'stack' => '"OpenDyslexicM Nerd Font Mono", "OpenDyslexicM Nerd Font", monospace',
241		),
242		'overpass' => array(
243			'sheet' => 'overpass.css',
244			'stack' => '"OverpassM Nerd Font Mono", "OverpassM Nerd Font", monospace',
245		),
246		'profont' => array(
247			'sheet' => 'profont.css',
248			'stack' => '"ProFont IIx Nerd Font Mono", "ProFont IIx Nerd Font", monospace',
249		),
250		'proggyclean' => array(
251			'sheet' => 'proggyclean.css',
252			'stack' => '"ProggyClean Nerd Font Mono", "ProggyClean Nerd Font", monospace',
253		),
254		'recursive' => array(
255			'sheet' => 'recursive.css',
256			'stack' => '"RecMonoCasual Nerd Font Mono", "RecMonoCasual Nerd Font", monospace',
257		),
258		'robotomono' => array(
259			'sheet' => 'robotomono.css',
260			'stack' => '"RobotoMono Nerd Font Mono", "RobotoMono Nerd Font", monospace',
261		),
262		'sharetechmono' => array(
263			'sheet' => 'sharetechmono.css',
264			'stack' => '"ShureTechMono Nerd Font Mono", "ShureTechMono Nerd Font", monospace',
265		),
266		'sourcecodepro' => array(
267			'sheet' => 'sourcecodepro.css',
268			'stack' => '"SauceCodePro NFM", "SauceCodePro NF", monospace',
269		),
270		'spacemono' => array(
271			'sheet' => 'spacemono.css',
272			'stack' => '"SpaceMono Nerd Font Mono", "SpaceMono Nerd Font", monospace',
273		),
274		'terminus' => array(
275			'sheet' => 'terminus.css',
276			'stack' => '"Terminess Nerd Font Mono", "Terminess Nerd Font", monospace',
277		),
278		'tinos' => array(
279			'sheet' => 'tinos.css',
280			'stack' => '"Tinos Nerd Font", serif',
281		),
282		'ubuntu' => array(
283			'sheet' => 'ubuntu.css',
284			'stack' => '"Ubuntu Nerd Font", sans-serif',
285		),
286		'ubuntumono' => array(
287			'sheet' => 'ubuntumono.css',
288			'stack' => '"UbuntuMono Nerd Font Mono", "UbuntuMono Nerd Font", monospace',
289		),
290		'ubuntusans' => array(
291			'sheet' => 'ubuntusans.css',
292			'stack' => '"UbuntuSansMono NFM", "UbuntuSansMono NF", monospace',
293		),
294		'victormono' => array(
295			'sheet' => 'victormono.css',
296			'stack' => '"VictorMono NFM", "VictorMono NF", monospace',
297		),
298		'zedmono' => array(
299			'sheet' => 'zedmono.css',
300			'stack' => '"ZedMono NFM", "ZedMono NF", monospace',
301		),
302	);
303	return isset($configs[$key]) ? $configs[$key] : $configs['firacode'];
304}
305
306/**
307 * Loads the glyph @font-face sheet and outputs font-family rules (after tpl_metaheaders()).
308 */
309function _tpl_font_headers() {
310	$cfg = _tpl_font_config();
311	$cdn = tpl_getConf('cdn');
312
313	switch ($cdn) {
314		case 'github':
315			$cdn_url = 'https://mshaugh.github.io/nerdfont-webfonts/build/';
316			break;
317		case 'jsdelivr':
318			$cdn_url = 'https://cdn.jsdelivr.net/gh/mshaugh/nerdfont-webfonts/build/';
319			break;
320		default:
321			// We're not supposed to end up here
322			$cdn_url = tpl_basedir() . 'assets/nerd-fonts/';
323			break;
324	}
325
326	echo '<link rel="stylesheet" href="' . hsc($cdn_url . $cfg['sheet']) . '" />' . PHP_EOL;
327	echo '<style type="text/css">' . PHP_EOL
328		. 'body,' . PHP_EOL
329		. 'input,' . PHP_EOL
330		. 'textarea,' . PHP_EOL
331		. 'select,' . PHP_EOL
332		. 'button,' . PHP_EOL
333		. '.hacker-button,' . PHP_EOL
334		. 'pre,' . PHP_EOL
335		. 'code,' . PHP_EOL
336		. 'kbd, samp,' . PHP_EOL
337		. '#mediamanager__page h2,' . PHP_EOL
338		. '#mediamanager__page h3' . PHP_EOL
339		. '{ font-family: ' . $cfg['stack'] . '; }' . PHP_EOL
340		. "</style>";
341}
342
343function _tpl_usertools() {
344	/* The optional second parameter of tpl_action() switches between a link and a button,
345	 e.g. a button inside a <li> would be: tpl_action('edit', 0, 'li') */
346	tpl_toolsevent('usertools', array(
347		'admin'     => tpl_action('admin', 1, 'li', 1),
348		'profile'   => tpl_action('profile', 1, 'li', 1),
349		'register'  => tpl_action('register', 1, 'li', 1),
350		'login'     => tpl_action('login', 1, 'li', 1),
351	));
352}
353
354function _tpl_sitetools() {
355	tpl_toolsevent('sitetools', array(
356		'recent'    => tpl_action('recent', 1, 'li', 1),
357		'media'     => tpl_action('media', 1, 'li', 1),
358		'index'     => tpl_action('index', 1, 'li', 1),
359	));
360}
361
362function _tpl_pagetools() {
363	tpl_toolsevent('pagetools', array(
364		'edit'      => tpl_action('edit', 1, 'li', 1),
365		'revisions' => tpl_action('revisions', 1, 'li', 1),
366		'backlink'  => tpl_action('backlink', 1, 'li', 1),
367		'subscribe' => tpl_action('subscribe', 1, 'li', 1),
368		'revert'    => tpl_action('revert', 1, 'li', 1),
369		'top'       => tpl_action('top', 1, 'li', 1),
370	));
371}
372
373function _tpl_detailtools() {
374	echo tpl_action('mediaManager', 1, 'li', 1);
375	echo tpl_action('img_backto', 1, 'li', 1);
376}
377