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