Example #1
0
 function InstallFiles($arParams = array())
 {
     global $APPLICATION;
     $archive = $this->getArchive();
     if ($archive == false) {
         // Copy from a local copy
         $this->errors = false;
         $fileName = pathinfo(self::ARCHIVE_URL, PATHINFO_BASENAME);
         $archiveLocal = $_SERVER['DOCUMENT_ROOT'] . '/' . $this->DIR_MODULE . '/modules/' . $this->MODULE_ID . '/install/data/' . $fileName;
         $archive = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/tmp/' . $fileName;
         CopyDirFiles($archiveLocal, $archive, true, true);
     }
     list($dirName, , , $fileName) = array_values(pathinfo($archive));
     require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/zip.php';
     $toDirData = $_SERVER['DOCUMENT_ROOT'] . '/' . $this->DIR_MODULE . '/modules/' . $this->MODULE_ID . '/data';
     $zip = new CZip($archive);
     if (!$zip->Unpack(sprintf('%s/%s/', $dirName, $fileName))) {
         $this->errors[] = $zip->GetErrors();
     } else {
         if (CheckDirPath($toDirData . '/')) {
             if (!CopyDirFiles(sprintf('%s/%s', $dirName, $fileName), $toDirData, true, true)) {
                 $this->errors[] = Loc::getMessage('OLEGPRO_IPGEOBASE_INSTALL_ERROR_COPY_IN_DIR', array('#FROM_DIR#' => sprintf('%s/%s/', $dirName, $fileName), '#TO_DIR#' => $_SERVER['DOCUMENT_ROOT'] . '/' . $this->DIR_MODULE . '/modules/' . $this->MODULE_ID . '/data'));
             }
         } else {
             $this->errors[] = Loc::getMessage('OLEGPRO_IPGEOBASE_INSTALL_ERROR_NOT_WRITE', array('#TO_DIR#' => $toDirData));
         }
     }
     return true;
 }
Example #2
0
 private function _deleteByRule(&$arResultList, &$arParams)
 {
     $arCentralDirInfo = array();
     $arHeaders = array();
     if (($res = $this->_openFile('rb')) != 1) {
         return $res;
     }
     if (($res = $this->_readEndCentralDir($arCentralDirInfo)) != 1) {
         $this->_closeFile();
         return $res;
     }
     //scanning all the files, starting at the beginning of Central Dir
     $entryPos = $arCentralDirInfo['offset'];
     @rewind($this->zipfile);
     if (@fseek($this->zipfile, $entryPos)) {
         //clean file
         $this->_closeFile();
         $this->_errorLog("ERR_INVALID_ARCHIVE_ZIP", GetMessage("MAIN_ZIP_ERR_INVALID_ARCHIVE_ZIP"));
         return $this->arErrors;
     }
     $j_start = 0;
     //reading each entry
     for ($i = 0, $extractedCounter = 0; $i < $arCentralDirInfo['entries']; $i++) {
         //reading file header
         $arHeaders[$extractedCounter] = array();
         $res = $this->_readCentralFileHeader($arHeaders[$extractedCounter]);
         if ($res != 1) {
             $this->_closeFile();
             return $res;
         }
         //saving index
         $arHeaders[$extractedCounter]['index'] = $i;
         //check specific extract rules
         $isFound = false;
         //name rule
         if (isset($arParams['by_name']) && $arParams['by_name'] != 0) {
             //if the filename is in the list
             for ($j = 0; $j < sizeof($arParams['by_name']) && !$isFound; $j++) {
                 if (substr($arParams['by_name'][$j], -1) == "/") {
                     //if the directory is in the filename path
                     if (strlen($arHeaders[$extractedCounter]['stored_filename']) > strlen($arParams['by_name'][$j]) && substr($arHeaders[$extractedCounter]['stored_filename'], 0, strlen($arParams['by_name'][$j])) == $arParams['by_name'][$j]) {
                         $isFound = true;
                     } elseif (($arHeaders[$extractedCounter]['external'] & 0x10) == 0x10 && $arHeaders[$extractedCounter]['stored_filename'] . '/' == $arParams['by_name'][$j]) {
                         $isFound = true;
                     }
                 } elseif ($arHeaders[$extractedCounter]['stored_filename'] == $arParams['by_name'][$j]) {
                     //check filename
                     $isFound = true;
                 }
             }
         } else {
             if (isset($arParams['by_preg']) && $arParams['by_preg'] != "") {
                 if (preg_match($arParams['by_preg'], $arHeaders[$extractedCounter]['stored_filename'])) {
                     $isFound = true;
                 }
             } else {
                 if (isset($arParams['by_index']) && $arParams['by_index'] != 0) {
                     //index rule: if index is in the list
                     for ($j = $j_start; $j < sizeof($arParams['by_index']) && !$isFound; $j++) {
                         if ($i >= $arParams['by_index'][$j]['start'] && $i <= $arParams['by_index'][$j]['end']) {
                             $isFound = true;
                         }
                         if ($i >= $arParams['by_index'][$j]['end']) {
                             $j_start = $j + 1;
                         }
                         if ($arParams['by_index'][$j]['start'] > $i) {
                             break;
                         }
                     }
                 }
             }
         }
         //delete?
         if ($isFound) {
             unset($arHeaders[$extractedCounter]);
         } else {
             $extractedCounter++;
         }
     }
     //if something should be deleted
     if ($extractedCounter > 0) {
         //create tmp file
         $zipname_tmp = GetDirPath($this->zipname) . uniqid('ziparc') . '.tmp';
         //create tmp zip archive
         $tmpzip = new CZip($zipname_tmp);
         if (($res = $tmpzip->_openFile('wb')) != 1) {
             $this->_closeFile();
             return $res;
         }
         //check which file should be kept
         for ($i = 0; $i < sizeof($arHeaders); $i++) {
             //calculate the position of the header
             @rewind($this->zipfile);
             if (@fseek($this->zipfile, $arHeaders[$i]['offset'])) {
                 $this->_closeFile();
                 $tmpzip->_closeFile();
                 @unlink($this->io->GetPhysicalName($zipname_tmp));
                 $this->_errorLog("ERR_INVALID_ARCHIVE_ZIP", GetMessage("MAIN_ZIP_ERR_INVALID_ARCHIVE_ZIP"));
                 return $this->arErrors;
             }
             if (($res = $this->_readFileHeader($arHeaders[$i])) != 1) {
                 $this->_closeFile();
                 $tmpzip->_closeFile();
                 @unlink($this->io->GetPhysicalName($zipname_tmp));
                 return $res;
             }
             //writing file header
             $res = $tmpzip->_writeFileHeader($arHeaders[$i]);
             if ($res != 1) {
                 $this->_closeFile();
                 $tmpzip->_closeFile();
                 @unlink($this->io->GetPhysicalName($zipname_tmp));
                 return $res;
             }
             //reading/writing data block
             $res = $this->_copyBlocks($this->zipfile, $tmpzip->zipfile, $arHeaders[$i]['compressed_size']);
             if ($res != 1) {
                 $this->_closeFile();
                 $tmpzip->_closeFile();
                 @unlink($this->io->GetPhysicalName($zipname_tmp));
                 return $res;
             }
         }
         //save central dir offset
         $offset = @ftell($tmpzip->zipfile);
         //re-write central dir files header
         for ($i = 0; $i < sizeof($arHeaders); $i++) {
             $res = $tmpzip->_writeCentralFileHeader($arHeaders[$i]);
             if ($res != 1) {
                 $tmpzip->_closeFile();
                 $this->_closeFile();
                 @unlink($this->io->GetPhysicalName($zipname_tmp));
                 return $res;
             }
             //convert header to the 'usable' format
             $tmpzip->_convertHeader2FileInfo($arHeaders[$i], $arResultList[$i]);
         }
         $zip_comment = '';
         $size = @ftell($tmpzip->zipfile) - $offset;
         $res = $tmpzip->_writeCentralHeader(sizeof($arHeaders), $size, $offset, $zip_comment);
         if ($res != 1) {
             unset($arHeaders);
             $tmpzip->_closeFile();
             $this->_closeFile();
             @unlink($this->io->GetPhysicalName($zipname_tmp));
             return $res;
         }
         $tmpzip->_closeFile();
         $this->_closeFile();
         //deleting zip file (result should be checked)
         @unlink($this->io->GetPhysicalName($this->zipname));
         //result should be checked
         $this->_renameTmpFile($zipname_tmp, $this->zipname);
         unset($tmpzip);
     }
     return $res;
 }