From 2c40f4397543d1f37c836d1b094b0f09e638d197 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 5 Jul 2018 16:30:15 +0000 Subject: [PATCH] wip #2116 @4 --- inc/ws/Metier/class.ws.book.parametres.php | 3 +- .../advancedseo/class.ws.html5.compiler.php | 55 ++++++------------- .../html5/advancedseo/class.ws.html5.seo.php | 39 ++++++++++++- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index 5af5e9fe9..fd3fc8337 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -484,9 +484,10 @@ class wsBookParametres extends wsParametres $this->fields['seoDescription'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __('Meta tag Description')); $this->fields['seoKeywords'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __('Meta tag Keywords')); $this->fields['seoAdvanced'] = ['type' => 'freefile', 'default' => '', 'editable' => true, 'label' => __('Données SEO par page'), 'grade' => 5, 'fileFilter' => $seoFilter]; + $this->fields['seoBaseURL'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __('URL de base'), 'grade' => 5, 'hint' => __("Si l'authentification échoue, redirection vers cette adresse")); $this->forms['seo'] = array('label' => __('Optimisation pour les moteurs de recherche'), - 'fieldsnames' => array('seoVersion', 'seoRobots', 'seoDescription', "seoKeywords", '|', 'seoAdvanced')); + 'fieldsnames' => array('seoVersion', 'seoRobots', 'seoDescription', "seoKeywords", '|', 'seoBaseURL', 'seoAdvanced')); $this->fields['home'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Accueil de l'interface multibrochure"), 'grade' => 5); $this->fields['multilang'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __('Langues'), 'hint' => __('Code langue') . ',' . __('Code pays') . ',' . __('URL')); 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 852ac734d..3be2a1f49 100644 --- a/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/advancedseo/class.ws.html5.compiler.php @@ -363,6 +363,7 @@ class wsHTML5Compiler $this->log('Langs written'); $this->writeSEO(); $this->writeIndex(); + $this->writeWidget(); $this->log('Index written'); $this->writeSounds(); $this->log('Sound written'); @@ -477,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 = $this->seo->pages[1]->getHTML(); - $uhtml = $html; + $seo = $this->seo->pages[$page]; + $html = $seo->getHTML(); $titre = $this->book->parametres->title; @@ -526,7 +527,7 @@ class wsHTML5Compiler $iscript .= '' . "\n"; } - $script = ''; + $script = '' . "\n"; $script .= '' . "\n"; $script .= '' . "\n"; if ($this->book->parametres->scorm_enable) { @@ -627,45 +628,21 @@ class wsHTML5Compiler } } - $scripts = array(); - foreach ($this->debugJsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->jsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->pluginJs as $js) { - $scripts[] = ''; - } - - $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('credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); - foreach ($vars as $v) { - $uhtml = str_replace('', $$v, $uhtml); + $seo->writePage($html, $this->vdir); + if ($page == 1) { + $seo->writePage($html, $this->vdir, 'index.html'); } + } - $script .= "\n\t\t" . ''; - $vars = array('credits', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); - foreach ($vars as $v) { - $thtml = str_replace('', $$v, $thtml); + protected function writeIndex() + { + foreach ($this->pages as $page => $infos) { + $this->_writeIndex($page); } + } - $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'); diff --git a/inc/ws/Util/html5/advancedseo/class.ws.html5.seo.php b/inc/ws/Util/html5/advancedseo/class.ws.html5.seo.php index 4f8661f8f..4890796db 100644 --- a/inc/ws/Util/html5/advancedseo/class.ws.html5.seo.php +++ b/inc/ws/Util/html5/advancedseo/class.ws.html5.seo.php @@ -143,7 +143,6 @@ class wsHTML5SeoPage $compiler = $this->_container->compiler; $html = file_get_contents($this->_container->compiler->assets . '/_index.html'); - $vars = ['description' => $this->description ? '' : '', 'keywords' => $this->keywords ? '' : '', 'titre' => $this->title, @@ -176,8 +175,44 @@ class wsHTML5SeoPage public function getURL() { if (null === $this->url) { - return $this->page . '-' . CubeIT_Text::str2URL($this->title); + 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 -- 2.39.5