Skip to content

Commit

Permalink
OpenTBS 1.10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrol29 committed Feb 22, 2022
1 parent 646b991 commit b61c252
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.0",
"tinybutstrong/tinybutstrong": ">=3.12.0"
"tinybutstrong/tinybutstrong": ">=3.13.1"
},
"autoload": {
"classmap": ["tbs_plugin_opentbs.php"]
Expand Down
39 changes: 24 additions & 15 deletions demo/tbs_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -819,7 +819,6 @@ public function ResetVarRef($ToGlobal) {
// value NULL means that VarRef refers to $GLOBALS
$x = ($ToGlobal) ? null : array();
$this->VarRef = &$x;

}

/**
Expand Down Expand Up @@ -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;
}
}

}
Expand Down
40 changes: 25 additions & 15 deletions tbs_plugin_opentbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>' . $f . '</f>');
}
}
if ($locV = clsTbsXmlLoc::FindElement($locC, 'v', 0, true)) {
$v = $locV->GetInnerSrc();
$locV->Delete();
$locV->UpdateParent(true);
}
$p = $locC->PosEnd;
}
$formulas[$f] = $v;
}

}
Expand Down

0 comments on commit b61c252

Please sign in to comment.