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;
$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);
}
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);
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)