Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2021-04-08 08:53:31 +0300
committerJulius Härtl <jus@bitgrid.net>2021-11-08 15:32:35 +0300
commitc3e331f658f71f880ee379ea97302d969bf645b6 (patch)
treebbe1b2afd3049f86f6315763647598de565db22e /lib
parent69ade4da1c08e37ab60267220b3f8cf200a39d54 (diff)
Add support for Collabora Online Draw and odg files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php25
-rw-r--r--lib/Capabilities.php10
-rw-r--r--lib/Service/CapabilitiesService.php15
-rw-r--r--lib/Template/CollaboraTemplateProvider.php6
-rw-r--r--lib/TemplateManager.php30
5 files changed, 51 insertions, 35 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 5701d50e..721e8031 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -84,7 +84,10 @@ class Application extends App implements IBootstrap {
\OCP\Util::addScript('richdocuments', 'richdocuments-viewer');
});
- $context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config) {
+ $context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) {
+ if (empty($capabilitiesService->getCapabilities())) {
+ return;
+ }
$ooxml = $config->getAppValue(self::APPNAME, 'doc_format', '') === 'ooxml';
$templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
$odtType = new TemplateFileCreator('richdocuments', $l10n->t('New document'), ($ooxml ? '.docx' : '.odt'));
@@ -125,6 +128,18 @@ class Application extends App implements IBootstrap {
$odpType->setRatio(16/9);
return $odpType;
});
+
+ if (!$capabilitiesService->hasDrawSupport()) {
+ return;
+ }
+ $templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
+ $odpType = new TemplateFileCreator('richdocuments', $l10n->t('New graphic'), '.odg');
+ $odpType->addMimetype('application/vnd.oasis.opendocument.graphics');
+ $odpType->addMimetype('application/vnd.oasis.opendocument.graphics-template');
+ $odpType->setIconClass('icon-filetype-draw');
+ $odpType->setRatio(16/9);
+ return $odpType;
+ });
});
$context->injectFn(function (SymfonyAdapter $eventDispatcher) {
@@ -159,14 +174,6 @@ class Application extends App implements IBootstrap {
public function registerProvider() {
$container = $this->getContainer();
- // Register mimetypes
- /** @var Detection $detector */
- $detector = $container->query(\OCP\Files\IMimeTypeDetector::class);
- $detector->getAllMappings();
- $detector->registerType('ott','application/vnd.oasis.opendocument.text-template');
- $detector->registerType('ots', 'application/vnd.oasis.opendocument.spreadsheet-template');
- $detector->registerType('otp', 'application/vnd.oasis.opendocument.presentation-template');
-
/** @var IPreview $previewManager */
$previewManager = $container->query(IPreview::class);
diff --git a/lib/Capabilities.php b/lib/Capabilities.php
index c4c345b3..0e58d48f 100644
--- a/lib/Capabilities.php
+++ b/lib/Capabilities.php
@@ -93,10 +93,18 @@ class Capabilities implements ICapability {
public function getCapabilities() {
if (!$this->capabilities) {
$collaboraCapabilities = $this->capabilitiesService->getCapabilities();
+ $filteredMimetypes = self::MIMETYPES;
+ // If version is too old, draw is not supported
+ if (!$this->capabilitiesService->hasDrawSupport()) {
+ $filteredMimetypes = array_diff($filteredMimetypes, [
+ 'application/vnd.oasis.opendocument.graphics',
+ 'application/vnd.oasis.opendocument.graphics-flat-xml',
+ ]);
+ }
$this->capabilities = [
'richdocuments' => [
'version' => \OC::$server->getAppManager()->getAppVersion('richdocuments'),
- 'mimetypes' => self::MIMETYPES,
+ 'mimetypes' => $filteredMimetypes,
'mimetypesNoDefaultOpen' => self::MIMETYPES_OPTIONAL,
'collabora' => $collaboraCapabilities,
'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) ?: false,
diff --git a/lib/Service/CapabilitiesService.php b/lib/Service/CapabilitiesService.php
index 58115795..3d18c957 100644
--- a/lib/Service/CapabilitiesService.php
+++ b/lib/Service/CapabilitiesService.php
@@ -72,22 +72,27 @@ class CapabilitiesService {
return $this->capabilities;
}
- public function hasTemplateSaveAs() {
+ public function hasDrawSupport(): bool {
+ $productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0';
+ return version_compare($productVersion, '6.4.7', '>=');
+ }
+
+ public function hasTemplateSaveAs(): bool {
return $this->getCapabilities()['hasTemplateSaveAs'] ?? false;
}
- public function hasTemplateSource() {
+ public function hasTemplateSource(): bool {
return $this->getCapabilities()['hasTemplateSource'] ?? false;
}
- public function clear() {
+ public function clear(): void {
$this->cache->remove('capabilities');
}
- public function refetch() {
+ public function refetch(): void {
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
if ($remoteHost === '') {
- return [];
+ return;
}
$capabilitiesEndpoint = rtrim($remoteHost, '/') . '/hosting/capabilities';
diff --git a/lib/Template/CollaboraTemplateProvider.php b/lib/Template/CollaboraTemplateProvider.php
index 669f54d6..4246f98b 100644
--- a/lib/Template/CollaboraTemplateProvider.php
+++ b/lib/Template/CollaboraTemplateProvider.php
@@ -53,10 +53,12 @@ class CollaboraTemplateProvider implements ICustomTemplateProvider {
public function getCustomTemplates(string $mimetype): array {
if (in_array($mimetype, TemplateManager::MIMES_DOCUMENTS)) {
$type = 'document';
- } else if (in_array($mimetype, TemplateManager::MIMES_SHEETS)) {
+ } elseif (in_array($mimetype, TemplateManager::MIMES_SHEETS)) {
$type = 'spreadsheet';
- } else if (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) {
+ } elseif (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) {
$type = 'presentation';
+ } elseif (in_array($mimetype, TemplateManager::MIMES_DRAWINGS)) {
+ $type = 'drawing';
} else {
return [];
}
diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php
index b54848ff..d8a01932 100644
--- a/lib/TemplateManager.php
+++ b/lib/TemplateManager.php
@@ -72,37 +72,30 @@ class TemplateManager {
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.ms-powerpoint'
];
+ const MIMES_DRAWINGS = [
+ 'application/vnd.oasis.opendocument.graphics-template',
+ ];
/** @var array Template mime types match */
static public $tplTypes = [
'document' => self::MIMES_DOCUMENTS,
'spreadsheet' => self::MIMES_SHEETS,
- 'presentation' => self::MIMES_PRESENTATIONS
+ 'presentation' => self::MIMES_PRESENTATIONS,
+ 'drawing' => self::MIMES_DRAWINGS,
];
const TYPE_EXTENTION = [
'document' => 'odt',
'spreadsheet' => 'ods',
- 'presentation' => 'odp'
+ 'presentation' => 'odp',
+ 'drawing' => 'odg',
];
const TYPE_EXTENSION_OOXML = [
'document' => 'docx',
'spreadsheet' => 'xlsx',
- 'presentation' => 'pptx'
- ];
-
- const EMPTY_TEMPLATE_ID_TYPE = [
- -1 => 'document',
- -2 => 'spreadsheet',
- -3 => 'presentation',
+ 'presentation' => 'pptx',
];
- const EMPTY_TEMPLATE_TYPE_ID = [
- 'document' => -1,
- 'spreadsheet' => -2,
- 'presentation' => -3,
- ];
-
/**
* Template manager
@@ -218,6 +211,7 @@ class TemplateManager {
'document.ott',
'spreadsheet.ots',
'presentation.otp',
+ 'drawing.otg',
];
foreach ($templates as $template) {
@@ -451,7 +445,7 @@ class TemplateManager {
'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]),
'type' => $this->flipTypes()[$template->getMimeType()],
'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]),
- 'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
+ 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
];
}
@@ -478,13 +472,13 @@ class TemplateManager {
'id' => $template->getId(),
'name' => $this->l->t('Empty'),
'type' => $this->flipTypes()[$template->getMimeType()],
- 'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
+ 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
];
}
public function isValidTemplateMime($mime, $type = null) {
if ($type === null) {
- $allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']);
+ $allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation'], self::$tplTypes['drawing']);
if (!in_array($mime, $allMimes)) {
return false;
}