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