Skip to content

Commit 8bcf1c1

Browse files
committed
LP: Plugin: Allow to show PDF files with onlyoffice when enabled - refs BT#22195 #5917
1 parent 54d55b5 commit 8bcf1c1

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

main/lp/learnpath.class.php

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,43 +3720,33 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
37203720
'odt',
37213721
'dot',
37223722
];
3723-
$officeExtensions = [
3724-
'ppt',
3725-
'pptx',
3726-
'odp',
3727-
'xls',
3728-
'xlsx',
3729-
'ods',
3730-
'csv',
3731-
'doc',
3732-
'docx',
3733-
'odt',
3734-
];
37353723

3736-
if (in_array($extension, $extensionsToDownload)) {
3737-
$found = false;
3738-
if (in_array($extension, $officeExtensions)) {
3739-
$onlyOffice = OnlyofficePlugin::create();
3740-
if ($onlyOffice->isEnabled()) {
3741-
$lpItem = $this->getItem($item_id);
3742-
if ($lpItem->get_type() == 'document') {
3743-
$docId = $lpItem->get_path();
3744-
if (method_exists('OnlyofficeTools', 'getPathToView')) {
3745-
$pathToView = OnlyofficeTools::getPathToView($docId, false);
3746-
// getPathView returns empty on error, so if this is the case,
3747-
// fallback to normal viewer/downloader
3748-
if (!empty($pathToView)) {
3749-
$file = $pathToView;
3750-
$found = true;
3751-
}
3752-
}
3724+
$onlyofficeEditable = false;
3725+
3726+
if (OnlyofficePlugin::create()->isEnabled()) {
3727+
$lpItem = $this->getItem($item_id);
3728+
3729+
if ($lpItem->get_type() == 'document'
3730+
&& OnlyofficePlugin::isExtensionAllowed($extension)
3731+
) {
3732+
$docId = $lpItem->get_path();
3733+
3734+
if (method_exists('OnlyofficeTools', 'getPathToView')) {
3735+
$pathToView = OnlyofficeTools::getPathToView($docId, false);
3736+
// getPathView returns empty on error, so if this is the case,
3737+
// fallback to normal viewer/downloader
3738+
if (!empty($pathToView)) {
3739+
$file = $pathToView;
3740+
$onlyofficeEditable = true;
37533741
}
37543742
}
37553743
}
3756-
if (false === $found) {
3757-
$file = api_get_path(WEB_CODE_PATH).
3758-
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
3759-
}
3744+
}
3745+
3746+
if (in_array($extension, $extensionsToDownload) && false === $onlyofficeEditable) {
3747+
$file = api_get_path(WEB_CODE_PATH)
3748+
.'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'
3749+
.api_get_cidreq();
37603750
}
37613751
}
37623752
}

plugin/onlyoffice/lib/onlyofficePlugin.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,23 @@ public function getPluginName()
121121
{
122122
return $this->pluginName;
123123
}
124+
125+
public static function isExtensionAllowed(string $extension): bool
126+
{
127+
$officeExtensions = [
128+
'ppt',
129+
'pptx',
130+
'odp',
131+
'xls',
132+
'xlsx',
133+
'ods',
134+
'csv',
135+
'doc',
136+
'docx',
137+
'odt',
138+
'pdf',
139+
];
140+
141+
return in_array($extension, $officeExtensions);
142+
}
124143
}

0 commit comments

Comments
 (0)