1<?php 2 3require_once(dirname(__FILE__)."/mpdf/mpdf.php"); 4 5class DokuPDF extends mpdf { 6 7 function __construct(){ 8 global $conf; 9 if(!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", $conf['tmpdir']); 10 11 // we're always UTF-8 12 parent::__construct('UTF-8-s'); 13 $this->SetAutoFont(AUTOFONT_ALL); 14 $this->ignore_invalid_utf8 = true; 15 16 // allimage sources are local (see _getImage) 17 $this->basepathIsLocal = 1; 18 } 19 20 21 /** 22 * Override the mpdf _getImage function 23 * 24 * This function takes care of gathering the image data from HTTP or 25 * local files before passing the data back to mpdf's original function 26 * making sure that only cached file paths are passed to mpdf. It also 27 * takes care of checking image ACls. 28 */ 29 function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false){ 30 list($ext,$mime) = mimetype($file); 31 if(substr($mime,0,6) == 'image/'){ 32 // build regex to parse URL back to media info 33 $re = preg_quote(ml('xxx123yyy'),'/'); 34 $re = str_replace('xxx123yyy','([^&\?]*)',$re); 35 36 37 if(preg_match("/$re/",$file,$m) || 38 preg_match('/[&\?]media=([^&\?]*)/',$file,$m)){ 39 $media = rawurldecode($m[1]); 40 41 if(preg_match('/[\?&]w=(\d+)/',$file, $m)) $w = $m[1]; 42 if(preg_match('/[\?&]h=(\d+)/',$file, $m)) $h = $m[1]; 43 44 if(preg_match('/^https?:\/\//',$media)){ 45 $local = media_get_from_URL($media,$ext,-1); 46 if(!$local) $local = $media; // let mpdf try again 47 }else{ 48 $media = cleanID($media); 49 //check permissions (namespace only) 50 if(auth_quickaclcheck(getNS($media).':X') < AUTH_READ){ 51 $file = ''; 52 } 53 $local = mediaFN($media); 54 } 55 56 //handle image resizing/cropping 57 if($w){ 58 if($h){ 59 $local = media_crop_image($local,$ext,$w,$h); 60 }else{ 61 $local = media_resize_image($local,$ext,$w,$h); 62 } 63 } 64 }elseif(preg_match('/^https?:\/\//',$file)){ // fixed external URLs 65 $local = media_get_from_URL($file,$ext,$conf['cachetime']); 66 } 67 68 if($local){ 69 $orig_srcpath = $local; 70 } 71 } 72 73 return parent::_getImage($file, $firsttime, $allowvector, $orig_srcpath); 74 } 75 76} 77