代码拉取完成,页面将自动刷新
同步操作将从 dragonli/kodbox_onlyoffice_plugin 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
class OnlyOfficePlugin extends PluginBase
{
function __construct()
{
parent::__construct();
}
public function regist()
{
$this->hookRegist(array(
'user.commonJs.insert' => 'OnlyOfficePlugin.echoJs'
));
}
public function echoJs()
{
$this->echoFile('static/main.js');
}
public function index()
{
$path = $this->filePath($this->in['path']);
$localFile = $this->pluginLocalFile($this->in['path']);
$fileUrl = $this->filePathLinkOut($this->in['path']);
$fileName = $this->fileInfo['name'];
$fileExt = get_path_ext($this->fileInfo['name']);
$config = $this->getConfig();
if (substr(APP_HOST, 0, 8) == 'https://') {
$dsServer = $config['apiServer-https'];
$http_header = 'https://';
} else {
$dsServer = $config['apiServer-http'];
$http_header = 'http://';
}
$option = array(
'apiServer' => $http_header . $dsServer,
'url' => $fileUrl,
'callbackUrl' => "",
'key' => md5_file($localFile),
'time' => filemtime($localFile),
'fileType' => $this->fileTypeAlias($fileExt),
'title' => $fileName,
'compact' => false,
'documentType' => $this->getDocumentType($fileExt),
'user' => Session::get('kodUser.nickName') . ' (' . Session::get('kodUser.name') . ')',
'UID' => Session::get('kodUser.userID'),
'mode' => 'view',
'type' => 'desktop',
'lang' => I18n::getType(),
'canDownload' => false,
'canEdit' => false,
'canPrint' => false,
);
// 设定未登录用户的文档信息
if (Session::get('kodUser') == null) {
$option['UID'] = 'guest';
$option['user'] = 'guest';
$option['canDownload'] = false;
$option['canPrint'] = false;
}
//可读权限检测,可读则可下载及打印
if (Action("explorer.auth")->fileCanRead($path)) {
$option['canDownload'] = true;
$option['canPrint'] = true;
}
//可写权限检测
if (Action("explorer.auth")->fileCanWrite($path)) {
$option['mode'] = 'edit';
$option['canEdit'] = true;
$option['key'] = md5($localFile . $option['time']);
$option['callbackUrl'] = $this->pluginApi . 'save&path=' . rawurlencode($path);
}
//内部对话框打开时,使用紧凑显示
if ($config['openWith'] == 'dialog') {
$option['compact'] = true;
$option['title'] = " ";
}
//匹配移动端
if (is_wap()) {
$option['type'] = 'mobile';
}
if (strlen($dsServer) > 0) {
include($this->pluginPath . '/php/office.php');
} else {
$error_msg = "OnlyOffice Document Server is not available.<br/>" .
"The API of \"" . $http_header . "\" must be filled.";
show_tips($error_msg);
}
}
private function getDocumentType($ext)
{
$ExtsDoc = ['doc', 'docm', 'docx', 'docxf', 'dot', 'dotm', 'dotx', 'epub', 'fodt', 'fb2', 'htm', 'html', 'mht', 'odt', 'oform', 'ott', 'oxps', 'pdf', 'rtf', 'txt', 'djvu', 'xml', 'xps'];
$ExtsPre = ['fodp', 'odp', 'otp', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx'];
$ExtsSheet = ['csv', 'fods', 'ods', 'ots', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx'];
if (in_array($ext, $ExtsDoc)) {
return "word";
} elseif (in_array($ext, $ExtsPre)) {
return "slide";
} elseif (in_array($ext, $ExtsSheet)) {
return "cell";
} else {
return "unknown";
}
}
private function fileTypeAlias($ext)
{
if (strpos(".docm.dotm.dot.wps.wpt", '.' . $ext) !== false) {
$ext = 'doc';
} else if (strpos(".xlt.xltx.xlsm.dotx.et.ett", '.' . $ext) !== false) {
$ext = 'xls';
} else if (strpos(".pot.potx.pptm.ppsm.potm.dps.dpt", '.' . $ext) !== false) {
$ext = 'ppt';
}
return $ext;
}
public function save()
{
if (($body_stream = file_get_contents("php://input")) === FALSE) {
echo "Bad Request";
}
$data = json_decode($body_stream, TRUE);
if ($data["status"] == 2) {
if (($new_office_content = file_get_contents($data["url"])) === FALSE) {
echo "Bad Response";
} else {
$this->pluginCacheFileSet($_GET['path'], $new_office_content);
}
}
echo "{\"error\":0}";
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。