1<?php 2/** 3 * Site Export Plugin - mPDF Extension 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14if ( file_exists(DOKU_PLUGIN . 'dw2pdf/DokuPDF.class.php') ) { 15 16 global $conf; 17 // if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'].'/dwpdf/'.rand(1,1000).'/'); 18 19 require_once(DOKU_PLUGIN . 'dw2pdf/DokuPDF.class.php'); 20 21 class siteexportPDF extends DokuPDF { 22 23 private $debugObj = false; 24 25 function __construct($debug) { 26 global $INPUT; 27 28 $dw2pdf = plugin_load('action', 'dw2pdf'); 29 30 // decide on the paper setup from param or config 31 $pagesize = $INPUT->str('pagesize', $dw2pdf->getConf('pagesize'), true); 32 $orientation = $INPUT->str('orientation', $dw2pdf->getConf('orientation'), true); 33 34 parent::__construct($pagesize, $orientation); 35 $this->debugObj = $debug; 36 $this->debug = $debug !== false; 37 $this->shrink_tables_to_fit = 1; // Does not shrink tables by default, only in emergency 38 $this->use_kwt = true; // avoids page-breaking in H1-H6 if a table follows directly 39 } 40 41 function message($msg, $vars=null, $lvl=1) 42 { 43 if ( $this->debugObj !== false ) { 44 $this->debugObj->message($msg, $vars, $lvl); 45 } 46 } 47 48 function Error($msg) 49 { 50 if ( $this->debugObj !== false && method_exists($this->debugObj, 'runtimeException') ) { 51 $this->debugObj->runtimeException($msg); 52 } else { 53 parent::Error($msg); 54 } 55 } 56 57 function GetFullPath(&$path,$basepath='') { 58 59 // Full Path might return a doubled path like /~gamma/documentation/lib//~gamma/documentation/lib/tpl/clearreports/./_print-images/background-bottom.jpg 60 61 $path = str_replace("\\","/",$path); //If on Windows 62 $path = preg_replace('/^\/\//','http://',$path); // mPDF 5.6.27 63 $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc" 64 $path = preg_replace($regexp,'',$path); 65 66 if ( preg_match("/^.+\/\.\.\//", $path) ) { 67 // ../ not at the beginning 68 $newpath = array(); 69 $oldpath = explode('/', $path); 70 71 foreach( $oldpath as $slice ) { 72 if ( $slice == ".." && count($newpath) > 0 ) { 73 array_pop($newpath); 74 continue; 75 } 76 77 $newpath[] = $slice; 78 } 79 80 $path = implode('/', $newpath); 81 } 82 83 parent::GetFullPath($path, $basepath); 84 85 $regex = "/^(". preg_quote(DOKU_BASE, '/') .".+)\\1/"; 86 if ( preg_match($regex, $path, $matches) ) { 87 $path = preg_replace($regex, "\\1", $path); 88 } 89 90 } 91 92 function OpenTag($tag, $attr) { 93 switch($tag) { 94 case 'BOOKMARK': 95 case 'TOCENTRY': 96 if ( $attr['CONTENT'] ) { 97 // resolve double encoding 98 $attr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'], ENT_QUOTES); 99 } 100 break; 101 } 102 return parent::OpenTag($tag, $attr); 103 } 104 } 105}