Files
document-server-integration/web/documentserver-example/php/doceditor.php
Alexander.Trofimov 4f21721901 change license to 2017
2017-01-18 10:46:50 +03:00

245 lines
8.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
*
* (c) Copyright Ascensio System Limited 2010-2017
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
?>
<?php
require_once( dirname(__FILE__) . '/config.php' );
require_once( dirname(__FILE__) . '/common.php' );
require_once( dirname(__FILE__) . '/functions.php' );
$filename;
$fileuri;
$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);
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() . '/'
. "webeditor-ajax.php"
. "?type=track&userAddress=" . getClientIp()
. "&fileName=" . urlencode($fileName);
}
?>
<!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 с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];
docEditor = new DocsAPI.DocEditor("iframeEditor",
{
width: "100%",
height: "100%",
type: "<?php echo ($_GET["type"] == "mobile" ? "mobile" : ($_GET["type"] == "embedded" ? "embedded" : "desktop")) ?>",
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: {
edit: <?php echo (in_array(strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)), $GLOBALS['DOC_SERV_EDITED']) ? "true" : "false") ?>,
download: 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 $fileuri ?>",
embedUrl: "<?php echo $fileuri ?>",
shareUrl: "<?php echo $fileuri ?>",
toolbarDocked: "top",
},
customization: {
about: true,
feedback: true,
goback: {
url: "<?php echo serverPath() ?>",
},
},
},
events: {
'onReady': onReady,
'onDocumentStateChange': onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
'onError': onError,
}
});
};
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>