-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrenderer.php
More file actions
64 lines (55 loc) · 1.63 KB
/
Copy pathrenderer.php
File metadata and controls
64 lines (55 loc) · 1.63 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
<?php
use dokuwiki\plugin\diagrams\Diagrams;
/**
* DokuWiki Plugin diagrams (Renderer Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Innovakom + CosmoCode <dokuwiki@cosmocode.de>
*/
class renderer_plugin_diagrams extends Doku_Renderer
{
/** @inheritDoc */
public function getFormat()
{
return 'diagrams';
}
/**
* Set proper headers
*/
public function document_start()
{
global $ID;
$headers = [
'Content-Type' => 'image/svg+xml',
'Content-Security-Policy' => $this->getCSP(),
];
p_set_metadata($ID, ['format' => ['diagrams' => $headers]]);
// don't cache
$this->nocache();
}
/**
* Create the content security policy
* @return string
*/
protected function getCSP() {
$policy = Diagrams::CSP;
/** @noinspection DuplicatedCode from dokuwiki\HTTP\Headers::contentSecurityPolicy() */
foreach ($policy as $key => $values) {
// if the value is not an array, we also accept newline terminated strings
if (!is_array($values)) $values = explode("\n", $values);
$values = array_map('trim', $values);
$values = array_unique($values);
$values = array_filter($values);
$policy[$key] = $values;
}
$cspheader = '';
foreach ($policy as $key => $values) {
if ($values) {
$cspheader .= " $key " . join(' ', $values) . ';';
} else {
$cspheader .= " $key;";
}
}
return $cspheader;
}
}