From 38c5e9d72344f1826bf6a8ab36c0c4cff730e52f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 13 Dec 2022 16:40:07 +0100 Subject: [PATCH] wait #5641 @0.25 --- src/Links/Link.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Links/Link.php b/src/Links/Link.php index 9e271e1..b9a42ea 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -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; + } + + } -- 2.39.5