]> _ Git - cubeextranet.git/commitdiff
wip #1799 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 17 Nov 2017 17:28:24 +0000 (17:28 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 17 Nov 2017 17:28:24 +0000 (17:28 +0000)
inc/ws/Controlleur/class.ws.services.php
inc/ws/Util/html5/socialarticles/class.ws.html5.compiler.php

index 3ae59698d95a5cc13bfccf7993802f9ec1de6194..a693c5c1fc0e802b0e8f8228ccfc3a0c7275373b 100644 (file)
@@ -169,48 +169,53 @@ class wsServices extends cubeFlashGateway {
 
                $book = $dao->selectById($this->args['id']);
 
-               if (isset($book->parametres->facebook_image) && $book->parametres->facebook_image != '') {
-                       $c = WS_BOOKS . '/working/' . $this->args['id'] . '/' . $book->parametres->facebook_image;
-                       if (file_exists($c)) {
-                               $cover = $c;
-                       }
-               }
-               if ($book->parametres->pdfThumbnails) {
-                       $pdf = wsDAOBook::getWorkingFile($book->parametres->pdfThumbnails, $book->book_id);
+               if (isset($this->args['image'])) {
+                       $cover = WS_BOOKS . '/working/' . $this->args['id'] . '/' . $this->args['image'];
+               } else {
 
-                       if (file_exists($pdf)) {
-                               $dir = WS_CACHE . '/thumbs/' . sha1($pdf) . '/';
-                               if (!file_exists($dir)) {
-                                       mkdir($dir, 0777, true);
+                       if (isset($book->parametres->facebook_image) && $book->parametres->facebook_image != '') {
+                               $c = WS_BOOKS . '/working/' . $this->args['id'] . '/' . $book->parametres->facebook_image;
+                               if (file_exists($c)) {
+                                       $cover = $c;
                                }
-                               $jpeg = $dir . '/cover.jpg';
-                               $mtime = filemtime($jpeg);
+                       }
+                       if ($book->parametres->pdfThumbnails) {
+                               $pdf = wsDAOBook::getWorkingFile($book->parametres->pdfThumbnails, $book->book_id);
+
+                               if (file_exists($pdf)) {
+                                       $dir = WS_CACHE . '/thumbs/' . sha1($pdf) . '/';
+                                       if (!file_exists($dir)) {
+                                               mkdir($dir, 0777, true);
+                                       }
+                                       $jpeg = $dir . '/cover.jpg';
+                                       $mtime = filemtime($jpeg);
 
-                               if (!file_exists($jpeg) || $mtime < filemtime(__FILE__) || $mtime < filemtime($pdf)) {
-                                       wsPDFConvert::makeShot($pdf, $jpeg, 1, '', 150, 90, 4, 'PNM', 1200, -1);
+                                       if (!file_exists($jpeg) || $mtime < filemtime(__FILE__) || $mtime < filemtime($pdf)) {
+                                               wsPDFConvert::makeShot($pdf, $jpeg, 1, '', 150, 90, 4, 'PNM', 1200, -1);
+                                       }
+                                       $cover = $jpeg;
                                }
-                               $cover = $jpeg;
                        }
-               }
 
-               if (!isset($cover)) {
-                       $pages = $dao->getPagesOfBook($this->args['id']);
-                       $dir = wsDocument::getDir($pages[1]['document_id']);
-                       $cover = $dir . '/html/t150-' . $pages[1]['document_page'] . '.jpg';
-                       if (!file_exists($cover)) {
-                               $cover = $dir . '/p' . $pages[1]['document_page'] . '.jpg';
-                       }
-                       $i = WS_FILES . '/cover/' . $this->args['id'] . '.jpg';
+                       if (!isset($cover)) {
+                               $pages = $dao->getPagesOfBook($this->args['id']);
+                               $dir = wsDocument::getDir($pages[1]['document_id']);
+                               $cover = $dir . '/html/t150-' . $pages[1]['document_page'] . '.jpg';
+                               if (!file_exists($cover)) {
+                                       $cover = $dir . '/p' . $pages[1]['document_page'] . '.jpg';
+                               }
+                               $i = WS_FILES . '/cover/' . $this->args['id'] . '.jpg';
 
-                       if (!file_exists($i) || filemtime(__FILE__) > filemtime($i) || filemtime($cover) > filemtime($i)) {
-                               $it = new imageTools();
-                               $it->loadImage($cover);
+                               if (!file_exists($i) || filemtime(__FILE__) > filemtime($i) || filemtime($cover) > filemtime($i)) {
+                                       $it = new imageTools();
+                                       $it->loadImage($cover);
 
-                               $it->resize(1200, 1000000, 'ratio', false);
-                               $it->output('jpeg', $i, 85);
-                               $it->close();
+                                       $it->resize(1200, 1000000, 'ratio', false);
+                                       $it->output('jpeg', $i, 85);
+                                       $it->close();
+                               }
+                               $cover = $i;
                        }
-                       $cover = $i;
                }
 
 
index bdf3e605a1ace02e53acdf98fc68cc00905b75eb..7465e3ad7e8d225086180941b09ca96a98519c13 100644 (file)
@@ -156,6 +156,7 @@ class wsHTML5Compiler {
        protected $stylesheets = array();
        protected $logfp = null;
        protected $logtime = null;
+       protected $seoArticles = [];
 
 
        function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) {
@@ -324,6 +325,7 @@ class wsHTML5Compiler {
                $this->log('Extras written');
                $this->writeJs();
                $this->log('Js written');
+               $this->writeSEO();
                $this->vdir->sync($delete);
                $this->log('Files Synced');
        }
@@ -590,6 +592,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 +774,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 +794,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 +851,10 @@ class wsHTML5Compiler {
                return $css;
        }
 
+       public function addSEOArticle($page, $title, $intro, $image) {
+               $this->seoArticles[] = ['title' => $title, 'description' => $intro, 'image' => $image, 'content' => '', 'page' => $page, 'url' => CubeIT_Text::str2URL($title) . '.html'];
+       }
+
        public function _sortLinks($a, $b) {
                $priorities = array(26 => 1);