use Cubist\Util\CSS;
use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Color;
use Cubist\Util\Json;
use SplFileInfo;
if ($ext === 'zip') {
$d = $this->unzipFile($this->to, false);
$this->_config = $this->getConfigZIP($d['dir']);
- $this->copyExternalDir($d['dir'], $d['fdir']);
- if (file_exists($d['dir'] . '/index.html')) {
- $html = file_get_contents($d['dir'] . '/index.html');
- $html = str_replace('var pRatio = window.devicePixelRatio || 1,', 'var pRatio = 0.5,', $html);
- $this->_config['lowDef'] = 'index_ld.html';
- $this->compiler->getVirtualDirectory()->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html);
- }
+
+ $htmlfile = $d['dir'] . '/index.html';
} elseif ($ext === 'html') {
$fdir = 'data/links';
$dir = $fdir;
-
- $d = array('fdir' => $fdir, 'dir' => $dir);
- $this->compiler->getVirtualDirectory()->copy($this->compiler->working_path($this->to), $d['dir'] . '/' . $this->to);
+ $d = array('fdir' => $fdir, 'dir' => $this->compiler->working_path());
$this->_config = $this->getConfigHTML($d['dir'], $this->to);
$this->copyExternalFile($d['dir'] . '/' . $this->to);
+ $htmlfile = $this->compiler->working_path($this->to);
+
+ }
+
+
+ $html = file_get_contents($htmlfile);
+ $bgc = new Color($this->background);
+ $html = preg_replace('/background-color:.*$/m', 'background-color:' . $bgc->toCSS() . ';', $html);
+ $html = preg_replace('/loop:\s*(true|false),\s*$/m', 'loop: ' . ($this->video_loop ? 'true' : 'false') . ',', $html);
+ $html = preg_replace('/autoplay:\s*(true|false),\s*$/m', 'autoplay: ' . ($this->video_auto_start ? 'true' : 'false') . ',', $html);
+ $html = preg_replace('/renderer:\s*\'(svg|canvas|html)\',\s*$/m', 'renderer: \'' . $this->renderer . '\',', $html);
+ $replacedHTML = $this->_htmlReplacedName($htmlfile);
+ file_put_contents($replacedHTML, $html);
+
+ if ($ext === 'zip') {
+ $this->copyExternalDir($d['dir'], $d['fdir']);
+ } else {
+ $this->compiler->getVirtualDirectory()->copy($replacedHTML, $d['fdir'] . '/' . $this->_htmlReplacedName($this->to));
}
+
+
if ($this->_config['width'] == 0) {
$this->_config['width'] = $this->width;
}
$res = '';
$s = $this->in_popup ? 1 : $this->getCssScale();
if ($this->_config['html']) {
- $this->_url = $d['fdir'] . '/' . $this->_config['html'];
+ $this->_url = $d['fdir'] . '/' . $this->_htmlReplacedName($this->_config['html']);
if ($this->extra) {
$this->_url .= '?' . $this->extra;
}
}
return $this->_content;
}
+
+ protected function _htmlReplacedName($html)
+ {
+ return str_replace('.html', '.r.html', $html);
+ }
}