]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6188 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 18 Sep 2023 15:01:34 +0000 (17:01 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 18 Sep 2023 15:01:34 +0000 (17:01 +0200)
app/Fluidbook/Compiler/Search.php
app/Fluidbook/Compiler/Secure.php
app/Fluidbook/SearchIndex.php

index 87840035e9eb1482b0a03658b9499f8bbfbc358b..996613754a3f09558ad2557af140dd9612fa501c 100644 (file)
@@ -18,20 +18,32 @@ trait Search
             FWSTK::lastUpdate() . '$$$' .
             $this->fluidbookSettings->search_mode . '=+='
         );
+
+        $doIndex = $this->fluidbookSettings->search_mode !== 'robust';
+
         $cacheDir = Files::mkdir(protected_path('fluidbookpublication/index/' . $this->book_id . '/' . $cache . '/'));
-        $indexFile = $cacheDir . '/search.index.js';
+        if ($doIndex) {
+            $indexFile = $cacheDir . '/search.index.js';
+        }
         $textFile = $cacheDir . '/search.texts.js';
         $hightlightsFile = $cacheDir . '/search.highlight.js';
 
-        if (!file_exists($indexFile) || !file_exists($textFile)) {
-            SearchIndex::makeTextsIndexes($this, $cacheDir, $index, $texts, true);
-            file_put_contents($indexFile, 'var INDEX=' . $index . ';' . "\r");
+        if (($doIndex && !file_exists($indexFile)) || !file_exists($textFile)) {
+            if ($doIndex) {
+                SearchIndex::makeTextsIndexes($this, $cacheDir, $index, $texts, true);
+                file_put_contents($indexFile, 'var INDEX=' . $index . ';' . "\r");
+            } else {
+                SearchIndex::makeTexts($this, $cacheDir, $texts, true);
+            }
             file_put_contents($textFile, 'var TEXTS=' . $texts . ";\r");
         }
+
         if ($this->fluidbookSettings->highlightResults && !file_exists($hightlightsFile)) {
             file_put_contents($hightlightsFile, 'var HIGHLIGHTS=' . json_encode(SearchIndex::makeHighlightIndex($this)) . ";\r");
         }
-        $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js');
+        if ($doIndex) {
+            $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js');
+        }
         if ($this->fluidbookSettings->highlightResults) {
             $this->vdir->copy($cacheDir . '/search.highlight.js', 'data/search.highlight.js');
         }
index e21c25f3ebcedcb14975a794399ca0740525a957..84c079da6fdad7c4861a7985994086f91a3cbff0 100644 (file)
@@ -58,6 +58,11 @@ trait Secure
         } else {
             $secure = file_get_contents($this->assets . '/_secure.html');
         }
+
+        if (!stristr($secure, 'data/noaccents.js')) {
+            $secure = str_replace('<script src="data/forge.js"></script>', '<script src="data/noaccents.js"></script><script src="data/forge.js"></script>', $secure);
+        }
+
         if ($this->fluidbookSettings->secureClientSideBackgroundImage) {
             $this->vdir->copy($this->wdir . '/' . $this->fluidbookSettings->secureClientSideBackgroundImage, 'data/secure/' . $this->fluidbookSettings->secureClientSideBackgroundImage);
             $variables['BACKGROUND_IMAGE'] = 'data/secure/' . $this->fluidbookSettings->secureClientSideBackgroundImage;
index 42a7b8319c0327a3207d3fb937d50b68e6f37a43..d5c3e67f951a3fe6d3fc94d6871abb73670c8792 100644 (file)
@@ -21,25 +21,17 @@ class SearchIndex
      */
     public static function makeTextsIndexes($compiler, $dir, &$index, &$textes, bool $simple = false, bool $force = false)
     {
+        self::makeTexts($compiler, $dir, $textes, $force);
+
         if ($simple) {
             $ifilec = $dir . '/sindex.json';
         } else {
             $ifilec = $dir . '/index.json';
         }
-        $tfilec = $dir . '/textes.json';
+        $index = [];
 
-        $index = array();
-        $textes = array();
         foreach ($compiler->pages as $page => $infos) {
-            $tfile = $compiler->getFluidbook()->getTextFile($page, FluidbookDocument::TEXT_PLAIN);
             $ifile = $compiler->getFluidbook()->getTextFile($page, FluidbookDocument::TEXT_INDEX);;
-
-
-            $text = PHP::retryOnError(function () use ($tfile) {
-                Gzip::compressIfNotCompressed($tfile);
-                return Gzip::file_get_contents($tfile);
-            }, 3, 0.5);
-
             $ipage = PHP::retryOnError(function () use ($ifile) {
                 Gzip::compressIfNotCompressed($ifile);
                 return Gzip::file_get_contents($ifile);
@@ -50,15 +42,28 @@ class SearchIndex
             } else {
                 self::fillIndexWithWords($index, $page, $ipage);
             }
-            $textes[$page] = $text;
+
         }
         ksort($index);
 
-        $textes = json_encode($textes);
         $index = json_encode($index);
+        Gzip::file_put_contents($ifilec, $index);
+    }
 
+    public static function makeTexts($compiler, $dir, &$textes, bool $force = false)
+    {
+        $tfilec = $dir . '/textes.json';
+        $textes = [];
+        foreach ($compiler->pages as $page => $infos) {
+            $tfile = $compiler->getFluidbook()->getTextFile($page, FluidbookDocument::TEXT_PLAIN);
+            $text = PHP::retryOnError(function () use ($tfile) {
+                Gzip::compressIfNotCompressed($tfile);
+                return Gzip::file_get_contents($tfile);
+            }, 3, 0.5);
+            $textes[$page] = $text;
+        }
+        $textes = json_encode($textes);
         Gzip::file_put_contents($tfilec, $textes);
-        Gzip::file_put_contents($ifilec, $index);
     }
 
     /**