Compare commits

..

13 Commits

23 changed files with 135 additions and 74 deletions

View File

@ -129,8 +129,8 @@ namespace OnlineEditorsExampleMVC.Helpers
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx",
Query = "type=track"
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
+ "&fileName=" + HttpUtility.UrlEncode(fileName)
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
};
return callbackUrl.ToString();
}

View File

@ -78,6 +78,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
@ -135,6 +139,7 @@
'onDocumentStateChange': onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
'onError': onError,
'onOutdatedVersion': onOutdatedVersion,
}
});
};

View File

@ -71,6 +71,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
@ -127,7 +131,8 @@
'onReady': onReady,
'onDocumentStateChange': onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
'onError': onError
'onError': onError,
'onOutdatedVersion': onOutdatedVersion,
}
});
};

View File

@ -61,8 +61,8 @@ namespace OnlineEditorsExample
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
callbackUrl.Query = "type=track"
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
+ "&fileName=" + HttpUtility.UrlEncode(FileName);
+ "&fileName=" + HttpUtility.UrlEncode(FileName)
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
return callbackUrl.ToString();
}
}

View File

@ -191,7 +191,7 @@ public class DocumentManager
{
String serverPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
String hostAddress = CurUserHostAddress(null);
String query = "?type=track&userAddress=" + URLEncoder.encode(hostAddress) + "&fileName=" + URLEncoder.encode(fileName);
String query = "?type=track&fileName=" + URLEncoder.encode(fileName) + "&userAddress=" + URLEncoder.encode(hostAddress);
return serverPath + "/IndexServlet" + query;
}

View File

@ -72,6 +72,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
@ -129,6 +133,7 @@
"onDocumentStateChange": onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
"onError": onError,
"onOutdatedVersion": onOutdatedVersion,
}
});
};

View File

@ -352,7 +352,7 @@ app.post("/track", function (req, res) {
response.write("{\"error\":0}");
response.end();
}
};
if (body.status == 1) { //Editing
if (body.actions && body.actions[0].type == 0) { //finished edit
@ -367,14 +367,16 @@ app.post("/track", function (req, res) {
}
}
response.write("{\"error\":0}");
response.end();
} else if (body.status == 2 || body.status == 3) { //MustSave, Corrupted
processSave(body.url, body, fileName, userAddress, response, true);
} else if (body.status == 6 || body.status == 7) { //MustForceSave, CorruptedForceSave
processSave(body.url, body, fileName, userAddress, response);
} else if (body.status == 2 || body.status == 3 //MustSave, Corrupted
|| body.status == 6 || body.status == 7) { //MustForceSave, CorruptedForceSave
var newVersion = (body.status == 2 || body.status == 3);
processSave(body.url, body, fileName, userAddress, response, newVersion);
return;
}
}
response.write("{\"error\":0}");
response.end();
};
var readbody = function (request, response, fileName, userAddress) {
var content = "";
@ -385,7 +387,7 @@ app.post("/track", function (req, res) {
var body = JSON.parse(content);
processTrack(response, body, fileName, userAddress);
});
}
};
if (req.body.hasOwnProperty("status")) {
processTrack(res, req.body, fileName, userAddress);
@ -410,7 +412,7 @@ app.get("/editor", function (req, res) {
if (fileExt != null) {
var fileName = docManager.createDemo((req.query.sample ? "sample." : "new.") + fileExt, userid, name);
var redirectPath = docManager.getProtocol() + "://" + docManager.req.get("host") + "/editor?fileName=" + encodeURIComponent(fileName) + docManager.getCustomParams();
var redirectPath = docManager.getServerUrl() + "/editor?fileName=" + encodeURIComponent(fileName) + docManager.getCustomParams();
res.redirect(redirectPath);
return;
}
@ -420,7 +422,11 @@ app.get("/editor", function (req, res) {
var key = docManager.getKey(fileName);
var url = docManager.getFileUri(fileName);
var mode = req.query.mode || "edit"; //mode: view/edit
var type = req.query.type || "desktop"; //type: embedded/mobile/desktop
var type = req.query.type || ""; //type: embedded/mobile/desktop
if (type == "") {
type = new RegExp(configServer.get("mobileRegEx"), "i").test(req.get('User-Agent')) ? "mobile" : "desktop";
}
var canEdit = configServer.get('editedDocs').indexOf(fileUtility.getFileExtension(fileName)) != -1;
var countVersion = 1;
@ -467,7 +473,7 @@ app.get("/editor", function (req, res) {
documentType: fileUtility.getFileType(fileName),
key: key,
callbackUrl: docManager.getCallback(fileName),
isEdit: canEdit,
isEdit: canEdit && mode != "review",
mode: canEdit && mode != "view" ? "edit" : "view",
canBackToFolder: type != "embedded",
getServerUrl: docManager.getServerUrl(),

View File

@ -24,6 +24,7 @@
"convertedDocs": [".doc", ".odt", ".xls", ".ods", ".ppt", ".pps", ".odp", ".rtf", ".mht", ".html", ".htm", ".epub"],
"storageFolder": "files",
"maxFileSize": 1073741824,
"mobileRegEx": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"static":[
{
"name": "/public",

View File

@ -139,12 +139,12 @@ docManager.saveFileData = function (fileName, userid, username) {
};
docManager.getFileData = function (fileName, userAddress) {
var file_info = docManager.historyPath(fileName, userAddress, true);
if (!this.existsSync(file_info)) {
const history = path.join(docManager.historyPath(fileName, userAddress, true), fileName + ".txt");
if (!this.existsSync(history)) {
return ["2016-01-01", "uid-1", "John Smith"];
}
return ((fileSystem.readFileSync(path.join(file_info, fileName + ".txt"))).toString()).split(",");
return ((fileSystem.readFileSync(history)).toString()).split(",");
};
docManager.getFileUri = function (fileName) {
@ -152,7 +152,7 @@ docManager.getFileUri = function (fileName) {
};
docManager.getlocalFileUri = function (fileName, version) {
var serverPath = docManager.getProtocol() + "://" + docManager.req.get("host");
var serverPath = docManager.getServerUrl();
var storagePath = storageFolder.length ? storageFolder + "/" : "";
var hostAddress = docManager.curUserHostAddress();
var url = serverPath + "/" + storagePath + hostAddress + "/" + encodeURIComponent(fileName);
@ -167,9 +167,9 @@ docManager.getServerUrl = function () {
};
docManager.getCallback = function (fileName) {
var server = docManager.getProtocol() + "://" + docManager.req.get("host");
var server = docManager.getServerUrl();
var hostAddress = docManager.curUserHostAddress();
var handler = "/track?useraddress=" + encodeURIComponent(hostAddress) + "&filename=" + encodeURIComponent(fileName);
var handler = "/track?filename=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress);
return server + handler;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

View File

@ -288,7 +288,7 @@ footer {
background-repeat: no-repeat;
display: inline-block;
height: 16px;
max-width: 450px;
max-width: 250px;
margin-bottom: -6px;
overflow: hidden;
padding: 8px 0 1px 34px;

View File

@ -96,6 +96,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var connectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
@ -114,8 +118,9 @@
created: new Date().toDateString()
},
permissions: {
download: true,
edit: "<%= editor.isEdit %>" == "true",
download: true
review: true,
}
},
editorConfig: {
@ -138,7 +143,7 @@
comments: true,
feedback: true,
goback: {
url: ("<%= editor.type %>" == "embedded" ? null : "<%= editor.getServerUrl %>")
url: "<%= editor.getServerUrl %>"
}
},
fileChoiceUrl: "<%= editor.fileChoiceUrl %>",
@ -151,7 +156,8 @@
"onError": onError,
"onRequestHistory": onRequestHistory,
"onRequestHistoryData": onRequestHistoryData,
"onRequestHistoryClose": onRequestHistoryClose
"onRequestHistoryClose": onRequestHistoryClose,
"onOutdatedVersion": onOutdatedVersion,
}
});
};

View File

@ -129,7 +129,7 @@
<thead>
<tr class="tableHeader">
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
<td colspan="2" class="tableHeaderCell contentCells-shift">Editors</td>
<td colspan="3" class="tableHeaderCell contentCells-shift">Editors</td>
<td colspan="3" class="tableHeaderCell">Viewers</td>
</tr>
</thead>
@ -137,7 +137,7 @@
<% for (var i = 0; i < storedFiles.length; i++) { %>
<tr class="tableRow" title="<%=storedFiles[i].name%>">
<td class="contentCells">
<a class="stored-edit <%= storedFiles[i].documentType%>" href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="stored-edit <%= storedFiles[i].documentType %>" href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<span title="<%= storedFiles[i].url %>"><%= storedFiles[i].name %></span></a>
<a href="<%= storedFiles[i].url %>">
<img class="icon-download" src="images/download-24.png" alt="Download" title="Download" /></a>
@ -145,15 +145,21 @@
<img class="icon-delete" src="images/delete-24.png" alt="Delete" title="Delete" /></a>
</td>
<td class="contentCells contentCells-icon">
<a href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a href="editor?type=desktop&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/desktop-24.png" alt="Open in editor for full size screens" title="Open in editor for full size screens" /></a>
</td>
<td class="contentCells contentCells-shift contentCells-icon">
<td class="contentCells contentCells-icon">
<a href="editor?type=mobile&mode=edit&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/mobile-24.png" alt="Open in editor for mobile devices" title="Open in editor for mobile devices" /></a>
</td>
<td class="contentCells contentCells-shift contentCells-icon">
<% if (storedFiles[i].documentType == "text") { %>
<a href="editor?type=desktop&mode=review&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/review-24.png" alt="Open in editor for review" title="Open in editor for review" /></a>
<% } %>
</td>
<td class="contentCells contentCells-icon">
<a href="editor?mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a href="editor?type=desktop&mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<img src="images/desktop-24.png" alt="Open in viewer for full size screens" title="Open in viewer for full size screens" /></a>
</td>
<td class="contentCells contentCells-icon">

View File

@ -142,8 +142,10 @@ function getClientIp() {
return $ipaddress;
}
function serverPath() {
return 'http://' . $_SERVER['HTTP_HOST'];
function serverPath($forDocumentServer) {
return $forDocumentServer && isset($GLOBALS['EXAMPLE_URL']) && $GLOBALS['EXAMPLE_URL'] != ""
? $GLOBALS['EXAMPLE_URL']
: ('http://' . $_SERVER['HTTP_HOST']);
}
function getCurUserHostAddress($userAddress = NULL) {
@ -223,35 +225,35 @@ function getStoredFiles() {
}
$cdir = scandir($directory);
foreach ($cdir as $key => $fileName)
{
if (!in_array($fileName,array(".","..")))
{
if (!is_dir($directory . DIRECTORY_SEPARATOR . $fileName))
{
$result[] = (object) array(
'name' => $fileName,
'url' => FileUri($fileName),
'documentType' => getDocumentType($fileName)
);
$result = array();
foreach($cdir as $key => $fileName) {
if (!in_array($fileName,array(".", ".."))) {
if (!is_dir($directory . DIRECTORY_SEPARATOR . $fileName)) {
$dat = filemtime($directory . DIRECTORY_SEPARATOR . $fileName);
$result[$dat] = (object) array(
"name" => $fileName,
"url" => FileUri($fileName),
"documentType" => getDocumentType($fileName)
);
}
}
}
return $result;
ksort($result);
return array_reverse($result);
}
function getVirtualPath() {
function getVirtualPath($forDocumentServer) {
$storagePath = trim(str_replace(array('/','\\'), '/', $GLOBALS['STORAGE_PATH']), '/');
$storagePath = $storagePath != "" ? $storagePath . '/' : "";
$virtPath = serverPath() . '/' . $storagePath . getCurUserHostAddress() . '/';
$virtPath = serverPath($forDocumentServer) . '/' . $storagePath . getCurUserHostAddress() . '/';
sendlog("getVirtualPath virtPath: " . $virtPath, "logs/common.log");
return $virtPath;
}
function FileUri($file_name) {
$uri = getVirtualPath() . $file_name;
function FileUri($file_name, $forDocumentServer) {
$uri = getVirtualPath($forDocumentServer) . $file_name;
return $uri;
}

View File

@ -18,6 +18,10 @@ $GLOBALS['DOC_SERV_API_URL'] = "https://doc.onlyoffice.com/web-apps/apps/api/doc
$GLOBALS['DOC_SERV_PRELOADER_URL'] = "https://doc.onlyoffice.com/web-apps/apps/api/documents/cache-scripts.html";
$GLOBALS['EXAMPLE_URL'] = "";
$GLOBALS['MOBILE_REGEX'] = "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino";
$GLOBALS['ExtsSpreadsheet'] = array(".xls", ".xlsx",
".ods", ".csv");

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

View File

@ -291,7 +291,7 @@ footer {
background-repeat: no-repeat;
display: inline-block;
height: 16px;
max-width: 450px;
max-width: 250px;
margin-bottom: -6px;
overflow: hidden;
padding: 8px 0 1px 34px;

View File

@ -31,7 +31,6 @@
require_once( dirname(__FILE__) . '/functions.php' );
$filename;
$fileuri;
$externalUrl = $_GET["fileUrl"];
if (!empty($externalUrl))
@ -53,8 +52,8 @@
exit;
}
$fileuri = FileUri($filename);
$fileuri = FileUri($filename, true);
$fileuriUser = FileUri($filename);
function tryGetDefaultByType($createExt) {
$demoName = ($_GET["sample"] ? "demo." : "new.") . $createExt;
@ -70,10 +69,11 @@
}
function getCallbackUrl($fileName) {
return serverPath() . '/'
return serverPath(TRUE) . '/'
. "webeditor-ajax.php"
. "?type=track&userAddress=" . getClientIp()
. "&fileName=" . urlencode($fileName);
. "?type=track"
. "&fileName=" . urlencode($fileName)
. "&userAddress=" . getClientIp();
}
?>
@ -145,6 +145,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var сonnectEditor = function () {
<?php
@ -153,14 +157,18 @@
}
?>
var user = [{id:"0","name":"Jonn Smith"}, {id:"1","name":"Mark Pottato"}, {id:"2","name":"Hamish Mitchell"}]["<?php echo $_GET["user"] ?>" || 0];
var user = [{id:"0","name":"Jonn Smith"}, {id:"1","name":"Mark Pottato"}, {id:"2","name":"Hamish Mitchell"}]["<?php echo $_GET["user"] ?>" || 0];
var type = "<?php echo ($_GET["type"] == "mobile" ? "mobile" : ($_GET["type"] == "embedded" ? "embedded" : ($_GET["type"] == "desktop" ? "desktop" : ""))) ?>";
if (type == "") {
type = new RegExp("<?php echo $GLOBALS['MOBILE_REGEX'] ?>", "i").test(window.navigator.userAgent) ? "mobile" : "desktop";
}
docEditor = new DocsAPI.DocEditor("iframeEditor",
{
width: "100%",
height: "100%",
type: "<?php echo ($_GET["type"] == "mobile" ? "mobile" : ($_GET["type"] == "embedded" ? "embedded" : "desktop")) ?>",
type: type,
documentType: "<?php echo getDocumentType($filename) ?>",
document: {
title: fileName,
@ -174,8 +182,9 @@
},
permissions: {
edit: <?php echo (in_array(strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)), $GLOBALS['DOC_SERV_EDITED']) ? "true" : "false") ?>,
download: true,
edit: <?php echo (in_array(strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)), $GLOBALS['DOC_SERV_EDITED']) && $_GET["action"] != "review" ? "true" : "false") ?>,
review: true
}
},
editorConfig: {
@ -188,9 +197,9 @@
user: user,
embedded: {
saveUrl: "<?php echo $fileuri ?>",
embedUrl: "<?php echo $fileuri ?>",
shareUrl: "<?php echo $fileuri ?>",
saveUrl: "<?php echo $fileuriUser ?>",
embedUrl: "<?php echo $fileuriUser ?>",
shareUrl: "<?php echo $fileuriUser ?>",
toolbarDocked: "top",
},
@ -207,6 +216,7 @@
'onDocumentStateChange': onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
'onError': onError,
'onOutdatedVersion': onOutdatedVersion,
}
});
};

View File

@ -249,8 +249,8 @@ function SendRequestToConvertService($document_uri, $from_extension, $to_extensi
if (!function_exists('simplexml_load_file')){
throw new Exception("Server can't read xml");
}
$data = simplexml_load_string($response_xml_data);
if (!$data) {
$response_data = simplexml_load_string($response_xml_data);
if (!$response_data) {
$exc = "Bad Response. Errors: ";
foreach(libxml_get_errors() as $error) {
$exc = $exc . "\t" . $error->message;
@ -258,7 +258,7 @@ function SendRequestToConvertService($document_uri, $from_extension, $to_extensi
throw new Exception ($exc);
}
return $data;
return $response_data;
}

View File

@ -163,7 +163,7 @@
<thead>
<tr class="tableHeader">
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
<td colspan="2" class="tableHeaderCell contentCells-shift">Editors</td>
<td colspan="3" class="tableHeaderCell contentCells-shift">Editors</td>
<td colspan="3" class="tableHeaderCell">Viewers</td>
</tr>
</thead>
@ -184,17 +184,23 @@
echo ' </a>';
echo ' </td>';
echo ' <td class="contentCells contentCells-icon">';
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'" target="_blank">';
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'&type=desktop" target="_blank">';
echo ' <img src="css/images/desktop-24.png" alt="Open in editor for full size screens" title="Open in editor for full size screens" /></a>';
echo ' </a>';
echo ' </td>';
echo ' <td class="contentCells contentCells-shift contentCells-icon">';
echo ' <td class="contentCells contentCells-icon">';
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'&type=mobile" target="_blank">';
echo ' <img src="css/images/mobile-24.png" alt="Open in editor for mobile devices" title="Open in editor for mobile devices" /></a>';
echo ' </a>';
echo ' <td class="contentCells contentCells-shift contentCells-icon">';
if ($storeFile->documentType == "text") {
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'&action=review&type=desktop" target="_blank">';
echo ' <img src="css/images/review-24.png" alt="Open in editor for review" title="Open in editor for review" /></a>';
echo ' </a>';
}
echo ' </td>';
echo ' <td class="contentCells contentCells-icon">';
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'&action=view" target="_blank">';
echo ' <a href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'&action=view&type=desktop" target="_blank">';
echo ' <img src="css/images/desktop-24.png" alt="Open in viewer for full size screens" title="Open in viewer for full size screens" /></a>';
echo ' </a>';
echo ' </td>';

View File

@ -58,7 +58,7 @@ if (isset($_GET["type"]) && !empty($_GET["type"])) { //Checks if type value exis
switch($type) { //Switch case for value of type
case "upload":
$response_array = upload();
$response_array['status'] = $response_array['error'] != NULL ? 'error' : 'success';
$response_array['status'] = isset($response_array['error']) ? 'error' : 'success';
die (json_encode($response_array));
case "convert":
$response_array = convert();
@ -201,8 +201,8 @@ function convert() {
if (in_array("." + $extension, $GLOBALS['DOC_SERV_CONVERT']) && $internalExtension != "") {
$fileUri = $_GET["fileUri"];
if ($fileUri == "") {
$fileUri = FileUri($fileName);
if ($fileUri == NULL || $fileUri == "") {
$fileUri = FileUri($fileName, TRUE);
}
$key = getDocEditorKey($fileName);

View File

@ -94,7 +94,7 @@ class DocumentHelper
def get_callback(file_name)
@@base_url + '/track?type=track&userAddress=' + cur_user_host_address(nil) + '&fileName=' + URI::encode(file_name)
@@base_url + '/track?type=track&fileName=' + URI::encode(file_name) + '&userAddress=' + cur_user_host_address(nil)
end

View File

@ -34,6 +34,10 @@
innerAlert(event.data);
};
var onOutdatedVersion = function (event) {
location.reload(true);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
@ -90,6 +94,7 @@
'onReady': onReady,
'onDocumentStateChange': onDocumentStateChange,
'onError': onError,
'onOutdatedVersion': onOutdatedVersion,
},
});
};