Backup & Restore Dropbox - Version 1.5.1

Version Description

Please, keep your Dropbox Backup and Restore plugin up-to-date.

Download this release

Release Info

Developer backup-dropbox
Plugin Icon 128x128 Backup & Restore Dropbox
Version 1.5.1
Comparing to
See all releases

Code changes from version 1.5 to 1.5.1

dropbox-backup.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
- Version: 1.5
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
+ Version: 1.5.1
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
functions/wpadm.php CHANGED
@@ -263,7 +263,7 @@ if (!function_exists('BackupsFoldersExclude')) {
263
  {
264
  $folders = array('aiowps_backups' => 'wp-content', 'backup-db' => 'wp-content', 'backups' => 'wp-content', 'bps-backup' => 'wp-content',
265
  'updraft' => 'wp-content', 'wpbackitup_backups' => 'wp-content', 'wpbackitup_restore' => 'wp-content',
266
- 'backup-guard' => 'uploads', 'ithemes-security' => 'uploads', 'wp-clone' => 'uploads');
267
  $in_name_folders = array( 'backupwordpress' => 'wp-content' );
268
 
269
  if ( empty( $folder_check ) ) {
263
  {
264
  $folders = array('aiowps_backups' => 'wp-content', 'backup-db' => 'wp-content', 'backups' => 'wp-content', 'bps-backup' => 'wp-content',
265
  'updraft' => 'wp-content', 'wpbackitup_backups' => 'wp-content', 'wpbackitup_restore' => 'wp-content',
266
+ 'backup-guard' => 'uploads', 'ithemes-security' => 'uploads', 'wp-clone' => 'uploads', 'backupbuddy_backups' => 'uploads');
267
  $in_name_folders = array( 'backupwordpress' => 'wp-content' );
268
 
269
  if ( empty( $folder_check ) ) {
methods/class-wpadm-method-local-backup.php CHANGED
@@ -305,24 +305,26 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
305
  $md5 = md5( print_r( $files, 1 ) );
306
  if ( !isset($files_archive[$md5]) ) {
307
  if ( WPAdm_Running::is_stop() ) {
308
- $af = $this->getArchiveName($to_file);
309
- $archive = new WPAdm_Archive($af, $to_file . '.md5');
310
  $archive->setRemovePath(ABSPATH);
311
- if ( !file_exists( $af ) ) {
312
- WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
313
  }
314
  }
315
  $targz = WPAdm_Running::getCommandResultData('test_targz_archive');
316
 
317
- if ( ( !empty($targz) && $targz === true ) || ( file_exists($af) && filesize($af) > 900000 ) ) {
318
  if ( WPAdm_Running::is_stop() ) {
319
- $af = $this->getNextArchiveName($to_file);
320
- unset($archive);
321
- if ( !file_exists( $af ) ) {
322
- WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
 
 
 
 
323
  }
324
- $archive = new WPAdm_Archive($af, $to_file . '.md5');
325
- $archive->setRemovePath( ABSPATH );
326
  } else {
327
  return true;
328
  }
@@ -346,9 +348,13 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
346
  WPAdm_Running::setCommandResultData('archive', $files_archive);
347
  WPAdm_Process::setInc( 'archiving', count($files) );
348
  } else {
349
- $this->result->setError( $archive->error );
350
- $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
351
- return $this->result;
 
 
 
 
352
  }
353
  } else {
354
  return true;
@@ -573,6 +579,24 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
573
  return $files;
574
  }
575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
 
577
  private function directoryToArray($directory, $recursive) {
578
  $array_items = array();
@@ -604,11 +628,11 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
604
  $d2 = strtolower(implode('/', $tmp));
605
  }
606
 
607
- /*if (stripos($d2, 'cache') !== false ) {
608
- WPAdm_Core::log( __('Skip of Cache-Folder ','dropbox-backup') . $directory);
609
- return array();
610
- } */
611
-
612
  if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
613
  WPAdm_Core::log(__('Skip of Cache-Folder ','dropbox-backup') . $directory);
614
  return array();
@@ -622,6 +646,11 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
622
  if(strpos($directory, 'wpadm_backups') !== false || strpos($directory, 'Dropbox_Backup') !== false) {
623
  return array();
624
  }
 
 
 
 
 
625
 
626
  if ($handle = opendir($directory)) {
627
  while (false !== ($file = readdir($handle))) {
@@ -649,7 +678,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
649
  $f = str_replace(ABSPATH, '', $ff);
650
  // skip "minus" dirs
651
  if (!in_array($f, $minus_path)) {
652
- $array_items[] = $ff;
653
  } else {
654
  WPAdm_Core::log( __('Skip of Folder ','dropbox-backup') . $ff);
655
  }
305
  $md5 = md5( print_r( $files, 1 ) );
306
  if ( !isset($files_archive[$md5]) ) {
307
  if ( WPAdm_Running::is_stop() ) {
308
+ $af1 = $this->getArchiveName($to_file);
309
+ $archive = new WPAdm_Archive($af1, $to_file . '.md5');
310
  $archive->setRemovePath(ABSPATH);
311
+ if ( !file_exists( $af1 ) ) {
312
+ WPAdm_Core::log( __('Create part ','dropbox-backup') . basename( $af1 ) );
313
  }
314
  }
315
  $targz = WPAdm_Running::getCommandResultData('test_targz_archive');
316
 
317
+ if ( ( !empty($targz) && $targz === true ) || ( file_exists($af1) && filesize($af1) > 900000 ) ) {
318
  if ( WPAdm_Running::is_stop() ) {
319
+ $af2 = $this->getNextArchiveName($to_file);
320
+ if ($af1 != $af2) {
321
+ unset($archive);
322
+ if ( !file_exists( $af2 ) ) {
323
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af2 ) );
324
+ }
325
+ $archive = new WPAdm_Archive($af2, $to_file . '.md5');
326
+ $archive->setRemovePath( ABSPATH );
327
  }
 
 
328
  } else {
329
  return true;
330
  }
348
  WPAdm_Running::setCommandResultData('archive', $files_archive);
349
  WPAdm_Process::setInc( 'archiving', count($files) );
350
  } else {
351
+ if ($archive->anew) {
352
+ return true;
353
+ } else {
354
+ $this->result->setError( $archive->error );
355
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
356
+ return $this->result;
357
+ }
358
  }
359
  } else {
360
  return true;
579
  return $files;
580
  }
581
 
582
+ public function tryToUtf8( $string, $strip = false )
583
+ {
584
+ $string = (string) $string;
585
+
586
+ if ( 0 === strlen( $string ) ) {
587
+ return '';
588
+ }
589
+ // preg match invalid UTF8
590
+ if ( 1 === @preg_match( '/^./us', $string ) ) {
591
+ return $string;
592
+ }
593
+
594
+ if ( $strip && function_exists( 'iconv' ) ) {
595
+ return iconv( 'utf-8', 'utf-8', $string );
596
+ }
597
+
598
+ return $string;
599
+ }
600
 
601
  private function directoryToArray($directory, $recursive) {
602
  $array_items = array();
628
  $d2 = strtolower(implode('/', $tmp));
629
  }
630
 
631
+ if (stripos($d2, 'cache') !== false ) {
632
+ WPAdm_Core::log( __('Skip of Cache-Folder ','dropbox-backup') . $directory);
633
+ return array();
634
+ }
635
+
636
  if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
637
  WPAdm_Core::log(__('Skip of Cache-Folder ','dropbox-backup') . $directory);
638
  return array();
646
  if(strpos($directory, 'wpadm_backups') !== false || strpos($directory, 'Dropbox_Backup') !== false) {
647
  return array();
648
  }
649
+
650
+ if (stripos($d2, 'backup') !== false ) {
651
+ WPAdm_Core::log( __('Skip of Backup-Folder ','dropbox-backup') . $directory);
652
+ return array();
653
+ }
654
 
655
  if ($handle = opendir($directory)) {
656
  while (false !== ($file = readdir($handle))) {
678
  $f = str_replace(ABSPATH, '', $ff);
679
  // skip "minus" dirs
680
  if (!in_array($f, $minus_path)) {
681
+ $array_items[] = $this->tryToUtf8( $ff );
682
  } else {
683
  WPAdm_Core::log( __('Skip of Folder ','dropbox-backup') . $ff);
684
  }
methods/class-wpadm-method-send-to-dropbox.php CHANGED
@@ -201,7 +201,7 @@ if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
201
  if ( WPAdm_Running::is_stop() ) {
202
  $delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
203
  if (isset($delete_file['error'])) {
204
- $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
205
  return false;
206
  }
207
  $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
@@ -239,7 +239,7 @@ if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
239
  $res = $dropbox->uploadFile($fromFile, $toFile, true);
240
  }
241
  if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
242
- $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
243
  return false;
244
  }
245
  if ( WPAdm_Running::is_stop() ) {
201
  if ( WPAdm_Running::is_stop() ) {
202
  $delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
203
  if (isset($delete_file['error'])) {
204
+ $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"(d)');
205
  return false;
206
  }
207
  $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
239
  $res = $dropbox->uploadFile($fromFile, $toFile, true);
240
  }
241
  if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
242
+ $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"(u)');
243
  return false;
244
  }
245
  if ( WPAdm_Running::is_stop() ) {
modules/archive.php CHANGED
@@ -460,7 +460,7 @@
460
  break;
461
  else if (substr($file['magic'], 0, 5) != "ustar")
462
  {
463
- $this->error[] = "This script does not support extracting this type of tar file." . "(" . substr($file['magic'], 0, 5) . ")";
464
  break;
465
  }
466
  $block = substr_replace($block, " ", 148, 8);
460
  break;
461
  else if (substr($file['magic'], 0, 5) != "ustar")
462
  {
463
+ $this->error[] = "This script does not support extracting this type of tar file." . "(" . utf8_encode( substr($file['magic'], 0, 5) ) . ")";
464
  break;
465
  }
466
  $block = substr_replace($block, " ", 148, 8);
modules/class-wpadm-archive.php CHANGED
@@ -21,6 +21,8 @@ if (!class_exists('WPAdm_Archive')) {
21
  private $archive;
22
  private $md5_file = '';
23
  public $error = '';
 
 
24
 
25
 
26
  private $method = '';
@@ -40,6 +42,7 @@ if (!class_exists('WPAdm_Archive')) {
40
  if ( isset( $this->type_backup['zip_archive'] ) && $this->type_backup['zip_archive'] == 1 && !empty($file_to_arhive) ) {
41
  $command = $this->getCommandToArchive('zip_archive', $file_to_arhive);
42
  if (!empty($command)) {
 
43
  $result_command = @exec($command, $command_return);
44
 
45
  $res = $this->parseResultZip($command_return);
@@ -84,19 +87,19 @@ if (!class_exists('WPAdm_Archive')) {
84
  $this->saveMd5( $file_to_arhive[$i] );
85
  }
86
  $this->close();
87
- /* include_once dirname(__FILE__) . '/archive.php';
88
  $gz = new wpadm_gzip_file($this->file_zip);
89
  $gz->set_options( array('basedir' => ABSPATH, 'delete_path_in_archive' => $this->remove_path ) );
90
  $gz->add_files( $file_to_arhive );
91
  $gz->create_archive();
92
  if (!empty( $gz->error ) ) {
93
- $this->error = implode(" ", $gz->error );
94
- WPAdm_Core::log( $this->error );
95
- return false;
96
  }
97
  $this->saveMd5( implode( PCLZIP_SEPARATOR, $file_to_arhive) );
98
  */
99
-
100
  /*if ( strpos($this->file_zip, '.tar.gz') !== false ) {
101
  $this->file_zip = str_replace('.tar.gz', '.zip', $this->file_zip);
102
  } */
@@ -305,6 +308,7 @@ if (!class_exists('WPAdm_Archive')) {
305
 
306
  $command = $this->getCommandToArchive('tar_archive', $file_to_arhive);
307
  if (!empty($command)) {
 
308
  $result_command = @exec ($command, $command_return);
309
  if (count($file_to_arhive) == count($command_return)) {
310
  $files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
@@ -341,7 +345,7 @@ if (!class_exists('WPAdm_Archive')) {
341
  $files_str = str_replace($this->remove_path, './', $files_str);
342
  $zip = str_replace($this->remove_path, './', $this->file_zip);
343
  } else {
344
- $files_str = implode(' ', $files);
345
  $zip = $this->file_zip;
346
  }
347
 
@@ -355,19 +359,36 @@ if (!class_exists('WPAdm_Archive')) {
355
  if (!empty( $this->remove_path) ) {
356
  $remove_dir = '-C ' . $this->remove_path . ' ';
357
  }
358
- $files_str = implode(' ', $files);
359
  $files_str = str_replace($this->remove_path, './', $files_str);
360
  $u = 'c';
361
  if (file_exists($this->file_zip)) {
362
  $u = 'r';
363
  }
364
- $return = trim( "tar -{$u}xvf {$this->file_zip} " . $remove_dir . $files_str );
365
  break;
366
  }
367
  return $return;
368
 
369
  }
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  public function add($file)
372
  {
373
  return $this->packed($file);
@@ -384,38 +405,59 @@ if (!class_exists('WPAdm_Archive')) {
384
  $this->setToLogArhive(__("Add File: ", 'dropbox-backup' ) . $files[$i] . ' [' . WPADM_getSize( filesize($files[$i]) ) . ']' . '[' . wpadm_class::perm($files[$i]) . ']' );
385
  }
386
  $file = implode(PCLZIP_SEPARATOR, $files);
387
- $command_zip_test = WPAdm_Running::getCommandResultData('test_zip_archive');
388
  $command_targz_test = WPAdm_Running::getCommandResultData('test_targz_archive');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  if ( !empty($command_zip_test) && $command_zip_test === true ) {
390
  if ( WPAdm_Running::is_stop() ) {
391
- return $this->zipArhive($files); // command zip
 
 
 
 
 
 
 
 
 
392
  }
393
- } elseif( !empty($command_targz_test) && $command_targz_test === true ) {
 
394
  if ( WPAdm_Running::is_stop() ) {
395
- return $this->targzArchive($files); // .tar.gz archive
396
  }
397
  } else {
398
- if (empty($this->remove_path)) {
399
- if ( WPAdm_Running::is_stop() ) {
400
- $res = $this->archive->add($file);
401
- }
402
- } else {
403
- if ( WPAdm_Running::is_stop() ) {
404
- $res = $this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
405
- }
406
- }
407
  if ( WPAdm_Running::is_stop() ) {
408
- if ($res == 0) {
409
- $this->checkError($file);
410
- WPAdm_Core::log( $this->archive->errorInfo(true) );
411
- if (file_exists($this->md5_file)) {
412
- unset($this->md5_file);
413
- }
414
- $this->error = $this->archive->errorInfo(true);
415
- return false;
416
- }
417
- $this->saveMd5($file);
418
  }
 
 
 
 
 
 
 
 
 
 
 
 
419
  }
420
  }
421
  return true;
21
  private $archive;
22
  private $md5_file = '';
23
  public $error = '';
24
+
25
+ public $anew = false;
26
 
27
 
28
  private $method = '';
42
  if ( isset( $this->type_backup['zip_archive'] ) && $this->type_backup['zip_archive'] == 1 && !empty($file_to_arhive) ) {
43
  $command = $this->getCommandToArchive('zip_archive', $file_to_arhive);
44
  if (!empty($command)) {
45
+ $command_return = array();
46
  $result_command = @exec($command, $command_return);
47
 
48
  $res = $this->parseResultZip($command_return);
87
  $this->saveMd5( $file_to_arhive[$i] );
88
  }
89
  $this->close();
90
+ /* include_once dirname(__FILE__) . '/archive.php';
91
  $gz = new wpadm_gzip_file($this->file_zip);
92
  $gz->set_options( array('basedir' => ABSPATH, 'delete_path_in_archive' => $this->remove_path ) );
93
  $gz->add_files( $file_to_arhive );
94
  $gz->create_archive();
95
  if (!empty( $gz->error ) ) {
96
+ $this->error = implode(" ", $gz->error );
97
+ WPAdm_Core::log( $this->error );
98
+ return false;
99
  }
100
  $this->saveMd5( implode( PCLZIP_SEPARATOR, $file_to_arhive) );
101
  */
102
+
103
  /*if ( strpos($this->file_zip, '.tar.gz') !== false ) {
104
  $this->file_zip = str_replace('.tar.gz', '.zip', $this->file_zip);
105
  } */
308
 
309
  $command = $this->getCommandToArchive('tar_archive', $file_to_arhive);
310
  if (!empty($command)) {
311
+ $command_return = array();
312
  $result_command = @exec ($command, $command_return);
313
  if (count($file_to_arhive) == count($command_return)) {
314
  $files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
345
  $files_str = str_replace($this->remove_path, './', $files_str);
346
  $zip = str_replace($this->remove_path, './', $this->file_zip);
347
  } else {
348
+ $files_str = '"' . implode('" "', $files) . '"';
349
  $zip = $this->file_zip;
350
  }
351
 
359
  if (!empty( $this->remove_path) ) {
360
  $remove_dir = '-C ' . $this->remove_path . ' ';
361
  }
362
+ $files_str = '"' . implode('" "', $files) . '"';
363
  $files_str = str_replace($this->remove_path, './', $files_str);
364
  $u = 'c';
365
  if (file_exists($this->file_zip)) {
366
  $u = 'r';
367
  }
368
+ $return = trim( "tar -{$u}zvf {$this->file_zip} " . $remove_dir . $files_str );
369
  break;
370
  }
371
  return $return;
372
 
373
  }
374
 
375
+ public function clearBackupDirectory($type = '')
376
+ {
377
+ if (!empty( $type ) ) {
378
+ $dir = substr($this->file_zip, 0, strlen($this->file_zip) - strlen( basename( $this->file_zip ) ) );
379
+ $open_dir = opendir( $dir );
380
+ if ($open_dir) {
381
+ while($d = readdir($open_dir)) {
382
+ if ($d != '.' && $d != '..') {
383
+ if ( substr($d, $type) !== false ) {
384
+ @unlink($dir . '/' . $d);
385
+ }
386
+ }
387
+ }
388
+ }
389
+ }
390
+ }
391
+
392
  public function add($file)
393
  {
394
  return $this->packed($file);
405
  $this->setToLogArhive(__("Add File: ", 'dropbox-backup' ) . $files[$i] . ' [' . WPADM_getSize( filesize($files[$i]) ) . ']' . '[' . wpadm_class::perm($files[$i]) . ']' );
406
  }
407
  $file = implode(PCLZIP_SEPARATOR, $files);
 
408
  $command_targz_test = WPAdm_Running::getCommandResultData('test_targz_archive');
409
+ if( !empty($command_targz_test) && $command_targz_test === true ) {
410
+ if ( WPAdm_Running::is_stop() ) {
411
+ WPAdm_Core::log(__('Trying to add files to archive using Tar shell or tar class', 'dropbox-backup') );
412
+ $tarGz = $this->targzArchive($files); // .tar.gz archive
413
+ if ($tarGz) {
414
+ WPAdm_Core::log(__('Trying to add files to archive using Tar shell or tar class was successful', 'dropbox-backup') );
415
+ return true;
416
+ }
417
+ $this->anew = true;
418
+ $this->clearBackupDirectory('.tar.gz');
419
+ $this->clearBackupDirectory('.md5');
420
+ $this->error = '';
421
+ WPAdm_Core::log(__('Add files to archive using Tar shell or tar class wasn\'t successful', 'dropbox-backup') );
422
+ WPAdm_Running::setCommandResultData('test_targz_archive', false);
423
+ return false;
424
+ }
425
+ }
426
+ $command_zip_test = WPAdm_Running::getCommandResultData('test_zip_archive');
427
  if ( !empty($command_zip_test) && $command_zip_test === true ) {
428
  if ( WPAdm_Running::is_stop() ) {
429
+ WPAdm_Core::log(__('Trying to add files to archive using Zip shell', 'dropbox-backup') );
430
+ $zip_shell = $this->zipArhive($files); // command zip
431
+ if ($zip_shell) {
432
+ WPAdm_Core::log(__('Add files to archive using Zip shell was successful', 'dropbox-backup') );
433
+ return true;
434
+ }
435
+ $this->anew = true;
436
+ WPAdm_Core::log(__('Add files to archive using Zip shell wasn\'t successful', 'dropbox-backup') );
437
+ WPAdm_Running::setCommandResultData('test_zip_archive', false);
438
+ return false;
439
  }
440
+ }
441
+ if (empty($this->remove_path)) {
442
  if ( WPAdm_Running::is_stop() ) {
443
+ $res = $this->archive->add($file);
444
  }
445
  } else {
 
 
 
 
 
 
 
 
 
446
  if ( WPAdm_Running::is_stop() ) {
447
+ $res = $this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
 
 
 
 
 
 
 
 
 
448
  }
449
+ }
450
+ if ( WPAdm_Running::is_stop() ) {
451
+ if ($res == 0) {
452
+ $this->checkError($file);
453
+ WPAdm_Core::log( $this->archive->errorInfo(true) );
454
+ if (file_exists($this->md5_file)) {
455
+ unset($this->md5_file);
456
+ }
457
+ $this->error = $this->archive->errorInfo(true);
458
+ return false;
459
+ }
460
+ $this->saveMd5($file);
461
  }
462
  }
463
  return true;
modules/class-wpadm-running.php CHANGED
@@ -140,7 +140,9 @@ if (!class_exists('WPAdm_Running')) {
140
 
141
  public static function createDebug( $result, $type_backup = '' )
142
  {
143
- wpadm_class::error_log_check( print_r( $result, 1 ), $type_backup );
 
 
144
  }
145
 
146
  public static function checkLock()
140
 
141
  public static function createDebug( $result, $type_backup = '' )
142
  {
143
+ if (isset($result['error']) && !empty( $result['error'] ) ) {
144
+ wpadm_class::error_log_check( print_r( $result, 1 ), $type_backup );
145
+ }
146
  }
147
 
148
  public static function checkLock()
modules/pclzip.lib.php CHANGED
@@ -1,3034 +1,3034 @@
1
- <?php
2
- if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
3
- define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
4
- }
5
- if (!defined('PCLZIP_SEPARATOR')) {
6
- define( 'PCLZIP_SEPARATOR', ',' );
7
- }
8
- if (!defined('PCLZIP_ERROR_EXTERNAL')) {
9
- define( 'PCLZIP_ERROR_EXTERNAL', 0 );
10
- }
11
- if (!defined('PCLZIP_TEMPORARY_DIR')) {
12
- define( 'PCLZIP_TEMPORARY_DIR', '' );
13
- }
14
- if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
15
- define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
16
- }
17
- // --------------------------------------------------------------------------------
18
- // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
19
- // --------------------------------------------------------------------------------
20
- $g_pclzip_version = "2.8.2";
21
- define( 'PCLZIP_ERR_USER_ABORTED', 2 );
22
- define( 'PCLZIP_ERR_NO_ERROR', 0 );
23
- define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
24
- define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
25
- define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
26
- define( 'PCLZIP_ERR_MISSING_FILE', -4 );
27
- define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
28
- define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
29
- define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
30
- define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
31
- define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
32
- define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
33
- define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
34
- define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
35
- define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
36
- define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
37
- define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
38
- define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
39
- define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
40
- define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
41
- define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
42
- define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
43
- define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
44
- define( 'PCLZIP_OPT_PATH', 77001 );
45
- define( 'PCLZIP_OPT_ADD_PATH', 77002 );
46
- define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
47
- define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
48
- define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
49
- define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
50
- define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
51
- define( 'PCLZIP_OPT_BY_NAME', 77008 );
52
- define( 'PCLZIP_OPT_BY_INDEX', 77009 );
53
- define( 'PCLZIP_OPT_BY_EREG', 77010 );
54
- define( 'PCLZIP_OPT_BY_PREG', 77011 );
55
- define( 'PCLZIP_OPT_COMMENT', 77012 );
56
- define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
57
- define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
58
- define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
59
- define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
60
- define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
61
- define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
62
- define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
63
- define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
64
- define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
65
- define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
66
- define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
67
- define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
68
- define( 'PCLZIP_ATT_FILE_NAME', 79001 );
69
- define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
70
- define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
71
- define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
72
- define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
73
- define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
74
- define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
75
- define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
76
- define( 'PCLZIP_CB_PRE_ADD', 78003 );
77
- define( 'PCLZIP_CB_POST_ADD', 78004 );
78
- /* For futur use
79
- define( 'PCLZIP_CB_PRE_LIST', 78005 );
80
- define( 'PCLZIP_CB_POST_LIST', 78006 );
81
- define( 'PCLZIP_CB_PRE_DELETE', 78007 );
82
- define( 'PCLZIP_CB_POST_DELETE', 78008 );
83
- */
84
- class PclZip
85
- {
86
- var $zipname = '';
87
- var $zip_fd = 0;
88
- var $error_code = 1;
89
- var $error_string = '';
90
- var $magic_quotes_status;
91
- function PclZip($p_zipname)
92
- {
93
- if (!function_exists('gzopen'))
94
- {
95
- die('Abort '.basename(__FILE__).' : Missing zlib extensions');
96
- }
97
- $this->zipname = $p_zipname;
98
- $this->zip_fd = 0;
99
- $this->magic_quotes_status = -1;
100
- return;
101
- }
102
- function create($p_filelist)
103
- {
104
- $v_result=1;
105
- $this->privErrorReset();
106
- $v_options = array();
107
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
108
- $v_size = func_num_args();
109
- if ($v_size > 1) {
110
- $v_arg_list = func_get_args();
111
- array_shift($v_arg_list);
112
- $v_size--;
113
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
114
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
115
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
116
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
117
- PCLZIP_OPT_ADD_PATH => 'optional',
118
- PCLZIP_CB_PRE_ADD => 'optional',
119
- PCLZIP_CB_POST_ADD => 'optional',
120
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
121
- PCLZIP_OPT_COMMENT => 'optional',
122
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
123
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
124
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
125
- ));
126
- if ($v_result != 1) {
127
- return 0;
128
- }
129
- }
130
- else {
131
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
132
- if ($v_size == 2) {
133
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
134
- }
135
- else if ($v_size > 2) {
136
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
137
- "Invalid number / type of arguments");
138
- return 0;
139
- }
140
- }
141
- }
142
- $this->privOptionDefaultThreshold($v_options);
143
- $v_string_list = array();
144
- $v_att_list = array();
145
- $v_filedescr_list = array();
146
- $p_result_list = array();
147
- if (is_array($p_filelist)) {
148
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
149
- $v_att_list = $p_filelist;
150
- }
151
- else {
152
- $v_string_list = $p_filelist;
153
- }
154
- }
155
- else if (is_string($p_filelist)) {
156
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
157
- }
158
- else {
159
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
160
- return 0;
161
- }
162
- if (sizeof($v_string_list) != 0) {
163
- foreach ($v_string_list as $v_string) {
164
- if ($v_string != '') {
165
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
166
- }
167
- else {
168
- }
169
- }
170
- }
171
- $v_supported_attributes
172
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
173
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
174
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
175
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
176
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
177
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
178
- );
179
- foreach ($v_att_list as $v_entry) {
180
- $v_result = $this->privFileDescrParseAtt($v_entry,
181
- $v_filedescr_list[],
182
- $v_options,
183
- $v_supported_attributes);
184
- if ($v_result != 1) {
185
- return 0;
186
- }
187
- }
188
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
189
- if ($v_result != 1) {
190
- return 0;
191
- }
192
- $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
193
- if ($v_result != 1) {
194
- return 0;
195
- }
196
- return $p_result_list;
197
- }
198
- function add($p_filelist)
199
- {
200
- $v_result=1;
201
- $this->privErrorReset();
202
- $v_options = array();
203
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
204
- $v_size = func_num_args();
205
- if ($v_size > 1) {
206
- $v_arg_list = func_get_args();
207
- array_shift($v_arg_list);
208
- $v_size--;
209
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
210
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
211
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
212
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
213
- PCLZIP_OPT_ADD_PATH => 'optional',
214
- PCLZIP_CB_PRE_ADD => 'optional',
215
- PCLZIP_CB_POST_ADD => 'optional',
216
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
217
- PCLZIP_OPT_COMMENT => 'optional',
218
- PCLZIP_OPT_ADD_COMMENT => 'optional',
219
- PCLZIP_OPT_PREPEND_COMMENT => 'optional',
220
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
221
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
222
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
223
- ));
224
- if ($v_result != 1) {
225
- return 0;
226
- }
227
- }
228
- else {
229
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
230
- if ($v_size == 2) {
231
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
232
- }
233
- else if ($v_size > 2) {
234
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
235
- return 0;
236
- }
237
- }
238
- }
239
- $this->privOptionDefaultThreshold($v_options);
240
- $v_string_list = array();
241
- $v_att_list = array();
242
- $v_filedescr_list = array();
243
- $p_result_list = array();
244
- if (is_array($p_filelist)) {
245
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
246
- $v_att_list = $p_filelist;
247
- }
248
- else {
249
- $v_string_list = $p_filelist;
250
- }
251
- }
252
- else if (is_string($p_filelist)) {
253
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
254
- }
255
- else {
256
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
257
- return 0;
258
- }
259
- if (sizeof($v_string_list) != 0) {
260
- foreach ($v_string_list as $v_string) {
261
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
262
- }
263
- }
264
- $v_supported_attributes
265
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
266
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
267
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
268
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
269
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
270
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
271
- );
272
- foreach ($v_att_list as $v_entry) {
273
- $v_result = $this->privFileDescrParseAtt($v_entry,
274
- $v_filedescr_list[],
275
- $v_options,
276
- $v_supported_attributes);
277
- if ($v_result != 1) {
278
- return 0;
279
- }
280
- }
281
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
282
- if ($v_result != 1) {
283
- return 0;
284
- }
285
- $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
286
- if ($v_result != 1) {
287
- return 0;
288
- }
289
- return $p_result_list;
290
- }
291
- function listContent()
292
- {
293
- $v_result=1;
294
- $this->privErrorReset();
295
- if (!$this->privCheckFormat()) {
296
- return(0);
297
- }
298
- $p_list = array();
299
- if (($v_result = $this->privList($p_list)) != 1)
300
- {
301
- unset($p_list);
302
- return(0);
303
- }
304
- return $p_list;
305
- }
306
- function extract()
307
- {
308
- $v_result=1;
309
- $this->privErrorReset();
310
- if (!$this->privCheckFormat()) {
311
- return(0);
312
- }
313
- $v_options = array();
314
- // $v_path = "./";
315
- $v_path = '';
316
- $v_remove_path = "";
317
- $v_remove_all_path = false;
318
- $v_size = func_num_args();
319
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
320
- if ($v_size > 0) {
321
- $v_arg_list = func_get_args();
322
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
323
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
324
- array (PCLZIP_OPT_PATH => 'optional',
325
- PCLZIP_OPT_REMOVE_PATH => 'optional',
326
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
327
- PCLZIP_OPT_ADD_PATH => 'optional',
328
- PCLZIP_CB_PRE_EXTRACT => 'optional',
329
- PCLZIP_CB_POST_EXTRACT => 'optional',
330
- PCLZIP_OPT_SET_CHMOD => 'optional',
331
- PCLZIP_OPT_BY_NAME => 'optional',
332
- PCLZIP_OPT_BY_EREG => 'optional',
333
- PCLZIP_OPT_BY_PREG => 'optional',
334
- PCLZIP_OPT_BY_INDEX => 'optional',
335
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
336
- PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
337
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
338
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
339
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
340
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
341
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
342
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
343
- ));
344
- if ($v_result != 1) {
345
- return 0;
346
- }
347
- if (isset($v_options[PCLZIP_OPT_PATH])) {
348
- $v_path = $v_options[PCLZIP_OPT_PATH];
349
- }
350
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
351
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
352
- }
353
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
354
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
355
- }
356
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
357
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
358
- $v_path .= '/';
359
- }
360
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
361
- }
362
- }
363
- else {
364
- $v_path = $v_arg_list[0];
365
- if ($v_size == 2) {
366
- $v_remove_path = $v_arg_list[1];
367
- }
368
- else if ($v_size > 2) {
369
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
370
- return 0;
371
- }
372
- }
373
- }
374
- $this->privOptionDefaultThreshold($v_options);
375
- $p_list = array();
376
- $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
377
- $v_remove_all_path, $v_options);
378
- if ($v_result < 1) {
379
- unset($p_list);
380
- return(0);
381
- }
382
- return $p_list;
383
- }
384
- function extractByIndex($p_index)
385
- {
386
- $v_result=1;
387
- $this->privErrorReset();
388
- if (!$this->privCheckFormat()) {
389
- return(0);
390
- }
391
- $v_options = array();
392
- // $v_path = "./";
393
- $v_path = '';
394
- $v_remove_path = "";
395
- $v_remove_all_path = false;
396
- $v_size = func_num_args();
397
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
398
- if ($v_size > 1) {
399
- $v_arg_list = func_get_args();
400
- array_shift($v_arg_list);
401
- $v_size--;
402
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
403
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
404
- array (PCLZIP_OPT_PATH => 'optional',
405
- PCLZIP_OPT_REMOVE_PATH => 'optional',
406
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
407
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
408
- PCLZIP_OPT_ADD_PATH => 'optional',
409
- PCLZIP_CB_PRE_EXTRACT => 'optional',
410
- PCLZIP_CB_POST_EXTRACT => 'optional',
411
- PCLZIP_OPT_SET_CHMOD => 'optional',
412
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
413
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
414
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
415
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
416
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
417
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
418
- ));
419
- if ($v_result != 1) {
420
- return 0;
421
- }
422
- if (isset($v_options[PCLZIP_OPT_PATH])) {
423
- $v_path = $v_options[PCLZIP_OPT_PATH];
424
- }
425
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
426
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
427
- }
428
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
429
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
430
- }
431
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
432
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
433
- $v_path .= '/';
434
- }
435
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
436
- }
437
- if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
438
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
439
- }
440
- else {
441
- }
442
- }
443
- else {
444
- $v_path = $v_arg_list[0];
445
- if ($v_size == 2) {
446
- $v_remove_path = $v_arg_list[1];
447
- }
448
- else if ($v_size > 2) {
449
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
450
- return 0;
451
- }
452
- }
453
- }
454
- $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
455
- $v_options_trick = array();
456
- $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
457
- array (PCLZIP_OPT_BY_INDEX => 'optional' ));
458
- if ($v_result != 1) {
459
- return 0;
460
- }
461
- $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
462
- $this->privOptionDefaultThreshold($v_options);
463
- if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
464
- return(0);
465
- }
466
- return $p_list;
467
- }
468
- function delete()
469
- {
470
- $v_result=1;
471
- $this->privErrorReset();
472
- if (!$this->privCheckFormat()) {
473
- return(0);
474
- }
475
- $v_options = array();
476
- $v_size = func_num_args();
477
- if ($v_size > 0) {
478
- $v_arg_list = func_get_args();
479
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
480
- array (PCLZIP_OPT_BY_NAME => 'optional',
481
- PCLZIP_OPT_BY_EREG => 'optional',
482
- PCLZIP_OPT_BY_PREG => 'optional',
483
- PCLZIP_OPT_BY_INDEX => 'optional' ));
484
- if ($v_result != 1) {
485
- return 0;
486
- }
487
- }
488
- $this->privDisableMagicQuotes();
489
- $v_list = array();
490
- if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
491
- $this->privSwapBackMagicQuotes();
492
- unset($v_list);
493
- return(0);
494
- }
495
- $this->privSwapBackMagicQuotes();
496
- return $v_list;
497
- }
498
- function deleteByIndex($p_index)
499
- {
500
- $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
501
- return $p_list;
502
- }
503
- function properties()
504
- {
505
- $this->privErrorReset();
506
- $this->privDisableMagicQuotes();
507
- if (!$this->privCheckFormat()) {
508
- $this->privSwapBackMagicQuotes();
509
- return(0);
510
- }
511
- $v_prop = array();
512
- $v_prop['comment'] = '';
513
- $v_prop['nb'] = 0;
514
- $v_prop['status'] = 'not_exist';
515
- if (@is_file($this->zipname))
516
- {
517
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
518
- {
519
- $this->privSwapBackMagicQuotes();
520
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
521
- return 0;
522
- }
523
- $v_central_dir = array();
524
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
525
- {
526
- $this->privSwapBackMagicQuotes();
527
- return 0;
528
- }
529
- $this->privCloseFd();
530
- $v_prop['comment'] = $v_central_dir['comment'];
531
- $v_prop['nb'] = $v_central_dir['entries'];
532
- $v_prop['status'] = 'ok';
533
- }
534
- $this->privSwapBackMagicQuotes();
535
- return $v_prop;
536
- }
537
- function duplicate($p_archive)
538
- {
539
- $v_result = 1;
540
- $this->privErrorReset();
541
- if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
542
- {
543
- $v_result = $this->privDuplicate($p_archive->zipname);
544
- }
545
- else if (is_string($p_archive))
546
- {
547
- if (!is_file($p_archive)) {
548
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
549
- $v_result = PCLZIP_ERR_MISSING_FILE;
550
- }
551
- else {
552
- $v_result = $this->privDuplicate($p_archive);
553
- }
554
- }
555
- else
556
- {
557
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
558
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
559
- }
560
- return $v_result;
561
- }
562
- function merge($p_archive_to_add)
563
- {
564
- $v_result = 1;
565
- $this->privErrorReset();
566
- if (!$this->privCheckFormat()) {
567
- return(0);
568
- }
569
- if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
570
- {
571
- $v_result = $this->privMerge($p_archive_to_add);
572
- }
573
- else if (is_string($p_archive_to_add))
574
- {
575
- $v_object_archive = new PclZip($p_archive_to_add);
576
- $v_result = $this->privMerge($v_object_archive);
577
- }
578
- else
579
- {
580
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
581
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
582
- }
583
- return $v_result;
584
- }
585
- function errorCode()
586
- {
587
- if (PCLZIP_ERROR_EXTERNAL == 1) {
588
- return(PclErrorCode());
589
- }
590
- else {
591
- return($this->error_code);
592
- }
593
- }
594
- function errorName($p_with_code=false)
595
- {
596
- $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
597
- PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
598
- PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
599
- PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
600
- PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
601
- PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
602
- PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
603
- PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
604
- PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
605
- PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
606
- PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
607
- PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
608
- PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
609
- PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
610
- PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
611
- PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
612
- PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
613
- PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
614
- PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
615
- ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
616
- ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
617
- );
618
- if (isset($v_name[$this->error_code])) {
619
- $v_value = $v_name[$this->error_code];
620
- }
621
- else {
622
- $v_value = 'NoName';
623
- }
624
- if ($p_with_code) {
625
- return($v_value.' ('.$this->error_code.')');
626
- }
627
- else {
628
- return($v_value);
629
- }
630
- }
631
- function errorInfo($p_full=false)
632
- {
633
- if (PCLZIP_ERROR_EXTERNAL == 1) {
634
- return(PclErrorString());
635
- }
636
- else {
637
- if ($p_full) {
638
- return($this->errorName(true)." : ".$this->error_string);
639
- }
640
- else {
641
- return($this->error_string." [code ".$this->error_code."]");
642
- }
643
- }
644
- }
645
- // --------------------------------------------------------------------------------
646
- // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
647
- // ***** *****
648
- // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
649
- // --------------------------------------------------------------------------------
650
- function privCheckFormat($p_level=0)
651
- {
652
- $v_result = true;
653
- // ----- Reset the file system cache
654
- clearstatcache();
655
- $this->privErrorReset();
656
- if (!is_file($this->zipname)) {
657
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
658
- return(false);
659
- }
660
- if (!is_readable($this->zipname)) {
661
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
662
- return(false);
663
- }
664
- return $v_result;
665
- }
666
- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
667
- {
668
- $v_result=1;
669
- $i=0;
670
- while ($i<$p_size) {
671
- if (!isset($v_requested_options[$p_options_list[$i]])) {
672
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
673
- return PclZip::errorCode();
674
- }
675
- switch ($p_options_list[$i]) {
676
- case PCLZIP_OPT_PATH :
677
- case PCLZIP_OPT_REMOVE_PATH :
678
- case PCLZIP_OPT_ADD_PATH :
679
- if (($i+1) >= $p_size) {
680
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
681
- return PclZip::errorCode();
682
- }
683
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
684
- $i++;
685
- break;
686
- case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
687
- if (($i+1) >= $p_size) {
688
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
689
- return PclZip::errorCode();
690
- }
691
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
692
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
693
- return PclZip::errorCode();
694
- }
695
- $v_value = $p_options_list[$i+1];
696
- if ((!is_integer($v_value)) || ($v_value<0)) {
697
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
698
- return PclZip::errorCode();
699
- }
700
- $v_result_list[$p_options_list[$i]] = $v_value*1048576;
701
- $i++;
702
- break;
703
- case PCLZIP_OPT_TEMP_FILE_ON :
704
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
705
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
706
- return PclZip::errorCode();
707
- }
708
- $v_result_list[$p_options_list[$i]] = true;
709
- break;
710
- case PCLZIP_OPT_TEMP_FILE_OFF :
711
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
712
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
713
- return PclZip::errorCode();
714
- }
715
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
716
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
717
- return PclZip::errorCode();
718
- }
719
- $v_result_list[$p_options_list[$i]] = true;
720
- break;
721
- case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
722
- if (($i+1) >= $p_size) {
723
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
724
- return PclZip::errorCode();
725
- }
726
- if ( is_string($p_options_list[$i+1])
727
- && ($p_options_list[$i+1] != '')) {
728
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
729
- $i++;
730
- }
731
- else {
732
- }
733
- break;
734
- case PCLZIP_OPT_BY_NAME :
735
- if (($i+1) >= $p_size) {
736
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
737
- return PclZip::errorCode();
738
- }
739
- if (is_string($p_options_list[$i+1])) {
740
- $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
741
- }
742
- else if (is_array($p_options_list[$i+1])) {
743
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
744
- }
745
- else {
746
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
747
- return PclZip::errorCode();
748
- }
749
- $i++;
750
- break;
751
- case PCLZIP_OPT_BY_EREG :
752
- $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
753
- case PCLZIP_OPT_BY_PREG :
754
- if (($i+1) >= $p_size) {
755
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
756
- return PclZip::errorCode();
757
- }
758
- if (is_string($p_options_list[$i+1])) {
759
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
760
- }
761
- else {
762
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
763
- return PclZip::errorCode();
764
- }
765
- $i++;
766
- break;
767
- case PCLZIP_OPT_COMMENT :
768
- case PCLZIP_OPT_ADD_COMMENT :
769
- case PCLZIP_OPT_PREPEND_COMMENT :
770
- if (($i+1) >= $p_size) {
771
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
772
- "Missing parameter value for option '"
773
- .PclZipUtilOptionText($p_options_list[$i])
774
- ."'");
775
- return PclZip::errorCode();
776
- }
777
- if (is_string($p_options_list[$i+1])) {
778
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
779
- }
780
- else {
781
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
782
- "Wrong parameter value for option '"
783
- .PclZipUtilOptionText($p_options_list[$i])
784
- ."'");
785
- return PclZip::errorCode();
786
- }
787
- $i++;
788
- break;
789
- case PCLZIP_OPT_BY_INDEX :
790
- if (($i+1) >= $p_size) {
791
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
792
- return PclZip::errorCode();
793
- }
794
- $v_work_list = array();
795
- if (is_string($p_options_list[$i+1])) {
796
- $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
797
- $v_work_list = explode(",", $p_options_list[$i+1]);
798
- }
799
- else if (is_integer($p_options_list[$i+1])) {
800
- $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
801
- }
802
- else if (is_array($p_options_list[$i+1])) {
803
- $v_work_list = $p_options_list[$i+1];
804
- }
805
- else {
806
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
807
- return PclZip::errorCode();
808
- }
809
- $v_sort_flag=false;
810
- $v_sort_value=0;
811
- for ($j=0; $j<sizeof($v_work_list); $j++) {
812
- $v_item_list = explode("-", $v_work_list[$j]);
813
- $v_size_item_list = sizeof($v_item_list);
814
- if ($v_size_item_list == 1) {
815
- $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
816
- $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
817
- }
818
- elseif ($v_size_item_list == 2) {
819
- $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
820
- $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
821
- }
822
- else {
823
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
824
- return PclZip::errorCode();
825
- }
826
- if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
827
- $v_sort_flag=true;
828
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
829
- return PclZip::errorCode();
830
- }
831
- $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
832
- }
833
- if ($v_sort_flag) {
834
- }
835
- $i++;
836
- break;
837
- case PCLZIP_OPT_REMOVE_ALL_PATH :
838
- case PCLZIP_OPT_EXTRACT_AS_STRING :
839
- case PCLZIP_OPT_NO_COMPRESSION :
840
- case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
841
- case PCLZIP_OPT_REPLACE_NEWER :
842
- case PCLZIP_OPT_STOP_ON_ERROR :
843
- $v_result_list[$p_options_list[$i]] = true;
844
- break;
845
- case PCLZIP_OPT_SET_CHMOD :
846
- if (($i+1) >= $p_size) {
847
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
848
- return PclZip::errorCode();
849
- }
850
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
851
- $i++;
852
- break;
853
- case PCLZIP_CB_PRE_EXTRACT :
854
- case PCLZIP_CB_POST_EXTRACT :
855
- case PCLZIP_CB_PRE_ADD :
856
- case PCLZIP_CB_POST_ADD :
857
- /* for futur use
858
- case PCLZIP_CB_PRE_DELETE :
859
- case PCLZIP_CB_POST_DELETE :
860
- case PCLZIP_CB_PRE_LIST :
861
- case PCLZIP_CB_POST_LIST :
862
- */
863
- if (($i+1) >= $p_size) {
864
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
865
- return PclZip::errorCode();
866
- }
867
- $v_function_name = $p_options_list[$i+1];
868
- if (!function_exists($v_function_name)) {
869
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
870
- return PclZip::errorCode();
871
- }
872
- $v_result_list[$p_options_list[$i]] = $v_function_name;
873
- $i++;
874
- break;
875
- default :
876
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
877
- "Unknown parameter '"
878
- .$p_options_list[$i]."'");
879
- return PclZip::errorCode();
880
- }
881
- $i++;
882
- }
883
- if ($v_requested_options !== false) {
884
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
885
- if ($v_requested_options[$key] == 'mandatory') {
886
- if (!isset($v_result_list[$key])) {
887
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
888
- return PclZip::errorCode();
889
- }
890
- }
891
- }
892
- }
893
- if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
894
- }
895
- return $v_result;
896
- }
897
- function privOptionDefaultThreshold(&$p_options)
898
- {
899
- $v_result=1;
900
- if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
901
- || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
902
- return $v_result;
903
- }
904
- $v_memory_limit = ini_get('memory_limit');
905
- $v_memory_limit = trim($v_memory_limit);
906
- $last = strtolower(substr($v_memory_limit, -1));
907
- if($last == 'g')
908
- $v_memory_limit = $v_memory_limit*1073741824;
909
- if($last == 'm')
910
- $v_memory_limit = $v_memory_limit*1048576;
911
- if($last == 'k')
912
- $v_memory_limit = $v_memory_limit*1024;
913
- $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
914
- if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
915
- unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
916
- }
917
- return $v_result;
918
- }
919
- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
920
- {
921
- $v_result=1;
922
- foreach ($p_file_list as $v_key => $v_value) {
923
- if (!isset($v_requested_options[$v_key])) {
924
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
925
- return PclZip::errorCode();
926
- }
927
- switch ($v_key) {
928
- case PCLZIP_ATT_FILE_NAME :
929
- if (!is_string($v_value)) {
930
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
931
- return PclZip::errorCode();
932
- }
933
- $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
934
- if ($p_filedescr['filename'] == '') {
935
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
936
- return PclZip::errorCode();
937
- }
938
- break;
939
- case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
940
- if (!is_string($v_value)) {
941
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
942
- return PclZip::errorCode();
943
- }
944
- $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
945
- if ($p_filedescr['new_short_name'] == '') {
946
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
947
- return PclZip::errorCode();
948
- }
949
- break;
950
- case PCLZIP_ATT_FILE_NEW_FULL_NAME :
951
- if (!is_string($v_value)) {
952
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
953
- return PclZip::errorCode();
954
- }
955
- $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
956
- if ($p_filedescr['new_full_name'] == '') {
957
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
958
- return PclZip::errorCode();
959
- }
960
- break;
961
- case PCLZIP_ATT_FILE_COMMENT :
962
- if (!is_string($v_value)) {
963
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
964
- return PclZip::errorCode();
965
- }
966
- $p_filedescr['comment'] = $v_value;
967
- break;
968
- case PCLZIP_ATT_FILE_MTIME :
969
- if (!is_integer($v_value)) {
970
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
971
- return PclZip::errorCode();
972
- }
973
- $p_filedescr['mtime'] = $v_value;
974
- break;
975
- case PCLZIP_ATT_FILE_CONTENT :
976
- $p_filedescr['content'] = $v_value;
977
- break;
978
- default :
979
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
980
- "Unknown parameter '".$v_key."'");
981
- return PclZip::errorCode();
982
- }
983
- if ($v_requested_options !== false) {
984
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
985
- if ($v_requested_options[$key] == 'mandatory') {
986
- if (!isset($p_file_list[$key])) {
987
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
988
- return PclZip::errorCode();
989
- }
990
- }
991
- }
992
- }
993
- }
994
- return $v_result;
995
- }
996
- function privFileDescrExpand(&$p_filedescr_list, &$p_options)
997
- {
998
- $v_result=1;
999
- $v_result_list = array();
1000
- for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
1001
- $v_descr = $p_filedescr_list[$i];
1002
- $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
1003
- $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
1004
- if (file_exists($v_descr['filename'])) {
1005
- if (@is_file($v_descr['filename'])) {
1006
- $v_descr['type'] = 'file';
1007
- }
1008
- else if (@is_dir($v_descr['filename'])) {
1009
- $v_descr['type'] = 'folder';
1010
- }
1011
- else if (@is_link($v_descr['filename'])) {
1012
- continue;
1013
- }
1014
- else {
1015
- continue;
1016
- }
1017
- }
1018
- else if (isset($v_descr['content'])) {
1019
- $v_descr['type'] = 'virtual_file';
1020
- }
1021
- else {
1022
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
1023
- return PclZip::errorCode();
1024
- }
1025
- $this->privCalculateStoredFilename($v_descr, $p_options);
1026
- $v_result_list[sizeof($v_result_list)] = $v_descr;
1027
- if ($v_descr['type'] == 'folder') {
1028
- $v_dirlist_descr = array();
1029
- $v_dirlist_nb = 0;
1030
- if ($v_folder_handler = @opendir($v_descr['filename'])) {
1031
- while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
1032
- if (($v_item_handler == '.') || ($v_item_handler == '..')) {
1033
- continue;
1034
- }
1035
- $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
1036
- if (($v_descr['stored_filename'] != $v_descr['filename'])
1037
- && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
1038
- if ($v_descr['stored_filename'] != '') {
1039
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
1040
- }
1041
- else {
1042
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
1043
- }
1044
- }
1045
- $v_dirlist_nb++;
1046
- }
1047
- @closedir($v_folder_handler);
1048
- }
1049
- else {
1050
- }
1051
- if ($v_dirlist_nb != 0) {
1052
- if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
1053
- return $v_result;
1054
- }
1055
- $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
1056
- }
1057
- else {
1058
- }
1059
- unset($v_dirlist_descr);
1060
- }
1061
- }
1062
- $p_filedescr_list = $v_result_list;
1063
- return $v_result;
1064
- }
1065
- function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
1066
- {
1067
- $v_result=1;
1068
- $v_list_detail = array();
1069
- $this->privDisableMagicQuotes();
1070
- if (($v_result = $this->privOpenFd('wb')) != 1)
1071
- {
1072
- return $v_result;
1073
- }
1074
- $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
1075
- $this->privCloseFd();
1076
- $this->privSwapBackMagicQuotes();
1077
- return $v_result;
1078
- }
1079
- function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
1080
- {
1081
- $v_result=1;
1082
- $v_list_detail = array();
1083
- if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
1084
- {
1085
- $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
1086
- return $v_result;
1087
- }
1088
- $this->privDisableMagicQuotes();
1089
- if (($v_result=$this->privOpenFd('rb')) != 1)
1090
- {
1091
- $this->privSwapBackMagicQuotes();
1092
- return $v_result;
1093
- }
1094
- $v_central_dir = array();
1095
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1096
- {
1097
- $this->privCloseFd();
1098
- $this->privSwapBackMagicQuotes();
1099
- return $v_result;
1100
- }
1101
- @rewind($this->zip_fd);
1102
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
1103
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
1104
- {
1105
- $this->privCloseFd();
1106
- $this->privSwapBackMagicQuotes();
1107
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
1108
- return PclZip::errorCode();
1109
- }
1110
- $v_size = $v_central_dir['offset'];
1111
- while ($v_size != 0)
1112
- {
1113
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1114
- $v_buffer = fread($this->zip_fd, $v_read_size);
1115
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
1116
- $v_size -= $v_read_size;
1117
- }
1118
- $v_swap = $this->zip_fd;
1119
- $this->zip_fd = $v_zip_temp_fd;
1120
- $v_zip_temp_fd = $v_swap;
1121
- $v_header_list = array();
1122
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
1123
- {
1124
- fclose($v_zip_temp_fd);
1125
- $this->privCloseFd();
1126
- @unlink($v_zip_temp_name);
1127
- $this->privSwapBackMagicQuotes();
1128
- return $v_result;
1129
- }
1130
- $v_offset = @ftell($this->zip_fd);
1131
- $v_size = $v_central_dir['size'];
1132
- while ($v_size != 0)
1133
- {
1134
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1135
- $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
1136
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
1137
- $v_size -= $v_read_size;
1138
- }
1139
- for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
1140
- {
1141
- if ($v_header_list[$i]['status'] == 'ok') {
1142
- if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1143
- fclose($v_zip_temp_fd);
1144
- $this->privCloseFd();
1145
- @unlink($v_zip_temp_name);
1146
- $this->privSwapBackMagicQuotes();
1147
- return $v_result;
1148
- }
1149
- $v_count++;
1150
- }
1151
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1152
- }
1153
- $v_comment = $v_central_dir['comment'];
1154
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
1155
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
1156
- }
1157
- if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
1158
- $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
1159
- }
1160
- if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
1161
- $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
1162
- }
1163
- $v_size = @ftell($this->zip_fd)-$v_offset;
1164
- if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
1165
- {
1166
- unset($v_header_list);
1167
- $this->privSwapBackMagicQuotes();
1168
- return $v_result;
1169
- }
1170
- $v_swap = $this->zip_fd;
1171
- $this->zip_fd = $v_zip_temp_fd;
1172
- $v_zip_temp_fd = $v_swap;
1173
- $this->privCloseFd();
1174
- @fclose($v_zip_temp_fd);
1175
- $this->privSwapBackMagicQuotes();
1176
- @unlink($this->zipname);
1177
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
1178
- return $v_result;
1179
- }
1180
- function privOpenFd($p_mode)
1181
- {
1182
- $v_result=1;
1183
- if ($this->zip_fd != 0)
1184
- {
1185
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
1186
- return PclZip::errorCode();
1187
- }
1188
- if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
1189
- {
1190
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
1191
- return PclZip::errorCode();
1192
- }
1193
- return $v_result;
1194
- }
1195
- function privCloseFd()
1196
- {
1197
- $v_result=1;
1198
- if ($this->zip_fd != 0)
1199
- @fclose($this->zip_fd);
1200
- $this->zip_fd = 0;
1201
- return $v_result;
1202
- }
1203
- // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
1204
- function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
1205
- {
1206
- $v_result=1;
1207
- $v_header_list = array();
1208
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
1209
- {
1210
- return $v_result;
1211
- }
1212
- $v_offset = @ftell($this->zip_fd);
1213
- for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
1214
- {
1215
- if ($v_header_list[$i]['status'] == 'ok') {
1216
- if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1217
- return $v_result;
1218
- }
1219
- $v_count++;
1220
- }
1221
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1222
- }
1223
- $v_comment = '';
1224
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
1225
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
1226
- }
1227
- $v_size = @ftell($this->zip_fd)-$v_offset;
1228
- if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
1229
- {
1230
- unset($v_header_list);
1231
- return $v_result;
1232
- }
1233
- return $v_result;
1234
- }
1235
- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
1236
- {
1237
- $v_result=1;
1238
- $v_header = array();
1239
- $v_nb = sizeof($p_result_list);
1240
- for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
1241
- $p_filedescr_list[$j]['filename']
1242
- = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
1243
- if ($p_filedescr_list[$j]['filename'] == "") {
1244
- continue;
1245
- }
1246
- if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
1247
- && (!file_exists($p_filedescr_list[$j]['filename']))) {
1248
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
1249
- return PclZip::errorCode();
1250
- }
1251
- // if ( (is_file($p_filedescr_list[$j]['filename']))
1252
- // || ( is_dir($p_filedescr_list[$j]['filename'])
1253
- if ( ($p_filedescr_list[$j]['type'] == 'file')
1254
- || ($p_filedescr_list[$j]['type'] == 'virtual_file')
1255
- || ( ($p_filedescr_list[$j]['type'] == 'folder')
1256
- && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
1257
- || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
1258
- ) {
1259
- $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
1260
- $p_options);
1261
- if ($v_result != 1) {
1262
- return $v_result;
1263
- }
1264
- $p_result_list[$v_nb++] = $v_header;
1265
- }
1266
- }
1267
- return $v_result;
1268
- }
1269
- function privAddFile($p_filedescr, &$p_header, &$p_options)
1270
- {
1271
- $v_result=1;
1272
- $p_filename = $p_filedescr['filename'];
1273
- if ($p_filename == "") {
1274
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
1275
- return PclZip::errorCode();
1276
- }
1277
- /* TBC : Removed
1278
- if (isset($p_filedescr['stored_filename'])) {
1279
- $v_stored_filename = $p_filedescr['stored_filename'];
1280
- }
1281
- else {
1282
- $v_stored_filename = $p_filedescr['stored_filename'];
1283
- }
1284
- */
1285
- clearstatcache();
1286
- $p_header['version'] = 20;
1287
- $p_header['version_extracted'] = 10;
1288
- $p_header['flag'] = 0;
1289
- $p_header['compression'] = 0;
1290
- $p_header['crc'] = 0;
1291
- $p_header['compressed_size'] = 0;
1292
- $p_header['filename_len'] = strlen($p_filename);
1293
- $p_header['extra_len'] = 0;
1294
- $p_header['disk'] = 0;
1295
- $p_header['internal'] = 0;
1296
- $p_header['offset'] = 0;
1297
- $p_header['filename'] = $p_filename;
1298
- // TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
1299
- $p_header['stored_filename'] = $p_filedescr['stored_filename'];
1300
- $p_header['extra'] = '';
1301
- $p_header['status'] = 'ok';
1302
- $p_header['index'] = -1;
1303
- if ($p_filedescr['type']=='file') {
1304
- $p_header['external'] = 0x00000000;
1305
- $p_header['size'] = filesize($p_filename);
1306
- }
1307
- else if ($p_filedescr['type']=='folder') {
1308
- $p_header['external'] = 0x00000010;
1309
- $p_header['mtime'] = filemtime($p_filename);
1310
- $p_header['size'] = filesize($p_filename);
1311
- }
1312
- else if ($p_filedescr['type'] == 'virtual_file') {
1313
- $p_header['external'] = 0x00000000;
1314
- $p_header['size'] = strlen($p_filedescr['content']);
1315
- }
1316
- if (isset($p_filedescr['mtime'])) {
1317
- $p_header['mtime'] = $p_filedescr['mtime'];
1318
- }
1319
- else if ($p_filedescr['type'] == 'virtual_file') {
1320
- $p_header['mtime'] = time();
1321
- }
1322
- else {
1323
- $p_header['mtime'] = filemtime($p_filename);
1324
- }
1325
- if (isset($p_filedescr['comment'])) {
1326
- $p_header['comment_len'] = strlen($p_filedescr['comment']);
1327
- $p_header['comment'] = $p_filedescr['comment'];
1328
- }
1329
- else {
1330
- $p_header['comment_len'] = 0;
1331
- $p_header['comment'] = '';
1332
- }
1333
- if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
1334
- $v_local_header = array();
1335
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
1336
- // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
1337
- $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
1338
- if ($v_result == 0) {
1339
- $p_header['status'] = "skipped";
1340
- $v_result = 1;
1341
- }
1342
- if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
1343
- $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
1344
- }
1345
- }
1346
- if ($p_header['stored_filename'] == "") {
1347
- $p_header['status'] = "filtered";
1348
- }
1349
- if (strlen($p_header['stored_filename']) > 0xFF) {
1350
- $p_header['status'] = 'filename_too_long';
1351
- }
1352
- if ($p_header['status'] == 'ok') {
1353
- if ($p_filedescr['type'] == 'file') {
1354
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
1355
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
1356
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
1357
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
1358
- $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
1359
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
1360
- return $v_result;
1361
- }
1362
- }
1363
- else {
1364
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
1365
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
1366
- return PclZip::errorCode();
1367
- }
1368
- $v_content = @fread($v_file, $p_header['size']);
1369
- @fclose($v_file);
1370
- $p_header['crc'] = @crc32($v_content);
1371
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
1372
- $p_header['compressed_size'] = $p_header['size'];
1373
- $p_header['compression'] = 0;
1374
- }
1375
- else {
1376
- $v_content = @gzdeflate($v_content);
1377
- $p_header['compressed_size'] = strlen($v_content);
1378
- $p_header['compression'] = 8;
1379
- }
1380
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1381
- @fclose($v_file);
1382
- return $v_result;
1383
- }
1384
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
1385
- }
1386
- }
1387
- else if ($p_filedescr['type'] == 'virtual_file') {
1388
- $v_content = $p_filedescr['content'];
1389
- $p_header['crc'] = @crc32($v_content);
1390
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
1391
- $p_header['compressed_size'] = $p_header['size'];
1392
- $p_header['compression'] = 0;
1393
- }
1394
- else {
1395
- $v_content = @gzdeflate($v_content);
1396
- $p_header['compressed_size'] = strlen($v_content);
1397
- $p_header['compression'] = 8;
1398
- }
1399
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1400
- @fclose($v_file);
1401
- return $v_result;
1402
- }
1403
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
1404
- }
1405
- else if ($p_filedescr['type'] == 'folder') {
1406
- if (@substr($p_header['stored_filename'], -1) != '/') {
1407
- $p_header['stored_filename'] .= '/';
1408
- }
1409
- $p_header['size'] = 0;
1410
- $p_header['external'] = 0x00000010; // Value for a folder : to be checked
1411
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
1412
- {
1413
- return $v_result;
1414
- }
1415
- }
1416
- }
1417
- if (isset($p_options[PCLZIP_CB_POST_ADD])) {
1418
- $v_local_header = array();
1419
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
1420
- // eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
1421
- $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
1422
- if ($v_result == 0) {
1423
- $v_result = 1;
1424
- }
1425
- }
1426
- return $v_result;
1427
- }
1428
- function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
1429
- {
1430
- $v_result=PCLZIP_ERR_NO_ERROR;
1431
- $p_filename = $p_filedescr['filename'];
1432
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
1433
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
1434
- return PclZip::errorCode();
1435
- }
1436
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
1437
- if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
1438
- fclose($v_file);
1439
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
1440
- return PclZip::errorCode();
1441
- }
1442
- $v_size = filesize($p_filename);
1443
- while ($v_size != 0) {
1444
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1445
- $v_buffer = @fread($v_file, $v_read_size);
1446
- @gzputs($v_file_compressed, $v_buffer, $v_read_size);
1447
- $v_size -= $v_read_size;
1448
- }
1449
- @fclose($v_file);
1450
- @gzclose($v_file_compressed);
1451
- if (filesize($v_gzip_temp_name) < 18) {
1452
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
1453
- return PclZip::errorCode();
1454
- }
1455
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
1456
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
1457
- return PclZip::errorCode();
1458
- }
1459
- $v_binary_data = @fread($v_file_compressed, 10);
1460
- $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
1461
- $v_data_header['os'] = bin2hex($v_data_header['os']);
1462
- @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
1463
- $v_binary_data = @fread($v_file_compressed, 8);
1464
- $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
1465
- $p_header['compression'] = ord($v_data_header['cm']);
1466
- $p_header['crc'] = $v_data_footer['crc'];
1467
- $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
1468
- @fclose($v_file_compressed);
1469
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1470
- return $v_result;
1471
- }
1472
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
1473
- {
1474
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
1475
- return PclZip::errorCode();
1476
- }
1477
- fseek($v_file_compressed, 10);
1478
- $v_size = $p_header['compressed_size'];
1479
- while ($v_size != 0)
1480
- {
1481
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1482
- $v_buffer = @fread($v_file_compressed, $v_read_size);
1483
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
1484
- $v_size -= $v_read_size;
1485
- }
1486
- @fclose($v_file_compressed);
1487
- @unlink($v_gzip_temp_name);
1488
- return $v_result;
1489
- }
1490
- function privCalculateStoredFilename(&$p_filedescr, &$p_options)
1491
- {
1492
- $v_result=1;
1493
- $p_filename = $p_filedescr['filename'];
1494
- if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
1495
- $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
1496
- }
1497
- else {
1498
- $p_add_dir = '';
1499
- }
1500
- if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
1501
- $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
1502
- }
1503
- else {
1504
- $p_remove_dir = '';
1505
- }
1506
- if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
1507
- $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
1508
- }
1509
- else {
1510
- $p_remove_all_dir = 0;
1511
- }
1512
- if (isset($p_filedescr['new_full_name'])) {
1513
- $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
1514
- }
1515
- else {
1516
- if (isset($p_filedescr['new_short_name'])) {
1517
- $v_path_info = pathinfo($p_filename);
1518
- $v_dir = '';
1519
- if ($v_path_info['dirname'] != '') {
1520
- $v_dir = $v_path_info['dirname'].'/';
1521
- }
1522
- $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
1523
- }
1524
- else {
1525
- $v_stored_filename = $p_filename;
1526
- }
1527
- if ($p_remove_all_dir) {
1528
- $v_stored_filename = basename($p_filename);
1529
- }
1530
- else if ($p_remove_dir != "") {
1531
- if (substr($p_remove_dir, -1) != '/')
1532
- $p_remove_dir .= "/";
1533
- if ( (substr($p_filename, 0, 2) == "./")
1534
- || (substr($p_remove_dir, 0, 2) == "./")) {
1535
- if ( (substr($p_filename, 0, 2) == "./")
1536
- && (substr($p_remove_dir, 0, 2) != "./")) {
1537
- $p_remove_dir = "./".$p_remove_dir;
1538
- }
1539
- if ( (substr($p_filename, 0, 2) != "./")
1540
- && (substr($p_remove_dir, 0, 2) == "./")) {
1541
- $p_remove_dir = substr($p_remove_dir, 2);
1542
- }
1543
- }
1544
- $v_compare = PclZipUtilPathInclusion($p_remove_dir,
1545
- $v_stored_filename);
1546
- if ($v_compare > 0) {
1547
- if ($v_compare == 2) {
1548
- $v_stored_filename = "";
1549
- }
1550
- else {
1551
- $v_stored_filename = substr($v_stored_filename,
1552
- strlen($p_remove_dir));
1553
- }
1554
- }
1555
- }
1556
- $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
1557
- if ($p_add_dir != "") {
1558
- if (substr($p_add_dir, -1) == "/")
1559
- $v_stored_filename = $p_add_dir.$v_stored_filename;
1560
- else
1561
- $v_stored_filename = $p_add_dir."/".$v_stored_filename;
1562
- }
1563
- }
1564
- $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
1565
- $p_filedescr['stored_filename'] = $v_stored_filename;
1566
- return $v_result;
1567
- }
1568
- function privWriteFileHeader(&$p_header)
1569
- {
1570
- $v_result=1;
1571
- $p_header['offset'] = ftell($this->zip_fd);
1572
- $v_date = getdate($p_header['mtime']);
1573
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
1574
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
1575
- $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
1576
- $p_header['version_extracted'], $p_header['flag'],
1577
- $p_header['compression'], $v_mtime, $v_mdate,
1578
- $p_header['crc'], $p_header['compressed_size'],
1579
- $p_header['size'],
1580
- strlen($p_header['stored_filename']),
1581
- $p_header['extra_len']);
1582
- fputs($this->zip_fd, $v_binary_data, 30);
1583
- if (strlen($p_header['stored_filename']) != 0)
1584
- {
1585
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
1586
- }
1587
- if ($p_header['extra_len'] != 0)
1588
- {
1589
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
1590
- }
1591
- return $v_result;
1592
- }
1593
- function privWriteCentralFileHeader(&$p_header)
1594
- {
1595
- $v_result=1;
1596
- $v_date = getdate($p_header['mtime']);
1597
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
1598
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
1599
- $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
1600
- $p_header['version'], $p_header['version_extracted'],
1601
- $p_header['flag'], $p_header['compression'],
1602
- $v_mtime, $v_mdate, $p_header['crc'],
1603
- $p_header['compressed_size'], $p_header['size'],
1604
- strlen($p_header['stored_filename']),
1605
- $p_header['extra_len'], $p_header['comment_len'],
1606
- $p_header['disk'], $p_header['internal'],
1607
- $p_header['external'], $p_header['offset']);
1608
- fputs($this->zip_fd, $v_binary_data, 46);
1609
- if (strlen($p_header['stored_filename']) != 0)
1610
- {
1611
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
1612
- }
1613
- if ($p_header['extra_len'] != 0)
1614
- {
1615
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
1616
- }
1617
- if ($p_header['comment_len'] != 0)
1618
- {
1619
- fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
1620
- }
1621
- return $v_result;
1622
- }
1623
- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
1624
- {
1625
- $v_result=1;
1626
- $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
1627
- $p_nb_entries, $p_size,
1628
- $p_offset, strlen($p_comment));
1629
- fputs($this->zip_fd, $v_binary_data, 22);
1630
- if (strlen($p_comment) != 0)
1631
- {
1632
- fputs($this->zip_fd, $p_comment, strlen($p_comment));
1633
- }
1634
- return $v_result;
1635
- }
1636
- function privList(&$p_list)
1637
- {
1638
- $v_result=1;
1639
- $this->privDisableMagicQuotes();
1640
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
1641
- {
1642
- $this->privSwapBackMagicQuotes();
1643
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
1644
- return PclZip::errorCode();
1645
- }
1646
- $v_central_dir = array();
1647
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1648
- {
1649
- $this->privSwapBackMagicQuotes();
1650
- return $v_result;
1651
- }
1652
- @rewind($this->zip_fd);
1653
- if (@fseek($this->zip_fd, $v_central_dir['offset']))
1654
- {
1655
- $this->privSwapBackMagicQuotes();
1656
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1657
- return PclZip::errorCode();
1658
- }
1659
- for ($i=0; $i<$v_central_dir['entries']; $i++)
1660
- {
1661
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
1662
- {
1663
- $this->privSwapBackMagicQuotes();
1664
- return $v_result;
1665
- }
1666
- $v_header['index'] = $i;
1667
- $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
1668
- unset($v_header);
1669
- }
1670
- $this->privCloseFd();
1671
- $this->privSwapBackMagicQuotes();
1672
- return $v_result;
1673
- }
1674
- function privConvertHeader2FileInfo($p_header, &$p_info)
1675
- {
1676
- $v_result=1;
1677
- $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
1678
- $p_info['filename'] = $v_temp_path;
1679
- $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
1680
- $p_info['stored_filename'] = $v_temp_path;
1681
- $p_info['size'] = $p_header['size'];
1682
- $p_info['compressed_size'] = $p_header['compressed_size'];
1683
- $p_info['mtime'] = $p_header['mtime'];
1684
- $p_info['comment'] = $p_header['comment'];
1685
- $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
1686
- $p_info['index'] = $p_header['index'];
1687
- $p_info['status'] = $p_header['status'];
1688
- $p_info['crc'] = $p_header['crc'];
1689
- return $v_result;
1690
- }
1691
- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
1692
- {
1693
- $v_result=1;
1694
- $this->privDisableMagicQuotes();
1695
- if ( ($p_path == "")
1696
- || ( (substr($p_path, 0, 1) != "/")
1697
- && (substr($p_path, 0, 3) != "../")
1698
- && (substr($p_path,1,2)!=":/")))
1699
- $p_path = "./".$p_path;
1700
- if (($p_path != "./") && ($p_path != "/"))
1701
- {
1702
- while (substr($p_path, -1) == "/")
1703
- {
1704
- $p_path = substr($p_path, 0, strlen($p_path)-1);
1705
- }
1706
- }
1707
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
1708
- {
1709
- $p_remove_path .= '/';
1710
- }
1711
- $p_remove_path_size = strlen($p_remove_path);
1712
- if (($v_result = $this->privOpenFd('rb')) != 1)
1713
- {
1714
- $this->privSwapBackMagicQuotes();
1715
- return $v_result;
1716
- }
1717
- $v_central_dir = array();
1718
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1719
- {
1720
- $this->privCloseFd();
1721
- $this->privSwapBackMagicQuotes();
1722
- return $v_result;
1723
- }
1724
- $v_pos_entry = $v_central_dir['offset'];
1725
- $j_start = 0;
1726
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
1727
- {
1728
- @rewind($this->zip_fd);
1729
- if (@fseek($this->zip_fd, $v_pos_entry))
1730
- {
1731
- $this->privCloseFd();
1732
- $this->privSwapBackMagicQuotes();
1733
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1734
- return PclZip::errorCode();
1735
- }
1736
- $v_header = array();
1737
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
1738
- {
1739
- $this->privCloseFd();
1740
- $this->privSwapBackMagicQuotes();
1741
- return $v_result;
1742
- }
1743
- $v_header['index'] = $i;
1744
- $v_pos_entry = ftell($this->zip_fd);
1745
- $v_extract = false;
1746
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
1747
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
1748
- for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
1749
- if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
1750
- if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
1751
- && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
1752
- $v_extract = true;
1753
- }
1754
- }
1755
- elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
1756
- $v_extract = true;
1757
- }
1758
- }
1759
- }
1760
- /*
1761
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
1762
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
1763
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
1764
- $v_extract = true;
1765
- }
1766
- }
1767
- */
1768
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
1769
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
1770
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
1771
- $v_extract = true;
1772
- }
1773
- }
1774
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
1775
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
1776
- for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
1777
- if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
1778
- $v_extract = true;
1779
- }
1780
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
1781
- $j_start = $j+1;
1782
- }
1783
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
1784
- break;
1785
- }
1786
- }
1787
- }
1788
- else {
1789
- $v_extract = true;
1790
- }
1791
- // ----- Check compression method
1792
- if ( ($v_extract)
1793
- && ( ($v_header['compression'] != 8)
1794
- && ($v_header['compression'] != 0))) {
1795
- $v_header['status'] = 'unsupported_compression';
1796
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1797
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1798
- $this->privSwapBackMagicQuotes();
1799
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
1800
- "Filename '".$v_header['stored_filename']."' is "
1801
- ."compressed by an unsupported compression "
1802
- ."method (".$v_header['compression'].") ");
1803
- return PclZip::errorCode();
1804
- }
1805
- }
1806
- // ----- Check encrypted files
1807
- if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
1808
- $v_header['status'] = 'unsupported_encryption';
1809
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1810
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1811
- $this->privSwapBackMagicQuotes();
1812
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
1813
- "Unsupported encryption for "
1814
- ." filename '".$v_header['stored_filename']
1815
- ."'");
1816
- return PclZip::errorCode();
1817
- }
1818
- }
1819
- if (($v_extract) && ($v_header['status'] != 'ok')) {
1820
- $v_result = $this->privConvertHeader2FileInfo($v_header,
1821
- $p_file_list[$v_nb_extracted++]);
1822
- if ($v_result != 1) {
1823
- $this->privCloseFd();
1824
- $this->privSwapBackMagicQuotes();
1825
- return $v_result;
1826
- }
1827
- $v_extract = false;
1828
- }
1829
- if ($v_extract)
1830
- {
1831
- @rewind($this->zip_fd);
1832
- if (@fseek($this->zip_fd, $v_header['offset']))
1833
- {
1834
- $this->privCloseFd();
1835
- $this->privSwapBackMagicQuotes();
1836
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1837
- return PclZip::errorCode();
1838
- }
1839
- if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
1840
- $v_string = '';
1841
- $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
1842
- if ($v_result1 < 1) {
1843
- $this->privCloseFd();
1844
- $this->privSwapBackMagicQuotes();
1845
- return $v_result1;
1846
- }
1847
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
1848
- {
1849
- $this->privCloseFd();
1850
- $this->privSwapBackMagicQuotes();
1851
- return $v_result;
1852
- }
1853
- $p_file_list[$v_nb_extracted]['content'] = $v_string;
1854
- $v_nb_extracted++;
1855
- if ($v_result1 == 2) {
1856
- break;
1857
- }
1858
- }
1859
- elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
1860
- && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
1861
- $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
1862
- if ($v_result1 < 1) {
1863
- $this->privCloseFd();
1864
- $this->privSwapBackMagicQuotes();
1865
- return $v_result1;
1866
- }
1867
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
1868
- $this->privCloseFd();
1869
- $this->privSwapBackMagicQuotes();
1870
- return $v_result;
1871
- }
1872
- if ($v_result1 == 2) {
1873
- break;
1874
- }
1875
- }
1876
- else {
1877
- $v_result1 = $this->privExtractFile($v_header,
1878
- $p_path, $p_remove_path,
1879
- $p_remove_all_path,
1880
- $p_options);
1881
- if ($v_result1 < 1) {
1882
- $this->privCloseFd();
1883
- $this->privSwapBackMagicQuotes();
1884
- return $v_result1;
1885
- }
1886
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
1887
- {
1888
- $this->privCloseFd();
1889
- $this->privSwapBackMagicQuotes();
1890
- return $v_result;
1891
- }
1892
- if ($v_result1 == 2) {
1893
- break;
1894
- }
1895
- }
1896
- }
1897
- }
1898
- $this->privCloseFd();
1899
- $this->privSwapBackMagicQuotes();
1900
- return $v_result;
1901
- }
1902
- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
1903
- {
1904
- $v_result=1;
1905
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
1906
- {
1907
- return $v_result;
1908
- }
1909
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
1910
- }
1911
- if ($p_remove_all_path == true) {
1912
- if (($p_entry['external']&0x00000010)==0x00000010) {
1913
- $p_entry['status'] = "filtered";
1914
- return $v_result;
1915
- }
1916
- $p_entry['filename'] = basename($p_entry['filename']);
1917
- }
1918
- else if ($p_remove_path != "")
1919
- {
1920
- if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
1921
- {
1922
- $p_entry['status'] = "filtered";
1923
- return $v_result;
1924
- }
1925
- $p_remove_path_size = strlen($p_remove_path);
1926
- if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
1927
- {
1928
- $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
1929
- }
1930
- }
1931
- if ($p_path != '') {
1932
- $p_entry['filename'] = $p_path."/".$p_entry['filename'];
1933
- }
1934
- if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
1935
- $v_inclusion
1936
- = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
1937
- $p_entry['filename']);
1938
- if ($v_inclusion == 0) {
1939
- PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
1940
- "Filename '".$p_entry['filename']."' is "
1941
- ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
1942
- return PclZip::errorCode();
1943
- }
1944
- }
1945
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
1946
- $v_local_header = array();
1947
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
1948
- // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
1949
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
1950
- if ($v_result == 0) {
1951
- $p_entry['status'] = "skipped";
1952
- $v_result = 1;
1953
- }
1954
- if ($v_result == 2) {
1955
- $p_entry['status'] = "aborted";
1956
- $v_result = PCLZIP_ERR_USER_ABORTED;
1957
- }
1958
- $p_entry['filename'] = $v_local_header['filename'];
1959
- }
1960
- if ($p_entry['status'] == 'ok') {
1961
- if (file_exists($p_entry['filename']))
1962
- {
1963
- if (is_dir($p_entry['filename']))
1964
- {
1965
- $p_entry['status'] = "already_a_directory";
1966
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1967
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1968
- PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
1969
- "Filename '".$p_entry['filename']."' is "
1970
- ."already used by an existing directory");
1971
- return PclZip::errorCode();
1972
- }
1973
- }
1974
- else if (!is_writeable($p_entry['filename']))
1975
- {
1976
- $p_entry['status'] = "write_protected";
1977
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1978
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1979
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
1980
- "Filename '".$p_entry['filename']."' exists "
1981
- ."and is write protected");
1982
- return PclZip::errorCode();
1983
- }
1984
- }
1985
- else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
1986
- {
1987
- if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
1988
- && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
1989
- }
1990
- else {
1991
- $p_entry['status'] = "newer_exist";
1992
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1993
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1994
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
1995
- "Newer version of '".$p_entry['filename']."' exists "
1996
- ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
1997
- return PclZip::errorCode();
1998
- }
1999
- }
2000
- }
2001
- else {
2002
- }
2003
- }
2004
- else {
2005
- if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
2006
- $v_dir_to_check = $p_entry['filename'];
2007
- else if (!strstr($p_entry['filename'], "/"))
2008
- $v_dir_to_check = "";
2009
- else
2010
- $v_dir_to_check = dirname($p_entry['filename']);
2011
- if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
2012
- $p_entry['status'] = "path_creation_fail";
2013
- $v_result = 1;
2014
- }
2015
- }
2016
- }
2017
- if ($p_entry['status'] == 'ok') {
2018
- if (!(($p_entry['external']&0x00000010)==0x00000010))
2019
- {
2020
- if ($p_entry['compression'] == 0) {
2021
- // ----- Opening destination file
2022
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
2023
- {
2024
- $p_entry['status'] = "write_error";
2025
- return $v_result;
2026
- }
2027
- $v_size = $p_entry['compressed_size'];
2028
- while ($v_size != 0)
2029
- {
2030
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2031
- $v_buffer = @fread($this->zip_fd, $v_read_size);
2032
- /* Try to speed up the code
2033
- $v_binary_data = pack('a'.$v_read_size, $v_buffer);
2034
- @fwrite($v_dest_file, $v_binary_data, $v_read_size);
2035
- */
2036
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
2037
- $v_size -= $v_read_size;
2038
- }
2039
- fclose($v_dest_file);
2040
- touch($p_entry['filename'], $p_entry['mtime']);
2041
- }
2042
- else {
2043
- if (($p_entry['flag'] & 1) == 1) {
2044
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
2045
- return PclZip::errorCode();
2046
- }
2047
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
2048
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
2049
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
2050
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
2051
- $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
2052
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
2053
- return $v_result;
2054
- }
2055
- }
2056
- else {
2057
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2058
- $v_file_content = @gzinflate($v_buffer);
2059
- unset($v_buffer);
2060
- if ($v_file_content === FALSE) {
2061
- $p_entry['status'] = "error";
2062
- return $v_result;
2063
- }
2064
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
2065
- $p_entry['status'] = "write_error";
2066
- return $v_result;
2067
- }
2068
- @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
2069
- unset($v_file_content);
2070
- @fclose($v_dest_file);
2071
- }
2072
- @touch($p_entry['filename'], $p_entry['mtime']);
2073
- }
2074
- if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
2075
- @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
2076
- }
2077
- }
2078
- }
2079
- // ----- Change abort status
2080
- if ($p_entry['status'] == "aborted") {
2081
- $p_entry['status'] = "skipped";
2082
- }
2083
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2084
- $v_local_header = array();
2085
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2086
- // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2087
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2088
- if ($v_result == 2) {
2089
- $v_result = PCLZIP_ERR_USER_ABORTED;
2090
- }
2091
- }
2092
- return $v_result;
2093
- }
2094
- function privExtractFileUsingTempFile(&$p_entry, &$p_options)
2095
- {
2096
- $v_result=1;
2097
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
2098
- if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
2099
- fclose($v_file);
2100
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
2101
- return PclZip::errorCode();
2102
- }
2103
- $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
2104
- @fwrite($v_dest_file, $v_binary_data, 10);
2105
- $v_size = $p_entry['compressed_size'];
2106
- while ($v_size != 0)
2107
- {
2108
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2109
- $v_buffer = @fread($this->zip_fd, $v_read_size);
2110
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
2111
- $v_size -= $v_read_size;
2112
- }
2113
- $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
2114
- @fwrite($v_dest_file, $v_binary_data, 8);
2115
- @fclose($v_dest_file);
2116
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
2117
- $p_entry['status'] = "write_error";
2118
- return $v_result;
2119
- }
2120
- if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
2121
- @fclose($v_dest_file);
2122
- $p_entry['status'] = "read_error";
2123
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
2124
- return PclZip::errorCode();
2125
- }
2126
- $v_size = $p_entry['size'];
2127
- while ($v_size != 0) {
2128
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2129
- $v_buffer = @gzread($v_src_file, $v_read_size);
2130
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
2131
- $v_size -= $v_read_size;
2132
- }
2133
- @fclose($v_dest_file);
2134
- @gzclose($v_src_file);
2135
- @unlink($v_gzip_temp_name);
2136
- return $v_result;
2137
- }
2138
- function privExtractFileInOutput(&$p_entry, &$p_options)
2139
- {
2140
- $v_result=1;
2141
- if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
2142
- return $v_result;
2143
- }
2144
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
2145
- }
2146
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
2147
- $v_local_header = array();
2148
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2149
- // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
2150
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
2151
- if ($v_result == 0) {
2152
- $p_entry['status'] = "skipped";
2153
- $v_result = 1;
2154
- }
2155
- if ($v_result == 2) {
2156
- $p_entry['status'] = "aborted";
2157
- $v_result = PCLZIP_ERR_USER_ABORTED;
2158
- }
2159
- $p_entry['filename'] = $v_local_header['filename'];
2160
- }
2161
- if ($p_entry['status'] == 'ok') {
2162
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
2163
- if ($p_entry['compressed_size'] == $p_entry['size']) {
2164
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2165
- echo $v_buffer;
2166
- unset($v_buffer);
2167
- }
2168
- else {
2169
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2170
- $v_file_content = gzinflate($v_buffer);
2171
- unset($v_buffer);
2172
- echo $v_file_content;
2173
- unset($v_file_content);
2174
- }
2175
- }
2176
- }
2177
- // ----- Change abort status
2178
- if ($p_entry['status'] == "aborted") {
2179
- $p_entry['status'] = "skipped";
2180
- }
2181
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2182
- $v_local_header = array();
2183
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2184
- // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2185
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2186
- if ($v_result == 2) {
2187
- $v_result = PCLZIP_ERR_USER_ABORTED;
2188
- }
2189
- }
2190
- return $v_result;
2191
- }
2192
- function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
2193
- {
2194
- $v_result=1;
2195
- $v_header = array();
2196
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
2197
- {
2198
- return $v_result;
2199
- }
2200
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
2201
- }
2202
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
2203
- $v_local_header = array();
2204
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2205
- // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
2206
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
2207
- if ($v_result == 0) {
2208
- $p_entry['status'] = "skipped";
2209
- $v_result = 1;
2210
- }
2211
- if ($v_result == 2) {
2212
- $p_entry['status'] = "aborted";
2213
- $v_result = PCLZIP_ERR_USER_ABORTED;
2214
- }
2215
- $p_entry['filename'] = $v_local_header['filename'];
2216
- }
2217
- if ($p_entry['status'] == 'ok') {
2218
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
2219
- if ($p_entry['compression'] == 0) {
2220
- $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
2221
- }
2222
- else {
2223
- $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
2224
- if (($p_string = @gzinflate($v_data)) === FALSE) {
2225
- }
2226
- }
2227
- }
2228
- else {
2229
- }
2230
- }
2231
- // ----- Change abort status
2232
- if ($p_entry['status'] == "aborted") {
2233
- $p_entry['status'] = "skipped";
2234
- }
2235
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2236
- $v_local_header = array();
2237
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2238
- $v_local_header['content'] = $p_string;
2239
- $p_string = '';
2240
- // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2241
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2242
- $p_string = $v_local_header['content'];
2243
- unset($v_local_header['content']);
2244
- if ($v_result == 2) {
2245
- $v_result = PCLZIP_ERR_USER_ABORTED;
2246
- }
2247
- }
2248
- return $v_result;
2249
- }
2250
- function privReadFileHeader(&$p_header)
2251
- {
2252
- $v_result=1;
2253
- $v_binary_data = @fread($this->zip_fd, 4);
2254
- $v_data = unpack('Vid', $v_binary_data);
2255
- if ($v_data['id'] != 0x04034b50)
2256
- {
2257
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
2258
- return PclZip::errorCode();
2259
- }
2260
- $v_binary_data = fread($this->zip_fd, 26);
2261
- if (strlen($v_binary_data) != 26)
2262
- {
2263
- $p_header['filename'] = "";
2264
- $p_header['status'] = "invalid_header";
2265
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
2266
- return PclZip::errorCode();
2267
- }
2268
- $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
2269
- $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
2270
- if ($v_data['extra_len'] != 0) {
2271
- $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
2272
- }
2273
- else {
2274
- $p_header['extra'] = '';
2275
- }
2276
- $p_header['version_extracted'] = $v_data['version'];
2277
- $p_header['compression'] = $v_data['compression'];
2278
- $p_header['size'] = $v_data['size'];
2279
- $p_header['compressed_size'] = $v_data['compressed_size'];
2280
- $p_header['crc'] = $v_data['crc'];
2281
- $p_header['flag'] = $v_data['flag'];
2282
- $p_header['filename_len'] = $v_data['filename_len'];
2283
- $p_header['mdate'] = $v_data['mdate'];
2284
- $p_header['mtime'] = $v_data['mtime'];
2285
- if ($p_header['mdate'] && $p_header['mtime'])
2286
- {
2287
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
2288
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
2289
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
2290
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
2291
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
2292
- $v_day = $p_header['mdate'] & 0x001F;
2293
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
2294
- }
2295
- else
2296
- {
2297
- $p_header['mtime'] = time();
2298
- }
2299
- $p_header['stored_filename'] = $p_header['filename'];
2300
- $p_header['status'] = "ok";
2301
- return $v_result;
2302
- }
2303
- function privReadCentralFileHeader(&$p_header)
2304
- {
2305
- $v_result=1;
2306
- $v_binary_data = @fread($this->zip_fd, 4);
2307
- $v_data = unpack('Vid', $v_binary_data);
2308
- if ($v_data['id'] != 0x02014b50)
2309
- {
2310
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
2311
- return PclZip::errorCode();
2312
- }
2313
- $v_binary_data = fread($this->zip_fd, 42);
2314
- if (strlen($v_binary_data) != 42)
2315
- {
2316
- $p_header['filename'] = "";
2317
- $p_header['status'] = "invalid_header";
2318
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
2319
- return PclZip::errorCode();
2320
- }
2321
- $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
2322
- if ($p_header['filename_len'] != 0)
2323
- $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
2324
- else
2325
- $p_header['filename'] = '';
2326
- if ($p_header['extra_len'] != 0)
2327
- $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
2328
- else
2329
- $p_header['extra'] = '';
2330
- if ($p_header['comment_len'] != 0)
2331
- $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
2332
- else
2333
- $p_header['comment'] = '';
2334
- if (1)
2335
- {
2336
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
2337
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
2338
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
2339
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
2340
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
2341
- $v_day = $p_header['mdate'] & 0x001F;
2342
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
2343
- }
2344
- else
2345
- {
2346
- $p_header['mtime'] = time();
2347
- }
2348
- $p_header['stored_filename'] = $p_header['filename'];
2349
- $p_header['status'] = 'ok';
2350
- if (substr($p_header['filename'], -1) == '/') {
2351
- $p_header['external'] = 0x00000010;
2352
- }
2353
- return $v_result;
2354
- }
2355
- function privCheckFileHeaders(&$p_local_header, &$p_central_header)
2356
- {
2357
- $v_result=1;
2358
- // ----- Check the static values
2359
- // TBC
2360
- if ($p_local_header['filename'] != $p_central_header['filename']) {
2361
- }
2362
- if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
2363
- }
2364
- if ($p_local_header['flag'] != $p_central_header['flag']) {
2365
- }
2366
- if ($p_local_header['compression'] != $p_central_header['compression']) {
2367
- }
2368
- if ($p_local_header['mtime'] != $p_central_header['mtime']) {
2369
- }
2370
- if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
2371
- }
2372
- // ----- Look for flag bit 3
2373
- if (($p_local_header['flag'] & 8) == 8) {
2374
- $p_local_header['size'] = $p_central_header['size'];
2375
- $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
2376
- $p_local_header['crc'] = $p_central_header['crc'];
2377
- }
2378
- return $v_result;
2379
- }
2380
- function privReadEndCentralDir(&$p_central_dir)
2381
- {
2382
- $v_result=1;
2383
- $v_size = filesize($this->zipname);
2384
- @fseek($this->zip_fd, $v_size);
2385
- if (@ftell($this->zip_fd) != $v_size)
2386
- {
2387
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
2388
- return PclZip::errorCode();
2389
- }
2390
- $v_found = 0;
2391
- if ($v_size > 26) {
2392
- @fseek($this->zip_fd, $v_size-22);
2393
- if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
2394
- {
2395
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
2396
- return PclZip::errorCode();
2397
- }
2398
- $v_binary_data = @fread($this->zip_fd, 4);
2399
- $v_data = @unpack('Vid', $v_binary_data);
2400
- if ($v_data['id'] == 0x06054b50) {
2401
- $v_found = 1;
2402
- }
2403
- $v_pos = ftell($this->zip_fd);
2404
- }
2405
- if (!$v_found) {
2406
- $v_maximum_size = 65557; // 0xFFFF + 22;
2407
- if ($v_maximum_size > $v_size)
2408
- $v_maximum_size = $v_size;
2409
- @fseek($this->zip_fd, $v_size-$v_maximum_size);
2410
- if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
2411
- {
2412
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
2413
- return PclZip::errorCode();
2414
- }
2415
- $v_pos = ftell($this->zip_fd);
2416
- $v_bytes = 0x00000000;
2417
- while ($v_pos < $v_size)
2418
- {
2419
- $v_byte = @fread($this->zip_fd, 1);
2420
- $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
2421
- if ($v_bytes == 0x504b0506)
2422
- {
2423
- $v_pos++;
2424
- break;
2425
- }
2426
- $v_pos++;
2427
- }
2428
- if ($v_pos == $v_size)
2429
- {
2430
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
2431
- return PclZip::errorCode();
2432
- }
2433
- }
2434
- $v_binary_data = fread($this->zip_fd, 18);
2435
- if (strlen($v_binary_data) != 18)
2436
- {
2437
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
2438
- return PclZip::errorCode();
2439
- }
2440
- $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
2441
- if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
2442
- // ----- Removed in release 2.2 see readme file
2443
- // The check of the file size is a little too strict.
2444
- // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
2445
- // While decrypted, zip has training 0 bytes
2446
- if (0) {
2447
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
2448
- 'The central dir is not at the end of the archive.'
2449
- .' Some trailing bytes exists after the archive.');
2450
- return PclZip::errorCode();
2451
- }
2452
- }
2453
- if ($v_data['comment_size'] != 0) {
2454
- $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
2455
- }
2456
- else
2457
- $p_central_dir['comment'] = '';
2458
- $p_central_dir['entries'] = $v_data['entries'];
2459
- $p_central_dir['disk_entries'] = $v_data['disk_entries'];
2460
- $p_central_dir['offset'] = $v_data['offset'];
2461
- $p_central_dir['size'] = $v_data['size'];
2462
- $p_central_dir['disk'] = $v_data['disk'];
2463
- $p_central_dir['disk_start'] = $v_data['disk_start'];
2464
- return $v_result;
2465
- }
2466
- function privDeleteByRule(&$p_result_list, &$p_options)
2467
- {
2468
- $v_result=1;
2469
- $v_list_detail = array();
2470
- if (($v_result=$this->privOpenFd('rb')) != 1)
2471
- {
2472
- return $v_result;
2473
- }
2474
- $v_central_dir = array();
2475
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
2476
- {
2477
- $this->privCloseFd();
2478
- return $v_result;
2479
- }
2480
- @rewind($this->zip_fd);
2481
- $v_pos_entry = $v_central_dir['offset'];
2482
- @rewind($this->zip_fd);
2483
- if (@fseek($this->zip_fd, $v_pos_entry))
2484
- {
2485
- $this->privCloseFd();
2486
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
2487
- return PclZip::errorCode();
2488
- }
2489
- $v_header_list = array();
2490
- $j_start = 0;
2491
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
2492
- {
2493
- $v_header_list[$v_nb_extracted] = array();
2494
- if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
2495
- {
2496
- $this->privCloseFd();
2497
- return $v_result;
2498
- }
2499
- $v_header_list[$v_nb_extracted]['index'] = $i;
2500
- $v_found = false;
2501
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
2502
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
2503
- for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
2504
- if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
2505
- if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
2506
- && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
2507
- $v_found = true;
2508
- }
2509
- elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
2510
- && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
2511
- $v_found = true;
2512
- }
2513
- }
2514
- elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
2515
- $v_found = true;
2516
- }
2517
- }
2518
- }
2519
- /*
2520
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
2521
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
2522
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
2523
- $v_found = true;
2524
- }
2525
- }
2526
- */
2527
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
2528
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
2529
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
2530
- $v_found = true;
2531
- }
2532
- }
2533
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
2534
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
2535
- for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
2536
- if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
2537
- $v_found = true;
2538
- }
2539
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
2540
- $j_start = $j+1;
2541
- }
2542
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
2543
- break;
2544
- }
2545
- }
2546
- }
2547
- else {
2548
- $v_found = true;
2549
- }
2550
- if ($v_found)
2551
- {
2552
- unset($v_header_list[$v_nb_extracted]);
2553
- }
2554
- else
2555
- {
2556
- $v_nb_extracted++;
2557
- }
2558
- }
2559
- if ($v_nb_extracted > 0) {
2560
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
2561
- $v_temp_zip = new PclZip($v_zip_temp_name);
2562
- if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
2563
- $this->privCloseFd();
2564
- return $v_result;
2565
- }
2566
- for ($i=0; $i<sizeof($v_header_list); $i++) {
2567
- @rewind($this->zip_fd);
2568
- if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
2569
- $this->privCloseFd();
2570
- $v_temp_zip->privCloseFd();
2571
- @unlink($v_zip_temp_name);
2572
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
2573
- return PclZip::errorCode();
2574
- }
2575
- $v_local_header = array();
2576
- if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
2577
- $this->privCloseFd();
2578
- $v_temp_zip->privCloseFd();
2579
- @unlink($v_zip_temp_name);
2580
- return $v_result;
2581
- }
2582
- if ($this->privCheckFileHeaders($v_local_header,
2583
- $v_header_list[$i]) != 1) {
2584
- }
2585
- unset($v_local_header);
2586
- if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
2587
- $this->privCloseFd();
2588
- $v_temp_zip->privCloseFd();
2589
- @unlink($v_zip_temp_name);
2590
- return $v_result;
2591
- }
2592
- if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
2593
- $this->privCloseFd();
2594
- $v_temp_zip->privCloseFd();
2595
- @unlink($v_zip_temp_name);
2596
- return $v_result;
2597
- }
2598
- }
2599
- $v_offset = @ftell($v_temp_zip->zip_fd);
2600
- for ($i=0; $i<sizeof($v_header_list); $i++) {
2601
- if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
2602
- $v_temp_zip->privCloseFd();
2603
- $this->privCloseFd();
2604
- @unlink($v_zip_temp_name);
2605
- return $v_result;
2606
- }
2607
- $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
2608
- }
2609
- $v_comment = '';
2610
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
2611
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
2612
- }
2613
- $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
2614
- if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
2615
- unset($v_header_list);
2616
- $v_temp_zip->privCloseFd();
2617
- $this->privCloseFd();
2618
- @unlink($v_zip_temp_name);
2619
- return $v_result;
2620
- }
2621
- $v_temp_zip->privCloseFd();
2622
- $this->privCloseFd();
2623
- @unlink($this->zipname);
2624
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
2625
- unset($v_temp_zip);
2626
- }
2627
- else if ($v_central_dir['entries'] != 0) {
2628
- $this->privCloseFd();
2629
- if (($v_result = $this->privOpenFd('wb')) != 1) {
2630
- return $v_result;
2631
- }
2632
- if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
2633
- return $v_result;
2634
- }
2635
- $this->privCloseFd();
2636
- }
2637
- return $v_result;
2638
- }
2639
- function privDirCheck($p_dir, $p_is_dir=false)
2640
- {
2641
- $v_result = 1;
2642
- if (($p_is_dir) && (substr($p_dir, -1)=='/'))
2643
- {
2644
- $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
2645
- }
2646
- if ((is_dir($p_dir)) || ($p_dir == ""))
2647
- {
2648
- return 1;
2649
- }
2650
- $p_parent_dir = dirname($p_dir);
2651
- if ($p_parent_dir != $p_dir)
2652
- {
2653
- if ($p_parent_dir != "")
2654
- {
2655
- if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
2656
- {
2657
- return $v_result;
2658
- }
2659
- }
2660
- }
2661
- if (!@mkdir($p_dir, 0777))
2662
- {
2663
- PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
2664
- return PclZip::errorCode();
2665
- }
2666
- return $v_result;
2667
- }
2668
- function privMerge(&$p_archive_to_add)
2669
- {
2670
- $v_result=1;
2671
- if (!is_file($p_archive_to_add->zipname))
2672
- {
2673
- $v_result = 1;
2674
- return $v_result;
2675
- }
2676
- if (!is_file($this->zipname))
2677
- {
2678
- $v_result = $this->privDuplicate($p_archive_to_add->zipname);
2679
- return $v_result;
2680
- }
2681
- if (($v_result=$this->privOpenFd('rb')) != 1)
2682
- {
2683
- return $v_result;
2684
- }
2685
- $v_central_dir = array();
2686
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
2687
- {
2688
- $this->privCloseFd();
2689
- return $v_result;
2690
- }
2691
- @rewind($this->zip_fd);
2692
- if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
2693
- {
2694
- $this->privCloseFd();
2695
- return $v_result;
2696
- }
2697
- $v_central_dir_to_add = array();
2698
- if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
2699
- {
2700
- $this->privCloseFd();
2701
- $p_archive_to_add->privCloseFd();
2702
- return $v_result;
2703
- }
2704
- @rewind($p_archive_to_add->zip_fd);
2705
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
2706
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
2707
- {
2708
- $this->privCloseFd();
2709
- $p_archive_to_add->privCloseFd();
2710
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
2711
- return PclZip::errorCode();
2712
- }
2713
- $v_size = $v_central_dir['offset'];
2714
- while ($v_size != 0)
2715
- {
2716
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2717
- $v_buffer = fread($this->zip_fd, $v_read_size);
2718
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2719
- $v_size -= $v_read_size;
2720
- }
2721
- $v_size = $v_central_dir_to_add['offset'];
2722
- while ($v_size != 0)
2723
- {
2724
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2725
- $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
2726
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2727
- $v_size -= $v_read_size;
2728
- }
2729
- $v_offset = @ftell($v_zip_temp_fd);
2730
- $v_size = $v_central_dir['size'];
2731
- while ($v_size != 0)
2732
- {
2733
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2734
- $v_buffer = @fread($this->zip_fd, $v_read_size);
2735
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2736
- $v_size -= $v_read_size;
2737
- }
2738
- $v_size = $v_central_dir_to_add['size'];
2739
- while ($v_size != 0)
2740
- {
2741
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2742
- $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
2743
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2744
- $v_size -= $v_read_size;
2745
- }
2746
- $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
2747
- $v_size = @ftell($v_zip_temp_fd)-$v_offset;
2748
- $v_swap = $this->zip_fd;
2749
- $this->zip_fd = $v_zip_temp_fd;
2750
- $v_zip_temp_fd = $v_swap;
2751
- if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
2752
- {
2753
- $this->privCloseFd();
2754
- $p_archive_to_add->privCloseFd();
2755
- @fclose($v_zip_temp_fd);
2756
- $this->zip_fd = null;
2757
- unset($v_header_list);
2758
- return $v_result;
2759
- }
2760
- $v_swap = $this->zip_fd;
2761
- $this->zip_fd = $v_zip_temp_fd;
2762
- $v_zip_temp_fd = $v_swap;
2763
- $this->privCloseFd();
2764
- $p_archive_to_add->privCloseFd();
2765
- @fclose($v_zip_temp_fd);
2766
- @unlink($this->zipname);
2767
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
2768
- return $v_result;
2769
- }
2770
- function privDuplicate($p_archive_filename)
2771
- {
2772
- $v_result=1;
2773
- if (!is_file($p_archive_filename))
2774
- {
2775
- $v_result = 1;
2776
- return $v_result;
2777
- }
2778
- if (($v_result=$this->privOpenFd('wb')) != 1)
2779
- {
2780
- return $v_result;
2781
- }
2782
- if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
2783
- {
2784
- $this->privCloseFd();
2785
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
2786
- return PclZip::errorCode();
2787
- }
2788
- $v_size = filesize($p_archive_filename);
2789
- while ($v_size != 0)
2790
- {
2791
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2792
- $v_buffer = fread($v_zip_temp_fd, $v_read_size);
2793
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
2794
- $v_size -= $v_read_size;
2795
- }
2796
- $this->privCloseFd();
2797
- @fclose($v_zip_temp_fd);
2798
- return $v_result;
2799
- }
2800
- function privErrorLog($p_error_code=0, $p_error_string='')
2801
- {
2802
- if (PCLZIP_ERROR_EXTERNAL == 1) {
2803
- PclError($p_error_code, $p_error_string);
2804
- }
2805
- else {
2806
- $this->error_code = $p_error_code;
2807
- $this->error_string = $p_error_string;
2808
- }
2809
- }
2810
- function privErrorReset()
2811
- {
2812
- if (PCLZIP_ERROR_EXTERNAL == 1) {
2813
- PclErrorReset();
2814
- }
2815
- else {
2816
- $this->error_code = 0;
2817
- $this->error_string = '';
2818
- }
2819
- }
2820
- function privDisableMagicQuotes()
2821
- {
2822
- $v_result=1;
2823
- if ( (!function_exists("get_magic_quotes_runtime"))
2824
- || (!function_exists("set_magic_quotes_runtime"))) {
2825
- return $v_result;
2826
- }
2827
- if ($this->magic_quotes_status != -1) {
2828
- return $v_result;
2829
- }
2830
- // ----- Get and memorize the magic_quote value
2831
- $this->magic_quotes_status = @get_magic_quotes_runtime();
2832
- // ----- Disable magic_quotes
2833
- if ($this->magic_quotes_status == 1) {
2834
- @set_magic_quotes_runtime(0);
2835
- }
2836
- return $v_result;
2837
- }
2838
- function privSwapBackMagicQuotes()
2839
- {
2840
- $v_result=1;
2841
- if ( (!function_exists("get_magic_quotes_runtime"))
2842
- || (!function_exists("set_magic_quotes_runtime"))) {
2843
- return $v_result;
2844
- }
2845
- if ($this->magic_quotes_status != -1) {
2846
- return $v_result;
2847
- }
2848
- // ----- Swap back magic_quotes
2849
- if ($this->magic_quotes_status == 1) {
2850
- @set_magic_quotes_runtime($this->magic_quotes_status);
2851
- }
2852
- return $v_result;
2853
- }
2854
- }
2855
- function PclZipUtilPathReduction($p_dir)
2856
- {
2857
- $v_result = "";
2858
- if ($p_dir != "") {
2859
- $v_list = explode("/", $p_dir);
2860
- $v_skip = 0;
2861
- for ($i=sizeof($v_list)-1; $i>=0; $i--) {
2862
- if ($v_list[$i] == ".") {
2863
- }
2864
- else if ($v_list[$i] == "..") {
2865
- $v_skip++;
2866
- }
2867
- else if ($v_list[$i] == "") {
2868
- // ----- First '/' i.e. root slash
2869
- if ($i == 0) {
2870
- $v_result = "/".$v_result;
2871
- if ($v_skip > 0) {
2872
- // ----- It is an invalid path, so the path is not modified
2873
- // TBC
2874
- $v_result = $p_dir;
2875
- $v_skip = 0;
2876
- }
2877
- }
2878
- // ----- Last '/' i.e. indicates a directory
2879
- else if ($i == (sizeof($v_list)-1)) {
2880
- $v_result = $v_list[$i];
2881
- }
2882
- // ----- Double '/' inside the path
2883
- else {
2884
- }
2885
- }
2886
- else {
2887
- // ----- Look for item to skip
2888
- if ($v_skip > 0) {
2889
- $v_skip--;
2890
- }
2891
- else {
2892
- $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
2893
- }
2894
- }
2895
- }
2896
- if ($v_skip > 0) {
2897
- while ($v_skip > 0) {
2898
- $v_result = '../'.$v_result;
2899
- $v_skip--;
2900
- }
2901
- }
2902
- }
2903
- return $v_result;
2904
- }
2905
- function PclZipUtilPathInclusion($p_dir, $p_path)
2906
- {
2907
- $v_result = 1;
2908
- if ( ($p_dir == '.')
2909
- || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
2910
- $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
2911
- }
2912
- if ( ($p_path == '.')
2913
- || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
2914
- $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
2915
- }
2916
- $v_list_dir = explode("/", $p_dir);
2917
- $v_list_dir_size = sizeof($v_list_dir);
2918
- $v_list_path = explode("/", $p_path);
2919
- $v_list_path_size = sizeof($v_list_path);
2920
- $i = 0;
2921
- $j = 0;
2922
- while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
2923
- if ($v_list_dir[$i] == '') {
2924
- $i++;
2925
- continue;
2926
- }
2927
- if ($v_list_path[$j] == '') {
2928
- $j++;
2929
- continue;
2930
- }
2931
- if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
2932
- $v_result = 0;
2933
- }
2934
- $i++;
2935
- $j++;
2936
- }
2937
- if ($v_result) {
2938
- while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
2939
- while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
2940
- if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
2941
- $v_result = 2;
2942
- }
2943
- else if ($i < $v_list_dir_size) {
2944
- $v_result = 0;
2945
- }
2946
- }
2947
- return $v_result;
2948
- }
2949
- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
2950
- {
2951
- $v_result = 1;
2952
- if ($p_mode==0)
2953
- {
2954
- while ($p_size != 0)
2955
- {
2956
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2957
- $v_buffer = @fread($p_src, $v_read_size);
2958
- @fwrite($p_dest, $v_buffer, $v_read_size);
2959
- $p_size -= $v_read_size;
2960
- }
2961
- }
2962
- else if ($p_mode==1)
2963
- {
2964
- while ($p_size != 0)
2965
- {
2966
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2967
- $v_buffer = @gzread($p_src, $v_read_size);
2968
- @fwrite($p_dest, $v_buffer, $v_read_size);
2969
- $p_size -= $v_read_size;
2970
- }
2971
- }
2972
- else if ($p_mode==2)
2973
- {
2974
- while ($p_size != 0)
2975
- {
2976
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2977
- $v_buffer = @fread($p_src, $v_read_size);
2978
- @gzwrite($p_dest, $v_buffer, $v_read_size);
2979
- $p_size -= $v_read_size;
2980
- }
2981
- }
2982
- else if ($p_mode==3)
2983
- {
2984
- while ($p_size != 0)
2985
- {
2986
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2987
- $v_buffer = @gzread($p_src, $v_read_size);
2988
- @gzwrite($p_dest, $v_buffer, $v_read_size);
2989
- $p_size -= $v_read_size;
2990
- }
2991
- }
2992
- return $v_result;
2993
- }
2994
- function PclZipUtilRename($p_src, $p_dest)
2995
- {
2996
- $v_result = 1;
2997
- if (!@rename($p_src, $p_dest)) {
2998
- if (!@copy($p_src, $p_dest)) {
2999
- $v_result = 0;
3000
- }
3001
- else if (!@unlink($p_src)) {
3002
- $v_result = 0;
3003
- }
3004
- }
3005
- return $v_result;
3006
- }
3007
- function PclZipUtilOptionText($p_option)
3008
- {
3009
- $v_list = get_defined_constants();
3010
- for (reset($v_list); $v_key = key($v_list); next($v_list)) {
3011
- $v_prefix = substr($v_key, 0, 10);
3012
- if (( ($v_prefix == 'PCLZIP_OPT')
3013
- || ($v_prefix == 'PCLZIP_CB_')
3014
- || ($v_prefix == 'PCLZIP_ATT'))
3015
- && ($v_list[$v_key] == $p_option)) {
3016
- return $v_key;
3017
- }
3018
- }
3019
- $v_result = 'Unknown';
3020
- return $v_result;
3021
- }
3022
- function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
3023
- {
3024
- if (stristr(php_uname(), 'windows')) {
3025
- if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
3026
- $p_path = substr($p_path, $v_position+1);
3027
- }
3028
- if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
3029
- $p_path = strtr($p_path, '\\', '/');
3030
- }
3031
- }
3032
- return $p_path;
3033
- }
3034
- ?>
1
+ <?php
2
+ if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
3
+ define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
4
+ }
5
+ if (!defined('PCLZIP_SEPARATOR')) {
6
+ define( 'PCLZIP_SEPARATOR', ',' );
7
+ }
8
+ if (!defined('PCLZIP_ERROR_EXTERNAL')) {
9
+ define( 'PCLZIP_ERROR_EXTERNAL', 0 );
10
+ }
11
+ if (!defined('PCLZIP_TEMPORARY_DIR')) {
12
+ define( 'PCLZIP_TEMPORARY_DIR', '' );
13
+ }
14
+ if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
15
+ define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
16
+ }
17
+ // --------------------------------------------------------------------------------
18
+ // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
19
+ // --------------------------------------------------------------------------------
20
+ $g_pclzip_version = "2.8.2";
21
+ define( 'PCLZIP_ERR_USER_ABORTED', 2 );
22
+ define( 'PCLZIP_ERR_NO_ERROR', 0 );
23
+ define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
24
+ define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
25
+ define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
26
+ define( 'PCLZIP_ERR_MISSING_FILE', -4 );
27
+ define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
28
+ define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
29
+ define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
30
+ define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
31
+ define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
32
+ define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
33
+ define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
34
+ define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
35
+ define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
36
+ define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
37
+ define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
38
+ define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
39
+ define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
40
+ define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
41
+ define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
42
+ define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
43
+ define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
44
+ define( 'PCLZIP_OPT_PATH', 77001 );
45
+ define( 'PCLZIP_OPT_ADD_PATH', 77002 );
46
+ define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
47
+ define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
48
+ define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
49
+ define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
50
+ define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
51
+ define( 'PCLZIP_OPT_BY_NAME', 77008 );
52
+ define( 'PCLZIP_OPT_BY_INDEX', 77009 );
53
+ define( 'PCLZIP_OPT_BY_EREG', 77010 );
54
+ define( 'PCLZIP_OPT_BY_PREG', 77011 );
55
+ define( 'PCLZIP_OPT_COMMENT', 77012 );
56
+ define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
57
+ define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
58
+ define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
59
+ define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
60
+ define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
61
+ define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
62
+ define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
63
+ define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
64
+ define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
65
+ define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
66
+ define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
67
+ define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
68
+ define( 'PCLZIP_ATT_FILE_NAME', 79001 );
69
+ define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
70
+ define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
71
+ define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
72
+ define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
73
+ define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
74
+ define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
75
+ define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
76
+ define( 'PCLZIP_CB_PRE_ADD', 78003 );
77
+ define( 'PCLZIP_CB_POST_ADD', 78004 );
78
+ /* For futur use
79
+ define( 'PCLZIP_CB_PRE_LIST', 78005 );
80
+ define( 'PCLZIP_CB_POST_LIST', 78006 );
81
+ define( 'PCLZIP_CB_PRE_DELETE', 78007 );
82
+ define( 'PCLZIP_CB_POST_DELETE', 78008 );
83
+ */
84
+ class PclZip
85
+ {
86
+ var $zipname = '';
87
+ var $zip_fd = 0;
88
+ var $error_code = 1;
89
+ var $error_string = '';
90
+ var $magic_quotes_status;
91
+ function __construct($p_zipname)
92
+ {
93
+ if (!function_exists('gzopen'))
94
+ {
95
+ die('Abort '.basename(__FILE__).' : Missing zlib extensions');
96
+ }
97
+ $this->zipname = $p_zipname;
98
+ $this->zip_fd = 0;
99
+ $this->magic_quotes_status = -1;
100
+ return;
101
+ }
102
+ function create($p_filelist)
103
+ {
104
+ $v_result=1;
105
+ $this->privErrorReset();
106
+ $v_options = array();
107
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
108
+ $v_size = func_num_args();
109
+ if ($v_size > 1) {
110
+ $v_arg_list = func_get_args();
111
+ array_shift($v_arg_list);
112
+ $v_size--;
113
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
114
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
115
+ array (PCLZIP_OPT_REMOVE_PATH => 'optional',
116
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
117
+ PCLZIP_OPT_ADD_PATH => 'optional',
118
+ PCLZIP_CB_PRE_ADD => 'optional',
119
+ PCLZIP_CB_POST_ADD => 'optional',
120
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
121
+ PCLZIP_OPT_COMMENT => 'optional',
122
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
123
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
124
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
125
+ ));
126
+ if ($v_result != 1) {
127
+ return 0;
128
+ }
129
+ }
130
+ else {
131
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
132
+ if ($v_size == 2) {
133
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
134
+ }
135
+ else if ($v_size > 2) {
136
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
137
+ "Invalid number / type of arguments");
138
+ return 0;
139
+ }
140
+ }
141
+ }
142
+ $this->privOptionDefaultThreshold($v_options);
143
+ $v_string_list = array();
144
+ $v_att_list = array();
145
+ $v_filedescr_list = array();
146
+ $p_result_list = array();
147
+ if (is_array($p_filelist)) {
148
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
149
+ $v_att_list = $p_filelist;
150
+ }
151
+ else {
152
+ $v_string_list = $p_filelist;
153
+ }
154
+ }
155
+ else if (is_string($p_filelist)) {
156
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
157
+ }
158
+ else {
159
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
160
+ return 0;
161
+ }
162
+ if (sizeof($v_string_list) != 0) {
163
+ foreach ($v_string_list as $v_string) {
164
+ if ($v_string != '') {
165
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
166
+ }
167
+ else {
168
+ }
169
+ }
170
+ }
171
+ $v_supported_attributes
172
+ = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
173
+ ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
174
+ ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
175
+ ,PCLZIP_ATT_FILE_MTIME => 'optional'
176
+ ,PCLZIP_ATT_FILE_CONTENT => 'optional'
177
+ ,PCLZIP_ATT_FILE_COMMENT => 'optional'
178
+ );
179
+ foreach ($v_att_list as $v_entry) {
180
+ $v_result = $this->privFileDescrParseAtt($v_entry,
181
+ $v_filedescr_list[],
182
+ $v_options,
183
+ $v_supported_attributes);
184
+ if ($v_result != 1) {
185
+ return 0;
186
+ }
187
+ }
188
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
189
+ if ($v_result != 1) {
190
+ return 0;
191
+ }
192
+ $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
193
+ if ($v_result != 1) {
194
+ return 0;
195
+ }
196
+ return $p_result_list;
197
+ }
198
+ function add($p_filelist)
199
+ {
200
+ $v_result=1;
201
+ $this->privErrorReset();
202
+ $v_options = array();
203
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
204
+ $v_size = func_num_args();
205
+ if ($v_size > 1) {
206
+ $v_arg_list = func_get_args();
207
+ array_shift($v_arg_list);
208
+ $v_size--;
209
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
210
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
211
+ array (PCLZIP_OPT_REMOVE_PATH => 'optional',
212
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
213
+ PCLZIP_OPT_ADD_PATH => 'optional',
214
+ PCLZIP_CB_PRE_ADD => 'optional',
215
+ PCLZIP_CB_POST_ADD => 'optional',
216
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
217
+ PCLZIP_OPT_COMMENT => 'optional',
218
+ PCLZIP_OPT_ADD_COMMENT => 'optional',
219
+ PCLZIP_OPT_PREPEND_COMMENT => 'optional',
220
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
221
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
222
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
223
+ ));
224
+ if ($v_result != 1) {
225
+ return 0;
226
+ }
227
+ }
228
+ else {
229
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
230
+ if ($v_size == 2) {
231
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
232
+ }
233
+ else if ($v_size > 2) {
234
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
235
+ return 0;
236
+ }
237
+ }
238
+ }
239
+ $this->privOptionDefaultThreshold($v_options);
240
+ $v_string_list = array();
241
+ $v_att_list = array();
242
+ $v_filedescr_list = array();
243
+ $p_result_list = array();
244
+ if (is_array($p_filelist)) {
245
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
246
+ $v_att_list = $p_filelist;
247
+ }
248
+ else {
249
+ $v_string_list = $p_filelist;
250
+ }
251
+ }
252
+ else if (is_string($p_filelist)) {
253
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
254
+ }
255
+ else {
256
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
257
+ return 0;
258
+ }
259
+ if (sizeof($v_string_list) != 0) {
260
+ foreach ($v_string_list as $v_string) {
261
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
262
+ }
263
+ }
264
+ $v_supported_attributes
265
+ = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
266
+ ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
267
+ ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
268
+ ,PCLZIP_ATT_FILE_MTIME => 'optional'
269
+ ,PCLZIP_ATT_FILE_CONTENT => 'optional'
270
+ ,PCLZIP_ATT_FILE_COMMENT => 'optional'
271
+ );
272
+ foreach ($v_att_list as $v_entry) {
273
+ $v_result = $this->privFileDescrParseAtt($v_entry,
274
+ $v_filedescr_list[],
275
+ $v_options,
276
+ $v_supported_attributes);
277
+ if ($v_result != 1) {
278
+ return 0;
279
+ }
280
+ }
281
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
282
+ if ($v_result != 1) {
283
+ return 0;
284
+ }
285
+ $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
286
+ if ($v_result != 1) {
287
+ return 0;
288
+ }
289
+ return $p_result_list;
290
+ }
291
+ function listContent()
292
+ {
293
+ $v_result=1;
294
+ $this->privErrorReset();
295
+ if (!$this->privCheckFormat()) {
296
+ return(0);
297
+ }
298
+ $p_list = array();
299
+ if (($v_result = $this->privList($p_list)) != 1)
300
+ {
301
+ unset($p_list);
302
+ return(0);
303
+ }
304
+ return $p_list;
305
+ }
306
+ function extract()
307
+ {
308
+ $v_result=1;
309
+ $this->privErrorReset();
310
+ if (!$this->privCheckFormat()) {
311
+ return(0);
312
+ }
313
+ $v_options = array();
314
+ // $v_path = "./";
315
+ $v_path = '';
316
+ $v_remove_path = "";
317
+ $v_remove_all_path = false;
318
+ $v_size = func_num_args();
319
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
320
+ if ($v_size > 0) {
321
+ $v_arg_list = func_get_args();
322
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
323
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
324
+ array (PCLZIP_OPT_PATH => 'optional',
325
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
326
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
327
+ PCLZIP_OPT_ADD_PATH => 'optional',
328
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
329
+ PCLZIP_CB_POST_EXTRACT => 'optional',
330
+ PCLZIP_OPT_SET_CHMOD => 'optional',
331
+ PCLZIP_OPT_BY_NAME => 'optional',
332
+ PCLZIP_OPT_BY_EREG => 'optional',
333
+ PCLZIP_OPT_BY_PREG => 'optional',
334
+ PCLZIP_OPT_BY_INDEX => 'optional',
335
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
336
+ PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
337
+ PCLZIP_OPT_REPLACE_NEWER => 'optional'
338
+ ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
339
+ ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
340
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
341
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
342
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
343
+ ));
344
+ if ($v_result != 1) {
345
+ return 0;
346
+ }
347
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
348
+ $v_path = $v_options[PCLZIP_OPT_PATH];
349
+ }
350
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
351
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
352
+ }
353
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
354
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
355
+ }
356
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
357
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
358
+ $v_path .= '/';
359
+ }
360
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
361
+ }
362
+ }
363
+ else {
364
+ $v_path = $v_arg_list[0];
365
+ if ($v_size == 2) {
366
+ $v_remove_path = $v_arg_list[1];
367
+ }
368
+ else if ($v_size > 2) {
369
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
370
+ return 0;
371
+ }
372
+ }
373
+ }
374
+ $this->privOptionDefaultThreshold($v_options);
375
+ $p_list = array();
376
+ $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
377
+ $v_remove_all_path, $v_options);
378
+ if ($v_result < 1) {
379
+ unset($p_list);
380
+ return(0);
381
+ }
382
+ return $p_list;
383
+ }
384
+ function extractByIndex($p_index)
385
+ {
386
+ $v_result=1;
387
+ $this->privErrorReset();
388
+ if (!$this->privCheckFormat()) {
389
+ return(0);
390
+ }
391
+ $v_options = array();
392
+ // $v_path = "./";
393
+ $v_path = '';
394
+ $v_remove_path = "";
395
+ $v_remove_all_path = false;
396
+ $v_size = func_num_args();
397
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
398
+ if ($v_size > 1) {
399
+ $v_arg_list = func_get_args();
400
+ array_shift($v_arg_list);
401
+ $v_size--;
402
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
403
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
404
+ array (PCLZIP_OPT_PATH => 'optional',
405
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
406
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
407
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
408
+ PCLZIP_OPT_ADD_PATH => 'optional',
409
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
410
+ PCLZIP_CB_POST_EXTRACT => 'optional',
411
+ PCLZIP_OPT_SET_CHMOD => 'optional',
412
+ PCLZIP_OPT_REPLACE_NEWER => 'optional'
413
+ ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
414
+ ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
415
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
416
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
417
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
418
+ ));
419
+ if ($v_result != 1) {
420
+ return 0;
421
+ }
422
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
423
+ $v_path = $v_options[PCLZIP_OPT_PATH];
424
+ }
425
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
426
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
427
+ }
428
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
429
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
430
+ }
431
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
432
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
433
+ $v_path .= '/';
434
+ }
435
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
436
+ }
437
+ if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
438
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
439
+ }
440
+ else {
441
+ }
442
+ }
443
+ else {
444
+ $v_path = $v_arg_list[0];
445
+ if ($v_size == 2) {
446
+ $v_remove_path = $v_arg_list[1];
447
+ }
448
+ else if ($v_size > 2) {
449
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
450
+ return 0;
451
+ }
452
+ }
453
+ }
454
+ $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
455
+ $v_options_trick = array();
456
+ $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
457
+ array (PCLZIP_OPT_BY_INDEX => 'optional' ));
458
+ if ($v_result != 1) {
459
+ return 0;
460
+ }
461
+ $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
462
+ $this->privOptionDefaultThreshold($v_options);
463
+ if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
464
+ return(0);
465
+ }
466
+ return $p_list;
467
+ }
468
+ function delete()
469
+ {
470
+ $v_result=1;
471
+ $this->privErrorReset();
472
+ if (!$this->privCheckFormat()) {
473
+ return(0);
474
+ }
475
+ $v_options = array();
476
+ $v_size = func_num_args();
477
+ if ($v_size > 0) {
478
+ $v_arg_list = func_get_args();
479
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
480
+ array (PCLZIP_OPT_BY_NAME => 'optional',
481
+ PCLZIP_OPT_BY_EREG => 'optional',
482
+ PCLZIP_OPT_BY_PREG => 'optional',
483
+ PCLZIP_OPT_BY_INDEX => 'optional' ));
484
+ if ($v_result != 1) {
485
+ return 0;
486
+ }
487
+ }
488
+ $this->privDisableMagicQuotes();
489
+ $v_list = array();
490
+ if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
491
+ $this->privSwapBackMagicQuotes();
492
+ unset($v_list);
493
+ return(0);
494
+ }
495
+ $this->privSwapBackMagicQuotes();
496
+ return $v_list;
497
+ }
498
+ function deleteByIndex($p_index)
499
+ {
500
+ $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
501
+ return $p_list;
502
+ }
503
+ function properties()
504
+ {
505
+ $this->privErrorReset();
506
+ $this->privDisableMagicQuotes();
507
+ if (!$this->privCheckFormat()) {
508
+ $this->privSwapBackMagicQuotes();
509
+ return(0);
510
+ }
511
+ $v_prop = array();
512
+ $v_prop['comment'] = '';
513
+ $v_prop['nb'] = 0;
514
+ $v_prop['status'] = 'not_exist';
515
+ if (@is_file($this->zipname))
516
+ {
517
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
518
+ {
519
+ $this->privSwapBackMagicQuotes();
520
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
521
+ return 0;
522
+ }
523
+ $v_central_dir = array();
524
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
525
+ {
526
+ $this->privSwapBackMagicQuotes();
527
+ return 0;
528
+ }
529
+ $this->privCloseFd();
530
+ $v_prop['comment'] = $v_central_dir['comment'];
531
+ $v_prop['nb'] = $v_central_dir['entries'];
532
+ $v_prop['status'] = 'ok';
533
+ }
534
+ $this->privSwapBackMagicQuotes();
535
+ return $v_prop;
536
+ }
537
+ function duplicate($p_archive)
538
+ {
539
+ $v_result = 1;
540
+ $this->privErrorReset();
541
+ if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
542
+ {
543
+ $v_result = $this->privDuplicate($p_archive->zipname);
544
+ }
545
+ else if (is_string($p_archive))
546
+ {
547
+ if (!is_file($p_archive)) {
548
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
549
+ $v_result = PCLZIP_ERR_MISSING_FILE;
550
+ }
551
+ else {
552
+ $v_result = $this->privDuplicate($p_archive);
553
+ }
554
+ }
555
+ else
556
+ {
557
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
558
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
559
+ }
560
+ return $v_result;
561
+ }
562
+ function merge($p_archive_to_add)
563
+ {
564
+ $v_result = 1;
565
+ $this->privErrorReset();
566
+ if (!$this->privCheckFormat()) {
567
+ return(0);
568
+ }
569
+ if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
570
+ {
571
+ $v_result = $this->privMerge($p_archive_to_add);
572
+ }
573
+ else if (is_string($p_archive_to_add))
574
+ {
575
+ $v_object_archive = new PclZip($p_archive_to_add);
576
+ $v_result = $this->privMerge($v_object_archive);
577
+ }
578
+ else
579
+ {
580
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
581
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
582
+ }
583
+ return $v_result;
584
+ }
585
+ function errorCode()
586
+ {
587
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
588
+ return(PclErrorCode());
589
+ }
590
+ else {
591
+ return($this->error_code);
592
+ }
593
+ }
594
+ function errorName($p_with_code=false)
595
+ {
596
+ $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
597
+ PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
598
+ PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
599
+ PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
600
+ PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
601
+ PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
602
+ PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
603
+ PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
604
+ PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
605
+ PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
606
+ PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
607
+ PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
608
+ PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
609
+ PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
610
+ PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
611
+ PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
612
+ PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
613
+ PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
614
+ PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
615
+ ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
616
+ ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
617
+ );
618
+ if (isset($v_name[$this->error_code])) {
619
+ $v_value = $v_name[$this->error_code];
620
+ }
621
+ else {
622
+ $v_value = 'NoName';
623
+ }
624
+ if ($p_with_code) {
625
+ return($v_value.' ('.$this->error_code.')');
626
+ }
627
+ else {
628
+ return($v_value);
629
+ }
630
+ }
631
+ function errorInfo($p_full=false)
632
+ {
633
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
634
+ return(PclErrorString());
635
+ }
636
+ else {
637
+ if ($p_full) {
638
+ return($this->errorName(true)." : ".$this->error_string);
639
+ }
640
+ else {
641
+ return($this->error_string." [code ".$this->error_code."]");
642
+ }
643
+ }
644
+ }
645
+ // --------------------------------------------------------------------------------
646
+ // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
647
+ // ***** *****
648
+ // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
649
+ // --------------------------------------------------------------------------------
650
+ function privCheckFormat($p_level=0)
651
+ {
652
+ $v_result = true;
653
+ // ----- Reset the file system cache
654
+ clearstatcache();
655
+ $this->privErrorReset();
656
+ if (!is_file($this->zipname)) {
657
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
658
+ return(false);
659
+ }
660
+ if (!is_readable($this->zipname)) {
661
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
662
+ return(false);
663
+ }
664
+ return $v_result;
665
+ }
666
+ function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
667
+ {
668
+ $v_result=1;
669
+ $i=0;
670
+ while ($i<$p_size) {
671
+ if (!isset($v_requested_options[$p_options_list[$i]])) {
672
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
673
+ return PclZip::errorCode();
674
+ }
675
+ switch ($p_options_list[$i]) {
676
+ case PCLZIP_OPT_PATH :
677
+ case PCLZIP_OPT_REMOVE_PATH :
678
+ case PCLZIP_OPT_ADD_PATH :
679
+ if (($i+1) >= $p_size) {
680
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
681
+ return PclZip::errorCode();
682
+ }
683
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
684
+ $i++;
685
+ break;
686
+ case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
687
+ if (($i+1) >= $p_size) {
688
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
689
+ return PclZip::errorCode();
690
+ }
691
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
692
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
693
+ return PclZip::errorCode();
694
+ }
695
+ $v_value = $p_options_list[$i+1];
696
+ if ((!is_integer($v_value)) || ($v_value<0)) {
697
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
698
+ return PclZip::errorCode();
699
+ }
700
+ $v_result_list[$p_options_list[$i]] = $v_value*1048576;
701
+ $i++;
702
+ break;
703
+ case PCLZIP_OPT_TEMP_FILE_ON :
704
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
705
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
706
+ return PclZip::errorCode();
707
+ }
708
+ $v_result_list[$p_options_list[$i]] = true;
709
+ break;
710
+ case PCLZIP_OPT_TEMP_FILE_OFF :
711
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
712
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
713
+ return PclZip::errorCode();
714
+ }
715
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
716
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
717
+ return PclZip::errorCode();
718
+ }
719
+ $v_result_list[$p_options_list[$i]] = true;
720
+ break;
721
+ case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
722
+ if (($i+1) >= $p_size) {
723
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
724
+ return PclZip::errorCode();
725
+ }
726
+ if ( is_string($p_options_list[$i+1])
727
+ && ($p_options_list[$i+1] != '')) {
728
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
729
+ $i++;
730
+ }
731
+ else {
732
+ }
733
+ break;
734
+ case PCLZIP_OPT_BY_NAME :
735
+ if (($i+1) >= $p_size) {
736
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
737
+ return PclZip::errorCode();
738
+ }
739
+ if (is_string($p_options_list[$i+1])) {
740
+ $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
741
+ }
742
+ else if (is_array($p_options_list[$i+1])) {
743
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
744
+ }
745
+ else {
746
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
747
+ return PclZip::errorCode();
748
+ }
749
+ $i++;
750
+ break;
751
+ case PCLZIP_OPT_BY_EREG :
752
+ $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
753
+ case PCLZIP_OPT_BY_PREG :
754
+ if (($i+1) >= $p_size) {
755
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
756
+ return PclZip::errorCode();
757
+ }
758
+ if (is_string($p_options_list[$i+1])) {
759
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
760
+ }
761
+ else {
762
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
763
+ return PclZip::errorCode();
764
+ }
765
+ $i++;
766
+ break;
767
+ case PCLZIP_OPT_COMMENT :
768
+ case PCLZIP_OPT_ADD_COMMENT :
769
+ case PCLZIP_OPT_PREPEND_COMMENT :
770
+ if (($i+1) >= $p_size) {
771
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
772
+ "Missing parameter value for option '"
773
+ .PclZipUtilOptionText($p_options_list[$i])
774
+ ."'");
775
+ return PclZip::errorCode();
776
+ }
777
+ if (is_string($p_options_list[$i+1])) {
778
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
779
+ }
780
+ else {
781
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
782
+ "Wrong parameter value for option '"
783
+ .PclZipUtilOptionText($p_options_list[$i])
784
+ ."'");
785
+ return PclZip::errorCode();
786
+ }
787
+ $i++;
788
+ break;
789
+ case PCLZIP_OPT_BY_INDEX :
790
+ if (($i+1) >= $p_size) {
791
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
792
+ return PclZip::errorCode();
793
+ }
794
+ $v_work_list = array();
795
+ if (is_string($p_options_list[$i+1])) {
796
+ $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
797
+ $v_work_list = explode(",", $p_options_list[$i+1]);
798
+ }
799
+ else if (is_integer($p_options_list[$i+1])) {
800
+ $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
801
+ }
802
+ else if (is_array($p_options_list[$i+1])) {
803
+ $v_work_list = $p_options_list[$i+1];
804
+ }
805
+ else {
806
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
807
+ return PclZip::errorCode();
808
+ }
809
+ $v_sort_flag=false;
810
+ $v_sort_value=0;
811
+ for ($j=0; $j<sizeof($v_work_list); $j++) {
812
+ $v_item_list = explode("-", $v_work_list[$j]);
813
+ $v_size_item_list = sizeof($v_item_list);
814
+ if ($v_size_item_list == 1) {
815
+ $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
816
+ $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
817
+ }
818
+ elseif ($v_size_item_list == 2) {
819
+ $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
820
+ $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
821
+ }
822
+ else {
823
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
824
+ return PclZip::errorCode();
825
+ }
826
+ if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
827
+ $v_sort_flag=true;
828
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
829
+ return PclZip::errorCode();
830
+ }
831
+ $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
832
+ }
833
+ if ($v_sort_flag) {
834
+ }
835
+ $i++;
836
+ break;
837
+ case PCLZIP_OPT_REMOVE_ALL_PATH :
838
+ case PCLZIP_OPT_EXTRACT_AS_STRING :
839
+ case PCLZIP_OPT_NO_COMPRESSION :
840
+ case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
841
+ case PCLZIP_OPT_REPLACE_NEWER :
842
+ case PCLZIP_OPT_STOP_ON_ERROR :
843
+ $v_result_list[$p_options_list[$i]] = true;
844
+ break;
845
+ case PCLZIP_OPT_SET_CHMOD :
846
+ if (($i+1) >= $p_size) {
847
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
848
+ return PclZip::errorCode();
849
+ }
850
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
851
+ $i++;
852
+ break;
853
+ case PCLZIP_CB_PRE_EXTRACT :
854
+ case PCLZIP_CB_POST_EXTRACT :
855
+ case PCLZIP_CB_PRE_ADD :
856
+ case PCLZIP_CB_POST_ADD :
857
+ /* for futur use
858
+ case PCLZIP_CB_PRE_DELETE :
859
+ case PCLZIP_CB_POST_DELETE :
860
+ case PCLZIP_CB_PRE_LIST :
861
+ case PCLZIP_CB_POST_LIST :
862
+ */
863
+ if (($i+1) >= $p_size) {
864
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
865
+ return PclZip::errorCode();
866
+ }
867
+ $v_function_name = $p_options_list[$i+1];
868
+ if (!function_exists($v_function_name)) {
869
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
870
+ return PclZip::errorCode();
871
+ }
872
+ $v_result_list[$p_options_list[$i]] = $v_function_name;
873
+ $i++;
874
+ break;
875
+ default :
876
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
877
+ "Unknown parameter '"
878
+ .$p_options_list[$i]."'");
879
+ return PclZip::errorCode();
880
+ }
881
+ $i++;
882
+ }
883
+ if ($v_requested_options !== false) {
884
+ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
885
+ if ($v_requested_options[$key] == 'mandatory') {
886
+ if (!isset($v_result_list[$key])) {
887
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
888
+ return PclZip::errorCode();
889
+ }
890
+ }
891
+ }
892
+ }
893
+ if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
894
+ }
895
+ return $v_result;
896
+ }
897
+ function privOptionDefaultThreshold(&$p_options)
898
+ {
899
+ $v_result=1;
900
+ if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
901
+ || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
902
+ return $v_result;
903
+ }
904
+ $v_memory_limit = ini_get('memory_limit');
905
+ $v_memory_limit = trim($v_memory_limit);
906
+ $last = strtolower(substr($v_memory_limit, -1));
907
+ if($last == 'g')
908
+ $v_memory_limit = $v_memory_limit*1073741824;
909
+ if($last == 'm')
910
+ $v_memory_limit = $v_memory_limit*1048576;
911
+ if($last == 'k')
912
+ $v_memory_limit = $v_memory_limit*1024;
913
+ $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
914
+ if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
915
+ unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
916
+ }
917
+ return $v_result;
918
+ }
919
+ function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
920
+ {
921
+ $v_result=1;
922
+ foreach ($p_file_list as $v_key => $v_value) {
923
+ if (!isset($v_requested_options[$v_key])) {
924
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
925
+ return PclZip::errorCode();
926
+ }
927
+ switch ($v_key) {
928
+ case PCLZIP_ATT_FILE_NAME :
929
+ if (!is_string($v_value)) {
930
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
931
+ return PclZip::errorCode();
932
+ }
933
+ $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
934
+ if ($p_filedescr['filename'] == '') {
935
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
936
+ return PclZip::errorCode();
937
+ }
938
+ break;
939
+ case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
940
+ if (!is_string($v_value)) {
941
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
942
+ return PclZip::errorCode();
943
+ }
944
+ $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
945
+ if ($p_filedescr['new_short_name'] == '') {
946
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
947
+ return PclZip::errorCode();
948
+ }
949
+ break;
950
+ case PCLZIP_ATT_FILE_NEW_FULL_NAME :
951
+ if (!is_string($v_value)) {
952
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
953
+ return PclZip::errorCode();
954
+ }
955
+ $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
956
+ if ($p_filedescr['new_full_name'] == '') {
957
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
958
+ return PclZip::errorCode();
959
+ }
960
+ break;
961
+ case PCLZIP_ATT_FILE_COMMENT :
962
+ if (!is_string($v_value)) {
963
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
964
+ return PclZip::errorCode();
965
+ }
966
+ $p_filedescr['comment'] = $v_value;
967
+ break;
968
+ case PCLZIP_ATT_FILE_MTIME :
969
+ if (!is_integer($v_value)) {
970
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
971
+ return PclZip::errorCode();
972
+ }
973
+ $p_filedescr['mtime'] = $v_value;
974
+ break;
975
+ case PCLZIP_ATT_FILE_CONTENT :
976
+ $p_filedescr['content'] = $v_value;
977
+ break;
978
+ default :
979
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
980
+ "Unknown parameter '".$v_key."'");
981
+ return PclZip::errorCode();
982
+ }
983
+ if ($v_requested_options !== false) {
984
+ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
985
+ if ($v_requested_options[$key] == 'mandatory') {
986
+ if (!isset($p_file_list[$key])) {
987
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
988
+ return PclZip::errorCode();
989
+ }
990
+ }
991
+ }
992
+ }
993
+ }
994
+ return $v_result;
995
+ }
996
+ function privFileDescrExpand(&$p_filedescr_list, &$p_options)
997
+ {
998
+ $v_result=1;
999
+ $v_result_list = array();
1000
+ for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
1001
+ $v_descr = $p_filedescr_list[$i];
1002
+ $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
1003
+ $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
1004
+ if (file_exists($v_descr['filename'])) {
1005
+ if (@is_file($v_descr['filename'])) {
1006
+ $v_descr['type'] = 'file';
1007
+ }
1008
+ else if (@is_dir($v_descr['filename'])) {
1009
+ $v_descr['type'] = 'folder';
1010
+ }
1011
+ else if (@is_link($v_descr['filename'])) {
1012
+ continue;
1013
+ }
1014
+ else {
1015
+ continue;
1016
+ }
1017
+ }
1018
+ else if (isset($v_descr['content'])) {
1019
+ $v_descr['type'] = 'virtual_file';
1020
+ }
1021
+ else {
1022
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
1023
+ return PclZip::errorCode();
1024
+ }
1025
+ $this->privCalculateStoredFilename($v_descr, $p_options);
1026
+ $v_result_list[sizeof($v_result_list)] = $v_descr;
1027
+ if ($v_descr['type'] == 'folder') {
1028
+ $v_dirlist_descr = array();
1029
+ $v_dirlist_nb = 0;
1030
+ if ($v_folder_handler = @opendir($v_descr['filename'])) {
1031
+ while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
1032
+ if (($v_item_handler == '.') || ($v_item_handler == '..')) {
1033
+ continue;
1034
+ }
1035
+ $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
1036
+ if (($v_descr['stored_filename'] != $v_descr['filename'])
1037
+ && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
1038
+ if ($v_descr['stored_filename'] != '') {
1039
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
1040
+ }
1041
+ else {
1042
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
1043
+ }
1044
+ }
1045
+ $v_dirlist_nb++;
1046
+ }
1047
+ @closedir($v_folder_handler);
1048
+ }
1049
+ else {
1050
+ }
1051
+ if ($v_dirlist_nb != 0) {
1052
+ if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
1053
+ return $v_result;
1054
+ }
1055
+ $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
1056
+ }
1057
+ else {
1058
+ }
1059
+ unset($v_dirlist_descr);
1060
+ }
1061
+ }
1062
+ $p_filedescr_list = $v_result_list;
1063
+ return $v_result;
1064
+ }
1065
+ function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
1066
+ {
1067
+ $v_result=1;
1068
+ $v_list_detail = array();
1069
+ $this->privDisableMagicQuotes();
1070
+ if (($v_result = $this->privOpenFd('wb')) != 1)
1071
+ {
1072
+ return $v_result;
1073
+ }
1074
+ $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
1075
+ $this->privCloseFd();
1076
+ $this->privSwapBackMagicQuotes();
1077
+ return $v_result;
1078
+ }
1079
+ function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
1080
+ {
1081
+ $v_result=1;
1082
+ $v_list_detail = array();
1083
+ if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
1084
+ {
1085
+ $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
1086
+ return $v_result;
1087
+ }
1088
+ $this->privDisableMagicQuotes();
1089
+ if (($v_result=$this->privOpenFd('rb')) != 1)
1090
+ {
1091
+ $this->privSwapBackMagicQuotes();
1092
+ return $v_result;
1093
+ }
1094
+ $v_central_dir = array();
1095
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1096
+ {
1097
+ $this->privCloseFd();
1098
+ $this->privSwapBackMagicQuotes();
1099
+ return $v_result;
1100
+ }
1101
+ @rewind($this->zip_fd);
1102
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
1103
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
1104
+ {
1105
+ $this->privCloseFd();
1106
+ $this->privSwapBackMagicQuotes();
1107
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
1108
+ return PclZip::errorCode();
1109
+ }
1110
+ $v_size = $v_central_dir['offset'];
1111
+ while ($v_size != 0)
1112
+ {
1113
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1114
+ $v_buffer = fread($this->zip_fd, $v_read_size);
1115
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
1116
+ $v_size -= $v_read_size;
1117
+ }
1118
+ $v_swap = $this->zip_fd;
1119
+ $this->zip_fd = $v_zip_temp_fd;
1120
+ $v_zip_temp_fd = $v_swap;
1121
+ $v_header_list = array();
1122
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
1123
+ {
1124
+ fclose($v_zip_temp_fd);
1125
+ $this->privCloseFd();
1126
+ @unlink($v_zip_temp_name);
1127
+ $this->privSwapBackMagicQuotes();
1128
+ return $v_result;
1129
+ }
1130
+ $v_offset = @ftell($this->zip_fd);
1131
+ $v_size = $v_central_dir['size'];
1132
+ while ($v_size != 0)
1133
+ {
1134
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1135
+ $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
1136
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
1137
+ $v_size -= $v_read_size;
1138
+ }
1139
+ for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
1140
+ {
1141
+ if ($v_header_list[$i]['status'] == 'ok') {
1142
+ if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1143
+ fclose($v_zip_temp_fd);
1144
+ $this->privCloseFd();
1145
+ @unlink($v_zip_temp_name);
1146
+ $this->privSwapBackMagicQuotes();
1147
+ return $v_result;
1148
+ }
1149
+ $v_count++;
1150
+ }
1151
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1152
+ }
1153
+ $v_comment = $v_central_dir['comment'];
1154
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
1155
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
1156
+ }
1157
+ if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
1158
+ $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
1159
+ }
1160
+ if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
1161
+ $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
1162
+ }
1163
+ $v_size = @ftell($this->zip_fd)-$v_offset;
1164
+ if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
1165
+ {
1166
+ unset($v_header_list);
1167
+ $this->privSwapBackMagicQuotes();
1168
+ return $v_result;
1169
+ }
1170
+ $v_swap = $this->zip_fd;
1171
+ $this->zip_fd = $v_zip_temp_fd;
1172
+ $v_zip_temp_fd = $v_swap;
1173
+ $this->privCloseFd();
1174
+ @fclose($v_zip_temp_fd);
1175
+ $this->privSwapBackMagicQuotes();
1176
+ @unlink($this->zipname);
1177
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
1178
+ return $v_result;
1179
+ }
1180
+ function privOpenFd($p_mode)
1181
+ {
1182
+ $v_result=1;
1183
+ if ($this->zip_fd != 0)
1184
+ {
1185
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
1186
+ return PclZip::errorCode();
1187
+ }
1188
+ if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
1189
+ {
1190
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
1191
+ return PclZip::errorCode();
1192
+ }
1193
+ return $v_result;
1194
+ }
1195
+ function privCloseFd()
1196
+ {
1197
+ $v_result=1;
1198
+ if ($this->zip_fd != 0)
1199
+ @fclose($this->zip_fd);
1200
+ $this->zip_fd = 0;
1201
+ return $v_result;
1202
+ }
1203
+ // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
1204
+ function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
1205
+ {
1206
+ $v_result=1;
1207
+ $v_header_list = array();
1208
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
1209
+ {
1210
+ return $v_result;
1211
+ }
1212
+ $v_offset = @ftell($this->zip_fd);
1213
+ for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
1214
+ {
1215
+ if ($v_header_list[$i]['status'] == 'ok') {
1216
+ if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1217
+ return $v_result;
1218
+ }
1219
+ $v_count++;
1220
+ }
1221
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1222
+ }
1223
+ $v_comment = '';
1224
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
1225
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
1226
+ }
1227
+ $v_size = @ftell($this->zip_fd)-$v_offset;
1228
+ if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
1229
+ {
1230
+ unset($v_header_list);
1231
+ return $v_result;
1232
+ }
1233
+ return $v_result;
1234
+ }
1235
+ function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
1236
+ {
1237
+ $v_result=1;
1238
+ $v_header = array();
1239
+ $v_nb = sizeof($p_result_list);
1240
+ for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
1241
+ $p_filedescr_list[$j]['filename']
1242
+ = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
1243
+ if ($p_filedescr_list[$j]['filename'] == "") {
1244
+ continue;
1245
+ }
1246
+ if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
1247
+ && (!file_exists($p_filedescr_list[$j]['filename']))) {
1248
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
1249
+ return PclZip::errorCode();
1250
+ }
1251
+ // if ( (is_file($p_filedescr_list[$j]['filename']))
1252
+ // || ( is_dir($p_filedescr_list[$j]['filename'])
1253
+ if ( ($p_filedescr_list[$j]['type'] == 'file')
1254
+ || ($p_filedescr_list[$j]['type'] == 'virtual_file')
1255
+ || ( ($p_filedescr_list[$j]['type'] == 'folder')
1256
+ && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
1257
+ || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
1258
+ ) {
1259
+ $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
1260
+ $p_options);
1261
+ if ($v_result != 1) {
1262
+ return $v_result;
1263
+ }
1264
+ $p_result_list[$v_nb++] = $v_header;
1265
+ }
1266
+ }
1267
+ return $v_result;
1268
+ }
1269
+ function privAddFile($p_filedescr, &$p_header, &$p_options)
1270
+ {
1271
+ $v_result=1;
1272
+ $p_filename = $p_filedescr['filename'];
1273
+ if ($p_filename == "") {
1274
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
1275
+ return PclZip::errorCode();
1276
+ }
1277
+ /* TBC : Removed
1278
+ if (isset($p_filedescr['stored_filename'])) {
1279
+ $v_stored_filename = $p_filedescr['stored_filename'];
1280
+ }
1281
+ else {
1282
+ $v_stored_filename = $p_filedescr['stored_filename'];
1283
+ }
1284
+ */
1285
+ clearstatcache();
1286
+ $p_header['version'] = 20;
1287
+ $p_header['version_extracted'] = 10;
1288
+ $p_header['flag'] = 0;
1289
+ $p_header['compression'] = 0;
1290
+ $p_header['crc'] = 0;
1291
+ $p_header['compressed_size'] = 0;
1292
+ $p_header['filename_len'] = strlen($p_filename);
1293
+ $p_header['extra_len'] = 0;
1294
+ $p_header['disk'] = 0;
1295
+ $p_header['internal'] = 0;
1296
+ $p_header['offset'] = 0;
1297
+ $p_header['filename'] = $p_filename;
1298
+ // TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
1299
+ $p_header['stored_filename'] = $p_filedescr['stored_filename'];
1300
+ $p_header['extra'] = '';
1301
+ $p_header['status'] = 'ok';
1302
+ $p_header['index'] = -1;
1303
+ if ($p_filedescr['type']=='file') {
1304
+ $p_header['external'] = 0x00000000;
1305
+ $p_header['size'] = filesize($p_filename);
1306
+ }
1307
+ else if ($p_filedescr['type']=='folder') {
1308
+ $p_header['external'] = 0x00000010;
1309
+ $p_header['mtime'] = filemtime($p_filename);
1310
+ $p_header['size'] = filesize($p_filename);
1311
+ }
1312
+ else if ($p_filedescr['type'] == 'virtual_file') {
1313
+ $p_header['external'] = 0x00000000;
1314
+ $p_header['size'] = strlen($p_filedescr['content']);
1315
+ }
1316
+ if (isset($p_filedescr['mtime'])) {
1317
+ $p_header['mtime'] = $p_filedescr['mtime'];
1318
+ }
1319
+ else if ($p_filedescr['type'] == 'virtual_file') {
1320
+ $p_header['mtime'] = time();
1321
+ }
1322
+ else {
1323
+ $p_header['mtime'] = filemtime($p_filename);
1324
+ }
1325
+ if (isset($p_filedescr['comment'])) {
1326
+ $p_header['comment_len'] = strlen($p_filedescr['comment']);
1327
+ $p_header['comment'] = $p_filedescr['comment'];
1328
+ }
1329
+ else {
1330
+ $p_header['comment_len'] = 0;
1331
+ $p_header['comment'] = '';
1332
+ }
1333
+ if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
1334
+ $v_local_header = array();
1335
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
1336
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
1337
+ $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
1338
+ if ($v_result == 0) {
1339
+ $p_header['status'] = "skipped";
1340
+ $v_result = 1;
1341
+ }
1342
+ if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
1343
+ $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
1344
+ }
1345
+ }
1346
+ if ($p_header['stored_filename'] == "") {
1347
+ $p_header['status'] = "filtered";
1348
+ }
1349
+ if (strlen($p_header['stored_filename']) > 0xFF) {
1350
+ $p_header['status'] = 'filename_too_long';
1351
+ }
1352
+ if ($p_header['status'] == 'ok') {
1353
+ if ($p_filedescr['type'] == 'file') {
1354
+ if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
1355
+ && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
1356
+ || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
1357
+ && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
1358
+ $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
1359
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
1360
+ return $v_result;
1361
+ }
1362
+ }
1363
+ else {
1364
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
1365
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
1366
+ return PclZip::errorCode();
1367
+ }
1368
+ $v_content = @fread($v_file, $p_header['size']);
1369
+ @fclose($v_file);
1370
+ $p_header['crc'] = @crc32($v_content);
1371
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
1372
+ $p_header['compressed_size'] = $p_header['size'];
1373
+ $p_header['compression'] = 0;
1374
+ }
1375
+ else {
1376
+ $v_content = @gzdeflate($v_content);
1377
+ $p_header['compressed_size'] = strlen($v_content);
1378
+ $p_header['compression'] = 8;
1379
+ }
1380
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1381
+ @fclose($v_file);
1382
+ return $v_result;
1383
+ }
1384
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
1385
+ }
1386
+ }
1387
+ else if ($p_filedescr['type'] == 'virtual_file') {
1388
+ $v_content = $p_filedescr['content'];
1389
+ $p_header['crc'] = @crc32($v_content);
1390
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
1391
+ $p_header['compressed_size'] = $p_header['size'];
1392
+ $p_header['compression'] = 0;
1393
+ }
1394
+ else {
1395
+ $v_content = @gzdeflate($v_content);
1396
+ $p_header['compressed_size'] = strlen($v_content);
1397
+ $p_header['compression'] = 8;
1398
+ }
1399
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1400
+ @fclose($v_file);
1401
+ return $v_result;
1402
+ }
1403
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
1404
+ }
1405
+ else if ($p_filedescr['type'] == 'folder') {
1406
+ if (@substr($p_header['stored_filename'], -1) != '/') {
1407
+ $p_header['stored_filename'] .= '/';
1408
+ }
1409
+ $p_header['size'] = 0;
1410
+ $p_header['external'] = 0x00000010; // Value for a folder : to be checked
1411
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
1412
+ {
1413
+ return $v_result;
1414
+ }
1415
+ }
1416
+ }
1417
+ if (isset($p_options[PCLZIP_CB_POST_ADD])) {
1418
+ $v_local_header = array();
1419
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
1420
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
1421
+ $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
1422
+ if ($v_result == 0) {
1423
+ $v_result = 1;
1424
+ }
1425
+ }
1426
+ return $v_result;
1427
+ }
1428
+ function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
1429
+ {
1430
+ $v_result=PCLZIP_ERR_NO_ERROR;
1431
+ $p_filename = $p_filedescr['filename'];
1432
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
1433
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
1434
+ return PclZip::errorCode();
1435
+ }
1436
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
1437
+ if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
1438
+ fclose($v_file);
1439
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
1440
+ return PclZip::errorCode();
1441
+ }
1442
+ $v_size = filesize($p_filename);
1443
+ while ($v_size != 0) {
1444
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1445
+ $v_buffer = @fread($v_file, $v_read_size);
1446
+ @gzputs($v_file_compressed, $v_buffer, $v_read_size);
1447
+ $v_size -= $v_read_size;
1448
+ }
1449
+ @fclose($v_file);
1450
+ @gzclose($v_file_compressed);
1451
+ if (filesize($v_gzip_temp_name) < 18) {
1452
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
1453
+ return PclZip::errorCode();
1454
+ }
1455
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
1456
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
1457
+ return PclZip::errorCode();
1458
+ }
1459
+ $v_binary_data = @fread($v_file_compressed, 10);
1460
+ $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
1461
+ $v_data_header['os'] = bin2hex($v_data_header['os']);
1462
+ @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
1463
+ $v_binary_data = @fread($v_file_compressed, 8);
1464
+ $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
1465
+ $p_header['compression'] = ord($v_data_header['cm']);
1466
+ $p_header['crc'] = $v_data_footer['crc'];
1467
+ $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
1468
+ @fclose($v_file_compressed);
1469
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
1470
+ return $v_result;
1471
+ }
1472
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
1473
+ {
1474
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
1475
+ return PclZip::errorCode();
1476
+ }
1477
+ fseek($v_file_compressed, 10);
1478
+ $v_size = $p_header['compressed_size'];
1479
+ while ($v_size != 0)
1480
+ {
1481
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1482
+ $v_buffer = @fread($v_file_compressed, $v_read_size);
1483
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
1484
+ $v_size -= $v_read_size;
1485
+ }
1486
+ @fclose($v_file_compressed);
1487
+ @unlink($v_gzip_temp_name);
1488
+ return $v_result;
1489
+ }
1490
+ function privCalculateStoredFilename(&$p_filedescr, &$p_options)
1491
+ {
1492
+ $v_result=1;
1493
+ $p_filename = $p_filedescr['filename'];
1494
+ if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
1495
+ $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
1496
+ }
1497
+ else {
1498
+ $p_add_dir = '';
1499
+ }
1500
+ if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
1501
+ $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
1502
+ }
1503
+ else {
1504
+ $p_remove_dir = '';
1505
+ }
1506
+ if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
1507
+ $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
1508
+ }
1509
+ else {
1510
+ $p_remove_all_dir = 0;
1511
+ }
1512
+ if (isset($p_filedescr['new_full_name'])) {
1513
+ $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
1514
+ }
1515
+ else {
1516
+ if (isset($p_filedescr['new_short_name'])) {
1517
+ $v_path_info = pathinfo($p_filename);
1518
+ $v_dir = '';
1519
+ if ($v_path_info['dirname'] != '') {
1520
+ $v_dir = $v_path_info['dirname'].'/';
1521
+ }
1522
+ $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
1523
+ }
1524
+ else {
1525
+ $v_stored_filename = $p_filename;
1526
+ }
1527
+ if ($p_remove_all_dir) {
1528
+ $v_stored_filename = basename($p_filename);
1529
+ }
1530
+ else if ($p_remove_dir != "") {
1531
+ if (substr($p_remove_dir, -1) != '/')
1532
+ $p_remove_dir .= "/";
1533
+ if ( (substr($p_filename, 0, 2) == "./")
1534
+ || (substr($p_remove_dir, 0, 2) == "./")) {
1535
+ if ( (substr($p_filename, 0, 2) == "./")
1536
+ && (substr($p_remove_dir, 0, 2) != "./")) {
1537
+ $p_remove_dir = "./".$p_remove_dir;
1538
+ }
1539
+ if ( (substr($p_filename, 0, 2) != "./")
1540
+ && (substr($p_remove_dir, 0, 2) == "./")) {
1541
+ $p_remove_dir = substr($p_remove_dir, 2);
1542
+ }
1543
+ }
1544
+ $v_compare = PclZipUtilPathInclusion($p_remove_dir,
1545
+ $v_stored_filename);
1546
+ if ($v_compare > 0) {
1547
+ if ($v_compare == 2) {
1548
+ $v_stored_filename = "";
1549
+ }
1550
+ else {
1551
+ $v_stored_filename = substr($v_stored_filename,
1552
+ strlen($p_remove_dir));
1553
+ }
1554
+ }
1555
+ }
1556
+ $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
1557
+ if ($p_add_dir != "") {
1558
+ if (substr($p_add_dir, -1) == "/")
1559
+ $v_stored_filename = $p_add_dir.$v_stored_filename;
1560
+ else
1561
+ $v_stored_filename = $p_add_dir."/".$v_stored_filename;
1562
+ }
1563
+ }
1564
+ $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
1565
+ $p_filedescr['stored_filename'] = $v_stored_filename;
1566
+ return $v_result;
1567
+ }
1568
+ function privWriteFileHeader(&$p_header)
1569
+ {
1570
+ $v_result=1;
1571
+ $p_header['offset'] = ftell($this->zip_fd);
1572
+ $v_date = getdate($p_header['mtime']);
1573
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
1574
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
1575
+ $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
1576
+ $p_header['version_extracted'], $p_header['flag'],
1577
+ $p_header['compression'], $v_mtime, $v_mdate,
1578
+ $p_header['crc'], $p_header['compressed_size'],
1579
+ $p_header['size'],
1580
+ strlen($p_header['stored_filename']),
1581
+ $p_header['extra_len']);
1582
+ fputs($this->zip_fd, $v_binary_data, 30);
1583
+ if (strlen($p_header['stored_filename']) != 0)
1584
+ {
1585
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
1586
+ }
1587
+ if ($p_header['extra_len'] != 0)
1588
+ {
1589
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
1590
+ }
1591
+ return $v_result;
1592
+ }
1593
+ function privWriteCentralFileHeader(&$p_header)
1594
+ {
1595
+ $v_result=1;
1596
+ $v_date = getdate($p_header['mtime']);
1597
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
1598
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
1599
+ $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
1600
+ $p_header['version'], $p_header['version_extracted'],
1601
+ $p_header['flag'], $p_header['compression'],
1602
+ $v_mtime, $v_mdate, $p_header['crc'],
1603
+ $p_header['compressed_size'], $p_header['size'],
1604
+ strlen($p_header['stored_filename']),
1605
+ $p_header['extra_len'], $p_header['comment_len'],
1606
+ $p_header['disk'], $p_header['internal'],
1607
+ $p_header['external'], $p_header['offset']);
1608
+ fputs($this->zip_fd, $v_binary_data, 46);
1609
+ if (strlen($p_header['stored_filename']) != 0)
1610
+ {
1611
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
1612
+ }
1613
+ if ($p_header['extra_len'] != 0)
1614
+ {
1615
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
1616
+ }
1617
+ if ($p_header['comment_len'] != 0)
1618
+ {
1619
+ fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
1620
+ }
1621
+ return $v_result;
1622
+ }
1623
+ function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
1624
+ {
1625
+ $v_result=1;
1626
+ $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
1627
+ $p_nb_entries, $p_size,
1628
+ $p_offset, strlen($p_comment));
1629
+ fputs($this->zip_fd, $v_binary_data, 22);
1630
+ if (strlen($p_comment) != 0)
1631
+ {
1632
+ fputs($this->zip_fd, $p_comment, strlen($p_comment));
1633
+ }
1634
+ return $v_result;
1635
+ }
1636
+ function privList(&$p_list)
1637
+ {
1638
+ $v_result=1;
1639
+ $this->privDisableMagicQuotes();
1640
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
1641
+ {
1642
+ $this->privSwapBackMagicQuotes();
1643
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
1644
+ return PclZip::errorCode();
1645
+ }
1646
+ $v_central_dir = array();
1647
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1648
+ {
1649
+ $this->privSwapBackMagicQuotes();
1650
+ return $v_result;
1651
+ }
1652
+ @rewind($this->zip_fd);
1653
+ if (@fseek($this->zip_fd, $v_central_dir['offset']))
1654
+ {
1655
+ $this->privSwapBackMagicQuotes();
1656
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1657
+ return PclZip::errorCode();
1658
+ }
1659
+ for ($i=0; $i<$v_central_dir['entries']; $i++)
1660
+ {
1661
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
1662
+ {
1663
+ $this->privSwapBackMagicQuotes();
1664
+ return $v_result;
1665
+ }
1666
+ $v_header['index'] = $i;
1667
+ $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
1668
+ unset($v_header);
1669
+ }
1670
+ $this->privCloseFd();
1671
+ $this->privSwapBackMagicQuotes();
1672
+ return $v_result;
1673
+ }
1674
+ function privConvertHeader2FileInfo($p_header, &$p_info)
1675
+ {
1676
+ $v_result=1;
1677
+ $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
1678
+ $p_info['filename'] = $v_temp_path;
1679
+ $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
1680
+ $p_info['stored_filename'] = $v_temp_path;
1681
+ $p_info['size'] = $p_header['size'];
1682
+ $p_info['compressed_size'] = $p_header['compressed_size'];
1683
+ $p_info['mtime'] = $p_header['mtime'];
1684
+ $p_info['comment'] = $p_header['comment'];
1685
+ $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
1686
+ $p_info['index'] = $p_header['index'];
1687
+ $p_info['status'] = $p_header['status'];
1688
+ $p_info['crc'] = $p_header['crc'];
1689
+ return $v_result;
1690
+ }
1691
+ function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
1692
+ {
1693
+ $v_result=1;
1694
+ $this->privDisableMagicQuotes();
1695
+ if ( ($p_path == "")
1696
+ || ( (substr($p_path, 0, 1) != "/")
1697
+ && (substr($p_path, 0, 3) != "../")
1698
+ && (substr($p_path,1,2)!=":/")))
1699
+ $p_path = "./".$p_path;
1700
+ if (($p_path != "./") && ($p_path != "/"))
1701
+ {
1702
+ while (substr($p_path, -1) == "/")
1703
+ {
1704
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
1705
+ }
1706
+ }
1707
+ if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
1708
+ {
1709
+ $p_remove_path .= '/';
1710
+ }
1711
+ $p_remove_path_size = strlen($p_remove_path);
1712
+ if (($v_result = $this->privOpenFd('rb')) != 1)
1713
+ {
1714
+ $this->privSwapBackMagicQuotes();
1715
+ return $v_result;
1716
+ }
1717
+ $v_central_dir = array();
1718
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1719
+ {
1720
+ $this->privCloseFd();
1721
+ $this->privSwapBackMagicQuotes();
1722
+ return $v_result;
1723
+ }
1724
+ $v_pos_entry = $v_central_dir['offset'];
1725
+ $j_start = 0;
1726
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
1727
+ {
1728
+ @rewind($this->zip_fd);
1729
+ if (@fseek($this->zip_fd, $v_pos_entry))
1730
+ {
1731
+ $this->privCloseFd();
1732
+ $this->privSwapBackMagicQuotes();
1733
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1734
+ return PclZip::errorCode();
1735
+ }
1736
+ $v_header = array();
1737
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
1738
+ {
1739
+ $this->privCloseFd();
1740
+ $this->privSwapBackMagicQuotes();
1741
+ return $v_result;
1742
+ }
1743
+ $v_header['index'] = $i;
1744
+ $v_pos_entry = ftell($this->zip_fd);
1745
+ $v_extract = false;
1746
+ if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
1747
+ && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
1748
+ for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
1749
+ if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
1750
+ if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
1751
+ && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
1752
+ $v_extract = true;
1753
+ }
1754
+ }
1755
+ elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
1756
+ $v_extract = true;
1757
+ }
1758
+ }
1759
+ }
1760
+ /*
1761
+ else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
1762
+ && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
1763
+ if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
1764
+ $v_extract = true;
1765
+ }
1766
+ }
1767
+ */
1768
+ else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
1769
+ && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
1770
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
1771
+ $v_extract = true;
1772
+ }
1773
+ }
1774
+ else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
1775
+ && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
1776
+ for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
1777
+ if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
1778
+ $v_extract = true;
1779
+ }
1780
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
1781
+ $j_start = $j+1;
1782
+ }
1783
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
1784
+ break;
1785
+ }
1786
+ }
1787
+ }
1788
+ else {
1789
+ $v_extract = true;
1790
+ }
1791
+ // ----- Check compression method
1792
+ if ( ($v_extract)
1793
+ && ( ($v_header['compression'] != 8)
1794
+ && ($v_header['compression'] != 0))) {
1795
+ $v_header['status'] = 'unsupported_compression';
1796
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1797
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1798
+ $this->privSwapBackMagicQuotes();
1799
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
1800
+ "Filename '".$v_header['stored_filename']."' is "
1801
+ ."compressed by an unsupported compression "
1802
+ ."method (".$v_header['compression'].") ");
1803
+ return PclZip::errorCode();
1804
+ }
1805
+ }
1806
+ // ----- Check encrypted files
1807
+ if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
1808
+ $v_header['status'] = 'unsupported_encryption';
1809
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1810
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1811
+ $this->privSwapBackMagicQuotes();
1812
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
1813
+ "Unsupported encryption for "
1814
+ ." filename '".$v_header['stored_filename']
1815
+ ."'");
1816
+ return PclZip::errorCode();
1817
+ }
1818
+ }
1819
+ if (($v_extract) && ($v_header['status'] != 'ok')) {
1820
+ $v_result = $this->privConvertHeader2FileInfo($v_header,
1821
+ $p_file_list[$v_nb_extracted++]);
1822
+ if ($v_result != 1) {
1823
+ $this->privCloseFd();
1824
+ $this->privSwapBackMagicQuotes();
1825
+ return $v_result;
1826
+ }
1827
+ $v_extract = false;
1828
+ }
1829
+ if ($v_extract)
1830
+ {
1831
+ @rewind($this->zip_fd);
1832
+ if (@fseek($this->zip_fd, $v_header['offset']))
1833
+ {
1834
+ $this->privCloseFd();
1835
+ $this->privSwapBackMagicQuotes();
1836
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
1837
+ return PclZip::errorCode();
1838
+ }
1839
+ if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
1840
+ $v_string = '';
1841
+ $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
1842
+ if ($v_result1 < 1) {
1843
+ $this->privCloseFd();
1844
+ $this->privSwapBackMagicQuotes();
1845
+ return $v_result1;
1846
+ }
1847
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
1848
+ {
1849
+ $this->privCloseFd();
1850
+ $this->privSwapBackMagicQuotes();
1851
+ return $v_result;
1852
+ }
1853
+ $p_file_list[$v_nb_extracted]['content'] = $v_string;
1854
+ $v_nb_extracted++;
1855
+ if ($v_result1 == 2) {
1856
+ break;
1857
+ }
1858
+ }
1859
+ elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
1860
+ && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
1861
+ $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
1862
+ if ($v_result1 < 1) {
1863
+ $this->privCloseFd();
1864
+ $this->privSwapBackMagicQuotes();
1865
+ return $v_result1;
1866
+ }
1867
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
1868
+ $this->privCloseFd();
1869
+ $this->privSwapBackMagicQuotes();
1870
+ return $v_result;
1871
+ }
1872
+ if ($v_result1 == 2) {
1873
+ break;
1874
+ }
1875
+ }
1876
+ else {
1877
+ $v_result1 = $this->privExtractFile($v_header,
1878
+ $p_path, $p_remove_path,
1879
+ $p_remove_all_path,
1880
+ $p_options);
1881
+ if ($v_result1 < 1) {
1882
+ $this->privCloseFd();
1883
+ $this->privSwapBackMagicQuotes();
1884
+ return $v_result1;
1885
+ }
1886
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
1887
+ {
1888
+ $this->privCloseFd();
1889
+ $this->privSwapBackMagicQuotes();
1890
+ return $v_result;
1891
+ }
1892
+ if ($v_result1 == 2) {
1893
+ break;
1894
+ }
1895
+ }
1896
+ }
1897
+ }
1898
+ $this->privCloseFd();
1899
+ $this->privSwapBackMagicQuotes();
1900
+ return $v_result;
1901
+ }
1902
+ function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
1903
+ {
1904
+ $v_result=1;
1905
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1)
1906
+ {
1907
+ return $v_result;
1908
+ }
1909
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
1910
+ }
1911
+ if ($p_remove_all_path == true) {
1912
+ if (($p_entry['external']&0x00000010)==0x00000010) {
1913
+ $p_entry['status'] = "filtered";
1914
+ return $v_result;
1915
+ }
1916
+ $p_entry['filename'] = basename($p_entry['filename']);
1917
+ }
1918
+ else if ($p_remove_path != "")
1919
+ {
1920
+ if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
1921
+ {
1922
+ $p_entry['status'] = "filtered";
1923
+ return $v_result;
1924
+ }
1925
+ $p_remove_path_size = strlen($p_remove_path);
1926
+ if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
1927
+ {
1928
+ $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
1929
+ }
1930
+ }
1931
+ if ($p_path != '') {
1932
+ $p_entry['filename'] = $p_path."/".$p_entry['filename'];
1933
+ }
1934
+ if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
1935
+ $v_inclusion
1936
+ = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
1937
+ $p_entry['filename']);
1938
+ if ($v_inclusion == 0) {
1939
+ PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
1940
+ "Filename '".$p_entry['filename']."' is "
1941
+ ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
1942
+ return PclZip::errorCode();
1943
+ }
1944
+ }
1945
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
1946
+ $v_local_header = array();
1947
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
1948
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
1949
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
1950
+ if ($v_result == 0) {
1951
+ $p_entry['status'] = "skipped";
1952
+ $v_result = 1;
1953
+ }
1954
+ if ($v_result == 2) {
1955
+ $p_entry['status'] = "aborted";
1956
+ $v_result = PCLZIP_ERR_USER_ABORTED;
1957
+ }
1958
+ $p_entry['filename'] = $v_local_header['filename'];
1959
+ }
1960
+ if ($p_entry['status'] == 'ok') {
1961
+ if (file_exists($p_entry['filename']))
1962
+ {
1963
+ if (is_dir($p_entry['filename']))
1964
+ {
1965
+ $p_entry['status'] = "already_a_directory";
1966
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1967
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1968
+ PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
1969
+ "Filename '".$p_entry['filename']."' is "
1970
+ ."already used by an existing directory");
1971
+ return PclZip::errorCode();
1972
+ }
1973
+ }
1974
+ else if (!is_writeable($p_entry['filename']))
1975
+ {
1976
+ $p_entry['status'] = "write_protected";
1977
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1978
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1979
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
1980
+ "Filename '".$p_entry['filename']."' exists "
1981
+ ."and is write protected");
1982
+ return PclZip::errorCode();
1983
+ }
1984
+ }
1985
+ else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
1986
+ {
1987
+ if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
1988
+ && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
1989
+ }
1990
+ else {
1991
+ $p_entry['status'] = "newer_exist";
1992
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
1993
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
1994
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
1995
+ "Newer version of '".$p_entry['filename']."' exists "
1996
+ ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
1997
+ return PclZip::errorCode();
1998
+ }
1999
+ }
2000
+ }
2001
+ else {
2002
+ }
2003
+ }
2004
+ else {
2005
+ if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
2006
+ $v_dir_to_check = $p_entry['filename'];
2007
+ else if (!strstr($p_entry['filename'], "/"))
2008
+ $v_dir_to_check = "";
2009
+ else
2010
+ $v_dir_to_check = dirname($p_entry['filename']);
2011
+ if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
2012
+ $p_entry['status'] = "path_creation_fail";
2013
+ $v_result = 1;
2014
+ }
2015
+ }
2016
+ }
2017
+ if ($p_entry['status'] == 'ok') {
2018
+ if (!(($p_entry['external']&0x00000010)==0x00000010))
2019
+ {
2020
+ if ($p_entry['compression'] == 0) {
2021
+ // ----- Opening destination file
2022
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
2023
+ {
2024
+ $p_entry['status'] = "write_error";
2025
+ return $v_result;
2026
+ }
2027
+ $v_size = $p_entry['compressed_size'];
2028
+ while ($v_size != 0)
2029
+ {
2030
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2031
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
2032
+ /* Try to speed up the code
2033
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);
2034
+ @fwrite($v_dest_file, $v_binary_data, $v_read_size);
2035
+ */
2036
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
2037
+ $v_size -= $v_read_size;
2038
+ }
2039
+ fclose($v_dest_file);
2040
+ touch($p_entry['filename'], $p_entry['mtime']);
2041
+ }
2042
+ else {
2043
+ if (($p_entry['flag'] & 1) == 1) {
2044
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
2045
+ return PclZip::errorCode();
2046
+ }
2047
+ if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
2048
+ && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
2049
+ || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
2050
+ && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
2051
+ $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
2052
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
2053
+ return $v_result;
2054
+ }
2055
+ }
2056
+ else {
2057
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2058
+ $v_file_content = @gzinflate($v_buffer);
2059
+ unset($v_buffer);
2060
+ if ($v_file_content === FALSE) {
2061
+ $p_entry['status'] = "error";
2062
+ return $v_result;
2063
+ }
2064
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
2065
+ $p_entry['status'] = "write_error";
2066
+ return $v_result;
2067
+ }
2068
+ @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
2069
+ unset($v_file_content);
2070
+ @fclose($v_dest_file);
2071
+ }
2072
+ @touch($p_entry['filename'], $p_entry['mtime']);
2073
+ }
2074
+ if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
2075
+ @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
2076
+ }
2077
+ }
2078
+ }
2079
+ // ----- Change abort status
2080
+ if ($p_entry['status'] == "aborted") {
2081
+ $p_entry['status'] = "skipped";
2082
+ }
2083
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2084
+ $v_local_header = array();
2085
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2086
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2087
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2088
+ if ($v_result == 2) {
2089
+ $v_result = PCLZIP_ERR_USER_ABORTED;
2090
+ }
2091
+ }
2092
+ return $v_result;
2093
+ }
2094
+ function privExtractFileUsingTempFile(&$p_entry, &$p_options)
2095
+ {
2096
+ $v_result=1;
2097
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
2098
+ if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
2099
+ fclose($v_file);
2100
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
2101
+ return PclZip::errorCode();
2102
+ }
2103
+ $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
2104
+ @fwrite($v_dest_file, $v_binary_data, 10);
2105
+ $v_size = $p_entry['compressed_size'];
2106
+ while ($v_size != 0)
2107
+ {
2108
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2109
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
2110
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
2111
+ $v_size -= $v_read_size;
2112
+ }
2113
+ $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
2114
+ @fwrite($v_dest_file, $v_binary_data, 8);
2115
+ @fclose($v_dest_file);
2116
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
2117
+ $p_entry['status'] = "write_error";
2118
+ return $v_result;
2119
+ }
2120
+ if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
2121
+ @fclose($v_dest_file);
2122
+ $p_entry['status'] = "read_error";
2123
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
2124
+ return PclZip::errorCode();
2125
+ }
2126
+ $v_size = $p_entry['size'];
2127
+ while ($v_size != 0) {
2128
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2129
+ $v_buffer = @gzread($v_src_file, $v_read_size);
2130
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
2131
+ $v_size -= $v_read_size;
2132
+ }
2133
+ @fclose($v_dest_file);
2134
+ @gzclose($v_src_file);
2135
+ @unlink($v_gzip_temp_name);
2136
+ return $v_result;
2137
+ }
2138
+ function privExtractFileInOutput(&$p_entry, &$p_options)
2139
+ {
2140
+ $v_result=1;
2141
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
2142
+ return $v_result;
2143
+ }
2144
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
2145
+ }
2146
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
2147
+ $v_local_header = array();
2148
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2149
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
2150
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
2151
+ if ($v_result == 0) {
2152
+ $p_entry['status'] = "skipped";
2153
+ $v_result = 1;
2154
+ }
2155
+ if ($v_result == 2) {
2156
+ $p_entry['status'] = "aborted";
2157
+ $v_result = PCLZIP_ERR_USER_ABORTED;
2158
+ }
2159
+ $p_entry['filename'] = $v_local_header['filename'];
2160
+ }
2161
+ if ($p_entry['status'] == 'ok') {
2162
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
2163
+ if ($p_entry['compressed_size'] == $p_entry['size']) {
2164
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2165
+ echo $v_buffer;
2166
+ unset($v_buffer);
2167
+ }
2168
+ else {
2169
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
2170
+ $v_file_content = gzinflate($v_buffer);
2171
+ unset($v_buffer);
2172
+ echo $v_file_content;
2173
+ unset($v_file_content);
2174
+ }
2175
+ }
2176
+ }
2177
+ // ----- Change abort status
2178
+ if ($p_entry['status'] == "aborted") {
2179
+ $p_entry['status'] = "skipped";
2180
+ }
2181
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2182
+ $v_local_header = array();
2183
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2184
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2185
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2186
+ if ($v_result == 2) {
2187
+ $v_result = PCLZIP_ERR_USER_ABORTED;
2188
+ }
2189
+ }
2190
+ return $v_result;
2191
+ }
2192
+ function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
2193
+ {
2194
+ $v_result=1;
2195
+ $v_header = array();
2196
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1)
2197
+ {
2198
+ return $v_result;
2199
+ }
2200
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
2201
+ }
2202
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
2203
+ $v_local_header = array();
2204
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2205
+ // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
2206
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
2207
+ if ($v_result == 0) {
2208
+ $p_entry['status'] = "skipped";
2209
+ $v_result = 1;
2210
+ }
2211
+ if ($v_result == 2) {
2212
+ $p_entry['status'] = "aborted";
2213
+ $v_result = PCLZIP_ERR_USER_ABORTED;
2214
+ }
2215
+ $p_entry['filename'] = $v_local_header['filename'];
2216
+ }
2217
+ if ($p_entry['status'] == 'ok') {
2218
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
2219
+ if ($p_entry['compression'] == 0) {
2220
+ $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
2221
+ }
2222
+ else {
2223
+ $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
2224
+ if (($p_string = @gzinflate($v_data)) === FALSE) {
2225
+ }
2226
+ }
2227
+ }
2228
+ else {
2229
+ }
2230
+ }
2231
+ // ----- Change abort status
2232
+ if ($p_entry['status'] == "aborted") {
2233
+ $p_entry['status'] = "skipped";
2234
+ }
2235
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
2236
+ $v_local_header = array();
2237
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
2238
+ $v_local_header['content'] = $p_string;
2239
+ $p_string = '';
2240
+ // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
2241
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
2242
+ $p_string = $v_local_header['content'];
2243
+ unset($v_local_header['content']);
2244
+ if ($v_result == 2) {
2245
+ $v_result = PCLZIP_ERR_USER_ABORTED;
2246
+ }
2247
+ }
2248
+ return $v_result;
2249
+ }
2250
+ function privReadFileHeader(&$p_header)
2251
+ {
2252
+ $v_result=1;
2253
+ $v_binary_data = @fread($this->zip_fd, 4);
2254
+ $v_data = unpack('Vid', $v_binary_data);
2255
+ if ($v_data['id'] != 0x04034b50)
2256
+ {
2257
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
2258
+ return PclZip::errorCode();
2259
+ }
2260
+ $v_binary_data = fread($this->zip_fd, 26);
2261
+ if (strlen($v_binary_data) != 26)
2262
+ {
2263
+ $p_header['filename'] = "";
2264
+ $p_header['status'] = "invalid_header";
2265
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
2266
+ return PclZip::errorCode();
2267
+ }
2268
+ $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
2269
+ $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
2270
+ if ($v_data['extra_len'] != 0) {
2271
+ $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
2272
+ }
2273
+ else {
2274
+ $p_header['extra'] = '';
2275
+ }
2276
+ $p_header['version_extracted'] = $v_data['version'];
2277
+ $p_header['compression'] = $v_data['compression'];
2278
+ $p_header['size'] = $v_data['size'];
2279
+ $p_header['compressed_size'] = $v_data['compressed_size'];
2280
+ $p_header['crc'] = $v_data['crc'];
2281
+ $p_header['flag'] = $v_data['flag'];
2282
+ $p_header['filename_len'] = $v_data['filename_len'];
2283
+ $p_header['mdate'] = $v_data['mdate'];
2284
+ $p_header['mtime'] = $v_data['mtime'];
2285
+ if ($p_header['mdate'] && $p_header['mtime'])
2286
+ {
2287
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
2288
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
2289
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
2290
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
2291
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
2292
+ $v_day = $p_header['mdate'] & 0x001F;
2293
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
2294
+ }
2295
+ else
2296
+ {
2297
+ $p_header['mtime'] = time();
2298
+ }
2299
+ $p_header['stored_filename'] = $p_header['filename'];
2300
+ $p_header['status'] = "ok";
2301
+ return $v_result;
2302
+ }
2303
+ function privReadCentralFileHeader(&$p_header)
2304
+ {
2305
+ $v_result=1;
2306
+ $v_binary_data = @fread($this->zip_fd, 4);
2307
+ $v_data = unpack('Vid', $v_binary_data);
2308
+ if ($v_data['id'] != 0x02014b50)
2309
+ {
2310
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
2311
+ return PclZip::errorCode();
2312
+ }
2313
+ $v_binary_data = fread($this->zip_fd, 42);
2314
+ if (strlen($v_binary_data) != 42)
2315
+ {
2316
+ $p_header['filename'] = "";
2317
+ $p_header['status'] = "invalid_header";
2318
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
2319
+ return PclZip::errorCode();
2320
+ }
2321
+ $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
2322
+ if ($p_header['filename_len'] != 0)
2323
+ $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
2324
+ else
2325
+ $p_header['filename'] = '';
2326
+ if ($p_header['extra_len'] != 0)
2327
+ $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
2328
+ else
2329
+ $p_header['extra'] = '';
2330
+ if ($p_header['comment_len'] != 0)
2331
+ $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
2332
+ else
2333
+ $p_header['comment'] = '';
2334
+ if (1)
2335
+ {
2336
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
2337
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
2338
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
2339
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
2340
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
2341
+ $v_day = $p_header['mdate'] & 0x001F;
2342
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
2343
+ }
2344
+ else
2345
+ {
2346
+ $p_header['mtime'] = time();
2347
+ }
2348
+ $p_header['stored_filename'] = $p_header['filename'];
2349
+ $p_header['status'] = 'ok';
2350
+ if (substr($p_header['filename'], -1) == '/') {
2351
+ $p_header['external'] = 0x00000010;
2352
+ }
2353
+ return $v_result;
2354
+ }
2355
+ function privCheckFileHeaders(&$p_local_header, &$p_central_header)
2356
+ {
2357
+ $v_result=1;
2358
+ // ----- Check the static values
2359
+ // TBC
2360
+ if ($p_local_header['filename'] != $p_central_header['filename']) {
2361
+ }
2362
+ if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
2363
+ }
2364
+ if ($p_local_header['flag'] != $p_central_header['flag']) {
2365
+ }
2366
+ if ($p_local_header['compression'] != $p_central_header['compression']) {
2367
+ }
2368
+ if ($p_local_header['mtime'] != $p_central_header['mtime']) {
2369
+ }
2370
+ if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
2371
+ }
2372
+ // ----- Look for flag bit 3
2373
+ if (($p_local_header['flag'] & 8) == 8) {
2374
+ $p_local_header['size'] = $p_central_header['size'];
2375
+ $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
2376
+ $p_local_header['crc'] = $p_central_header['crc'];
2377
+ }
2378
+ return $v_result;
2379
+ }
2380
+ function privReadEndCentralDir(&$p_central_dir)
2381
+ {
2382
+ $v_result=1;
2383
+ $v_size = filesize($this->zipname);
2384
+ @fseek($this->zip_fd, $v_size);
2385
+ if (@ftell($this->zip_fd) != $v_size)
2386
+ {
2387
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
2388
+ return PclZip::errorCode();
2389
+ }
2390
+ $v_found = 0;
2391
+ if ($v_size > 26) {
2392
+ @fseek($this->zip_fd, $v_size-22);
2393
+ if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
2394
+ {
2395
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
2396
+ return PclZip::errorCode();
2397
+ }
2398
+ $v_binary_data = @fread($this->zip_fd, 4);
2399
+ $v_data = @unpack('Vid', $v_binary_data);
2400
+ if ($v_data['id'] == 0x06054b50) {
2401
+ $v_found = 1;
2402
+ }
2403
+ $v_pos = ftell($this->zip_fd);
2404
+ }
2405
+ if (!$v_found) {
2406
+ $v_maximum_size = 65557; // 0xFFFF + 22;
2407
+ if ($v_maximum_size > $v_size)
2408
+ $v_maximum_size = $v_size;
2409
+ @fseek($this->zip_fd, $v_size-$v_maximum_size);
2410
+ if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
2411
+ {
2412
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
2413
+ return PclZip::errorCode();
2414
+ }
2415
+ $v_pos = ftell($this->zip_fd);
2416
+ $v_bytes = 0x00000000;
2417
+ while ($v_pos < $v_size)
2418
+ {
2419
+ $v_byte = @fread($this->zip_fd, 1);
2420
+ $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
2421
+ if ($v_bytes == 0x504b0506)
2422
+ {
2423
+ $v_pos++;
2424
+ break;
2425
+ }
2426
+ $v_pos++;
2427
+ }
2428
+ if ($v_pos == $v_size)
2429
+ {
2430
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
2431
+ return PclZip::errorCode();
2432
+ }
2433
+ }
2434
+ $v_binary_data = fread($this->zip_fd, 18);
2435
+ if (strlen($v_binary_data) != 18)
2436
+ {
2437
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
2438
+ return PclZip::errorCode();
2439
+ }
2440
+ $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
2441
+ if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
2442
+ // ----- Removed in release 2.2 see readme file
2443
+ // The check of the file size is a little too strict.
2444
+ // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
2445
+ // While decrypted, zip has training 0 bytes
2446
+ if (0) {
2447
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
2448
+ 'The central dir is not at the end of the archive.'
2449
+ .' Some trailing bytes exists after the archive.');
2450
+ return PclZip::errorCode();
2451
+ }
2452
+ }
2453
+ if ($v_data['comment_size'] != 0) {
2454
+ $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
2455
+ }
2456
+ else
2457
+ $p_central_dir['comment'] = '';
2458
+ $p_central_dir['entries'] = $v_data['entries'];
2459
+ $p_central_dir['disk_entries'] = $v_data['disk_entries'];
2460
+ $p_central_dir['offset'] = $v_data['offset'];
2461
+ $p_central_dir['size'] = $v_data['size'];
2462
+ $p_central_dir['disk'] = $v_data['disk'];
2463
+ $p_central_dir['disk_start'] = $v_data['disk_start'];
2464
+ return $v_result;
2465
+ }
2466
+ function privDeleteByRule(&$p_result_list, &$p_options)
2467
+ {
2468
+ $v_result=1;
2469
+ $v_list_detail = array();
2470
+ if (($v_result=$this->privOpenFd('rb')) != 1)
2471
+ {
2472
+ return $v_result;
2473
+ }
2474
+ $v_central_dir = array();
2475
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
2476
+ {
2477
+ $this->privCloseFd();
2478
+ return $v_result;
2479
+ }
2480
+ @rewind($this->zip_fd);
2481
+ $v_pos_entry = $v_central_dir['offset'];
2482
+ @rewind($this->zip_fd);
2483
+ if (@fseek($this->zip_fd, $v_pos_entry))
2484
+ {
2485
+ $this->privCloseFd();
2486
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
2487
+ return PclZip::errorCode();
2488
+ }
2489
+ $v_header_list = array();
2490
+ $j_start = 0;
2491
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
2492
+ {
2493
+ $v_header_list[$v_nb_extracted] = array();
2494
+ if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
2495
+ {
2496
+ $this->privCloseFd();
2497
+ return $v_result;
2498
+ }
2499
+ $v_header_list[$v_nb_extracted]['index'] = $i;
2500
+ $v_found = false;
2501
+ if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
2502
+ && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
2503
+ for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
2504
+ if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
2505
+ if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
2506
+ && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
2507
+ $v_found = true;
2508
+ }
2509
+ elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
2510
+ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
2511
+ $v_found = true;
2512
+ }
2513
+ }
2514
+ elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
2515
+ $v_found = true;
2516
+ }
2517
+ }
2518
+ }
2519
+ /*
2520
+ else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
2521
+ && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
2522
+ if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
2523
+ $v_found = true;
2524
+ }
2525
+ }
2526
+ */
2527
+ else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
2528
+ && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
2529
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
2530
+ $v_found = true;
2531
+ }
2532
+ }
2533
+ else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
2534
+ && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
2535
+ for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
2536
+ if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
2537
+ $v_found = true;
2538
+ }
2539
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
2540
+ $j_start = $j+1;
2541
+ }
2542
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
2543
+ break;
2544
+ }
2545
+ }
2546
+ }
2547
+ else {
2548
+ $v_found = true;
2549
+ }
2550
+ if ($v_found)
2551
+ {
2552
+ unset($v_header_list[$v_nb_extracted]);
2553
+ }
2554
+ else
2555
+ {
2556
+ $v_nb_extracted++;
2557
+ }
2558
+ }
2559
+ if ($v_nb_extracted > 0) {
2560
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
2561
+ $v_temp_zip = new PclZip($v_zip_temp_name);
2562
+ if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
2563
+ $this->privCloseFd();
2564
+ return $v_result;
2565
+ }
2566
+ for ($i=0; $i<sizeof($v_header_list); $i++) {
2567
+ @rewind($this->zip_fd);
2568
+ if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
2569
+ $this->privCloseFd();
2570
+ $v_temp_zip->privCloseFd();
2571
+ @unlink($v_zip_temp_name);
2572
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
2573
+ return PclZip::errorCode();
2574
+ }
2575
+ $v_local_header = array();
2576
+ if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
2577
+ $this->privCloseFd();
2578
+ $v_temp_zip->privCloseFd();
2579
+ @unlink($v_zip_temp_name);
2580
+ return $v_result;
2581
+ }
2582
+ if ($this->privCheckFileHeaders($v_local_header,
2583
+ $v_header_list[$i]) != 1) {
2584
+ }
2585
+ unset($v_local_header);
2586
+ if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
2587
+ $this->privCloseFd();
2588
+ $v_temp_zip->privCloseFd();
2589
+ @unlink($v_zip_temp_name);
2590
+ return $v_result;
2591
+ }
2592
+ if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
2593
+ $this->privCloseFd();
2594
+ $v_temp_zip->privCloseFd();
2595
+ @unlink($v_zip_temp_name);
2596
+ return $v_result;
2597
+ }
2598
+ }
2599
+ $v_offset = @ftell($v_temp_zip->zip_fd);
2600
+ for ($i=0; $i<sizeof($v_header_list); $i++) {
2601
+ if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
2602
+ $v_temp_zip->privCloseFd();
2603
+ $this->privCloseFd();
2604
+ @unlink($v_zip_temp_name);
2605
+ return $v_result;
2606
+ }
2607
+ $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
2608
+ }
2609
+ $v_comment = '';
2610
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
2611
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
2612
+ }
2613
+ $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
2614
+ if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
2615
+ unset($v_header_list);
2616
+ $v_temp_zip->privCloseFd();
2617
+ $this->privCloseFd();
2618
+ @unlink($v_zip_temp_name);
2619
+ return $v_result;
2620
+ }
2621
+ $v_temp_zip->privCloseFd();
2622
+ $this->privCloseFd();
2623
+ @unlink($this->zipname);
2624
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
2625
+ unset($v_temp_zip);
2626
+ }
2627
+ else if ($v_central_dir['entries'] != 0) {
2628
+ $this->privCloseFd();
2629
+ if (($v_result = $this->privOpenFd('wb')) != 1) {
2630
+ return $v_result;
2631
+ }
2632
+ if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
2633
+ return $v_result;
2634
+ }
2635
+ $this->privCloseFd();
2636
+ }
2637
+ return $v_result;
2638
+ }
2639
+ function privDirCheck($p_dir, $p_is_dir=false)
2640
+ {
2641
+ $v_result = 1;
2642
+ if (($p_is_dir) && (substr($p_dir, -1)=='/'))
2643
+ {
2644
+ $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
2645
+ }
2646
+ if ((is_dir($p_dir)) || ($p_dir == ""))
2647
+ {
2648
+ return 1;
2649
+ }
2650
+ $p_parent_dir = dirname($p_dir);
2651
+ if ($p_parent_dir != $p_dir)
2652
+ {
2653
+ if ($p_parent_dir != "")
2654
+ {
2655
+ if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
2656
+ {
2657
+ return $v_result;
2658
+ }
2659
+ }
2660
+ }
2661
+ if (!@mkdir($p_dir, 0777))
2662
+ {
2663
+ PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
2664
+ return PclZip::errorCode();
2665
+ }
2666
+ return $v_result;
2667
+ }
2668
+ function privMerge(&$p_archive_to_add)
2669
+ {
2670
+ $v_result=1;
2671
+ if (!is_file($p_archive_to_add->zipname))
2672
+ {
2673
+ $v_result = 1;
2674
+ return $v_result;
2675
+ }
2676
+ if (!is_file($this->zipname))
2677
+ {
2678
+ $v_result = $this->privDuplicate($p_archive_to_add->zipname);
2679
+ return $v_result;
2680
+ }
2681
+ if (($v_result=$this->privOpenFd('rb')) != 1)
2682
+ {
2683
+ return $v_result;
2684
+ }
2685
+ $v_central_dir = array();
2686
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
2687
+ {
2688
+ $this->privCloseFd();
2689
+ return $v_result;
2690
+ }
2691
+ @rewind($this->zip_fd);
2692
+ if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
2693
+ {
2694
+ $this->privCloseFd();
2695
+ return $v_result;
2696
+ }
2697
+ $v_central_dir_to_add = array();
2698
+ if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
2699
+ {
2700
+ $this->privCloseFd();
2701
+ $p_archive_to_add->privCloseFd();
2702
+ return $v_result;
2703
+ }
2704
+ @rewind($p_archive_to_add->zip_fd);
2705
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
2706
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
2707
+ {
2708
+ $this->privCloseFd();
2709
+ $p_archive_to_add->privCloseFd();
2710
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
2711
+ return PclZip::errorCode();
2712
+ }
2713
+ $v_size = $v_central_dir['offset'];
2714
+ while ($v_size != 0)
2715
+ {
2716
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2717
+ $v_buffer = fread($this->zip_fd, $v_read_size);
2718
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2719
+ $v_size -= $v_read_size;
2720
+ }
2721
+ $v_size = $v_central_dir_to_add['offset'];
2722
+ while ($v_size != 0)
2723
+ {
2724
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2725
+ $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
2726
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2727
+ $v_size -= $v_read_size;
2728
+ }
2729
+ $v_offset = @ftell($v_zip_temp_fd);
2730
+ $v_size = $v_central_dir['size'];
2731
+ while ($v_size != 0)
2732
+ {
2733
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2734
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
2735
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2736
+ $v_size -= $v_read_size;
2737
+ }
2738
+ $v_size = $v_central_dir_to_add['size'];
2739
+ while ($v_size != 0)
2740
+ {
2741
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2742
+ $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
2743
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2744
+ $v_size -= $v_read_size;
2745
+ }
2746
+ $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
2747
+ $v_size = @ftell($v_zip_temp_fd)-$v_offset;
2748
+ $v_swap = $this->zip_fd;
2749
+ $this->zip_fd = $v_zip_temp_fd;
2750
+ $v_zip_temp_fd = $v_swap;
2751
+ if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
2752
+ {
2753
+ $this->privCloseFd();
2754
+ $p_archive_to_add->privCloseFd();
2755
+ @fclose($v_zip_temp_fd);
2756
+ $this->zip_fd = null;
2757
+ unset($v_header_list);
2758
+ return $v_result;
2759
+ }
2760
+ $v_swap = $this->zip_fd;
2761
+ $this->zip_fd = $v_zip_temp_fd;
2762
+ $v_zip_temp_fd = $v_swap;
2763
+ $this->privCloseFd();
2764
+ $p_archive_to_add->privCloseFd();
2765
+ @fclose($v_zip_temp_fd);
2766
+ @unlink($this->zipname);
2767
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
2768
+ return $v_result;
2769
+ }
2770
+ function privDuplicate($p_archive_filename)
2771
+ {
2772
+ $v_result=1;
2773
+ if (!is_file($p_archive_filename))
2774
+ {
2775
+ $v_result = 1;
2776
+ return $v_result;
2777
+ }
2778
+ if (($v_result=$this->privOpenFd('wb')) != 1)
2779
+ {
2780
+ return $v_result;
2781
+ }
2782
+ if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
2783
+ {
2784
+ $this->privCloseFd();
2785
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
2786
+ return PclZip::errorCode();
2787
+ }
2788
+ $v_size = filesize($p_archive_filename);
2789
+ while ($v_size != 0)
2790
+ {
2791
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2792
+ $v_buffer = fread($v_zip_temp_fd, $v_read_size);
2793
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
2794
+ $v_size -= $v_read_size;
2795
+ }
2796
+ $this->privCloseFd();
2797
+ @fclose($v_zip_temp_fd);
2798
+ return $v_result;
2799
+ }
2800
+ function privErrorLog($p_error_code=0, $p_error_string='')
2801
+ {
2802
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
2803
+ PclError($p_error_code, $p_error_string);
2804
+ }
2805
+ else {
2806
+ $this->error_code = $p_error_code;
2807
+ $this->error_string = $p_error_string;
2808
+ }
2809
+ }
2810
+ function privErrorReset()
2811
+ {
2812
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
2813
+ PclErrorReset();
2814
+ }
2815
+ else {
2816
+ $this->error_code = 0;
2817
+ $this->error_string = '';
2818
+ }
2819
+ }
2820
+ function privDisableMagicQuotes()
2821
+ {
2822
+ $v_result=1;
2823
+ if ( (!function_exists("get_magic_quotes_runtime"))
2824
+ || (!function_exists("set_magic_quotes_runtime"))) {
2825
+ return $v_result;
2826
+ }
2827
+ if ($this->magic_quotes_status != -1) {
2828
+ return $v_result;
2829
+ }
2830
+ // ----- Get and memorize the magic_quote value
2831
+ $this->magic_quotes_status = @get_magic_quotes_runtime();
2832
+ // ----- Disable magic_quotes
2833
+ if ($this->magic_quotes_status == 1) {
2834
+ @set_magic_quotes_runtime(0);
2835
+ }
2836
+ return $v_result;
2837
+ }
2838
+ function privSwapBackMagicQuotes()
2839
+ {
2840
+ $v_result=1;
2841
+ if ( (!function_exists("get_magic_quotes_runtime"))
2842
+ || (!function_exists("set_magic_quotes_runtime"))) {
2843
+ return $v_result;
2844
+ }
2845
+ if ($this->magic_quotes_status != -1) {
2846
+ return $v_result;
2847
+ }
2848
+ // ----- Swap back magic_quotes
2849
+ if ($this->magic_quotes_status == 1) {
2850
+ @set_magic_quotes_runtime($this->magic_quotes_status);
2851
+ }
2852
+ return $v_result;
2853
+ }
2854
+ }
2855
+ function PclZipUtilPathReduction($p_dir)
2856
+ {
2857
+ $v_result = "";
2858
+ if ($p_dir != "") {
2859
+ $v_list = explode("/", $p_dir);
2860
+ $v_skip = 0;
2861
+ for ($i=sizeof($v_list)-1; $i>=0; $i--) {
2862
+ if ($v_list[$i] == ".") {
2863
+ }
2864
+ else if ($v_list[$i] == "..") {
2865
+ $v_skip++;
2866
+ }
2867
+ else if ($v_list[$i] == "") {
2868
+ // ----- First '/' i.e. root slash
2869
+ if ($i == 0) {
2870
+ $v_result = "/".$v_result;
2871
+ if ($v_skip > 0) {
2872
+ // ----- It is an invalid path, so the path is not modified
2873
+ // TBC
2874
+ $v_result = $p_dir;
2875
+ $v_skip = 0;
2876
+ }
2877
+ }
2878
+ // ----- Last '/' i.e. indicates a directory
2879
+ else if ($i == (sizeof($v_list)-1)) {
2880
+ $v_result = $v_list[$i];
2881
+ }
2882
+ // ----- Double '/' inside the path
2883
+ else {
2884
+ }
2885
+ }
2886
+ else {
2887
+ // ----- Look for item to skip
2888
+ if ($v_skip > 0) {
2889
+ $v_skip--;
2890
+ }
2891
+ else {
2892
+ $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
2893
+ }
2894
+ }
2895
+ }
2896
+ if ($v_skip > 0) {
2897
+ while ($v_skip > 0) {
2898
+ $v_result = '../'.$v_result;
2899
+ $v_skip--;
2900
+ }
2901
+ }
2902
+ }
2903
+ return $v_result;
2904
+ }
2905
+ function PclZipUtilPathInclusion($p_dir, $p_path)
2906
+ {
2907
+ $v_result = 1;
2908
+ if ( ($p_dir == '.')
2909
+ || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
2910
+ $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
2911
+ }
2912
+ if ( ($p_path == '.')
2913
+ || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
2914
+ $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
2915
+ }
2916
+ $v_list_dir = explode("/", $p_dir);
2917
+ $v_list_dir_size = sizeof($v_list_dir);
2918
+ $v_list_path = explode("/", $p_path);
2919
+ $v_list_path_size = sizeof($v_list_path);
2920
+ $i = 0;
2921
+ $j = 0;
2922
+ while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
2923
+ if ($v_list_dir[$i] == '') {
2924
+ $i++;
2925
+ continue;
2926
+ }
2927
+ if ($v_list_path[$j] == '') {
2928
+ $j++;
2929
+ continue;
2930
+ }
2931
+ if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
2932
+ $v_result = 0;
2933
+ }
2934
+ $i++;
2935
+ $j++;
2936
+ }
2937
+ if ($v_result) {
2938
+ while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
2939
+ while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
2940
+ if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
2941
+ $v_result = 2;
2942
+ }
2943
+ else if ($i < $v_list_dir_size) {
2944
+ $v_result = 0;
2945
+ }
2946
+ }
2947
+ return $v_result;
2948
+ }
2949
+ function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
2950
+ {
2951
+ $v_result = 1;
2952
+ if ($p_mode==0)
2953
+ {
2954
+ while ($p_size != 0)
2955
+ {
2956
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2957
+ $v_buffer = @fread($p_src, $v_read_size);
2958
+ @fwrite($p_dest, $v_buffer, $v_read_size);
2959
+ $p_size -= $v_read_size;
2960
+ }
2961
+ }
2962
+ else if ($p_mode==1)
2963
+ {
2964
+ while ($p_size != 0)
2965
+ {
2966
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2967
+ $v_buffer = @gzread($p_src, $v_read_size);
2968
+ @fwrite($p_dest, $v_buffer, $v_read_size);
2969
+ $p_size -= $v_read_size;
2970
+ }
2971
+ }
2972
+ else if ($p_mode==2)
2973
+ {
2974
+ while ($p_size != 0)
2975
+ {
2976
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2977
+ $v_buffer = @fread($p_src, $v_read_size);
2978
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
2979
+ $p_size -= $v_read_size;
2980
+ }
2981
+ }
2982
+ else if ($p_mode==3)
2983
+ {
2984
+ while ($p_size != 0)
2985
+ {
2986
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
2987
+ $v_buffer = @gzread($p_src, $v_read_size);
2988
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
2989
+ $p_size -= $v_read_size;
2990
+ }
2991
+ }
2992
+ return $v_result;
2993
+ }
2994
+ function PclZipUtilRename($p_src, $p_dest)
2995
+ {
2996
+ $v_result = 1;
2997
+ if (!@rename($p_src, $p_dest)) {
2998
+ if (!@copy($p_src, $p_dest)) {
2999
+ $v_result = 0;
3000
+ }
3001
+ else if (!@unlink($p_src)) {
3002
+ $v_result = 0;
3003
+ }
3004
+ }
3005
+ return $v_result;
3006
+ }
3007
+ function PclZipUtilOptionText($p_option)
3008
+ {
3009
+ $v_list = get_defined_constants();
3010
+ for (reset($v_list); $v_key = key($v_list); next($v_list)) {
3011
+ $v_prefix = substr($v_key, 0, 10);
3012
+ if (( ($v_prefix == 'PCLZIP_OPT')
3013
+ || ($v_prefix == 'PCLZIP_CB_')
3014
+ || ($v_prefix == 'PCLZIP_ATT'))
3015
+ && ($v_list[$v_key] == $p_option)) {
3016
+ return $v_key;
3017
+ }
3018
+ }
3019
+ $v_result = 'Unknown';
3020
+ return $v_result;
3021
+ }
3022
+ function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
3023
+ {
3024
+ if (stristr(php_uname(), 'windows')) {
3025
+ if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
3026
+ $p_path = substr($p_path, $v_position+1);
3027
+ }
3028
+ if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
3029
+ $p_path = strtr($p_path, '\\', '/');
3030
+ }
3031
+ }
3032
+ return $p_path;
3033
+ }
3034
+ ?>
modules/restore-class.php CHANGED
@@ -13,6 +13,10 @@ if (!function_exists('dbr_extract_func')) {
13
  }
14
  }
15
 
 
 
 
 
16
  if (!function_exists('dbr_extract_func_targz')) {
17
  function dbr_extract_func_targz($filename)
18
  {
@@ -81,7 +85,7 @@ if (!class_exists('dbr_database')) {
81
  //include ABSPATH . 'wp-config.php';
82
  self::getWpMysqlParams();
83
  if ( !defined('WP_CONTENT_DIR') )
84
- define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
85
 
86
  if (function_exists('mysqli_connect')) {
87
  self::$is_mysqli = true;
@@ -377,6 +381,182 @@ if ( !class_exists('dbr_helper') ) {
377
 
378
  private static $cron_is_work = 90;
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  public static function check_invalid_utf8( $string, $strip = false )
381
  {
382
  $string = (string) $string;
@@ -440,7 +620,7 @@ if ( !class_exists('dbr_helper') ) {
440
  $string = str_replace( "'", '&#039;', $string );
441
 
442
  return $string;
443
- }
444
 
445
  public static function sanitize($str, $is_newlines = false)
446
  {
@@ -462,9 +642,12 @@ if ( !class_exists('dbr_helper') ) {
462
 
463
  public static function modSecureInstalled()
464
  {
465
- ob_start();
466
- phpinfo(INFO_MODULES);
467
- $contents = ob_get_clean();
 
 
 
468
  return strpos($contents, 'mod_security') !== false;
469
  }
470
 
@@ -538,10 +721,26 @@ if ( !class_exists('dbr_helper') ) {
538
  @unlink(DBP_PATH_TMP . '/' . $file);
539
  }
540
  }
 
541
  // @rmdir(DBP_PATH_TMP);
542
  }
543
  }
544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  public static function unpack_setting($str)
546
  {
547
  return unserialize( base64_decode( $str ) );
@@ -721,7 +920,7 @@ if ( !class_exists('dbr_methods') ) {
721
  $this->main = dbr_helper::unpack_setting( $setting['option_value'] );
722
  }
723
 
724
- $backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
725
  if (isset($this->main['backup_folder']) && !empty($this->main['backup_folder'])) {
726
  $backup_dir = $this->main['backup_folder'];
727
  }
@@ -783,7 +982,7 @@ if ( !class_exists('dbr_methods') ) {
783
  $arr_sql = dbr_helper::getCommand('sql-restore');
784
  if ( !isset( $arr_sql[md5($sql)] ) || $arr_sql === false ) {
785
  $ress = dbr_database::query( $sql );
786
- dbr_helper::is_work(time(), 'start');
787
  if (stripos($sql, 'create') !== false) {
788
  preg_match("/CREATE[\s]{1,}TABLE[\s]{1,}`(.*)`/iUu", $sql, $table_insert) ;
789
  if (isset($table_insert[1]) && !empty($table_insert[1])) {
@@ -857,13 +1056,66 @@ if ( !class_exists('dbr_methods') ) {
857
 
858
  }
859
 
860
- private function restoreTarGz($archive)
861
  {
862
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
863
  }
864
 
865
  private function restoreFiles()
866
  {
 
867
  $files = dbr_helper::getCommand('files-list-retore');
868
  if ($files) {
869
  dbr_helper::is_work(time(), 'start');
@@ -914,6 +1166,19 @@ if ( !class_exists('dbr_methods') ) {
914
  dbr_log::log('Data will be decompressed of ' . basename($file));
915
  if (strpos($f, '.zip')) {
916
  if (file_exists($file) && filesize($file) > 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
917
  $archive = new PclZip($file);
918
  $unzip = $archive->extract(
919
  PCLZIP_CB_PRE_EXTRACT, 'dbr_extract_func',
@@ -936,52 +1201,7 @@ if ( !class_exists('dbr_methods') ) {
936
  if ($unzip == 0) {
937
  dbr_helper::setError("Error during extracting of database config from archive: " . $archive->errorInfo(true) );
938
  }
939
- $db_params = array(
940
- 'password' => 'DB_PASSWORD',
941
- 'db' => 'DB_NAME',
942
- 'user' => 'DB_USER',
943
- 'host' => 'DB_HOST',
944
- 'charset' => 'DB_CHARSET',
945
- );
946
-
947
- $r = "/define\([\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
948
- $config = @file_get_contents(ABSPATH . "wp-config.php");
949
- preg_match_all($r, $config, $m);
950
- $params = array_combine( $m[1], $m[2] );
951
- $change_config = false;
952
- foreach($db_params as $k => $p) {
953
- $db_params[$k] = $params[$p];
954
- if (dbr_database::$db_params[$k] != $db_params[$k]) {
955
- $change_config = true;
956
- }
957
- }
958
- if ($change_config) {
959
- dbr_log::log('Configure file "wp-config.php" was started');
960
- $patterns = array();
961
- $patterns[0] = "/define[\s]{0,}\([\s]{0,}'DB_PASSWORD'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
962
- $patterns[1] = "/define[\s]{0,}\([\s]{0,}'DB_NAME'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
963
- $patterns[2] = "/define[\s]{0,}\([\s]{0,}'DB_USER'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
964
- $patterns[3] = "/define[\s]{0,}\([\s]{0,}'DB_HOST'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
965
- $patterns[4] = "/define[\s]{0,}\([\s]{0,}'DB_CHARSET'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
966
-
967
- $replacements = array();
968
- $replacements[0] = "define('DB_PASSWORD', '" . dbr_database::$db_params['password'] . "')";
969
- $replacements[1] = "define('DB_NAME', '" . dbr_database::$db_params['db'] . "')";
970
- $replacements[2] = "define('DB_USER', '" . dbr_database::$db_params['user'] . "')";
971
- $replacements[3] = "define('DB_HOST', '" . dbr_database::$db_params['host'] . "')";
972
- $replacements[4] = "define('DB_CHARSET', '" . dbr_database::$db_params['charset'] . "')";
973
-
974
- $config = preg_replace($patterns, $replacements, $config);
975
-
976
- $config = preg_replace("/table_prefix[\s]{0,}=[\s]{0,}[\"']{1}(.*)[\"']{1}/U", "table_prefix = '" . dbr_database::$db_prefix . "'", $config);
977
-
978
- $write = @file_put_contents(ABSPATH . "wp-config.php", $config);
979
-
980
- if (!$write) {
981
- dbr_helper::setError( "File 'wp-config.php' is not writable" );
982
- }
983
- dbr_log::log('Configure file "wp-config.php" was successfully');
984
- }
985
  }
986
  if ($zip_database && strpos($file, $zip_database[2]) !== false) {
987
  $archive = new PclZip($file);
@@ -1001,6 +1221,19 @@ if ( !class_exists('dbr_methods') ) {
1001
  }
1002
  } elseif ($tar_gz) {
1003
  if (file_exists($file) && filesize($file) > 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
1004
  include_once 'archive.php' ;
1005
  dbr_helper::is_work(time(), 'start');
1006
  $gz = new wpadm_gzip_file($file);
@@ -1029,52 +1262,8 @@ if ( !class_exists('dbr_methods') ) {
1029
  dbr_helper::is_work(time(), 'start');
1030
  $gz->extract_gz_files();
1031
  dbr_helper::is_work(time(), 'start');
1032
- $db_params = array(
1033
- 'password' => 'DB_PASSWORD',
1034
- 'db' => 'DB_NAME',
1035
- 'user' => 'DB_USER',
1036
- 'host' => 'DB_HOST',
1037
- 'charset' => 'DB_CHARSET',
1038
- );
1039
-
1040
- $r = "/define\([\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1041
- $config = @file_get_contents(ABSPATH . "wp-config.php");
1042
- preg_match_all($r, $config, $m);
1043
- $params = array_combine( $m[1], $m[2] );
1044
- $change_config = false;
1045
- foreach($db_params as $k => $p) {
1046
- $db_params[$k] = $params[$p];
1047
- if (dbr_database::$db_params[$k] != $db_params[$k]) {
1048
- $change_config = true;
1049
- }
1050
- }
1051
- if ($change_config) {
1052
- dbr_log::log('Configure file "wp-config.php" was started');
1053
- $patterns = array();
1054
- $patterns[0] = "/define[\s]{0,}\([\s]{0,}['\"]{1}DB_PASSWORD['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1055
- $patterns[1] = "/define[\s]{0,}\([\s]{0,}['\"]{1}DB_NAME['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1056
- $patterns[2] = "/define[\s]{0,}\([\s]{0,}['\"]{1}DB_USER['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1057
- $patterns[3] = "/define[\s]{0,}\([\s]{0,}['\"]{1}DB_HOST['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1058
- $patterns[4] = "/define[\s]{0,}\([\s]{0,}['\"]{1}DB_CHARSET['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1059
-
1060
- $replacements = array();
1061
- $replacements[0] = "define('DB_PASSWORD', '" . dbr_database::$db_params['password'] . "')";
1062
- $replacements[1] = "define('DB_NAME', '" . dbr_database::$db_params['db'] . "')";
1063
- $replacements[2] = "define('DB_USER', '" . dbr_database::$db_params['user'] . "')";
1064
- $replacements[3] = "define('DB_HOST', '" . dbr_database::$db_params['host'] . "')";
1065
- $replacements[4] = "define('DB_CHARSET', '" . dbr_database::$db_params['charset'] . "')";
1066
- dbr_helper::is_work(time(), 'start');
1067
- $config = preg_replace($patterns, $replacements, $config);
1068
 
1069
- $config = preg_replace("/table_prefix[\s]{0,}=[\s]{0,}[\"']{1}(.*)[\"']{1}/U", "table_prefix = '" . dbr_database::$db_prefix . "'", $config);
1070
-
1071
- $write = @file_put_contents(ABSPATH . "wp-config.php", $config);
1072
- dbr_helper::is_work(time(), 'start');
1073
- if (!$write) {
1074
- dbr_helper::setError( "File 'wp-config.php' is not writable" );
1075
- }
1076
- dbr_log::log('Configure file "wp-config.php" was successfully');
1077
- }
1078
  }
1079
  }
1080
  }
@@ -1162,6 +1351,18 @@ if (!class_exists('dbr_route')) {
1162
  if (!defined('ABSPATH')) {
1163
  define('ABSPATH', dirname(__FILE__) . '/../../../../');
1164
  }
 
 
 
 
 
 
 
 
 
 
 
 
1165
  if (!defined('DBP_PATH')) {
1166
  define('DBP_PATH', dirname(__FILE__) . '/../');
1167
  }
@@ -1192,6 +1393,7 @@ if (!class_exists('dbr_route')) {
1192
  } elseif( isset($_POST['name'] ) ) {
1193
  try {
1194
  dbr_helper::clearTMP();
 
1195
  dbr_database::inc_wp_config();
1196
  $setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
1197
  if (isset($setting['option_value'])) {
@@ -1242,7 +1444,7 @@ if (!class_exists('dbr_route')) {
1242
  $backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
1243
  if (isset($this->setting['backup_folder']) && !empty($this->setting['backup_folder'])) {
1244
  $backup_dir = $this->setting['backup_folder'];
1245
- }
1246
  dbr_helper::setCommand('backup-folder', $backup_dir );
1247
  echo json_encode(array('result' => 'work'));
1248
  } catch(Exception $e) {
@@ -1257,7 +1459,7 @@ if (!class_exists('dbr_route')) {
1257
  private function parsMethod()
1258
  {
1259
  if ( isset($_POST['method']) ) {
1260
- $this->setting_restore = dbr_helper::getCommand('restore-backup');
1261
  try {
1262
  dbr_helper::mkdir(DBP_PATH_TMP);
1263
  if (!dbr_helper::is_work() || in_array($_POST['method'], $this->method_access ) ) {
13
  }
14
  }
15
 
16
+ if (!defined('PCLZIP_SEPARATOR')) {
17
+ define('PCLZIP_SEPARATOR', '<|>');
18
+ }
19
+
20
  if (!function_exists('dbr_extract_func_targz')) {
21
  function dbr_extract_func_targz($filename)
22
  {
85
  //include ABSPATH . 'wp-config.php';
86
  self::getWpMysqlParams();
87
  if ( !defined('WP_CONTENT_DIR') )
88
+ define( 'WP_CONTENT_DIR', ABSPATH_REAL . 'wp-content' );
89
 
90
  if (function_exists('mysqli_connect')) {
91
  self::$is_mysqli = true;
381
 
382
  private static $cron_is_work = 90;
383
 
384
+ public static function testOtherArchive()
385
+ {
386
+ dbr_log::log('Testing of TarGz under shell');
387
+ $res_tar = self::TarGz( DBP_PATH_TMP . '/test.tar.gz', array(DBP_PATH_TMP .'/index.php', DBP_PATH_TMP .'/.htaccess'), ABSPATH );
388
+ if ($res_tar) {
389
+ dbr_log::log('Testing of TarGz under shell was finished successfully');
390
+ dbr_helper::setCommand('test_targz_c', true);
391
+ }
392
+ dbr_log::log('Testing of unTarGz under shell');
393
+ $res_tar = self::unTarGz( DBP_PATH_TMP . '/test.tar.gz', DBP_PATH_TMP . '/test/' );
394
+ if ($res_tar) {
395
+ dbr_log::log('Testing of unTarGz under shell was finished successfully');
396
+ dbr_helper::setCommand('test_targz_c', true);
397
+ }
398
+
399
+ dbr_log::log('Testing of Zip under shell');
400
+ $res_zip = self::Zip( DBP_PATH_TMP . '/test.zip', array(DBP_PATH_TMP .'/index.php', DBP_PATH_TMP .'/.htaccess'), ABSPATH );
401
+ if ($res_tar) {
402
+ dbr_log::log('Testing of ZIP under shell was finished successfully');
403
+ dbr_helper::setCommand('test_zip_c', true);
404
+ }
405
+ }
406
+
407
+ public static function getCommandToArchive($file_name, $type = 'zip_archive', $files = array(), $type_action = 'create', $remove_path = '' )
408
+ {
409
+ $return = '';
410
+ $remove_dir = '';
411
+ switch($type) {
412
+ case 'zip_archive':
413
+ if ($type_action == 'create') {
414
+ if (!empty( $remove_path ) ) {
415
+ $remove_dir = 'cd ' . $remove_path. ' &&';
416
+ $files_str = '"' . implode('" "', $files) . '"';
417
+ $files_str = str_replace($remove_path, './', $files_str);
418
+ $zip = str_replace($remove_path, './', $file_name);
419
+ } else {
420
+ $files_str = '"' . implode('" "', $files) . '"';
421
+ $zip = $file_name;
422
+ }
423
+ $return .= trim( "$remove_dir zip {$zip} " . $files_str );
424
+ } else {
425
+ $zip = $file_name;
426
+ if (!empty( $remove_path ) ) { // for extract this param of directory to
427
+ $remove_dir = 'cd ' . $remove_path . ' &&';
428
+ }
429
+ $exclude = '';
430
+ if ( !empty( $files ) ) { // exclude file
431
+ $exclude = ' -x ' . '"' . implode('" "', $files) . '"';
432
+ }
433
+ $return .= trim( "$remove_dir unzip -o {$zip} $exclude" );
434
+ }
435
+
436
+ break;
437
+ case 'tar_archive':
438
+ if ( strpos($file_name, '.zip') !== false ) {
439
+ $file_name = str_replace('.zip', '.tar.gz', $file_name);
440
+ }
441
+
442
+ if (!empty( $remove_path ) ) {
443
+ $remove_dir = '-C "' . $remove_path . '" ';
444
+ }
445
+ if ($type_action == 'create') {
446
+ $files_str = '"' . implode('" "', $files) . '"';
447
+ $files_str = str_replace($remove_path, './', $files_str);
448
+ $u = 'c';
449
+ if (file_exists($file_name)) {
450
+ $u = 'r';
451
+ }
452
+ $return = trim( "tar -{$u}zvf {$file_name} " . $remove_dir . $files_str );
453
+ } else {
454
+
455
+ $return = trim( "tar zxvf \"{$file_name}\" " . $remove_dir );
456
+ }
457
+ break;
458
+ }
459
+ return $return;
460
+
461
+ }
462
+
463
+ public static function parseResultZip($command_return)
464
+ {
465
+ $add = 0;
466
+ $error = 0;
467
+ if (!empty( $command_return) ) {
468
+ $n = count($command_return);
469
+ for($i = 0; $i < $n; $i++) {
470
+ if (strpos($command_return[$i], 'add') !== false || strpos($command_return[$i], 'updating') !== false || strpos($command_return[$i], 'inflating') !== false) {
471
+ $add ++;
472
+ } elseif (strpos($command_return[$i], 'error') !== false || strpos($command_return[$i], 'warning') !== false ) {
473
+ $error++;
474
+ $this->error .= " " . $command_return[$i];
475
+ }
476
+ }
477
+ }
478
+ return array( 'add' => $add, 'error' => $error );
479
+
480
+ }
481
+
482
+ public static function TarGz($file_name, $files, $delete_foler = '')
483
+ {
484
+ $command = self::getCommandToArchive($file_name, 'tar_archive', $files, 'create', $delete_foler);
485
+ if (!empty($command)) {
486
+
487
+ $result_command = @exec($command, $command_return);
488
+
489
+ if (count($files) == count($command_return)) {
490
+ return true;
491
+ }
492
+
493
+ if (count($command_return) > 0) {
494
+ return true;
495
+ }
496
+ if (file_exists($file_name)) {
497
+ return true;
498
+ }
499
+ return "Files not adding to arhive";
500
+ }
501
+
502
+ return false;
503
+ }
504
+
505
+ public static function unTarGz($file_name, $dir_to)
506
+ {
507
+ $command = self::getCommandToArchive($file_name, 'tar_archive', array(), 'etract', $dir_to);
508
+
509
+ if (!empty($command)) {
510
+
511
+ $result_command = @exec($command, $command_return);
512
+
513
+ if (count($command_return) > 0) {
514
+ return true;
515
+ }
516
+ if (file_exists($file_name)) {
517
+ return true;
518
+ }
519
+ return "Files not adding to arhive";
520
+ }
521
+
522
+ return false;
523
+ }
524
+
525
+ public static function Zip($file_name, $files, $delete_foler = '')
526
+ {
527
+ $command = self::getCommandToArchive($file_name, 'zip_archive', $files, 'create', $delete_foler);
528
+ if (!empty($command)) {
529
+ $result_command = @exec($command, $command_return);
530
+
531
+ $res = self::parseResultZip($command_return);
532
+
533
+ if ($res['add'] == count($files)) {
534
+ return true;
535
+ }
536
+ if ( file_exists( $file_name ) && $res['error'] === 0 ) {
537
+ return true;
538
+ }
539
+ }
540
+
541
+ return false;
542
+ }
543
+
544
+ public static function unZip($file_name, $dir_to, $exclude = array() )
545
+ {
546
+ $command = self::getCommandToArchive($file_name, 'zip_archive', $exclude, 'extract', $dir_to);
547
+ if (!empty($command)) {
548
+ $result_command = @exec($command, $command_return);
549
+
550
+ $res = self::parseResultZip($command_return);
551
+
552
+ if ( $res['error'] === 0 ) {
553
+ return true;
554
+ }
555
+ }
556
+
557
+ return false;
558
+ }
559
+
560
  public static function check_invalid_utf8( $string, $strip = false )
561
  {
562
  $string = (string) $string;
620
  $string = str_replace( "'", '&#039;', $string );
621
 
622
  return $string;
623
+ }
624
 
625
  public static function sanitize($str, $is_newlines = false)
626
  {
642
 
643
  public static function modSecureInstalled()
644
  {
645
+ $contents = '';
646
+ if (defined('INFO_MODULES') && function_exists('phpinfo')) {
647
+ ob_start();
648
+ @phpinfo(INFO_MODULES);
649
+ $contents = ob_get_clean();
650
+ }
651
  return strpos($contents, 'mod_security') !== false;
652
  }
653
 
721
  @unlink(DBP_PATH_TMP . '/' . $file);
722
  }
723
  }
724
+ self::createDefaultFiles(DBP_PATH_TMP);
725
  // @rmdir(DBP_PATH_TMP);
726
  }
727
  }
728
 
729
+ public static function createDefaultFiles($dir)
730
+ {
731
+ if (!file_exists($dir . '/index.php')) {
732
+ @file_put_contents($dir . '/index.php', '<?php echo "Hello World!"; ');
733
+ if ( !is_writable($dir . '/index.php') ) {
734
+ return str_replace("&s", $dir . '/index.php' , 'Backup creating<br /><br />Please check the permissions on file "&s". Failed to create file.' );
735
+ }
736
+ }
737
+ if (!file_exists($dir . '/.htaccess')) {
738
+ @file_put_contents($dir . '/.htaccess', 'DENY FROM ALL');
739
+ }
740
+ return true;
741
+ }
742
+
743
+
744
  public static function unpack_setting($str)
745
  {
746
  return unserialize( base64_decode( $str ) );
920
  $this->main = dbr_helper::unpack_setting( $setting['option_value'] );
921
  }
922
 
923
+ $backup_dir = WP_CONTENT_DIR . '/' . DROPBOX_BACKUP_DIR_NAME;
924
  if (isset($this->main['backup_folder']) && !empty($this->main['backup_folder'])) {
925
  $backup_dir = $this->main['backup_folder'];
926
  }
982
  $arr_sql = dbr_helper::getCommand('sql-restore');
983
  if ( !isset( $arr_sql[md5($sql)] ) || $arr_sql === false ) {
984
  $ress = dbr_database::query( $sql );
985
+ dbr_helper::is_work(time(), 'start');
986
  if (stripos($sql, 'create') !== false) {
987
  preg_match("/CREATE[\s]{1,}TABLE[\s]{1,}`(.*)`/iUu", $sql, $table_insert) ;
988
  if (isset($table_insert[1]) && !empty($table_insert[1])) {
1056
 
1057
  }
1058
 
1059
+ private function reconfig()
1060
  {
1061
 
1062
+ dbr_helper::is_work(time(), 'start');
1063
+ if ( dbr_helper::is_writable(ABSPATH . 'wp-config.php') === false) {
1064
+ dbr_helper::setError( "File 'wp-config.php' is not writable" );
1065
+ }
1066
+ $db_params = array(
1067
+ 'password' => 'DB_PASSWORD',
1068
+ 'db' => 'DB_NAME',
1069
+ 'user' => 'DB_USER',
1070
+ 'host' => 'DB_HOST',
1071
+ 'charset' => 'DB_CHARSET',
1072
+ );
1073
+
1074
+ $r = "/define\([\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
1075
+ $config = @file_get_contents(ABSPATH . "wp-config.php");
1076
+ preg_match_all($r, $config, $m);
1077
+ $params = array_combine( $m[1], $m[2] );
1078
+ $change_config = false;
1079
+ foreach($db_params as $k => $p) {
1080
+ $db_params[$k] = $params[$p];
1081
+ if (dbr_database::$db_params[$k] != $db_params[$k]) {
1082
+ $change_config = true;
1083
+ }
1084
+ }
1085
+ dbr_helper::is_work(time(), 'start');
1086
+ if ($change_config) {
1087
+ dbr_log::log('Configure file "wp-config.php" was started');
1088
+ $patterns = array();
1089
+ $patterns[0] = "/define[\s]{0,}\([\s]{0,}'DB_PASSWORD'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
1090
+ $patterns[1] = "/define[\s]{0,}\([\s]{0,}'DB_NAME'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
1091
+ $patterns[2] = "/define[\s]{0,}\([\s]{0,}'DB_USER'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
1092
+ $patterns[3] = "/define[\s]{0,}\([\s]{0,}'DB_HOST'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
1093
+ $patterns[4] = "/define[\s]{0,}\([\s]{0,}'DB_CHARSET'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
1094
+
1095
+ $replacements = array();
1096
+ $replacements[0] = "define('DB_PASSWORD', '" . dbr_database::$db_params['password'] . "')";
1097
+ $replacements[1] = "define('DB_NAME', '" . dbr_database::$db_params['db'] . "')";
1098
+ $replacements[2] = "define('DB_USER', '" . dbr_database::$db_params['user'] . "')";
1099
+ $replacements[3] = "define('DB_HOST', '" . dbr_database::$db_params['host'] . "')";
1100
+ $replacements[4] = "define('DB_CHARSET', '" . dbr_database::$db_params['charset'] . "')";
1101
+
1102
+ $config = preg_replace($patterns, $replacements, $config);
1103
+
1104
+ $config = preg_replace("/table_prefix[\s]{0,}=[\s]{0,}[\"']{1}(.*)[\"']{1}/U", "table_prefix = '" . dbr_database::$db_prefix . "'", $config);
1105
+
1106
+ $write = @file_put_contents(ABSPATH . "wp-config.php", $config);
1107
+
1108
+ dbr_helper::is_work(time(), 'start');
1109
+ if (!$write) {
1110
+ dbr_helper::setError( "File 'wp-config.php' is not writable" );
1111
+ }
1112
+ dbr_log::log('Configure file "wp-config.php" was successfully');
1113
+ }
1114
  }
1115
 
1116
  private function restoreFiles()
1117
  {
1118
+
1119
  $files = dbr_helper::getCommand('files-list-retore');
1120
  if ($files) {
1121
  dbr_helper::is_work(time(), 'start');
1166
  dbr_log::log('Data will be decompressed of ' . basename($file));
1167
  if (strpos($f, '.zip')) {
1168
  if (file_exists($file) && filesize($file) > 0) {
1169
+ $test_zip = dbr_helper::getCommand('test_zip_c');
1170
+ if ($test_zip) {
1171
+ $unzip = dbr_helper::unZip($file, ABSPATH_REAL, array('wp-content/plugins/dropbox-backup/*', 'wp-content/plugins/dropbox-backup-pro/*') );
1172
+ if ($unzip) {
1173
+ if ($zip_config && strpos($file, $zip_config[2]) !== false) {
1174
+ $this->reconfig();
1175
+ }
1176
+ continue;
1177
+ } else {
1178
+ dbr_log::log('Data will be decompressed of ' . basename($file) . ' wasn\'t successful. Try other method "PclZip"');
1179
+ dbr_helper::setCommand('test_zip_c', false);
1180
+ }
1181
+ }
1182
  $archive = new PclZip($file);
1183
  $unzip = $archive->extract(
1184
  PCLZIP_CB_PRE_EXTRACT, 'dbr_extract_func',
1201
  if ($unzip == 0) {
1202
  dbr_helper::setError("Error during extracting of database config from archive: " . $archive->errorInfo(true) );
1203
  }
1204
+ $this->reconfig();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1205
  }
1206
  if ($zip_database && strpos($file, $zip_database[2]) !== false) {
1207
  $archive = new PclZip($file);
1221
  }
1222
  } elseif ($tar_gz) {
1223
  if (file_exists($file) && filesize($file) > 0) {
1224
+ $test_targz = dbr_helper::getCommand('test_targz_c');
1225
+ if ($test_targz) {
1226
+ $untargz = dbr_helper::unTarGz($file, rtrim( ABSPATH_REAL , '/'), array('wp-content/plugins/dropbox-backup/*', 'wp-content/plugins/dropbox-backup-pro/*') );
1227
+ if ($untargz) {
1228
+ if ($zip_config && strpos($file, $zip_config[2]) !== false) {
1229
+ $this->reconfig();
1230
+ }
1231
+ continue;
1232
+ } else {
1233
+ dbr_log::log('Data will be decompressed of ' . basename($file) . ' wasn\'t successful. Try other method "PHP tar class"');
1234
+ dbr_helper::setCommand('test_targz_c', false);
1235
+ }
1236
+ }
1237
  include_once 'archive.php' ;
1238
  dbr_helper::is_work(time(), 'start');
1239
  $gz = new wpadm_gzip_file($file);
1262
  dbr_helper::is_work(time(), 'start');
1263
  $gz->extract_gz_files();
1264
  dbr_helper::is_work(time(), 'start');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1265
 
1266
+ $this->reconfig();
 
 
 
 
 
 
 
 
1267
  }
1268
  }
1269
  }
1351
  if (!defined('ABSPATH')) {
1352
  define('ABSPATH', dirname(__FILE__) . '/../../../../');
1353
  }
1354
+ if (!defined('ABSPATH_REAL')) {
1355
+ $dir = dirname(__FILE__);
1356
+ $dir = str_replace("\\", '/', $dir);
1357
+ $dir_arr = explode("/", $dir);
1358
+ for($i = 0; $i < 4; $i++) {
1359
+ array_pop($dir_arr);
1360
+ }
1361
+ $dir = implode('/', $dir_arr) . '/';
1362
+
1363
+ define('ABSPATH_REAL', $dir );
1364
+ }
1365
+
1366
  if (!defined('DBP_PATH')) {
1367
  define('DBP_PATH', dirname(__FILE__) . '/../');
1368
  }
1393
  } elseif( isset($_POST['name'] ) ) {
1394
  try {
1395
  dbr_helper::clearTMP();
1396
+ dbr_helper::testOtherArchive();
1397
  dbr_database::inc_wp_config();
1398
  $setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
1399
  if (isset($setting['option_value'])) {
1444
  $backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
1445
  if (isset($this->setting['backup_folder']) && !empty($this->setting['backup_folder'])) {
1446
  $backup_dir = $this->setting['backup_folder'];
1447
+ }
1448
  dbr_helper::setCommand('backup-folder', $backup_dir );
1449
  echo json_encode(array('result' => 'work'));
1450
  } catch(Exception $e) {
1459
  private function parsMethod()
1460
  {
1461
  if ( isset($_POST['method']) ) {
1462
+ $this->setting_restore = dbr_helper::getCommand('restore-backup');
1463
  try {
1464
  dbr_helper::mkdir(DBP_PATH_TMP);
1465
  if (!dbr_helper::is_work() || in_array($_POST['method'], $this->method_access ) ) {
readme.txt CHANGED
@@ -1,6 +1,6 @@
1
  === Backup & Restore Dropbox ===
2
  Plugin Name: Backup & Restore Dropbox
3
- Version: 1.5
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
1
  === Backup & Restore Dropbox ===
2
  Plugin Name: Backup & Restore Dropbox
3
+ Version: 1.5.1
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool