mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-07-15 17:08:11 +00:00
move code into controller and add hooks
This commit is contained in:
parent
7a25859a19
commit
f17b120126
74
controllers/class.PdfPreview.php
Normal file
74
controllers/class.PdfPreview.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of PdfPreview controller
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @license GPL 2
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class which does the busines logic for previewing a document
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_Controller_PdfPreview extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
global $theme;
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$type = $this->params['type'];
|
||||||
|
$settings = $this->params['settings'];
|
||||||
|
|
||||||
|
switch($type) {
|
||||||
|
case "version":
|
||||||
|
$version = $this->params['version'];
|
||||||
|
$document = $this->params['document'];
|
||||||
|
if($version < 1) {
|
||||||
|
$content = $this->callHook('documentLatestContent', $document);
|
||||||
|
if($content === null)
|
||||||
|
$content = $document->getLatestContent();
|
||||||
|
} else {
|
||||||
|
$content = $this->callHook('documentContent', $document, $version);
|
||||||
|
if($content === null)
|
||||||
|
$content = $document->getContentByVersion($version);
|
||||||
|
}
|
||||||
|
if (!is_object($content)) {
|
||||||
|
$this->errormsg = 'invalid_version';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/* set params['content'] for compatiblity with older extensions which
|
||||||
|
* expect the content in the controller
|
||||||
|
*/
|
||||||
|
$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());
|
||||||
|
$previewer->setXsendfile($settings->_enableXsendfile);
|
||||||
|
if(!$previewer->hasPreview($content)) {
|
||||||
|
add_log_line("");
|
||||||
|
if(!$previewer->createPreview($content)) {
|
||||||
|
add_log_line("", PEAR_LOG_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!$previewer->hasPreview($content)) {
|
||||||
|
header('Content-Type: application/pdf');
|
||||||
|
readfile('../views/'.$theme.'/images/empty.pdf');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
header('Content-Type: application/pdf');
|
||||||
|
$previewer->getPreview($content);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,12 +27,11 @@ include("../inc/inc.Init.php");
|
||||||
include("../inc/inc.Extension.php");
|
include("../inc/inc.Extension.php");
|
||||||
include("../inc/inc.DBInit.php");
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
|
include("../inc/inc.ClassController.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
|
|
||||||
/**
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
* Include class to preview documents
|
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||||
*/
|
|
||||||
require_once("SeedDMS/Preview.php");
|
|
||||||
|
|
||||||
$documentid = $_GET["documentid"];
|
$documentid = $_GET["documentid"];
|
||||||
if (!isset($documentid) || !is_numeric($documentid) || intval($documentid)<1) {
|
if (!isset($documentid) || !is_numeric($documentid) || intval($documentid)<1) {
|
||||||
|
@ -52,10 +51,13 @@ if(isset($_GET['version'])) {
|
||||||
$version = $_GET["version"];
|
$version = $_GET["version"];
|
||||||
if (!is_numeric($version))
|
if (!is_numeric($version))
|
||||||
exit;
|
exit;
|
||||||
if(intval($version)<1)
|
$controller->setParam('document', $document);
|
||||||
$object = $document->getLatestContent();
|
$controller->setParam('version', $version);
|
||||||
else
|
$controller->setParam('type', 'version');
|
||||||
$object = $document->getContentByVersion($version);
|
if(!$controller->run()) {
|
||||||
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
|
||||||
|
}
|
||||||
|
exit;
|
||||||
} elseif(isset($_GET['file'])) {
|
} elseif(isset($_GET['file'])) {
|
||||||
$file = $_GET['file'];
|
$file = $_GET['file'];
|
||||||
if (!is_numeric($file) || intval($file)<1)
|
if (!is_numeric($file) || intval($file)<1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user