-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathdwcssloader.php
More file actions
242 lines (219 loc) · 9.47 KB
/
Copy pathdwcssloader.php
File metadata and controls
242 lines (219 loc) · 9.47 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* Helper class to load standrad DokuWiki CSS files.
* Adopted code from dw2pdf plugin by Andreas Gohr <andi@splitbrain.org>.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author LarsDW223
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Class helper_plugin_odt_dwcssloader
*
* @package helper\dwcssloader
*/
class helper_plugin_odt_dwcssloader extends DokuWiki_Plugin {
/** var string Usually empty, can be used for debugging */
public $trace_dump = NULL;
/**
* Return list of implemented methods.
*
* @return array
*/
function getMethods() {
$result = array();
$result[] = array(
'name' => 'load',
'desc' => 'Loads standard DokuWiki, plugin specific and format specific CSS files and templates. Includes handling of replacements and less parsing.',
'params' => array('$plugin_name' => 'string',
'$format' => 'string',
'$template' => 'string'),
'return' => array('All CSS styles' => 'string'),
);
return $result;
}
/**
* Load all the style sheets and apply the needed replacements
* @param $plugin_name
* @param $format
* @param $template
* @return string
*/
public function load($plugin_name, $format, $template) {
$mediatypes = array('screen', 'all', 'print');
//reusue the CSS dispatcher functions without triggering the main function
define('SIMPLE_TEST', 1);
require_once(DOKU_INC . 'lib/exe/css.php');
// Always only use small letters in format
$format = strtolower ($format);
// load style.ini
if (function_exists('css_styleini')) {
// compatiblity layer for pre-Greebo releases of DokuWiki
$styleini = css_styleini($template);
} else {
// Greebo functionality
$this->config = plugin_load('helper', 'odt_config');
if($this->config->getParam('css_usage') !== "off (plugins only)") {
$styleUtils = new \dokuwiki\StyleUtils($template);
} else {
$styleUtils = new \dokuwiki\StyleUtils();
}
$styleini = $styleUtils->cssStyleini($template); // older versions need still the template
}
$template_files = array();
foreach($mediatypes as $mediatype) {
$template_files[$mediatype] = array();
// load template styles
if (isset($styleini['stylesheets'][$mediatype])) {
$template_files[$mediatype] = array_merge($template_files[$mediatype], $styleini['stylesheets'][$mediatype]);
}
}
// prepare CSS files
$files = array_merge(
array(
DOKU_INC . 'lib/styles/screen.css'
=> DOKU_BASE . 'lib/styles/',
DOKU_INC . 'lib/styles/print.css'
=> DOKU_BASE . 'lib/styles/',
),
css_pluginstyles('all'),
$this->css_pluginFormatStyles($format),
array(
DOKU_PLUGIN . $plugin_name.'/conf/style.css'
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/conf/',
DOKU_PLUGIN . $plugin_name.'/tpl/' . $template . '/style.css'
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/tpl/' . $template . '/',
DOKU_PLUGIN . $plugin_name.'/conf/style.local.css'
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/conf/',
)
);
$css = '';
$css .= $this->get_css_for_filetypes();
// build the stylesheet
foreach($files as $file => $location) {
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
$css_content = "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
$css_content = css_loadfile($file, $location);
if (strpos ($file, 'screen.css') !== false ||
strpos ($file, 'screen.less') !== false) {
$css .= "\n@media screen {\n" . $css_content . "\n}\n";
} else if (strpos ($file, 'style.css') !== false ||
strpos ($file, 'style.less') !== false) {
$css .= "\n@media screen {\n" . $css_content . "\n}\n";
} else if (strpos ($file, $format.'.css') !== false ||
strpos ($file, $format.'.less') !== false) {
$css .= "\n@media print {\n" . $css_content . "\n}\n";
} else if (strpos ($file, 'print.css') !== false ||
strpos ($file, 'print.less') !== false) {
$css .= "\n@media print {\n" . $css_content . "\n}\n";
} else {
$css .= $css_content;
}
}
foreach ($mediatypes as $mediatype) {
// load files
$css_content = '';
foreach($template_files[$mediatype] as $file => $location){
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
$css_content .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
$css_content .= css_loadfile($file, $location);
}
switch ($mediatype) {
case 'screen':
$css .= NL.'@media screen { /* START screen styles */'.NL.$css_content.NL.'} /* /@media END screen styles */'.NL;
break;
case 'print':
$css .= NL.'@media print { /* START print styles */'.NL.$css_content.NL.'} /* /@media END print styles */'.NL;
break;
case 'all':
case 'feed':
default:
$css .= NL.'/* START rest styles */ '.NL.$css_content.NL.'/* END rest styles */'.NL;
break;
}
}
if(function_exists('css_parseless')) {
// apply pattern replacements
$css = css_applystyle($css, $styleini['replacements']);
// parse less
$css = css_parseless($css);
} else {
// @deprecated 2013-12-19: fix backward compatibility
$css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $template . '/');
}
return $css;
}
/**
* Returns a list of possible Plugin Styles for format $format
*
* Checks for a $format.'.css', falls back to print.css
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string $format
* @return array
*/
protected function css_pluginFormatStyles($format) {
$list = array();
$plugins = plugin_list();
foreach($plugins as $p) {
// Always load normal/screen CSS code
// That way plugins can choose with the media selector which CSS code they like to use
$list[DOKU_PLUGIN . $p ."/screen.css"] = DOKU_INC . "lib/plugins/". $p ."/";
$list[DOKU_PLUGIN . $p ."/screen.less"] = DOKU_INC . "lib/plugins/". $p ."/";
$list[DOKU_PLUGIN . $p ."/style.css"] = DOKU_INC . "lib/plugins/". $p ."/";
$list[DOKU_PLUGIN . $p ."/style.less"] = DOKU_INC . "lib/plugins/". $p ."/";
// Do $format.css (e.g. odt.css) or print.css exists?
$format_css = file_exists(DOKU_PLUGIN . $p ."/". $format .".css");
$format_less = file_exists(DOKU_PLUGIN . $p ."/". $format .".less");
$print_css = file_exists(DOKU_PLUGIN . $p ."/print.css");
$print_less = file_exists(DOKU_PLUGIN . $p ."/print.less");
if($format_css || $format_less) {
$list[DOKU_PLUGIN . $p ."/". $format .".css"] = DOKU_INC . "lib/plugins/". $p ."/";
$list[DOKU_PLUGIN . $p ."/". $format .".less"] = DOKU_INC . "lib/plugins/". $p ."/";
} else if ($print_css || $print_less) {
$list[DOKU_PLUGIN . $p ."/print.css"] = DOKU_INC . "lib/plugins/". $p ."/";
$list[DOKU_PLUGIN . $p ."/print.less"] = DOKU_INC . "lib/plugins/". $p ."/";
}
}
return $list;
}
/**
* Returns classes for file download links
* (Adjusted from lib/exe/css.php: function css_filetypes())
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
protected function get_css_for_filetypes() {
$css = '';
// default style
$css .= '.mediafile {';
$css .= ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
$css .= ' padding-left: 18px;';
$css .= ' padding-bottom: 1px;';
$css .= '}';
// additional styles when icon available
// scan directory for all icons
$exts = array();
if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
while(false !== ($file = readdir($dh))){
if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){
$ext = strtolower($match[1]);
$type = '.'.strtolower($match[2]);
if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){
$exts[$ext] = $type;
}
}
}
closedir($dh);
}
foreach($exts as $ext=>$type){
$class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
$css .= ".mf_$class {";
$css .= ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
$css .= '}';
}
return $css;
}
}