PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.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 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Shared / OLE / PPS.php

PPS.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Shared/OLE/PPS.php

215 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Shared\OLE;
4
5 // vim: set expandtab tabstop=4 shiftwidth=4:
6 // +----------------------------------------------------------------------+
7 // | PHP Version 4 |
8 // +----------------------------------------------------------------------+
9 // | Copyright (c) 1997-2002 The PHP Group |
10 // +----------------------------------------------------------------------+
11 // | This source file is subject to version 2.02 of the PHP license, |
12 // | that is bundled with this package in the file LICENSE, and is |
13 // | available at through the world-wide-web at |
14 // | http://www.php.net/license/2_02.txt. |
15 // | If you did not receive a copy of the PHP license and are unable to |
16 // | obtain it through the world-wide-web, please send a note to |
17 // | [email protected] so we can mail you a copy immediately. |
18 // +----------------------------------------------------------------------+
19 // | Author: Xavier Noguer <[email protected]> |
20 // | Based on OLE::Storage_Lite by Kawai, Takanori |
21 // +----------------------------------------------------------------------+
22 //
23 use TablePress\PhpOffice\PhpSpreadsheet\Shared\OLE;
24
25 /**
26 * Class for creating PPS's for OLE containers.
27 *
28 * @author Xavier Noguer <[email protected]>
29 */
30 class PPS
31 {
32 private const ALL_ONE_BITS = (PHP_INT_SIZE > 4) ? 0xFFFFFFFF : -1;
33
34 /**
35 * The PPS index.
36 */
37 public int $No;
38
39 /**
40 * The PPS name (in Unicode).
41 */
42 public string $Name;
43
44 /**
45 * The PPS type. Dir, Root or File.
46 */
47 public int $Type;
48
49 /**
50 * The index of the previous PPS.
51 */
52 public int $PrevPps;
53
54 /**
55 * The index of the next PPS.
56 */
57 public int $NextPps;
58
59 /**
60 * The index of it's first child if this is a Dir or Root PPS.
61 */
62 public int $DirPps;
63
64 /**
65 * A timestamp.
66 * @var float|int
67 */
68 public $Time1st;
69
70 /**
71 * A timestamp.
72 * @var float|int
73 */
74 public $Time2nd;
75
76 /**
77 * Starting block (small or big) for this PPS's data inside the container.
78 */
79 public ?int $startBlock = null;
80
81 /**
82 * The size of the PPS's data (in bytes).
83 */
84 public int $Size;
85
86 /**
87 * The PPS's data (only used if it's not using a temporary file).
88 */
89 public string $_data = '';
90
91 /**
92 * Array of child PPS's (only used by Root and Dir PPS's).
93 *
94 * @var mixed[]
95 */
96 public array $children = [];
97
98 /**
99 * Pointer to OLE container.
100 */
101 public OLE $ole;
102
103 /**
104 * The constructor.
105 *
106 * @param ?int $No The PPS index
107 * @param ?string $name The PPS name
108 * @param ?int $type The PPS type. Dir, Root or File
109 * @param ?int $prev The index of the previous PPS
110 * @param ?int $next The index of the next PPS
111 * @param ?int $dir The index of it's first child if this is a Dir or Root PPS
112 * @param null|float|int $time_1st A timestamp
113 * @param null|float|int $time_2nd A timestamp
114 * @param ?string $data The (usually binary) source data of the PPS
115 * @param mixed[] $children Array containing children PPS for this PPS
116 */
117 public function __construct(?int $No, ?string $name, ?int $type, ?int $prev, ?int $next, ?int $dir, $time_1st, $time_2nd, ?string $data, array $children)
118 {
119 $this->No = (int) $No;
120 $this->Name = (string) $name;
121 $this->Type = (int) $type;
122 $this->PrevPps = (int) $prev;
123 $this->NextPps = (int) $next;
124 $this->DirPps = (int) $dir;
125 $this->Time1st = $time_1st ?? 0;
126 $this->Time2nd = $time_2nd ?? 0;
127 $this->_data = (string) $data;
128 $this->children = $children;
129 $this->Size = strlen((string) $data);
130 }
131
132 /**
133 * Returns the amount of data saved for this PPS.
134 *
135 * @return int The amount of data (in bytes)
136 */
137 public function getDataLen(): int
138 {
139 //if (!isset($this->_data)) {
140 // return 0;
141 //}
142
143 return strlen($this->_data);
144 }
145
146 /**
147 * Returns a string with the PPS's WK (What is a WK?).
148 *
149 * @return string The binary string
150 */
151 public function getPpsWk(): string
152 {
153 $ret = str_pad($this->Name, 64, "\x00");
154
155 $ret .= pack('v', strlen($this->Name) + 2) // 66
156 . pack('c', $this->Type) // 67
157 . pack('c', 0x00) //UK // 68
158 . pack('V', $this->PrevPps) //Prev // 72
159 . pack('V', $this->NextPps) //Next // 76
160 . pack('V', $this->DirPps) //Dir // 80
161 . "\x00\x09\x02\x00" // 84
162 . "\x00\x00\x00\x00" // 88
163 . "\xc0\x00\x00\x00" // 92
164 . "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
165 . "\x00\x00\x00\x00" // 100
166 . OLE::localDateToOLE($this->Time1st) // 108
167 . OLE::localDateToOLE($this->Time2nd) // 116
168 . pack('V', $this->startBlock ?? 0) // 120
169 . pack('V', $this->Size) // 124
170 . pack('V', 0); // 128
171
172 return $ret;
173 }
174
175 /**
176 * Updates index and pointers to previous, next and children PPS's for this
177 * PPS. I don't think it'll work with Dir PPS's.
178 *
179 * @param self[] $raList Reference to the array of PPS's for the whole OLE
180 * container
181 *
182 * @return int The index for this PPS
183 * @param mixed $to_save
184 */
185 public static function savePpsSetPnt(array &$raList, $to_save, int $depth = 0): int
186 {
187 if (!is_array($to_save) || (empty($to_save))) {
188 return self::ALL_ONE_BITS;
189 }
190 /** @var self[] $to_save */
191 if (count($to_save) == 1) {
192 $cnt = count($raList);
193 // If the first entry, it's the root... Don't clone it!
194 $raList[$cnt] = ($depth == 0) ? $to_save[0] : clone $to_save[0];
195 $raList[$cnt]->No = $cnt;
196 $raList[$cnt]->PrevPps = self::ALL_ONE_BITS;
197 $raList[$cnt]->NextPps = self::ALL_ONE_BITS;
198 $raList[$cnt]->DirPps = self::savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
199 } else {
200 $iPos = (int) floor(count($to_save) / 2);
201 $aPrev = array_slice($to_save, 0, $iPos);
202 $aNext = array_slice($to_save, $iPos + 1);
203 $cnt = count($raList);
204 // If the first entry, it's the root... Don't clone it!
205 $raList[$cnt] = ($depth == 0) ? $to_save[$iPos] : clone $to_save[$iPos];
206 $raList[$cnt]->No = $cnt;
207 $raList[$cnt]->PrevPps = self::savePpsSetPnt($raList, $aPrev, $depth++);
208 $raList[$cnt]->NextPps = self::savePpsSetPnt($raList, $aNext, $depth++);
209 $raList[$cnt]->DirPps = self::savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
210 }
211
212 return $cnt;
213 }
214 }
215