xref: /plugin/dw2pdf/action.php (revision 72cadc311bdf8648238687c0c93b0ed182d02f97)
1<?php
2/**
3 * dw2Pdf Plugin: Conversion from dokuwiki content to pdf.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Luigi Micco <l.micco@tiscali.it>
7 * @author     Andreas Gohr <andi@splitbrain.org>
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13/**
14 * Class action_plugin_dw2pdf
15 *
16 * Export hmtl content to pdf, for different url parameter configurations
17 * DokuPDF which extends mPDF is used for generating the pdf from html.
18 */
19class action_plugin_dw2pdf extends DokuWiki_Action_Plugin {
20    /**
21     * Settings for current export, collected from url param, plugin config, global config
22     *
23     * @var array
24     */
25    protected $exportConfig = null;
26    protected $tpl;
27    protected $list = array();
28
29    /**
30     * Constructor. Sets the correct template
31     */
32    public function __construct() {
33        $this->tpl = $this->getExportConfig('template');
34    }
35
36    /**
37     * Register the events
38     */
39    public function register(Doku_Event_Handler $controller) {
40        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'convert', array());
41        $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'addbutton', array());
42    }
43
44    /**
45     * Do the HTML to PDF conversion work
46     *
47     * @param Doku_Event $event
48     * @param array      $param
49     * @return bool
50     */
51    public function convert(Doku_Event $event, $param) {
52        global $ACT;
53        global $REV;
54        global $ID;
55
56        // our event?
57        if(($ACT != 'export_pdfbook') && ($ACT != 'export_pdf') && ($ACT != 'export_pdfns')) return false;
58
59        // check user's rights
60        if(auth_quickaclcheck($ID) < AUTH_READ) return false;
61
62        if($data = $this->collectExportPages($event)) {
63            list($title, $this->list) = $data;
64        } else {
65            return false;
66        }
67
68        // it's ours, no one else's
69        $event->preventDefault();
70
71        // prepare cache
72        $cachekey = join(',', $this->list)
73                    . $REV
74                    . $this->getExportConfig('template')
75                    . $this->getExportConfig('pagesize')
76                    . $this->getExportConfig('orientation')
77                    . $this->getExportConfig('doublesided')
78                    . ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0')
79                    . $title;
80        $cache = new cache($cachekey, '.dw2.pdf');
81
82        $mediafiles = array();
83        foreach($this->list as $pageid) {
84            $mediainuse = p_get_metadata($pageid, 'relation media');
85            if(is_array($mediainuse)) {
86                foreach($mediainuse as $mediaid => $exists) {
87                    if($exists) {
88                        $mediafiles[] = mediaFN($mediaid);
89                    }
90                }
91            }
92        }
93
94        $depends['files']   = array_map('wikiFN', $this->list);
95        $depends['files'][] = __FILE__;
96        $depends['files'][] = dirname(__FILE__) . '/renderer.php';
97        $depends['files'][] = dirname(__FILE__) . '/mpdf/mpdf.php';
98        $depends['files']   = array_merge($depends['files'], $mediafiles, getConfigFiles('main'));
99
100        // hard work only when no cache available
101        if(!$this->getConf('usecache') || !$cache->useCache($depends)) {
102            $this->generatePDF($cache->cache, $title);
103        }
104
105        // deliver the file
106        $this->sendPDFFile($cache->cache, $title);
107        return true;
108    }
109
110
111    /**
112     * Obtain list of pages and title, based on url parameters
113     *
114     * @param Doku_Event $event
115     * @return string|bool
116     */
117    protected function collectExportPages(Doku_Event $event) {
118        global $ACT;
119        global $ID;
120        global $INPUT;
121        global $conf;
122
123        // list of one or multiple pages
124        $list = array();
125
126        if($ACT == 'export_pdf') {
127            $list[0] = $ID;
128            $title = $INPUT->str('pdftitle');
129            if(!$title) {
130                $title = p_get_first_heading($ID);
131            }
132
133        } elseif($ACT == 'export_pdfns') {
134            //check input for title and ns
135            if(!$title = $INPUT->str('pdfns_title')) {
136                $this->showPageWithErrorMsg($event, 'needtitle');
137                return false;
138            }
139            $pdfnamespace = cleanID($INPUT->str('pdfns_ns'));
140            if(!@is_dir(dirname(wikiFN($pdfnamespace . ':dummy')))) {
141                $this->showPageWithErrorMsg($event, 'needns');
142                return false;
143            }
144
145            //sort order
146            $order = $INPUT->str('pdfns_order', 'natural', true);
147            $sortoptions = array('pagename', 'date', 'natural');
148            if(!in_array($order, $sortoptions)) {
149                $order = 'natural';
150            }
151
152            //search depth
153            $depth = $INPUT->int('pdfns_depth', 0);
154            if($depth < 0) {
155                $depth = 0;
156            }
157
158            //page search
159            $result = array();
160            $opts = array('depth' => $depth); //recursive all levels
161            $dir = utf8_encodeFN(str_replace(':', '/', $pdfnamespace));
162            search($result, $conf['datadir'], 'search_allpages', $opts, $dir);
163
164            //sorting
165            if(count($result) > 0) {
166                if($order == 'date') {
167                    usort($result, array($this, '_datesort'));
168                } elseif($order == 'pagename') {
169                    usort($result, array($this, '_pagenamesort'));
170                }
171            }
172
173            foreach($result as $item) {
174                $list[] = $item['id'];
175            }
176
177        } elseif(isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) {
178            //is in Bookmanager of bookcreator plugin a title given?
179            if(!$title = $INPUT->str('pdfbook_title')) {
180                $this->showPageWithErrorMsg($event, 'needtitle');
181                return false;
182            } else {
183                $list = explode("|", $_COOKIE['list-pagelist']);
184            }
185
186        } else {
187            //show empty bookcreator message
188            $this->showPageWithErrorMsg($event, 'empty');
189            return false;
190        }
191
192        $list = array_map('cleanID', $list);
193        return array($title, $list);
194    }
195
196
197    /**
198     * Set error notification and reload page again
199     *
200     * @param Doku_Event $event
201     * @param string     $msglangkey key of translation key
202     */
203    private function showPageWithErrorMsg(Doku_Event $event, $msglangkey) {
204        msg($this->getLang($msglangkey), -1);
205
206        $event->data = 'show';
207        $_SERVER['REQUEST_METHOD'] = 'POST'; //clears url
208    }
209
210    /**
211     * Build a pdf from the html
212     *
213     * @param string $cachefile
214     * @param string $title
215     */
216    protected function generatePDF($cachefile, $title) {
217        global $ID;
218        global $REV;
219        global $INPUT;
220
221        //some shortcuts to export settings
222        $hasToC = $this->getExportConfig('hasToC');
223        $levels = $this->getExportConfig('levels');
224        $isDebug = $this->getExportConfig('isDebug');
225
226        // initialize PDF library
227        require_once(dirname(__FILE__) . "/DokuPDF.class.php");
228
229        $mpdf = new DokuPDF($this->getExportConfig('pagesize'), $this->getExportConfig('orientation'));
230
231        // let mpdf fix local links
232        $self = parse_url(DOKU_URL);
233        $url = $self['scheme'] . '://' . $self['host'];
234        if($self['port']) {
235            $url .= ':' . $self['port'];
236        }
237        $mpdf->setBasePath($url);
238
239        // Set the title
240        $mpdf->SetTitle($title);
241
242        // some default document settings
243        //note: double-sided document, starts at an odd page (first page is a right-hand side page)
244        //      single-side document has only odd pages
245        $mpdf->mirrorMargins = $this->getExportConfig('doublesided');
246        $mpdf->useOddEven = $this->getExportConfig('doublesided'); //duplicate of mirrorMargins
247        $mpdf->setAutoTopMargin = 'stretch';
248        $mpdf->setAutoBottomMargin = 'stretch';
249//            $mpdf->pagenumSuffix = '/'; //prefix for {nbpg}
250        if($hasToC) {
251            $mpdf->PageNumSubstitutions[] = array('from' => 1, 'reset' => 0, 'type' => 'i', 'suppress' => 'off'); //use italic pageno until ToC
252            $mpdf->h2toc = $levels;
253        } else {
254            $mpdf->PageNumSubstitutions[] = array('from' => 1, 'reset' => 0, 'type' => '1', 'suppress' => 'off');
255        }
256
257        // load the template
258        $template = $this->load_template($title);
259
260        // prepare HTML header styles
261        $html = '';
262        if($isDebug) {
263            $html .= '<html><head>';
264            $html .= '<style type="text/css">';
265        }
266        $styles = $this->load_css();
267        $styles .= '@page { size:auto; ' . $template['page'] . '}';
268        $styles .= '@page :first {' . $template['first'] . '}';
269
270        $styles .= '@page landscape-page { size:landscape }';
271        $styles .= 'div.dw2pdf-landscape { page:landscape-page }';
272        $styles .= '@page portrait-page { size:portrait }';
273        $styles .= 'div.dw2pdf-portrait { page:portrait-page }';
274
275        $mpdf->WriteHTML($styles, 1);
276
277        if($isDebug) {
278            $html .= $styles;
279            $html .= '</style>';
280            $html .= '</head><body>';
281        }
282
283        $body_start = $template['html'];
284        $body_start .= '<div class="dokuwiki">';
285
286        // insert the cover page
287        $body_start .= $template['cover'];
288
289        $mpdf->WriteHTML($body_start, 2, true, false); //start body html
290        if($isDebug) {
291            $html .= $body_start;
292        }
293        if($hasToC) {
294            //Note: - for double-sided document the ToC is always on an even number of pages, so that the following content is on a correct odd/even page
295            //      - first page of ToC starts always at odd page (so eventually an additional blank page is included before)
296            //      - there is no page numbering at the pages of the ToC
297            $mpdf->TOCpagebreakByArray(
298                array(
299                    'toc-preHTML' => '<h2>' . $this->getLang('tocheader') . '</h2>',
300                    'toc-bookmarkText' => $this->getLang('tocheader'),
301                    'links' => true,
302                    'outdent' => '1em',
303                    'resetpagenum' => true, //start pagenumbering after ToC
304                    'pagenumstyle' => '1'
305                )
306            );
307            $html .= '<tocpagebreak>';
308        }
309
310        // store original pageid
311        $keep = $ID;
312
313        // loop over all pages
314        $cnt = count($this->list);
315        for($n = 0; $n < $cnt; $n++) {
316            $page = $this->list[$n];
317
318            // set global pageid to the rendered page
319            $ID = $page;
320
321            $pagehtml = p_cached_output(wikiFN($page, $REV), 'dw2pdf', $page);
322            $pagehtml .= $this->page_depend_replacements($template['cite'], $page);
323            if($n < ($cnt - 1)) {
324                $pagehtml .= '<pagebreak />';
325            }
326
327            $mpdf->WriteHTML($pagehtml, 2, false, false); //intermediate body html
328            if($isDebug) {
329                $html .= $pagehtml;
330            }
331        }
332        //restore ID
333        $ID = $keep;
334
335        // insert the back page
336        $body_end = $template['back'];
337
338        $body_end .= '</div>';
339
340        $mpdf->WriteHTML($body_end, 2, false, true); // finish body html
341        if($isDebug) {
342            $html .= $body_end;
343            $html .= '</body>';
344            $html .= '</html>';
345        }
346
347        //Return html for debugging
348        if($isDebug) {
349            if($INPUT->str('debughtml', 'text', true) == 'html') {
350                echo $html;
351            } else {
352                header('Content-Type: text/plain; charset=utf-8');
353                echo $html;
354            }
355            exit();
356        };
357
358        // write to cache file
359        $mpdf->Output($cachefile, 'F');
360    }
361
362    /**
363     * @param string $cachefile
364     * @param string $title
365     */
366    protected function sendPDFFile($cachefile, $title) {
367        header('Content-Type: application/pdf');
368        header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
369        header('Pragma: public');
370        http_conditionalRequest(filemtime($cachefile));
371
372        $filename = rawurlencode(cleanID(strtr($title, ':/;"', '    ')));
373        if($this->getConf('output') == 'file') {
374            header('Content-Disposition: attachment; filename="' . $filename . '.pdf";');
375        } else {
376            header('Content-Disposition: inline; filename="' . $filename . '.pdf";');
377        }
378
379        //try to send file, and exit if done
380        http_sendfile($cachefile);
381
382        $fp = @fopen($cachefile, "rb");
383        if($fp) {
384            http_rangeRequest($fp, filesize($cachefile), 'application/pdf');
385        } else {
386            header("HTTP/1.0 500 Internal Server Error");
387            print "Could not read file - bad permissions?";
388        }
389        exit();
390    }
391
392    /**
393     * Load the various template files and prepare the HTML/CSS for insertion
394     */
395    protected function load_template($title) {
396        global $ID;
397        global $conf;
398
399        // this is what we'll return
400        $output = array(
401            'cover' => '',
402            'html'  => '',
403            'page'  => '',
404            'first' => '',
405            'cite'  => '',
406        );
407
408        // prepare header/footer elements
409        $html = '';
410        foreach(array('header', 'footer') as $section) {
411            foreach(array('', '_odd', '_even', '_first') as $order) {
412                $file = DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/' . $section . $order . '.html';
413                if(file_exists($file)) {
414                    $html .= '<htmlpage' . $section . ' name="' . $section . $order . '">' . DOKU_LF;
415                    $html .= file_get_contents($file) . DOKU_LF;
416                    $html .= '</htmlpage' . $section . '>' . DOKU_LF;
417
418                    // register the needed pseudo CSS
419                    if($order == '_first') {
420                        $output['first'] .= $section . ': html_' . $section . $order . ';' . DOKU_LF;
421                    } elseif($order == '_even') {
422                        $output['page'] .= 'even-' . $section . '-name: html_' . $section . $order . ';' . DOKU_LF;
423                    } elseif($order == '_odd') {
424                        $output['page'] .= 'odd-' . $section . '-name: html_' . $section . $order . ';' . DOKU_LF;
425                    } else {
426                        $output['page'] .= $section . ': html_' . $section . $order . ';' . DOKU_LF;
427                    }
428                }
429            }
430        }
431
432        // prepare replacements
433        $replace = array(
434            '@PAGE@'    => '{PAGENO}',
435            '@PAGES@'   => '{nbpg}', //see also $mpdf->pagenumSuffix = ' / '
436            '@TITLE@'   => hsc($title),
437            '@WIKI@'    => $conf['title'],
438            '@WIKIURL@' => DOKU_URL,
439            '@DATE@'    => dformat(time()),
440            '@BASE@'    => DOKU_BASE,
441            '@TPLBASE@' => DOKU_BASE . 'lib/plugins/dw2pdf/tpl/' . $this->tpl . '/'
442        );
443
444        // set HTML element
445        $html = str_replace(array_keys($replace), array_values($replace), $html);
446        //TODO For bookcreator $ID (= bookmanager page) makes no sense
447        $output['html'] = $this->page_depend_replacements($html, $ID);
448
449        // cover page
450        $coverfile = DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/cover.html';
451        if(file_exists($coverfile)) {
452            $output['cover'] = file_get_contents($coverfile);
453            $output['cover'] = str_replace(array_keys($replace), array_values($replace), $output['cover']);
454            $output['cover'] .= '<pagebreak />';
455        }
456
457        // cover page
458        $backfile = DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/back.html';
459        if(file_exists($backfile)) {
460            $output['back'] = '<pagebreak />';
461            $output['back'] .= file_get_contents($backfile);
462            $output['back'] = str_replace(array_keys($replace), array_values($replace), $output['back']);
463        }
464
465        // citation box
466        $citationfile = DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/citation.html';
467        if(file_exists($citationfile)) {
468            $output['cite'] = file_get_contents($citationfile);
469            $output['cite'] = str_replace(array_keys($replace), array_values($replace), $output['cite']);
470        }
471
472        return $output;
473    }
474
475    /**
476     * @param string $raw code with placeholders
477     * @param string $id  pageid
478     * @return string
479     */
480    protected function page_depend_replacements($raw, $id) {
481        global $REV;
482
483        // generate qr code for this page using google infographics api
484        $qr_code = '';
485        if($this->getConf('qrcodesize')) {
486            $url = urlencode(wl($id, '', '&', true));
487            $qr_code = '<img src="https://chart.googleapis.com/chart?chs=' .
488                $this->getConf('qrcodesize') . '&cht=qr&chl=' . $url . '" />';
489        }
490        // prepare replacements
491        $replace['@ID@']      = $id;
492        $replace['@UPDATE@']  = dformat(filemtime(wikiFN($id, $REV)));
493        $replace['@PAGEURL@'] = wl($id, ($REV) ? array('rev' => $REV) : false, true, "&");
494        $replace['@QRCODE@']  = $qr_code;
495
496        $content = str_replace(array_keys($replace), array_values($replace), $raw);
497
498        // @DATE(<date>[, <format>])@
499        $content = preg_replace_callback(
500            '/@DATE\((.*?)(?:,\s*(.*?))?\)@/',
501            array($this, 'replacedate'),
502            $content
503        );
504
505        return $content;
506    }
507
508
509    /**
510     * (callback) Replace date by request datestring
511     * e.g. '%m(30-11-1975)' is replaced by '11'
512     *
513     * @param array $match with [0]=>whole match, [1]=> first subpattern, [2] => second subpattern
514     * @return string
515     */
516    function replacedate($match) {
517        global $conf;
518        //no 2nd argument for default date format
519        if($match[2] == null) {
520            $match[2] = $conf['dformat'];
521        }
522        return strftime($match[2], strtotime($match[1]));
523    }
524
525
526    /**
527     * Load all the style sheets and apply the needed replacements
528     */
529    protected function load_css() {
530        global $conf;
531        //reusue the CSS dispatcher functions without triggering the main function
532        define('SIMPLE_TEST', 1);
533        require_once(DOKU_INC . 'lib/exe/css.php');
534
535        // prepare CSS files
536        $files = array_merge(
537            array(
538                DOKU_INC . 'lib/styles/screen.css'
539                    => DOKU_BASE . 'lib/styles/',
540                DOKU_INC . 'lib/styles/print.css'
541                    => DOKU_BASE . 'lib/styles/',
542            ),
543            css_pluginstyles('all'),
544            $this->css_pluginPDFstyles(),
545            array(
546                DOKU_PLUGIN . 'dw2pdf/conf/style.css'
547                    => DOKU_BASE . 'lib/plugins/dw2pdf/conf/',
548                DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/style.css'
549                    => DOKU_BASE . 'lib/plugins/dw2pdf/tpl/' . $this->tpl . '/',
550                DOKU_PLUGIN . 'dw2pdf/conf/style.local.css'
551                    => DOKU_BASE . 'lib/plugins/dw2pdf/conf/',
552            )
553        );
554        $css = '';
555        foreach($files as $file => $location) {
556            $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
557            $css .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
558            $css .= css_loadfile($file, $location);
559        }
560
561        if(function_exists('css_parseless')) {
562            // apply pattern replacements
563            $styleini = css_styleini($conf['template']);
564            $css = css_applystyle($css, $styleini['replacements']);
565
566            // parse less
567            $css = css_parseless($css);
568        } else {
569            // @deprecated 2013-12-19: fix backward compatibility
570            $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
571        }
572
573        return $css;
574    }
575
576    /**
577     * Returns a list of possible Plugin PDF Styles
578     *
579     * Checks for a pdf.css, falls back to print.css
580     *
581     * @author Andreas Gohr <andi@splitbrain.org>
582     */
583    protected function css_pluginPDFstyles() {
584        $list = array();
585        $plugins = plugin_list();
586
587        $usestyle = explode(',', $this->getConf('usestyles'));
588        foreach($plugins as $p) {
589            if(in_array($p, $usestyle)) {
590                $list[DOKU_PLUGIN . "$p/screen.css"] = DOKU_BASE . "lib/plugins/$p/";
591                $list[DOKU_PLUGIN . "$p/style.css"] = DOKU_BASE . "lib/plugins/$p/";
592            }
593
594            if(file_exists(DOKU_PLUGIN . "$p/pdf.css")) {
595                $list[DOKU_PLUGIN . "$p/pdf.css"] = DOKU_BASE . "lib/plugins/$p/";
596            } else {
597                $list[DOKU_PLUGIN . "$p/print.css"] = DOKU_BASE . "lib/plugins/$p/";
598            }
599        }
600        return $list;
601    }
602
603    /**
604     * Returns array of pages which will be included in the exported pdf
605     *
606     * @return array
607     */
608    public function getExportedPages() {
609        return $this->list;
610    }
611
612    /**
613     * usort callback to sort by file lastmodified time
614     */
615    public function _datesort($a, $b) {
616        if($b['rev'] < $a['rev']) return -1;
617        if($b['rev'] > $a['rev']) return 1;
618        return strcmp($b['id'], $a['id']);
619    }
620
621    /**
622     * usort callback to sort by page id
623     */
624    public function _pagenamesort($a, $b) {
625        if($a['id'] <= $b['id']) return -1;
626        if($a['id'] > $b['id']) return 1;
627        return 0;
628    }
629
630    /**
631     * Return settings read from:
632     *   1. url parameters
633     *   2. plugin config
634     *   3. global config
635     *
636     * @return array
637     */
638    protected function loadExportConfig() {
639        global $INPUT;
640        global $conf;
641
642        $this->exportConfig = array();
643
644        // decide on the paper setup from param or config
645        $this->exportConfig['pagesize'] = $INPUT->str('pagesize', $this->getConf('pagesize'), true);
646        $this->exportConfig['orientation'] = $INPUT->str('orientation', $this->getConf('orientation'), true);
647
648        $doublesided = $INPUT->bool('doublesided', (bool) $this->getConf('doublesided'));
649        $this->exportConfig['doublesided'] = $doublesided ? '1' : '0';
650
651        $hasToC = $INPUT->bool('toc', (bool) $this->getConf('toc'));
652        $levels = array();
653        if($hasToC) {
654            $toclevels = $INPUT->str('toclevels', $this->getConf('toclevels'), true);
655            list($top_input, $max_input) = explode('-', $toclevels, 2);
656            list($top_conf, $max_conf) = explode('-', $this->getConf('toclevels'), 2);
657            $bounds_input = array(
658                'top' => array(
659                    (int) $top_input,
660                    (int) $top_conf
661                ),
662                'max' => array(
663                    (int) $max_input,
664                    (int) $max_conf
665                )
666            );
667            $bounds = array(
668                'top' => $conf['toptoclevel'],
669                'max' => $conf['maxtoclevel']
670
671            );
672            foreach($bounds_input as $bound => $values) {
673                foreach($values as $value) {
674                    if($value > 0 && $value <= 5) {
675                        //stop at valid value and store
676                        $bounds[$bound] = $value;
677                        break;
678                    }
679                }
680            }
681
682            if($bounds['max'] < $bounds['top']) {
683                $bounds['max'] = $bounds['top'];
684            }
685
686            for($level = $bounds['top']; $level <= $bounds['max']; $level++) {
687                $levels["H$level"] = $level - 1;
688            }
689        }
690        $this->exportConfig['hasToC'] = $hasToC;
691        $this->exportConfig['levels'] = $levels;
692
693        $this->exportConfig['maxbookmarks'] = $INPUT->int('maxbookmarks', $this->getConf('maxbookmarks'), true);
694
695        $tplconf = $this->getConf('template');
696        $tpl = $INPUT->str('tpl', $tplconf, true);
697        if(!is_dir(DOKU_PLUGIN . 'dw2pdf/tpl/' . $tpl)) {
698            $tpl = $tplconf;
699        }
700        if(!$tpl){
701            $tpl = 'default';
702        }
703        $this->exportConfig['template'] = $tpl;
704
705        $this->exportConfig['isDebug'] = $conf['allowdebug'] && $INPUT->has('debughtml');
706    }
707
708    /**
709     * Returns requested config
710     *
711     * @param string $name
712     * @param mixed  $notset
713     * @return mixed|bool
714     */
715    public function getExportConfig($name, $notset = false) {
716        if ($this->exportConfig === null){
717            $this->loadExportConfig();
718        }
719
720        if(isset($this->exportConfig[$name])){
721            return $this->exportConfig[$name];
722        }else{
723            return $notset;
724        }
725    }
726
727    /**
728     * Add 'export pdf'-button to pagetools
729     *
730     * @param Doku_Event $event
731     * @param mixed      $param not defined
732     */
733    public function addbutton(Doku_Event $event, $param) {
734        global $ID, $REV;
735
736        if($this->getConf('showexportbutton') && $event->data['view'] == 'main') {
737            $params = array('do' => 'export_pdf');
738            if($REV) {
739                $params['rev'] = $REV;
740            }
741
742            // insert button at position before last (up to top)
743            $event->data['items'] = array_slice($event->data['items'], 0, -1, true) +
744                array('export_pdf' =>
745                          '<li>'
746                          . '<a href="' . wl($ID, $params) . '"  class="action export_pdf" rel="nofollow" title="' . $this->getLang('export_pdf_button') . '">'
747                          . '<span>' . $this->getLang('export_pdf_button') . '</span>'
748                          . '</a>'
749                          . '</li>'
750                ) +
751                array_slice($event->data['items'], -1, 1, true);
752        }
753    }
754}
755