Revision 1289
Added by kweitzel almost 15 years ago
pclzip.lib.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
// -------------------------------------------------------------------------------- |
3 |
// PhpConcept Library - Zip Module 2.6
|
|
3 |
// PhpConcept Library - Zip Module 2.8.2
|
|
4 | 4 |
// -------------------------------------------------------------------------------- |
5 |
// License GNU/LGPL - Vincent Blavet - March 2006
|
|
5 |
// License GNU/LGPL - Vincent Blavet - August 2009
|
|
6 | 6 |
// http://www.phpconcept.net |
7 | 7 |
// -------------------------------------------------------------------------------- |
8 | 8 |
// |
... | ... | |
22 | 22 |
// The use of this software is at the risk of the user. |
23 | 23 |
// |
24 | 24 |
// -------------------------------------------------------------------------------- |
25 |
// $Id: pclzip.lib.php,v 1.47 2007/07/20 13:56:07 vblavet Exp $
|
|
25 |
// $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $
|
|
26 | 26 |
// -------------------------------------------------------------------------------- |
27 | 27 |
|
28 | 28 |
// ----- Constants |
... | ... | |
66 | 66 |
define( 'PCLZIP_TEMPORARY_DIR', '' ); |
67 | 67 |
} |
68 | 68 |
|
69 |
// ----- Optional threshold ratio for use of temporary files |
|
70 |
// Pclzip sense the size of the file to add/extract and decide to |
|
71 |
// use or not temporary file. The algorythm is looking for |
|
72 |
// memory_limit of PHP and apply a ratio. |
|
73 |
// threshold = memory_limit * ratio. |
|
74 |
// Recommended values are under 0.5. Default 0.47. |
|
75 |
// Samples : |
|
76 |
// define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
|
77 |
if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
|
78 |
define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
|
79 |
} |
|
80 |
|
|
69 | 81 |
// -------------------------------------------------------------------------------- |
70 | 82 |
// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** |
71 | 83 |
// -------------------------------------------------------------------------------- |
72 | 84 |
|
73 | 85 |
// ----- Global variables |
74 |
$g_pclzip_version = "2.6";
|
|
86 |
$g_pclzip_version = "2.8.2";
|
|
75 | 87 |
|
76 | 88 |
// ----- Error codes |
77 | 89 |
// -1 : Unable to open file in binary write mode |
... | ... | |
134 | 146 |
// which is not correctly supported by PHP ... |
135 | 147 |
//define( 'PCLZIP_OPT_CRYPT', 77018 ); |
136 | 148 |
define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
149 |
define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); |
|
150 |
define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias |
|
151 |
define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); |
|
152 |
define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias |
|
153 |
define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); |
|
154 |
define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias |
|
137 | 155 |
|
138 | 156 |
// ----- File description attributes |
139 | 157 |
define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
... | ... | |
196 | 214 |
// -------------------------------------------------------------------------------- |
197 | 215 |
function PclZip($p_zipname) |
198 | 216 |
{ |
199 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname"); |
|
200 | 217 |
|
201 | 218 |
// ----- Tests the zlib |
202 | 219 |
if (!function_exists('gzopen')) |
203 | 220 |
{ |
204 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing"); |
|
205 | 221 |
die('Abort '.basename(__FILE__).' : Missing zlib extensions'); |
206 | 222 |
} |
207 | 223 |
|
... | ... | |
211 | 227 |
$this->magic_quotes_status = -1; |
212 | 228 |
|
213 | 229 |
// ----- Return |
214 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); |
|
215 | 230 |
return; |
216 | 231 |
} |
217 | 232 |
// -------------------------------------------------------------------------------- |
... | ... | |
255 | 270 |
// -------------------------------------------------------------------------------- |
256 | 271 |
function create($p_filelist) |
257 | 272 |
{ |
258 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); |
|
259 | 273 |
$v_result=1; |
260 | 274 |
|
261 | 275 |
// ----- Reset the error handler |
... | ... | |
267 | 281 |
|
268 | 282 |
// ----- Look for variable options arguments |
269 | 283 |
$v_size = func_num_args(); |
270 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
|
271 | 284 |
|
272 | 285 |
// ----- Look for arguments |
273 | 286 |
if ($v_size > 1) { |
... | ... | |
280 | 293 |
|
281 | 294 |
// ----- Look for first arg |
282 | 295 |
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
283 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); |
|
284 | 296 |
|
285 | 297 |
// ----- Parse the options |
286 | 298 |
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
... | ... | |
290 | 302 |
PCLZIP_CB_PRE_ADD => 'optional', |
291 | 303 |
PCLZIP_CB_POST_ADD => 'optional', |
292 | 304 |
PCLZIP_OPT_NO_COMPRESSION => 'optional', |
293 |
PCLZIP_OPT_COMMENT => 'optional' |
|
305 |
PCLZIP_OPT_COMMENT => 'optional', |
|
306 |
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
307 |
PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
308 |
PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
294 | 309 |
//, PCLZIP_OPT_CRYPT => 'optional' |
295 | 310 |
)); |
296 | 311 |
if ($v_result != 1) { |
297 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
298 | 312 |
return 0; |
299 | 313 |
} |
300 | 314 |
} |
... | ... | |
303 | 317 |
// Here we need to support the first historic synopsis of the |
304 | 318 |
// method. |
305 | 319 |
else { |
306 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
|
307 | 320 |
|
308 | 321 |
// ----- Get the first argument |
309 | 322 |
$v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; |
... | ... | |
315 | 328 |
else if ($v_size > 2) { |
316 | 329 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
317 | 330 |
"Invalid number / type of arguments"); |
318 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
319 | 331 |
return 0; |
320 | 332 |
} |
321 | 333 |
} |
322 | 334 |
} |
335 |
|
|
336 |
// ----- Look for default option values |
|
337 |
$this->privOptionDefaultThreshold($v_options); |
|
323 | 338 |
|
324 | 339 |
// ----- Init |
325 | 340 |
$v_string_list = array(); |
... | ... | |
351 | 366 |
// ----- Invalid variable type for $p_filelist |
352 | 367 |
else { |
353 | 368 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
354 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
355 | 369 |
return 0; |
356 | 370 |
} |
357 | 371 |
|
... | ... | |
362 | 376 |
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
363 | 377 |
} |
364 | 378 |
else { |
365 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename"); |
|
366 | 379 |
} |
367 | 380 |
} |
368 | 381 |
} |
... | ... | |
382 | 395 |
$v_options, |
383 | 396 |
$v_supported_attributes); |
384 | 397 |
if ($v_result != 1) { |
385 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
386 | 398 |
return 0; |
387 | 399 |
} |
388 | 400 |
} |
... | ... | |
390 | 402 |
// ----- Expand the filelist (expand directories) |
391 | 403 |
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
392 | 404 |
if ($v_result != 1) { |
393 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
394 | 405 |
return 0; |
395 | 406 |
} |
396 | 407 |
|
397 | 408 |
// ----- Call the create fct |
398 | 409 |
$v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); |
399 | 410 |
if ($v_result != 1) { |
400 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
401 | 411 |
return 0; |
402 | 412 |
} |
403 | 413 |
|
404 | 414 |
// ----- Return |
405 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); |
|
406 | 415 |
return $p_result_list; |
407 | 416 |
} |
408 | 417 |
// -------------------------------------------------------------------------------- |
... | ... | |
444 | 453 |
// -------------------------------------------------------------------------------- |
445 | 454 |
function add($p_filelist) |
446 | 455 |
{ |
447 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); |
|
448 | 456 |
$v_result=1; |
449 | 457 |
|
450 | 458 |
// ----- Reset the error handler |
... | ... | |
456 | 464 |
|
457 | 465 |
// ----- Look for variable options arguments |
458 | 466 |
$v_size = func_num_args(); |
459 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
|
460 | 467 |
|
461 | 468 |
// ----- Look for arguments |
462 | 469 |
if ($v_size > 1) { |
... | ... | |
469 | 476 |
|
470 | 477 |
// ----- Look for first arg |
471 | 478 |
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
472 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); |
|
473 | 479 |
|
474 | 480 |
// ----- Parse the options |
475 | 481 |
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
... | ... | |
481 | 487 |
PCLZIP_OPT_NO_COMPRESSION => 'optional', |
482 | 488 |
PCLZIP_OPT_COMMENT => 'optional', |
483 | 489 |
PCLZIP_OPT_ADD_COMMENT => 'optional', |
484 |
PCLZIP_OPT_PREPEND_COMMENT => 'optional' |
|
490 |
PCLZIP_OPT_PREPEND_COMMENT => 'optional', |
|
491 |
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
492 |
PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
493 |
PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
485 | 494 |
//, PCLZIP_OPT_CRYPT => 'optional' |
486 | 495 |
)); |
487 | 496 |
if ($v_result != 1) { |
488 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
489 | 497 |
return 0; |
490 | 498 |
} |
491 | 499 |
} |
... | ... | |
494 | 502 |
// Here we need to support the first historic synopsis of the |
495 | 503 |
// method. |
496 | 504 |
else { |
497 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
|
498 | 505 |
|
499 | 506 |
// ----- Get the first argument |
500 | 507 |
$v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; |
... | ... | |
508 | 515 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
509 | 516 |
|
510 | 517 |
// ----- Return |
511 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
512 | 518 |
return 0; |
513 | 519 |
} |
514 | 520 |
} |
515 | 521 |
} |
516 | 522 |
|
523 |
// ----- Look for default option values |
|
524 |
$this->privOptionDefaultThreshold($v_options); |
|
525 |
|
|
517 | 526 |
// ----- Init |
518 | 527 |
$v_string_list = array(); |
519 | 528 |
$v_att_list = array(); |
... | ... | |
544 | 553 |
// ----- Invalid variable type for $p_filelist |
545 | 554 |
else { |
546 | 555 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
547 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
548 | 556 |
return 0; |
549 | 557 |
} |
550 | 558 |
|
... | ... | |
570 | 578 |
$v_options, |
571 | 579 |
$v_supported_attributes); |
572 | 580 |
if ($v_result != 1) { |
573 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
574 | 581 |
return 0; |
575 | 582 |
} |
576 | 583 |
} |
... | ... | |
578 | 585 |
// ----- Expand the filelist (expand directories) |
579 | 586 |
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
580 | 587 |
if ($v_result != 1) { |
581 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
582 | 588 |
return 0; |
583 | 589 |
} |
584 | 590 |
|
585 | 591 |
// ----- Call the create fct |
586 | 592 |
$v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); |
587 | 593 |
if ($v_result != 1) { |
588 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
589 | 594 |
return 0; |
590 | 595 |
} |
591 | 596 |
|
592 | 597 |
// ----- Return |
593 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); |
|
594 | 598 |
return $p_result_list; |
595 | 599 |
} |
596 | 600 |
// -------------------------------------------------------------------------------- |
... | ... | |
623 | 627 |
// write protected |
624 | 628 |
// newer_exist : the file was not extracted because a newer file exists |
625 | 629 |
// path_creation_fail : the file is not extracted because the folder |
626 |
// does not exists and can not be created
|
|
630 |
// does not exist and can not be created |
|
627 | 631 |
// write_error : the file was not extracted because there was a |
628 | 632 |
// error while writing the file |
629 | 633 |
// read_error : the file was not extracted because there was a error |
... | ... | |
638 | 642 |
// -------------------------------------------------------------------------------- |
639 | 643 |
function listContent() |
640 | 644 |
{ |
641 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', ""); |
|
642 | 645 |
$v_result=1; |
643 | 646 |
|
644 | 647 |
// ----- Reset the error handler |
... | ... | |
646 | 649 |
|
647 | 650 |
// ----- Check archive |
648 | 651 |
if (!$this->privCheckFormat()) { |
649 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
650 | 652 |
return(0); |
651 | 653 |
} |
652 | 654 |
|
... | ... | |
655 | 657 |
if (($v_result = $this->privList($p_list)) != 1) |
656 | 658 |
{ |
657 | 659 |
unset($p_list); |
658 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
|
659 | 660 |
return(0); |
660 | 661 |
} |
661 | 662 |
|
662 | 663 |
// ----- Return |
663 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); |
|
664 | 664 |
return $p_list; |
665 | 665 |
} |
666 | 666 |
// -------------------------------------------------------------------------------- |
... | ... | |
699 | 699 |
// -------------------------------------------------------------------------------- |
700 | 700 |
function extract() |
701 | 701 |
{ |
702 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", ""); |
|
703 | 702 |
$v_result=1; |
704 | 703 |
|
705 | 704 |
// ----- Reset the error handler |
... | ... | |
707 | 706 |
|
708 | 707 |
// ----- Check archive |
709 | 708 |
if (!$this->privCheckFormat()) { |
710 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
711 | 709 |
return(0); |
712 | 710 |
} |
713 | 711 |
|
... | ... | |
720 | 718 |
|
721 | 719 |
// ----- Look for variable options arguments |
722 | 720 |
$v_size = func_num_args(); |
723 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
|
724 | 721 |
|
725 | 722 |
// ----- Default values for option |
726 | 723 |
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
... | ... | |
732 | 729 |
|
733 | 730 |
// ----- Look for first arg |
734 | 731 |
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
735 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); |
|
736 | 732 |
|
737 | 733 |
// ----- Parse the options |
738 | 734 |
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
... | ... | |
751 | 747 |
PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
752 | 748 |
PCLZIP_OPT_REPLACE_NEWER => 'optional' |
753 | 749 |
,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
754 |
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' |
|
750 |
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
751 |
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
752 |
PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
753 |
PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
755 | 754 |
)); |
756 | 755 |
if ($v_result != 1) { |
757 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
758 | 756 |
return 0; |
759 | 757 |
} |
760 | 758 |
|
... | ... | |
781 | 779 |
// Here we need to support the first historic synopsis of the |
782 | 780 |
// method. |
783 | 781 |
else { |
784 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
|
785 | 782 |
|
786 | 783 |
// ----- Get the first argument |
787 | 784 |
$v_path = $v_arg_list[0]; |
... | ... | |
795 | 792 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
796 | 793 |
|
797 | 794 |
// ----- Return |
798 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
|
799 | 795 |
return 0; |
800 | 796 |
} |
801 | 797 |
} |
802 | 798 |
} |
803 | 799 |
|
800 |
// ----- Look for default option values |
|
801 |
$this->privOptionDefaultThreshold($v_options); |
|
802 |
|
|
804 | 803 |
// ----- Trace |
805 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); |
|
806 | 804 |
|
807 | 805 |
// ----- Call the extracting fct |
808 | 806 |
$p_list = array(); |
... | ... | |
810 | 808 |
$v_remove_all_path, $v_options); |
811 | 809 |
if ($v_result < 1) { |
812 | 810 |
unset($p_list); |
813 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
|
814 | 811 |
return(0); |
815 | 812 |
} |
816 | 813 |
|
817 | 814 |
// ----- Return |
818 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); |
|
819 | 815 |
return $p_list; |
820 | 816 |
} |
821 | 817 |
// -------------------------------------------------------------------------------- |
... | ... | |
860 | 856 |
//function extractByIndex($p_index, options...) |
861 | 857 |
function extractByIndex($p_index) |
862 | 858 |
{ |
863 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ..."); |
|
864 | 859 |
$v_result=1; |
865 | 860 |
|
866 | 861 |
// ----- Reset the error handler |
... | ... | |
868 | 863 |
|
869 | 864 |
// ----- Check archive |
870 | 865 |
if (!$this->privCheckFormat()) { |
871 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
872 | 866 |
return(0); |
873 | 867 |
} |
874 | 868 |
|
... | ... | |
881 | 875 |
|
882 | 876 |
// ----- Look for variable options arguments |
883 | 877 |
$v_size = func_num_args(); |
884 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
|
885 | 878 |
|
886 | 879 |
// ----- Default values for option |
887 | 880 |
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
... | ... | |
897 | 890 |
|
898 | 891 |
// ----- Look for first arg |
899 | 892 |
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
900 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); |
|
901 | 893 |
|
902 | 894 |
// ----- Parse the options |
903 | 895 |
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
... | ... | |
911 | 903 |
PCLZIP_OPT_SET_CHMOD => 'optional', |
912 | 904 |
PCLZIP_OPT_REPLACE_NEWER => 'optional' |
913 | 905 |
,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
914 |
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' |
|
906 |
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
907 |
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
908 |
PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
909 |
PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
915 | 910 |
)); |
916 | 911 |
if ($v_result != 1) { |
917 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
918 | 912 |
return 0; |
919 | 913 |
} |
920 | 914 |
|
... | ... | |
937 | 931 |
} |
938 | 932 |
if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
939 | 933 |
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
940 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set."); |
|
941 | 934 |
} |
942 | 935 |
else { |
943 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set."); |
|
944 | 936 |
} |
945 | 937 |
} |
946 | 938 |
|
... | ... | |
948 | 940 |
// Here we need to support the first historic synopsis of the |
949 | 941 |
// method. |
950 | 942 |
else { |
951 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
|
952 | 943 |
|
953 | 944 |
// ----- Get the first argument |
954 | 945 |
$v_path = $v_arg_list[0]; |
... | ... | |
962 | 953 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
963 | 954 |
|
964 | 955 |
// ----- Return |
965 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
966 | 956 |
return 0; |
967 | 957 |
} |
968 | 958 |
} |
969 | 959 |
} |
970 | 960 |
|
971 | 961 |
// ----- Trace |
972 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); |
|
973 | 962 |
|
974 | 963 |
// ----- Trick |
975 | 964 |
// Here I want to reuse extractByRule(), so I need to parse the $p_index |
... | ... | |
979 | 968 |
$v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
980 | 969 |
array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
981 | 970 |
if ($v_result != 1) { |
982 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
983 | 971 |
return 0; |
984 | 972 |
} |
985 | 973 |
$v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; |
986 | 974 |
|
975 |
// ----- Look for default option values |
|
976 |
$this->privOptionDefaultThreshold($v_options); |
|
977 |
|
|
987 | 978 |
// ----- Call the extracting fct |
988 | 979 |
if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { |
989 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
|
990 | 980 |
return(0); |
991 | 981 |
} |
992 | 982 |
|
993 | 983 |
// ----- Return |
994 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); |
|
995 | 984 |
return $p_list; |
996 | 985 |
} |
997 | 986 |
// -------------------------------------------------------------------------------- |
... | ... | |
1016 | 1005 |
// -------------------------------------------------------------------------------- |
1017 | 1006 |
function delete() |
1018 | 1007 |
{ |
1019 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", ""); |
|
1020 | 1008 |
$v_result=1; |
1021 | 1009 |
|
1022 | 1010 |
// ----- Reset the error handler |
... | ... | |
1024 | 1012 |
|
1025 | 1013 |
// ----- Check archive |
1026 | 1014 |
if (!$this->privCheckFormat()) { |
1027 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
1028 | 1015 |
return(0); |
1029 | 1016 |
} |
1030 | 1017 |
|
... | ... | |
1033 | 1020 |
|
1034 | 1021 |
// ----- Look for variable options arguments |
1035 | 1022 |
$v_size = func_num_args(); |
1036 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
|
1037 | 1023 |
|
1038 | 1024 |
// ----- Look for arguments |
1039 | 1025 |
if ($v_size > 0) { |
... | ... | |
1047 | 1033 |
PCLZIP_OPT_BY_PREG => 'optional', |
1048 | 1034 |
PCLZIP_OPT_BY_INDEX => 'optional' )); |
1049 | 1035 |
if ($v_result != 1) { |
1050 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
1051 | 1036 |
return 0; |
1052 | 1037 |
} |
1053 | 1038 |
} |
... | ... | |
1060 | 1045 |
if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { |
1061 | 1046 |
$this->privSwapBackMagicQuotes(); |
1062 | 1047 |
unset($v_list); |
1063 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
|
1064 | 1048 |
return(0); |
1065 | 1049 |
} |
1066 | 1050 |
|
... | ... | |
1068 | 1052 |
$this->privSwapBackMagicQuotes(); |
1069 | 1053 |
|
1070 | 1054 |
// ----- Return |
1071 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list); |
|
1072 | 1055 |
return $v_list; |
1073 | 1056 |
} |
1074 | 1057 |
// -------------------------------------------------------------------------------- |
... | ... | |
1081 | 1064 |
// -------------------------------------------------------------------------------- |
1082 | 1065 |
function deleteByIndex($p_index) |
1083 | 1066 |
{ |
1084 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); |
|
1085 | 1067 |
|
1086 | 1068 |
$p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
1087 | 1069 |
|
1088 | 1070 |
// ----- Return |
1089 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); |
|
1090 | 1071 |
return $p_list; |
1091 | 1072 |
} |
1092 | 1073 |
// -------------------------------------------------------------------------------- |
... | ... | |
1107 | 1088 |
// -------------------------------------------------------------------------------- |
1108 | 1089 |
function properties() |
1109 | 1090 |
{ |
1110 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", ""); |
|
1111 | 1091 |
|
1112 | 1092 |
// ----- Reset the error handler |
1113 | 1093 |
$this->privErrorReset(); |
... | ... | |
1118 | 1098 |
// ----- Check archive |
1119 | 1099 |
if (!$this->privCheckFormat()) { |
1120 | 1100 |
$this->privSwapBackMagicQuotes(); |
1121 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
1122 | 1101 |
return(0); |
1123 | 1102 |
} |
1124 | 1103 |
|
... | ... | |
1132 | 1111 |
if (@is_file($this->zipname)) |
1133 | 1112 |
{ |
1134 | 1113 |
// ----- Open the zip file |
1135 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
1136 | 1114 |
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
1137 | 1115 |
{ |
1138 | 1116 |
$this->privSwapBackMagicQuotes(); |
... | ... | |
1141 | 1119 |
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
1142 | 1120 |
|
1143 | 1121 |
// ----- Return |
1144 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0); |
|
1145 | 1122 |
return 0; |
1146 | 1123 |
} |
1147 | 1124 |
|
... | ... | |
1150 | 1127 |
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
1151 | 1128 |
{ |
1152 | 1129 |
$this->privSwapBackMagicQuotes(); |
1153 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
1154 | 1130 |
return 0; |
1155 | 1131 |
} |
1156 | 1132 |
|
... | ... | |
1167 | 1143 |
$this->privSwapBackMagicQuotes(); |
1168 | 1144 |
|
1169 | 1145 |
// ----- Return |
1170 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop); |
|
1171 | 1146 |
return $v_prop; |
1172 | 1147 |
} |
1173 | 1148 |
// -------------------------------------------------------------------------------- |
... | ... | |
1186 | 1161 |
// -------------------------------------------------------------------------------- |
1187 | 1162 |
function duplicate($p_archive) |
1188 | 1163 |
{ |
1189 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", ""); |
|
1190 | 1164 |
$v_result = 1; |
1191 | 1165 |
|
1192 | 1166 |
// ----- Reset the error handler |
... | ... | |
1195 | 1169 |
// ----- Look if the $p_archive is a PclZip object |
1196 | 1170 |
if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
1197 | 1171 |
{ |
1198 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'"); |
|
1199 | 1172 |
|
1200 | 1173 |
// ----- Duplicate the archive |
1201 | 1174 |
$v_result = $this->privDuplicate($p_archive->zipname); |
... | ... | |
1204 | 1177 |
// ----- Look if the $p_archive is a string (so a filename) |
1205 | 1178 |
else if (is_string($p_archive)) |
1206 | 1179 |
{ |
1207 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'"); |
|
1208 | 1180 |
|
1209 | 1181 |
// ----- Check that $p_archive is a valid zip file |
1210 | 1182 |
// TBC : Should also check the archive format |
... | ... | |
1228 | 1200 |
} |
1229 | 1201 |
|
1230 | 1202 |
// ----- Return |
1231 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
1232 | 1203 |
return $v_result; |
1233 | 1204 |
} |
1234 | 1205 |
// -------------------------------------------------------------------------------- |
... | ... | |
1249 | 1220 |
// -------------------------------------------------------------------------------- |
1250 | 1221 |
function merge($p_archive_to_add) |
1251 | 1222 |
{ |
1252 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", ""); |
|
1253 | 1223 |
$v_result = 1; |
1254 | 1224 |
|
1255 | 1225 |
// ----- Reset the error handler |
... | ... | |
1257 | 1227 |
|
1258 | 1228 |
// ----- Check archive |
1259 | 1229 |
if (!$this->privCheckFormat()) { |
1260 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
|
1261 | 1230 |
return(0); |
1262 | 1231 |
} |
1263 | 1232 |
|
1264 | 1233 |
// ----- Look if the $p_archive_to_add is a PclZip object |
1265 | 1234 |
if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
1266 | 1235 |
{ |
1267 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object"); |
|
1268 | 1236 |
|
1269 | 1237 |
// ----- Merge the archive |
1270 | 1238 |
$v_result = $this->privMerge($p_archive_to_add); |
... | ... | |
1273 | 1241 |
// ----- Look if the $p_archive_to_add is a string (so a filename) |
1274 | 1242 |
else if (is_string($p_archive_to_add)) |
1275 | 1243 |
{ |
1276 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename"); |
|
1277 | 1244 |
|
1278 | 1245 |
// ----- Create a temporary archive |
1279 | 1246 |
$v_object_archive = new PclZip($p_archive_to_add); |
... | ... | |
1291 | 1258 |
} |
1292 | 1259 |
|
1293 | 1260 |
// ----- Return |
1294 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
1295 | 1261 |
return $v_result; |
1296 | 1262 |
} |
1297 | 1263 |
// -------------------------------------------------------------------------------- |
... | ... | |
1406 | 1372 |
// -------------------------------------------------------------------------------- |
1407 | 1373 |
function privCheckFormat($p_level=0) |
1408 | 1374 |
{ |
1409 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", ""); |
|
1410 | 1375 |
$v_result = true; |
1411 | 1376 |
|
1412 | 1377 |
// ----- Reset the file system cache |
... | ... | |
1419 | 1384 |
if (!is_file($this->zipname)) { |
1420 | 1385 |
// ----- Error log |
1421 | 1386 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
1422 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); |
|
1423 | 1387 |
return(false); |
1424 | 1388 |
} |
1425 | 1389 |
|
... | ... | |
1427 | 1391 |
if (!is_readable($this->zipname)) { |
1428 | 1392 |
// ----- Error log |
1429 | 1393 |
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
1430 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); |
|
1431 | 1394 |
return(false); |
1432 | 1395 |
} |
1433 | 1396 |
|
... | ... | |
1441 | 1404 |
// TBC |
1442 | 1405 |
|
1443 | 1406 |
// ----- Return |
1444 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
1445 | 1407 |
return $v_result; |
1446 | 1408 |
} |
1447 | 1409 |
// -------------------------------------------------------------------------------- |
... | ... | |
1463 | 1425 |
// -------------------------------------------------------------------------------- |
1464 | 1426 |
function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
1465 | 1427 |
{ |
1466 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); |
|
1467 | 1428 |
$v_result=1; |
1468 | 1429 |
|
1469 | 1430 |
// ----- Read the options |
1470 | 1431 |
$i=0; |
1471 | 1432 |
while ($i<$p_size) { |
1472 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); |
|
1473 | 1433 |
|
1474 | 1434 |
// ----- Check if the option is supported |
1475 | 1435 |
if (!isset($v_requested_options[$p_options_list[$i]])) { |
... | ... | |
1477 | 1437 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
1478 | 1438 |
|
1479 | 1439 |
// ----- Return |
1480 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1481 | 1440 |
return PclZip::errorCode(); |
1482 | 1441 |
} |
1483 | 1442 |
|
... | ... | |
1493 | 1452 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1494 | 1453 |
|
1495 | 1454 |
// ----- Return |
1496 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1497 | 1455 |
return PclZip::errorCode(); |
1498 | 1456 |
} |
1499 | 1457 |
|
1500 | 1458 |
// ----- Get the value |
1501 | 1459 |
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1502 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1503 | 1460 |
$i++; |
1504 | 1461 |
break; |
1505 | 1462 |
|
1463 |
case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
|
1464 |
// ----- Check the number of parameters |
|
1465 |
if (($i+1) >= $p_size) { |
|
1466 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
1467 |
return PclZip::errorCode(); |
|
1468 |
} |
|
1469 |
|
|
1470 |
// ----- Check for incompatible options |
|
1471 |
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
1472 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
1473 |
return PclZip::errorCode(); |
|
1474 |
} |
|
1475 |
|
|
1476 |
// ----- Check the value |
|
1477 |
$v_value = $p_options_list[$i+1]; |
|
1478 |
if ((!is_integer($v_value)) || ($v_value<0)) { |
|
1479 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
1480 |
return PclZip::errorCode(); |
|
1481 |
} |
|
1482 |
|
|
1483 |
// ----- Get the value (and convert it in bytes) |
|
1484 |
$v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
1485 |
$i++; |
|
1486 |
break; |
|
1487 |
|
|
1488 |
case PCLZIP_OPT_TEMP_FILE_ON : |
|
1489 |
// ----- Check for incompatible options |
|
1490 |
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
1491 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
1492 |
return PclZip::errorCode(); |
|
1493 |
} |
|
1494 |
|
|
1495 |
$v_result_list[$p_options_list[$i]] = true; |
|
1496 |
break; |
|
1497 |
|
|
1498 |
case PCLZIP_OPT_TEMP_FILE_OFF : |
|
1499 |
// ----- Check for incompatible options |
|
1500 |
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
|
1501 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
|
1502 |
return PclZip::errorCode(); |
|
1503 |
} |
|
1504 |
// ----- Check for incompatible options |
|
1505 |
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
1506 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
|
1507 |
return PclZip::errorCode(); |
|
1508 |
} |
|
1509 |
|
|
1510 |
$v_result_list[$p_options_list[$i]] = true; |
|
1511 |
break; |
|
1512 |
|
|
1506 | 1513 |
case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
1507 | 1514 |
// ----- Check the number of parameters |
1508 | 1515 |
if (($i+1) >= $p_size) { |
... | ... | |
1510 | 1517 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1511 | 1518 |
|
1512 | 1519 |
// ----- Return |
1513 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1514 | 1520 |
return PclZip::errorCode(); |
1515 | 1521 |
} |
1516 | 1522 |
|
... | ... | |
1518 | 1524 |
if ( is_string($p_options_list[$i+1]) |
1519 | 1525 |
&& ($p_options_list[$i+1] != '')) { |
1520 | 1526 |
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1521 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1522 | 1527 |
$i++; |
1523 | 1528 |
} |
1524 | 1529 |
else { |
1525 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); |
|
1526 | 1530 |
} |
1527 | 1531 |
break; |
1528 | 1532 |
|
... | ... | |
1534 | 1538 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1535 | 1539 |
|
1536 | 1540 |
// ----- Return |
1537 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1538 | 1541 |
return PclZip::errorCode(); |
1539 | 1542 |
} |
1540 | 1543 |
|
... | ... | |
1550 | 1553 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1551 | 1554 |
|
1552 | 1555 |
// ----- Return |
1553 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1554 | 1556 |
return PclZip::errorCode(); |
1555 | 1557 |
} |
1556 |
////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1557 | 1558 |
$i++; |
1558 | 1559 |
break; |
1559 | 1560 |
|
1560 | 1561 |
// ----- Look for options that request an EREG or PREG expression |
1561 | 1562 |
case PCLZIP_OPT_BY_EREG : |
1563 |
// ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG |
|
1564 |
// to PCLZIP_OPT_BY_PREG |
|
1565 |
$p_options_list[$i] = PCLZIP_OPT_BY_PREG; |
|
1562 | 1566 |
case PCLZIP_OPT_BY_PREG : |
1563 | 1567 |
//case PCLZIP_OPT_CRYPT : |
1564 | 1568 |
// ----- Check the number of parameters |
... | ... | |
1567 | 1571 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1568 | 1572 |
|
1569 | 1573 |
// ----- Return |
1570 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1571 | 1574 |
return PclZip::errorCode(); |
1572 | 1575 |
} |
1573 | 1576 |
|
... | ... | |
1580 | 1583 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1581 | 1584 |
|
1582 | 1585 |
// ----- Return |
1583 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1584 | 1586 |
return PclZip::errorCode(); |
1585 | 1587 |
} |
1586 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1587 | 1588 |
$i++; |
1588 | 1589 |
break; |
1589 | 1590 |
|
... | ... | |
1600 | 1601 |
."'"); |
1601 | 1602 |
|
1602 | 1603 |
// ----- Return |
1603 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1604 | 1604 |
return PclZip::errorCode(); |
1605 | 1605 |
} |
1606 | 1606 |
|
... | ... | |
1616 | 1616 |
."'"); |
1617 | 1617 |
|
1618 | 1618 |
// ----- Return |
1619 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1620 | 1619 |
return PclZip::errorCode(); |
1621 | 1620 |
} |
1622 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1623 | 1621 |
$i++; |
1624 | 1622 |
break; |
1625 | 1623 |
|
... | ... | |
1631 | 1629 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1632 | 1630 |
|
1633 | 1631 |
// ----- Return |
1634 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1635 | 1632 |
return PclZip::errorCode(); |
1636 | 1633 |
} |
1637 | 1634 |
|
1638 | 1635 |
// ----- Get the value |
1639 | 1636 |
$v_work_list = array(); |
1640 | 1637 |
if (is_string($p_options_list[$i+1])) { |
1641 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); |
|
1642 | 1638 |
|
1643 | 1639 |
// ----- Remove spaces |
1644 | 1640 |
$p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
... | ... | |
1647 | 1643 |
$v_work_list = explode(",", $p_options_list[$i+1]); |
1648 | 1644 |
} |
1649 | 1645 |
else if (is_integer($p_options_list[$i+1])) { |
1650 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'"); |
|
1651 | 1646 |
$v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
1652 | 1647 |
} |
1653 | 1648 |
else if (is_array($p_options_list[$i+1])) { |
1654 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); |
|
1655 | 1649 |
$v_work_list = $p_options_list[$i+1]; |
1656 | 1650 |
} |
1657 | 1651 |
else { |
... | ... | |
1659 | 1653 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1660 | 1654 |
|
1661 | 1655 |
// ----- Return |
1662 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1663 | 1656 |
return PclZip::errorCode(); |
1664 | 1657 |
} |
1665 | 1658 |
|
... | ... | |
1693 | 1686 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1694 | 1687 |
|
1695 | 1688 |
// ----- Return |
1696 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1697 | 1689 |
return PclZip::errorCode(); |
1698 | 1690 |
} |
1699 | 1691 |
|
1700 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]"); |
|
1701 | 1692 |
|
1702 | 1693 |
// ----- Look for list sort |
1703 | 1694 |
if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
1704 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ..."); |
|
1705 | 1695 |
$v_sort_flag=true; |
1706 | 1696 |
|
1707 | 1697 |
// ----- TBC : An automatic sort should be writen ... |
... | ... | |
1709 | 1699 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1710 | 1700 |
|
1711 | 1701 |
// ----- Return |
1712 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1713 | 1702 |
return PclZip::errorCode(); |
1714 | 1703 |
} |
1715 | 1704 |
$v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
... | ... | |
1718 | 1707 |
// ----- Sort the items |
1719 | 1708 |
if ($v_sort_flag) { |
1720 | 1709 |
// TBC : To Be Completed |
1721 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ..."); |
|
1722 | 1710 |
} |
1723 | 1711 |
|
1724 | 1712 |
// ----- Next option |
... | ... | |
1733 | 1721 |
case PCLZIP_OPT_REPLACE_NEWER : |
1734 | 1722 |
case PCLZIP_OPT_STOP_ON_ERROR : |
1735 | 1723 |
$v_result_list[$p_options_list[$i]] = true; |
1736 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1737 | 1724 |
break; |
1738 | 1725 |
|
1739 | 1726 |
// ----- Look for options that request an octal value |
... | ... | |
1744 | 1731 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1745 | 1732 |
|
1746 | 1733 |
// ----- Return |
1747 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1748 | 1734 |
return PclZip::errorCode(); |
1749 | 1735 |
} |
1750 | 1736 |
|
1751 | 1737 |
// ----- Get the value |
1752 | 1738 |
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
1753 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1754 | 1739 |
$i++; |
1755 | 1740 |
break; |
1756 | 1741 |
|
... | ... | |
1771 | 1756 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1772 | 1757 |
|
1773 | 1758 |
// ----- Return |
1774 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1775 | 1759 |
return PclZip::errorCode(); |
1776 | 1760 |
} |
1777 | 1761 |
|
1778 | 1762 |
// ----- Get the value |
1779 | 1763 |
$v_function_name = $p_options_list[$i+1]; |
1780 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'"); |
|
1781 | 1764 |
|
1782 | 1765 |
// ----- Check that the value is a valid existing function |
1783 | 1766 |
if (!function_exists($v_function_name)) { |
... | ... | |
1785 | 1768 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1786 | 1769 |
|
1787 | 1770 |
// ----- Return |
1788 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1789 | 1771 |
return PclZip::errorCode(); |
1790 | 1772 |
} |
1791 | 1773 |
|
... | ... | |
1801 | 1783 |
.$p_options_list[$i]."'"); |
1802 | 1784 |
|
1803 | 1785 |
// ----- Return |
1804 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1805 | 1786 |
return PclZip::errorCode(); |
1806 | 1787 |
} |
1807 | 1788 |
|
... | ... | |
1814 | 1795 |
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
1815 | 1796 |
// ----- Look for mandatory option |
1816 | 1797 |
if ($v_requested_options[$key] == 'mandatory') { |
1817 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); |
|
1818 | 1798 |
// ----- Look if present |
1819 | 1799 |
if (!isset($v_result_list[$key])) { |
1820 | 1800 |
// ----- Error log |
1821 | 1801 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
1822 | 1802 |
|
1823 | 1803 |
// ----- Return |
1824 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1825 | 1804 |
return PclZip::errorCode(); |
1826 | 1805 |
} |
1827 | 1806 |
} |
1828 | 1807 |
} |
1829 | 1808 |
} |
1809 |
|
|
1810 |
// ----- Look for default values |
|
1811 |
if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
1812 |
|
|
1813 |
} |
|
1830 | 1814 |
|
1831 | 1815 |
// ----- Return |
1832 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
1833 | 1816 |
return $v_result; |
1834 | 1817 |
} |
1835 | 1818 |
// -------------------------------------------------------------------------------- |
1836 | 1819 |
|
1837 | 1820 |
// -------------------------------------------------------------------------------- |
1821 |
// Function : privOptionDefaultThreshold() |
|
1822 |
// Description : |
|
1823 |
// Parameters : |
|
1824 |
// Return Values : |
|
1825 |
// -------------------------------------------------------------------------------- |
|
1826 |
function privOptionDefaultThreshold(&$p_options) |
|
1827 |
{ |
|
1828 |
$v_result=1; |
|
1829 |
|
|
1830 |
if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
1831 |
|| isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
1832 |
return $v_result; |
|
1833 |
} |
|
1834 |
|
|
1835 |
// ----- Get 'memory_limit' configuration value |
|
1836 |
$v_memory_limit = ini_get('memory_limit'); |
|
1837 |
$v_memory_limit = trim($v_memory_limit); |
|
1838 |
$last = strtolower(substr($v_memory_limit, -1)); |
|
1839 |
|
|
1840 |
if($last == 'g') |
|
1841 |
//$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
1842 |
$v_memory_limit = $v_memory_limit*1073741824; |
|
1843 |
if($last == 'm') |
|
1844 |
//$v_memory_limit = $v_memory_limit*1024*1024; |
|
1845 |
$v_memory_limit = $v_memory_limit*1048576; |
|
1846 |
if($last == 'k') |
|
1847 |
$v_memory_limit = $v_memory_limit*1024; |
|
1848 |
|
|
1849 |
$p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
|
1850 |
|
|
1851 |
|
|
1852 |
// ----- Sanity check : No threshold if value lower than 1M |
|
1853 |
if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { |
|
1854 |
unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); |
|
1855 |
} |
|
1856 |
|
|
1857 |
// ----- Return |
|
1858 |
return $v_result; |
|
1859 |
} |
|
1860 |
// -------------------------------------------------------------------------------- |
|
1861 |
|
|
1862 |
// -------------------------------------------------------------------------------- |
|
1838 | 1863 |
// Function : privFileDescrParseAtt() |
1839 | 1864 |
// Description : |
1840 | 1865 |
// Parameters : |
... | ... | |
1844 | 1869 |
// -------------------------------------------------------------------------------- |
1845 | 1870 |
function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
1846 | 1871 |
{ |
1847 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); |
|
1848 | 1872 |
$v_result=1; |
1849 | 1873 |
|
1850 | 1874 |
// ----- For each file in the list check the attributes |
... | ... | |
1856 | 1880 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
1857 | 1881 |
|
1858 | 1882 |
// ----- Return |
1859 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1860 | 1883 |
return PclZip::errorCode(); |
1861 | 1884 |
} |
1862 | 1885 |
|
... | ... | |
1865 | 1888 |
case PCLZIP_ATT_FILE_NAME : |
1866 | 1889 |
if (!is_string($v_value)) { |
1867 | 1890 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1868 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1869 | 1891 |
return PclZip::errorCode(); |
1870 | 1892 |
} |
1871 | 1893 |
|
1872 | 1894 |
$p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
1873 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1874 | 1895 |
|
1875 | 1896 |
if ($p_filedescr['filename'] == '') { |
1876 | 1897 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1877 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1878 | 1898 |
return PclZip::errorCode(); |
1879 | 1899 |
} |
1880 | 1900 |
|
... | ... | |
1883 | 1903 |
case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
1884 | 1904 |
if (!is_string($v_value)) { |
1885 | 1905 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1886 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1887 | 1906 |
return PclZip::errorCode(); |
1888 | 1907 |
} |
1889 | 1908 |
|
1890 | 1909 |
$p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
1891 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1892 | 1910 |
|
1893 | 1911 |
if ($p_filedescr['new_short_name'] == '') { |
1894 | 1912 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1895 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1896 | 1913 |
return PclZip::errorCode(); |
1897 | 1914 |
} |
1898 | 1915 |
break; |
... | ... | |
1900 | 1917 |
case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
1901 | 1918 |
if (!is_string($v_value)) { |
1902 | 1919 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1903 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1904 | 1920 |
return PclZip::errorCode(); |
1905 | 1921 |
} |
1906 | 1922 |
|
1907 | 1923 |
$p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
1908 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1909 | 1924 |
|
1910 | 1925 |
if ($p_filedescr['new_full_name'] == '') { |
1911 | 1926 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1912 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1913 | 1927 |
return PclZip::errorCode(); |
1914 | 1928 |
} |
1915 | 1929 |
break; |
... | ... | |
1918 | 1932 |
case PCLZIP_ATT_FILE_COMMENT : |
1919 | 1933 |
if (!is_string($v_value)) { |
1920 | 1934 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1921 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1922 | 1935 |
return PclZip::errorCode(); |
1923 | 1936 |
} |
1924 | 1937 |
|
1925 | 1938 |
$p_filedescr['comment'] = $v_value; |
1926 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1927 | 1939 |
break; |
1928 | 1940 |
|
1929 | 1941 |
case PCLZIP_ATT_FILE_MTIME : |
1930 | 1942 |
if (!is_integer($v_value)) { |
1931 | 1943 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1932 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1933 | 1944 |
return PclZip::errorCode(); |
1934 | 1945 |
} |
1935 | 1946 |
|
1936 | 1947 |
$p_filedescr['mtime'] = $v_value; |
1937 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1938 | 1948 |
break; |
1939 | 1949 |
|
1940 | 1950 |
case PCLZIP_ATT_FILE_CONTENT : |
1941 | 1951 |
$p_filedescr['content'] = $v_value; |
1942 |
////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
1943 | 1952 |
break; |
1944 | 1953 |
|
1945 | 1954 |
default : |
... | ... | |
1948 | 1957 |
"Unknown parameter '".$v_key."'"); |
1949 | 1958 |
|
1950 | 1959 |
// ----- Return |
1951 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1952 | 1960 |
return PclZip::errorCode(); |
1953 | 1961 |
} |
1954 | 1962 |
|
... | ... | |
1957 | 1965 |
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
1958 | 1966 |
// ----- Look for mandatory option |
1959 | 1967 |
if ($v_requested_options[$key] == 'mandatory') { |
1960 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); |
|
1961 | 1968 |
// ----- Look if present |
1962 | 1969 |
if (!isset($p_file_list[$key])) { |
1963 | 1970 |
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
1964 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1965 | 1971 |
return PclZip::errorCode(); |
1966 | 1972 |
} |
1967 | 1973 |
} |
... | ... | |
1972 | 1978 |
} |
1973 | 1979 |
|
1974 | 1980 |
// ----- Return |
1975 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
1976 | 1981 |
return $v_result; |
1977 | 1982 |
} |
1978 | 1983 |
// -------------------------------------------------------------------------------- |
... | ... | |
1980 | 1985 |
// -------------------------------------------------------------------------------- |
1981 | 1986 |
// Function : privFileDescrExpand() |
1982 | 1987 |
// Description : |
1988 |
// This method look for each item of the list to see if its a file, a folder |
|
1989 |
// or a string to be added as file. For any other type of files (link, other) |
|
1990 |
// just ignore the item. |
|
1991 |
// Then prepare the information that will be stored for that file. |
|
1992 |
// When its a folder, expand the folder with all the files that are in that |
|
1993 |
// folder (recursively). |
|
1983 | 1994 |
// Parameters : |
1984 | 1995 |
// Return Values : |
1985 | 1996 |
// 1 on success. |
... | ... | |
1987 | 1998 |
// -------------------------------------------------------------------------------- |
1988 | 1999 |
function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
1989 | 2000 |
{ |
1990 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); |
|
1991 | 2001 |
$v_result=1; |
1992 | 2002 |
|
1993 | 2003 |
// ----- Create a result list |
... | ... | |
1995 | 2005 |
|
1996 | 2006 |
// ----- Look each entry |
1997 | 2007 |
for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
1998 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); |
|
1999 | 2008 |
|
2000 | 2009 |
// ----- Get filedescr |
2001 | 2010 |
$v_descr = $p_filedescr_list[$i]; |
2002 | 2011 |
|
2003 | 2012 |
// ----- Reduce the filename |
2004 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); |
|
2005 |
$v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']); |
|
2013 |
$v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
|
2006 | 2014 |
$v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
2007 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); |
|
2008 | 2015 |
|
2009 | 2016 |
// ----- Look for real file or folder |
2010 | 2017 |
if (file_exists($v_descr['filename'])) { |
2011 | 2018 |
if (@is_file($v_descr['filename'])) { |
2012 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); |
|
2013 | 2019 |
$v_descr['type'] = 'file'; |
2014 | 2020 |
} |
2015 | 2021 |
else if (@is_dir($v_descr['filename'])) { |
2016 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); |
|
2017 | 2022 |
$v_descr['type'] = 'folder'; |
2018 | 2023 |
} |
2019 | 2024 |
else if (@is_link($v_descr['filename'])) { |
2020 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); |
|
2021 | 2025 |
// skip |
2022 | 2026 |
continue; |
2023 | 2027 |
} |
2024 | 2028 |
else { |
2025 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); |
|
2026 | 2029 |
// skip |
2027 | 2030 |
continue; |
2028 | 2031 |
} |
... | ... | |
2030 | 2033 |
|
2031 | 2034 |
// ----- Look for string added as file |
2032 | 2035 |
else if (isset($v_descr['content'])) { |
2033 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file"); |
|
2034 | 2036 |
$v_descr['type'] = 'virtual_file'; |
2035 | 2037 |
} |
2036 | 2038 |
|
2037 | 2039 |
// ----- Missing file |
2038 | 2040 |
else { |
2039 | 2041 |
// ----- Error log |
2040 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists"); |
|
2041 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists"); |
|
2042 |
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
|
2042 | 2043 |
|
2043 | 2044 |
// ----- Return |
2044 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2045 | 2045 |
return PclZip::errorCode(); |
2046 | 2046 |
} |
2047 | 2047 |
|
... | ... | |
2058 | 2058 |
$v_dirlist_nb = 0; |
2059 | 2059 |
if ($v_folder_handler = @opendir($v_descr['filename'])) { |
2060 | 2060 |
while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
2061 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); |
|
2062 | 2061 |
|
2063 | 2062 |
// ----- Skip '.' and '..' |
2064 | 2063 |
if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
... | ... | |
2071 | 2070 |
// ----- Look for different stored filename |
2072 | 2071 |
// Because the name of the folder was changed, the name of the |
2073 | 2072 |
// files/sub-folders also change |
2074 |
if ($v_descr['stored_filename'] != $v_descr['filename']) { |
|
2073 |
if (($v_descr['stored_filename'] != $v_descr['filename']) |
|
2074 |
&& (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
|
2075 | 2075 |
if ($v_descr['stored_filename'] != '') { |
2076 | 2076 |
$v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
2077 | 2077 |
} |
... | ... | |
2086 | 2086 |
@closedir($v_folder_handler); |
2087 | 2087 |
} |
2088 | 2088 |
else { |
2089 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); |
|
2090 | 2089 |
// TBC : unable to open folder in read mode |
2091 | 2090 |
} |
2092 | 2091 |
|
... | ... | |
2094 | 2093 |
if ($v_dirlist_nb != 0) { |
2095 | 2094 |
// ----- Expand |
2096 | 2095 |
if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
2097 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2098 | 2096 |
return $v_result; |
2099 | 2097 |
} |
2100 | 2098 |
|
2101 | 2099 |
// ----- Concat the resulting list |
2102 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); |
|
2103 | 2100 |
$v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
2104 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); |
|
2105 | 2101 |
} |
2106 | 2102 |
else { |
2107 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); |
|
2108 | 2103 |
} |
2109 | 2104 |
|
2110 | 2105 |
// ----- Free local array |
... | ... | |
2116 | 2111 |
$p_filedescr_list = $v_result_list; |
2117 | 2112 |
|
2118 | 2113 |
// ----- Return |
2119 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2120 | 2114 |
return $v_result; |
2121 | 2115 |
} |
2122 | 2116 |
// -------------------------------------------------------------------------------- |
... | ... | |
2129 | 2123 |
// -------------------------------------------------------------------------------- |
2130 | 2124 |
function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
2131 | 2125 |
{ |
2132 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); |
|
2133 | 2126 |
$v_result=1; |
2134 | 2127 |
$v_list_detail = array(); |
2135 | 2128 |
|
... | ... | |
2140 | 2133 |
if (($v_result = $this->privOpenFd('wb')) != 1) |
2141 | 2134 |
{ |
2142 | 2135 |
// ----- Return |
2143 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2144 | 2136 |
return $v_result; |
2145 | 2137 |
} |
2146 | 2138 |
|
... | ... | |
2154 | 2146 |
$this->privSwapBackMagicQuotes(); |
2155 | 2147 |
|
2156 | 2148 |
// ----- Return |
2157 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2158 | 2149 |
return $v_result; |
2159 | 2150 |
} |
2160 | 2151 |
// -------------------------------------------------------------------------------- |
... | ... | |
2167 | 2158 |
// -------------------------------------------------------------------------------- |
2168 | 2159 |
function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
2169 | 2160 |
{ |
2170 |
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); |
|
2171 | 2161 |
$v_result=1; |
2172 | 2162 |
$v_list_detail = array(); |
2173 | 2163 |
|
2174 | 2164 |
// ----- Look if the archive exists or is empty |
2175 | 2165 |
if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
2176 | 2166 |
{ |
2177 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); |
|
2178 | 2167 |
|
2179 | 2168 |
// ----- Do a create |
2180 | 2169 |
$v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
2181 | 2170 |
|
2182 | 2171 |
// ----- Return |
2183 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2184 | 2172 |
return $v_result; |
2185 | 2173 |
} |
2186 | 2174 |
// ----- Magic quotes trick |
2187 | 2175 |
$this->privDisableMagicQuotes(); |
2188 | 2176 |
|
2189 | 2177 |
// ----- Open the zip file |
2190 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
2191 | 2178 |
if (($v_result=$this->privOpenFd('rb')) != 1) |
2192 | 2179 |
{ |
2193 | 2180 |
// ----- Magic quotes trick |
2194 | 2181 |
$this->privSwapBackMagicQuotes(); |
2195 | 2182 |
|
2196 | 2183 |
// ----- Return |
2197 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2198 | 2184 |
return $v_result; |
2199 | 2185 |
} |
2200 | 2186 |
|
... | ... | |
2204 | 2190 |
{ |
2205 | 2191 |
$this->privCloseFd(); |
2206 | 2192 |
$this->privSwapBackMagicQuotes(); |
2207 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2208 | 2193 |
return $v_result; |
2209 | 2194 |
} |
2210 | 2195 |
|
2211 | 2196 |
// ----- Go to beginning of File |
2212 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
2213 | 2197 |
@rewind($this->zip_fd); |
2214 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
2215 | 2198 |
|
2216 | 2199 |
// ----- Creates a temporay file |
2217 | 2200 |
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
2218 | 2201 |
|
2219 | 2202 |
// ----- Open the temporary file in write mode |
2220 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
2221 | 2203 |
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
2222 | 2204 |
{ |
2223 | 2205 |
$this->privCloseFd(); |
... | ... | |
2226 | 2208 |
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
2227 | 2209 |
|
2228 | 2210 |
// ----- Return |
2229 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2230 | 2211 |
return PclZip::errorCode(); |
2231 | 2212 |
} |
2232 | 2213 |
|
... | ... | |
2236 | 2217 |
while ($v_size != 0) |
2237 | 2218 |
{ |
2238 | 2219 |
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2239 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
2240 | 2220 |
$v_buffer = fread($this->zip_fd, $v_read_size); |
2241 | 2221 |
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
2242 | 2222 |
$v_size -= $v_read_size; |
... | ... | |
2259 | 2239 |
$this->privSwapBackMagicQuotes(); |
2260 | 2240 |
|
2261 | 2241 |
// ----- Return |
2262 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2263 | 2242 |
return $v_result; |
2264 | 2243 |
} |
2265 | 2244 |
|
2266 | 2245 |
// ----- Store the offset of the central dir |
2267 | 2246 |
$v_offset = @ftell($this->zip_fd); |
2268 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); |
|
2269 | 2247 |
|
2270 | 2248 |
// ----- Copy the block of file headers from the old archive |
2271 | 2249 |
$v_size = $v_central_dir['size']; |
2272 | 2250 |
while ($v_size != 0) |
2273 | 2251 |
{ |
2274 | 2252 |
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2275 |
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
2276 | 2253 |
$v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
2277 | 2254 |
@fwrite($this->zip_fd, $v_buffer, $v_read_size); |
2278 | 2255 |
$v_size -= $v_read_size; |
... | ... | |
2290 | 2267 |
$this->privSwapBackMagicQuotes(); |
2291 | 2268 |
|
2292 | 2269 |
// ----- Return |
2293 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2294 | 2270 |
return $v_result; |
2295 | 2271 |
} |
2296 | 2272 |
$v_count++; |
... | ... | |
2323 | 2299 |
$this->privSwapBackMagicQuotes(); |
2324 | 2300 |
|
2325 | 2301 |
// ----- Return |
2326 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2327 | 2302 |
return $v_result; |
2328 | 2303 |
} |
2329 | 2304 |
|
... | ... | |
2351 | 2326 |
PclZipUtilRename($v_zip_temp_name, $this->zipname); |
2352 | 2327 |
|
2353 | 2328 |
// ----- Return |
2354 |
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
Also available in: Unified diff
Branch 2.8.1 merged back into Trunk