r81379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81378‎ | r81379 | r81380 >
Date:10:56, 2 February 2011
Author:questpc
Status:deferred
Tags:
Comment:
Spreadsheet writer now uses the latest PEAR classes available up to date
Modified paths:
  • /trunk/extensions/QPoll/Excel/Console_Getopt.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_BIFFwriter.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Format.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Parser.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Validator.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Workbook.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Worksheet.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/Excel_Writer.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/OLE.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/OLE_ChainedBlockStream.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/OLE_PPS.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/OLE_PPS_File.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/OLE_PPS_Root.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/PEAR.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/System.php (modified) (history)
  • /trunk/extensions/QPoll/Excel/patch.php (deleted) (history)
  • /trunk/extensions/QPoll/Excel/readme.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/Excel/patch.php
@@ -1,308 +0,0 @@
2 -<?php
3 - /**
4 - * Calculate
5 - * Handling of the SST continue blocks is complicated by the need to include an
6 - * additional continuation byte depending on whether the string is split between
7 - * blocks or whether it starts at the beginning of the block. (There are also
8 - * additional complications that will arise later when/if Rich Strings are
9 - * supported).
10 - *
11 - * @access private
12 - */
13 - function _calculateSharedStringsSizes()
14 - {
15 - /* Iterate through the strings to calculate the CONTINUE block sizes.
16 - For simplicity we use the same size for the SST and CONTINUE records:
17 - 8228 : Maximum Excel97 block size
18 - -4 : Length of block header
19 - -8 : Length of additional SST header information
20 - -8 : Arbitrary number to keep within _add_continue() limit
21 - = 8208
22 - */
23 - $continue_limit = 8208;
24 - $block_length = 0;
25 - $written = 0;
26 - $this->_block_sizes = array();
27 - $continue = 0;
28 -
29 - foreach (array_keys($this->_str_table) as $string) {
30 - $string_length = strlen($string);
31 - $headerinfo = unpack("vlength/Cencoding", $string);
32 - $encoding = $headerinfo["encoding"];
33 - $split_string = 0;
34 -
35 - // Block length is the total length of the strings that will be
36 - // written out in a single SST or CONTINUE block.
37 - $block_length += $string_length;
38 -
39 - // We can write the string if it doesn't cross a CONTINUE boundary
40 - if ($block_length < $continue_limit) {
41 - $written += $string_length;
42 - continue;
43 - }
44 -
45 - // Deal with the cases where the next string to be written will exceed
46 - // the CONTINUE boundary. If the string is very long it may need to be
47 - // written in more than one CONTINUE record.
48 - while ($block_length >= $continue_limit) {
49 -
50 - // We need to avoid the case where a string is continued in the first
51 - // n bytes that contain the string header information.
52 - $header_length = 3; // Min string + header size -1
53 - $space_remaining = $continue_limit - $written - $continue;
54 -
55 -
56 - /* TODO: Unicode data should only be split on char (2 byte)
57 - boundaries. Therefore, in some cases we need to reduce the
58 - amount of available
59 - */
60 - $align = 0;
61 -
62 - # Only applies to Unicode strings
63 - if ($encoding == 1) {
64 - # Min string + header size -1
65 - $header_length = 4;
66 -
67 - if ($space_remaining > $header_length) {
68 - # String contains 3 byte header => split on odd boundary
69 - if (!$split_string && $space_remaining % 2 != 1) {
70 - $space_remaining--;
71 - $align = 1;
72 - }
73 - # Split section without header => split on even boundary
74 - else if ($split_string && $space_remaining % 2 == 1) {
75 - $space_remaining--;
76 - $align = 1;
77 - }
78 -
79 - $split_string = 1;
80 - }
81 - }
82 -
83 -
84 - if ($space_remaining > $header_length) {
85 - // Write as much as possible of the string in the current block
86 - $written += $space_remaining;
87 -
88 - // Reduce the current block length by the amount written
89 - $block_length -= $continue_limit - $continue - $align;
90 -
91 - // Store the max size for this block
92 - $this->_block_sizes[] = $continue_limit - $align;
93 -
94 - // If the current string was split then the next CONTINUE block
95 - // should have the string continue flag (grbit) set unless the
96 - // split string fits exactly into the remaining space.
97 - if ($block_length > 0) {
98 - $continue = 1;
99 - } else {
100 - $continue = 0;
101 - }
102 - } else {
103 - // Store the max size for this block
104 - $this->_block_sizes[] = $written + $continue;
105 -
106 - // Not enough space to start the string in the current block
107 - $block_length -= $continue_limit - $space_remaining - $continue;
108 - $continue = 0;
109 -
110 - }
111 -
112 - // If the string (or substr) is small enough we can write it in the
113 - // new CONTINUE block. Else, go through the loop again to write it in
114 - // one or more CONTINUE blocks
115 - if ($block_length < $continue_limit) {
116 - $written = $block_length;
117 - } else {
118 - $written = 0;
119 - }
120 - }
121 - }
122 -
123 - // Store the max size for the last block unless it is empty
124 - if ($written + $continue) {
125 - $this->_block_sizes[] = $written + $continue;
126 - }
127 -
128 -
129 - /* Calculate the total length of the SST and associated CONTINUEs (if any).
130 - The SST record will have a length even if it contains no strings.
131 - This length is required to set the offsets in the BOUNDSHEET records since
132 - they must be written before the SST records
133 - */
134 -
135 - $tmp_block_sizes = array();
136 - $tmp_block_sizes = $this->_block_sizes;
137 -
138 - $length = 12;
139 - if (!empty($tmp_block_sizes)) {
140 - $length += array_shift($tmp_block_sizes); # SST
141 - }
142 - while (!empty($tmp_block_sizes)) {
143 - $length += 4 + array_shift($tmp_block_sizes); # CONTINUEs
144 - }
145 -
146 - return $length;
147 - }
148 -
149 - /**
150 - * Write all of the workbooks strings into an indexed array.
151 - * See the comments in _calculate_shared_string_sizes() for more information.
152 - *
153 - * The Excel documentation says that the SST record should be followed by an
154 - * EXTSST record. The EXTSST record is a hash table that is used to optimise
155 - * access to SST. However, despite the documentation it doesn't seem to be
156 - * required so we will ignore it.
157 - *
158 - * @access private
159 - */
160 - function _storeSharedStringsTable()
161 - {
162 - $record = 0x00fc; // Record identifier
163 - $length = 0x0008; // Number of bytes to follow
164 - $total = 0x0000;
165 -
166 - // Iterate through the strings to calculate the CONTINUE block sizes
167 - $continue_limit = 8208;
168 - $block_length = 0;
169 - $written = 0;
170 - $continue = 0;
171 -
172 - // sizes are upside down
173 - $tmp_block_sizes = $this->_block_sizes;
174 -// $tmp_block_sizes = array_reverse($this->_block_sizes);
175 -
176 - # The SST record is required even if it contains no strings. Thus we will
177 - # always have a length
178 - #
179 - if (!empty($tmp_block_sizes)) {
180 - $length = 8 + array_shift($tmp_block_sizes);
181 - }
182 - else {
183 - # No strings
184 - $length = 8;
185 - }
186 -
187 -
188 -
189 - // Write the SST block header information
190 - $header = pack("vv", $record, $length);
191 - $data = pack("VV", $this->_str_total, $this->_str_unique);
192 - $this->_append($header . $data);
193 -
194 -
195 -
196 -
197 - /* TODO: not good for performance */
198 - foreach (array_keys($this->_str_table) as $string) {
199 -
200 - $string_length = strlen($string);
201 - $headerinfo = unpack("vlength/Cencoding", $string);
202 - $encoding = $headerinfo["encoding"];
203 - $split_string = 0;
204 -
205 - // Block length is the total length of the strings that will be
206 - // written out in a single SST or CONTINUE block.
207 - //
208 - $block_length += $string_length;
209 -
210 -
211 - // We can write the string if it doesn't cross a CONTINUE boundary
212 - if ($block_length < $continue_limit) {
213 - $this->_append($string);
214 - $written += $string_length;
215 - continue;
216 - }
217 -
218 - // Deal with the cases where the next string to be written will exceed
219 - // the CONTINUE boundary. If the string is very long it may need to be
220 - // written in more than one CONTINUE record.
221 - //
222 - while ($block_length >= $continue_limit) {
223 -
224 - // We need to avoid the case where a string is continued in the first
225 - // n bytes that contain the string header information.
226 - //
227 - $header_length = 3; // Min string + header size -1
228 - $space_remaining = $continue_limit - $written - $continue;
229 -
230 -
231 - // Unicode data should only be split on char (2 byte) boundaries.
232 - // Therefore, in some cases we need to reduce the amount of available
233 - // space by 1 byte to ensure the correct alignment.
234 - $align = 0;
235 -
236 - // Only applies to Unicode strings
237 - if ($encoding == 1) {
238 - // Min string + header size -1
239 - $header_length = 4;
240 -
241 - if ($space_remaining > $header_length) {
242 - // String contains 3 byte header => split on odd boundary
243 - if (!$split_string && $space_remaining % 2 != 1) {
244 - $space_remaining--;
245 - $align = 1;
246 - }
247 - // Split section without header => split on even boundary
248 - else if ($split_string && $space_remaining % 2 == 1) {
249 - $space_remaining--;
250 - $align = 1;
251 - }
252 -
253 - $split_string = 1;
254 - }
255 - }
256 -
257 -
258 - if ($space_remaining > $header_length) {
259 - // Write as much as possible of the string in the current block
260 - $tmp = substr($string, 0, $space_remaining);
261 - $this->_append($tmp);
262 -
263 - // The remainder will be written in the next block(s)
264 - $string = substr($string, $space_remaining);
265 -
266 - // Reduce the current block length by the amount written
267 - $block_length -= $continue_limit - $continue - $align;
268 -
269 - // If the current string was split then the next CONTINUE block
270 - // should have the string continue flag (grbit) set unless the
271 - // split string fits exactly into the remaining space.
272 - //
273 - if ($block_length > 0) {
274 - $continue = 1;
275 - } else {
276 - $continue = 0;
277 - }
278 - } else {
279 - // Not enough space to start the string in the current block
280 - $block_length -= $continue_limit - $space_remaining - $continue;
281 - $continue = 0;
282 - }
283 -
284 - // Write the CONTINUE block header
285 - if (!empty($this->_block_sizes)) {
286 - $record = 0x003C;
287 - $length = array_shift($tmp_block_sizes);
288 -
289 - $header = pack('vv', $record, $length);
290 - if ($continue) {
291 - $header .= pack('C', $encoding);
292 - }
293 - $this->_append($header);
294 - }
295 -
296 - // If the string (or substr) is small enough we can write it in the
297 - // new CONTINUE block. Else, go through the loop again to write it in
298 - // one or more CONTINUE blocks
299 - //
300 - if ($block_length < $continue_limit) {
301 - $this->_append($string);
302 - $written = $block_length;
303 - } else {
304 - $written = 0;
305 - }
306 - }
307 - }
308 - }
309 -
\ No newline at end of file
Index: trunk/extensions/QPoll/Excel/Excel_Worksheet.php
@@ -364,13 +364,15 @@
365365 * @param mixed &$firstsheet The first worksheet in the workbook we belong to
366366 * @param mixed &$url_format The default format for hyperlinks
367367 * @param mixed &$parser The formula parser created for the Workbook
 368+ * @param string $tmp_dir The path to the directory for temporary files
368369 * @access private
369370 */
370371 function __construct($BIFF_version, $name,
371372 $index, &$activesheet,
372373 &$firstsheet, &$str_total,
373374 &$str_unique, &$str_table,
374 - &$url_format, &$parser)
 375+ &$url_format, &$parser,
 376+ $tmp_dir)
375377 {
376378 // It needs to call its parent's constructor explicitly
377379 parent::__construct();
@@ -461,6 +463,8 @@
462464
463465 $this->_dv = array();
464466
 467+ $this->_tmp_dir = $tmp_dir;
 468+
465469 $this->_initialize();
466470 }
467471
@@ -473,14 +477,32 @@
474478 */
475479 function _initialize()
476480 {
 481+ if ($this->_using_tmpfile == false) {
 482+ return;
 483+ }
 484+
 485+ if ($this->_tmp_dir === '' && ini_get('open_basedir') === false) {
 486+ // open_basedir restriction in effect - store data in memory
 487+ // ToDo: Let the error actually have an effect somewhere
 488+ $this->_using_tmpfile = false;
 489+ return new PEAR_Error('Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead');
 490+ }
 491+
477492 // Open tmp file for storing Worksheet data
478 - $fh = tmpfile();
479 - if ($fh) {
480 - // Store filehandle
481 - $this->_filehandle = $fh;
 493+ if ($this->_tmp_dir === '') {
 494+ $fh = tmpfile();
482495 } else {
 496+ // For people with open base dir restriction
 497+ $tmpfilename = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
 498+ $fh = @fopen($tmpfilename, "w+b");
 499+ }
 500+
 501+ if ($fh === false) {
483502 // If tmpfile() fails store data in memory
484503 $this->_using_tmpfile = false;
 504+ } else {
 505+ // Store filehandle
 506+ $this->_filehandle = $fh;
485507 }
486508 }
487509
@@ -1155,9 +1177,6 @@
11561178 } elseif (preg_match("/^=/", $token)) {
11571179 // Match formula
11581180 return $this->writeFormula($row, $col, $token, $format);
1159 - } elseif (preg_match("/^@/", $token)) {
1160 - // Match formula
1161 - return $this->writeFormula($row, $col, $token, $format);
11621181 } elseif ($token == '') {
11631182 // Match blank
11641183 return $this->writeBlank($row, $col, $format);
@@ -1319,15 +1338,17 @@
13201339 $row = $match[2];
13211340
13221341 // Convert base26 column string to number
1323 - $chars = split('', $col);
 1342+ // empty split / explode always equals to false and produces a warning
 1343+ //$chars = split('', $col);
13241344 $expn = 0;
13251345 $col = 0;
13261346
 1347+ /* equals to false
13271348 while ($chars) {
13281349 $char = array_pop($chars); // LS char first
13291350 $col += (ord($char) -ord('A') +1) * pow(26,$expn);
13301351 $expn++;
1331 - }
 1352+ } */
13321353
13331354 // Convert 1-index to zero-index
13341355 $row--;
@@ -2879,7 +2900,7 @@
28802901 $colcount = count($this->_colinfo);
28812902 for ($i = 0; $i < $colcount; $i++) {
28822903 // Skip cols without outline level info.
2883 - if (count($col_level) >= 6) {
 2904+ if (count($this->_colinfo[$i]) >= 6) {
28842905 $col_level = max($this->_colinfo[$i][5], $col_level);
28852906 }
28862907 }
@@ -3499,4 +3520,3 @@
35003521 }
35013522 }
35023523 }
3503 -?>
Index: trunk/extensions/QPoll/Excel/Excel_Writer.php
@@ -101,4 +101,3 @@
102102 return $chr1 . $chr2 . $row;
103103 }
104104 }
105 -?>
Index: trunk/extensions/QPoll/Excel/OLE_PPS_File.php
@@ -122,4 +122,3 @@
123123 $this->ole->getStream($this);
124124 }
125125 }
126 -?>
Index: trunk/extensions/QPoll/Excel/OLE_PPS.php
@@ -219,4 +219,3 @@
220220 return $this->No;
221221 }
222222 }
223 -?>
Index: trunk/extensions/QPoll/Excel/OLE_PPS_Root.php
@@ -483,4 +483,3 @@
484484 }
485485 }
486486 }
487 -?>
Index: trunk/extensions/QPoll/Excel/Excel_Validator.php
@@ -226,5 +226,3 @@
227227 //$this->_formula1 = ...;
228228 }
229229 }*/
230 -
231 -?>
Index: trunk/extensions/QPoll/Excel/Excel_Format.php
@@ -429,7 +429,7 @@
430430
431431 $header = pack("vv", $record, $length);
432432
433 - $rotation = 0x00;
 433+ $rotation = $this->_rotation;
434434 $biff8_options = 0x00;
435435 $data = pack("vvvC", $ifnt, $ifmt, $style, $align);
436436 $data .= pack("CCC", $rotation, $biff8_options, $used_attrib);
@@ -996,20 +996,32 @@
997997 $this->_rotation = 0;
998998 break;
999999 case 90:
 1000+ if ($this->_BIFF_version == 0x0500) {
10001001 $this->_rotation = 3;
 1002+ } elseif ($this->_BIFF_version == 0x0600) {
 1003+ $this->_rotation = 180;
 1004+ }
10011005 break;
10021006 case 270:
 1007+ if ($this->_BIFF_version == 0x0500) {
10031008 $this->_rotation = 2;
 1009+ } elseif ($this->_BIFF_version == 0x0600) {
 1010+ $this->_rotation = 90;
 1011+ }
10041012 break;
10051013 case -1:
 1014+ if ($this->_BIFF_version == 0x0500) {
10061015 $this->_rotation = 1;
 1016+ } elseif ($this->_BIFF_version == 0x0600) {
 1017+ $this->_rotation = 255;
 1018+ }
10071019 break;
10081020 default :
10091021 return $this->raiseError("Invalid value for angle.".
10101022 " Possible values are: 0, 90, 270 and -1 ".
10111023 "for stacking top-to-bottom.");
1012 - //$this->_rotation = 0;
1013 - //break;
 1024+ $this->_rotation = 0;
 1025+ break;
10141026 }
10151027 }
10161028
@@ -1099,4 +1111,3 @@
11001112 $this->_font_name = $font_family;
11011113 }
11021114 }
1103 -?>
Index: trunk/extensions/QPoll/Excel/Excel_Parser.php
@@ -92,6 +92,10 @@
9393 */
9494 define('SPREADSHEET_EXCEL_WRITER_NE', "<>");
9595
 96+/**
 97+* * @const SPREADSHEET_EXCEL_WRITER_CONCAT token identifier for character "&"
 98+*/
 99+define('SPREADSHEET_EXCEL_WRITER_CONCAT', "&");
96100
97101 require_once( qp_Setup::$ExtDir . '/Excel/PEAR.php' );
98102
@@ -663,15 +667,15 @@
664668 * @access private
665669 * @param string $range An Excel range in the A1:A2 or A1..A2 format.
666670 */
667 - function _convertRange2d($range)
 671+ function _convertRange2d($range, $class=0)
668672 {
669 - $class = 2; // as far as I know, this is magick.
670673
 674+ // TODO: possible class value 0,1,2 check Formula.pm
671675 // Split the range into 2 cell refs
672676 if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {
673 - list($cell1, $cell2) = split(':', $range);
 677+ list($cell1, $cell2) = explode(':', $range);
674678 } elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {
675 - list($cell1, $cell2) = split('\.\.', $range);
 679+ list($cell1, $cell2) = explode('..', $range);
676680
677681 } else {
678682 // TODO: use real error codes
@@ -717,7 +721,7 @@
718722 $class = 2; // as far as I know, this is magick.
719723
720724 // Split the ref at the ! symbol
721 - list($ext_ref, $range) = split('!', $token);
 725+ list($ext_ref, $range) = explode('!', $token);
722726
723727 // Convert the external reference part (different for BIFF8)
724728 if ($this->_BIFF_version == 0x0500) {
@@ -733,7 +737,7 @@
734738 }
735739
736740 // Split the range into 2 cell refs
737 - list($cell1, $cell2) = split(':', $range);
 741+ list($cell1, $cell2) = explode(':', $range);
738742
739743 // Convert the cell references
740744 if (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1)) {
@@ -814,7 +818,7 @@
815819 $class = 2; // as far as I know, this is magick.
816820
817821 // Split the ref at the ! symbol
818 - list($ext_ref, $cell) = split('!', $cell);
 822+ list($ext_ref, $cell) = explode('!', $cell);
819823
820824 // Convert the external reference part (different for BIFF8)
821825 if ($this->_BIFF_version == 0x0500) {
@@ -861,7 +865,7 @@
862866
863867 // Check if there is a sheet range eg., Sheet1:Sheet2.
864868 if (preg_match("/:/", $ext_ref)) {
865 - list($sheet_name1, $sheet_name2) = split(':', $ext_ref);
 869+ list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
866870
867871 $sheet1 = $this->_getSheetIndex($sheet_name1);
868872 if ($sheet1 == -1) {
@@ -907,7 +911,7 @@
908912
909913 // Check if there is a sheet range eg., Sheet1:Sheet2.
910914 if (preg_match("/:/", $ext_ref)) {
911 - list($sheet_name1, $sheet_name2) = split(':', $ext_ref);
 915+ list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
912916
913917 $sheet1 = $this->_getSheetIndex($sheet_name1);
914918 if ($sheet1 == -1) {
@@ -1203,10 +1207,13 @@
12041208 case SPREADSHEET_EXCEL_WRITER_NE:
12051209 return $token;
12061210 break;
 1211+ case SPREADSHEET_EXCEL_WRITER_CONCAT:
 1212+ return $token;
 1213+ break;
12071214 default:
12081215 // if it's a reference
12091216 if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and
1210 - !ereg("[0-9]",$this->_lookahead) and
 1217+ !preg_match("/[0-9]/",$this->_lookahead) and
12111218 ($this->_lookahead != ':') and ($this->_lookahead != '.') and
12121219 ($this->_lookahead != '!'))
12131220 {
@@ -1214,39 +1221,39 @@
12151222 }
12161223 // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1)
12171224 elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and
1218 - !ereg("[0-9]",$this->_lookahead) and
 1225+ !preg_match("/[0-9]/",$this->_lookahead) and
12191226 ($this->_lookahead != ':') and ($this->_lookahead != '.'))
12201227 {
12211228 return $token;
12221229 }
12231230 // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1)
12241231 elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and
1225 - !ereg("[0-9]",$this->_lookahead) and
 1232+ !preg_match("/[0-9]/",$this->_lookahead) and
12261233 ($this->_lookahead != ':') and ($this->_lookahead != '.'))
12271234 {
12281235 return $token;
12291236 }
12301237 // if it's a range (A1:A2)
12311238 elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
1232 - !ereg("[0-9]",$this->_lookahead))
 1239+ !preg_match("/[0-9]/",$this->_lookahead))
12331240 {
12341241 return $token;
12351242 }
12361243 // if it's a range (A1..A2)
12371244 elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
1238 - !ereg("[0-9]",$this->_lookahead))
 1245+ !preg_match("/[0-9]/",$this->_lookahead))
12391246 {
12401247 return $token;
12411248 }
12421249 // If it's an external range like Sheet1!A1 or Sheet1:Sheet2!A1:B2
12431250 elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and
1244 - !ereg("[0-9]",$this->_lookahead))
 1251+ !preg_match("/[0-9]/",$this->_lookahead))
12451252 {
12461253 return $token;
12471254 }
12481255 // If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2
12491256 elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and
1250 - !ereg("[0-9]",$this->_lookahead))
 1257+ !preg_match("/[0-9]/",$this->_lookahead))
12511258 {
12521259 return $token;
12531260 }
@@ -1258,12 +1265,12 @@
12591266 return $token;
12601267 }
12611268 // If it's a string (of maximum 255 characters)
1262 - elseif (ereg("^\"[^\"]{0,255}\"$",$token))
 1269+ elseif (preg_match("/^\"[^\"]{0,255}\"$/",$token))
12631270 {
12641271 return $token;
12651272 }
12661273 // if it's a function call
1267 - elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$token) and ($this->_lookahead == "("))
 1274+ elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "("))
12681275 {
12691276 return $token;
12701277 }
@@ -1347,7 +1354,14 @@
13481355 return $result2;
13491356 }
13501357 $result = $this->_createTree('ptgNE', $result, $result2);
 1358+ } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_CONCAT) {
 1359+ $this->_advance();
 1360+ $result2 = $this->_expression();
 1361+ if (PEAR::isError($result2)) {
 1362+ return $result2;
13511363 }
 1364+ $result = $this->_createTree('ptgConcat', $result, $result2);
 1365+ }
13521366 return $result;
13531367 }
13541368
@@ -1363,7 +1377,7 @@
13641378 function _expression()
13651379 {
13661380 // If it's a string return a string node
1367 - if (ereg("^\"[^\"]{0,255}\"$", $this->_current_token)) {
 1381+ if (preg_match("/^\"[^\"]{0,255}\"$/", $this->_current_token)) {
13681382 $result = $this->_createTree($this->_current_token, '', '');
13691383 $this->_advance();
13701384 return $result;
@@ -1521,7 +1535,7 @@
15221536 return $result;
15231537 }
15241538 // if it's a function call
1525 - elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$this->_current_token))
 1539+ elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token))
15261540 {
15271541 $result = $this->_func();
15281542 return $result;
@@ -1686,4 +1700,3 @@
16871701 return $polish;
16881702 }
16891703 }
1690 -?>
Index: trunk/extensions/QPoll/Excel/Excel_Workbook.php
@@ -160,12 +160,6 @@
161161 var $_country_code;
162162
163163 /**
164 - * The temporary dir for storing the OLE file
165 - * @var string
166 - */
167 - var $_tmp_dir;
168 -
169 - /**
170164 * number of bytes for sizeinfo of strings
171165 * @var integer
172166 */
@@ -207,7 +201,6 @@
208202 $this->_str_unique = 0;
209203 $this->_str_table = array();
210204 $this->_setPaletteXl97();
211 - $this->_tmp_dir = '';
212205 }
213206
214207 /**
@@ -276,6 +269,7 @@
277270 $this->_tmp_format->_BIFF_version = $version;
278271 $this->_url_format->_BIFF_version = $version;
279272 $this->_parser->_BIFF_version = $version;
 273+ $this->_codepage = 0x04B0;
280274
281275 $total_worksheets = count($this->_worksheets);
282276 // change version for all worksheets too
@@ -343,7 +337,7 @@
344338 $this->_activesheet, $this->_firstsheet,
345339 $this->_str_total, $this->_str_unique,
346340 $this->_str_table, $this->_url_format,
347 - $this->_parser);
 341+ $this->_parser, $this->_tmp_dir);
348342
349343 $this->_worksheets[$index] = &$worksheet; // Store ref for iterator
350344 $this->_sheetnames[$index] = $name; // Store EXTERNSHEET names
@@ -495,6 +489,10 @@
496490 */
497491 function _storeWorkbook()
498492 {
 493+ if (count($this->_worksheets) == 0) {
 494+ return true;
 495+ }
 496+
499497 // Ensure that at least one worksheet has been selected.
500498 if ($this->_activesheet == 0) {
501499 $this->_worksheets[0]->selected = 1;
@@ -560,22 +558,6 @@
561559 }
562560
563561 /**
564 - * Sets the temp dir used for storing the OLE file
565 - *
566 - * @access public
567 - * @param string $dir The dir to be used as temp dir
568 - * @return true if given dir is valid, false otherwise
569 - */
570 - function setTempDir($dir)
571 - {
572 - if (is_dir($dir)) {
573 - $this->_tmp_dir = $dir;
574 - return true;
575 - }
576 - return false;
577 - }
578 -
579 - /**
580562 * Store the workbook in an OLE container
581563 *
582564 * @access private
@@ -583,7 +565,11 @@
584566 */
585567 function _storeOLEFile()
586568 {
587 - $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
 569+ if($this->_BIFF_version == 0x0600) {
 570+ $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
 571+ } else {
 572+ $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
 573+ }
588574 if ($this->_tmp_dir != '') {
589575 $OLE->setTempDir($this->_tmp_dir);
590576 }
@@ -1311,8 +1297,7 @@
13121298 8228 : Maximum Excel97 block size
13131299 -4 : Length of block header
13141300 -8 : Length of additional SST header information
1315 - -8 : Arbitrary number to keep within _add_continue() limit
1316 - = 8208
 1301+ -8 : Arbitrary number to keep within _add_continue() limit = 8208
13171302 */
13181303 $continue_limit = 8208;
13191304 $block_length = 0;
@@ -1601,4 +1586,3 @@
16021587 }
16031588 }
16041589 }
1605 -?>
Index: trunk/extensions/QPoll/Excel/OLE.php
@@ -567,4 +567,3 @@
568568 return floor($big_date);
569569 }
570570 }
571 -?>
Index: trunk/extensions/QPoll/Excel/OLE_ChainedBlockStream.php
@@ -225,5 +225,3 @@
226226 // bool dir_rewinddir ( void )
227227 // bool dir_closedir ( void )
228228 }
229 -
230 -?>
Index: trunk/extensions/QPoll/Excel/Excel_BIFFwriter.php
@@ -85,6 +85,12 @@
8686 var $_limit;
8787
8888 /**
 89+ * The temporary dir for storing the OLE file
 90+ * @var string
 91+ */
 92+ var $_tmp_dir;
 93+
 94+ /**
8995 * Constructor
9096 *
9197 * @access public
@@ -95,6 +101,7 @@
96102 $this->_data = '';
97103 $this->_datasize = 0;
98104 $this->_limit = 2080;
 105+ $this->_tmp_dir = '';
99106 // Set the byte order
100107 $this->_setByteOrder();
101108 }
@@ -234,5 +241,21 @@
235242
236243 return $tmp;
237244 }
 245+
 246+ /**
 247+ * Sets the temp dir used for storing the OLE file
 248+ *
 249+ * @access public
 250+ * @param string $dir The dir to be used as temp dir
 251+ * @return true if given dir is valid, false otherwise
 252+ */
 253+ function setTempDir($dir)
 254+ {
 255+ if (is_dir($dir)) {
 256+ $this->_tmp_dir = $dir;
 257+ return true;
 258+ }
 259+ return false;
 260+ }
 261+
238262 }
239 -?>
Index: trunk/extensions/QPoll/Excel/Console_Getopt.php
@@ -1,32 +1,40 @@
22 <?php
33 /* vim: set expandtab tabstop=4 shiftwidth=4: */
4 -// +----------------------------------------------------------------------+
5 -// | PHP Version 5 |
6 -// +----------------------------------------------------------------------+
7 -// | Copyright (c) 1997-2004 The PHP Group |
8 -// +----------------------------------------------------------------------+
9 -// | This source file is subject to version 3.0 of the PHP license, |
10 -// | that is bundled with this package in the file LICENSE, and is |
11 -// | available through the world-wide-web at the following url: |
12 -// | http://www.php.net/license/3_0.txt. |
13 -// | If you did not receive a copy of the PHP license and are unable to |
14 -// | obtain it through the world-wide-web, please send a note to |
15 -// | license@php.net so we can mail you a copy immediately. |
16 -// +----------------------------------------------------------------------+
17 -// | Author: Andrei Zmievski <andrei@php.net> |
18 -// +----------------------------------------------------------------------+
19 -//
20 -// $Id: Getopt.php,v 1.4 2007/06/12 14:58:56 cellog Exp $
 4+/**
 5+ * PHP Version 5
 6+ *
 7+ * Copyright (c) 1997-2004 The PHP Group
 8+ *
 9+ * This source file is subject to version 3.0 of the PHP license,
 10+ * that is bundled with this package in the file LICENSE, and is
 11+ * available through the world-wide-web at the following url:
 12+ * http://www.php.net/license/3_0.txt.
 13+ * If you did not receive a copy of the PHP license and are unable to
 14+ * obtain it through the world-wide-web, please send a note to
 15+ * license@php.net so we can mail you a copy immediately.
 16+ *
 17+ * @category Console
 18+ * @package Console_Getopt
 19+ * @author Andrei Zmievski <andrei@php.net>
 20+ * @license http://www.php.net/license/3_0.txt PHP 3.0
 21+ * @version CVS: $Id: Getopt.php 306067 2010-12-08 00:13:31Z dufuz $
 22+ * @link http://pear.php.net/package/Console_Getopt
 23+ */
2124
2225 require_once( qp_Setup::$ExtDir . '/Excel/PEAR.php' );
2326
2427 /**
2528 * Command-line options parsing class.
2629 *
27 - * @author Andrei Zmievski <andrei@php.net>
28 - *
 30+ * @category Console
 31+ * @package Console_Getopt
 32+ * @author Andrei Zmievski <andrei@php.net>
 33+ * @license http://www.php.net/license/3_0.txt PHP 3.0
 34+ * @link http://pear.php.net/package/Console_Getopt
2935 */
30 -class Console_Getopt {
 36+class Console_Getopt
 37+{
 38+
3139 /**
3240 * Parses the command-line options.
3341 *
@@ -53,46 +61,61 @@
5462 *
5563 * Most of the semantics of this function are based on GNU getopt_long().
5664 *
57 - * @param array $args an array of command-line arguments
58 - * @param string $short_options specifies the list of allowed short options
59 - * @param array $long_options specifies the list of allowed long options
 65+ * @param array $args an array of command-line arguments
 66+ * @param string $short_options specifies the list of allowed short options
 67+ * @param array $long_options specifies the list of allowed long options
 68+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
6069 *
6170 * @return array two-element array containing the list of parsed options and
6271 * the non-option arguments
63 - *
6472 * @access public
65 - *
6673 */
67 - function getopt2($args, $short_options, $long_options = null)
 74+ function getopt2($args, $short_options, $long_options = null, $skip_unknown = false)
6875 {
69 - return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
 76+ return Console_Getopt::doGetopt(2, $args, $short_options, $long_options, $skip_unknown);
7077 }
7178
7279 /**
7380 * This function expects $args to start with the script name (POSIX-style).
7481 * Preserved for backwards compatibility.
 82+ *
 83+ * @param array $args an array of command-line arguments
 84+ * @param string $short_options specifies the list of allowed short options
 85+ * @param array $long_options specifies the list of allowed long options
 86+ *
7587 * @see getopt2()
76 - */
77 - function getopt($args, $short_options, $long_options = null)
 88+ * @return array two-element array containing the list of parsed options and
 89+ * the non-option arguments
 90+ */
 91+ function getopt($args, $short_options, $long_options = null, $skip_unknown = false)
7892 {
79 - return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
 93+ return Console_Getopt::doGetopt(1, $args, $short_options, $long_options, $skip_unknown);
8094 }
8195
8296 /**
8397 * The actual implementation of the argument parsing code.
 98+ *
 99+ * @param int $version Version to use
 100+ * @param array $args an array of command-line arguments
 101+ * @param string $short_options specifies the list of allowed short options
 102+ * @param array $long_options specifies the list of allowed long options
 103+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
 104+ *
 105+ * @return array
84106 */
85 - function doGetopt($version, $args, $short_options, $long_options = null)
 107+ function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
86108 {
87109 // in case you pass directly readPHPArgv() as the first arg
88110 if (PEAR::isError($args)) {
89111 return $args;
90112 }
 113+
91114 if (empty($args)) {
92115 return array(array(), array());
93116 }
94 - $opts = array();
95 - $non_opts = array();
96117
 118+ $non_opts = $opts = array();
 119+
97120 settype($args, 'array');
98121
99122 if ($long_options) {
@@ -111,7 +134,6 @@
112135
113136 reset($args);
114137 while (list($i, $arg) = each($args)) {
115 -
116138 /* The special element '--' means explicit end of
117139 options. Treat the rest of the arguments as non-options
118140 and end the loop. */
@@ -124,17 +146,27 @@
125147 $non_opts = array_merge($non_opts, array_slice($args, $i));
126148 break;
127149 } elseif (strlen($arg) > 1 && $arg{1} == '-') {
128 - $error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
129 - if (PEAR::isError($error))
 150+ $error = Console_Getopt::_parseLongOption(substr($arg, 2),
 151+ $long_options,
 152+ $opts,
 153+ $args,
 154+ $skip_unknown);
 155+ if (PEAR::isError($error)) {
130156 return $error;
 157+ }
131158 } elseif ($arg == '-') {
132159 // - is stdin
133160 $non_opts = array_merge($non_opts, array_slice($args, $i));
134161 break;
135162 } else {
136 - $error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
137 - if (PEAR::isError($error))
 163+ $error = Console_Getopt::_parseShortOption(substr($arg, 1),
 164+ $short_options,
 165+ $opts,
 166+ $args,
 167+ $skip_unknown);
 168+ if (PEAR::isError($error)) {
138169 return $error;
 170+ }
139171 }
140172 }
141173
@@ -142,19 +174,31 @@
143175 }
144176
145177 /**
 178+ * Parse short option
 179+ *
 180+ * @param string $arg Argument
 181+ * @param string[] $short_options Available short options
 182+ * @param string[][] &$opts
 183+ * @param string[] &$args
 184+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
 185+ *
146186 * @access private
147 - *
 187+ * @return void
148188 */
149 - function _parseShortOption($arg, $short_options, &$opts, &$args)
 189+ function _parseShortOption($arg, $short_options, &$opts, &$args, $skip_unknown)
150190 {
151191 for ($i = 0; $i < strlen($arg); $i++) {
152 - $opt = $arg{$i};
 192+ $opt = $arg{$i};
153193 $opt_arg = null;
154194
155195 /* Try to find the short option in the specifier string. */
156 - if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
157 - {
158 - return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
 196+ if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') {
 197+ if ($skip_unknown === true) {
 198+ break;
 199+ }
 200+
 201+ $msg = "Console_Getopt: unrecognized option -- $opt";
 202+ return PEAR::raiseError($msg);
159203 }
160204
161205 if (strlen($spec) > 1 && $spec{1} == ':') {
@@ -173,11 +217,14 @@
174218 break;
175219 } else if (list(, $opt_arg) = each($args)) {
176220 /* Else use the next argument. */;
177 - if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
178 - return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
 221+ if (Console_Getopt::_isShortOpt($opt_arg)
 222+ || Console_Getopt::_isLongOpt($opt_arg)) {
 223+ $msg = "option requires an argument --$opt";
 224+ return PEAR::raiseError("Console_Getopt:" . $msg);
179225 }
180226 } else {
181 - return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
 227+ $msg = "option requires an argument --$opt";
 228+ return PEAR::raiseError("Console_Getopt:" . $msg);
182229 }
183230 }
184231 }
@@ -187,36 +234,54 @@
188235 }
189236
190237 /**
 238+ * Checks if an argument is a short option
 239+ *
 240+ * @param string $arg Argument to check
 241+ *
191242 * @access private
192 - *
 243+ * @return bool
193244 */
194245 function _isShortOpt($arg)
195246 {
196 - return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
 247+ return strlen($arg) == 2 && $arg[0] == '-'
 248+ && preg_match('/[a-zA-Z]/', $arg[1]);
197249 }
198250
199251 /**
 252+ * Checks if an argument is a long option
 253+ *
 254+ * @param string $arg Argument to check
 255+ *
200256 * @access private
201 - *
 257+ * @return bool
202258 */
203259 function _isLongOpt($arg)
204260 {
205261 return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
206 - preg_match('/[a-zA-Z]+$/', substr($arg, 2));
 262+ preg_match('/[a-zA-Z]+$/', substr($arg, 2));
207263 }
208264
209265 /**
 266+ * Parse long option
 267+ *
 268+ * @param string $arg Argument
 269+ * @param string[] $long_options Available long options
 270+ * @param string[][] &$opts
 271+ * @param string[] &$args
 272+ *
210273 * @access private
211 - *
 274+ * @return void|PEAR_Error
212275 */
213 - function _parseLongOption($arg, $long_options, &$opts, &$args)
 276+ function _parseLongOption($arg, $long_options, &$opts, &$args, $skip_unknown)
214277 {
215278 @list($opt, $opt_arg) = explode('=', $arg, 2);
 279+
216280 $opt_len = strlen($opt);
217281
218282 for ($i = 0; $i < count($long_options); $i++) {
219283 $long_opt = $long_options[$i];
220284 $opt_start = substr($long_opt, 0, $opt_len);
 285+
221286 $long_opt_name = str_replace('=', '', $long_opt);
222287
223288 /* Option doesn't match. Go on to the next one. */
@@ -224,7 +289,7 @@
225290 continue;
226291 }
227292
228 - $opt_rest = substr($long_opt, $opt_len);
 293+ $opt_rest = substr($long_opt, $opt_len);
229294
230295 /* Check that the options uniquely matches one of the allowed
231296 options. */
@@ -233,12 +298,15 @@
234299 } else {
235300 $next_option_rest = '';
236301 }
 302+
237303 if ($opt_rest != '' && $opt{0} != '=' &&
238304 $i + 1 < count($long_options) &&
239305 $opt == substr($long_options[$i+1], 0, $opt_len) &&
240306 $next_option_rest != '' &&
241307 $next_option_rest{0} != '=') {
242 - return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
 308+
 309+ $msg = "Console_Getopt: option --$opt is ambiguous";
 310+ return PEAR::raiseError($msg);
243311 }
244312
245313 if (substr($long_opt, -1) == '=') {
@@ -246,37 +314,47 @@
247315 /* Long option requires an argument.
248316 Take the next argument if one wasn't specified. */;
249317 if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
250 - return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
 318+ $msg = "Console_Getopt: option requires an argument --$opt";
 319+ return PEAR::raiseError($msg);
251320 }
252 - if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
253 - return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
 321+
 322+ if (Console_Getopt::_isShortOpt($opt_arg)
 323+ || Console_Getopt::_isLongOpt($opt_arg)) {
 324+ $msg = "Console_Getopt: option requires an argument --$opt";
 325+ return PEAR::raiseError($msg);
254326 }
255327 }
256328 } else if ($opt_arg) {
257 - return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
 329+ $msg = "Console_Getopt: option --$opt doesn't allow an argument";
 330+ return PEAR::raiseError($msg);
258331 }
259332
260333 $opts[] = array('--' . $opt, $opt_arg);
261334 return;
262335 }
263336
 337+ if ($skip_unknown === true) {
 338+ return;
 339+ }
 340+
264341 return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
265342 }
266343
267344 /**
268 - * Safely read the $argv PHP array across different PHP configurations.
269 - * Will take care on register_globals and register_argc_argv ini directives
270 - *
271 - * @access public
272 - * @return mixed the $argv PHP array or PEAR error if not registered
273 - */
 345+ * Safely read the $argv PHP array across different PHP configurations.
 346+ * Will take care on register_globals and register_argc_argv ini directives
 347+ *
 348+ * @access public
 349+ * @return mixed the $argv PHP array or PEAR error if not registered
 350+ */
274351 function readPHPArgv()
275352 {
276353 global $argv;
277354 if (!is_array($argv)) {
278355 if (!@is_array($_SERVER['argv'])) {
279356 if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
280 - return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
 357+ $msg = "Could not read cmd args (register_argc_argv=Off?)";
 358+ return PEAR::raiseError("Console_Getopt: " . $msg);
281359 }
282360 return $GLOBALS['HTTP_SERVER_VARS']['argv'];
283361 }
@@ -285,6 +363,4 @@
286364 return $argv;
287365 }
288366
289 -}
290 -
291 -?>
 367+}
\ No newline at end of file
Index: trunk/extensions/QPoll/Excel/System.php
@@ -9,7 +9,7 @@
1010 * @author Tomas V.V.Cox <cox@idecnet.com>
1111 * @copyright 1997-2009 The Authors
1212 * @license http://opensource.org/licenses/bsd-license.php New BSD License
13 - * @version CVS: $Id: System.php,v 1.66 2009/02/24 23:52:56 dufuz Exp $
 13+ * @version CVS: $Id: System.php 276386 2009-02-24 23:52:56Z dufuz $
1414 * @link http://pear.php.net/package/PEAR
1515 * @since File available since Release 0.1
1616 */
@@ -51,7 +51,7 @@
5252 * @author Tomas V.V. Cox <cox@idecnet.com>
5353 * @copyright 1997-2006 The PHP Group
5454 * @license http://opensource.org/licenses/bsd-license.php New BSD License
55 -* @version Release: 1.8.1
 55+* @version Release: 1.9.1
5656 * @link http://pear.php.net/package/PEAR
5757 * @since Class available since Release 0.1
5858 * @static
Index: trunk/extensions/QPoll/Excel/readme.txt
@@ -2,25 +2,17 @@
33
44 Uses the following PEAR classes:
55
6 -PEAR-1.8.1.tgz
 6+PEAR-1.9.1.tgz
 7+Console_Getopt-1.3.0.tgz
78 OLE-1.0.0RC1.tgz
8 -Spreadsheet_Excel_Writer-0.9.1.tgz
 9+Spreadsheet_Excel_Writer-0.9.2.tgz
910
1011 Nested filename paths are replaced to longer filenames with underscores, because I find deep nesting unhandy.
1112 require_once() and include_once() calls are made relative from qp_Setup::$ExtDir extension's property.
1213
13 -Spreadsheet_Excel_Writer-0.9.1 has a bug related to UTF16-LE string cell data encoding.
14 -This bug can cause corruption of exported XLS files when non-ASCII set of codes
15 -(such as Cyrillic or Chinesse) are used in polls.
 14+2009-09-18: patch to Excel_Workbook.php
 15+Removed "& new" (create object by reference) because it is incompatible with future versions of PHP
1616
17 -The following path has been applied to 'Excel_Workbook.php' to fix this problem:
18 -http://blog.teatime.com.tw/post/1/111
 17+2010-12-19: tweaked for PHP 5.3 in E_STRICT mode
1918
20 -The patch still hasn't been merged into PEAR SVN (2009, april 27th ).
21 -Watch these bugreports for further information:
22 -http://pear.php.net/bugs/bug.php?id=1572
23 -http://pear.php.net/bugs/bug.php?id=2159
24 -
25 -18.09.2009: patch to Excel_Workbook.php
26 -Removed "& new" (create object by reference) because it is incompatible with future versions of PHP
27 -19.12.2010: tweaked for PHP 5.3 in E_STRICT mode
\ No newline at end of file
 19+2011-02-02: get rid of additional PHP 5.3 deprecations; upgrade classes to latest PEAR version
Index: trunk/extensions/QPoll/Excel/PEAR.php
@@ -12,9 +12,9 @@
1313 * @author Stig Bakken <ssb@php.net>
1414 * @author Tomas V.V.Cox <cox@idecnet.com>
1515 * @author Greg Beaver <cellog@php.net>
16 - * @copyright 1997-2009 The Authors
 16+ * @copyright 1997-2010 The Authors
1717 * @license http://opensource.org/licenses/bsd-license.php New BSD License
18 - * @version CVS: $Id: PEAR.php,v 1.112 2009/04/15 04:05:13 dufuz Exp $
 18+ * @version CVS: $Id: PEAR.php 299159 2010-05-08 22:32:52Z dufuz $
1919 * @link http://pear.php.net/package/PEAR
2020 * @since File available since Release 0.1
2121 */
@@ -78,7 +78,7 @@
7979 * @author Greg Beaver <cellog@php.net>
8080 * @copyright 1997-2006 The PHP Group
8181 * @license http://opensource.org/licenses/bsd-license.php New BSD License
82 - * @version Release: 1.8.1
 82+ * @version Release: 1.9.1
8383 * @link http://pear.php.net/package/PEAR
8484 * @see PEAR_Error
8585 * @since Class available since PHP 4.0.2
@@ -158,9 +158,11 @@
159159 if ($this->_debug) {
160160 print "PEAR constructor called, class=$classname\n";
161161 }
 162+
162163 if ($error_class !== null) {
163164 $this->_error_class = $error_class;
164165 }
 166+
165167 while ($classname && strcasecmp($classname, "pear")) {
166168 $destructor = "_$classname";
167169 if (method_exists($this, $destructor)) {
@@ -319,7 +321,6 @@
320322 *
321323 * @since PHP 4.0.5
322324 */
323 -
324325 function setErrorHandling($mode = null, $options = null)
325326 {
326327 if (isset($this) && is_a($this, 'PEAR')) {
@@ -382,7 +383,7 @@
383384 } else {
384385 array_push($this->_expected_errors, array($code));
385386 }
386 - return sizeof($this->_expected_errors);
 387+ return count($this->_expected_errors);
387388 }
388389
389390 // }}}
@@ -413,8 +414,7 @@
414415 function _checkDelExpect($error_code)
415416 {
416417 $deleted = false;
417 -
418 - foreach ($this->_expected_errors AS $key => $error_array) {
 418+ foreach ($this->_expected_errors as $key => $error_array) {
419419 if (in_array($error_code, $error_array)) {
420420 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
421421 $deleted = true;
@@ -425,6 +425,7 @@
426426 unset($this->_expected_errors[$key]);
427427 }
428428 }
 429+
429430 return $deleted;
430431 }
431432
@@ -444,24 +445,20 @@
445446 {
446447 $deleted = false;
447448 if ((is_array($error_code) && (0 != count($error_code)))) {
448 - // $error_code is a non-empty array here;
449 - // we walk through it trying to unset all
450 - // values
451 - foreach($error_code as $key => $error) {
452 - if ($this->_checkDelExpect($error)) {
453 - $deleted = true;
454 - } else {
455 - $deleted = false;
456 - }
 449+ // $error_code is a non-empty array here; we walk through it trying
 450+ // to unset all values
 451+ foreach ($error_code as $key => $error) {
 452+ $deleted = $this->_checkDelExpect($error) ? true : false;
457453 }
 454+
458455 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
459456 } elseif (!empty($error_code)) {
460457 // $error_code comes alone, trying to unset it
461458 if ($this->_checkDelExpect($error_code)) {
462459 return true;
463 - } else {
464 - return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
465 - }
 460+ }
 461+
 462+ return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
466463 }
467464
468465 // $error_code is empty
@@ -525,10 +522,16 @@
526523 $message = $message->getMessage();
527524 }
528525
529 - if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
 526+ if (
 527+ isset($this) &&
 528+ isset($this->_expected_errors) &&
 529+ count($this->_expected_errors) > 0 &&
 530+ count($exp = end($this->_expected_errors))
 531+ ) {
530532 if ($exp[0] == "*" ||
531533 (is_int(reset($exp)) && in_array($code, $exp)) ||
532 - (is_string(reset($exp)) && in_array($message, $exp))) {
 534+ (is_string(reset($exp)) && in_array($message, $exp))
 535+ ) {
533536 $mode = PEAR_ERROR_RETURN;
534537 }
535538 }
@@ -576,12 +579,19 @@
577580 * Simpler form of raiseError with fewer options. In most cases
578581 * message, code and userinfo are enough.
579582 *
580 - * @param string $message
 583+ * @param mixed $message a text error message or a PEAR error object
581584 *
 585+ * @param int $code a numeric error code (it is up to your class
 586+ * to define these if you want to use codes)
 587+ *
 588+ * @param string $userinfo If you need to pass along for example debug
 589+ * information, this parameter is meant for that.
 590+ *
 591+ * @access public
 592+ * @return object a PEAR error object
 593+ * @see PEAR::raiseError
582594 */
583 - function &throwError($message = null,
584 - $code = null,
585 - $userinfo = null)
 595+ function &throwError($message = null, $code = null, $userinfo = null)
586596 {
587597 if (isset($this) && is_a($this, 'PEAR')) {
588598 $a = &$this->raiseError($message, $code, null, null, $userinfo);
@@ -735,28 +745,32 @@
736746 */
737747 function loadExtension($ext)
738748 {
739 - if (!extension_loaded($ext)) {
740 - // if either returns true dl() will produce a FATAL error, stop that
741 - if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
742 - return false;
743 - }
 749+ if (extension_loaded($ext)) {
 750+ return true;
 751+ }
744752
745 - if (OS_WINDOWS) {
746 - $suffix = '.dll';
747 - } elseif (PHP_OS == 'HP-UX') {
748 - $suffix = '.sl';
749 - } elseif (PHP_OS == 'AIX') {
750 - $suffix = '.a';
751 - } elseif (PHP_OS == 'OSX') {
752 - $suffix = '.bundle';
753 - } else {
754 - $suffix = '.so';
755 - }
 753+ // if either returns true dl() will produce a FATAL error, stop that
 754+ if (
 755+ function_exists('dl') === false ||
 756+ ini_get('enable_dl') != 1 ||
 757+ ini_get('safe_mode') == 1
 758+ ) {
 759+ return false;
 760+ }
756761
757 - return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
 762+ if (OS_WINDOWS) {
 763+ $suffix = '.dll';
 764+ } elseif (PHP_OS == 'HP-UX') {
 765+ $suffix = '.sl';
 766+ } elseif (PHP_OS == 'AIX') {
 767+ $suffix = '.a';
 768+ } elseif (PHP_OS == 'OSX') {
 769+ $suffix = '.bundle';
 770+ } else {
 771+ $suffix = '.so';
758772 }
759773
760 - return true;
 774+ return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
761775 }
762776
763777 // }}}
@@ -803,7 +817,11 @@
804818 }
805819
806820 // Now call the shutdown functions
807 - if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
 821+ if (
 822+ isset($GLOBALS['_PEAR_shutdown_funcs']) &&
 823+ is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
 824+ !empty($GLOBALS['_PEAR_shutdown_funcs'])
 825+ ) {
808826 foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
809827 call_user_func_array($value[0], $value[1]);
810828 }
@@ -823,7 +841,7 @@
824842 * @author Gregory Beaver <cellog@php.net>
825843 * @copyright 1997-2006 The PHP Group
826844 * @license http://opensource.org/licenses/bsd-license.php New BSD License
827 - * @version Release: 1.8.1
 845+ * @version Release: 1.9.1
828846 * @link http://pear.php.net/manual/en/core.pear.pear-error.php
829847 * @see PEAR::raiseError(), PEAR::throwError()
830848 * @since Class available since PHP 4.0.2
@@ -886,6 +904,7 @@
887905 unset($this->backtrace[0]['object']);
888906 }
889907 }
 908+
890909 if ($mode & PEAR_ERROR_CALLBACK) {
891910 $this->level = E_USER_NOTICE;
892911 $this->callback = $options;
@@ -896,6 +915,7 @@
897916 $this->level = $options;
898917 $this->callback = null;
899918 }
 919+
900920 if ($this->mode & PEAR_ERROR_PRINT) {
901921 if (is_null($options) || is_int($options)) {
902922 $format = "%s";
@@ -904,9 +924,11 @@
905925 }
906926 printf($format, $this->getMessage());
907927 }
 928+
908929 if ($this->mode & PEAR_ERROR_TRIGGER) {
909930 trigger_error($this->getMessage(), $this->level);
910931 }
 932+
911933 if ($this->mode & PEAR_ERROR_DIE) {
912934 $msg = $this->getMessage();
913935 if (is_null($options) || is_int($options)) {
@@ -919,11 +941,11 @@
920942 }
921943 die(sprintf($format, $msg));
922944 }
923 - if ($this->mode & PEAR_ERROR_CALLBACK) {
924 - if (is_callable($this->callback)) {
925 - call_user_func($this->callback, $this);
926 - }
 945+
 946+ if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
 947+ call_user_func($this->callback, $this);
927948 }
 949+
928950 if ($this->mode & PEAR_ERROR_EXCEPTION) {
929951 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
930952 eval('$e = new Exception($this->message, $this->code);throw($e);');
@@ -939,7 +961,8 @@
940962 * @return int error mode
941963 * @access public
942964 */
943 - function getMode() {
 965+ function getMode()
 966+ {
944967 return $this->mode;
945968 }
946969
@@ -952,7 +975,8 @@
953976 * @return mixed callback function or object/method array
954977 * @access public
955978 */
956 - function getCallback() {
 979+ function getCallback()
 980+ {
957981 return $this->callback;
958982 }
959983
@@ -1077,7 +1101,8 @@
10781102 * @return string a string with an object summary
10791103 * @access public
10801104 */
1081 - function toString() {
 1105+ function toString()
 1106+ {
10821107 $modes = array();
10831108 $levels = array(E_USER_NOTICE => 'notice',
10841109 E_USER_WARNING => 'warning',

Status & tagging log