This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathModule.php
124 lines (101 loc) · 3.03 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\onlydocuments;
use Yii;
use yii\helpers\Url;
use yii\helpers\Json;
use humhub\modules\file\libs\FileHelper;
use humhub\libs\CURLHelper;
/**
* File Module
*
* @since 0.5
*/
class Module extends \humhub\components\Module
{
public $resourcesPath = 'resources';
/**
* Open modes
*/
const OPEN_MODE_VIEW = 'view';
const OPEN_MODE_EDIT = 'edit';
/**
* Only document types
*/
const DOCUMENT_TYPE_TEXT = 'text';
const DOCUMENT_TYPE_PRESENTATION = 'presentation';
const DOCUMENT_TYPE_SPREADSHEET = 'spreadsheet';
/**
* @var string[] allowed spreadsheet extensions
*/
public $spreadsheetExtensions = ['xls', 'xlsx', 'ods', 'csv'];
/**
* @var string[] allowed presentation extensions
*/
public $presentationExtensions = ['ppsx', 'pps', 'ppt', 'pptx', 'odp'];
/**
* @var string[] allowed text extensions
*/
public $textExtensions = ['docx', 'doc', 'odt', 'rtf', 'txt', 'html', 'htm', 'mht', 'pdf', 'djvu', 'fb2', 'epub', 'xps'];
public function getServerUrl()
{
return $this->settings->get('serverUrl');
}
/**
*
* @return type
*/
public function getServerApiUrl()
{
return $this->getServerUrl() . '/web-apps/apps/api/documents/api.js';
}
public function getDocumentType($file)
{
$fileExtension = FileHelper::getExtension($file);
if (in_array($fileExtension, $this->spreadsheetExtensions)) {
return self::DOCUMENT_TYPE_SPREADSHEET;
} elseif (in_array($fileExtension, $this->presentationExtensions)) {
return self::DOCUMENT_TYPE_PRESENTATION;
} elseif (in_array($fileExtension, $this->textExtensions)) {
return self::DOCUMENT_TYPE_TEXT;
}
return null;
}
/**
* @inheritdoc
*/
public function getConfigUrl()
{
return Url::to([
'/onlydocuments/admin'
]);
}
public function commandService($data)
{
$url = $this->getServerUrl() . '/coauthoring/CommandService.ashx';
try {
$http = new \Zend\Http\Client($url, [
'adapter' => '\Zend\Http\Client\Adapter\Curl',
'curloptions' => CURLHelper::getOptions(),
'timeout' => 10
]);
$http->setMethod('POST');
$http->setRawBody(Json::encode($data));
$response = $http->send();
$json = $response->getBody();
} catch (\Exception $ex) {
Yii::error('Could not get document server response! ' . $ex->getMessage());
return [];
}
try {
return Json::decode($json);
} catch (\yii\base\InvalidParamException $ex) {
Yii::error('Could not get document server response! ' . $ex->getMessage());
return [];
}
}
}