Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / pear / OLE / PPS.php
blob6ab48491ff5ddb354e463be1d682997720a9f621
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 // +----------------------------------------------------------------------+
20 // $Id$
23 require_once('PEAR.php');
24 require_once('OLE.php');
26 /**
27 * Class for creating PPS's for OLE containers
29 * @author Xavier Noguer <xnoguer@php.net>
30 * @category Structures
31 * @package OLE
33 class OLE_PPS extends PEAR
35 /**
36 * The PPS index
37 * @var integer
39 var $No;
41 /**
42 * The PPS name (in Unicode)
43 * @var string
45 var $Name;
47 /**
48 * The PPS type. Dir, Root or File
49 * @var integer
51 var $Type;
53 /**
54 * The index of the previous PPS
55 * @var integer
57 var $PrevPps;
59 /**
60 * The index of the next PPS
61 * @var integer
63 var $NextPps;
65 /**
66 * The index of it's first child if this is a Dir or Root PPS
67 * @var integer
69 var $DirPps;
71 /**
72 * A timestamp
73 * @var integer
75 var $Time1st;
77 /**
78 * A timestamp
79 * @var integer
81 var $Time2nd;
83 /**
84 * Starting block (small or big) for this PPS's data inside the container
85 * @var integer
87 var $_StartBlock;
89 /**
90 * The size of the PPS's data (in bytes)
91 * @var integer
93 var $Size;
95 /**
96 * The PPS's data (only used if it's not using a temporary file)
97 * @var string
99 var $_data;
102 * Array of child PPS's (only used by Root and Dir PPS's)
103 * @var array
105 var $children = array();
108 * The constructor
110 * @access public
111 * @param integer $No The PPS index
112 * @param string $name The PPS name (in Unicode)
113 * @param integer $type The PPS type. Dir, Root or File
114 * @param integer $prev The index of the previous PPS
115 * @param integer $next The index of the next PPS
116 * @param integer $dir The index of it's first child if this is a Dir or Root PPS
117 * @param integer $time_1st A timestamp
118 * @param integer $time_2nd A timestamp
119 * @param array $children Array containing children PPS for this PPS
121 function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
123 $this->No = $No;
124 $this->Name = $name;
125 $this->Type = $type;
126 $this->PrevPps = $prev;
127 $this->NextPps = $next;
128 $this->DirPps = $dir;
129 $this->Time1st = $time_1st;
130 $this->Time2nd = $time_2nd;
131 $this->_data = $data;
132 $this->children = $children;
133 if ($data != '') {
134 $this->Size = strlen($data);
136 else {
137 $this->Size = 0;
142 * Returns the amount of data saved for this PPS
144 * @access private
145 * @return integer The amount of data (in bytes)
147 function _DataLen()
149 if (!isset($this->_data)) {
150 return 0;
152 if (isset($this->_PPS_FILE))
154 fseek($this->_PPS_FILE, 0);
155 $stats = fstat($this->_PPS_FILE);
156 return $stats[7];
158 else {
159 return strlen($this->_data);
164 * Returns a string with the PPS's WK (What is a WK?)
166 * @access private
167 * @return string The binary string
169 function _getPpsWk()
171 $ret = $this->Name;
172 for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
173 $ret .= "\x00";
175 $ret .= pack("v", strlen($this->Name) + 2) // 66
176 . pack("c", $this->Type) // 67
177 . pack("c", 0x00) //UK // 68
178 . pack("V", $this->PrevPps) //Prev // 72
179 . pack("V", $this->NextPps) //Next // 76
180 . pack("V", $this->DirPps) //Dir // 80
181 . "\x00\x09\x02\x00" // 84
182 . "\x00\x00\x00\x00" // 88
183 . "\xc0\x00\x00\x00" // 92
184 . "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
185 . "\x00\x00\x00\x00" // 100
186 . OLE::LocalDate2OLE($this->Time1st) // 108
187 . OLE::LocalDate2OLE($this->Time2nd) // 116
188 . pack("V", isset($this->_StartBlock)?
189 $this->_StartBlock:0) // 120
190 . pack("V", $this->Size) // 124
191 . pack("V", 0); // 128
192 return $ret;
196 * Updates index and pointers to previous, next and children PPS's for this
197 * PPS. I don't think it'll work with Dir PPS's.
199 * @access private
200 * @param array &$pps_array Reference to the array of PPS's for the whole OLE
201 * container
202 * @return integer The index for this PPS
204 function _savePpsSetPnt(&$pps_array)
206 $pps_array[count($pps_array)] = &$this;
207 $this->No = count($pps_array) - 1;
208 $this->PrevPps = 0xFFFFFFFF;
209 $this->NextPps = 0xFFFFFFFF;
210 if (count($this->children) > 0) {
211 $this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
213 else {
214 $this->DirPps = 0xFFFFFFFF;
216 return $this->No;