Files
Hermes 818c793ce6 Core-clean variant: editor id eurooffice, no text-app patch
- HtmlDirectEditor getId() now returns 'eurooffice' (hard-coded in the
  iOS/Android editor registry) -> 'Öffnen mit Office' long-press renders HTML
- install.sh restores the original TextDirectEditor if a previous
  install patched it; no core app patch anymore
- README rewritten: behavior, variant rationale, files
2026-09-11 12:28:13 +00:00

92 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 HtmlViewer / patch by Hermes Agent
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* DirectEditing editor for text/html so the Nextcloud iOS/Android apps
* open HTML files in an embedded WebView instead of falling back to
* QuickLook source display.
*/
namespace OCA\HtmlViewer\DirectEditing;
use OCA\HtmlViewer\AppInfo\Application;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\DirectEditing\IEditor;
use OCP\DirectEditing\IToken;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
class HtmlDirectEditor implements IEditor {
public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
) {
}
#[\Override]
public function getId(): string {
// "eurooffice" is one of the hard-coded editor IDs the Nextcloud
// iOS/Android apps resolve in their editor registry. The menu
// "Öffnen mit Office" (long press) then opens this editor.
return 'eurooffice';
}
#[\Override]
public function getName(): string {
return $this->l10n->t('HTML Viewer');
}
#[\Override]
public function getMimetypes(): array {
return [
'text/html',
];
}
#[\Override]
public function getMimetypesOptional(): array {
return [];
}
#[\Override]
public function getCreators(): array {
return [];
}
#[\Override]
public function isSecure(): bool {
return false;
}
#[\Override]
public function open(IToken $token): Response {
$token->useTokenScope();
try {
$file = $token->getFile();
return new TemplateResponse(
Application::APP_ID,
'directEditing',
[
'fileId' => $file->getId(),
'fileName' => $file->getName(),
'fileContent' => $file->getContent(),
],
'base'
);
} catch (InvalidPathException|NotFoundException) {
return new NotFoundResponse();
}
}
}