]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 22 May 2018 13:02:43 +0000 (13:02 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 22 May 2018 13:02:43 +0000 (13:02 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Metier/class.ws.book.parametres.php
inc/ws/Metier/class.ws.document.php

index 090dbf422ad15fef2c8a0da94ad0854a94dcba16..3f0a50692a0930b47c33b5edb3f6feaa23466c90 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 
-class wsMaintenance {
+class wsMaintenance
+{
 
-       public static function in($args) {
+       public static function in($args)
+       {
                $args = cubePage::getArgs($args);
                $f = array_shift($args);
                $callback = array('wsMaintenance', $f);
@@ -11,7 +13,8 @@ class wsMaintenance {
                }
        }
 
-       public static function cleanOriginauxPDF() {
+       public static function cleanOriginauxPDF()
+       {
                global $core;
                cubePHP::neverStop();
                $r = $core->con->select('SELECT document_id FROM documents');
@@ -27,7 +30,8 @@ class wsMaintenance {
                }
        }
 
-       public static function initCompositionVersions($args) {
+       public static function initCompositionVersions($args)
+       {
                global $core;
                $dao = new wsDAOBook($core->con);
 
@@ -37,7 +41,8 @@ class wsMaintenance {
                }
        }
 
-       public static function setCID() {
+       public static function setCID()
+       {
                global $core;
                $dao = new wsDAOBook($core->con);
 
@@ -49,7 +54,8 @@ class wsMaintenance {
                }
        }
 
-       public static function compactLinks() {
+       public static function compactLinks()
+       {
                global $core;
                $r = $core->con->select('SELECT * FROM `document_links_versions` GROUP BY document_id,links,rulers');
                $keep = array();
@@ -65,7 +71,8 @@ class wsMaintenance {
                }
        }
 
-       public static function checkSerializeLinks() {
+       public static function checkSerializeLinks()
+       {
                global $core;
                $r = $core->con->select('SELECT * FROM document_links_versions');
                while ($r->fetch()) {
@@ -80,7 +87,8 @@ class wsMaintenance {
                }
        }
 
-       public static function moveLinksToVersionDB() {
+       public static function moveLinksToVersionDB()
+       {
                global $core;
                $r = $core->con->select('SELECT * FROM document_links');
                $d = array();
@@ -113,7 +121,8 @@ class wsMaintenance {
                }
        }
 
-       public static function importFromOldWS($args) {
+       public static function importFromOldWS($args)
+       {
                global $core;
                // Import des fluidbooks
                // Donc le dernier importé est le max dont le numéro est inférieur Ã  10000
@@ -135,7 +144,8 @@ class wsMaintenance {
                $core->refreshWSUsersTree();
        }
 
-       public static function importLangs($oldBooks) {
+       public static function importLangs($oldBooks)
+       {
                global $core, $allTrads, $trads;
                // On regarde d'abord les langues que nous avons déjà
                $r = $core->con->select('SELECT lang_id FROM langues');
@@ -189,7 +199,8 @@ class wsMaintenance {
                }
        }
 
-       public static function importThemes($oldBooks) {
+       public static function importThemes($oldBooks)
+       {
                global $core, $signatures;
 
                $r = $core->con->select('SELECT tid,sigid FROM ws.theme');
@@ -226,7 +237,8 @@ class wsMaintenance {
                }
        }
 
-       public static function importDocs($oldBooks) {
+       public static function importDocs($oldBooks)
+       {
                global $core;
                // On cherche maintenant Ã  savoir si l'on doit importer de nouveaux documents associés
                $oldDocuments = array();
@@ -253,7 +265,8 @@ class wsMaintenance {
                }
        }
 
-       public static function copyLinks($args) {
+       public static function copyLinks($args)
+       {
                list($from, $to) = $args;
                global $core;
 
@@ -280,7 +293,8 @@ class wsMaintenance {
                $dao->setLinksAndRulers($to, $tolinks, $torulers, 'Copy links from #' . $from . '  to #' . $to, $core->user->utilisateur_id);
        }
 
-       public static function importBooks($oldBooks) {
+       public static function importBooks($oldBooks)
+       {
                global $core, $allTrads, $signatures;
                // Importe les fluidbooks
                $r = $core->con->select('SELECT * FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ' ORDER BY bid');
@@ -345,7 +359,8 @@ class wsMaintenance {
                }
        }
 
-       protected static function _oldIconesToColor($iid, &$parametres) {
+       protected static function _oldIconesToColor($iid, &$parametres)
+       {
                global $oldIconesColors;
                if (!isset($oldIconesColors)) {
                        $oldIconesColors = array();
@@ -372,7 +387,8 @@ class wsMaintenance {
                }
        }
 
-       protected static function _getWsUser($oldid) {
+       protected static function _getWsUser($oldid)
+       {
                global $ws2ext;
                if (!isset($ws2ext)) {
                        self::_getAllUsers();
@@ -386,7 +402,8 @@ class wsMaintenance {
                return $ws2ext[$oldid];
        }
 
-       protected static function _getAllUsers() {
+       protected static function _getAllUsers()
+       {
                global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs;
                $grades = array(0 => 1, 0.4 => 1, '0.4' => 1, 0.5 => 1, '0.5' => 1, 1 => 1, 2 => 2, 3 => 3, 4 => 5);
                // Contrôle des entreprises déjà dans la base extranet
@@ -424,7 +441,8 @@ class wsMaintenance {
                }
        }
 
-       protected static function _importOldUser($oldid) {
+       protected static function _importOldUser($oldid)
+       {
                global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs;
                // Get user from old
                $r = $core->con->select('SELECT * FROM ws.user WHERE uid=\'' . $core->con->escape($oldid) . '\'');
@@ -506,11 +524,13 @@ class wsMaintenance {
                }
        }
 
-       protected static function _sqlIn($tab) {
+       protected static function _sqlIn($tab)
+       {
                return ' IN(\'' . implode('\',\'', $tab) . '\') ';
        }
 
-       protected static function _getLangCode($lang) {
+       protected static function _getLangCode($lang)
+       {
                $lang = strtolower($lang);
                if ($lang == 'cz') {
                        $lang = 'cs';
@@ -518,11 +538,13 @@ class wsMaintenance {
                return $lang;
        }
 
-       public static function dumpDatabase() {
+       public static function dumpDatabase()
+       {
                cubeDb::mysqlDump(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD, ROOT . '/backups/dump-' . date('Y-m-d-H-i-s') . '.sql', true, 8);
        }
 
-       public static function cleanPackages() {
+       public static function cleanPackages()
+       {
                $limit = TIME - (2 * 3600); // 2 heures avant maintenant*
                //
                $dirs = array(
@@ -558,7 +580,8 @@ class wsMaintenance {
                }
        }
 
-       public static function cleanConversionSessions() {
+       public static function cleanConversionSessions()
+       {
                $limit = TIME - (4 * 3600); // 4 heures avant maintenant*
 
                $dir = ROOT . '/cache/conversionSessions/';
@@ -575,7 +598,8 @@ class wsMaintenance {
                }
        }
 
-       public static function cleanUnusedDocs() {
+       public static function cleanUnusedDocs()
+       {
                global $core;
                cubePHP::neverStop();
                $r = $core->con->select('SELECT document_id FROM documents WHERE document_id NOT IN (SELECT document_id FROM book_pages)');
@@ -591,8 +615,14 @@ class wsMaintenance {
                        }
                }
 
+               self::_moveDocs(WS_DOCS, '/data/extranet/www/fluidbook/docs1', 750);
+               self::_moveDocs('/data/extranet/www/fluidbook/docs1', '/data/extranet/www/fluidbook/docs2', 2000);
+       }
+
+       protected static function _moveDocs($from, $to, $keep, $batch = 250)
+       {
                $docs = array();
-               $dr = opendir(WS_DOCS);
+               $dr = opendir($from);
                while ($d = readdir($dr)) {
                        if ($d == '.' || $d == '..') {
                                continue;
@@ -605,16 +635,16 @@ class wsMaintenance {
                }
 
                sort($docs);
-               $docs = array_splice($docs, 0, count($docs) - 750);
+               $docs = array_splice($docs, 0, count($docs) - $keep);
                if (count($docs)) {
-                       $toMove = array_slice($docs, 0, 250);
+                       $toMove = array_slice($docs, 0, $batch);
 
                        foreach ($toMove as $d) {
                                if (trim($d) == '') {
                                        continue;
                                }
-                               $source = WS_DOCS . '/' . $d . '/';
-                               $dest = '/data/extranet/www/fluidbook/docs1/' . $d . '/';
+                               $source = $from . '/' . $d . '/';
+                               $dest = $to . '/' . $d . '/';
                                if (!file_exists($dest)) {
                                        mkdir($dest, 0777, true);
                                }
@@ -627,7 +657,8 @@ class wsMaintenance {
                }
        }
 
-       public static function moveFluidbookDatas() {
+       public static function moveFluidbookDatas()
+       {
                $dir = WS_BOOKS . '/final/';
                $dr = opendir($dir);
                while ($d = readdir($dr)) {
@@ -639,7 +670,8 @@ class wsMaintenance {
                }
        }
 
-       public static function mergeEntreprise($args) {
+       public static function mergeEntreprise($args)
+       {
                global $core;
 
                $from = $args[0];
@@ -654,7 +686,8 @@ class wsMaintenance {
                $core->refreshWSUsersTree();
        }
 
-       public static function updateLuceneTime() {
+       public static function updateLuceneTime()
+       {
                global $core;
                $dao = new wsDAOBook($core->con);
                $books = $dao->selectLuceneTimeNotSet();
@@ -682,7 +715,8 @@ class wsMaintenance {
                }
        }
 
-       public static function makeLuceneIndexes() {
+       public static function makeLuceneIndexes()
+       {
                global $core;
 
                cubePHP::neverStop();
@@ -695,7 +729,8 @@ class wsMaintenance {
                }
        }
 
-       public static function exportSommaire($args) {
+       public static function exportSommaire($args)
+       {
                global $core;
                $book_id = $args[0];
                $dao = new wsDAOBook($core->con);
@@ -712,7 +747,8 @@ class wsMaintenance {
                exit;
        }
 
-       public static function copySommaire($args) {
+       public static function copySommaire($args)
+       {
                global $core;
                $from = $args[0];
                $to = $args[1];
@@ -721,7 +757,8 @@ class wsMaintenance {
                $dao->setChapters($to, json_encode($fbook->chapters));
        }
 
-       public static function copyComposition($args) {
+       public static function copyComposition($args)
+       {
                global $core;
 
                $from = $args[0];
@@ -766,7 +803,8 @@ class wsMaintenance {
                }
        }
 
-       protected static function _duplicateLines($table, $key, $currentKey, $newKey) {
+       protected static function _duplicateLines($table, $key, $currentKey, $newKey)
+       {
                global $core;
                $tmptable = 'tmptable_' . $table . '_' . $newKey;
 
@@ -776,7 +814,8 @@ class wsMaintenance {
                $core->con->execute('DROP TEMPORARY TABLE IF EXISTS ' . $tmptable);
        }
 
-       public static function restoreComposition($args) {
+       public static function restoreComposition($args)
+       {
                global $core;
                $book_id = $args[0];
                if (isset($args[1])) {
@@ -803,11 +842,13 @@ class wsMaintenance {
                }
        }
 
-       public static function getV1Translations() {
+       public static function getV1Translations()
+       {
                wsLang::getV1Translations();
        }
 
-       public static function appendDocument($args) {
+       public static function appendDocument($args)
+       {
                global $core;
                $book_id = $args[0];
                $document_id = $args[1];
@@ -815,7 +856,8 @@ class wsMaintenance {
                $dao->appendDocument($book_id, $document_id);
        }
 
-       public static function reprocessVideos($args) {
+       public static function reprocessVideos($args)
+       {
                global $core;
 
                $book_id = $args[0];
@@ -839,7 +881,8 @@ class wsMaintenance {
                }
        }
 
-       public static function syncLDAP() {
+       public static function syncLDAP()
+       {
                global $core;
                cubePHP::neverStop();
 
@@ -890,7 +933,8 @@ class wsMaintenance {
                return $res;
        }
 
-       public static function createBranch($args) {
+       public static function createBranch($args)
+       {
                commonDroits::min(5);
                $branch = $args[0];
 
@@ -906,7 +950,8 @@ class wsMaintenance {
                echo $git->executeCmd('checkout master');
        }
 
-       public static function deleteBranch($args) {
+       public static function deleteBranch($args)
+       {
                commonDroits::min(5);
                $branch = trim($args[0]);
                if ($branch == 'master' || !$branch) {
@@ -928,7 +973,8 @@ class wsMaintenance {
                self::updateHTML5Sources();
        }
 
-       public static function updateHTML5Sources($args = array(), $externals = true) {
+       public static function updateHTML5Sources($args = array(), $externals = true)
+       {
                $playerDir = WS_COMPILE_ASSETS . '/player/';
                $branchesDir = $playerDir . 'branches/';
                $localDir = $playerDir . 'local/';
@@ -980,7 +1026,8 @@ class wsMaintenance {
                file_put_contents(WS_CACHE . '/activebranches', json_encode($branches));
        }
 
-       public static function cleanDownload($args) {
+       public static function cleanDownload($args)
+       {
                $dirs = [ROOT . '/cache/download/', WS_FILES . '/packager/download'];
                foreach ($dirs as $dir) {
                        cubeFiles::scanRecursiveDir($dir, $files);
@@ -993,7 +1040,8 @@ class wsMaintenance {
                }
        }
 
-       public static function deleteOldFilesFromFTP($args) {
+       public static function deleteOldFilesFromFTP($args)
+       {
                global $core;
                cubePHP::neverStop();
 
@@ -1004,7 +1052,8 @@ class wsMaintenance {
                cubeFiles::deleteFilesOlderThan('/home/ws/www/getpdf', 60);
        }
 
-       public static function reencodeVideos($args) {
+       public static function reencodeVideos($args)
+       {
 
                cubePHP::neverStop();
 
@@ -1028,7 +1077,8 @@ class wsMaintenance {
                }
        }
 
-       public static function correctAutoBookmarkLinks($args) {
+       public static function correctAutoBookmarkLinks($args)
+       {
                global $core;
                $book_id = $args[0];
                wsLinks::getLinksAndRulers($book_id, $links, $rulers);
@@ -1046,12 +1096,14 @@ class wsMaintenance {
                $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Autobookmark links correction', $core->user->utilisateur_id);
        }
 
-       public static function compress() {
+       public static function compress()
+       {
                `gzip /home/extranet/www/fluidbook/docs/*/p*.csv`;
                `gzip /home/extranet/www/fluidbook/docs/*/*.txt`;
        }
 
-       public static function restoreChapters($args) {
+       public static function restoreChapters($args)
+       {
                global $core;
 
                $book_id = $args[0];
@@ -1066,7 +1118,8 @@ class wsMaintenance {
                echo $r->chapters;
        }
 
-       public static function offsetLinksPos($args) {
+       public static function offsetLinksPos($args)
+       {
                global $core;
                $book_id = $args[0];
                $direction = $args[1];
@@ -1093,7 +1146,8 @@ class wsMaintenance {
                $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Offset links positions (' . $direction . ' :: ' . $value . ')', $core->user->utilisateur_id);
        }
 
-       public static function extractTexts($args) {
+       public static function extractTexts($args)
+       {
                global $core;
                $book_id = $args[0];
                $dao = new wsDAOBook($core->con);
@@ -1147,7 +1201,8 @@ class wsMaintenance {
                die('<pre>' . $res . '</pre>');
        }
 
-       public static function _reencodeVideos($book_id, $format) {
+       public static function _reencodeVideos($book_id, $format)
+       {
                wsLinks::getLinksAndRulers($book_id, $links, $rulers);
                foreach ($links as $l) {
                        if ($l['type'] == 10) {
@@ -1157,7 +1212,8 @@ class wsMaintenance {
                }
        }
 
-       public static function syncKadreoMailchimp() {
+       public static function syncKadreoMailchimp()
+       {
                global $core;
 
                set_time_limit(0);
@@ -1193,7 +1249,8 @@ class wsMaintenance {
        }
 
 
-       public static function syncCubedesignersMailchimp() {
+       public static function syncCubedesignersMailchimp()
+       {
                global $core;
 
                set_time_limit(0);
@@ -1254,7 +1311,8 @@ class wsMaintenance {
                echo '<pre>' . print_r($runs, true) . '</pre>';
        }
 
-       public static function resetPlayerVersion() {
+       public static function resetPlayerVersion()
+       {
                global $core;
                $dev = [10000, 10003, 1540, 15571, 15837];
                $r = $core->con->select('SELECT book_id, parametres FROM books WHERE book_id NOT IN(' . implode(',', $dev) . ')');
@@ -1287,7 +1345,8 @@ class wsMaintenance {
        }
 
 
-       public static function getSVGPage($args) {
+       public static function getSVGPage($args)
+       {
 
                global $core;
                $fluidbook = $args[0];
@@ -1315,7 +1374,8 @@ class wsMaintenance {
                exit;
        }
 
-       public static function testSVG() {
+       public static function testSVG()
+       {
                $test = '/home/extranet/www/fluidbook/docs/117077/html/zz%s.svg';
                echo wsTools::optimizeSVG('/home/extranet/www/fluidbook/docs/117077/html/fp11.svg', $test, [150, 300], true);
        }
@@ -1370,16 +1430,17 @@ class wsMaintenance {
        //
        //      }
 
-       public static function svgToFlash() {
+       public static function svgToFlash()
+       {
                $iconSets = array(15);
                $names = array('nav-share' => 'nav-friend',
-                              'nav-bookmarks' => 'nav-bookmark',
-                              'nav-chapters' => 'nav-sommaire',
-                              'nav-download' => 'nav-save',
-                              'nav-fullscreen' => 'nav-fullscreen',
-                              'nav-fullscreen-exit' => 'nav-normalscreen',
-                              'nav-sound-off' => 'nav-soundoff',
-                              'nav-sound-on' => 'nav-soundon',
+                       'nav-bookmarks' => 'nav-bookmark',
+                       'nav-chapters' => 'nav-sommaire',
+                       'nav-download' => 'nav-save',
+                       'nav-fullscreen' => 'nav-fullscreen',
+                       'nav-fullscreen-exit' => 'nav-normalscreen',
+                       'nav-sound-off' => 'nav-soundoff',
+                       'nav-sound-on' => 'nav-soundon',
                );
 
 
@@ -1426,17 +1487,18 @@ class wsMaintenance {
                }
        }
 
-       public static function iconSetToInterface() {
+       public static function iconSetToInterface()
+       {
                $iconSets = array(1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
 
                $names = array('nav-share' => 'nav-friend',
-                              'nav-bookmarks' => 'nav-bookmark',
-                              'nav-chapters' => 'nav-sommaire',
-                              'nav-download' => 'nav-save',
-                              'nav-fullscreen' => 'nav-fullscreen',
-                              'nav-fullscreen-exit' => 'nav-normalscreen',
-                              'nav-sound-off' => 'nav-soundoff',
-                              'nav-sound-on' => 'nav-soundon',
+                       'nav-bookmarks' => 'nav-bookmark',
+                       'nav-chapters' => 'nav-sommaire',
+                       'nav-download' => 'nav-save',
+                       'nav-fullscreen' => 'nav-fullscreen',
+                       'nav-fullscreen-exit' => 'nav-normalscreen',
+                       'nav-sound-off' => 'nav-soundoff',
+                       'nav-sound-on' => 'nav-soundon',
                );
 
                $shares = array('email', 'facebook', 'twitter', 'googleplus', 'linkedin', 'viadeo');
@@ -1529,21 +1591,24 @@ class wsMaintenance {
                }
        }
 
-       public static function installAtlanticCommunicationBook() {
+       public static function installAtlanticCommunicationBook()
+       {
                $exporter = new wsExporter();
                $exporter->export(15316, $x, 'install_ftp', 'online', "atlanticki-01:Tjz3N85h@ftp.cluster023.hosting.ovh.net/www/", '');
                header('Location: http://www.atlantic-international-book-com.com/');
                exit;
        }
 
-       public static function installWescoVentes() {
+       public static function installWescoVentes()
+       {
                $exporter = new wsExporter();
                $exporter->export(16328, $x, 'install_ftp', 'online', "wescogrolj-catalogca:b9uA7U72eW@ftp.cluster023.hosting.ovh.net", '');
                header('Location: https://wesco-group.com/download/Catalogues/2018/Wesco_Rapport_ventes_0-12-ans');
                exit;
        }
 
-       public static function fixStats($args) {
+       public static function fixStats($args)
+       {
                commonDroits::min(5);
                $book = trim($args[0], ' .');
                if (!$book) {
@@ -1557,7 +1622,8 @@ class wsMaintenance {
                `rm -rf /home/stats/www/objects/$book*;/home/stats/www/FWStats.sh /home/stats/www redobook=$book`;
        }
 
-       public static function processInbox() {
+       public static function processInbox()
+       {
 
                $base = WS_FILES . '/INBOX/';
 
@@ -1586,7 +1652,8 @@ class wsMaintenance {
 
        }
 
-       public static function _processPDF($publication) {
+       public static function _processPDF($publication)
+       {
                $fluidbook = new CubeIT_Services_Fluidbook();
                // Login
                $fluidbook->login($publication['user'], 'Jvia*qpkMydh6tZ#euGa');
@@ -1599,7 +1666,8 @@ class wsMaintenance {
                unlink($publication['spl']->getPathname());
        }
 
-       public static function nwbuild($args) {
+       public static function nwbuild($args)
+       {
                wsPackager::package(16200, 'win-exe-html');
        }
 }
index d964e830cbed8b68c82f74a41952ba127d6863e3..143c06b8c3d77fff00302aa6483c659ee850bb48 100644 (file)
@@ -535,13 +535,17 @@ class wsBookParametres extends wsParametres
 
 
                $this->fields['scorm_enable'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Activer SCORM'), 'grade' => 5);
+               $this->fields['scorm_version'] = array('type' => 'combo', 'default' => '1.2', 'editable' => true, 'label' => __('Version du standard SCORM'), 'grade' => 5,
+                       'datas' => array(__('SCORM 1.2') => '1.2',
+                               __('SCORM 2004 4th edition') => '2004')
+               );
                $this->fields['scorm_id'] = array('type' => 'text', 'default' => 'MFMCTE091mobile', 'editable' => true, 'label' => __('Identifiant SCORM'), 'grade' => 5);
                $this->fields['scorm_org'] = array('type' => 'text', 'default' => 'ACME-ORG-1350650111249', 'editable' => true, 'label' => __('Organisation SCORM'), 'grade' => 5);
                $this->fields['scorm_title'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __('Titre SCORM'), 'grade' => 5, 'hint' => __('Laisser vide pour utiliser le titre de la publication'));
                $this->fields['scorm_variables'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __('Variables SCORM'), 'grade' => 5, 'hint' => __('Laisser vide pour utiliser le titre de la publication'));
 
                $this->forms['scorm'] = array('label' => __('SCORM'),
-                       'fieldsnames' => array('scorm_enable', 'scorm_id', 'scorm_org', 'scorm_title', 'scorm_variables'));
+                       'fieldsnames' => array('scorm_enable', 'scorm_version', 'scorm_id', 'scorm_org', 'scorm_title', 'scorm_variables'));
        }
 
 }
index 5b817725be425daab3b2bc48ae3539091b250b51..317020356968febe9c663fe1ce602a5b9ceb4b6f 100644 (file)
@@ -9,7 +9,8 @@
  * @version $Id$
  * @access public
  */
-class wsDocument extends cubeMetier {
+class wsDocument extends cubeMetier
+{
 
        protected $document_id;
        protected $file;
@@ -56,10 +57,11 @@ class wsDocument extends cubeMetier {
        // Number section styles
        protected static
                $numberStyles = array('NoNumber' => 'no', 'DecimalArabicNumerals' => 'decimal',
-                                     'UppercaseRomanNumerals' => 'roman_up', 'LowercaseRomanNumerals' => 'roman_low',
-                                     'UppercaseLetters' => 'letters_up', 'LowercaseLetters' => 'letters_low');
+               'UppercaseRomanNumerals' => 'roman_up', 'LowercaseRomanNumerals' => 'roman_low',
+               'UppercaseLetters' => 'letters_up', 'LowercaseLetters' => 'letters_low');
 
-       public function init() {
+       public function init()
+       {
                $this->out = wsDocument::getDir($this->document_id);
                $this->log = $this->out . '/logs/';
                $this->html = $this->out . '/html/';
@@ -81,22 +83,26 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       public function copyOriginalFromUpload($tmp_file) {
+       public function copyOriginalFromUpload($tmp_file)
+       {
                move_uploaded_file($tmp_file, $this->in);
        }
 
-       public function copyOriginalFromOlderVersion() {
+       public function copyOriginalFromOlderVersion()
+       {
                if (!file_exists($this->in)) {
                        copy('https://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);
                }
        }
 
-       public function extractFonts() {
+       public function extractFonts()
+       {
                $extractor = new wsPDFFontExtractor($this->out, $this);
                $extractor->extract();
        }
 
-       public function getInfos($in = null, $force = false) {
+       public function getInfos($in = null, $force = false)
+       {
                if (is_null($in)) {
                        $in = $this->in;
                }
@@ -134,12 +140,14 @@ class wsDocument extends cubeMetier {
                $this->findCutDisposition();
        }
 
-       public function findCutDisposition() {
+       public function findCutDisposition()
+       {
                $this->detectSpreads();
                $this->detectPageDifferences();
        }
 
-       protected function detectPageDifferences() {
+       protected function detectPageDifferences()
+       {
                $this->addToLog('Detect page differences');
                // Vérifie si la cropbox et la trimbox sont identiques pour toutes les pages
                $difference = false;
@@ -172,7 +180,8 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       protected function detectSpreads() {
+       protected function detectSpreads()
+       {
                $this->addToLog('Detect spreads');
                // Détection des spreads
 
@@ -219,16 +228,19 @@ class wsDocument extends cubeMetier {
                $this->addToLog('Detect Spreads : Manual cut ' . $this->manualcut . ' ; Auto cut : ' . $this->autocut);
        }
 
-       public static function compareSizes($x, $y, $tolerance = 0.9) {
+       public static function compareSizes($x, $y, $tolerance = 0.9)
+       {
                return cubeMath::compare($x[0], $y[0], $tolerance) && cubeMath::compare($x[1], $y[1], $tolerance);
        }
 
-       public function lnCrop() {
+       public function lnCrop()
+       {
                $root = dirname($this->cropped);
                `cd $root;ln -s original.pdf crop.pdf`;
        }
 
-       public function parseInfos($data) {
+       public function parseInfos($data)
+       {
                cubePHP::set_memory('4G');
                // This function get general infos (pages sizes, boxes, number sections and
                // bookmarks
@@ -277,12 +289,14 @@ class wsDocument extends cubeMetier {
                return $res;
        }
 
-       public function getPagesNumber() {
+       public function getPagesNumber()
+       {
                $this->getInfos();
                return $this->generalInfos['pages'];
        }
 
-       public function globalOperations() {
+       public function globalOperations()
+       {
                $this->addToLog('Get infos');
                $this->getInfos();
                if ($this->CropAndCut()) {
@@ -295,7 +309,8 @@ class wsDocument extends cubeMetier {
                $this->splitDoc();
        }
 
-       public function splitDoc() {
+       public function splitDoc()
+       {
                $this->addToLog('Split document');
                mkdir($this->out . '/pdf');
                $pdftk = new cubeCommandLine('pdftk');
@@ -308,7 +323,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($pdftk);
        }
 
-       public function CropAndCut() {
+       public function CropAndCut()
+       {
                $this->addToLog('Crop And Cut');
                if (!$this->isCropped()) {
                        $this->lnCrop();
@@ -327,7 +343,8 @@ class wsDocument extends cubeMetier {
                return false;
        }
 
-       public function cutDocument($mode) {
+       public function cutDocument($mode)
+       {
                $fwstk = new cubeCommandLine('fwstk.sh');
                $fwstk->setPath(CONVERTER_PATH);
                $fwstk->setArg('--input ' . $this->in);
@@ -337,7 +354,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($fwstk);
        }
 
-       public function trimDocument() {
+       public function trimDocument()
+       {
                $fwstk = new cubeCommandLine('fwstk.sh');
                $fwstk->setPath(CONVERTER_PATH);
                $fwstk->setArg('--input ' . $this->in);
@@ -347,7 +365,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($fwstk);
        }
 
-       public function processOnePage($page, $force = true) {
+       public function processOnePage($page, $force = true)
+       {
                if ($force) {
                        $this->addToLog('Processing page #' . $page);
                        $this->makeMiniShot($page);
@@ -356,19 +375,22 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       public function processAllPages() {
+       public function processAllPages()
+       {
                for ($i = 1; $i <= $this->generalInfos['pages']; $i++) {
                        $this->processOnePage($i);
                }
        }
 
-       public function processRange($pages) {
+       public function processRange($pages)
+       {
                foreach ($pages as $i) {
                        $this->processOnePage($i);
                }
        }
 
-       public function getLinks() {
+       public function getLinks()
+       {
                $fwstk = new cubeCommandLine('fwstk.sh');
                $fwstk->setPath(CONVERTER_PATH);
                $fwstk->setArg('--input ' . $this->cropped);
@@ -378,7 +400,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($fwstk);
        }
 
-       public function getHighlightTextsData() {
+       public function getHighlightTextsData()
+       {
                $fwstk = new cubeCommandLine('fwstk.sh');
                $fwstk->setPath(CONVERTER_PATH);
                $fwstk->setArg('--input ' . $this->cropped);
@@ -389,18 +412,21 @@ class wsDocument extends cubeMetier {
                $this->addToLog($fwstk);
        }
 
-       public function getResolutionRatio() {
+       public function getResolutionRatio()
+       {
                $a4surface = 500990; // en pt²
                $docSurface = $this->generalInfos['size'][0] * $this->generalInfos['size'][1]; // en pt²
                // to have the same surface resulting in px, we have to sqrt the ratio between the two surfaces defined above
                return sqrt($a4surface / $docSurface);
        }
 
-       public function makeMiniShot($page) {
+       public function makeMiniShot($page)
+       {
                $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'PNM');
        }
 
-       public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') {
+       public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM')
+       {
                // Make thumbs of $w width
                // resolution 72 make 1pt=1px
                $width = $this->generalInfos['size'][0];
@@ -408,7 +434,8 @@ class wsDocument extends cubeMetier {
                $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
        }
 
-       public function makeShotFixedHeight($page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM') {
+       public function makeShotFixedHeight($page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM')
+       {
                // Make thumbs of $w height
                // resolution 72 make 1pt=1px
                $height = $this->generalInfos['size'][1];
@@ -416,7 +443,8 @@ class wsDocument extends cubeMetier {
                $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
        }
 
-       public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null) {
+       public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null)
+       {
                $error = false;
                if (is_null($in)) {
                        $in = $this->cropped;
@@ -446,7 +474,8 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null) {
+       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)
+       {
                if (is_null($in)) {
                        $in = $this->cropped;
                }
@@ -483,7 +512,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($gs, true, $page);
        }
 
-       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true) {
+       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true)
+       {
                if (is_null($in)) {
                        $in = $this->cropped;
                }
@@ -532,11 +562,13 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       protected function isCropped() {
+       protected function isCropped()
+       {
                return $this->autocrop || $this->manualcrop || $this->autocut || $this->manualcut;
        }
 
-       public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version = null) {
+       public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version = null)
+       {
                $conversionSettings = $this->conversionInfos->pages[$page];
                if (is_null($storeAllChars)) {
                        $storeAllChars = true;
@@ -606,7 +638,8 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       public function makeHTML5Files($page) {
+       public function makeHTML5Files($page)
+       {
                // Then make HD background shots
                $resolutions = array(300 => 85, 150 => 85, 36 => 85);
                $rratio = $this->getResolutionRatio();
@@ -617,7 +650,8 @@ class wsDocument extends cubeMetier {
                $this->makeSVGFile($page);
        }
 
-       public function makeSVGFile($page) {
+       public function makeSVGFile($page)
+       {
                $svgFile = $this->out . '/html/fp' . $page . '.svg';
 
                $pdftocairo = new cubeCommandLine('pdftocairo');
@@ -633,7 +667,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($pdftocairo, true, $page);
        }
 
-       public static function extractTexts($svgFile, $textFile, $force = false) {
+       public static function extractTexts($svgFile, $textFile, $force = false)
+       {
                $do = $force || !file_exists($textFile) || filemtime($svgFile) > filemtime($textFile) || filemtime($textFile) < filemtime(__FILE__);
                if (!$do) {
                        return;
@@ -650,13 +685,13 @@ class wsDocument extends cubeMetier {
                $xpath->registerNamespace("php", "http://php.net/xpath");
                $xpath->registerPhpFunctions('has_not_text');
                $toDelete = array('//svg:defs/svg:clipPath',
-                                 '//svg:defs/svg:image',
-                                 '//svg:defs/svg:path',
-                                 '//svg:defs/svg:pattern',
-                                 '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',
-                                 '/svg:svg/svg:g//svg:path',
-                                 '/svg:svg/svg:g//svg:rect',
-                                 '//svg:use[starts-with(@xlink:href, "#image")]'
+                       '//svg:defs/svg:image',
+                       '//svg:defs/svg:path',
+                       '//svg:defs/svg:pattern',
+                       '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',
+                       '/svg:svg/svg:g//svg:path',
+                       '/svg:svg/svg:g//svg:rect',
+                       '//svg:use[starts-with(@xlink:href, "#image")]'
                );
 
                //global $svglog;
@@ -678,14 +713,16 @@ class wsDocument extends cubeMetier {
                //return $svglog;
        }
 
-       protected function _cleanSVG($svgFile, $page) {
+       protected function _cleanSVG($svgFile, $page)
+       {
                $svglog = self::cleanSVG($svgFile);
 
                $this->addToLog(implode("\n", $svglog), false, $page);
 
        }
 
-       protected function checkObjectsNumber($file, $maxObjects, $page) {
+       protected function checkObjectsNumber($file, $maxObjects, $page)
+       {
                $swfdump = new cubeCommandLine('swfdump', null, true);
                $swfdump->setPath(CONVERTER_PATH);
                $swfdump->setArg(null, $file);
@@ -699,7 +736,8 @@ class wsDocument extends cubeMetier {
                return false;
        }
 
-       protected function dumpSWF($page, $prefix = 'p') {
+       protected function dumpSWF($page, $prefix = 'p')
+       {
                $swfdump = new cubeCommandLine('/usr/local/swftools/special-swfdump/bin/swfdump', null, true);
                $swfdump->setPath(CONVERTER_PATH);
                $swfdump->setArg('t');
@@ -721,7 +759,8 @@ class wsDocument extends cubeMetier {
         * @param integer $method
         * @return
         */
-       protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version = 'stable') {
+       protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version = 'stable')
+       {
                /*
                  -h , --help                    Print short help message and exit
                  -V , --version                 Print version info and exit
@@ -866,12 +905,14 @@ class wsDocument extends cubeMetier {
                }
        }
 
-       protected function _findMultiply($resolution) {
+       protected function _findMultiply($resolution)
+       {
                $resolution /= $this->getResolutionRatio();
                return self::$resolution2multiply[$resolution];
        }
 
-       protected function makeAS3($page) {
+       protected function makeAS3($page)
+       {
                $swffile = $this->out . 'p' . $page . '.swf';
 
                $swfcombine = new cubeCommandLine('swfcombine');
@@ -887,7 +928,8 @@ class wsDocument extends cubeMetier {
                $this->addToLog($swfcombine, true, $page);
        }
 
-       protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4) {
+       protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4)
+       {
                // Fabrique les images
 
                $this->addToLog('Making barbare swf', true, $page);
@@ -943,11 +985,13 @@ class wsDocument extends cubeMetier {
                return '';
        }
 
-       public function resetLog() {
+       public function resetLog()
+       {
                unlink($this->log . '/commons.log.gz');
        }
 
-       public function addToLog($cl, $output = true, $page = null) {
+       public function addToLog($cl, $output = true, $page = null)
+       {
                if ($cl instanceof cubeCommandLine) {
                        $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n";
                        if ($output) {
@@ -986,11 +1030,13 @@ class wsDocument extends cubeMetier {
                $fclose($pointer);
        }
 
-       public function __destruct() {
+       public function __destruct()
+       {
 
        }
 
-       public static function getDir($id) {
+       public static function getDir($id)
+       {
 
                if (!is_array(self::$_docsDir)) {
                        self::$_docsDir = array();
@@ -1002,6 +1048,7 @@ class wsDocument extends cubeMetier {
 
                $new = WS_DOCS . '/' . $id . '/';
                $old = WS_FILES . '/docs1/' . $id . '/';
+               $veryold = WS_FILES . '/docs2/' . $id . '/';
 
                if (file_exists($new . 'p1.swf')) {
                        self::$_docsDir[$id] = $new;
@@ -1009,6 +1056,9 @@ class wsDocument extends cubeMetier {
                } elseif (file_exists($old . 'p1.swf')) {
                        self::$_docsDir[$id] = $old;
                        return $old;
+               } else if (file_exists($veryold . 'p1.swf')) {
+                       self::$_docsDir[$id] = $veryold;
+                       return $veryold;
                }
                if (!file_exists($new)) {
                        mkdir($new, 0777, true);