]> _ Git - fluidbook_tools.git/commitdiff
wip #6274 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 15:39:56 +0000 (17:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 15:39:56 +0000 (17:39 +0200)
.idea/fluidbook_tools.iml
.idea/php.xml
.idea/phpunit.xml [new file with mode: 0644]
src/Links/CustomLink.php
src/Links/Link.php

index b3a424ca450cbab77fe9794b4fbbddfc6ec49d33..ecd464b66a369423420b4752c1021b4bb18a20d2 100644 (file)
@@ -97,6 +97,8 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php83" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-uuid" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/uid" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/chillerlan/php-qrcode" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/chillerlan/php-settings-container" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index 3945e1bb59d3d4c0e93c1b42c54238b0123cb344..c271f25d2affbb26dbd007817bc603490d54c785 100644 (file)
       <path value="$PROJECT_DIR$/vendor/guzzlehttp/uri-template" />
       <path value="$PROJECT_DIR$/vendor/laravel/prompts" />
       <path value="$PROJECT_DIR$/vendor/psr/clock" />
+      <path value="$PROJECT_DIR$/vendor/chillerlan/php-settings-container" />
+      <path value="$PROJECT_DIR$/vendor/chillerlan/php-qrcode" />
     </include_path>
   </component>
   <component name="PhpProjectSharedConfiguration" php_language_level="8.0">
     <option name="suggestChangeDefaultLanguageLevel" value="false" />
   </component>
+  <component name="PhpUnit">
+    <phpunit_settings>
+      <PhpUnitSettings custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" />
+    </phpunit_settings>
+  </component>
 </project>
\ No newline at end of file
diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml
new file mode 100644 (file)
index 0000000..4f8104c
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="PHPUnit">
+    <option name="directories">
+      <list>
+        <option value="$PROJECT_DIR$/tests" />
+      </list>
+    </option>
+  </component>
+</project>
\ No newline at end of file
index f105db6c30fbd6d39740dea11f212b6692f13220..7244519af7138f07c5736f56bdd4229885ef32c2 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Fluidbook\Tools\Links;
 
+use Illuminate\Support\Facades\DB;
+
 class CustomLink extends NormalLink
 {
     protected $role = 'link';
@@ -11,25 +13,6 @@ class CustomLink extends NormalLink
         return static::_getURL($this->to);
     }
 
-    protected static function _getURLOfType($type, $ref, $default = null)
-    {
-        global $core;
-        $e = explode(':', $ref, 2);
-        if (count($e) == 2 && $e[0] == $type) {
-            $ref = $e[1];
-        }
-        $nospaceref = str_replace(' ', '', $ref);
-        $r = $core->con->select("SELECT * FROM wsref WHERE (ref='" . $core->con->escape($ref) . "' OR ref='" . $core->con->escape($nospaceref) . "') AND type='" . $core->con->escape($type) . "'");
-        if ($r->count()) {
-            return $r->url;
-        }
-        if (null === $default) {
-            return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($type . '|' . $ref);
-        }
-        return $default;
-    }
-
-
     public function getTarget()
     {
         return '_blank';
@@ -52,14 +35,24 @@ class CustomLink extends NormalLink
         return new CustomLink($id, $init, $compiler);
     }
 
-    public static function _getURL($to)
+    protected static function _getURL($ref, $type = '', $default = null)
     {
-        $e = explode(':', $to, 2);
-        if (!count($e) == 1) {
-            return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($to);
+        $ref = str_replace('custom:', '', $ref);
+        $e = explode(':', $ref, 2);
+        if (count($e) == 2 && $e[0] == $type) {
+            $ref = $e[1];
+            $type = $e[0];
         }
-        $type = trim($e[0]);
-        $ref = trim($e[1]);
-        return self::_getURLOfType($type, $ref);
+        $nospaceref = str_replace(' ', '', $ref);
+
+        $res = DB::table('fluidbook_reference_url')->where('type', $type)->whereIn('ref', [$ref, $nospaceref])->get();
+        if ($res->count() > 0) {
+            $url = $res->get('url');
+            if (!$url || $url === '-') {
+                return $default;
+            }
+            return $url;
+        }
+        return $default;
     }
 }
index 6ff8dad06d5d1c76b183122bffa32ea9457124c1..2fe5fd5c8872e96bbe4117f780427333b4770ffe 100644 (file)
@@ -395,7 +395,7 @@ class Link
         $url = trim($url);
         if (strpos($url, 'custom:') === 0) {
             $e = explode(':', $url, 2);
-            return customLink::_getURL($e[1]);
+            return CustomLink::_getURL($e[1]);
         }
 
         return $url;