ThumbnailController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filters() 0 3 1
A actionGenerate() 0 13 2
1
<?php
2
3
/**
4
 * Handles thumbnails
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; 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
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
46
	}
47
48
}