]> _ Git - cubeextranet.git/commitdiff
wip #5701 @3
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 1 Feb 2023 18:34:18 +0000 (18:34 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 1 Feb 2023 18:34:18 +0000 (18:34 +0000)
24 files changed:
.docker/docker-compose.yml
.docker/images/php/Dockerfile
inc/commons/class.common.ajax.php
inc/commons/class.common.core.php
inc/config.inc.php
inc/ws/Controlleur/class.ws.ajax.php
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Controlleur/class.ws.services.php
inc/ws/Controlleur/class.ws.url.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/DAO/class.ws.dao.book3.php [deleted file]
inc/ws/DAO/class.ws.dao.document.php
inc/ws/Metier/class.ws.book.php
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.links.php
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php
inc/ws/Util/html5/master/class.ws.html5.seo.php
inc/ws/Util/packager/class.ws.packager.html.php
inc/ws/Util/packager/class.ws.packager.mac.exe.html.php
inc/ws/Util/packager/class.ws.packager.php
inc/ws/Util/packager/class.ws.packager.win.exe.html.php
inc/ws/Util/packager/class.ws.packager.win.inst.html.php

index d1839f0776792eafff836a83a0c55f2ddf7f6e03..fa306397fed1ba1ebac39d413593208552c9fde2 100644 (file)
@@ -25,7 +25,6 @@ services:
       - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover'\r
       - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook'\r
       - '/mnt/sshfs/macparis:/mnt/sshfs/macparis'\r
-      - '/mnt/sshfs/codesign:/mnt/sshfs/codesign'\r
       - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache'\r
       - '/home/toolbox/www:/home/toolbox/www'\r
       - '/home/stats/www:/home/stats/www'\r
@@ -66,7 +65,6 @@ services:
       - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover'\r
       - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook'\r
       - '/mnt/sshfs/macparis:/mnt/sshfs/macparis'\r
-      - '/mnt/sshfs/codesign:/mnt/sshfs/codesign'\r
       - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache'\r
       - '/home/toolbox/www:/home/toolbox/www'\r
       - '/home/stats/www:/home/stats/www'\r
@@ -143,7 +141,6 @@ services:
       - '/data/extranet/www/fluidbook/cover:/application/fluidbook/cover'\r
       - '/mnt/sshfs/fluidbook:/mnt/sshfs/fluidbook'\r
       - '/mnt/sshfs/macparis:/mnt/sshfs/macparis'\r
-      - '/mnt/sshfs/codesign:/mnt/sshfs/codesign'\r
       - '/data/extranet/www/fluidbook/cache/nwbuild:/usr/lib/node_modules/nw-builder/cache'\r
       - '/home/toolbox/www:/home/toolbox/www'\r
       - '/home/stats/www:/home/stats/www'\r
index 1e89134ca3c55057507e9ad2354af555683bb1a4..3301714eb927ff345b65d64f09d23b34ea30a8b5 100644 (file)
@@ -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
 
index cfade69b1e697bd89987b4d3246f98dd48cceb20..78eafaf8f5b09aaf9d5d1aae03f60dc2657eaaff 100644 (file)
@@ -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 = [];
index 7c6a354f50793eaf458c4331461c71326b848b72..d884cf29e541ade6782593b71c09b4f57b2adfa6 100644 (file)
@@ -327,6 +327,7 @@ class commonCore extends cubeCore
         // .\r
         // Table documents\r
         $db->documents->document_id('integer', 0, false);\r
+        $db->documents->region('varchar', 2, false,'"UE"');\r
         $db->documents->file('varchar', 256, false);\r
         $db->documents->proprietaire('integer', 0, false);\r
         $db->documents->pages('integer', 0, false);\r
index b60173643558958076970cbd3885c528db51f3d9..0738fc8fb80444f13bbc99cd014ce507f42889a6 100644 (file)
@@ -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');
index 44efcc8975f91c9b547f84096cb9275304afc3b4..b690949ab08499b711185482379f34bbf0908d57 100644 (file)
@@ -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);
index 130526e188ab2a4a9c73f5768da1f4020d1a6ffe..4ea21544c3119c61e930262ad75c9bd1b9a0aba1 100644 (file)
@@ -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('<pre>' . $res . '</pre>');
@@ -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)
index 6be12afaf54358d06a4ed4c7014a15ee79e85355..0174412b09ee28fc5ed7c44aa2466289588f29a1 100644 (file)
@@ -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);
index 3617cb34eabce3bbf8ed71758ea349a68d16eee1..944efeb777e275a59f6b9865850111f9723bad0b 100644 (file)
@@ -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);
index 18e9e1cbff5cce1ee34f3a579134cd1dddc53493..343854f300ee3fb95ccb902b59bd952965ebbc94 100644 (file)
@@ -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 (file)
index 95e87c2..0000000
+++ /dev/null
@@ -1,733 +0,0 @@
-<?php
-
-class wsDAOBook3 extends wsDAOBook
-{
-
-    public static $pagesOfBookCache = array();
-
-    /** @var wsHTML5Compiler */
-    public static $lastHTML5Compiler = null;
-
-    protected $_compileLock = null;
-
-    /**
-     * wsDAOBook::singleton()
-     *
-     * @param mixed $r
-     * @return
-     */
-
-    protected static function _toTimestamp($date)
-    {
-        return strtotime($date);
-    }
-
-    protected function singleton($r)
-    {
-
-        $book = new wsBook();
-        $book->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) . '\'');
-    }
-}
index 0a39e3f1d513e71e81ee2cb28e32d0b7cc7a4ed5..28426f3e2dc3ee122b42a771654dbdce2576dfcf 100644 (file)
@@ -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)
index 5b7de131d33e2f3fcb4f3ebb93235afc302f6daa..e8c81d429e18f24cc373cca0cfe706b0bbc266e0 100644 (file)
@@ -40,6 +40,9 @@ class wsBook extends cubeMetier
 \r
     protected $_docs = [];\r
 \r
+\r
+    protected static $_bookDirs = [];\r
+\r
     public function __get($varname)\r
     {\r
         if (!property_exists($this, $varname)) {\r
@@ -111,10 +114,7 @@ class wsBook extends cubeMetier
 \r
     public function getAssetDir($sub = '')\r
     {\r
-        if($this->region==='US'){\r
-            return rtrim(US_BOOKS . '/working/' . $this->getAssetDirId() . '/' . trim($sub, '/'), '/') . '/';\r
-        }\r
-        return rtrim(WS_BOOKS . '/working/' . $this->getAssetDirId() . '/' . trim($sub, '/'), '/') . '/';\r
+        return rtrim(wsBook::getDir($this->getAssetDirId(), 'working') . '/' . trim($sub, '/'), '/') . '/';\r
     }\r
 \r
     public function getAssetDirId()\r
@@ -136,4 +136,50 @@ class wsBook extends cubeMetier
         // Begin to generate files async\r
         wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id, 1);\r
     }\r
+\r
+\r
+    public static function getDir($id, $dir, $addSlash = true, $onlyroot = false)\r
+    {\r
+        if (!isset(self::$_bookDirs[$id])) {\r
+            self::$_bookDirs[$id] = self::_getRegion($id);\r
+        }\r
+        $res = (self::$_bookDirs[$id] === 'UE' ? WS_BOOKS : US_BOOKS) . '/';\r
+        $res .= $dir . '/';\r
+        if (!$onlyroot) {\r
+            $res .= $id . '/';\r
+        }\r
+        if (!$addSlash) {\r
+            $res = rtrim($res, '/');\r
+        } else {\r
+            if (!file_exists($res)) {\r
+                mkdir($res, 0777, true);\r
+            }\r
+        }\r
+        return $res;\r
+    }\r
+\r
+    public static function getPackagerDir($id, $onlyroot = false)\r
+    {\r
+        if (!isset(self::$_bookDirs[$id])) {\r
+            self::$_bookDirs[$id] = self::_getRegion($id);\r
+        }\r
+        $res = (self::$_bookDirs[$id] === 'UE' ? ROOT . '/fluidbook' : US_FILES) . '/packager/';\r
+        if (!$onlyroot) {\r
+            $res .= $id . '/';\r
+        }\r
+        return $res;\r
+    }\r
+\r
+    public static function getCacheDir($id){\r
+        return (self::$_bookDirs[$id] === 'UE' ? ROOT . '/fluidbook' : US_FILES) . '/cache/';\r
+    }\r
+\r
+    protected static function _getRegion($id)\r
+    {\r
+        global $core;\r
+\r
+        $dao = new wsDAOBook($core->con);\r
+        $book = $dao->selectById($id, true);\r
+        return $book->region;\r
+    }\r
 }
\ No newline at end of file
index 60cef9da582e8eb5e0c2d2f4c68573da8958e8b7..ef3b446eefc1df92e0f32cd9b9d03d28775b782f 100644 (file)
@@ -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;
index b951a2d9cea4109f4c35652faee4376719141dd6..89d90bf0810245e82404f22a2b546f46f731b56c 100644 (file)
@@ -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);
         }
index c6064afd538ae18e84f09f1430221b5500f74dba..3652099f0768420063e5064db25a2285ae37e3ed 100644 (file)
@@ -304,14 +304,14 @@ class wsUtil
             return false;\r
         }\r
 \r
-        $cacheDir = WS_BOOKS . '/pdf/' . $book->book_id;\r
+        $cacheDir = wsBook::getDir($book->book_id, 'pdf');\r
         if (!file_exists($cacheDir)) {\r
             mkdir($cacheDir, 0777, true);\r
         }\r
 \r
-        $normalPDF = $cacheDir . '/normal.pdf';\r
-        $originalPDF = $cacheDir . '/original.pdf';\r
-        $compressedPDF = $cacheDir . '/compressed.pdf';\r
+        $normalPDF = $cacheDir . 'normal.pdf';\r
+        $originalPDF = $cacheDir . 'original.pdf';\r
+        $compressedPDF = $cacheDir . 'compressed.pdf';\r
 \r
         $files = [$normalPDF, $originalPDF, $compressedPDF];\r
 \r
@@ -355,7 +355,7 @@ class wsUtil
         if ($invalid) {\r
 \r
             if (file_exists($originalPDF)) {\r
-                self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf', false);\r
+                self::copy($originalPDF, $cacheDir . 'original.' . TIME . '.pdf', false);\r
             }\r
 \r
             $pdfList = array();\r
@@ -449,7 +449,7 @@ class wsUtil
 \r
                 $args .= ' output ' . $originalPDF;\r
 \r
-                $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf';\r
+                $cached = wsBook::getDir($book->book_id, 'pdf', true, true) . $hash . '.pdf';\r
 \r
                 if (file_exists($cached) && filesize($cached) > 0) {\r
                     self::copy($cached, $originalPDF, false);\r
index 229984af1435bd5e7a4444a1010b7b6b07ffea33..62384eb68b27ee8ac0cea6dc34c974e18bfebbc7 100644 (file)
@@ -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"></iframe></noscript>
             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"></iframe></noscript>
     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);
 
index e42f6c6e42aa809dab6ddd5aca583ec5614fa33b..aabd683a87bddd8ffc81dbd5a605df2413bda13d 100644 (file)
@@ -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);
index 97d901bdc85598707dd3a3ddfac8014ed21fcfce..f07c60d607e25b39adfca55e5f15279505213d60 100644 (file)
@@ -278,7 +278,7 @@ class wsHTML5SeoPage
         }\r
         $html = str_replace('<!-- $base -->', $base, $html);\r
 \r
-        $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/';\r
+        $dir = wsBook::getDir( $this->_container->compiler->book_id,'seo');\r
         if (!file_exists($dir)) {\r
             mkdir($dir, 0777, true);\r
         }\r
index 75095684e34d800d25b13e70ed0dfc329a5c1fc6..2507c32b8e947fd3bb63a7b22b92f9cde9243762 100644 (file)
@@ -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();
 
index 686832cf46ca1539885a9cff85bc8eba83c1e3a3..3020d1c9c0328f74da40a051c0fd8c5bec642889 100644 (file)
@@ -47,7 +47,8 @@ class wsPackagerMacEXEHTML extends wsPackagerWinEXEHTML
         $this->copyFluidbookFiles();\r
         $this->makeJSON();\r
 \r
-        $this->buildPath = WS_PACKAGER . '/nwbuild/' . $this->version . '/' . $this->book_id;\r
+\r
+        $this->buildPath = wsBook::getPackagerDir($this->book_id, true) . 'nwbuild/' . $this->version . '/' . $this->book_id;\r
         if (!file_exists($this->buildPath)) {\r
             mkdir($this->buildPath, 0777, true);\r
         }\r
@@ -64,8 +65,8 @@ class wsPackagerMacEXEHTML extends wsPackagerWinEXEHTML
         $cl->debug();\r
 \r
         $this->replaceFFMpeg();\r
-        if(!file_exists($this->getAppPath())){\r
-            die('Error while building mac app : '.$cl->commande.' // '.$cl->output);\r
+        if (!file_exists($this->getAppPath())) {\r
+            die('Error while building mac app : ' . $cl->commande . ' // ' . $cl->output);\r
         }\r
 \r
         $this->signApp();\r
index 011709452bb56fddc468160c4bee7bf404072629..9d43fa7b0d072cc7be857f3b01ced08ba0897d0a 100644 (file)
@@ -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;
     }
 
index a7e971ee4a15d273ebaa4e6effce0e029910b2db..5592904903bfedee4ee5e42f4aabc45ce9bffced 100644 (file)
@@ -176,7 +176,7 @@ class wsPackagerWinEXEHTML extends wsPackager
         $cp = new cubeCommandLine('cp');\r
         $cp->setArg('R');\r
         $cp->setArg('p');\r
-        $cp->setArg(null, WS_BOOKS . '/html5/' . $this->book->book_id . '/*');\r
+        $cp->setArg(null, wsBook::getDir($this->book->book_id, 'html5') . '*');\r
         $cp->setArg(null, $this->vdir);\r
         $cp->execute();\r
 \r
index 37d736afb12767d09895d5d8445db4663e899460..25b8bbd5c185f4625af0d1dccb9aac430fb41f4f 100644 (file)
@@ -32,10 +32,6 @@ class wsPackagerWinINSTHTML extends wsPackagerWinEXEHTML
             $lang->nsis = 'English';\r
         }\r
 \r
-        if (!file_exists(WS_FILES . '/packager/download')) {\r
-            mkdir(WS_FILES . '/packager/download', 0777, true);\r
-        }\r
-\r
         $fname = $this->exeName;\r
         $title = $this->appName;\r
 \r