From b61c25211ca41bca4f58d4e756084b9a96bf5883 Mon Sep 17 00:00:00 2001 From: Skrol29 Date: Tue, 22 Feb 2022 03:39:59 +0100 Subject: [PATCH] OpenTBS 1.10.5 --- CHANGELOG.md | 11 +++++++++++ composer.json | 2 +- demo/tbs_class.php | 39 ++++++++++++++++++++++++--------------- tbs_plugin_opentbs.php | 40 +++++++++++++++++++++++++--------------- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 340be52..464794a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. +## [1.10.5] - 2022-02-22 + +### Bug fixes + +- Composer : the required version of TBS is updated in order to ensure the compatibility with PHP 8.1. + +### Enhancements + +- Prevent invalid XLSX when merged sheets have dynamic array formulas (a new feature first released with Office 365 in 2018) + + ## [1.10.4] - 2022-02-07 ### Bug fixes diff --git a/composer.json b/composer.json index a7a5ad8..ff0df86 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=5.0", - "tinybutstrong/tinybutstrong": ">=3.12.0" + "tinybutstrong/tinybutstrong": ">=3.13.1" }, "autoload": { "classmap": ["tbs_plugin_opentbs.php"] diff --git a/demo/tbs_class.php b/demo/tbs_class.php index 39a8878..dc79810 100644 --- a/demo/tbs_class.php +++ b/demo/tbs_class.php @@ -3,8 +3,8 @@ * * TinyButStrong - Template Engine for Pro and Beginners * - * @version 3.13.0 for PHP 5, 7, 8 - * @date 2022-01-30 + * @version 3.13.1 for PHP 5, 7, 8 + * @date 2022-02-13 * @link http://www.tinybutstrong.com Web site * @author http://www.tinybutstrong.com/onlyyou.html * @license http://opensource.org/licenses/LGPL-3.0 LGPL-3.0 @@ -655,7 +655,7 @@ class clsTinyButStrong { public $ExtendedMethods = array(); public $ErrCount = 0; // Undocumented (can change at any version) -public $Version = '3.13.0'; +public $Version = '3.13.1'; public $Charset = ''; public $TurboBlock = true; public $VarPrefix = ''; @@ -819,7 +819,6 @@ public function ResetVarRef($ToGlobal) { // value NULL means that VarRef refers to $GLOBALS $x = ($ToGlobal) ? null : array(); $this->VarRef = &$x; - } /** @@ -857,25 +856,35 @@ public function GetVarRefItem($key, $default) { * Set an item value to VarRef. * Ensure the compatibility with PHP 8.1 if VarRef is set to Global. * - * @param string $key The item key. - * @param mixed $value The item value. Use NULL in order to delete the item. + * @param string|array $keyOrList A list of keys and items to add, or the item key. + * @param mixed $value (optional) The item value. Use NULL in order to delete the item. */ -public function SetVarRefItem($key, $value) { +public function SetVarRefItem($keyOrList, $value = null) { + + if (is_array($keyOrList)) { + $list = $keyOrList; + } else { + $list = array($keyOrList => $value); + } if (is_null($this->VarRef)) { - if (is_null($value)) { - unset($GLOBALS[$key]); - } else { - $GLOBALS[$key] = $value; + foreach ($list as $key => $value) { + if (is_null($value)) { + unset($GLOBALS[$key]); + } else { + $GLOBALS[$key] = $value; + } } } else { - if (is_null($value)) { - unset($this->VarRef[$key]); - } else { - $this->VarRef[$key] = $value; + foreach ($list as $key => $value) { + if (is_null($value)) { + unset($this->VarRef[$key]); + } else { + $this->VarRef[$key] = $value; + } } } diff --git a/tbs_plugin_opentbs.php b/tbs_plugin_opentbs.php index 31f7d33..cca2afa 100644 --- a/tbs_plugin_opentbs.php +++ b/tbs_plugin_opentbs.php @@ -7,8 +7,8 @@ * This TBS plug-in can open a zip file, read the central directory, * and retrieve the content of a zipped file which is not compressed. * - * @version 1.10.4 - * @date 2022-02-07 + * @version 1.10.5 + * @date 2022-02-22 * @see http://www.tinybutstrong.com/plugins.php * @author Skrol29 http://www.tinybutstrong.com/onlyyou.html * @license LGPL-3.0 @@ -98,7 +98,7 @@ function OnInstall() { if (!isset($TBS->OtbsClearMsPowerpoint)) $TBS->OtbsClearMsPowerpoint = true; if (!isset($TBS->OtbsGarbageCollector)) $TBS->OtbsGarbageCollector = true; if (!isset($TBS->OtbsMsExcelCompatibility)) $TBS->OtbsMsExcelCompatibility = true; - $this->Version = '1.10.4'; + $this->Version = '1.10.5'; $this->DebugLst = false; // deactivate the debug mode $this->ExtInfo = false; $TBS->TbsZip = &$this; // a shortcut @@ -4751,18 +4751,28 @@ function MsExcel_DeleteFormulaResults($idx, &$Txt) { $p = 0; while ( ($locF = clsTbsXmlLoc::FindElement($Txt, 'f', $p, true)) !== false ) { - $f = $locF->GetInnerSrc(); - $p = $locF->PosEnd; - $v = null; - if ($locC = clsTbsXmlLoc::FindElement($Txt, 'c', $locF->PosBeg, false)) { - if ($locV = clsTbsXmlLoc::FindElement($locC, 'v', 0, true)) { - $v = $locV->GetInnerSrc(); - $locV->Delete(); - $locV->UpdateParent(true); - } - $p = $locC->PosEnd; - } - $formulas[$f] = $v; + $f = $locF->GetInnerSrc(); + $t = $locF->GetAttLazy('t'); + $p = $locF->PosEnd; + $v = null; + if ($locC = clsTbsXmlLoc::FindElement($Txt, 'c', $locF->PosBeg, false)) { + // Since 2018, Office 365 brings dynamic array formulas. They can be typed array even if they are single, and they have a "ref" attribute + // that can makes the XLSX invalid if the ref does not start with ref of the cell. Unfortunately this can happen when cells are duplicated with OpenTBS. + // In order to avoid invalid XML, then if it is a dynamic array formula but on a single cell, then we turn it into a simple formula. + if ($t == 'array') { + $ref = $locF->GetAttLazy('ref'); + if (strpos($ref, ':') === false) { + $locF->ReplaceSrc('' . $f . ''); + } + } + if ($locV = clsTbsXmlLoc::FindElement($locC, 'v', 0, true)) { + $v = $locV->GetInnerSrc(); + $locV->Delete(); + $locV->UpdateParent(true); + } + $p = $locC->PosEnd; + } + $formulas[$f] = $v; } }