Commit 0698281099c26b2b0bded28672ceefcea2c682a8

Authored by Paul Barrett
1 parent 38f34f0e

Added thumbnail support for image types registered in the mime types table. Fix…

…ed issue with thumbnail display width when orientation is horizontal

Story ID:143418. Image Thumbnails

Committed by: Paul Barrett

Reviewed by: Megan Watson
plugins/ktstandard/documentpreview/documentPreviewPlugin.php
... ... @@ -89,8 +89,10 @@ class PreviewColumn extends AdvancedColumn {
89 89 // hook into thumbnail plugin to get display for thumbnail
90 90 include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php');
91 91 $thumbnailer = new ThumbnailViewlet();
92   - $thumbnailwidth = $thumbnailer->get_width($iDocumentId);
93   - $width += $thumbnailwidth + 30;
  92 + $thumbWidth = $thumbnailer->getDisplaySize($iDocumentId);
  93 + if ($thumbWidth > 0) {
  94 + $width += $thumbWidth + 30;
  95 + }
94 96 }
95 97  
96 98 //$link = '<a name = "ktP'.$iDocumentId.'" href = "#ktP'.$iDocumentId.'" class="ktAction ktPreview" id = "box_'.$iDocumentId.'" ';
... ...
plugins/thumbnails/templates/thumbnail_viewlet.smarty
... ... @@ -23,7 +23,7 @@
23 23 {if $url}
24 24 <a href='{$url}' target='_blank'>
25 25 {/if}
26   - <img src="{$thumbnail}" height="200px"/>
  26 + <img src="{$thumbnail}"/>
27 27 {if $url}
28 28 </a>
29 29 {/if}
... ...
plugins/thumbnails/thumbnails.php
... ... @@ -83,7 +83,7 @@ class thumbnailGenerator extends BaseProcessor
83 83 // 'otg', 'std', 'asc');
84 84  
85 85 // work around for ms office xp and 2003 templates - the mime type is identical but the templates aren't supported
86   - if(!empty($fileType)){
  86 + if(!empty($fileType)) {
87 87 $types = array('dot', 'xlt', 'pot');
88 88 if(in_array($fileType, $types)){
89 89 return false;
... ... @@ -132,9 +132,16 @@ class thumbnailGenerator extends BaseProcessor
132 132 $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
133 133 //$mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
134 134  
135   - // In addition PDF files are also supported
  135 + // In addition PDF and (standard) Image files are also supported
136 136 $mime_types[] = 'application/pdf';
137   -
  137 +
  138 + $sQuery = "SELECT DISTINCT mimetypes FROM mime_types WHERE mimetypes LIKE 'image/%'";
  139 + $aTempRes = DBUtil::getResultArray($sQuery);
  140 + $count =count($aTempRes);
  141 + for($i = 0; $i < $count; $i++ ) {
  142 + $mime_types[] = $aTempRes[$i]['mimetypes'];
  143 + }
  144 +
138 145 return $mime_types;
139 146 }
140 147  
... ... @@ -157,23 +164,30 @@ class thumbnailGenerator extends BaseProcessor
157 164 */
158 165 global $default;
159 166  
  167 + $type = 'pdf'; // default type expected
160 168 $mimeTypeId = $this->document->getMimeTypeID();
161 169 $mimeType = KTMime::getMimeTypeName($mimeTypeId);
162 170  
  171 + // Check document type: Image or PDF
  172 + if (strstr($mimeType, 'image')) {
  173 + $type = 'image';
  174 + $srcDir = $default->documentRoot;
  175 + $srcFile = $srcDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath();
  176 + }
163 177 // Get the pdf source file - if the document is a pdf then use the document as the source
164   - if($mimeType == 'application/pdf') {
  178 + else if($mimeType == 'application/pdf') {
165 179 $pdfDir = $default->documentRoot;
166   - $pdfFile = $pdfDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath();
  180 + $srcFile = $pdfDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath();
167 181 } else {
168 182 $pdfDir = $default->pdfDirectory;
169   - $pdfFile = $pdfDir .DIRECTORY_SEPARATOR. $this->document->iId.'.pdf';
  183 + $srcFile = $pdfDir .DIRECTORY_SEPARATOR. $this->document->iId.'.pdf';
170 184 }
171 185  
172 186 $thumbnaildir = $default->varDirectory.DIRECTORY_SEPARATOR.'thumbnails';
173 187  
174 188 if (stristr(PHP_OS,'WIN')) {
175 189 $thumbnaildir = str_replace('/', '\\', $thumbnaildir);
176   - $pdfFile = str_replace('/', '\\', $pdfFile);
  190 + $srcFile = str_replace('/', '\\', $srcFile);
177 191 }
178 192  
179 193 $thumbnailfile = $thumbnaildir.DIRECTORY_SEPARATOR.$this->document->iId.'.jpg';
... ... @@ -185,8 +199,8 @@ class thumbnailGenerator extends BaseProcessor
185 199 }
186 200  
187 201 // if there is no pdf that exists - hop out
188   - if(!file_exists($pdfFile)){
189   - $default->log->debug('Thumbnail Generator Plugin: PDF file does not exist, cannot generate a thumbnail');
  202 + if(!file_exists($srcFile)){
  203 + $default->log->debug('Thumbnail Generator Plugin: Source file for conversion does not exist, cannot generate a thumbnail');
190 204 return false;
191 205 }
192 206  
... ... @@ -198,12 +212,12 @@ class thumbnailGenerator extends BaseProcessor
198 212 $pathConvert = (!empty($default->convertPath)) ? $default->convertPath : 'convert';
199 213 // windows path may contain spaces
200 214 if (stristr(PHP_OS,'WIN')) {
201   - $cmd = "\"{$pathConvert}\" \"{$pdfFile}[0]\" -resize 200x200 \"$thumbnailfile\"";
  215 + $cmd = "\"{$pathConvert}\" \"{$srcFile}" . ($type == 'pdf' ? "[0]" : "") . "\" -resize 200x200 \"$thumbnailfile\"";
202 216 }
203 217 else {
204   - $cmd = "{$pathConvert} {$pdfFile}[0] -resize 200x200 $thumbnailfile";
  218 + $cmd = "{$pathConvert} {$srcFile}" . ($type == 'pdf' ? "[0]" : "") . " -resize 200x200 $thumbnailfile";
205 219 }
206   -
  220 +
207 221 $result = KTUtil::pexec($cmd);
208 222 return true;
209 223 }
... ... @@ -226,7 +240,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
226 240 // Set up the template
227 241 $oKTTemplating =& KTTemplating::getSingleton();
228 242 $oTemplate =& $oKTTemplating->loadTemplate('thumbnail_viewlet');
229   - if (is_null($oTemplate)){
  243 + if (is_null($oTemplate)) {
230 244 return '';
231 245 }
232 246  
... ... @@ -241,7 +255,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
241 255 }
242 256  
243 257 // if the thumbnail doesn't exist try to create it
244   - if (!file_exists($thumbnailCheck)){
  258 + if (!file_exists($thumbnailCheck)) {
245 259 $thumbnailer = new thumbnailGenerator();
246 260 $thumbnailer->setDocument($this->oDocument);
247 261 $thumbnailer->processDocument();
... ... @@ -254,8 +268,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
254 268  
255 269 // check for existence and status of the instant view plugin
256 270 $url = '';
257   - if (KTPluginUtil::pluginIsActive('instaview.processor.plugin'))
258   - {
  271 + if (KTPluginUtil::pluginIsActive('instaview.processor.plugin')) {
259 272 require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php';
260 273 $ivLinkAction = new instaViewLinkAction();
261 274 $url = $ivLinkAction->getViewLink($documentId, 'document');
... ... @@ -276,7 +289,10 @@ class ThumbnailViewlet extends KTDocumentViewlet {
276 289 return $oTemplate->render();
277 290 }
278 291  
279   - public function get_width($documentId){
  292 + // determines whether the image exists and returns the maximum aspect to display;
  293 + // this is used for anywhere which might require display resizing based on the presence or absence of the thumbnail
  294 + public function getDisplaySize($documentId)
  295 + {
280 296 global $default;
281 297 $varDir = $default->varDirectory;
282 298 $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg';
... ... @@ -284,8 +300,6 @@ class ThumbnailViewlet extends KTDocumentViewlet {
284 300 return 200;
285 301 }
286 302 return 0;
287   - //$size = getimagesize($thumbnailfile);
288   - //return $size[0];
289 303 }
290 304 }
291 305  
... ...