1<?php
2/**
3 * Renderer for Dokutexit output
4 * Copyright (C) ???? Harry Fuecks, Andreas Gohr
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * --------------------------------------------------------------------
20 *
21 * @author Harry Fuecks <hfuecks@gmail.com>
22 * @author Andreas Gohr <andi@splitbrain.org>
23 */
24// must be run within Dokuwiki
25if(!defined('DOKU_INC')) die();
26
27// we inherit from the XHTML renderer instead directly of the base renderer
28//require_once DOKU_INC.'inc/parser/xhtml.php';
29//require_once DOKU_INC.'inc/parser/renderer.php';
30require_once DOKU_INC.'lib/plugins/texit/latex.php';
31require_once DOKU_INC.'lib/plugins/texit/texitrender.php';
32/**
33 * The Renderer
34 */
35class renderer_plugin_texit extends Doku_Renderer {
36    var $info = array(
37        'cache' => false, // may the rendered result cached?
38        'toc'   => false, // render the TOC?
39    );
40
41    /**
42     * the format we produce
43     */
44    function getFormat(){
45        // this should be 'texit' usally, but we inherit from the xhtml renderer
46        // and produce XHTML as well, so we can gain magically compatibility
47        // by saying we're the 'xhtml' renderer here.
48        return 'texit';
49    }
50
51
52    /**
53     * Initialize the rendering
54     */
55    function document_start() {
56      global $ID;
57
58      $this->id  = $ID;
59      if (!isset($this->_texit)) {
60	if (!$this->configloaded) {
61	  $this->loadConfig();
62	}
63	$this->_texit = new texitrender_plugin_texit($this->id);
64	$info = array();
65	if (preg_match("/<texit info>(.*?)<\/texit>/",
66		       str_replace("\n", '\n', rawWiki($this->id)),
67		       $info, PREG_OFFSET_CAPTURE)) {
68	  $this->_texit->add_data('info',
69				  str_replace('\n', "\n", $info[0][0]));
70	} else {
71	  echo "error preg_match";
72	}
73 	if ($_REQUEST['texit_type'] == 'zip')
74 	  $this->_texit->_texit_conf['zipsources'] = true;
75	if ($this->_texit->generate('pdf')) {
76	  $filename = null;
77	  switch ($_REQUEST['texit_type']) {
78	  case 'zip':
79	    if (is_readable($this->_texit->zip['file'])) {
80	      $filename = $this->_texit->zip['file'];
81	      header('Content-Type: application/zip');
82	    }
83	    break;
84	  case 'pdf':
85	  default:
86	    if (is_readable($this->_texit->pdf['file'])) {
87	      $filename = $this->_texit->pdf['file'];
88	      header('Content-Type: application/pdf');
89	    }
90	    break;
91	  }
92	  $hdr = "Content-Disposition: attachment;";
93	  $hdr .= "filename=".basename($filename).";";
94	  header($hdr);
95	  header("Content-Transfer-Encoding: binary");
96	  header("Content-Length: ".filesize($filename));
97	  readfile("$filename");
98	  die;
99	}
100      }
101    }
102}
103