Skip to content

Commit 019e8fa

Browse files
committed
Merge pull request 'hotfix/1.4.1' from develop into master
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/onlyoffice-chamilo/pulls/10
2 parents b5f3c6c + a0c4eb6 commit 019e8fa

9 files changed

+72
-48
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
This plugin is developed and maintained at https://github.com/ONLYOFFICE/onlyoffice-chamilo.
44

5+
## 1.4.1
6+
## Changed
7+
- minor fixes
8+
59
## 1.4.0
610
## Added
711
- using onlyoffice/docs-integration-sdk
8-
- Arabic and Serbian empty file templates
912
- default empty file templates
10-
- Finnish, Hebrew, Norwegian, Slovenian empty file templates
13+
- Arabic, Serbian, Finnish, Hebrew, Norwegian, Slovenian empty file templates
1114

1215
## 1.3.0
1316
## Added

ajax/saveas.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
if (isset($result['error'])) {
7474
if ('fileIsExist' === $result['error']) {
75-
$result['error'] = 'File is exist';
75+
$result['error'] = 'File already exists';
7676
}
7777
if ('impossibleCreateFile' === $result['error']) {
7878
$result['error'] = 'Impossible to create file';

callback.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
case 'download':
7676
$callbackResponseArray = download();
7777
exit(json_encode($callbackResponseArray));
78+
case 'empty':
79+
$callbackResponseArray = emptyFile();
80+
exit(json_encode($callbackResponseArray));
7881
default:
7982
$callbackResponseArray['status'] = 'error';
8083
$callbackResponseArray['error'] = '404 Method not found';
@@ -210,3 +213,51 @@ function download()
210213
readfile($filePath);
211214
exit;
212215
}
216+
217+
/**
218+
* Downloading empty file by the document service.
219+
*/
220+
function emptyFile()
221+
{
222+
global $plugin;
223+
global $type;
224+
global $courseCode;
225+
global $userId;
226+
global $docId;
227+
global $groupId;
228+
global $sessionId;
229+
global $courseInfo;
230+
global $appSettings;
231+
global $jwtManager;
232+
233+
234+
if ($type !== 'empty') {
235+
$result['status'] = 'error';
236+
$result['error'] = 'Download empty with other action';
237+
return $result;
238+
}
239+
240+
if ($jwtManager->isJwtEnabled()) {
241+
$token = substr(getallheaders()[$appSettings->getJwtHeader()], strlen('Bearer '));
242+
try {
243+
$payload = $jwtManager->decode($token, $appSettings->getJwtKey());
244+
} catch (UnexpectedValueException $e) {
245+
$result['status'] = 'error';
246+
$result['error'] = '403 Access denied';
247+
return $result;
248+
}
249+
}
250+
251+
$template = TemplateManager::getEmptyTemplate('docx');
252+
253+
if (!$template) {
254+
$result['status'] = 'error';
255+
$result['error'] = 'File not found';
256+
return $result;
257+
}
258+
259+
@header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
260+
@header('Content-Disposition: attachment; filename='.'docx.docx');
261+
readfile($template);
262+
exit;
263+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"onlyoffice/docs-integration-sdk": "^1.0.0"
3+
"onlyoffice/docs-integration-sdk": "^1.0.1"
44
},
55
"repositories": [
66
{

create.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
$values = $form->exportValues();
7878

7979
$fileType = $values['fileFormat'];
80-
var_dump($fileType);
8180
$fileExt = $documentManager->getDocExtByType($fileType);
8281

8382
$result = OnlyofficeDocumentManager::createFile(

lib/onlyofficeAppRequests.php

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,18 @@ class OnlyofficeAppRequests extends RequestService
2929
public function __construct($settingsManager, $httpClient, $jwtManager)
3030
{
3131
parent::__construct($settingsManager, $httpClient, $jwtManager);
32-
$tempFile = self::createTempFile();
33-
$this->convertFileUrl = $tempFile['fileUrl'];
34-
$this->convertFilePath = $tempFile['filePath'];
35-
}
36-
37-
public function __destruct()
38-
{
39-
unlink($this->convertFilePath);
4032
}
4133

4234
public function getFileUrlForConvert()
4335
{
44-
return $this->convertFileUrl;
45-
}
46-
47-
/**
48-
* Create temporary file for convert service testing.
49-
*
50-
* @return array
51-
*/
52-
private function createTempFile()
53-
{
54-
$fileUrl = null;
55-
$fileName = 'convert.docx';
56-
$fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
57-
$baseName = strtolower(pathinfo($fileName, PATHINFO_FILENAME));
58-
$templatePath = TemplateManager::getEmptyTemplate($fileExt);
59-
$folderPath = api_get_path(SYS_PLUGIN_PATH).$this->settingsManager->plugin->getPluginName();
60-
$filePath = $folderPath.'/'.$fileName;
61-
62-
if ($fp = @fopen($filePath, 'w')) {
63-
$content = file_get_contents($templatePath);
64-
fputs($fp, $content);
65-
fclose($fp);
66-
chmod($filePath, api_get_permissions_for_new_files());
67-
$fileUrl = api_get_path(WEB_PLUGIN_PATH).$this->settingsManager->plugin->getPluginName().'/'.$fileName;
68-
}
69-
70-
return [
71-
'fileUrl' => $fileUrl,
72-
'filePath' => $filePath,
36+
$data = [
37+
'type' => 'empty',
38+
'courseId' => api_get_course_int_id(),
39+
'userId' => api_get_user_id(),
40+
'sessionId' => api_get_session_id(),
7341
];
42+
$hashUrl = $this->jwtManager->getHash($data);
43+
return api_get_path(WEB_PLUGIN_PATH).'onlyoffice/callback.php?hash='.$hashUrl;
7444
}
45+
7546
}

lib/onlyofficeFormatsManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct()
2525
$this->formatsList = self::buildNamedFormatsArray($formats);
2626
}
2727

28-
private function getFormats()
28+
private static function getFormats()
2929
{
3030
$formats = file_get_contents(dirname(__DIR__).
3131
DIRECTORY_SEPARATOR.

lib/onlyofficePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class OnlyofficePlugin extends Plugin implements HookPluginInterface
3333
protected function __construct()
3434
{
3535
parent::__construct(
36-
'1.4.0',
36+
'1.4.1',
3737
'Asensio System SIA',
3838
[
3939
'enable_onlyoffice_plugin' => 'boolean',

lib/onlyofficeSettingsFormBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OnlyofficeSettingsFormBuilder
2929
*
3030
* @return FormValidator
3131
*/
32-
public function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
32+
public static function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
3333
{
3434
$plugin = $settingsManager->plugin;
3535
$demoData = $settingsManager->getDemoData();
@@ -78,7 +78,7 @@ public function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
7878
*
7979
* @return OnlyofficePlugin
8080
*/
81-
public function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
81+
public static function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
8282
{
8383
$plugin = $settingsManager->plugin;
8484
$errorMsg = null;
@@ -114,7 +114,7 @@ public function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
114114
*
115115
* @return string
116116
*/
117-
private function buildTemplate($templateName, $params = [])
117+
private static function buildTemplate($templateName, $params = [])
118118
{
119119
$tpl = new Template('', false, false, false, false, false, false);
120120
if (!empty($params)) {
@@ -135,7 +135,7 @@ private function buildTemplate($templateName, $params = [])
135135
*
136136
* @return void
137137
*/
138-
private function displayError($errorMessage, $location = null)
138+
private static function displayError($errorMessage, $location = null)
139139
{
140140
Display::addFlash(
141141
Display::return_message(

0 commit comments

Comments
 (0)