]> _ Git - cubeextranet.git/commitdiff
#1807
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 22 Nov 2017 14:38:03 +0000 (14:38 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 22 Nov 2017 14:38:03 +0000 (14:38 +0000)
inc/ws/Util/html5/centerbook/class.ws.html5.compiler.php
inc/ws/Util/html5/centerbook/class.ws.html5.links.php

index 0be865da8c409cc75a29129881e44c819341b258..e7924bca2fbc4a80e376adbb6a91d3d4384be04c 100644 (file)
@@ -2,7 +2,7 @@
 
 class wsHTML5Compiler {
        protected static $resolutions = array(150, 300);
-       protected $maxRes = 300;
+       public $maxRes = 300;
 
        public $jsFiles = array(
                'js/libs/modernizr/modernizr.min.js',
@@ -81,7 +81,7 @@ class wsHTML5Compiler {
                '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'
        );
@@ -157,12 +157,14 @@ class wsHTML5Compiler {
        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;
@@ -202,20 +204,6 @@ class wsHTML5Compiler {
                $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);
@@ -252,11 +240,14 @@ class wsHTML5Compiler {
                }
                $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) {
@@ -272,12 +263,37 @@ class wsHTML5Compiler {
                $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);
                }
@@ -299,24 +315,16 @@ class wsHTML5Compiler {
                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();
@@ -339,7 +347,8 @@ class wsHTML5Compiler {
                $this->log('Extras written');
                $this->writeJs();
                $this->log('Js written');
-               $this->vdir->sync(true);
+               $this->writeSEO();
+               $this->vdir->sync($delete);
                $this->log('Files Synced');
        }
 
@@ -489,9 +498,8 @@ class wsHTML5Compiler {
                $pagesContents = '';
 
                $cache = '';
-               if ($this->appcache) {
-                       $cache = ' manifest="cache.appcache"';
-               }
+
+               $beginbody = implode("\n", array_unique($this->beginBody));
 
                $iscript = '';
                if (count($this->htmlmultimedia)) {
@@ -545,8 +553,9 @@ class wsHTML5Compiler {
                        }
                }
 
+               $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);
                }
@@ -605,6 +614,25 @@ class wsHTML5Compiler {
                }
        }
 
+       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) {
@@ -768,7 +796,7 @@ class wsHTML5Compiler {
 
 
                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'];
@@ -788,6 +816,10 @@ class wsHTML5Compiler {
                        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;
@@ -841,6 +873,10 @@ class wsHTML5Compiler {
                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);
 
@@ -920,11 +956,17 @@ class wsHTML5Compiler {
                                $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);
@@ -1016,6 +1058,7 @@ class wsHTML5Compiler {
                        }
                }
                $this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages);
+               $this->config->seoArticles = $this->seoArticles;
 
                return 'var DATAS=' . json_encode($this->config) . ';' . "\n";
        }
@@ -1063,6 +1106,21 @@ class wsHTML5Compiler {
        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']);
@@ -1095,7 +1153,6 @@ class wsHTML5Compiler {
                                                $this->maxRes = 150;
                                        }
                                }
-                               $this->vdir->copy(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.jpg', 'data/thumbnails/p' . $page . '.jpg');
                        }
 
                        $thumb = false;
@@ -1107,6 +1164,7 @@ class wsHTML5Compiler {
                        }
 
                        $thumbs[$page] = $thumb;
+                       $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.jpg');
 
                        if ($page == 1) {
                                $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg');
@@ -1371,6 +1429,7 @@ class wsHTML5Compiler {
                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);
        }
@@ -1555,4 +1614,4 @@ class wsHTML5Compiler {
 
        }
 
-}
\ No newline at end of file
+}
index 86f1633a657db997896b02103b8f3254c568b7d0..ab2fc24cfe3c4509185df876f5d6213e661cabf3 100644 (file)
@@ -128,6 +128,9 @@ class wsHTML5Link {
                        case 27:
                                return new eventOverlayLink($id, $init, $compiler);
                                break;
+                       case 29:
+                               return new facebookLikeLink($id, $init, $compiler);
+                               break;
                        default:
                                return null;
                }
@@ -750,12 +753,18 @@ class actionLink extends internalLink {
        }
 
        public function getAdditionnalContent() {
+               $res = parent::getAdditionnalContent();
+               if ($this->extra) {
+                       $res .= ' data-extra="' . $this->extra . '"';
+               }
+
                if (in_array($this->to, $this->_share)) {
-                       return parent::getAdditionnalContent() . ' data-service="' . $this->to . '" ';
+                       $res .= ' data-service="' . $this->to . '" ';
                } else {
-                       return /*parent::getClasses()*/
+                       $res .= /*parent::getClasses()*/
                                ' data-action="' . $this->to . '" ';
                }
+               return $res;
        }
 
        public function getDefaultTooltip() {
@@ -810,6 +819,13 @@ class fileLink extends normalLink {
 
 }
 
+class facebookLikeLink extends wsHTML5Link {
+       public function getHTMLContent() {
+               $this->compiler->addFacebookSDK();
+               return '<div class="fb-like" data-href="' . $this->to . '" data-layout="standard" data-action="like"  data-size="large" data-show-faces="false" data-share="false"></div>';
+       }
+}
+
 class htmlMultimediaLink extends wsHTML5Link {
 
        protected $_config = null;
@@ -1307,4 +1323,4 @@ class zoomLink extends normalLink {
        public function getClasses() {
                return array_merge(['zoomPopup'], parent::getClasses());
        }
-}
\ No newline at end of file
+}