[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> Unzip.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  require_once ('vtlib/thirdparty/dUnzip2.inc.php');
  11  
  12  /**
  13   * Provides API to make working with zip file extractions easy
  14   * @package vtlib
  15   */
  16  class Vtiger_Unzip extends dUnzip2 {
  17  
  18      /**
  19       * Check existence of path in the given array
  20       * @access private
  21       */
  22  	function __checkPathInArray($path, $pathArray) {
  23          foreach($pathArray as $checkPath) {
  24              if(strpos($path, $checkPath) === 0)
  25                  return true;
  26          }
  27          return false;
  28      }
  29  
  30      /**
  31       * Check if the file path is directory
  32       * @param String Zip file path
  33       */
  34  	function isdir($filepath) {
  35          if(substr($filepath, -1, 1) == "/") return true;
  36          return false;
  37      }
  38  
  39      /**
  40       * Extended unzipAll function (look at base class)
  41       * Allows you to rename while unzipping and handle exclusions.
  42       * @access private
  43       */
  44      Function unzipAllEx($targetDir=false, $includeExclude=false, $renamePaths=false, $ignoreFiles=false,
  45          $baseDir="", $applyChmod=0755){
  46  
  47          // We want to always maintain the structure
  48          $maintainStructure = true;
  49  
  50          if($targetDir === false)
  51              $targetDir = dirname(__FILE__)."/";
  52  
  53          if($renamePaths === false) $renamePaths = Array();
  54  
  55          /*
  56           * Setup includeExclude parameter
  57           * FORMAT:
  58           * Array(
  59           * 'include'=> Array('zipfilepath1', 'zipfilepath2', ...),
  60           * 'exclude'=> Array('zipfilepath3', ...)
  61           * )
  62           *
  63           * DEFAULT: If include is specified only files under the specified path will be included.
  64           * If exclude is specified folders or files will be excluded.
  65           */
  66          if($includeExclude === false) $includeExclude = Array();
  67  
  68          $lista = $this->getList();
  69          if(sizeof($lista)) foreach($lista as $fileName=>$trash){
  70              // Should the file be ignored?
  71              if($includeExclude['include'] &&
  72                  !$this->__checkPathInArray($fileName, $includeExclude['include'])) {
  73                      // Do not include something not specified in include
  74                      continue;
  75              }
  76              if($includeExclude['exclude'] &&
  77                  $this->__checkPathInArray($fileName, $includeExclude['exclude'])) {
  78                      // Do not include something not specified in include
  79                      continue;
  80              }
  81              // END
  82  
  83              $dirname  = dirname($fileName);
  84  
  85              // Rename the path with the matching one (as specified)
  86              if(!empty($renamePaths)) {
  87                  foreach($renamePaths as $lookup => $replace) {
  88                      if(strpos($dirname, $lookup) === 0) {
  89                          $dirname = substr_replace($dirname, $replace, 0, strlen($lookup));
  90                          break;
  91                      }
  92                  }
  93              }
  94              // END
  95  
  96              $outDN    = "$targetDir/$dirname";
  97  
  98              if(substr($dirname, 0, strlen($baseDir)) != $baseDir)
  99                  continue;
 100  
 101              if(!is_dir($outDN) && $maintainStructure){
 102                  $str = "";
 103                  $folders = explode("/", $dirname);
 104                  foreach($folders as $folder){
 105                      $str = $str?"$str/$folder":$folder;
 106                      if(!is_dir("$targetDir/$str")){
 107                          $this->debugMsg(1, "Creating folder: $targetDir/$str");
 108                          mkdir("$targetDir/$str");
 109                          if($applyChmod)
 110                              @chmod("$targetDir/$str", $applyChmod);
 111                      }
 112                  }
 113              }
 114              if(substr($fileName, -1, 1) == "/")
 115                  continue;
 116  
 117              if (substr($fileName, -3) == '.sh') $applyChmod = 0775; // Script executable.
 118              $this->unzip($fileName, "$targetDir/$dirname/".basename($fileName), $applyChmod);
 119          }
 120      }
 121  
 122      /**
 123       * Function checks if the file exist in the zip
 124       * @param type $fileName
 125       * @return boolean
 126       */
 127  	function checkFileExistsInRootFolder($fileName) {
 128          $fileList = $this->getList();
 129          foreach($fileList as $file => $details) {
 130              if($fileName === $file)
 131                  return true;
 132          }
 133          return false;
 134      }
 135  }
 136  ?>


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