Skip to content

Commit

Permalink
Merge pull request 'hotfix/1.4.1' from develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Oct 18, 2024
2 parents b5f3c6c + a0c4eb6 commit 019e8fa
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 48 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

## 1.4.1
## Changed
- minor fixes

## 1.4.0
## Added
- using onlyoffice/docs-integration-sdk
- Arabic and Serbian empty file templates
- default empty file templates
- Finnish, Hebrew, Norwegian, Slovenian empty file templates
- Arabic, Serbian, Finnish, Hebrew, Norwegian, Slovenian empty file templates

## 1.3.0
## Added
Expand Down
2 changes: 1 addition & 1 deletion ajax/saveas.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

if (isset($result['error'])) {
if ('fileIsExist' === $result['error']) {
$result['error'] = 'File is exist';
$result['error'] = 'File already exists';
}
if ('impossibleCreateFile' === $result['error']) {
$result['error'] = 'Impossible to create file';
Expand Down
51 changes: 51 additions & 0 deletions callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
case 'download':
$callbackResponseArray = download();
exit(json_encode($callbackResponseArray));
case 'empty':
$callbackResponseArray = emptyFile();
exit(json_encode($callbackResponseArray));
default:
$callbackResponseArray['status'] = 'error';
$callbackResponseArray['error'] = '404 Method not found';
Expand Down Expand Up @@ -210,3 +213,51 @@ function download()
readfile($filePath);
exit;
}

/**
* Downloading empty file by the document service.
*/
function emptyFile()
{
global $plugin;
global $type;
global $courseCode;
global $userId;
global $docId;
global $groupId;
global $sessionId;
global $courseInfo;
global $appSettings;
global $jwtManager;


if ($type !== 'empty') {
$result['status'] = 'error';
$result['error'] = 'Download empty with other action';
return $result;
}

if ($jwtManager->isJwtEnabled()) {
$token = substr(getallheaders()[$appSettings->getJwtHeader()], strlen('Bearer '));
try {
$payload = $jwtManager->decode($token, $appSettings->getJwtKey());
} catch (UnexpectedValueException $e) {
$result['status'] = 'error';
$result['error'] = '403 Access denied';
return $result;
}
}

$template = TemplateManager::getEmptyTemplate('docx');

if (!$template) {
$result['status'] = 'error';
$result['error'] = 'File not found';
return $result;
}

@header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
@header('Content-Disposition: attachment; filename='.'docx.docx');
readfile($template);
exit;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"onlyoffice/docs-integration-sdk": "^1.0.0"
"onlyoffice/docs-integration-sdk": "^1.0.1"
},
"repositories": [
{
Expand Down
1 change: 0 additions & 1 deletion create.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
$values = $form->exportValues();

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

$result = OnlyofficeDocumentManager::createFile(
Expand Down
45 changes: 8 additions & 37 deletions lib/onlyofficeAppRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,18 @@ class OnlyofficeAppRequests extends RequestService
public function __construct($settingsManager, $httpClient, $jwtManager)
{
parent::__construct($settingsManager, $httpClient, $jwtManager);
$tempFile = self::createTempFile();
$this->convertFileUrl = $tempFile['fileUrl'];
$this->convertFilePath = $tempFile['filePath'];
}

public function __destruct()
{
unlink($this->convertFilePath);
}

public function getFileUrlForConvert()
{
return $this->convertFileUrl;
}

/**
* Create temporary file for convert service testing.
*
* @return array
*/
private function createTempFile()
{
$fileUrl = null;
$fileName = 'convert.docx';
$fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$baseName = strtolower(pathinfo($fileName, PATHINFO_FILENAME));
$templatePath = TemplateManager::getEmptyTemplate($fileExt);
$folderPath = api_get_path(SYS_PLUGIN_PATH).$this->settingsManager->plugin->getPluginName();
$filePath = $folderPath.'/'.$fileName;

if ($fp = @fopen($filePath, 'w')) {
$content = file_get_contents($templatePath);
fputs($fp, $content);
fclose($fp);
chmod($filePath, api_get_permissions_for_new_files());
$fileUrl = api_get_path(WEB_PLUGIN_PATH).$this->settingsManager->plugin->getPluginName().'/'.$fileName;
}

return [
'fileUrl' => $fileUrl,
'filePath' => $filePath,
$data = [
'type' => 'empty',
'courseId' => api_get_course_int_id(),
'userId' => api_get_user_id(),
'sessionId' => api_get_session_id(),
];
$hashUrl = $this->jwtManager->getHash($data);
return api_get_path(WEB_PLUGIN_PATH).'onlyoffice/callback.php?hash='.$hashUrl;
}

}
2 changes: 1 addition & 1 deletion lib/onlyofficeFormatsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct()
$this->formatsList = self::buildNamedFormatsArray($formats);
}

private function getFormats()
private static function getFormats()
{
$formats = file_get_contents(dirname(__DIR__).
DIRECTORY_SEPARATOR.
Expand Down
2 changes: 1 addition & 1 deletion lib/onlyofficePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OnlyofficePlugin extends Plugin implements HookPluginInterface
protected function __construct()
{
parent::__construct(
'1.4.0',
'1.4.1',
'Asensio System SIA',
[
'enable_onlyoffice_plugin' => 'boolean',
Expand Down
8 changes: 4 additions & 4 deletions lib/onlyofficeSettingsFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OnlyofficeSettingsFormBuilder
*
* @return FormValidator
*/
public function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
public static function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
{
$plugin = $settingsManager->plugin;
$demoData = $settingsManager->getDemoData();
Expand Down Expand Up @@ -78,7 +78,7 @@ public function buildSettingsForm(OnlyofficeAppsettings $settingsManager)
*
* @return OnlyofficePlugin
*/
public function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
public static function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
{
$plugin = $settingsManager->plugin;
$errorMsg = null;
Expand Down Expand Up @@ -114,7 +114,7 @@ public function validateSettingsForm(OnlyofficeAppsettings $settingsManager)
*
* @return string
*/
private function buildTemplate($templateName, $params = [])
private static function buildTemplate($templateName, $params = [])
{
$tpl = new Template('', false, false, false, false, false, false);
if (!empty($params)) {
Expand All @@ -135,7 +135,7 @@ private function buildTemplate($templateName, $params = [])
*
* @return void
*/
private function displayError($errorMessage, $location = null)
private static function displayError($errorMessage, $location = null)
{
Display::addFlash(
Display::return_message(
Expand Down

0 comments on commit 019e8fa

Please sign in to comment.