From ab59c265d46a2373f6a54abd62924b2ae9b5195c Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 4 Oct 2021 14:05:10 +0200 Subject: [PATCH] First commit --- include/Docsbox.php | 112 ++++++++++++++++++++++++++++++ include/dokument_export.class.php | 71 +++++++++---------- 2 files changed, 148 insertions(+), 35 deletions(-) create mode 100644 include/Docsbox.php diff --git a/include/Docsbox.php b/include/Docsbox.php new file mode 100644 index 000000000..08b04f71b --- /dev/null +++ b/include/Docsbox.php @@ -0,0 +1,112 @@ +attach(array('file' => $inputFileName)) + ->expectsJson() + ->send(); + + var_dump($response);exit; + } + catch(\Httpful\Exception\ConnectionErrorException $cee) + { + // Error + } + catch (Exception $e) + { + // Error + } + + if (is_object($response) && isset($response->id) && isset($response->status)) + { + $status = null; + $result_url = null; + + while ($status == null) + { + try + { + $response = \Httpful\Request::get('http://docconverter.technikum-wien.at/api/v1/'.$response->id) + ->expectsJson() + ->send(); + + var_dump($response); + } + catch(\Httpful\Exception\ConnectionErrorException $cee) + { + // Error + } + catch (Exception $e) + { + // Error + } + + if (is_object($response) && isset($response->id) && isset($response->status)) + { + if ($response->status == 'finished' && isset($response->result_url)) + { + $status = $response->status; + $result_url = $response->result_url; + } + else + { + // Error + } + } + else + { + // Error + } + } + + try + { + $response = \Httpful\Request::get($result_url)->send(); + + var_dump($response); + } + catch(\Httpful\Exception\ConnectionErrorException $cee) + { + // Error + } + catch (Exception $e) + { + // Error + } + + var_dump($response);exit; + } + else + { + // Error + } + } +} + diff --git a/include/dokument_export.class.php b/include/dokument_export.class.php index 4f23a7dcd..30af55ac6 100644 --- a/include/dokument_export.class.php +++ b/include/dokument_export.class.php @@ -37,7 +37,6 @@ class dokument_export private $images=array(); private $sourceDir; public $errormsg; - private $unoconv_version; private $sign; private $sign_user; private $sign_profile; @@ -50,18 +49,6 @@ class dokument_export if(!isset($vorlage)) return; - exec('unoconv --version',$ret_arr); - if(isset($ret_arr[0])) - { - $hlp = explode(' ',$ret_arr[0]); - if(isset($hlp[1])) - $this->unoconv_version = $hlp[1]; - else - die('Could not get Unoconv Version'); - } - else - die('Unoconv not found'); - //Vorlage aus der Datenbank holen $this->vorlage = new vorlage(); if(!$this->vorlage->getAktuelleVorlage($oe_kurzbz, $vorlage, $version)) @@ -281,20 +268,27 @@ class dokument_export // Unoconv Version 0.6 hat eine Bug wodurch die Berechtigungen des PDF/Doc nicht korrekt gesetzt // werden. Deshalb wird dies hier speziell behandelt. // Die 2. Variante hat den Vorteil dass hier eine bessere Fehlerbehandlung moeglich ist - if($this->unoconv_version=='0.6') - $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' %2$s > %1$s'; - else - $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' --output %s %s 2>&1'; + //if($this->unoconv_version=='0.6') + // $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' %2$s > %1$s'; + //else + // $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $this->outputformat . ' --output %s %s 2>&1'; - $command = sprintf($command, $this->temp_filename, $tempname_zip); + //$command = sprintf($command, $this->temp_filename, $tempname_zip); - exec($command, $out, $ret); + //exec($command, $out, $ret); - if($ret!=0) - { - $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator'; - return false; - } + require_once('Docsbox.php'); + + var_dump($tempname_zip); + var_dump($this->temp_filename); + + Docsbox::convert($tempname_zip, $this->temp_filename); + + //if($ret!=0) + //{ + // $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator'; + // return false; + //} break; case 'odt': default: @@ -455,19 +449,26 @@ class dokument_export */ public function convert($inFile, $outFile, $format = "pdf") { - if($this->unoconv_version=='0.6') - $command = 'unoconv -f %1$s %3$s > %2$s'; - else - $command = 'unoconv -f %s --output %s %s 2>&1'; - $command = sprintf($command, $format, $outFile, $inFile); + //require_once('Docsbox.php'); - exec($command, $out, $ret); + //var_dump($inFile); + //var_dump($outFile); - if($ret!=0) - { - $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator'; - return false; - } + //Docsbox::convert(); + + //if($this->unoconv_version=='0.6') + // $command = 'unoconv -f %1$s %3$s > %2$s'; + //else + // $command = 'unoconv -f %s --output %s %s 2>&1'; + //$command = sprintf($command, $format, $outFile, $inFile); + + //exec($command, $out, $ret); + + //if($ret!=0) + //{ + // $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte versuchen Sie es in einer Minute erneut oder kontaktieren Sie einen Administrator'; + // return false; + //} return true; }