From: vincent@cubedesigners.com Date: Wed, 23 Aug 2017 16:35:16 +0000 (+0000) Subject: #811 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5720521d061e684dc5d1397143bb1d62bd861fea;p=cubeextranet.git #811 --- diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 8f86c0fb2..550db6385 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -925,6 +925,33 @@ class wsDAOBook extends commonDAO { CubeIT_Util_Gzip::file_put_contents($ifilec, $index); } + public function makeHighlightIndex($book, $pages) { + $jar = WS_TOOLS . '/fwstk/out/artifacts/fwstk_jar/fwstk.jar'; + + + $daoDoc = new wsDAODocument($this->con); + $res = array(); + foreach ($pages as $book_page => $infos) { + $fby = wsDocument::getDir($infos['document_id']) . 'html/p' . $infos['document_page'] . '.fby'; + // Refresh highlight data if fby file doesn't exists or if fwstk has been updated + if (!file_exists($fby) || filemtime($jar) > filemtime($fby)) { + $doc = $daoDoc->selectById($infos['document_id']); + $doc->getHighlightTextsData(); + } + $words = CubeIT_Util_Json::decode(file_get_contents($fby), CubeIT_Util_Json::TYPE_ARRAY); + foreach ($words as $w) { + $word = $w['word']; + unset($w['word']); + $w['page'] = $book_page; + if (!isset($res[$word])) { + $res[$word] = array(); + } + $res[$word][] = $w; + } + } + return $res; + } + protected function _escapeIndex($str) { $todelete = array('\ufffd'); foreach ($todelete as $d) { diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 9b72771c2..8077d9f6c 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -80,6 +80,4 @@ class wsBook extends cubeMetier { return $this->$varname; } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index b032c1ed9..0aaebbef6 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -361,15 +361,17 @@ class wsDocument extends cubeMetier { $fwstk->setArg('--threads 1'); $fwstk->execute(); $this->addToLog($fwstk); + } - /* $fwstk = new cubeCommandLine('fwstk'); - $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->cropped); - $fwstk->setArg('--layout ' . $this->html . 'p%d.layout'); - $fwstk->setArg('--cmaps ' . $this->html); - $fwstk->setArg('--fonts' . $this->out . 'fonts/web/'); - $fwstk->execute(); - $this->addToLog($fwstk); */ + public function getHighlightTextsData(){ + $fwstk = new cubeCommandLine('fwstk.sh'); + $fwstk->setPath(CONVERTER_PATH); + $fwstk->setArg('--input ' . $this->cropped); + $fwstk->setArg('--layout ' . $this->html . 'p%d.fby'); + $fwstk->setArg('--cmaps ' . $this->html); + $fwstk->setArg('--fonts' . $this->out . 'fonts/web/'); + $fwstk->execute(); + $this->addToLog($fwstk); } public function getResolutionRatio() { @@ -617,10 +619,10 @@ class wsDocument extends cubeMetier { $this->_cleanSVG($svgFile, $page); } - public static function cleanSVG($svgFile,$debug=false) { + public static function cleanSVG($svgFile, $debug = false) { $svg = new DOMDocument(); $svg->preserveWhiteSpace = false; - $svg->load($svgFile,LIBXML_PARSEHUGE); + $svg->load($svgFile, LIBXML_PARSEHUGE); // Operations to delete $xpath = new DOMXPath($svg); 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 e9f8fdc22..871a2ff12 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -979,6 +979,7 @@ class wsHTML5Compiler { file_put_contents($this->vdir . '/data/search.index.js', $jsindex); file_put_contents($this->vdir . '/data/search.texts.js', $jstexts); + file_put_contents($this->vdir . '/data/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r"); } public function supportSVG() {