First commit

This commit is contained in:
Paolo
2021-10-04 14:05:10 +02:00
parent 825a440ef3
commit ab59c265d4
2 changed files with 148 additions and 35 deletions
+112
View File
@@ -0,0 +1,112 @@
<?php
/* Copyright (C) 2021 fhcomplete.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*/
require_once(dirname(__FILE__).'/../vendor/nategood/httpful/bootstrap.php');
class Docsbox
{
/**
*
*/
public static function convert($inputFileName, $outputFileName)
{
try
{
$response = \Httpful\Request::post('http://docconverter.technikum-wien.at/api/v1/')
->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
}
}
}
+36 -35
View File
@@ -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;
}