This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.php
72 lines (63 loc) · 2.19 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
<?php
/**
* DokuWiki Action Plugin GoogleFonts
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Tamara Phillips <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_googlefonts extends DokuWiki_Action_Plugin {
// register hook
function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_METAHEADER_OUTPUT','BEFORE', $this, '_addFontCode');
}
/**
* @param unknown_type $event
* @param unknown_type $param
*/
function _addFontCode(&$event, $param) {
$CSSfiles = array();
$CSSembed = array();
$fontNames = array();
for ($i = 1; $i <= 6; $i++) {
${'fontName'.$i} = $this->getConf('fontName'.$i);
${'headings'.$i} = $this->getConf('headings'.$i);
${'genFamily'.$i} = $this->getConf('genFamily'.$i);
${'addStyle'.$i} = $this->getConf('addStyle'.$i);
$fontNames[] = ${'fontName'.$i};
// add styles
// if not set, set them through CSS as usual
if ( ${'addStyle'.$i} && !empty(${'fontName'.$i}) ) {
$CSSembed[] = ${'headings'.$i}." { font-family: '".preg_replace('/:.*/','',${'fontName'.$i})."', ".${'genFamily'.$i}."; }";
}
}
$CSSfiles = array(
'//fonts.googleapis.com/css?family='.trim(implode("|",str_replace(' ', '+', $fontNames)),"|")
);
// include all relevant CSS files
if (!empty($CSSfiles)) {
foreach($CSSfiles as $CSSfile) {
$event->data['link'][] = array(
'type' => 'text/css',
'rel' => 'stylesheet',
'media' => 'screen',
'href' => $CSSfile
);
}
}
// embed all relevant CSS code
if (!empty($CSSembed)){
foreach($CSSembed as $CSSembeded) {
$event->data['style'][] = array(
'type' => 'text/css',
'media' => 'screen',
'_data' => $CSSembeded
);
}
}
}
}