23 require_once (
'classes/OLE/PPS.php');
73 $this->_tmp_dir =
$dir;
91 $this->_BIG_BLOCK_SIZE = pow(2,
92 ((isset($this->_BIG_BLOCK_SIZE))? $this->
_adjust2($this->_BIG_BLOCK_SIZE) : 9));
93 $this->_SMALL_BLOCK_SIZE= pow(2,
94 ((isset($this->_SMALL_BLOCK_SIZE))? $this->
_adjust2($this->_SMALL_BLOCK_SIZE): 6));
99 $this->_tmp_filename = tempnam($this->_tmp_dir,
"OLE_PPS_Root");
100 $this->_FILEH_ = @fopen($this->_tmp_filename,
"w+b");
101 if ($this->_FILEH_ ==
false) {
102 return $this->raiseError(
"Can't create temporary file.");
107 $this->_FILEH_ = @fopen(
$filename,
"wb");
108 if ($this->_FILEH_ ==
false) {
109 return $this->raiseError(
"Can't open $filename. It may be in use or protected.");
116 list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->
_calcSize($aList);
128 $this->
_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
132 fseek($this->_FILEH_, 0);
133 fpassthru($this->_FILEH_);
134 @fclose($this->_FILEH_);
136 @unlink($this->_tmp_filename);
139 @fclose($this->_FILEH_);
154 list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
157 for ($i = 0; $i < count($raList); $i++) {
159 $raList[$i]->Size = $raList[$i]->_DataLen();
161 $iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
162 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
165 $iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
166 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
170 $iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
172 $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
173 $iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
174 (( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
175 $iCnt = count($raList);
177 $iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
179 return array($iSBDcnt, $iBBcnt, $iPPScnt);
192 $iWk = log($i2)/log(2);
193 return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
206 $FILE = $this->_FILEH_;
213 $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
215 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
216 $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
219 if ($iBdCnt >$i1stBdL)
225 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
226 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
227 if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
235 "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
249 . pack(
"V", $iBBcnt+$iSBDcnt)
256 if ($iBdCnt < $i1stBdL)
265 fwrite($FILE, pack(
"V", $iAll+$iBdCnt) . pack(
"V", $iBdExL));
269 for ($i=0; $i<$i1stBdL and $i < $iBdCnt; $i++) {
270 fwrite($FILE, pack(
"V", $iAll+$i));
274 for ($j = 0; $j < ($i1stBdL-$i); $j++) {
275 fwrite($FILE, (pack(
"V", -1)));
289 $FILE = $this->_FILEH_;
292 for ($i = 0; $i < count($raList); $i++)
296 $raList[$i]->Size = $raList[$i]->_DataLen();
301 if(isset($raList[$i]->_PPS_FILE))
304 fseek($raList[$i]->_PPS_FILE, 0);
305 while($sBuff = fread($raList[$i]->_PPS_FILE, 4096))
307 $iLen += strlen($sBuff);
308 fwrite($FILE, $sBuff);
312 fwrite($FILE, $raList[$i]->_data);
315 if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)
317 for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); $j++) {
318 fwrite($FILE,
"\x00");
322 $raList[$i]->_StartBlock = $iStBlk;
324 (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
325 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
328 if (isset($raList[$i]->_PPS_FILE))
330 @fclose($raList[$i]->_PPS_FILE);
331 $raList[$i]->_PPS_FILE = null;
332 @unlink($raList[$i]->_tmp_filename);
347 $FILE = $this->_FILEH_;
350 for ($i = 0; $i < count($raList); $i++)
355 if ($raList[$i]->Size <= 0) {
360 $iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
361 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
363 for ($j = 0; $j < ($iSmbCnt-1); $j++) {
364 fwrite($FILE, pack(
"V", $j+$iSmBlk+1));
366 fwrite($FILE, pack(
"V", -2));
369 if ($raList[$i]->_PPS_FILE)
371 fseek($raList[$i]->_PPS_FILE, 0);
372 while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
377 $sRes .= $raList[$i]->_data;
379 if($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)
381 for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); $j++) {
386 $raList[$i]->_StartBlock = $iSmBlk;
392 if($iSmBlk % $iSbCnt)
394 for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); $i++) {
395 fwrite($FILE, pack(
"V", -1));
410 for ($i = 0; $i < count($raList); $i++) {
411 fwrite($this->_FILEH_, $raList[$i]->
_getPpsWk());
414 $iCnt = count($raList);
418 for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) *
OLE_PPS_SIZE); $i++) {
419 fwrite($this->_FILEH_,
"\x00");
434 $FILE = $this->_FILEH_;
440 $iAll = $iBsize + $iPpsCnt + $iSbdSize;
442 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
443 $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
445 if ($iBdCnt >$i1stBdL)
451 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
452 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
453 if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
463 for ($i = 0; $i<($iSbdSize-1); $i++) {
464 fwrite($FILE, pack(
"V", $i+1));
466 fwrite($FILE, pack(
"V", -2));
469 for ($i = 0; $i<($iBsize-1); $i++) {
470 fwrite($FILE, pack(
"V", $i+$iSbdSize+1));
472 fwrite($FILE, pack(
"V", -2));
475 for ($i = 0; $i<($iPpsCnt-1); $i++) {
476 fwrite($FILE, pack(
"V", $i+$iSbdSize+$iBsize+1));
478 fwrite($FILE, pack(
"V", -2));
480 for ($i=0; $i<$iBdCnt;$i++) {
481 fwrite($FILE, pack(
"V", 0xFFFFFFFD));
484 for ($i=0; $i<$iBdExL;$i++) {
485 fwrite($FILE, pack(
"V", 0xFFFFFFFC));
488 if (($iAllW + $iBdCnt) % $iBbCnt)
490 for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); $i++) {
491 fwrite($FILE, pack(
"V", -1));
495 if ($iBdCnt > $i1stBdL)
499 for ($i=$i1stBdL;$i<$iBdCnt; $i++, $iN++)
501 if ($iN>=($iBbCnt-1))
505 fwrite($FILE, pack(
"V", $iAll+$iBdCnt+$iNb));
507 fwrite($FILE, pack(
"V", $iBsize+$iSbdSize+$iPpsCnt+$i));
509 if (($iBdCnt-$i1stBdL) % ($iBbCnt-1))
511 for ($i = 0; $i < (($iBbCnt-1) - (($iBdCnt-$i1stBdL) % ($iBbCnt-1))); $i++) {
512 fwrite($FILE, pack(
"V", -1));
515 fwrite($FILE, pack(
"V", -2));