Skip to content

Commit

Permalink
LPs: Show document protected if link is invisible BT#18135
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Feb 16, 2021
1 parent 702936e commit c40f6b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
46 changes: 25 additions & 21 deletions main/lp/learnpath.class.php
Expand Up @@ -2547,7 +2547,7 @@ class="progress-bar progress-bar-success" role="progressbar"
*/
public function getProgressBar($mode = null)
{
list($percentage, $text_add) = $this->get_progress_bar_text($mode);
[$percentage, $text_add] = $this->get_progress_bar_text($mode);

return self::get_progress_bar($percentage, $text_add);
}
Expand Down Expand Up @@ -3576,7 +3576,7 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
$lp_item_params = $row['liparams'];

if (empty($lp_item_params) && strpos($lp_item_path, '?') !== false) {
list($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
[$lp_item_path, $lp_item_params] = explode('?', $lp_item_path);
}
$sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
if ($type === 'http') {
Expand Down Expand Up @@ -3639,23 +3639,27 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
$file = 'lp_content.php?type=dir&'.api_get_cidreq();
break;
case 'link':
if (Link::is_youtube_link($file)) {
$src = Link::get_youtube_video_id($file);
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=youtube&source='.$src;
} elseif (Link::isVimeoLink($file)) {
$src = Link::getVimeoLinkId($file);
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=vimeo&source='.$src;
} else {
// If the current site is HTTPS and the link is
// HTTP, browsers will refuse opening the link
$urlId = api_get_current_access_url_id();
$url = api_get_access_url($urlId, false);
$protocol = substr($url['url'], 0, 5);
if ($protocol === 'https') {
$linkProtocol = substr($file, 0, 5);
if ($linkProtocol === 'http:') {
//this is the special intervention case
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=nonhttps&source='.urlencode($file);
if (!empty($file)) {
if (Link::is_youtube_link($file)) {
$src = Link::get_youtube_video_id($file);
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=youtube&source='.$src;
} elseif (Link::isVimeoLink($file)) {
$src = Link::getVimeoLinkId($file);
$file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=vimeo&source='.$src;
} else {
// If the current site is HTTPS and the link is
// HTTP, browsers will refuse opening the link
$urlId = api_get_current_access_url_id();
$url = api_get_access_url($urlId, false);
$protocol = substr($url['url'], 0, 5);
if ($protocol === 'https') {
$linkProtocol = substr($file, 0, 5);
if ($linkProtocol === 'http:') {
//this is the special intervention case
$file = api_get_path(
WEB_CODE_PATH
).'lp/embed.php?type=nonhttps&source='.urlencode($file);
}
}
}
}
Expand Down Expand Up @@ -3754,7 +3758,7 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path))) {
// if file not found.
$decoded = html_entity_decode($lp_item_path);
list($decoded) = explode('?', $decoded);
[$decoded] = explode('?', $decoded);
if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded))) {
$file = self::rl_get_resource_link_for_learnpath(
$course_id,
Expand Down Expand Up @@ -4941,7 +4945,7 @@ public function save_last($score = null)

if (!api_is_invitee()) {
// Save progress.
list($progress) = $this->get_progress_bar_text('%');
[$progress] = $this->get_progress_bar_text('%');
$scoreAsProgressSetting = api_get_configuration_value('lp_score_as_progress_enable');
$scoreAsProgress = $this->getUseScoreAsProgress();
if ($scoreAsProgress && $scoreAsProgressSetting && (null === $score || empty($score) || -1 == $score)) {
Expand Down
5 changes: 5 additions & 0 deletions main/lp/lp_view.php
Expand Up @@ -259,6 +259,11 @@
$get_toc_list
);

if (empty($src)) {
$src = 'blank.php?'.api_get_cidreq().'&error=document_protected';
break;
}

// Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
$file_info = parse_url($src);
if (isset($file_info['path'])) {
Expand Down

0 comments on commit c40f6b5

Please sign in to comment.