Skip to content

Commit

Permalink
introduce new version of chumper/zipper compatible with laravel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasvielmetter committed Sep 28, 2019
1 parent b18dfa0 commit dac6f4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"require": {
"php" : ">=7.1.0",
"mustache/mustache": "^2.12",
"intervention/image": "^2.5"
"intervention/image": "^2.5",
"wrklst/zipper": "^1.0"
},
"homepage" : "https://github.com/wrklst/docxmustache",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/WrkLst/DocxMustache/DocImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public function ResampleImage($parent, $imgs, $k, $data, $dpi = 72)
$img_rework->save($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest']));
}

$parent->zipper->addEmptyDir('word/media')->addFile($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest']));
$parent->zipper->folder('word/media')->add($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest']));


return [
'height' => $new_height,
Expand Down
14 changes: 7 additions & 7 deletions src/WrkLst/DocxMustache/DocxMustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct($items, $local_template_file)
$this->template_file_name = basename($local_template_file);
$this->template_file = $local_template_file;
$this->word_doc = false;
$this->zipper = new \ZipArchive();
$this->zipper = new \Wrklst\Zipper\Zipper();

//name of disk for storage
$this->storageDisk = 'local';
Expand Down Expand Up @@ -98,8 +98,8 @@ public function CopyTmplate()
protected function exctractOpenXmlFile($file)
{
$this->zipper
->open($this->StoragePath($this->local_path.$this->template_file_name))
->extractTo($this->StoragePath($this->local_path), [$file]);
->make($this->StoragePath($this->local_path.$this->template_file_name))
->extractTo($this->StoragePath($this->local_path), [$file], \Wrklst\Zipper\Zipper::WHITELIST);
}

protected function ReadOpenXmlFile($file, $type = 'file')
Expand All @@ -126,11 +126,11 @@ protected function SaveOpenXmlFile($file, $folder, $content)
->put($this->local_path.$file, $content);
//add new content to word doc
if ($folder) {
$this->zipper->addEmptyDir($folder)
->addFile($this->StoragePath($this->local_path.$file));
$this->zipper->folder($folder)
->add($this->StoragePath($this->local_path.$file));
} else {
$this->zipper
->addFile($this->StoragePath($this->local_path.$file));
->add($this->StoragePath($this->local_path.$file));
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ protected function RemoveReplaceImages($imgs_replaced, &$rels_file)
$i = 0;
foreach ($rels_file as $rel) {
if ((string) $rel->attributes()['Id'] == $img_replaced) {
$this->zipper->deleteName('word/'.(string) $rel->attributes()['Target']);
$this->zipper->remove('word/'.(string) $rel->attributes()['Target']);
unset($rels_file->Relationship[$i]);
}
$i++;
Expand Down

0 comments on commit dac6f4d

Please sign in to comment.