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) . '/'); 12if(!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH', $conf['cachedir'] . '/mpdf_ttf/'); 13 14require_once __DIR__ . '/vendor/autoload.php'; 15require __DIR__ . '/DokuImageProcessorDecorator.class.php'; 16 17/** 18 * Class DokuPDF 19 * Some DokuWiki specific extentions 20 */ 21class DokuPDF extends \Mpdf\Mpdf { 22 23 function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) { 24 global $conf; 25 26 io_mkdir_p(_MPDF_TTFONTDATAPATH); 27 io_mkdir_p(_MPDF_TEMP_PATH); 28 29 $format = $pagesize; 30 if($orientation == 'landscape') { 31 $format .= '-L'; 32 } 33 34 switch($conf['lang']) { 35 case 'zh': 36 case 'zh-tw': 37 case 'ja': 38 case 'ko': 39 $mode = '+aCJK'; 40 break; 41 default: 42 $mode = 'UTF-8-s'; 43 44 } 45 46 // we're always UTF-8 47 parent::__construct( 48 array( 49 'mode' => $mode, 50 'format' => $format, 51 'fontsize' => $fontsize, 52 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 53 ) 54 ); 55 56 $this->autoScriptToLang = true; 57 $this->baseScript = 1; 58 $this->autoVietnamese = true; 59 $this->autoArabic = true; 60 $this->autoLangToFont = true; 61 62 $this->ignore_invalid_utf8 = true; 63 $this->tabSpaces = 4; 64 } 65 66 /** 67 * Cleanup temp dir 68 */ 69 function __destruct() { 70 io_rmdir(_MPDF_TEMP_PATH, true); 71 } 72 73 /** 74 * Decode all paths, since DokuWiki uses XHTML compliant URLs 75 */ 76 function GetFullPath(&$path, $basepath = '') { 77 $path = htmlspecialchars_decode($path); 78 parent::GetFullPath($path, $basepath); 79 } 80} 81