new method getPreviewFile(), start version 1.13.0

This commit is contained in:
Uwe Steinmann 2020-01-21 08:11:03 +01:00
parent 74300082fc
commit e830477bf0
4 changed files with 48 additions and 13 deletions

View File

@ -50,6 +50,12 @@ class SeedDMS_Preview_Base {
*/
protected $xsendfile;
/**
* @var string $lastpreviewfile will be set to the file name of the last preview
* @access protected
*/
protected $lastpreviewfile;
function __construct($previewDir, $timeout=5, $xsendfile=true) { /* {{{ */
if(!is_dir($previewDir)) {
if (!SeedDMS_Core_File::makeDir($previewDir)) {
@ -154,14 +160,14 @@ class SeedDMS_Preview_Base {
return array_key_exists($mimetype, $this->converters) && $this->converters[$mimetype];
} /* }}} */
/**
* Send a file from disk to the browser
*
* This function uses either readfile() or the xѕendfile apache module if
* it is installed.
*
* @param string $filename
*/
/**
* Send a file from disk to the browser
*
* This function uses either readfile() or the xѕendfile apache module if
* it is installed.
*
* @param string $filename
*/
protected function sendFile($filename) { /* {{{ */
if($this->xsendfile && function_exists('apache_get_modules') && in_array('mod_xsendfile',apache_get_modules())) {
header("X-Sendfile: ".$filename);
@ -173,5 +179,14 @@ class SeedDMS_Preview_Base {
readfile($filename);
}
} /* }}} */
/**
* Return path of last created preview file
*
* @return string
*/
public function getPreviewFile() { /* {{{ */
return $this->lastpreviewfile;
} /* }}} */
}

View File

@ -96,6 +96,7 @@ class SeedDMS_Preview_PdfPreviewer extends SeedDMS_Preview_Base {
return false;
if(!$target)
$target = $this->previewDir.$dir.md5($infile);
$this->lastpreviewfile = $target.'.png';
if($target != '' && (!file_exists($target.'.pdf') || filectime($target.'.pdf') < filectime($infile))) {
$cmd = '';
$mimeparts = explode('/', $mimetype, 2);
@ -110,6 +111,7 @@ class SeedDMS_Preview_PdfPreviewer extends SeedDMS_Preview_Base {
try {
self::execWithTimeout($cmd, $this->timeout);
} catch(Exception $e) {
$this->lastpreviewfile = '';
return false;
}
}

View File

@ -105,6 +105,7 @@ class SeedDMS_Preview_Previewer extends SeedDMS_Preview_Base {
return false;
if(!$target)
$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);
@ -120,6 +121,7 @@ class SeedDMS_Preview_Previewer extends SeedDMS_Preview_Base {
try {
self::execWithTimeout($cmd, $this->timeout);
} catch(Exception $e) {
$this->lastpreviewfile = '';
return false;
}
}

View File

@ -11,11 +11,11 @@
<email>uwe@steinmann.cx</email>
<active>yes</active>
</lead>
<date>2019-02-11</date>
<date>2020-01-21</date>
<time>10:59:39</time>
<version>
<release>1.2.10</release>
<api>1.2.10</api>
<release>1.3.0</release>
<api>1.3.0</api>
</version>
<stability>
<release>stable</release>
@ -23,8 +23,7 @@
</stability>
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
<notes>
new parameter for enabling/disabling xsendfile
fix creation of pdf preview if document content class is not SeedDMS_Core_DocumentContent
add new methode getPreviewFile()
</notes>
<contents>
<dir baseinstalldir="SeedDMS" name="/">
@ -404,5 +403,22 @@ make sure list of converters is always an array
usage of mod_sendfile can be configured
</notes>
</release>
<release>
<date>2019-02-11</date>
<time>10:59:39</time>
<version>
<release>1.2.10</release>
<api>1.2.10</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
<notes>
new parameter for enabling/disabling xsendfile
fix creation of pdf preview if document content class is not SeedDMS_Core_DocumentContent
</notes>
</release>
</changelog>
</package>