Closed franzliedke closed 7 years ago
Thank you for the contribution. I will try to release a new version this weekend.
Cool, good to know.
Just FYI, here is a minimal patch that I needed to adapt in order to make this compatible with PHP 7.1:
From 0d076a40ea2dc95408b83d32c42fd6d6cb190ad3 Mon Sep 17 00:00:00 2001
From: Franz Liedke
Date: Tue, 20 Jun 2017 22:52:53 +0200
Subject: [PATCH] Fix a bunch of PHP 7.1 incompatibilities in wp-mpdf
---
site/web/app/plugins/wp-mpdf/mpdf/classes/bmp.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/cssmgr.php | 8 ++++++--
site/web/app/plugins/wp-mpdf/mpdf/classes/directw.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/form.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/gif.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/grad.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/indic.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/svg.php | 14 +++++++-------
site/web/app/plugins/wp-mpdf/mpdf/classes/tocontents.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/ttfontsuni.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/classes/wmf.php | 2 +-
site/web/app/plugins/wp-mpdf/mpdf/includes/functions.php | 4 ++--
site/web/app/plugins/wp-mpdf/mpdf/mpdf.php | 9 ++++-----
13 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/bmp.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/bmp.php
index acf7f80..cf373f0 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/bmp.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/bmp.php
@@ -4,7 +4,7 @@ class bmp {
var $mpdf = null;
-function bmp(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/cssmgr.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/cssmgr.php
index 9bbbed9..ed1d71a 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/cssmgr.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/cssmgr.php
@@ -12,7 +12,7 @@ var $tbCSSlvl;
var $listCSSlvl;
-function cssmgr(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
$this->tablecascadeCSS = array();
$this->listcascadeCSS = array();
@@ -1061,7 +1061,11 @@ function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDE
function MergeCSS($inherit,$tag,$attr) {
$p = array();
- $zp = array();
+ $zp = array();
+
+ if (!is_array($attr)) {
+ $attr = array();
+ }
$classes = array();
if (isset($attr['CLASS'])) {
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/directw.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/directw.php
index 04c9dfc..daea96b 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/directw.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/directw.php
@@ -4,7 +4,7 @@ class directw {
var $mpdf = null;
-function directw(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/form.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/form.php
index 3699b7b..87ac18a 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/form.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/form.php
@@ -49,7 +49,7 @@ var $form_button_icon;
// FORMS
var $textarea_lineheight;
-function form(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
// ACTIVE FORMS
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/gif.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/gif.php
index 582de0d..ce5df87 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/gif.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/gif.php
@@ -26,7 +26,7 @@ class CGIFLZW
///////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR
- function CGIFLZW()
+ function __construct()
{
$this->MAX_LZW_BITS = 12;
unSet($this->Next);
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/grad.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/grad.php
index b5db602..361983e 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/grad.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/grad.php
@@ -4,7 +4,7 @@ class grad {
var $mpdf = null;
-function grad(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/indic.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/indic.php
index e747ded..989ba39 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/indic.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/indic.php
@@ -2,7 +2,7 @@
class indic {
-function indic() {
+function __construct() {
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/svg.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/svg.php
index 40abd76..dc2a3a1 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/svg.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/svg.php
@@ -5,7 +5,7 @@
// http://www.godisaduck.com/svg2pdf_with_fpdf
// http://rhodopsin.blogspot.com
//
-// cette class etendue est open source, toute modification devra cependant etre repertoriée~
+// cette class etendue est open source, toute modification devra cependant etre repertoriï¿œe~
// NB UNITS - Works in pixels as main units - converting to PDF units when outputing to PDF string
@@ -13,12 +13,12 @@
class SVG {
- var $svg_gradient; // array - contient les infos sur les gradient fill du svg classé par id du svg
+ var $svg_gradient; // array - contient les infos sur les gradient fill du svg classᅵ par id du svg
var $svg_shadinglist; // array - contient les ids des objet shading
var $svg_info; // array contenant les infos du svg voulue par l'utilisateur
var $svg_attribs; // array - holds all attributes of root <svg> tag
var $svg_style; // array contenant les style de groupes du svg
- var $svg_string; // String contenant le tracage du svg en lui même.
+ var $svg_string; // String contenant le tracage du svg en lui mï¿œme.
var $txt_data; // array - holds string info to write txt to image
var $txt_style; // array - current text style
var $mpdf_ref;
@@ -31,7 +31,7 @@ class SVG {
var $kp; // mPDF 4.4.003 convert pixels to PDF units
var $pathBBox; // mPDF 5.0.039
- function SVG(&$mpdf){
+ function __construct(&$mpdf){
$this->svg_gradient = array();
$this->svg_shadinglist = array();
$this->txt_data = array();
@@ -911,7 +911,7 @@ $md = $sy * cos($t);
$path_style = '';
if (substr_count($critere_style['fill'],'url')>0){
//
- // couleur degradé
+ // couleur degradᅵ
$id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['fill']);
if ($id_gradient != $critere_style['fill']) {
if (isset($this->svg_gradient[$id_gradient])) {
@@ -1713,7 +1713,7 @@ function Arcto($x1, $y1, $x2, $y2, $rx, $ry, $angle, $largeArcFlag, $sweepFlag)
//
// fonction retracant les <ellipse /> et <circle />
- // le cercle est tracé grave a 4 bezier cubic, les poitn de controles
+ // le cercle est tracᅵ grave a 4 bezier cubic, les poitn de controles
// sont deduis grace a la constante kappa * rayon
function svgEllipse($arguments){
if ($arguments['rx']==0 || $arguments['ry']==0) { return ''; } // mPDF 4.4.003
@@ -2420,7 +2420,7 @@ function svgDefineTxtStyle($critere_style)
}
//
- //insertion des path et du style dans le flux de donné general.
+ //insertion des path et du style dans le flux de donnᅵ general.
if (isset($path_cmd) && $path_cmd) { // mPDF 4.4.003
// mPDF 5.0
list($prestyle,$poststyle) = $svg_class->svgStyle($path_style, $attribs, strtolower($name));
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/tocontents.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/tocontents.php
index 7b75547..96c6878 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/tocontents.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/tocontents.php
@@ -29,7 +29,7 @@ var $TOC_even_footer_value;
var $TOC_page_selector;
var $m_TOC;
-function tocontents(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
$this->_toc=array();
$this->TOCmark = 0;
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/ttfontsuni.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/ttfontsuni.php
index f639b00..907f000 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/ttfontsuni.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/ttfontsuni.php
@@ -79,7 +79,7 @@ var $TTCFonts;
var $maxUniChar;
var $kerninfo;
- function TTFontFile() {
+ function __construct() {
$this->maxStrLenRead = 200000; // Maximum size of glyf table to read in as string (otherwise reads each glyph from file)
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/classes/wmf.php b/site/web/app/plugins/wp-mpdf/mpdf/classes/wmf.php
index e5f5e3c..d1aa818 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/classes/wmf.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/classes/wmf.php
@@ -5,7 +5,7 @@ class wmf {
var $mpdf = null;
var $gdiObjectArray;
-function wmf(&$mpdf) {
+function __construct(&$mpdf) {
$this->mpdf = $mpdf;
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/includes/functions.php b/site/web/app/plugins/wp-mpdf/mpdf/includes/functions.php
index 91e75da..dfa76b1 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/includes/functions.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/includes/functions.php
@@ -93,8 +93,8 @@ if(!function_exists('strcode2utf')){
function strcode2utf($str,$lo=true) {
//converts all the &#nnn; and &#xhhh; in a string to Unicode
if ($lo) { $lo = 1; } else { $lo = 0; }
- $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
- $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
+ $str = preg_replace_callback('/\&\#([0-9]+)\;/m', function ($match) use ($lo) { return code2utf($match[1], $lo); }, $str);
+ $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', function ($match) use ($lo) { return codeHex2utf($match[1], $lo); }, $str);
return $str;
}
}
diff --git a/site/web/app/plugins/wp-mpdf/mpdf/mpdf.php b/site/web/app/plugins/wp-mpdf/mpdf/mpdf.php
index 2ec3806..73eafc7 100644
--- a/site/web/app/plugins/wp-mpdf/mpdf/mpdf.php
+++ b/site/web/app/plugins/wp-mpdf/mpdf/mpdf.php
@@ -823,7 +823,7 @@ var $innerblocktags;
// **********************************
// **********************************
-function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
+function __construct($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
/*-- BACKGROUNDS --*/
if (!class_exists('grad', false)) { include(_MPDF_PATH.'classes/grad.php'); }
@@ -11349,7 +11349,7 @@ function Header($content='') {
if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
$hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
$hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
- $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
+ $hd = preg_replace_callback('/\{DATE\s+(.*?)\}/', function ($match) { return date($match[1]); }, $hd);
if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
else { $hff = $this->original_default_font; }
if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
@@ -12488,7 +12488,7 @@ function Footer() {
if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
$hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
$hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
- $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
+ $hd = preg_replace_callback('/\{DATE\s+(.*?)\}/', function ($match) { return date($match[1]); }, $hd);
if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
else { $hff = $this->original_default_font; }
if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
@@ -31962,7 +31962,7 @@ function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
// For text $maxsize = Fontsize
// Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
//Identify size (remember: we are using 'mm' units here)
- $size = trim(strtolower($size));
+ $size = (int) trim(strtolower($size));
if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders
elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels
@@ -32021,7 +32021,6 @@ function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
else { $size *= $maxsize*2; }
}
else $size *= (25.4/$this->dpi); //nothing == px
-
return $size;
}
--
2.8.2
Can you add this changes directly to your pull request please?
I can. However, I am unsure whether this really fixes everything, it also caused problems with our PHP generation.
It looks like the mpdf library has improved - will you update it to the latest version?
I was thinking about that but the library has some breaking changes if I saw it correctly. And since I do not longer use this plugin myself and I do not make any money with this plugin I do not really have the time for bigger changes like that. But feel free to become a contributor and do this upgrade. I am more then willing to help keep this project alive.
Okay, I managed to get this to work with the new beta version of mPDF 7.0. Once that is out in a stable version, I will upstream my changes back here. :)
@fkrauthan I've fixed this for our site by using the beta release of mPDF, integrated using Composer. But this requires more changes to the plugin as well, as the API changed quite a bit.
How do you want to proceed with this?
Can you make the changes compatible to the current template format? I have no problem changing the internal API 100% as long as the existing templates will continue to work. Otherwise the idea would be to create a wp-mpdf2 plugin with a new interface and templates (something on my mind just do not have the time nor money to really work on that).
I am currently working on a upgrade of the mpdf library to use the latest version that fully supports PHP 7. I should be able to release that within the next couple of days.
@franzliedke I just release version 3.3 for my plugin which updates the mpdf library to the latest version which has full PHP 7 support. Hope this will work for you.
A duplicate default statement in a switch block is not allowed. It yielded somewhat unpredictable behavior in previous versions of PHP, but now throws a fatal error.
See https://github.com/facebook/hhvm/issues/3822.
Would be very cool to have a new release with this fix. :)