use Cubist\Util\Files\Files;
use Cubist\Util\Files\VirtualDirectory;
use Cubist\Util\PHP;
-use Cubist\Util\Zip;
use Exception;
use Fluidbook\Tools\Jobs\ProcessFile;
use Fluidbook\Tools\Jobs\ProcessPage;
use Illuminate\Queue\SerializesModels;
use JsonException;
use stdClass;
-use ZipStream\File;
class Compiler implements ShouldQueue, ShouldBeUnique
{
/**
* @var string
*/
- public $wdir;
+ public $wdir = '';
/**
* @var string
{
start_measure('Compile fluidbook');
- $this->wdir = resource_path('fluidbook/working/');
- Files::mkdir($this->wdir);
+ if ($this->wdir === '') {
+ $this->wdir = resource_path('fluidbook/working/');
+ Files::mkdir($this->wdir);
+ }
+
$this->vdir = new VirtualDirectory($this->out);
if ($this->stub !== '') {
$this->vdir->copyDirectory($this->stub, '/');
}
}
- public function unzipFile($file, $moveAssets = false, $baseDir = null)
- {
- $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', $file) : $baseDir;
-
- $tmp = Files::tmpdir();
- $dir = $tmp . '/' . $fdir;
- Files::mkdir($dir);
-
- Zip::extract($this->wdir . '/' . $file, $dir);
-
- if ($moveAssets) {
- `mv $dir/Assets/* $dir`;
- rmdir($dir . '/Assets');
- }
-
- return array('dir' => $dir, 'fdir' => $fdir);
- }
-
protected function compilePageNumbers()
{
namespace Fluidbook\Tools\Compiler;
use Cubist\Util\ArrayUtil;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Zip;
+use Exception;
use Fluidbook\Tools\Links\ContentLink;
use Fluidbook\Tools\Links\Link;
use Nette\Utils\Image;
foreach ($source as $so) {
$s = $this->wdir . $so;
- //dd($s,$so,$dest);
if (file_exists($s)) {
$d = $dest . '/' . $so;
$this->simpleCopyLinkFile($s, $d, false);
}
}
}
+
+ /**
+ * @throws Exception
+ */
+ public function unzipFile($file, $moveAssets = false, $baseDir = null)
+ {
+ $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', Files::getFilename($file)) : $baseDir;
+
+ $dir = $this->wdir . $fdir;
+ Files::mkdir($dir);
+
+ if (!file_exists($file) && file_exists($this->wdir . '/' . $file)) {
+ $file = $this->wdir . '/' . $file;
+ }
+
+ if (!file_exists($file)) {
+ throw new Exception('Zip file ' . $file . ' does not exist');
+ }
+
+
+ Zip::extract($file, $dir);
+
+ if ($moveAssets) {
+ `mv $dir/Assets/* $dir`;
+ rmdir($dir . '/Assets');
+ }
+
+ return array('dir' => $dir, 'fdir' => $fdir);
+ }
}
$this->copyExternalDir($d['dir'], $d['fdir']);
$this->path = $d['fdir'];
- $this->path_absolute = $this->compiler->getVirtualDirectory()->path($d['fdir']);
+ $this->path_absolute = $d['dir'];
return '#/slideshow/' . $this->uid;
}
$res .= '<ul class="splide__list">';
foreach ($slides as $slide) {
- $image_path_relative = $this->compiler->getVirtualDirectory()->relativePath($slide['path']);
+
+ $image_path_relative = str_replace($this->compiler->wdir, '', $slide['path']);
+
$image_info = Image::getimagesize($slide['path']);
$image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1], 'ratio' => round($image_info[0] / $image_info[1], 4)]) : '';
+
$image_dimensions = ($image_info) ? $image_info[3] : '';
// When displaying thumbnails, they are a fixed size, based on height