Browse Source

Update LP from 1.11.x

Julio 6 years ago
parent
commit
272f4a8922

+ 5 - 61
main/lp/aicc.class.php

@@ -439,6 +439,7 @@ class aicc extends learnpath
         $files_found = [];
         $subdir_isset = false;
         // The following loop should be stopped as soon as we found the right config files (.crs, .au, .des and .cst).
+        $realFileSize = 0;
         foreach ($zipContentArray as $thisContent) {
             if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
                 // If a php file is found, do not authorize (security risk).
@@ -576,68 +577,11 @@ class aicc extends learnpath
             if ($this->debug >= 1) {
                 error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0);
             }
-            $saved_dir = getcwd();
             chdir($course_sys_dir.$new_dir);
-            $unzippingState = $zipFile->extract();
-            for ($j = 0; $j < count($unzippingState); $j++) {
-                $state = $unzippingState[$j];
-
-                // TODO: Fix relative links in html files (?)
-                $extension = strrchr($state["stored_filename"], '.');
-                //if ($this->debug > 1) { error_log('New LP - found extension '.$extension.' in '.$state['stored_filename'], 0); }
-            }
-
-            if (!empty($new_dir)) {
-                $new_dir = $new_dir.'/';
-            }
-            // Rename files, for example with \\ in it.
-            if ($dir = @opendir($course_sys_dir.$new_dir)) {
-                if ($this->debug == 1) {
-                    error_log('New LP - Opened dir '.$course_sys_dir.$new_dir, 0);
-                }
-                while ($file = readdir($dir)) {
-                    if ($file != '.' && $file != '..') {
-                        $filetype = 'file';
-
-                        if (is_dir($course_sys_dir.$new_dir.$file)) {
-                            $filetype = 'folder';
-                        }
-
-                        // TODO: RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
-                        //$safe_file = api_replace_dangerous_char($file, 'strict');
-                        $find_str = ['\\', '.php', '.phtml'];
-                        $repl_str = ['/', '.txt', '.txt'];
-                        $safe_file = str_replace($find_str, $repl_str, $file);
-
-                        if ($safe_file != $file) {
-                            //@rename($course_sys_dir.$new_dir, $course_sys_dir.'/'.$safe_file);
-                            $mydir = dirname($course_sys_dir.$new_dir.$safe_file);
-                            if (!is_dir($mydir)) {
-                                $mysubdirs = split('/', $mydir);
-                                $mybasedir = '/';
-                                foreach ($mysubdirs as $mysubdir) {
-                                    if (!empty($mysubdir)) {
-                                        $mybasedir = $mybasedir.$mysubdir.'/';
-                                        if (!is_dir($mybasedir)) {
-                                            @mkdir($mybasedir, api_get_permissions_for_new_directories());
-                                            if ($this->debug == 1) {
-                                                error_log('New LP - Dir '.$mybasedir.' doesnt exist. Creating.');
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                            @rename($course_sys_dir.$new_dir.$file, $course_sys_dir.$new_dir.$safe_file);
-                            if ($this->debug == 1) {
-                                error_log('New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file);
-                            }
-                        }
-                    }
-                }
-
-                closedir($dir);
-                chdir($saved_dir);
-            }
+            $zipFile->extract(
+                PCLZIP_CB_PRE_EXTRACT,
+                'clean_up_files_in_zip'
+            );
         } else {
             return '';
         }

+ 2 - 1
main/lp/aicc_api.php

@@ -35,7 +35,8 @@ require_once __DIR__.'/../inc/global.inc.php';
 
 // Is this needed? This is probabaly done in the header file.
 $file = Session::read('file');
-$oLP = unserialize(Session::read('lpobject'));
+/** @var learnpath $oLP */
+$oLP = UnserializeApi::unserialize('lp', Session::read('lpobject'));
 $oItem = $oLP->items[$oLP->current];
 if (!is_object($oItem)) {
     error_log('New LP - scorm_api - Could not load oItem item', 0);

+ 5 - 1
main/lp/aicc_hacp.php

@@ -63,7 +63,11 @@ if ($debug > 2) {
 
 // Is this needed? This is probabaly done in the header file.
 $file = Session::read('file');
-$oLP = unserialize(Session::read('lpobject'));
+/** @var learnpath $oLP */
+$oLP = UnserializeApi::unserialize(
+    'not_allowed_classes',
+    Session::read('lpobject')
+);
 $oItem = &$oLP->items[$oLP->current];
 if (!is_object($oItem)) {
     error_log('New LP - aicc_hacp - Could not load oItem item', 0);

+ 47 - 48
main/lp/learnpath.class.php

@@ -2040,16 +2040,16 @@ class learnpath
         $nextIcon = '';
         if ($hideArrows === false) {
             $previousIcon = '
-            <a class="icon-toolbar" id="scorm-previous" href="#" 
-                onclick="switch_item('.$mycurrentitemid.',\'previous\');return false;" title="'.$previousText.'">
-                <span class="fa fa-chevron-left"></span><span class="sr-only">'.$previousText.'</span>
-            </a>';
+                <a class="icon-toolbar" id="scorm-previous" href="#" 
+                    onclick="switch_item('.$mycurrentitemid.',\'previous\');return false;" title="'.$previousText.'">
+                    <span class="fa fa-chevron-left"></span><span class="sr-only">'.$previousText.'</span>
+                </a>';
 
             $nextIcon = '
-            <a class="icon-toolbar" id="scorm-next" href="#" 
-                onclick="switch_item('.$mycurrentitemid.',\'next\');return false;" title="'.$nextText.'">
-                <span class="fa fa-chevron-right"></span><span class="sr-only">'.$nextText.'</span>
-            </a>';
+                <a class="icon-toolbar" id="scorm-next" href="#" 
+                    onclick="switch_item('.$mycurrentitemid.',\'next\');return false;" title="'.$nextText.'">
+                    <span class="fa fa-chevron-right"></span><span class="sr-only">'.$nextText.'</span>
+                </a>';
         }
 
         if ($this->mode === 'fullscreen') {
@@ -2315,27 +2315,26 @@ class learnpath
 
             switch ($row['item_type']) {
                 case 'quiz':
-            $type_quiz = false;
-
-            foreach ($list as $toc) {
-                if ($toc['id'] == $_SESSION['oLP']->current) {
-                    $type_quiz = true;
-                }
-            }
+                    $type_quiz = false;
+                    foreach ($list as $toc) {
+                        if ($toc['id'] == $_SESSION['oLP']->current) {
+                            $type_quiz = true;
+                        }
+                    }
 
-            if ($type_quiz) {
-                if ($_SESSION['oLP']->prevent_reinit == 1) {
-                    $autostart_audio = $row['status'] === 'completed' ? 'false' : 'true';
-                } else {
-                    $autostart_audio = $autostart;
-                }
-            }
+                    if ($type_quiz) {
+                        if ($_SESSION['oLP']->prevent_reinit == 1) {
+                            $autostart_audio = $row['status'] === 'completed' ? 'false' : 'true';
+                        } else {
+                            $autostart_audio = $autostart;
+                        }
+                    }
                     break;
                 case TOOL_READOUT_TEXT:;
                     $autostart_audio = 'false';
                     break;
                 default:
-                $autostart_audio = 'true';
+                    $autostart_audio = 'true';
             }
 
             $courseInfo = api_get_course_info();
@@ -2550,19 +2549,19 @@ class learnpath
 
                 // Check if the subscription users/group to a LP is ON
                 if (isset($row['subscribe_users']) && $row['subscribe_users'] == 1 &&
-                $subscriptionSettings['allow_add_users_to_lp'] === true
-            ) {
+                    $subscriptionSettings['allow_add_users_to_lp'] === true
+                ) {
                     // Try group
                     $is_visible = false;
                     // Checking only the user visibility
                     $userVisibility = api_get_item_visibility(
-                    $courseInfo,
-                    'learnpath',
-                    $row['id'],
-                    $sessionId,
-                    $student_id,
-                    'LearnpathSubscription'
-                );
+                        $courseInfo,
+                        'learnpath',
+                        $row['id'],
+                        $sessionId,
+                        $student_id,
+                        'LearnpathSubscription'
+                    );
 
                     if ($userVisibility == 1) {
                         $is_visible = true;
@@ -2572,14 +2571,14 @@ class learnpath
                             foreach ($userGroups as $groupInfo) {
                                 $groupId = $groupInfo['iid'];
                                 $userVisibility = api_get_item_visibility(
-                                $courseInfo,
-                                'learnpath',
-                                $row['id'],
-                                $sessionId,
-                                null,
-                                'LearnpathSubscription',
-                                $groupId
-                            );
+                                    $courseInfo,
+                                    'learnpath',
+                                    $row['id'],
+                                    $sessionId,
+                                    null,
+                                    'LearnpathSubscription',
+                                    $groupId
+                                );
 
                                 if ($userVisibility == 1) {
                                     $is_visible = true;
@@ -3711,7 +3710,7 @@ class learnpath
                     }
                     switch ($lp_item_type) {
                         case 'document':
-
+                            // 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']);
@@ -7432,8 +7431,8 @@ class learnpath
                     case TOOL_DOCUMENT:
                     case TOOL_READOUT_TEXT:
                         $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
-                        $sql_doc = "SELECT path FROM ".$tbl_doc."
-                                    WHERE c_id = ".$course_id." AND iid = ".intval($row['path']);
+                        $sql_doc = "SELECT path FROM $tbl_doc
+                                    WHERE c_id = $course_id AND iid = ".intval($row['path']);
                         $result = Database::query($sql_doc);
                         $path_file = Database::result($result, 0, 0);
                         $path_parts = pathinfo($path_file);
@@ -10162,6 +10161,7 @@ class learnpath
         if (in_array($item_type, [TOOL_DOCUMENT, TOOL_LP_FINAL_ITEM, TOOL_HOTPOTATOES])) {
             $documentData = DocumentManager::get_document_data_by_id($row['path'], $course_code);
             if (empty($documentData)) {
+                // Try with iid
                 $table = Database::get_course_table(TABLE_DOCUMENT);
                 $sql = "SELECT path FROM $table
                         WHERE 
@@ -10968,7 +10968,6 @@ class learnpath
     public function get_forums()
     {
         require_once '../forum/forumfunction.inc.php';
-        require_once '../forum/forumconfig.inc.php';
 
         $forumCategories = get_forum_categories();
         $forumsInNoCategory = get_forums_in_category(0);
@@ -12689,7 +12688,7 @@ EOD;
         $learnPath = null;
         $lpObject = Session::read('lpobject');
         if ($lpObject !== null) {
-            $learnPath = unserialize($lpObject);
+            $learnPath = UnserializeApi::unserialize('lp', $lpObject);
             if ($debug) {
                 error_log('getLpFromSession: unserialize');
                 error_log('------getLpFromSession------');
@@ -13492,9 +13491,9 @@ EOD;
                 }
 
                 $documentPathInfo = pathinfo($document->getPath());
-                $jplayerSupportedFiles = ['mp4', 'ogv', 'flv', 'm4v'];
+                $mediaSupportedFiles = ['mp3', 'mp4', 'ogv', 'flv', 'm4v'];
                 $extension = isset($documentPathInfo['extension']) ? $documentPathInfo['extension'] : '';
-                $showDirectUrl = !in_array($extension, $jplayerSupportedFiles);
+                $showDirectUrl = !in_array($extension, $mediaSupportedFiles);
 
                 $openmethod = 2;
                 $officedoc = false;
@@ -13536,7 +13535,7 @@ EOD;
                 }
 
                 return $main_dir_path.'work/work.php?'.api_get_cidreq().'&id='.$rowItem->getPath().'&'.$extraParams;
-        } //end switch
+        }
 
         return $link;
     }

+ 2 - 1
main/lp/lp_controller.php

@@ -214,7 +214,8 @@ if (!empty($lpObject)) {
     if ($debug) {
         error_log(' SESSION[lpobject] is defined');
     }
-    $oLP = unserialize($lpObject);
+    /** @var learnpath $oLP */
+    $oLP = UnserializeApi::unserialize('lp', $lpObject);
     if (isset($oLP) && is_object($oLP)) {
         if ($debug) {
             error_log(' oLP is object');

+ 1 - 1
main/lp/lp_edit.php

@@ -158,7 +158,7 @@ $form->addElement('html', '<div class="help-block">'.get_lang('LpPrerequisiteDes
 $form->addElement('html', '</div>');
 $form->addElement('html', '<div class="col-md-2"></div>');
 $form->addElement('html', '</div>');
-//Start date
+
 // Time Control
 if (Tracking::minimunTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
     $accumulateTime = $_SESSION['oLP']->getAccumulateWorkTime();

+ 9 - 12
main/lp/lp_nav.php

@@ -50,17 +50,14 @@ if ($myLP) {
     $progress_bar = $myLP->getProgressBar();
     $navigation_bar = $myLP->get_navigation_bar();
     $mediaplayer = $myLP->get_mediaplayer($lpItemId, $autostart);
+
+    if ($mediaplayer) {
+        echo $mediaplayer;
+        echo "<script>
+            $(function() {
+                jQuery('video:not(.skip), audio:not(.skip)').mediaelementplayer();
+            });
+        </script>";
+    }
 }
 session_write_close();
-?>
-<script>
-    $(document).ready(function() {
-        jQuery('video:not(.skip), audio:not(.skip)').mediaelementplayer({
-            success: function(player, node) {
-            }
-        });
-    });
-</script>
-<span>
-    <?php echo !empty($mediaplayer) ? $mediaplayer : '&nbsp;'; ?>
-</span>

+ 6 - 5
main/lp/lp_update_scorm.php

@@ -8,13 +8,14 @@
  *
  * @package chamilo.learnpath
  */
-$this_section = SECTION_COURSES;
-
 require_once __DIR__.'/../inc/global.inc.php';
 
+$this_section = SECTION_COURSES;
+
 api_protect_course_script();
+
 $allow = api_is_allowed_to_edit(null, true);
-$lpId = !empty($_GET['lp_id']) ? intval($_GET['lp_id']) : 0;
+$lpId = !empty($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
 
 if (!$allow || empty($lpId)) {
     api_not_allowed(true);
@@ -44,8 +45,8 @@ $form = new FormValidator(
     api_get_self().'?'.api_get_cidreq().'&lp_id='.$lpId,
     '',
     [
-        'id' => "upload_form",
-        'enctype' => "multipart/form-data",
+        'id' => 'upload_form',
+        'enctype' => 'multipart/form-data',
     ]
 );
 $form->addHeader(get_lang('UpdateFile'));

+ 1 - 5
main/lp/lp_view.php

@@ -423,7 +423,7 @@ if (!api_is_invitee()) {
     $progress_bar = $lp->getProgressBar();
 }
 $navigation_bar = $lp->get_navigation_bar();
-$navigation_bar_bottom = $lp->get_navigation_bar("control-bottom", "display:none");
+$navigation_bar_bottom = $lp->get_navigation_bar('control-bottom', 'display:none');
 $mediaplayer = $lp->get_mediaplayer($lp->current, $autostart);
 
 $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
@@ -459,10 +459,6 @@ if ($is_allowed_to_edit) {
         'url' => '#',
         'name' => get_lang('Preview'),
     ];
-}
-
-// Return to course home.
-if ($is_allowed_to_edit) {
     $buttonHomeUrl = 'lp_controller.php?'.api_get_cidreq(true, true, 'course').'&'.http_build_query([
         'isStudentView' => 'false',
         'action' => 'return_to_course_homepage',

+ 1 - 1
main/lp/lp_view_item.php

@@ -24,7 +24,7 @@ $lp = Session::read('oLP');
 
 if (isset($_GET['lp_item_id'])) {
     // Get parameter only came from lp_view.php.
-    $lp_item_id = intval($_GET['lp_item_id']);
+    $lp_item_id = (int) $_GET['lp_item_id'];
     if (is_object($lp)) {
         $src = $lp->get_link('http', $lp_item_id);
     }

+ 75 - 125
main/lp/scorm.class.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Symfony\Component\DomCrawler\Crawler;
+
 /**
  * Defines the scorm class, which is meant to contain the scorm items (nuclear elements).
  *
@@ -94,9 +96,13 @@ class scorm extends learnpath
 
             // UTF-8 is supported by DOMDocument class, this is for sure.
             $xml = api_utf8_encode_xml($xml, $this->manifest_encoding);
-            $doc = new DOMDocument();
-            $res = @$doc->loadXML($xml);
-            if ($res === false) {
+
+            $crawler = new Crawler();
+            $crawler->addXmlContent($xml);
+
+            $xmlErrors = libxml_get_errors();
+
+            if (!empty($xmlErrors)) {
                 if ($this->debug > 0) {
                     error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument');
                 }
@@ -105,10 +111,11 @@ class scorm extends learnpath
             }
 
             if ($this->debug > 1) {
-                error_log('New LP - Called  (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')', 0);
+                error_log('New LP - Called  (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0);
             }
 
-            $root = $doc->documentElement;
+            $root = $crawler->getNode(0);
+
             if ($root->hasAttributes()) {
                 $attributes = $root->attributes;
                 if ($attributes->length !== 0) {
@@ -220,8 +227,7 @@ class scorm extends learnpath
                     }
                 }
             }
-            unset($doc);
-        // End parsing using PHP5 DOMXML methods.
+            // End parsing using PHP5 DOMXML methods.
         } else {
             if ($this->debug > 1) {
                 error_log('New LP - Could not open/read file '.$file);
@@ -586,8 +592,8 @@ class scorm extends learnpath
     /**
      * Imports a zip file into the Chamilo structure.
      *
-     * @param string    $zip_file_info     Zip file info as given by $_FILES['userFile']
-     * @param string    $current_dir
+     * @param string    $zipFileInfo       Zip file info as given by $_FILES['userFile']
+     * @param string    $currentDir
      * @param array     $courseInfo
      * @param bool      $updateDirContents
      * @param learnpath $lpToCheck
@@ -595,55 +601,58 @@ class scorm extends learnpath
      * @return string $current_dir Absolute path to the imsmanifest.xml file or empty string on error
      */
     public function import_package(
-        $zip_file_info,
-        $current_dir = '',
+        $zipFileInfo,
+        $currentDir = '',
         $courseInfo = [],
         $updateDirContents = false,
         $lpToCheck = null
     ) {
         if ($this->debug > 0) {
             error_log(
-                'In scorm::import_package('.print_r($zip_file_info, true).',"'.$current_dir.'") method'
+                'In scorm::import_package('.print_r($zipFileInfo, true).',"'.$currentDir.'") method'
             );
         }
 
         $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
         $maxFilledSpace = DocumentManager::get_course_quota($courseInfo['code']);
 
-        $zip_file_path = $zip_file_info['tmp_name'];
-        $zip_file_name = $zip_file_info['name'];
+        $zipFilePath = $zipFileInfo['tmp_name'];
+        $zipFileName = $zipFileInfo['name'];
 
         if ($this->debug > 1) {
-            error_log('New LP - import_package() - zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name, 0);
+            error_log(
+                'New LP - import_package() - zip file path = '.$zipFilePath.', zip file name = '.$zipFileName,
+                0
+            );
         }
 
-        $course_rel_dir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
-        $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // Absolute system path for this course.
-        $current_dir = api_replace_dangerous_char(trim($current_dir)); // Current dir we are in, inside scorm/
+        $courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
+        $courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course.
+        $currentDir = api_replace_dangerous_char(trim($currentDir)); // Current dir we are in, inside scorm/
 
         if ($this->debug > 1) {
-            error_log('New LP - import_package() - current_dir = '.$current_dir, 0);
+            error_log('New LP - import_package() - current_dir = '.$currentDir, 0);
         }
 
         // Get name of the zip file without the extension.
-        $file_info = pathinfo($zip_file_name);
-        $filename = $file_info['basename'];
-        $extension = $file_info['extension'];
-        $file_base_name = str_replace('.'.$extension, '', $filename); // Filename without its extension.
-        $this->zipname = $file_base_name; // Save for later in case we don't have a title.
-        $new_dir = api_replace_dangerous_char(trim($file_base_name));
-        $this->subdir = $new_dir;
+        $fileInfo = pathinfo($zipFileName);
+        $filename = $fileInfo['basename'];
+        $extension = $fileInfo['extension'];
+        $fileBaseName = str_replace('.'.$extension, '', $filename); // Filename without its extension.
+        $this->zipname = $fileBaseName; // Save for later in case we don't have a title.
+        $newDir = api_replace_dangerous_char(trim($fileBaseName));
+        $this->subdir = $newDir;
         if ($this->debug > 1) {
-            error_log('New LP - Received zip file name: '.$zip_file_path);
+            error_log('New LP - Received zip file name: '.$zipFilePath);
             error_log("New LP - subdir is first set to : ".$this->subdir);
-            error_log("New LP - base file name is : ".$file_base_name);
+            error_log("New LP - base file name is : ".$fileBaseName);
         }
 
-        $zipFile = new PclZip($zip_file_path);
+        $zipFile = new PclZip($zipFilePath);
         // Check the zip content (real size and file extension).
         $zipContentArray = $zipFile->listContent();
-        $package_type = '';
-        $manifest_list = [];
+        $packageType = '';
+        $manifestList = [];
         // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
         $realFileSize = 0;
         foreach ($zipContentArray as $thisContent) {
@@ -657,29 +666,29 @@ class scorm extends learnpath
                         error_log("New LP - subdir is now ".$this->subdir);
                     }
                 }
-                $package_type = 'scorm';
-                $manifest_list[] = $thisContent['filename'];
+                $packageType = 'scorm';
+                $manifestList[] = $thisContent['filename'];
             }
             $realFileSize += $thisContent['size'];
         }
 
         // Now get the shortest path (basically, the imsmanifest that is the closest to the root).
-        $shortest_path = $manifest_list[0];
-        $slash_count = substr_count($shortest_path, '/');
-        foreach ($manifest_list as $manifest_path) {
-            $tmp_slash_count = substr_count($manifest_path, '/');
-            if ($tmp_slash_count < $slash_count) {
-                $shortest_path = $manifest_path;
-                $slash_count = $tmp_slash_count;
+        $shortestPath = $manifestList[0];
+        $slashCount = substr_count($shortestPath, '/');
+        foreach ($manifestList as $manifestPath) {
+            $tmpSlashCount = substr_count($manifestPath, '/');
+            if ($tmpSlashCount < $slashCount) {
+                $shortestPath = $manifestPath;
+                $slashCount = $tmpSlashCount;
             }
         }
 
-        $this->subdir .= '/'.dirname($shortest_path); // Do not concatenate because already done above.
-        $manifest = $shortest_path;
+        $this->subdir .= '/'.dirname($shortestPath); // Do not concatenate because already done above.
+        $manifest = $shortestPath;
         if ($this->debug) {
-            error_log("New LP - Package type is now: '$package_type'");
+            error_log("New LP - Package type is now: '$packageType'");
         }
-        if ($package_type == '') {
+        if ($packageType == '') {
             Display::addFlash(
                 Display::return_message(get_lang('NotScormContent'))
             );
@@ -687,7 +696,7 @@ class scorm extends learnpath
             return false;
         }
 
-        if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
+        if (!enough_size($realFileSize, $courseSysDir, $maxFilledSpace)) {
             if ($this->debug > 1) {
                 error_log('New LP - Not enough space to store package');
             }
@@ -700,20 +709,20 @@ class scorm extends learnpath
 
         if ($updateDirContents && $lpToCheck) {
             $originalPath = str_replace('/.', '', $lpToCheck->path);
-            if ($originalPath != $new_dir) {
+            if ($originalPath != $newDir) {
                 Display::addFlash(Display::return_message(get_lang('FileError')));
 
                 return false;
             }
         }
 
-        // It happens on Linux that $new_dir sometimes doesn't start with '/'
-        if ($new_dir[0] != '/') {
-            $new_dir = '/'.$new_dir;
+        // It happens on Linux that $newDir sometimes doesn't start with '/'
+        if ($newDir[0] != '/') {
+            $newDir = '/'.$newDir;
         }
 
-        if ($new_dir[strlen($new_dir) - 1] == '/') {
-            $new_dir = substr($new_dir, 0, -1);
+        if ($newDir[strlen($newDir) - 1] == '/') {
+            $newDir = substr($newDir, 0, -1);
         }
 
         /* Uncompressing phase */
@@ -723,92 +732,33 @@ class scorm extends learnpath
             - parse & change relative html links
             - make sure the filenames are secure (filter funny characters or php extensions)
         */
-        if (is_dir($course_sys_dir.$new_dir) ||
-            @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories())
+        if (is_dir($courseSysDir.$newDir) ||
+            @mkdir(
+                $courseSysDir.$newDir,
+                api_get_permissions_for_new_directories()
+            )
         ) {
             // PHP method - slower...
             if ($this->debug >= 1) {
-                error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir);
-            }
-            $saved_dir = getcwd();
-            chdir($course_sys_dir.$new_dir);
-            $unzippingState = $zipFile->extract();
-
-            for ($j = 0; $j < count($unzippingState); $j++) {
-                $state = $unzippingState[$j];
-                // TODO: Fix relative links in html files (?)
-                $extension = strrchr($state['stored_filename'], '.');
-                if ($this->debug >= 1) {
-                    error_log('New LP - found extension '.$extension.' in '.$state['stored_filename']);
-                }
+                error_log('New LP - Changing dir to '.$courseSysDir.$newDir);
             }
 
-            if (!empty($new_dir)) {
-                $new_dir = $new_dir.'/';
-            }
+            chdir($courseSysDir.$newDir);
 
-            // Rename files, for example with \\ in it.
-            if ($this->debug >= 1) {
-                error_log('New LP - try to open: '.$course_sys_dir.$new_dir);
-            }
-
-            if ($dir = @opendir($course_sys_dir.$new_dir)) {
-                if ($this->debug >= 1) {
-                    error_log('New LP - Opened dir '.$course_sys_dir.$new_dir);
-                }
-                while ($file = readdir($dir)) {
-                    if ($file != '.' && $file != '..') {
-                        // TODO: RENAMING FILES CAN BE VERY DANGEROUS SCORM-WISE, avoid that as much as possible!
-                        //$safe_file = api_replace_dangerous_char($file, 'strict');
-                        $find_str = ['\\', '.php', '.phtml'];
-                        $repl_str = ['/', '.txt', '.txt'];
-                        $safe_file = str_replace($find_str, $repl_str, $file);
-
-                        if ($this->debug >= 1) {
-                            error_log('Comparing:  '.$safe_file);
-                            error_log('and:  '.$file);
-                        }
-
-                        if ($safe_file != $file) {
-                            $mydir = dirname($course_sys_dir.$new_dir.$safe_file);
-                            if (!is_dir($mydir)) {
-                                $mysubdirs = explode('/', $mydir);
-                                $mybasedir = '/';
-                                foreach ($mysubdirs as $mysubdir) {
-                                    if (!empty($mysubdir)) {
-                                        $mybasedir = $mybasedir.$mysubdir.'/';
-                                        if (!is_dir($mybasedir)) {
-                                            @mkdir($mybasedir, api_get_permissions_for_new_directories());
-                                            if ($this->debug >= 1) {
-                                                error_log('New LP - Dir '.$mybasedir.' doesnt exist. Creating.');
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                            @rename($course_sys_dir.$new_dir.$file, $course_sys_dir.$new_dir.$safe_file);
-                            if ($this->debug >= 1) {
-                                error_log(
-                                    'New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file
-                                );
-                            }
-                        }
-                    }
-                }
-
-                closedir($dir);
-                chdir($saved_dir);
+            $zipFile->extract(
+                PCLZIP_CB_PRE_EXTRACT,
+                'clean_up_files_in_zip'
+            );
 
-                api_chmod_R($course_sys_dir.$new_dir, api_get_permissions_for_new_directories());
-                if ($this->debug > 1) {
-                    error_log('New LP - changed back to init dir: '.$course_sys_dir.$new_dir);
-                }
+            if (!empty($newDir)) {
+                $newDir = $newDir.'/';
             }
+            api_chmod_R($courseSysDir.$newDir, api_get_permissions_for_new_directories());
         } else {
             return false;
         }
 
-        return $course_sys_dir.$new_dir.$manifest;
+        return $courseSysDir.$newDir.$manifest;
     }
 
     /**

+ 11 - 6
main/lp/scorm_api.php

@@ -31,7 +31,10 @@ require_once __DIR__.'/../inc/global.inc.php';
 
 $file = Session::read('file');
 /** @var learnpath $oLP */
-$oLP = unserialize(Session::read('lpobject'));
+$oLP = UnserializeApi::unserialize(
+    'lp',
+    Session::read('lpobject')
+);
 /** @var learnpathItem $oItem */
 $oItem = isset($oLP->items[$oLP->current]) ? $oLP->items[$oLP->current] : null;
 
@@ -235,6 +238,7 @@ $(document).ready(function() {
     olms.info_lms_item[0] = '<?php echo $oItem->get_id(); ?>';
     olms.info_lms_item[1] = '<?php echo $oItem->get_id(); ?>';
 
+
     $("#content_id").load(function() {
         logit_lms('#content_id load event starts');
         olms.info_lms_item[0] = olms.info_lms_item[1];
@@ -387,8 +391,7 @@ function Initialize() {
 function LMSGetValue(param) {
     olms.G_LastError = G_NoError;
     olms.G_LastErrorMessage = 'No error';
-    var result='';
-
+    var result = '';
     // the LMSInitialize is missing
     if (olms.lms_initialized == 0) {
          if (param == 'cmi.core.score.raw') {
@@ -539,7 +542,7 @@ function LMSGetValue(param) {
                         olms.G_LastError = G_NotImplementedError;
                         olms.G_LastErrorString = 'Not implemented yet';
                     }
-                }else if(req_type == 'status'){
+                } else if(req_type == 'status'){
                     result = 'not attempted';
                 }
            } else {
@@ -612,7 +615,9 @@ function LMSGetValue(param) {
         result = '';
         return result;
     }
-    logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
+
+    logit_scorm("LMSGetValue ('"+param+"') returned '"+result+"'",1);
+
     return result;
 }
 
@@ -653,7 +658,7 @@ function LMSSetValue(param, val) {
     } else if ( param == "cmi.core.lesson_location" ) {
         olms.lesson_location = val;
         olms.updatable_vars_list['cmi.core.lesson_location']=true;
-        return_value='true';
+        return_value = 'true';
     } else if ( param == "cmi.core.lesson_status" ) {
         olms.lesson_status = val;
         olms.updatable_vars_list['cmi.core.lesson_status'] = true;