Subversion Repositories eFlore/Applications.cel

Rev

Rev 3473 | Details | Compare with Previous | Last modification | View Log | RSS feed

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