]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6014 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jun 2023 09:43:26 +0000 (11:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jun 2023 09:43:26 +0000 (11:43 +0200)
app/Fluidbook/Compiler/Links.php
app/Fluidbook/Farm.php
app/Fluidbook/Link/LinksData.php
app/Models/FluidbookPublication.php
app/Models/Traits/PublicationSettings.php

index ecc5b7215622ffb6294b2ce64b1591d510c823cb..c7085fca150b116b221283a2fbc12de4fb6c305a 100644 (file)
@@ -131,6 +131,20 @@ trait Links
         $anchorExists = [];
         $closedLinks = [];
 
+        $anchorsFromExcel = $this->_fluidbook->getAnchorsFromExcel();
+        foreach ($anchorsFromExcel as $name => $page) {
+            $links[] = [
+                'page' => $page,
+                'top' => 0,
+                'left' => 0,
+                'width' => 10,
+                'height' => 10,
+                'type' => AnchorLink::class,
+                'to' => $name,
+                'uid' => LinksData::generateUID()
+            ];
+        }
+
         $linksCopy = $links;
 
 
@@ -219,7 +233,7 @@ trait Links
                 $ids = explode(',', $linkData['to']);
                 $close = ($linkData['close_button'] && $linkData['close_button'] !== 'none');
                 foreach ($ids as $id) {
-                    $id = trim($id,'+- ');
+                    $id = trim($id, '+- ');
                     if ($id === 'tabs') {
                         $this->config->tabsHiddenAtStartup = true;
                     } else {
@@ -234,6 +248,7 @@ trait Links
             }
         }
 
+
         if ($this->fluidbookSettings->anchorsAliases && file_exists($this->fluidbookSettings->anchorsAliases)) {
             $aliases = [];
             for ($i = 0; $i <= 2; $i++) {
@@ -250,7 +265,7 @@ trait Links
                             'left' => 0,
                             'width' => 100,
                             'height' => 100,
-                            'type' => 26,
+                            'type' => AnchorLink::class,
                             'to' => $from,
                             'uid' => LinksData::generateUID()
                         ];
index ef9c820c8f6df82c77ae187fb670d557caae4347..e2f500294814aa82b61eb096fac7b0eedff6c37e 100644 (file)
@@ -137,12 +137,16 @@ class Farm
             Cache::forget($cachekey);
         }
 
-        return Cache::rememberForever($cachekey, function () use ($params) {
+        $res = Cache::rememberForever($cachekey, function () use ($params) {
             return self::_getFile($params);
         });
+        if (!$res) {
+            Cache::forget($cachekey);
+        }
+        return $res;
     }
 
-    protected static function _getFile($params)
+    protected static function _getFile($params, $attempts = 3)
     {
         $start = microtime(true);
         $farmer = self::pickOneServer();
@@ -167,6 +171,10 @@ class Farm
 
         error_log($log);
 
+        if (!$res && $attempts > 0) {
+            return static::_getFile($params, $attempts - 1);
+        }
+
         return $res;
     }
 
index ea2d137a230957aaabd497ef9fddca2807f5f4b9..f529730abf312cd4bfc3c77bb3bcbadad3398d10 100644 (file)
@@ -507,14 +507,21 @@ class LinksData
 
     protected static function getName($u)
     {
-        if (!isset(self::$_names[$u])) {
+        if (is_array($u)) {
+            if (isset($u['firstname'])) {
+                return $u['firstname'] . ' ' . $u['lastname'];
+            } else {
+                return '-';
+            }
+        }
+        if (!isset(static::$_names[$u])) {
             try {
-                self::$_names[$u] = User::find($u)->name;
+                static::$_names[$u] = User::find($u)->name;
             } catch (\Exception $e) {
-                self::$_names[$u] = '-';
+                static::$_names[$u] = '-';
             }
         }
-        return self::$_names[$u];
+        return static::$_names[$u];
     }
 
     public static function getMeta($book_id, $update = 'latest')
index 8b2003c55aac16455a7565c2841d86a051c296ee..af91295842b9624cab23770c11d7e50257c452dc 100644 (file)
@@ -39,6 +39,8 @@ use Cubist\Backpack\Magic\Fields\Hidden;
 use Cubist\Backpack\Magic\Fields\Integer;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Operations\CreateOperation;
+use Cubist\Excel\Excel;
+use Cubist\Excel\ExcelToArray;
 use Cubist\Util\ArrayUtil;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Graphics\Image;
@@ -789,6 +791,7 @@ class FluidbookPublication extends ToolboxSettingsModel
         for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
             $res[$i] = [];
         }
+        // Get anchors from links
         $this->getLinksAndRulers($links, $rulers);
         foreach ($links as $link) {
             if ($link['type'] !== Link::ANCHOR && $link['type'] !== Link::PAGE_LABEL) {
@@ -799,10 +802,49 @@ class FluidbookPublication extends ToolboxSettingsModel
             }
             $res[$link['page']][] = $link['to'];
         }
+        // Get anchors from Excel file
+        $anchors = $this->getAnchorsFromExcel();
+        foreach ($anchors as $anchor => $page) {
+            if (!isset($res[$page])) {
+                continue;
+            }
+            $res[$page][] = $anchor;
+        }
         return $res;
     }
 
-    public function getPreviewURL(){
-        return route('fluidbook_preview',['version'=>'online','id'=>$this->id,'hash'=>$this->hash]);
+    public function getAnchorsFromExcel()
+    {
+        $res = [];
+        if (!$this->anchors) {
+            return $res;
+        }
+        $file = $this->getAssetDir() . '/' . $this->anchors;
+        if (!file_exists($file)) {
+            return $res;
+        }
+
+        ExcelToArray::setCache(protected_path('fluidbookpublication/cache/exceltoarray'));
+        $contents = ExcelToArray::excelToArrayFirstSheet($file);
+
+        foreach ($contents as $row) {
+            $page = trim($row[0]);
+            if (!is_numeric($page)) {
+                continue;
+            }
+            $page = (int)$page;
+            $name = trim($row[1]);
+            if ($page >= 0 && $page <= $this->getPagesNumber()) {
+                $res[$name] = $page;
+            }
+        }
+        return $res;
+
+
+    }
+
+    public function getPreviewURL()
+    {
+        return route('fluidbook_preview', ['version' => 'online', 'id' => $this->id, 'hash' => $this->hash]);
     }
 }
index e9bffbb91a1460c73ca84f189d2c3670233821b6..bf89bd08292fb0ffe649ae558c975f83d7ff0da0 100644 (file)
@@ -114,6 +114,7 @@ trait PublicationSettings
         $this->_audioplayer();
         $this->_downloadPortions();
         $this->_articles();
+        $this->_anchors();
         $this->_assets();
     }
 
@@ -266,11 +267,7 @@ trait PublicationSettings
         ]);
         $this->addSettingField('facebook_image', FilesOrURL::class, $this->__('Miniature affichée'), [
             'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Miniature affich\\u00e9e!\\u00a7!","fileFilter":{"name":"\\u00a7!\\u00a7Images!\\u00a7! (*.jpg, *.png)","extensions":"*.jpg;*.jpeg;*.png"}}',
-            'accept' => [
-                0 => '.jpg',
-                1 => '.jpeg',
-                2 => '.png',
-            ],
+            'accept' => self::$acceptImages,
         ]);
         $this->addSettingField('twitter_description', Textarea::class, $this->__('Contenu Partage court'), [
             'v2' => '{"type":"textarea","default":"%title% : %short%","editable":true,"label":"\\u00a7!\\u00a7Contenu Partage court!\\u00a7!","hint":"\\u00a7!\\u00a7Contenu du partag\\u00e9 sur les partages courts!\\u00a7!"}',
@@ -1491,11 +1488,7 @@ trait PublicationSettings
         $this->addSettingField('section_splash', FormSection::class, $this->__('Ecran de chargement'));
         $this->addSettingField('splashImage', FilesOrURL::class, $this->__('Image'), [
             'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Image!\\u00a7!","grade":3,"fileFilter":{"name":"\\u00a7!\\u00a7Images!\\u00a7! (*.jpg, *.png)","extensions":"*.jpg;*.jpeg;*.png"}}',
-            'accept' => [
-                0 => '.jpg',
-                1 => '.jpeg',
-                2 => '.png',
-            ],
+            'accept' => self::$acceptImages,
         ]);
         $this->addSettingField('splashURL', LongText::class, $this->__('URL'), [
             'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7URL!\\u00a7!","grade":3}',
@@ -1568,16 +1561,22 @@ trait PublicationSettings
 
     }
 
+    protected function _anchors()
+    {
+        $this->addSettingField('section_anchors', FormSection::class, $this->__('Ancres'));
+        $this->addSettingField('anchors', FilesOrURL::class, $this->__('Définir les ancres'), [
+            'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Ancres!\\u00a7!","fileFilter":{"name":"\\u00a7!\\u00a7Fichier Excel!\\u00a7! (.xlsx)","extensions":"*.xlsx"}}',
+            'accept' => self::$acceptXLSX,
+            'hint' => __('Colonne A : numéro de page physique, Colonne B : nom de l\'ancre')
+        ]);
+    }
+
     protected function _archives()
     {
         $this->addSettingField('section_archives', FormSection::class, $this->__('Archives'));
         $this->addSettingField('externalArchives', FilesOrURL::class, $this->__('Archives'), [
             'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Archives!\\u00a7!","grade":3,"fileFilter":{"name":"\\u00a7!\\u00a7Images!\\u00a7! (*.jpg, *.png)","extensions":"*.jpg;*.jpeg;*.png"}}',
-            'accept' => [
-                0 => '.jpg',
-                1 => '.jpeg',
-                2 => '.png',
-            ],
+            'accept' => self::$acceptImages,
         ]);
         $this->addSettingField('archivesLabel', LongText::class, $this->__('Label'), [
             'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Label!\\u00a7!","grade":5}',
@@ -1682,20 +1681,12 @@ trait PublicationSettings
         $this->addSettingField('', FormSeparator::class);
         $this->addSettingField('cartHeaderImage', FilesOrURL::class, $this->__('Header panier'), [
             'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Header panier!\\u00a7!","grade":3,"fileFilter":{"name":"\\u00a7!\\u00a7Images!\\u00a7! (*.jpg, *.png)","extensions":"*.jpg;*.jpeg;*.png"},"dir":"commerce"}',
-            'accept' => [
-                0 => '.jpg',
-                1 => '.jpeg',
-                2 => '.png',
-            ],
+            'accept' => self::$acceptImages,
             'destination' => 'commerce',
         ]);
         $this->addSettingField('cartHeaderMobileImage', FilesOrURL::class, $this->__('Header panier (mobile)'), [
             'v2' => '{"type":"freefile","default":"","editable":true,"label":"\\u00a7!\\u00a7Header panier (mobile)!\\u00a7!","grade":3,"fileFilter":{"name":"\\u00a7!\\u00a7Images!\\u00a7! (*.jpg, *.png)","extensions":"*.jpg;*.jpeg;*.png"},"dir":"commerce"}',
-            'accept' => [
-                0 => '.jpg',
-                1 => '.jpeg',
-                2 => '.png',
-            ],
+            'accept' => self::$acceptImages,
             'destination' => 'commerce',
         ]);
         $this->addSettingField('cartExtraSettings', Textarea::class, $this->__('Paramètres panier'), [