1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018, Collabora Productivity. |
4
|
|
|
* |
5
|
|
|
* @author Tor Lillqvist <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
namespace OCA\Richdocuments\Preview; |
23
|
|
|
|
24
|
|
|
use OC\Preview\Provider; |
25
|
|
|
use OCA\Richdocuments\Capabilities; |
26
|
|
|
use OCP\Http\Client\IClientService; |
27
|
|
|
use OCP\IConfig; |
28
|
|
|
|
29
|
|
|
abstract class Office extends Provider { |
30
|
|
|
|
31
|
|
|
/** @var IClientService */ |
32
|
|
|
private $clientService; |
33
|
|
|
|
34
|
|
|
/** @var IConfig */ |
35
|
|
|
private $config; |
36
|
|
|
|
37
|
|
|
/** @var array */ |
38
|
|
|
private $capabilitites; |
39
|
|
|
|
40
|
|
|
public function __construct(IClientService $clientService, IConfig $config, Capabilities $capabilities) { |
41
|
|
|
$this->clientService = $clientService; |
42
|
|
|
$this->config = $config; |
43
|
|
|
$this->capabilitites = $capabilities->getCapabilities()['richdocuments']; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function getWopiURL() { |
47
|
|
|
return $this->config->getAppValue('richdocuments', 'wopi_url'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isAvailable(\OCP\Files\FileInfo $file) { |
51
|
|
|
if (isset($this->capabilitites['collabora']['convert-to'])) { |
52
|
|
|
return $this->capabilitites['collabora']['convert-to']; |
53
|
|
|
} |
54
|
|
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
|
|
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
61
|
|
|
$stream = $fileview->fopen($path, 'r'); |
62
|
|
|
|
63
|
|
|
$client = $this->clientService->newClient(); |
64
|
|
|
$options = ['timeout' => 10]; |
65
|
|
|
|
66
|
|
|
if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') { |
67
|
|
|
$options['verify'] = false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (version_compare($this->config->getSystemValue('version'), '14.0.0.0', '<')) { |
71
|
|
|
$options['body'] = new \GuzzleHttp\Post\PostFile($path, $stream); // Since we upgraded guzzle in NC14 we have to do some dark magic here |
72
|
|
|
} else { |
73
|
|
|
$options['multipart'] = [['name' => $path, 'contents' => $stream]]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
try { |
77
|
|
|
$response = $client->post($this->getWopiURL(). '/lool/convert-to/png', $options); |
78
|
|
|
} catch (\Exception $e) { |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$image = new \OC_Image(); |
83
|
|
|
$image->loadFromData($response->getBody()); |
84
|
|
|
|
85
|
|
|
if ($image->valid()) { |
86
|
|
|
$image->scaleDownToFit($maxX, $maxY); |
87
|
|
|
return $image; |
88
|
|
|
} |
89
|
|
|
return false; |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|