Jalle19 /
xbmc-video-server
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Handles thumbnails |
||
| 5 | * |
||
| 6 | * @author Sam Stenvall <[email protected]> |
||
| 7 | * @copyright Copyright © Sam Stenvall 2013- |
||
| 8 | * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
||
| 9 | */ |
||
| 10 | class ThumbnailController extends Controller |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Disable all default filters (including authentication) since the generate action |
||
| 15 | * may be called from e.g. a media player which naturally isn't |
||
| 16 | * authenticated |
||
| 17 | * @return array the filters for this controller |
||
| 18 | */ |
||
| 19 | public function filters() |
||
| 20 | { |
||
| 21 | return array('releaseSessionLock'); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Generates a thumbnail for the specified image path and size, then serves |
||
| 26 | * it to the browser. The next time the same thumbnail is rendered its URL |
||
| 27 | * will point to the generated image instead of this action. |
||
| 28 | * @see Thumbnail |
||
| 29 | * @param string $path the thumbnail path |
||
| 30 | * @param int $size the thumbnail size |
||
| 31 | * @throws PageNotFoundException if the image could not be generated |
||
| 32 | */ |
||
| 33 | public function actionGenerate($path, $size) |
||
| 34 | { |
||
| 35 | $thumbnail = new Thumbnail($path, $size); |
||
| 36 | $thumbnail->generate(); |
||
| 37 | |||
| 38 | $path = $thumbnail->getPath(); |
||
| 39 | |||
| 40 | if ($path === false) |
||
| 41 | throw new PageNotFoundException(); |
||
| 42 | |||
| 43 | header('Content-Type: '.CFileHelper::getMimeType($path)); |
||
| 44 | readfile($path); |
||
| 45 | exit; |
||
|
0 ignored issues
–
show
|
|||
| 46 | } |
||
| 47 | |||
| 48 | } |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.