class wsHTML5Compiler {
protected static $resolutions = array(150, 300);
- protected $maxRes = 300;
+ public $maxRes = 300;
public $jsFiles = array(
'js/libs/modernizr/modernizr.min.js',
'js/libs/cube/fb.js',
'js/libs/modernizr/modernizr.min.js',
'js/libs/modernizr/tests.js',
- 'js/libs/jquery/jquery.js',
+ 'js/libs/jquery/jquery.min.js',
'js/libs/jquery/jquery.transit.js',
'js/widget.js'
);
protected $stylesheets = array();
protected $logfp = null;
protected $logtime = null;
+ protected $beginBody = array();
+ protected $seoArticles = [];
+ protected $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com'];
function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) {
global $core;
-
$this->phonegapVersion = wsHTML5::getPhonegapVersion($phonegapVersion);
$this->appcache = $appcache;
$this->multiApp = $this->home = $home;
$this->book = $this->daoBook->selectById($book_id);
$this->pages = $this->daoBook->getPagesOfBook($book_id);
- switch ($this->book->parametres->mobileVersion) {
- case 'html5-desktop':
- $this->backgroundsPrefix = array('t', 'p');
- $this->svg = true;
- break;
- case 'html5-images':
- $this->backgroundsPrefix = array('t');
- $this->svg = false;
- break;
- default:
- $this->backgroundsPrefix = array('p');
- $this->svg = true;
- break;
- }
$daoTheme = new wsDAOTheme($core->con);
$this->theme = $daoTheme->getThemeOfBook($book_id, true);
}
$this->numerotation = explode(',', $this->book->numerotation);
- $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject());
-
+ $this->initConfig();
$this->log('Defined dimensions');
}
+ public function initConfig() {
+ $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject());
+ }
+
public function log($step) {
$currenttime = microtime(true);
if (null === $this->logfp) {
$this->logtime = $currenttime;
}
+ public function addFacebookSDK() {
+ $lang = str_replace('-', '_', $this->book->lang);
+ $e = explode('_', $lang);
+ if (count($e) > 1) {
+ $e[1] = mb_strtoupper($lang);
+ }
+ $lang = implode('_', $e);
+ $this->beginBody[] = "<div id=\"fb-root\"></div>
+<script>(function(d, s, id) {
+ var js, fjs = d.getElementsByTagName(s)[0];
+ if (d.getElementById(id)) return;
+ js = d.createElement(s); js.id = id;
+ js.src = 'https://connect.facebook.net/" . $lang . "/sdk.js#xfbml=1&version=v2.11&appId=132006430233560';
+ fjs.parentNode.insertBefore(js, fjs);
+}(document, 'script', 'facebook-jssdk'));</script>";
+ $this->securityPolicyWhitelist[] = '*.facebook.net';
+ $this->securityPolicyWhitelist[] = 'data:';
+ }
+
public function addPageLabel($page, $label) {
$this->pageLabels[$label] = $page;
}
public function getResolutions() {
- $res = self::$resolutions;
+ $res = [];
+ foreach (self::$resolutions as $r) {
+ if ($r > $this->maxRes) {
+ continue;
+ }
+ $res[] = $r;
+ }
if ($this->widget) {
$res = array_merge(array(36), $res);
}
return $p + 1;
}
- public function compile() {
+ public function compile($delete = true) {
$this->log('Start compile process');
- // Copy fonts folder
- $from = $this->assets . '/style/fonts';
- $to = 'style/fonts';
- $this->vdir->copyDirectory($from, $to);
-
- // Copy images folder
- $from = $this->assets . '/images';
- $to = 'images';
- $this->vdir->copyDirectory($from, $to);
-
- // Copy images folder
- $from = $this->assets . '/video';
- $to = 'video';
- $this->vdir->copyDirectory($from, $to);
+ // Raw copy of some directories
+ $directories = array('style/fonts', 'images', 'sound', 'video');
+ foreach ($directories as $directory) {
+ $from = $this->assets . '/' . $directory;
+ $this->vdir->copyDirectory($from, $directory);
+ }
$this->log('Copied assets');
$this->loadPlugins();
$this->log('Extras written');
$this->writeJs();
$this->log('Js written');
- $this->vdir->sync(true);
+ $this->writeSEO();
+ $this->vdir->sync($delete);
$this->log('Files Synced');
}
$pagesContents = '';
$cache = '';
- if ($this->appcache) {
- $cache = ' manifest="cache.appcache"';
- }
+
+ $beginbody = implode("\n", array_unique($this->beginBody));
$iscript = '';
if (count($this->htmlmultimedia)) {
}
}
+ $securitypolicywhitelist = implode(' ', array_unique($this->securityPolicyWhitelist));
- $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg');
+ $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'securitypolicywhitelist');
foreach ($vars as $v) {
$html = str_replace('<!-- $' . $v . ' -->', $$v, $html);
}
}
}
+ function writeSEO() {
+ foreach ($this->seoArticles as $seoArticle) {
+ $html = file_get_contents($this->assets . '/_seo.html');
+ $a = $seoArticle;
+ unset($a['image']);
+ $a['imageurl'] = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=15793&j=' . time();
+ if ($seoArticle['image']) {
+ $a['imageurl'] .= '&image=' . $seoArticle['image'];
+ }
+ $dim = getimagesize($a['imageurl']);
+ $a['imagewidth'] = $dim[0];
+ $a['imageheight'] = $dim[1];
+ foreach ($a as $k => $v) {
+ $html = str_replace('$' . $k, $v, $html);
+ }
+ $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html);
+ }
+ }
+
protected function writeScorm() {
$manifest = file_get_contents($this->assets . '/_imsmanifest.xml');
if (!$this->book->parametres->scorm_title) {
foreach ($links as $linkData) {
- if (isset($linkData['image']) && $linkData['image']) {
+ if (isset($linkData['image']) && $linkData['image'] && $linkData['type'] != 28) {
$dupData = $linkData;
$dupData['image'] = '';
$dupData['to'] = $linkData['image'];
if (in_array($linkData['type'], $ignore)) {
continue;
}
+ if ($linkData['type'] == 28) {
+ $this->addSEOArticle($linkData['page'], $linkData['to'], $linkData['extra'], $linkData['image']);
+ continue;
+ }
$link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this);
if (is_null($link)) {
continue;
return $css;
}
+ public function addSEOArticle($page, $title, $intro, $image) {
+ $this->seoArticles[$title] = ['title' => $title, 'description' => $intro, 'image' => $image, 'content' => '', 'page' => $page, 'url' => CubeIT_Text::str2URL($title) . '.html'];
+ }
+
public function _sortLinks($a, $b) {
$priorities = array(26 => 1);
$tmp = cubeFiles::tempnam();
file_put_contents($tmp, $js);
+ unlink($minimized);
+
$uglify = new CubeIT_CommandLine('/usr/local/bin/uglifyjs');
$uglify->setArg('o', $minimized);
$uglify->setArg(null, $tmp);
$uglify->execute();
$uglify->debug();
+
+ if (!file_exists($minimized)) {
+ die('An error occured while uglifying : ' . $uglify->output);
+ }
}
$dest = 'data/' . $jsfinal . '.js';
$this->vdir->copy($minimized, $dest);
}
}
$this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages);
+ $this->config->seoArticles = $this->seoArticles;
return 'var DATAS=' . json_encode($this->config) . ';' . "\n";
}
protected function writeImages() {
global $core;
+ switch ($this->book->parametres->mobileVersion) {
+ case 'html5-desktop':
+ $this->backgroundsPrefix = array('t', 'p');
+ $this->svg = true;
+ break;
+ case 'html5-images':
+ $this->backgroundsPrefix = array('t');
+ $this->svg = false;
+ break;
+ default:
+ $this->backgroundsPrefix = array('p');
+ $this->svg = true;
+ break;
+ }
+
$thumbs = array();
foreach ($this->pages as $page => $infos) {
$docdir = wsDocument::getDir($infos['document_id']);
$this->maxRes = 150;
}
}
- $this->vdir->copy(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.jpg', 'data/thumbnails/p' . $page . '.jpg');
}
$thumb = false;
}
$thumbs[$page] = $thumb;
+ $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.jpg');
if ($page == 1) {
$this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg');
foreach ($res as $k => $css) {
$this->stylesheets[] = 'data/style/style_' . $k . '.css';
$this->vdir->file_put_contents(sprintf($file, $k), implode("\n", $css));
+ $this->log('Write CSS ' . sprintf($file, $k));
}
return count($res);
}
}
-}
\ No newline at end of file
+}