From f9de6a3561edca6e185352b308acc98899d204de Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 8 Feb 2011 10:33:31 +0000 Subject: [PATCH] --- inc/ws/Controlleur/_common.php | 2 +- inc/ws/Controlleur/class.ws.ajax.php | 6 +- inc/ws/Controlleur/class.ws.book.packager.php | 12 -- inc/ws/Controlleur/packager/_common.php | 5 + .../packager/class.ws.packager.html.php | 134 ++++++++++++++++++ .../packager/class.ws.packager.php | 112 +++++++++++++++ 6 files changed, 255 insertions(+), 16 deletions(-) delete mode 100644 inc/ws/Controlleur/class.ws.book.packager.php create mode 100644 inc/ws/Controlleur/packager/_common.php create mode 100644 inc/ws/Controlleur/packager/class.ws.packager.html.php create mode 100644 inc/ws/Controlleur/packager/class.ws.packager.php diff --git a/inc/ws/Controlleur/_common.php b/inc/ws/Controlleur/_common.php index 99be5facb..551049511 100644 --- a/inc/ws/Controlleur/_common.php +++ b/inc/ws/Controlleur/_common.php @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 3f2e25dd9..bbda3a668 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -219,15 +219,15 @@ class wsAjax extends cubeAjax { $popup = commonAjax::form('downbook/' . $book_id . '/' . $version, __('Téléchargement du Fluidbook'), wsUrl::valideDownload($book_id, $version), - __('Télécharger'),2,'','',true); + __('Télécharger'), 2, '', '', true); $x->addOpenPopup($popup); return; } } - $packager = new wsBookPackager($book_id); - $x->addRedirection($packager->makePackage($version)); + $url = wsPackager::package($book_id, $version); + $x->addRedirection($url); } public static function changeLang($args, &$x) diff --git a/inc/ws/Controlleur/class.ws.book.packager.php b/inc/ws/Controlleur/class.ws.book.packager.php deleted file mode 100644 index c94960eaa..000000000 --- a/inc/ws/Controlleur/class.ws.book.packager.php +++ /dev/null @@ -1,12 +0,0 @@ - \ No newline at end of file diff --git a/inc/ws/Controlleur/packager/_common.php b/inc/ws/Controlleur/packager/_common.php new file mode 100644 index 000000000..99b8a6890 --- /dev/null +++ b/inc/ws/Controlleur/packager/_common.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/inc/ws/Controlleur/packager/class.ws.packager.html.php b/inc/ws/Controlleur/packager/class.ws.packager.html.php new file mode 100644 index 000000000..b2e01a2e5 --- /dev/null +++ b/inc/ws/Controlleur/packager/class.ws.packager.html.php @@ -0,0 +1,134 @@ +version = 'html'; + } + + public function makePackage() + { + parent::makePackage(); + + $this->copyFluidbookFiles(); + $this->copyOtherFiles(array('fluidbook.js', 'getflash.gif', 'index.html', 'index.swf', 'player.swf', 'style.css')); + + mkdir($this->vdir . '/pages/', 0777, true); + + $ga = ''; + if ($this->book->parametres->googleAnalytics != '') { + $ga = cubePage::googleAnalytics(explode(',', $this->book->parametres->googleAnalytics)); + } + + $facebook = ''; + if ($this->book->parametres->facebook) { + if ($this->book->parametres->facebook_title != '') { + $facebook .= ''; + } else { + $facebook .= ''; + } + if ($this->book->parametres->facebook_description != '') { + $facebook .= ''; + } + $facebook .= ''; + } + // Stuffs to replace in html + $toReplace = array('lang' => strtolower($this->book->lang), 'title' => htmlentities($this->book->parametres->title, ENT_COMPAT, 'UTF-8'), 'ga' => $ga, 'facebook' => $facebook, 'bgcolor' => $this->theme->parametres->loadingBackColor); + + $this->origHTML = file_get_contents($this->vdir . '/index.html'); + $this->origHTML = $this->replaceHTML($toReplace); + + $nav1 = $this->makeHTMLNav(true); + $nav = $this->makeHTMLNav(false); + $footer = $this->makeHTMLFooter(); + + foreach($this->pages as $page => $infos) { + $pathToIndex = 'index.swf'; + $redirectScript = ''; + if ($page == 1) { + $dest = 'index.html'; + } else { + $dest = 'pages/page' . $page . '.html'; + $pathToIndex = '../index.swf'; + $redirectScript = ''; + } + $alt = ''; + + $htmlfile = WS_DOCS . '/' . $infos['document_id'] . '/h' . $infos['document_page'] . '.txt'; + + if (file_exists($htmlfile)) { + $html = file($htmlfile); + + array_pop($html); + array_splice($html, 0, 6); + foreach($html as $i => $h) { + $html[$i] = trim($h) . ' '; + } + $html = implode("", $html); + $alt .= $html . "\n"; + } + + if ($page == 1) { + $alt .= $nav1; + } else { + $alt .= $nav; + } + $alt .= $footer; + + $data = str_replace('$alt', $alt , $this->origHTML); + $data = str_replace('$pathToIndex', $pathToIndex, $data); + $data = str_replace('$redirectScript', $redirectScript, $data); + + file_put_contents($this->vdir . $dest, $data); + } + + return $this->zip(); + } + + protected function makeHTMLNav($root) + { + $res = ''; + return $res; + } + + protected function makeHTMLFooter() + { + $res = ''; + return $res; + } + + protected function replaceHTML($toReplace) + { + $res = $this->origHTML; + foreach($toReplace as $k => $v) { + if (is_null($v)) { + return; + } + $res = str_replace('$' . $k, $v, $res); + } + return $res; + } +} + +?> \ No newline at end of file diff --git a/inc/ws/Controlleur/packager/class.ws.packager.php b/inc/ws/Controlleur/packager/class.ws.packager.php new file mode 100644 index 000000000..452707ec6 --- /dev/null +++ b/inc/ws/Controlleur/packager/class.ws.packager.php @@ -0,0 +1,112 @@ +makePackage(); + } + + public function __construct($book_id) + { + global $core; + + $this->dir = WS_FILES . '/packager/' . $book_id . '/'; + + if (!file_exists($this->dir)) { + mkdir($this->dir, 0777, true); + } + + $daoBook = new wsDAOBook($core->con); + $this->book = $daoBook->selectById($book_id); + $this->pages = $daoBook->getPagesOfBook($book_id); + + $daoTheme = new wsDAOTheme($core->con); + $this->theme = $daoTheme->getThemeOfBook($book_id, true); + } + + public function makePackage() + { + $this->initTempDir(); + } + + protected function copyFluidbookFiles() + { + // Copie du FB vers un répertoire temporaire + $cp = new cubeCommandLine('cp'); + $cp->setArg('R'); + $cp->setArg(null, WS_BOOKS . '/final/' . $this->book->book_id . '/*'); + $cp->setArg(null, $this->vdir); + $cp->execute(); + } + + protected function copyOtherFiles($files) + { + foreach($files as $f) { + copy(WS_COMPILE_ASSETS . '/' . $f, $this->vdir . $f); + } + } + + protected function zip($zipfile = null) + { + $base = '/packager/download/' . $this->version . '-' . date('Ymdhis') . '-' . cubeText::str2URL($this->book->parametres->title) . '.zip'; + $url = '/fluidbook' . $base; + $final = WS_FILES . $base ; + $rename = false; + if (is_null($zipfile)) { + $zipfile = $final; + } else { + $rename = true; + } + + $zip = new cubeCommandLine('zip'); + $zip->cd($this->vdir); + $zip->setArg(null, $zipfile); + $zip->setArg('0'); + $zip->setArg('u'); + $zip->setArg('r'); + $zip->setArg('X'); + $zip->setArg(null, '.'); + $zip->execute(); + + if ($rename) { + rename($zipfile, $final); + } + return $url; + } + + protected function initTempDir() + { + $this->vdir = $this->dir . $this->version . '/'; + $this->cleanVdir(); + mkdir($this->vdir, 0777, true); + } + + protected function cleanVdir() + { + if (file_exists($this->vdir)) { + // Suppression du répertoire si il existe + $rm = new cubeCommandLine('rm'); + $rm->setArg('r'); + $rm->setArg('f'); + $rm->setArg(null, $this->vdir); + $rm->execute(); + } + } + + public function __destruct() + { + $this->cleanVdir(); + } +} + +?> \ No newline at end of file -- 2.39.5