|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* (c) Copyright Ascensio System SIA 2021 |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
class OnlyofficeTools { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Return button-link to onlyoffice editor for file |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function getButtonEdit(array $document_data): string |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
$plugin = OnlyofficePlugin::create(); |
|
29
|
|
|
|
|
30
|
|
|
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true"; |
|
31
|
|
|
if (!$isEnable) { |
|
32
|
|
|
return ''; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$urlToEdit = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/editor.php"; |
|
36
|
|
|
|
|
37
|
|
|
$extension = strtolower(pathinfo($document_data["title"], PATHINFO_EXTENSION)); |
|
38
|
|
|
|
|
39
|
|
|
$canEdit = in_array($extension, FileUtility::$can_edit_types); |
|
40
|
|
|
$canView = in_array($extension, FileUtility::$can_view_types); |
|
41
|
|
|
|
|
42
|
|
|
$groupId = api_get_group_id(); |
|
43
|
|
|
if (!empty($groupId)) { |
|
44
|
|
|
$urlToEdit = $urlToEdit . "?groupId=" . $groupId . "&"; |
|
45
|
|
|
} else { |
|
46
|
|
|
$urlToEdit = $urlToEdit . "?"; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$documentId = $document_data["id"]; |
|
50
|
|
|
$urlToEdit = $urlToEdit . "docId=" . $documentId; |
|
51
|
|
|
|
|
52
|
|
|
if ($canEdit || $canView) { |
|
53
|
|
|
return Display::url( |
|
54
|
|
|
Display::return_icon( |
|
55
|
|
|
'../../plugin/onlyoffice/resources/onlyoffice_edit.png', |
|
56
|
|
|
$plugin->get_lang('openByOnlyoffice') |
|
57
|
|
|
), |
|
58
|
|
|
$urlToEdit |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return ''; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Return button-link to onlyoffice editor for view file |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function getButtonView (array $document_data): string |
|
69
|
|
|
{ |
|
70
|
|
|
|
|
71
|
|
|
$plugin = OnlyofficePlugin::create(); |
|
72
|
|
|
|
|
73
|
|
|
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true"; |
|
74
|
|
|
if (!$isEnable) { |
|
75
|
|
|
return ''; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$urlToEdit = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/editor.php"; |
|
79
|
|
|
|
|
80
|
|
|
$sessionId = api_get_session_id(); |
|
81
|
|
|
$courseInfo = api_get_course_info(); |
|
82
|
|
|
$documentId = $document_data["id"]; |
|
83
|
|
|
$userId = api_get_user_id(); |
|
84
|
|
|
|
|
85
|
|
|
$docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo["code"], false, $sessionId); |
|
86
|
|
|
|
|
87
|
|
|
$extension = strtolower(pathinfo($document_data["title"], PATHINFO_EXTENSION)); |
|
88
|
|
|
$canView = in_array($extension, FileUtility::$can_view_types); |
|
89
|
|
|
|
|
90
|
|
|
$isGroupAccess = false; |
|
91
|
|
|
$groupId = api_get_group_id(); |
|
92
|
|
|
if (!empty($groupId)) { |
|
93
|
|
|
$groupProperties = GroupManager::get_group_properties($groupId); |
|
94
|
|
|
$docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId); |
|
95
|
|
|
$isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo["code"], $groupProperties, $docInfoGroup); |
|
96
|
|
|
|
|
97
|
|
|
$urlToEdit = $urlToEdit . "?groupId=" . $groupId . "&"; |
|
98
|
|
|
} else { |
|
99
|
|
|
$urlToEdit = $urlToEdit . "?"; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$isAllowToEdit = api_is_allowed_to_edit(true, true); |
|
103
|
|
|
$isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo["absolute_parent_path"], $sessionId); |
|
104
|
|
|
|
|
105
|
|
|
$accessRights = $isAllowToEdit || $isMyDir || $isGroupAccess; |
|
106
|
|
|
|
|
107
|
|
|
$urlToEdit = $urlToEdit . "docId=" . $documentId; |
|
108
|
|
|
|
|
109
|
|
|
if ($canView && !$accessRights) { |
|
110
|
|
|
return Display::url(Display::return_icon('../../plugin/onlyoffice/resources/onlyoffice_view.png', $plugin->get_lang('openByOnlyoffice')), $urlToEdit, ["style" => "float:right; margin-right:8px"]); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return ''; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Return button-link to onlyoffice create new |
|
118
|
|
|
*/ |
|
119
|
|
|
public static function getButtonCreateNew (): string |
|
120
|
|
|
{ |
|
121
|
|
|
|
|
122
|
|
|
$plugin = OnlyofficePlugin::create(); |
|
123
|
|
|
|
|
124
|
|
|
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true"; |
|
125
|
|
|
if (!$isEnable) { |
|
126
|
|
|
return ''; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$courseId = api_get_course_int_id(); |
|
130
|
|
|
$sessionId = api_get_session_id(); |
|
131
|
|
|
$groupId = api_get_group_id(); |
|
132
|
|
|
$userId = api_get_user_id(); |
|
133
|
|
|
|
|
134
|
|
|
$urlToCreate = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/create.php" |
|
135
|
|
|
."?folderId=" . (empty($_GET["id"])?'0':(int)$_GET["id"]) |
|
136
|
|
|
. "&courseId=" . $courseId |
|
137
|
|
|
. "&groupId=" . $groupId |
|
138
|
|
|
. "&sessionId=" . $sessionId |
|
139
|
|
|
. "&userId=" . $userId; |
|
140
|
|
|
|
|
141
|
|
|
return Display::url( |
|
142
|
|
|
Display::return_icon( |
|
143
|
|
|
"../../plugin/onlyoffice/resources/onlyoffice_create.png", |
|
144
|
|
|
$plugin->get_lang("createNew") |
|
145
|
|
|
), |
|
146
|
|
|
$urlToCreate |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|