Skip to content

Commit

Permalink
Merge pull request 'Release/v1.5.0' 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 019e8fa + 15984d5 commit e2dac81
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## 1.5.0
## Added
- support learning path

## 1.4.1
## Changed
- minor fixes
Expand Down
17 changes: 15 additions & 2 deletions editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@
$config = json_decode(json_encode($config), true);
$isMobileAgent = $configService->isMobileAgent($_SERVER['HTTP_USER_AGENT']);

$showHeaders = true;
$headerHeight = 'calc(100% - 140px)';
if (!empty($_GET['nh'])) {
$showHeaders = false;
$headerHeight = '100%';
}

?>
<title>ONLYOFFICE</title>
<style>
#app > iframe {
height: calc(100% - 140px);
height: <?php echo $headerHeight; ?>;
}
body {
height: 100%;
Expand Down Expand Up @@ -172,4 +179,10 @@
}

</script>
<?php echo Display::display_header(); ?>
<?php
if ($showHeaders) {
echo Display::display_header();
} else {
echo Display::display_reduced_header();
}
?>
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.1',
'1.5.0',
'Asensio System SIA',
[
'enable_onlyoffice_plugin' => 'boolean',
Expand Down
60 changes: 60 additions & 0 deletions lib/onlyofficeTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,64 @@ public static function getButtonCreateNew(): string
$urlToCreate
);
}

/**
* Return path to OnlyOffice viewer for a given file.
* @param int $documentId The ID from c_document.iid
* @param bool $showHeaders Whether to show Chamilo headers on top of the OnlyOffice frame or not
*
* @return string A link to open the OnlyOffice viewer
*/
public static function getPathToView(int $documentId, bool $showHeaders = true): string
{
$plugin = OnlyofficePlugin::create();
$appSettings = new OnlyofficeAppsettings($plugin);
$documentManager = new OnlyofficeDocumentManager($appSettings, []);

$isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin');
if (!$isEnable) {
return '';
}

$urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php';

$sessionId = api_get_session_id();
$courseInfo = api_get_course_info();
$userId = api_get_user_id();

$docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId);

$extension = strtolower(pathinfo($docInfo['path'], PATHINFO_EXTENSION));
$canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false;

$isGroupAccess = false;
$groupId = api_get_group_id();
if (!empty($groupId)) {
$groupProperties = GroupManager::get_group_properties($groupId);
$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.'&';
} else {
$urlToEdit = $urlToEdit.'?';
}
error_log(__LINE__.' '.$urlToEdit);

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

$accessRights = $isMyDir || $isGroupAccess;

$urlToEdit = $urlToEdit.'docId='.$documentId;
if (false === $showHeaders) {
$urlToEdit .= '&nh=1';
}

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

return $urlToEdit;
}

return '';
}
}

0 comments on commit e2dac81

Please sign in to comment.