]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 23 Feb 2010 09:05:41 +0000 (09:05 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 23 Feb 2010 09:05:41 +0000 (09:05 +0000)
inc/extranet/Controlleur/class.ws.conversion.session.php
inc/extranet/Controlleur/class.ws.flash.php
inc/extranet/DAO/class.ws.dao.document.php
inc/extranet/Metier/_common.php
inc/extranet/Metier/class.ws.document.php
inc/extranet/Metier/class.ws.link.php [new file with mode: 0644]

index 913495e69f18603053c6aae381a06788b8ab941e..6c0accbfaf5b13a8c2f068335ed32c993d77d860 100644 (file)
@@ -6,8 +6,10 @@ class wsConversionSession {
        protected $guid;\r
        protected $progress = 0;\r
        protected $processing = false;\r
+       protected $inited=false;\r
        protected $complete = false;\r
        protected $totalPages = null;\r
+       protected $processedPages = 0;\r
 \r
        public function __construct($guid)\r
        {\r
@@ -28,21 +30,28 @@ class wsConversionSession {
                $this->totalPages = 0;\r
 \r
                foreach($this->documents as $doc) {\r
-                       $this->totalPages += $doc->getPagesNumber;\r
+                       $this->totalPages += $doc->getPagesNumber();\r
                }\r
+               $inited=true;\r
        }\r
 \r
        public function process()\r
        {\r
                $this->processing = true;\r
                $this->initDocuments();\r
+               $this->serialize();\r
 \r
-               foreach($this->documents as $doc){\r
-                       $doc->getTextes();\r
+               foreach($this->documents as $doc) {\r
+                       for($i = 1;$i <= $doc->generalInfos['pages'];$i++) {\r
+                               $doc->processOnePage($i);\r
+                               $this->processedPages++;\r
+                               $this->setProgress(($this->processedPages / $this->totalPages) * 100);\r
+                       }\r
                }\r
 \r
                $this->complete = true;\r
                $this->processing = false;\r
+               $this->setProgress(100);\r
        }\r
 \r
        public function getProgress()\r
@@ -56,6 +65,16 @@ class wsConversionSession {
                $this->serialize();\r
        }\r
 \r
+       public function getTotalPages()\r
+       {\r
+               return $this->totalPages;\r
+       }\r
+\r
+       public function getProcessedPages()\r
+       {\r
+               return $this->processedPages;\r
+       }\r
+\r
        public function serialize()\r
        {\r
                file_put_contents(self::getCachePath($this->guid), serialize($this));\r
@@ -63,7 +82,7 @@ class wsConversionSession {
 \r
        public function __destruct()\r
        {\r
-               $this->serialize();\r
+               //$this->serialize();\r
        }\r
 \r
        public static function openFromGUID($guid)\r
index 05f60190d0bacba571f32a7aa30b0a50fec7f266..096fc428ebcaef527978af9b854cd72c5218aa13 100644 (file)
@@ -71,6 +71,7 @@ class wsFlash extends cubeFlashGateway {
                $_SESSION['sessionConversionGUID'] = $sessionConversionGUID = uniqid('conversion_', true);\r
                $session = new wsConversionSession($sessionConversionGUID);\r
                $session->setDocuments($_SESSION['conversionSession']);\r
+               unset($_SESSION['conversionSession']);\r
                $session->serialize();\r
 \r
                $http = new cubeHTTP($_SERVER['HTTP_HOST']);\r
@@ -94,6 +95,8 @@ class wsFlash extends cubeFlashGateway {
                set_time_limit(1);\r
                $session = wsConversionSession::openFromGUID($_SESSION['sessionConversionGUID']);\r
                $this->xml->addChild('progress', $session->getProgress());\r
+               $this->xml->addChild('totalPages',$session->getTotalPages());\r
+               $this->xml->addChild('processedPages',$session->getProcessedPages());\r
        }\r
 }\r
 \r
index b3276a494d300a79e1689df11ea8ec1f028de07a..918987093f2a5cbbb650e8bb9dc14311e3fd040c 100644 (file)
@@ -4,6 +4,7 @@ class wsDAODocument extends extranetDAO {
        {\r
                $document = new wsDocument();\r
                $document->document_id = $r->document_id;\r
+               $document->init();\r
                $document->file = $r->file;\r
                $document->proprietaire = $r->proprietaire;\r
                $document->pages = $r->pages;\r
index 0501d9c39fd32e452f185cb22330900625fdf7a2..af70ffc8350349c2e123e071dc8f20ad97dcd760 100644 (file)
@@ -19,6 +19,7 @@ $__autoload['wsThemeParametres'] = dirname(__FILE__) . '/class.ws.theme.parametr
 $__autoload['wsBookParametres'] = dirname(__FILE__) . '/class.ws.book.parametres.php';\r
 $__autoload['wsLangueTextes'] = dirname(__FILE__) . '/class.ws.langue.textes.php';\r
 $__autoload['wsDocument'] = dirname(__FILE__) . '/class.ws.document.php';\r
+$__autoload['wsLink'] = dirname(__FILE__) . '/class.ws.link.php';\r
 $__autoload['wsDocumentLocalInfos'] = dirname(__FILE__) . '/class.ws.document.localinfos.php';\r
 \r
 ?>
\ No newline at end of file
index 3f7d093f5b85bfaffe833e23dab53b9703798672..3b1218052c3bf924175e82227e10b8e190dabaae 100644 (file)
@@ -30,8 +30,15 @@ class wsDocument extends cubeMetier {
 \r
        private $_basicInfos = null;\r
        private $_advancedInfos = null;\r
+       private $_links = array();\r
 \r
-       public function copyOriginal($tmp_file)\r
+       const NORMAL = 0;\r
+       const FLATTEN = 1;\r
+       const POLY2BITMAP = 2;\r
+       const BITMAP = 3;\r
+       const BARBARE = 4;\r
+\r
+       public function init()\r
        {\r
                $this->out = ROOT . '/docs/' . $this->document_id . '/';\r
                $this->log = $this->out . 'log.txt';\r
@@ -42,6 +49,10 @@ class wsDocument extends cubeMetier {
                        mkdir($this->out, 0755, true);\r
                }\r
                $this->log_pointer = fopen($this->log, 'a');\r
+       }\r
+\r
+       public function copyOriginal($tmp_file)\r
+       {\r
                move_uploaded_file($tmp_file, $this->in);\r
        }\r
 \r
@@ -59,6 +70,7 @@ class wsDocument extends cubeMetier {
        {\r
                if (is_null($this->_basicInfos)) {\r
                        $pdfinfo = new cubeCommandLine('pdfinfo', null, false);\r
+                       $pdfinfo->setPath(CONVERTER_PATH);\r
                        $pdfinfo->setArg('-box');\r
                        $pdfinfo->setArg('f', 1);\r
                        $pdfinfo->setArg('l', 10000);\r
@@ -75,6 +87,7 @@ class wsDocument extends cubeMetier {
        {\r
                if (is_null($this->_advancedInfos)) {\r
                        $pdftk = new cubeCommandLine('pdftk', null, true);\r
+                       $pdftk->setPath(CONVERTER_PATH);\r
                        $pdftk->setArg(null, $this->in);\r
                        $pdftk->setArg(null, 'dump_data');\r
                        $pdftk->execute();\r
@@ -144,8 +157,7 @@ class wsDocument extends cubeMetier {
                $this->getTexts($page);\r
                $this->makeMiniShot($page);\r
                $this->makeRealShot($page);\r
-               $out = $this->makeSWFFiles($page);\r
-               $this->extractLinks($page,$out,$multiply);\r
+               $this->makeSWFFiles($page);\r
        }\r
 \r
        public function processAllPages()\r
@@ -165,6 +177,7 @@ class wsDocument extends cubeMetier {
        public function getTexts($page = null)\r
        {\r
                $pdftotext = new cubeCommandLine('pdftotext', null, true);\r
+               $pdftotext->setPath(CONVERTER_PATH);\r
                $pdftotext->setArg('q');\r
                if (is_null($page)) {\r
                        $pdftotext->setArg('f', 1);\r
@@ -206,7 +219,7 @@ class wsDocument extends cubeMetier {
                // resolution 72 make 1pt=1px\r
                $height = $this->generalInfos['size'][1];\r
                $ratio = $height / $h;\r
-               $this->makeShot($prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);\r
+               $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);\r
        }\r
 \r
        public function makeShot($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS')\r
@@ -243,11 +256,12 @@ class wsDocument extends cubeMetier {
                }\r
        }\r
 \r
-       protected function makeShotGS($page = null, $prefix = null, $resolution = 72, $quality = 90, $antialiasing = 4)\r
+       protected function makeShotGS($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4)\r
        {\r
                // Fabrication des thumbanails avec ghostscript\r
                $gs = new cubeCommandLine('gs', null, true);\r
-               // $gs->setEnv('GS_FONTPATH', '/home/typo/fonts');\r
+               $gs->setPath(CONVERTER_PATH);\r
+               $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
                $gs->setArg('-dBATCH');\r
                $gs->setArg('-dNOPAUSE');\r
                $gs->setArg('-dNOPROMPT');\r
@@ -275,6 +289,7 @@ class wsDocument extends cubeMetier {
                $resolution = round($resolution);\r
                // Exporte les fichiers\r
                $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
+               $pdftoppm->setPath(CONVERTER_PATH);\r
                if (is_null($page)) {\r
                        $pdftoppm->setArg('f', 1);\r
                        $pdftoppm->setArg('l', 10000);\r
@@ -304,6 +319,7 @@ class wsDocument extends cubeMetier {
                                break;\r
                        }\r
                        $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false);\r
+                       $pnmtojpeg->setPath(CONVERTER_PATH);\r
                        $pnmtojpeg->setArg('-quality=' . $quality);\r
                        $pnmtojpeg->setArg('-density=' . $resolution . 'x' . $resolution . 'dpi');\r
                        $pnmtojpeg->setManualArg($ppmfile);\r
@@ -314,56 +330,70 @@ class wsDocument extends cubeMetier {
                }\r
        }\r
 \r
-       public function makeSWFFiles($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 'normal')\r
+       public function makeSWFFiles($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0, &$muliply = 1)\r
        {\r
                if ($maxObjects <= 1) {\r
-                       $method = 'poly2bitmap';\r
+                       $method = self::POLY2BITMAP;\r
                }\r
 \r
-               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method);\r
-               // Analyse de la sortie pour détecter des typos manquantes\r
-               $overflow = false;\r
-               $overflowObjects = false;\r
-               $written = false;\r
-               $missing_fonts = array();\r
-               $fp = fopen($out, 'rb');\r
-               while ($line = fgets($fp)) {\r
-                       if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) {\r
-                               $missing_fonts[] = $matches[1];\r
-                       } elseif (stristr($line, 'ID Table overflow')) {\r
-                               $overflow = true;\r
-                       } elseif (stristr($line, 'NOTICE  SWF written')) {\r
-                               $written = true;\r
-                       } elseif (stristr($line, 'NOTICE  Writing SWF file')) {\r
+               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, $multiply);\r
+               if ($method < self::BARBARE) {\r
+                       // Analyse de la sortie pour détecter des typos manquantes\r
+                       $overflow = false;\r
+                       $overflowObjects = false;\r
+                       $written = false;\r
+                       $missing_fonts = array();\r
+                       if (file_exists($out['outputfile'])) {\r
+                               $fp = fopen($out['outputfile'], 'rb');\r
+                               while ($line = fgets($fp)) {\r
+                                       if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) {\r
+                                               $missing_fonts[] = $matches[1];\r
+                                       } elseif (stristr($line, 'ID Table overflow')) {\r
+                                               $overflow = true;\r
+                                       } elseif (stristr($line, 'NOTICE  SWF written')) {\r
+                                               $written = true;\r
+                                       } elseif (stristr($line, 'NOTICE  Writing SWF file')) {\r
+                                               $written = true;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {\r
                                $written = true;\r
                        }\r
-               }\r
-               // On teste si le fichier est écrit et qu'il a été généré par le premier niveau\r
-               if ($method == 'flatten' && $written) {\r
-                       $swfstrings = new cubeCommandLine($this->swftools . '/swfdump', null, true);\r
-                       $swfstrings->setArg('t');\r
-                       $swfstrings->setArg(null, $this->out . '/temp.swf');\r
-                       $swfstrings->execute();\r
-\r
-                       str_replace('[01a]', '', $swfstrings->output, $nbObjects);\r
-                       if ($nbObjects > $maxObjects) {\r
-                               $overflowObjects = true;\r
+                       if ($written && $method < self::BITMAP && !isset($this->_links[$page])) {\r
+                               file_put_contents(ROOT . '/test.txt', print_r($out, true));\r
+                               $this->_links[$page] = $this->extractLinks($page, $out['outputfile'], $out['multiply']);\r
+                       }\r
+                       // On teste si le fichier est écrit et qu'il a été généré par le premier niveau\r
+                       if ($method < self::POLY2BITMAP && $written) {\r
+                               $overflowObjects = $this->checkObjectsNumber($this->out . 'p' . $page . '.swf', $maxObjects);\r
+                       }\r
+\r
+                       if (!$written || $overflow || $overflowObjects) {\r
+                               return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1, $multiply);\r
                        }\r
                }\r
-               // On traite les erreurs\r
-               if (!$written && !$overflow) {\r
-                       // Si le fichier n'a pas été généré et que il était en plus n'était pas en overflow,\r
-                       // on tente directement la méthode de barbare\r
-                       $out = $this->pdf2swf($page, $resolution, $quality, false, 'barbare');\r
-               } elseif ($overflow || $overflowObjects) {\r
-                       // Si le nombre d'objets max ou définis par l'utilisateur est trop important\r
-                       // On écrase les graphismes.\r
-                       $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, 'poly2bitmap');\r
-               }\r
+\r
                return $out;\r
        }\r
 \r
-       protected function pdf2swf($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 'normal')\r
+       protected function checkObjectsNumber($file, $maxObjects)\r
+       {\r
+               $swfdump = new cubeCommandLine('swfdump', null, true);\r
+               $swfdump->setPath(CONVERTER_PATH);\r
+               $swfdump->setArg('t');\r
+               $swfdump->setArg(null, $file);\r
+               $swfdump->execute();\r
+               $this->addToLog($swfdump);\r
+\r
+               str_replace('[01a]', '', $swfdump->output, $nbObjects);\r
+               if ($nbObjects > $maxObjects) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       protected function pdf2swf($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0)\r
        {\r
                /*\r
 -h , --help                    Print short help message and exit\r
@@ -437,25 +467,30 @@ splinequality=<value>       Set the quality of spline convertion to value (0-100
 disablelinks                Disable links.\r
        */\r
 \r
-               if ($method != 'barbare') {\r
+               if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {\r
+                       unlink($this->out . 'p' . $page . '.swf');\r
+               }\r
+\r
+               if ($method < self::BARBARE) {\r
                        $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
 \r
                        $pdf2swf = new cubeCommandLine('pdf2swf', null, true);\r
+                       $pdf2swf->setPath(CONVERTER_PATH);\r
                        if (!is_null($page)) {\r
                                $pdf2swf->setArg('p', $page);\r
                        }\r
-                       if ($method == 'normal') {\r
+                       if ($method == self::NORMAL) {\r
                                // Default\r
-                               $multiply=1;\r
-                       } elseif ($method == 'flatten') {\r
+                               $multiply = 1;\r
+                       } elseif ($method == self::FLATTEN) {\r
                                $pdf2swf->setArg('flatten');\r
-                               $multiply=1;\r
-                       } elseif ($method == 'poly2bitmap') {\r
+                               $multiply = 1;\r
+                       } elseif ($method == self::POLY2BITMAP) {\r
                                // Raster graphics, keep texts\r
                                $pdf2swf->setArg('poly2bitmap');\r
                                $multiply = $resolution2multiply[$resolution];\r
                                $pdf2swf->setArg('multiply', $multiply);\r
-                       } elseif ($method == 'bitmap') {\r
+                       } elseif ($method == self::BITMAP) {\r
                                // Raster all\r
                                $pdf2swf->setArg('bitmap');\r
                                $multiply = $resolution2multiply[$resolution];\r
@@ -483,16 +518,16 @@ disablelinks                Disable links.
                        $pdf2swf->execute();\r
 \r
                        $this->addToLog($pdf2swf, true);\r
-                       return $pdf2swf->outputfile;\r
+                       return array('outputfile' => $pdf2swf->outputfile, 'multiply' => $multiply, 'object' => $pdf2swf);\r
                } else {\r
-                       return $this->pdf2swfBarbare($page, $resolution, $quality);\r
+                       return array('outputfile' => $this->pdf2swfBarbare($page, $resolution, $quality), 'multiply' => 1);\r
                }\r
        }\r
 \r
        protected function makeAS3($swffile)\r
        {\r
                $swfcombine = new cubeCommandLine('swfcombine');\r
-               $swfcombine->setEnv('PATH', self::$path);\r
+               $swfcombine->setPath(CONVERTER_PATH);\r
                $swfcombine->setArg('merge');\r
                $swfcombine->setArg('stack1');\r
                $swfcombine->setArg('z');\r
@@ -507,7 +542,7 @@ disablelinks                Disable links.
        protected function pdf2swfBarbare($page = null, $resolution = 150, $quality = 85)\r
        {\r
                // Fabrique les images\r
-               $this->makeShot($page, 'barbare', $resolution, $quality, 'PNM');\r
+               $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'PNM');\r
                // A partir des images, on crée les swf\r
                if (is_null($page)) {\r
                        $startpage = 1;\r
@@ -518,6 +553,7 @@ disablelinks                Disable links.
 \r
                for($i = $startpage;$i <= $endpage;$i++) {\r
                        $jpeg2swf = new cubeCommandLine('jpeg2swf');\r
+                       $jpeg2swf->setPath(CONVERTER_PATH);\r
                        $jpeg2swf->setArg('q', $quality);\r
                        $jpeg2swf->setArg('o', $this->out . 'p' . $i . '.swf');\r
                        $jpeg2swf->setArg('f');\r
@@ -532,14 +568,18 @@ disablelinks                Disable links.
 \r
        public function addToLog($cl, $output = true)\r
        {\r
-               $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n";\r
-               if ($output) {\r
-                       $c .= $cl->output . "\n\n";\r
+               if ($cl instanceof cubeCommandLine) {\r
+                       $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n";\r
+                       if ($output) {\r
+                               $c .= $cl->output . "\n\n";\r
+                       }\r
+               } elseif (is_string($cl)) {\r
+                       $c = $cl;\r
                }\r
                fwrite($this->log_pointer, $c);\r
        }\r
 \r
-       public function extractLinks($page, $logfile, $multiply = 1)\r
+       public function extractLinks($page, $outputfile, $multiply = 1)\r
        {\r
                /*\r
 DEBUG   drawlink\r
@@ -553,14 +593,14 @@ TRACE   drawlink action=3
 TRACE   drawlink s=http://www.ladocumentationfrancaise.fr/\r
 */\r
 \r
-               $fp = fopen($logfile, 'rb');\r
+               $fp = fopen($outputfile, 'rb');\r
                $log = 'BEGIN extracting link' . "\n";\r
                $link = null;\r
                while ($line = fgets($fp)) {\r
                        $line = trim($line);\r
                        if (preg_match('|TRACE   drawlink(( [-0-9\./]+)+)|', $line, $matches)) {\r
                                $log .= 'FOUND a link' . "\n";\r
-                               $link = new fwsLink($multiply);\r
+                               $link = new wsLink($multiply);\r
                                $log .= 'SETTING POINTS ' . $matches[1] . "\n";\r
                                $points = explode(' ', trim($matches[1]));\r
                                foreach($points as $point) {\r
@@ -586,6 +626,7 @@ TRACE   drawlink s=http://www.ladocumentationfrancaise.fr/
                        }\r
                }\r
                $log .= 'END OF EXTRACTING' . "\n";\r
+               $this->addToLog($log);\r
                fclose($fp);\r
 \r
                return $log;\r
@@ -593,7 +634,7 @@ TRACE   drawlink s=http://www.ladocumentationfrancaise.fr/
 \r
        public function __destruct()\r
        {\r
-               if (isset($this->log_pointer)) {\r
+               if (isset($this->log_pointer) && is_resource($this->log_pointer)) {\r
                        fclose($this->log_pointer);\r
                }\r
        }\r
diff --git a/inc/extranet/Metier/class.ws.link.php b/inc/extranet/Metier/class.ws.link.php
new file mode 100644 (file)
index 0000000..db72212
--- /dev/null
@@ -0,0 +1,62 @@
+<?php\r
+class wsLink {\r
+       private $origine;\r
+       private $points;\r
+       private $action;\r
+       private $link;\r
+       private $multiply;\r
+\r
+       public function __construct($multiply = 1)\r
+       {\r
+               $this->origine = array();\r
+               $this->points = array();\r
+               $this->action = null;\r
+               $this->link = null;\r
+               $this->multiply = $multiply;\r
+       }\r
+\r
+       public function addPoint($point = array())\r
+       {\r
+               $point[0] = (float)$point[0] / $this->multiply;\r
+               $point[1] = (float)$point[1] / $this->multiply;\r
+               if ($this->origine == null) {\r
+                       $this->origine = $point;\r
+               } else {\r
+                       $this->points[] = $point;\r
+               }\r
+       }\r
+\r
+       public function setAction($action)\r
+       {\r
+               $this->action = $action;\r
+       }\r
+\r
+       public function setLink($link)\r
+       {\r
+               $this->link = $link;\r
+       }\r
+\r
+       public function toArray()\r
+       {\r
+               if (is_null($this->link)) {\r
+                       return false;\r
+               }\r
+\r
+               $res = array();\r
+               $res['left'] = $this->origine[0];\r
+               $res['top'] = $this->origine[1];\r
+\r
+               $res['width'] = $this->points[1][0] - $this->origine[0];\r
+               $res['height'] = $this->points[1][1] - $this->origine[1];\r
+\r
+               if ($this->action == 0) {\r
+                       $res['href'] = 'temp.html#' . $this->link;\r
+               } elseif ($this->action == 3) {\r
+                       $res['href'] = $this->link;\r
+               }\r
+\r
+               return $res;\r
+       }\r
+}\r
+\r
+?>
\ No newline at end of file