From 22229069c8d8e07dbd3e54a3c716f3e89a28cecd Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 1 Feb 2023 18:34:18 +0000 Subject: [PATCH] wip #5701 @3 --- .docker/docker-compose.yml | 3 - .docker/images/php/Dockerfile | 34 +- inc/commons/class.common.ajax.php | 2 +- inc/commons/class.common.core.php | 1 + inc/config.inc.php | 2 +- inc/ws/Controlleur/class.ws.ajax.php | 7 +- inc/ws/Controlleur/class.ws.maintenance.php | 30 +- inc/ws/Controlleur/class.ws.services.php | 66 +- inc/ws/Controlleur/class.ws.url.php | 4 +- inc/ws/DAO/class.ws.dao.book.php | 52 +- inc/ws/DAO/class.ws.dao.book3.php | 733 ------------------ inc/ws/DAO/class.ws.dao.document.php | 12 +- inc/ws/Metier/class.ws.book.php | 54 +- inc/ws/Metier/class.ws.document.php | 22 +- inc/ws/Util/class.ws.links.php | 2 +- inc/ws/Util/class.ws.util.php | 12 +- .../html5/master/class.ws.html5.compiler.php | 9 +- .../html5/master/class.ws.html5.links.php | 6 +- .../Util/html5/master/class.ws.html5.seo.php | 2 +- .../Util/packager/class.ws.packager.html.php | 2 +- .../class.ws.packager.mac.exe.html.php | 7 +- inc/ws/Util/packager/class.ws.packager.php | 35 +- .../class.ws.packager.win.exe.html.php | 2 +- .../class.ws.packager.win.inst.html.php | 4 - 24 files changed, 170 insertions(+), 933 deletions(-) delete mode 100644 inc/ws/DAO/class.ws.dao.book3.php diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index d1839f077..fa306397f 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -25,7 +25,6 @@ services: - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover' - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook' - '/mnt/sshfs/macparis:/mnt/sshfs/macparis' - - '/mnt/sshfs/codesign:/mnt/sshfs/codesign' - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache' - '/home/toolbox/www:/home/toolbox/www' - '/home/stats/www:/home/stats/www' @@ -66,7 +65,6 @@ services: - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover' - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook' - '/mnt/sshfs/macparis:/mnt/sshfs/macparis' - - '/mnt/sshfs/codesign:/mnt/sshfs/codesign' - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache' - '/home/toolbox/www:/home/toolbox/www' - '/home/stats/www:/home/stats/www' @@ -143,7 +141,6 @@ services: - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover' - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook' - '/mnt/sshfs/macparis:/mnt/sshfs/macparis' - - '/mnt/sshfs/codesign:/mnt/sshfs/codesign' - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache' - '/home/toolbox/www:/home/toolbox/www' - '/home/stats/www:/home/stats/www' diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index 1e89134ca..3301714eb 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -23,7 +23,7 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-php.list \ && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C -RUN apt-get update && apt-get -y --no-install-recommends install \ +RUN apt update && apt -y --no-install-recommends install \ git \ php7.2-fpm \ php7.2-apcu \ @@ -55,21 +55,21 @@ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer STOPSIGNAL SIGQUIT # Toolbox -RUN apt-get -y --no-install-recommends install nodejs google-chrome-stable -RUN apt-get -y --no-install-recommends install sudo -RUN apt-get -y --no-install-recommends install supervisor ssh rsync -RUN apt-get -y --no-install-recommends install default-jre pdftk poppler-utils inkscape mupdf-tools ghostscript imagemagick netpbm libjpeg-turbo8 libjpeg-turbo-progs -RUN apt-get -y --no-install-recommends install zip unzip gzip 7zip -RUN apt-get -y --no-install-recommends install icoutils fontforge icnsutils -RUN apt-get -y --no-install-recommends install ffmpeg lame x264 vorbis-tools -RUN apt-get -y --no-install-recommends install inkscape mupdf-tools librsvg2-bin -RUN apt-get -y --no-install-recommends install cron monit locate -RUN apt-get -y --no-install-recommends install build-essential chrpath libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev -RUN apt-get -y --no-install-recommends install libreoffice -RUN apt-get -y --no-install-recommends install sshfs lftp -RUN apt-get -y --no-install-recommends install sshfs python3 python3-pip -RUN apt-get -y --no-install-recommends install openssh-server rsyslog -RUN apt-get -y --no-install-recommends install mariadb-client +RUN apt -y --no-install-recommends install nodejs google-chrome-stable +RUN apt -y --no-install-recommends install sudo +RUN apt -y --no-install-recommends install supervisor ssh rsync +RUN apt -y --no-install-recommends install default-jre pdftk poppler-utils inkscape mupdf-tools ghostscript imagemagick netpbm libjpeg-turbo8 libjpeg-turbo-progs +RUN apt -y --no-install-recommends install zip unzip gzip 7zip +RUN apt -y --no-install-recommends install icoutils fontforge icnsutils +RUN apt -y --no-install-recommends install ffmpeg lame x264 vorbis-tools +RUN apt -y --no-install-recommends install inkscape mupdf-tools librsvg2-bin +RUN apt -y --no-install-recommends install cron monit locate +RUN apt -y --no-install-recommends install build-essential chrpath libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev +RUN apt -y --no-install-recommends install libreoffice +RUN apt -y --no-install-recommends install sshfs lftp +RUN apt -y --no-install-recommends install sshfs python3 python3-pip +RUN apt -y --no-install-recommends install openssh-server rsyslog +RUN apt -y --no-install-recommends install mariadb-client RUN cd /root;wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2;tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2;mv phantomjs-2.1.1-linux-x86_64 /usr/local/share;ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin RUN cd /root;wget https://github.com/nwutils/Web2Executable/releases/download/v0.7.1b/Web2ExeLinux-CMD.zip;unzip Web2ExeLinux-CMD.zip;mv Web2ExeLinux-CMD /usr/local/web2exe @@ -80,7 +80,7 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true RUN npm install --unsafe-perm --global uglify-js less sass puppeteer favicons nw-builder@3.5.7 RUN pip3 install font-line -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* +RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* RUN groupadd fluidbook;groupadd sudo;useradd -d /application -g 33 -G sudo -s /bin/bash -u 1002 extranet diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index cfade69b1..78eafaf8f 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -435,7 +435,7 @@ class commonAjax $f = $file->getRealPath(); $f = addcslashes($f, "$ #!\"\'&)(*,;<>?[]\^`{}|~"); $n = CubeIT_Text::str2URL($base) . '.xlsx'; - $dest = WS_BOOKS . '/working/' . $id . '/'; + $dest = wsBook::getDir($id,'working'); $cmd = "mv $f $dest/$n"; `$cmd`; $settings = []; diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 7c6a354f5..d884cf29e 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -327,6 +327,7 @@ class commonCore extends cubeCore // . // Table documents $db->documents->document_id('integer', 0, false); + $db->documents->region('varchar', 2, false,'"UE"'); $db->documents->file('varchar', 256, false); $db->documents->proprietaire('integer', 0, false); $db->documents->pages('integer', 0, false); diff --git a/inc/config.inc.php b/inc/config.inc.php index b60173643..0738fc8fb 100644 --- a/inc/config.inc.php +++ b/inc/config.inc.php @@ -40,7 +40,7 @@ define('WS_SOUNDS', WS_FILES . '/sounds'); define('WS_TOOLS', WS_FILES . '/tools'); define('WS_PACKAGER', WS_FILES . '/packager'); -define('UUS_FILES', '/application/usstorage/'); +define('US_FILES', '/application/usstorage/'); define('US_BOOKS', US_FILES . '/books'); define('US_COLLECTIONS', US_FILES . '/collections'); define('US_DOCS', US_FILES . '/docs'); diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 44efcc897..b690949ab 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -719,7 +719,6 @@ class wsAjax extends cubeAjax $exporter = new wsExporter(); - file_put_contents(WS_CACHE . '/' . $_POST['book_id'] . '.post.options', print_r($_POST, true)); $exporter->export($_POST['book_id'], $x, $_POST['action'], $_POST['version'], $dest['dir'], $dest['file'], $_POST['options'] ?? []); $x->addClosePopup(); @@ -878,7 +877,7 @@ class wsAjax extends cubeAjax if (!$id) { $c = __('Entrez le numéro du fluidbook source pour sélectionner les fichiers à transférer'); } else { - $dr = opendir(WS_BOOKS . '/working/' . $id); + $dr = opendir(wsBook::getDir($id,'working')); $files = array(); while ($f = readdir($dr)) { if ($f == '.' || $f == '..') { @@ -911,11 +910,11 @@ class wsAjax extends cubeAjax return; } - $d = WS_BOOKS . '/working/' . $_POST['dest']; + $d = wsBook::getDir($_POST['dest'],'working'); if (!file_exists($d)) { mkdir($d, 0777, true); } - $s = WS_BOOKS . '/working/' . $_POST['source']; + $s = wsBook::getDir($_POST['source'],'working'); foreach ($_POST['files'] as $f) { copy($s . '/' . $f, $d . '/' . $f); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 130526e18..4ea21544c 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -106,8 +106,8 @@ class wsMaintenance $torulers = $fromrulers; } - $wt = WS_BOOKS . '/working/' . $to; - $wf = WS_BOOKS . '/working/' . $from; + $wt = wsBook::getDir($to, 'working'); + $wf = wsBook::getDir($from, 'working'); if (file_exists($wf)) { $wf1 = $wf . '/*'; @@ -371,7 +371,7 @@ class wsMaintenance $book_id = $args[0]; - $dir = WS_BOOKS . '/working/' . $book_id; + $dir = wsBook::getDir($book_id, 'working'); wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); foreach ($links as $link) { @@ -424,7 +424,7 @@ class wsMaintenance $book_id = $args[0]; $format = $args[1]; - $dir = WS_BOOKS . '/working/' . $book_id; + $dir = wsBook::getDir($book_id, 'working'); wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); @@ -558,7 +558,7 @@ class wsMaintenance $res .= $fwstk->output; } - $dir = WS_BOOKS . '/index/' . $book->book_id; + $dir = wsBook::getDir($book->book_id, 'index'); if ($book->parametres->ignoreSearchSeparators != '') { $dir .= '/' . sha1($book->parametres->ignoreSearchSeparators); } @@ -575,7 +575,7 @@ class wsMaintenance } } - $i = WS_BOOKS . '/index/' . $book_id . '/*'; + $i = wsBook::getDir($book_id, 'index') . '*'; `rm -rf $i`; ob_end_clean(); die('
' . $res . '
'); @@ -1167,11 +1167,13 @@ class wsMaintenance $book_id = $args[0]; + $pdf = wsBook::getDir($book_id, 'pdf'); + $places = [ - WS_BOOKS . '/pdf/' . $book_id . '/original.pdf', - WS_BOOKS . '/pdf/' . $book_id . '/normal.pdf', - WS_BOOKS . '/final/' . $book_id . '/data/document.pdf', - WS_BOOKS . '/html5/' . $book_id . '/data/document.pdf', + wsBook::getDir($book_id, 'pdf') . 'original.pdf', + wsBook::getDir($book_id, 'pdf') . 'normal.pdf', + wsBook::getDir($book_id, 'final') . 'data/document.pdf', + wsBook::getDir($book_id, 'html5') . 'data/document.pdf', ]; $ok = false; @@ -1239,7 +1241,7 @@ class wsMaintenance } $tmp = CubeIT_Files::tempnam() . ".zip"; - CubeIT_Util_Zip::archive(WS_BOOKS . '/working/' . $book_id, $tmp); + CubeIT_Util_Zip::archive(wsBook::getDir($book_id, 'working'), $tmp); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="working_' . $book_id . '.zip"'); header('Content-Length: ' . filesize($tmp)); @@ -1401,8 +1403,10 @@ class wsMaintenance public static function clearLocks() { - $dir = WS_BOOKS . '/locks/*'; - `rm $dir`; + $dirs = [WS_BOOKS . '/locks/*', US_BOOKS . '/locks/*']; + foreach ($dirs as $dir) { + `rm $dir`; + } } public static function processPage($args) diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 6be12afaf..0174412b0 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -207,7 +207,7 @@ class wsServices extends cubeFlashGateway //die($limit . ':' . $book->changedate . '//' . filemtime($cover)); if (isset($_GET['force']) || !file_exists($cover) || filemtime($cover) < $limit || filesize($cover) < $minsize) { - $lock = WS_BOOKS . '/locks/' . $id . '.social_screenshot'; + $lock = wsBook::getDir($id, 'locks', false) . '.social_screenshot'; if (!file_exists($lock) || filemtime($lock) < time() - 3600) { touch($lock); @@ -281,63 +281,6 @@ class wsServices extends cubeFlashGateway exit; } - 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(); - $terms = array(); - foreach ($query->getQueryTerms() as $t) { - $terms[] = $t->text; - 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)); - $this->xml->addChild('terms', implode(',', $terms)); - } - protected function getTerms($term) { $term = trim($term, '*? '); @@ -359,7 +302,7 @@ class wsServices extends cubeFlashGateway if (is_null($book)) { $book = $this->callArgs[0]; - $range = $this->callArgs[1]??''; + $range = $this->callArgs[1] ?? ''; } $daoBook = new wsDAOBook($core->con); @@ -397,7 +340,8 @@ class wsServices extends cubeFlashGateway return false; } - $destDir = WS_CACHE . '/exportpdf/' . $book->cid; + + $destDir = wsBook::getCacheDir($book->book_id) . '/exportpdf/' . $book->cid; if (!file_exists($destDir)) { mkdir($destDir, 0777, true); } @@ -460,7 +404,7 @@ class wsServices extends cubeFlashGateway break; case 'pages': default: - $normal = WS_BOOKS . '/pdf/' . $book->book_id . '/original.pdf'; + $normal = wsBook::getDir($book->book_id, 'pdf') . 'original.pdf'; if (!file_exists($normal)) { $daoBook = new wsDAOBook($core->con); $pages = $daoBook->getPagesOfBook($book->book_id); diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 3617cb34e..944efeb77 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -948,7 +948,7 @@ html.tall{height:150%}' . "\n"; $book_id = $args[1]; $time = $args[2]; - $file = WS_BOOKS . '/links/' . $book_id . '/' . $time . '.xlsx'; + $file = wsBook::getDir($book_id, 'links') . $time . '.xlsx'; if (!file_exists($file) || filesize($file) === 0) { wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $time); @@ -1192,7 +1192,7 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co if (!$forceTheme) { self::logReferer($book_id); } - $htmlFile = WS_BOOKS . '/html5' . $dir . '/' . $id . '/index.html'; + $htmlFile = wsBook::getDir($id, 'html5') . 'index.html'; $html = ''; if (file_exists($htmlFile)) { $html = file_get_contents($htmlFile); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 18e9e1cbf..343854f30 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -10,6 +10,7 @@ class wsDAOBook extends commonDAO protected $_compileLock = null; + /** * wsDAOBook::singleton() * @@ -170,6 +171,7 @@ class wsDAOBook extends commonDAO return $this->factory($r); } + public function selectById($book_id = null, $simple = false) { if (is_null($book_id)) { @@ -243,7 +245,8 @@ class wsDAOBook extends commonDAO return $this->selectById($book_id); } - public function initUSStorage($book_id){ + public function initUSStorage($book_id) + { } @@ -793,42 +796,6 @@ class wsDAOBook extends commonDAO $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - /** - * @param $book wsBook - * @param $version - * @return bool - */ - public function isUpToDate($book, $version) - { - $version = (string)$version; - if ($version == '2') { - if (!file_exists(WS_BOOKS . '/final/' . $book->book_id)) { - return false; - } - if ($book->compiledate < $book->changedate) { - return false; - } - } else if ($version == '1') { - // V1 - if (!file_exists(WS_BOOKS . '/finalv1/' . $book->book_id . '/index.swf')) { - return false; - } - if ($book->compile1date < $book->changedate) { - return false; - } - } else if ($version == 'html5') { - return false; - // HTML5 - $checks = array($book->changedate, cubeFiles::filemtimeRecursive($book->getAssetDir()), cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT . '/inc/ws/Util/html5')); - foreach ($checks as $check) { - if ($check > $book->compilehtml5date) { - return false; - } - } - } - return true; - } - public function setComposition($book_id, $pages, $setNumerotation = true) { $numerotation = array(); @@ -903,7 +870,7 @@ class wsDAOBook extends commonDAO $prefix = 'f'; } - $dir = WS_BOOKS . '/index/' . $book->book_id; + $dir = wsBook::getDir($book->book_id, 'index'); if ($book->parametres->ignoreSearchSeparators !== '') { $dir .= '/' . sha1($book->parametres->ignoreSearchSeparators); } @@ -1143,7 +1110,7 @@ class wsDAOBook extends commonDAO $lockId .= '-' . wsTheme::hashThemeArray($forceTheme); } - $this->_compileLock = WS_BOOKS . '/locks/' . $lockId . '.lock'; + $this->_compileLock = wsBook::getDir($lockId, 'locks', false) . '.lock'; while (file_exists($this->_compileLock) && filemtime($this->_compileLock) > (time() - 900)) { @@ -1215,12 +1182,7 @@ class wsDAOBook extends commonDAO public function compilePDF($book, $pages) { - $res = wsUtil::compilePDF($book, $pages); - - $finalPDF = WS_BOOKS . '/final/' . $book->book_id . '/data/' . $book->parametres->pdfName; - if ($res) { - $this->copy($res, $finalPDF); - } + return wsUtil::compilePDF($book, $pages); } public function generateCID() diff --git a/inc/ws/DAO/class.ws.dao.book3.php b/inc/ws/DAO/class.ws.dao.book3.php deleted file mode 100644 index 95e87c2be..000000000 --- a/inc/ws/DAO/class.ws.dao.book3.php +++ /dev/null @@ -1,733 +0,0 @@ -book_id = $r->id; - $book->cid = $r->cid; - $book->nom = $r->name; - $book->lang = $r->locale; - $book->theme = $r->theme; - $book->proprietaire = $r->proprietaire_nom; - $book->proprietaire_id = $r->owner; - $book->proprietaire_utilisateur = $r->proprietaire_utilisateur; - $book->hash = $r->hash; - $book->demo_counter = $book->compteur_visites = $r->visits_counter; - $book->status = $r->status; - $book->date_status = self::_toTimestamp($r->status_date); - $book->date = self::_toTimestamp($r->created_at); - $book->pages = array(); - $book->chapters = $r->chapters; - $book->traductions = $r->translations; - $book->parametres = new wsBookParametres($this); - $book->parametres->importFromJson($r->settings); - $book->numerotation = $r->page_numbers; - $book->changedate = self::_toTimestamp($r->updated_at); - $book->compilehtml5date = $book->compile1date = $book->compiledate = self::_toTimestamp($r->compilation_date); - if (isset($r->facturable)) { - $book->facturable = $r->facturable; - } - if (isset($r->facturable_id)) { - $book->facturable_id = $r->facturable_id; - } - $book->tache = $r->extranet_task; - if (isset($r->projet)) { - $book->projet = $r->projet; - } - $book->version = 2; - $book->composition_update = self::_toTimestamp($r->composition_updated_at); - $book->exportdatas = $r->export_data; - - return $book; - } - - protected function cree($r) - { - $book = new wsBook(); - $book->book_id = 'new'; - $book->nom = ''; - $book->cid = null; - $book->lang = 'fr'; - $book->theme = 1; - $book->proprietaire = ''; - $book->proprietaire_id = 0; - $book->hash = ''; - $book->compteur_visites = 20; - $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; - $book->pages = array(); - $book->version = 2; - return $book; - } - - protected function getNextId() - { - $r = $this->con->select('SELECT MAX(book_id) AS book_id FROM books'); - if ($r->book_id < 10000) { - return 10000; - } - return $r->book_id + 1; - } - - public function saveExportDatas($book_id, $datas) - { - $c = $this->con->openCursor('books'); - $c->exportdatas = json_encode($datas); - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function addDemoCount($book_id) - { - - $r = $this->con->select('SELECT demo_counter,nom FROM books WHERE book_id=\'' . $book_id . '\''); - $m = 20; - if ($r->demo_counter > 0 && $r->demo_counter % $m == 0) { - $mail = new cubeMail(); - $mail->charset = 'UTF-8'; - $mail->from = 'contact@fluidbook.com'; - $mail->to = 'tech@fluidbook.com'; - $mail->subject = '[Fluidbook Workshop] Fluidbook consulté via l\'url publique'; - $mail->body = 'Le fluidbook suivant a été consulté ' . $m . ' fois (et ' . $r->demo_counter . ' au total) via l\'url publique : ' . "\r\n" . - 'Fluidbook # ' . $book_id . ' - ' . $r->nom; - $mail->send(); - } - - $this->con->select('UPDATE books SET demo_counter=demo_counter+1 WHERE book_id=\'' . $book_id . '\''); - } - - public function selectByIds($book_ids = array(), $simple = false) - { - if ($simple) { - $table = 'books'; - } else { - $table = 'books_vue'; - } - - $ids = array(); - foreach ($book_ids as $bid) { - - if (intval($bid) > 0) { - $ids[] = $bid; - } - } - - $sql = 'SELECT * FROM ' . $table . ' WHERE book_id IN (' . implode(',', $ids) . ')'; - $books = $this->factory($this->con->select($sql)); - $res = array(); - foreach ($books as $book) { - $res[$book->book_id] = $book; - } - return $res; - } - - public function selectAll() - { - $table = 'books_vue'; - $sql = 'SELECT * FROM ' . $table; - $r = $this->con->select($sql); - return $this->factory($r); - } - - public function selectById($book_id = null, $simple = false) - { - if (is_null($book_id)) { - return $this->cree(); - } - if ($simple) { - $table = 'books'; - } else { - $table = 'books_vue'; - } - $sql = 'SELECT * FROM ' . $table . ' WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1'; - $r = $this->con->select($sql); - return $this->singleton($r); - } - - public function selectByCid($cid = null, $simple = false) - { - if ($simple) { - $table = 'books'; - } else { - $table = 'books_vue'; - } - - $sql = 'SELECT * FROM ' . $table . ' WHERE cid LIKE BINARY \'' . $this->con->escape($cid) . '\' LIMIT 1'; - $r = $this->con->select($sql); - return $this->singleton($r); - } - - - /** - * wsDAOBook::sauve() - * - * @param mixed $createur - * @param mixed $data - * @return - */ - public function sauve($createur, $data) - { - $c = $this->con->openCursor('books'); - if (isset($data['nom'])) { - $c->nom = $data['nom']; - } - if (isset($data['lang'])) { - $c->lang = $data['lang']; - } - if (isset($data['theme'])) { - $c->theme = $data['theme']; - } - if (isset($data['proprietaire'])) { - $c->proprietaire = $data['proprietaire']; - } - - if ($data['book_id'] == 'new' || $data['book_id'] == '') { - $c->date = TIME; - $c->hash = md5(rand(0, 123456789365469)); - $c->compteur_visites = 20; - $c->parametres = serialize(new wsParametres()); - $c->changedate = TIME; - $book_id = $c->book_id = $this->getNextId(); - - $c->insert(); - } else { - $c->changedate = TIME; - $book_id = $data['book_id']; - $c->update('WHERE book_id=\'' . $this->con->escape($data['book_id']) . '\''); - } - - if (isset(self::$pagesOfBookCache[$book_id])) { - unset(self::$pagesOfBookCache[$book_id]); - } - - return $this->selectById($book_id); - } - - public function duplicate($book_id, $createur, $nom = null, $pages = false, $complete = false) - { - $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - - $old_id = $book_id; - - - $parametres = unserialize($r->parametres); - $parametres->setParent($this); - if (null === $nom) { - $nom = $parametres->title; - } - $parametres->title = $nom; - - if (!$complete) { - $parametres->pdfReplace = ''; - } - - $c = $this->con->openCursor('books'); - $c->proprietaire = $createur; - $c->date = TIME; - $c->hash = md5(rand(0, 1234567893)); - $c->cid = $this->generateCID(); - $c->compteur_visites = 20; - $c->status = -1; - $c->date_status = TIME; - $c->lang = $r->lang; - $c->parametres = serialize($parametres); - $c->nom = $nom; - $c->theme = $r->theme; - $c->changedate = TIME; - $c->compiledate = 0; - $c->version = 2; - $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 ($complete) { - $c->numerotation = $r->numerotation; - $c->chapters = $r->chapters; - } - $c->insert(); - - $this->saveCompositionVersion($book_id); - - return $this->selectById($book_id); - } - - public function creeEmpty($createur, $lang, $nom) - { - $c = $this->con->openCursor('books'); - - $parametres = new wsBookParametres($this); - $parametres->title = $nom; - - $c->proprietaire = $createur; - $c->cid = $this->generateCID(); - $c->nom = $nom; - $c->date = TIME; - $c->hash = md5(rand(0, 1234567893)); - $c->compteur_visites = 20; - $c->status = -1; - $c->date_status = TIME; - $c->parametres = serialize($parametres); - - $c->theme = 1; - $c->lang = $lang; - $c->changedate = TIME; - $c->compiledate = 0; - $c->version = 2; - $c->composition_update = TIME; - $book_id = $c->book_id = $this->getNextId(); - $c->insert(); - return $this->selectById($book_id); - } - - public function supprime($book_id) - { - $this->con->execute('DELETE FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - $this->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - return $this->con->execute('DELETE FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function count($limitedToUserRights = false) - { - $filters = $this->makeWhereFromFiltres(); - if ($filters == '1=1') { - $table = 'books'; - } else { - $table = 'books_vue'; - } - - $where = '(' . $filters . ')'; - $where .= $this->limitToUserRights($limitedToUserRights); - $r = $this->con->select('SELECT COUNT(*) AS nb FROM ' . $table . ' WHERE ' . $where); - return $r->nb; - } - - - public function insertDocument($book_id, $after_page, $document_id) - { - // Obtiens le book - $book = $this->selectById($book_id); - $num = explode(',', $book->numerotation); - // Obtiens le nombre de pages - $r = $this->con->select('SELECT pages,numberSections FROM documents WHERE document_id=\'' . $this->con->escape($document_id) . '\''); - // Décale les pages vers le bas - if ($after_page > 0) { - $this->decalePages($book_id, $after_page, $r->pages); - } - // Insère les pages - $c = $this->con->openCursor('book_pages'); - $c->book_id = $book_id; - $c->document_id = $document_id; - for ($i = 1; $i <= $r->pages; $i++) { - $c->document_page = $i; - $c->book_page = $after_page + $i; - $c->insert(); - } - // Mets à jour la liste des numéros des pages - $before = array_slice($num, 0, $after_page); - $after = array_slice($num, $after_page, count($num) - $after_page); - - $newnum = $r->numberSections; - if (trim($newnum, ',') == '') { - // If no number detected, we create a numeric list from 1 - $between = range(1, $r->pages); - } else { - // Else, we use numbers detected at conversion - $between = explode(',', $r->numberSections); - } - $num = array_merge($before, $between, $after); - // Mets à jour la numerotation de la publication - $c = $this->con->openCursor('books'); - $c->numerotation = implode(',', $num); - $c->composition_update = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - - $this->saveCompositionVersion($book_id); - } - - - public function getListe($orderby = null, $sens = null, $limit = null, $limitedToUserRights = false) - { - if (!is_null($this->q)) { - $where = '('; - if ($this->search_id) { - $where .= ' book_id=\'' . $this->con->escape($this->q) . '\' OR '; - } - - if (!cubeMath::is_int($this->q)) { - $where .= 'nom LIKE \'%' . $this->con->escape($this->q) . '%\''; - $daoClient = new commonDAOClient($this->con); - $where .= ' OR proprietaire_id IN(' . $daoClient->querySearchByName($this->q) . ') OR '; - } - $limit = null; - $where .= '1=2)'; - } else { - $where = '(' . $this->makeWhereFromFiltres() . ')'; - } - $where .= $this->limitToUserRights($limitedToUserRights); - - $orderby = is_null($orderby) ? 'book_id' : $orderby; - $sens = is_null($sens) ? 'DESC' : $sens; - $limit = is_null($limit) ? '' : $this->con->limit($limit); - - $sql = 'SELECT * FROM books_vue WHERE ' . $where . ' ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit; - $r = $this->con->select($sql); - return $this->factory($r); - } - - protected function limitToUserRights($utilisateur) - { - if ($utilisateur) { - if (wsDroits::admin()) { - return ''; - } - return ' AND proprietaire IN (' . $utilisateur->ws_rights . ')'; - } - return ''; - } - - protected function makeWhereFromFiltres() - { - if (!is_null($this->filtres)) { - $w = array('1=1'); - if (commonFiltre::test('admin_book', $this->filtres)) { - $w[] = 'super_admin IN (' . implode(',', array_keys($this->filtres['admin_book'])) . ')'; - } - if (commonFiltre::test('status_book', $this->filtres)) { - $w[] = 'status IN(' . implode(',', array_keys($this->filtres['status_book'])) . ')'; - } - if (commonFiltre::test('revendeur_book', $this->filtres)) { - $v = array_keys($this->filtres['revendeur_book']); - $values = array(); - foreach ($v as $r) { - $values[] = $this->con->escape($r); - } - - - $w[] = 'facturable IN(\'' . implode('\',\'', $values) . '\')'; - } - return implode(' AND ', $w); - } else { - return '1=1'; - } - } - - 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('|\s+' . $n . '$|iu', '', $c['label'])); - $res[] = $c; - } - - $json_chapters = json_encode($res); - - $c = $this->con->openCursor('books'); - $c->chapters = $json_chapters; - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - - if ($json_chapters && $json_chapters != '[]') { - if (count($res) == 1) { - if ($res[0]['label'] == '' && $res[0]['page'] == '') { - return; - } - } - $c = $this->con->openCursor('books_chapters_versions'); - $c->book_id = $book_id; - $c->chapters = $json_chapters; - $c->time = TIME; - $c->insert(); - } - } - - public function setTheme($book_id, $theme) - { - $c = $this->con->openCursor('books'); - $c->theme = $theme; - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setStatus($book_id, $status) - { - $c = $this->con->openCursor('books'); - if ($status < 2) { - $c->tache = 0; - } - $c->status = $status; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - return $this->selectById($book_id); - } - - public function setLang($book_id, $base, $traductions) - { - // Cleanup user translations - $traductions = json_decode($traductions, true); - foreach ($traductions as $k => $v) { - $traductions[$k] = $v; - } - - $daoLang = new wsDAOLang($this->con); - $lang = $daoLang->selectById($base); - // Cleanup base translations - $baseTraductions = $lang->traductions; - foreach ($baseTraductions as $k => $v) { - $baseTraductions[$k] = $v; - } - // Then compare them. If there is no differences, we don't save translations in the book - if ($traductions == $baseTraductions) { - $t = ''; - } else { - $t = json_encode($traductions); - } - - $c = $this->con->openCursor('books'); - $c->lang = $base; - $c->traductions = $t; - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setSettings($book_id, $settings) - { - $book = $this->selectById($book_id); - $parametres = $book->parametres; - $new = $settings; - $root = ['lang', 'proprietaire_id', 'status']; - $rootSettings = []; - foreach ($new as $k => $v) { - if ($k == '_empty_') { - continue; - } - if (in_array($k, $root)) { - $rootSettings[$k] = $v; - } else { - try { - $parametres->$k = $v; - } catch (Exception $e) { - - } - } - } - - - $ip = array(); - if (isset($parametres->stats_exclude_ip) && trim($parametres->stats_exclude_ip) != '') { - $list = $parametres->stats_exclude_ip; - $list = str_replace("\r", "\n", $list); - $e = explode("\n", $list); - foreach ($e as $i) { - $i = trim($i); - if ($i == '') { - continue; - } - $long = ip2long($i); - if ($long !== false) { - $ip[] = $long; - } - } - } - - $file = '/home/stats/www/exclude/' . $book_id; - - if (count($ip)) { - file_put_contents($file, implode(',', $ip)); - chmod($file, 0777); - chown($file, 'stats'); - } else if (file_exists($file)) { - unlink($file); - } - - $c = $this->con->openCursor('books'); - $c->nom = $parametres->title; - $c->parametres = serialize($parametres); - $c->changedate = TIME; - foreach ($rootSettings as $k => $v) { - $c->$k = $v; - } - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setProprietaire($book_id, $proprietaire_id) - { - $c = $this->con->openCursor('books'); - $c->proprietaire = $proprietaire_id; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setTache($book_id, $tache) - { - $c = $this->con->openCursor('books'); - $c->tache = $tache; - $c->status = 2; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setVersion($book_id, $version) - { - $c = $this->con->openCursor('books'); - $c->version = $version; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function touch($book_id) - { - $c = $this->con->openCursor('books'); - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function touchCompile($book_id, $version = 'all') - { - $c = $this->con->openCursor('books'); - if ($version == '2') { - $c->compiledate = TIME; - } elseif ($version == '1') { - $c->compile1date = TIME; - } elseif ($version == 'html5') { - $c->compilehtml5date = TIME; - } else { - $c->compiledate = TIME; - $c->compile1date = TIME; - $c->compilehtml5date = TIME; - } - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - /** - * @param $book wsBook - * @param $version - * @return bool - */ - public function isUpToDate($book, $version) - { - $version = (string)$version; - if ($version == '2') { - if (!file_exists(WS_BOOKS . '/final/' . $book->book_id)) { - return false; - } - if ($book->compiledate < $book->changedate) { - return false; - } - } else if ($version == '1') { - // V1 - if (!file_exists(WS_BOOKS . '/finalv1/' . $book->book_id . '/index.swf')) { - return false; - } - if ($book->compile1date < $book->changedate) { - return false; - } - } else if ($version == 'html5') { - return false; - // HTML5 - $checks = array($book->changedate, cubeFiles::filemtimeRecursive($book->getAssetDir()), cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT . '/inc/ws/Util/html5')); - foreach ($checks as $check) { - if ($check > $book->compilehtml5date) { - return false; - } - } - } - return true; - } - - public function setComposition($book_id, $pages, $setNumerotation = true) - { - $numerotation = array(); - $nb_pages = 0; - foreach ($pages as $p) { - if ($setNumerotation) { - $numerotation[] = $p->virtual; - } - $nb_pages++; - } - - $book = $this->selectById($book_id); - $parametres = $book->parametres; - $parametres->pages = $nb_pages; - - $c = $this->con->openCursor('books'); - $c->parametres = serialize($parametres); - if ($setNumerotation) { - $c->numerotation = implode(',', $numerotation); - } - $c->changedate = TIME; - - // 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(); - $ref = array(); - while ($r->fetch()) { - $ref[$r->book_page] = array((int)$r->document_id, (int)$r->document_page); - } - $i = 1; - foreach ($pages as $p) { - $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) . '\''); - - $c1 = $this->con->openCursor('book_pages'); - $c1->book_id = $book_id; - $i = 1; - foreach ($pages as $p) { - $c1->document_id = $p->document_id; - $c1->document_page = $p->document_page; - $c1->book_page = $i; - $c1->insert(); - $i++; - } - $c->composition_update = TIME; - $this->saveCompositionVersion($book_id); - } - - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function setInstallDir($book_id, $dir, $server) - { - $col = 'dir_' . $server; - - $c = $this->con->openCursor('books'); - $c->$col = $dir; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } -} diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 0a39e3f1d..28426f3e2 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -3,10 +3,10 @@ class wsDAODocument extends commonDAO { - public static $normal = array('document_id', 'file', 'proprietaire', 'pages', 'date', 'numberSections', 'version'); + public static $normal = array('document_id', 'file', 'proprietaire', 'pages', 'date', 'numberSections', 'version', 'region'); public static $complex = array('localInfos', 'bookmarks', 'generalInfos', 'conversionInfos', 'trim'); - public function singleton($r) + public function singleton($r, $init = true) { set_time_limit(0); $document = new wsDocument(); @@ -18,7 +18,9 @@ class wsDAODocument extends commonDAO $document->$k = unserialize($r->$k); } } - $document->init(); + if ($init) { + $document->init(); + } return $document; } @@ -46,10 +48,10 @@ class wsDAODocument extends commonDAO return $r->document_id + 1; } - public function selectById($document_id) + public function selectById($document_id, $init = true) { $r = $this->con->select('SELECT * FROM documents WHERE document_id=\'' . $this->con->escape($document_id) . '\''); - return $this->singleton($r); + return $this->singleton($r, $init); } public function selectByBookId($book_id) diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 5b7de131d..e8c81d429 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -40,6 +40,9 @@ class wsBook extends cubeMetier protected $_docs = []; + + protected static $_bookDirs = []; + public function __get($varname) { if (!property_exists($this, $varname)) { @@ -111,10 +114,7 @@ class wsBook extends cubeMetier public function getAssetDir($sub = '') { - if($this->region==='US'){ - return rtrim(US_BOOKS . '/working/' . $this->getAssetDirId() . '/' . trim($sub, '/'), '/') . '/'; - } - return rtrim(WS_BOOKS . '/working/' . $this->getAssetDirId() . '/' . trim($sub, '/'), '/') . '/'; + return rtrim(wsBook::getDir($this->getAssetDirId(), 'working') . '/' . trim($sub, '/'), '/') . '/'; } public function getAssetDirId() @@ -136,4 +136,50 @@ class wsBook extends cubeMetier // Begin to generate files async wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id, 1); } + + + public static function getDir($id, $dir, $addSlash = true, $onlyroot = false) + { + if (!isset(self::$_bookDirs[$id])) { + self::$_bookDirs[$id] = self::_getRegion($id); + } + $res = (self::$_bookDirs[$id] === 'UE' ? WS_BOOKS : US_BOOKS) . '/'; + $res .= $dir . '/'; + if (!$onlyroot) { + $res .= $id . '/'; + } + if (!$addSlash) { + $res = rtrim($res, '/'); + } else { + if (!file_exists($res)) { + mkdir($res, 0777, true); + } + } + return $res; + } + + public static function getPackagerDir($id, $onlyroot = false) + { + if (!isset(self::$_bookDirs[$id])) { + self::$_bookDirs[$id] = self::_getRegion($id); + } + $res = (self::$_bookDirs[$id] === 'UE' ? ROOT . '/fluidbook' : US_FILES) . '/packager/'; + if (!$onlyroot) { + $res .= $id . '/'; + } + return $res; + } + + public static function getCacheDir($id){ + return (self::$_bookDirs[$id] === 'UE' ? ROOT . '/fluidbook' : US_FILES) . '/cache/'; + } + + protected static function _getRegion($id) + { + global $core; + + $dao = new wsDAOBook($core->con); + $book = $dao->selectById($id, true); + return $book->region; + } } \ 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 60cef9da5..ef3b446ee 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -47,8 +47,9 @@ class wsDocument extends cubeMetier protected $cropped; protected $rgb; protected $filesdata = null; + protected $region = 'UE'; - protected static $_docsDir; + protected static $_docsDir = []; const NORMAL = 0; const FLATTEN = 1; @@ -833,16 +834,31 @@ class wsDocument extends cubeMetier } } - public static function getDir($id) + public static function _getDir($id) { + global $core; - $res = WS_DOCS . '/' . $id . '/'; + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($id, false); + if ($doc->region === 'UE') { + $res = WS_DOCS . '/' . $id . '/'; + } else { + $res = US_DOCS . '/' . $id . '/'; + } if (!file_exists($res)) { mkdir($res, 0777, true); } return $res; } + public static function getDir($id) + { + if (!isset(self::$_docsDir[$id])) { + self::$_docsDir[$id] = self::_getDir($id); + } + return self::$_docsDir[$id]; + } + // public static function makeHTML5FilesIfNotExists($document_id, $document_page, $format = 'jpg') // { // global $core; diff --git a/inc/ws/Util/class.ws.links.php b/inc/ws/Util/class.ws.links.php index b951a2d9c..89d90bf08 100644 --- a/inc/ws/Util/class.ws.links.php +++ b/inc/ws/Util/class.ws.links.php @@ -394,7 +394,7 @@ class wsLinks public static function getLinksDir($book_id) { - $dir = WS_BOOKS . '/links/' . $book_id; + $dir = wsBook::getDir($book_id,'links'); if (!file_exists($dir)) { mkdir($dir, 0777, true); } diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index c6064afd5..3652099f0 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -304,14 +304,14 @@ class wsUtil return false; } - $cacheDir = WS_BOOKS . '/pdf/' . $book->book_id; + $cacheDir = wsBook::getDir($book->book_id, 'pdf'); if (!file_exists($cacheDir)) { mkdir($cacheDir, 0777, true); } - $normalPDF = $cacheDir . '/normal.pdf'; - $originalPDF = $cacheDir . '/original.pdf'; - $compressedPDF = $cacheDir . '/compressed.pdf'; + $normalPDF = $cacheDir . 'normal.pdf'; + $originalPDF = $cacheDir . 'original.pdf'; + $compressedPDF = $cacheDir . 'compressed.pdf'; $files = [$normalPDF, $originalPDF, $compressedPDF]; @@ -355,7 +355,7 @@ class wsUtil if ($invalid) { if (file_exists($originalPDF)) { - self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf', false); + self::copy($originalPDF, $cacheDir . 'original.' . TIME . '.pdf', false); } $pdfList = array(); @@ -449,7 +449,7 @@ class wsUtil $args .= ' output ' . $originalPDF; - $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf'; + $cached = wsBook::getDir($book->book_id, 'pdf', true, true) . $hash . '.pdf'; if (file_exists($cached) && filesize($cached) > 0) { self::copy($cached, $originalPDF, false); 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 229984af1..62384eb68 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -279,7 +279,7 @@ class wsHTML5Compiler if ($forceThemeId) { $id .= '-' . $forceThemeId; } - $this->dir = WS_BOOKS . '/html5/' . $id . '/'; + $this->dir = wsBook::getDir($id, 'html5'); } else { $this->dir = $dir; } @@ -1503,10 +1503,7 @@ height="0" width="0" style="display:none;visibility:hidden"> if ($voiceInfos) { $hash = hash('sha256', $voiceInfos . '_^_' . $text); $fname = $hash . '.mp3'; - $dir = WS_BOOKS . '/audiodescription/'; - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } + $dir = wsBook::getDir($this->book_id, 'audiodescription', true, true); $file = $dir . $fname; @@ -2833,7 +2830,7 @@ height="0" width="0" style="display:none;visibility:hidden"> public function writeTexts() { $cache = sha1($this->book->parametres->highlightResults . '/--/' . $this->book->parametres->searchWordSelectionAlgorithm . '///' . $this->book->parametres->textExtraction . '|--|' . $this->book->parametres->ignoreSearchSeparators . '|||' . $this->book->composition_update . '()()()' . filemtime(WS_TOOLS . '/fwstk/out/artifacts/fwstk_jar/fwstk.jar')); - $cacheDir = WS_BOOKS . '/index/' . $this->book_id . '/' . $cache . '/'; + $cacheDir = wsBook::getDir( $this->book_id,'index').'cache/'; if (!file_exists($cacheDir)) { mkdir($cacheDir, 0777, true); 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 e42f6c6e4..aabd683a8 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -81,7 +81,7 @@ class wsHTML5Link $init = wsLinks::decryptLink($init); $init = CubeIT_Util_Array::asArray($init); - $wdir = WS_BOOKS . '/' . $id . '/working/'; + $wdir = wsBook::getDir($id, 'working'); $init['scorm'] = self::isScorm($init); $init['to'] = self::replaceCustomURL($init['to']); @@ -2926,7 +2926,7 @@ class zoomLink extends normalLink $leftfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, $extractPage, array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h), - $left, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/'); + $left, $extractOptions, wsBook::getCacheDir($compiler->book_id) . $cachedir . '/' . $compiler->book_id . '/'); if (!file_exists($leftfile)) { die('Error generating left part ' . $leftfile); @@ -2951,7 +2951,7 @@ class zoomLink extends normalLink $rightfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, $extractPage, array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h), - $right, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/'); + $right, $extractOptions, wsBook::getCacheDir($compiler->book_id) . $cachedir . '/' . $compiler->book_id . '/'); if (!file_exists($rightfile)) { die('Error generating right part ' . $rightfile); diff --git a/inc/ws/Util/html5/master/class.ws.html5.seo.php b/inc/ws/Util/html5/master/class.ws.html5.seo.php index 97d901bdc..f07c60d60 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.seo.php +++ b/inc/ws/Util/html5/master/class.ws.html5.seo.php @@ -278,7 +278,7 @@ class wsHTML5SeoPage } $html = str_replace('', $base, $html); - $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/'; + $dir = wsBook::getDir( $this->_container->compiler->book_id,'seo'); if (!file_exists($dir)) { mkdir($dir, 0777, true); } diff --git a/inc/ws/Util/packager/class.ws.packager.html.php b/inc/ws/Util/packager/class.ws.packager.html.php index 75095684e..2507c32b8 100644 --- a/inc/ws/Util/packager/class.ws.packager.html.php +++ b/inc/ws/Util/packager/class.ws.packager.html.php @@ -251,7 +251,7 @@ class wsPackagerHTML extends wsPackager $cp->setPath(CONVERTER_PATH); $cp->setArg('r'); $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/html5/' . $bookId . '/*'); + $cp->setArg(null, wsBook::getDir($bookId, 'html5') . '*'); $cp->setArg(null, $dest); $cp->execute(); diff --git a/inc/ws/Util/packager/class.ws.packager.mac.exe.html.php b/inc/ws/Util/packager/class.ws.packager.mac.exe.html.php index 686832cf4..3020d1c9c 100644 --- a/inc/ws/Util/packager/class.ws.packager.mac.exe.html.php +++ b/inc/ws/Util/packager/class.ws.packager.mac.exe.html.php @@ -47,7 +47,8 @@ class wsPackagerMacEXEHTML extends wsPackagerWinEXEHTML $this->copyFluidbookFiles(); $this->makeJSON(); - $this->buildPath = WS_PACKAGER . '/nwbuild/' . $this->version . '/' . $this->book_id; + + $this->buildPath = wsBook::getPackagerDir($this->book_id, true) . 'nwbuild/' . $this->version . '/' . $this->book_id; if (!file_exists($this->buildPath)) { mkdir($this->buildPath, 0777, true); } @@ -64,8 +65,8 @@ class wsPackagerMacEXEHTML extends wsPackagerWinEXEHTML $cl->debug(); $this->replaceFFMpeg(); - if(!file_exists($this->getAppPath())){ - die('Error while building mac app : '.$cl->commande.' // '.$cl->output); + if (!file_exists($this->getAppPath())) { + die('Error while building mac app : ' . $cl->commande . ' // ' . $cl->output); } $this->signApp(); diff --git a/inc/ws/Util/packager/class.ws.packager.php b/inc/ws/Util/packager/class.ws.packager.php index 011709452..9d43fa7b0 100644 --- a/inc/ws/Util/packager/class.ws.packager.php +++ b/inc/ws/Util/packager/class.ws.packager.php @@ -63,7 +63,7 @@ class wsPackager $this->book_id = $book_id; $this->vdir = $vdir; - $this->dir = ROOT . '/fluidbook/packager/' . $book_id . '/'; + $this->dir = wsBook::getPackagerDir($book_id); $this->whole = $whole; if (!file_exists($this->dir)) { @@ -123,13 +123,7 @@ class wsPackager protected function copyFluidbookFiles() { - // Copie du FB vers un répertoire temporaire - $cp = new cubeCommandLine('cp'); - $cp->setArg('R'); - $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/final/' . $this->book->book_id . '/*'); - $cp->setArg(null, $this->vdir); - $cp->execute(); + } protected function copyOtherFiles($files) @@ -179,7 +173,14 @@ class wsPackager protected function getURLBase($ext = '') { - $res = '/fluidbook' . $this->getRelativeBase(); + if ($this->book->region === 'UE') { + $res = '/fluidbook'; + } else { + $res = '/usstorage'; + } + + + $res = $this->getRelativeBase(); if ($ext != '') { $res .= '.' . $ext; } @@ -188,7 +189,15 @@ class wsPackager protected function getPathBase($ext = '') { - $res = WS_FILES . $this->getRelativeBase(); + if ($this->book->region === 'UE') { + $base = WS_FILES; + } else { + $res = US_FILES; + } + if (!file_exists($base . '/packager/download')) { + mkdir($base . '/packager/download', 0777, true); + } + $res = $base . $this->getRelativeBase(); if ($ext != '') { $res .= '.' . $ext; } @@ -225,10 +234,6 @@ class wsPackager $zip->debug(); } - if (!file_exists(WS_FILES . '/packager/download')) { - mkdir(WS_FILES . '/packager/download', 0777, true); - } - if ($rename) { rename($zipfile, $final); } @@ -238,7 +243,7 @@ class wsPackager public function getFinalPackageDir() { $dir = $this->vdir; - $dir .= '/m/'; + $dir .= '/m/'; return $dir; } diff --git a/inc/ws/Util/packager/class.ws.packager.win.exe.html.php b/inc/ws/Util/packager/class.ws.packager.win.exe.html.php index a7e971ee4..559290490 100644 --- a/inc/ws/Util/packager/class.ws.packager.win.exe.html.php +++ b/inc/ws/Util/packager/class.ws.packager.win.exe.html.php @@ -176,7 +176,7 @@ class wsPackagerWinEXEHTML extends wsPackager $cp = new cubeCommandLine('cp'); $cp->setArg('R'); $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/html5/' . $this->book->book_id . '/*'); + $cp->setArg(null, wsBook::getDir($this->book->book_id, 'html5') . '*'); $cp->setArg(null, $this->vdir); $cp->execute(); diff --git a/inc/ws/Util/packager/class.ws.packager.win.inst.html.php b/inc/ws/Util/packager/class.ws.packager.win.inst.html.php index 37d736afb..25b8bbd5c 100644 --- a/inc/ws/Util/packager/class.ws.packager.win.inst.html.php +++ b/inc/ws/Util/packager/class.ws.packager.win.inst.html.php @@ -32,10 +32,6 @@ class wsPackagerWinINSTHTML extends wsPackagerWinEXEHTML $lang->nsis = 'English'; } - if (!file_exists(WS_FILES . '/packager/download')) { - mkdir(WS_FILES . '/packager/download', 0777, true); - } - $fname = $this->exeName; $title = $this->appName; -- 2.39.5