Using ONLYOFFICE Full-Screen Editing on the Nextcloud Platform

Full-Screen Editing with OnlyOffice on the Nextcloud Platform

1. Function Description

In OnlyOffice 9.11, API support and backend configuration options have already been provided.

See the reference image below:

However, the display logic has not yet been completed.

Let’s first take a look at the current usage behavior of OnlyOffice within Nextcloud in its default mode:

This integration method is tightly coupled with Nextcloud, enabling users to quickly switch to other functional areas via the top navigation menu.

But it has some drawbacks:

  1. For immersive editing, the top navigation bar is redundant.
  2. For small-screen laptops, the top bar wastes valuable space.

Now let’s look at the full-screen effect:

The full-screen editing mode resolves the above problems perfectly.

OnlyOffice 9.11 already supports two layout modes from the admin panel, but the implementation was not fully completed.
So we will supplement this feature manually.

2. Implementation

2.1 Modify onlyoffice/lib/Controller/EditorController.php

Edit using a text editor:

$response = null;

if ($inframe === true) {
    $params["inframe"] = true;
    $response = new TemplateResponse($this->appName, "editor", $params, "base");
} else {

    if ($isLoggedIn) {
        $response = new TemplateResponse($this->appName, "editor", $params);
    } else {

        $response = new PublicTemplateResponse($this->appName, "editor", $params);

        list($file, $error, $share) =
        $this->fileUtility->getFileByToken($fileId, $shareToken);

        if (!isset($error)) {
            $response->setHeaderTitle($file->getName());
        }
    }
}

The key part we modify is:

if ($isLoggedIn) {
    $response = new TemplateResponse($this->appName, "editor", $params, "base");
}

Essentially, we just add the "base" parameter.

2.2 Modify onlyoffice/templates/editor.php

Edit the following snippet:

<?php if (!empty($_["inviewer"])) { ?>
class="onlyoffice-inviewer"
<?php } ?>

Replace with:

<?php if ($_["inframe"] !== true) { ?>

It is unclear whether this is a bug or an unfinished feature in OnlyOffice.
After modifying these two locations, the full-screen mode works as expected.

3. Nextcloud Template Mechanism

Nextcloud provides two layout templates:

The core difference lies in the renderAs parameter of TemplateResponse.

Template Type Description
base Full-screen mode (no top navigation)
user (default) With Nextcloud top menu

3.1 Text App - Full-Screen Mode (No Top Menu)

return new TemplateResponse('text', 'main', [], 'base');
  • Uses renderAs = 'base'
  • Template file: core/templates/layout.base.php
  • Features: basic HTML structure only, no Nextcloud header

3.2 OnlyOffice App - With Top Menu

if ($isLoggedIn) {
    $response = new TemplateResponse($this->appName, "editor", $params);
} else {
    $response = new PublicTemplateResponse($this->appName, "editor", $params);
}
  • Uses renderAs = 'user' (default)
  • Template file: core/templates/layout.user.php
  • Features: includes full Nextcloud header, app menu, user menu, etc.

Layout Comparison

Feature layout.base.php layout.user.php
Top navigation :x: No :white_check_mark: Yes
App menu :x: No :white_check_mark: Yes
User menu :x: No :white_check_mark: Yes
Search bar :x: No :white_check_mark: Yes
Notifications :x: No :white_check_mark: Yes
<body> class body-public body-user
Content shell <div id="content" class="app-public"> <div id="content" class="app-{appid}">

4. Summary

OnlyOffice already provides internal support for a full-screen editor through its interface.
However, some display logic is either incomplete or contains a bug.
With the minor adjustments above, you can already enable a truly full-screen editing experience.

This patch has not yet been fully regression-tested, so compatibility is not guaranteed.
It is expected that OnlyOffice will officially implement this feature in the near future.

source
https://github.com/ebfming/onlyoffice-full-screen-edit

基于nextcloud平台使用onlyoffice全屏编辑

1、功能说明

在onlyoffice9.11插件中,已经提供了API的支持,以及后台配置。

参考下图:

只是展示逻辑还没有完成

我们先看一下功能效果。

默认onlyoffice在nextcloud中的时使用效果如下:

这种使用方式优点是和nextcloud紧密结合。可快速通过顶部菜单切换至其他功能区。

缺点是

1、如果沉浸式办公操作,顶部菜单显得多余;

2、针对小屏幕电脑,如:笔记本,顶部菜单有点浪费空间。

接下来我们看全屏效果:

以上是全屏编辑效果,他完美解决了以上问题。

Onlyoffice 9.11 从后台管理功能中支持两种形式。只是还没有开发完成。

我们来补充一下这个功能

2、具体实施

2.1、修改 onlyoffice/lib/Controller/EditorController.php

使用文本编辑器修改:

$response = null**;**

if ($inframe === true**)** {

$params**[“inframe”]** = true**;**

$response = new TemplateResponse($this****->appName, “editor”, $params**,** “base”);

} else {

if ($isLoggedIn**)** {

$response = new TemplateResponse($this****->appName, “editor”, $params);

} else {

$response = new PublicTemplateResponse($this****->appName, “editor”, $params);

list($file**,** $error**,** $share) = $this**->fileUtilitygetFileByToken($fileId,** $shareToken);

if (!isset($error)) {

$response**->setHeaderTitle($filegetName());**

}

}

}

其中:

if ($isLoggedIn**)** {

$response = new TemplateResponse($this****->appName, “editor”, $params**,** “base”);

}

部分是我们修改的主要对象。实际我们只是添加了一个参数:”base”

2.2、修改 onlyoffice/templates/editor.php

使用文本编辑器修改:

<?php if (!empty($_["inviewer"])) { ?>

class=“onlyoffice-inviewer”

<?php } ?>>

其中:

if (!empty($_[“inviewer”]))

替换为:

<?php** **if** **(**$_**[**"inframe"**]** **!==** **true****)** **{** **?>

即可。

我不清楚这是不是onlyoffice的bug还是没有开发完成。经过修改这两个位置之后,即可满足以上的使用需求。

3、nextcloud 模板功能

nextcloud提供了两种展示模板,分别是

核心区别:TemplateResponse 的 renderAs 参数

1. Text App - 全屏模式(无顶部菜单)

return new TemplateResponse(‘text’, ‘main’, , ‘base’);

  • 使用 renderAs = ‘base’
  • 对应模板:core/templates/layout.base.php
  • 特点:只有基础的 HTML 结构,没有 Nextcloud 的顶部导航栏(header)

2. OnlyOffice App - 带顶部菜单

if ($isLoggedIn) { $response = new TemplateResponse($this->appName, “editor”, $params);} else { $response = new PublicTemplateResponse($this->appName, “editor”, $params);}

  • 使用 renderAs = ‘user’(默认值)
  • 对应模板:core/templates/layout.user.php
  • 特点:包含完整的 Nextcloud 顶部导航栏(header)、应用菜单、用户菜单等

布局模板对比

特性 layout.base.php layout.user.php
顶部导航栏 :x: :white_check_mark: 有(#header
应用菜单 :x: :white_check_mark:
用户菜单 :x: :white_check_mark:
搜索框 :x: :white_check_mark:
通知 :x: :white_check_mark:
body class body-public body-user
content 容器

4、总结

onlyoffice已经提供了关于全屏编辑器的支持接口。只是部分展示逻辑没有补充或者存在bug。经过小修补后即可使用。目前没有经过全面测试,我不能保证这个调整适配是完美的。相信不久 onlyoffice 将提供正式的全屏编辑器功能

您好 @ebfming

现在您的建议不太清晰。首先您提到第二个方案“美解决了以上问题”,但随后又提到“还没有开发完成”。

当前情况下,在同一标签页中打开文件时,确实会显示 Nextcloud 的顶部栏;而在新标签页中打开文件时,编辑器会全屏显示,并且可以通过“返回”按钮回到文件管理器中的上一位置。这是系统设计的预期行为。

如果您希望修改源代码,请确保遵循许可证要求:

此外,请注意,我们无法保证在此类更改后应用程序仍能稳定运行。

注意以上文字说明:
完美解决是指:我修复的全屏使用功能。
“还没有开发完成”:是指oo现的现状。
当前无论是配置新标签与否,实际效果是一样的。

请说明哪里没有遵循许可证要求,第一次修改源码。可能会有疏忽

已登记相关的功能改进,我已经将您的建议添加到该记录中。

感谢确认。我会在本地继续验证该修改逻辑,如官方版本未来实现该功能,可再比较两者表现。

1 Like