Esempio n. 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();
 }
Esempio n. 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;
 }
         if (substr($txt, $p - 1, 1) === ' ') {
             $p--;
         }
         if (substr($txt, $p - 1, 1) === "\n") {
             $p--;
         }
         // $x = substr($txt, $p, $pe - $p +1);
         $txt = substr_replace($txt, '', $p, $pe - $p + 1);
         $replace_manifest++;
     } else {
         // item suivant
         $p = $pc;
     }
 }
 if ($replace_manifest > 0) {
     $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++;
$text2 = $zip->FileRead('subfolder/readme.txt');
if ($ok) {
    $zip->FileExists('subfolder/help.html');
}
// -----------------------------
// Modifying data in the archive
// -----------------------------
// add a file in the archive
$zip->FileAdd('newfile.txt', $data, TBSZIP_STRING);
// add the file by giving the content
$zip->FileAdd('newpic1.png', './images/localpic1.png', TBSZIP_FILE);
// add the file by copying a local file
$zip->FileAdd('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false);
// 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
Esempio n. 5
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);
 }