Skip to content

Commit

Permalink
Plugin: OnlyOffice: Add OnlyOffice viewer by default for correspondin…
Browse files Browse the repository at this point in the history
…g extensions in documents tool - refs chamilo#5395
  • Loading branch information
ywarnier committed Dec 13, 2024
1 parent 3439ff1 commit ab1f124
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 7 additions & 1 deletion main/inc/lib/document.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5479,7 +5479,13 @@ public static function create_document_link(
} else {
// For a "PDF Download" of the file.
$pdfPreview = null;
if ($ext != 'pdf' && !in_array($ext, $webODFList)) {

if (OnlyofficePlugin::create()->isEnabled() &&
OnlyofficePlugin::isExtensionAllowed($document_data['file_extension']) &&
method_exists('OnlyofficeTools', 'getPathToView')
) {
$url = OnlyofficeTools::getPathToView($document_data['id']);
} elseif ($ext != 'pdf' && !in_array($ext, $webODFList)) {
$url = $basePageUrl.'showinframes.php?'.$courseParams.'&id='.$document_data['id'];
} else {
$pdfPreview = Display::url(
Expand Down
4 changes: 2 additions & 2 deletions plugin/onlyoffice/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

$config = [];
$docApiUrl = $appSettings->getDocumentServerApiUrl();
$docId = $_GET['docId'];
$groupId = isset($_GET['groupId']) && !empty($_GET['groupId']) ? $_GET['groupId'] : null;
$docId = (int) $_GET['docId'];
$groupId = isset($_GET['groupId']) && !empty($_GET['groupId']) ? (int) $_GET['groupId'] : (!empty($_GET['gidReq']) ? (int) $_GET['gidReq'] : null);
$userId = api_get_user_id();
$userInfo = api_get_user_info($userId);
$sessionId = api_get_session_id();
Expand Down
6 changes: 2 additions & 4 deletions plugin/onlyoffice/lib/onlyofficeTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ public static function getPathToView(int $documentId, bool $showHeaders = true):
$docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId);
$isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo['code'], $groupProperties, $docInfoGroup);

$urlToEdit = $urlToEdit.'?groupId='.$groupId.'&';
$urlToEdit = $urlToEdit.'?'.api_get_cidreq().'&';
} else {
$urlToEdit = $urlToEdit.'?';
$urlToEdit = $urlToEdit.'?'.api_get_cidreq().'&';
}
error_log(__LINE__.' '.$urlToEdit);

$isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo['absolute_parent_path'], $sessionId);

Expand All @@ -203,7 +202,6 @@ public static function getPathToView(int $documentId, bool $showHeaders = true):
}

if ($canView && !$accessRights) {
error_log(__LINE__.' '.$urlToEdit);

return $urlToEdit;
}
Expand Down

0 comments on commit ab1f124

Please sign in to comment.