]> _ Git - fluidbook_tools.git/commitdiff
wip #6273 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 15:37:06 +0000 (17:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 15:37:06 +0000 (17:37 +0200)
composer.json
src/Links/Link.php
src/Links/ZoomLink.php

index e37cde60b03fa7f7474fa4778438c6e261f53975..c817bc7e42eaa04edaa530b033749d3cab14dd7f 100644 (file)
         "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"
     }
 }
index 1775979161fe85a6fd21ca905692a63ba2ad38c8..6ff8dad06d5d1c76b183122bffa32ea9457124c1 100644 (file)
@@ -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 '';
+    }
+
 
 }
index a2bd4eb0057c6f9f0dbf555d7990ba37e6f64e9a..aefa38f49e1eaf395e56adb5b3a73e621c0ef122 100644 (file)
@@ -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;
     }