]> _ Git - cubeextranet.git/commitdiff
wip #4866 @2
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 8 Nov 2021 21:09:17 +0000 (21:09 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 8 Nov 2021 21:09:17 +0000 (21:09 +0000)
inc/ws/Metier/class.ws.book.parametres.php
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php

index 1053f3d9cc8e8e34b9489960e9e7434652d9120c..bec01fa88a3dfd199e7eef0fad101304e6f360ae 100644 (file)
@@ -300,7 +300,7 @@ class wsBookParametres extends wsParametres
         $this->fields['dynamicBackgroundColor'] = ['type' => 'textarea', 'default' => '', 'editable' => true, 'label' => 'Couleur de fond dynamique', 'grade' => 3];
 
         $this->forms['3d_mode'] = array('label' => __('Options de visualisation'),
-            'fieldsnames' => array('mobileNavigationType', '|', 'mobileTransitions', 'mobileTransitionDuration', '|', 'forceWhiteBackground', 'rasterizePages', 'vectorPages', 'visualisationMode', 'antialiasReading', 'correctCenter', 'pagesBaseAngle', 'centerBook', '|', 'extraXSpace', 'mobileExtraXSpace', 'extraYSpace', '|', 'viewMode', '|', 'dynamicBackgroundColor', '|', 'svgToCanvasUpscale','textsThickness','textsThicknessPages', '|', 'imageFormat', 'maxResolution', 'JPEGQuality'));
+            'fieldsnames' => array('mobileNavigationType', '|', 'mobileTransitions', 'mobileTransitionDuration', '|', 'forceWhiteBackground', 'rasterizePages', 'vectorPages', 'visualisationMode', 'antialiasReading', 'correctCenter', 'pagesBaseAngle', 'centerBook', '|', 'extraXSpace', 'mobileExtraXSpace', 'extraYSpace', '|', 'viewMode', '|', 'dynamicBackgroundColor', '|', 'svgToCanvasUpscale', 'textsThickness', 'textsThicknessPages', '|', 'imageFormat', 'maxResolution', 'JPEGQuality'));
 
         $this->fields['rasterizeOnSafari'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Ecraser les pages pour Safari (Mac OS)'), 'grade' => 1);
         $this->forms['performances'] = ['label' => __('Performances'),
@@ -460,8 +460,9 @@ class wsBookParametres extends wsParametres
         $this->fields['tagcommander_prod'] = ['type' => 'boolean', 'default' => true, 'editable' => true, 'label' => 'Production', 'grade' => 3];
         $this->fields['tagcommander_plan'] = ['type' => 'freefile', 'default' => '', 'editable' => true, 'label' => 'Plan de taggage "Tag commander"', 'grade' => 3];
         $this->fields['tagcommander_default_vars'] = ['type' => 'textarea', 'default' => '', 'editable' => true, 'label' => 'Variables par défaut', 'grade' => 3];
+        $this->fields['anchorsAliases'] = ['type' => 'text', 'default' => '', 'editable' => true, 'label' => __('Alias des ancres')];
         $this->forms['stats'] = array('label' => __('Statistiques avancées'),
-            'fieldsnames' => array('stats_score', 'stats_exclude_ip', '|', 'relay_url_params', '|', 'gtag_additional_code', '|', 'googleAnalyticsCustom', 'statsCustom', '|', 'xiti', 'xiti_page', '|', 'tagcommander_id', 'tagcommander_prod', 'tagcommander_plan', 'tagcommander_default_vars'));
+            'fieldsnames' => array('tagcommander_id', 'tagcommander_prod', 'tagcommander_plan', 'tagcommander_default_vars', 'anchorsAliases', '|', 'stats_score', 'stats_exclude_ip', '|', 'relay_url_params', '|', 'gtag_additional_code', '|', 'googleAnalyticsCustom', 'statsCustom', '|', 'xiti', 'xiti_page'));
 
         $this->fields['displayChaptersPopup'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Always display chapters in a popup'), 'grade' => 1);
         $this->fields['displayChaptersIcon'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __("Affiche l'icône du sommaire"), 'grade' => 1);
@@ -529,6 +530,7 @@ class wsBookParametres extends wsParametres
         $this->fields['linkTooltipMaxWidth'] = array('type' => 'integer', 'default' => 140, 'editable' => true, 'label' => __('Largeur max des infobulles des liens de type "infobulle"'));
         $this->fields['openLinkAtStartup'] = ['type' => 'text', 'default' => '', 'editable' => true, 'label' => __('Déclencher un lien à l\'ouverture du fluidbook')];
 
+
         $this->fields['mobileIgnoreBackgroundLinks'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Ignorer les liens de background'));
         $this->forms['links'] = array('label' => __('Liens'),
             'fieldsnames' => array('permanentLinks', 'mobileLinksRevealAnim', 'linkBlinkTime', 'linkBlinkRepetition', '|', 'openLinkAtStartup', '|', 'customLinkClass', 'ignoreLinksTypes', 'mobileIgnoreBackgroundLinks', 'linkTooltipManager', 'linkCornerSize', 'linkTooltipMaxWidth', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkFilePrefix'));
index 6b97fd336a6c1a1df33d2bcece97cfcdeb326ee7..78a78fbbc2f110ea0f55126aebfc869538d543f6 100644 (file)
@@ -31,7 +31,7 @@ class wsUtil
             return array();\r
         }\r
 \r
-        $cacheFile = $cacheBase . sha1($excelFile . '/' . filemtime($excelFile).'/'.$assoc);\r
+        $cacheFile = $cacheBase . sha1($excelFile . '/' . filemtime($excelFile) . '/' . $assoc);\r
 \r
         if (!$force && file_exists($cacheFile) && filemtime($cacheFile) > filemtime($excelFile)) {\r
             $worksheets = json_decode(file_get_contents($cacheFile), true);\r
@@ -45,12 +45,11 @@ class wsUtil
             $objPHPExcel = $objReader->load($excelFile);\r
 \r
 \r
-\r
             foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {\r
                 if ($worksheet->getSheetState() != PHPExcel_Worksheet::SHEETSTATE_VISIBLE) {\r
                     continue;\r
                 }\r
-                $title = $worksheet->getTitle();\r
+                $title = trim($worksheet->getTitle());\r
 \r
                 if (strlen($title) == 2 && cubeCountry::getCountry($title)) {\r
                     $title = cubeCountry::getCountry($title);\r
@@ -83,35 +82,53 @@ class wsUtil
 \r
     public static function excelToArrayKeyVars($excelFile, $reader = 'Excel2007', $skipEmptyId = false)\r
     {\r
+        global $core;\r
+\r
+        $e = explode('#', $excelFile);\r
+        $excelFile = $e[0];\r
+\r
         $worksheets = self::excelToArray($excelFile, false, $reader);\r
+\r
+        if (isset($e[1])) {\r
+            $sheetName = trim($e[1]);\r
+        }\r
+\r
+\r
+        if (isset($sheetName, $worksheets[$sheetName])) {\r
+            $worksheet = $worksheets[$sheetName];\r
+        } else {\r
+            $worksheet = array_unshift($worksheets);\r
+        }\r
+\r
         $res = [];\r
-        foreach ($worksheets as $worksheet) {\r
-            foreach ($worksheet as $i => $line) {\r
-                if ($i === 0) {\r
-                    $vars = [];\r
-                    foreach ($line as $j => $varname) {\r
-                        if ($j === 0) {\r
-                            continue;\r
-                        }\r
-                        $vars[$j] = $varname;\r
-                    }\r
-                } else {\r
-                    $r = [];\r
-                    foreach ($vars as $j => $varname) {\r
-                        $r[$varname] = trim($line[$j]);\r
+        foreach ($worksheet as $i => $line) {\r
+            if ($i === 0) {\r
+                $vars = [];\r
+                foreach ($line as $j => $varname) {\r
+                    if ($j === 0) {\r
+                        continue;\r
                     }\r
-                    $id = trim($line[0]);\r
-                    if ($id === '') {\r
-                        if ($skipEmptyId) {\r
-                            continue;\r
-                        }\r
-                        $id = $i;\r
+                    $vars[$j] = $varname;\r
+                }\r
+            } else {\r
+                if (trim(implode('', $line)) == '') {\r
+                    continue;\r
+                }\r
+                $r = [];\r
+                foreach ($vars as $j => $varname) {\r
+                    $r[$varname] = trim($line[$j]);\r
+                }\r
+                $id = trim($line[0]);\r
+                if ($id === '') {\r
+                    if ($skipEmptyId) {\r
+                        continue;\r
                     }\r
-                    $res[$id] = $r;\r
+                    $id = $i;\r
                 }\r
+                $res[$id] = $r;\r
             }\r
-            break;\r
         }\r
+\r
         return $res;\r
     }\r
 \r
@@ -355,7 +372,7 @@ class wsUtil
 \r
 \r
         if ($book->parametres->pdfReplace) {\r
-            $replace = $book->getAssetDir().$book->parametres->pdfReplace;\r
+            $replace = $book->getAssetDir() . $book->parametres->pdfReplace;\r
             if (file_exists($replace) && filesize($replace) > 0) {\r
                 if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) {\r
                     self::copy($replace, $normalPDF);\r
index be5675122d3f77539b0dde6098c43f51176dc8cd..8c7587281e764ff4b2fcc2998a1e0639657b5ced 100644 (file)
@@ -894,9 +894,9 @@ class wsHTML5Compiler
             $this->addSlideshowLibrary(false);
             $this->addSlideshowLibrary(true);
         }
-        $this->writeStats();
-        $this->writeSecure();
+
         $this->log('Copied assets');
+        $this->writeSecure();
         $this->loadPlugins();
         $this->log('Plugins loaded');
         $this->writeImages();
@@ -906,6 +906,8 @@ class wsHTML5Compiler
         $this->log('Articles written');
         $linksCSS = $this->writeLinks();
         $this->log('Links written');
+        $this->writeStats();
+        $this->log('Stats written');
         $this->writeLangs();
         $this->log('Langs written');
         $this->writeSEO();
@@ -939,6 +941,7 @@ class wsHTML5Compiler
 
     protected function writeStats()
     {
+        global $core;
         if ($this->book->parametres->tagcommander_id) {
             $id = $this->book->parametres->tagcommander_id;
             if (!$this->book->parametres->tagcommander_prod) {
@@ -953,9 +956,8 @@ class wsHTML5Compiler
             $this->book->parametres->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/tc_Multisite_Analytics.js"></script>';
             $this->book->parametres->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/tc_Multisite_Medias.js"></script>';
 
-
             if ($this->book->parametres->tagcommander_plan) {
-                $plan = wsUtil::excelToArrayKeyVars($this->wdir . '/' . $this->book->parametres->tagcommander_plan);
+                $plan = wsUtil::excelToArrayKeyVars($this->_wdirOrAbsolute($this->book->parametres->tagcommander_plan));
                 $fixedplan = [];
                 foreach ($plan as $k => $v) {
                     $e = explode('#', $k);
@@ -963,7 +965,7 @@ class wsHTML5Compiler
                         $k = $e[1];
                     }
 
-                    $fixedplan[trim($k, '#/')] = $v;
+                    $fixedplan[$this->_labelToPage($k)] = $v;
                 }
                 $this->config->tagcommander_plan = $fixedplan;
             }
@@ -981,9 +983,42 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
 <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=' . $this->book->parametres->googleTagManager . '"
 height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
 <!-- End Google Tag Manager (noscript) -->';
+
+
         }
     }
 
+
+    protected function _wdirOrAbsolute($path)
+    {
+        $e = explode('#', $path);
+        if (file_exists($e[0])) {
+            return $path;
+        }
+            return $this->wdir . $path;
+
+    }
+
+    protected function _labelToPage($k)
+    {
+        global $core;
+        $k = trim($k, '#/');
+        $k = str_replace('page/page', 'page', $k);
+
+        if (preg_match('/^page\/(\d+)$/', $k, $matches)) {
+            return $k;
+        }
+
+        if (preg_match('/^page\/(.+)$/', $k, $matches)) {
+            $matches[1]=CubeIT_Util_Text::removeAccents($matches[1]);
+            $matches[1]=mb_strtolower($matches[1]);
+            if (isset($this->pageLabels[$matches[1]])) {
+                return 'page/' . $this->pageLabels[$matches[1]];
+            }
+        }
+        return $k;
+    }
+
     protected function writeSecure()
     {
         if ($this->book->parametres->secureClientSidePassword !== '') {
@@ -1798,10 +1833,14 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
 
         $pagesOfCustomLinks = [];
         $hiddenLinks = [];
+        $anchorExists = [];
 
         $linksCopy = $links;
 
         foreach ($linksCopy as $k => $linkData) {
+            if ($linkData['type'] == 26 || $linkData == 40) {
+                $anchorExists[$linkData['to']] = $linkData;
+            }
             if ($linkData['type'] == 35 || $linkData['type'] == 15 || $linkData['type'] == 39) {
                 $linkData = wsLinks::decryptLink($linkData);
                 $animations = contentLink::parseAnimations($linkData['image_rollover']);
@@ -1874,6 +1913,41 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             }
         }
 
+        if ($this->book->parametres->anchorsAliases && file_exists($this->book->parametres->anchorsAliases)) {
+            $aliases = [];
+            $anchors = [];
+            $lines = CubeIT_Util_Text::explodeNewLines(file_get_contents($this->book->parametres->anchorsAliases));
+            foreach ($lines as $line) {
+                $e = explode("\t", $line);
+                $from = trim($e[0]);
+                $to = trim($e[1]);
+                $aliases[$from] = $to;
+                if (is_numeric($to) && !isset($anchorExists[$from])) {
+                    $anchor = [
+                        'page' => $to,
+                        'top' => 0,
+                        'left' => 0,
+                        'width' => 100,
+                        'height' => 100,
+                        'type' => 26,
+                        'to' => $from,
+                        'uid' => wsHTML5Link::generateUID()
+                    ];
+                    $anchorExists[$from] = $anchor;
+                    $links[] = $anchor;
+                } else {
+                    if (!isset($anchorExists[$from]) && isset($anchorExists[$to])) {
+                        $anchor = $anchorExists[$to];
+                        $anchor['to'] = $from;
+                        $anchor['uid'] = wsHTML5Link::generateUID();
+                        $anchorExists[$from] = $anchor;
+                        $links[] = $anchor;
+                    }
+                }
+            }
+        }
+
+
         $this->config->pagesOfCustomLinks = $pagesOfCustomLinks;
 
         $i = 1;
@@ -1956,6 +2030,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             }
         }
 
+
         $allpages = range(0, $this->book->parametres->pages + 1);
         if ($this->book->parametres->themeEnableAfterSearch) {
             $allpages[] = 'aftersearch';
index 8f4b02b0fc017dfdc0b6156108b58990f5fe3a12..68dc938f59b559c6bafe1b453ad4e45586d65026 100644 (file)
@@ -274,6 +274,11 @@ class wsHTML5Link
 
     }
 
+    public static function generateUID()
+    {
+        return dechex(rand(0, pow(16, 10)));
+    }
+
     public function getSurface()
     {
         return $this->width * $this->height;