|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Copyright Ascensio System SIA 2024. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Plugin class for the Onlyoffice plugin. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Asensio System SIA |
|
22
|
|
|
*/ |
|
23
|
|
|
class OnlyofficePlugin extends Plugin implements HookPluginInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* OnlyofficePlugin name. |
|
27
|
|
|
*/ |
|
28
|
|
|
private $pluginName = 'onlyoffice'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* OnlyofficePlugin constructor. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct( |
|
36
|
|
|
'1.5.0', |
|
37
|
|
|
'Asensio System SIA', |
|
38
|
|
|
[ |
|
39
|
|
|
'enable_onlyoffice_plugin' => 'boolean', |
|
40
|
|
|
'document_server_url' => 'text', |
|
41
|
|
|
'jwt_secret' => 'text', |
|
42
|
|
|
'jwt_header' => 'text', |
|
43
|
|
|
'document_server_internal' => 'text', |
|
44
|
|
|
'storage_url' => 'text', |
|
45
|
|
|
] |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create OnlyofficePlugin object. |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function create(): OnlyofficePlugin |
|
53
|
|
|
{ |
|
54
|
|
|
static $result = null; |
|
55
|
|
|
|
|
56
|
|
|
return $result ?: $result = new self(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* This method install the plugin tables. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function install() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->installHook(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* This method drops the plugin tables. |
|
69
|
|
|
*/ |
|
70
|
|
|
public function uninstall() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->uninstallHook(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Install the "create" hooks. |
|
77
|
|
|
*/ |
|
78
|
|
|
public function installHook() |
|
79
|
|
|
{ |
|
80
|
|
|
$itemActionObserver = OnlyofficeItemActionObserver::create(); |
|
81
|
|
|
HookDocumentItemAction::create()->attach($itemActionObserver); |
|
82
|
|
|
|
|
83
|
|
|
$actionObserver = OnlyofficeActionObserver::create(); |
|
84
|
|
|
HookDocumentAction::create()->attach($actionObserver); |
|
85
|
|
|
|
|
86
|
|
|
$viewObserver = OnlyofficeItemViewObserver::create(); |
|
87
|
|
|
HookDocumentItemView::create()->attach($viewObserver); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Uninstall the "create" hooks. |
|
92
|
|
|
*/ |
|
93
|
|
|
public function uninstallHook() |
|
94
|
|
|
{ |
|
95
|
|
|
$itemActionObserver = OnlyofficeItemActionObserver::create(); |
|
96
|
|
|
HookDocumentItemAction::create()->detach($itemActionObserver); |
|
97
|
|
|
|
|
98
|
|
|
$actionObserver = OnlyofficeActionObserver::create(); |
|
99
|
|
|
HookDocumentAction::create()->detach($actionObserver); |
|
100
|
|
|
|
|
101
|
|
|
$viewObserver = OnlyofficeItemViewObserver::create(); |
|
102
|
|
|
HookDocumentItemView::create()->detach($viewObserver); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get link to plugin settings. |
|
107
|
|
|
* |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getConfigLink() |
|
111
|
|
|
{ |
|
112
|
|
|
return api_get_path(WEB_PATH).'main/admin/configure_plugin.php?name='.$this->pluginName; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get plugin name. |
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getPluginName() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->pluginName; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public static function isExtensionAllowed(string $extension): bool |
|
126
|
|
|
{ |
|
127
|
|
|
$officeExtensions = [ |
|
128
|
|
|
'ppt', |
|
129
|
|
|
'pptx', |
|
130
|
|
|
'odp', |
|
131
|
|
|
'xls', |
|
132
|
|
|
'xlsx', |
|
133
|
|
|
'ods', |
|
134
|
|
|
'csv', |
|
135
|
|
|
'doc', |
|
136
|
|
|
'docx', |
|
137
|
|
|
'odt', |
|
138
|
|
|
'pdf', |
|
139
|
|
|
]; |
|
140
|
|
|
|
|
141
|
|
|
return in_array($extension, $officeExtensions); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|