From 8ad2d467060f38f7b78ae4009ecd9e0cc86b73a0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 12 Sep 2023 17:37:06 +0200 Subject: [PATCH] wip #6273 @0.25 --- composer.json | 4 +++- src/Links/Link.php | 35 ++++++++++++++++++++++++++++++++++- src/Links/ZoomLink.php | 11 +++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index e37cde6..c817bc7 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,12 @@ "ext-json": "*", "ext-iconv": "*", "ext-gd": "*", + "ext-sodium": "*", "laravel/framework": "~5.8|^6.0|^7.0|^8.0|^9.0|^10.0", "cubist/util": "dev-master", "cubist/pdf": "dev-master", "barryvdh/laravel-debugbar": "*", - "spatie/laravel-medialibrary": "^9.12.4|^10.7.16" + "spatie/laravel-medialibrary": "^9.12.4|^10.7.16", + "chillerlan/php-qrcode": "dev-main" } } diff --git a/src/Links/Link.php b/src/Links/Link.php index 1775979..6ff8dad 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -2,6 +2,7 @@ namespace Fluidbook\Tools\Links; +use chillerlan\QRCode\QRCode; use Cubist\Util\ArrayUtil; use Cubist\Util\Crypt; use Cubist\Util\CSS; @@ -11,7 +12,6 @@ use Cubist\Util\Json; use Cubist\Util\ObjectUtil; use Cubist\Util\Text; use Cubist\Util\Xml; -use Fluidbook\Tools\Compiler\Compiler; use Fluidbook\Tools\Compiler\CompilerInterface; use SodiumException; use stdClass; @@ -158,6 +158,10 @@ class Link $init['scorm'] = self::isScorm($init); $init['to'] = self::replaceCustomURL($init['to']); + if ($init['to'] === 'auto:qrcode') { + $init['to'] = self::scanQRCode($init, $compiler); + } + switch ($init['type']) { case static::WEB: case static::WEB_INFOS: @@ -903,5 +907,34 @@ class Link return $link; } + /** + * @throws \Exception + */ + public static function scanQRCode($link, $compiler) + { + $image = ZoomLink::generateImage([ + 'id' => $link['uid'], + 'page' => $link['page'], + 'maxzoom' => 2, + 'group' => '', + 'group-count' => 0, + 'width' => round($link['width']), + 'height' => round($link['height']), + 'x' => round($link['left']), + 'y' => round($link['top']), + 'border' => 0, + 'borderColor' => '', + ], $compiler, 'qrcodereader', 'qrcode', false, false); + + return ':)'; + try { + $result = (new QRCode)->readFromFile($image); + return (string)$result; + } catch (\Exception $e) { + + } + return ''; + } + } diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index a2bd4eb..aefa38f 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -91,12 +91,12 @@ class ZoomLink extends NormalLink { /** * @param $attributes - * @param $compiler CompilerInterface + * @param $compiler CompilerInterface|null * @param $cachedir * @param $save - * @return void + * @return string */ - public static function generateImage($attributes, $compiler, $cachedir, $save, $trim = false) { + public static function generateImage($attributes, $compiler, $cachedir, $save, $trim = false,$copy=true) { $maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor $maxzoom = max(0, min($maxzoom, 20)); @@ -228,7 +228,10 @@ class ZoomLink extends NormalLink { Log::error('Failed generate image ' . json_encode($attributes)); } $dest = 'data/links/' . $save . '_' . $attributes['id'] . '.' . $ext; - $compiler->simpleCopyLinkFile($both, $dest); + if($copy) { + $compiler->simpleCopyLinkFile($both, $dest); + } + return $both; } -- 2.39.5