]> _ Git - cubeextranet.git/commitdiff
#809
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 24 Jul 2018 16:45:11 +0000 (16:45 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 24 Jul 2018 16:45:11 +0000 (16:45 +0000)
inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php

index 957b189b3544d91ab7625449a27cbe4344ac3cfc..80cda6617e6e404cf9fa29dc1a18efd4be0fa32b 100644 (file)
@@ -2,7 +2,7 @@
 
 class wsHTML5Compiler
 {
-       protected static $resolutions = array(150, 300);
+       public static $resolutions = array(150, 300);
        public $maxRes = 300;
 
        public $jsFiles = array(
@@ -104,17 +104,17 @@ class wsHTML5Compiler
        public $pluginCSS = array();
        public $pluginJs = array();
        public $htmlmultimedia = array();
-       protected $cssX = array();
-       protected $cssY = array();
-       protected $cssWidths = array();
-       protected $pdf2htmlRatio;
-       protected $scale;
-       protected $multiply;
-       protected $div = array();
-       protected $numerotation;
-       protected $fontDocs = array();
-       protected $dir;
-       protected $z = 3;
+       public $cssX = array();
+       public $cssY = array();
+       public $cssWidths = array();
+       public $pdf2htmlRatio;
+       public $scale;
+       public $multiply;
+       public $div = array();
+       public $numerotation;
+       public $fontDocs = array();
+       public $dir;
+       public $z = 3;
        public $vdir;
        public $wdir;
 
@@ -123,51 +123,57 @@ class wsHTML5Compiler
         * @var wsBook
         */
        public $book;
-       protected $pages;
-       protected $theme;
+       public $pages;
+       public $theme;
        public $version;
        public $book_id;
-       protected $themeRoot;
+       public $themeRoot;
 
        /**
         *
         * @var wsDAOBook
         */
-       protected $daoBook;
-       protected $needToRecompileContents = true;
-       protected $needToRecompileSettings = true;
+       public $daoBook;
+       public $needToRecompileContents = true;
+       public $needToRecompileSettings = true;
        public $width;
        public $height;
-       protected $cssWidth;
-       protected $cssHeight;
-       protected $cssOneWidth;
-       protected $cssOneHeight;
-       protected $cssScale;
-       protected $cssSVGScale;
-       protected $optimalWidth = 567;
-       protected $optimalHeight = 709;
-       protected $additionalConfig = array();
-       protected $fontScale = 1;
-       protected $cache = array();
-       protected $backgroundsPrefix = array();
-       protected $svg = true;
-       protected $config = array();
-       protected $assets = '';
-       protected $phonegap = false;
-       protected $phonegapVersion;
-       protected $standalone = false;
-       protected $hiddenContents = array();
-       protected $appcache;
-       protected $home;
-       protected $widget = true;
-       protected $multiApp = false;
-       protected $pageLabels = array();
-       protected $stylesheets = array();
-       protected $logfp = null;
-       protected $logtime = null;
-       protected $beginBody = array();
-       protected $seoArticles = [];
-       protected $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com'];
+       public $cssWidth;
+       public $cssHeight;
+       public $cssOneWidth;
+       public $cssOneHeight;
+       public $cssScale;
+       public $cssSVGScale;
+       public $optimalWidth = 567;
+       public $optimalHeight = 709;
+       public $additionalConfig = array();
+       public $fontScale = 1;
+       public $cache = array();
+       public $backgroundsPrefix = array();
+       public $svg = true;
+       public $config = array();
+       public $assets = '';
+       public $phonegap = false;
+       public $phonegapVersion;
+       public $standalone = false;
+       public $hiddenContents = array();
+       public $appcache;
+       public $home;
+       public $widget = true;
+       public $multiApp = false;
+       public $pageLabels = array();
+       public $stylesheets = array();
+       public $logfp = null;
+       public $logtime = null;
+       public $beginBody = array();
+       public $seoArticles = [];
+       public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com'];
+
+       public $_signature;
+       /**
+        * @var wsHTML5Seo
+        */
+       public $seo = null;
 
 
        function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false)
@@ -363,8 +369,16 @@ class wsHTML5Compiler
                $this->log('CSS written');
                $this->writeLangs();
                $this->log('Langs written');
+               $this->writeSEO();
+               $this->log('SEO written');
                $this->writeIndex();
                $this->log('Index written');
+               if ($this->book->parametres->scorm_enable) {
+                       $this->writeScorm();
+                       $this->log('SCORM written');
+               }
+               $this->writeWidget();
+               $this->log('Widget written');
                $this->writeSounds();
                $this->log('Sound written');
                $this->writeTexts();
@@ -373,7 +387,6 @@ class wsHTML5Compiler
                $this->log('Extras written');
                $this->writeJs();
                $this->log('Js written');
-               $this->writeSEO();
                $this->vdir->sync($delete);
                $this->log('Files Synced');
        }
@@ -420,15 +433,6 @@ class wsHTML5Compiler
        public function getVideosFormats($poster = true)
        {
                $res = [];
-               //
-               //        if (!$this->phonegap) {
-               //                      $res = array('ogv', 'webm', 'mp4', 'flv');
-               //              } elseif ($this->phonegap == 'ios') {
-               //                      $res = array('mp4');
-               //              } else if ($this->phonegap == 'android') {
-               //                      $res = array('webm', 'mp4');
-               //              }
-
                $res[] = 'mp4';
 
                if ($poster) {
@@ -479,47 +483,31 @@ class wsHTML5Compiler
                $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds');
        }
 
-       protected function writeIndex()
+       protected function _writeIndex($page)
        {
                global $core;
 
-               $html = file_get_contents($this->assets . '/_index.html');
-               $uhtml = $html;
+               $seo = $this->seo->pages[$page];
+               $html = $seo->getHTML();
 
                $titre = $this->book->parametres->title;
 
 
+               if (null === $this->_signature) {
                $daoSignature = new wsDAOSignature($core->con);
-               $signature = $daoSignature->selectById($this->book->parametres->signature);
-
-               $exportSignature = array('main' => $signature->main,
-                       'mainLink' => $signature->mainLink,
-                       'partner' => $signature->partner,
-                       'partnerLink' => $signature->partnerLink);
+                       $this->_signature = $daoSignature->selectById($this->book->parametres->signature);
+               }
 
                $credits = '';
-               if ($signature->partner != '') {
-                       $credits = '<a href="' . $signature->partnerLink . '" target="_blank">' . $signature->partner . '</a> ';
+               if ($this->_signature->partner != '') {
+                       $credits = '<a href="' . $this->_signature->partnerLink . '" target="_blank">' . $this->_signature->partner . '</a> ';
                }
-               $credits .= '<a href="' . $signature->mainLink . '" target="_blank">' . $signature->main . '</a>';
+               $credits .= '<a href="' . $this->_signature->mainLink . '" target="_blank">' . $this->_signature->main . '</a>';
 
                $hiddenContents = implode("\n", $this->hiddenContents);
 
                $bgcolor = $this->theme->parametres->loadingBackColor;
 
-               // Google analytics
-               $ga = '';
-               if ($this->book->parametres->googleAnalytics != '') {
-                       $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics);
-               }
-               if ($this->book->parametres->googleAnalyticsCustom != '') {
-                       $ga .= $this->book->parametres->googleAnalyticsCustom;
-               }
-
-               $statsfooter = '';
-               if ($this->book->parametres->statsCustom != '') {
-                       $statsfooter = $this->book->parametres->statsCustom;
-               }
                // Feuilles de style
                $sheets = array_merge($this->stylesheets, $this->specialCSS);
 
@@ -542,12 +530,11 @@ class wsHTML5Compiler
                        $iscript .= '</script>' . "\n";
                }
 
-               $script = '';
+               $script = '<script type="text/javascript">var FLUIDBOOK_START_PAGE="' . $page . '";</script>' . "\n";
                $script .= '<script type="text/javascript" charset="utf-8" src="data/datas.js"></script>' . "\n";
                $script .= '<script type="text/javascript" charset="utf-8" src="data/fluidbook.js"></script>' . "\n";
                if ($this->book->parametres->scorm_enable) {
                        $script .= '<script type="text/javascript" charset="utf-8" src="data/scorm.js"></script>' . "\n";
-                       $this->writeScorm();
                }
                if (count($this->specialJsFiles)) {
                        $script .= '<script type="text/javascript" charset="utf-8" src="data/special.js"></script>' . "\n";
@@ -556,11 +543,10 @@ class wsHTML5Compiler
                        $script .= '<script type="text/javascript" charset="utf-8" src="' . $p . '"></script>' . "\n";
                }
                $script .= $iscript;
-               $description = '<meta name="description" content="' . html::escapeHTML(isset($this->book->parametres->seoDescription) && $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $titre . ' - Powered by Fluidbook') . '">';
 
                $socialTitle = $this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre;
                $socialDescription = $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $this->book->parametres->seoDescription;
-               $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book_id . '&j=' . time();
+               $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book_id . '&j=' . TIME;
                $dim = CubeIT_Image::getimagesize($socialImage);
                $socialImageWidth = $dim[0];
                $socialImageHeight = $dim[1];
@@ -635,7 +621,7 @@ class wsHTML5Compiler
                if ($this->phonegap) {
                        $csp = "<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self' data: gap: 'unsafe-inline' *; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' " . implode(' ', array_unique($this->securityPolicyWhitelist)) . "; img-src * data:\">";
                }
-               $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard');
+               $vars = array('credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard');
                foreach ($vars as $v) {
                        if (isset($$v)) {
                                $html = str_replace('<!-- $' . $v . ' -->', $$v, $html);
@@ -644,45 +630,21 @@ class wsHTML5Compiler
                        }
                }
 
-               $scripts = array();
-               foreach ($this->debugJsFiles as $js) {
-                       $scripts[] = '<script type="text/javascript" charset="utf-8" src="' . $js . '"></script>';
-               }
-               foreach ($this->jsFiles as $js) {
-                       $scripts[] = '<script type="text/javascript" charset="utf-8" src="' . $js . '"></script>';
+               $seo->writePage($html, $this->vdir);
+               if ($page == 1) {
+                       $seo->writePage($html, $this->vdir, 'index.html');
                }
-               foreach ($this->pluginJs as $js) {
-                       $scripts[] = '<script type="text/javascript" charset="utf-8" src="' . $js . '"></script>';
                }
 
-               $scripts[] = '<script type="text/javascript" charset="utf-8" src="data/datas.js"></script>';
-               $scripts[] = $iscript;
-               $script = implode("\n\t\t", $scripts);
-
-               $scripts = array();
-               foreach ($this->testJsFiles as $js) {
-                       $scripts[] = '<script type="text/javascript" charset="utf-8" src="' . $js . '"></script>';
-               }
-               $scripts[] = '<script type="text/javascript" charset="utf-8" src="data/datas.js"></script>';
-               $script_test = implode("\n\t\t", $scripts);
-
-               $thtml = $uhtml;
-
-               $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon');
-               foreach ($vars as $v) {
-                       $uhtml = str_replace('<!-- $' . $v . ' -->', $$v, $uhtml);
+       protected function writeIndex()
+       {
+               foreach ($this->pages as $page => $infos) {
+                       $this->_writeIndex($page);
                }
-
-               $script .= "\n\t\t" . '<script type="text/javascript" charset="utf-8">window.tester = true;</script>';
-               $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message');
-               foreach ($vars as $v) {
-                       $thtml = str_replace('<!-- $' . $v . ' -->', $$v, $thtml);
                }
 
-               $this->vdir->file_put_contents('index.html', $html);
-               $this->vdir->file_put_contents('indexu.html', $uhtml);
-               $this->vdir->file_put_contents('indext.html', $thtml);
-
+       protected function writeWidget()
+       {
                // Write widget html
                if ($this->widget) {
                        $whtml = file_get_contents($this->assets . '/widget.html');
@@ -716,6 +678,7 @@ class wsHTML5Compiler
                        }
                        $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html);
                }
+               $this->seo = new wsHTML5Seo($this);
        }
 
        protected function writeScorm()
@@ -766,7 +729,10 @@ class wsHTML5Compiler
                        return;
                }
 
-               $this->vdir->copy(WS_BOOKS . '/final/' . $this->book->book_id . '/data/' . $this->book->parametres->pdfName, 'data/' . $this->book->parametres->pdfName);
+               $res = wsUtil::compilePDF($this->book, $this->pages);
+               if ($res !== false) {
+                       $this->vdir->copy($res, 'data/' . $this->book->parametres->pdfName);
+               }
                return '';
        }
 
@@ -1113,13 +1079,9 @@ class wsHTML5Compiler
                        $this->vdir->copy($minimized, $dest);
                }
 
-               $this->vdir->copyDirectory($this->assets . '/js/3dflip', 'js/3dflip');
-
-
                if ($this->phonegap) {
                        $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js');
                }
-
        }
 
        public function writeTexts()
@@ -1198,6 +1160,7 @@ class wsHTML5Compiler
                        switch ($this->config->basketManager) {
                                case 'Remarkable':
                                        $this->addJs('js/libs/parsley.min.js');
+                                       $this->addJs('js/libs/jquery/jquery.cookie.js');
                                        $this->addJs('js/libs/fluidbook/cart/fluidbook.cart.remarkable.js');
                                        break;
                                default:
@@ -1859,7 +1822,7 @@ class wsHTML5Compiler
                $res = array('width' => 0, 'height' => 0);
                if (file_exists($d . '/index.html')) {
                        $doc = new DOMDocument();
-                       $doc->loadHTMLFile($d . '/index.html');
+                       @$doc->loadHTMLFile($d . '/index.html');
                        $xpath = new DOMXPath($doc);
                        $c = $xpath->query("//canvas");
                        foreach ($c as $canvas) {