<?php\r
+include_once(dirname(__FILE__) . '/packager/_common.php');\r
// Workshop\r
$__autoload['wsFlash'] = dirname(__FILE__) . '/class.ws.flash.php';\r
$__autoload['wsAjax'] = dirname(__FILE__) . '/class.ws.ajax.php';\r
$__autoload['wsServices'] = dirname(__FILE__) . '/class.ws.services.php';\r
$__autoload['wsUsersTree'] = dirname(__FILE__) . '/class.ws.users.tree.php';\r
$__autoload['wsSecureSWF'] = dirname(__FILE__) . '/class.ws.secure.swf.php';\r
-$__autoload['wsBookPackager'] = dirname(__FILE__) . '/class.ws.book.packager.php';\r
\r
?>
\ No newline at end of file
$popup = commonAjax::form('downbook/' . $book_id . '/' . $version,\r
__('Téléchargement du Fluidbook'),\r
wsUrl::valideDownload($book_id, $version),\r
- __('Télécharger'),2,'','',true);\r
+ __('Télécharger'), 2, '', '', true);\r
\r
$x->addOpenPopup($popup);\r
return;\r
}\r
}\r
\r
- $packager = new wsBookPackager($book_id);\r
- $x->addRedirection($packager->makePackage($version));\r
+ $url = wsPackager::package($book_id, $version);\r
+ $x->addRedirection($url);\r
}\r
\r
public static function changeLang($args, &$x)\r
+++ /dev/null
-<?php\r
-class wsBookPackager {\r
- public function __construct($book_id)\r
- {\r
- }\r
-\r
- public function makePackage($version)\r
- {\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
--- /dev/null
+<?php\r
+$__autoload['wsPackager'] = dirname(__FILE__) . '/class.ws.packager.php';\r
+$__autoload['wsPackagerHTML'] = dirname(__FILE__) . '/class.ws.packager.html.php';\r
+\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+class wsPackagerHTML extends wsPackager {\r
+ protected $origHTML;\r
+\r
+ public function __construct($book_id)\r
+ {\r
+ parent::__construct($book_id);\r
+ $this->version = 'html';\r
+ }\r
+\r
+ public function makePackage()\r
+ {\r
+ parent::makePackage();\r
+\r
+ $this->copyFluidbookFiles();\r
+ $this->copyOtherFiles(array('fluidbook.js', 'getflash.gif', 'index.html', 'index.swf', 'player.swf', 'style.css'));\r
+\r
+ mkdir($this->vdir . '/pages/', 0777, true);\r
+\r
+ $ga = '';\r
+ if ($this->book->parametres->googleAnalytics != '') {\r
+ $ga = cubePage::googleAnalytics(explode(',', $this->book->parametres->googleAnalytics));\r
+ }\r
+\r
+ $facebook = '';\r
+ if ($this->book->parametres->facebook) {\r
+ if ($this->book->parametres->facebook_title != '') {\r
+ $facebook .= '<meta property="og:title" content="' . $this->book->parametres->facebook_title . '" />';\r
+ } else {\r
+ $facebook .= '<meta property="og:title" content="' . $this->book->parametres->title . '" />';\r
+ }\r
+ if ($this->book->parametres->facebook_description != '') {\r
+ $facebook .= '<meta property="og:description" content="' . $this->book->parametres->facebook_description . '" />';\r
+ }\r
+ $facebook .= '<meta property="og:image" content="http://dev.ws.fluidbook.com/services/facebook_thumbnail?id=' . $this->book->book_id . '" />';\r
+ }\r
+ // Stuffs to replace in html\r
+ $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);\r
+\r
+ $this->origHTML = file_get_contents($this->vdir . '/index.html');\r
+ $this->origHTML = $this->replaceHTML($toReplace);\r
+\r
+ $nav1 = $this->makeHTMLNav(true);\r
+ $nav = $this->makeHTMLNav(false);\r
+ $footer = $this->makeHTMLFooter();\r
+\r
+ foreach($this->pages as $page => $infos) {\r
+ $pathToIndex = 'index.swf';\r
+ $redirectScript = '';\r
+ if ($page == 1) {\r
+ $dest = 'index.html';\r
+ } else {\r
+ $dest = 'pages/page' . $page . '.html';\r
+ $pathToIndex = '../index.swf';\r
+ $redirectScript = '<script type="text/javascript">window.location=\'../index.html#' . $page . '\';</script>';\r
+ }\r
+ $alt = '';\r
+\r
+ $htmlfile = WS_DOCS . '/' . $infos['document_id'] . '/h' . $infos['document_page'] . '.txt';\r
+\r
+ if (file_exists($htmlfile)) {\r
+ $html = file($htmlfile);\r
+\r
+ array_pop($html);\r
+ array_splice($html, 0, 6);\r
+ foreach($html as $i => $h) {\r
+ $html[$i] = trim($h) . ' ';\r
+ }\r
+ $html = implode("", $html);\r
+ $alt .= $html . "\n";\r
+ }\r
+\r
+ if ($page == 1) {\r
+ $alt .= $nav1;\r
+ } else {\r
+ $alt .= $nav;\r
+ }\r
+ $alt .= $footer;\r
+\r
+ $data = str_replace('$alt', $alt , $this->origHTML);\r
+ $data = str_replace('$pathToIndex', $pathToIndex, $data);\r
+ $data = str_replace('$redirectScript', $redirectScript, $data);\r
+\r
+ file_put_contents($this->vdir . $dest, $data);\r
+ }\r
+\r
+ return $this->zip();\r
+ }\r
+\r
+ protected function makeHTMLNav($root)\r
+ {\r
+ $res = '<ul id="nav">';\r
+ foreach($this->pages as $page => $infos) {\r
+ if ($page == 1) {\r
+ if ($root) {\r
+ $url = 'index.html';\r
+ } else {\r
+ $url = '../index.html';\r
+ }\r
+ } else {\r
+ if ($root) {\r
+ $url = 'pages/page' . $page . '.html';\r
+ } else {\r
+ $url = 'page' . $page . '.html';\r
+ }\r
+ }\r
+ $res .= '<li><a href="' . $url . '">Page ' . $page . '</a></li>';\r
+ }\r
+ $res .= '</ul>';\r
+ return $res;\r
+ }\r
+\r
+ protected function makeHTMLFooter()\r
+ {\r
+ $res = '<div class="footer">';\r
+ $res .= '<h2><a href="http://www.fluidbook.com">Fluidbook : Solution de catalogues interactifs et brochures en ligne</a></h2>';\r
+ $res .= '</div>';\r
+ return $res;\r
+ }\r
+\r
+ protected function replaceHTML($toReplace)\r
+ {\r
+ $res = $this->origHTML;\r
+ foreach($toReplace as $k => $v) {\r
+ if (is_null($v)) {\r
+ return;\r
+ }\r
+ $res = str_replace('$' . $k, $v, $res);\r
+ }\r
+ return $res;\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+class wsPackager {\r
+ protected $dir;\r
+ protected $vdir;\r
+ protected $book;\r
+ protected $pages;\r
+ protected $theme;\r
+ protected $version;\r
+\r
+ public static function package($book_id, $version)\r
+ {\r
+ if ($version == 'html') {\r
+ $packager = new wsPackagerHTML($book_id);\r
+ }\r
+\r
+ return $packager->makePackage();\r
+ }\r
+\r
+ public function __construct($book_id)\r
+ {\r
+ global $core;\r
+\r
+ $this->dir = WS_FILES . '/packager/' . $book_id . '/';\r
+\r
+ if (!file_exists($this->dir)) {\r
+ mkdir($this->dir, 0777, true);\r
+ }\r
+\r
+ $daoBook = new wsDAOBook($core->con);\r
+ $this->book = $daoBook->selectById($book_id);\r
+ $this->pages = $daoBook->getPagesOfBook($book_id);\r
+\r
+ $daoTheme = new wsDAOTheme($core->con);\r
+ $this->theme = $daoTheme->getThemeOfBook($book_id, true);\r
+ }\r
+\r
+ public function makePackage()\r
+ {\r
+ $this->initTempDir();\r
+ }\r
+\r
+ protected function copyFluidbookFiles()\r
+ {\r
+ // Copie du FB vers un répertoire temporaire\r
+ $cp = new cubeCommandLine('cp');\r
+ $cp->setArg('R');\r
+ $cp->setArg(null, WS_BOOKS . '/final/' . $this->book->book_id . '/*');\r
+ $cp->setArg(null, $this->vdir);\r
+ $cp->execute();\r
+ }\r
+\r
+ protected function copyOtherFiles($files)\r
+ {\r
+ foreach($files as $f) {\r
+ copy(WS_COMPILE_ASSETS . '/' . $f, $this->vdir . $f);\r
+ }\r
+ }\r
+\r
+ protected function zip($zipfile = null)\r
+ {\r
+ $base = '/packager/download/' . $this->version . '-' . date('Ymdhis') . '-' . cubeText::str2URL($this->book->parametres->title) . '.zip';\r
+ $url = '/fluidbook' . $base;\r
+ $final = WS_FILES . $base ;\r
+ $rename = false;\r
+ if (is_null($zipfile)) {\r
+ $zipfile = $final;\r
+ } else {\r
+ $rename = true;\r
+ }\r
+\r
+ $zip = new cubeCommandLine('zip');\r
+ $zip->cd($this->vdir);\r
+ $zip->setArg(null, $zipfile);\r
+ $zip->setArg('0');\r
+ $zip->setArg('u');\r
+ $zip->setArg('r');\r
+ $zip->setArg('X');\r
+ $zip->setArg(null, '.');\r
+ $zip->execute();\r
+\r
+ if ($rename) {\r
+ rename($zipfile, $final);\r
+ }\r
+ return $url;\r
+ }\r
+\r
+ protected function initTempDir()\r
+ {\r
+ $this->vdir = $this->dir . $this->version . '/';\r
+ $this->cleanVdir();\r
+ mkdir($this->vdir, 0777, true);\r
+ }\r
+\r
+ protected function cleanVdir()\r
+ {\r
+ if (file_exists($this->vdir)) {\r
+ // Suppression du répertoire si il existe\r
+ $rm = new cubeCommandLine('rm');\r
+ $rm->setArg('r');\r
+ $rm->setArg('f');\r
+ $rm->setArg(null, $this->vdir);\r
+ $rm->execute();\r
+ }\r
+ }\r
+\r
+ public function __destruct()\r
+ {\r
+ $this->cleanVdir();\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file