mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
- libraries/DocsboxLib:
- Added new constant DEFAULT_FORMAT - ERROR and SUCCESS constant values are the same of EXIT_ERROR and EXIT_SUCCESS - public method convert parameter format does not have a default value anymore - Added use import of ZipArchive - libraries/DocumentLib: removed unused variables
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/* Copyright (C) 2021 fhcomplete.net
|
||||
/* Copyright (C) 2022 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
|
||||
* 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
|
||||
@@ -20,19 +20,23 @@
|
||||
require_once(dirname(__FILE__).'/../config/docsbox.php');
|
||||
require_once(dirname(__FILE__).'/../../vendor/nategood/httpful/bootstrap.php');
|
||||
|
||||
use \ZipArchive as ZipArchive;
|
||||
|
||||
/**
|
||||
* Simple client to convert documents using Docsbox
|
||||
*/
|
||||
class DocsboxLib
|
||||
{
|
||||
const ERROR = 1;
|
||||
const SUCCESS = 0;
|
||||
const ERROR = EXIT_ERROR;
|
||||
const SUCCESS = EXIT_SUCCESS;
|
||||
const STATUS_FINISHED = 'finished'; // Docsbox status when a document conversion ended
|
||||
const STATUS_QUEUED = 'queued'; // Docsbox status when a file has been queued for the conversion
|
||||
const STATUS_STARTED = 'started'; // Docsbox status when a file has started being worked
|
||||
const STATUS_WORKING = 'working'; // Docsbox status when a file is being converted
|
||||
const OUTPUT_FILENAME = 'out.zip.pdf'; // File name used by docsbox to save a converted document
|
||||
|
||||
const DEFAULT_FORMAT = 'pdf'; // Default supported format
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// Public static methods
|
||||
|
||||
@@ -41,10 +45,13 @@ class DocsboxLib
|
||||
* It return 0 on success and any other integer on error
|
||||
* NOTE: currently format is not supported
|
||||
*/
|
||||
public static function convert($inputFileName, $outputFileName, $format = 'pdf')
|
||||
public static function convert($inputFileName, $outputFileName, $format)
|
||||
{
|
||||
// If a format has not been given
|
||||
if (isEmptyString($format)) $format = self::DEFAULT_FORMAT;
|
||||
|
||||
// Posts the file to docsbox
|
||||
$queueId = self::_postFile($inputFileName);
|
||||
$queueId = self::_postFile($inputFileName);
|
||||
// If an error occurred
|
||||
if ($queueId == null) return self::ERROR;
|
||||
|
||||
@@ -229,7 +236,7 @@ class DocsboxLib
|
||||
&& $getFileResponse->body != '')
|
||||
{
|
||||
// Output directory where to unzip the downloaded zip file
|
||||
$outputDirectory = dirname($outputFileName);
|
||||
$outputDirectory = dirname($outputFileName);
|
||||
// The path and name of the downloaded zip file
|
||||
$temporaryDownloadedZip = sys_get_temp_dir().'/'.basename($resultUrl);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class DocumentLib
|
||||
// Gets CI instance
|
||||
$this->ci =& get_instance();
|
||||
|
||||
// Which document converter has to be used
|
||||
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
|
||||
{
|
||||
// Use docsbox!!
|
||||
@@ -119,7 +120,7 @@ class DocumentLib
|
||||
|
||||
finfo_close($finfo);
|
||||
|
||||
exec($cmd, $out, $ret);
|
||||
exec($cmd, null, $ret);
|
||||
if ($ret != 0)
|
||||
{
|
||||
return error('PDF-zusammenfuegung ist derzeit nicht möglich. Bitte informieren Sie den Administrator');
|
||||
@@ -154,7 +155,7 @@ class DocumentLib
|
||||
$command = 'unoconv -f %s --output %s %s 2>&1';
|
||||
$command = sprintf($command, $format, $outFile, $inFile);
|
||||
|
||||
exec($command, $out, $ret);
|
||||
exec($command, null, $ret);
|
||||
}
|
||||
|
||||
if ($ret != 0)
|
||||
@@ -217,7 +218,7 @@ class DocumentLib
|
||||
$cmd .= '/countspaces { [ exch { dup 32 ne { pop } if } forall ] length } bind def >> ';
|
||||
$cmd .= 'setpagedevice viewJPEG"';
|
||||
|
||||
exec($cmd, $out, $ret);
|
||||
exec($cmd, null, $ret);
|
||||
if ($ret != 0)
|
||||
{
|
||||
$this->errormsg = 'jpegToPdf ist derzeit nicht möglich. Bitte informieren Sie den Administrator';
|
||||
|
||||
Reference in New Issue
Block a user