Skip to content
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
13 changes: 9 additions & 4 deletions public/main/lp/learnpath.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3001,12 +3001,17 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
.'?docId='.$docId
.'&cid='.$course_id
.'&sid='.(int) $this->get_lp_session_id()
.'&groupId='.(int) api_get_group_id()
.'&nh=1'
.('' !== $returnUrl ? '&returnUrl='.rawurlencode($returnUrl) : '');
.'&origin=learnpath'
.'&embedded=1';

if (in_array($extension, $onlyofficeViewOnlyExtensions, true)) {
$onlyofficeUrl .= '&readOnly=1';
$currentGroupId = (int) api_get_group_id();
if ($currentGroupId > 0) {
$onlyofficeUrl .= '&groupId='.$currentGroupId;
}

if ('' !== $returnUrl) {
$onlyofficeUrl .= '&returnUrl='.rawurlencode($returnUrl);
}

$file = $onlyofficeUrl;
Expand Down
83 changes: 69 additions & 14 deletions public/plugin/Onlyoffice/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
$questionId = isset($_GET['questionId']) ? (int) $_GET['questionId'] : null;
$isReadOnly = isset($_GET['readOnly']) ? (int) $_GET['readOnly'] : null;
$forceEdit = isset($_GET['forceEdit']) && in_array(strtolower((string) $_GET['forceEdit']), ['1', 'true', 'yes', 'on'], true);
$origin = isset($_GET['origin']) ? strtolower(trim((string) $_GET['origin'])) : '';
$isEmbedded = isset($_GET['embedded']) && in_array(strtolower((string) $_GET['embedded']), ['1', 'true', 'yes', 'on'], true);
$isLearnpathEmbedded = $isEmbedded || 'learnpath' === $origin;
$rawReturnUrl = isset($_GET['returnUrl']) ? urldecode((string) $_GET['returnUrl']) : '';
$returnUrl = resolveOnlyofficeEditorReturnUrl(
$rawReturnUrl,
Expand Down Expand Up @@ -93,6 +96,9 @@
'questionId' => $questionId,
'meta' => $isMetaRequest,
'returnUrl' => $returnUrl,
'origin' => $origin,
'embedded' => $isEmbedded,
'learnpathEmbedded' => $isLearnpathEmbedded,
]);

if (!empty($docPath)) {
Expand Down Expand Up @@ -182,6 +188,8 @@
.($isReadOnly ? '&readOnly='.$isReadOnly : '')
.($groupId ? '&groupId='.$groupId : '')
.($forceEdit ? '&forceEdit=true' : '')
.($origin ? '&origin='.rawurlencode($origin) : '')
.($isEmbedded ? '&embedded=1' : '')
.($returnUrl ? '&returnUrl='.rawurlencode($returnUrl) : ''),
'document_url' => $callbackUrl,
'direct_url' => $fileUrl,
Expand All @@ -193,6 +201,8 @@
'creator_id' => $userId,
'version_token' => $versionToken,
'return_url' => $returnUrl,
'origin' => $origin,
'embedded' => $isEmbedded,
];

onlyofficeEditorLog('DEBUG', 'Resolved direct path document', [
Expand Down Expand Up @@ -256,6 +266,8 @@
.($isReadOnly ? '&readOnly='.$isReadOnly : '')
.($groupId ? '&groupId='.$groupId : '')
.($forceEdit ? '&forceEdit=true' : '')
.($origin ? '&origin='.rawurlencode($origin) : '')
.($isEmbedded ? '&embedded=1' : '')
.($returnUrl ? '&returnUrl='.rawurlencode($returnUrl) : ''),
'document_url' => $callbackUrl,
'direct_url' => $fileUrl,
Expand All @@ -269,6 +281,8 @@
'resource_file_id' => $resolvedC2['resourceFileId'],
'version_token' => $versionToken,
'return_url' => $returnUrl,
'origin' => $origin,
'embedded' => $isEmbedded,
];

onlyofficeEditorLog('DEBUG', 'Resolved C2 document', [
Expand Down Expand Up @@ -329,10 +343,14 @@
$docInfo['document_url'] = $callbackUrl;
$docInfo['version_token'] = $versionToken;
$docInfo['return_url'] = $returnUrl;
$docInfo['origin'] = $origin;
$docInfo['embedded'] = $isEmbedded;
$docInfo['url'] = api_get_path(WEB_PLUGIN_PATH).'Onlyoffice/editor.php?docId='.$docId
.($isReadOnly ? '&readOnly='.$isReadOnly : '')
.($groupId ? '&groupId='.$groupId : '')
.($forceEdit ? '&forceEdit=true' : '')
.($origin ? '&origin='.rawurlencode($origin) : '')
.($isEmbedded ? '&embedded=1' : '')
.($returnUrl ? '&returnUrl='.rawurlencode($returnUrl) : '');

onlyofficeEditorLog('DEBUG', 'Resolved legacy document', [
Expand Down Expand Up @@ -381,7 +399,9 @@
$questionId,
$isReadOnly,
$forceEdit,
$returnUrl
$returnUrl,
$origin,
$isEmbedded
);

$fileUrl = $fileUrl ?? $documentManager->getFileUrl($runtimeIdentifier);
Expand Down Expand Up @@ -443,10 +463,6 @@
$config['editorConfig']['customization'] = [];
}

if (!isset($config['editorConfig']['customization']['goback']) || !is_array($config['editorConfig']['customization']['goback'])) {
$config['editorConfig']['customization']['goback'] = [];
}

$config['document']['url'] = $fileUrl;
$config['document']['title'] = (string) ($docInfo['title'] ?? basename((string) ($docInfo['path'] ?? 'document')));
$config['document']['key'] = $runtimeKey;
Expand All @@ -465,13 +481,28 @@

$config['editorConfig']['customization']['autosave'] = true;
$config['editorConfig']['customization']['forcesave'] = true;
$config['editorConfig']['customization']['close'] = [
'visible' => true,
];

if ('' !== $returnUrl) {
$config['editorConfig']['customization']['goback']['url'] = $returnUrl;
$config['editorConfig']['customization']['goback']['blank'] = false;
if ($isLearnpathEmbedded) {
if (isset($config['editorConfig']['customization']['goback'])) {
unset($config['editorConfig']['customization']['goback']);
}

$config['editorConfig']['customization']['close'] = [
'visible' => false,
];
} else {
if (!isset($config['editorConfig']['customization']['goback']) || !is_array($config['editorConfig']['customization']['goback'])) {
$config['editorConfig']['customization']['goback'] = [];
}

$config['editorConfig']['customization']['close'] = [
'visible' => true,
];

if ('' !== $returnUrl) {
$config['editorConfig']['customization']['goback']['url'] = $returnUrl;
$config['editorConfig']['customization']['goback']['blank'] = false;
}
}

$config = refreshOnlyofficeEditorToken($config, $jwtManager, $appSettings);
Expand All @@ -491,6 +522,9 @@
'jwtTokenPresent' => !empty($config['token']),
'metaUrl' => $metaUrl,
'returnUrl' => $returnUrl,
'origin' => $origin,
'embedded' => $isEmbedded,
'learnpathEmbedded' => $isLearnpathEmbedded,
]);

sendOnlyofficeEditorNoCacheHeaders();
Expand Down Expand Up @@ -536,6 +570,8 @@
const isMobileAgent = <?php echo json_encode((bool) $isMobileAgent); ?>;
const debugEnabled = <?php echo json_encode((bool) ONLYOFFICE_EDITOR_LOG_ENABLED); ?>;
const safeReturnUrl = <?php echo json_encode($returnUrl, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>;
const isEmbeddedEditor = <?php echo json_encode((bool) $isLearnpathEmbedded); ?>;
const fallbackHomeUrl = <?php echo json_encode(api_get_path(WEB_PATH), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>;

const isEditableMode = !!(
config &&
Expand Down Expand Up @@ -576,6 +612,15 @@ function getNavigationType() {
}

function leaveEditorSafely() {
if (isEmbeddedEditor) {
if (safeReturnUrl && window.top && window.top !== window) {
window.top.location.href = safeReturnUrl;
return;
}

return;
}

if (safeReturnUrl) {
window.location.href = safeReturnUrl;
return;
Expand All @@ -591,11 +636,11 @@ function leaveEditorSafely() {
return;
}

window.location.href = <?php echo json_encode(api_get_path(WEB_PATH)); ?>;
window.location.href = fallbackHomeUrl;
}

function handleUnsafeReload() {
alert("Refreshing the editor while the document session is still open is not supported. You will return to the previous page so the document can be reopened safely.");
alert("Refreshing the editor while the document session is still open is not supported. You will return to a safe page so the document can be reopened correctly.");
leaveEditorSafely();
}

Expand Down Expand Up @@ -1029,7 +1074,9 @@ function buildOnlyofficeMetaUrl(
?int $questionId,
?int $isReadOnly,
bool $forceEdit,
string $returnUrl = ''
string $returnUrl = '',
string $origin = '',
bool $isEmbedded = false
): string {
$params = [
'meta' => '1',
Expand Down Expand Up @@ -1071,6 +1118,14 @@ function buildOnlyofficeMetaUrl(
$params['returnUrl'] = $returnUrl;
}

if ('' !== $origin) {
$params['origin'] = $origin;
}

if ($isEmbedded) {
$params['embedded'] = '1';
}

return api_get_path(WEB_PLUGIN_PATH).'Onlyoffice/editor.php?'.http_build_query($params);
}

Expand Down
Loading