id == "uid-1" && !1; // check if the Submit form button is displayed or not $mode = $canEdit && $editorsMode != "view" ? "edit" : "view"; // define if the editing mode is edit or view $type = empty($_GET["type"]) ? "desktop" : $_GET["type"]; $templatesImageUrl = getTemplateImageUrl($filename); // templates image url in the "From Template" section $createUrl = getCreateUrl($filename, $user->id, $type); $templates = array( array ( "image" => "", "title" => "Blank", "url" => $createUrl ), array ( "image" => $templatesImageUrl, "title" => "With sample content", "url" => $createUrl . "&sample=true" ) ); // specify the document config $config = [ "type" => $type, "documentType" => getDocumentType($filename), "document" => [ "title" => $filename, "url" => getDownloadUrl($filename), "directUrl" => $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" => 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 "saveUrl" => $directUrl, // the absolute URL that will allow the document to be saved onto the user personal computer "embedUrl" => $directUrl, // the absolute URL to the document serving as a source file for the document embedded into the web page "shareUrl" => $directUrl, // the absolute URL that will allow other users to share this document "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 "forcesave" => false, // adds the request for the forced file saving to the callback handler when saving the document "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 "url" => serverPath(), // the absolute URL to the website address which will be opened when clicking the Open file location menu button ] ] ] ]; // an image for inserting $dataInsertImage = [ "fileType" => "png", "url" => serverPath(true) . "/css/images/logo.png", "directUrl" => serverPath(false) . "/css/images/logo.png" ]; // a document for comparing $dataCompareFile = [ "fileType" => "docx", "url" => serverPath(true) . "/webeditor-ajax.php?type=assets&name=sample.docx", "directUrl" => serverPath(false) . "/webeditor-ajax.php?type=assets&name=sample.docx" ]; // recipients data for mail merging $dataMailMergeRecipients = [ "fileType" =>"csv", "url" => serverPath(true) . "/webeditor-ajax.php?type=csv", "directUrl" => serverPath(false) . "/webeditor-ajax.php?type=csv" ]; // users data for mentions $usersForMentions = $user->id != "uid-0" ? getUsersForMentions($user->id) : null; // check if the secret key to generate token exists if (isJwtEnabled()) { $config["token"] = jwtEncode($config); // encode config into the token $dataInsertImage["token"] = jwtEncode($dataInsertImage); // encode the dataInsertImage object into the token $dataCompareFile["token"] = jwtEncode($dataCompareFile); // encode the dataCompareFile object into the token $dataMailMergeRecipients["token"] = jwtEncode($dataMailMergeRecipients); // encode the dataMailMergeRecipients object into the token } // get demo file name by the extension function tryGetDefaultByType($createExt, $user) { $demoName = ($_GET["sample"] ? "sample." : "new.") . $createExt; $demoPath = "assets" . DIRECTORY_SEPARATOR . ($_GET["sample"] ? "sample" : "new") . DIRECTORY_SEPARATOR; $demoFilename = GetCorrectName($demoName); if(!@copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . $demoPath . $demoName, getStoragePath($demoFilename))) { sendlog("Copy file error to ". getStoragePath($demoFilename), "common.log"); // Copy error!!! } // create demo file meta information createMeta($demoFilename, $user->id, $user->name); return $demoFilename; } // get the callback url function getCallbackUrl($fileName) { return serverPath(TRUE) . '/' . "webeditor-ajax.php" . "?type=track" . "&fileName=" . urlencode($fileName) . "&userAddress=" . getClientIp(); } // get url to the created file function getCreateUrl($fileName, $uid, $type) { $ext = trim(getInternalExtension($fileName),'.'); return serverPath(false) . '/' . "doceditor.php" . "?fileExt=" . $ext . "&user=" . $uid . "&type=" . $type; } function getHistoryDownloadUrl($fileName, $version, $file, $isServer = TRUE) { $userAddress = $isServer ? "&userAddress=" . getClientIp() : ""; return serverPath($isServer) . '/' . "webeditor-ajax.php" . "?type=history" . "&fileName=" . urlencode($fileName) . "&ver=" . $version . "&file=" . urlencode($file) . $userAddress; } // get url to download a file function getDownloadUrl($fileName, $isServer = TRUE) { $userAddress = $isServer ? "&userAddress=" . getClientIp() : ""; return serverPath($isServer) . '/' . "webeditor-ajax.php" . "?type=download" . "&fileName=" . urlencode($fileName) . $userAddress; } // get document history function getHistory($filename, $filetype, $docKey, $fileuri) { $storagePath = $GLOBALS['STORAGE_PATH']; $histDir = getHistoryDir(getStoragePath($filename)); // get the path to the file history if (getFileVersion($histDir) > 0) { // check if the file was modified (the file version is greater than 0) $curVer = getFileVersion($histDir); $hist = []; $histData = []; for ($i = 1; $i <= $curVer; $i++) { // run through all the file versions $obj = []; $dataObj = []; $verDir = getVersionDir($histDir, $i); // get the path to the file version $key = $i == $curVer ? $docKey : file_get_contents($verDir . DIRECTORY_SEPARATOR . "key.txt"); // get document key $obj["key"] = $key; $obj["version"] = $i; if ($i == 1) { // check if the version number is equal to 1 $createdInfo = file_get_contents($histDir . DIRECTORY_SEPARATOR . "createdInfo.json"); // get meta data of this file $json = json_decode($createdInfo, true); // decode the meta data from the createdInfo.json file $obj["created"] = $json["created"]; $obj["user"] = [ "id" => $json["uid"], "name" => $json["name"] ]; } $fileExe = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $prevFileName = $verDir . DIRECTORY_SEPARATOR . "prev." . $filetype; $prevFileName = substr($prevFileName, strlen(getStoragePath(""))); $dataObj["fileType"] = $fileExe; $dataObj["key"] = $key; $directUrl = $i == $curVer ? FileUri($filename, FALSE) : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe, FALSE); $prevFileUrl = $i == $curVer ? $fileuri : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe); if (realpath($storagePath) === $storagePath) { $prevFileUrl = $i == $curVer ? getDownloadUrl($filename) : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe); $directUrl = $i == $curVer ? getDownloadUrl($filename, FALSE) : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe, FALSE); } $dataObj["url"] = $prevFileUrl; // write file url to the data object $dataObj["directUrl"] = $directUrl; // write direct url to the data object $dataObj["version"] = $i; if ($i > 1) { // check if the version number is greater than 1 (the document was modified) $changes = json_decode(file_get_contents(getVersionDir($histDir, $i - 1) . DIRECTORY_SEPARATOR . "changes.json"), true); // get the path to the changes.json file $change = $changes["changes"][0]; $obj["changes"] = $changes ? $changes["changes"] : null; // write information about changes to the object $obj["serverVersion"] = $changes["serverVersion"]; $obj["created"] = $change ? $change["created"] : null; $obj["user"] = $change ? $change["user"] : null; $prev = $histData[$i - 2]; // get the history data from the previous file version $dataObj["previous"] = [ // write information about previous file version to the data object "fileType" => $prev["fileType"], "key" => $prev["key"], "url" => $prev["url"], "directUrl" => $prev["directUrl"] ]; // write the path to the diff.zip archive with differences in this file version $dataObj["changesUrl"] = getHistoryDownloadUrl($filename, $i - 1, "diff.zip"); } if (isJwtEnabled()) { $dataObj["token"] = jwtEncode($dataObj); } array_push($hist, $obj); // add object dictionary to the hist list $histData[$i - 1] = $dataObj; // write data object information to the history data } // write history information about the current file version $out = []; array_push($out, [ "currentVersion" => $curVer, "history" => $hist ], $histData); return $out; } } ?>