diff --git a/CHANGELOG b/CHANGELOG index e16c71140..abcd88e31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ a folder - get zendframework from pkgist - auto generate path if not set in settings.xml +- add document conversion service -------------------------------------------------------------------------------- Changes in version 5.1.23 diff --git a/SeedDMS_Preview/Preview/Base.php b/SeedDMS_Preview/Preview/Base.php index b58b6775b..1b67bcfae 100644 --- a/SeedDMS_Preview/Preview/Base.php +++ b/SeedDMS_Preview/Preview/Base.php @@ -38,6 +38,12 @@ class SeedDMS_Preview_Base { */ protected $converters; + /** + * @var object $conversionmgr + * @access protected + */ + protected $conversionmgr; + /** * @var integer $timeout maximum time for execution of external commands * @access protected @@ -68,6 +74,7 @@ class SeedDMS_Preview_Base { } $this->timeout = intval($timeout); $this->xsendfile = $xsendfile; + $this->conversionmgr = null; } /* }}} */ /** @@ -141,6 +148,18 @@ class SeedDMS_Preview_Base { $this->converters = $arr; } /* }}} */ + /** + * Set conversion service manager + * + * A conversion manager is a service for converting files from one format + * to another format. + * + * @param object $conversionmgr + */ + function setConversionMgr($conversionmgr) { /* {{{ */ + $this->conversionmgr = $conversionmgr; + } /* }}} */ + /** * Enable/Disable xsendfile extension * @@ -169,11 +188,16 @@ class SeedDMS_Preview_Base { /** * Check if converter for a given mimetype is set * - * @param string $mimetype + * @param string $from from mimetype + * @param string $to to mimetype + * * @return boolean true if converter exists, otherwise false */ - function hasConverter($mimetype) { /* {{{ */ - return array_key_exists($mimetype, $this->converters) && $this->converters[$mimetype]; + function hasConverter($from, $to='') { /* {{{ */ + if($this->conversionmgr) + return $this->conversionmgr->hasService($from, $to); + else + return array_key_exists($from, $this->converters) && $this->converters[$from]; } /* }}} */ /** diff --git a/SeedDMS_Preview/Preview/PdfPreviewer.php b/SeedDMS_Preview/Preview/PdfPreviewer.php index 202fe4e18..b9f3987b5 100644 --- a/SeedDMS_Preview/Preview/PdfPreviewer.php +++ b/SeedDMS_Preview/Preview/PdfPreviewer.php @@ -68,6 +68,17 @@ class SeedDMS_Preview_PdfPreviewer extends SeedDMS_Preview_Base { return $target; } /* }}} */ + /** + * Check if converter for a given mimetype is set + * + * @param string $mimetype from mimetype + * + * @return boolean true if converter exists, otherwise false + */ + function hasConverter($from, $to='') { /* {{{ */ + return parent::hasConverter($from, 'application/pdf'); + } /* }}} */ + /** * Create a pdf preview for a given file * @@ -98,21 +109,27 @@ class SeedDMS_Preview_PdfPreviewer extends SeedDMS_Preview_Base { $target = $this->previewDir.$dir.md5($infile); $this->lastpreviewfile = $target.'.pdf'; if($target != '' && (!file_exists($target.'.pdf') || filectime($target.'.pdf') < filectime($infile))) { - $cmd = ''; - $mimeparts = explode('/', $mimetype, 2); - if(isset($this->converters[$mimetype])) { - $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters[$mimetype]); - } elseif(isset($this->converters[$mimeparts[0].'/*'])) { - $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters[$mimeparts[0].'/*']); - } elseif(isset($this->converters['*'])) { - $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters['*']); - } - if($cmd) { - try { - self::execWithTimeout($cmd, $this->timeout); - } catch(Exception $e) { - $this->lastpreviewfile = ''; - return false; + if($this->conversionmgr) { + if($this->conversionmgr->hasService($mimetype, 'application/pdf')) { + return $this->conversionmgr->convert($infile, $mimetype, 'application/pdf', $target.'.pdf'); + } + } else { + $cmd = ''; + $mimeparts = explode('/', $mimetype, 2); + if(isset($this->converters[$mimetype])) { + $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters[$mimetype]); + } elseif(isset($this->converters[$mimeparts[0].'/*'])) { + $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters[$mimeparts[0].'/*']); + } elseif(isset($this->converters['*'])) { + $cmd = str_replace(array('%f', '%o', '%m'), array($infile, $target.'.pdf', $mimetype), $this->converters['*']); + } + if($cmd) { + try { + self::execWithTimeout($cmd, $this->timeout); + } catch(Exception $e) { + $this->lastpreviewfile = ''; + return false; + } } } return true; diff --git a/SeedDMS_Preview/Preview/Previewer.php b/SeedDMS_Preview/Preview/Previewer.php index 32a06cc89..388356a2d 100644 --- a/SeedDMS_Preview/Preview/Previewer.php +++ b/SeedDMS_Preview/Preview/Previewer.php @@ -72,6 +72,17 @@ class SeedDMS_Preview_Previewer extends SeedDMS_Preview_Base { return $target; } /* }}} */ + /** + * Check if converter for a given mimetype is set + * + * @param string $mimetype from mimetype + * + * @return boolean true if converter exists, otherwise false + */ + function hasConverter($from, $to='') { /* {{{ */ + return parent::hasConverter($from, 'image/png'); + } /* }}} */ + /** * Create a preview image for a given file * @@ -107,23 +118,33 @@ class SeedDMS_Preview_Previewer extends SeedDMS_Preview_Base { $target = $this->previewDir.$dir.md5($infile).'-'.$width; $this->lastpreviewfile = $target.'.png'; if($target != '' && (!file_exists($target.'.png') || filectime($target.'.png') < filectime($infile))) { - $cmd = ''; - $mimeparts = explode('/', $mimetype, 2); - if(isset($this->converters[$mimetype])) { - $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters[$mimetype]); - } elseif(isset($this->converters[$mimeparts[0].'/*'])) { - $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters[$mimeparts[0].'/*']); - } elseif(isset($this->converters['*'])) { - $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters['*']); - } + if($this->conversionmgr) { + if($this->conversionmgr->hasService($mimetype, 'image/png')) { + if(!$this->conversionmgr->convert($infile, $mimetype, 'image/png', $target.'.png', array('width'=>$width))) { + $this->lastpreviewfile = ''; + return false; + } + } + $new = true; + } else { + $cmd = ''; + $mimeparts = explode('/', $mimetype, 2); + if(isset($this->converters[$mimetype])) { + $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters[$mimetype]); + } elseif(isset($this->converters[$mimeparts[0].'/*'])) { + $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters[$mimeparts[0].'/*']); + } elseif(isset($this->converters['*'])) { + $cmd = str_replace(array('%w', '%f', '%o', '%m'), array($width, $infile, $target.'.png', $mimetype), $this->converters['*']); + } - if($cmd) { - try { - self::execWithTimeout($cmd, $this->timeout); - $new = true; - } catch(Exception $e) { - $this->lastpreviewfile = ''; - return false; + if($cmd) { + try { + self::execWithTimeout($cmd, $this->timeout); + $new = true; + } catch(Exception $e) { + $this->lastpreviewfile = ''; + return false; + } } } return true; diff --git a/controllers/class.PdfPreview.php b/controllers/class.PdfPreview.php index dfe10ef71..400e953c2 100644 --- a/controllers/class.PdfPreview.php +++ b/controllers/class.PdfPreview.php @@ -27,6 +27,7 @@ class SeedDMS_Controller_PdfPreview extends SeedDMS_Controller_Common { $dms = $this->params['dms']; $type = $this->params['type']; $settings = $this->params['settings']; + $conversionmgr = $this->params['conversionmgr']; switch($type) { case "version": @@ -51,7 +52,10 @@ class SeedDMS_Controller_PdfPreview extends SeedDMS_Controller_Common { $this->params['content'] = $content; if(null === $this->callHook('version')) { $previewer = new SeedDMS_Preview_PdfPreviewer($settings->_cacheDir, $settings->_cmdTimeout); - $previewer->setConverters(isset($settings->_converters['pdf']) ? $settings->_converters['pdf'] : array()); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters(isset($settings->_converters['pdf']) ? $settings->_converters['pdf'] : array()); $previewer->setXsendfile($settings->_enableXsendfile); if(!$previewer->hasPreview($content)) { add_log_line(""); diff --git a/controllers/class.Preview.php b/controllers/class.Preview.php index 688ed7a0a..3cea95428 100644 --- a/controllers/class.Preview.php +++ b/controllers/class.Preview.php @@ -27,6 +27,7 @@ class SeedDMS_Controller_Preview extends SeedDMS_Controller_Common { $dms = $this->params['dms']; $type = $this->params['type']; $settings = $this->params['settings']; + $conversionmgr = $this->params['conversionmgr']; switch($type) { case "version": @@ -55,7 +56,10 @@ class SeedDMS_Controller_Preview extends SeedDMS_Controller_Common { $previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir, $width, $settings->_cmdTimeout); else $previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir); - $previewer->setConverters($settings->_converters['preview']); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($settings->_converters['preview']); $previewer->setXsendfile($settings->_enableXsendfile); if(!$previewer->hasPreview($content)) { add_log_line(""); @@ -86,7 +90,10 @@ class SeedDMS_Controller_Preview extends SeedDMS_Controller_Common { $previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir, $width, $settings->_cmdTimeout); else $previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir); - $previewer->setConverters($settings->_converters['preview']); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($settings->_converters['preview']); $previewer->setXsendfile($settings->_enableXsendfile); if(!$previewer->hasPreview($object)) { diff --git a/inc/inc.ClassConversionMgr.php b/inc/inc.ClassConversionMgr.php new file mode 100644 index 000000000..8358f202e --- /dev/null +++ b/inc/inc.ClassConversionMgr.php @@ -0,0 +1,65 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +require_once("inc/inc.ClassConversionServiceExec.php"); +require_once("inc/inc.ClassConversionServiceImageToImage.php"); +require_once("inc/inc.ClassConversionServicePdfToImage.php"); +require_once("inc/inc.ClassConversionServiceTextToText.php"); + +/** + * Implementation of conversion manager + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_ConversionMgr { + /** + * List of services for searching fulltext + */ + public $services; + + public function __construct() { + $this->services = array(); + } + + public function addService($service) { + $this->services[$service->from][$service->to][] = $service; + return $service; + } + + public function hasService($from, $to) { + if(!empty($this->services[$from][$to])) + return true; + else + return false; + } + + /** + * Convert a file + * + * @param string $file name of file to convert + * @param string $from mimetype of input file + * @param string $to mimetype of output file + * + * @return boolean true on success, other false + */ + public function convert($file, $from, $to, $target=null, $params=array()) { + if(isset($this->services[$from][$to])) { + $service = array_pop($this->services[$from][$to]); + return $service->convert($file, $target, $params); + } + } +} diff --git a/inc/inc.ClassConversionServiceBase.php b/inc/inc.ClassConversionServiceBase.php new file mode 100644 index 000000000..a0859d674 --- /dev/null +++ b/inc/inc.ClassConversionServiceBase.php @@ -0,0 +1,54 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Implementation of conversion service base class + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +abstract class SeedDMS_ConversionServiceBase { + /** + * mimetype original file + */ + public $from; + + /** + * mimetype converted file + */ + public $to; + + /** + * logger + */ + protected $logger; + + public function __construct() { + $this->from = null; + $this->to = null; + } + + public function setLogger($logger) { + $this->logger = $logger; + } + + public function getInfo() { + return 'Conversion service'; + } + + public function convert($infile, $target = null, $params = array()) { + } +} diff --git a/inc/inc.ClassConversionServiceExec.php b/inc/inc.ClassConversionServiceExec.php new file mode 100644 index 000000000..1603932f9 --- /dev/null +++ b/inc/inc.ClassConversionServiceExec.php @@ -0,0 +1,126 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +require_once("inc/inc.ClassConversionServiceBase.php"); + +/** + * Implementation of conversion service exec class + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_ConversionServiceExec extends SeedDMS_ConversionServiceBase { + /** + * shell cmd + */ + public $cmd; + + /** + * timeout + */ + public $timeout; + + /** + * Run a shell command + * + * @param $cmd + * @param int $timeout + * @return array + * @throws Exception + */ + static function execWithTimeout($cmd, $timeout=5) { /* {{{ */ + $descriptorspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("pipe", "w") + ); + $pipes = array(); + + $timeout += time(); + // Putting an 'exec' before the command will not fork the command + // and therefore not create any child process. proc_terminate will + // then reliably terminate the cmd and not just shell. See notes of + // https://www.php.net/manual/de/function.proc-terminate.php + $process = proc_open('exec '.$cmd, $descriptorspec, $pipes); + if (!is_resource($process)) { + throw new Exception("proc_open failed on: " . $cmd); + } + stream_set_blocking($pipes[1], 0); + stream_set_blocking($pipes[2], 0); + + $output = $error = ''; + $timeleft = $timeout - time(); + $read = array($pipes[1], $pipes[2]); + $write = NULL; + $exeptions = NULL; + do { + $num_changed_streams = stream_select($read, $write, $exeptions, $timeleft, 200000); + + if ($num_changed_streams === false) { + proc_terminate($process); + throw new Exception("stream select failed on: " . $cmd); + } elseif ($num_changed_streams > 0) { + $output .= fread($pipes[1], 8192); + $error .= fread($pipes[2], 8192); + } + $timeleft = $timeout - time(); + } while (!feof($pipes[1]) && $timeleft > 0); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + if ($timeleft <= 0) { + proc_terminate($process); + throw new Exception("command timeout on: " . $cmd); + } else { + $return_value = proc_close($process); + return array('stdout'=>$output, 'stderr'=>$error, 'return'=>$return_value); + } + } /* }}} */ + + public function __construct($from, $to, $cmd) { + $this->from = $from; + $this->to = $to; + $this->cmd = $cmd; + $this->timeout = 5; + } + + public function convert($infile, $target = null, $params = array()) { + $start = microtime(true); + if(!$target) + $tmpfile = tempnam(sys_get_temp_dir(), 'convert'); + else + $tmpfile = $target; + $cmd = str_replace(array('%w', '%f', '%o', '%m'), array(isset($params['width']) ? $params['width'] : '', $infile, $tmpfile, $this->from), $this->cmd); + try { + self::execWithTimeout($cmd, $this->timeout); + } catch(Exception $e) { + return false; + } + $end = microtime(true); + if($this->logger) { + $this->logger->log('Conversion from '.$this->from.' to '.$this->to.' with cmd "'.$this->cmd.'" took '.($end-$start).' sec.', PEAR_LOG_INFO); + } + if(!$target) { + $content = file_get_contents($tmpfile); + unlink($tmpfile); + return $content; + } else { + return true; + } + } +} + diff --git a/inc/inc.ClassConversionServiceImageToImage.php b/inc/inc.ClassConversionServiceImageToImage.php new file mode 100644 index 000000000..1b9961918 --- /dev/null +++ b/inc/inc.ClassConversionServiceImageToImage.php @@ -0,0 +1,57 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +require_once("inc/inc.ClassConversionServiceBase.php"); + +/** + * Implementation of conversion service image class + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_ConversionServiceImageToImage extends SeedDMS_ConversionServiceBase { + /** + * timeout + */ + public $timeout; + + public function __construct($from, $to) { + $this->from = $from; + $this->to = $to; + $this->timeout = 5; + } + + public function convert($infile, $target = null, $params = array()) { + $start = microtime(true); + $imagick = new Imagick(); + if($imagick->readImage($infile)) { + if(!empty($params['width'])) + $imagick->scaleImage((int) $params['width'], 0); + $end = microtime(true); + if($this->logger) { + $this->logger->log('Conversion from '.$this->from.' to '.$this->to.' with image service took '.($end-$start).' sec.', PEAR_LOG_INFO); + } + if($target) { + return $imagick->writeImage($target); + } else { + return $imagick->getImageBlob(); + } + } + return false; + } +} + + diff --git a/inc/inc.ClassConversionServicePdfToImage.php b/inc/inc.ClassConversionServicePdfToImage.php new file mode 100644 index 000000000..69623aa5b --- /dev/null +++ b/inc/inc.ClassConversionServicePdfToImage.php @@ -0,0 +1,63 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +require_once("inc/inc.ClassConversionServiceBase.php"); + +/** + * Implementation of conversion service pdf class + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_ConversionServicePdfToImage extends SeedDMS_ConversionServiceBase { + /** + * timeout + */ + public $timeout; + + public function __construct($from, $to) { + $this->from = $from; + $this->to = $to; + $this->timeout = 5; + } + + public function convert($infile, $target = null, $params = array()) { + $start = microtime(true); + $imagick = new Imagick(); + /* Setting a smaller resolution will speed up the conversion + * A resolution of 72,72 will create a 596x842 image + */ + $imagick->setResolution(36,36); + if($imagick->readImage($infile.'[0]')) { + if(!empty($params['width'])) + $imagick->scaleImage((int) $params['width'], 0); + $imagick->setImageFormat('png'); + $end = microtime(true); + if($this->logger) { + $this->logger->log('Conversion from '.$this->from.' to '.$this->to.' with pdf service took '.($end-$start).' sec.', PEAR_LOG_INFO); + } + if($target) { + return $imagick->writeImage($target); + } else { + return $imagick->getImageBlob(); + } + } + return false; + } +} + + + diff --git a/inc/inc.ClassConversionServiceTextToText.php b/inc/inc.ClassConversionServiceTextToText.php new file mode 100644 index 000000000..be29030d2 --- /dev/null +++ b/inc/inc.ClassConversionServiceTextToText.php @@ -0,0 +1,39 @@ + + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ + +require_once("inc/inc.ClassConversionServiceBase.php"); + +/** + * Implementation of conversion service class for text to text + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2021 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_ConversionServiceTextToText extends SeedDMS_ConversionServiceBase { + public function __construct($from, $to) { + $this->from = $from; + $this->to = $to; + } + + public function convert($infile, $target = null, $params = array()) { + if($target) { + file_put_contents($target, file_get_contents($infile)); + return true; + } else + return file_get_contents($infile); + } +} + diff --git a/inc/inc.ConversionInit.php b/inc/inc.ConversionInit.php new file mode 100644 index 000000000..54089de4a --- /dev/null +++ b/inc/inc.ConversionInit.php @@ -0,0 +1,36 @@ +_converters['preview'])) { + foreach($settings->_converters['preview'] as $mimetype=>$cmd) { + $conversionmgr->addService(new SeedDMS_ConversionServiceExec($mimetype, 'image/png', $cmd))->setLogger($logger); + } +} + +if(!empty($settings->_converters['pdf'])) { + foreach($settings->_converters['pdf'] as $mimetype=>$cmd) { + $conversionmgr->addService(new SeedDMS_ConversionServiceExec($mimetype, 'application/pdf', $cmd))->setLogger($logger); + } +} + +$conversionmgr->addService(new SeedDMS_ConversionServicePdfToImage('application/pdf', 'image/png'))->setLogger($logger); + +$conversionmgr->addService(new SeedDMS_ConversionServiceImageToImage('image/jpeg', 'image/png'))->setLogger($logger); +$conversionmgr->addService(new SeedDMS_ConversionServiceImageToImage('image/png', 'image/png'))->setLogger($logger); +$conversionmgr->addService(new SeedDMS_ConversionServiceImageToImage('image/jpg', 'image/png'))->setLogger($logger); + +$conversionmgr->addService(new SeedDMS_ConversionServiceTextToText('text/plain', 'text/plain'))->setLogger($logger); + +if(isset($GLOBALS['SEEDDMS_HOOKS']['initConversion'])) { + foreach($GLOBALS['SEEDDMS_HOOKS']['initConversion'] as $hookObj) { + if (method_exists($hookObj, 'getConversionServices')) { + if($services = $hookObj->getConversionServices(array('dms'=>$dms, 'settings'=>$settings, 'logger'=>$logger))) { + foreach($services as $service) { + $conversionmgr->addService($service)->setLogger($logger); + } + } + } + } +} diff --git a/op/op.PdfPreview.php b/op/op.PdfPreview.php index 9f0ad2849..e3743fb05 100644 --- a/op/op.PdfPreview.php +++ b/op/op.PdfPreview.php @@ -59,6 +59,7 @@ if(isset($_GET['version'])) { $controller->setParam('document', $document); $controller->setParam('version', $version); $controller->setParam('type', 'version'); + $controller->setParam('conversionmgr', $conversionmgr); if(!$controller->run()) { UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); } diff --git a/op/op.Preview.php b/op/op.Preview.php index da3c11a9a..9e560e4aa 100644 --- a/op/op.Preview.php +++ b/op/op.Preview.php @@ -54,6 +54,7 @@ if ($document->getAccessMode($user) < M_READ) { exit; } +$controller->setParam('conversionmgr', $conversionmgr); if(isset($_GET['version'])) { $version = $_GET["version"]; if (!is_numeric($version)) diff --git a/out/out.DocumentVersionDetail.php b/out/out.DocumentVersionDetail.php index b0809c996..58923d132 100644 --- a/out/out.DocumentVersionDetail.php +++ b/out/out.DocumentVersionDetail.php @@ -71,6 +71,7 @@ $accessop = new SeedDMS_AccessOperation($dms, $document, $user, $settings); $tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); $view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user)); if($view) { + $view->setParam('conversionmgr', $conversionmgr); $view->setParam('folder', $folder); $view->setParam('document', $document); $view->setParam('version', $version); diff --git a/out/out.ViewDocument.php b/out/out.ViewDocument.php index 0923b4d5b..e1013cb84 100644 --- a/out/out.ViewDocument.php +++ b/out/out.ViewDocument.php @@ -66,6 +66,7 @@ if ($document->verifyLastestContentExpriry()){ if($view) { $view->setParam('fulltextservice', $fulltextservice); + $view->setParam('conversionmgr', $conversionmgr); $view->setParam('folder', $folder); $view->setParam('document', $document); $view->setParam('accessobject', $accessop); diff --git a/out/out.ViewFolder.php b/out/out.ViewFolder.php index 65f68eff0..2aca32070 100644 --- a/out/out.ViewFolder.php +++ b/out/out.ViewFolder.php @@ -77,6 +77,7 @@ if($view) { if(isset($_GET['action']) && $_GET['action'] == 'subtree') $view->setParam('node', $node); $view->setParam('fulltextservice', $fulltextservice); + $view->setParam('conversionmgr', $conversionmgr); $view->setParam('folder', $folder); $view->setParam('orderby', $orderby); $view->setParam('enableFolderTree', $settings->_enableFolderTree); diff --git a/views/bootstrap/class.DocumentVersionDetail.php b/views/bootstrap/class.DocumentVersionDetail.php index 9c75985be..29767ac20 100644 --- a/views/bootstrap/class.DocumentVersionDetail.php +++ b/views/bootstrap/class.DocumentVersionDetail.php @@ -60,6 +60,7 @@ class SeedDMS_View_DocumentVersionDetail extends SeedDMS_Theme_Style { $converttopdf = $this->params['convertToPdf']; $pdfconverters = $this->params['pdfConverters']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $version = $this->params['version']; if(!$showfullpreview) return; @@ -125,7 +126,10 @@ class SeedDMS_View_DocumentVersionDetail extends SeedDMS_Theme_Style { if($converttopdf) { $pdfpreviewer = new SeedDMS_Preview_PdfPreviewer($cachedir, $timeout, $xsendfile); - $pdfpreviewer->setConverters($pdfconverters); + if($conversionmgr) + $pdfpreviewer->setConversionMgr($conversionmgr); + else + $pdfpreviewer->setConverters($pdfconverters); if($pdfpreviewer->hasConverter($version->getMimeType())) { $this->contentHeading(getMLText("preview_pdf")); ?> @@ -145,7 +149,9 @@ class SeedDMS_View_DocumentVersionDetail extends SeedDMS_Theme_Style { $viewonlinefiletypes = $this->params['viewonlinefiletypes']; $enableversionmodification = $this->params['enableversionmodification']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $previewwidthdetail = $this->params['previewWidthDetail']; + $previewconverters = $this->params['previewConverters']; $timeout = $this->params['timeout']; $xsendfile = $this->params['xsendfile']; @@ -261,6 +267,10 @@ class SeedDMS_View_DocumentVersionDetail extends SeedDMS_Theme_Style { print ""; $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $previewer->createPreview($version); if ($file_exists) { if ($viewonlinefiletypes && (in_array(strtolower($version->getFileType()), $viewonlinefiletypes) || in_array(strtolower($version->getMimeType()), $viewonlinefiletypes))) { diff --git a/views/bootstrap/class.ViewDocument.php b/views/bootstrap/class.ViewDocument.php index 05540984a..6bb964aef 100644 --- a/views/bootstrap/class.ViewDocument.php +++ b/views/bootstrap/class.ViewDocument.php @@ -120,10 +120,19 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Theme_Style { $user = $this->params['user']; $previewwidth = $this->params['previewWidthList']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; + $previewconverters = $this->params['previewConverters']; + $timeout = $this->params['timeout']; + $xsendfile = $this->params['xsendfile']; $document = $this->params['document']; + if($document) { if ($document->getAccessMode($user) >= M_READ) { - $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth); + $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $txt = $this->callHook('documentListItem', $document, $previewer, false, 'viewitem'); if(is_string($txt)) $content = $txt; @@ -226,6 +235,7 @@ $(document).ready( function() { $accessobject = $this->params['accessobject']; $viewonlinefiletypes = $this->params['viewonlinefiletypes']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $previewwidthdetail = $this->params['previewWidthDetail']; $previewconverters = $this->params['previewConverters']; $timeout = $this->params['timeout']; @@ -233,7 +243,10 @@ $(document).ready( function() { $documentid = $document->getId(); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile); - $previewer->setConverters($previewconverters); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $latestContent = $this->callHook('documentLatestContent', $document); if($latestContent === null) $latestContent = $document->getLatestContent(); @@ -498,6 +511,7 @@ $(document).ready( function() { $converttopdf = $this->params['convertToPdf']; $pdfconverters = $this->params['pdfConverters']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; if(!$showfullpreview) return; @@ -567,7 +581,10 @@ $(document).ready( function() { if($converttopdf) { $pdfpreviewer = new SeedDMS_Preview_PdfPreviewer($cachedir, $timeout, $xsendfile); - $pdfpreviewer->setConverters($pdfconverters); + if($conversionmgr) + $pdfpreviewer->setConversionMgr($conversionmgr); + else + $pdfpreviewer->setConverters($pdfconverters); if($pdfpreviewer->hasConverter($latestContent->getMimeType())) { $this->contentHeading(getMLText("preview_pdf")); ?> @@ -774,6 +791,7 @@ $(document).ready( function() { $enableremoverevapp = $this->params['enableremoverevapp']; $workflowmode = $this->params['workflowmode']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $previewwidthlist = $this->params['previewWidthList']; $previewwidthdetail = $this->params['previewWidthDetail']; $previewconverters = $this->params['previewConverters']; @@ -917,7 +935,10 @@ $(document).ready( function() { $this->contentContainerStart(); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile); - $previewer->setConverters($previewconverters); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $this->showVersionDetails($latestContent, $previewer, true); $this->contentContainerEnd(); diff --git a/views/bootstrap/class.ViewFolder.php b/views/bootstrap/class.ViewFolder.php index 6f8ed0722..ffd14c398 100644 --- a/views/bootstrap/class.ViewFolder.php +++ b/views/bootstrap/class.ViewFolder.php @@ -353,6 +353,7 @@ $('body').on('click', '.order-btn', function(ev) { $orderby = $this->params['orderby']; $orderdir = (isset($orderby[1]) ? ($orderby[1] == 'd' ? 'desc' : 'asc') : 'asc'); $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $maxItemsPerPage = $this->params['maxItemsPerPage']; $incItemsPerPage = $this->params['incItemsPerPage']; $previewwidth = $this->params['previewWidthList']; @@ -362,7 +363,10 @@ $('body').on('click', '.order-btn', function(ev) { $onepage = $this->params['onepage']; $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); - $previewer->setConverters($previewconverters); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $txt = $this->callHook('listHeader', $folder); if(is_string($txt)) @@ -491,6 +495,7 @@ $('body').on('click', '.order-btn', function(ev) { $orderby = $this->params['orderby']; $orderdir = (isset($orderby[1]) ? ($orderby[1] == 'd' ? 'desc' : 'asc') : 'asc'); $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $previewwidth = $this->params['previewWidthList']; $previewconverters = $this->params['previewConverters']; $timeout = $this->params['timeout']; @@ -501,7 +506,10 @@ $('body').on('click', '.order-btn', function(ev) { header('Content-Type: application/json'); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); - $previewer->setConverters($previewconverters); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $subFolders = $this->callHook('folderGetSubFolders', $folder, $orderby[0]); if($subFolders === null) @@ -568,6 +576,7 @@ $('body').on('click', '.order-btn', function(ev) { $expandFolderTree = $this->params['expandFolderTree']; $showtree = $this->params['showtree']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $enableRecursiveCount = $this->params['enableRecursiveCount']; $maxRecursiveCount = $this->params['maxRecursiveCount']; $maxItemsPerPage = $this->params['maxItemsPerPage']; @@ -579,7 +588,10 @@ $('body').on('click', '.order-btn', function(ev) { $folderid = $folder->getId(); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); - $previewer->setConverters($previewconverters); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); // echo $this->callHook('startPage'); $this->htmlStartPage(getMLText("folder_title", array("foldername" => htmlspecialchars($folder->getName()))));