]> _ Git - cubeextranet.git/commitdiff
#1802 #1799
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 21 Nov 2017 13:55:15 +0000 (13:55 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 21 Nov 2017 13:55:15 +0000 (13:55 +0000)
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php

index bdf3e605a1ace02e53acdf98fc68cc00905b75eb..eb3e27e50dc0948b8698776dff5263b4dbd9fc46 100644 (file)
@@ -156,6 +156,9 @@ 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) {
@@ -259,6 +262,25 @@ 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;
        }
@@ -324,6 +346,7 @@ class wsHTML5Compiler {
                $this->log('Extras written');
                $this->writeJs();
                $this->log('Js written');
+               $this->writeSEO();
                $this->vdir->sync($delete);
                $this->log('Files Synced');
        }
@@ -474,9 +497,8 @@ class wsHTML5Compiler {
                $pagesContents = '';
 
                $cache = '';
-               if ($this->appcache) {
-                       $cache = ' manifest="cache.appcache"';
-               }
+
+               $beginbody = implode("\n", array_unique($this->beginBody));
 
                $iscript = '';
                if (count($this->htmlmultimedia)) {
@@ -530,8 +552,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);
                }
@@ -590,6 +613,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) {
@@ -753,7 +795,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'];
@@ -773,6 +815,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;
@@ -826,6 +872,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);
 
@@ -1007,6 +1057,7 @@ class wsHTML5Compiler {
                        }
                }
                $this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages);
+               $this->config->seoArticles = $this->seoArticles;
 
                return 'var DATAS=' . json_encode($this->config) . ';' . "\n";
        }
index 76305d856971a5b8d9b8dbce2e9411d6621b3ad0..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;