]> _ Git - cubeextranet.git/commitdiff
#2842
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 18 Jun 2019 09:51:43 +0000 (09:51 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 18 Jun 2019 09:51:43 +0000 (09:51 +0000)
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.seo.php

index 9f2bf926e34827102b8d3bd5a5c41946b6e261f7..0c28e635f777dd3eedea3dfce71a17488f373579 100644 (file)
@@ -28,6 +28,7 @@ class wsHTML5Compiler
                 'js/libs/jquery/jquery.mousewheel.min.js',
                 'js/libs/jquery/jquery.hashchange.min.js'
             ],
+        'bluebird' => ['js/libs/bluebird.min.js'],
         'screenfull' => ['js/libs/screenfull.min.js'],
         'storage' => ['js/libs/storage.js',],
         'keymaster' => ['js/libs/keymaster.js',],
index f184c849ef769443b680dee4f620eab88669d9bf..1963b08f96f7e39f49d9da076c5a95ae5a497238 100644 (file)
 \r
 class wsHTML5Seo\r
 {\r
-       /**\r
-        * @var wsHTML5Compiler\r
-        */\r
-       public $compiler;\r
-       public $pages;\r
-       public $html;\r
-       protected $_nav = null;\r
-\r
-\r
-       public function __construct($compiler)\r
-       {\r
-               $this->compiler = $compiler;\r
-               // Define default seo contents\r
-               $this->pages = [];\r
-\r
-               foreach ($compiler->pages as $page => $infos) {\r
-                       $p = new wsHTML5SeoPage($this);\r
-                       $p->page = $page;\r
-                       $p->title = ($page == 1) ? $this->compiler->book->parametres->title : $this->_getPageLabel($page);\r
-                       $p->text = $this->getTextContent($infos);\r
-                       $p->description = $this->compiler->book->parametres->seoDescription ? $this->compiler->book->parametres->seoDescription : $this->compiler->book->parametres->title . ' - Powered by Fluidbook';\r
-                       $p->socialDescription = $this->compiler->book->parametres->facebook_description || $this->compiler->book->parametres->seoDescription;\r
-                       $p->keywords = $this->compiler->book->parametres->seoKeywords;\r
-                       $p->robots = $this->compiler->book->parametres->seoRobots ? 'index,follow' : 'noindex,nofollow';\r
-\r
-                       // Google analytics\r
-                       $p->ua = '';\r
-                       if ($this->compiler->book->parametres->googleAnalytics != '') {\r
-                               $codes = explode(',', $this->compiler->book->parametres->googleAnalytics);\r
-                               $p->ua .= "<script async src=\"https://www.googletagmanager.com/gtag/js?id=" . $codes[0] . "\"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}</script>";\r
-                       }\r
-                       if ($this->compiler->book->parametres->googleAnalyticsCustom != '') {\r
-                               $p->ua .= $this->compiler->book->parametres->googleAnalyticsCustom;\r
-                       }\r
-\r
-                       if ($this->compiler->book->parametres->statsCustom != '') {\r
-                               $p->footer = $this->compiler->book->parametres->statsCustom;\r
-                       }\r
-\r
-                       $this->pages[$page] = $p;\r
-               }\r
-\r
-\r
-               if ($compiler->book->parametres->seoAdvanced) {\r
-                       $sheets = wsUtil::excelToArray($compiler->wdir . '/' . $compiler->book->parametres->seoAdvanced, true);\r
-                       foreach ($sheets as $sheet) {\r
-                               $a = $sheet;\r
-                               break;\r
-                       }\r
-                       $minPage = 100000000;\r
-                       foreach ($a as $item) {\r
-                               $minPage = min($minPage, $item['page']);\r
-                       }\r
-                       $offsetPage = -($minPage - 1);\r
-\r
-                       foreach ($a as $item) {\r
-                               $page = $item['page'] + $offsetPage;\r
-                               $item['url'] = CubeIT_Text::removeAccents($item['url']);\r
-                               foreach ($item as $k => $v) {\r
-                                       if ($k == 'page') {\r
-                                               continue;\r
-                                       }\r
-                                       $this->pages[$page]->$k = $v;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               $this->html = file_get_contents($this->compiler->assets . '/_index.html');\r
-       }\r
-\r
-       public function getTextContent($infos)\r
-       {\r
-               switch ($this->compiler->book->parametres->textExtraction) {\r
-                       case 'poppler':\r
-                               $prefix = 'p';\r
-                               break;\r
-                       case 'fluidbook':\r
-                               $prefix = 'f';\r
-                               break;\r
-                       default:\r
-                               $prefix = '';\r
-                               break;\r
-               }\r
-\r
-               $f = wsDocument::getDir($infos['document_id']) . $prefix . 'h' . $infos['document_page'] . '.txt';\r
-               if (file_exists($f)) {\r
-                       $res = trim(file_get_contents($f));\r
-               } else {\r
-                       $res = '';\r
-               }\r
-\r
-               if (strpos($res, '<div>') !== 0) {\r
-                       $res = preg_replace('|\<\/div\>$|', '', $res);\r
-               }\r
-\r
-               return $res;\r
-       }\r
-\r
-       public function _getPageLabel($page)\r
-       {\r
-               $res = $this->compiler->book->parametres->title;\r
-               foreach ($this->compiler->book->chapters as $chapter) {\r
-                       if (trim($chapter->label, "\t\r\n\0\x0B-+") == '') {\r
-                               continue;\r
-                       }\r
-                       if ($chapter->page == '') {\r
-                               continue;\r
-                       }\r
-                       $p = $this->compiler->virtualToPhysical($chapter->page);\r
-                       if ($p == '') {\r
-                               continue;\r
-                       }\r
-                       if ($page < $p) {\r
-                               continue;\r
-                       }\r
-                       if ($page >= $p) {\r
-                               $res = $chapter->label;\r
-                       }\r
-               }\r
-               return $res;\r
-       }\r
-\r
-       public function getNav()\r
-       {\r
-               if (null == $this->_nav) {\r
-                       $this->_nav = '<nav>';\r
-                       foreach ($this->pages as $page => $p) {\r
-                               if (method_exists($p, 'getUrl')) {\r
-                                       $this->_nav .= '<a href="' . $p->getUrl() . '">' . $p->title . '</a>';\r
-                               }\r
-                       }\r
-                       $this->_nav .= '</nav>';\r
-               }\r
-               return $this->_nav;\r
-       }\r
+    /**\r
+     * @var wsHTML5Compiler\r
+     */\r
+    public $compiler;\r
+    public $pages;\r
+    public $html;\r
+    protected $_nav = null;\r
+\r
+\r
+    public function __construct($compiler)\r
+    {\r
+        $this->compiler = $compiler;\r
+        // Define default seo contents\r
+        $this->pages = [];\r
+\r
+        foreach ($compiler->pages as $page => $infos) {\r
+            $p = new wsHTML5SeoPage($this);\r
+            $p->page = $page;\r
+            $p->title = ($page == 1) ? $this->compiler->book->parametres->title : $this->_getPageLabel($page);\r
+            $p->text = $this->getTextContent($infos);\r
+            $p->description = $this->compiler->book->parametres->seoDescription ? $this->compiler->book->parametres->seoDescription : $this->compiler->book->parametres->title . ' - Powered by Fluidbook';\r
+            $p->socialDescription = $this->compiler->book->parametres->facebook_description || $this->compiler->book->parametres->seoDescription;\r
+            $p->keywords = $this->compiler->book->parametres->seoKeywords;\r
+            $p->robots = $this->compiler->book->parametres->seoRobots ? 'index,follow' : 'noindex,nofollow';\r
+\r
+            // Google analytics\r
+            $p->ua = '';\r
+            if ($this->compiler->book->parametres->googleAnalytics != '') {\r
+                $codes = explode(',', $this->compiler->book->parametres->googleAnalytics);\r
+                $p->ua .= "<script async src=\"https://www.googletagmanager.com/gtag/js?id=" . $codes[0] . "\"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}</script>";\r
+            }\r
+            if ($this->compiler->book->parametres->googleAnalyticsCustom != '') {\r
+                $p->ua .= $this->compiler->book->parametres->googleAnalyticsCustom;\r
+            }\r
+\r
+            if ($this->compiler->book->parametres->statsCustom != '') {\r
+                $p->footer = $this->compiler->book->parametres->statsCustom;\r
+            }\r
+\r
+            $this->pages[$page] = $p;\r
+        }\r
+\r
+\r
+        if ($compiler->book->parametres->seoAdvanced) {\r
+            $sheets = wsUtil::excelToArray($compiler->wdir . '/' . $compiler->book->parametres->seoAdvanced, true);\r
+            foreach ($sheets as $sheet) {\r
+                $a = $sheet;\r
+                break;\r
+            }\r
+            $minPage = 100000000;\r
+            foreach ($a as $item) {\r
+                $minPage = min($minPage, $item['page']);\r
+            }\r
+            $offsetPage = -($minPage - 1);\r
+\r
+            foreach ($a as $item) {\r
+                $page = $item['page'] + $offsetPage;\r
+                $item['url'] = CubeIT_Text::removeAccents($item['url']);\r
+                foreach ($item as $k => $v) {\r
+                    if ($k == 'page') {\r
+                        continue;\r
+                    }\r
+                    $this->pages[$page]->$k = $v;\r
+                }\r
+            }\r
+        }\r
+\r
+        $this->html = file_get_contents($this->compiler->assets . '/_index.html');\r
+    }\r
+\r
+    public function getTextContent($infos)\r
+    {\r
+        switch ($this->compiler->book->parametres->textExtraction) {\r
+            case 'poppler':\r
+                $prefix = 'p';\r
+                break;\r
+            case 'fluidbook':\r
+                $prefix = 'f';\r
+                break;\r
+            default:\r
+                $prefix = '';\r
+                break;\r
+        }\r
+\r
+        $f = wsDocument::getDir($infos['document_id']) . $prefix . 'h' . $infos['document_page'] . '.txt';\r
+        if (file_exists($f)) {\r
+            $res = trim(file_get_contents($f));\r
+        } else {\r
+            $res = '';\r
+        }\r
+\r
+        if (strpos($res, '<div>') !== 0) {\r
+            $res = preg_replace('|\<\/div\>$|', '', $res);\r
+        }\r
+\r
+        return $res;\r
+    }\r
+\r
+    public function _getPageLabel($page)\r
+    {\r
+        $res = $this->compiler->book->parametres->title;\r
+        foreach ($this->compiler->book->chapters as $chapter) {\r
+            if (trim($chapter->label, "\t\r\n\0\x0B-+") == '') {\r
+                continue;\r
+            }\r
+            if ($chapter->page == '') {\r
+                continue;\r
+            }\r
+            $p = $this->compiler->virtualToPhysical($chapter->page);\r
+            if ($p == '') {\r
+                continue;\r
+            }\r
+            if ($page < $p) {\r
+                continue;\r
+            }\r
+            if ($page >= $p) {\r
+                $res = $chapter->label;\r
+            }\r
+        }\r
+        return $res;\r
+    }\r
+\r
+    public function getNav()\r
+    {\r
+        if (null == $this->_nav) {\r
+            $this->_nav = '<nav>';\r
+            foreach ($this->pages as $page => $p) {\r
+                if (method_exists($p, 'getUrl')) {\r
+                    $this->_nav .= '<a href="' . $p->getUrl() . '">' . $p->title . '</a>';\r
+                }\r
+            }\r
+            $this->_nav .= '</nav>';\r
+        }\r
+        return $this->_nav;\r
+    }\r
 }\r
 \r
 class wsHTML5SeoPage\r
 {\r
-       public $page;\r
-       public $text;\r
-       public $title;\r
-       public $description;\r
-       public $url = null;\r
-       public $h1;\r
-       public $ua;\r
-       public $canonical;\r
-       public $prev;\r
-       public $next;\r
-       public $keywords;\r
-       public $robots;\r
-       public $footer;\r
-\r
-       /**\r
-        * @var wsHTML5Seo\r
-        */\r
-       public $_container;\r
-\r
-\r
-       public function __construct($container)\r
-       {\r
-               $this->_container = $container;\r
-       }\r
-\r
-       public function getHTML()\r
-       {\r
-               $html = $this->_container->html;\r
-\r
-               $vars = ['description' => $this->description ? '<meta name="description" content="' . $this->description . '">' : '',\r
-                       'keywords' => $this->keywords ? '<meta name="keywords" content="' . $this->keywords . '">' : '',\r
-                       'titre' => $this->title,\r
-                       'canonical' => $this->canonical ? '<link rel="canonical" href="' . $this->canonical . '">' : '',\r
-                       'prev' => $this->prev ? '<meta name="prev" href="' . $this->prev . '">' : '',\r
-                       'next' => $this->next ? '<meta name="next" href="' . $this->next . '">' : '',\r
-                       'robots' => $this->robots ? '<meta name="robots" content="' . $this->robots . '">' : '',\r
-                       'statsfooter' => $this->footer,\r
-                       'ga' => $this->ua,\r
-                       'seoContent' => $this->getSEOContent(),\r
-                       'startpage' => '<script type="text/javascript">var FLUIDBOOK_START_PAGE="' . $this->page . '";</script>' . "\n"];\r
-\r
-               foreach ($vars as $k => $var) {\r
-                       $html = str_replace('<!-- $' . $k . ' -->', $var, $html);\r
-               }\r
-\r
-               return $html;\r
-       }\r
-\r
-       public function getSEOContent()\r
-       {\r
-\r
-\r
-               $res = '';\r
-               if (null !== $this->h1) {\r
-                       $res .= '<h1>' . htmlentities($this->h1) . '</h1>';\r
-               }\r
-               $res .= $this->text;\r
-               $res .= $this->_container->getNav();\r
-               return $res;\r
-       }\r
-\r
-       public function getURL()\r
-       {\r
-               if (null === $this->url) {\r
-                       return $this->page . '-' . CubeIT_Text::str2URL(CubeIT_Text::removeAccents($this->title)) . '.html';\r
-               }\r
-               return $this->url;\r
-       }\r
-\r
-       public function getHTMLRelativePath()\r
-       {\r
-               $url = $this->getURL();\r
-               if (null == $this->url) {\r
-                       $res = 'p/' . $url;\r
-               }\r
-\r
-               if ($this->_container->compiler->book->parametres->seoBaseURL == '') {\r
-                       $res = $url;\r
-               } else {\r
-                       $res = str_replace($this->_container->compiler->book->parametres->seoBaseURL, '', $url);\r
-               }\r
-\r
-               return ltrim($res, '/');\r
-       }\r
-\r
-       /**\r
-        * @param string $html\r
-        * @param CubeIT_Files_VirtualDirectory $vdir\r
-        * @param null|string $path\r
-        */\r
-       public function writePage($html, $vdir, $path = null)\r
-       {\r
-               if ($path == null) {\r
-                       $path = $this->getHTMLRelativePath();\r
-               }\r
-               $relativeLevel = count(explode('/', rtrim($path, "/"))) - 1;\r
-               $base = '';\r
-               if ($relativeLevel > 0) {\r
-                       $base = '<base href="' . str_repeat('../', $relativeLevel) . '" >';\r
-               }\r
-               $html = str_replace('<!-- $base -->', $base, $html);\r
-\r
-               $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/';\r
-               if (!file_exists($dir)) {\r
-                       mkdir($dir, 0777, true);\r
-               }\r
-               $file = $dir . $this->page . '.html';\r
-               $hash = sha1($html);\r
-               $hashfile = $dir . $this->page . '.hash';\r
-               if (!file_exists($hashfile) || file_get_contents($hashfile) != $hash) {\r
-                       file_put_contents($file, $html);\r
-                       file_put_contents($hashfile, $hash);\r
-               }\r
-               $vdir->copy($file, $path);\r
-       }\r
+    public $page;\r
+    public $text;\r
+    public $title;\r
+    public $description;\r
+    public $url = null;\r
+    public $h1;\r
+    public $ua;\r
+    public $canonical;\r
+    public $prev;\r
+    public $next;\r
+    public $keywords;\r
+    public $robots;\r
+    public $footer;\r
+\r
+    /**\r
+     * @var wsHTML5Seo\r
+     */\r
+    public $_container;\r
+\r
+\r
+    public function __construct($container)\r
+    {\r
+        $this->_container = $container;\r
+    }\r
+\r
+    public function getHTML()\r
+    {\r
+        $html = $this->_container->html;\r
+\r
+        $vars = ['description' => $this->description ? '<meta name="description" content="' . $this->description . '">' : '',\r
+            'keywords' => $this->keywords ? '<meta name="keywords" content="' . $this->keywords . '">' : '',\r
+            'titre' => $this->title,\r
+            'canonical' => $this->canonical ? '<link rel="canonical" href="' . $this->canonical . '">' : '',\r
+            'prev' => $this->prev ? '<meta name="prev" href="' . $this->prev . '">' : '',\r
+            'next' => $this->next ? '<meta name="next" href="' . $this->next . '">' : '',\r
+            'robots' => $this->robots ? '<meta name="robots" content="' . $this->robots . '">' : '',\r
+            'statsfooter' => $this->footer,\r
+            'ga' => $this->ua,\r
+            'seoContent' => $this->getSEOContent(),\r
+            'startpage' => '<script type="text/javascript">var FLUIDBOOK_START_PAGE="' . $this->page . '";</script>' . "\n"];\r
+\r
+        foreach ($vars as $k => $var) {\r
+            $html = str_replace('<!-- $' . $k . ' -->', $var, $html);\r
+        }\r
+\r
+        return $html;\r
+    }\r
+\r
+    public function getSEOContent()\r
+    {\r
+\r
+\r
+        $res = '';\r
+        if (null !== $this->h1) {\r
+            $res .= '<h1>' . htmlentities($this->h1) . '</h1>';\r
+        }\r
+        $res .= $this->text;\r
+        $res .= $this->_container->getNav();\r
+        return $res;\r
+    }\r
+\r
+    public function getURL()\r
+    {\r
+        if (null === $this->url) {\r
+            return $this->page . '-' . CubeIT_Text::str2URL(CubeIT_Text::removeAccents($this->title)) . '.html';\r
+        }\r
+        return $this->url;\r
+    }\r
+\r
+    public function getHTMLRelativePath()\r
+    {\r
+        $url = $this->getURL();\r
+        if (null == $this->url) {\r
+            $res = 'p/' . $url;\r
+        }\r
+\r
+        if ($this->_container->compiler->book->parametres->seoBaseURL == '') {\r
+            $res = $url;\r
+        } else {\r
+            $res = str_replace($this->_container->compiler->book->parametres->seoBaseURL, '', $url);\r
+        }\r
+\r
+        return ltrim($res, '/');\r
+    }\r
+\r
+    /**\r
+     * @param string $html\r
+     * @param CubeIT_Files_VirtualDirectory $vdir\r
+     * @param null|string $path\r
+     */\r
+    public function writePage($html, $vdir, $path = null)\r
+    {\r
+        if ($path == null) {\r
+            $path = $this->getHTMLRelativePath();\r
+        }\r
+        $relativeLevel = count(explode('/', rtrim($path, "/"))) - 1;\r
+        $base = '';\r
+        if ($relativeLevel > 0) {\r
+            $base = '<base href="' . str_repeat('../', $relativeLevel) . '" >';\r
+        }\r
+        $html = str_replace('<!-- $base -->', $base, $html);\r
+\r
+        $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/';\r
+        if (!file_exists($dir)) {\r
+            mkdir($dir, 0777, true);\r
+        }\r
+        $file = $dir . $this->page . '.html';\r
+        $hash = sha1($html);\r
+        $hashfile = $dir . $this->page . '.hash';\r
+        if (!file_exists($hashfile) || file_get_contents($hashfile) != $hash) {\r
+            file_put_contents($file, $html);\r
+            file_put_contents($hashfile, $hash);\r
+        }\r
+        $vdir->copy($file, $path);\r
+    }\r
 }
\ No newline at end of file