LP: show download link instead of downloading the file directly BT#15131

pull/2757/head^2
Julio Montoya 7 years ago
parent b1974ee3b4
commit 2da99aeb3e
  1. 23
      main/lp/embed.php
  2. 53
      main/lp/learnpath.class.php

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
require_once __DIR__.'/../inc/global.inc.php';
$type = $_REQUEST['type'];
@ -11,6 +13,27 @@ if (empty($type) || empty($src)) {
$iframe = '';
switch ($type) {
case 'download':
/** @var learnpath $learnPath */
$learnPath = Session::read('oLP');
$itemId = isset($_GET['lp_item_id']) ? $_GET['lp_item_id'] : '';
if (!$learnPath || empty($itemId)) {
api_not_allowed();
}
$file = learnpath::rl_get_resource_link_for_learnpath(
api_get_course_int_id(),
$learnPath->get_id(),
$itemId,
$learnPath->get_view_id()
);
$iframe = Display::return_message(
Display::url(get_lang('Download'), $file, ['class' => 'btn btn-primary']),
'info',
false
);
break;
case 'youtube':
$src = '//www.youtube.com/embed/'.$src;
$iframe .= '<div id="content" style="width: 700px ;margin-left:auto; margin-right:auto;"><br />';

@ -3666,10 +3666,18 @@ class learnpath
switch ($lp_item_type) {
case 'document':
if (api_get_configuration_value('allow_pdf_viewerjs_in_lp')) {
if (Link::isPdfLink($file)) {
$pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file;
$file = $pdfUrl;
// Shows a button to download the file instead of just downloading the file directly.
$documentPathInfo = pathinfo($file);
if (isset($documentPathInfo['extension'])) {
$parsed = parse_url($documentPathInfo['extension']);
if (isset($parsed['path'])) {
$extension = $parsed['path'];
$extensionsToDownload = ['zip', 'ppt', 'pptx', 'ods', 'xlsx', 'xls', 'csv'];
if (in_array($extension, $extensionsToDownload)) {
$file = api_get_path(WEB_CODE_PATH).
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
}
}
}
break;
@ -3722,14 +3730,14 @@ class learnpath
$type_quiz = false;
foreach ($list as $toc) {
if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') {
$type_quiz = true;
}
}
if ($type_quiz) {
$lp_item_id = intval($lp_item_id);
$lp_view_id = intval($lp_view_id);
$lp_item_id = (int) $lp_item_id;
$lp_view_id = (int) $lp_view_id;
$sql = "SELECT count(*) FROM $lp_item_view_table
WHERE
c_id = $course_id AND
@ -3749,7 +3757,6 @@ class learnpath
}
$tmp_array = explode('/', $file);
$document_name = $tmp_array[count($tmp_array) - 1];
if (strpos($document_name, '_DELETED_')) {
$file = 'blank.php?error=document_deleted';
@ -13402,18 +13409,15 @@ EOD;
return $main_dir_path.'forum/viewthread.php?post='.$id.'&thread='.$myrow['thread_id'].'&forum='
.$myrow['forum_id'].'&lp=true&'.$extraParams;
case TOOL_READOUT_TEXT:
return api_get_path(WEB_CODE_PATH).'lp/readout_text.php?&id='.$id.'&lp_id='.$learningPathId.'&'
.$extraParams;
return api_get_path(WEB_CODE_PATH).
'lp/readout_text.php?&id='.$id.'&lp_id='.$learningPathId.'&'.$extraParams;
case TOOL_DOCUMENT:
$document = $em
->getRepository('ChamiloCourseBundle:CDocument')
->findOneBy(['cId' => $course_id, 'iid' => $id]);
$repo = $em->getRepository('ChamiloCourseBundle:CDocument');
$document = $repo->findOneBy(['cId' => $course_id, 'iid' => $id]);
if (empty($document)) {
// Try with normal id
$document = $em
->getRepository('ChamiloCourseBundle:CDocument')
->findOneBy(['cId' => $course_id, 'id' => $id]);
$document = $repo->findOneBy(['cId' => $course_id, 'id' => $id]);
if (empty($document)) {
return '';
@ -13421,9 +13425,9 @@ EOD;
}
$documentPathInfo = pathinfo($document->getPath());
$jplayer_supported_files = ['mp4', 'ogv', 'flv', 'm4v'];
$jplayerSupportedFiles = ['mp4', 'ogv', 'flv', 'm4v'];
$extension = isset($documentPathInfo['extension']) ? $documentPathInfo['extension'] : '';
$showDirectUrl = !in_array($extension, $jplayer_supported_files);
$showDirectUrl = !in_array($extension, $jplayerSupportedFiles);
$openmethod = 2;
$officedoc = false;
@ -13431,7 +13435,16 @@ EOD;
Session::write('officedoc', $officedoc);
if ($showDirectUrl) {
return $main_course_path.'document'.$document->getPath().'?'.$extraParams;
$file = $main_course_path.'document'.$document->getPath().'?'.$extraParams;
if (api_get_configuration_value('allow_pdf_viewerjs_in_lp')) {
if (Link::isPdfLink($file)) {
$pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file;
return $pdfUrl;
}
}
return $file;
}
return api_get_path(WEB_CODE_PATH).'document/showinframes.php?id='.$id.'&'.$extraParams;
@ -13456,7 +13469,7 @@ EOD;
}
return $main_dir_path.'work/work.php?'.api_get_cidreq().'&id='.$rowItem->getPath().'&'.$extraParams;
} //end switch
}
return $link;
}

Loading…
Cancel
Save