Prechádzať zdrojové kódy

PDF view with viewerjs in LP

Alex Aragón 6 rokov pred
rodič
commit
ad1ecb2b28
2 zmenil súbory, kde vykonal 27 pridanie a 0 odobranie
  1. 18 0
      main/inc/lib/link.lib.php
  2. 9 0
      main/lp/learnpath.class.php

+ 18 - 0
main/inc/lib/link.lib.php

@@ -1564,6 +1564,24 @@ class Link extends Model
         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.
      *

+ 9 - 0
main/lp/learnpath.class.php

@@ -3665,6 +3665,14 @@ class learnpath
                     }
 
                     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':
                             $file = 'lp_content.php?type=dir';
                             break;
@@ -3742,6 +3750,7 @@ 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';