-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrenderer.php
56 lines (46 loc) · 1.44 KB
/
renderer.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
<?php
/**
* DokuWiki Plugin PreserveFilenames / renderer.php
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <[email protected]>
*/
// must be run within DokuWiki
if (!defined('DOKU_INC')) {
die();
}
if (!defined('DOKU_PLUGIN')) {
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
}
require_once(DOKU_INC . 'inc/parser/code.php');
require_once(DOKU_PLUGIN . 'preservefilenames/common.php');
class renderer_plugin_preservefilenames extends Doku_Renderer_code
{
/**
* Outputs code snippet with a correct filename
*
* @see Doku_Renderer_code::code
*/
function code($text, $language = NULL, $filename = '')
{
// do nothing if codeblock number not matched
if ($_REQUEST['codeblock'] != $this->_codeblock++) {
return;
}
$common = new PreserveFilenames_Common();
$language = $common->_sanitizeFilename($language);
if (!$language) {
$language = 'txt';
}
$filename = $common->_correctBasename($filename);
$filename = $common->_sanitizeFilename($filename);
if (!$filename) {
$filename = 'snippet.' . $language;
}
header('Content-Type: text/plain; charset=utf-8');
header($common->_buildContentDispositionHeader('download', $filename, 'no_pathinfo'));
header('X-Robots-Tag: noindex');
print trim($text, "\r\n");
exit;
}
}