From 0ae8cbf5c0b1a198b963490985b7738392ebcb97 Mon Sep 17 00:00:00 2001 From: ahriman Date: Mon, 3 Dec 2018 19:22:25 -0500 Subject: installed dokuwiki, added to navbar, updated news --- wiki/inc/parser/code.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 wiki/inc/parser/code.php (limited to 'wiki/inc/parser/code.php') diff --git a/wiki/inc/parser/code.php b/wiki/inc/parser/code.php new file mode 100644 index 0000000..f91f1d2 --- /dev/null +++ b/wiki/inc/parser/code.php @@ -0,0 +1,73 @@ + + */ +if(!defined('DOKU_INC')) die('meh.'); + +class Doku_Renderer_code extends Doku_Renderer { + var $_codeblock = 0; + + /** + * Send the wanted code block to the browser + * + * When the correct block was found it exits the script. + * + * @param string $text + * @param string $language + * @param string $filename + */ + function code($text, $language = null, $filename = '') { + global $INPUT; + if(!$language) $language = 'txt'; + $language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language); + if(!$filename) $filename = 'snippet.'.$language; + $filename = utf8_basename($filename); + $filename = utf8_stripspecials($filename, '_'); + + // send CRLF to Windows clients + if(strpos($INPUT->server->str('HTTP_USER_AGENT'), 'Windows') !== false) { + $text = str_replace("\n", "\r\n", $text); + } + + if($this->_codeblock == $INPUT->str('codeblock')) { + header("Content-Type: text/plain; charset=utf-8"); + header("Content-Disposition: attachment; filename=$filename"); + header("X-Robots-Tag: noindex"); + echo trim($text, "\r\n"); + exit; + } + + $this->_codeblock++; + } + + /** + * Wraps around code() + * + * @param string $text + * @param string $language + * @param string $filename + */ + function file($text, $language = null, $filename = '') { + $this->code($text, $language, $filename); + } + + /** + * This should never be reached, if it is send a 404 + */ + function document_end() { + http_status(404); + echo '404 - Not found'; + exit; + } + + /** + * Return the format of the renderer + * + * @returns string 'code' + */ + function getFormat() { + return 'code'; + } +} -- cgit 1.4.1-2-gfad0