From: vincent@cubedesigners.com Date: Fri, 20 Jul 2018 13:08:55 +0000 (+0000) Subject: wait #2116 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=62e245081b43a377fdeb9bec6d2d3f05f790366e;p=cubeextranet.git wait #2116 @0.5 --- diff --git a/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php b/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php index 3be2a1f49..5bf08d9d2 100644 --- a/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php @@ -1157,6 +1157,7 @@ class wsHTML5Compiler switch ($this->config->basketManager) { case 'Remarkable': $this->addJs('js/libs/parsley.min.js'); + $this->addJs('js/libs/jquery/jquery.cookie.js'); $this->addJs('js/libs/fluidbook/cart/fluidbook.cart.remarkable.js'); break; default: @@ -1818,7 +1819,7 @@ class wsHTML5Compiler $res = array('width' => 0, 'height' => 0); if (file_exists($d . '/index.html')) { $doc = new DOMDocument(); - $doc->loadHTMLFile($d . '/index.html'); + @$doc->loadHTMLFile($d . '/index.html'); $xpath = new DOMXPath($doc); $c = $xpath->query("//canvas"); foreach ($c as $canvas) { 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 c2206d310..ed57b637d 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -2,7 +2,7 @@ class wsHTML5Compiler { - protected static $resolutions = array(150, 300); + public static $resolutions = array(150, 300); public $maxRes = 300; public $jsFiles = array( @@ -98,17 +98,17 @@ class wsHTML5Compiler public $pluginCSS = array(); public $pluginJs = array(); public $htmlmultimedia = array(); - protected $cssX = array(); - protected $cssY = array(); - protected $cssWidths = array(); - protected $pdf2htmlRatio; - protected $scale; - protected $multiply; - protected $div = array(); - protected $numerotation; - protected $fontDocs = array(); - protected $dir; - protected $z = 3; + public $cssX = array(); + public $cssY = array(); + public $cssWidths = array(); + public $pdf2htmlRatio; + public $scale; + public $multiply; + public $div = array(); + public $numerotation; + public $fontDocs = array(); + public $dir; + public $z = 3; public $vdir; public $wdir; @@ -117,51 +117,55 @@ class wsHTML5Compiler * @var wsBook */ public $book; - protected $pages; - protected $theme; + public $pages; + public $theme; public $version; public $book_id; - protected $themeRoot; + public $themeRoot; /** * * @var wsDAOBook */ - protected $daoBook; - protected $needToRecompileContents = true; - protected $needToRecompileSettings = true; + public $daoBook; + public $needToRecompileContents = true; + public $needToRecompileSettings = true; public $width; public $height; - protected $cssWidth; - protected $cssHeight; - protected $cssOneWidth; - protected $cssOneHeight; - protected $cssScale; - protected $cssSVGScale; - protected $optimalWidth = 567; - protected $optimalHeight = 709; - protected $additionalConfig = array(); - protected $fontScale = 1; - protected $cache = array(); - protected $backgroundsPrefix = array(); - protected $svg = true; - protected $config = array(); - protected $assets = ''; - protected $phonegap = false; - protected $phonegapVersion; - protected $standalone = false; - protected $hiddenContents = array(); - protected $appcache; - protected $home; - protected $widget = true; - protected $multiApp = false; - protected $pageLabels = array(); - protected $stylesheets = array(); - protected $logfp = null; - protected $logtime = null; - protected $beginBody = array(); - protected $seoArticles = []; - protected $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com']; + public $cssWidth; + public $cssHeight; + public $cssOneWidth; + public $cssOneHeight; + public $cssScale; + public $cssSVGScale; + public $optimalWidth = 567; + public $optimalHeight = 709; + public $additionalConfig = array(); + public $fontScale = 1; + public $cache = array(); + public $backgroundsPrefix = array(); + public $svg = true; + public $config = array(); + public $assets = ''; + public $phonegap = false; + public $phonegapVersion; + public $standalone = false; + public $hiddenContents = array(); + public $appcache; + public $home; + public $widget = true; + public $multiApp = false; + public $pageLabels = array(); + public $stylesheets = array(); + public $logfp = null; + public $logtime = null; + public $beginBody = array(); + public $seoArticles = []; + public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com']; + /** + * @var wsHTML5Seo + */ + public $seo = null; function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) @@ -357,7 +361,9 @@ class wsHTML5Compiler $this->log('CSS written'); $this->writeLangs(); $this->log('Langs written'); + $this->writeSEO(); $this->writeIndex(); + $this->writeWidget(); $this->log('Index written'); $this->writeSounds(); $this->log('Sound written'); @@ -367,7 +373,6 @@ class wsHTML5Compiler $this->log('Extras written'); $this->writeJs(); $this->log('Js written'); - $this->writeSEO(); $this->vdir->sync($delete); $this->log('Files Synced'); } @@ -473,12 +478,12 @@ class wsHTML5Compiler $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds'); } - protected function writeIndex() + protected function _writeIndex($page) { global $core; - $html = file_get_contents($this->assets . '/_index.html'); - $uhtml = $html; + $seo = $this->seo->pages[$page]; + $html = $seo->getHTML(); $titre = $this->book->parametres->title; @@ -501,19 +506,6 @@ class wsHTML5Compiler $bgcolor = $this->theme->parametres->loadingBackColor; - // Google analytics - $ga = ''; - if ($this->book->parametres->googleAnalytics != '') { - $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); - } - if ($this->book->parametres->googleAnalyticsCustom != '') { - $ga .= $this->book->parametres->googleAnalyticsCustom; - } - - $statsfooter = ''; - if ($this->book->parametres->statsCustom != '') { - $statsfooter = $this->book->parametres->statsCustom; - } // Feuilles de style $sheets = array_merge($this->stylesheets, $this->specialCSS); @@ -536,7 +528,7 @@ class wsHTML5Compiler $iscript .= '' . "\n"; } - $script = ''; + $script = '' . "\n"; $script .= '' . "\n"; $script .= '' . "\n"; if ($this->book->parametres->scorm_enable) { @@ -550,7 +542,6 @@ class wsHTML5Compiler $script .= '' . "\n"; } $script .= $iscript; - $description = ''; $socialTitle = $this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre; $socialDescription = $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $this->book->parametres->seoDescription; @@ -629,7 +620,7 @@ class wsHTML5Compiler if ($this->phonegap) { $csp = "securityPolicyWhitelist)) . "; img-src * data:\">"; } - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard'); + $vars = array('credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard'); foreach ($vars as $v) { if (isset($$v)) { $html = str_replace('', $$v, $html); @@ -638,45 +629,21 @@ class wsHTML5Compiler } } - $scripts = array(); - foreach ($this->debugJsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->jsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->pluginJs as $js) { - $scripts[] = ''; + $seo->writePage($html, $this->vdir); + if ($page == 1) { + $seo->writePage($html, $this->vdir, 'index.html'); } - - $scripts[] = ''; - $scripts[] = $iscript; - $script = implode("\n\t\t", $scripts); - - $scripts = array(); - foreach ($this->testJsFiles as $js) { - $scripts[] = ''; } - $scripts[] = ''; - $script_test = implode("\n\t\t", $scripts); - - $thtml = $uhtml; - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); - foreach ($vars as $v) { - $uhtml = str_replace('', $$v, $uhtml); + protected function writeIndex() + { + foreach ($this->pages as $page => $infos) { + $this->_writeIndex($page); } - - $script .= "\n\t\t" . ''; - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); - foreach ($vars as $v) { - $thtml = str_replace('', $$v, $thtml); } - $this->vdir->file_put_contents('index.html', $html); - $this->vdir->file_put_contents('indexu.html', $uhtml); - $this->vdir->file_put_contents('indext.html', $thtml); - + protected function writeWidget() + { // Write widget html if ($this->widget) { $whtml = file_get_contents($this->assets . '/widget.html'); @@ -710,6 +677,7 @@ class wsHTML5Compiler } $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html); } + $this->seo = new wsHTML5Seo($this); } protected function writeScorm() diff --git a/inc/ws/Util/html5/master/class.ws.html5.seo.php b/inc/ws/Util/html5/master/class.ws.html5.seo.php new file mode 100644 index 000000000..4890796db --- /dev/null +++ b/inc/ws/Util/html5/master/class.ws.html5.seo.php @@ -0,0 +1,218 @@ +compiler = $compiler; + // Define default seo contents + $this->pages = []; + + foreach ($compiler->pages as $page => $infos) { + $p = new wsHTML5SeoPage($this); + $p->page = $page; + $p->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->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 != '') { + $p->ua .= cubePage::googleAnalytics($this->compiler->book->parametres->googleAnalytics); + } + 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; + foreach ($item as $k => $v) { + if ($k == 'page') { + continue; + } + $this->pages[$page]->$k = $v; + } + } + } + } + + public function getTextContent($infos) + { + switch ($this->compiler->book->parametres->textExtraction) { + case 'poppler': + $prefix = 'p'; + break; + case 'fluidbook': + $prefix = 'f'; + break; + default: + $prefix = ''; + break; + } + + return file_get_contents(wsDocument::getDir($infos['document_id']) . $prefix . 'h' . $infos['document_page'] . '.txt'); + } + + public function _getPageLabel($page) + { + $res = $this->compiler->book->parametres->title; + foreach ($this->compiler->book->chapters as $chapter) { + $p = $this->compiler->virtualToPhysical($chapter->page); + 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() + { + $compiler = $this->_container->compiler; + $html = file_get_contents($this->_container->compiler->assets . '/_index.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()]; + + 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($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); + + $vdir->file_put_contents($path, $html); + } +} \ No newline at end of file