Commit 8f1072d4e2614e0fcf6fe07da692a649cc3fd89c

Authored by Prince Mbekwa
1 parent f90adba9

Added thumbnailer functionality

plugins/ktstandard/documentpreview/documentPreview.php 100644 → 100755
... ... @@ -257,8 +257,8 @@ class DocumentPreview {
257 257 $sId = $this->_IDocId;
258 258  
259 259 /* Create table */
260   -
261   - $sInfo = "<table cellspacing='3px' cellpadding='3px'>
  260 +
  261 + $sInfo = "<div style='float:left;'><table cellspacing='3px' cellpadding='3px'>
262 262 <tr><td>{$sFilenameLb}</td><td><b>{$sFilename}</b></td></tr>
263 263 <tr><td>{$sMimeTypeLb}</td><td><b>{$sMimeType}</b></td></tr>
264 264 <tr><td>{$sVersionLb}</td><td><b>{$iVersion}</b></td></tr>
... ... @@ -276,8 +276,19 @@ class DocumentPreview {
276 276 $sInfo .= "<tr><td>{$sCheckedLb}</td><td><b>{$sCheckedOutBy}</b></td></tr>";
277 277 }
278 278  
279   - $sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>
280   - </table>";
  279 + $sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>";
  280 + $sInfo .= " </table></div>";
  281 +
  282 + // Check for existence of thumbnail plugin
  283 + if (KTPluginUtil::pluginIsActive('thumbnails.generator.processor.plugin')) {
  284 + // hook into thumbnail plugin to get display for thumbnail
  285 + include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php');
  286 + $thumbnailer = new ThumbnailViewlet();
  287 + $thumbnailDisplay = $thumbnailer->display_viewlet($sId);
  288 + if ($thumbnailDisplay != '') {
  289 + $sInfo .= "<div>$thumbnailDisplay</div>";
  290 + }
  291 + }
281 292  
282 293 return $sInfo;
283 294 }
... ...
plugins/ktstandard/documentpreview/documentPreviewPlugin.php 100644 → 100755
... ... @@ -68,14 +68,23 @@ class PreviewColumn extends AdvancedColumn {
68 68 $sTitle = _kt('Property Preview');
69 69 $sLoading = _kt('Loading...');
70 70  
71   -
  71 + $width = 500;
  72 +
  73 + // Check for existence of thumbnail plugin
  74 + if (KTPluginUtil::pluginIsActive('thumbnails.generator.processor.plugin')) {
  75 + // hook into thumbnail plugin to get display for thumbnail
  76 + include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php');
  77 + $thumbnailer = new ThumbnailViewlet();
  78 + $width += $thumbnailer->get_width($iDocumentId);
  79 + }
  80 +
72 81 $link = '<a href = "#" class="ktAction ktPreview" id = "box_'.$iDocumentId.'" ';
73 82  
74 83 if($this->sActivation == 'mouse-over'){
75   - $sJs = "javascript: this.t = setTimeout('showInfo(\'$iDocumentId\', \'$sUrl\', \'$sDir\', \'$sLoading\')', $iDelay);";
  84 + $sJs = "javascript: this.t = setTimeout('showInfo(\'$iDocumentId\', \'$sUrl\', \'$sDir\', \'$sLoading\', $width)', $iDelay);";
76 85 $link .= 'onmouseover = "'.$sJs.'" onmouseout = "clearTimeout(this.t);">';
77 86 }else{
78   - $sJs = "javascript: showInfo('$iDocumentId', '$sUrl', '$sDir', '$sLoading');";
  87 + $sJs = "javascript: showInfo('$iDocumentId', '$sUrl', '$sDir', '$sLoading', $width);";
79 88 $link .= 'onclick = "'.$sJs.'" title="'.$sTitle.'">';
80 89 }
81 90  
... ...
plugins/ktstandard/documentpreview/resources/preview.js 100644 → 100755
1 1 /*
2 2 Create the preview / info box using an ExtJS Dialog window
3 3 */
4   -var showInfo = function(iDocId, sUrl, sDir, loading){
  4 +var showInfo = function(iDocId, sUrl, sDir, loading, mwidth){
5 5  
6 6 // Create the info box container div
7 7 createPanel();
... ... @@ -14,7 +14,7 @@ var showInfo = function(iDocId, sUrl, sDir, loading){
14 14 shadow: false,
15 15 modal: true,
16 16 plain: false,
17   - width: 500,
  17 + width: mwidth,
18 18 height: 360,
19 19 minWidth: 300,
20 20 minHeight: 250
... ...
plugins/thumbnails/templates/thumbnail_viewlet.smarty 100644 → 100755
  1 +<div>
  2 + <div><img src="{$thumbnail}" height="200px"/></div>
  3 +</div>
0 4 \ No newline at end of file
... ...
plugins/thumbnails/thumbnails.php 100644 → 100755
... ... @@ -131,34 +131,64 @@ class thumbnailGenerator extends BaseProcessor
131 131 - check out ktcore/KTDocumentViewlets.php
132 132 - viewlet class is below
133 133 */
134   -
  134 + global $default;
135 135 $pdfDir = $default->pdfDirectory;
136 136 $pdfFile = $pdfDir .'/'. $this->document->iId.'.pdf';
  137 + $thumbnaildir = $pdfDir."/thumbnails";
  138 + $thumbnailfile = $thumbnaildir.'/'.$this->document->iId.'.jpg';
  139 +
  140 + //if thumbail dir does not exist, generate one
  141 + if (!file_exists($thumbnaildir)) {
  142 + mkdir($thumbnaildir, 0755);
  143 + }
137 144  
138   - // if a previous version of the pdf exists - delete it
  145 + // if there is no pdf that exists - hop out
139 146 if(!file_exists($pdfFile)){
140 147 global $default;
141 148 $default->log->debug('Thumbnail Generator Plugin: PDF file does not exist, cannot generate a thumbnail');
142 149 return false;
143 150 }
144   -
  151 + // if a previous version of the thumbnail exists - delete it
  152 + if (file_exists($thumbnailfile)) {
  153 + @unlink($thumbnailfile);
  154 + }
145 155 // do generation
146   - return true;
  156 + if (extension_loaded('imagick')) {
  157 + $result= shell_exec("convert -size 200x200 {$pdfFile}[0] -resize 200x200 $thumbnailfile");
  158 + return true;
  159 + }else{
  160 + $default->log->debug('Thumbnail Generator Plugin: Imagemagick not installed, cannot generate a thumbnail');
  161 + return false;
  162 + }
  163 +
147 164 }
148 165 }
149 166  
150   -
151 167 class ThumbnailViewlet extends KTDocumentViewlet {
152 168 var $sName = 'thumbnail.viewlets';
153 169  
154   - function display_viewlet() {
  170 + public function display_viewlet($documentId) {
  171 + global $default;
155 172 $oKTTemplating =& KTTemplating::getSingleton();
156 173 $oTemplate =& $oKTTemplating->loadTemplate('thumbnail_viewlet');
157 174 if (is_null($oTemplate)) return '';
158   -
159   - $oTemplate->setData(array());
  175 + $pdfDir = $default->pdfDirectory;
  176 + $thumbnailfile = $pdfDir . '/thumbnails/'.$documentId.'.jpg';
  177 + // check that file exists
  178 + if (!file_exists($thumbnailfile)) return '';
  179 + // NOTE this is to turn the config setting for the PDF directory into a proper URL and not a path
  180 + $thumbnailUrl = str_replace($default->varDirectory, 'var/', $thumbnailfile);
  181 + $oTemplate->setData(array('thumbnail' => $thumbnailUrl));
160 182 return $oTemplate->render();
161 183 }
  184 +
  185 + public function get_width($documentId){
  186 + global $default;
  187 + $pdfDir = $default->pdfDirectory;
  188 + $thumbnailfile = $pdfDir . '/thumbnails/'.$documentId.'.jpg';
  189 + $size = getimagesize($thumbnailfile);
  190 + return $size[0];
  191 + }
162 192 }
163 193  
164 194 ?>
165 195 \ No newline at end of file
... ...
plugins/thumbnails/thumbnailsPlugin.php 100644 → 100755