namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
use App\Http\Middleware\CheckIfAdmin;
+use App\Jobs\FluidbookCompiler;
use App\Models\FluidbookPublication;
+use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
use Illuminate\Support\Facades\Route;
trait PreviewOperation
{
protected function setupPreviewRoutes($segment, $routeName, $controller)
{
-// // Redirect to the url with a timestamp to prevent cache
-// Route::match(['get'], $segment . '/preview/{id}_{hash}', function ($id, $hash) use ($segment) {
-// return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()));
-// })->whereNumber('id')
-// ->where('hash', '[0-9a-f]{32}')
-// ->withoutMiddleware([CheckIfAdmin::class]);
-//
-// Route::match(['get'], $segment . '/preview/{id}_{hash}_{time}/{path?}', function ($id, $hash, $time, $path = 'index.html') use ($segment, $controller) {
-// // If timestamp is too old, redirect to a more recent one
-// if ($path === 'index.html' && (time() - $time) > 30) {
-// return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time() . '/'));
-// }
-// return $this->preview($id, $hash, $path);
-// })->whereNumber('id')
-// ->where('hash', '[0-9a-f]{32}')
-// ->where('path', '.*')
-// ->withoutMiddleware([CheckIfAdmin::class]);
+ // Redirect to the url with a timestamp to prevent cache
+ Route::match(['get'], $segment . '/preview/{id}_{hash}', function ($id, $hash) use ($segment) {
+ return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/');
+ })->whereNumber('id')
+ ->where('hash', '[0-9a-f]{32}')
+ ->withoutMiddleware([CheckIfAdmin::class]);
+
+ Route::match(['get'], $segment . '/preview/{id}_{hash}_{time}/{path?}', function ($id, $hash, $time, $path = 'index.html') use ($segment, $controller) {
+ // If timestamp is too old, redirect to a more recent one
+ if ($path === 'index.html' && (time() - $time) > 30) {
+ return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/');
+ }
+ return $this->preview($id, $hash, $path);
+ })->whereNumber('id')
+ ->where('hash', '[0-9a-f]{32}')
+ ->where('path', '.*')
+ ->withoutMiddleware([CheckIfAdmin::class]);
}
protected function setupPreviewDefaults()
$this->crud->addButtonFromView('line', 'preview', 'fluidbook_publication.preview', 'end');
}
+ /**
+ * @throws \Exception
+ */
public function preview($id, $hash, $path = 'index.html')
{
$fluidbook = FluidbookPublication::where('id', $id)->where('hash', $hash)->first();
if (null === $fluidbook) {
abort(404);
}
- $dest = $fluidbook->getFinalPath();
+ $dest = $fluidbook->getFinalPath();
if ($path === 'index.html') {
- $fluidbook->compile($dest);
+ $compiler = new FluidbookCompiler($fluidbook);
+ $compiler->handle();
}
- return response('Preview of fluidbook ' . $id . ': ' . $path);
+ return XSendFileController::sendfile($dest . '/' . $path);
}
}
use App\Models\FluidbookTranslate;
use App\Models\Traits\FluidbookPlayerBranches;
use App\Util\FluidbookLinks;
+use Cubist\Backpack\Magic\Fields\Checkbox;
use Cubist\Excel\ExcelToArray;
use Cubist\Locale\Country;
use Cubist\Locale\Locale;
$this->scale = 1;
- $this->numerotation = explode(',', $this->getFluidbook()->numerotation);
-
if ($this->isMobileFirst()) {
$this->cssScale = $this->cssOneScale = 480 / $this->width;
$this->linkScale = $this->cssScale;
public function initConfig()
{
$this->config = new Data(array_merge($this->fluidbookSettings->getRawData()['settings'], $this->themeSettings->getRawData()));
+ $this->config->pages = count($this->getFluidbook()->composition);
$this->config->bookmarkDisablePages = ArrayUtil::parseRange($this->config->bookmarkDisablePages);
$this->config->rasterizePages = ArrayUtil::parseRange($this->config->rasterizePages);
$this->config->vectorPages = array_diff(ArrayUtil::parseRange($this->config->vectorPages), $this->config->rasterizePages);
+ $this->numerotation = $this->config->numerotation = explode(',', $this->getFluidbook()->page_numbers);
$hideOnPages = ArrayUtil::parseRange($this->config->tabsHideOnPages);
$this->config->tabsDisabledOnPages = ArrayUtil::parseRange($this->config->tabsDisabledOnPages);
protected function populateConfig()
{
- $this->config->numerotation = explode(',', $this->getFluidbook()->numerotation);
$this->config->id = $this->getFluidbook()->book_id;
$this->config->cid = $this->getFluidbook()->cid;
$this->config->cacheDate = time();
- $this->config->width = $this->cssWidth;
- $this->config->height = $this->cssHeight;
- $this->config->optimalWidth = $this->optimalWidth;
- $this->config->optimalHeight = $this->optimalHeight;
+ $this->config->width = round($this->cssWidth, 2);
+ $this->config->height = round($this->cssHeight, 2);
+ $this->config->optimalWidth = round($this->optimalWidth, 2);
+ $this->config->optimalHeight = round($this->optimalHeight, 2);
$this->config->chapters = $this->getFluidbook()->chapters;
$this->config->videoFormats = $this->getVideosFormats(false);
$this->config->htmlmultimedia = $this->htmlmultimedia;
$this->config->standardResolution = min($this->fluidbookSettings->maxResolution, 150);
$this->config->pageLabels = $this->pageLabels;
$this->config->pageZoomFactor = $this->z;
- $this->config->multiply = $this->multiply;
- $this->config->cssScale = $this->cssScale;
- $this->config->pdfZoomFactor = $this->pdf2htmlRatio;
+ $this->config->multiply = round($this->multiply, 6);
+ $this->config->cssScale = round($this->cssScale, 6);
+ $this->config->pdfZoomFactor = round($this->pdf2htmlRatio, 6);
if ($this->home) {
$this->config->home = 'http://home';
}
protected function writeConfig()
{
- $c = json_encode($this->config);
- return 'var SETTINGS=' . $c . ';' . "\n";
+ $data = $this->config->getRawData();
+ foreach ($data as $k => $v) {
+ if (null === $v) {
+ $v = $data[$k] = '';
+ }
+ if ($this->getFluidbook()->getField($k) instanceof Checkbox) {
+ $v = $data[$k] = !!$v;
+ }
+ }
+ return 'var SETTINGS=' . json_encode($data) . ';' . "\n";
}
protected function writeCountries()
{
- $c = Zend_Locale::getTranslationList('Territory', $this->getFluidbook()->lang, 2);
+ $c = Country::getList($this->getFluidbook()->locale);
asort($c);
$this->config->countries = $c;
}
$k = 'pagesDimensions.' . $page;
if (!$this->config->has($k)) {
$d = $this->getFluidbook()->getDocumentSize($page);
- $res = [$this->cssWidth, $d[1] * ($this->cssWidth / $d[0])];
+ $res = [round($this->cssWidth, 2), round($d[1] * ($this->cssWidth / $d[0]), 2)];
$this->config->set($k, $res);
return $res;
}
continue;
}
$doc = self::_getDocument($data[0]);
- $this->_documentsSize[$data[0]] = $doc->pdf_data['size'];
+ $s = $doc->pdf_data['size'];
+ $s[0] = round($s[0], 2);
+ $s[1] = round($s[1], 2);
+ $this->_documentsSize[$data[0]] = $s;
}
}
return $this->_documentsSize;
# Redirect to https if accessing from http
RewriteCond %{HTTPS} off
- RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
+ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=308,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
- RewriteRule ^admin(.*)$ $1 [L,R=301]
-
- # Redirect Trailing Slashes If Not A Folder...
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_URI} (.+)/$
- RewriteRule ^ %1 [L,R=301]
+ RewriteRule ^admin(.*)$ $1 [L,R=308]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d