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