mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
256 lines
8.5 KiB
PHP
256 lines
8.5 KiB
PHP
<?php
|
||
/*
|
||
*
|
||
* (c) Copyright Ascensio System Limited 2010-2017
|
||
*
|
||
* The MIT License (MIT)
|
||
*
|
||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
* of this software and associated documentation files (the "Software"), to deal
|
||
* in the Software without restriction, including without limitation the rights
|
||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
* copies of the Software, and to permit persons to whom the Software is
|
||
* furnished to do so, subject to the following conditions:
|
||
*
|
||
* The above copyright notice and this permission notice shall be included in all
|
||
* copies or substantial portions of the Software.
|
||
*
|
||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||
* SOFTWARE.
|
||
*
|
||
*/
|
||
?>
|
||
|
||
<?php
|
||
require_once( dirname(__FILE__) . '/config.php' );
|
||
require_once( dirname(__FILE__) . '/common.php' );
|
||
require_once( dirname(__FILE__) . '/functions.php' );
|
||
|
||
$filename;
|
||
|
||
$externalUrl = $_GET["fileUrl"];
|
||
if (!empty($externalUrl))
|
||
{
|
||
$filename = DoUpload($externalUrl);
|
||
}
|
||
else
|
||
{
|
||
$filename = basename($_GET["fileID"]);
|
||
}
|
||
$createExt = $_GET["fileExt"];
|
||
|
||
if (!empty($createExt))
|
||
{
|
||
$filename = tryGetDefaultByType($createExt);
|
||
|
||
$new_url = "doceditor.php?fileID=" . $filename . "&user=" . $_GET["user"];
|
||
header('Location: ' . $new_url, true);
|
||
exit;
|
||
}
|
||
|
||
$fileuri = FileUri($filename, true);
|
||
$fileuriUser = FileUri($filename);
|
||
|
||
function tryGetDefaultByType($createExt) {
|
||
$demoName = ($_GET["sample"] ? "demo." : "new.") . $createExt;
|
||
$demoFilename = GetCorrectName($demoName);
|
||
|
||
if(!@copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . "app_data" . DIRECTORY_SEPARATOR . $demoName, getStoragePath($demoFilename)))
|
||
{
|
||
sendlog("Copy file error to ". getStoragePath($demoFilename), "logs/common.log");
|
||
//Copy error!!!
|
||
}
|
||
|
||
return $demoFilename;
|
||
}
|
||
|
||
function getCallbackUrl($fileName) {
|
||
return serverPath(TRUE) . '/'
|
||
. "webeditor-ajax.php"
|
||
. "?type=track"
|
||
. "&fileName=" . urlencode($fileName)
|
||
. "&userAddress=" . getClientIp();
|
||
}
|
||
|
||
?>
|
||
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
|
||
<title>ONLYOFFICE</title>
|
||
|
||
<style>
|
||
html {
|
||
height: 100%;
|
||
width: 100%;
|
||
}
|
||
|
||
body {
|
||
background: #fff;
|
||
color: #333;
|
||
font-family: Arial, Tahoma,sans-serif;
|
||
font-size: 12px;
|
||
font-weight: normal;
|
||
height: 100%;
|
||
margin: 0;
|
||
overflow-y: hidden;
|
||
padding: 0;
|
||
text-decoration: none;
|
||
}
|
||
|
||
form {
|
||
height: 100%;
|
||
}
|
||
|
||
div {
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
</style>
|
||
|
||
<script type="text/javascript" src="<?php echo $GLOBALS["DOC_SERV_API_URL"] ?>"></script>
|
||
|
||
<script type="text/javascript">
|
||
|
||
var docEditor;
|
||
var fileName = "<?php echo $filename ?>";
|
||
var fileType = "<?php echo strtolower(pathinfo($filename, PATHINFO_EXTENSION)) ?>";
|
||
|
||
var innerAlert = function (message) {
|
||
if (console && console.log)
|
||
console.log(message);
|
||
};
|
||
|
||
var onReady = function () {
|
||
innerAlert("Document editor ready");
|
||
};
|
||
|
||
var onDocumentStateChange = function (event) {
|
||
var title = document.title.replace(/\*$/g, "");
|
||
document.title = title + (event.data ? "*" : "");
|
||
};
|
||
|
||
var onRequestEditRights = function () {
|
||
location.href = location.href.replace(RegExp("action=view\&?", "i"), "");
|
||
};
|
||
|
||
var onError = function (event) {
|
||
if (event)
|
||
innerAlert(event.data);
|
||
};
|
||
|
||
var onOutdatedVersion = function (event) {
|
||
location.reload(true);
|
||
};
|
||
|
||
var сonnectEditor = function () {
|
||
|
||
<?php
|
||
if (!file_exists(getStoragePath($filename))) {
|
||
echo "alert('File not found'); return;";
|
||
}
|
||
?>
|
||
|
||
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: type,
|
||
documentType: "<?php echo getDocumentType($filename) ?>",
|
||
document: {
|
||
title: fileName,
|
||
url: "<?php echo $fileuri ?>",
|
||
fileType: fileType,
|
||
key: "<?php echo getDocEditorKey($filename) ?>",
|
||
|
||
info: {
|
||
author: "Me",
|
||
created: "<?php echo date('d.m.y') ?>",
|
||
},
|
||
|
||
permissions: {
|
||
download: true,
|
||
edit: <?php echo (in_array(strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)), $GLOBALS['DOC_SERV_EDITED']) && $_GET["action"] != "review" ? "true" : "false") ?>,
|
||
review: true
|
||
}
|
||
},
|
||
editorConfig: {
|
||
mode: '<?php echo $GLOBALS['MODE'] != 'view' && in_array(strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)), $GLOBALS['DOC_SERV_EDITED']) && $_GET["action"] != "view" ? "edit" : "view" ?>',
|
||
|
||
lang: "en",
|
||
|
||
callbackUrl: "<?php echo getCallbackUrl($filename) ?>",
|
||
|
||
user: user,
|
||
|
||
embedded: {
|
||
saveUrl: "<?php echo $fileuriUser ?>",
|
||
embedUrl: "<?php echo $fileuriUser ?>",
|
||
shareUrl: "<?php echo $fileuriUser ?>",
|
||
toolbarDocked: "top",
|
||
},
|
||
|
||
customization: {
|
||
about: true,
|
||
feedback: true,
|
||
goback: {
|
||
url: "<?php echo serverPath() ?>",
|
||
},
|
||
},
|
||
},
|
||
events: {
|
||
'onReady': onReady,
|
||
'onDocumentStateChange': onDocumentStateChange,
|
||
'onRequestEditRights': onRequestEditRights,
|
||
'onError': onError,
|
||
'onOutdatedVersion': onOutdatedVersion,
|
||
}
|
||
});
|
||
};
|
||
|
||
if (window.addEventListener) {
|
||
window.addEventListener("load", сonnectEditor);
|
||
} else if (window.attachEvent) {
|
||
window.attachEvent("load", сonnectEditor);
|
||
}
|
||
|
||
function getXmlHttp() {
|
||
var xmlhttp;
|
||
try {
|
||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||
} catch (e) {
|
||
try {
|
||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||
} catch (ex) {
|
||
xmlhttp = false;
|
||
}
|
||
}
|
||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
|
||
xmlhttp = new XMLHttpRequest();
|
||
}
|
||
return xmlhttp;
|
||
}
|
||
|
||
</script>
|
||
</head>
|
||
<body>
|
||
<form id="form1">
|
||
<div id="iframeEditor">
|
||
</div>
|
||
</form>
|
||
</body>
|
||
</html>
|