From: vincent@cubedesigners.com Date: Wed, 1 Dec 2021 11:49:43 +0000 (+0000) Subject: wip #4916 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b1a73bd8cfd229b8f9ce903883f1d3307c36aebd;p=cubeextranet.git wip #4916 @2 --- diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 1e3d97865..d4b4776df 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -224,6 +224,7 @@ class wsHTML5Compiler protected $_indexVars = null; public $accessibleTexts = []; protected $_svgSymbols = []; + protected $_addedPDFJS = false; protected $_docDimensions = []; @@ -940,10 +941,10 @@ class wsHTML5Compiler $this->writeImages(); $this->log('Images written'); $this->writeCartConfig(); - $this->writeArticles(); - $this->log('Articles written'); $linksCSS = $this->writeLinks(); $this->log('Links written'); + $this->writeArticles(); + $this->log('Articles written'); $this->writeStats(); $this->log('Stats written'); $this->writeLangs(); @@ -2246,6 +2247,37 @@ height="0" width="0" style="display:none;visibility:hidden"> $this->config->content_lock = $this->content_lock; } + public function addPDFJS($force = false) + { + if ($this->_addedPDFJS) { + return; + } + + if (stripos($this->book->parametres->PDFRenderer, 'pdfjs') !== false) { + $renderer = $this->book->parametres->PDFRenderer; + } else if ($force) { + $renderer = 'pdfjs-legacy'; + } else { + return; + } + + $this->_addedPDFJS = true; + + + if ($renderer === 'pdfjs') { + $this->vdir->copyDirectory(WS_COMPILE_ASSETS . '/pdfjs', 'pdfjs'); + } else if ($renderer === 'pdfjs-legacy') { + $this->vdir->copyDirectory(WS_COMPILE_ASSETS . '/pdfjs-legacy', 'pdfjs'); + } + + $css = '.article #sidebarContainer, .article .toolbar {display:none !important;}'; + $css .= '.article .pdfViewer{padding:0 !important;}'; + $css .= '.article #viewerContainer{top:0 !important;overflow:visible !important;}'; + $css .= '.article{--page-border:0;--page-margin:0;--body-bg-color:transparent;}'; + $css .= '.openFile,.rotateCw,.rotateCcw,.rotateCcw + .horizontalToolbarSeparator{display:none !important;}' . $this->book->parametres->PDFJSCSS; + $this->vdir->file_put_contents('pdfjs/web/viewer.css', file_get_contents(WS_COMPILE_ASSETS . '/' . $renderer . '/web/viewer.css') . $css); + } + protected function writeJs() { $this->beforeWriteConfig(); @@ -2256,16 +2288,7 @@ height="0" width="0" style="display:none;visibility:hidden"> $finals = $this->jsLibs; - if ($this->book->parametres->PDFRenderer === 'pdfjs') { - $this->vdir->copyDirectory(WS_COMPILE_ASSETS . '/pdfjs', 'pdfjs'); - } else if ($this->book->parametres->PDFRenderer === 'pdfjs-legacy') { - $this->vdir->copyDirectory(WS_COMPILE_ASSETS . '/pdfjs-legacy', 'pdfjs'); - } - - if (stripos($this->book->parametres->PDFRenderer, 'pdfjs') !== false) { - $css = '.openFile,.rotateCw,.rotateCcw,.rotateCcw + .horizontalToolbarSeparator{display:none !important;}' . $this->book->parametres->PDFJSCSS; - $this->vdir->file_put_contents('pdfjs/web/viewer.css', file_get_contents(WS_COMPILE_ASSETS . '/' . $this->book->parametres->PDFRenderer . '/web/viewer.css') . $css); - } + $this->addPDFJS(); if ($this->book->parametres->scorm_enable) { $finals['scorm'] = array(); @@ -3231,131 +3254,125 @@ height="0" width="0" style="display:none;visibility:hidden"> $this->lessVariables['articles-font'] = 'OpenSans'; $list = []; - - $f = $this->book->parametres->articlesFile; - if ($f === '') { - $this->config->articlesList = $list; - return; - } - $f = $this->wdir . '/' . $f; - if (!file_exists($f)) { - $this->config->articlesList = $list; - return; + if (isset($this->config->articlesList)) { + $list = $this->config->articlesList; } - $this->addLess('articles'); - if ($this->book->parametres->articlesStyle !== 'default') { - $this->lessVariables['articles-styles'] = $this->book->parametres->articlesStyle; - } + $f = $this->book->parametres->articlesFile; + if ($f !== '' && file_exists($f = $this->wdir . '/' . $f)) { + $this->addLess('articles'); + if ($this->book->parametres->articlesStyle !== 'default') { + $this->lessVariables['articles-styles'] = $this->book->parametres->articlesStyle; + } - $this->lessVariables['articles-title-color'] = '#565657'; - $this->lessVariables['articles-font'] = $mapFonts[$this->book->parametres->articlesFont] ?? $this->book->parametres->articlesFont; - $fontPath = $this->addFontKit($this->book->parametres->articlesFont); + $this->lessVariables['articles-title-color'] = '#565657'; + $this->lessVariables['articles-font'] = $mapFonts[$this->book->parametres->articlesFont] ?? $this->book->parametres->articlesFont; + $fontPath = $this->addFontKit($this->book->parametres->articlesFont); - $svg = ' + $svg = ' '; - $x = simplexml_load_string(file_get_contents($f)); - $prevurl = ''; - foreach ($x->xpath('/articles/article') as $k => $a) { - $dir = isset($a['dir']) ? (string)$a['dir'] : null; - $url = (string)$a['url']; - $id = (string)$a['id']; - $color = (string)$a['color']; - if (!$color) { - $color = '#000'; - } + $x = simplexml_load_string(file_get_contents($f)); + foreach ($x->xpath('/articles/article') as $k => $a) { + $dir = isset($a['dir']) ? (string)$a['dir'] : null; + $url = (string)$a['url']; + $id = (string)$a['id']; + $color = (string)$a['color']; + if (!$color) { + $color = '#000'; + } - $specificStyles = '## h3, ## figure figcaption{background-color:' . $color . '}'; - $specificStyles .= '## .chapo, ## blockquote, ## a{color:' . $color . ';}'; + $specificStyles = '## h3, ## figure figcaption{background-color:' . $color . '}'; + $specificStyles .= '## .chapo, ## blockquote, ## a{color:' . $color . ';}'; - $inner = '
'; - $inner .= '
'; - if ($this->book->parametres->articlesShare && $this->book->parametres->share) { - $inner .= ''; - } - $inner .= ''; - $inner .= '
'; + $inner = '
'; + $inner .= '
'; + if ($this->book->parametres->articlesShare && $this->book->parametres->share) { + $inner .= ''; + } + $inner .= ''; + $inner .= '
'; - $inner .= '
'; + $inner .= '
'; - $title = ''; - $lead = ''; - $image = ''; + $title = ''; + $lead = ''; + $image = ''; - $first = true; + $first = true; - foreach ($a->children() as $child) { - if ($first) { - $first = false; - if ($child->getName() !== 'category') { - $inner .= '

 

'; + foreach ($a->children() as $child) { + if ($first) { + $first = false; + if ($child->getName() !== 'category') { + $inner .= '

 

'; + } } + $inner .= $this->_articleToHTML($child, $title, $lead, $image, $dir); } - $inner .= $this->_articleToHTML($child, $title, $lead, $image, $dir); - } - $inner .= '
'; + $inner .= ''; - if (!$title) { - $title = 'Article sans titre ' . $k; - } + if (!$title) { + $title = 'Article sans titre ' . $k; + } - if (!$id) { - $id = CubeIT_Text::str2URL($title); - } + if (!$id) { + $id = CubeIT_Text::str2URL($title); + } - if (!$url) { - $url = $id . '.html'; - } + if (!$url) { + $url = $id . '.html'; + } - $inner = str_replace(array('$id', '$url'), array($id, $url), $inner); + $inner = str_replace(array('$id', '$url'), array($id, $url), $inner); - $article = ['id' => $id, - 'url' => $url, - 'color' => $color, - 'contents' => '', - 'prev' => $prevurl, - 'next' => '']; + $article = ['id' => $id, + 'url' => $url, + 'color' => $color, + 'contents' => '', + 'type' => 'xml']; - if ($prevurl !== '') { - $list[count($list) - 1]['next'] = $url; - } else { - $firsturl = $url; - } + $article['contents'] = $inner; + $content = ''; + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $content .= $svg; + $content .= $inner; + $content .= ''; + $article['print'] = $content; + $list[] = $article; - $prevurl = $url; + $this->addSEOArticle('#/article/' . $article['url'], $title, $lead, $image, $article['id'], $article['url'], $inner); + } + } - $article['contents'] = $inner; - $content = ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= $svg; - $content .= $inner; - $content .= ''; - $article['print'] = $content; - $list[] = $article; - $this->addSEOArticle('#/article/' . $article['url'], $title, $lead, $image, $article['id'], $article['url'], $inner); + $nb = count($list); + foreach ($list as $k => $item) { + $nextIndex = ($k + 1) % $nb; + $prevIndex = ($k - 1 + $nb) % $nb; + $list[$k]['prev'] = $list[$prevIndex]['url']; + $list[$k]['next'] = $list[$nextIndex]['url']; } - $list[0]['prev'] = $prevurl; - $list[count($list) - 1]['next'] = $firsturl; + $idlist = []; foreach ($list as $item) { $idlist[$item['id']] = $item; } + $this->config->articlesList = $idlist; } diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 48d4e2af6..d01523392 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -76,6 +76,8 @@ class wsHTML5Link $init = wsLinks::decryptLink($init); $init = CubeIT_Util_Array::asArray($init); + $wdir = WS_BOOKS . '/' . $id . '/working/'; + $init['scorm'] = self::isScorm($init); $init['to'] = self::replaceCustomURL($init['to']); @@ -257,7 +259,11 @@ class wsHTML5Link case 35: return new textLink($id, $init, $compiler); case 36: - return new articleLink($id, $init, $compiler); + if (stripos($init['to'], '.pdf') !== false) { + return new articlePDFLink($id, $init, $compiler); + } else { + return new articleLink($id, $init, $compiler); + } case 37: return new downloadPortionLink($id, $init, $compiler); case 38: @@ -1013,7 +1019,7 @@ class htmlMultimediaPopupImage extends normalLink if ($this->read_mode) { $read = ' data-readmode="1"'; } - return $res . ' ' . $read . ' data-md5="'.md5($this->alternative).'" data-multimedia="' . rawurlencode($markup) . '" '; + return $res . ' ' . $read . ' data-md5="' . md5($this->alternative) . '" data-multimedia="' . rawurlencode($markup) . '" '; } public function keep() @@ -3052,6 +3058,44 @@ class iframeLink extends wsHTML5Link } +class articlePDFLink extends articleLink +{ + public $title = ''; + public $description = ''; + + public function init() + { + $this->compiler->addPDFJS(true); + + $e = explode('.', $this->to); + array_pop($e); + $name = implode('.', $e); + $pdffile = $this->wdir . $this->to; + + $htmlfile = $this->wdir . $name . '.html'; + if (!file_exists($htmlfile)) { + $cmd = "pdftotext -f 1 -l 1 -htmlmeta $pdffile $htmlfile"; + `$cmd`; + } + $infosfile = $this->wdir . $name . '.nfo'; + if (!file_exists($infosfile)) { + $i = `pdfinfo -f 1 -l 1 -box $pdffile`; + if (preg_match('/Page\s+1\s+size:\s+([0-9\.]+) x ([0-9\.]+)/', $i, $matches)) { + $infos = ['width' => $matches[1], 'height' => $matches[2]]; + file_put_contents($infosfile, json_encode($infos)); + } + } else { + $infos = json_decode(file_get_contents($infosfile)); + } + + $this->copyExternalFile($this->to); + $text = file_get_contents($htmlfile); + $this->article = ['page' => $this->page, 'type' => 'pdf', 'id' => $name, 'url' => $name, 'infos' => $infos, 'content' => $this->to, 'textcontent' => $text]; + $this->compiler->config->articlesList[] = $this->article; + $this->compiler->addSEOArticle('#/article/' . $name, $this->title, $this->description, '', $name, $name . '.html', $text); + } +} + class articleLink extends normalLink { protected $article; @@ -3059,6 +3103,8 @@ class articleLink extends normalLink public function init() { parent::init(); + + $this->article = $this->compiler->config->articlesList[$this->to]; if (!isset($this->compiler->config->articlesList[$this->to]['page'])) { $this->compiler->config->articlesList[$this->to]['page'] = $this->page;