From 98b9b7feb3e6b71dc1a384de2d5640daea210692 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 18 Jun 2019 09:51:43 +0000 Subject: [PATCH] #2842 --- .../html5/master/class.ws.html5.compiler.php | 1 + .../Util/html5/master/class.ws.html5.seo.php | 500 +++++++++--------- 2 files changed, 251 insertions(+), 250 deletions(-) diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 9f2bf926e..0c28e635f 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -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',], diff --git a/inc/ws/Util/html5/master/class.ws.html5.seo.php b/inc/ws/Util/html5/master/class.ws.html5.seo.php index f184c849e..1963b08f9 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.seo.php +++ b/inc/ws/Util/html5/master/class.ws.html5.seo.php @@ -2,258 +2,258 @@ class wsHTML5Seo { - /** - * @var wsHTML5Compiler - */ - public $compiler; - public $pages; - public $html; - protected $_nav = null; - - - public function __construct($compiler) - { - $this->compiler = $compiler; - // Define default seo contents - $this->pages = []; - - foreach ($compiler->pages as $page => $infos) { - $p = new wsHTML5SeoPage($this); - $p->page = $page; - $p->title = ($page == 1) ? $this->compiler->book->parametres->title : $this->_getPageLabel($page); - $p->text = $this->getTextContent($infos); - $p->description = $this->compiler->book->parametres->seoDescription ? $this->compiler->book->parametres->seoDescription : $this->compiler->book->parametres->title . ' - Powered by Fluidbook'; - $p->socialDescription = $this->compiler->book->parametres->facebook_description || $this->compiler->book->parametres->seoDescription; - $p->keywords = $this->compiler->book->parametres->seoKeywords; - $p->robots = $this->compiler->book->parametres->seoRobots ? 'index,follow' : 'noindex,nofollow'; - - // Google analytics - $p->ua = ''; - if ($this->compiler->book->parametres->googleAnalytics != '') { - $codes = explode(',', $this->compiler->book->parametres->googleAnalytics); - $p->ua .= ""; - } - if ($this->compiler->book->parametres->googleAnalyticsCustom != '') { - $p->ua .= $this->compiler->book->parametres->googleAnalyticsCustom; - } - - if ($this->compiler->book->parametres->statsCustom != '') { - $p->footer = $this->compiler->book->parametres->statsCustom; - } - - $this->pages[$page] = $p; - } - - - if ($compiler->book->parametres->seoAdvanced) { - $sheets = wsUtil::excelToArray($compiler->wdir . '/' . $compiler->book->parametres->seoAdvanced, true); - foreach ($sheets as $sheet) { - $a = $sheet; - break; - } - $minPage = 100000000; - foreach ($a as $item) { - $minPage = min($minPage, $item['page']); - } - $offsetPage = -($minPage - 1); - - foreach ($a as $item) { - $page = $item['page'] + $offsetPage; - $item['url'] = CubeIT_Text::removeAccents($item['url']); - foreach ($item as $k => $v) { - if ($k == 'page') { - continue; - } - $this->pages[$page]->$k = $v; - } - } - } - - $this->html = file_get_contents($this->compiler->assets . '/_index.html'); - } - - public function getTextContent($infos) - { - switch ($this->compiler->book->parametres->textExtraction) { - case 'poppler': - $prefix = 'p'; - break; - case 'fluidbook': - $prefix = 'f'; - break; - default: - $prefix = ''; - break; - } - - $f = wsDocument::getDir($infos['document_id']) . $prefix . 'h' . $infos['document_page'] . '.txt'; - if (file_exists($f)) { - $res = trim(file_get_contents($f)); - } else { - $res = ''; - } - - if (strpos($res, '
') !== 0) { - $res = preg_replace('|\<\/div\>$|', '', $res); - } - - return $res; - } - - public function _getPageLabel($page) - { - $res = $this->compiler->book->parametres->title; - foreach ($this->compiler->book->chapters as $chapter) { - if (trim($chapter->label, "\t\r\n\0\x0B-+") == '') { - continue; - } - if ($chapter->page == '') { - continue; - } - $p = $this->compiler->virtualToPhysical($chapter->page); - if ($p == '') { - continue; - } - if ($page < $p) { - continue; - } - if ($page >= $p) { - $res = $chapter->label; - } - } - return $res; - } - - public function getNav() - { - if (null == $this->_nav) { - $this->_nav = ''; - } - return $this->_nav; - } + /** + * @var wsHTML5Compiler + */ + public $compiler; + public $pages; + public $html; + protected $_nav = null; + + + public function __construct($compiler) + { + $this->compiler = $compiler; + // Define default seo contents + $this->pages = []; + + foreach ($compiler->pages as $page => $infos) { + $p = new wsHTML5SeoPage($this); + $p->page = $page; + $p->title = ($page == 1) ? $this->compiler->book->parametres->title : $this->_getPageLabel($page); + $p->text = $this->getTextContent($infos); + $p->description = $this->compiler->book->parametres->seoDescription ? $this->compiler->book->parametres->seoDescription : $this->compiler->book->parametres->title . ' - Powered by Fluidbook'; + $p->socialDescription = $this->compiler->book->parametres->facebook_description || $this->compiler->book->parametres->seoDescription; + $p->keywords = $this->compiler->book->parametres->seoKeywords; + $p->robots = $this->compiler->book->parametres->seoRobots ? 'index,follow' : 'noindex,nofollow'; + + // Google analytics + $p->ua = ''; + if ($this->compiler->book->parametres->googleAnalytics != '') { + $codes = explode(',', $this->compiler->book->parametres->googleAnalytics); + $p->ua .= ""; + } + if ($this->compiler->book->parametres->googleAnalyticsCustom != '') { + $p->ua .= $this->compiler->book->parametres->googleAnalyticsCustom; + } + + if ($this->compiler->book->parametres->statsCustom != '') { + $p->footer = $this->compiler->book->parametres->statsCustom; + } + + $this->pages[$page] = $p; + } + + + if ($compiler->book->parametres->seoAdvanced) { + $sheets = wsUtil::excelToArray($compiler->wdir . '/' . $compiler->book->parametres->seoAdvanced, true); + foreach ($sheets as $sheet) { + $a = $sheet; + break; + } + $minPage = 100000000; + foreach ($a as $item) { + $minPage = min($minPage, $item['page']); + } + $offsetPage = -($minPage - 1); + + foreach ($a as $item) { + $page = $item['page'] + $offsetPage; + $item['url'] = CubeIT_Text::removeAccents($item['url']); + foreach ($item as $k => $v) { + if ($k == 'page') { + continue; + } + $this->pages[$page]->$k = $v; + } + } + } + + $this->html = file_get_contents($this->compiler->assets . '/_index.html'); + } + + public function getTextContent($infos) + { + switch ($this->compiler->book->parametres->textExtraction) { + case 'poppler': + $prefix = 'p'; + break; + case 'fluidbook': + $prefix = 'f'; + break; + default: + $prefix = ''; + break; + } + + $f = wsDocument::getDir($infos['document_id']) . $prefix . 'h' . $infos['document_page'] . '.txt'; + if (file_exists($f)) { + $res = trim(file_get_contents($f)); + } else { + $res = ''; + } + + if (strpos($res, '
') !== 0) { + $res = preg_replace('|\<\/div\>$|', '', $res); + } + + return $res; + } + + public function _getPageLabel($page) + { + $res = $this->compiler->book->parametres->title; + foreach ($this->compiler->book->chapters as $chapter) { + if (trim($chapter->label, "\t\r\n\0\x0B-+") == '') { + continue; + } + if ($chapter->page == '') { + continue; + } + $p = $this->compiler->virtualToPhysical($chapter->page); + if ($p == '') { + continue; + } + if ($page < $p) { + continue; + } + if ($page >= $p) { + $res = $chapter->label; + } + } + return $res; + } + + public function getNav() + { + if (null == $this->_nav) { + $this->_nav = ''; + } + return $this->_nav; + } } class wsHTML5SeoPage { - public $page; - public $text; - public $title; - public $description; - public $url = null; - public $h1; - public $ua; - public $canonical; - public $prev; - public $next; - public $keywords; - public $robots; - public $footer; - - /** - * @var wsHTML5Seo - */ - public $_container; - - - public function __construct($container) - { - $this->_container = $container; - } - - public function getHTML() - { - $html = $this->_container->html; - - $vars = ['description' => $this->description ? '' : '', - 'keywords' => $this->keywords ? '' : '', - 'titre' => $this->title, - 'canonical' => $this->canonical ? '' : '', - 'prev' => $this->prev ? '' : '', - 'next' => $this->next ? '' : '', - 'robots' => $this->robots ? '' : '', - 'statsfooter' => $this->footer, - 'ga' => $this->ua, - 'seoContent' => $this->getSEOContent(), - 'startpage' => '' . "\n"]; - - foreach ($vars as $k => $var) { - $html = str_replace('', $var, $html); - } - - return $html; - } - - public function getSEOContent() - { - - - $res = ''; - if (null !== $this->h1) { - $res .= '

' . htmlentities($this->h1) . '

'; - } - $res .= $this->text; - $res .= $this->_container->getNav(); - return $res; - } - - public function getURL() - { - if (null === $this->url) { - return $this->page . '-' . CubeIT_Text::str2URL(CubeIT_Text::removeAccents($this->title)) . '.html'; - } - return $this->url; - } - - public function getHTMLRelativePath() - { - $url = $this->getURL(); - if (null == $this->url) { - $res = 'p/' . $url; - } - - if ($this->_container->compiler->book->parametres->seoBaseURL == '') { - $res = $url; - } else { - $res = str_replace($this->_container->compiler->book->parametres->seoBaseURL, '', $url); - } - - return ltrim($res, '/'); - } - - /** - * @param string $html - * @param CubeIT_Files_VirtualDirectory $vdir - * @param null|string $path - */ - public function writePage($html, $vdir, $path = null) - { - if ($path == null) { - $path = $this->getHTMLRelativePath(); - } - $relativeLevel = count(explode('/', rtrim($path, "/"))) - 1; - $base = ''; - if ($relativeLevel > 0) { - $base = ''; - } - $html = str_replace('', $base, $html); - - $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/'; - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - $file = $dir . $this->page . '.html'; - $hash = sha1($html); - $hashfile = $dir . $this->page . '.hash'; - if (!file_exists($hashfile) || file_get_contents($hashfile) != $hash) { - file_put_contents($file, $html); - file_put_contents($hashfile, $hash); - } - $vdir->copy($file, $path); - } + public $page; + public $text; + public $title; + public $description; + public $url = null; + public $h1; + public $ua; + public $canonical; + public $prev; + public $next; + public $keywords; + public $robots; + public $footer; + + /** + * @var wsHTML5Seo + */ + public $_container; + + + public function __construct($container) + { + $this->_container = $container; + } + + public function getHTML() + { + $html = $this->_container->html; + + $vars = ['description' => $this->description ? '' : '', + 'keywords' => $this->keywords ? '' : '', + 'titre' => $this->title, + 'canonical' => $this->canonical ? '' : '', + 'prev' => $this->prev ? '' : '', + 'next' => $this->next ? '' : '', + 'robots' => $this->robots ? '' : '', + 'statsfooter' => $this->footer, + 'ga' => $this->ua, + 'seoContent' => $this->getSEOContent(), + 'startpage' => '' . "\n"]; + + foreach ($vars as $k => $var) { + $html = str_replace('', $var, $html); + } + + return $html; + } + + public function getSEOContent() + { + + + $res = ''; + if (null !== $this->h1) { + $res .= '

' . htmlentities($this->h1) . '

'; + } + $res .= $this->text; + $res .= $this->_container->getNav(); + return $res; + } + + public function getURL() + { + if (null === $this->url) { + return $this->page . '-' . CubeIT_Text::str2URL(CubeIT_Text::removeAccents($this->title)) . '.html'; + } + return $this->url; + } + + public function getHTMLRelativePath() + { + $url = $this->getURL(); + if (null == $this->url) { + $res = 'p/' . $url; + } + + if ($this->_container->compiler->book->parametres->seoBaseURL == '') { + $res = $url; + } else { + $res = str_replace($this->_container->compiler->book->parametres->seoBaseURL, '', $url); + } + + return ltrim($res, '/'); + } + + /** + * @param string $html + * @param CubeIT_Files_VirtualDirectory $vdir + * @param null|string $path + */ + public function writePage($html, $vdir, $path = null) + { + if ($path == null) { + $path = $this->getHTMLRelativePath(); + } + $relativeLevel = count(explode('/', rtrim($path, "/"))) - 1; + $base = ''; + if ($relativeLevel > 0) { + $base = ''; + } + $html = str_replace('', $base, $html); + + $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/'; + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + $file = $dir . $this->page . '.html'; + $hash = sha1($html); + $hashfile = $dir . $this->page . '.hash'; + if (!file_exists($hashfile) || file_get_contents($hashfile) != $hash) { + file_put_contents($file, $html); + file_put_contents($hashfile, $hash); + } + $vdir->copy($file, $path); + } } \ No newline at end of file -- 2.39.5