From 904f39712eaaa2705b69df34573a717d60e47c8d Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 29 May 2020 14:14:29 +0000 Subject: [PATCH] wip #3655 @5 --- inc/commons/class.common.core.php | 42 +-- inc/postconfig.inc.php | 28 +- inc/ws/Controlleur/class.ws.ajax.php | 8 +- .../class.ws.conversion.session.php | 2 - inc/ws/Controlleur/class.ws.flash.php | 17 +- inc/ws/Controlleur/class.ws.maintenance.php | 149 +------- inc/ws/Controlleur/class.ws.url.php | 6 + inc/ws/DAO/class.ws.dao.book.php | 2 +- inc/ws/DAO/class.ws.dao.document.php | 353 ------------------ inc/ws/Util/class.ws.links.php | 118 +----- .../icon-bar/class.ws.html5.compiler.php | 3 +- .../html5/master/class.ws.html5.compiler.php | 9 +- .../html5/raster/class.ws.html5.compiler.php | 3 +- inc/ws/Util/packager/class.ws.packager.v1.php | 3 +- 14 files changed, 48 insertions(+), 695 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index a6b1e3e94..6c6b04282 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -342,32 +342,6 @@ class commonCore extends cubeCore $db->documents->index('index_documents_proprietaire', 'BTREE', 'proprietaire'); $db->documents->index('index_documents_version', 'BTREE', 'version'); // . - // Table pages des documents - $db->document_links->document_id('integer', 0, false); - $db->document_links->links('text', 0, false); - $db->document_links->rulers('text', 0, false); - // Clés - $db->document_links->primary('pk_document_links', 'document_id'); - - // . - // Tables versions des liens - $db->document_links_versions->document_id('integer', 0, false); - $db->document_links_versions->links('text', 0, false); - $db->document_links_versions->rulers('text', 0, false); - $db->document_links_versions->comments('varchar', 128, false); - $db->document_links_versions->user('integer', 0, false); - $db->document_links_versions->update('integer', 0, false); - // . - $db->document_links_versions->primary('pk_document_links_version', 'document_id', 'update'); - $db->document_links_versions->index('idx_document_links_version_update', 'BTREE', 'update'); - - $db->special_links_versions->book_id('integer', 0, false); - $db->special_links_versions->links('text', 0, false); - $db->special_links_versions->rulers('text', 0, false); - $db->special_links_versions->update('integer', 0, false); - - $db->special_links_versions->primary('pk_special_links_versionsn', 'book_id', 'update'); - $db->special_links_versions->index('idx_special_links_versions_update', 'BTREE', 'update'); // Table Books $db->books->book_id('integer', 0, false); @@ -582,14 +556,14 @@ class commonCore extends cubeCore . 'GROUP BY e.entreprise_id'); $this->views->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye ' . 'FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise'); -// $this->views->createView('entreprises_ws', 'SELECT e.*, a.prenom AS administrateur, r.nom AS revendeur,a.utilisateur_id AS ws_super_admin, fb.ca AS ca -//FROM entreprises e -//LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id -//LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id -//LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id -//LEFT JOIN ws_entreprises_tree wet ON wet.entreprise_id=r.entreprise_id -//LEFT JOIN ca_fluidbook fb ON e.entreprise_id=fb.client -//LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); + $this->views->createView('entreprises_ws', 'SELECT e.*, a.prenom AS administrateur, r.nom AS revendeur,a.utilisateur_id AS ws_super_admin, fb.ca AS ca +FROM entreprises e +LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id +LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id +LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id +LEFT JOIN ws_entreprises_tree wet ON wet.entreprise_id=r.entreprise_id +LEFT JOIN ca_fluidbook fb ON e.entreprise_id=fb.client +LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); $this->views->createView('clients_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, e.site AS site, e.type AS type ' . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0'); $this->views->createView('utilisateurs_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, ' diff --git a/inc/postconfig.inc.php b/inc/postconfig.inc.php index 2525e2a1a..1bc4bcc4e 100644 --- a/inc/postconfig.inc.php +++ b/inc/postconfig.inc.php @@ -6,7 +6,7 @@ $ws = !$extranet; $theme = false; if ($_SERVER['HTTP_HOST'] == 'workshop.studio-france.com') { - $theme = 'studiofrance'; + $theme = 'studiofrance'; } @@ -18,18 +18,12 @@ define('DEV', $dev); //define('DB_HOST', ':/var/run/mysqld/mysqld.sock'); -if ($_SERVER['SERVER_ADDR'] == '91.121.74.76') { - define('AMARCORD', true); - define('SERVER', 'amarcord'); - define('DB_HOST', 'alien.cubedesigners.com'); -} else { - - define('SERVER', 'alien'); - define('DB_HOST', '127.0.0.1'); - define('AMARCORD', false); - -} -define('DB_NAME', 'extranet'); +define('SERVER', 'alien'); +//define('DB_HOST', '127.0.0.1'); +define('DB_HOST', 'localhost'); +//define('DB_HOST', ':/var/run/mysqld/mysqld.sock'); +define('AMARCORD', false); +define('DB_NAME', 'extranet_clean'); define('DB_USER', 'extranet'); define('DB_PASSWORD', 'WvcAeYBDnrB93RXa'); @@ -38,9 +32,9 @@ define('WS_URL', SCHEME . '://workshop.fluidbook.com'); if ($ws) { - define('MODE', 'ws'); + define('MODE', 'ws'); } elseif ($extranet) { - define('MODE', 'extranet'); + define('MODE', 'extranet'); } define('STATIC_SERVER', SCHEME . '://' . $_SERVER['HTTP_HOST'] . WEBROOT); @@ -53,9 +47,9 @@ define('SYSIMG', ROOT . '/images/' . MODE); define('IMG', WEBROOT . '/images/' . MODE); if (THEME) { - $faviconroot = IMG . '/white/' . THEME . '/favicon'; + $faviconroot = IMG . '/white/' . THEME . '/favicon'; } else { - $faviconroot = IMG . '/favicon'; + $faviconroot = IMG . '/favicon'; } diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 957d7a2e3..c8c32f9f8 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -943,10 +943,6 @@ class wsAjax extends cubeAjax // New Way wsLinks::saveLinksInFile($book_id, $core->user->utilisateur_id, $comments, $links, $rulers); - - // Old way - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), $comments, $core->user->utilisateur_id); } protected function _importLinksAsAutobookmarkText($book_id) @@ -954,9 +950,7 @@ class wsAjax extends cubeAjax global $core; wsLinks::getLinksFromAutobookmarkText(file_get_contents($_FILES['file']['tmp_name']), $links, $rulers); - - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from fwstk text export', $core->user->utilisateur_id); + wsLinks::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Import links from Autobookmark file', $links, $rulers); } public static function offsetLinks($args, &$x) diff --git a/inc/ws/Controlleur/class.ws.conversion.session.php b/inc/ws/Controlleur/class.ws.conversion.session.php index e48bd44eb..6dfe41916 100644 --- a/inc/ws/Controlleur/class.ws.conversion.session.php +++ b/inc/ws/Controlleur/class.ws.conversion.session.php @@ -145,8 +145,6 @@ class wsConversionSession if (!$this->reload) { wsLinks::addLinksFromPDF($this->bookId); - $log = $dao->putLinksFromCSV($this->currentDoc->document_id); - $this->currentDoc->addToLog($log); } $this->processedDoc++; diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index fe65ebac9..41d5e49d0 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -612,8 +612,7 @@ class wsFlash extends cubeFlashGateway $maxHeight = max($size[1], $maxHeight); } - - $daoDoc->getLinksAndRulersFromFile($this->args['book_id'], $links, $rulers); + wsLinks::getLinksAndRulersFromFile($this->args['book_id'], $links, $rulers); $this->json = true; @@ -695,13 +694,6 @@ class wsFlash extends cubeFlashGateway $comments = isset($this->args['comments']) ? $this->args['comments'] : 'Saved from editor'; - // - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'], $comments, $core->user->utilisateur_id, false); - - $daoBook = new wsDAOBook($core->con); - $daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']); - wsLinks::saveLinksInFile($this->args['book_id'], $core->user->utilisateur_id, $comments, $this->args['links'], $this->args['rulers'], $this->args['specialLinks'], $this->args['specialRulers']); @@ -862,13 +854,6 @@ class wsFlash extends cubeFlashGateway $this->xml->addChild('texts', json_encode($GLOBALS['__l10n'])); } - public function copyLinks() - { - global $core; - $daoDocument = new wsDAODocument($core->con); - $daoDocument->copyLinks($this->args['fromDoc'], $this->args['toDoc']); - } - public function compile() { global $core; diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index db20a09a0..5a0d93621 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -54,73 +54,6 @@ class wsMaintenance } } - public static function compactLinks() - { - global $core; - $r = $core->con->select('SELECT * FROM `document_links_versions` GROUP BY document_id,links,rulers'); - $keep = array(); - while ($r->fetch()) { - if (!isset($keep[$r->document_id])) { - $keep[$r->document_id] = array(); - } - $keep[$r->document_id][] = $r->update; - } - - foreach ($keep as $document_id => $dates) { - $core->con->execute('DELETE FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update` NOT IN(' . implode(',', $dates) . ')'); - } - } - - public static function checkSerializeLinks() - { - global $core; - $r = $core->con->select('SELECT * FROM document_links_versions'); - while ($r->fetch()) { - if (substr($r->links, 1, 1) == ':') { - $links = unserialize($r->links); - $rulers = unserialize($r->rulers); - $c = $core->con->openCursor('document_links_versions'); - $c->rulers = json_encode($rulers); - $c->links = json_encode($links); - $c->update('WHERE document_id=' . $r->document_id . ' AND `update`=' . $r->update); - } - } - } - - public static function moveLinksToVersionDB() - { - global $core; - $r = $core->con->select('SELECT * FROM document_links'); - $d = array(); - while ($r->fetch()) { - if (!isset($d[$r->document_id])) { - $d[$r->document_id] = array(); - } - if (!isset($d[$r->document_id][$r->update])) { - $d[$r->document_id][$r->update] = array(); - } - if (!isset($d[$r->document_id][$r->update][$r->document_page])) { - $d[$r->document_id][$r->update]['links'][$r->document_page] = json_decode($r->links); - $d[$r->document_id][$r->update]['rulers'][$r->document_page] = json_encode($r->rulers); - } - } - - $c = $core->con->openCursor('document_links_versions'); - foreach ($d as $document_id => $updates) { - $c->document_id = $document_id; - foreach ($updates as $date => $dummy) { - $c->update = $date; - $c->links = json_encode($d[$document_id][$date]['links']); - $c->rulers = json_encode($d[$document_id][$date]['rulers']); - try { - $c->insert(); - } catch (Exception $e) { - // fb($e); - } - } - } - } - public static function importFromOldWS($args) { global $core; @@ -271,11 +204,10 @@ class wsMaintenance $to = $args[1]; global $core; - $dao = new wsDAODocument($core->con); + wsLinks::getLinksAndRulersFromFile($from, $fromlinks, $fromrulers); - $dao->getLinksAndRulers($from, $fromlinks, $fromrulers); if (!$eraseTo) { - $dao->getLinksAndRulers($to, $tolinks, $torulers); + wsLinks::getLinksAndRulersFromFile($to, $tolinks, $torulers); $tolinks = array_merge($tolinks, $fromlinks); $torulers = array_merge($torulers, $fromrulers); @@ -296,8 +228,7 @@ class wsMaintenance $cmd = "cp -r $wf1 $wt"; echo `$cmd`; } - - $dao->setLinksAndRulers($to, $tolinks, $torulers, 'Copy links from #' . $from . ' to #' . $to, $core->user->utilisateur_id); + wsLinks::saveLinksInFile($to, $core->user->utilisateur_id, 'Copy links from #' . $from . ' to #' . $to, $tolinks, $torulers); } public static function importBooks($oldBooks) @@ -788,8 +719,6 @@ class wsMaintenance $newid = $r->document_id + 1; self::_duplicateLines('documents', 'document_id', $doc, $newid); - self::_duplicateLines('document_links', 'document_id', $doc, $newid); - self::_duplicateLines('document_links_versions', 'document_id', $doc, $newid); $f = wsDocument::getDir($doc); $t = WS_DOCS . '/' . $newid; @@ -875,9 +804,7 @@ class wsMaintenance $dir = WS_BOOKS . '/working/' . $book_id; - $dao = new wsDAODocument($core->con); - $dao->getLinksAndRulers($book_id, $links, $rulers); - + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); foreach ($links as $link) { if ($link['type'] != 4) { continue; @@ -1074,7 +1001,7 @@ class wsMaintenance $format = $args[1]; $dir = WS_BOOKS . '/working/' . $book_id; - wsLinks::getLinksAndRulers($book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); foreach ($links as $link) { if ($link['type'] != 4) { @@ -1094,7 +1021,7 @@ class wsMaintenance { global $core; $book_id = $args[0]; - wsLinks::getLinksAndRulers($book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); $newlinks = array(); foreach ($links as $link) { @@ -1105,8 +1032,7 @@ class wsMaintenance $newlinks[] = $link; } - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Autobookmark links correction', $core->user->utilisateur_id); + wsLinks::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Autobookmark links correction', $newlinks, $rulers); } public static function compress() @@ -1137,7 +1063,7 @@ class wsMaintenance $book_id = $args[0]; $direction = $args[1]; $value = intval($args[2]); - wsLinks::getLinksAndRulers($book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); if ($direction == 'y') { $k = 'top'; @@ -1155,8 +1081,7 @@ class wsMaintenance $newlinks[] = $link; } - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Offset links positions (' . $direction . ' :: ' . $value . ')', $core->user->utilisateur_id); + wsLinks::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Offset links positions (' . $direction . ' :: ' . $value . ')', $newlinks, $rulers); } public static function duplicateBook($args) @@ -1234,7 +1159,7 @@ class wsMaintenance public static function _reencodeVideos($book_id, $format) { - wsLinks::getLinksAndRulers($book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); foreach ($links as $l) { if ($l['type'] == 10) { $to = $l['to']; @@ -1736,60 +1661,6 @@ class wsMaintenance $exporter->export($id, $x, 'install_hosting', 'online', "/airtahitiexport/" . $id, ''); } } - - public static function moveLinksToFiles($args) - { - CubeIT_Util_PHP::neverStop(); - - global $core; - - if (isset($args[0]) && $args[0]) { - $books = [$args[0]]; - } else { - $r = $core->con->select('SELECT * FROM books ORDER BY book_id DESC'); - $books = []; - while ($r->fetch()) { - $books[] = $r->book_id; - } - } - - - foreach ($books as $id) { - $dir = wsLinks::getLinksDir($id); - /** @var $book wsBook */ - $dao = new wsDAODocument($core->con); - $updates = $dao->getLinksVersions($id); - - $max = 0; - foreach ($updates as $time => $update) { - $max = max($max, $time); - self::_writeLinks($id, $dir, $time, $update); - } - self::_writeLinks($id, $dir, $max, $updates[$max], 'latest'); - } - } - - protected static function _writeLinks($book_id, $dir, $time, $data, $version = 'time') - { - if ($version === 'time') { - $version = $time; - } - - $file = $dir . '/' . $version . '.links.gz'; - $meta = $dir . '/' . $version . '.meta.gz'; - if (file_exists($file)) { - return; - } - - $links = []; - $rulers = []; - - wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time); - - $res = ['links' => $links, 'rulers' => $rulers]; - file_put_contents($file, gzencode(json_encode($res))); - file_put_contents($meta, gzencode(json_encode($data))); - } } diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 2bfb33221..68544929a 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -1715,6 +1715,7 @@ html.tall{height:150%}' . "\n"; public static function clients($args) { global $core; + cubePage::truePopup(); cubePage::autoComplete(); cubePage::emptyfield(); @@ -1756,12 +1757,16 @@ html.tall{height:150%}' . "\n"; $admin = wsDroits::admin(); + + + if ($admin) { $liste = $dao->getListe($settings['orderby'], $settings['sens'], $settings['limit'], null, 'entreprises_ws'); } else { $liste = $dao->getListe($settings['orderby'], $settings['sens'], $settings['limit'], $core->user, 'entreprises_ws'); } + $res = ''; $res .= ''; $res .= ''; @@ -1774,6 +1779,7 @@ html.tall{height:150%}' . "\n"; } $res .= ''; $i = 0; + foreach ($liste as $id => $client) { if (!is_array($client->contacts)) { $client->contacts = array(); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 374169ff2..2292a2276 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -1379,7 +1379,7 @@ class wsDAOBook extends commonDAO $this->makeTextsIndexes($book, $pages, $index, $textes); - $daoDoc->getLinksAndRulers($book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers); $audiodescription = array(); diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 024ee5df0..355a4e8e6 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -25,19 +25,6 @@ class wsDAODocument extends commonDAO { // New way wsLinks::addLinksFromPDF($book_id); - - // Old way - $daoBook = new wsDAOBook($this->con); - $pages = $daoBook->getPagesOfBook($book_id); - - foreach ($pages as $page => $infos) { - $docs[] = $infos['document_id']; - } - - $docs = array_unique($docs); - foreach ($docs as $document_id) { - $this->putLinksFromCSV($document_id); - } } public function restoreLinksVersion($book_id, $update, $user = 0) @@ -47,346 +34,6 @@ class wsDAODocument extends commonDAO // New way wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $update); wsLinks::saveLinksInFile($book_id, $user, $comments, $links, $rulers, [], []); - - // OLD Way - wsLinks::getLinksAndRulers($book_id, $links, $rulers, $update); - - $this->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), $comments, $user); - - $r = $this->con->select('SELECT * FROM special_links_versions WHERE `update`=' . $update . ' AND book_id=\'' . $this->con->escape($book_id) . '\''); - if ($r->count()) { - $daoBook = new wsDAOBook($this->con); - $daoBook->setSpecialLinksAndRulers($book_id, $r->links, $r->rulers); - } - } - - public function putLinksFromCSV($document_id) - { - $log = array('Copie des liens du PDF vers la base de données'); - $document = $this->selectById($document_id); - - $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on'); - - $links = array(); - - for ($page = 1; $page <= $document->generalInfos['pages']; $page++) { - $links[$page] = array(); - - $csv = wsDocument::getDir($document->document_id) . '/p' . $page . '.csv'; - if (!file_exists($csv) && file_exists($csv . '.gz')) { - $csv = 'compress.zlib://' . $csv . '.gz'; - } elseif (!file_exists($csv)) { - $log[] = 'Links file of page ' . $page . ' not found'; - continue; - } - - $newformat = (filemtime($csv) > 1363685416); - - $log[] = 'Links file of page ' . $page . ' found'; - - $fp = fopen($csv, 'rb'); - - while (true) { - $line = fgetcsv($fp, 512, ';', '"'); - // End of file - if (!$line) { - break; - } - // Commentaire || ligne vide - if (substr($line[0], 0, 1) == '#' || is_null($line[0])) { - continue; - } - $link = array(); - if ($newformat) { - $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical'); - } else { - $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical'); - } - $k = 0; - foreach ($cols as $col => $default) { - if (isset($line[$k])) { - if (in_array($k, $booleans)) { - $link[$col] = ($line[$k] == '1'); - } else { - $link[$col] = utf8_encode($line[$k]); - } - } else { - $link[$col] = $default; - } - $k++; - } - $link['page'] = $page; - $links[$page][] = $link; - } - - $log[] = 'Added ' . count($links) . ' links'; - } - - wsLinks::setDocumentLinks($document_id, json_encode($links), json_encode(array()), 0, 'Links imported from PDF', TIME); - - - return implode("\n", $log); - } - - public function setLinksAndRulers($book_id, $links, $rulers, $comments = '', $user = 0, $handleSpecials = true) - { - $daoBook = new wsDAOBook($this->con); - $pages = $daoBook->getPagesOfBook($book_id, false); - - if (is_array($links)) { - $links = json_encode($links); - } - if (is_array($rulers)) { - $rulers = json_encode($rulers); - } - $links = json_decode($links, false); - $rulers = json_decode($rulers, false); - - $links = wsLinks::encryptLinks($links); - - $t = array(); - - foreach ($links as $link) { - if (!isset($t[$link->page])) { - $t[$link->page] = array('links' => array(), 'rulers' => array()); - } - $link->to = trim($link->to); - $t[$link->page]['links'][] = $link; - } - foreach ($rulers as $ruler) { - if (!isset($t[$ruler->page])) { - $t[$ruler->page] = array('links' => array(), 'rulers' => array()); - } - $t[$ruler->page]['rulers'][] = $ruler; - } - - $links = array(); - $rulers = array(); - - foreach ($pages as $p) { - if (!isset($links[$p['document_id']])) { - $links[$p['document_id']] = array(); - $rulers[$p['document_id']] = array(); - } - - if (!isset($links[$p['document_id']][$p['document_page']])) { - $links[$p['document_id']][$p['document_page']] = array(); - $rulers[$p['document_id']][$p['document_page']] = array(); - } - } - - $specialLinks = array(); - $specialRulers = array(); - - foreach ($t as $page => $tt) { - if (!is_int($page) && $handleSpecials) { - if (isset($tt['links'])) { - $specialLinks = array_merge($specialLinks, $tt['links']); - } - if (isset($tt['rulers'])) { - $specialRulers = array_merge($specialRulers, $tt['rulers']); - } - continue; - } - - if (!isset($pages[$page])) { - continue; - } - - $infos = $pages[$page]; - $doc_id = $infos['document_id']; - $doc_page = $infos['document_page']; - - if (!isset($links[$doc_id])) { - $links[$doc_id] = array(); - $rulers[$doc_id] = array(); - } - if (!isset($links[$doc_id][$doc_page])) { - $links[$doc_id][$doc_page] = array(); - $rulers[$doc_id][$doc_page] = array(); - } - - foreach ($tt['links'] as $link) { - $link->to = trim($link->to); - $links[$doc_id][$doc_page][] = $link; - } - - foreach ($tt['rulers'] as $ruler) { - $rulers[$doc_id][$doc_page][] = $ruler; - } - } - - foreach ($links as $document_id => $dummy) { - wsLinks::setDocumentLinks($document_id, json_encode($links[$document_id]), json_encode($rulers[$document_id]), $user, $comments, TIME); - } - if ($handleSpecials) { - $daoBook->setSpecialLinksAndRulers($book_id, $specialLinks, $specialRulers); - } - - $c = $this->con->openCursor('books'); - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function copyLinks($from, $to) - { - $sql = 'REPLACE INTO document_links_versions (`document_id`,`links`,`rulers`,`update`) ' - . 'SELECT \'' . $to . '\',`links`,`rulers`,`update` FROM document_links_versions WHERE document_id=\'' . $from . '\''; - - $this->con->execute($sql); - } - - public function setLinksFromOldFluidbook($book_id) - { - $daoBook = new wsDAOBook($this->con); - $pages = $daoBook->getPagesOfBook($book_id); - - $book = $daoBook->selectById($book_id); - $width = $book->parametres->width; - - $xml = simplexml_load_file('https://ws.fluidbook.com/books/' . $book_id . '/data/links.xml'); - echo $xml; - $links = $xml->xpath('//oneLink'); - - $res = array(); - $lpages = array(); - foreach ($links as $l) { - if ((string)$l->page == '') { - continue; - } - - $left = floatval((string)$l->startX); - $right = floatval((string)$l->endX); - $top = floatval((string)$l->startY); - $bottom = floatval((string)$l->endY); - - $lwidth = abs($right - $left); - $lheight = abs($bottom - $top); - - $left = min($left, $right); - $top = min($top, $bottom); - - $link = array(); - $link['page'] = (string)$l->page; - $link['numerotation'] = false; - $link['left'] = $left; - $link['width'] = $lwidth; - if ($link['left'] > $width) { - $link['page']++; - $link['left'] -= $width; - } - $page = $link['page']; - $link['top'] = $top; - $link['height'] = $lheight; - $link['infobulle'] = ''; - $link['target'] = '_blank'; - $link['to'] = (string)$l->linkTo; - $link['type'] = intval((string)$l->linkType); - $link['video_loop'] = ((string)$l->loopFlag == '1'); - $link['video_auto_start'] = true; - $link['video_controls'] = ((string)$l->playerActive == '1'); - $link['video_sound_on'] = ((string)$l->soundOn == '1'); - - $dir = WS_BOOKS . '/working/' . $book_id . '/'; - - if ($link['type'] == '4' || $link['type'] == '6') { - if (!stristr($link['to'], ':/')) { - if (!file_exists($dir)) { - mkdir($dir, 0755, true); - } - copy('https://ws.fluidbook.com/books/' . $book_id . '/data/' . $link['to'], $dir . '/' . $link['to']); - } - } - - if (!isset($lpages[$page])) { - $lpages[$page] = array(); - } - $lpages[$page][] = $link; - } - - - $links = array(); - foreach ($pages as $p => $infos) { - if (!isset($links[$infos['document_id']])) { - $links[$infos['document_id']] = array(); - } - if (isset($lpages[$p])) { - $links[$infos['document_id']][$infos['document_page']] = $lpages[$p]; - } - } - - krsort($links); - - foreach ($links as $document_id => $l) { - wsLinks::setDocumentLinks($document_id, json_encode($l), json_encode(array()), 0, 'Import from Fluidbook V1', TIME); - } - - $c = $this->con->openCursor('books'); - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - - public function getLinksAndRulers($book_id, &$links, &$rulers, $time = null) - { - return wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time); - } - - public function getLinksAndRulersFromFile($book_id, &$links, &$rulers, $time = 'latest') - { - return wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $time); - } - - public function getLinksVersions($book_id) - { - - $r = $this->con->select('SELECT * FROM special_links_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - $specials = ['links' => 0, 'rulers' => 0]; - while ($r->fetch()) { - $ll = json_decode($r->links); - $lr = json_decode($r->rulers); - $specials[$r->update] = ['links' => count($ll), 'rulers' => count($lr)]; - } - - // Get composition versions - $r = $this->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - $docs = []; - while ($r->fetch()) { - $c = unserialize($r->composition); - foreach ($c as $infos) { - $docs[] = $infos['document_id']; - } - } - - if (!$docs) { - return []; - } - - $res = array(); - $sql = 'SELECT * FROM document_links_versions WHERE document_id IN(' . implode(',', $docs) . ')'; - $r = $this->con->select($sql); - - while ($r->fetch()) { - if (!isset($res[$r->update])) { - if (isset($specials[$r->update])) { - $res[$r->update] = $specials[$r->update]; - } else { - $res[$r->update] = array('links' => 0, 'rulers' => 0); - } - } - - $ll = json_decode($r->links); - foreach ($ll as $lll) { - $res[$r->update]['links'] += count($lll); - } - $rr = json_decode($r->rulers); - foreach ($rr as $rrr) { - $res[$r->update]['rulers'] += count($rrr); - } - $res[$r->update]['comments'] = $r->comments; - $res[$r->update]['user'] = $r->user; - } - - return $res; } public function getNextId() diff --git a/inc/ws/Util/class.ws.links.php b/inc/ws/Util/class.ws.links.php index a22f1ad60..aef5e13fe 100644 --- a/inc/ws/Util/class.ws.links.php +++ b/inc/ws/Util/class.ws.links.php @@ -148,125 +148,9 @@ class wsLinks return false; } - public static function setDocumentLinks($document_id, $links, $rulers, $user, $comments, $time) - { - global $core; - $c = $core->con->openCursor('document_links_versions'); - $c1 = $core->con->openCursor('document_links'); - $c1->document_id = $c->document_id = $document_id; - $c1->links = $c->links = $links; - $c1->rulers = $c->rulers = $rulers; - $c->comments = $comments; - $c->user = $user; - $c->update = $time; - $c->insert(); - - $core->con->execute('DELETE FROM document_links WHERE document_id=' . $document_id); - $c1->insert(); - } - - public static function getDocumentLastLinks($document_id) - { - global $core; - - $r = $core->con->select('SELECT * FROM document_links WHERE document_id=\'' . $document_id . '\''); - if (!$r->count()) { - $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' ORDER BY `update` DESC LIMIT 1'); - $c = $core->con->openCursor('document_links'); - $c->document_id = $document_id; - $c->links = $r->links; - $c->rulers = $r->rulers; - try { - $c->insert(); - } catch (Exception $e) { - fb($e); - } - } - - return self::_recordToLinks($r); - } - - public static function getDocumentVersionLinks($document_id, $time) - { - global $core; - $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update`<=' . $time . ' ORDER BY `update` DESC LIMIT 1'); - return self::_recordToLinks($r); - } - - protected static function _recordToLinks($r) - { - if (mb_substr($r->links, 1, 1) == ':') { - $ll = unserialize($r->links); - $rr = unserialize($r->rulers); - } else { - $ll = json_decode($r->links, true); - $rr = json_decode($r->rulers, true); - } - - return array('links' => $ll, 'rulers' => $rr); - } - public static function getLinksAndRulers($book_id, &$links, &$rulers, $time = null) { - global $core; - - $daoBook = new wsDAOBook($core->con); - $pages = $daoBook->getPagesOfBookAt($book_id, $time); - - $documents = []; - foreach ($pages as $p => $infos) { - $documents[] = $infos['document_id']; - } - $documents = array_unique($documents); - - $tlinks = array(); - $trulers = array(); - - $links = array(); - $rulers = array(); - - foreach ($documents as $d) { - if (is_null($time)) { - $lr = self::getDocumentLastLinks($d); - } else { - $lr = self::getDocumentVersionLinks($d, $time); - } - $tlinks[$d] = $lr['links']; - $trulers[$d] = $lr['rulers']; - } - - $i = 1; - foreach ($pages as $p => $infos) { - if (isset($tlinks[$infos['document_id']][$infos['document_page']])) { - $l = $tlinks[$infos['document_id']][$infos['document_page']]; - foreach ($l as $link) { - $link = (array)$link; - $link['page'] = $p; - $link['id'] = $i; - if (!isset($link['rot'])) { - $link['rot'] = 0; - } - $links[] = $link; - $i++; - } - } - if (isset($trulers[$infos['document_id']][$infos['document_page']])) { - $ru = $trulers[$infos['document_id']][$infos['document_page']]; - if (is_array($ru)) { - foreach ($ru as $ruler) { - $ruler['page'] = $p; - $rulers[] = $ruler; - } - } - } - - } - - $daoBook = new wsDAOBook($core->con); - $book = $daoBook->selectById($book_id); - - $rulers = array_merge($rulers, $book->specialRulers); - $links = array_merge($links, $book->specialLinks); + return self::getLinksAndRulersFromFile($book_id,$links,$rulers,$time); } public static function getLinksAndRulersFromFile($book_id, &$links, &$rulers, $time = 'latest') diff --git a/inc/ws/Util/html5/icon-bar/class.ws.html5.compiler.php b/inc/ws/Util/html5/icon-bar/class.ws.html5.compiler.php index 28a2c666b..ad538e166 100644 --- a/inc/ws/Util/html5/icon-bar/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/icon-bar/class.ws.html5.compiler.php @@ -1239,8 +1239,7 @@ class wsHTML5Compiler $this->vdir->copyDirectory($d['dir'], $d['fdir']); } - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers); // Custom landing page content if ($this->book->parametres->landingPage != '') { diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index c18bab25e..735e336f2 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -2373,8 +2373,11 @@ class wsHTML5Compiler return $res; } - public function addFontKit($font){ - $this->vdir->copyDirectory('style/fonts/Montserrat'); + public function addFontKit($font) + { + $path = 'style/fonts/Montserrat'; + $this->stylesheets[] = $path . '/font.css'; + $this->vdir->copyDirectory($this->assets . '/' . $path, $path); } public function writeArticles() @@ -2391,7 +2394,7 @@ class wsHTML5Compiler return; } - if($this->book->parametres->articlesFont!=='OpenSans'){ + if ($this->book->parametres->articlesFont !== 'OpenSans') { $this->addFontKit($this->book->parametres->articlesFont); } diff --git a/inc/ws/Util/html5/raster/class.ws.html5.compiler.php b/inc/ws/Util/html5/raster/class.ws.html5.compiler.php index cf0b403da..803f2de47 100644 --- a/inc/ws/Util/html5/raster/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/raster/class.ws.html5.compiler.php @@ -1208,8 +1208,7 @@ class wsHTML5Compiler $this->vdir->copyDirectory($d['dir'], $d['fdir']); } - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers); // Custom landing page content if ($this->book->parametres->landingPage != '') { diff --git a/inc/ws/Util/packager/class.ws.packager.v1.php b/inc/ws/Util/packager/class.ws.packager.v1.php index a88a9aaad..a0e7d7f35 100644 --- a/inc/ws/Util/packager/class.ws.packager.v1.php +++ b/inc/ws/Util/packager/class.ws.packager.v1.php @@ -82,8 +82,7 @@ class wsPackagerV1 extends wsPackagerHTML { */ $xml = simplexml_load_string(''); - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers); foreach ($links as $link) { $one = $xml->addChild('oneLink'); -- 2.39.5
' . commonUrl::orderby('#', 'entreprise_id', $settings, 'sort' . $change) . '' . commonUrl::orderby(__('Raison sociale'), 'nom', $settings, 'sort' . $change) . '