mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-12 20:51:30 +00:00
added package for creating preview images of documents
This commit is contained in:
parent
43eabc489e
commit
3a57e074fc
24
LetoDMS_Preview/Preview.php
Normal file
24
LetoDMS_Preview/Preview.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
// LetoDMS. Document Management System
|
||||||
|
// Copyright (C) 2011-2013 Uwe Steinmann
|
||||||
|
//
|
||||||
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @uses Preview/Previewer.php
|
||||||
|
*/
|
||||||
|
require_once('Preview/Previewer.php');
|
||||||
|
|
||||||
|
?>
|
134
LetoDMS_Preview/Preview/Previewer.php
Normal file
134
LetoDMS_Preview/Preview/Previewer.php
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of preview documents
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package LetoDMS_Preview
|
||||||
|
* @license GPL 2
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010, Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for managing creation of preview images for documents.
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package LetoDMS_Preview
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2011, Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class LetoDMS_Preview_Previewer {
|
||||||
|
/**
|
||||||
|
* @var string $cacheDir location in the file system where all the
|
||||||
|
* cached data like thumbnails are located. This should be an
|
||||||
|
* absolute path.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $previewDir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var integer $width maximum width/height of resized image
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
protected $width;
|
||||||
|
|
||||||
|
function __construct($previewDir, $width=40) {
|
||||||
|
if(!is_dir($previewDir)) {
|
||||||
|
if (!LetoDMS_Core_File::makeDir($previewDir)) {
|
||||||
|
$this->previewDir = '';
|
||||||
|
} else {
|
||||||
|
$this->previewDir = $previewDir;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->previewDir = $previewDir;
|
||||||
|
}
|
||||||
|
$this->width = intval($width);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPreview($documentcontent, $width=0) { /* {{{ */
|
||||||
|
if($width == 0)
|
||||||
|
$width = $this->width;
|
||||||
|
else
|
||||||
|
$width = intval($width);
|
||||||
|
if(!$this->previewDir)
|
||||||
|
return false;
|
||||||
|
$document = $documentcontent->getDocument();
|
||||||
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
|
if(!is_dir($dir)) {
|
||||||
|
if (!LetoDMS_Core_File::makeDir($dir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$file = $document->_dms->contentDir.$documentcontent->getPath();
|
||||||
|
if(!file_exists($file))
|
||||||
|
return false;
|
||||||
|
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
||||||
|
if(!file_exists($target)) {
|
||||||
|
$cmd = '';
|
||||||
|
switch($documentcontent->getMimeType()) {
|
||||||
|
case "image/png":
|
||||||
|
case "image/gif":
|
||||||
|
case "image/jpeg":
|
||||||
|
case "image/jpg":
|
||||||
|
$cmd = 'convert -resize '.$width.'x'.$width.' '.$file.' '.$target;
|
||||||
|
break;
|
||||||
|
case "application/pdf":
|
||||||
|
$cmd = 'convert -density 18 -resize '.$width.'x'.$width.' '.$file.'[0] '.$target;
|
||||||
|
}
|
||||||
|
if($cmd) {
|
||||||
|
system( $cmd);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
function hasPreview($documentcontent, $width=0) { /* {{{ */
|
||||||
|
if($width == 0)
|
||||||
|
$width = $this->width;
|
||||||
|
else
|
||||||
|
$width = intval($width);
|
||||||
|
if(!$this->previewDir)
|
||||||
|
return false;
|
||||||
|
$document = $documentcontent->getDocument();
|
||||||
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
|
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
||||||
|
if(file_exists($target)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
function getPreview($documentcontent, $width=0) { /* {{{ */
|
||||||
|
if($width == 0)
|
||||||
|
$width = $this->width;
|
||||||
|
else
|
||||||
|
$width = intval($width);
|
||||||
|
if(!$this->previewDir)
|
||||||
|
return false;
|
||||||
|
$document = $documentcontent->getDocument();
|
||||||
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
|
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
||||||
|
if(file_exists($target)) {
|
||||||
|
readfile($target);
|
||||||
|
}
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
function deletePreview($document, $documentcontent) { /* {{{ */
|
||||||
|
if($width == 0)
|
||||||
|
$width = $this->width;
|
||||||
|
else
|
||||||
|
$width = intval($width);
|
||||||
|
if(!$this->previewDir)
|
||||||
|
return false;
|
||||||
|
$dir = $this->previewDir.'/'.$document->getDir();
|
||||||
|
$target = $dir.'p'.$documentcontent->getVersion().'-'.$width.'.png';
|
||||||
|
} /* }}} */
|
||||||
|
}
|
||||||
|
?>
|
57
LetoDMS_Preview/package.xml
Normal file
57
LetoDMS_Preview/package.xml
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<package packagerversion="1.8.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
|
||||||
|
<name>LetoDMS_Preview</name>
|
||||||
|
<channel>pear.php.net</channel>
|
||||||
|
<summary>Create thumbnails from document content for LetoDMS</summary>
|
||||||
|
<description>LetoDMS is a web based document management system (DMS). These
|
||||||
|
are the classes to create preview images from the document content.</description>
|
||||||
|
<lead>
|
||||||
|
<name>Uwe Steinmann</name>
|
||||||
|
<user>steinm</user>
|
||||||
|
<email>uwe@steinmann.cx</email>
|
||||||
|
<active>yes</active>
|
||||||
|
</lead>
|
||||||
|
<date>2012-11-20</date>
|
||||||
|
<time>08:05:38</time>
|
||||||
|
<version>
|
||||||
|
<release>1.0.0</release>
|
||||||
|
<api>1.0.0</api>
|
||||||
|
</version>
|
||||||
|
<stability>
|
||||||
|
<release>beta</release>
|
||||||
|
<api>beta</api>
|
||||||
|
</stability>
|
||||||
|
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
|
||||||
|
<notes>
|
||||||
|
initial version
|
||||||
|
</notes>
|
||||||
|
<contents>
|
||||||
|
<dir baseinstalldir="LetoDMS" name="/">
|
||||||
|
<dir name="Preview">
|
||||||
|
<file name="Preview.php" role="php">
|
||||||
|
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||||
|
</file>
|
||||||
|
</dir> <!-- /Lucene -->
|
||||||
|
<dir name="tests">
|
||||||
|
</dir> <!-- /tests -->
|
||||||
|
<file name="Preview.php" role="php">
|
||||||
|
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||||
|
</file>
|
||||||
|
</dir> <!-- / -->
|
||||||
|
</contents>
|
||||||
|
<dependencies>
|
||||||
|
<required>
|
||||||
|
<php>
|
||||||
|
<min>4.3.0</min>
|
||||||
|
</php>
|
||||||
|
<pearinstaller>
|
||||||
|
<min>1.5.4</min>
|
||||||
|
</pearinstaller>
|
||||||
|
</required>
|
||||||
|
</dependencies>
|
||||||
|
<phprelease />
|
||||||
|
<changelog>
|
||||||
|
<release>
|
||||||
|
</release>
|
||||||
|
</changelog>
|
||||||
|
</package>
|
0
LetoDMS_Preview/tests/Preview.php
Normal file
0
LetoDMS_Preview/tests/Preview.php
Normal file
Loading…
Reference in New Issue
Block a user