Skip to content

Commit

Permalink
PDF view with viewerjs in LP
Browse files Browse the repository at this point in the history
  • Loading branch information
aragonc committed Nov 8, 2018
1 parent 92962a9 commit ad1ecb2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main/inc/lib/link.lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1564,6 +1564,24 @@ public static function is_youtube_link($url)
return $is_youtube_link; return $is_youtube_link;
} }


/**
* This function checks if the url is a PDF File link.
*
* @author Jorge Frisancho
* @author Alex Aragón - Fixing code
*
* @version 1.0
*/
public static function is_pdf_link($url)
{
$is_pdf_link = strrpos($url, ".pdf") || strrpos(
$url,
".PDF"
);

return $is_pdf_link;
}

/** /**
* Get youtube id from an URL. * Get youtube id from an URL.
* *
Expand Down
9 changes: 9 additions & 0 deletions main/lp/learnpath.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3665,6 +3665,14 @@ public function get_link($type = 'http', $item_id = null, $provided_toc = false)
} }


switch ($lp_item_type) { switch ($lp_item_type) {
case 'document':
if(api_get_configuration_value('allow_pdf_viewerjs_in_lp')){
if(Link::is_pdf_link($file)){
$pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file;
$file = $pdfUrl;
}
}
break;
case 'dir': case 'dir':
$file = 'lp_content.php?type=dir'; $file = 'lp_content.php?type=dir';
break; break;
Expand Down Expand Up @@ -3742,6 +3750,7 @@ public function get_link($type = 'http', $item_id = null, $provided_toc = false)
} }


$tmp_array = explode('/', $file); $tmp_array = explode('/', $file);

$document_name = $tmp_array[count($tmp_array) - 1]; $document_name = $tmp_array[count($tmp_array) - 1];
if (strpos($document_name, '_DELETED_')) { if (strpos($document_name, '_DELETED_')) {
$file = 'blank.php?error=document_deleted'; $file = 'blank.php?error=document_deleted';
Expand Down

0 comments on commit ad1ecb2

Please sign in to comment.