14
14
* @copyright 2010-2018 PHPWord contributors
15
15
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
16
*/
17
+
17
18
namespace PhpOffice \PhpWord \Shared ;
18
19
19
20
use PhpOffice \PhpWord \Exception \Exception ;
@@ -29,40 +30,37 @@ class OLERead
29
30
const IDENTIFIER_OLE = IDENTIFIER_OLE ;
30
31
31
32
// Size of a sector = 512 bytes
32
- const BIG_BLOCK_SIZE = 0x200 ;
33
+ const BIG_BLOCK_SIZE = 0x200 ;
33
34
34
35
// Size of a short sector = 64 bytes
35
- const SMALL_BLOCK_SIZE = 0x40 ;
36
+ const SMALL_BLOCK_SIZE = 0x40 ;
36
37
37
38
// Size of a directory entry always = 128 bytes
38
- const PROPERTY_STORAGE_BLOCK_SIZE = 0x80 ;
39
+ const PROPERTY_STORAGE_BLOCK_SIZE = 0x80 ;
39
40
40
41
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
41
- const SMALL_BLOCK_THRESHOLD = 0x1000 ;
42
+ const SMALL_BLOCK_THRESHOLD = 0x1000 ;
42
43
43
44
// header offsets
44
- const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c ;
45
- const ROOT_START_BLOCK_POS = 0x30 ;
46
- const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c ;
47
- const EXTENSION_BLOCK_POS = 0x44 ;
48
- const NUM_EXTENSION_BLOCK_POS = 0x48 ;
49
- const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c ;
45
+ const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c ;
46
+ const ROOT_START_BLOCK_POS = 0x30 ;
47
+ const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c ;
48
+ const EXTENSION_BLOCK_POS = 0x44 ;
49
+ const NUM_EXTENSION_BLOCK_POS = 0x48 ;
50
+ const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c ;
50
51
51
52
// property storage offsets (directory offsets)
52
- const SIZE_OF_NAME_POS = 0x40 ;
53
- const TYPE_POS = 0x42 ;
54
- const START_BLOCK_POS = 0x74 ;
55
- const SIZE_POS = 0x78 ;
56
-
57
-
58
-
59
- public $ wrkdocument = null ;
60
- public $ wrk1Table = null ;
61
- public $ wrkData = null ;
62
- public $ wrkObjectPool = null ;
63
- public $ summaryInformation = null ;
64
- public $ docSummaryInfos = null ;
65
-
53
+ const SIZE_OF_NAME_POS = 0x40 ;
54
+ const TYPE_POS = 0x42 ;
55
+ const START_BLOCK_POS = 0x74 ;
56
+ const SIZE_POS = 0x78 ;
57
+
58
+ public $ wrkdocument = null ;
59
+ public $ wrk1Table = null ;
60
+ public $ wrkData = null ;
61
+ public $ wrkObjectPool = null ;
62
+ public $ summaryInformation = null ;
63
+ public $ docSummaryInfos = null ;
66
64
67
65
/**
68
66
* Read the file
@@ -75,7 +73,7 @@ public function read($sFileName)
75
73
{
76
74
// Check if file exists and is readable
77
75
if (!is_readable ($ sFileName )) {
78
- throw new Exception (" Could not open " . $ sFileName . " for reading! File does not exist, or it is not readable. " );
76
+ throw new Exception (' Could not open ' . $ sFileName . ' for reading! File does not exist, or it is not readable. ' );
79
77
}
80
78
81
79
// Get the file identifier
@@ -112,7 +110,7 @@ public function read($sFileName)
112
110
113
111
// @codeCoverageIgnoreStart
114
112
if ($ this ->numExtensionBlocks != 0 ) {
115
- $ bbdBlocks = (self ::BIG_BLOCK_SIZE - self ::BIG_BLOCK_DEPOT_BLOCKS_POS )/ 4 ;
113
+ $ bbdBlocks = (self ::BIG_BLOCK_SIZE - self ::BIG_BLOCK_DEPOT_BLOCKS_POS ) / 4 ;
116
114
}
117
115
// @codeCoverageIgnoreEnd
118
116
@@ -144,8 +142,8 @@ public function read($sFileName)
144
142
for ($ i = 0 ; $ i < $ this ->numBigBlockDepotBlocks ; ++$ i ) {
145
143
$ pos = ($ bigBlockDepotBlocks [$ i ] + 1 ) * self ::BIG_BLOCK_SIZE ;
146
144
147
- $ this ->bigBlockChain .= substr ($ this ->data , $ pos , 4 * $ bbs );
148
- $ pos += 4 * $ bbs ;
145
+ $ this ->bigBlockChain .= substr ($ this ->data , $ pos , 4 * $ bbs );
146
+ $ pos += 4 * $ bbs ;
149
147
}
150
148
151
149
$ pos = 0 ;
@@ -154,10 +152,10 @@ public function read($sFileName)
154
152
while ($ sbdBlock != -2 ) {
155
153
$ pos = ($ sbdBlock + 1 ) * self ::BIG_BLOCK_SIZE ;
156
154
157
- $ this ->smallBlockChain .= substr ($ this ->data , $ pos , 4 * $ bbs );
158
- $ pos += 4 * $ bbs ;
155
+ $ this ->smallBlockChain .= substr ($ this ->data , $ pos , 4 * $ bbs );
156
+ $ pos += 4 * $ bbs ;
159
157
160
- $ sbdBlock = self ::getInt4d ($ this ->bigBlockChain , $ sbdBlock* 4 );
158
+ $ sbdBlock = self ::getInt4d ($ this ->bigBlockChain , $ sbdBlock * 4 );
161
159
}
162
160
163
161
// read the directory stream
@@ -170,6 +168,7 @@ public function read($sFileName)
170
168
/**
171
169
* Extract binary stream data
172
170
*
171
+ * @param mixed $stream
173
172
* @return string
174
173
*/
175
174
public function getStream ($ stream )
@@ -189,7 +188,7 @@ public function getStream($stream)
189
188
$ pos = $ block * self ::SMALL_BLOCK_SIZE ;
190
189
$ streamData .= substr ($ rootdata , $ pos , self ::SMALL_BLOCK_SIZE );
191
190
192
- $ block = self ::getInt4d ($ this ->smallBlockChain , $ block* 4 );
191
+ $ block = self ::getInt4d ($ this ->smallBlockChain , $ block * 4 );
193
192
}
194
193
195
194
return $ streamData ;
@@ -201,15 +200,15 @@ public function getStream($stream)
201
200
}
202
201
203
202
if ($ numBlocks == 0 ) {
204
- return '' ;// @codeCoverageIgnore
203
+ return '' ; // @codeCoverageIgnore
205
204
}
206
205
207
206
$ block = $ this ->props [$ stream ]['startBlock ' ];
208
207
209
208
while ($ block != -2 ) {
210
209
$ pos = ($ block + 1 ) * self ::BIG_BLOCK_SIZE ;
211
210
$ streamData .= substr ($ this ->data , $ pos , self ::BIG_BLOCK_SIZE );
212
- $ block = self ::getInt4d ($ this ->bigBlockChain , $ block* 4 );
211
+ $ block = self ::getInt4d ($ this ->bigBlockChain , $ block * 4 );
213
212
}
214
213
215
214
return $ streamData ;
@@ -229,8 +228,9 @@ private function readData($blSectorId)
229
228
while ($ block != -2 ) {
230
229
$ pos = ($ block + 1 ) * self ::BIG_BLOCK_SIZE ;
231
230
$ data .= substr ($ this ->data , $ pos , self ::BIG_BLOCK_SIZE );
232
- $ block = self ::getInt4d ($ this ->bigBlockChain , $ block* 4 );
231
+ $ block = self ::getInt4d ($ this ->bigBlockChain , $ block * 4 );
233
232
}
233
+
234
234
return $ data ;
235
235
}
236
236
@@ -248,7 +248,7 @@ private function readPropertySets()
248
248
$ data = substr ($ this ->entry , $ offset , self ::PROPERTY_STORAGE_BLOCK_SIZE );
249
249
250
250
// size in bytes of name
251
- $ nameSize = ord ($ data [self ::SIZE_OF_NAME_POS ]) | (ord ($ data [self ::SIZE_OF_NAME_POS + 1 ]) << 8 );
251
+ $ nameSize = ord ($ data [self ::SIZE_OF_NAME_POS ]) | (ord ($ data [self ::SIZE_OF_NAME_POS + 1 ]) << 8 );
252
252
253
253
// type of entry
254
254
$ type = ord ($ data [self ::TYPE_POS ]);
@@ -259,14 +259,13 @@ private function readPropertySets()
259
259
260
260
$ size = self ::getInt4d ($ data , self ::SIZE_POS );
261
261
262
- $ name = str_replace ("\x00" , "" , substr ($ data , 0 , $ nameSize ));
262
+ $ name = str_replace ("\x00" , '' , substr ($ data , 0 , $ nameSize ));
263
263
264
-
265
- $ this ->props [] = array (
266
- 'name ' => $ name ,
267
- 'type ' => $ type ,
264
+ $ this ->props [] = array (
265
+ 'name ' => $ name ,
266
+ 'type ' => $ type ,
268
267
'startBlock ' => $ startBlock ,
269
- 'size ' => $ size );
268
+ 'size ' => $ size, );
270
269
271
270
// tmp helper to simplify checks
272
271
$ upName = strtoupper ($ name );
@@ -318,6 +317,7 @@ private static function getInt4d($data, $pos)
318
317
} else {
319
318
$ ord24 = ($ or24 & 127 ) << 24 ;
320
319
}
320
+
321
321
return ord ($ data [$ pos ]) | (ord ($ data [$ pos + 1 ]) << 8 ) | (ord ($ data [$ pos + 2 ]) << 16 ) | $ ord24 ;
322
322
}
323
323
}
0 commit comments