1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OC\Preview; |
24
|
|
|
|
25
|
|
|
use OC\Files\View; |
26
|
|
|
use OCP\Files\File; |
27
|
|
|
use OCP\Files\IRootFolder; |
28
|
|
|
use OCP\Files\SimpleFS\ISimpleFile; |
29
|
|
|
use OCP\IConfig; |
30
|
|
|
use OCP\IImage; |
31
|
|
|
use OCP\Image as OCPImage; |
32
|
|
|
use OCP\Preview\IProvider; |
33
|
|
|
use OCP\Preview\IProviderV2; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Very small wrapper class to make the generator fully unit testable |
37
|
|
|
*/ |
38
|
|
|
class GeneratorHelper { |
39
|
|
|
|
40
|
|
|
/** @var IRootFolder */ |
41
|
|
|
private $rootFolder; |
42
|
|
|
|
43
|
|
|
/** @var IConfig */ |
44
|
|
|
private $config; |
45
|
|
|
|
46
|
|
|
public function __construct(IRootFolder $rootFolder, IConfig $config) { |
47
|
|
|
$this->rootFolder = $rootFolder; |
48
|
|
|
$this->config = $config; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param IProvider $provider |
53
|
|
|
* @param File $file |
54
|
|
|
* @param int $maxWidth |
55
|
|
|
* @param int $maxHeight |
56
|
|
|
* @return bool|IImage |
57
|
|
|
*/ |
58
|
|
|
public function getThumbnail(IProviderV2 $provider, File $file, $maxWidth, $maxHeight) { |
59
|
|
|
return $provider->getThumbnail($file, $maxWidth, $maxHeight); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param ISimpleFile $maxPreview |
64
|
|
|
* @return IImage |
65
|
|
|
*/ |
66
|
|
|
public function getImage(ISimpleFile $maxPreview) { |
67
|
|
|
$image = new OCPImage(); |
68
|
|
|
$image->loadFromData($maxPreview->getContent()); |
69
|
|
|
return $image; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param callable $providerClosure |
74
|
|
|
* @return IProviderV2 |
75
|
|
|
*/ |
76
|
|
|
public function getProvider($providerClosure) { |
77
|
|
|
$provider = $providerClosure(); |
78
|
|
|
if ($provider instanceof IProvider) { |
79
|
|
|
$provider = new ProviderV1Adapter($provider); |
80
|
|
|
} |
81
|
|
|
return $provider; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|