]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7894 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 19 Jan 2026 15:58:50 +0000 (16:58 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 19 Jan 2026 15:58:50 +0000 (16:58 +0100)
app/Fluidbook/Compiler/Accessibility.php
app/Fluidbook/Compiler/Links.php

index 39a4d06a8979a49d83613c3e8ab276883e845e3d..758958c518a549424b4494d06fde1ee44bd49492 100644 (file)
@@ -2,10 +2,13 @@
 
 namespace App\Fluidbook\Compiler;
 
+use App\Fluidbook\Farm;
+use App\Jobs\OCR;
 use App\Models\FluidbookHealthIssues;
 use Cubist\Azure\TTS\Api;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Text;
+use Cubist\Util\Url;
 use Exception;
 use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
 
@@ -135,4 +138,51 @@ trait Accessibility
         } catch (Exception $e) {
         }
     }
+
+    public function getLinkAlternativeText($link, $returnJobs = false)
+    {
+        $ocr = $link->getOCR();
+        if ($returnJobs) {
+            $res = [];
+        } else {
+            $res = '';
+        }
+
+        if (!$ocr) {
+            return $res;
+        }
+
+        foreach ($ocr as $attr) {
+            if (Url::isDistant($link->$attr)) {
+                continue;
+            }
+            $file = $this->wdir . '/' . $link->$attr;
+
+            if (!file_exists($file)) {
+                continue;
+            }
+            $ext = ['jpg', 'jpeg', 'png', /*'svg',*/
+                'pdf'];
+            $f = new \SplFileInfo($file);
+            if (!in_array($f->getExtension(), $ext)) {
+                continue;
+            }
+
+            if ($returnJobs) {
+                $j = new OCR($file, $this->getFluidbook()->locale);
+                if ($j->isOK()) {
+                    continue;
+                }
+                $res[] = $j;
+            } else {
+                $o = Farm::OCR($file, $this->getFluidbook()->locale);
+                if (file_exists($o)) {
+                    $o = file_get_contents($o);
+                }
+                $res .= $o;
+            }
+        }
+
+        return $res;
+    }
 }
index 3acfbc38a9c4357388f3ff93a6997e5c9c1bc9b9..d256e9fc1d86e61cc76885ad4a9bc35fc3ef1972 100644 (file)
@@ -529,43 +529,5 @@ trait Links
         $this->config->push('triggersLinks', ['page' => $page, 'link' => $link, 'delay' => $delay]);
     }
 
-    public function getLinkAlternativeText($link, $returnJobs = false)
-    {
-        $ocr = $link->getOCR();
-        if ($returnJobs) {
-            $res = [];
-        } else {
-            $res = '';
-        }
-        if (!$ocr) {
-            return $res;
-        }
-
-        foreach ($ocr as $attr) {
-            if (Url::isDistant($link->$attr)) {
-                continue;
-            }
-            $file = $this->wdir . '/' . $link->$attr;
-
-            if (!file_exists($file)) {
-                continue;
-            }
-            $ext = ['jpg', 'jpeg', 'png', /*'svg',*/ 'pdf'];
-            $f = new \SplFileInfo($file);
-            if (!in_array($f->getExtension(), $ext)) {
-                continue;
-            }
 
-            if ($returnJobs) {
-                $j = new OCR($file, $this->getFluidbook()->locale);
-                if ($j->isOK()) {
-                    continue;
-                }
-                $res[] = $j;
-            } else {
-                $res .= Farm::OCR($file, $this->getFluidbook()->locale);
-            }
-        }
-        return $res;
-    }
 }