protected function actionThumb($params) { GO::session()->closeWriting(); $dir = GO::config()->root_path . 'views/Extjs3/themes/Default/images/128x128/filetypes/'; $url = GO::config()->host . 'views/Extjs3/themes/Default/images/128x128/filetypes/'; $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $params['src']); if (is_dir(GO::config()->file_storage_path . $params['src'])) { $src = $dir . 'folder.png'; } else { switch (strtolower($file->extension())) { case 'svg': case 'ico': case 'jpg': case 'jpeg': case 'png': case 'gif': case 'xmind': $src = GO::config()->file_storage_path . $params['src']; break; case 'tar': case 'tgz': case 'gz': case 'bz2': case 'zip': $src = $dir . 'zip.png'; break; case 'odt': case 'docx': case 'doc': case 'htm': case 'html': $src = $dir . 'doc.png'; break; case 'odc': case 'ods': case 'xls': case 'xlsx': $src = $dir . 'spreadsheet.png'; break; case 'odp': case 'pps': case 'pptx': case 'ppt': $src = $dir . 'pps.png'; break; case 'eml': $src = $dir . 'message.png'; break; case 'log': $src = $dir . 'txt.png'; break; default: if (file_exists($dir . $file->extension() . '.png')) { $src = $dir . $file->extension() . '.png'; } else { $src = $dir . 'unknown.png'; } break; } } $file = new \GO\Base\Fs\File($src); if ($file->size() > \GO::config()->max_thumbnail_size * 1024 * 1024) { throw new \Exception("Image may not be larger than 5MB."); } $w = isset($params['w']) ? intval($params['w']) : 0; $h = isset($params['h']) ? intval($params['h']) : 0; $zc = !empty($params['zc']) && !empty($w) && !empty($h); $lw = isset($params['lw']) ? intval($params['lw']) : 0; $lh = isset($params['lh']) ? intval($params['lh']) : 0; $pw = isset($params['pw']) ? intval($params['pw']) : 0; $ph = isset($params['ph']) ? intval($params['ph']) : 0; if ($file->extension() == 'xmind') { // $filename = $file->nameWithoutExtension().'.jpeg'; // // if (!file_exists($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) || filectime($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) < filectime($GLOBALS['GO_CONFIG']->file_storage_path . $path)) { // $zipfile = zip_open($GLOBALS['GO_CONFIG']->file_storage_path . $path); // // while ($entry = zip_read($zipfile)) { // if (zip_entry_name($entry) == 'Thumbnails/thumbnail.jpg') { // require_once($GLOBALS['GO_CONFIG']->class_path . 'filesystem.class.inc'); // zip_entry_open($zipfile, $entry, 'r'); // file_put_contents($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename, zip_entry_read($entry, zip_entry_filesize($entry))); // zip_entry_close($entry); // break; // } // } // zip_close($zipfile); // } // $path = 'thumbcache/' . $filename; } $cacheDir = new \GO\Base\Fs\Folder(GO::config()->orig_tmpdir . 'thumbcache'); $cacheDir->create(); $cacheFilename = str_replace(array('/', '\\'), '_', $file->parent()->path() . '_' . $w . '_' . $h . '_' . $lw . '_' . $ph . '_' . '_' . $pw . '_' . $lw); if ($zc) { $cacheFilename .= '_zc'; } //$cache_filename .= '_'.filesize($full_path); $cacheFilename .= $file->name(); $readfile = $cacheDir->path() . '/' . $cacheFilename; $thumbExists = file_exists($cacheDir->path() . '/' . $cacheFilename); $thumbMtime = $thumbExists ? filemtime($cacheDir->path() . '/' . $cacheFilename) : 0; GO::debug("Thumb mtime: " . $thumbMtime . " (" . $cacheFilename . ")"); if (!empty($params['nocache']) || !$thumbExists || $thumbMtime < $file->mtime() || $thumbMtime < $file->ctime()) { GO::debug("Resizing image"); $image = new \GO\Base\Util\Image($file->path()); if (!$image->load_success) { GO::debug("Failed to load image for thumbnailing"); //failed. Stream original image $readfile = $file->path(); } else { if ($zc) { $image->zoomcrop($w, $h); } else { if ($lw || $lh || $pw || $lw) { //treat landscape and portrait differently $landscape = $image->landscape(); if ($landscape) { $w = $lw; $h = $lh; } else { $w = $pw; $h = $ph; } } GO::debug($w . "x" . $h); if ($w && $h) { $image->resize($w, $h); } elseif ($w) { $image->resizeToWidth($w); } else { $image->resizeToHeight($h); } } $image->save($cacheDir->path() . '/' . $cacheFilename); } } header("Expires: " . date("D, j M Y G:i:s ", time() + 86400 * 365) . 'GMT'); //expires in 1 year header('Cache-Control: cache'); header('Pragma: cache'); header('Content-Type: ' . $file->mimeType()); header('Content-Disposition: inline; filename="' . $cacheFilename . '"'); header('Content-Transfer-Encoding: binary'); readfile($readfile); // case 'pdf': // $this->redirect($url . 'pdf.png'); // break; // // case 'tar': // case 'tgz': // case 'gz': // case 'bz2': // case 'zip': // $this->redirect( $url . 'zip.png'); // break; // case 'odt': // case 'docx': // case 'doc': // $this->redirect( $url . 'doc.png'); // break; // // case 'odc': // case 'ods': // case 'xls': // case 'xlsx': // $this->redirect( $url . 'spreadsheet.png'); // break; // // case 'odp': // case 'pps': // case 'pptx': // case 'ppt': // $this->redirect( $url . 'pps.png'); // break; // case 'eml': // $this->redirect( $url . 'message.png'); // break; // // case 'htm': // $this->redirect( $url . 'doc.png'); // break; // // case 'log': // $this->redirect( $url . 'txt.png'); // break; // // default: // if (file_exists($dir . $file->extension() . '.png')) { // $this->redirect( $url . $file->extension() . '.png'); // } else { // $this->redirect( $url . 'unknown.png'); // } // break; }