@@ -54,50 +54,50 @@ |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | switch ($type) { |
| 57 | - case 'jpg': |
|
| 58 | - header('Content-Type: image/jpeg'); |
|
| 59 | - //by default, we don't cache |
|
| 60 | - $thumbnailCacheFullpath = null; |
|
| 61 | - if (isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '') { |
|
| 62 | - $thumbnailCacheFullpath = $config['cops_thumbnail_cache_directory']; |
|
| 63 | - //if multiple databases, add a subfolder with the database ID |
|
| 64 | - $thumbnailCacheFullpath .= !is_null(GetUrlParam(DB)) ? 'db-' . GetUrlParam(DB) . DIRECTORY_SEPARATOR : ''; |
|
| 65 | - //when there are lots of thumbnails, it's better to save files in subfolders, so if the book's uuid is |
|
| 66 | - //"01234567-89ab-cdef-0123-456789abcdef", we will save the thumbnail in .../0/12/34567-89ab-cdef-0123-456789abcdef-... |
|
| 67 | - $thumbnailCacheFullpath .= substr($book->uuid, 0, 1) . DIRECTORY_SEPARATOR . substr($book->uuid, 1, 2) . DIRECTORY_SEPARATOR; |
|
| 68 | - //check if cache folder exists or create it |
|
| 69 | - if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) { |
|
| 70 | - //we name the thumbnail from the book's uuid and it's dimensions (width and/or height) |
|
| 71 | - $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam('width') . 'x' . getURLParam('height') . '.jpg'; |
|
| 72 | - $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName; |
|
| 73 | - } else { |
|
| 74 | - //error creating the folder, so we don't cache |
|
| 75 | - $thumbnailCacheFullpath = null; |
|
| 57 | + case 'jpg': |
|
| 58 | + header('Content-Type: image/jpeg'); |
|
| 59 | + //by default, we don't cache |
|
| 60 | + $thumbnailCacheFullpath = null; |
|
| 61 | + if (isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '') { |
|
| 62 | + $thumbnailCacheFullpath = $config['cops_thumbnail_cache_directory']; |
|
| 63 | + //if multiple databases, add a subfolder with the database ID |
|
| 64 | + $thumbnailCacheFullpath .= !is_null(GetUrlParam(DB)) ? 'db-' . GetUrlParam(DB) . DIRECTORY_SEPARATOR : ''; |
|
| 65 | + //when there are lots of thumbnails, it's better to save files in subfolders, so if the book's uuid is |
|
| 66 | + //"01234567-89ab-cdef-0123-456789abcdef", we will save the thumbnail in .../0/12/34567-89ab-cdef-0123-456789abcdef-... |
|
| 67 | + $thumbnailCacheFullpath .= substr($book->uuid, 0, 1) . DIRECTORY_SEPARATOR . substr($book->uuid, 1, 2) . DIRECTORY_SEPARATOR; |
|
| 68 | + //check if cache folder exists or create it |
|
| 69 | + if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) { |
|
| 70 | + //we name the thumbnail from the book's uuid and it's dimensions (width and/or height) |
|
| 71 | + $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam('width') . 'x' . getURLParam('height') . '.jpg'; |
|
| 72 | + $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName; |
|
| 73 | + } else { |
|
| 74 | + //error creating the folder, so we don't cache |
|
| 75 | + $thumbnailCacheFullpath = null; |
|
| 76 | + } |
|
| 76 | 77 | } |
| 77 | - } |
|
| 78 | 78 | |
| 79 | - if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) { |
|
| 80 | - //return the already cached thumbnail |
|
| 81 | - readfile($thumbnailCacheFullpath); |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ($book->getThumbnail(getURLParam('width'), getURLParam('height'), $thumbnailCacheFullpath)) { |
|
| 86 | - //if we don't cache the thumbnail, imagejpeg() in $book->getThumbnail() already return the image data |
|
| 87 | - if ($thumbnailCacheFullpath === null) { |
|
| 88 | - // The cover had to be resized |
|
| 89 | - return; |
|
| 90 | - } else { |
|
| 91 | - //return the just cached thumbnail |
|
| 79 | + if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) { |
|
| 80 | + //return the already cached thumbnail |
|
| 92 | 81 | readfile($thumbnailCacheFullpath); |
| 93 | 82 | return; |
| 94 | 83 | } |
| 95 | - } |
|
| 96 | - break; |
|
| 97 | - default: |
|
| 98 | - $data = $book->getDataById($idData); |
|
| 99 | - header('Content-Type: ' . $data->getMimeType()); |
|
| 100 | - break; |
|
| 84 | + |
|
| 85 | + if ($book->getThumbnail(getURLParam('width'), getURLParam('height'), $thumbnailCacheFullpath)) { |
|
| 86 | + //if we don't cache the thumbnail, imagejpeg() in $book->getThumbnail() already return the image data |
|
| 87 | + if ($thumbnailCacheFullpath === null) { |
|
| 88 | + // The cover had to be resized |
|
| 89 | + return; |
|
| 90 | + } else { |
|
| 91 | + //return the just cached thumbnail |
|
| 92 | + readfile($thumbnailCacheFullpath); |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + break; |
|
| 97 | + default: |
|
| 98 | + $data = $book->getDataById($idData); |
|
| 99 | + header('Content-Type: ' . $data->getMimeType()); |
|
| 100 | + break; |
|
| 101 | 101 | } |
| 102 | 102 | $file = $book->getFilePath($type, $idData, true); |
| 103 | 103 | if (!$viewOnly && $type == 'epub' && $config['cops_update_epub-metadata']) { |