74 $this->bigBlockSize = 2 ** (
75 (isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9
77 $this->smallBlockSize = 2 ** (
78 (isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6
85 [$iSBDcnt, $iBBcnt, $iPPScnt] = $this->
calcSize($aList);
87 $this->
saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
97 $this->
saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
112 [$iSBDcnt, $iBBcnt, $iPPScnt] = [0, 0, 0];
115 $iCount = count($raList);
116 for (
$i = 0;
$i < $iCount; ++
$i) {
118 $raList[
$i]->Size = $raList[
$i]->getDataLen();
120 $iSBcnt += floor($raList[
$i]->
Size / $this->smallBlockSize)
123 $iBBcnt += (floor($raList[
$i]->
Size / $this->bigBlockSize) +
130 $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt) ? 1 : 0);
131 $iBBcnt += (floor($iSmallLen / $this->bigBlockSize) +
133 $iCnt = count($raList);
135 $iPPScnt = (floor($iCnt / $iBdCnt) + (($iCnt % $iBdCnt) ? 1 : 0));
137 return [$iSBDcnt, $iBBcnt, $iPPScnt];
151 $iWk = log($i2) / log(2);
153 return ($iWk > floor($iWk)) ? floor($iWk) + 1 : $iWk;
163 private function saveHeader($iSBDcnt, $iBBcnt, $iPPScnt): void
172 $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
174 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0);
175 $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0);
178 if ($iBdCnt > $i1stBdL) {
182 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0);
183 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0);
184 if ($iBdCnt <= ($iBdExL * $iBlCnt + $i1stBdL)) {
193 "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" 207 . pack(
'V', $iBBcnt + $iSBDcnt)
210 . pack(
'V', $iSBDcnt ? 0 : -2)
211 . pack(
'V', $iSBDcnt)
214 if ($iBdCnt < $i1stBdL) {
221 fwrite($FILE, pack(
'V', $iAll + $iBdCnt) . pack(
'V', $iBdExL));
225 for (
$i = 0;
$i < $i1stBdL &&
$i < $iBdCnt; ++
$i) {
226 fwrite($FILE, pack(
'V', $iAll +
$i));
230 for ($j = 0; $j < $jB; ++$j) {
231 fwrite($FILE, (pack(
'V', -1)));
247 $iCount = count($raList);
248 for (
$i = 0;
$i < $iCount; ++
$i) {
250 $raList[
$i]->Size = $raList[
$i]->getDataLen();
252 fwrite($FILE, $raList[
$i]->_data);
254 if ($raList[
$i]->
Size % $this->bigBlockSize) {
255 fwrite($FILE, str_repeat(
"\x00", $this->bigBlockSize - ($raList[
$i]->
Size % $this->bigBlockSize)));
258 $raList[
$i]->startBlock = $iStBlk;
260 (floor($raList[
$i]->
Size / $this->bigBlockSize) +
280 $iCount = count($raList);
281 for (
$i = 0;
$i < $iCount; ++
$i) {
284 if ($raList[
$i]->
Size <= 0) {
288 $iSmbCnt = floor($raList[
$i]->
Size / $this->smallBlockSize)
292 for ($j = 0; $j < $jB; ++$j) {
293 fwrite($FILE, pack(
'V', $j + $iSmBlk + 1));
295 fwrite($FILE, pack(
'V', -2));
298 $sRes .= $raList[
$i]->_data;
299 if ($raList[
$i]->
Size % $this->smallBlockSize) {
300 $sRes .= str_repeat(
"\x00", $this->smallBlockSize - ($raList[
$i]->
Size % $this->smallBlockSize));
303 $raList[
$i]->startBlock = $iSmBlk;
309 if ($iSmBlk % $iSbCnt) {
310 $iB = $iSbCnt - ($iSmBlk % $iSbCnt);
311 for (
$i = 0;
$i < $iB; ++
$i) {
312 fwrite($FILE, pack(
'V', -1));
327 $iC = count($raList);
328 for (
$i = 0;
$i < $iC; ++
$i) {
329 fwrite($this->fileHandle, $raList[
$i]->
getPpsWk());
332 $iCnt = count($raList);
334 if ($iCnt % $iBCnt) {
335 fwrite($this->fileHandle, str_repeat(
"\x00", ($iBCnt - ($iCnt % $iBCnt)) *
OLE::OLE_PPS_SIZE));
346 private function saveBbd($iSbdSize, $iBsize, $iPpsCnt): void
354 $iAll = $iBsize + $iPpsCnt + $iSbdSize;
356 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0);
357 $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0);
359 if ($iBdCnt > $i1stBdL) {
363 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0);
364 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0);
365 if ($iBdCnt <= ($iBdExL * $iBbCnt + $i1stBdL)) {
374 for (
$i = 0;
$i < ($iSbdSize - 1); ++
$i) {
375 fwrite($FILE, pack(
'V',
$i + 1));
377 fwrite($FILE, pack(
'V', -2));
380 for (
$i = 0;
$i < ($iBsize - 1); ++
$i) {
381 fwrite($FILE, pack(
'V',
$i + $iSbdSize + 1));
383 fwrite($FILE, pack(
'V', -2));
386 for (
$i = 0;
$i < ($iPpsCnt - 1); ++
$i) {
387 fwrite($FILE, pack(
'V',
$i + $iSbdSize + $iBsize + 1));
389 fwrite($FILE, pack(
'V', -2));
391 for (
$i = 0;
$i < $iBdCnt; ++
$i) {
392 fwrite($FILE, pack(
'V', 0xFFFFFFFD));
395 for (
$i = 0;
$i < $iBdExL; ++
$i) {
396 fwrite($FILE, pack(
'V', 0xFFFFFFFC));
399 if (($iAllW + $iBdCnt) % $iBbCnt) {
400 $iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt));
401 for (
$i = 0;
$i < $iBlock; ++
$i) {
402 fwrite($FILE, pack(
'V', -1));
406 if ($iBdCnt > $i1stBdL) {
409 for (
$i = $i1stBdL;
$i < $iBdCnt;
$i++, ++$iN) {
410 if ($iN >= ($iBbCnt - 1)) {
413 fwrite($FILE, pack(
'V', $iAll + $iBdCnt + $iNb));
415 fwrite($FILE, pack(
'V', $iBsize + $iSbdSize + $iPpsCnt +
$i));
417 if (($iBdCnt - $i1stBdL) % ($iBbCnt - 1)) {
418 $iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1));
419 for (
$i = 0;
$i < $iB; ++
$i) {
420 fwrite($FILE, pack(
'V', -1));
423 fwrite($FILE, pack(
'V', -2));
calcSize(&$raList)
Calculate some numbers.
static ascToUcs($ascii)
Utility function to transform ASCII text to Unicode.
static adjust2($i2)
Helper function for caculating a magic value for block sizes.
static savePpsSetPnt(&$raList, $to_save, $depth=0)
Updates index and pointers to previous, next and children PPS's for this PPS.
Class for creating PPS's for OLE containers.
saveBigData($iStBlk, &$raList)
Saving big data (PPS's with data bigger than ::OLE_DATA_SIZE_SMALL).
saveBbd($iSbdSize, $iBsize, $iPpsCnt)
Saving Big Block Depot.
save($fileHandle)
Method for saving the whole OLE container (including files).
makeSmallData(&$raList)
get small data (PPS's with data smaller than ::OLE_DATA_SIZE_SMALL).
__construct($time_1st, $time_2nd, $raChild)
savePps(&$raList)
Saves all the PPS's WKs.
const OLE_DATA_SIZE_SMALL
Class for creating Root PPS's for OLE containers.
getPpsWk()
Returns a string with the PPS's WK (What is a WK?).
saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
Save OLE header.