]> _ Git - cubeextranet.git/commitdiff
#2384
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 29 Nov 2018 17:51:55 +0000 (17:51 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 29 Nov 2018 17:51:55 +0000 (17:51 +0000)
inc/commons/class.common.ajax.php
inc/commons/class.common.tools.php
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Controlleur/class.ws.url.php
inc/ws/Util/class.ws.tools.php

index 409576783e3dac163159cd8684a1e207937fc01c..2aacaae29d6c83acfae097f3145dd4c1e69ae89d 100644 (file)
@@ -472,4 +472,5 @@ Mot de passe : $password";
                $mail->send($transport);
        }
 
+
 }
index ea3e48360264dace66cdd8bd0b1d1496e4a16967..eae96d4847f4c79b6f2b663d64ca93abf76a5d1a 100644 (file)
@@ -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 .= '<form action="/tools/dowspagestohtml" class="notajax" method="get">';
+               $res .= '<table class="liste">';
+               $res .= '<tr><th colspan="3"><strong>' . __('Convertir une page du fluidbook en HTML') . '</strong></th></tr>';
+               $res .= '<tr><td>' . __('Fluidbook') . '</td><td>' . form::field('fluidbook', 5, 5) . '</td></tr>';
+               $res .= '<tr><td>' . __('Page') . '</td><td>' . form::field('page', 5, 5) . '</td></tr>';
+               $res .= '<tr><td class="right" colspan="3"><a href="#" class="submit">' . $core->typo->BoutonOK(__('Convertir')) . '</a></td></td>';
+               $res .= '</table>';
+               $res .= '</form>';
+               $res .= '</div>';
+               $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);
index 8cd26209d1442c63f58fa3e8cce189c6e327b62d..45b393ac9f7824d5c5634570310578c391e57d2d 100644 (file)
@@ -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('<br />', $reset) . '<br />';
-       //              echo 'skip : ' . implode(', ', $skip) . '<br />';
-       //              echo 'error : ' . implode(', ', $error) . '<br />';
-       //
-       //      }
+       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()
        {
index 36e508fea7e0f93121e0c682170c2ee6156b8638..1b6e0e1d7f2c60768bc8bfbf7699ef34d149d1dd 100644 (file)
@@ -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;
index 9526374dccd5e32f33373e9992cb82afa9555436..548fb5a240a1ed5544270ade55cec43d2ecff232 100644 (file)
@@ -1,10 +1,15 @@
 <?php
 
-class wsTools {
+class wsTools
+{
 
        protected static $_r;
+       protected static $_i;
+       protected static $_e;
+       protected static $_u;
 
-       public static function encodeWebVideos($file, $dir = null, $async = true, $force = false, $format = 'all') {
+       public static function encodeWebVideos($file, $dir = null, $async = true, $force = false, $format = 'all')
+       {
                if (is_null($dir)) {
                        $dir = dirname($file);
                }
@@ -52,7 +57,8 @@ class wsTools {
                $webvideo->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('|\<image([^>]*)\>|', '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 '<image />';
+               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 = '<image ';
+               foreach ($attrs as $k => $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 .= '<div class="page" id="p' . $item . '">';
+                               $svg .= self::_svg(file_get_contents($f), $item);
+                               $svg .= '</div>';
+                               $css .= '#p' . $item . '{left:' . $left . 'px;}';
+                               $left += ($width - 1);
+                       }
+               }
+
+               $res = '<html>';
+               $res .= '<head>';
+               $res .= '<meta name="width" value="' . $left . '">';
+               $res .= '<meta name="height" value="' . $height . '">';
+               $res .= '<!-- tweenmax --><script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script><!-- -->';
+               $res .= '<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><!-- -->';
+               $res .= '<script src="main.js"></script>';
+               $res .= '<style type="text/css">*{padding:0;margin:0}svg{display: block;}.page{position: absolute;top: 0;}.page svg{width:' . $width . 'px;height:' . $height . 'px;}' . $css . '</style></head>';
+               $res .= '<link href="main.css" type="text/css" rel="stylesheet" />';
+               $res .= '<body>';
+               $res .= $svg;
+               $res .= '</body>';
+               $res .= '</html>';
+
+               $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('/\<image([^\>]*)\>/m', function ($matches) use ($p) {
+                       self::$_i++;
+                       return '<g id="p' . $p . '-imageholder-' . self::$_i . '"><image id="p' . $p . '-image-' . self::$_i . '" ' . $matches[1] . '></g>';
+               }, $c);
+               $c = str_replace('</image>', '</image></g></g>', $c);
+
+               $c = preg_replace_callback('/<path /', function () use ($p) {
+                       self::$_e++;
+                       return '<path id="p' . $p . '-e-' . self::$_e . '" ';
+               }, $c);
+               $c = preg_replace_callback('/<use /', function () use ($p) {
+                       self::$_u++;
+                       return '<use id="p' . $p . '-u-' . self::$_u . '" ';
+               }, $c);
+
+               return $c;
        }
 
 
+       public function chiffres()
+       {
+
+       }
+
 
 }