@@ -28,41 +28,41 @@ |
||
28 | 28 | use OCP\Preview\IProvider; |
29 | 29 | |
30 | 30 | abstract class Provider implements IProvider { |
31 | - private $options; |
|
31 | + private $options; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - * |
|
36 | - * @param array $options |
|
37 | - */ |
|
38 | - public function __construct(array $options = []) { |
|
39 | - $this->options = $options; |
|
40 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + * |
|
36 | + * @param array $options |
|
37 | + */ |
|
38 | + public function __construct(array $options = []) { |
|
39 | + $this->options = $options; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return string Regex with the mimetypes that are supported by this provider |
|
44 | - */ |
|
45 | - abstract public function getMimeType(); |
|
42 | + /** |
|
43 | + * @return string Regex with the mimetypes that are supported by this provider |
|
44 | + */ |
|
45 | + abstract public function getMimeType(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Check if a preview can be generated for $path |
|
49 | - * |
|
50 | - * @param \OCP\Files\FileInfo $file |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
54 | - return true; |
|
55 | - } |
|
47 | + /** |
|
48 | + * Check if a preview can be generated for $path |
|
49 | + * |
|
50 | + * @param \OCP\Files\FileInfo $file |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
54 | + return true; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
59 | - * |
|
60 | - * @param string $path Path of file |
|
61 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
62 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
63 | - * @param bool $scalingup Disable/Enable upscaling of previews |
|
64 | - * @param \OC\Files\View $fileview fileview object of user folder |
|
65 | - * @return bool|\OCP\IImage false if no preview was generated |
|
66 | - */ |
|
67 | - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
57 | + /** |
|
58 | + * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
59 | + * |
|
60 | + * @param string $path Path of file |
|
61 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
62 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
63 | + * @param bool $scalingup Disable/Enable upscaling of previews |
|
64 | + * @param \OC\Files\View $fileview fileview object of user folder |
|
65 | + * @return bool|\OCP\IImage false if no preview was generated |
|
66 | + */ |
|
67 | + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
68 | 68 | } |
@@ -23,10 +23,10 @@ |
||
23 | 23 | |
24 | 24 | //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt |
25 | 25 | class OpenDocument extends Office { |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getMimeType() { |
|
30 | - return '/application\/vnd.oasis.opendocument.*/'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getMimeType() { |
|
30 | + return '/application\/vnd.oasis.opendocument.*/'; |
|
31 | + } |
|
32 | 32 | } |
@@ -25,10 +25,10 @@ |
||
25 | 25 | |
26 | 26 | //.psd |
27 | 27 | class Photoshop extends Bitmap { |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getMimeType() { |
|
32 | - return '/application\/x-photoshop/'; |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getMimeType() { |
|
32 | + return '/application\/x-photoshop/'; |
|
33 | + } |
|
34 | 34 | } |
@@ -23,10 +23,10 @@ |
||
23 | 23 | namespace OC\Preview; |
24 | 24 | |
25 | 25 | class PNG extends Image { |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getMimeType() { |
|
30 | - return '/image\/png/'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getMimeType() { |
|
30 | + return '/image\/png/'; |
|
31 | + } |
|
32 | 32 | } |
@@ -29,42 +29,42 @@ |
||
29 | 29 | |
30 | 30 | abstract class Image extends Provider { |
31 | 31 | |
32 | - /** |
|
33 | - * {@inheritDoc} |
|
34 | - */ |
|
35 | - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
36 | - //get fileinfo |
|
37 | - $fileInfo = $fileview->getFileInfo($path); |
|
38 | - if (!$fileInfo) { |
|
39 | - return false; |
|
40 | - } |
|
32 | + /** |
|
33 | + * {@inheritDoc} |
|
34 | + */ |
|
35 | + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
36 | + //get fileinfo |
|
37 | + $fileInfo = $fileview->getFileInfo($path); |
|
38 | + if (!$fileInfo) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | - $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50); |
|
43 | - $size = $fileInfo->getSize(); |
|
42 | + $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50); |
|
43 | + $size = $fileInfo->getSize(); |
|
44 | 44 | |
45 | - if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) { |
|
46 | - return false; |
|
47 | - } |
|
45 | + if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) { |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - $image = new \OC_Image(); |
|
49 | + $image = new \OC_Image(); |
|
50 | 50 | |
51 | - $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal(); |
|
52 | - if ($useTempFile) { |
|
53 | - $fileName = $fileview->toTmpFile($path); |
|
54 | - } else { |
|
55 | - $fileName = $fileview->getLocalFile($path); |
|
56 | - } |
|
57 | - $image->loadFromFile($fileName); |
|
58 | - $image->fixOrientation(); |
|
59 | - if ($useTempFile) { |
|
60 | - unlink($fileName); |
|
61 | - } |
|
62 | - if ($image->valid()) { |
|
63 | - $image->scaleDownToFit($maxX, $maxY); |
|
51 | + $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal(); |
|
52 | + if ($useTempFile) { |
|
53 | + $fileName = $fileview->toTmpFile($path); |
|
54 | + } else { |
|
55 | + $fileName = $fileview->getLocalFile($path); |
|
56 | + } |
|
57 | + $image->loadFromFile($fileName); |
|
58 | + $image->fixOrientation(); |
|
59 | + if ($useTempFile) { |
|
60 | + unlink($fileName); |
|
61 | + } |
|
62 | + if ($image->valid()) { |
|
63 | + $image->scaleDownToFit($maxX, $maxY); |
|
64 | 64 | |
65 | - return $image; |
|
66 | - } |
|
67 | - return false; |
|
68 | - } |
|
65 | + return $image; |
|
66 | + } |
|
67 | + return false; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -25,10 +25,10 @@ |
||
25 | 25 | |
26 | 26 | //.tiff |
27 | 27 | class TIFF extends Bitmap { |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getMimeType() { |
|
32 | - return '/image\/tiff/'; |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getMimeType() { |
|
32 | + return '/image\/tiff/'; |
|
33 | + } |
|
34 | 34 | } |
@@ -23,10 +23,10 @@ |
||
23 | 23 | |
24 | 24 | //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx |
25 | 25 | class MSOffice2007 extends Office { |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getMimeType() { |
|
30 | - return '/application\/vnd.openxmlformats-officedocument.*/'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getMimeType() { |
|
30 | + return '/application\/vnd.openxmlformats-officedocument.*/'; |
|
31 | + } |
|
32 | 32 | } |
@@ -26,89 +26,89 @@ |
||
26 | 26 | namespace OC\Preview; |
27 | 27 | |
28 | 28 | class Movie extends Provider { |
29 | - public static $avconvBinary; |
|
30 | - public static $ffmpegBinary; |
|
29 | + public static $avconvBinary; |
|
30 | + public static $ffmpegBinary; |
|
31 | 31 | |
32 | - /** |
|
33 | - * {@inheritDoc} |
|
34 | - */ |
|
35 | - public function getMimeType() { |
|
36 | - return '/video\/.*/'; |
|
37 | - } |
|
32 | + /** |
|
33 | + * {@inheritDoc} |
|
34 | + */ |
|
35 | + public function getMimeType() { |
|
36 | + return '/video\/.*/'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - */ |
|
42 | - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
43 | - // TODO: use proc_open() and stream the source file ? |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + */ |
|
42 | + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
43 | + // TODO: use proc_open() and stream the source file ? |
|
44 | 44 | |
45 | - $fileInfo = $fileview->getFileInfo($path); |
|
46 | - $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted()); |
|
45 | + $fileInfo = $fileview->getFileInfo($path); |
|
46 | + $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted()); |
|
47 | 47 | |
48 | - if ($useFileDirectly) { |
|
49 | - $absPath = $fileview->getLocalFile($path); |
|
50 | - } else { |
|
51 | - $absPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
48 | + if ($useFileDirectly) { |
|
49 | + $absPath = $fileview->getLocalFile($path); |
|
50 | + } else { |
|
51 | + $absPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
52 | 52 | |
53 | - $handle = $fileview->fopen($path, 'rb'); |
|
53 | + $handle = $fileview->fopen($path, 'rb'); |
|
54 | 54 | |
55 | - // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB. |
|
56 | - // in some cases 1MB was no enough to generate thumbnail |
|
57 | - $firstmb = stream_get_contents($handle, 5242880); |
|
58 | - file_put_contents($absPath, $firstmb); |
|
59 | - } |
|
55 | + // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB. |
|
56 | + // in some cases 1MB was no enough to generate thumbnail |
|
57 | + $firstmb = stream_get_contents($handle, 5242880); |
|
58 | + file_put_contents($absPath, $firstmb); |
|
59 | + } |
|
60 | 60 | |
61 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); |
|
62 | - if ($result === false) { |
|
63 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); |
|
64 | - if ($result === false) { |
|
65 | - $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); |
|
66 | - } |
|
67 | - } |
|
61 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5); |
|
62 | + if ($result === false) { |
|
63 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1); |
|
64 | + if ($result === false) { |
|
65 | + $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - if (!$useFileDirectly) { |
|
70 | - unlink($absPath); |
|
71 | - } |
|
69 | + if (!$useFileDirectly) { |
|
70 | + unlink($absPath); |
|
71 | + } |
|
72 | 72 | |
73 | - return $result; |
|
74 | - } |
|
73 | + return $result; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param int $maxX |
|
78 | - * @param int $maxY |
|
79 | - * @param string $absPath |
|
80 | - * @param int $second |
|
81 | - * @return bool|\OCP\IImage |
|
82 | - */ |
|
83 | - private function generateThumbNail($maxX, $maxY, $absPath, $second) { |
|
84 | - $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
76 | + /** |
|
77 | + * @param int $maxX |
|
78 | + * @param int $maxY |
|
79 | + * @param string $absPath |
|
80 | + * @param int $second |
|
81 | + * @return bool|\OCP\IImage |
|
82 | + */ |
|
83 | + private function generateThumbNail($maxX, $maxY, $absPath, $second) { |
|
84 | + $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); |
|
85 | 85 | |
86 | - if (self::$avconvBinary) { |
|
87 | - $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) . |
|
88 | - ' -i ' . escapeshellarg($absPath) . |
|
89 | - ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . |
|
90 | - ' > /dev/null 2>&1'; |
|
91 | - } else { |
|
92 | - $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . |
|
93 | - ' -i ' . escapeshellarg($absPath) . |
|
94 | - ' -f mjpeg -vframes 1' . |
|
95 | - ' ' . escapeshellarg($tmpPath) . |
|
96 | - ' > /dev/null 2>&1'; |
|
97 | - } |
|
86 | + if (self::$avconvBinary) { |
|
87 | + $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) . |
|
88 | + ' -i ' . escapeshellarg($absPath) . |
|
89 | + ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . |
|
90 | + ' > /dev/null 2>&1'; |
|
91 | + } else { |
|
92 | + $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . |
|
93 | + ' -i ' . escapeshellarg($absPath) . |
|
94 | + ' -f mjpeg -vframes 1' . |
|
95 | + ' ' . escapeshellarg($tmpPath) . |
|
96 | + ' > /dev/null 2>&1'; |
|
97 | + } |
|
98 | 98 | |
99 | - exec($cmd, $output, $returnCode); |
|
99 | + exec($cmd, $output, $returnCode); |
|
100 | 100 | |
101 | - if ($returnCode === 0) { |
|
102 | - $image = new \OC_Image(); |
|
103 | - $image->loadFromFile($tmpPath); |
|
104 | - unlink($tmpPath); |
|
105 | - if ($image->valid()) { |
|
106 | - $image->scaleDownToFit($maxX, $maxY); |
|
101 | + if ($returnCode === 0) { |
|
102 | + $image = new \OC_Image(); |
|
103 | + $image->loadFromFile($tmpPath); |
|
104 | + unlink($tmpPath); |
|
105 | + if ($image->valid()) { |
|
106 | + $image->scaleDownToFit($maxX, $maxY); |
|
107 | 107 | |
108 | - return $image; |
|
109 | - } |
|
110 | - } |
|
111 | - unlink($tmpPath); |
|
112 | - return false; |
|
113 | - } |
|
108 | + return $image; |
|
109 | + } |
|
110 | + } |
|
111 | + unlink($tmpPath); |
|
112 | + return false; |
|
113 | + } |
|
114 | 114 | } |
@@ -84,15 +84,15 @@ |
||
84 | 84 | $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); |
85 | 85 | |
86 | 86 | if (self::$avconvBinary) { |
87 | - $cmd = self::$avconvBinary . ' -y -ss ' . escapeshellarg($second) . |
|
88 | - ' -i ' . escapeshellarg($absPath) . |
|
89 | - ' -an -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . |
|
87 | + $cmd = self::$avconvBinary.' -y -ss '.escapeshellarg($second). |
|
88 | + ' -i '.escapeshellarg($absPath). |
|
89 | + ' -an -f mjpeg -vframes 1 -vsync 1 '.escapeshellarg($tmpPath). |
|
90 | 90 | ' > /dev/null 2>&1'; |
91 | 91 | } else { |
92 | - $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . |
|
93 | - ' -i ' . escapeshellarg($absPath) . |
|
94 | - ' -f mjpeg -vframes 1' . |
|
95 | - ' ' . escapeshellarg($tmpPath) . |
|
92 | + $cmd = self::$ffmpegBinary.' -y -ss '.escapeshellarg($second). |
|
93 | + ' -i '.escapeshellarg($absPath). |
|
94 | + ' -f mjpeg -vframes 1'. |
|
95 | + ' '.escapeshellarg($tmpPath). |
|
96 | 96 | ' > /dev/null 2>&1'; |
97 | 97 | } |
98 | 98 |
@@ -25,10 +25,10 @@ |
||
25 | 25 | |
26 | 26 | //.ai |
27 | 27 | class Illustrator extends Bitmap { |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getMimeType() { |
|
32 | - return '/application\/illustrator/'; |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getMimeType() { |
|
32 | + return '/application\/illustrator/'; |
|
33 | + } |
|
34 | 34 | } |