From 5aab08603e966fc4337284743cb271e5fc94aff9 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 19 Mar 2012 09:12:17 +0000 Subject: [PATCH] --- inc/ws/DAO/class.ws.dao.book.php | 50 ++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 7cab8b482..aeec00571 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -35,7 +35,9 @@ class wsDAOBook extends commonDAO { $book->facturable = $r->facturable; $book->facturable_id = $r->facturable_id; $book->tache = $r->tache; - $book->projet = $r->projet; + if (isset($r->projet)) { + $book->projet = $r->projet; + } $book->version = $r->version; $book->composition_update = $r->composition_update; $book->dir_references = $r->dir_references; @@ -79,7 +81,7 @@ class wsDAOBook extends commonDAO { return $this->cree(); } $sql = 'SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1'; - $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1'); + $r = $this->con->select($sql); return $this->singleton($r); } @@ -410,8 +412,18 @@ class wsDAOBook extends commonDAO { } public function setChapters($book_id, $json) { + $chapters = json_decode($json,TRUE); + $res = array(); + + foreach ($chapters as $c) { + $c['label'] = trim($c['label']); + $n = (string) $c['page']; + $c['label'] = trim(preg_replace('|' . $n . '$|', '', $c['label'])); + $res[] = $c; + } + $c = $this->con->openCursor('books'); - $c->chapters = json_encode(json_decode($json, false)); + $c->chapters = json_encode($res); $c->changedate = TIME; $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } @@ -648,6 +660,23 @@ class wsDAOBook extends commonDAO { public function makeTextsIndexes($book, $pages, &$index, &$textes) { + $dir = WS_BOOKS . '/index/' . $book->book_id; + if ($book->parametres->ignoreSearchSeparators != '') { + $dir.='/' . sha1($book->parametres->ignoreSearchSeparators); + } + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + + $ifilec = $dir . '/index.json'; + $tfilec = $dir . '/textes.json'; + + if (file_exists($ifilec) && file_exists($tfilec) && (min(filemtime($ifilec), filemtime($tfilec)) >= $book->composition_update)) { + $index = file_get_contents($ifilec); + $textes = file_get_contents($tfilec); + return; + } + if ($book->parametres->ignoreSearchSeparators != "") { $docs = array(); foreach ($pages as $p => $i) { @@ -679,6 +708,13 @@ class wsDAOBook extends commonDAO { $textes[$book_page] = $text; } ksort($index); + + + $textes = json_encode($textes); + $index = json_encode($index); + + file_put_contents($tfilec, $textes); + file_put_contents($ifilec, $index); } protected function fillIndexWithWords(&$index, $page, $ipage) { @@ -690,7 +726,11 @@ class wsDAOBook extends commonDAO { continue; } list($woa, $worddata) = $w1; - list($total, $wordslist) = explode("\t", $worddata, 2); + $e = explode("\t", $worddata, 2); + if (count($e) < 2) { + continue; + } + list($total, $wordslist) = $e; if ($woa == '') { continue; @@ -738,7 +778,7 @@ class wsDAOBook extends commonDAO { $packager->makePackage(false); } - public function compile3($book_id, $complete) { + public function compile3($book_id, $complete, &$book) { $res = ''; $compilerDir = WS_BOOKS . '/datasCompiler/' . $book_id . '/'; -- 2.39.5