]> _ Git - cubeextranet.git/commitdiff
wip #2572 @3
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 4 Feb 2019 15:57:19 +0000 (15:57 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 4 Feb 2019 15:57:19 +0000 (15:57 +0000)
inc/ws/Controlleur/class.ws.flash.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/DAO/class.ws.dao.document.php
inc/ws/Util/class.ws.links.php
inc/ws/Util/html5/master/class.ws.html5.links.php
info.php

index 38bd4f06fd82af341ccf6284961177941a59da67..0100a12881931b5b4d962f9d85b49a50a47fe8b2 100644 (file)
@@ -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();
index c578ee54783d78bd0e2c86410ead4eae98e4520f..3c9165517c5381fadfb0ac2b6b4025f6b953a69e 100644 (file)
@@ -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);
                }
index 1f2b96824c18ac224e9540c5739ceb0a72d7d474..64cb80e0bcefeedb94ba75ea8c6185a1efab7f8e 100644 (file)
@@ -1,11 +1,13 @@
 <?php
 
-class wsDAODocument extends commonDAO {
+class wsDAODocument extends commonDAO
+{
 
        public static $normal = array('document_id', 'file', 'proprietaire', 'pages', 'date', 'numberSections', 'version');
        public static $complex = array('localInfos', 'bookmarks', 'generalInfos', 'conversionInfos', 'trim');
 
-       public function singleton($r) {
+       public function singleton($r)
+       {
                $document = new wsDocument();
                foreach (self::$normal as $k) {
                        $document->$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);
        }
 
index c16e6a65f9a342ccf6ca072b8c72c084ee453045..02d2ad51b1f78f4babf2680f1cdf2f71acb6a54e 100644 (file)
@@ -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
index 9237a87caef2574307a337b4108c4caa0c9cbf90..03f771fe6ee84e00d290c69b9ba9ce98e579b210 100644 (file)
@@ -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']) {
index 2786b5e1180096c4f6737cee264406869946bbf0..246cd9f097e68dc22e46377c2d97c1c01aa1a327 100644 (file)
--- a/info.php
+++ b/info.php
@@ -1,4 +1,5 @@
 <?php\r
+//echo base64_encode(sodium_crypto_secretbox_keygen());\r
 trigger_error('test');\r
 phpinfo();\r
 ?>
\ No newline at end of file