[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/_ext/ -> _zip_archives.php (source)

   1  <?php
   2  /**

   3   * TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1

   4   * By Devin Doucette

   5   * Copyright (c) 2005 Devin Doucette

   6   * Email bugs/suggestions to darksnoopy@shaw.ca

   7   * @link http://www.phpclasses.org/browse/package/945.html

   8   *

   9   * This script has been created and released under

  10   * the GNU GPL and is free to use and redistribute

  11   * only if this copyright statement is not removed

  12   *

  13   * b2evolution - {@link http://b2evolution.net/}

  14   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

  15   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

  16   *

  17   * @author Devin Doucette - darksnoopy@shaw.ca

  18   *

  19   * @package evocore

  20   */
  21  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  22  
  23  /**

  24   * Class Archive

  25   *

  26   * @author Devin Doucette

  27   * @package evocore

  28   */
  29  class archive
  30  {
  31  	function archive($name)
  32      {
  33          $this->options = array (
  34              'basedir' => ".",
  35              'name' => $name,
  36              'prepend' => "",
  37              'inmemory' => 0,
  38              'overwrite' => 0,
  39              'recurse' => 1,
  40              'storepaths' => 1,
  41              'followlinks' => 0,
  42              'level' => 3,
  43              'method' => 1,
  44              'sfx' => "",
  45              'type' => "",
  46              'comment' => ""
  47          );
  48          $this->files = array ();
  49          $this->exclude = array ();
  50          $this->storeonly = array ();
  51          $this->error = array ();
  52      }
  53  
  54  	function set_options($options)
  55      {
  56          foreach ($options as $key => $value)
  57              $this->options[$key] = $value;
  58          if (!empty ($this->options['basedir']))
  59          {
  60              $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
  61              $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
  62              $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
  63          }
  64          if (!empty ($this->options['name']))
  65          {
  66              $this->options['name'] = str_replace("\\", "/", $this->options['name']);
  67              $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
  68          }
  69          if (!empty ($this->options['prepend']))
  70          {
  71              $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
  72              $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
  73              $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
  74              $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
  75          }
  76      }
  77  
  78  	function create_archive()
  79      {
  80          $this->make_list();
  81  
  82          if ($this->options['inmemory'] == 0)
  83          {
  84              $pwd = getcwd();
  85              chdir($this->options['basedir']);
  86              if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
  87              {
  88                  $this->error[] = "File {$this->options['name']} already exists.";
  89                  chdir($pwd);
  90                  return 0;
  91              }
  92              else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
  93                  chdir($pwd);
  94              else
  95              {
  96                  $this->error[] = "Could not open {$this->options['name']} for writing.";
  97                  chdir($pwd);
  98                  return 0;
  99              }
 100          }
 101          else
 102              $this->archive = "";
 103  
 104          switch ($this->options['type'])
 105          {
 106          case "zip":
 107              if (!$this->create_zip())
 108              {
 109                  $this->error[] = "Could not create zip file.";
 110                  return 0;
 111              }
 112              break;
 113          case "bzip":
 114              if (!$this->create_tar())
 115              {
 116                  $this->error[] = "Could not create tar file.";
 117                  return 0;
 118              }
 119              if (!$this->create_bzip())
 120              {
 121                  $this->error[] = "Could not create bzip2 file.";
 122                  return 0;
 123              }
 124              break;
 125          case "gzip":
 126              if (!$this->create_tar())
 127              {
 128                  $this->error[] = "Could not create tar file.";
 129                  return 0;
 130              }
 131              if (!$this->create_gzip())
 132              {
 133                  $this->error[] = "Could not create gzip file.";
 134                  return 0;
 135              }
 136              break;
 137          case "tar":
 138              if (!$this->create_tar())
 139              {
 140                  $this->error[] = "Could not create tar file.";
 141                  return 0;
 142              }
 143          }
 144  
 145          if ($this->options['inmemory'] == 0)
 146          {
 147              fclose($this->archive);
 148              if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
 149                  unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
 150          }
 151      }
 152  
 153  	function add_data($data)
 154      {
 155          if ($this->options['inmemory'] == 0)
 156              fwrite($this->archive, $data);
 157          else
 158              $this->archive .= $data;
 159      }
 160  
 161  	function make_list()
 162      {
 163          if (!empty ($this->exclude))
 164              foreach ($this->files as $key => $value)
 165                  foreach ($this->exclude as $current)
 166                      if ($value['name'] == $current['name'])
 167                          unset ($this->files[$key]);
 168          if (!empty ($this->storeonly))
 169              foreach ($this->files as $key => $value)
 170                  foreach ($this->storeonly as $current)
 171                      if ($value['name'] == $current['name'])
 172                          $this->files[$key]['method'] = 0;
 173          unset ($this->exclude, $this->storeonly);
 174      }
 175  
 176  	function add_files($list)
 177      {
 178          $temp = $this->list_files($list);
 179          foreach ($temp as $current)
 180              $this->files[] = $current;
 181      }
 182  
 183  	function exclude_files($list)
 184      {
 185          $temp = $this->list_files($list);
 186          foreach ($temp as $current)
 187              $this->exclude[] = $current;
 188      }
 189  
 190  	function store_files($list)
 191      {
 192          $temp = $this->list_files($list);
 193          foreach ($temp as $current)
 194              $this->storeonly[] = $current;
 195      }
 196  
 197  	function list_files($list)
 198      {
 199          if (!is_array ($list))
 200          {
 201              $temp = $list;
 202              $list = array ($temp);
 203              unset ($temp);
 204          }
 205  
 206          $files = array ();
 207  
 208          $pwd = getcwd();
 209          chdir($this->options['basedir']);
 210  
 211          foreach ($list as $current)
 212          {
 213              $current = str_replace("\\", "/", $current);
 214              $current = preg_replace("/\/+/", "/", $current);
 215              $current = preg_replace("/\/$/", "", $current);
 216              if (strstr($current, "*"))
 217              {
 218                  $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
 219                  $regex = str_replace("*", ".*", $regex);
 220                  $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
 221                  $temp = $this->parse_dir($dir);
 222                  foreach ($temp as $current2)
 223                      if (preg_match("/^{$regex}$/i", $current2['name']))
 224                          $files[] = $current2;
 225                  unset ($regex, $dir, $temp, $current);
 226              }
 227              else if (@is_dir($current))
 228              {
 229                  $temp = $this->parse_dir($current);
 230                  foreach ($temp as $file)
 231                      $files[] = $file;
 232                  unset ($temp, $file);
 233              }
 234              else if (@file_exists($current))
 235                  $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
 236                      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
 237                      substr($current, strrpos($current, "/") + 1) : $current),
 238                      'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
 239                      'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
 240          }
 241  
 242          chdir($pwd);
 243  
 244          unset ($current, $pwd);
 245  
 246          usort($files, array ("archive", "sort_files"));
 247  
 248          return $files;
 249      }
 250  
 251  	function parse_dir($dirname)
 252      {
 253          if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))

 254              $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .

 255                  preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?

 256                  substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));

 257          else

 258              $files = array ();

 259          $dir = @opendir($dirname);

 260  

 261          while ($file = @readdir($dir))

 262          {

 263              $fullname = $dirname . "/" . $file;

 264              if ($file == "." || $file == "..")

 265                  continue;

 266              else if (@is_dir($fullname))

 267              {

 268                  if (empty ($this->options['recurse']))

 269                      continue;

 270                  $temp = $this->parse_dir($fullname);

 271                  foreach ($temp as $file2)

 272                      $files[] = $file2;

 273              }

 274              else if (@file_exists($fullname))

 275                  $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .

 276                      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?

 277                      substr($fullname, strrpos($fullname, "/") + 1) : $fullname),

 278                      'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,

 279                      'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));

 280          }

 281  

 282          @closedir($dir);

 283  

 284          return $files;

 285      }

 286  

 287      function sort_files($a, $b)

 288      {

 289          if ($a['type'] != $b['type'])

 290              if ($a['type'] == 5 || $b['type'] == 2)

 291                  return -1;

 292              else if ($a['type'] == 2 || $b['type'] == 5)

 293                  return 1;

 294          else if ($a['type'] == 5)

 295              return strcmp(strtolower($a['name']), strtolower($b['name']));

 296          else if ($a['ext'] != $b['ext'])

 297              return strcmp($a['ext'], $b['ext']);

 298          else if ($a['stat'][7] != $b['stat'][7])

 299              return $a['stat'][7] > $b['stat'][7] ? -1 : 1;

 300          else

 301              return strcmp(strtolower($a['name']), strtolower($b['name']));

 302          return 0;

 303      }

 304  

 305      function download_file()

 306      {

 307          if ($this->options['inmemory'] == 0)

 308          {

 309              $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";

 310              return;

 311          }

 312          switch ($this->options['type'])

 313          {

 314          case "zip":

 315              header("Content-Type: application/zip");

 316              break;

 317          case "bzip":

 318              header("Content-Type: application/x-bzip2");

 319              break;

 320          case "gzip":

 321              header("Content-Type: application/x-gzip");

 322              break;

 323          case "tar":

 324              header("Content-Type: application/x-tar");

 325          }

 326          $header = "Content-Disposition: attachment; filename=\"";

 327          $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];

 328          $header .= "\"";

 329          header($header);

 330          header("Content-Length: " . strlen($this->archive));

 331          header("Content-Transfer-Encoding: binary");

 332          header("Cache-Control: no-cache, must-revalidate, max-age=60");

 333          header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");

 334          print($this->archive);

 335      }

 336  }

 337  

 338  /**

 339   * Class Tar file

 340   *

 341   * @author Devin Doucette

 342   * @package evocore

 343   */
 344  class tar_file extends archive
 345  {
 346  	function tar_file($name)
 347      {
 348          $this->archive($name);
 349          $this->options['type'] = "tar";
 350      }
 351  
 352  	function create_tar()
 353      {
 354          $pwd = getcwd();
 355          chdir($this->options['basedir']);
 356  
 357          foreach ($this->files as $current)
 358          {
 359              if ($current['name'] == $this->options['name'])
 360                  continue;
 361              if (strlen($current['name2']) > 99)
 362              {
 363                  $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
 364                  $current['name2'] = substr($current['name2'], strlen($path));
 365                  if (strlen($path) > 154 || strlen($current['name2']) > 99)
 366                  {
 367                      $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
 368                      continue;
 369                  }
 370              }
 371              $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
 372                  $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
 373                  sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
 374                  "        ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
 375                  "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
 376  
 377              $checksum = 0;
 378              for ($i = 0; $i < 512; $i++)
 379                  $checksum += ord(substr($block, $i, 1));
 380              $checksum = pack("a8", sprintf("%07o", $checksum));
 381              $block = substr_replace($block, $checksum, 148, 8);
 382  
 383              if ($current['type'] == 2 || $current['stat'][7] == 0)
 384                  $this->add_data($block);
 385              else if ($fp = @fopen($current['name'], "rb"))
 386              {
 387                  $this->add_data($block);
 388                  while ($temp = fread($fp, 1048576))
 389                      $this->add_data($temp);
 390                  if ($current['stat'][7] % 512 > 0)
 391                  {
 392                      $temp = "";
 393                      for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
 394                          $temp .= "\0";
 395                      $this->add_data($temp);
 396                  }
 397                  fclose($fp);
 398              }
 399              else
 400                  $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
 401          }
 402  
 403          $this->add_data(pack("a1024", ""));
 404  
 405          chdir($pwd);
 406  
 407          return 1;
 408      }
 409  
 410  	function extract_files()
 411      {
 412          $pwd = getcwd();
 413          chdir($this->options['basedir']);
 414  
 415          if ($fp = $this->open_archive())
 416          {
 417              if ($this->options['inmemory'] == 1)
 418                  $this->files = array ();
 419  
 420              while ($block = fread($fp, 512))
 421              {
 422                  $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
 423                  $file = array (
 424                      'name' => $temp['prefix'] . $temp['name'],
 425                      'stat' => array (
 426                          2 => $temp['mode'],
 427                          4 => octdec($temp['uid']),
 428                          5 => octdec($temp['gid']),
 429                          7 => octdec($temp['size']),
 430                          9 => octdec($temp['mtime']),
 431                      ),
 432                      'checksum' => octdec($temp['checksum']),
 433                      'type' => $temp['type'],
 434                      'magic' => $temp['magic'],
 435                  );
 436                  if ($file['checksum'] == 0x00000000)
 437                      break;
 438                  else if (substr($file['magic'], 0, 5) != "ustar")
 439                  {
 440                      $this->error[] = "This script does not support extracting this type of tar file.";
 441                      break;
 442                  }
 443                  $block = substr_replace($block, "        ", 148, 8);
 444                  $checksum = 0;
 445                  for ($i = 0; $i < 512; $i++)
 446                      $checksum += ord(substr($block, $i, 1));
 447                  if ($file['checksum'] != $checksum)
 448                      $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
 449  
 450                  if ($this->options['inmemory'] == 1)
 451                  {
 452                      $file['data'] = fread($fp, $file['stat'][7]);
 453                      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
 454                      unset ($file['checksum'], $file['magic']);
 455                      $this->files[] = $file;
 456                  }
 457                  else if ($file['type'] == 5)
 458                  {
 459                      if (!is_dir($file['name']))
 460                          mkdir($file['name'], $file['stat'][2]);
 461                  }
 462                  else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
 463                  {
 464                      $this->error[] = "{$file['name']} already exists.";
 465                      continue;
 466                  }
 467                  else if ($file['type'] == 2)
 468                  {
 469                      symlink($temp['symlink'], $file['name']);
 470                      chmod($file['name'], $file['stat'][2]);
 471                  }
 472                  else if ($new = @fopen($file['name'], "wb"))
 473                  {
 474                      fwrite($new, fread($fp, $file['stat'][7]));
 475                      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
 476                      fclose($new);
 477                      chmod($file['name'], $file['stat'][2]);
 478                  }
 479                  else
 480                  {
 481                      $this->error[] = "Could not open {$file['name']} for writing.";
 482                      continue;
 483                  }
 484                  chown($file['name'], $file['stat'][4]);
 485                  chgrp($file['name'], $file['stat'][5]);
 486                  touch($file['name'], $file['stat'][9]);
 487                  unset ($file);
 488              }
 489          }
 490          else
 491              $this->error[] = "Could not open file {$this->options['name']}";
 492  
 493          chdir($pwd);
 494      }
 495  
 496  	function open_archive()
 497      {
 498          return @fopen($this->options['name'], "rb");
 499      }
 500  }
 501  
 502  /**

 503   * Class Gzip_file

 504   *

 505   * @author Devin Doucette

 506   * @package evocore

 507   */
 508  class gzip_file extends tar_file
 509  {
 510  	function gzip_file($name)
 511      {
 512          $this->tar_file($name);
 513          $this->options['type'] = "gzip";
 514      }
 515  
 516  	function create_gzip()
 517      {
 518          if ($this->options['inmemory'] == 0)
 519          {
 520              $pwd = getcwd();
 521              chdir($this->options['basedir']);
 522              if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
 523              {
 524                  fseek($this->archive, 0);
 525                  while ($temp = fread($this->archive, 1048576))
 526                      gzwrite($fp, $temp);
 527                  gzclose($fp);
 528                  chdir($pwd);
 529              }
 530              else
 531              {
 532                  $this->error[] = "Could not open {$this->options['name']} for writing.";
 533                  chdir($pwd);
 534                  return 0;
 535              }
 536          }
 537          else
 538              $this->archive = gzencode($this->archive, $this->options['level']);
 539  
 540          return 1;
 541      }
 542  
 543  	function open_archive()
 544      {
 545          return @gzopen($this->options['name'], "rb");
 546      }
 547  }
 548  
 549  /**

 550   * Class Bzip_file

 551   *

 552   * @author Devin Doucette

 553   * @package evocore

 554   */
 555  class bzip_file extends tar_file
 556  {
 557  	function bzip_file($name)
 558      {
 559          $this->tar_file($name);
 560          $this->options['type'] = "bzip";
 561      }
 562  
 563  	function create_bzip()
 564      {
 565          if ($this->options['inmemory'] == 0)
 566          {
 567              $pwd = getcwd();
 568              chdir($this->options['basedir']);
 569              if ($fp = bzopen($this->options['name'], "wb"))
 570              {
 571                  fseek($this->archive, 0);
 572                  while ($temp = fread($this->archive, 1048576))
 573                      bzwrite($fp, $temp);
 574                  bzclose($fp);
 575                  chdir($pwd);
 576              }
 577              else
 578              {
 579                  $this->error[] = "Could not open {$this->options['name']} for writing.";
 580                  chdir($pwd);
 581                  return 0;
 582              }
 583          }
 584          else
 585              $this->archive = bzcompress($this->archive, $this->options['level']);
 586  
 587          return 1;
 588      }
 589  
 590  	function open_archive()
 591      {
 592          return @bzopen($this->options['name'], "rb");
 593      }
 594  }
 595  
 596  /**

 597   * Class Zip_file

 598   *

 599   * @author Devin Doucette

 600   * @package evocore

 601   */
 602  class zip_file extends archive
 603  {
 604  	function zip_file($name)
 605      {
 606          $this->archive($name);
 607          $this->options['type'] = "zip";
 608      }
 609  
 610  	function create_zip()
 611      {
 612          $files = 0;
 613          $offset = 0;
 614          $central = "";
 615  
 616          if (!empty ($this->options['sfx']))
 617              if ($fp = @fopen($this->options['sfx'], "rb"))
 618              {
 619                  $temp = fread($fp, filesize($this->options['sfx']));
 620                  fclose($fp);
 621                  $this->add_data($temp);
 622                  $offset += strlen($temp);
 623                  unset ($temp);
 624              }
 625              else
 626                  $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
 627  
 628          $pwd = getcwd();
 629          chdir($this->options['basedir']);
 630  
 631          foreach ($this->files as $current)
 632          {
 633              if ($current['name'] == $this->options['name'])
 634                  continue;
 635  
 636              $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
 637              $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
 638                  ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
 639  
 640              $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
 641  
 642              if ($current['stat'][7] == 0 && $current['type'] == 5)
 643              {
 644                  $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
 645                  $block .= $current['name2'] . "/";
 646                  $this->add_data($block);
 647                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 648                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 649                      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
 650                  $central .= $current['name2'] . "/";
 651                  $files++;
 652                  $offset += (31 + strlen($current['name2']));
 653              }
 654              else if ($current['stat'][7] == 0)
 655              {
 656                  $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
 657                  $block .= $current['name2'];
 658                  $this->add_data($block);
 659                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 660                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 661                      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
 662                  $central .= $current['name2'];
 663                  $files++;
 664                  $offset += (30 + strlen($current['name2']));
 665              }
 666              else if ($fp = @fopen($current['name'], "rb"))
 667              {
 668                  $temp = fread($fp, $current['stat'][7]);
 669                  fclose($fp);
 670                  $crc32 = crc32($temp);
 671                  if (!isset($current['method']) && $this->options['method'] == 1)
 672                  {
 673                      $temp = gzcompress($temp, $this->options['level']);
 674                      $size = strlen($temp) - 6;
 675                      $temp = substr($temp, 2, $size);
 676                  }
 677                  else
 678                      $size = strlen($temp);
 679                  $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
 680                  $block .= $current['name2'];
 681                  $this->add_data($block);
 682                  $this->add_data($temp);
 683                  unset ($temp);
 684                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 685                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 686                      $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
 687                  $central .= $current['name2'];
 688                  $files++;
 689                  $offset += (30 + strlen($current['name2']) + $size);
 690              }
 691              else
 692                  $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
 693          }
 694  
 695          $this->add_data($central);
 696  
 697          $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
 698              !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
 699  
 700          if (!empty ($this->options['comment']))
 701              $this->add_data($this->options['comment']);
 702  
 703          chdir($pwd);
 704  
 705          return 1;
 706      }
 707  }
 708  
 709  /*

 710   * $Log: _zip_archives.php,v $

 711   * Revision 1.1  2007/06/25 10:59:12  fplanque

 712   * MODULES (refactored MVC)

 713   *

 714   * Revision 1.3  2007/04/26 00:11:12  fplanque

 715   * (c) 2007

 716   *

 717   * Revision 1.2  2006/07/04 17:32:30  fplanque

 718   * no message

 719   *

 720   * Revision 1.1  2006/02/23 21:12:33  fplanque

 721   * File reorganization to MVC (Model View Controller) architecture.

 722   * See index.hml files in folders.

 723   * (Sorry for all the remaining bugs induced by the reorg... :/)

 724   *

 725   * Revision 1.5  2005/09/06 17:14:12  fplanque

 726   * stop processing early if referer spam has been detected

 727   *

 728   * Revision 1.4  2005/08/19 17:20:52  blueyed

 729   * Merged from upstream.

 730   *

 731   * Revision 1.3  2005/02/28 09:06:44  blueyed

 732   * removed constants for DB config (allows to override it from _config_TEST.php), introduced EVO_CONFIG_LOADED

 733   *

 734   * Revision 1.2  2004/10/16 01:31:24  blueyed

 735   * documentation changes

 736   *

 737   * Revision 1.1  2004/10/13 22:46:34  fplanque

 738   * renamed [b2]evocore/*

 739   *

 740   */
 741  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics