From ab1f124dfdf3efe812c5ebe2f58a02d0c591f2ec Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 13 Dec 2024 15:37:08 +0100 Subject: [PATCH] Plugin: OnlyOffice: Add OnlyOffice viewer by default for corresponding extensions in documents tool - refs #5395 --- main/inc/lib/document.lib.php | 8 +++++++- plugin/onlyoffice/editor.php | 4 ++-- plugin/onlyoffice/lib/onlyofficeTools.php | 6 ++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 8eb1fd1a977..54a1c9f5de3 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -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( diff --git a/plugin/onlyoffice/editor.php b/plugin/onlyoffice/editor.php index 18b54579f30..5d16ad385bb 100644 --- a/plugin/onlyoffice/editor.php +++ b/plugin/onlyoffice/editor.php @@ -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(); diff --git a/plugin/onlyoffice/lib/onlyofficeTools.php b/plugin/onlyoffice/lib/onlyofficeTools.php index 3bf2b34e70c..037e08e6adf 100644 --- a/plugin/onlyoffice/lib/onlyofficeTools.php +++ b/plugin/onlyoffice/lib/onlyofficeTools.php @@ -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); @@ -203,7 +202,6 @@ public static function getPathToView(int $documentId, bool $showHeaders = true): } if ($canView && !$accessRights) { - error_log(__LINE__.' '.$urlToEdit); return $urlToEdit; }