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