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,8 +89,10 @@ class PreviewColumn extends AdvancedColumn {
89 // hook into thumbnail plugin to get display for thumbnail 89 // hook into thumbnail plugin to get display for thumbnail
90 include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php'); 90 include_once(KT_DIR . '/plugins/thumbnails/thumbnails.php');
91 $thumbnailer = new ThumbnailViewlet(); 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 //$link = '<a name = "ktP'.$iDocumentId.'" href = "#ktP'.$iDocumentId.'" class="ktAction ktPreview" id = "box_'.$iDocumentId.'" '; 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,7 +23,7 @@
23 {if $url} 23 {if $url}
24 <a href='{$url}' target='_blank'> 24 <a href='{$url}' target='_blank'>
25 {/if} 25 {/if}
26 - <img src="{$thumbnail}" height="200px"/> 26 + <img src="{$thumbnail}"/>
27 {if $url} 27 {if $url}
28 </a> 28 </a>
29 {/if} 29 {/if}
plugins/thumbnails/thumbnails.php
@@ -83,7 +83,7 @@ class thumbnailGenerator extends BaseProcessor @@ -83,7 +83,7 @@ class thumbnailGenerator extends BaseProcessor
83 // 'otg', 'std', 'asc'); 83 // 'otg', 'std', 'asc');
84 84
85 // work around for ms office xp and 2003 templates - the mime type is identical but the templates aren't supported 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 $types = array('dot', 'xlt', 'pot'); 87 $types = array('dot', 'xlt', 'pot');
88 if(in_array($fileType, $types)){ 88 if(in_array($fileType, $types)){
89 return false; 89 return false;
@@ -132,9 +132,16 @@ class thumbnailGenerator extends BaseProcessor @@ -132,9 +132,16 @@ class thumbnailGenerator extends BaseProcessor
132 $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; 132 $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
133 //$mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; 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 $mime_types[] = 'application/pdf'; 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 return $mime_types; 145 return $mime_types;
139 } 146 }
140 147
@@ -157,23 +164,30 @@ class thumbnailGenerator extends BaseProcessor @@ -157,23 +164,30 @@ class thumbnailGenerator extends BaseProcessor
157 */ 164 */
158 global $default; 165 global $default;
159 166
  167 + $type = 'pdf'; // default type expected
160 $mimeTypeId = $this->document->getMimeTypeID(); 168 $mimeTypeId = $this->document->getMimeTypeID();
161 $mimeType = KTMime::getMimeTypeName($mimeTypeId); 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 // Get the pdf source file - if the document is a pdf then use the document as the source 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 $pdfDir = $default->documentRoot; 179 $pdfDir = $default->documentRoot;
166 - $pdfFile = $pdfDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath(); 180 + $srcFile = $pdfDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath();
167 } else { 181 } else {
168 $pdfDir = $default->pdfDirectory; 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 $thumbnaildir = $default->varDirectory.DIRECTORY_SEPARATOR.'thumbnails'; 186 $thumbnaildir = $default->varDirectory.DIRECTORY_SEPARATOR.'thumbnails';
173 187
174 if (stristr(PHP_OS,'WIN')) { 188 if (stristr(PHP_OS,'WIN')) {
175 $thumbnaildir = str_replace('/', '\\', $thumbnaildir); 189 $thumbnaildir = str_replace('/', '\\', $thumbnaildir);
176 - $pdfFile = str_replace('/', '\\', $pdfFile); 190 + $srcFile = str_replace('/', '\\', $srcFile);
177 } 191 }
178 192
179 $thumbnailfile = $thumbnaildir.DIRECTORY_SEPARATOR.$this->document->iId.'.jpg'; 193 $thumbnailfile = $thumbnaildir.DIRECTORY_SEPARATOR.$this->document->iId.'.jpg';
@@ -185,8 +199,8 @@ class thumbnailGenerator extends BaseProcessor @@ -185,8 +199,8 @@ class thumbnailGenerator extends BaseProcessor
185 } 199 }
186 200
187 // if there is no pdf that exists - hop out 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 return false; 204 return false;
191 } 205 }
192 206
@@ -198,12 +212,12 @@ class thumbnailGenerator extends BaseProcessor @@ -198,12 +212,12 @@ class thumbnailGenerator extends BaseProcessor
198 $pathConvert = (!empty($default->convertPath)) ? $default->convertPath : 'convert'; 212 $pathConvert = (!empty($default->convertPath)) ? $default->convertPath : 'convert';
199 // windows path may contain spaces 213 // windows path may contain spaces
200 if (stristr(PHP_OS,'WIN')) { 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 else { 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 $result = KTUtil::pexec($cmd); 221 $result = KTUtil::pexec($cmd);
208 return true; 222 return true;
209 } 223 }
@@ -226,7 +240,7 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -226,7 +240,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
226 // Set up the template 240 // Set up the template
227 $oKTTemplating =& KTTemplating::getSingleton(); 241 $oKTTemplating =& KTTemplating::getSingleton();
228 $oTemplate =& $oKTTemplating->loadTemplate('thumbnail_viewlet'); 242 $oTemplate =& $oKTTemplating->loadTemplate('thumbnail_viewlet');
229 - if (is_null($oTemplate)){ 243 + if (is_null($oTemplate)) {
230 return ''; 244 return '';
231 } 245 }
232 246
@@ -241,7 +255,7 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -241,7 +255,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
241 } 255 }
242 256
243 // if the thumbnail doesn't exist try to create it 257 // if the thumbnail doesn't exist try to create it
244 - if (!file_exists($thumbnailCheck)){ 258 + if (!file_exists($thumbnailCheck)) {
245 $thumbnailer = new thumbnailGenerator(); 259 $thumbnailer = new thumbnailGenerator();
246 $thumbnailer->setDocument($this->oDocument); 260 $thumbnailer->setDocument($this->oDocument);
247 $thumbnailer->processDocument(); 261 $thumbnailer->processDocument();
@@ -254,8 +268,7 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -254,8 +268,7 @@ class ThumbnailViewlet extends KTDocumentViewlet {
254 268
255 // check for existence and status of the instant view plugin 269 // check for existence and status of the instant view plugin
256 $url = ''; 270 $url = '';
257 - if (KTPluginUtil::pluginIsActive('instaview.processor.plugin'))  
258 - { 271 + if (KTPluginUtil::pluginIsActive('instaview.processor.plugin')) {
259 require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php'; 272 require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php';
260 $ivLinkAction = new instaViewLinkAction(); 273 $ivLinkAction = new instaViewLinkAction();
261 $url = $ivLinkAction->getViewLink($documentId, 'document'); 274 $url = $ivLinkAction->getViewLink($documentId, 'document');
@@ -276,7 +289,10 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -276,7 +289,10 @@ class ThumbnailViewlet extends KTDocumentViewlet {
276 return $oTemplate->render(); 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 global $default; 296 global $default;
281 $varDir = $default->varDirectory; 297 $varDir = $default->varDirectory;
282 $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg'; 298 $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg';
@@ -284,8 +300,6 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -284,8 +300,6 @@ class ThumbnailViewlet extends KTDocumentViewlet {
284 return 200; 300 return 200;
285 } 301 }
286 return 0; 302 return 0;
287 - //$size = getimagesize($thumbnailfile);  
288 - //return $size[0];  
289 } 303 }
290 } 304 }
291 305