From 925f4dc15c6c7bece0637181b06a89014a1fbe29 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 17 Nov 2017 17:28:24 +0000 Subject: [PATCH] wip #1799 @1.5 --- inc/ws/Controlleur/class.ws.services.php | 71 ++++++++++--------- .../class.ws.html5.compiler.php | 31 +++++++- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 3ae59698d..a693c5c1f 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -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; } diff --git a/inc/ws/Util/html5/socialarticles/class.ws.html5.compiler.php b/inc/ws/Util/html5/socialarticles/class.ws.html5.compiler.php index bdf3e605a..7465e3ad7 100644 --- a/inc/ws/Util/html5/socialarticles/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/socialarticles/class.ws.html5.compiler.php @@ -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); -- 2.39.5