Exemple #1
0
 public function read_file($file)
 {
     $zip = new clsTbsZip();
     $zip->Open($file);
     $content = $zip->FileRead('word/document.xml');
     $content = str_replace(array_keys($this->dbData), array_values($this->dbData), $content);
     $zip->FileReplace('word/document.xml', $content);
     $path_parts = pathinfo($file);
     $zip->Flush(TBSZIP_FILE, $this->fileFolder . '/' . $path_parts['filename'] . "MODIFIED." . $path_parts['extension']);
     $zip->close();
 }
Exemple #2
0
 public static function avr(array $params, $filename)
 {
     $zip = new clsTbsZip();
     $default = array('investorName' => '', 'customerName' => '', 'contractorName' => '', 'constructionName' => '', 'objectName' => '', 'investorCode' => '', 'customerCode' => '', 'contractorCode' => '', 'constructionCode' => '', 'objectCode' => '', 'kindOfActivity' => '', 'contractNumber' => '', 'typeOfOperation' => '', 'dayOfContract' => '', 'mounthOfContract' => '', 'yearOfContract' => '', 'documentNumber' => '', 'dateOfDocument' => '', 'reportingPeriodFrom' => '', 'reportingPeriodTo' => '', 'outlayPrice' => '', 'totalQuantity' => '', 'totalPrice' => '', 'table' => array(), 'personWhoGiveTranscript' => '', 'personWhoGiveOfficialCapacity' => '', 'personWhoTakeTranscript' => '', 'personWhoTakeOfficialCapacity' => '');
     $params = array_merge($default, $params);
     while (sizeof($params['table']) < 10) {
         $params['table'][] = array('byOrder' => '', 'byOutlay' => '', 'workName' => '', 'unitPriceNumber' => '', 'measurement' => '', 'quantity' => '', 'unitPrice' => '', 'price' => '');
     }
     $zip->Open(dirname(__FILE__) . '/Avr/origin.odt');
     $zip->FileReplace('content.xml', Evil_Avr::_avrDocument($params), TBSZIP_STRING);
     $zip->Flush(TBSZIP_FILE, $filename);
     $zip->Close();
     return true;
 }
 public function actionZip()
 {
     Yii::import('application.helpers.vendors.zip.clsTbsZip');
     $zip = new clsTbsZip();
     /**create**/
     //		$zip->CreateNew();
     //
     //		$zip->FileAdd('sub/test2.txt', './public/test2.txt',TBSZIP_FILE);
     //
     //		$zip->Flush(TBSZIP_FILE, './public/zip/test.zip');
     $zipfile = './public/zip/test.zip';
     $tmpfile = './public/zip/tmp.zip';
     $zip->Open($zipfile);
     //		echo $zip->FileExists('test2.txt');
     if (!$zip->FileExists('test.txt')) {
         $zip->FileAdd('test.txt', './public/test.txt', TBSZIP_FILE);
     }
     if (!$zip->FileExists('pclzip-2-8.zip')) {
         $zip->FileAdd('pclzip-2-8.zip', './public/zip/pclzip-2-8.zip', TBSZIP_FILE);
     }
     //		$zip->FileAdd('hello.jpg', './public/uploadfiles/82671333902992.jpg', TBSZIP_FILE);
     echo $zip->FileRead('pclzip-2-8.zip');
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip');
     //		echo $zip->FileRead('test.txt');
     //		foreach ($zip->CdFileLst as $file)
     //		{
     //			UtilHelper::dump($zip->FileRead($file['v_name']));
     //		}
     $zip->Flush(TBSZIP_FILE, $tmpfile);
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip');
     $zip->close();
     //		if (file_exists($zipfile)){
     //			unlink($zipfile);
     //
     //			copy($tmpfile, $zipfile);
     //
     //			unlink($tmpfile);
     //		}
 }
        $odf->FileReplace($manifest, $txt, TBSZIP_STRING);
        // si on ne compresse pas ça fait un bug !! à vérifier pourquoi
        echo "<span style='color:red;'>{$replace_manifest} modifications ont été apportées au fichier manifest</span><br>\r\n";
    }
    // recherche du bug dans le fichier style
    $replace_style = 0;
    if ($odf->FileExists($styles)) {
        $txt = $odf->FileRead($styles);
        $item = ' fo:font-size="0pt"';
        if (strpos($txt, $item) !== false) {
            $item2 = str_replace('"0pt"', '"14pt"', $item);
            $txt = str_replace($item, $item2, $txt);
            $odf->FileReplace($styles, $txt, TBSZIP_STRING);
            // si on ne compresse pas ça fait un bug !! à vérifier pourquoi
            echo "<span style='color:red;'>une modification a été apportée au fichier styles</span><br>\r\n";
            $replace_style++;
        }
    }
    if ($replace_manifest + $replace_style > 0) {
        $temp = $file . '.tmp';
        $odf->Flush(TBSZIP_FILE, $temp);
        $odf->OutputClose();
        // à ajouter car bug si TbsZip <= 2.3
        $odf->Close();
        unlink($file);
        rename($temp, $file);
    } else {
        echo "<span style='color:green;'>L'archive n'a pas été modifiée.</span><br>\r\n";
    }
}
//echo $txt;
// add the uncompressed file by copying a local file
// delete an existing file in the archive
$zip->FileReplace('newfile.txt', $data, TBSZIP_STRING);
// replace the file by giving the content
$zip->FileReplace('newpic1.png', './images/localpic1.png', TBSZIP_FILE);
// replace the file by copying a local file
$zip->FileReplace('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false);
// replace the uncompressed file by copying a local file
$zip->FileReplace('newpic3.png', false);
// delete the file in the archive
// cancel the last modification on the file (add/replace/delete)
$zip->FileCancelModif('newpic2.png');
// ----------------------
// Applying modifications
// ----------------------
$zip->Flush(TBSZIP_FILE, './save/new_archive.zip');
// apply modifications as a new local file
// apply modifications as an HTTP downloaded file
$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip');
$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip');
// with a specific Content-Type
// apply modifications as a downloaded file with your customized HTTP headers
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=download.zip");
header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
$zip->Flush(TBSZIP_DOWNLOAD + TBSZIP_NOHEADER);
// -----------------
// Close the archive
// -----------------
$zip->Close();
// stop to work with the opened archive. Modifications are not applied to the opened archive, use Flush() to commit
Exemple #6
0
 /**
  * Modify contents of docx/odt file(s) and later merged into one final document
  *
  * @param string $filePath
  *   Document file path
  * @param array $contents
  *   Content of formatted/token-replaced document
  * @param string $docType
  *   Document type e.g. odt/docx
  * @param clsTbsZip $zip
  *   Zip archive
  * @param bool $returnFinalContent
  *   Return the content of file document as a string used in unit test
  *
  * @return string
  */
 public static function printDocuments($filePath, $contents, $docType, $zip, $returnFinalContent = FALSE)
 {
     $dataMap = self::$ooxmlMap[$docType];
     $finalContent = $zip->FileRead($dataMap['dataFile']);
     // token-replaced document contents of each contact will be merged into final document
     foreach ($contents as $key => $content) {
         if ($key == 0) {
             $finalContent = $content;
             continue;
         }
         // 1. fetch the start position of document body
         // 2. later fetch only the body part starting from position $start
         // 3. replace closing body tag with pageBreak
         // 4. append the $content to the finalContent
         $start = strpos($content, $dataMap['startTag']);
         $content = substr($content, $start);
         $content = str_replace($dataMap['startTag'], $dataMap['pageBreak'], $content);
         $finalContent = str_replace($dataMap['endTag'], $content, $finalContent);
     }
     if ($returnFinalContent) {
         return $finalContent;
     }
     // Replace the loaded document file content located at $filePath with $finaContent
     $zip->FileReplace($dataMap['dataFile'], $finalContent, TBSZIP_STRING);
     $fileName = pathinfo($filePath, PATHINFO_FILENAME) . '.' . $docType;
     $zip->Flush(TBSZIP_DOWNLOAD, $fileName);
 }