11ef68647SAndreas Gohr<?php 21ef68647SAndreas Gohr 31ef68647SAndreas Gohrrequire_once(dirname(__FILE__)."/mpdf/mpdf.php"); 41ef68647SAndreas Gohr 51ef68647SAndreas Gohrclass DokuPDF extends mpdf { 61ef68647SAndreas Gohr 71ef68647SAndreas Gohr function __construct(){ 81ef68647SAndreas Gohr global $conf; 91ef68647SAndreas Gohr if(!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", $conf['tmpdir']); 101ef68647SAndreas Gohr 111ef68647SAndreas Gohr // we're always UTF-8 121ef68647SAndreas Gohr parent::__construct('UTF-8-s'); 131ef68647SAndreas Gohr $this->SetAutoFont(AUTOFONT_ALL); 141ef68647SAndreas Gohr $this->ignore_invalid_utf8 = true; 151ef68647SAndreas Gohr 161ef68647SAndreas Gohr // allimage sources are local (see _getImage) 17*08b99b84SAndreas Gohr $this->basepathIsLocal = 1; 181ef68647SAndreas Gohr } 191ef68647SAndreas Gohr 201ef68647SAndreas Gohr 211ef68647SAndreas Gohr /** 221ef68647SAndreas Gohr * Override the mpdf _getImage function 231ef68647SAndreas Gohr * 241ef68647SAndreas Gohr * This function takes care of gathering the image data from HTTP or 251ef68647SAndreas Gohr * local files before passing the data back to mpdf's original function 261ef68647SAndreas Gohr * making sure that only cached file paths are passed to mpdf. It also 271ef68647SAndreas Gohr * takes care of checking image ACls. 281ef68647SAndreas Gohr */ 291ef68647SAndreas Gohr function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false){ 301ef68647SAndreas Gohr list($ext,$mime) = mimetype($file); 311ef68647SAndreas Gohr if(substr($mime,0,6) == 'image/'){ 321ef68647SAndreas Gohr // build regex to parse URL back to media info 331ef68647SAndreas Gohr $re = preg_quote(ml('xxx123yyy'),'/'); 34*08b99b84SAndreas Gohr $re = str_replace('xxx123yyy','([^&\?]*)',$re); 351ef68647SAndreas Gohr 36*08b99b84SAndreas Gohr 37*08b99b84SAndreas Gohr if(preg_match("/$re/",$file,$m) || 38*08b99b84SAndreas Gohr preg_match('/[&\?]media=([^&\?]*)/',$file,$m)){ 391ef68647SAndreas Gohr $media = rawurldecode($m[1]); 401ef68647SAndreas Gohr 41*08b99b84SAndreas Gohr if(preg_match('/[\?&]w=(\d+)/',$file, $m)) $w = $m[1]; 42*08b99b84SAndreas Gohr if(preg_match('/[\?&]h=(\d+)/',$file, $m)) $h = $m[1]; 43*08b99b84SAndreas Gohr 44*08b99b84SAndreas Gohr if(preg_match('/^https?:\/\//',$media)){ 45*08b99b84SAndreas Gohr $local = media_get_from_URL($media,$ext,-1); 46*08b99b84SAndreas Gohr if(!$local) $local = $media; // let mpdf try again 471ef68647SAndreas Gohr }else{ 481ef68647SAndreas Gohr $media = cleanID($media); 491ef68647SAndreas Gohr //check permissions (namespace only) 501ef68647SAndreas Gohr if(auth_quickaclcheck(getNS($media).':X') < AUTH_READ){ 511ef68647SAndreas Gohr $file = ''; 521ef68647SAndreas Gohr } 531ef68647SAndreas Gohr $local = mediaFN($media); 541ef68647SAndreas Gohr } 551ef68647SAndreas Gohr 561ef68647SAndreas Gohr //handle image resizing/cropping 571ef68647SAndreas Gohr if($w){ 58*08b99b84SAndreas Gohr if($h){ 591ef68647SAndreas Gohr $local = media_crop_image($local,$ext,$w,$h); 601ef68647SAndreas Gohr }else{ 611ef68647SAndreas Gohr $local = media_resize_image($local,$ext,$w,$h); 621ef68647SAndreas Gohr } 631ef68647SAndreas Gohr } 64*08b99b84SAndreas Gohr }elseif(preg_match('/^https?:\/\//',$file)){ // fixed external URLs 65*08b99b84SAndreas Gohr $local = media_get_from_URL($file,$ext,$conf['cachetime']); 661ef68647SAndreas Gohr } 671ef68647SAndreas Gohr 681ef68647SAndreas Gohr if($local){ 691ef68647SAndreas Gohr $orig_srcpath = $local; 701ef68647SAndreas Gohr } 711ef68647SAndreas Gohr } 721ef68647SAndreas Gohr 731ef68647SAndreas Gohr return parent::_getImage($file, $firsttime, $allowvector, $orig_srcpath); 741ef68647SAndreas Gohr } 751ef68647SAndreas Gohr 761ef68647SAndreas Gohr} 77