Documents: Fix pdf show in frames show toolbar + clean code BT#18393

pull/3766/head^2
Julio Montoya 5 years ago
parent 3365cdf497
commit ca76bf9550
  1. 156
      main/document/showinframes.php

@ -176,14 +176,14 @@ $frameheight = 135;
if (api_is_course_admin()) { if (api_is_course_admin()) {
$frameheight = 165; $frameheight = 165;
} }
$execute_iframe = true;
$frameReady = Display::getFrameReadyBlock('#mainFrame'); $frameReady = Display::getFrameReadyBlock('#mainFrame');
$web_odf_supported_files = DocumentManager::get_web_odf_extension_list(); $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
// PDF should be displayed with viewerJS // PDF should be displayed with viewerJS
$web_odf_supported_files[] = 'pdf'; $web_odf_supported_files[] = 'pdf';
if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) { if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
$show_web_odf = true; $show_web_odf = true;
$execute_iframe = false;
$htmlHeadXtra[] = ' $htmlHeadXtra[] = '
<script> <script>
resizeIframe = function() { resizeIframe = function() {
@ -194,15 +194,14 @@ if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
$(function() { $(function() {
$(window).resize(resizeIframe()); $(window).resize(resizeIframe());
}); });
</script>' </script>';
;
} }
// Activate code highlight. // Activate code highlight.
$isChatFolder = false; $isChatFolder = false;
if (isset($document_data['parents']) && isset($document_data['parents'][0])) { if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
$chatFolder = $document_data['parents'][0]; $chatFolder = $document_data['parents'][0];
if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') { if (isset($chatFolder['path']) && $chatFolder['path'] === '/chat_files') {
$isChatFolder = true; $isChatFolder = true;
} }
} }
@ -217,17 +216,12 @@ if ($isChatFolder) {
</script>'; </script>';
} }
$execute_iframe = true;
if ($playerSupported) { if ($playerSupported) {
$extension = api_strtolower($pathinfo['extension']); $extension = api_strtolower($pathinfo['extension']);
$execute_iframe = false; $execute_iframe = false;
} }
if ($show_web_odf) { $is_freemind_available = $pathinfo['extension'] === 'mm' && api_get_setting('enable_freemind') === 'true';
$execute_iframe = false;
}
$is_freemind_available = $pathinfo['extension'] == 'mm' && api_get_setting('enable_freemind') == 'true';
if ($is_freemind_available) { if ($is_freemind_available) {
$execute_iframe = false; $execute_iframe = false;
} }
@ -259,27 +253,6 @@ if ($originIsLearnpath) {
$file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file; $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
$file_url_web = $file_url.'?'.api_get_cidreq(); $file_url_web = $file_url.'?'.api_get_cidreq();
if ($show_web_odf) {
echo '<div class="text-center">';
$browser = api_get_navigator();
$pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html?zoom=page-width#'.$file_url;
if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
$pdfUrl = $file_url;
}
echo '<div id="viewerJS">';
echo '<iframe
id="viewerJSContent"
frameborder="0"
allowfullscreen="allowfullscreen"
webkitallowfullscreen
style="width:100%;height:600px;"
src="'.$pdfUrl.'">
</iframe>';
echo '</div>';
echo '</div>';
}
if ($playerSupported) { if ($playerSupported) {
echo DocumentManager::generateMediaPreview($file_url_web, $extension); echo DocumentManager::generateMediaPreview($file_url_web, $extension);
} }
@ -342,42 +315,37 @@ if ($is_freemind_available) {
//fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa" //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
//fo.addVariable("defaultWordWrap","300"); //default 600 //fo.addVariable("defaultWordWrap","300"); //default 600
// //
fo.write("flashcontent"); fo.write("flashcontent");
// ]]> // ]]>
</script> </script>
<?php <?php
} }
if ($execute_iframe) { if (($execute_iframe || $show_web_odf) && !$isChatFolder) {
if ($isChatFolder) { $parentId = $document_data['parent_id'];
$content = Security::remove_XSS(file_get_contents($file_url_sys)); $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parentId;
echo $content; $actionsLeft = Display::url(
} else { Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
$parentId = $document_data['parent_id']; $url
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parentId; );
$actionsLeft = Display::url(
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
$url
);
$groupMemberWithEditRights = false; $groupMemberWithEditRights = false;
$groupId = api_get_group_id(); $groupId = api_get_group_id();
if (!empty($groupId)) { if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId); $groupInfo = GroupManager::get_group_properties($groupId);
if ($groupInfo) { if ($groupInfo) {
$groupMemberWithEditRights = GroupManager::allowUploadEditDocument( $groupMemberWithEditRights = GroupManager::allowUploadEditDocument(
api_get_user_id(), api_get_user_id(),
api_get_course_int_id(), api_get_course_int_id(),
$groupInfo, $groupInfo,
$document_data $document_data
); );
}
} }
}
$allowToEdit = api_is_allowed_to_edit(null, true) || $groupMemberWithEditRights; $allowToEdit = api_is_allowed_to_edit(null, true) || $groupMemberWithEditRights;
if ($allowToEdit) {
if ($allowToEdit) { if (false === $show_web_odf) {
$actionsLeft .= Display::url( $actionsLeft .= Display::url(
Display::return_icon( Display::return_icon(
'edit.png', 'edit.png',
@ -387,36 +355,66 @@ if ($execute_iframe) {
), ),
api_get_path(WEB_CODE_PATH).'document/edit_document.php?'.api_get_cidreq().'&id='.$document_id api_get_path(WEB_CODE_PATH).'document/edit_document.php?'.api_get_cidreq().'&id='.$document_id
); );
}
$titleToShow = addslashes(basename($document_data['title'])); $titleToShow = addslashes(basename($document_data['title']));
$urlDeleteParams = http_build_query(
[
'action' => 'delete_item',
'id' => $parentId,
'deleteid' => $document_data['id'],
]
);
$urlDeleteParams = http_build_query( $actionsLeft .= Display::url(
[ Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_MEDIUM),
'action' => 'delete_item', '#',
'id' => $parentId, [
'deleteid' => $document_data['id'], 'data-item-title' => $titleToShow,
] 'data-href' =>
); api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&'.$urlDeleteParams,
$actionsLeft .= Display::url( 'data-toggle' => 'modal',
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_MEDIUM), 'data-target' => '#confirm-delete',
'#', ]
[ );
'data-item-title' => $titleToShow,
'data-href' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq( if (false === $show_web_odf) {
).'&'.$urlDeleteParams,
'data-toggle' => 'modal',
'data-target' => '#confirm-delete',
]
);
$actionsLeft .= Display::url( $actionsLeft .= Display::url(
Display::return_icon('pdf.png', get_lang('Export2PDF'), [], ICON_SIZE_MEDIUM), Display::return_icon('pdf.png', get_lang('Export2PDF'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq( api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(
).'&action=export_to_pdf&id='.$document_id ).'&action=export_to_pdf&id='.$document_id
); );
} }
}
echo $toolbar = Display::toolbarAction('actions-documents', [$actionsLeft]);
}
echo $toolbar = Display::toolbarAction('actions-documents', [$actionsLeft]); if ($show_web_odf) {
$execute_iframe = false;
echo '<div class="text-center">';
$browser = api_get_navigator();
$pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html?zoom=page-width#'.$file_url;
if ($browser['name'] === 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
$pdfUrl = $file_url;
}
echo '<div id="viewerJS">';
echo '<iframe
id="viewerJSContent"
frameborder="0"
allowfullscreen="allowfullscreen"
webkitallowfullscreen
style="width:100%;height:600px;"
src="'.$pdfUrl.'">
</iframe>';
echo '</div>';
echo '</div>';
}
if ($execute_iframe) {
if ($isChatFolder) {
$content = Security::remove_XSS(file_get_contents($file_url_sys));
echo $content;
} else {
echo '<iframe echo '<iframe
id="mainFrame" id="mainFrame"
name="mainFrame" name="mainFrame"

Loading…
Cancel
Save