From f77d3d166814c8796181a1b838cfcb9767d3d03d Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 5 Sep 2014 10:20:12 +0100 Subject: [PATCH] Bugfix: Work Item GH-384 - DOM loadHTMLFile() failing with options flags when using PHP < 5.4.0 Additional check that libxml is running at an appropriate version by testing if libxml flag value constants are defined --- Classes/PHPExcel/Reader/HTML.php | 2 +- Classes/PHPExcel/Settings.php | 12 ++++++++---- changelog.txt | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Classes/PHPExcel/Reader/HTML.php b/Classes/PHPExcel/Reader/HTML.php index 3a59bb16..6adcc857 100644 --- a/Classes/PHPExcel/Reader/HTML.php +++ b/Classes/PHPExcel/Reader/HTML.php @@ -424,7 +424,7 @@ class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_ // Create a new DOM object $dom = new DOMDocument; // Reload the HTML file into the DOM object - if (version_compare(PHP_VERSION, '5.4.0') >= 0) { + if ((version_compare(PHP_VERSION, '5.4.0') >= 0) && defined(LIBXML_DTDLOAD)) { $loaded = $dom->loadHTMLFile($pFilename, PHPExcel_Settings::getLibXmlLoaderOptions()); } else { $loaded = $dom->loadHTMLFile($pFilename); diff --git a/Classes/PHPExcel/Settings.php b/Classes/PHPExcel/Settings.php index d9d197a5..c78d9350 100644 --- a/Classes/PHPExcel/Settings.php +++ b/Classes/PHPExcel/Settings.php @@ -363,10 +363,12 @@ class PHPExcel_Settings */ public static function setLibXmlLoaderOptions($options = null) { - if (is_null($options)) { + if (is_null($options) && defined(LIBXML_DTDLOAD)) { $options = LIBXML_DTDLOAD | LIBXML_DTDATTR; } - @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR)); + if (version_compare(PHP_VERSION, '5.2.11') >= 0) { + @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR)); + } self::$_libXmlLoaderOptions = $options; } // function setLibXmlLoaderOptions @@ -378,10 +380,12 @@ class PHPExcel_Settings */ public static function getLibXmlLoaderOptions() { - if (is_null(self::$_libXmlLoaderOptions)) { + if (is_null(self::$_libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) { self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR); } - @libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR)); + if (version_compare(PHP_VERSION, '5.2.11') >= 0) { + @libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR)); + } return self::$_libXmlLoaderOptions; } // function getLibXmlLoaderOptions } diff --git a/changelog.txt b/changelog.txt index 8e4a5f6e..12794548 100644 --- a/changelog.txt +++ b/changelog.txt @@ -29,7 +29,7 @@ Planned for v1.8.1 - Bugfix: (MBaker) - Fix to ensure that current cell is maintained when executing formula calculations - Bugfix: (MBaker) Work Item GH-350 - Keep/set the value on Reader _loadSheetsOnly as NULL, courtesy of Restless-ET - Bugfix: (MBaker) Work Item CP18105 - Loading an Excel 2007 spreadsheet throws an "Autofilter must be set on a range of cells" exception -- Bugfix: (MBaker) - Fix to autoloader registration for backward compatibility with PHP 5.2.0 not accepting the prepend flag +- Bugfix: (MBaker) Work Item GH-388 - Fix to autoloader registration for backward compatibility with PHP 5.2.0 not accepting the prepend flag - Bugfix: (MBaker) Work Item GH-384 - DOM loadHTMLFile() failing with options flags when using PHP < 5.4.0 - Bugfix: (MBaker) - Fix for percentage operator in formulae for BIFF Writer - General: (MBaker) - Small performance improvement for autosize columns