mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-06-02 06:57:40 +00:00
create preview from document files as well
a preview image can now be created from a document content or a document file.
This commit is contained in:
parent
ecc800fc24
commit
9f7b665c48
|
@ -50,27 +50,50 @@ class SeedDMS_Preview_Previewer {
|
||||||
$this->width = intval($width);
|
$this->width = intval($width);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPreview($documentcontent, $width=0) { /* {{{ */
|
/**
|
||||||
|
* Retrieve the physical filename of the preview image on disk
|
||||||
|
*
|
||||||
|
* @param object $object document content or document file
|
||||||
|
* @param integer $width width of preview image
|
||||||
|
* @return string file name of preview image
|
||||||
|
*/
|
||||||
|
protected function getFileName($object, $width) { /* }}} */
|
||||||
|
$document = $object->getDocument();
|
||||||
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
|
switch(get_class($object)) {
|
||||||
|
case "SeedDMS_Core_DocumentContent":
|
||||||
|
$target = $dir.'p'.$object->getVersion().'-'.$width.'.png';
|
||||||
|
break;
|
||||||
|
case "SeedDMS_Core_DocumentFile":
|
||||||
|
$target = $dir.'f'.$object->getID().'-'.$width.'.png';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $target;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
public function createPreview($object, $width=0) { /* {{{ */
|
||||||
if($width == 0)
|
if($width == 0)
|
||||||
$width = $this->width;
|
$width = $this->width;
|
||||||
else
|
else
|
||||||
$width = intval($width);
|
$width = intval($width);
|
||||||
if(!$this->previewDir)
|
if(!$this->previewDir)
|
||||||
return false;
|
return false;
|
||||||
$document = $documentcontent->getDocument();
|
$document = $object->getDocument();
|
||||||
$dir = $this->previewDir.'/'.$document->getDir();
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
if(!is_dir($dir)) {
|
if(!is_dir($dir)) {
|
||||||
if (!SeedDMS_Core_File::makeDir($dir)) {
|
if (!SeedDMS_Core_File::makeDir($dir)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file = $document->_dms->contentDir.$documentcontent->getPath();
|
$file = $document->_dms->contentDir.$object->getPath();
|
||||||
if(!file_exists($file))
|
if(!file_exists($file))
|
||||||
return false;
|
return false;
|
||||||
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
$target = $this->getFileName($object, $width);
|
||||||
if(!file_exists($target)) {
|
if($target !== false && !file_exists($target)) {
|
||||||
$cmd = '';
|
$cmd = '';
|
||||||
switch($documentcontent->getMimeType()) {
|
switch($object->getMimeType()) {
|
||||||
case "image/png":
|
case "image/png":
|
||||||
case "image/gif":
|
case "image/gif":
|
||||||
case "image/jpeg":
|
case "image/jpeg":
|
||||||
|
@ -89,46 +112,43 @@ class SeedDMS_Preview_Previewer {
|
||||||
|
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function hasPreview($documentcontent, $width=0) { /* {{{ */
|
public function hasPreview($object, $width=0) { /* {{{ */
|
||||||
if($width == 0)
|
if($width == 0)
|
||||||
$width = $this->width;
|
$width = $this->width;
|
||||||
else
|
else
|
||||||
$width = intval($width);
|
$width = intval($width);
|
||||||
if(!$this->previewDir)
|
if(!$this->previewDir)
|
||||||
return false;
|
return false;
|
||||||
$document = $documentcontent->getDocument();
|
$target = $this->getFileName($object, $width);
|
||||||
$dir = $this->previewDir.'/'.$document->getDir();
|
if($target && file_exists($target)) {
|
||||||
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
|
||||||
if(file_exists($target)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function getPreview($documentcontent, $width=0) { /* {{{ */
|
public function getPreview($object, $width=0) { /* {{{ */
|
||||||
if($width == 0)
|
if($width == 0)
|
||||||
$width = $this->width;
|
$width = $this->width;
|
||||||
else
|
else
|
||||||
$width = intval($width);
|
$width = intval($width);
|
||||||
if(!$this->previewDir)
|
if(!$this->previewDir)
|
||||||
return false;
|
return false;
|
||||||
$document = $documentcontent->getDocument();
|
|
||||||
$dir = $this->previewDir.'/'.$document->getDir();
|
$target = $this->getFileName($object, $width);
|
||||||
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
if($target && file_exists($target)) {
|
||||||
if(file_exists($target)) {
|
|
||||||
readfile($target);
|
readfile($target);
|
||||||
}
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function deletePreview($document, $documentcontent) { /* {{{ */
|
public function deletePreview($document, $object, $width=0) { /* {{{ */
|
||||||
if($width == 0)
|
if($width == 0)
|
||||||
$width = $this->width;
|
$width = $this->width;
|
||||||
else
|
else
|
||||||
$width = intval($width);
|
$width = intval($width);
|
||||||
if(!$this->previewDir)
|
if(!$this->previewDir)
|
||||||
return false;
|
return false;
|
||||||
$dir = $this->previewDir.'/'.$document->getDir();
|
|
||||||
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
$target = $this->getFileName($object, $width);
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user