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

Opening external link #359

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions controller/editorapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,24 @@ public function config($fileId, $filePath = null, $shareToken = null, $version =
}

$folderLink = null;
$publicPageLink = null;

if (!empty($shareToken)) {
$node = $share->getNode();
$linkAttr = [
"token" => $shareToken
];
if ($node instanceof Folder) {
$sharedFolder = $node;
$folderPath = $sharedFolder->getRelativePath($file->getParent()->getPath());
if (!empty($folderPath)) {
$linkAttr = [
"path" => $folderPath,
"scrollto" => $file->getName(),
"token" => $shareToken
];
$linkAttr["scrollto"] = $file->getName();
$linkAttr["path"] = $folderPath;
$folderLink = $this->urlGenerator->linkToRouteAbsolute("files_sharing.sharecontroller.showShare", $linkAttr);
}
} else if ($node instanceof File) {
$linkAttr["redirect"] = false;
$publicPageLink = $this->urlGenerator->linkToRouteAbsolute("files_sharing.sharecontroller.showShare", $linkAttr);
}
} else if (!empty($userId)) {
$userFolder = $this->root->getUserFolder($userId);
Expand Down Expand Up @@ -491,10 +495,10 @@ public function config($fileId, $filePath = null, $shareToken = null, $version =
$params["_file_path"] = $userFolder->getRelativePath($file->getPath());
}

if ($folderLink !== null
if (($folderLink !== null || $publicPageLink !== null)
&& $this->config->GetSystemValue($this->config->_customization_goback) !== false) {
$params["editorConfig"]["customization"]["goback"] = [
"url" => $folderLink
"url" => $folderLink !== null ? $folderLink : $publicPageLink
];

if (!$desktop) {
Expand Down
36 changes: 20 additions & 16 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
);
};

OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor) {
OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor, redirect) {
var filePath = "";
if (fileName) {
filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName;
Expand All @@ -101,7 +101,7 @@

if (winEditor && winEditor.location) {
winEditor.location.href = url;
} else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) {
} else if ((!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) && !redirect) {
winEditor = window.open(url, "_blank");
} else if ($("#isPublic").val() === "1" && !$("#filestable").length) {
location.href = url;
Expand Down Expand Up @@ -445,25 +445,29 @@
return;
}

var editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));
var redirect = true;
var flag = /\?redirect=([\w-]{1})/.exec(location.search);
if (flag && flag.length > 0 && flag[1] === "0") {
redirect = false;
}

if (oc_appswebroots.richdocuments
|| oc_appswebroots.files_pdfviewer && extension === "pdf"
|| oc_appswebroots.files_texteditor && extension === "txt") {
var isThirdPartyApps = oc_appswebroots.richdocuments
|| oc_appswebroots.files_pdfviewer && extension === "pdf"
|| oc_appswebroots.files_texteditor && extension === "txt";

var button = document.createElement("a");
button.href = editorUrl;
if (!redirect || isThirdPartyApps) {
var button = document.createElement("button");
button.className = "onlyoffice-public-open button";
button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE")

if (!OCA.Onlyoffice.setting.sameTab) {
button.target = "_blank";
}
button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE");

$("#preview").prepend(button);
} else {
var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + editorUrl + "?inframe=true\" />");
$("#preview").append($iframe);
button.addEventListener("click", function(event) {
OCA.Onlyoffice.OpenEditor();
});
}

if (redirect && !isThirdPartyApps) {
OCA.Onlyoffice.OpenEditor(0, "", "", 0, null, redirect);
}
};

Expand Down