]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5641 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Dec 2022 15:40:14 +0000 (16:40 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Dec 2022 15:40:14 +0000 (16:40 +0100)
app/Util/FluidbookLinks.php
resources/views/fluidbook_publication/link_editor.blade.php

index 9cc37eb8d2e2fafaeb966486e50de63da5156bbb..cf6cc283052f0d46b4099a6a0de9fd3b830a4b56 100644 (file)
@@ -9,6 +9,7 @@ use Cubist\Util\Crypt;
 use Cubist\Util\Files\Files;
 use Cubist\Util\ObjectUtil;
 use Cubist\Util\Str;
+use Fluidbook\Tools\Links\Link;
 use PhpOffice\PhpSpreadsheet\Cell\DataType;
 use PhpOffice\PhpSpreadsheet\Exception;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -160,6 +161,12 @@ class FluidbookLinks
         $r = json_decode(gzdecode(file_get_contents($file)), true);
         $links = self::_UID($r['links']);
         $rulers = self::_UID($r['rulers']);
+        if (can('fluidbook-publication:links:edit-animations')) {
+            $links = Link::decryptLinks($links);
+        }else{
+            $links = Link::encryptLinks($links);
+        }
+
         self::_correctImageSpecialLinks($links);
     }
 
@@ -291,93 +298,6 @@ class FluidbookLinks
         self::_correctImageSpecialLinks($links);
     }
 
-    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;
-    }
-
-    /**
-     * @throws SodiumException
-     */
-    public static function encryptLinkAttrs($link)
-    {
-        if (is_array($link)) {
-            $link = ObjectUtil::asObject($link);
-        }
-
-        $crypted = [13, 14, 35];
-
-        if (!isset($link->type) || !in_array($link->type, $crypted)) {
-            return $link;
-        }
-
-        $attrs = ['image_rollover'];
-        foreach ($attrs as $attr) {
-            if (!isset($link->$attr)) {
-                continue;
-            }
-            $link->$attr = trim($link->$attr);
-            if (str_starts_with($link->$attr, '///') || $link->$attr == '') {
-                continue;
-            }
-            $link->$attr = '///' . Crypt::safeEncrypt($link->uid . '|||' . $link->$attr, self::_getLinkKey());
-        }
-        return $link;
-    }
-
-    /**
-     * @throws SodiumException
-     */
-    public static function decryptLink($link)
-    {
-        $array = false;
-        if (is_array($link)) {
-            $array = true;
-            $link = ObjectUtil::asObject($link);
-        }
-
-        foreach ($link as $attr => $item) {
-            if (!str_starts_with($item, '///')) {
-                continue;
-            }
-            $v = Crypt::safeDecrypt(substr($item, 3), self::_getLinkKey());
-            $e = explode('|||', $v);
-            if ($e[0] === $link->uid) {
-                $link->$attr = $e[1];
-            } else {
-                $link->$attr = '';
-            }
-        }
-        if (!$array) {
-            return $link;
-        }
-        return ArrayUtil::asArray($link);
-    }
-
-    /**
-     * @throws SodiumException
-     */
-    public static function decryptLinks($links)
-    {
-        $res = [];
-        foreach ($links as $key => $link) {
-            $res[$key] = self::decryptLink($link);
-        }
-        return $res;
-    }
-
     public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [])
     {
         $lr = self::mergeLinksAndRulers($links, $rulers, $specialLinks, $specialRulers);
@@ -453,7 +373,7 @@ class FluidbookLinks
 
         self::_correctImageSpecialLinks($finalLinks);
 
-        return ['links' => self::encryptLinks($finalLinks), 'rulers' => array_merge(self::_getAsArray($rulers), self::_getAsArray($specialRulers))];
+        return ['links' => Link::encryptLinks($finalLinks), 'rulers' => array_merge(self::_getAsArray($rulers), self::_getAsArray($specialRulers))];
     }
 
     protected static function _getAsArray($v)
index b2f6aed6e6855b4d85af7c76b96bc37cb647085f..6b61ceec5d257a32923c50abf5c6812e24730bd4 100644 (file)
     ];
 
     $rulers=!count($rulers)?'{}':json_encode($rulers);
-
-    if(can('fluidbook-publication:links:edit-animations')){
-        $links=\Fluidbook\Tools\Links\Link::decryptLinks($links);
-    }
     $links=!count($links)?'{}':json_encode($links);
     /** @var \App\Models\User $user */
     $user=backpack_user();