[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/kcfinder/lib/ -> class_zipFolder.php (source)

   1  <?php
   2  
   3  /** This file is part of KCFinder project. The class are taken from
   4    * http://www.php.net/manual/en/function.ziparchive-addemptydir.php
   5    *
   6    *      @desc Directory to ZIP file archivator
   7    *   @package KCFinder
   8    *   @version 2.21
   9    *    @author Pavel Tzonkov <[email protected]>
  10    * @copyright 2010 KCFinder Project
  11    *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
  12    *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
  13    *      @link http://kcfinder.sunhater.com
  14    */
  15  
  16  class zipFolder {
  17      protected $zip;
  18      protected $root;
  19      protected $ignored;
  20  
  21      function __construct($file, $folder, $ignored=null) {
  22          $this->zip = new ZipArchive();
  23  
  24          $this->ignored = is_array($ignored)
  25              ? $ignored
  26              : ($ignored ? array($ignored) : array());
  27  
  28          if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE)
  29              throw new Exception("cannot open <$file>\n");
  30  
  31          $folder = rtrim($folder, '/');
  32  
  33          if (strstr($folder, '/')) {
  34              $this->root = substr($folder, 0, strrpos($folder, '/') + 1);
  35              $folder = substr($folder, strrpos($folder, '/') + 1);
  36          }
  37  
  38          $this->zip($folder);
  39          $this->zip->close();
  40      }
  41  
  42      function zip($folder, $parent=null) {
  43          $full_path = "{$this->root}$parent$folder";
  44          $zip_path = "$parent$folder";
  45          $this->zip->addEmptyDir($zip_path);
  46          $dir = new DirectoryIterator($full_path);
  47          foreach ($dir as $file)
  48              if (!$file->isDot()) {
  49                  $filename = $file->getFilename();
  50                  if (!in_array($filename, $this->ignored)) {
  51                      if ($file->isDir())
  52                          $this->zip($filename, "$zip_path/");
  53                      else
  54                          $this->zip->addFile("$full_path/$filename", "$zip_path/$filename");
  55                  }
  56              }
  57      }
  58  }
  59  
  60  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1