1<?php 2/** 3 * Wrapper around the mpdf library class 4 * 5 * This class overrides some functions to make mpdf make use of DokuWiki' 6 * standard tools instead of its own. 7 * 8 * @author Andreas Gohr <andi@splitbrain.org> 9 */ 10global $conf; 11if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); 12 13require_once __DIR__ . '/vendor/autoload.php'; 14require __DIR__ . '/DokuImageProcessorDecorator.class.php'; 15 16/** 17 * Class DokuPDF 18 * Some DokuWiki specific extentions 19 */ 20class DokuPDF extends \Mpdf\Mpdf { 21 22 /** 23 * DokuPDF constructor. 24 * 25 * @param string $pagesize 26 * @param string $orientation 27 * @param int $fontsize 28 */ 29 function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) { 30 global $conf; 31 32 io_mkdir_p(_MPDF_TEMP_PATH); 33 34 $format = $pagesize; 35 if($orientation == 'landscape') { 36 $format .= '-L'; 37 } 38 39 switch($conf['lang']) { 40 case 'zh': 41 case 'zh-tw': 42 case 'ja': 43 case 'ko': 44 $mode = '+aCJK'; 45 break; 46 default: 47 $mode = 'UTF-8-s'; 48 49 } 50 51 // we're always UTF-8 52 parent::__construct( 53 array( 54 'mode' => $mode, 55 'format' => $format, 56 'fontsize' => $fontsize, 57 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 58 'tempDir' => _MPDF_TEMP_PATH //$conf['tmpdir'] . '/tmp/dwpdf' 59 ) 60 ); 61 62 $this->autoScriptToLang = true; 63 $this->baseScript = 1; 64 $this->autoVietnamese = true; 65 $this->autoArabic = true; 66 $this->autoLangToFont = true; 67 68 $this->ignore_invalid_utf8 = true; 69 $this->tabSpaces = 4; 70 } 71 72 /** 73 * Cleanup temp dir 74 */ 75 function __destruct() { 76 io_rmdir(_MPDF_TEMP_PATH, true); 77 } 78 79 /** 80 * Decode all paths, since DokuWiki uses XHTML compliant URLs 81 * 82 * @param string $path 83 * @param string $basepath 84 */ 85 function GetFullPath(&$path, $basepath = '') { 86 $path = htmlspecialchars_decode($path); 87 parent::GetFullPath($path, $basepath); 88 } 89} 90