Fixing - PHP warnings, format code.

1.9.x
Julio Montoya 11 years ago
parent e6bb5354e0
commit c9362e4852
  1. 12
      main/newscorm/lp_upload.php
  2. 41
      main/newscorm/scorm.class.php
  3. 1
      main/upload/form.document.php
  4. 12
      main/upload/form.scorm.php
  5. 71
      main/upload/index.php
  6. 114
      main/upload/upload.document.php
  7. 33
      main/upload/upload.php
  8. 66
      main/upload/upload.scorm.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));

@ -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);
}
}

@ -34,4 +34,3 @@ api_display_tool_title($nameTools.$add_group_to_title);
FOOTER
*/
Display::display_footer();
?>

@ -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', '<br /><br /><br />');
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();
Display::display_footer();

@ -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[] = '<script type="text/javascript">
/**
* Now call the corresponding display script, the current script acting like a controller.
*/
switch($my_tool){
case TOOL_LEARNPATH:
require('form.scorm.php');
break;
//the following cases need to be distinguished later on
case TOOL_DROPBOX:
case TOOL_STUDENTPUBLICATION:
case TOOL_DOCUMENT:
default:
require('form.document.php');
break;
}
switch ($my_tool) {
case TOOL_LEARNPATH:
require('form.scorm.php');
break;
//the following cases need to be distinguished later on
case TOOL_DROPBOX:
case TOOL_STUDENTPUBLICATION:
case TOOL_DOCUMENT:
default:
require('form.document.php');
break;
}

@ -17,108 +17,130 @@
*/
//many useful functions in main_api.lib.php, by default included
if(!function_exists('api_get_path')){header('location: upload.php');die;}
if (!function_exists('api_get_path')) {
header('location: upload.php');
die;
}
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
require_once '../document/document.inc.php';
$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($_POST['curdirpath'])) {
$path = $_POST['curdirpath'];
}else{
$path = '/';
if (isset($_POST['curdirpath'])) {
$path = $_POST['curdirpath'];
} else {
$path = '/';
}
// Check the path
// If the path is not found (no document id), set the path to /
if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; }
if (!DocumentManager::get_document_id($_course, $path)) {
$path = '/';
}
/**
* Header
*/
$nameTools = get_lang('UplUploadDocument');
$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments);
Display::display_header($nameTools,"Doc");
$interbreadcrumb[] = array(
"url" => "./document.php?curdirpath=" . urlencode(
$path
) . $req_gid,
"name" => $langDocuments
);
Display::display_header($nameTools, "Doc");
//show the title
api_display_tool_title($nameTools.$add_group_to_title);
api_display_tool_title($nameTools . $add_group_to_title);
/**
* Process
*/
//user has submitted a file
if(isset($_FILES['user_upload'])) {
if (isset($_FILES['user_upload'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
if($upload_ok) {
if ($upload_ok) {
//file got on the server without problems, now process it
$new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$_POST['unzip'],$_POST['if_exists']);
$new_path = handle_uploaded_document(
$_course,
$_FILES['user_upload'],
$base_work_dir,
$_POST['curdirpath'],
$_user['user_id'],
$to_group_id,
$to_user_id,
$_POST['unzip'],
$_POST['if_exists']
);
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
if ($new_path && ($new_comment || $new_title))
if (($docid = DocumentManager::get_document_id($_course, $new_path)))
{
if (($docid = DocumentManager::get_document_id($_course, $new_path))) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_comment) $ct .= ", comment='$new_comment'";
if ($new_title) $ct .= ", title='$new_title'";
Database::query("UPDATE $table_document SET" . substr($ct, 1) .
" WHERE id = '$docid'");
Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'");
}
//check for missing images in html files
$missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
if($missing_files)
{
if ($missing_files) {
//show a form to upload the missing files
Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name']));
}
}
}
//missing images are submitted
if(isset($_POST['submit_image'])) {
if (isset($_POST['submit_image'])) {
$number_of_uploaded_images = count($_FILES['img_file']['name']);
//if images are uploaded
if ($number_of_uploaded_images > 0)
{
if ($number_of_uploaded_images > 0) {
//we could also create a function for this, I'm not sure...
//create a directory for the missing files
$img_directory = str_replace('.','_',$_POST['related_file']."_files");
$missing_files_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$img_directory);
$missing_files_dir = create_unexisting_directory(
$_course,
$_user['user_id'],
api_get_session_id(),
$to_group_id,
$to_user_id,
$base_work_dir,
$img_directory
);
//put the uploaded files in the new directory and get the paths
$paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space);
//open the html file and replace the paths
replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']);
replace_img_path_in_html_file(
$_POST['img_file_path'],
$paths_to_replace_in_file,
$base_work_dir . $_POST['related_file']
);
//update parent folders
item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']);
}
}
//they want to create a directory
if(isset($_POST['create_dir']) && $_POST['dirname']!='')
{
if (isset($_POST['create_dir']) && $_POST['dirname']!='') {
$added_slash = ($path=='/')?'':'/';
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
$created_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']);
if($created_dir)
{
//Display::display_normal_message("<strong>".$created_dir."</strong> was created!");
Display::display_normal_message(get_lang('DirCr'));
$path = $created_dir;
}
else
{
display_error(get_lang('CannotCreateDir'));
}
if ($created_dir) {
Display::display_normal_message(get_lang('DirCr'));
$path = $created_dir;
} else {
display_error(get_lang('CannotCreateDir'));
}
}
if(isset($_GET['createdir']))
{
if (isset($_GET['createdir'])) {
//create the form that asks for the directory name
$new_folder_text = '<form action="'.api_get_self().'" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
@ -128,11 +150,13 @@ if(isset($_GET['createdir']))
$new_folder_text .= '</form>';
//show the form
Display::display_normal_message($new_folder_text);
}
else { //give them a link to create a directory
?>
<p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" /> <?php echo(get_lang('CreateDir'));?></a></p>
<?php
} else { //give them a link to create a directory
?>
<p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" />
<?php echo(get_lang('CreateDir'));?>
</a>
</p>
<?php
}
?>

@ -18,27 +18,30 @@ $language_file[] = 'scorm';
require_once '../inc/global.inc.php';
// return to index if no tool is set
if(empty($_SESSION['my_tool'])){header('location:index.php');}
if (empty($_SESSION['my_tool'])) {
header('location:index.php');
exit;
}
// check access permissions (edit permission is needed to add a document or a LP)
$is_allowed_to_edit = api_is_allowed_to_edit();
if (!$is_allowed_to_edit){
api_not_allowed(true);
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
/**
* Redirect to the correct script to handle this type of upload
*/
switch($_SESSION['my_tool']){
case TOOL_LEARNPATH:
require 'upload.scorm.php';
break;
//the following cases need to be distinguished later on
case TOOL_DROPBOX:
case TOOL_STUDENTPUBLICATION:
case TOOL_DOCUMENT:
default:
require 'upload.document.php';
break;
}
switch ($_SESSION['my_tool']) {
case TOOL_LEARNPATH:
require 'upload.scorm.php';
break;
//the following cases need to be distinguished later on
case TOOL_DROPBOX:
case TOOL_STUDENTPUBLICATION:
case TOOL_DOCUMENT:
default:
require 'upload.document.php';
break;
}

@ -14,42 +14,52 @@ $language_file = 'scorm';
$cwdir = getcwd();
require_once '../newscorm/lp_upload.php';
//reinit current working directory as many functions in upload change it
// Reinit current working directory as many functions in upload change it
chdir($cwdir);
$error = api_failure::get_last_failure();
if ($error == 'upload_file_too_big'){
if ($error == 'upload_file_too_big') {
$msg = urlencode(get_lang('UplFileTooBig'));
$dialogtype = 'error';
}else if ($error=='not_a_learning_path') {
$dialogtype = 'error';
} else {
if ($error == 'not_a_learning_path') {
$msg = urlencode(get_lang('ScormUnknownPackageFormat'));
$dialogtype = 'error';
} elseif ($error == 'not_enough_space') {
$msg = urlencode(get_lang('ScormNotEnoughSpaceInCourseToInstallPackage'));
$dialogtype = 'error';
} elseif ($error == 'not_scorm_content') {
$dialogtype = 'error';
} elseif ($error == 'not_enough_space') {
$msg = urlencode(
get_lang('ScormNotEnoughSpaceInCourseToInstallPackage')
);
$dialogtype = 'error';
} elseif ($error == 'not_scorm_content') {
$msg = urlencode(get_lang('ScormPackageFormatNotScorm'));
$dialogtype = 'error';
} else {
if (api_get_setting('search_enabled')=='true') {
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$specific_fields = get_specific_field_list();
$dialogtype = 'error';
} else {
if (api_get_setting('search_enabled') == 'true') {
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$specific_fields = get_specific_field_list();
foreach ($specific_fields as $specific_field) {
$values = explode(',', trim($_POST[$specific_field['code']]));
if ( !empty($values) ) {
foreach ($values as $value) {
$value = trim($value);
if ( !empty($value) ) {
add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $oScorm->lp_id, $value);
}
}
}
foreach ($specific_fields as $specific_field) {
$values = explode(',', trim($_POST[$specific_field['code']]));
if (!empty($values)) {
foreach ($values as $value) {
$value = trim($value);
if (!empty($value)) {
add_specific_field_value(
$specific_field['id'],
api_get_course_id(),
TOOL_LEARNPATH,
$oScorm->lp_id,
$value
);
}
}
}
}
}
$msg = urlencode(get_lang('UplUploadSucceeded'));
$dialogtype = 'confirmation';
}
$msg = urlencode(get_lang('UplUploadSucceeded'));
$dialogtype = 'confirmation';
}
header('location: ../newscorm/lp_controller.php?action=list&dialog_box='.$msg.'&dialogtype='.$dialogtype);
exit;
header('location: ../newscorm/lp_controller.php?action=list&dialog_box=' . $msg . '&dialogtype=' . $dialogtype);
exit;

Loading…
Cancel
Save