]> _ Git - fluidbook_tools.git/commitdiff
wait #5641 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Dec 2022 15:40:07 +0000 (16:40 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Dec 2022 15:40:07 +0000 (16:40 +0100)
src/Links/Link.php

index 9e271e1b16abfa530b488fa0c340b06a49c85d05..b9a42ea60dd7225c763f09f4ba4384dd3b4960b3 100644 (file)
@@ -12,6 +12,7 @@ use Cubist\Util\Text;
 use Cubist\Util\Xml;
 use Fluidbook\Tools\Compiler\Compiler;
 use Fluidbook\Tools\Compiler\CompilerInterface;
+use SodiumException;
 use stdClass;
 
 class Link {
@@ -668,5 +669,44 @@ class Link {
     }
 
 
+    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;
+    }
+
+
 
 }