23require_once
'OLE/PPS.php';
24require_once
'System.php';
74 $this->_tmp_dir = $dir;
92 $this->_BIG_BLOCK_SIZE = pow(2,
93 ((isset($this->_BIG_BLOCK_SIZE))? $this->
_adjust2($this->_BIG_BLOCK_SIZE) : 9));
94 $this->_SMALL_BLOCK_SIZE= pow(2,
95 ((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.");
105 $this->_FILEH_ = @fopen(
$filename,
"wb");
106 if ($this->_FILEH_ ==
false) {
107 return $this->
raiseError(
"Can't open $filename. It may be in use or protected.");
114 list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->
_calcSize($aList);
126 $this->
_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
129 fseek($this->_FILEH_, 0);
130 fpassthru($this->_FILEH_);
131 @fclose($this->_FILEH_);
133 @unlink($this->_tmp_filename);
135 @fclose($this->_FILEH_);
151 list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
154 for ($i = 0; $i < count($raList); $i++) {
156 $raList[$i]->Size = $raList[$i]->_DataLen();
158 $iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
159 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
161 $iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
162 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
166 $iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
168 $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
169 $iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
170 (( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
171 $iCnt = count($raList);
173 $iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
175 return array($iSBDcnt, $iBBcnt, $iPPScnt);
188 $iWk = log($i2)/log(2);
189 return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
202 $FILE = $this->_FILEH_;
209 $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
211 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
212 $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
215 if ($iBdCnt > $i1stBdL) {
219 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
220 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
221 if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
229 "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
243 . pack(
"V", $iBBcnt+$iSBDcnt)
250 if ($iBdCnt < $i1stBdL) {
256 fwrite($FILE, pack(
"V", $iAll+$iBdCnt) . pack(
"V", $iBdExL));
260 for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; $i++) {
261 fwrite($FILE, pack(
"V", $iAll+$i));
264 for ($j = 0; $j < ($i1stBdL-$i); $j++) {
265 fwrite($FILE, (pack(
"V", -1)));
279 $FILE = $this->_FILEH_;
282 for ($i = 0; $i < count($raList); $i++) {
284 $raList[$i]->Size = $raList[$i]->_DataLen();
289 if (isset($raList[$i]->_PPS_FILE)) {
291 fseek($raList[$i]->_PPS_FILE, 0);
292 while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
293 $iLen += strlen($sBuff);
294 fwrite($FILE, $sBuff);
297 fwrite($FILE, $raList[$i]->_data);
300 if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
301 for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); $j++) {
302 fwrite($FILE,
"\x00");
306 $raList[$i]->_StartBlock = $iStBlk;
308 (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
309 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
312 if (isset($raList[$i]->_PPS_FILE)) {
313 @fclose($raList[$i]->_PPS_FILE);
314 $raList[$i]->_PPS_FILE =
null;
315 @unlink($raList[$i]->_tmp_filename);
330 $FILE = $this->_FILEH_;
333 for ($i = 0; $i < count($raList); $i++) {
336 if ($raList[$i]->Size <= 0) {
340 $iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
341 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
343 for ($j = 0; $j < ($iSmbCnt-1); $j++) {
344 fwrite($FILE, pack(
"V", $j+$iSmBlk+1));
346 fwrite($FILE, pack(
"V", -2));
349 if ($raList[$i]->_PPS_FILE) {
350 fseek($raList[$i]->_PPS_FILE, 0);
351 while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
355 $sRes .= $raList[$i]->_data;
357 if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
358 for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); $j++) {
363 $raList[$i]->_StartBlock = $iSmBlk;
369 if ($iSmBlk % $iSbCnt) {
370 for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); $i++) {
371 fwrite($FILE, pack(
"V", -1));
386 for ($i = 0; $i < count($raList); $i++) {
387 fwrite($this->_FILEH_, $raList[$i]->
_getPpsWk());
390 $iCnt = count($raList);
392 if ($iCnt % $iBCnt) {
393 for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) *
OLE_PPS_SIZE); $i++) {
394 fwrite($this->_FILEH_,
"\x00");
409 $FILE = $this->_FILEH_;
415 $iAll = $iBsize + $iPpsCnt + $iSbdSize;
417 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
418 $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
420 if ($iBdCnt >$i1stBdL) {
424 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
425 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
426 if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
435 for ($i = 0; $i < ($iSbdSize - 1); $i++) {
436 fwrite($FILE, pack(
"V", $i+1));
438 fwrite($FILE, pack(
"V", -2));
441 for ($i = 0; $i < ($iBsize - 1); $i++) {
442 fwrite($FILE, pack(
"V", $i+$iSbdSize+1));
444 fwrite($FILE, pack(
"V", -2));
447 for ($i = 0; $i < ($iPpsCnt - 1); $i++) {
448 fwrite($FILE, pack(
"V", $i+$iSbdSize+$iBsize+1));
450 fwrite($FILE, pack(
"V", -2));
452 for ($i = 0; $i < $iBdCnt; $i++) {
453 fwrite($FILE, pack(
"V", 0xFFFFFFFD));
456 for ($i = 0; $i < $iBdExL; $i++) {
457 fwrite($FILE, pack(
"V", 0xFFFFFFFC));
460 if (($iAllW + $iBdCnt) % $iBbCnt) {
461 for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); $i++) {
462 fwrite($FILE, pack(
"V", -1));
466 if ($iBdCnt > $i1stBdL) {
469 for ($i = $i1stBdL;$i < $iBdCnt; $i++, $iN++) {
470 if ($iN >= ($iBbCnt - 1)) {
473 fwrite($FILE, pack(
"V", $iAll+$iBdCnt+$iNb));
475 fwrite($FILE, pack(
"V", $iBsize+$iSbdSize+$iPpsCnt+$i));
477 if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) {
478 for ($i = 0; $i < (($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1))); $i++) {
479 fwrite($FILE, pack(
"V", -1));
482 fwrite($FILE, pack(
"V", -2));
const OLE_PPS_TYPE_ROOT
Constants for OLE package.
const OLE_DATA_SIZE_SMALL
_calcSize(&$raList)
Calculate some numbers.
setTempDir($dir)
Sets the temp dir used for storing the OLE file.
_savePps(&$raList)
Saves all the PPS's WKs.
_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
Save OLE header.
_saveBbd($iSbdSize, $iBsize, $iPpsCnt)
Saving Big Block Depot.
_adjust2($i2)
Helper function for caculating a magic value for block sizes.
save($filename)
Method for saving the whole OLE container (including files).
_makeSmallData(&$raList)
get small data (PPS's with data smaller than OLE_DATA_SIZE_SMALL)
_saveBigData($iStBlk, &$raList)
Saving big data (PPS's with data bigger than OLE_DATA_SIZE_SMALL)
OLE_PPS_Root($time_1st, $time_2nd, $raChild)
Constructor.
_savePpsSetPnt(&$pps_array)
Updates index and pointers to previous, next and children PPS's for this PPS.
OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
The constructor.
_getPpsWk()
Returns a string with the PPS's WK (What is a WK?)
Asc2Ucs($ascii)
Utility function to transform ASCII text to Unicode.
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
tmpdir()
Get the path of the temporal directory set in the system by looking in its environments variables.