Commit c446a64bad22e0ee0215caebe0f259b96df4f55e

Authored by Megan Watson
1 parent 410a3115

Added thumbnail column

PT: 1434184

Committed by: Megan Watson
plugins/thumbnails/resources/thumbnails.css 0 → 100644
  1 +.thumb-shadow {
  2 + float:left;
  3 + background: url(plugins/thumbnails/templates/shadowAlpha.png) no-repeat bottom right !important;
  4 + background: url(plugins/thumbnails/templates/shadow.gif) no-repeat bottom right;
  5 + margin: 10px 0 0 10px !important;
  6 + margin: 10px 0 0 5px;
  7 +}
  8 +
  9 +.thumb-shadow img {
  10 + display: block;
  11 + position: relative;
  12 + background-color: #fff;
  13 + border: 1px solid #a9a9a9;
  14 + margin: -6px 6px 6px -6px;
  15 + padding: 4px;
  16 +}
0 \ No newline at end of file 17 \ No newline at end of file
plugins/thumbnails/thumbnails.php
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
36 */ 36 */
37 37
38 require_once(KT_LIB_DIR . "/actions/documentviewlet.inc.php"); 38 require_once(KT_LIB_DIR . "/actions/documentviewlet.inc.php");
  39 +require_once(KT_LIB_DIR . '/browse/advancedcolumns.inc.php');
39 require_once(KT_DIR . '/search2/documentProcessor/documentProcessor.inc.php'); 40 require_once(KT_DIR . '/search2/documentProcessor/documentProcessor.inc.php');
40 41
41 /** 42 /**
@@ -134,14 +135,14 @@ class thumbnailGenerator extends BaseProcessor @@ -134,14 +135,14 @@ class thumbnailGenerator extends BaseProcessor
134 135
135 // In addition PDF and (standard) Image files are also supported 136 // In addition PDF and (standard) Image files are also supported
136 $mime_types[] = 'application/pdf'; 137 $mime_types[] = 'application/pdf';
137 - 138 +
138 $sQuery = "SELECT DISTINCT mimetypes FROM mime_types WHERE mimetypes LIKE 'image/%'"; 139 $sQuery = "SELECT DISTINCT mimetypes FROM mime_types WHERE mimetypes LIKE 'image/%'";
139 $aTempRes = DBUtil::getResultArray($sQuery); 140 $aTempRes = DBUtil::getResultArray($sQuery);
140 $count =count($aTempRes); 141 $count =count($aTempRes);
141 for($i = 0; $i < $count; $i++ ) { 142 for($i = 0; $i < $count; $i++ ) {
142 $mime_types[] = $aTempRes[$i]['mimetypes']; 143 $mime_types[] = $aTempRes[$i]['mimetypes'];
143 } 144 }
144 - 145 +
145 return $mime_types; 146 return $mime_types;
146 } 147 }
147 148
@@ -218,7 +219,7 @@ class thumbnailGenerator extends BaseProcessor @@ -218,7 +219,7 @@ class thumbnailGenerator extends BaseProcessor
218 else { 219 else {
219 $cmd = "{$pathConvert} {$srcFile}" . $pageNumber . " -resize 200x200 $thumbnailfile"; 220 $cmd = "{$pathConvert} {$srcFile}" . $pageNumber . " -resize 200x200 $thumbnailfile";
220 } 221 }
221 - 222 +
222 $result = KTUtil::pexec($cmd); 223 $result = KTUtil::pexec($cmd);
223 return true; 224 return true;
224 } 225 }
@@ -304,4 +305,76 @@ class ThumbnailViewlet extends KTDocumentViewlet { @@ -304,4 +305,76 @@ class ThumbnailViewlet extends KTDocumentViewlet {
304 } 305 }
305 } 306 }
306 307
  308 +/**
  309 + * Displays a column in the Browse view of the document thumbnail
  310 + */
  311 +class ThumbnailColumn extends AdvancedColumn {
  312 + var $name = 'thumnailcolumn';
  313 + var $namespace = 'thumbnails.generator.column';
  314 +
  315 + function ThumbnailColumn() {
  316 + $this->label = _kt('Thumbnail');
  317 + }
  318 +
  319 + function renderHeader($sReturnURL) {
  320 + global $main;
  321 +
  322 + $path = dirname(__FILE__);
  323 +
  324 + // Get the CSS to render the thumbnail
  325 + $main->requireCSSResource('plugins/thumbnails/resources/thumbnails.css');
  326 + return '&nbsp;';
  327 + }
  328 +
  329 + /**
  330 + * Render the thumbnail for the given document
  331 + *
  332 + * @param array $aDataRow
  333 + * @return string HTML
  334 + */
  335 + function renderData($aDataRow) {
  336 + if ($aDataRow["type"] == "document") {
  337 + $docid = $aDataRow['docid'];
  338 + $oDoc = $aDataRow['document'];
  339 +
  340 + $config = KTConfig::getSingleton();
  341 + $height = $config->get('browse/thumbnail_height', 75);
  342 + $rootUrl = $config->get('KnowledgeTree/rootUrl');
  343 +
  344 + // Check if the thumbnail exists
  345 + global $default;
  346 + $varDir = $default->varDirectory;
  347 + $thumbnailCheck = $varDir . '/thumbnails/'.$docid.'.jpg';
  348 +
  349 + // Use correct slashes for windows
  350 + if (strpos(PHP_OS, 'WIN') !== false) {
  351 + $thumbnailCheck = str_replace('/', '\\', $thumbnailCheck);
  352 + }
  353 +
  354 + // We won't try generate one - will slow down browsing too much
  355 + if (!file_exists($thumbnailCheck)){
  356 + $tag = "
  357 + <div class='thumb-shadow'>
  358 + <img src='{$rootUrl}/resources/graphics/no_preview.png' height='{$height}' />
  359 + </div>";
  360 + return $tag;
  361 + }
  362 +
  363 + $sHostPath = KTUtil::kt_url();
  364 + $plugin_path = KTPluginUtil::getPluginPath('thumbnails.generator.processor.plugin');
  365 + $thumbnailUrl = $plugin_path . 'thumbnail_view.php?documentId='.$docid;
  366 + $thumbnailUrl = str_replace('\\', '/', $thumbnailUrl);
  367 + $thumbnailUrl = str_replace(KT_DIR, $sHostPath, $thumbnailUrl);
  368 +
  369 + $sInfo = '
  370 + <div class="thumb-shadow">
  371 + <img src="'.$thumbnailUrl.'" height='.$height.' />
  372 + </div>';
  373 +
  374 + return $sInfo;
  375 + }
  376 + return '';
  377 + }
  378 +}
  379 +
307 ?> 380 ?>
plugins/thumbnails/thumbnailsPlugin.php
@@ -60,6 +60,7 @@ class thumbnailsPlugin extends KTPlugin { @@ -60,6 +60,7 @@ class thumbnailsPlugin extends KTPlugin {
60 $dir = $plugin_dir . 'thumbnails.php'; 60 $dir = $plugin_dir . 'thumbnails.php';
61 $this->registerProcessor('thumbnailGenerator', 'thumbnails.generator.processor', $dir); 61 $this->registerProcessor('thumbnailGenerator', 'thumbnails.generator.processor', $dir);
62 $this->registerAction('documentviewlet', 'ThumbnailViewlet', 'thumbnail.viewlets', $dir); 62 $this->registerAction('documentviewlet', 'ThumbnailViewlet', 'thumbnail.viewlets', $dir);
  63 + $this->registerColumn(_kt('Thumbnail'), 'thumbnails.generator.column', 'ThumbnailColumn', $dir);
63 64
64 require_once(KT_LIB_DIR . '/templating/templating.inc.php'); 65 require_once(KT_LIB_DIR . '/templating/templating.inc.php');
65 $oTemplating =& KTTemplating::getSingleton(); 66 $oTemplating =& KTTemplating::getSingleton();
resources/graphics/no_preview.png 0 → 100644

2.66 KB