]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7868 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jan 2026 16:56:08 +0000 (17:56 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jan 2026 16:56:08 +0000 (17:56 +0100)
app/Fluidbook/Compiler/Links.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
app/Models/FluidbookPublication.php
resources/linkeditor-stable/js/linkeditor.form.js
resources/linkeditor-stable/js/linkeditor.save.js
resources/views/fluidbook_publication/link_editor.blade.php

index 4ee4a8750c8f8ff18424b3def57deeffc8693803..704ef34446550115eb4412abaa2f466878554aad 100644 (file)
@@ -530,7 +530,8 @@ trait Links
 
     public function shortenURL($url)
     {
-        if ($this->config->linkShortener === 'none' || !Url::isDistant($url)) {
+
+        if (!$this->config->linkShortener || !Url::isDistant($url)) {
             return $url;
         }
         return LinkShortener::shorturl($url, $this->config->linkShortener);
index 405a1c208c37916fe64b2354fda65b564dd8fa93..0f54f45b3e9def2f554df4220beb7edb3798f3ec 100644 (file)
@@ -81,7 +81,7 @@ trait LinksOperation
         );
 
         $fb = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id);
-        return response()->json(['assets' => $fb->getLinksAssetsDimensions(), 'versions' => LinksData::getLinksVersions($fluidbook_id)]);
+        return response()->json(['assets' => $fb->getLinksAssetsDimensions(), 'versions' => LinksData::getLinksVersions($fluidbook_id), 'shortenedLinks' => $fb->getShortenedLinks()]);
     }
 
     protected function generateFont(Request $request, $id)
index d9ae9160f9326976865a809100c186d2dd7497d0..f26235469e624e3dee4cd289f7fbad750ae1e382 100644 (file)
@@ -70,6 +70,7 @@ use Cubist\Util\Gzip;
 use Cubist\Util\Json;
 use Cubist\Util\Markdown;
 use Cubist\Util\Str;
+use Cubist\Util\Url;
 use Datetime;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
@@ -950,7 +951,7 @@ class FluidbookPublication extends ToolboxStatusModel
         return true;
     }
 
-    protected function _baseReplicate(?array $except=null)
+    protected function _baseReplicate(?array $except = null)
     {
         $current = $this;
         if ($this->syncFromWorkshop()) {
@@ -970,7 +971,7 @@ class FluidbookPublication extends ToolboxStatusModel
         return $new;
     }
 
-    public function replicateFull(?array $except=null)
+    public function replicateFull(?array $except = null)
     {
         $new = $this->_baseReplicate($except);
         if (!$this->composition_fluidbook && $this->version >= 3) {
@@ -987,7 +988,7 @@ class FluidbookPublication extends ToolboxStatusModel
         return $new;
     }
 
-    public function replicateSettings(?array $except=null)
+    public function replicateSettings(?array $except = null)
     {
         $new = $this->_baseReplicate(array_merge($except ?? [], ['composition']));
         $new->composition = [];
@@ -1406,4 +1407,19 @@ class FluidbookPublication extends ToolboxStatusModel
             ->orderBy('created_at', 'desc')
             ->pluck('id');
     }
+
+    public function getShortenedLinks()
+    {
+        if (!$this->linkShortener) {
+            return [];
+        }
+        $res = [];
+        LinksData::getLinksAndRulers($this->id, $links, $rulers);
+        foreach ($links as $link) {
+            if (Url::isDistant($link['to'])) {
+                $res[$link['to']] = LinkShortener::shorturl($link['to'], $this->linkShortener);
+            }
+        }
+        return $res;
+    }
 }
index 8a6bdeb9e3ab06a1c442bf9754e8e747c9417386..bf6b258c54d470e1086f33b4f50504a0e672872c 100644 (file)
@@ -273,10 +273,16 @@ LinkeditorForm.prototype = {
         var type = $(link).attr('fb-type');
         var form = $("#linkeditor-form-template-" + type).clone(false);
 
+
+
         $(form).attr('id', null);
         $(form).data('link', link);
         $(form).find('.init-tooltip').removeClass('init-tooltip');
         this.updateFormData(form);
+        if (SHORTENED_LINKS[$(form).find('[name="to"]').val()] !== undefined) {
+            $(form).find('[name="to"]').after('<p class="help-block">' + TRANSLATIONS['short_link'] + ': <strong>' + SHORTENED_LINKS[$(form).find('[name="to"]').val()] + '</strong></p>');
+        }
+
         container.append(form);
         this.linkeditor.initTooltips();
 
index 6f9dbc96e89a2c262c54c0145a829b96b2dfc46a..11b0278c64f11a1994efb3c6e57784637d538c5f 100644 (file)
@@ -72,6 +72,7 @@ LinkeditorSave.prototype = {
                 $this.runningAutomaticSaveTimeout = false;
 
                 window.ASSETS = data.assets;
+                window.SHORTENED_LINKS = data.shortenedLinks;
                 $this.linkeditor.versions.setVersions(data.versions);
                 callback();
             },
index a041ff62bea812a5ca88b71d1376240208a92e6e..c08a15d58673aff8dcecb8366959b78b5d44de53 100644 (file)
         'fix_offset'=>__('Corriger décalage de page'),
         'interactive_links'=>__('Liens interactifs'),
         'noninteractive_links'=>__('Liens non-interactifs'),
+        'short_link'=>__('Lien raccourci'),
     ];
 
     $rulers=!count($rulers)?'{}':json_encode($rulers);
         $settings[$k]=$user->getToolboxSetting('linkeditor_'.$k,$v);
     }
     $assets=$fluidbook->getLinksAssetsDimensions();
+    $shortenedLinks=$fluidbook->getShortenedLinks();
 
     $alignments=[
         'left'=>__('Aligner la sélection à gauche'),
                          data-tooltip="{{__('Ajout automatique de liens à partir d\'un excel')}}">
                         <form class="importExcel"
                               data-save-before-submit="{{__("Sauvegarde avant l'ajout automatique à partir d'un excel")}}"
-                              action="/fluidbook-publication/{{$fbdata['id']}}/edit/links/import/automatic" method="post"
+                              action="/fluidbook-publication/{{$fbdata['id']}}/edit/links/import/automatic"
+                              method="post"
                               enctype="multipart/form-data">
                             <input type="file"
                                    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
         var ASSETS = @json($assets);
         var CAN_CONTAIN_LINKS = @json($canContainLinks);
         var DEPTH = @json($depths);
+        var SHORTENED_LINKS = @json($shortenedLinks);
     </script>
     <script
         src="/packages/linkeditor{{$scriptVersion}}/js/linkeditor.js?v={{filemtime(public_path('packages/linkeditor'.$scriptVersion.'/js/linkeditor.js'))}}"></script>