| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Excel 2007-2019/Office 365 Reader class | |
| 3 | + * Excel 2007-2019/Office 365 Reader Class | |
| 4 | 4 | * |
| 5 | - * Based on SimpleXLSX v1.1.17 by Sergey Shuchkin. | |
| 5 | + * Based on SimpleXLSX v1.0.21 by Sergey Shuchkin. | |
| 6 | 6 | * @link https://github.com/shuchkin/simplexlsx/ |
| 7 | 7 | * |
| 8 | 8 | * @package TablePress |
| 9 | 9 | * @subpackage Import |
| @@ -15,10 +15,9 @@ | ||
| 15 | 15 | |
| 16 | 16 | use SimpleXMLElement; |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * PHP Excel 2007-2013/Office 365 Reader class | |
| 20 | - * | |
| 19 | + * PHP Excel 2007-2013/Office 365 Reader Class | |
| 21 | 20 | * @package TablePress |
| 22 | 21 | * @subpackage Import |
| 23 | 22 | * @author Sergey Shuchkin, Tobias Bäthge |
| 24 | 23 | * @since 1.1.0 |
| @@ -160,9 +159,9 @@ | ||
| 160 | 159 | |
| 161 | 160 | if ($is_data) { |
| 162 | 161 | $this->package['filename'] = 'default.xlsx'; |
| 163 | 162 | $this->package['mtime'] = time(); |
| 164 | - $this->package['size'] = self::strlen($filename); | |
| 163 | + $this->package['size'] = SimpleXLSX::strlen($filename); | |
| 165 | 164 | |
| 166 | 165 | $vZ = $filename; |
| 167 | 166 | } else { |
| 168 | 167 | if (!is_readable($filename)) { |
| @@ -230,25 +229,25 @@ | ||
| 230 | 229 | $mF = $aP['EFL']; |
| 231 | 230 | |
| 232 | 231 | // Special case : value block after the compressed data |
| 233 | 232 | if ($aP['GPF'] & 0x0008) { |
| 234 | - $aP1 = unpack('V1CRC/V1CS/V1UCS', self::substr($vZ, -12)); | |
| 233 | + $aP1 = unpack('V1CRC/V1CS/V1UCS', SimpleXLSX::substr($vZ, -12)); | |
| 235 | 234 | |
| 236 | 235 | $aP['CRC'] = $aP1['CRC']; |
| 237 | 236 | $aP['CS'] = $aP1['CS']; |
| 238 | 237 | $aP['UCS'] = $aP1['UCS']; |
| 239 | 238 | // 2013-08-10 |
| 240 | - $vZ = self::substr($vZ, 0, -12); | |
| 241 | - if (self::substr($vZ, -4) === "\x50\x4b\x07\x08") { | |
| 242 | - $vZ = self::substr($vZ, 0, -4); | |
| 239 | + $vZ = SimpleXLSX::substr($vZ, 0, -12); | |
| 240 | + if (SimpleXLSX::substr($vZ, -4) === "\x50\x4b\x07\x08") { | |
| 241 | + $vZ = SimpleXLSX::substr($vZ, 0, -4); | |
| 243 | 242 | } |
| 244 | 243 | } |
| 245 | 244 | |
| 246 | 245 | // Getting stored filename |
| 247 | - $aI['N'] = self::substr($vZ, 26, $nF); | |
| 246 | + $aI['N'] = SimpleXLSX::substr($vZ, 26, $nF); | |
| 248 | 247 | $aI['N'] = str_replace('\\', '/', $aI['N']); |
| 249 | 248 | |
| 250 | - if (self::substr($aI['N'], -1) === '/') { | |
| 249 | + if (SimpleXLSX::substr($aI['N'], -1) === '/') { | |
| 251 | 250 | // is a directory entry - will be skipped |
| 252 | 251 | continue; |
| 253 | 252 | } |
| 254 | 253 | |
| @@ -256,11 +255,11 @@ | ||
| 256 | 255 | $aI['P'] = dirname($aI['N']); |
| 257 | 256 | $aI['P'] = ($aI['P'] === '.') ? '' : $aI['P']; |
| 258 | 257 | $aI['N'] = basename($aI['N']); |
| 259 | 258 | |
| 260 | - $vZ = self::substr($vZ, 26 + $nF + $mF); | |
| 259 | + $vZ = SimpleXLSX::substr($vZ, 26 + $nF + $mF); | |
| 261 | 260 | |
| 262 | - if ($aP['CS'] > 0 && (self::strlen($vZ) !== (int)$aP['CS'])) { // check only if availabled | |
| 261 | + if ($aP['CS'] > 0 && (SimpleXLSX::strlen($vZ) !== (int)$aP['CS'])) { // check only if availabled | |
| 263 | 262 | $aI['E'] = 1; |
| 264 | 263 | $aI['EM'] = 'Compressed size is not equal with the value in header information.'; |
| 265 | 264 | } |
| 266 | 265 | // } elseif ( $bE ) { |
| @@ -352,9 +351,9 @@ | ||
| 352 | 351 | // Read relations and search for officeDocument |
| 353 | 352 | if ($relations = $this->getEntryXML('_rels/.rels')) { |
| 354 | 353 | foreach ($relations->Relationship as $rel) { |
| 355 | 354 | $rel_type = basename(trim((string)$rel['Type'])); // officeDocument |
| 356 | - $rel_target = self::getTarget('', (string)$rel['Target']); // /xl/workbook.xml or xl/workbook.xml | |
| 355 | + $rel_target = SimpleXLSX::getTarget('', (string)$rel['Target']); // /xl/workbook.xml or xl/workbook.xml | |
| 357 | 356 | |
| 358 | 357 | if ($rel_type === 'officeDocument' |
| 359 | 358 | && $workbook = $this->getEntryXML($rel_target) |
| 360 | 359 | ) { |
| @@ -378,9 +377,9 @@ | ||
| 378 | 377 | if ($workbookRelations = $this->getEntryXML(dirname($rel_target) . '/_rels/workbook.xml.rels')) { |
| 379 | 378 | // Loop relations for workbook and extract sheets... |
| 380 | 379 | foreach ($workbookRelations->Relationship as $workbookRelation) { |
| 381 | 380 | $wrel_type = basename(trim((string)$workbookRelation['Type'])); // worksheet |
| 382 | - $wrel_target = self::getTarget(dirname($rel_target), (string)$workbookRelation['Target']); | |
| 381 | + $wrel_target = SimpleXLSX::getTarget(dirname($rel_target), (string)$workbookRelation['Target']); | |
| 383 | 382 | if (!$this->entryExists($wrel_target)) { |
| 384 | 383 | continue; |
| 385 | 384 | } |
| 386 | 385 | |
| @@ -401,9 +400,9 @@ | ||
| 401 | 400 | foreach ($sharedStrings->si as $val) { |
| 402 | 401 | if (isset($val->t)) { |
| 403 | 402 | $this->sharedstrings[] = (string)$val->t; |
| 404 | 403 | } elseif (isset($val->r)) { |
| 405 | - $this->sharedstrings[] = self::parseRichText($val); | |
| 404 | + $this->sharedstrings[] = SimpleXLSX::parseRichText($val); | |
| 406 | 405 | } |
| 407 | 406 | } |
| 408 | 407 | } |
| 409 | 408 | } elseif ($wrel_type === 'styles') { |
| @@ -477,10 +476,9 @@ | ||
| 477 | 476 | $this->deleteEntry($name); // economy memory |
| 478 | 477 | // dirty remove namespace prefixes and empty rows |
| 479 | 478 | $entry_xml = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $entry_xml); // remove namespaces |
| 480 | 479 | $entry_xml .= ' '; // force run garbage collector |
| 481 | - // remove namespaced attrs | |
| 482 | - $entry_xml = preg_replace('/[a-zA-Z0-9]+:([a-zA-Z0-9]+="[^"]+")/', '$1', $entry_xml); | |
| 480 | + $entry_xml = preg_replace('/[a-zA-Z0-9]+:([a-zA-Z0-9]+="[^"]+")/', '$1', $entry_xml); // remove namespaced attrs | |
| 483 | 481 | $entry_xml .= ' '; |
| 484 | 482 | $entry_xml = preg_replace('/<[a-zA-Z0-9]+:([^>]+)>/', '<$1>', $entry_xml); // fix namespaced openned tags |
| 485 | 483 | $entry_xml .= ' '; |
| 486 | 484 | $entry_xml = preg_replace('/<\/[a-zA-Z0-9]+:([^>]+)>/', '</$1>', $entry_xml); // fix namespaced closed tags |
| @@ -487,9 +485,8 @@ | ||
| 487 | 485 | $entry_xml .= ' '; |
| 488 | 486 | |
| 489 | 487 | if (strpos($name, '/sheet')) { // dirty skip empty rows |
| 490 | 488 | // remove <row...> <c /><c /></row> |
| 491 | - $cnt = $cnt2 = $cnt3 = null; | |
| 492 | 489 | $entry_xml = preg_replace('/<row[^>]+>\s*(<c[^\/]+\/>\s*)+<\/row>/', '', $entry_xml, -1, $cnt); |
| 493 | 490 | $entry_xml .= ' '; |
| 494 | 491 | // remove <row /> |
| 495 | 492 | $entry_xml = preg_replace('/<row[^\/>]*\/>/', '', $entry_xml, -1, $cnt2); |
| @@ -543,12 +540,12 @@ | ||
| 543 | 540 | |
| 544 | 541 | public function getEntryData($name) |
| 545 | 542 | { |
| 546 | 543 | $name = ltrim(str_replace('\\', '/', $name), '/'); |
| 547 | - $dir = self::strtoupper(dirname($name)); | |
| 548 | - $name = self::strtoupper(basename($name)); | |
| 544 | + $dir = SimpleXLSX::strtoupper(dirname($name)); | |
| 545 | + $name = SimpleXLSX::strtoupper(basename($name)); | |
| 549 | 546 | foreach ($this->package['entries'] as &$entry) { |
| 550 | - if (self::strtoupper($entry['path']) === $dir && self::strtoupper($entry['name']) === $name) { | |
| 547 | + if (SimpleXLSX::strtoupper($entry['path']) === $dir && SimpleXLSX::strtoupper($entry['name']) === $name) { | |
| 551 | 548 | if ($entry['error']) { |
| 552 | 549 | return false; |
| 553 | 550 | } |
| 554 | 551 | switch ($entry['cm']) { |
| @@ -575,9 +572,9 @@ | ||
| 575 | 572 | $entry['cm'] = -1; |
| 576 | 573 | if ($entry['data'] === false) { |
| 577 | 574 | $entry['error'] = 2; |
| 578 | 575 | $entry['error_msg'] = 'Decompression of data failed.'; |
| 579 | - } elseif ($entry['ucs'] > 0 && (self::strlen($entry['data']) !== (int)$entry['ucs'])) { | |
| 576 | + } elseif ($entry['ucs'] > 0 && (SimpleXLSX::strlen($entry['data']) !== (int)$entry['ucs'])) { | |
| 580 | 577 | $entry['error'] = 3; |
| 581 | 578 | $entry['error_msg'] = 'Uncompressed size is not equal with the value in header information.'; |
| 582 | 579 | } elseif (crc32($entry['data']) !== $entry['crc']) { |
| 583 | 580 | $entry['error'] = 4; |
| @@ -595,12 +592,12 @@ | ||
| 595 | 592 | } |
| 596 | 593 | public function deleteEntry($name) |
| 597 | 594 | { |
| 598 | 595 | $name = ltrim(str_replace('\\', '/', $name), '/'); |
| 599 | - $dir = self::strtoupper(dirname($name)); | |
| 600 | - $name = self::strtoupper(basename($name)); | |
| 596 | + $dir = SimpleXLSX::strtoupper(dirname($name)); | |
| 597 | + $name = SimpleXLSX::strtoupper(basename($name)); | |
| 601 | 598 | foreach ($this->package['entries'] as $k => $entry) { |
| 602 | - if (self::strtoupper($entry['path']) === $dir && self::strtoupper($entry['name']) === $name) { | |
| 599 | + if (SimpleXLSX::strtoupper($entry['path']) === $dir && SimpleXLSX::strtoupper($entry['name']) === $name) { | |
| 603 | 600 | unset($this->package['entries'][$k]); |
| 604 | 601 | return true; |
| 605 | 602 | } |
| 606 | 603 | } |
| @@ -619,12 +616,12 @@ | ||
| 619 | 616 | |
| 620 | 617 | public function entryExists($name) |
| 621 | 618 | { |
| 622 | 619 | // 0.6.6 |
| 623 | - $dir = self::strtoupper(dirname($name)); | |
| 624 | - $name = self::strtoupper(basename($name)); | |
| 620 | + $dir = SimpleXLSX::strtoupper(dirname($name)); | |
| 621 | + $name = SimpleXLSX::strtoupper(basename($name)); | |
| 625 | 622 | foreach ($this->package['entries'] as $entry) { |
| 626 | - if (self::strtoupper($entry['path']) === $dir && self::strtoupper($entry['name']) === $name) { | |
| 623 | + if (SimpleXLSX::strtoupper($entry['path']) === $dir && SimpleXLSX::strtoupper($entry['name']) === $name) { | |
| 627 | 624 | return true; |
| 628 | 625 | } |
| 629 | 626 | } |
| 630 | 627 | |
| @@ -711,9 +708,9 @@ | ||
| 711 | 708 | /* @var SimpleXMLElement $ws */ |
| 712 | 709 | |
| 713 | 710 | $ref = (string)$ws->dimension['ref']; |
| 714 | 711 | |
| 715 | - if (self::strpos($ref, ':') !== false) { | |
| 712 | + if (SimpleXLSX::strpos($ref, ':') !== false) { | |
| 716 | 713 | $d = explode(':', $ref); |
| 717 | 714 | $idx = $this->getIndex($d[1]); |
| 718 | 715 | |
| 719 | 716 | return [$idx[0] + 1, $idx[1] + 1]; |
| @@ -759,15 +756,14 @@ | ||
| 759 | 756 | } |
| 760 | 757 | |
| 761 | 758 | public function getIndex($cell = 'A1') |
| 762 | 759 | { |
| 763 | - $m = null; | |
| 764 | 760 | |
| 765 | 761 | if (preg_match('/([A-Z]+)(\d+)/', $cell, $m)) { |
| 766 | 762 | $col = $m[1]; |
| 767 | 763 | $row = $m[2]; |
| 768 | 764 | |
| 769 | - $colLen = self::strlen($col); | |
| 765 | + $colLen = SimpleXLSX::strlen($col); | |
| 770 | 766 | $index = 0; |
| 771 | 767 | |
| 772 | 768 | for ($i = $colLen - 1; $i >= 0; $i--) { |
| 773 | 769 | $index += (ord($col[$i]) - 64) * pow(26, $colLen - $i - 1); |
| @@ -817,15 +813,22 @@ | ||
| 817 | 813 | break; |
| 818 | 814 | |
| 819 | 815 | case 'b': |
| 820 | 816 | // Value is boolean |
| 821 | - $value = self::boolean((string)$cell->v); | |
| 817 | + $value = (string)$cell->v; | |
| 818 | + if ($value === '0') { | |
| 819 | + $value = false; | |
| 820 | + } elseif ($value === '1') { | |
| 821 | + $value = true; | |
| 822 | + } else { | |
| 823 | + $value = (bool)$cell->v; | |
| 824 | + } | |
| 822 | 825 | |
| 823 | 826 | break; |
| 824 | 827 | |
| 825 | 828 | case 'inlineStr': |
| 826 | 829 | // Value is rich text inline |
| 827 | - $value = self::parseRichText($cell->is); | |
| 830 | + $value = SimpleXLSX::parseRichText($cell->is); | |
| 828 | 831 | |
| 829 | 832 | break; |
| 830 | 833 | |
| 831 | 834 | case 'e': |
| @@ -837,10 +840,9 @@ | ||
| 837 | 840 | |
| 838 | 841 | case 'D': |
| 839 | 842 | // Date as float |
| 840 | 843 | if (!empty($cell->v)) { |
| 841 | - $value = $this->datetimeFormat ? | |
| 842 | - gmdate($this->datetimeFormat, $this->unixstamp((float)$cell->v)) : (float)$cell->v; | |
| 844 | + $value = $this->datetimeFormat ? gmdate($this->datetimeFormat, $this->unixstamp((float)$cell->v)) : (float)$cell->v; | |
| 843 | 845 | } |
| 844 | 846 | break; |
| 845 | 847 | |
| 846 | 848 | case 'd': |
| @@ -914,12 +916,9 @@ | ||
| 914 | 916 | |
| 915 | 917 | if ($x === 0 && $c['height']) { |
| 916 | 918 | $css .= 'height: '.round($c['height'] * 1.3333).'px;'; |
| 917 | 919 | } |
| 918 | - $v = htmlspecialchars($c['value'], ENT_QUOTES); | |
| 919 | - $v = preg_replace('/\R/', "<br>\r\n", $v); | |
| 920 | - $s .= '<'.$tag.' style="'.$css.'" nowrap>' | |
| 921 | - . ($v === '' ? ' ' : $v) . '</'.$tag.'>'; | |
| 920 | + $s .= '<'.$tag.' style="'.$css.'" nowrap>' . ($c['value'] === '' ? ' ' : htmlspecialchars($c['value'], ENT_QUOTES)) . '</'.$tag.'>'; | |
| 922 | 921 | $x++; |
| 923 | 922 | } |
| 924 | 923 | $s .= "</tr>\r\n"; |
| 925 | 924 | $y++; |
| @@ -1031,9 +1030,9 @@ | ||
| 1031 | 1030 | if (($ws = $this->worksheet($worksheetIndex)) === false) { |
| 1032 | 1031 | return false; |
| 1033 | 1032 | } |
| 1034 | 1033 | if (is_array($cell)) { |
| 1035 | - $cell = self::num2name($cell[0]) . $cell[1];// [3,21] -> D21 | |
| 1034 | + $cell = SimpleXLSX::num2name($cell[0]) . $cell[1];// [3,21] -> D21 | |
| 1036 | 1035 | } |
| 1037 | 1036 | if (is_string($cell)) { |
| 1038 | 1037 | $result = $ws->sheetData->xpath("row/c[@r='" . $cell . "']"); |
| 1039 | 1038 | if (count($result)) { |
| @@ -1080,10 +1079,9 @@ | ||
| 1080 | 1079 | return isset($this->sheetMetaData[$worksheetIndex]) ? $this->sheetMetaData[$worksheetIndex] : false; |
| 1081 | 1080 | } |
| 1082 | 1081 | public function isHiddenSheet($worksheetIndex) |
| 1083 | 1082 | { |
| 1084 | - return isset($this->sheetMetaData[$worksheetIndex]['state']) | |
| 1085 | - && $this->sheetMetaData[$worksheetIndex]['state'] === 'hidden'; | |
| 1083 | + return isset($this->sheetMetaData[$worksheetIndex]['state']) && $this->sheetMetaData[$worksheetIndex]['state'] === 'hidden'; | |
| 1086 | 1084 | } |
| 1087 | 1085 | |
| 1088 | 1086 | public function getStyles() |
| 1089 | 1087 | { |
| @@ -1103,9 +1101,9 @@ | ||
| 1103 | 1101 | public static function getTarget($base, $target) |
| 1104 | 1102 | { |
| 1105 | 1103 | $target = trim($target); |
| 1106 | 1104 | if (strpos($target, '/') === 0) { |
| 1107 | - return self::substr($target, 1); | |
| 1105 | + return SimpleXLSX::substr($target, 1); | |
| 1108 | 1106 | } |
| 1109 | 1107 | $target = ($base ? $base . '/' : '') . $target; |
| 1110 | 1108 | // a/b/../c -> a/c |
| 1111 | 1109 | $parts = explode('/', $target); |
| @@ -1143,9 +1141,9 @@ | ||
| 1143 | 1141 | $numeric = ($num - 1) % 26; |
| 1144 | 1142 | $letter = chr(65 + $numeric); |
| 1145 | 1143 | $num2 = (int)(($num - 1) / 26); |
| 1146 | 1144 | if ($num2 > 0) { |
| 1147 | - return self::num2name($num2) . $letter; | |
| 1145 | + return SimpleXLSX::num2name($num2) . $letter; | |
| 1148 | 1146 | } |
| 1149 | 1147 | return $letter; |
| 1150 | 1148 | } |
| 1151 | 1149 | |
| @@ -1155,23 +1153,12 @@ | ||
| 1155 | 1153 | } |
| 1156 | 1154 | |
| 1157 | 1155 | public static function substr($str, $start, $length = null) |
| 1158 | 1156 | { |
| 1159 | - return (ini_get('mbstring.func_overload') & 2) ? | |
| 1160 | - mb_substr($str, $start, ($length === null) ? mb_strlen($str, '8bit') : $length, '8bit') | |
| 1161 | - : substr($str, $start, ($length === null) ? strlen($str) : $length); | |
| 1157 | + return (ini_get('mbstring.func_overload') & 2) ? mb_substr($str, $start, ($length === null) ? mb_strlen($str, '8bit') : $length, '8bit') : substr($str, $start, ($length === null) ? strlen($str) : $length); | |
| 1162 | 1158 | } |
| 1163 | 1159 | |
| 1164 | 1160 | public static function strpos($haystack, $needle, $offset = 0) |
| 1165 | 1161 | { |
| 1166 | - return (ini_get('mbstring.func_overload') & 2) ? | |
| 1167 | - mb_strpos($haystack, $needle, $offset, '8bit') : strpos($haystack, $needle, $offset); | |
| 1168 | - } | |
| 1169 | - public static function boolean($value) | |
| 1170 | - { | |
| 1171 | - if (is_numeric($value)) { | |
| 1172 | - return (bool) $value; | |
| 1173 | - } | |
| 1174 | - | |
| 1175 | - return $value === 'true' || $value === 'TRUE'; | |
| 1162 | + return (ini_get('mbstring.func_overload') & 2) ? mb_strpos($haystack, $needle, $offset, '8bit') : strpos($haystack, $needle, $offset); | |
| 1176 | 1163 | } |
| 1177 | 1164 | } |