From e6b6fc71e229c6900f40cc787350aa3e041c5e4f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 13 Jul 2011 18:56:34 +0000 Subject: [PATCH] --- inc/ws/Controlleur/class.ws.flash.php | 4 ++ inc/ws/Util/_common.php | 3 +- inc/ws/Util/class.ws.tools.php | 70 +++++++++++++++++++ inc/ws/Util/packager/_common.php | 2 +- inc/ws/Util/packager/class.ws.packager.php | 7 +- .../{ => html5}/class.ws.packager.html5.php | 37 ++++------ 6 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 inc/ws/Util/class.ws.tools.php rename inc/ws/Util/packager/{ => html5}/class.ws.packager.html5.php (91%) diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 1432e3492..6d07dc57c 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -181,6 +181,10 @@ class wsFlash extends cubeFlashGateway { } $dest = $dir . $fname; move_uploaded_file($infos['tmp_name'], $dest); + if (in_array(strtolower(files::getExtension($dest)), array('flv', 'f4v', 'mp4'))) { + // convert uploaded file as webvideo (ogv and mp4) + wsTools::encodeWebVideos($dest, null, true, false); + } $this->xml->addChild('file', $fname); return; } diff --git a/inc/ws/Util/_common.php b/inc/ws/Util/_common.php index ce25bae62..d13335f27 100644 --- a/inc/ws/Util/_common.php +++ b/inc/ws/Util/_common.php @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php new file mode 100644 index 000000000..faf132aa9 --- /dev/null +++ b/inc/ws/Util/class.ws.tools.php @@ -0,0 +1,70 @@ +setPath(CONVERTER_PATH); + if ($async) { + $webvideo->setNohup(true); + } + $webvideo->setArg(null, $dest); + $webvideo->setArg(null, $dir); + $webvideo->execute(); + } + + public static function colorizeAndRasterizeIcon($iconSet, $icon, $color, $dest, $scale, &$w, &$h) { + // Init directory + $color = ltrim($color, '#'); + $dirColorized = WS_ICONS . '/' . $iconSet . '/mobile/' . $color . '/'; + if (!file_exists($dirColorized)) { + mkdir($dirColorized, 0777, true); + } + + + // SVG + $svgRef = WS_ICONS . '/' . $iconSet . '/mobile/' . $icon . '.svg'; + $svgColorized = $dirColorized . '/' . $icon . '.svg'; + + if (!file_exists($svgColorized) || filemtime($svgColorized) <= filemtime($svgRef)) { + $svg = file_get_contents($svgRef); + // Colorize it + $svg = str_replace('$colorize', '#' . $color, $svg); + file_put_contents($svgColorized, $svg); + } + copy($svgColorized, $dest . '/' . $icon . '.svg'); + + // PNG + $png = $dirColorized . '/' . $icon . '.png'; + if (!file_exists($png) || filemtime($png) <= filemtime($svgColorized)) { + $svg = simplexml_load_file($svgColorized); + $w = (string) $svg['width']; + $h = (string) $svg['height']; + $w = rtrim($w, 'px'); + $h = rtrim($h, 'px'); + // Finally rasterize it + $batik = new cubeCommandLine('/usr/local/batik/batik-rasterizer'); + $batik->setArg('d', $dirColorized); + $batik->setArg('m', 'image/png'); + if ($scale != 1) { + $batik->setArg('w', $w * $scale); + $batik->setArg('h', $h * $scale); + } + $batik->setManualArg($svgColorized); + $batik->execute(); + } + copy($png, $dest . '/' . $icon . '.png'); + } + +} + +?> diff --git a/inc/ws/Util/packager/_common.php b/inc/ws/Util/packager/_common.php index 17aca9b37..caa932b13 100644 --- a/inc/ws/Util/packager/_common.php +++ b/inc/ws/Util/packager/_common.php @@ -1,7 +1,7 @@ dir, 0777, true); } - $daoBook = new wsDAOBook($core->con); - $this->book = $daoBook->selectById($book_id); - $this->pages = $daoBook->getPagesOfBook($book_id); + $this->daoBook = new wsDAOBook($core->con); + $this->book = $this->daoBook->selectById($book_id); + $this->pages = $this->daoBook->getPagesOfBook($book_id); $daoTheme = new wsDAOTheme($core->con); $this->theme = $daoTheme->getThemeOfBook($book_id, true); diff --git a/inc/ws/Util/packager/class.ws.packager.html5.php b/inc/ws/Util/packager/html5/class.ws.packager.html5.php similarity index 91% rename from inc/ws/Util/packager/class.ws.packager.html5.php rename to inc/ws/Util/packager/html5/class.ws.packager.html5.php index d5dd6866f..3defc0aa6 100644 --- a/inc/ws/Util/packager/class.ws.packager.html5.php +++ b/inc/ws/Util/packager/html5/class.ws.packager.html5.php @@ -65,11 +65,22 @@ class wsPackagerHTML5 extends wsPackager { } $this->writeFonts(); $this->writeImages(); + $this->writeLinks(); $this->writeCSS($this->vdir . '/data/style/style_%d.css'); file_put_contents($this->vdir . '/data/datas.js', $this->writeConfig()); } + protected function writeLinks() { + global $core; + $daoDoc = new wsDAODocument($core->con); + $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + + foreach ($links as $link) { + fb($link); + } + } + protected function writeConfig() { $config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); $config->id = $this->book->book_id; @@ -100,36 +111,12 @@ class wsPackagerHTML5 extends wsPackager { 'next' => $arrowsColor, 'previous' => $arrowsColor, 'search' => $couleurI); foreach ($icons as $icon => $color) { - // Get content of the svg - $svg = file_get_contents(WS_ICONS . '/' . $this->theme->parametres->iconSet . '/mobile/' . $icon . '.svg'); - // Colorize it - $svg = str_replace('$colorize', $color, $svg); - // Write the file - file_put_contents($this->vdir . '/data/images/' . $icon . '.svg', $svg); - $svg = simplexml_load_string($svg); - $w = (string) $svg['width']; - $h = (string) $svg['height']; - $w = rtrim($w, 'px'); - $h = rtrim($h, 'px'); - // Finally rasterize it - $this->rasterizeSVG($this->vdir . '/data/images/' . $icon . '.svg', 'image/png', $w, $h, 4); + wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/',4, $w, $h); $res[] = '#icon-' . $icon . '{width:' . $w . 'px;height:' . $h . 'px;background-image:url(data/images/' . $icon . '.svg), url(data/images/' . $icon . '.png);background-repeat:no-repeat;background-size:' . $w . 'px ' . $h . 'px}'; } return $res; } - protected function rasterizeSVG($file, $type, $w, $h, $scale=1) { - $batik = new cubeCommandLine('/usr/local/batik/batik-rasterizer'); - $batik->setArg('d', $this->vdir . '/data/images'); - $batik->setArg('m', 'image/png'); - if ($scale != 1) { - $batik->setArg('w', $w * $scale); - $batik->setArg('h', $h * $scale); - } - $batik->setManualArg($file); - $batik->execute(); - } - protected function writeImages() { foreach (self::$resolutions as $r) { -- 2.39.5