From: Vincent Vanwaelscappel Date: Tue, 12 Sep 2023 15:39:56 +0000 (+0200) Subject: wip #6274 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fc51a5bc2d8f7e8f165f78c7af844515bf66ef49;p=fluidbook_tools.git wip #6274 @0.5 --- diff --git a/.idea/fluidbook_tools.iml b/.idea/fluidbook_tools.iml index b3a424c..ecd464b 100644 --- a/.idea/fluidbook_tools.iml +++ b/.idea/fluidbook_tools.iml @@ -97,6 +97,8 @@ + + diff --git a/.idea/php.xml b/.idea/php.xml index 3945e1b..c271f25 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -101,9 +101,16 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml new file mode 100644 index 0000000..4f8104c --- /dev/null +++ b/.idea/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/Links/CustomLink.php b/src/Links/CustomLink.php index f105db6..7244519 100644 --- a/src/Links/CustomLink.php +++ b/src/Links/CustomLink.php @@ -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; } } diff --git a/src/Links/Link.php b/src/Links/Link.php index 6ff8dad..2fe5fd5 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -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;