From: vincent@cubedesigners.com Date: Sat, 16 Jul 2011 01:01:57 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ec63e9cafaf9a0972b6c80b4507bb1a03ced4203;p=cubeextranet.git --- diff --git a/fluidbook/icones/1/mobile/nav-facebook.svg b/fluidbook/icones/1/mobile/nav-facebook.svg new file mode 100644 index 000000000..c2d1399ac --- /dev/null +++ b/fluidbook/icones/1/mobile/nav-facebook.svg @@ -0,0 +1,11 @@ + + + + + + diff --git a/fluidbook/icones/1/mobile/nav-twitter.svg b/fluidbook/icones/1/mobile/nav-twitter.svg new file mode 100644 index 000000000..97bcabe54 --- /dev/null +++ b/fluidbook/icones/1/mobile/nav-twitter.svg @@ -0,0 +1,15 @@ + + + + + + diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 6a5fc513a..4c2ff41e3 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -374,7 +374,8 @@ class commonCore extends cubeCore { $db->books->numerotation('text', 0, false); $db->books->changedate('integer', 0, false); $db->books->compiledate('integer', 0, false); - $db->books->version('integer',0,false,2); + $db->books->version('integer', 0, false, 2); + $db->books->composition_update('integer', 0, false); // Clés $db->books->primary('pk_books', 'book_id'); $db->books->index('index_books_nom', 'BTREE', 'nom'); diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 7694bbca0..780b0c8dc 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -1,16 +1,16 @@ con, $args); } - public function sendEmail() - { + public function sendEmail() { // Check protection hash $hash = md5(substr($this->args['fromemail'], 2, 6) . substr($this->args['email'], 3, 5) . 'SFGHF566!S' . $this->args['id']); if ($hash != $this->args['hash']) { @@ -27,17 +27,16 @@ class wsServices extends cubeFlashGateway { $mail->to = $this->args['email']; $mail->from = $this->args['fromname'] . '<' . $this->args['fromemail'] . '>'; $mail->subject = $this->args['subject']; - /*if ($this->args['attachPDFInEmail'] == '1') { - $doc_name = isset($this->args['attachmentName'])?$this->args['attachmentName']:'document.pdf'; - $file = fwsConverter::extractPages($this->args['id'], $this->args['attachPDFInEmail'], false); - $mail->addFile($doc_name, $file); - }*/ + /* if ($this->args['attachPDFInEmail'] == '1') { + $doc_name = isset($this->args['attachmentName'])?$this->args['attachmentName']:'document.pdf'; + $file = fwsConverter::extractPages($this->args['id'], $this->args['attachPDFInEmail'], false); + $mail->addFile($doc_name, $file); + } */ $mail->body = $this->args['body']; - $this->xml->addChild('ok', $mail->send()?'1':'0'); + $this->xml->addChild('ok', $mail->send() ? '1' : '0'); } - protected function shortenURL($url, $id) - { + protected function shortenURL($url, $id) { $bitLyUser = 'fluidbook'; $bitLyKey = 'R_3858dd1c9884d5c6a5fe386d7e95cf1d'; // Recherche dans le cache @@ -66,8 +65,7 @@ class wsServices extends cubeFlashGateway { * * @return */ - public function facebook_thumbnail() - { + public function facebook_thumbnail() { $this->outputXML = false; $dao = new wsDAOBook($this->con); $pages = $dao->getPagesOfBook($this->args['id']); @@ -94,24 +92,82 @@ class wsServices extends cubeFlashGateway { exit; } - public function facebookShare() - { + public function facebookShare() { http::redirect('http://www.facebook.com/sharer/sharer.php?u=' . urlencode($this->args['url'])); exit; } - public function twitterShare() - { + public function twitterShare() { $url = $this->shortenURL($this->args['url'], $this->args['id']); + $post = str_replace('%short%', $url, $this->args['post']); $post = rawurlencode($post); - http::redirect('http://twitter.com/?status=' . $post); + http::redirect('http://twitter.com/intent/tweet?source=webclient&text=' . $post); exit; } - public function exportpdf() - { + public function searchHints() { + $index = Zend_Search_Lucene::open(WS_BOOKS . '/search/' . $this->args['id']); + + $charsLimit = 2; + + $terms = $this->getTerms($this->args['term']); + $term = array_pop($terms); + + if (strlen($term) < $charsLimit) { + $this->xml->addChild('hints', '{}'); + return; + } + + $term = new Zend_Search_Lucene_Index_Term($term . '*', 'contents'); + $query = new Zend_Search_Lucene_Search_Query_Wildcard($term); + $query->setMinPrefixLength($charsLimit); + + $index->find($query); + $terms = $query->getQueryTerms(); + $res = array(); + foreach ($terms as $t) { + $res[$t->text] = array_sum($index->termFreqs($t)); + } + arsort($res); + $res = array_slice($res, 0, 10, true); + $this->xml->addChild('hints', json_encode($res)); + } + + public function searchResults() { + $index = Zend_Search_Lucene::open(WS_BOOKS . '/search/' . $this->args['id']); + + $terms = $this->getTerms($this->args['term']); + + $query = new Zend_Search_Lucene_Search_Query_MultiTerm(); + foreach ($terms as $term) { + $query->addTerm(new Zend_Search_Lucene_Index_Term($term, 'contents'), null); + } + + $hits = $index->find($query); + $res = array(); + foreach ($query->getQueryTerms() as $t) { + foreach ($index->termFreqs($t) as $doc_id => $f) { + $page = trim($index->getDocument($doc_id)->getField('url')->getUtf8Value(), "#"); + if (!isset($res[$page])) { + $res[$page] = 0; + } + $res[$page]+=$f; + } + } + $this->xml->addChild('results', json_encode($res)); + } + + protected function getTerms($term) { + $term = trim($term, '*? '); + $term = mb_strtolower($term); + $term = cubeText::removeAccents($term); + $terms = explode(' ', $term); + return $terms; + } + + public function exportpdf() { global $core; $daoBook = new wsDAOBook($core->con); @@ -146,7 +202,7 @@ class wsServices extends cubeFlashGateway { mkdir($destDir, 0777, true); } $fname = md5(implode(',%ù', $range)) . '.pdf'; - $destFile = $destDir . '/' . $fname ; + $destFile = $destDir . '/' . $fname; $destURL = '/fluidbook/cache/exportpdf/' . $book->book_id . '/' . $fname; // If result exists, don't make the pdf again if (file_exists($destFile) && filemtime($destFile) > filemtime($baseDocument)) { @@ -155,14 +211,14 @@ class wsServices extends cubeFlashGateway { } // Prepare the command line $l = array('A=' . $baseDocument, 'cat'); - foreach($range as $page) { + foreach ($range as $page) { if ($page < 1 || $page > $book->parametres->pages) { continue; } $l[] = 'A' . $page; } $l[] = 'output'; - $l[] = $destFile ; + $l[] = $destFile; $args = implode(' ', $l); // Execute the command line @@ -177,6 +233,7 @@ class wsServices extends cubeFlashGateway { http::redirect($destURL); exit; } + } ?> \ No newline at end of file diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 47571441d..ddd323cf5 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -37,6 +37,7 @@ class wsDAOBook extends commonDAO { $book->tache = $r->tache; $book->projet = $r->projet; $book->version = $r->version; + $book->composition_update = $r->composition_update; return $book; } @@ -54,6 +55,7 @@ class wsDAOBook extends commonDAO { $book->status = 0; $book->date_status = TIME; $book->date = TIME; + $book->composition_update = TIME; $book->chapters = json_encode(array()); $book->parametres = new wsBookParametres(); $book->tache = 0; @@ -119,11 +121,11 @@ class wsDAOBook extends commonDAO { return $this->selectById($book_id); } - public function duplicate($book_id, $createur, $nom,$pages=false) { + public function duplicate($book_id, $createur, $nom, $pages=false) { $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - $old_id=$book_id; - + $old_id = $book_id; + $parametres = unserialize($r->parametres); $parametres->setParent($this); $parametres->title = $nom; @@ -142,14 +144,15 @@ class wsDAOBook extends commonDAO { $c->changedate = TIME; $c->compiledate = 0; $c->version = 2; - $c->traductions=$r->traductions; - $c->specialLinks=$r->specialLinks; - $c->specialRulers=$r->specialRulers; + $c->traductions = $r->traductions; + $c->specialLinks = $r->specialLinks; + $c->specialRulers = $r->specialRulers; + $c->composition_update = TIME; $book_id = $c->book_id = $this->getNextId(); - if($pages){ - $c->numerotation=$r->numerotation; - $c->chapters=$r->chapters; - $this->con->execute('INSERT INTO book_pages SELECT '.$book_id.' AS book_id,book_page,document_id,document_page FROM book_pages WHERE book_id='.$old_id); + if ($pages) { + $c->numerotation = $r->numerotation; + $c->chapters = $r->chapters; + $this->con->execute('INSERT INTO book_pages SELECT ' . $book_id . ' AS book_id,book_page,document_id,document_page FROM book_pages WHERE book_id=' . $old_id); } $c->insert(); @@ -176,6 +179,7 @@ class wsDAOBook extends commonDAO { $c->changedate = TIME; $c->compiledate = TIME; $c->version = 2; + $c->composition_update = TIME; $book_id = $c->book_id = $this->getNextId(); $c->insert(); return $this->selectById($book_id); @@ -490,20 +494,36 @@ class wsDAOBook extends commonDAO { $c->parametres = serialize($parametres); $c->numerotation = implode(',', $numerotation); $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - - $this->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - $c = $this->con->openCursor('book_pages'); - $c->book_id = $book_id; + // Check if composition need to be updated + $r = $this->con->select('SELECT * FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + $tab = array(); + $now = array(); + while ($r->fetch()) { + $ref[$r->book_page] = array((int) $r->document_id, (int) $r->document_page); + } $i = 1; foreach ($pages as $p) { - $c->document_id = $p->document_id; - $c->document_page = $p->document_page; - $c->book_page = $i; - $c->insert(); + $now[$i] = array((int) $p->document_id, (int) $p->document_page); $i++; } + if ($now != $ref) { + $this->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + + $c = $this->con->openCursor('book_pages'); + $c->book_id = $book_id; + $i = 1; + foreach ($pages as $p) { + $c->document_id = $p->document_id; + $c->document_page = $p->document_page; + $c->book_page = $i; + $c->insert(); + $i++; + } + $c->composition_update = TIME; + } + + $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } public function makeTextsIndexes($book_id, &$index, &$textes) { @@ -800,11 +820,29 @@ class wsDAOBook extends commonDAO { } $this->compilePDF($book, $pages); + $this->indexPDF($book, $pages); $this->touchCompile($book_id); return $res; } + public function indexPDF($book, $pages) { + $indexPath = WS_BOOKS . '/search/' . $book->book_id; + Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); + + if (file_exists($indexPath)) { + files::deltree($indexPath); + } + $index = Zend_Search_Lucene::create($indexPath); + + foreach ($pages as $i => $infos) { + $doc = new Zend_Search_Lucene_Document(); + $doc->addField(Zend_Search_Lucene_Field::Text('url', '#' . $i)); + $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', file_get_contents(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.txt'))); + $index->addDocument($doc); + } + } + public function compilePDF($book, $pages) { $finalPDF = WS_BOOKS . '/final/' . $book->book_id . '/data/document.pdf'; @@ -816,6 +854,22 @@ class wsDAOBook extends commonDAO { return; } + if (file_exists($finalPDF)) { + $fmtime = filemtime($finalPDF); + if ($fmtime >= $book->composition_update) { + $invalid = false; + foreach ($pages as $i => $infos) { + $doc = WS_DOCS . '/' . $infos['document_id'] . '/crop.pdf'; + if (filemtime($doc) > $fmtime) { + $invalid = true; + } + } + if (!$invalid) { + return; + } + } + } + $pdfList = array(); $pagesList = array(); $nb_pages = array(); @@ -882,8 +936,6 @@ class wsDAOBook extends commonDAO { } } - fb($ranges); - foreach ($ranges as $range) { $args .= ' ' . $range['lettre'] . $range['start']; if ($range['start'] == $range['end']) { @@ -898,9 +950,6 @@ class wsDAOBook extends commonDAO { $pdftk->setPath(CONVERTER_PATH); $pdftk->setManualArg($args); $pdftk->execute(); - - fb($pdftk->commande); - fb($pdftk->output); } } diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index c0c458220..131840c1a 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -28,7 +28,9 @@ class wsBook extends cubeMetier { protected $specialRulers; protected $changedate; protected $compiledate; + protected $composition_update; protected $version; + public function __get($varname) { if (!property_exists($this, $varname)) { diff --git a/inc/ws/Util/packager/html5/class.ws.packager.html5.php b/inc/ws/Util/packager/html5/class.ws.packager.html5.php index 7770b83c8..67132ef8a 100644 --- a/inc/ws/Util/packager/html5/class.ws.packager.html5.php +++ b/inc/ws/Util/packager/html5/class.ws.packager.html5.php @@ -132,7 +132,7 @@ class wsPackagerHTML5 extends wsPackager { $arrowsColor = '#' . $this->theme->parametres->arrowsColor; // Set the icon list with the color $icons = array('nav-bookmark' => $couleurI, 'nav-friend' => $couleurI, 'nav-help' => $couleurI, 'nav-index' => $couleurI, 'nav-sommaire' => $couleurI, - 'next' => $arrowsColor, 'previous' => $arrowsColor, 'search' => $couleurI); + 'next' => $arrowsColor, 'previous' => $arrowsColor, 'search' => $couleurI,'nav-facebook'=>$couleurI,'nav-twitter'=>$couleurI); foreach ($icons as $icon => $color) { wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h); @@ -366,6 +366,17 @@ class wsPackagerHTML5 extends wsPackager { $res = array_merge($res, $links); $res[] = '.link a.displayArea:hover,.link a.displayArea.animating{background-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; + // Menus + # View + $res[] = '.portrait #view{width:' . $w . ';min-height:' . $h . '}'; + $res[] = '.landscape #view{width:' . $w2 . ';min-height:' . $h . '}'; + $res[] = '#view{background-color:' . self::colorToCSS($this->theme->parametres->couleurB) . ';color:' . self::colorToCSS($this->theme->parametres->subTextColor) . ';}'; + # Index + $ratio = $this->book->parametres->width / $this->book->parametres->height; + $thumbh = round(100 / $ratio); + $res[] = '#index .thumb img{width:100px;height:' . $thumbh . 'px;}'; + $res[] = '#index .doubleThumb{height:' . $thumbh . 'px;' . $this->writeCSSUA('box-shadow', '0 0 3px ' . $shadowColor) . '}'; + // Pages styles foreach ($this->cssColor as $color => $index) { $res[] = '.c' . $index . '{color:#' . $color . '}'; @@ -568,7 +579,8 @@ class wsPackagerHTML5 extends wsPackager { } public function copyLinkFile($source, $dest, $video=false) { - + // TODO delete that return; + return; $origDir = WS_BOOKS . '/working/' . $this->book_id . '/'; $types = array('mp4', 'ogv', 'webm', 'jpg'); if ($video) { @@ -588,7 +600,6 @@ class wsPackagerHTML5 extends wsPackager { foreach ($source as $so) { $s = $origDir . $so; - fb($s); if (file_exists($s)) { $d = $this->vdir . '/' . $dest . '/' . $so; if (!file_exists(dirname($d))) {