1<?php 2/** 3 * DokuWiki Plugin PreserveFilenames / renderer.php 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Kazutaka Miyasaka <kazmiya@gmail.com> 7 */ 8 9// must be run within DokuWiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14if (!defined('DOKU_PLUGIN')) { 15 define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 16} 17 18require_once(DOKU_INC . 'inc/parser/code.php'); 19require_once(DOKU_PLUGIN . 'preservefilenames/common.php'); 20 21class renderer_plugin_preservefilenames extends Doku_Renderer_code 22{ 23 /** 24 * Outputs code snippet with a correct filename 25 * 26 * @see Doku_Renderer_code::code 27 */ 28 function code($text, $language = NULL, $filename = '') 29 { 30 // do nothing if codeblock number not matched 31 if ($_REQUEST['codeblock'] != $this->_codeblock++) { 32 return; 33 } 34 35 $common = new PreserveFilenames_Common(); 36 37 $language = $common->_sanitizeFilename($language); 38 39 if (!$language) { 40 $language = 'txt'; 41 } 42 43 $filename = $common->_correctBasename($filename); 44 $filename = $common->_sanitizeFilename($filename); 45 46 if (!$filename) { 47 $filename = 'snippet.' . $language; 48 } 49 50 header('Content-Type: text/plain; charset=utf-8'); 51 header($common->_buildContentDispositionHeader('download', $filename, 'no_pathinfo')); 52 header('X-Robots-Tag: noindex'); 53 print trim($text, "\r\n"); 54 exit; 55 } 56} 57