Commit fc8c1ba6ca635c937d131d109f5817b06f28a757
1 parent
7d380d0a
Moved the thumbnails behind a view controller and moved them into the external var directory.
PT: 1829778 Committed by: Megan Watson
Showing
2 changed files
with
75 additions
and
14 deletions
plugins/thumbnails/thumbnail_view.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +require_once('../../config/dmsDefaults.php'); | ||
| 4 | + | ||
| 5 | +// Check the session, ensure the user is logged in | ||
| 6 | +$session = new Session(); | ||
| 7 | +$sessionStatus = $session->verify(); | ||
| 8 | + | ||
| 9 | +if(PEAR::isError($sessionStatus)){ | ||
| 10 | + echo $sessionStatus->getMessage(); | ||
| 11 | + exit; | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +if(!$sessionStatus){ | ||
| 15 | + exit; | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +// Get the document | ||
| 19 | +$documentId = $_GET['documentId']; | ||
| 20 | +$oDocument = Document::get($documentId); | ||
| 21 | + | ||
| 22 | +if (PEAR::isError($oDocument)) { | ||
| 23 | + exit; | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +// Check the document is available and the user has permission to view it | ||
| 27 | +if ($oDocument->getStatusID() == ARCHIVED) { | ||
| 28 | + exit; | ||
| 29 | +} else if ($oDocument->getStatusID() == DELETED) { | ||
| 30 | + exit; | ||
| 31 | +}else if (!Permission::userHasDocumentReadPermission($oDocument)) { | ||
| 32 | + exit; | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +// Get and render the thumbnail | ||
| 36 | +// Check for the thumbnail | ||
| 37 | +$varDir = $default->varDirectory; | ||
| 38 | +$thumbnailCheck = $varDir . '/thumbnails/'.$documentId.'.jpg'; | ||
| 39 | + | ||
| 40 | +if(!file_exists($thumbnailCheck)){ | ||
| 41 | + exit; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// Use correct slashes for windows | ||
| 45 | +if (strpos(PHP_OS, 'WIN') !== false) { | ||
| 46 | + $thumbnailCheck = str_replace('/', '\\', $thumbnailCheck); | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +$fileSize = filesize($thumbnailCheck); | ||
| 50 | + | ||
| 51 | +header("Content-Type: image/jpeg"); | ||
| 52 | +header("Content-Length: {$fileSize}"); | ||
| 53 | + | ||
| 54 | +echo readfile($thumbnailCheck); | ||
| 55 | +exit; | ||
| 56 | +?> | ||
| 0 | \ No newline at end of file | 57 | \ No newline at end of file |
plugins/thumbnails/thumbnails.php
| @@ -155,7 +155,7 @@ class thumbnailGenerator extends BaseProcessor | @@ -155,7 +155,7 @@ class thumbnailGenerator extends BaseProcessor | ||
| 155 | $pdfFile = $pdfDir .DIRECTORY_SEPARATOR. $this->document->iId.'.pdf'; | 155 | $pdfFile = $pdfDir .DIRECTORY_SEPARATOR. $this->document->iId.'.pdf'; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | - $thumbnaildir = $default->internalVarDirectory.DIRECTORY_SEPARATOR.'thumbnails'; | 158 | + $thumbnaildir = $default->varDirectory.DIRECTORY_SEPARATOR.'thumbnails'; |
| 159 | 159 | ||
| 160 | if (stristr(PHP_OS,'WIN')) { | 160 | if (stristr(PHP_OS,'WIN')) { |
| 161 | $thumbnaildir = str_replace('/', '\\', $thumbnaildir); | 161 | $thumbnaildir = str_replace('/', '\\', $thumbnaildir); |
| @@ -189,7 +189,7 @@ class thumbnailGenerator extends BaseProcessor | @@ -189,7 +189,7 @@ class thumbnailGenerator extends BaseProcessor | ||
| 189 | else { | 189 | else { |
| 190 | $cmd = "{$pathConvert} {$pdfFile}[0] -resize 200x200 $thumbnailfile"; | 190 | $cmd = "{$pathConvert} {$pdfFile}[0] -resize 200x200 $thumbnailfile"; |
| 191 | } | 191 | } |
| 192 | - | 192 | + |
| 193 | $result = KTUtil::pexec($cmd); | 193 | $result = KTUtil::pexec($cmd); |
| 194 | return true; | 194 | return true; |
| 195 | } | 195 | } |
| @@ -216,17 +216,16 @@ class ThumbnailViewlet extends KTDocumentViewlet { | @@ -216,17 +216,16 @@ class ThumbnailViewlet extends KTDocumentViewlet { | ||
| 216 | return ''; | 216 | return ''; |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | - // Check for the thumbnail | 219 | + // Check that the thumbnail exists on disk |
| 220 | global $default; | 220 | global $default; |
| 221 | - $varDir = $default->internalVarDirectory; | ||
| 222 | - $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg'; | 221 | + $varDir = $default->varDirectory; |
| 222 | + $thumbnailCheck = $varDir . '/thumbnails/'.$documentId.'.jpg'; | ||
| 223 | 223 | ||
| 224 | - if (stristr(PHP_OS,'WIN')) { | ||
| 225 | - $varDir = str_replace('/', '\\', $varDir); | 224 | + // Use correct slashes for windows |
| 225 | + if (strpos(PHP_OS, 'WIN') !== false) { | ||
| 226 | + $thumbnailCheck = str_replace('/', '\\', $thumbnailCheck); | ||
| 226 | } | 227 | } |
| 227 | 228 | ||
| 228 | - $thumbnailCheck = $varDir . '/thumbnails/'.$documentId.'.jpg'; | ||
| 229 | - | ||
| 230 | // if the thumbnail doesn't exist try to create it | 229 | // if the thumbnail doesn't exist try to create it |
| 231 | if (!file_exists($thumbnailCheck)){ | 230 | if (!file_exists($thumbnailCheck)){ |
| 232 | $thumbnailer = new thumbnailGenerator(); | 231 | $thumbnailer = new thumbnailGenerator(); |
| @@ -239,18 +238,24 @@ class ThumbnailViewlet extends KTDocumentViewlet { | @@ -239,18 +238,24 @@ class ThumbnailViewlet extends KTDocumentViewlet { | ||
| 239 | } | 238 | } |
| 240 | } | 239 | } |
| 241 | 240 | ||
| 242 | - // check for existence and status of instant view plugin | 241 | + // check for existence and status of the instant view plugin |
| 243 | $url = ''; | 242 | $url = ''; |
| 244 | if (KTPluginUtil::pluginIsActive('instaview.processor.plugin')) | 243 | if (KTPluginUtil::pluginIsActive('instaview.processor.plugin')) |
| 245 | { | 244 | { |
| 246 | require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php'; | 245 | require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php'; |
| 247 | $ivLinkAction = new instaViewLinkAction(); | 246 | $ivLinkAction = new instaViewLinkAction(); |
| 248 | $url = $ivLinkAction->getViewLink($documentId, 'document'); | 247 | $url = $ivLinkAction->getViewLink($documentId, 'document'); |
| 249 | - } | 248 | + } |
| 250 | 249 | ||
| 251 | // Get the url to the thumbnail and render it | 250 | // Get the url to the thumbnail and render it |
| 252 | - $thumbnailUrl = str_replace($default->internalVarDirectory, 'var', $thumbnailfile); | ||
| 253 | - $oTemplate->setData(array( | 251 | + // Ensure url has correct slashes |
| 252 | + $sHostPath = KTUtil::kt_url(); | ||
| 253 | + $plugin_path = KTPluginUtil::getPluginPath('thumbnails.generator.processor.plugin'); | ||
| 254 | + $thumbnailUrl = $plugin_path . 'thumbnail_view.php?documentId='.$documentId; | ||
| 255 | + $thumbnailUrl = str_replace('\\', '/', $thumbnailUrl); | ||
| 256 | + $thumbnailUrl = str_replace(KT_DIR, $sHostPath, $thumbnailUrl); | ||
| 257 | + | ||
| 258 | + $oTemplate->setData(array( | ||
| 254 | 'thumbnail' => $thumbnailUrl, | 259 | 'thumbnail' => $thumbnailUrl, |
| 255 | 'url' => $url | 260 | 'url' => $url |
| 256 | )); | 261 | )); |
| @@ -259,7 +264,7 @@ class ThumbnailViewlet extends KTDocumentViewlet { | @@ -259,7 +264,7 @@ class ThumbnailViewlet extends KTDocumentViewlet { | ||
| 259 | 264 | ||
| 260 | public function get_width($documentId){ | 265 | public function get_width($documentId){ |
| 261 | global $default; | 266 | global $default; |
| 262 | - $varDir = $default->internalVarDirectory; | 267 | + $varDir = $default->varDirectory; |
| 263 | $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg'; | 268 | $thumbnailfile = $varDir . '/thumbnails/'.$documentId.'.jpg'; |
| 264 | if(file_exists($thumbnailfile)){ | 269 | if(file_exists($thumbnailfile)){ |
| 265 | return 200; | 270 | return 200; |