1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpSpreadsheet\Shared\OLE\PPS; |
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
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class for creating Root PPS's for OLE containers |
26
|
|
|
* |
27
|
|
|
* @author Xavier Noguer <[email protected]> |
28
|
|
|
* @category PhpSpreadsheet |
29
|
|
|
*/ |
30
|
|
|
class Root extends \PhpSpreadsheet\Shared\OLE\PPS |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Directory for temporary files |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $tempDirectory = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param int $time_1st A timestamp |
40
|
|
|
* @param int $time_2nd A timestamp |
41
|
|
|
* @param File[] $raChild |
42
|
|
|
*/ |
43
|
|
|
public function __construct($time_1st, $time_2nd, $raChild) |
44
|
|
|
{ |
45
|
|
|
$this->_tempDir = \PhpSpreadsheet\Shared\File::sysGetTempDir(); |
|
|
|
|
46
|
|
|
|
47
|
|
|
parent::__construct(null, \PhpSpreadsheet\Shared\OLE::ascToUcs('Root Entry'), \PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Method for saving the whole OLE container (including files). |
52
|
|
|
* In fact, if called with an empty argument (or '-'), it saves to a |
53
|
|
|
* temporary file and then outputs it's contents to stdout. |
54
|
|
|
* If a resource pointer to a stream created by fopen() is passed |
55
|
|
|
* it will be used, but you have to close such stream by yourself. |
56
|
|
|
* |
57
|
|
|
* @param string|resource $filename The name of the file or stream where to save the OLE container. |
58
|
|
|
* @throws \PhpSpreadsheet\Writer\Exception |
59
|
|
|
* @return bool true on success |
60
|
|
|
*/ |
61
|
|
|
public function save($filename) |
62
|
|
|
{ |
63
|
|
|
// Initial Setting for saving |
64
|
|
|
$this->_BIG_BLOCK_SIZE = pow( |
|
|
|
|
65
|
|
|
2, |
66
|
|
|
(isset($this->_BIG_BLOCK_SIZE)) ? self::adjust2($this->_BIG_BLOCK_SIZE) : 9 |
67
|
|
|
); |
68
|
|
|
$this->_SMALL_BLOCK_SIZE = pow( |
|
|
|
|
69
|
|
|
2, |
70
|
|
|
(isset($this->_SMALL_BLOCK_SIZE)) ? self::adjust2($this->_SMALL_BLOCK_SIZE) : 6 |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
if (is_resource($filename)) { |
74
|
|
|
$this->_FILEH_ = $filename; |
|
|
|
|
75
|
|
|
} elseif ($filename == '-' || $filename == '') { |
76
|
|
|
if ($this->tempDirectory === null) { |
77
|
|
|
$this->tempDirectory = \PhpSpreadsheet\Shared\File::sysGetTempDir(); |
78
|
|
|
} |
79
|
|
|
$this->_tmp_filename = tempnam($this->tempDirectory, 'OLE_PPS_Root'); |
|
|
|
|
80
|
|
|
$this->_FILEH_ = fopen($this->_tmp_filename, 'w+b'); |
81
|
|
|
if ($this->_FILEH_ == false) { |
82
|
|
|
throw new \PhpSpreadsheet\Writer\Exception("Can't create temporary file."); |
83
|
|
|
} |
84
|
|
|
} else { |
85
|
|
|
$this->_FILEH_ = fopen($filename, 'wb'); |
86
|
|
|
} |
87
|
|
|
if ($this->_FILEH_ == false) { |
88
|
|
|
throw new \PhpSpreadsheet\Writer\Exception("Can't open $filename. It may be in use or protected."); |
89
|
|
|
} |
90
|
|
|
// Make an array of PPS's (for Save) |
91
|
|
|
$aList = []; |
92
|
|
|
\PhpSpreadsheet\Shared\OLE\PPS::_savePpsSetPnt($aList, [$this]); |
93
|
|
|
// calculate values for header |
94
|
|
|
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo); |
95
|
|
|
// Save Header |
96
|
|
|
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt); |
97
|
|
|
|
98
|
|
|
// Make Small Data string (write SBD) |
99
|
|
|
$this->_data = $this->_makeSmallData($aList); |
100
|
|
|
|
101
|
|
|
// Write BB |
102
|
|
|
$this->_saveBigData($iSBDcnt, $aList); |
103
|
|
|
// Write PPS |
104
|
|
|
$this->_savePps($aList); |
105
|
|
|
// Write Big Block Depot and BDList and Adding Header informations |
106
|
|
|
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt); |
107
|
|
|
|
108
|
|
|
if (!is_resource($filename)) { |
109
|
|
|
fclose($this->_FILEH_); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Calculate some numbers |
117
|
|
|
* |
118
|
|
|
* @param array $raList Reference to an array of PPS's |
119
|
|
|
* @return float[] The array of numbers |
120
|
|
|
*/ |
121
|
|
|
public function _calcSize(&$raList) |
122
|
|
|
{ |
123
|
|
|
// Calculate Basic Setting |
124
|
|
|
list($iSBDcnt, $iBBcnt, $iPPScnt) = [0, 0, 0]; |
|
|
|
|
125
|
|
|
$iSmallLen = 0; |
|
|
|
|
126
|
|
|
$iSBcnt = 0; |
127
|
|
|
$iCount = count($raList); |
128
|
|
|
for ($i = 0; $i < $iCount; ++$i) { |
129
|
|
|
if ($raList[$i]->Type == \PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_FILE) { |
130
|
|
|
$raList[$i]->Size = $raList[$i]->getDataLen(); |
131
|
|
|
if ($raList[$i]->Size < \PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) { |
132
|
|
|
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) |
133
|
|
|
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) ? 1 : 0); |
134
|
|
|
} else { |
135
|
|
|
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) + |
136
|
|
|
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) ? 1 : 0)); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE; |
141
|
|
|
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE); |
142
|
|
|
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt) ? 1 : 0); |
143
|
|
|
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) + |
144
|
|
|
(($iSmallLen % $this->_BIG_BLOCK_SIZE) ? 1 : 0)); |
145
|
|
|
$iCnt = count($raList); |
146
|
|
|
$iBdCnt = $this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE; |
147
|
|
|
$iPPScnt = (floor($iCnt / $iBdCnt) + (($iCnt % $iBdCnt) ? 1 : 0)); |
148
|
|
|
|
149
|
|
|
return [$iSBDcnt, $iBBcnt, $iPPScnt]; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Helper function for caculating a magic value for block sizes |
154
|
|
|
* |
155
|
|
|
* @param int $i2 The argument |
156
|
|
|
* @see save() |
157
|
|
|
* @return float |
158
|
|
|
*/ |
159
|
|
|
private static function adjust2($i2) |
160
|
|
|
{ |
161
|
|
|
$iWk = log($i2) / log(2); |
162
|
|
|
|
163
|
|
|
return ($iWk > floor($iWk)) ? floor($iWk) + 1 : $iWk; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Save OLE header |
168
|
|
|
* |
169
|
|
|
* @param int $iSBDcnt |
170
|
|
|
* @param int $iBBcnt |
171
|
|
|
* @param int $iPPScnt |
172
|
|
|
*/ |
173
|
|
|
public function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt) |
174
|
|
|
{ |
175
|
|
|
$FILE = $this->_FILEH_; |
176
|
|
|
|
177
|
|
|
// Calculate Basic Setting |
178
|
|
|
$iBlCnt = $this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; |
179
|
|
|
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; |
180
|
|
|
|
181
|
|
|
$iBdExL = 0; |
182
|
|
|
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt; |
183
|
|
|
$iAllW = $iAll; |
184
|
|
|
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0); |
185
|
|
|
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0); |
186
|
|
|
|
187
|
|
|
// Calculate BD count |
188
|
|
View Code Duplication |
if ($iBdCnt > $i1stBdL) { |
|
|
|
|
189
|
|
|
while (1) { |
190
|
|
|
++$iBdExL; |
191
|
|
|
++$iAllW; |
192
|
|
|
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0); |
193
|
|
|
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0); |
194
|
|
|
if ($iBdCnt <= ($iBdExL * $iBlCnt + $i1stBdL)) { |
195
|
|
|
break; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
// Save Header |
201
|
|
|
fwrite( |
202
|
|
|
$FILE, |
203
|
|
|
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" |
204
|
|
|
. "\x00\x00\x00\x00" |
205
|
|
|
. "\x00\x00\x00\x00" |
206
|
|
|
. "\x00\x00\x00\x00" |
207
|
|
|
. "\x00\x00\x00\x00" |
208
|
|
|
. pack('v', 0x3b) |
209
|
|
|
. pack('v', 0x03) |
210
|
|
|
. pack('v', -2) |
211
|
|
|
. pack('v', 9) |
212
|
|
|
. pack('v', 6) |
213
|
|
|
. pack('v', 0) |
214
|
|
|
. "\x00\x00\x00\x00" |
215
|
|
|
. "\x00\x00\x00\x00" |
216
|
|
|
. pack('V', $iBdCnt) |
217
|
|
|
. pack('V', $iBBcnt + $iSBDcnt) //ROOT START |
218
|
|
|
. pack('V', 0) |
219
|
|
|
. pack('V', 0x1000) |
220
|
|
|
. pack('V', $iSBDcnt ? 0 : -2) //Small Block Depot |
221
|
|
|
. pack('V', $iSBDcnt) |
222
|
|
|
); |
223
|
|
|
// Extra BDList Start, Count |
224
|
|
|
if ($iBdCnt < $i1stBdL) { |
225
|
|
|
fwrite( |
226
|
|
|
$FILE, |
227
|
|
|
pack('V', -2) // Extra BDList Start |
228
|
|
|
. pack('V', 0)// Extra BDList Count |
229
|
|
|
); |
230
|
|
|
} else { |
231
|
|
|
fwrite($FILE, pack('V', $iAll + $iBdCnt) . pack('V', $iBdExL)); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
// BDList |
235
|
|
|
for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) { |
236
|
|
|
fwrite($FILE, pack('V', $iAll + $i)); |
237
|
|
|
} |
238
|
|
|
if ($i < $i1stBdL) { |
239
|
|
|
$jB = $i1stBdL - $i; |
240
|
|
View Code Duplication |
for ($j = 0; $j < $jB; ++$j) { |
|
|
|
|
241
|
|
|
fwrite($FILE, (pack('V', -1))); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Saving big data (PPS's with data bigger than \PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) |
248
|
|
|
* |
249
|
|
|
* @param int $iStBlk |
250
|
|
|
* @param array &$raList Reference to array of PPS's |
251
|
|
|
*/ |
252
|
|
|
public function _saveBigData($iStBlk, &$raList) |
253
|
|
|
{ |
254
|
|
|
$FILE = $this->_FILEH_; |
255
|
|
|
|
256
|
|
|
// cycle through PPS's |
257
|
|
|
$iCount = count($raList); |
258
|
|
|
for ($i = 0; $i < $iCount; ++$i) { |
259
|
|
|
if ($raList[$i]->Type != \PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_DIR) { |
260
|
|
|
$raList[$i]->Size = $raList[$i]->getDataLen(); |
261
|
|
|
if (($raList[$i]->Size >= \PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == \PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) { |
262
|
|
|
fwrite($FILE, $raList[$i]->_data); |
263
|
|
|
|
264
|
|
View Code Duplication |
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) { |
|
|
|
|
265
|
|
|
fwrite($FILE, str_repeat("\x00", $this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE))); |
266
|
|
|
} |
267
|
|
|
// Set For PPS |
268
|
|
|
$raList[$i]->startBlock = $iStBlk; |
269
|
|
|
$iStBlk += |
270
|
|
|
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) + |
271
|
|
|
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) ? 1 : 0)); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* get small data (PPS's with data smaller than \PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) |
279
|
|
|
* |
280
|
|
|
* @param array &$raList Reference to array of PPS's |
281
|
|
|
*/ |
282
|
|
|
public function _makeSmallData(&$raList) |
283
|
|
|
{ |
284
|
|
|
$sRes = ''; |
285
|
|
|
$FILE = $this->_FILEH_; |
286
|
|
|
$iSmBlk = 0; |
287
|
|
|
|
288
|
|
|
$iCount = count($raList); |
289
|
|
|
for ($i = 0; $i < $iCount; ++$i) { |
290
|
|
|
// Make SBD, small data string |
291
|
|
|
if ($raList[$i]->Type == \PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_FILE) { |
292
|
|
|
if ($raList[$i]->Size <= 0) { |
293
|
|
|
continue; |
294
|
|
|
} |
295
|
|
|
if ($raList[$i]->Size < \PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) { |
296
|
|
|
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) |
297
|
|
|
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) ? 1 : 0); |
298
|
|
|
// Add to SBD |
299
|
|
|
$jB = $iSmbCnt - 1; |
300
|
|
View Code Duplication |
for ($j = 0; $j < $jB; ++$j) { |
|
|
|
|
301
|
|
|
fwrite($FILE, pack('V', $j + $iSmBlk + 1)); |
302
|
|
|
} |
303
|
|
|
fwrite($FILE, pack('V', -2)); |
304
|
|
|
|
305
|
|
|
// Add to Data String(this will be written for RootEntry) |
306
|
|
|
$sRes .= $raList[$i]->_data; |
307
|
|
View Code Duplication |
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) { |
|
|
|
|
308
|
|
|
$sRes .= str_repeat("\x00", $this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); |
309
|
|
|
} |
310
|
|
|
// Set for PPS |
311
|
|
|
$raList[$i]->startBlock = $iSmBlk; |
312
|
|
|
$iSmBlk += $iSmbCnt; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE); |
317
|
|
|
if ($iSmBlk % $iSbCnt) { |
318
|
|
|
$iB = $iSbCnt - ($iSmBlk % $iSbCnt); |
319
|
|
View Code Duplication |
for ($i = 0; $i < $iB; ++$i) { |
|
|
|
|
320
|
|
|
fwrite($FILE, pack('V', -1)); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
return $sRes; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Saves all the PPS's WKs |
329
|
|
|
* |
330
|
|
|
* @param array $raList Reference to an array with all PPS's |
331
|
|
|
*/ |
332
|
|
|
public function _savePps(&$raList) |
333
|
|
|
{ |
334
|
|
|
// Save each PPS WK |
335
|
|
|
$iC = count($raList); |
336
|
|
|
for ($i = 0; $i < $iC; ++$i) { |
337
|
|
|
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk()); |
338
|
|
|
} |
339
|
|
|
// Adjust for Block |
340
|
|
|
$iCnt = count($raList); |
341
|
|
|
$iBCnt = $this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE; |
342
|
|
|
if ($iCnt % $iBCnt) { |
343
|
|
|
fwrite($this->_FILEH_, str_repeat("\x00", ($iBCnt - ($iCnt % $iBCnt)) * \PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE)); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Saving Big Block Depot |
349
|
|
|
* |
350
|
|
|
* @param int $iSbdSize |
351
|
|
|
* @param int $iBsize |
352
|
|
|
* @param int $iPpsCnt |
353
|
|
|
*/ |
354
|
|
|
public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt) |
355
|
|
|
{ |
356
|
|
|
$FILE = $this->_FILEH_; |
357
|
|
|
// Calculate Basic Setting |
358
|
|
|
$iBbCnt = $this->_BIG_BLOCK_SIZE / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; |
359
|
|
|
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / \PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; |
360
|
|
|
|
361
|
|
|
$iBdExL = 0; |
362
|
|
|
$iAll = $iBsize + $iPpsCnt + $iSbdSize; |
363
|
|
|
$iAllW = $iAll; |
364
|
|
|
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0); |
365
|
|
|
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0); |
366
|
|
|
// Calculate BD count |
367
|
|
View Code Duplication |
if ($iBdCnt > $i1stBdL) { |
|
|
|
|
368
|
|
|
while (1) { |
369
|
|
|
++$iBdExL; |
370
|
|
|
++$iAllW; |
371
|
|
|
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0); |
372
|
|
|
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0); |
373
|
|
|
if ($iBdCnt <= ($iBdExL * $iBbCnt + $i1stBdL)) { |
374
|
|
|
break; |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
// Making BD |
380
|
|
|
// Set for SBD |
381
|
|
|
if ($iSbdSize > 0) { |
382
|
|
View Code Duplication |
for ($i = 0; $i < ($iSbdSize - 1); ++$i) { |
|
|
|
|
383
|
|
|
fwrite($FILE, pack('V', $i + 1)); |
384
|
|
|
} |
385
|
|
|
fwrite($FILE, pack('V', -2)); |
386
|
|
|
} |
387
|
|
|
// Set for B |
388
|
|
View Code Duplication |
for ($i = 0; $i < ($iBsize - 1); ++$i) { |
|
|
|
|
389
|
|
|
fwrite($FILE, pack('V', $i + $iSbdSize + 1)); |
390
|
|
|
} |
391
|
|
|
fwrite($FILE, pack('V', -2)); |
392
|
|
|
|
393
|
|
|
// Set for PPS |
394
|
|
View Code Duplication |
for ($i = 0; $i < ($iPpsCnt - 1); ++$i) { |
|
|
|
|
395
|
|
|
fwrite($FILE, pack('V', $i + $iSbdSize + $iBsize + 1)); |
396
|
|
|
} |
397
|
|
|
fwrite($FILE, pack('V', -2)); |
398
|
|
|
// Set for BBD itself ( 0xFFFFFFFD : BBD) |
399
|
|
|
for ($i = 0; $i < $iBdCnt; ++$i) { |
400
|
|
|
fwrite($FILE, pack('V', 0xFFFFFFFD)); |
401
|
|
|
} |
402
|
|
|
// Set for ExtraBDList |
403
|
|
|
for ($i = 0; $i < $iBdExL; ++$i) { |
404
|
|
|
fwrite($FILE, pack('V', 0xFFFFFFFC)); |
405
|
|
|
} |
406
|
|
|
// Adjust for Block |
407
|
|
|
if (($iAllW + $iBdCnt) % $iBbCnt) { |
408
|
|
|
$iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); |
409
|
|
|
for ($i = 0; $i < $iBlock; ++$i) { |
410
|
|
|
fwrite($FILE, pack('V', -1)); |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
// Extra BDList |
414
|
|
|
if ($iBdCnt > $i1stBdL) { |
415
|
|
|
$iN = 0; |
416
|
|
|
$iNb = 0; |
417
|
|
|
for ($i = $i1stBdL; $i < $iBdCnt; $i++, ++$iN) { |
418
|
|
|
if ($iN >= ($iBbCnt - 1)) { |
419
|
|
|
$iN = 0; |
420
|
|
|
++$iNb; |
421
|
|
|
fwrite($FILE, pack('V', $iAll + $iBdCnt + $iNb)); |
422
|
|
|
} |
423
|
|
|
fwrite($FILE, pack('V', $iBsize + $iSbdSize + $iPpsCnt + $i)); |
424
|
|
|
} |
425
|
|
|
if (($iBdCnt - $i1stBdL) % ($iBbCnt - 1)) { |
426
|
|
|
$iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1)); |
427
|
|
View Code Duplication |
for ($i = 0; $i < $iB; ++$i) { |
|
|
|
|
428
|
|
|
fwrite($FILE, pack('V', -1)); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
fwrite($FILE, pack('V', -2)); |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: