Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/document formats submodule #456

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
rm -rf ./.git/
rm ./.gitmodules
rm -rf ./assets/document-templates/.git
rm -rf ./assets/document-formats/.git
cd ./appinfo
sed -i 's|<licence>apl2|<licence>agpl|' info.xml
cd $cwd
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/new
[submodule "assets/document-formats"]
path = assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- compatible with ownCloud Web 7.0
- list of users to protect ranges of cells
- offline viewer for share link
- updatable list of supported formats

## Added
- reference data from coediting
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ The app allows to:

Supported formats:

* For viewing and editing: DOCX, XLSX, PPTX, CSV, TXT, DOCXF, OFORM.
* For viewing only: PDF.
* For converting to Office Open XML formats: DOC, DOCM, DOT, DOTX, EPUB, HTM, HTML, ODP, ODT, POT, POTM, POTX, PPS, PPSM, PPSX, PPT, PPTM, RTF, XLS, XLSM, XLT, XLTM, XLTX.
* For editing: DOCM, DOCX, DOCXF, DOTM, DOTX, EPUB, FB2, HTML, ODT, OTT, RTF, TXT, CSV, ODS, OTS, XLSM, XLSX, XLTM, XLTX, ODP, OTP, POTM, POTX, PPSM, PPSX, PPTM, PPTX.
* For viewing only: DJVU, DOC, DOT, FODT, HTM, MHT, MHTML, OFORM, PDF, STW, SXW, WPS, WPT, XML, XPS, ET, ETT, FODS, SXC, XLS, XLSB, XLT, DPS, DPT, FODP, POT, PPS, PPT, SXI.

ODT, ODS, and ODP is also available for instant conversion. After you enable the corresponding option in the admin settings, ODF-formatted documents are immediately converted in the editor and opened after you click on it.

Expand Down Expand Up @@ -234,12 +233,12 @@ The table below will help you to make the right choice.
| Conversion Service | + | + |
| Document Builder Service | + | + |
| **Interface** | **Community Edition** | **Enterprise Edition** |
| Tabbed interface | + | + |
| Dark theme | + | + |
| 125%, 150%, 175%, 200% scaling | + | + |
| White Label | - | - |
| Integrated test example (node.js) | + | + |
| Mobile web editors | - | +* |
| Tabbed interface | + | + |
| Dark theme | + | + |
| 125%, 150%, 175%, 200% scaling | + | + |
| White Label | - | - |
| Integrated test example (node.js) | + | + |
| Mobile web editors | - | +* |
| **Plugins & Macros** | **Community Edition** | **Enterprise Edition** |
| Plugins | + | + |
| Macros | + | + |
Expand Down
1 change: 1 addition & 0 deletions assets/document-formats
Submodule document-formats added at 730e13
111 changes: 51 additions & 60 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,74 +330,65 @@
return true;
}

OCA.Files.fileActions.registerAction({
name: "onlyofficeOpen",
displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"),
mime: config.mime,
permissions: OC.PERMISSION_READ,
iconClass: "icon-onlyoffice-open",
actionHandler: OCA.Onlyoffice.FileClick
});

if (config.def) {
OCA.Files.fileActions.setDefault(config.mime, "onlyofficeOpen");
}

if (config.conv) {
let mimeTypes = config.mime;
mimeTypes.forEach((mime) => {
OCA.Files.fileActions.registerAction({
name: "onlyofficeConvert",
displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"),
mime: config.mime,
permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
iconClass: "icon-onlyoffice-convert",
actionHandler: OCA.Onlyoffice.FileConvertClick
});
}

if (config.fillForms) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeFill",
displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"),
mime: config.mime,
permissions: OC.PERMISSION_UPDATE,
iconClass: "icon-onlyoffice-fill",
name: "onlyofficeOpen",
displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"),
mime: mime,
permissions: OC.PERMISSION_READ,
iconClass: "icon-onlyoffice-open",
actionHandler: OCA.Onlyoffice.FileClick
});
}

if (config.fillForms) {
OCA.Files.fileActions.setDefault(config.mime, "onlyofficeFill");
}
if (config.def) {
OCA.Files.fileActions.setDefault(mime, "onlyofficeOpen");
}

if (config.createForm) {
var permission = OC.PERMISSION_READ;
if ($("#isPublic").val()) {
permission = OC.PERMISSION_UPDATE;
if (parseInt($("#sharePermission").val()) === (OC.PERMISSION_READ | OC.PERMISSION_CREATE)) {
permission = OC.PERMISSION_READ;
}
if (config.conv) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeConvert",
displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"),
mime: mime,
permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
iconClass: "icon-onlyoffice-convert",
actionHandler: OCA.Onlyoffice.FileConvertClick
});
}

OCA.Files.fileActions.registerAction({
name: "onlyofficeCreateForm",
displayName: t(OCA.Onlyoffice.AppName, "Create form"),
mime: config.mime,
permissions: permission,
iconClass: "icon-onlyoffice-create",
actionHandler: OCA.Onlyoffice.CreateFormClick
});
}
if (config.fillForms) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeFill",
displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"),
mime: mime,
permissions: OC.PERMISSION_UPDATE,
iconClass: "icon-onlyoffice-fill",
actionHandler: OCA.Onlyoffice.FileClick
});
}

if (config.saveas && !$("#isPublic").val()) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeDownload",
displayName: t(OCA.Onlyoffice.AppName, "Download as"),
mime: config.mime,
permissions: OC.PERMISSION_READ,
iconClass: "icon-onlyoffice-download",
actionHandler: OCA.Onlyoffice.DownloadClick
});
}
if (config.createForm) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeCreateForm",
displayName: t(OCA.Onlyoffice.AppName, "Create form"),
mime: mime,
permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
iconClass: "icon-onlyoffice-create",
actionHandler: OCA.Onlyoffice.CreateFormClick
});
}

if (config.saveas && !$("#isPublic").val()) {
OCA.Files.fileActions.registerAction({
name: "onlyofficeDownload",
displayName: t(OCA.Onlyoffice.AppName, "Download as"),
mime: mime,
permissions: OC.PERMISSION_READ,
iconClass: "icon-onlyoffice-download",
actionHandler: OCA.Onlyoffice.DownloadClick
});
}
});
});
}

Expand Down
152 changes: 110 additions & 42 deletions lib/appconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use \DateInterval;
use \DateTime;

use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;

Expand Down Expand Up @@ -312,6 +314,13 @@ class AppConfig {
*/
private $_editors_check_interval = "editors_check_interval";

/**
* The config key for store cache
*
* @var ICache
*/
private $cache;

/**
* @param string $AppName - application name
*/
Expand All @@ -320,6 +329,8 @@ public function __construct($AppName) {

$this->config = \OC::$server->getConfig();
$this->logger = \OC::$server->getLogger();
$cacheFactory = \OC::$server->getMemCacheFactory();
$this->cache = $cacheFactory->createLocal($this->appName);
}

/**
Expand Down Expand Up @@ -1232,7 +1243,7 @@ public function checkEncryptionModule() {
* @NoAdminRequired
*/
public function formatsSetting() {
$result = $this->formats;
$result = $this->buildOnlyofficeFormats();

$defFormats = $this->getDefaultFormats();
foreach ($defFormats as $format => $setting) {
Expand Down Expand Up @@ -1280,47 +1291,104 @@ public function getEditorsCheckInterval() {
}

/**
* Additional data about formats
*
* @var array
*/
private $formats = [
"csv" => [ "mime" => "text/csv", "type" => "cell", "edit" => true, "editable" => true, "saveas" => ["ods", "pdf", "xlsx"] ],
"doc" => [ "mime" => "application/msword", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"docm" => [ "mime" => "application/vnd.ms-word.document.macroEnabled.12", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"docx" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "type" => "word", "edit" => true, "def" => true, "review" => true, "comment" => true, "saveas" => ["odt", "pdf", "rtf", "txt"] ],
"docxf" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf", "type" => "word", "edit" => true, "def" => true, "review" => true, "comment" => true, "saveas" => ["odt", "pdf", "rtf", "txt"], "createForm" => true ],
"oform" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform", "type" => "word", "fillForms" => true, "def" => true ],
"dot" => [ "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"dotx" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"epub" => [ "mime" => "application/epub+zip", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"htm" => [ "type" => "word", "conv" => true ],
"html" => [ "mime" => "text/html", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"odp" => [ "mime" => "application/vnd.oasis.opendocument.presentation", "type" => "slide", "conv" => true, "editable" => true, "saveas" => ["pdf", "pptx"] ],
"ods" => [ "mime" => "application/vnd.oasis.opendocument.spreadsheet", "type" => "cell", "conv" => true, "editable" => true, "saveas" => ["csv", "pdf", "xlsx"] ],
"odt" => [ "mime" => "application/vnd.oasis.opendocument.text", "type" => "word", "conv" => true, "editable" => true, "saveas" => ["docx", "pdf", "rtf", "txt"] ],
"otp" => [ "mime" => "application/vnd.oasis.opendocument.presentation-template", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"ots" => [ "mime" => "application/vnd.oasis.opendocument.spreadsheet-template", "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ],
"ott" => [ "mime" => "application/vnd.oasis.opendocument.text-template", "type" => "word", "conv" => true, "saveas" => ["docx", "odt", "pdf", "rtf", "txt"] ],
"pdf" => [ "mime" => "application/pdf", "type" => "word" ],
"pot" => [ "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"potm" => [ "mime" => "application/vnd.ms-powerpoint.template.macroEnabled.12", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"potx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.template", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"pps" => [ "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"ppsm" => [ "mime" => "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"ppsx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"ppt" => [ "mime" => "application/vnd.ms-powerpoint", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"pptm" => [ "mime" => "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "type" => "slide", "conv" => true, "saveas" => ["pdf", "pptx", "odp"] ],
"pptx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", "type" => "slide", "edit" => true, "def" => true, "comment" => true, "saveas" => ["pdf", "odp"] ],
"rtf" => [ "mime" => "text/rtf", "type" => "word", "conv" => true, "editable" => true, "saveas" => ["docx", "odt", "pdf", "txt"] ],
"txt" => [ "mime" => "text/plain", "type" => "word", "edit" => true, "editable" => true, "saveas" => ["docx", "odt", "pdf", "rtf"] ],
"xls" => [ "mime" => "application/vnd.ms-excel", "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ],
"xlsm" => [ "mime" => "application/vnd.ms-excel.sheet.macroEnabled.12", "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ],
"xlsx" => [ "mime" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "type" => "cell", "edit" => true, "def" => true, "comment" => true, "modifyFilter" => true, "saveas" => ["csv", "ods", "pdf"] ],
"xlt" => [ "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ],
"xltm" => [ "mime" => "application/vnd.ms-excel.template.macroEnabled.12", "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ],
"xltx" => [ "mime" => "application/vnd.openxmlformats-officedocument.spreadsheetml.template", "type" => "cell", "conv" => true, "saveas" => ["csv", "ods", "pdf", "xlsx"] ]
];
* Get ONLYOFFICE formats list
*
* @return array
*/
private function buildOnlyofficeFormats() {
try {
$onlyofficeFormats = $this->getFormats();
$result = [];
$additionalFormats = $this->getAdditionalFormatAttributes();

if ($onlyofficeFormats !== false) {
foreach ($onlyofficeFormats as $onlyOfficeFormat) {
if ($onlyOfficeFormat["name"]
&& $onlyOfficeFormat["mime"]
&& $onlyOfficeFormat["type"]
&& $onlyOfficeFormat["actions"]
&& $onlyOfficeFormat["convert"]) {
$result[$onlyOfficeFormat["name"]] = [
"mime" => $onlyOfficeFormat["mime"],
"type" => $onlyOfficeFormat["type"],
"edit" => in_array("edit", $onlyOfficeFormat["actions"]),
"editable" => in_array("lossy-edit", $onlyOfficeFormat["actions"]),
"conv" => in_array("auto-convert", $onlyOfficeFormat["actions"]),
"fillForms" => in_array("fill", $onlyOfficeFormat["actions"]),
"saveas" => $onlyOfficeFormat["convert"],
];
if (isset($additionalFormats[$onlyOfficeFormat["name"]])) {
$result[$onlyOfficeFormat["name"]] = array_merge($result[$onlyOfficeFormat["name"]], $additionalFormats[$onlyOfficeFormat["name"]]);
}
}
}
}
return $result;
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Format matrix error", "app" => $this->appName]);
return [];
}
}

/**
* Get the additional format attributes
*
* @return array
*/
private function getAdditionalFormatAttributes() {
$additionalFormatAttributes = [
"docx" => [
"def" => true,
"review" => true,
"comment" => true,
],
"docxf" => [
"def" => true,
"review" => true,
"comment" => true,
"createForm" => true,
],
"oform" => [
"def" => true,
],
"pdf" => [
"def" => true,
],
"pptx" => [
"def" => true,
"comment" => true,
],
"xlsx" => [
"def" => true,
"comment" => true,
"modifyFilter" => true,
],
"txt" => [
"edit" => true,
],
"csv" => [
"edit" => true,
],
];
return $additionalFormatAttributes;
}

/**
* Get the formats list from cache or file
*
* @return array
*/
public function getFormats() {
$cachedFormats = $this->cache->get("document_formats");
if ($cachedFormats !== null) {
return json_decode($cachedFormats, true);
}

$formats = file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-formats" . DIRECTORY_SEPARATOR . "onlyoffice-docs-formats.json");
$this->cache->set("document_formats", $formats, 6 * 3600);
$this->logger->debug("Getting formats from file", ["app" => $this->appName]);
return json_decode($formats, true);
}

/**
* DEMO DATA
Expand Down
2 changes: 1 addition & 1 deletion templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</p>
<div class="onlyoffice-exts">
<?php foreach ($_["formats"] as $format => $setting) { ?>
<?php if (\array_key_exists("editable", $setting)) { ?>
<?php if (\array_key_exists("editable", $setting) && $setting["editable"]) { ?>
<div>
<input type="checkbox" class="checkbox"
id="onlyofficeEditFormat<?php p($format) ?>"
Expand Down
Loading