first commit. dokuwiki.
[h2N7SspZmY.git] / inc / parser / code.php
blob4d94dcf4ec4e36b1d9d1abcac8f2963a569f429a
1 <?php
2 /**
3 * A simple renderer that allows downloading of code and file snippets
5 * @author Andreas Gohr <andi@splitbrain.org>
6 */
7 if(!defined('DOKU_INC')) die('meh.');
8 require_once DOKU_INC . 'inc/parser/renderer.php';
10 class Doku_Renderer_code extends Doku_Renderer {
11 var $_codeblock=0;
13 /**
14 * Send the wanted code block to the browser
16 * When the correct block was found it exits the script.
18 function code($text, $language = NULL, $filename='' ) {
19 if(!$language) $language = 'txt';
20 if(!$filename) $filename = 'snippet.'.$language;
21 $filename = basename($filename);
23 if($this->_codeblock == $_REQUEST['codeblock']){
24 header("Content-Type: text/plain; charset=utf-8");
25 header("Content-Disposition: attachment; filename=$filename");
26 header("X-Robots-Tag: noindex");
27 echo trim($text,"\r\n");
28 exit;
31 $this->_codeblock++;
34 /**
35 * Wraps around code()
37 function file($text, $language = NULL, $filename='') {
38 $this->code($text, $language, $filename);
41 /**
42 * This should never be reached, if it is send a 404
44 function document_end() {
45 header("HTTP/1.0 404 Not Found");
46 echo '404 - Not found';
47 exit;
50 /**
51 * Return the format of the renderer
53 * @returns string 'code'
55 function getFormat(){
56 return 'code';