Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 function handleOOXMLUpload()
 {
     if (isset($_FILES['uploaded'])) {
         $target = './upload/pptx/' . $_SESSION['uid'] . '/';
         if (!file_exists($target)) {
             mkdir($target);
         }
         $target = $target . basename($_FILES['uploaded']['name']);
         $pptxType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
         if ($_FILES['uploaded']['type'] != $pptxType) {
             $message = '<div id="error-type">File type not supported! Please, upload .pptx files.</div>';
             // die();
         } elseif ($_FILES['uploaded']['error'] === UPLOAD_ERR_OK) {
             if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
                 if (isset($_POST['import_with_style'])) {
                     $import_with_style = $_POST['import_with_style'];
                 } else {
                     $import_with_style = false;
                 }
                 // quick fix for cheking file formatting
                 $zip = new clsTbsZip();
                 $zip->Open($target);
                 if ($zip->FileExists('docProps/core.xml')) {
                     $proper_pptx = true;
                 } else {
                     $proper_pptx = false;
                 }
                 $zip->Close();
                 if ($proper_pptx) {
                     $pr = new pptxPresentation($target, $import_with_style);
                     $deck_num = $pr->saveToDB($this->_user['id']);
                 } else {
                     $message = '<div id="error-type">Not proper .pptx format! Open Office .pptx files are not supported yet.</div>';
                 }
             } else {
                 $message = 'Sorry, there was a problem uploading your file.';
             }
         } else {
             $message = $this->file_upload_error_message($_FILES['uploaded']['error']);
         }
     } else {
         $message = '<div id="error-type">There was no file to upload.</div>';
     }
     if (empty($message)) {
         $this->set('deck_num', $deck_num);
     } else {
         $this->set('message', $message);
     }
 }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
0
 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);
     //		}
 }
Exemplo n.º 5
0
2011-03-26: un internaute me fait ermarque que le fichier modèle ODT n'est pas valide selon les outils ODF validators
  http://tools.services.openoffice.org/odfvalidator/
 Cela vient du fait que certaines version d'OpenOffice ne respecte les standard strcits d'ODf et aussi est buggé par d'autre moments.
 Ce script corrige les problèmes connus afin que els fichiers passent positivement le test du validateur.
 */
if (file_exists('tbszip.php')) {
    include_once 'tbszip.php';
} else {
    include_once '../tbs_plugin_opentbs.php';
}
$file_lst = array('demo_oo_text.odt', 'demo_oo_formula.odf', 'demo_oo_graph.odg', 'demo_oo_presentation.odp', 'demo_oo_spreadsheet.ods');
$version = '1.2';
// valeur par défaut à mettre dans le manifest
$manifest = 'META-INF/manifest.xml';
$styles = 'styles.xml';
$odf = new clsTbsZip();
foreach ($file_lst as $file) {
    $odf->Open($file);
    echo "<h4>Étude du fichier '{$file}'.</h4>\r\n";
    $extension = strtolower(substr($file, -4));
    if (!$odf->FileExists($manifest)) {
        echo "Le fichier manifest n'a pas été trouvé.<br>\r\n";
        continue;
    }
    /* debug
    	if (file_exists('manifest.xml')) {
    		$odf->FileReplace($manifest, 'manifest.xml', TBSZIP_FILE);
    		$temp = $file.'.tmp.odt';
    		$odf->Flush(TBSZIP_FILE, $temp);
    		echo "Fichier fanifest remplacé par le fichier 'manifest.xml' trouvé dans le répertoire.<br>\r\n";
    		exit;
Exemplo n.º 6
0
<?php

/* Some code examples for TbsZip
Skrol29, 2010-09-03
*/
include_once 'tbszip.php';
// load the TbsZip library
$zip = new clsTbsZip();
// create a new instance of the TbsZip class
$zip->CreateNew();
// start a new empty archive for adding files
// or
$zip->Open('an_existing_archive.zip');
// open an existing archive for reading and/or modifying
// --------------------------------------------------
// Reading information and data in the opened archive
// --------------------------------------------------
// check if a file is existing in the archive, the name must precise subfolders if any
$ok = $zip->FileExists('subfolder/help.html');
// count the files stored in the archive
$file_nbr = count($zip->CdFileLst);
// retrieve the content of an compressed file in the archive
$text1 = $zip->FileRead('readme.txt');
// retrieve the content of an compressed file in a subfolder of the archive
$text2 = $zip->FileRead('subfolder/readme.txt');
if ($ok) {
    $zip->FileExists('subfolder/help.html');
}
// -----------------------------
// Modifying data in the archive
// -----------------------------
Exemplo n.º 7
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);
 }