From 187d29667739f1b67745f2bb5fe06c4a02b300a5 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 3 May 2017 16:12:49 +0200 Subject: [PATCH] Format code, remove function_exists, remove count( get_included_files()) --- main/exercise/aiken.php | 2 +- main/exercise/export/aiken/aiken_classes.php | 20 ++++----- .../export/aiken/aiken_import.inc.php | 43 ++++++++++++++----- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/main/exercise/aiken.php b/main/exercise/aiken.php index a13cf3001c..276eeac1e0 100755 --- a/main/exercise/aiken.php +++ b/main/exercise/aiken.php @@ -35,7 +35,7 @@ if ((api_is_allowed_to_edit(null, true))) { if (isset($_POST['submit'])) { $id = aiken_import_file($_FILES['userFile']); if (is_numeric($id) && !empty($id)) { - header('Location: admin.php?' . api_get_cidreq() . '&exerciseId=' . $id); + header('Location: admin.php?'.api_get_cidreq().'&exerciseId='.$id); exit; } } diff --git a/main/exercise/export/aiken/aiken_classes.php b/main/exercise/export/aiken/aiken_classes.php index 5519e8c4c2..18420bb1f8 100755 --- a/main/exercise/export/aiken/aiken_classes.php +++ b/main/exercise/export/aiken/aiken_classes.php @@ -7,20 +7,16 @@ * @package chamilo.exercise */ -if ( count( get_included_files() ) == 1 ) die( '---' ); - -if (!function_exists('mime_content_type')) { - - /** - * @param string $filename - * @return string - */ - function mime_content_type($filename) - { - return DocumentManager::file_get_mime_type((string)$filename); - } +/** + * @param string $filename + * @return string + */ +function mime_content_type($filename) +{ + return DocumentManager::file_get_mime_type((string) $filename); } + /** * Aiken2Question transformation class */ diff --git a/main/exercise/export/aiken/aiken_import.inc.php b/main/exercise/export/aiken/aiken_import.inc.php index f0ba8578e6..b8fcb16810 100755 --- a/main/exercise/export/aiken/aiken_import.inc.php +++ b/main/exercise/export/aiken/aiken_import.inc.php @@ -8,11 +8,6 @@ * @package chamilo.exercise */ -/** - * Security check - */ -if (count(get_included_files()) == 1) - die('---'); /** * Creates a temporary directory @@ -84,18 +79,45 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) return false; } - if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1, 'overwrite', false)) { + if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && + handle_uploaded_document( + $_course, + $_FILES['userFile'], + $baseWorkDir, + $uploadPath, + $_user['user_id'], + 0, + null, + 1, + 'overwrite', + false + ) + ) { if (!function_exists('gzopen')) { return false; } // upload successful return true; - } elseif (preg_match('/.txt/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 0, 'overwrite', false)) { + } elseif (preg_match('/.txt/i', $_FILES['userFile']['name']) && + handle_uploaded_document( + $_course, + $_FILES['userFile'], + $baseWorkDir, + $uploadPath, + $_user['user_id'], + 0, + null, + 0, + 'overwrite', + false + ) + ) { return true; } else { return false; } } + /** * Main function to import the Aiken exercise * @return mixed True on success, error message on failure @@ -103,7 +125,7 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) function aiken_import_exercise($file) { global $exercise_info; - $archive_path = api_get_path(SYS_ARCHIVE_PATH) . 'aiken'; + $archive_path = api_get_path(SYS_ARCHIVE_PATH).'aiken/'; $baseWorkDir = $archive_path; if (!is_dir($baseWorkDir)) { @@ -132,6 +154,7 @@ function aiken_import_exercise($file) } // find the different manifests for each question and parse them + $exerciseHandle = opendir($baseWorkDir); $file_found = false; $operation = false; @@ -267,7 +290,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) } $new_question = false; //make sure it is transformed from iso-8859-1 to utf-8 if in that form - if (!mb_check_encoding($info,'utf-8') && mb_check_encoding($info, 'iso-8859-1')) { + if (!mb_check_encoding($info, 'utf-8') && mb_check_encoding($info, 'iso-8859-1')) { $info = utf8_encode($info); } $exercise_info['question'][$question_index]['type'] = 'MCUA'; @@ -329,7 +352,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) } $total_questions = count($exercise_info['question']); $total_weight = (!empty($_POST['total_weight'])) ? intval($_POST['total_weight']) : 20; - foreach ($exercise_info['question'] as $key => $question) { + foreach ($exercise_info['question'] as $key => $question) { $exercise_info['question'][$key]['weighting'][current(array_keys($exercise_info['question'][$key]['weighting']))] = $total_weight / $total_questions; } return true;