diff --git a/main/newscorm/lp_upload.php b/main/newscorm/lp_upload.php index b46b2c41c6..e627811426 100755 --- a/main/newscorm/lp_upload.php +++ b/main/newscorm/lp_upload.php @@ -35,9 +35,7 @@ if (Request::is_post() && $is_error) { } else if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) { // A file upload has been detected, now deal with the file... - // Directory creation. - $stopping_error = false; $s = $_FILES['user_file']['name']; @@ -66,7 +64,8 @@ if (Request::is_post() && $is_error) { require_once 'scorm.class.php'; $oScorm = new scorm(); $manifest = $oScorm->import_package($_FILES['user_file'], $current_dir); - if (!$manifest) { //if api_set_failure + if (!$manifest) { + //if api_set_failure return api_failure::set_failure(api_failure::get_last_failure()); } if (!empty($manifest)) { @@ -109,13 +108,9 @@ if (Request::is_post() && $is_error) { } } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { // end if is_uploaded_file - - // If file name given to get in claroline/upload/, try importing this way. - + // If file name given to get in /upload/, try importing this way. // A file upload has been detected, now deal with the file... - // Directory creation. - $stopping_error = false; // Escape path with basename so it can only be directly into the claroline/upload directory. @@ -132,7 +127,6 @@ if (Request::is_post() && $is_error) { $result = learnpath::verify_document_size($s); if ($result == true) { return api_failure::set_failure('upload_file_too_big'); - } $type = learnpath::get_package_type($s, basename($s)); diff --git a/main/newscorm/scorm.class.php b/main/newscorm/scorm.class.php index f51a2ae567..46f2dd8f74 100755 --- a/main/newscorm/scorm.class.php +++ b/main/newscorm/scorm.class.php @@ -491,20 +491,26 @@ class scorm extends learnpath */ public function import_package($zip_file_info, $current_dir = '') { - if ($this->debug > 0) { error_log('In scorm::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method', 0); } + if ($this->debug > 0) { + error_log('In scorm::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method', 0); + } $maxFilledSpace = DocumentManager :: get_course_quota(); $zip_file_path = $zip_file_info['tmp_name']; $zip_file_name = $zip_file_info['name']; - if ($this->debug > 1) { error_log('New LP - import_package() - zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name, 0); } + if ($this->debug > 1) { + error_log('New LP - import_package() - zip file path = ' . $zip_file_path . ', zip file name = ' . $zip_file_name, 0); + } $course_rel_dir = api_get_course_path().'/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 = replace_dangerous_char(trim($current_dir),'strict'); // Current dir we are in, inside scorm/ - if ($this->debug > 1) { error_log('New LP - import_package() - current_dir = '.$current_dir, 0); } - //$uploaded_filename = $_FILES['userFile']['name']; + if ($this->debug > 1) { + error_log( 'New LP - import_package() - current_dir = ' . $current_dir, 0); + } + // Get name of the zip file without the extension. if ($this->debug > 1) { error_log('New LP - Received zip file name: '.$zip_file_path, 0); } $file_info = pathinfo($zip_file_name); @@ -521,7 +527,6 @@ class scorm extends learnpath $zipFile = new PclZip($zip_file_path); // Check the zip content (real size and file extension). - $zipContentArray = $zipFile->listContent(); $package_type = ''; @@ -533,17 +538,14 @@ class scorm extends learnpath $realFileSize = 0; foreach ($zipContentArray as $thisContent) { $thisContent['filename']; - //error_log('Looking at '.$thisContent['filename'], 0); if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) { $file = $thisContent['filename']; $this->set_error_msg("File $file contains a PHP script"); - //return api_failure::set_failure('php_file_in_zip_file'); } elseif (stristr($thisContent['filename'], 'imsmanifest.xml')) { //error_log('Found imsmanifest at '.$thisContent['filename'], 0); if ($thisContent['filename'] == basename($thisContent['filename'])) { $at_root = true; } else { - //$this->subdir .= '/'.dirname($thisContent['filename']); if ($this->debug > 2) { error_log("New LP - subdir is now ".$this->subdir, 0); } } $package_type = 'scorm'; @@ -565,14 +567,12 @@ class scorm extends learnpath $slash_count = $tmp_slash_count; } } + $this->subdir .= '/'.dirname($shortest_path); // Do not concatenate because already done above. $manifest = $shortest_path; - if ($this->debug > 1) { error_log('New LP - Package type is now '.$package_type, 0); } - - if ($package_type== '') - // && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM) - { + if ($package_type== '') { + // && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM) if ($this->debug > 1) { error_log('New LP - Package type is empty', 0); } return api_failure::set_failure('not_scorm_content'); } @@ -599,7 +599,9 @@ 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) OR @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories())) { + if (is_dir($course_sys_dir.$new_dir) OR + @mkdir($course_sys_dir.$new_dir, 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, 0); } @@ -609,7 +611,6 @@ class scorm extends learnpath 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); } @@ -618,8 +619,8 @@ class scorm extends learnpath if (!empty($new_dir)) { $new_dir = $new_dir.'/'; } - // Rename files, for example with \\ in it. + // Rename files, for example with \\ in it. if ($this->debug >= 1) { error_log('New LP - try to open: '.$course_sys_dir.$new_dir, 0); } if ($dir = @opendir($course_sys_dir.$new_dir)) { @@ -628,7 +629,9 @@ class scorm extends learnpath if ($file != '.' && $file != '..') { $filetype = 'file'; - if (is_dir($course_sys_dir.$new_dir.$file)) $filetype = 'folder'; + if (is_dir($course_sys_dir . $new_dir . $file)) { + $filetype = 'folder'; + } // TODO: RENAMING FILES CAN BE VERY DANGEROUS SCORM-WISE, avoid that as much as possible! //$safe_file = replace_dangerous_char($file, 'strict'); @@ -640,11 +643,10 @@ class scorm extends learnpath if ($this->debug >= 1) { error_log('and: '.$file, 0); } 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); + $mysubdirs = explode('/', $mydir); $mybasedir = '/'; foreach ($mysubdirs as $mysubdir) { if (!empty($mysubdir)) { @@ -659,7 +661,6 @@ class scorm extends learnpath @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, 0); } } - //set_default_settings($course_sys_dir, $safe_file, $filetype); } } diff --git a/main/upload/form.document.php b/main/upload/form.document.php index d8509f7e82..c7c9e6ff89 100755 --- a/main/upload/form.document.php +++ b/main/upload/form.document.php @@ -34,4 +34,3 @@ api_display_tool_title($nameTools.$add_group_to_title); FOOTER */ Display::display_footer(); -?> diff --git a/main/upload/form.scorm.php b/main/upload/form.scorm.php index 9844c95637..0dddec1aeb 100755 --- a/main/upload/form.scorm.php +++ b/main/upload/form.scorm.php @@ -18,7 +18,8 @@ function get_zip_files_in_garbage() { //ignore } else { while ($entry = readdir($dh)) { - if (substr($entry, 0, 1) == '.') {/* ignore files starting with . */ + if (substr($entry, 0, 1) == '.') { + /* ignore files starting with . */ } else { if (preg_match('/^.*\.zip$/i', $entry)) { $list[] = $entry; @@ -28,6 +29,7 @@ function get_zip_files_in_garbage() { natcasesort($list); closedir($dh); } + return $list; } @@ -70,7 +72,6 @@ if (api_is_platform_admin()) { } $form->addElement('style_submit_button', 'submit', get_lang('Send'), 'class="upload"'); - $form->addElement('html', '


'); if (is_dir(api_get_path(PLUGIN_PATH)."/pens")) { @@ -87,8 +88,11 @@ if (is_dir(api_get_path(PLUGIN_PATH)."/pens")) { // the default values for the form $defaults = array('index_document' => 'checked="checked"', 'use_max_score' => 1); $form->setDefaults($defaults); -Display::display_normal_message(Display::tag('strong', get_lang('SupportedScormContentMakers')).': '.implode(', ', $content_origins), false); +Display::display_normal_message( + Display::tag('strong', get_lang('SupportedScormContentMakers')).': '.implode(', ', $content_origins), + false +); $form->display(); // footer -Display::display_footer(); \ No newline at end of file +Display::display_footer(); diff --git a/main/upload/index.php b/main/upload/index.php index 11f0311fe1..90a9d7993b 100755 --- a/main/upload/index.php +++ b/main/upload/index.php @@ -54,49 +54,32 @@ if(!$is_allowed_to_edit){ api_not_allowed(true); } - -/* - Libraries -*/ - -//many useful functions in main_api.lib.php, by default included - require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'); require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php'); -/* - Variables - - some need defining before inclusion of libraries -*/ -$courseDir = $_course['path']."/document"; +$courseDir = $_course['path'] . "/document"; $sys_course_path = api_get_path(SYS_COURSE_PATH); -$base_work_dir = $sys_course_path.$courseDir; -$noPHP_SELF=true; +$base_work_dir = $sys_course_path . $courseDir; +$noPHP_SELF = true; $max_filled_space = DocumentManager::get_course_quota(); //what's the current path? -if(isset($_REQUEST['curdirpath'])) { - $path = $_REQUEST['curdirpath']; -}else{ - $path = '/'; +if (isset($_REQUEST['curdirpath'])) { + $path = $_REQUEST['curdirpath']; +} else { + $path = '/'; } // set calling tool -if(isset($_REQUEST['tool'])) { - $my_tool = $_REQUEST['tool']; - $_SESSION['my_tool'] = $_REQUEST['tool']; -}elseif(!empty($_SESSION['my_tool'])){ - $my_tool = $_SESSION['my_tool']; -}else{ - $my_tool = 'document'; - $_SESSION['my_tool'] = $my_tool; +if (isset($_REQUEST['tool'])) { + $my_tool = $_REQUEST['tool']; + $_SESSION['my_tool'] = $_REQUEST['tool']; +} elseif (!empty($_SESSION['my_tool'])) { + $my_tool = $_SESSION['my_tool']; +} else { + $my_tool = 'document'; + $_SESSION['my_tool'] = $my_tool; } -// Check the path -// If the path is not found (no document id), set the path to / -//if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; } - -//$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments); - /** * Process */ @@ -114,15 +97,15 @@ $htmlHeadXtra[] = '