documentPreview.php
9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/*
* $Id: $
*
* The contents of this file are subject to the KnowledgeTree
* Commercial Editions On-Premise License ("License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.knowledgetree.com/about/legal/
* The terms of this license may change from time to time and the latest
* license will be published from time to time at the above Internet address.
*
* This edition of the KnowledgeTree software
* is NOT licensed to you under Open Source terms.
* You may not redistribute this source code.
* For more information please see the License above.
*
* (c) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Ltd;
* All Rights Reserved.
*
*/
$kt_dir = $_REQUEST['kt_dir'];
require_once($kt_dir.'/config/dmsDefaults.php');
class DocumentPreview {
var $_oDocument;
var $_IDocId;
var $_iMimeId;
var $_oFolder;
var $_iFolderId;
/**
* Constructer - creates the document object
*
* @param int $iDocumentId The document Id
* @return
*/
function DocumentPreview($iId, $type = 'document'){
if($type == 'folder'){
// $type should never be a folder.
$this->_oDocument = false;
return;
}
$oDocument = Document::get($iId);
if(PEAR::isError($oDocument)){
$this->_oDocument = false;
return;
}
$this->_oDocument = $oDocument;
$this->_IDocId = $iId;
$this->_iMimeId = $oDocument->getMimeTypeID();
$this->imageMimeTypes = array(10, 27, 37, 38, 39, 71);
}
/**
* Get the document title for the preview
*
* @return string The document title and mime icon
*/
function getTitle(){
if($this->_oDocument === false){
return '<b>'._kt('Error').'</b>';
}
GLOBAL $default;
$sIcon = '';
$sTitle = htmlentities($this->_oDocument->getName(), ENT_NOQUOTES, 'utf-8');
$iLen = strlen($sTitle);
if($iLen > 60){
$sFull = $sTitle;
if($iLen >= 99){
$sTitle = substr($sTitle, 0, 97).'...';
}
$sTitle = '<h4 title="'.$sFull.'">'.$sTitle.'</h4>';
}else{
$sTitle = '<h2>'.$sTitle.'</h2>';
}
// Get the icon
$sIcon = $this->getMimeIcon();
$sTitle = '<div class="previewhd">
<div style="float:left">'.$sIcon.'</div>
<div style="float:left; width: 375px;">'.$sTitle.'</div>
</div>';
return $sTitle;
}
/**
* Display the mime type icon.
*
* @param unknown_type $iMimeId
* @return unknown
*/
function getMimeIcon() {
global $default;
$iMimeId = $this->_iMimeId;
$sIconPath = $this->getIconPath();
$sIconPath = $default->rootUrl.$sIconPath;
return "<img src='$sIconPath' title='$sTitle' /> ";
}
/**
* If there isn't an icon for the given extension, find a generic icon for the type else return the default icon.
*
* @param string $ext
* @return string
*/
function checkForGeneric($ext) {
if(in_array($ext, array('py','php'))){
return 'generic/source';
}
if(in_array($ext, array('odt','sxw', 'ott', 'sxt'))){
return 'generic/wordprocessing';
}
if(in_array($ext, array('ods','ots', 'sxc', 'stc'))){
return 'spreadsheet';
}
if(in_array($ext, array('odp','otp', 'sxi', 'sti'))){
return 'generic/pres';
}
if(in_array($ext, array('mp3','m4a'))){
return 'generic/sound';
}
if(in_array($ext, array('m4v'))){
return 'generic/video';
}
return 'default';
}
/**
* Get the path to the correct icon for the mime type
*
* @return string
*/
function getIconPath() {
$sIconPath = KTMime::getIconPath($this->_iMimeId);
// Get mime type icon
$sIconPath = '/resources/mimetypes/big/'.$sIconPath.'.png';
if(!file_exists(KT_DIR.$sIconPath)){
// See if there is an icon for the extension
$sMimeType = KTMime::getMimeTypeName($this->_iMimeId);
$aMimeInfo = KTMime::getFriendlyNameAndExtension($sMimeType);
if(!PEAR::isError($aMimeInfo) && !empty($aMimeInfo)){
$sExt = $aMimeInfo[0]['filetypes'];
$sIconPath = '/resources/mimetypes/big/'.$sExt.'.png';
if(!file_exists(KT_DIR.$sIconPath)){
$generic = $this->checkForGeneric($sExt);
// if all else fails, use the default icon
$sIconPath = '/resources/mimetypes/big/'.$generic.'.png';
}
}
}
return $sIconPath;
}
/**
* Render the info box content
*
* @return string
*/
function renderPreview(){
if($this->_oDocument === false){
return '<p>'._kt('A problem occured while loading the property preview.').'</p>';
}
$sInfo = $this->getMetadata();
return '<div id="preview" class="preview" onclick="javascript: destroyPanel();">'.$sInfo.'</div>';
}
/**
* Create a table of the document metadata.
* Hard coded for the moment
*
* @return unknown
*/
function getMetadata(){
/* Get document info */
// Filename
$sFilenameLb = _kt('Document Filename: ');
$sFilename = $this->_oDocument->getFileName();
// Mime type
$sMimeTypeLb = _kt('File is a: ');
$iMimeId = $this->_oDocument->getMimeTypeID();
$sMimeType = KTMime::getMimeTypeName($iMimeId);
$sMimeType = KTMime::getFriendlyNameForString($sMimeType);
// Version
$sVersionLb = _kt('Document Version: ');
$iVersion = $this->_oDocument->getVersion();
// Created by
$sCreatedByLb = _kt('Created by: ');
$iCreatorId = $this->_oDocument->getCreatorID();
$sCreated = $this->_oDocument->getCreatedDateTime();
$oCreator = User::get($iCreatorId);
$sCreatedBy = $oCreator->getName().' ('.$sCreated.')';
// Owned by
$sOwnedByLb = _kt('Owned by: ');
$iOwnedId = $this->_oDocument->getOwnerID();
$oOwner = User::get($iOwnedId);
$sOwnedBy = $oOwner->getName();
// Last update by
$iModifiedId = $this->_oDocument->getModifiedUserId();
$sLastUpdatedByLb = ''; $sLastUpdatedBy = '';
if(!empty($iModifiedId)){
$sLastUpdatedByLb = _kt('Last updated by: ');
$sModified = $this->_oDocument->getLastModifiedDate();
$oModifier = User::get($iModifiedId);
$sLastUpdatedBy = $oModifier->getName().' ('.$sModified.')';
}
// Document type
$sDocTypeLb = _kt('Document Type: ');
$iDocTypeId = $this->_oDocument->getDocumentTypeID();
$oDocType = DocumentType::get($iDocTypeId);
$sDocType = $oDocType->getName();
// Workflow
$iWFId = $this->_oDocument->getWorkflowId();
$sWF = ''; $sWFLb = '';
if(!empty($iWFId)){
$sWFLb = _kt('Workflow: ');
$iWFStateId = $this->_oDocument->getWorkflowStateId();
$oWF = KTWorkflow::get($iWFId);
$sWF = $oWF->getHumanName();
$oWFState = KTWorkflowState::get($iWFStateId);
$sWF .= ' ('.$oWFState->getHumanName().')';
}
// Checked out by
$sCheckedLb = ''; $sCheckedOutBy = '';
if($this->_oDocument->getIsCheckedOut()){
$sCheckedLb = _kt('Checked out by: ');
$iCheckedID = $this->_oDocument->getCheckedOutUserID();
$oCheckedUser = User::get($iCheckedID);
$sCheckedOutBy = $oCheckedUser->getName();
}
// Id
$sIdLb = _kt('Document ID: ');
$sId = $this->_IDocId;
/* Create table */
$sInfo = "<div style='float:left;'><table cellspacing='3px' cellpadding='3px'>
<tr><td>{$sFilenameLb}</td><td><b>{$sFilename}</b></td></tr>
<tr><td>{$sMimeTypeLb}</td><td><b>{$sMimeType}</b></td></tr>
<tr><td>{$sVersionLb}</td><td><b>{$iVersion}</b></td></tr>
<tr><td>{$sCreatedByLb}</td><td><b>{$sCreatedBy}</b></td></tr>
<tr><td>{$sOwnedByLb}</td><td><b>{$sOwnedBy}</b></td></tr>";
if(!empty($sLastUpdatedBy)){
$sInfo .= "<tr><td>{$sLastUpdatedByLb}</td><td><b>{$sLastUpdatedBy}</b></td></tr>";
}
$sInfo .= "<tr><td>{$sDocTypeLb}</td><td><b>{$sDocType}</b></td></tr>";
if(!empty($sWF)){
$sInfo .= "<tr><td>{$sWFLb}</td><td><b>{$sWF}</b></td></tr>";
}
if(!empty($sCheckedOutBy)){
$sInfo .= "<tr><td>{$sCheckedLb}</td><td><b>{$sCheckedOutBy}</b></td></tr>";
}
$sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>";
$sInfo .= " </table></div>";
// Check for existence of thumbnail plugin
if (KTPluginUtil::pluginIsActive('thumbnails.generator.processor.plugin')) {
// hook into thumbnail plugin to get display for thumbnail
include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php');
$thumbnailer = new ThumbnailViewlet();
$thumbnailDisplay = $thumbnailer->display_viewlet($sId);
if ($thumbnailDisplay != '') {
$sInfo .= "<div>$thumbnailDisplay</div>";
}
}
return $sInfo;
}
}
/**
* Get the document id and render the preview / info box
*/
$iDocumentId = $_REQUEST['fDocumentId'];
$oPreview = new DocumentPreview($iDocumentId);
$sTitle = $oPreview->getTitle();
$sContent = $oPreview->renderPreview();
echo $sTitle.'<br />'.$sContent;
exit;
?>