diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-07-19 13:57:55 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-09-04 16:17:33 +0300 |
commit | 7abe2f88f030192abf3cb93e1d329c5e81eb4e8a (patch) | |
tree | 817ddc7cc6118c382a04fb69b5e62f819780dedf /lib | |
parent | 34923a97e7049d229a0fe8de4b26a3f5339f79d6 (diff) |
Add preview provider for ODF that uses Collabora Online's web API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 32 | ||||
-rw-r--r-- | lib/Preview/MSExcel.php | 31 | ||||
-rw-r--r-- | lib/Preview/MSWord.php | 31 | ||||
-rw-r--r-- | lib/Preview/OOXML.php | 31 | ||||
-rw-r--r-- | lib/Preview/Office.php | 71 | ||||
-rw-r--r-- | lib/Preview/OpenDocument.php | 32 |
6 files changed, 227 insertions, 1 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d85d6997..83ba668d 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -23,9 +23,13 @@ namespace OCA\Richdocuments\AppInfo; use OC\AppFramework\Utility\TimeFactory; use OCA\Richdocuments\Capabilities; -use OCA\Richdocuments\WOPI\DiscoveryManager; +use OCA\Richdocuments\Preview\MSExcel; +use OCA\Richdocuments\Preview\MSWord; +use OCA\Richdocuments\Preview\OOXML; +use OCA\Richdocuments\Preview\OpenDocument; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; +use OCP\IPreview; class Application extends App { @@ -36,4 +40,30 @@ class Application extends App { $this->getContainer()->registerCapability(Capabilities::class); } + + public function registerProvider() { + $container = $this->getContainer(); + + /** @var IPreview $previewManager */ + $previewManager = $container->query(IPreview::class); + + $previewManager->registerProvider('/application\/vnd.ms-excel/', function() use ($container) { + return $container->query(MSExcel::class); + }); + + $previewManager->registerProvider('/application\/msword/', function() use ($container) { + return $container->query(MSWord::class); + }); + + $previewManager->registerProvider('/application\/vnd.openxmlformats-officedocument.*/', function() use ($container) { + return $container->query(OOXML::class); + }); + + // \OC::$server->getLogger()->debug('==== Richdocuments Application registerProvider: calling manager registerProvider:'); + $previewManager->registerProvider('/application\/vnd.oasis.opendocument.*/', function() use ($container) { + // \OC::$server->getLogger()->debug('==== Richdocuments Application registerProvider lambda. OpenDocument::class=' . OpenDocument::class); + return $container->query(OpenDocument::class); + }); + + } } diff --git a/lib/Preview/MSExcel.php b/lib/Preview/MSExcel.php new file mode 100644 index 00000000..1d0a0801 --- /dev/null +++ b/lib/Preview/MSExcel.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2018, Collabora Productivity. + * + * @author Tor Lillqvist <tml@collabora.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\Richdocuments\Preview; + +class MSExcel extends Office { + /** + * {@inheritDoc} + */ + public function getMimeType() { + return '/application\/vnd.ms-excel/'; + } +} diff --git a/lib/Preview/MSWord.php b/lib/Preview/MSWord.php new file mode 100644 index 00000000..f56ee18b --- /dev/null +++ b/lib/Preview/MSWord.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2018, Collabora Productivity. + * + * @author Tor Lillqvist <tml@collabora.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\Richdocuments\Preview; + +class MSWord extends Office { + /** + * {@inheritDoc} + */ + public function getMimeType() { + return '/application\/msword/'; + } +} diff --git a/lib/Preview/OOXML.php b/lib/Preview/OOXML.php new file mode 100644 index 00000000..3052c3f8 --- /dev/null +++ b/lib/Preview/OOXML.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2018, Collabora Productivity. + * + * @author Tor Lillqvist <tml@collabora.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\Richdocuments\Preview; + +class OOXML extends Office { + /** + * {@inheritDoc} + */ + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.*/'; + } +} diff --git a/lib/Preview/Office.php b/lib/Preview/Office.php new file mode 100644 index 00000000..a99ad8ef --- /dev/null +++ b/lib/Preview/Office.php @@ -0,0 +1,71 @@ +<?php +/** + * @copyright Copyright (c) 2018, Collabora Productivity. + * + * @author Tor Lillqvist <tml@collabora.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\Richdocuments\Preview; + +use OC\Preview\Provider; +use \GuzzleHttp\Client; +use \GuzzleHttp\Post\PostFile; + +abstract class Office extends Provider { + /** + * {@inheritDoc} + */ + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + // \OC::$server->getLogger()->debug('==== getThumbnail: ' . $path); + $data = $fileview->file_get_contents($path); + + $client = new Client(['base_uri' => 'http://localhost:9980/', 'timeout' => 2.0]); + + $request = $client->createRequest('POST', 'http://localhost:9980/lool/convert-to/png', + [ + 'body' => + [ + new PostFile($path, $data) + ] + + ]); + $response = $client->send($request); +/* + $headers = $response->getHeaders(); + + foreach ($headers as $key => $value) { + $concatvalue = ''; + foreach ($value as $vvalue) { + $concatvalue = $concatvalue . $vvalue; + } + // \OC::$server->getLogger()->debug('==== response: ' . $key . ': ' . $concatvalue); + } + + \OC::$server->getLogger()->debug('==== response body type: ' . gettype($response->getBody())); +*/ + $image = new \OC_Image(); + $image->loadFromData($response->getBody()); + + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); + return $image; + } + return false; + + } + +} diff --git a/lib/Preview/OpenDocument.php b/lib/Preview/OpenDocument.php new file mode 100644 index 00000000..fc7dab45 --- /dev/null +++ b/lib/Preview/OpenDocument.php @@ -0,0 +1,32 @@ +<?php +/** + * @copyright Copyright (c) 2018, Collabora Productivity. + * + * @author Tor Lillqvist <tml@collabora.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\Richdocuments\Preview; + +//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt +class OpenDocument extends Office { + /** + * {@inheritDoc} + */ + public function getMimeType() { + return '/application\/vnd.oasis.opendocument.*/'; + } +} |