diff options
author | sembrestels <sembrestels@riseup.net> | 2011-10-13 15:23:11 +0200 |
---|---|---|
committer | sembrestels <sembrestels@riseup.net> | 2011-10-13 15:23:11 +0200 |
commit | 74bd6999c5e5c23ebbf90dbb6bdaabbddd7594cf (patch) | |
tree | 834c120d692be288f261bcae169eedd3d6b31d74 /vendors/dokuwiki/inc/parser/code.php | |
parent | f8be8643f0faadb2c0ce87d553b7b9d569af5afd (diff) | |
download | elgg-74bd6999c5e5c23ebbf90dbb6bdaabbddd7594cf.tar.gz elgg-74bd6999c5e5c23ebbf90dbb6bdaabbddd7594cf.tar.bz2 |
Rename lib/dokuwiki to vendors/dokuwiki
Diffstat (limited to 'vendors/dokuwiki/inc/parser/code.php')
-rw-r--r-- | vendors/dokuwiki/inc/parser/code.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vendors/dokuwiki/inc/parser/code.php b/vendors/dokuwiki/inc/parser/code.php new file mode 100644 index 000000000..4d94dcf4e --- /dev/null +++ b/vendors/dokuwiki/inc/parser/code.php @@ -0,0 +1,58 @@ +<?php +/** + * A simple renderer that allows downloading of code and file snippets + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +if(!defined('DOKU_INC')) die('meh.'); +require_once DOKU_INC . 'inc/parser/renderer.php'; + +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. + */ + function code($text, $language = NULL, $filename='' ) { + if(!$language) $language = 'txt'; + if(!$filename) $filename = 'snippet.'.$language; + $filename = basename($filename); + + if($this->_codeblock == $_REQUEST['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() + */ + 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() { + header("HTTP/1.0 404 Not Found"); + echo '404 - Not found'; + exit; + } + + /** + * Return the format of the renderer + * + * @returns string 'code' + */ + function getFormat(){ + return 'code'; + } +} |