diff --git a/appinfo/app.php b/appinfo/app.php
index 596a8f0bd..2c9cf7cbd 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -66,3 +66,6 @@ if ($wopiUrl !== '') {
$policy->addAllowedFrameDomain($wopiUrl);
$manager->addDefaultPolicy($policy);
}
+
+$app = new Application();
+$app->registerProvider();
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 138dd1bb1..36dc5c30b 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -9,6 +9,8 @@
Collabora Productivity based on work of Frank Karlitschek, Victor Dubiniuk
+
+
https://nextcloud.com/collaboraonline/
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index d85d69976..83ba668dc 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 000000000..1d0a08019
--- /dev/null
+++ b/lib/Preview/MSExcel.php
@@ -0,0 +1,31 @@
+
+ *
+ * @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
+ *
+ */
+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 000000000..f56ee18b4
--- /dev/null
+++ b/lib/Preview/MSWord.php
@@ -0,0 +1,31 @@
+
+ *
+ * @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
+ *
+ */
+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 000000000..3052c3f82
--- /dev/null
+++ b/lib/Preview/OOXML.php
@@ -0,0 +1,31 @@
+
+ *
+ * @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
+ *
+ */
+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 000000000..a99ad8ef2
--- /dev/null
+++ b/lib/Preview/Office.php
@@ -0,0 +1,71 @@
+
+ *
+ * @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
+ *
+ */
+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 000000000..fc7dab453
--- /dev/null
+++ b/lib/Preview/OpenDocument.php
@@ -0,0 +1,32 @@
+
+ *
+ * @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
+ *
+ */
+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.*/';
+ }
+}