Browse Source

Minor - Format code

Angel Fernando Quiroz Campos 6 years ago
parent
commit
fcdd6fef6e
1 changed files with 74 additions and 67 deletions
  1. 74 67
      main/lp/scorm.class.php

+ 74 - 67
main/lp/scorm.class.php

@@ -590,8 +590,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
@@ -599,55 +599,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) {
@@ -661,29 +664,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'))
             );
@@ -691,7 +694,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');
             }
@@ -704,20 +707,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 */
@@ -727,15 +730,18 @@ 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);
+                error_log('New LP - Changing dir to '.$courseSysDir.$newDir);
             }
-            $saved_dir = getcwd();
-            chdir($course_sys_dir.$new_dir);
+            $savedDir = getcwd();
+            chdir($courseSysDir.$newDir);
             $unzippingState = $zipFile->extract();
 
             for ($j = 0; $j < count($unzippingState); $j++) {
@@ -747,34 +753,34 @@ class scorm extends learnpath
                 }
             }
 
-            if (!empty($new_dir)) {
-                $new_dir = $new_dir.'/';
+            if (!empty($newDir)) {
+                $newDir = $newDir.'/';
             }
 
             // Rename files, for example with \\ in it.
             if ($this->debug >= 1) {
-                error_log('New LP - try to open: '.$course_sys_dir.$new_dir);
+                error_log('New LP - try to open: '.$courseSysDir.$newDir);
             }
 
-            if ($dir = @opendir($course_sys_dir.$new_dir)) {
+            if ($dir = @opendir($courseSysDir.$newDir)) {
                 if ($this->debug >= 1) {
-                    error_log('New LP - Opened dir '.$course_sys_dir.$new_dir);
+                    error_log('New LP - Opened dir '.$courseSysDir.$newDir);
                 }
                 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);
+                        //$safeFile = api_replace_dangerous_char($file, 'strict');
+                        $findStr = ['\\', '.php', '.phtml'];
+                        $replStr = ['/', '.txt', '.txt'];
+                        $safeFile = str_replace($findStr, $replStr, $file);
 
                         if ($this->debug >= 1) {
-                            error_log('Comparing:  '.$safe_file);
+                            error_log('Comparing:  '.$safeFile);
                             error_log('and:  '.$file);
                         }
 
-                        if ($safe_file != $file) {
-                            $mydir = dirname($course_sys_dir.$new_dir.$safe_file);
+                        if ($safeFile != $file) {
+                            $mydir = dirname($courseSysDir.$newDir.$safeFile);
                             if (!is_dir($mydir)) {
                                 $mysubdirs = explode('/', $mydir);
                                 $mybasedir = '/';
@@ -790,10 +796,11 @@ class scorm extends learnpath
                                     }
                                 }
                             }
-                            @rename($course_sys_dir.$new_dir.$file, $course_sys_dir.$new_dir.$safe_file);
+                            @rename($courseSysDir.$newDir.$file, $courseSysDir.$newDir.$safeFile);
                             if ($this->debug >= 1) {
                                 error_log(
-                                    'New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file
+                                    'New LP - Renaming '.$courseSysDir.$newDir.$file.' to '.$courseSysDir.$newDir
+                                        .$safeFile
                                 );
                             }
                         }
@@ -801,18 +808,18 @@ class scorm extends learnpath
                 }
 
                 closedir($dir);
-                chdir($saved_dir);
+                chdir($savedDir);
 
-                api_chmod_R($course_sys_dir.$new_dir, api_get_permissions_for_new_directories());
+                api_chmod_R($courseSysDir.$newDir, api_get_permissions_for_new_directories());
                 if ($this->debug > 1) {
-                    error_log('New LP - changed back to init dir: '.$course_sys_dir.$new_dir);
+                    error_log('New LP - changed back to init dir: '.$courseSysDir.$newDir);
                 }
             }
         } else {
             return false;
         }
 
-        return $course_sys_dir.$new_dir.$manifest;
+        return $courseSysDir.$newDir.$manifest;
     }
 
     /**