From: vincent@cubedesigners.com Date: Thu, 29 Nov 2018 17:51:55 +0000 (+0000) Subject: #2384 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8b5d62542d31b95c58b018550132ed0abce74b0e;p=cubeextranet.git #2384 --- diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index 409576783..2aacaae29 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -472,4 +472,5 @@ Mot de passe : $password"; $mail->send($transport); } + } diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index ea3e48360..eae96d484 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -1086,6 +1086,39 @@ class commonTools } } + public static function wspagestohtml() + { + commonDroits::min(5); + global $core; + $res = commonPage::barre(); + $res .= commonPage::tMain(); + $res .= commonPage::bh(); + $res .= '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Convertir une page du fluidbook en HTML') . '
' . __('Fluidbook') . '' . form::field('fluidbook', 5, 5) . '
' . __('Page') . '' . form::field('page', 5, 5) . '
' . $core->typo->BoutonOK(__('Convertir')) . '
'; + $res .= '
'; + $res .= ''; + $res .= commonPage::bf(); + $res .= commonPage::bMain(); + return $res; + } + + public static function dowspagestohtml() + { + commonDroits::min(5); + global $core; + + $book_id = $_GET['fluidbook']; + $page = $_GET['page']; + + $z = wsTools::pages2html($book_id, $page); + cubeHTTP::downloadFile($z['path'], $z['name']); + } + public static function SNCFCodes() { //commonDroits::min(1); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 8cd26209d..45b393ac9 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1463,61 +1463,21 @@ class wsMaintenance exit; } - public static function testSVG() - { - $test = '/home/extranet/www/fluidbook/docs/117077/html/zz%s.svg'; - echo wsTools::optimizeSVG('/home/extranet/www/fluidbook/docs/117077/html/fp11.svg', $test, [150, 300], true); - } - - // public function addSearch() { - // global $core; - // $r = $core->con->select('SELECT book_id, parametres FROM books WHERE book_id'); - // $reset = []; - // $error = []; - // $skip = []; - // while ($r->fetch()) { - // /** @var wsBookParametres $parametres */ - // try { - // $former = - // $parametres = unserialize($r->parametres); - // $order = explode(',', $parametres->navOrder); - // $former = $parametres->navOrder; - // $order = array_map('trim', $order); - // if (in_array('search', $order)) { - // $skip[] = $r->book_id; - // continue; - // } - // - // $searchLocation = 0; - // $chaptersLocation = array_search('chapters', $order); - // if ($chaptersLocation !== false) { - // $searchLocation = $chaptersLocation + 1; - // } else { - // $indexLocation = array_search('index', $order); - // if ($indexLocation !== false) { - // $searchLocation = $indexLocation + 1; - // } - // } - // array_splice($order, $searchLocation, 0, 'search'); - // - // $newOrder = join(', ' , $order); - // - // $c = $core->con->openCursor('books'); - // $parametres->navOrder=$newOrder; - // $c->parametres = serialize($parametres); - // $c->changedate = TIME; - // $c->update('WHERE book_id=' . $r->book_id); - // $reset[] = $r->book_id . ' : ' . $former . ' -> ' . $newOrder; - // } catch (Exception $e) { - // $error[] = $r->book_id; - // } - // } - // - // echo 'reset : ' . implode('
', $reset) . '
'; - // echo 'skip : ' . implode(', ', $skip) . '
'; - // echo 'error : ' . implode(', ', $error) . '
'; - // - // } + public static function testSVG($args) + { + global $core; + + $book = $args[0]; + $page = $args[1]; + + $dao = new wsDAOBook($core->con); + $pages = $dao->getPagesOfBook($book); + $p = $pages[$page]; + + $dir = wsDocument::getDir($p['document_id']); + $test = $dir . '/html/zz%s.svg'; + wsTools::optimizeSVG($dir . '/html/fp' . $p['document_page'] . '.svg', $test, [150, 300], true); + } public static function svgToFlash() { diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 36e508fea..1b6e0e1d7 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -1108,7 +1108,7 @@ html{height:100%}' . "\n"; $dao->compile($book_id, 'html5'); $time = self::getHTML5CacheTime($book_id); - if (count($e) == 2 || $e[2] <= $time - 10) { + if (count($e) == 2 /*|| $e[2] <= $time - 10*/) { $e[2] = $time; http::redirect(SITE_PATH . 'viewerh/' . implode('_', $e) . '/'); exit; diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index 9526374dc..548fb5a24 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -1,10 +1,15 @@ execute(); } - public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true) { + public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true) + { // Init directory if (is_string($colors)) { $colors = array('colorize' => $colors); @@ -138,7 +144,8 @@ class wsTools { } } - public static function optimizeSVG($original, $optimized, $resolutions = [], $force = false) { + public static function optimizeSVG($original, $optimized, $resolutions = [], $force = false) + { if (!file_exists($original)) { return 'doesnt exists'; @@ -174,7 +181,9 @@ class wsTools { foreach ($resolutions as $resolution) { self::$_r = $resolution; $osvg = preg_replace_callback('|\]*)\>|', 'wsTools::optimizeRaster', $svg); - file_put_contents(sprintf($optimized, '-' . $resolution), $osvg); + $ofname = sprintf($optimized, '-' . $resolution); + echo $ofname . "\n"; + file_put_contents($ofname, $osvg); } } return true; @@ -182,12 +191,52 @@ class wsTools { return false; } - public static function optimizeRaster($matches) { + public static function optimizeRaster($matches) + { + preg_match_all('/([a-z\:\-]*)="([^"]*)"/', $matches[1], $m); - return ''; + foreach ($m[1] as $i => $key) { + $attrs[$key] = $m[2][$i]; + } + $e = explode(',', $attrs['xlink:href'], 2); + $image = imagecreatefromstring(base64_decode($e[1])); + $iw = imagesx($image); + $ih = imagesy($image); + $scale = 1; + if (isset($attrs['transform']) && strpos($attrs['transform'], 'matrix(') === 0) { + preg_match_all('/([\d\-\.]+)/', $attrs['transform'], $ma); + $values = $ma[0]; + $scale = max($values[0], $values[1]); + + } + + $resolutionScale = ($iw / $attrs['width']) * $scale * (self::$_r / 72); + echo $resolutionScale . "\n"; + + $dw = round($resolutionScale * $iw); + $dh = round($resolutionScale * $ih); + + $im = imagecreatetruecolor($dw, $dh); + imagecopyresampled($im, $image, 0, 0, 0, 0, $dw, $dh, $iw, $ih); + imagedestroy($image); + + $tmp = CubeIT_Files::tempnam(); + imagejpeg($im, $tmp, 85); + imagedestroy($im); + + $attrs['xlink:href'] = 'data:image/jpeg;base64,' . base64_encode(file_get_contents($tmp)); + unlink($tmp); + + $res = ' $v) { + $res .= $k . '="' . $v . '" '; + } + $res .= '/>'; + return $res; } - public static function copy($source, $dest) { + public static function copy($source, $dest) + { if (!file_exists($source)) { return; } @@ -199,10 +248,97 @@ class wsTools { touch($dest, filemtime($source)); } - public function chiffres() { + public static function pages2html($book_id, $page) + { + global $core; + if ($page % 2 == 1) { + $page--; + } + + $convert = [$page, $page + 1]; + + $dao = new wsDAOBook($core->con); + $pages = $dao->getPagesOfBook($book_id); + $svg = ''; + $left = 0; + $css = ''; + foreach ($convert as $item) { + + if (isset($pages[$item])) { + $p = $pages[$item]; + $dir = wsDocument::getDir($p['document_id']); + $f = $dir . '/html/fo' . $p['document_page'] . '-150.svg'; + + if (!isset($width)) { + $s = CubeIT_Image::getimagesize($f); + $width = $s[0]; + $height = $s[1]; + } + + $svg .= '
'; + $svg .= self::_svg(file_get_contents($f), $item); + $svg .= '
'; + $css .= '#p' . $item . '{left:' . $left . 'px;}'; + $left += ($width - 1); + } + } + + $res = ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= $svg; + $res .= ''; + $res .= ''; + + $n = 'fb_' . $book_id . '_' . $page . '.zip'; + $zipname = '/tmp/' . $n; + $zip = new ZipArchive(); + $zip->open($zipname, ZipArchive::CREATE); + $zip->addFromString('index.html', $res); + $zip->close(); + return ['name' => $n, 'path' => $zipname]; + } + + protected static function _svg($c, $p) + { + self::$_i = 0; + self::$_e = 0; + self::$_u = 0; + + $c = str_replace('id="', 'id="p' . $p . '-', $c); + $c = str_replace('url(#', 'url(#p' . $p . '-', $c); + $c = str_replace('xlink:href="#', 'xlink:href="#p' . $p . '-', $c); + $c = preg_replace_callback('/\]*)\>/m', function ($matches) use ($p) { + self::$_i++; + return ''; + }, $c); + $c = str_replace('', '', $c); + + $c = preg_replace_callback('/