use App\Fluidbook\PDF;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\SocialImageOperation;
+use App\Http\Controllers\Admin\Operations\Tools\Favicon;
use App\Models\Signature;
use App\Fluidbook\SearchIndex;
use App\Fluidbook\SEO\Document;
use Fluidbook\Tools\Links\AnchorLink;
use Fluidbook\Tools\Links\ContentLink;
use App\Fluidbook\Link\Link;
+use Fluidbook\Tools\SVG\SVGTools;
use Illuminate\Console\Command;
use SimpleXMLElement;
use SplFileInfo;
{
use FluidbookPlayerBranches;
use \Fluidbook\Tools\Compiler\FluidbookCompiler;
+ use SocialImageOperation;
+ use Favicon;
protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
if ($this->themeSettings->iconSet > 15) {
$this->svgfiles[] = storage_path('icons/' . $this->themeSettings->iconSet . '.svg');
}
- if ($this->themeSettings->symbols !== '') {
- $this->svgfiles[] = $this->themeAsset($this->themeSettings->symbols);
+ if ($symbols = $this->themeAsset('symbols')) {
+ $this->svgfiles[] = $symbols->getPathname();
}
if ($this->isMobileFirst()) {
$this->fluidbookSettings->set($key, $value);
}
- public function themeAsset($key, $default = null)
+
+ /**
+ * @param $key
+ * @param $default
+ * @return null|SplFileInfo
+ */
+ public function themeAsset($key)
{
$collection = $this->theme->{$key};
+
if ($collection) {
$path = $this->theme->getFirstMediaPath($collection);
- if (!$path) {
- return $default;
+ if (!$path || !file_exists($path)) {
+ return false;
}
- return $path;
- } else {
- return $default;
+ return new SplFileInfo($path);
}
+ return false;
}
/**
$socialDescription = htmlspecialchars($this->fluidbookSettings->facebook_description ?: $this->fluidbookSettings->seoDescription, ENT_COMPAT);
$socialImage = 'https://toolbox.fluidbook.com/services/socialimage/' . $this->getFluidbook()->cid;
- $dim = SocialImageOperation::getSocialImageSize($this->getFluidbook());
+ $dim = self::getSocialImageSize($this->getFluidbook());
$socialImageWidth = $dim[0];
$socialImageHeight = $dim[1];
$this->log('Got index vars 3');
$favicon = '';
- $hasIos = false;
- //if ($iosico = $this->checkThemeImage($this->>$this->themeSettings->iosicon)) {
- // $hasIos = true;
- // $this->vdir->copy($iosico, 'data/apple-touch-icon.png');
- // $favicon .= '<link rel="apple-touch-icon" href="data/apple-touch-icon.png" />' . "\n\t";
- //}
- if ($this->themeSettings->favicon != '') {
-
- $pngFile = $this->checkThemeImage($this->themeSettings->favicon);
- $icoFile = $this->checkThemeImage('favicon.ico');
-
- if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) {
- $tmp = Files::tempnam() . '.png';
- $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp";
- `$convert`;
-
- $icotool = new CommandLine('icotool');
- $icotool->setArg('c');
- $icotool->setArg('o', $icoFile);
- $icotool->setArg(null, $tmp);
- $icotool->execute();
-
- unlink($tmp);
- }
+ $faviconAsset = $this->themeAsset('favicon');
+ if ($faviconAsset) {
+ $pngFile = $faviconAsset->getPathname();
+ $faviconDir = self::generateFavicons($pngFile);
- $this->vdir->copy($icoFile, 'data/favicon.ico');
+ $this->vdir->copy($faviconDir . '/favicon.ico', 'data/favicon.ico');
$this->vdir->copy($pngFile, 'data/favicon.png');
+ $this->vdir->copy($faviconDir . '/apple-touch-icon.png', 'data/apple-touch-icon.png');
$datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile));
$favicon .= '<link rel="icon" type="image/png" href="' . $datapng . '" />' . "\n\t";
- if (!$hasIos) {
- $favicon .= '<link rel="apple-touch-icon" href="data/favicon.png" />';
- }
+ $favicon .= '<link rel="apple-touch-icon" href="data/apple-touch-icon.png" />';
}
$print = $this->writePrint();
$splash = '';
$splashstyles = '';
- $img = $this->fluidbookSettings->splashImage;
- if ($img) {
- $this->vdir->copy($this->wdir . '/' . $img, 'data/images/' . $img);
- $splashstyles = 'background-image:url(' . 'data/images/' . $img . ');background-size:contain;background-position:50% 50%;';
+ $splashImage = $this->themeAsset('splashImage');
+ if ($splashImage) {
+ $this->vdir->copy($splashImage->getPathname(), 'data/images/' . $splashImage->getFilename());
+ $splashstyles = 'background-image:url(' . 'data/images/' . $splashImage->getFilename() . ');background-size:contain;background-position:50% 50%;';
if ($this->fluidbookSettings->splashURL !== '') {
$splash = '<a href="' . $this->fluidbookSettings->splashURL . '" target="' . $this->fluidbookSettings->splashTarget . '" style="display:block;position:absolute;top:0;left;0;width:100%;height:100%"></a>';
}
- } else if ($ll = $this->checkThemeImage($this->themeSettings->logoLoader)) {
- $dim = Image::getimagesize($ll);
+ } else if ($logoLoader = $this->themeAsset('logoLoader')) {
+ $dim = Image::getimagesize($logoLoader->getPathname());
if ($dim !== false) {
- $this->vdir->copy($ll, 'data/images/' . $this->themeSettings->logoLoader);
- $splash .= '<div class="logo"><img src="data/images/' . $this->themeSettings->logoLoader . '" width="' . $dim[0] . '" height="' . $dim[1] . '" alt="" /></div>';
+ $this->vdir->copy($logoLoader->getPathname(), 'data/images/' . $logoLoader->getFilename());
+ $splash .= '<div class="logo"><img src="data/images/' . $logoLoader->getFilename() . '" width="' . $dim[0] . '" height="' . $dim[1] . '" alt="" /></div>';
}
}
$svg = $this->_mergeSVG();
protected function writeExtras()
{
- if ($as = $this->checkThemeImage($this->themeSettings->afterSearch)) {
- $this->vdir->copy($as, 'data/images/' . $this->themeSettings->afterSearch);
+ if ($afterSearch = $this->themeAsset('afterSearch')) {
+ $this->vdir->copy($afterSearch->getPathname(), $afterSearch->getFilename());
}
if ($this->fluidbookSettings->externalArchives != '') {
$this->addFilesInfos('archives', $this->wdir . '/' . $this->fluidbookSettings->externalArchives);
protected function addSVGSymbolFromFile($svg, $symbolName)
{
- $svg = wsTools::optimizeSVG($svg);
+ $svg = SVGTools::optimizeSVG($svg);
$xml = simplexml_load_string(file_get_contents($svg));
$viewBox = (string)$xml['viewBox'];
// Header
$header = 'header{';
$header .= 'height:' . $this->themeSettings->menuHeight . 'px;';
- if ($mi = $this->checkThemeImage($this->themeSettings->menuImage)) {
- $this->vdir->copy($mi, 'data/images/' . $this->themeSettings->menuImage);
- $header .= 'background-image:url(../images/' . $this->themeSettings->menuImage . ');';
+ if ($mi = $this->themeAsset('menuImage')) {
+ $this->vdir->copy($mi->getPathname(), 'data/images/' . $mi->getFilename());
+ $header .= 'background-image:url(../images/' . $mi->getFilename() . ');';
$header .= 'background-repeat:no-repeat;';
$header .= 'background-size:100% ' . $this->themeSettings->menuHeight . 'px;';
} else {
$this->log('CSS 5');
// Logo
$logo = '#logo{';
- if ($l = $this->checkThemeImage($this->themeSettings->logo)) {
- $this->vdir->copy($l, 'data/images/' . $this->themeSettings->logo);
- $dim = Image::getimagesize($l);
- $logo .= 'background-image:url(../images/' . $this->themeSettings->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;';
+ if ($l = $this->themeAsset('logo')) {
+ $this->vdir->copy($l->getPathname(), 'data/images/' . $l->getFilename());
+ $dim = Image::getimagesize($l->getPathname());
+ $logo .= 'background-image:url(../images/' . $l->getFilename() . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;';
}
$logo .= '}';
$res[] = $logo;
$this->log('Write CSS');
}
- protected function checkThemeImage($path)
- {
- $path = trim($path);
- $path = trim($path, '/');
- if (!$path) {
- return false;
- }
- $p = $this->themeRoot . '/' . $path;
- if (file_exists($p)) {
- return $p;
- }
- $po = str_replace('.svg', '.o.svg', $p);
- if (file_exists($po)) {
- copy($po, $p);
- return $p;
- }
- return false;
- }
-
protected function _writeLess($variables, $lessContents = '')
{
if ($this->widget) {
break;
}
- if ($bi = $this->checkThemeImage($this->themeSettings->backgroundImage)) {
+ if ($backgroundImage = $this->themeAsset('backgroundImage')) {
- $dbi = Image::getimagesize($bi);
+ $dbi = Image::getimagesize($backgroundImage->getPathname());
$this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]);
- $this->vdir->copy($bi, 'data/images/' . $this->themeSettings->backgroundImage);
- $body .= 'background-image:url(../images/' . $this->themeSettings->backgroundImage . ');';
+ $this->vdir->copy($backgroundImage->getPathname(), 'data/images/' . $backgroundImage->getFilename());
+ $body .= 'background-image:url(../images/' . $backgroundImage->getFilename() . ');';
$body .= 'background-position:';
switch ($this->themeSettings->backgroundVAlign) {