getUser($_GET["user"]); $isEnableDirectUrl = isset($_GET["directUrl"]) ? filter_var($_GET["directUrl"], FILTER_VALIDATE_BOOLEAN) : false; // get the file url and upload it $externalUrl = $_GET["fileUrl"] ?? ""; if (!empty($externalUrl)) { try { $filename = $utils->doUpload($externalUrl); } catch (\Exception $e) { } } else { // if the file url doesn't exist, get file name and file extension $filename = basename($_GET["fileID"]); } $createExt = $_GET["fileExt"] ?? ""; if (!empty($createExt)) { // and get demo file name by the extension $filename = $fileUtility->tryGetDefaultByType($createExt, $user); // create the demo file url $new_url = "doceditor.php?fileID=" . $filename . "&user=" . $_GET["user"]; header('Location: ' . $new_url, true); exit; } $fileuri = $fileUtility->fileUri($filename, true); $fileuriUser = realpath($configManager->getConfig("storagePath")) === $configManager->getConfig("storagePath") ? $fileUtility->getDownloadUrl($filename) . "&dmode=emb" : $fileUtility->fileUri($filename); $directUrl = $fileUtility->getDownloadUrl($filename, false); $docKey = $fileUtility->getDocEditorKey($filename); $filetype = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $ext = mb_strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)); $editorsMode = empty($_GET["action"]) ? "edit" : $_GET["action"]; // get the editors mode $canEdit = in_array($ext, $configManager->getConfig("docServEdited")); // check if the file can be edited if ((!$canEdit && $editorsMode == "edit" || $editorsMode == "fillForms") && in_array($ext, $configManager->getConfig("docServFillforms")) ) { $editorsMode = "fillForms"; $canEdit = true; } // check if the Submit form button is displayed or not $submitForm = $editorsMode == "fillForms" && $user->id == "uid-1" && !1; $mode = $canEdit && $editorsMode != "view" ? "edit" : "view"; // define if the editing mode is edit or view $type = empty($_GET["type"]) ? "desktop" : $_GET["type"]; $templatesImageUrl = $fileUtility->getTemplateImageUrl($filename); // templates image url in the "From Template" section $createUrl = $fileUtility->getCreateUrl($filename, $user->id, $type); $templates = [ [ "image" => "", "title" => "Blank", "url" => $createUrl, ], [ "image" => $templatesImageUrl, "title" => "With sample content", "url" => $createUrl . "&sample=true", ], ]; // specify the document config $config = [ "type" => $type, "documentType" => $fileUtility->getDocumentType($filename), "document" => [ "title" => $filename, "url" => $fileUtility->getDownloadUrl($filename), "directUrl" => $isEnableDirectUrl ? $directUrl : "", "fileType" => $filetype, "key" => $docKey, "info" => [ "owner" => "Me", "uploaded" => date('d.m.y'), "favorite" => $user->favorite, ], "permissions" => [ // the permission for the document to be edited and downloaded or not "comment" => $editorsMode != "view" && $editorsMode != "fillForms" && $editorsMode != "embedded" && $editorsMode != "blockcontent", "copy" => !in_array("copy", $user->deniedPermissions), "download" => !in_array("download", $user->deniedPermissions), "edit" => $canEdit && ($editorsMode == "edit" || $editorsMode == "view" || $editorsMode == "filter" || $editorsMode == "blockcontent"), "print" => !in_array("print", $user->deniedPermissions), "fillForms" => $editorsMode != "view" && $editorsMode != "comment" && $editorsMode != "embedded" && $editorsMode != "blockcontent", "modifyFilter" => $editorsMode != "filter", "modifyContentControl" => $editorsMode != "blockcontent", "review" => $canEdit && ($editorsMode == "edit" || $editorsMode == "review"), "chat" => $user->id != "uid-0", "reviewGroups" => $user->reviewGroups, "commentGroups" => $user->commentGroups, "userInfoGroups" => $user->userInfoGroups, ], ], "editorConfig" => [ "actionLink" => empty($_GET["actionLink"]) ? null : json_decode($_GET["actionLink"]), "mode" => $mode, "lang" => empty($_COOKIE["ulang"]) ? "en" : $_COOKIE["ulang"], "callbackUrl" => $fileUtility->getCallbackUrl($filename), // absolute URL to the document storage service "coEditing" => $editorsMode == "view" && $user->id == "uid-0" ? [ "mode" => "strict", "change" => false, ] : null, "createUrl" => $user->id != "uid-0" ? $createUrl : null, "templates" => $user->templates ? $templates : null, "user" => [ // the user currently viewing or editing the document "id" => $user->id != "uid-0" ? $user->id : null, "name" => $user->name, "group" => $user->group, ], "embedded" => [ // the parameters for the embedded document type // the absolute URL that will allow the document to be saved onto the user personal computer "saveUrl" => $directUrl, // the absolute URL to the document serving as a source file for the document embedded into the web page "embedUrl" => $directUrl, // the absolute URL that will allow other users to share this document "shareUrl" => $directUrl, "toolbarDocked" => "top", // the place for the embedded viewer toolbar (top or bottom) ], "customization" => [ // the parameters for the editor interface "about" => true, // the About section display "comments" => true, "feedback" => true, // the Feedback & Support menu button display // adds the request for the forced file saving to the callback handler when saving the document "forcesave" => false, "submitForm" => $submitForm, // if the Submit form button is displayed or not "goback" => [ // settings for the Open file location menu button and upper right corner button // the absolute URL to the website address which will be opened // when clicking the Open file location menu button "url" => $fileUtility->serverPath(), ], ], ], ]; // an image for inserting $dataInsertImage = $isEnableDirectUrl ? [ "fileType" => "png", "url" => $fileUtility->serverPath(true) . "/css/images/logo.png", "directUrl" => $fileUtility->serverPath(false) . "/css/images/logo.png", ] : [ "fileType" => "png", "url" => $fileUtility->serverPath(true) . "/css/images/logo.png", ]; // a document for comparing $dataCompareFile = $isEnableDirectUrl ? [ "fileType" => "docx", "url" => $fileUtility->serverPath(true) . "/webeditor-ajax.php?type=assets&name=sample.docx", "directUrl" => $fileUtility->serverPath(false) . "/webeditor-ajax.php?type=assets&name=sample.docx", ] : [ "fileType" => "docx", "url" => $fileUtility->serverPath(true) . "/webeditor-ajax.php?type=assets&name=sample.docx", ]; // recipients data for mail merging $dataMailMergeRecipients = $isEnableDirectUrl ? [ "fileType" => "csv", "url" => $fileUtility->serverPath(true) . "/webeditor-ajax.php?type=csv", "directUrl" => $fileUtility->serverPath(false) . "/webeditor-ajax.php?type=csv", ] : [ "fileType" => "csv", "url" => $fileUtility->serverPath(true) . "/webeditor-ajax.php?type=csv", ]; // users data for mentions $usersForMentions = $user->id != "uid-0" ? $users->getUsersForMentions($user->id) : null; // check if the secret key to generate token exists $jwtManager = new JwtManager(); if ($jwtManager->isJwtEnabled()) { $config["token"] = $jwtManager->jwtEncode($config); // encode config into the token // encode the dataInsertImage object into the token $dataInsertImage["token"] = $jwtManager->jwtEncode($dataInsertImage); // encode the dataCompareFile object into the token $dataCompareFile["token"] = $jwtManager->jwtEncode($dataCompareFile); // encode the dataMailMergeRecipients object into the token $dataMailMergeRecipients["token"] = $jwtManager->jwtEncode($dataMailMergeRecipients); } ?> ONLYOFFICE