From: vincent@cubedesigners.com Date: Mon, 4 Feb 2019 15:57:19 +0000 (+0000) Subject: wip #2572 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=cfe956d51839efb827e875a74bce2c90100a18f6;p=cubeextranet.git wip #2572 @3 --- diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 38bd4f06f..0100a1288 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -687,7 +687,7 @@ class wsFlash extends cubeFlashGateway $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'], $comments, $core->user->utilisateur_id); $daoBook = new wsDAOBook($core->con); - $daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']); + $daoBook->setSpecialLinksAndRulers($this->args['book_id'],$this->args['specialLinks'], $this->args['specialRulers']); if (isset($this->args['getLinks'])) { $this->getLinks(); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index c578ee547..3c9165517 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -615,6 +615,8 @@ class wsDAOBook extends commonDAO $rulers = json_encode(json_decode($rulers, false)); } + $links = wsLinks::encryptLinks($links); + if (is_array($links)) { $links = json_encode($links); } diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 1f2b96824..64cb80e0b 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -1,11 +1,13 @@ $k = $r->$k; @@ -19,7 +21,8 @@ class wsDAODocument extends commonDAO { return $document; } - public function setFluidbookLinksFromCSV($book_id) { + public function setFluidbookLinksFromCSV($book_id) + { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); @@ -33,7 +36,8 @@ class wsDAODocument extends commonDAO { } } - public function restoreLinksVersion($book_id, $update, $user = 0) { + public function restoreLinksVersion($book_id, $update, $user = 0) + { wsLinks::getLinksAndRulers($book_id, $links, $rulers, $update); $this->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Restore links from ' . date('Y-m-d H:i:s', $update), $user); @@ -45,7 +49,8 @@ class wsDAODocument extends commonDAO { } } - public function putLinksFromCSV($document_id) { + public function putLinksFromCSV($document_id) + { $log = array('Copie des liens du PDF vers la base de données'); $document = $this->selectById($document_id); @@ -111,7 +116,8 @@ class wsDAODocument extends commonDAO { return implode("\n", $log); } - public function setLinksAndRulers($book_id, $links, $rulers, $comments = '', $user = 0) { + public function setLinksAndRulers($book_id, $links, $rulers, $comments = '', $user = 0) + { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id, false); @@ -124,6 +130,8 @@ class wsDAODocument extends commonDAO { $links = json_decode($links, false); $rulers = json_decode($rulers, false); + $links = wsLinks::encryptLinks($links); + $t = array(); foreach ($links as $link) { @@ -201,14 +209,16 @@ class wsDAODocument extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function copyLinks($from, $to) { + 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) { + public function setLinksFromOldFluidbook($book_id) + { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); @@ -297,11 +307,13 @@ class wsDAODocument extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function getLinksAndRulers($book_id, &$links, &$rulers, $time = null) { + public function getLinksAndRulers($book_id, &$links, &$rulers, $time = null) + { return wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time); } - public function getLinksVersions($book_id) { + public function getLinksVersions($book_id) + { $r = $this->con->select('SELECT * FROM special_links_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); $specials = array(); @@ -322,7 +334,7 @@ class wsDAODocument extends commonDAO { } $res = array(); - $sql='SELECT l.*,u.prenom,u.nom FROM document_links_versions l LEFT JOIN utilisateurs u ON l.user=u.utilisateur_id WHERE document_id IN(' . implode(',', $docs) . ')'; + $sql = 'SELECT l.*,u.prenom,u.nom FROM document_links_versions l LEFT JOIN utilisateurs u ON l.user=u.utilisateur_id WHERE document_id IN(' . implode(',', $docs) . ')'; $r = $this->con->select($sql); @@ -356,7 +368,8 @@ class wsDAODocument extends commonDAO { return $res; } - public function getNextId() { + public function getNextId() + { $r = $this->con->select('SELECT MAX(document_id) AS document_id FROM documents'); if ($r->document_id < 100000) { return 100000; @@ -364,22 +377,26 @@ class wsDAODocument extends commonDAO { return $r->document_id + 1; } - public function selectById($document_id) { + public function selectById($document_id) + { $r = $this->con->select('SELECT * FROM documents WHERE document_id=\'' . $this->con->escape($document_id) . '\''); return $this->singleton($r); } - public function selectByBookId($book_id) { + public function selectByBookId($book_id) + { $r = $this->con->select('SELECT * FROM documents WHERE document_id IN(SELECT document_id FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\')'); return $this->factory($r); } - public function selectInList($documents_id) { + public function selectInList($documents_id) + { $r = $this->con->select('SELECT * FROM documents WHERE document_id IN(' . implode(',', $documents_id) . ')'); return $this->factory($r); } - public function cree() { + public function cree() + { $document = new wsDocument(); $document->document_id = 'new'; $document->file = ''; @@ -391,7 +408,8 @@ class wsDAODocument extends commonDAO { return $document; } - public function sauve($data) { + public function sauve($data) + { if (!isset($data['document_id'])) { $data['document_id'] = 'new'; } @@ -423,13 +441,15 @@ class wsDAODocument extends commonDAO { return $doc; } - public function updateField($document_id, $fieldName, $value) { + public function updateField($document_id, $fieldName, $value) + { $c = $this->con->openCursor('documents'); $c->$fieldName = $value; $c->update('WHERE document_id=\'' . $this->con->escape($document_id) . '\''); } - public function updateFromObject($document) { + public function updateFromObject($document) + { $data = array(); foreach (self::$normal as $k) { $data[$k] = $document->$k; @@ -440,7 +460,8 @@ class wsDAODocument extends commonDAO { return $this->sauve($data); } - public function getLinksAsExcel($links, $rulers) { + public function getLinksAsExcel($links, $rulers) + { return wsLinks::linksToExcel($links, $rulers); } diff --git a/inc/ws/Util/class.ws.links.php b/inc/ws/Util/class.ws.links.php index c16e6a65f..02d2ad51b 100644 --- a/inc/ws/Util/class.ws.links.php +++ b/inc/ws/Util/class.ws.links.php @@ -13,6 +13,7 @@ class wsLinks { protected static $_testLinkCache = null; + protected static $_linksKey = null; public static function linksToExcel($links, $rulers, $pages = null) { @@ -360,4 +361,72 @@ class wsLinks 'infobulle' => '', 'numerotation' => $numerotation, 'display_area' => '1'); } } + + public static function _getLinkKey() + { + if (self::$_linksKey === null) { + self::$_linksKey = base64_decode('o2p2yYGI8yMEHf+Y5/e6NdTINbbXg3NIo8BODgdhPxI='); + } + return self::$_linksKey; + } + + public static function encryptLinks($links) + { + $res = []; + foreach ($links as $key => $link) { + $res[$key] = self::encryptLinkAttrs($link); + } + return $res; + } + + public static function encryptLinkAttrs($link) + { + if (is_array($link)) { + $link = CubeIT_Util_Object::asObject($link); + } + + if ($link->type != 13 && $link->type != 14) { + return $link; + } + + $attrs = ['image_rollover']; + foreach ($attrs as $attr) { + $link->$attr = trim($link->$attr); + if (strpos($link->$attr, '///') === 0 || $link->$attr == '') { + continue; + } + $link->$attr = '///' . CubeIT_Crypt::safeEncrypt($link->uid . '|||' . $link->$attr, self::_getLinkKey()); + } + return $link; + } + + public static function decryptLink($link) + { + if (is_array($link)) { + $link = CubeIT_Util_Object::asObject($link); + } + + foreach ($link as $attr => $item) { + if (strpos($item, '///') !== 0) { + continue; + } + $v = CubeIT_Crypt::safeDecrypt(substr($item, 3), self::_getLinkKey()); + $e = explode('|||', $v); + if ($e[0] === $link->uid) { + $link->$attr = $e[1]; + } else { + $link->$attr = ''; + } + } + return $link; + } + + public static function decryptLinks($links) + { + $res = []; + foreach ($links as $key => $link) { + $res[$key] = self::decryptLink($link); + } + return $res; + } } \ No newline at end of file diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 9237a87ca..03f771fe6 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -55,8 +55,10 @@ class wsHTML5Link */ public static function getInstance($id, $init, &$compiler) { - $init['scorm'] = self::isScorm($init); + $init = wsLinks::decryptLink($init); + $init = CubeIT_Util_Array::asArray($init); + $init['scorm'] = self::isScorm($init); $init['to'] = self::replaceCustomURL($init['to']); switch ($init['type']) { diff --git a/info.php b/info.php index 2786b5e11..246cd9f09 100644 --- a/info.php +++ b/info.php @@ -1,4 +1,5 @@ \ No newline at end of file