From efc4ecaadf880a6bc06ef49faa83cd1974a6f6b6 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 25 Jan 2013 14:32:45 +0100 Subject: [PATCH] Moving function from fileDisplay.lib.php to fileManage.lib.php --- main/admin/class_import.php | 2 - main/admin/class_list.php | 3 - main/admin/special_exports.php | 35 +- main/admin/user_export.php | 3 +- main/admin/usergroup_user_import.php | 1 - main/auth/profile.php | 1 - .../classes/CourseArchiver.class.php | 8 +- .../classes/CourseRestorer.class.php | 6 +- main/document/document.inc.php | 4 +- main/document/document.php | 19 +- main/document/document_lite.php | 216 ++--- main/document/edit_document.php | 6 +- main/dropbox/dropbox_init.inc.php | 2 +- main/exercice/GC.php | 2 +- main/exercice/exercice.php | 12 +- main/exercice/export/exercise_import.inc.php | 2 +- main/exercice/hotpotatoes.lib.php | 2 +- main/exercice/hotpotatoes.php | 4 +- main/exercice/savescores.php | 2 +- main/exercice/showinframes.php | 2 +- main/inc/ajax/social.ajax.php | 8 +- main/inc/course_document.inc.php | 27 +- main/inc/global.inc.php | 1 - main/inc/lib/document.lib.php | 8 +- .../fckeditor/editor/plugins/MP3/fck_mp3.php | 6 +- .../ajaxfilemanager/ajax_file_paste.php | 8 +- main/inc/lib/fileDisplay.lib.php | 244 ----- main/inc/lib/fileManage.lib.php | 893 ++++++++++-------- .../lib/formvalidator/FormValidator.class.php | 14 +- main/inc/lib/groupmanager.lib.php | 2 +- main/inc/lib/main_api.lib.php | 9 + .../document_processor.class.php | 2 +- .../update-db-scorm-1.6.x-1.8.0.inc.php | 1 - main/metadata/importmanifest.php | 6 +- main/newscorm/aicc.class.php | 4 +- main/newscorm/learnpath_functions.inc.php | 2 +- main/newscorm/resourcelinker.inc.php | 12 +- main/newscorm/scorm.class.php | 4 +- main/resourcelinker/resourcelinker.inc.php | 8 +- main/work/work.lib.php | 4 +- main/work/work.php | 6 +- tests/main/inc/lib/fileDisplay.lib.test.php | 61 +- tests/main/inc/lib/fileManage.lib.test.php | 28 +- tests/main/inc/lib/fileManager.lib.test.php | 28 +- 44 files changed, 713 insertions(+), 1005 deletions(-) mode change 100755 => 100644 main/exercice/GC.php delete mode 100644 main/inc/lib/fileDisplay.lib.php mode change 100755 => 100644 main/metadata/importmanifest.php diff --git a/main/admin/class_import.php b/main/admin/class_import.php index 4ed47d9c34..c665deec7e 100644 --- a/main/admin/class_import.php +++ b/main/admin/class_import.php @@ -54,8 +54,6 @@ $cidReset = true; // Including some necessary dokeos files. include '../inc/global.inc.php'; -require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; -require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'import.lib.php'; // Setting the section (for the tabs). diff --git a/main/admin/class_list.php b/main/admin/class_list.php index b696574d64..f0680f7f39 100644 --- a/main/admin/class_list.php +++ b/main/admin/class_list.php @@ -69,9 +69,6 @@ function modify_filter($class_id) { return $result; } -require api_get_path(LIBRARY_PATH).'fileManage.lib.php'; -require api_get_path(LIBRARY_PATH).'classmanager.lib.php'; - $tool_name = get_lang('ClassList'); $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); diff --git a/main/admin/special_exports.php b/main/admin/special_exports.php index b364a6f195..12cf4f4364 100644 --- a/main/admin/special_exports.php +++ b/main/admin/special_exports.php @@ -3,7 +3,7 @@ /** * Special exports * - * @author Jhon Hinojosa + * @author Jhon Hinojosa * @author Julio Montoya Fixing pclzip folder + some clean * @package chamilo.include.export */ @@ -24,7 +24,6 @@ $nameTools = get_lang('SpecialExports'); // include additional libraries require_once '../document/document.inc.php'; // include additional libraries -require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once '../coursecopy/classes/CourseBuilder.class.php'; require_once '../coursecopy/classes/CourseArchiver.class.php'; require_once '../coursecopy/classes/CourseRestorer.class.php'; @@ -50,30 +49,30 @@ $error =0; $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); -if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) { +if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) { $export = false; if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') { $FileZip = create_zip(); - $to_group_id = 0; + $to_group_id = 0; $sql_session = "SELECT id, name FROM $tbl_session "; $query_session = Database::query($sql_session); $ListSession = array(); while ($rows_session = Database::fetch_assoc($query_session)) { $ListSession[$rows_session['id']] = $rows_session['name']; } - + $zip_folder=new PclZip($FileZip['TEMP_FILE_ZIP']); if(!isset($_POST['resource']) || count($_POST['resource']) == 0 ) { Display::display_error_message(get_lang('ErrorMsgSpecialExport')); } else { $Resource = $_POST['resource']; - + foreach ($Resource as $Code_course => $Sessions) { - $_course = Database::get_course_info($Code_course); + $_course = Database::get_course_info($Code_course); $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_id = $_course['real_id']; - + //Add item to the zip file course $sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props WHERE props.tool='".TOOL_DOCUMENT."' @@ -82,7 +81,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i AND docs.filetype='file' AND docs.session_id = '0' AND props.visibility<>'2' - AND props.to_group_id= $to_group_id AND docs.c_id = $course_id AND props.c_id = $course_id"; + AND props.to_group_id= $to_group_id AND docs.c_id = $course_id AND props.c_id = $course_id"; $query = Database::query($sql ); while ($rows_course_file = Database::fetch_assoc($query)) { $zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'], @@ -90,7 +89,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE'] ); } - + foreach ($Sessions as $IdSession => $value){ $session_id = Security::remove_XSS($IdSession); //Add tem to the zip file session course @@ -129,8 +128,8 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i } if ($export && $name) { - Display::display_confirmation_message(get_lang('BackupCreated')); - echo '
'.get_lang('Download').''; + Display::display_confirmation_message(get_lang('BackupCreated')); + echo '
'.get_lang('Download').''; } else { // Display forms especial export if (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') { @@ -168,7 +167,7 @@ function form_special_export() { function create_zip(){ $path = ''; if(empty($path)) { $path='/'; } - $remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/'; + $remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/'; $sys_archive_path = api_get_path(SYS_ARCHIVE_PATH); $sys_course_path = api_get_path(SYS_COURSE_PATH); $temp_zip_dir = $sys_archive_path."temp"; @@ -211,11 +210,11 @@ function fullexportspecial(){ $list_course = array(); $zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']); $list_course = Database::get_course_list(); - + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); - - + + if (count($list_course) >0 ) { foreach($list_course as $_course) { if($FileZip['PATH'] == '/') { @@ -223,8 +222,8 @@ function fullexportspecial(){ } else { $querypath = $FileZip['PATH']; } - $course_id = $_course['real_id']; - + $course_id = $_course['real_id']; + //Add tem to the zip file course $sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props WHERE props.tool='".TOOL_DOCUMENT."' diff --git a/main/admin/user_export.php b/main/admin/user_export.php index 8d121c01eb..29064c4daf 100644 --- a/main/admin/user_export.php +++ b/main/admin/user_export.php @@ -15,7 +15,6 @@ require_once '../inc/global.inc.php'; $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(); -require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php'; // Database table definitions @@ -94,7 +93,7 @@ if ($form->validate()) { $sql .= " FROM $user_table u ORDER BY lastname,firstname"; } $filename = 'export_users_'.date('Y-m-d_H-i-s'); - } + } $data = array(); $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false); if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') { diff --git a/main/admin/usergroup_user_import.php b/main/admin/usergroup_user_import.php index 4081f1528c..19468ee8f2 100644 --- a/main/admin/usergroup_user_import.php +++ b/main/admin/usergroup_user_import.php @@ -129,7 +129,6 @@ require_once '../inc/global.inc.php'; $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(true); -require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'import.lib.php'; $tool_name = get_lang('AddUsersToAClass') . ' CSV'; diff --git a/main/auth/profile.php b/main/auth/profile.php index 95328443c8..78c925f596 100644 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -96,7 +96,6 @@ EOF; require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; // Libraries -require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile'); diff --git a/main/coursecopy/classes/CourseArchiver.class.php b/main/coursecopy/classes/CourseArchiver.class.php index c5c8968e44..7defce8fc3 100644 --- a/main/coursecopy/classes/CourseArchiver.class.php +++ b/main/coursecopy/classes/CourseArchiver.class.php @@ -91,7 +91,7 @@ class CourseArchiver { foreach ($course->resources[RESOURCE_SCORM] as $id => $document) { $doc_dir = dirname($backup_dir . $document->path); @mkdir($doc_dir, $perm_dirs, true); - copyDirTo($course->path . $document->path, $doc_dir, false); + FileManager::copyDirTo($course->path . $document->path, $doc_dir, false); } } @@ -100,14 +100,14 @@ class CourseArchiver { if (is_array($course->resources[RESOURCE_EVENT])) { $doc_dir = dirname($backup_dir . '/upload/calendar/'); @mkdir($doc_dir, $perm_dirs, true); - copyDirTo($course->path . 'upload/calendar/', $doc_dir, false); + FileManager::copyDirTo($course->path . 'upload/calendar/', $doc_dir, false); } //Copy learningpath author image if (is_array($course->resources[RESOURCE_LEARNPATH])) { $doc_dir = dirname($backup_dir . '/upload/learning_path/'); @mkdir($doc_dir, $perm_dirs, true); - copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false); + FileManager::copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false); } //Copy announcements attachments @@ -115,7 +115,7 @@ class CourseArchiver { if (is_array($course->resources[RESOURCE_ANNOUNCEMENT])) { $doc_dir = dirname($backup_dir . '/upload/announcements/'); @mkdir($doc_dir, $perm_dirs, true); - copyDirTo($course->path . 'upload/announcements/', $doc_dir, false); + FileManager::copyDirTo($course->path . 'upload/announcements/', $doc_dir, false); } // Zip the course-contents diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 61957fa20d..3e6d2b3e22 100644 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -663,7 +663,7 @@ class CourseRestorer switch ($this->file_option) { case FILE_OVERWRITE : rmdirr($path.$document->path); - copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); + FileManager::copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); break; case FILE_SKIP : @@ -692,14 +692,14 @@ class CourseRestorer } rename($this->course->backup_path.'/'.$document->path, $this->course->backup_path.'/'.$new_file_name); - copyDirTo($this->course->backup_path.'/'.$new_file_name, $path.dirname($new_file_name), false); + FileManager::copyDirTo($this->course->backup_path.'/'.$new_file_name, $path.dirname($new_file_name), false); rename($this->course->backup_path.'/'.$new_file_name, $this->course->backup_path.'/'.$document->path); break; } // end switch } // end if file exists else { - copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); + FileManager::copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); } } // end for each } diff --git a/main/document/document.inc.php b/main/document/document.inc.php index 907ed08bd6..56625063b3 100644 --- a/main/document/document.inc.php +++ b/main/document/document.inc.php @@ -121,7 +121,7 @@ function create_document_link($document_data, $show_as_icon = false, $counter = } $filetype = $document_data['filetype']; - $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size']; + $size = $filetype == 'folder' ? FileManager::get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size']; $path = $document_data['path']; $url_path = urlencode($document_data['path']); @@ -363,7 +363,7 @@ function build_document_icon_tag($type, $path) $current_session_id = api_get_session_id(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); if ($type == 'file') { - $icon = choose_image($basename); + $icon = FileManager::choose_image($basename); if (preg_match('/_chnano_.wav$/i', $basename)) { $icon = "jplayer_play.png"; diff --git a/main/document/document.php b/main/document/document.php index 576251779b..e1aaca5425 100644 --- a/main/document/document.php +++ b/main/document/document.php @@ -45,18 +45,7 @@ require_once $lib_path . 'fileDisplay.lib.php'; require_once $lib_path . 'fileManage.lib.php'; api_protect_course_script(true); -/* -Testing time labels -$now = api_get_utc_datetime(); -var_dump(api_convert_and_format_date($now, TIME_NO_SEC_FORMAT)); -var_dump(api_convert_and_format_date($now, DATE_FORMAT_SHORT)); -var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG)); -var_dump(api_convert_and_format_date($now, DATE_FORMAT_NUMBER)); -var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG_24H)); -var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_SHORT)); -var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_SHORT_TIME_FIRST)); -var_dump(api_convert_and_format_date($now, DATE_FORMAT_NUMBER_NO_YEAR)); -*/ + //erase temp nanogons' audio, image edit if(isset($_SESSION['temp_audio_nanogong']) && !empty($_SESSION['temp_audio_nanogong'])) { unlink($_SESSION['temp_audio_nanogong']); @@ -613,8 +602,8 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold if (file_exists($real_path_target)) { $fileExist = true; } - if (move($base_work_dir . $document_to_move['path'], $base_work_dir . $_POST['move_to'])) { - update_db_info('update', $document_to_move['path'], $_POST['move_to'] . '/' . basename($document_to_move['path'])); + if (FileManager::move($base_work_dir . $document_to_move['path'], $base_work_dir . $_POST['move_to'])) { + FileManager::update_db_info('update', $document_to_move['path'], $_POST['move_to'] . '/' . basename($document_to_move['path'])); //update database item property $doc_id = $_POST['move_file']; @@ -1035,7 +1024,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) { $invisibility_span_close = ($is_visible == 0) ? '' : ''; // Size (or total size of a directory) - $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size']; + $size = $document_data['filetype'] == 'folder' ? FileManager::get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size']; // Get the title or the basename depending on what we're using if ($document_data['title'] != '') { diff --git a/main/document/document_lite.php b/main/document/document_lite.php index 78229f4119..6e39708c33 100644 --- a/main/document/document_lite.php +++ b/main/document/document_lite.php @@ -57,7 +57,7 @@ if (api_get_session_id() != 0) { $document_id = intval($_REQUEST['id']); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; - + switch ($action) { case 'download': $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id()); @@ -81,23 +81,23 @@ switch ($action) { // Check visibility of document and paths if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id())) { api_not_allowed(true); - } + } $full_file_name = $base_work_dir.$document_data['path']; if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) { DocumentManager::file_send_for_download($full_file_name, true); } exit; - break; - case 'downloadfolder' : + break; + case 'downloadfolder' : if (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) { $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id()); - + //filter when I am into shared folder, I can donwload only my shared folder - if (is_any_user_shared_folder($document_data['path'], $session_id)) { + if (is_any_user_shared_folder($document_data['path'], $session_id)) { if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){ require 'downloadfolder.inc.php'; } - } else { + } else { require 'downloadfolder.inc.php'; } exit; @@ -106,22 +106,22 @@ switch ($action) { } -//If no actions we proceed to show the document (Hack in order to use document.php?id=X) +//If no actions we proceed to show the document (Hack in order to use document.php?id=X) if (isset($document_id)) { $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true); - + //If the document is not a folder we show the document if ($document_data) { $parent_id = $document_data['parent_id']; - + //$visibility = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id()); $visibility = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id()); - - if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') { - if ($visibility && api_is_allowed_to_session_edit()) { - $url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq(); + + if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') { + if ($visibility && api_is_allowed_to_session_edit()) { + $url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq(); header("Location: $url"); - } + } exit; } else { if (!$visibility && !api_is_allowed_to_edit()) { @@ -130,7 +130,7 @@ if (isset($document_id)) { } $_GET['curdirpath'] = $document_data['path']; } - + // What's the current path? // We will verify this a bit further down if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') { @@ -139,9 +139,9 @@ if (isset($document_id)) { $curdirpath = Security::remove_XSS($_POST['curdirpath']); } else { $curdirpath = '/'; - } + } $curdirpathurl = urlencode($curdirpath); - + } else { // What's the current path? // We will verify this a bit further down @@ -152,19 +152,19 @@ if (isset($document_id)) { } else { $curdirpath = '/'; } - + $curdirpathurl = urlencode($curdirpath); - + // Check the path // If the path is not found (no document id), set the path to / $document_id = DocumentManager::get_document_id($course_info, $curdirpath); - + if (!$document_id) { $document_id = DocumentManager::get_document_id($course_info, $curdirpath); } - - $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true); - $parent_id = $document_data['parent_id']; + + $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true); + $parent_id = $document_data['parent_id']; } $current_folder_id = $document_id; @@ -203,7 +203,7 @@ if ($to_group_id != 0 && $curdirpath == '/') { //if (!$is_allowed_to_edit || api_is_coach()) { before if (!$is_allowed_to_edit && api_is_coach()) { - if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) { + if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) { api_not_allowed(true); } } @@ -231,12 +231,12 @@ if ($is_certificate_mode) { // Interbreadcrumb for the current directory root path if (empty($document_data['parents'])) { - if (isset($_GET['createdir'])) { + if (isset($_GET['createdir'])) { $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']); } else { $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); - } -} else { + } +} else { foreach($document_data['parents'] as $document_sub_data) { if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) { $document_sub_data['document_url'] = '#'; @@ -258,37 +258,37 @@ $file_list = $format_list = ''; $count = 1; if (!empty($docs_and_folders)) -foreach ($docs_and_folders as $file) { +foreach ($docs_and_folders as $file) { if ($file['filetype'] == 'file') { - $path_info = pathinfo($file['path']); + $path_info = pathinfo($file['path']); $extension = strtolower($path_info['extension']); //@todo use a js loop to autogenerate this code if (in_array($extension, array('ogg', 'mp3', 'wav'))) { $document_data = DocumentManager::get_document_data_by_id($file['id'], api_get_course_id()); - + if ($extension == 'ogg') { $extension = 'oga'; - } - $jquery .= ' $("#jquery_jplayer_'.$count.'").jPlayer({ - ready: function() { - $(this).jPlayer("setMedia", { - '.$extension.' : "'.$document_data['direct_url'].'" + } + $jquery .= ' $("#jquery_jplayer_'.$count.'").jPlayer({ + ready: function() { + $(this).jPlayer("setMedia", { + '.$extension.' : "'.$document_data['direct_url'].'" }); - }, + }, swfPath: "'.$js_path.'jquery-jplayer", - supplied: "mp3, m4a, oga, ogv, wav", - solution: "flash, html", // Do not change this setting otherwise - cssSelectorAncestor: "#jp_interface_'.$count.'", + supplied: "mp3, m4a, oga, ogv, wav", + solution: "flash, html", // Do not change this setting otherwise + cssSelectorAncestor: "#jp_interface_'.$count.'", });'."\n\n"; - $count++; - } + $count++; + } } } - + $htmlHeadXtra[] = ''; diff --git a/main/document/edit_document.php b/main/document/edit_document.php index d11390850a..be6571bdbc 100644 --- a/main/document/edit_document.php +++ b/main/document/edit_document.php @@ -492,9 +492,9 @@ Display::display_footer(); function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) { $file_name_for_change = $base_work_dir.$dir.$source_file; - //api_display_debug_info("call my_rename: params $file_name_for_change, $rename_to"); + //api_display_debug_info("call FileManager::my_rename: params $file_name_for_change, $rename_to"); $rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file - $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API + $rename_to = FileManager::my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API if ($rename_to) { if (isset($dir) && $dir != '') { @@ -505,7 +505,7 @@ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) { $new_full_file_name = '/'.$rename_to; } - update_db_info('update', $source_file, $new_full_file_name); // fileManage API + FileManager::update_db_info('update', $source_file, $new_full_file_name); // fileManage API $name_changed = get_lang('ElRen'); $info_message = get_lang('fileModified'); diff --git a/main/dropbox/dropbox_init.inc.php b/main/dropbox/dropbox_init.inc.php index 9dac7904b3..dca6429ace 100644 --- a/main/dropbox/dropbox_init.inc.php +++ b/main/dropbox/dropbox_init.inc.php @@ -64,7 +64,7 @@ require_once 'dropbox_class.inc.php'; // including some libraries that are also used in the documents tool require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; // we use a function build_document_icon_tag -require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function choose_image is used +require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function FileManager::choose_image is used require_once api_get_path(LIBRARY_PATH).'document.lib.php'; diff --git a/main/exercice/GC.php b/main/exercice/GC.php old mode 100755 new mode 100644 index 678a1d7f66..eff68efcea --- a/main/exercice/GC.php +++ b/main/exercice/GC.php @@ -52,7 +52,7 @@ function HotPotGCt($folder,$flag,$userID) { // Garbage Collector if (stristr($val,$userID.".t.html")) { if ($flag == 1) { - my_delete($folder."/".$val); + FileManager::my_delete($folder."/".$val); } else { diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 2bdf89d80d..d3e598d5d9 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -266,16 +266,16 @@ if ($is_allowedToEdit) { GetImgParams($file, $documentPath, $imgparams, $imgcount); $fld = GetFolderName($file); for ($i = 0; $i < $imgcount; $i++) { - my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]); - update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]); + FileManager::my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]); + FileManager::update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]); } - if (my_delete($documentPath . $file)) { - update_db_info("delete", $file); + if (FileManager::my_delete($documentPath . $file)) { + FileManager::update_db_info("delete", $file); } // hotpotatoes folder may contains several tests so don't delete folder if not empty : http://support.chamilo.org/issues/2165 - if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) { - my_delete($documentPath . $uploadPath . "/" . $fld . "/"); + if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !FileManager::folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) { + FileManager::my_delete($documentPath . $uploadPath . "/" . $fld . "/"); } break; case 'enable' : // enables an exercise $newVisibilityStatus = "1"; //"visible" diff --git a/main/exercice/export/exercise_import.inc.php b/main/exercice/export/exercise_import.inc.php index 57e87af6a1..ffa7defbe7 100644 --- a/main/exercice/export/exercise_import.inc.php +++ b/main/exercice/export/exercise_import.inc.php @@ -168,7 +168,7 @@ function import_exercise($file) { $answer->save(); } // delete the temp dir where the exercise was unzipped - my_delete($baseWorkDir . $uploadPath); + FileManager::my_delete($baseWorkDir . $uploadPath); $operation = true; } return $operation; diff --git a/main/exercice/hotpotatoes.lib.php b/main/exercice/hotpotatoes.lib.php index bd658cbd2b..1ddcb4f70c 100644 --- a/main/exercice/hotpotatoes.lib.php +++ b/main/exercice/hotpotatoes.lib.php @@ -417,7 +417,7 @@ function HotPotGCt($folder, $flag, $user_id) { while (list($key, $val) = each($filelist)) { if (stristr($val, $user_id.'.t.html')) { if ($flag == 1) { - my_delete($folder.'/'.$val); + FileManager::my_delete($folder.'/'.$val); } else { echo $folder.'/'.$val.'
'; } diff --git a/main/exercice/hotpotatoes.php b/main/exercice/hotpotatoes.php index 2aca9acb46..9116198e23 100644 --- a/main/exercice/hotpotatoes.php +++ b/main/exercice/hotpotatoes.php @@ -134,8 +134,8 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2))) if ($checked) { $imgcount = $imgcount-1; } else { $dialogBox .= $filename.' '.get_lang('NameNotEqual'); - my_delete($document_sys_path.$uploadPath.'/'.$fld.'/'.$filename); - update_db_info('delete', $uploadPath.'/'.$fld.'/'.$filename); + FileManager::my_delete($document_sys_path.$uploadPath.'/'.$fld.'/'.$filename); + FileManager::update_db_info('delete', $uploadPath.'/'.$fld.'/'.$filename); } if ($imgcount == 0) { // all image uploaded $finish = 1; diff --git a/main/exercice/savescores.php b/main/exercice/savescores.php index 390e6008b3..56f4f409e5 100644 --- a/main/exercice/savescores.php +++ b/main/exercice/savescores.php @@ -30,7 +30,7 @@ require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document"; $full_file_path = $documentPath.$test; -my_delete($full_file_path.$_user['user_id'].".t.html"); +FileManager::my_delete($full_file_path.$_user['user_id'].".t.html"); $TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER); diff --git a/main/exercice/showinframes.php b/main/exercice/showinframes.php index 7790ec52ef..75bbc6c94f 100644 --- a/main/exercice/showinframes.php +++ b/main/exercice/showinframes.php @@ -24,7 +24,7 @@ $time = $_REQUEST['time']; $user_id = api_get_user_id(); $full_file_path = $document_path.$doc_url; -my_delete($full_file_path.$user_id.'.t.html'); +FileManager::my_delete($full_file_path.$user_id.'.t.html'); $content = ReadFileCont($full_file_path.$user_id.'.t.html'); if ($content == '') { diff --git a/main/inc/ajax/social.ajax.php b/main/inc/ajax/social.ajax.php index 68f07c4127..f635488402 100644 --- a/main/inc/ajax/social.ajax.php +++ b/main/inc/ajax/social.ajax.php @@ -18,7 +18,7 @@ switch ($action) { $my_current_friend = Security::remove_XSS($_POST['friend_id']); $my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']); - $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']); + $FileManager::my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']); $friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']); $type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered? $is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered? @@ -43,7 +43,7 @@ switch ($action) { } $my_current_friend = Security::remove_XSS($_POST['friend_id']); $my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']); - $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']); + $FileManager::my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']); $friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']); $type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered? $is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered? @@ -62,9 +62,9 @@ switch ($action) { echo ''; break; } - $my_delete_friend = intval($_POST['delete_friend_id']); + $FileManager::my_delete_friend = intval($_POST['delete_friend_id']); if (isset($_POST['delete_friend_id'])) { - SocialManager::remove_user_rel_user($my_delete_friend); + SocialManager::remove_user_rel_user($FileManager::my_delete_friend); } break; case 'show_my_friends': diff --git a/main/inc/course_document.inc.php b/main/inc/course_document.inc.php index 05b044be47..ba0341c3f2 100644 --- a/main/inc/course_document.inc.php +++ b/main/inc/course_document.inc.php @@ -189,20 +189,13 @@ if ($docs_and_folders) { $invisibility_span_open = ($id['visibility'] == 0) ? '' : ''; //size (or total size of a directory) - $size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id[size]; + $size = $id['filetype'] == 'folder' ? FileManager::get_total_folder_size($id['path'], $is_allowed_to_edit) : $id[size]; //get the title or the basename depending on what we're using if ($id['title'] != '') { $document_name = $id['title']; } else { $document_name = basename($id['path']); } - //$row[] = $key; //testing - //data for checkbox - /* - if ($is_allowed_to_edit AND count($docs_and_folders) > 1) { - $row[] = $id['path']; - } - */ // icons with hyperlinks $row[]= ''.build_document_icon_tag($id['filetype'],$id['path']).''; //document title with hyperlink @@ -212,7 +205,7 @@ if ($docs_and_folders) { $display_size = format_file_size($size); $row[] = ''.$size.''.$invisibility_span_open.$display_size.$invisibility_span_close; //last edit date - $display_date = format_date(strtotime($id['lastedit_date'])); + $display_date = date('d.m.Y', (strtotime($id['lastedit_date']))); $row[] = ''.$id['lastedit_date'].''.$invisibility_span_open.$display_date.$invisibility_span_close; $sortable_data[] = $row; @@ -242,24 +235,12 @@ $table->set_header($column++, api_htmlentities(get_lang('Title'), ENT_QUOTES)); $table->set_header($column++, api_htmlentities(get_lang('Size'), ENT_QUOTES)); $table->set_header($column++, api_htmlentities(get_lang('Date'), ENT_QUOTES)); -//currently only delete action -> take only DELETE right into account -/* -if (count($docs_and_folders) > 1) { - if ($is_allowed_to_edit) { - $form_actions = array(); - $form_action['delete'] = get_lang('Delete'); - $table->set_form_actions($form_action, 'path'); - } -} -*/ - echo api_utf8_encode($table->get_table_html()); echo api_utf8_encode($table_footer); // Functions - ?> - + \ No newline at end of file diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 432826077f..25cff56066 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -201,7 +201,6 @@ if (isset($_configuration['main_database'])) { ) )); - //Setting Doctrine ORM $app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array( "orm.proxies_dir" => $app['db.orm.proxies_dir'], diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 45875be057..98a029a9f5 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -913,9 +913,9 @@ class DocumentManager { self::delete_document_from_db($row['id'], $_course, $current_session_id, true); } //delete documents, do it like this so metadata get's deleted too - //update_db_info('delete', $path); + //FileManager::update_db_info('delete', $path); //throw it away - my_delete($base_work_dir.$path); + FileManager::my_delete($base_work_dir.$path); $file_deleted_from_disk = true; } } else { @@ -1149,7 +1149,7 @@ class DocumentManager { $template_id = Database::result($result,0,0); include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'); - my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg'); + FileManager::my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg'); $sql = 'DELETE FROM '.$table_template.' WHERE course_code="'.$course_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"'; @@ -2890,7 +2890,7 @@ class DocumentManager { if (!is_array($resource)) { $resource = base64_decode($resource); // It's a file. - $icon = choose_image($resource); + $icon = FileManager::choose_image($resource); $position = strrpos($icon, '.'); $icon = substr($icon, 0, $position) . '_small.gif'; $file_info = explode('|@j@|', $resource); diff --git a/main/inc/lib/fckeditor/editor/plugins/MP3/fck_mp3.php b/main/inc/lib/fckeditor/editor/plugins/MP3/fck_mp3.php index f0653ab2fa..d3d07f5997 100644 --- a/main/inc/lib/fckeditor/editor/plugins/MP3/fck_mp3.php +++ b/main/inc/lib/fckeditor/editor/plugins/MP3/fck_mp3.php @@ -47,10 +47,8 @@ include('../../../../../../inc/global.inc.php'); diff --git a/main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/ajax_file_paste.php b/main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/ajax_file_paste.php index a4d77d2c14..0e1ff06661 100644 --- a/main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/ajax_file_paste.php +++ b/main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/ajax_file_paste.php @@ -101,7 +101,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) { } $new_path = $chamiloFolder; //sample /images $dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo - update_db_info('update', $old_path, $new_path); //Chamilo + FileManager::update_db_info('update', $old_path, $new_path); //Chamilo $curdirpath = $new_path; $doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo $current_session_id = api_get_session_id(); @@ -152,7 +152,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) { } $new_path = $chamiloFolder; //sample /images $dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo - update_db_info('update', $old_path, $new_path); //Chamilo + FileManager::update_db_info('update', $old_path, $new_path); //Chamilo $curdirpath = $new_path; $doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo $current_session_id = api_get_session_id(); @@ -164,7 +164,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) { } $new_path = $chamiloFolder; //sample /images/book_highlight.jpg $dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo - update_db_info('update', $old_path, $new_path); //Chamilo + FileManager::update_db_info('update', $old_path, $new_path); //Chamilo //update items $curdirpath = $new_path; $doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo @@ -181,7 +181,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) { $new_path = $chamiloFolder; //sample /images/book_highlight.jpg //update documents $dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo - update_db_info('update', $old_path, $new_path); //Chamilo + FileManager::update_db_info('update', $old_path, $new_path); //Chamilo //update items $curdirpath = $new_path; $doc_id = DocumentManager::get_document_id($_course, $curdirpath); diff --git a/main/inc/lib/fileDisplay.lib.php b/main/inc/lib/fileDisplay.lib.php deleted file mode 100644 index af7a1ea50c..0000000000 --- a/main/inc/lib/fileDisplay.lib.php +++ /dev/null @@ -1,244 +0,0 @@ - - * @param - needle (mixed) - * @param - haystack (array) - * @return - array key or FALSE - * - * @see - http://www.php.net/array_search - */ - function array_search($needle, $haystack) - { - while (list($key, $val) = each($haystack)) - if ($val == $needle) - return $key; - return false; - } -} - -/* FILE DISPLAY FUNCTIONS */ -/** - * Define the image to display for each file extension. - * This needs an existing image repository to work. - * - * @author - Hugues Peeters - * @param - $file_name (string) - Name of a file - * @return - The gif image to chose - */ -function choose_image($file_name) -{ - static $type, $image; - - /* TABLES INITIALISATION */ - if (!$type || !$image) - { - $type['word' ] = array('doc', 'dot', 'rtf', 'mcw', 'wps', 'psw', 'docm', 'docx', 'dotm', 'dotx'); - $type['web' ] = array('htm', 'html', 'htx', 'xml', 'xsl', 'php', 'xhtml'); - $type['image' ] = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'tif', 'tiff'); - $type['image_vect'] = array('svg','svgz'); - $type['audio' ] = array('wav', 'mid', 'mp2', 'mp3', 'midi', 'sib', 'amr', 'kar', 'oga','au','wma'); - $type['video' ] = array('mp4', 'mov', 'rm', 'pls', 'mpg', 'mpeg', 'm2v', 'm4v', 'flv', 'f4v', 'avi', 'wmv', 'asf', '3gp','ogv','ogg','ogx','webm'); - $type['excel' ] = array('xls', 'xlt', 'xls', 'xlt', 'pxl', 'xlsx', 'xlsm', 'xlam', 'xlsb', 'xltm', 'xltx'); - $type['compressed'] = array('zip', 'tar', 'rar', 'gz'); - $type['code' ] = array('js', 'cpp', 'c', 'java', 'phps', 'jsp', 'asp', 'aspx', 'cfm'); - $type['acrobat' ] = array('pdf'); - $type['powerpoint'] = array('ppt', 'pps', 'pptm', 'pptx', 'potm', 'potx', 'ppam', 'ppsm', 'ppsx'); - $type['flash' ] = array('fla', 'swf'); - $type['text' ] = array('txt','log'); - $type['oo_writer' ] = array('odt', 'ott', 'sxw', 'stw'); - $type['oo_calc' ] = array('ods', 'ots', 'sxc', 'stc'); - $type['oo_impress'] = array('odp', 'otp', 'sxi', 'sti'); - $type['oo_draw' ] = array('odg', 'otg', 'sxd', 'std'); - $type['epub' ] = array('epub'); - $type['java' ] = array('class','jar'); - $type['freemind' ] = array('mm'); - - $image['word' ] = 'word.gif'; - $image['web' ] = 'file_html.gif'; - $image['image' ] = 'file_image.gif'; - $image['image_vect'] = 'file_svg.png'; - $image['audio' ] = 'file_sound.gif'; - $image['video' ] = 'film.gif'; - $image['excel' ] = 'excel.gif'; - $image['compressed'] = 'file_zip.gif'; - $image['code' ] = 'icons/22/mime_code.png'; - $image['acrobat' ] = 'file_pdf.gif'; - $image['powerpoint'] = 'powerpoint.gif'; - $image['flash' ] = 'file_flash.gif'; - $image['text' ] = 'icons/22/mime_text.png'; - $image['oo_writer' ] = 'file_oo_writer.gif'; - $image['oo_calc' ] = 'file_oo_calc.gif'; - $image['oo_impress'] = 'file_oo_impress.gif'; - $image['oo_draw' ] = 'file_oo_draw.gif'; - $image['epub' ] = 'file_epub.gif'; - $image['java' ] = 'file_java.png'; - $image['freemind' ] = 'file_freemind.png'; - } - - /* FUNCTION CORE */ - $extension = array(); - if (!is_array($file_name)) { - if (preg_match('/\.([[:alnum:]]+)(\?|$)/', $file_name, $extension)) { - $extension[1] = strtolower($extension[1]); - - foreach ($type as $generic_type => $extension_list) - { - if (in_array($extension[1], $extension_list)) - { - return $image[$generic_type]; - } - } - } - } - return 'defaut.gif'; -} - - -/** - * Transform a UNIX time stamp in human readable format date. - * - * @author - Hugues Peeters - * @param - $date - UNIX time stamp - * @return - A human readable representation of the UNIX date - */ -function format_date($date) -{ - return date('d.m.Y', $date); -} - -/** - * Transform the file path to a URL. - * - * @param - $file_path (string) - Relative local path of the file on the hard disk - * @return - Relative url - */ -function format_url($file_path) -{ - $path_component = explode('/', $file_path); - - $path_component = array_map('rawurlencode', $path_component); - - return implode('/', $path_component); -} - -/** - * Get the most recent time the content of a folder was changed. - * - * @param - $dir_name (string) - Path of the dir on the hard disk - * @param - $do_recursive (bool) - Traverse all folders in the folder? - * @return - Time the content of the folder was changed - */ -function recent_modified_file_time($dir_name, $do_recursive = true) -{ - - $dir = dir($dir_name); - $last_modified = 0; - $return = 0; - if (is_dir($dir)) { - while(($entry = $dir->read()) !== false) - { - if ($entry != '.' && $entry != '..') - continue; - - if (!is_dir($dir_name.'/'.$entry)) - $current_modified = filemtime($dir_name.'/'.$entry); - elseif ($do_recursive) - $current_modified = recent_modified_file_time($dir_name.'/'.$entry, true); - - if ($current_modified > $last_modified) - $last_modified = $current_modified; - } - - $dir->close(); - //prevents returning 0 (for empty directories) - $return = ($last_modified == 0) ? filemtime($dir_name) : $last_modified; - } - return $return; -} - -/** - * Get the total size of a directory. - * - * @param - $dir_name (string) - Path of the dir on the hard disk - * @return - Total size in bytes - */ -function folder_size($dir_name) -{ - $size = 0; - - if ($dir_handle = opendir($dir_name)) - { - while (($entry = readdir($dir_handle)) !== false) - { - if($entry == '.' || $entry == '..') - continue; - - if(is_dir($dir_name.'/'.$entry)) - $size += folder_size($dir_name.'/'.$entry); - else - $size += filesize($dir_name.'/'.$entry); - } - - closedir($dir_handle); - } - - return $size; -} - -/** - * Calculates the total size of a directory by adding the sizes (that - * are stored in the database) of all files & folders in this directory. - * - * @param string $path - * @param boolean $can_see_invisible - * @return Total size - */ -function get_total_folder_size($path, $can_see_invisible = false) { - $table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY); - $table_document = Database::get_course_table(TABLE_DOCUMENT); - $tool_document = TOOL_DOCUMENT; - - $course_id = api_get_course_int_id(); - $session_id = api_get_session_id(); - $session_condition = api_get_session_condition($session_id, true, true, 'props.id_session'); - - $visibility_rule = ' props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1'); - - $sql = "SELECT SUM(table1.size) FROM ( - SELECT size FROM $table_itemproperty AS props, $table_document AS docs - WHERE docs.c_id = $course_id AND - docs.id = props.ref AND - docs.path LIKE '$path/%' AND - props.c_id = $course_id AND - props.tool = '$tool_document' AND - $visibility_rule - $session_condition - GROUP BY ref - ) as table1"; - - $result = Database::query($sql); - if ($result && Database::num_rows($result) != 0) { - $row = Database::fetch_row($result); - return $row[0] == null ? 0 : $row[0]; - } else { - return 0; - } -} \ No newline at end of file diff --git a/main/inc/lib/fileManage.lib.php b/main/inc/lib/fileManage.lib.php index 7835067b6c..853afd4398 100644 --- a/main/inc/lib/fileManage.lib.php +++ b/main/inc/lib/fileManage.lib.php @@ -1,5 +1,6 @@ - * @param - action (string) - action type require : 'delete' or 'update' - * @param - old_path (string) - old path info stored to change - * @param - new_path (string) - new path info to substitute - * @desc Update the file or directory path in the document db document table - * - */ -function update_db_info($action, $old_path, $new_path = '') { - $dbTable = Database::get_course_table(TABLE_DOCUMENT); - $course_id = api_get_course_int_id(); - - /* DELETE */ - if ($action == 'delete') { - - $old_path = Database::escape_string($old_path); - $to_delete = "WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'"; - $query = "DELETE FROM $dbTable " . $to_delete; - - $result = Database::query("SELECT id FROM $dbTable " . $to_delete); - - if (Database::num_rows($result)) { - require_once api_get_path(INCLUDE_PATH).'../metadata/md_funcs.php'; - $mdStore = new mdstore(TRUE); // create if needed + This class contains functions that you can access statically. - $md_type = (substr($dbTable, -13) == 'scormdocument') ? 'Scorm' : 'Document'; + FileManager::list_all_directories($path) + FileManager::list_all_files($dir_array) + FileManager::compat_load_file($file_name) + FileManager::set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v') - while ($row = Database::fetch_array($result)) { - $eid = $md_type . '.' . $row['id']; - $mdStore->mds_delete($eid); - $mdStore->mds_delete_offspring($eid); + @author Roan Embrechts + @version 1.1, July 2004 + * @package chamilo.library +*/ +class FileManager +{ + /** + * Update the file or directory path in the document db document table + * + * @author - Hugues Peeters + * @param - action (string) - action type require : 'delete' or 'update' + * @param - old_path (string) - old path info stored to change + * @param - new_path (string) - new path info to substitute + * @desc Update the file or directory path in the document db document table + * + */ + static function update_db_info($action, $old_path, $new_path = '') { + $dbTable = Database::get_course_table(TABLE_DOCUMENT); + $course_id = api_get_course_int_id(); + + /* DELETE */ + if ($action == 'delete') { + + $old_path = Database::escape_string($old_path); + $to_delete = "WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'"; + $query = "DELETE FROM $dbTable " . $to_delete; + + $result = Database::query("SELECT id FROM $dbTable " . $to_delete); + + if (Database::num_rows($result)) { + require_once api_get_path(INCLUDE_PATH).'../metadata/md_funcs.php'; + $mdStore = new mdstore(TRUE); // create if needed + + $md_type = (substr($dbTable, -13) == 'scormdocument') ? 'Scorm' : 'Document'; + + while ($row = Database::fetch_array($result)) { + $eid = $md_type . '.' . $row['id']; + $mdStore->mds_delete($eid); + $mdStore->mds_delete_offspring($eid); + } } } - } - - /* UPDATE */ - - if ($action == 'update') { - if ($new_path[0] == '.') $new_path = substr($new_path, 1); - $new_path = str_replace('//', '/', $new_path); - - // Attempt to update - tested & working for root dir - $new_path = Database::escape_string($new_path); - $query = "UPDATE $dbTable - SET path = CONCAT('".$new_path."', SUBSTRING(path, LENGTH('".$old_path."')+1) ) - WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'"; - } - Database::query($query); -} - -/** - * Cheks a file or a directory actually exist at this location - * - * @author - Hugues Peeters - * @param - file_path (string) - path of the presume existing file or dir - * @return - boolean TRUE if the file or the directory exists - * boolean FALSE otherwise. - */ -function check_name_exist($file_path) { - clearstatcache(); - $save_dir = getcwd(); - if (!is_dir(dirname($file_path))) { - return false; - } - chdir(dirname($file_path)); - $file_name = basename($file_path); - - if (file_exists($file_name)) { - chdir($save_dir); - return true; - } else { - chdir($save_dir); - return false; - } -} - -/** - * Deletes a file or a directory - * - * @author - Hugues Peeters - * @param - $file (String) - the path of file or directory to delete - * @return - bolean - true if the delete succeed - * bolean - false otherwise. - * @see - delete() uses check_name_exist() and removeDir() functions - */ -function my_delete($file) { - if (check_name_exist($file)) { - if (is_file($file)) { // FILE CASE - unlink($file); - return true; - } elseif (is_dir($file)) { // DIRECTORY CASE - removeDir($file); - return true; - } - } else { - return false; // no file or directory to delete - } -} - -/** - * Removes a directory recursively - * - * @returns true if OK, otherwise false - * - * @author Amary (from Nexen.net) - * @author Olivier Brouckaert - * - * @param string $dir directory to remove - */ -function removeDir($dir) { - if (!@$opendir = opendir($dir)) { - return false; - } - - while ($readdir = readdir($opendir)) { - if ($readdir != '..' && $readdir != '.') { - if (is_file($dir.'/'.$readdir)) { - if (!@unlink($dir.'/'.$readdir)) { - return false; - } - } elseif (is_dir($dir.'/'.$readdir)) { - if (!removeDir($dir.'/'.$readdir)) { - return false; - } - } - } - } - - closedir($opendir); - - if (!@rmdir($dir)) { - return false; - } - return true; -} + /* UPDATE */ + if ($action == 'update') { + if ($new_path[0] == '.') $new_path = substr($new_path, 1); + $new_path = str_replace('//', '/', $new_path); -/** - * Return true if folder is empty - * @author : hubert.borderiou@grenet.fr - * @param string $in_folder : folder path on disk - * @return 1 if folder is empty, 0 otherwise -*/ - -function folder_is_empty($in_folder) { - $tab_folder_content = scandir($in_folder); - $folder_is_empty = 0; - if ((count($tab_folder_content) == 2 && in_array(".", $tab_folder_content) && in_array("..", $tab_folder_content)) || (count($tab_folder_content) < 2)) { - $folder_is_empty = 1; + // Attempt to update - tested & working for root dir + $new_path = Database::escape_string($new_path); + $query = "UPDATE $dbTable + SET path = CONCAT('".$new_path."', SUBSTRING(path, LENGTH('".$old_path."')+1) ) + WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'"; + } + Database::query($query); } - return $folder_is_empty; -} + /** + * Cheks a file or a directory actually exist at this location + * + * @author - Hugues Peeters + * @param - file_path (string) - path of the presume existing file or dir + * @return - boolean TRUE if the file or the directory exists + * boolean FALSE otherwise. + */ + static function check_name_exist($file_path) { + clearstatcache(); + $save_dir = getcwd(); + if (!is_dir(dirname($file_path))) { + return false; + } + chdir(dirname($file_path)); + $file_name = basename($file_path); + + if (file_exists($file_name)) { + chdir($save_dir); + return true; + } else { + chdir($save_dir); + return false; + } + } -/** - * Renames a file or a directory - * - * @author - Hugues Peeters - * @param - $file_path (string) - complete path of the file or the directory - * @param - $new_file_name (string) - new name for the file or the directory - * @return - boolean - true if succeed - * - boolean - false otherwise - * @see - rename() uses the check_name_exist() and php2phps() functions - */ -function my_rename($file_path, $new_file_name) { + /** + * Deletes a file or a directory + * + * @author - Hugues Peeters + * @param - $file (String) - the path of file or directory to delete + * @return - bolean - true if the delete succeed + * bolean - false otherwise. + * @see - delete() uses check_name_exist() and removeDir() functions + */ + static function my_delete($file) { + if (self::check_name_exist($file)) { + if (is_file($file)) { // FILE CASE + unlink($file); + return true; + } elseif (is_dir($file)) { // DIRECTORY CASE + self::removeDir($file); + return true; + } + } else { + return false; // no file or directory to delete + } + } - $save_dir = getcwd(); - $path = dirname($file_path); - $old_file_name = basename($file_path); + /** + * Removes a directory recursively + * + * @returns true if OK, otherwise false + * + * @author Amary (from Nexen.net) + * @author Olivier Brouckaert + * + * @param string $dir directory to remove + */ + static function removeDir($dir) { + if (!@$opendir = opendir($dir)) { + return false; + } - $new_file_name = replace_dangerous_char($new_file_name); + while ($readdir = readdir($opendir)) { + if ($readdir != '..' && $readdir != '.') { + if (is_file($dir.'/'.$readdir)) { + if (!@unlink($dir.'/'.$readdir)) { + return false; + } + } elseif (is_dir($dir.'/'.$readdir)) { + if (!self::removeDir($dir.'/'.$readdir)) { + return false; + } + } + } + } - // If no extension, take the old one - if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) { - $new_file_name .= substr($old_file_name, $dotpos); - } + closedir($opendir); - // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz' - // This is useful for folder names, where otherwise '.' would be sticky + if (!@rmdir($dir)) { + return false; + } - // Extension PHP is not allowed, change to PHPS - $new_file_name = php2phps($new_file_name); + return true; + } - if ($new_file_name == $old_file_name) { - return $old_file_name; - } - if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) { - return false; - } - // On a Windows server, it would be better not to do the above check - // because it succeeds for some new names resembling the old name. - // But on Unix/Linux the check must be done because rename overwrites. + /** + * Return true if folder is empty + * @author : hubert.borderiou@grenet.fr + * @param string $in_folder : folder path on disk + * @return 1 if folder is empty, 0 otherwise + */ - chdir($path); - $res = rename($old_file_name, $new_file_name) ? $new_file_name : false; - chdir($save_dir); - return $res; -} + static function folder_is_empty($in_folder) { + $tab_folder_content = scandir($in_folder); + $folder_is_empty = 0; + if ((count($tab_folder_content) == 2 && in_array(".", $tab_folder_content) && in_array("..", $tab_folder_content)) || (count($tab_folder_content) < 2)) { + $folder_is_empty = 1; + } + return $folder_is_empty; + } -/** - * Moves a file or a directory to an other area - * - * @author - Hugues Peeters - * @param - $source (String) - the path of file or directory to move - * @param - $target (String) - the path of the new area - * @return - bolean - true if the move succeed - * bolean - false otherwise. - * @see - move() uses check_name_exist() and copyDirTo() functions - */ -function move($source, $target) { - if (check_name_exist($source)) { - $file_name = basename($source); + /** + * Renames a file or a directory + * + * @author - Hugues Peeters + * @param - $file_path (string) - complete path of the file or the directory + * @param - $new_file_name (string) - new name for the file or the directory + * @return - boolean - true if succeed + * - boolean - false otherwise + * @see - rename() uses the check_name_exist() and php2phps() functions + */ + static function my_rename($file_path, $new_file_name) { - if (check_name_exist($target.'/'.$file_name)) { - return false; - } else { - /* File case */ - if (is_file($source)) { - copy($source , $target.'/'.$file_name); - unlink($source); - return true; - } - /* Directory case */ - elseif (is_dir($source)) { - // Check to not copy the directory inside itself - if (ereg('^'.$source.'/', $target.'/')) { // TODO: ereg() function is deprecated in PHP 5.3 - return false; - } else { - copyDirTo($source, $target); - return true; - } - } - } - } else { - return false; - } -} + $save_dir = getcwd(); + $path = dirname($file_path); + $old_file_name = basename($file_path); -/** - * Moves a directory and its content to an other area - * - * @author - Hugues Peeters - * @param - $orig_dir_path (string) - the path of the directory to move - * @param - $destination (string) - the path of the new area - * @return - no return - */ -function copyDirTo($orig_dir_path, $destination, $move = true) { - - $save_dir = getcwd(); - // Extract directory name - create it at destination - update destination trail - $dir_name = basename($orig_dir_path); - if (is_dir($orig_dir_path)) { - mkdir($destination.'/'.$dir_name, api_get_permissions_for_new_directories()); - $destination_trail = $destination.'/'.$dir_name; - if (is_dir($destination)) { - chdir ($orig_dir_path) ; - $handle = opendir($orig_dir_path); + $new_file_name = replace_dangerous_char($new_file_name); - while ($element = readdir($handle)) { - if ($element == '.' || $element == '..') { - continue; // Skip the current and parent directories - } elseif (is_file($element)) { - copy($element, $destination_trail.'/'.$element); - - if ($move) { - unlink($element) ; - } - } elseif (is_dir($element)) { - $dir_to_copy[] = $orig_dir_path.'/'.$element; - } - } + // If no extension, take the old one + if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) { + $new_file_name .= substr($old_file_name, $dotpos); + } - closedir($handle) ; + // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz' + // This is useful for folder names, where otherwise '.' would be sticky - if (sizeof($dir_to_copy) > 0) { - foreach ($dir_to_copy as $this_dir) { - copyDirTo($this_dir, $destination_trail, $move); // Recursivity - } - } + // Extension PHP is not allowed, change to PHPS + $new_file_name = php2phps($new_file_name); - if ($move) { - rmdir($orig_dir_path) ; - } - chdir($save_dir); - } - } -} + if ($new_file_name == $old_file_name) { + return $old_file_name; + } -/* NOTE: These functions batch is used to automatically build HTML forms - * with a list of the directories contained on the course Directory. - * - * From a thechnical point of view, form_dir_lists calls sort_dir wich calls index_dir - */ + if (strtolower($new_file_name) != strtolower($old_file_name) && self::check_name_exist($path.'/'.$new_file_name)) { + return false; + } + // On a Windows server, it would be better not to do the above check + // because it succeeds for some new names resembling the old name. + // But on Unix/Linux the check must be done because rename overwrites. + + chdir($path); + $res = rename($old_file_name, $new_file_name) ? $new_file_name : false; + chdir($save_dir); + return $res; + } -/** - * Gets all the directories and subdirectories - * contented in a given directory - * - * @author - Hugues Peeters - * @param - path (string) - directory path of the one to index - * @return - an array containing the path of all the subdirectories - */ -function index_dir($path) { - $dir_array = array(); - $save_dir = getcwd(); - if (is_dir($path)){ - chdir($path); - $handle = opendir($path); - // Reads directory content end record subdirectoies names in $dir_array - if ($handle !== false) { - while ($element = readdir($handle)) { - if ($element == '.' || $element == '..') continue; // Skip the current and parent directories - if (is_dir($element)) $dir_array[] = $path.'/'.$element; - } - closedir($handle) ; - } - // Recursive operation if subdirectories exist - $dir_number = sizeof($dir_array); - if ($dir_number > 0) { - for ($i = 0 ; $i < $dir_number ; $i++) { - $sub_dir_array = index_dir($dir_array[$i]); // Function recursivity - $dir_array = array_merge((array)$dir_array, (array)$sub_dir_array); // Data merge + /** + * Moves a file or a directory to an other area + * + * @author - Hugues Peeters + * @param - $source (String) - the path of file or directory to move + * @param - $target (String) - the path of the new area + * @return - bolean - true if the move succeed + * bolean - false otherwise. + * @see - move() uses check_name_exist() and copyDirTo() functions + */ + static function move($source, $target) { + + if (self::check_name_exist($source)) { + $file_name = basename($source); + + if (self::check_name_exist($target.'/'.$file_name)) { + return false; + } else { + /* File case */ + if (is_file($source)) { + copy($source , $target.'/'.$file_name); + unlink($source); + return true; + } elseif (is_dir($source)) { + /* Directory case */ + // Check to not copy the directory inside itself + if (ereg('^'.$source.'/', $target.'/')) { // TODO: ereg() function is deprecated in PHP 5.3 + return false; + } else { + self::copyDirTo($source, $target); + return true; + } + } } + } else { + return false; } - } - chdir($save_dir) ; - return $dir_array ; -} - -/** - * Indexes all the directories and subdirectories - * contented in a given directory, and sort them alphabetically - * - * @author - Hugues Peeters - * @param - path (string) - directory path of the one to index - * @return - an array containing the path of all the subdirectories sorted - * false, if there is no directory - * @see - index_and_sort_dir uses the index_dir() function - */ -function index_and_sort_dir($path) { - $dir_list = index_dir($path); - if ($dir_list) { - natsort($dir_list); - return $dir_list; - } - return false; -} - - -/** - * Builds a html form listing all directories of a given directory - * - */ -function form_dir_list($source_type, $source_component, $command, $base_work_dir) { - - $dir_list = index_and_sort_dir($base_work_dir); - $dialog_box .= "
\n" ; - $dialog_box .= "\n" ; - $dialog_box .= get_lang('Move').' '.$source_component.' '.get_lang('To'); - $dialog_box .= "\n"; - $dialog_box .= ""; - $dialog_box .= "
\n"; - - return $dialog_box; -} + } -/** - * Extracting extention of a filename - * - * @returns array - * @param string $filename filename - */ -function getextension($filename) { - $bouts = explode('.', $filename); - return array(array_pop($bouts), implode('.', $bouts)); -} + /** + * Moves a directory and its content to an other area + * + * @author - Hugues Peeters + * @param - $orig_dir_path (string) - the path of the directory to move + * @param - $destination (string) - the path of the new area + * @return - no return + */ + static function copyDirTo($orig_dir_path, $destination, $move = true) { + + $save_dir = getcwd(); + // Extract directory name - create it at destination - update destination trail + $dir_name = basename($orig_dir_path); + if (is_dir($orig_dir_path)) { + mkdir($destination.'/'.$dir_name, api_get_permissions_for_new_directories()); + $destination_trail = $destination.'/'.$dir_name; + if (is_dir($destination)) { + chdir ($orig_dir_path) ; + $handle = opendir($orig_dir_path); + + while ($element = readdir($handle)) { + if ($element == '.' || $element == '..') { + continue; // Skip the current and parent directories + } elseif (is_file($element)) { + copy($element, $destination_trail.'/'.$element); + + if ($move) { + unlink($element) ; + } + } elseif (is_dir($element)) { + $dir_to_copy[] = $orig_dir_path.'/'.$element; + } + } + + closedir($handle) ; + + if (sizeof($dir_to_copy) > 0) { + foreach ($dir_to_copy as $this_dir) { + self::copyDirTo($this_dir, $destination_trail, $move); // Recursivity + } + } + + if ($move) { + rmdir($orig_dir_path) ; + } + chdir($save_dir); + } + } + } -/** - * Calculation size of a directory - * - * @returns integer size - * @param string $path path to size - * @param boolean $recursive if true , include subdir in total - */ -function dirsize($root, $recursive = true) { - $dir = @opendir($root); - $size = 0; - while ($file = @readdir($dir)) { - if (!in_array($file, array('.', '..'))) { - if (is_dir($root.'/'.$file)) { - $size += $recursive ? dirsize($root.'/'.$file) : 0; - } else { - $size += @filesize($root.'/'.$file); - } - } - } - @closedir($dir); - return $size; -} + /* NOTE: These functions batch is used to automatically build HTML forms + * with a list of the directories contained on the course Directory. + * + * From a thechnical point of view, form_dir_lists calls sort_dir wich calls index_dir + */ + + /** + * Gets all the directories and subdirectories + * contented in a given directory + * + * @author - Hugues Peeters + * @param - path (string) - directory path of the one to index + * @return - an array containing the path of all the subdirectories + */ + static function index_dir($path) { + $dir_array = array(); + $save_dir = getcwd(); + if (is_dir($path)){ + chdir($path); + $handle = opendir($path); + // Reads directory content end record subdirectoies names in $dir_array + if ($handle !== false) { + while ($element = readdir($handle)) { + if ($element == '.' || $element == '..') continue; // Skip the current and parent directories + if (is_dir($element)) $dir_array[] = $path.'/'.$element; + } + closedir($handle) ; + } + // Recursive operation if subdirectories exist + $dir_number = sizeof($dir_array); + if ($dir_number > 0) { + for ($i = 0 ; $i < $dir_number ; $i++) { + $sub_dir_array = self::index_dir($dir_array[$i]); // Function recursivity + $dir_array = array_merge((array)$dir_array, (array)$sub_dir_array); // Data merge + } + } + } + chdir($save_dir) ; + return $dir_array ; + } -/* CLASS FileManager */ + /** + * Indexes all the directories and subdirectories + * contented in a given directory, and sort them alphabetically + * + * @author - Hugues Peeters + * @param - path (string) - directory path of the one to index + * @return - an array containing the path of all the subdirectories sorted + * false, if there is no directory + * @see - index_and_sort_dir uses the index_dir() function + */ + static function index_and_sort_dir($path) { + $dir_list = self::index_dir($path); + if ($dir_list) { + natsort($dir_list); + return $dir_list; + } + return false; + } -/** - This class contains functions that you can access statically. - FileManager::list_all_directories($path) - FileManager::list_all_files($dir_array) - FileManager::compat_load_file($file_name) - FileManager::set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v') + /** + * Extracting extention of a filename + * + * @returns array + * @param string $filename filename + */ + static function getextension($filename) { + $bouts = explode('.', $filename); + return array(array_pop($bouts), implode('.', $bouts)); + } - @author Roan Embrechts - @version 1.1, July 2004 - * @package chamilo.library -*/ -class FileManager -{ + /** + * Calculation size of a directory + * + * @returns integer size + * @param string $path path to size + * @param boolean $recursive if true , include subdir in total + */ + static function dirsize($root, $recursive = true) { + $dir = @opendir($root); + $size = 0; + while ($file = @readdir($dir)) { + if (!in_array($file, array('.', '..'))) { + if (is_dir($root.'/'.$file)) { + $size += $recursive ? dirsize($root.'/'.$file) : 0; + } else { + $size += @filesize($root.'/'.$file); + } + } + } + @closedir($dir); + return $size; + } /** Returns a list of all directories, except the base dir, @@ -460,7 +417,7 @@ class FileManager @author Roan Embrechts @version 1.0.1 */ - function list_all_directories($path) { + static function list_all_directories($path) { $result_array = array(); if (is_dir($path)) { @@ -581,6 +538,124 @@ class FileManager Database::query($query); } + function choose_image($file_name) + { + static $type, $image; + + /* TABLES INITIALISATION */ + if (!$type || !$image) + { + $type['word' ] = array('doc', 'dot', 'rtf', 'mcw', 'wps', 'psw', 'docm', 'docx', 'dotm', 'dotx'); + $type['web' ] = array('htm', 'html', 'htx', 'xml', 'xsl', 'php', 'xhtml'); + $type['image' ] = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'tif', 'tiff'); + $type['image_vect'] = array('svg','svgz'); + $type['audio' ] = array('wav', 'mid', 'mp2', 'mp3', 'midi', 'sib', 'amr', 'kar', 'oga','au','wma'); + $type['video' ] = array('mp4', 'mov', 'rm', 'pls', 'mpg', 'mpeg', 'm2v', 'm4v', 'flv', 'f4v', 'avi', 'wmv', 'asf', '3gp','ogv','ogg','ogx','webm'); + $type['excel' ] = array('xls', 'xlt', 'xls', 'xlt', 'pxl', 'xlsx', 'xlsm', 'xlam', 'xlsb', 'xltm', 'xltx'); + $type['compressed'] = array('zip', 'tar', 'rar', 'gz'); + $type['code' ] = array('js', 'cpp', 'c', 'java', 'phps', 'jsp', 'asp', 'aspx', 'cfm'); + $type['acrobat' ] = array('pdf'); + $type['powerpoint'] = array('ppt', 'pps', 'pptm', 'pptx', 'potm', 'potx', 'ppam', 'ppsm', 'ppsx'); + $type['flash' ] = array('fla', 'swf'); + $type['text' ] = array('txt','log'); + $type['oo_writer' ] = array('odt', 'ott', 'sxw', 'stw'); + $type['oo_calc' ] = array('ods', 'ots', 'sxc', 'stc'); + $type['oo_impress'] = array('odp', 'otp', 'sxi', 'sti'); + $type['oo_draw' ] = array('odg', 'otg', 'sxd', 'std'); + $type['epub' ] = array('epub'); + $type['java' ] = array('class','jar'); + $type['freemind' ] = array('mm'); + + $image['word' ] = 'word.gif'; + $image['web' ] = 'file_html.gif'; + $image['image' ] = 'file_image.gif'; + $image['image_vect'] = 'file_svg.png'; + $image['audio' ] = 'file_sound.gif'; + $image['video' ] = 'film.gif'; + $image['excel' ] = 'excel.gif'; + $image['compressed'] = 'file_zip.gif'; + $image['code' ] = 'icons/22/mime_code.png'; + $image['acrobat' ] = 'file_pdf.gif'; + $image['powerpoint'] = 'powerpoint.gif'; + $image['flash' ] = 'file_flash.gif'; + $image['text' ] = 'icons/22/mime_text.png'; + $image['oo_writer' ] = 'file_oo_writer.gif'; + $image['oo_calc' ] = 'file_oo_calc.gif'; + $image['oo_impress'] = 'file_oo_impress.gif'; + $image['oo_draw' ] = 'file_oo_draw.gif'; + $image['epub' ] = 'file_epub.gif'; + $image['java' ] = 'file_java.png'; + $image['freemind' ] = 'file_freemind.png'; + } + /* FUNCTION CORE */ + $extension = array(); + if (!is_array($file_name)) { + if (preg_match('/\.([[:alnum:]]+)(\?|$)/', $file_name, $extension)) { + $extension[1] = strtolower($extension[1]); + + foreach ($type as $generic_type => $extension_list) + { + if (in_array($extension[1], $extension_list)) + { + return $image[$generic_type]; + } + } + } + } + return 'defaut.gif'; + } -} //end class FileManager + /** + * Transform the file path to a URL. + * + * @param - $file_path (string) - Relative local path of the file on the hard disk + * @return - Relative url + */ + function format_url($file_path) + { + $path_component = explode('/', $file_path); + $path_component = array_map('rawurlencode', $path_component); + return implode('/', $path_component); + } + + /** + * Calculates the total size of a directory by adding the sizes (that + * are stored in the database) of all files & folders in this directory. + * + * @param string $path + * @param boolean $can_see_invisible + * @return Total size + */ + function get_total_folder_size($path, $can_see_invisible = false) { + $table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY); + $table_document = Database::get_course_table(TABLE_DOCUMENT); + $tool_document = TOOL_DOCUMENT; + + $course_id = api_get_course_int_id(); + $session_id = api_get_session_id(); + $session_condition = api_get_session_condition($session_id, true, true, 'props.id_session'); + + $visibility_rule = ' props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1'); + + $sql = "SELECT SUM(table1.size) FROM ( + SELECT size FROM $table_itemproperty AS props, $table_document AS docs + WHERE docs.c_id = $course_id AND + docs.id = props.ref AND + docs.path LIKE '$path/%' AND + props.c_id = $course_id AND + props.tool = '$tool_document' AND + $visibility_rule + $session_condition + GROUP BY ref + ) as table1"; + + $result = Database::query($sql); + if ($result && Database::num_rows($result) != 0) { + $row = Database::fetch_row($result); + return $row[0] == null ? 0 : $row[0]; + } else { + return 0; + } + } +} \ No newline at end of file diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 8b64390f40..bbcf9371d4 100644 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -5,21 +5,11 @@ require_once api_get_path(LIBRARY_PATH) . 'pear/HTML/QuickForm.php'; require_once api_get_path(LIBRARY_PATH) . 'pear/HTML/QuickForm/advmultiselect.php'; -/** - * Filter - */ -define('NO_HTML', 1); -define('STUDENT_HTML', 2); -define('TEACHER_HTML', 3); -define('STUDENT_HTML_FULLPAGE', 4); -define('TEACHER_HTML_FULLPAGE', 5); - /** * Objects of this class can be used to create/manipulate/validate user input. */ class FormValidator extends HTML_QuickForm { - /** * Create a form validator based on an array of form data: * @@ -143,9 +133,9 @@ class FormValidator extends HTML_QuickForm $this->registerRule('filetype', null, 'HTML_QuickForm_Rule_Filetype', $dir . 'Rule/Filetype.php'); $this->registerRule('multiple_required', 'required', 'HTML_QuickForm_Rule_MultipleRequired', $dir . 'Rule/MultipleRequired.php'); $this->registerRule('url', null, 'HTML_QuickForm_Rule_Url', $dir . 'Rule/Url.php'); - $this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php'); + $this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php'); $this->registerRule('compare_datetime_text', null, 'HTML_QuickForm_Rule_CompareDateTimeText', $dir . 'Rule/CompareDateTimeText.php'); - + // Modify the default templates $renderer = & $this->defaultRenderer(); diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 59c611b669..6716f165d2 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -369,7 +369,7 @@ class GroupManager { if (file_exists($source_directory)) { if (api_get_setting('permanently_remove_deleted_files') == 'true') { //Delete - my_delete($source_directory); + FileManager::my_delete($source_directory); } else { //Rename rename($source_directory, $destination_dir); diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 1553b3ec79..adfc0b9f9e 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -359,6 +359,15 @@ define('MESSAGE_STATUS_INVITATION_DENIED', '7'); define('SESSION_LINK_TARGET', '_self'); +/** + * Form validator + */ +define('NO_HTML', 1); +define('STUDENT_HTML', 2); +define('TEACHER_HTML', 3); +define('STUDENT_HTML_FULLPAGE', 4); +define('TEACHER_HTML_FULLPAGE', 5); + /** * Inclusion of internationalization libraries diff --git a/main/inc/lib/search/tool_processors/document_processor.class.php b/main/inc/lib/search/tool_processors/document_processor.class.php index 3ae195e573..dcf7e5fd17 100644 --- a/main/inc/lib/search/tool_processors/document_processor.class.php +++ b/main/inc/lib/search/tool_processors/document_processor.class.php @@ -91,7 +91,7 @@ class document_processor extends search_processor { $url = sprintf($url, $course_path, $row['path']); // Get the image path include_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php'; - $icon = choose_image(basename($row['path'])); + $icon = FileManager::choose_image(basename($row['path'])); $thumbnail = api_get_path(WEB_CODE_PATH) . 'img/' . $icon; $image = $thumbnail; //FIXME: use big images diff --git a/main/install/update-db-scorm-1.6.x-1.8.0.inc.php b/main/install/update-db-scorm-1.6.x-1.8.0.inc.php index ea209eb51b..a90cacd98b 100644 --- a/main/install/update-db-scorm-1.6.x-1.8.0.inc.php +++ b/main/install/update-db-scorm-1.6.x-1.8.0.inc.php @@ -14,7 +14,6 @@ */ require_once api_get_path(LIBRARY_PATH).'document.lib.php'; -require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; //check_name_exists() require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php'; diff --git a/main/metadata/importmanifest.php b/main/metadata/importmanifest.php old mode 100755 new mode 100644 index ffc90eef8b..0723c66ef8 --- a/main/metadata/importmanifest.php +++ b/main/metadata/importmanifest.php @@ -1,5 +1,5 @@ -', get_lang('OrElse'), '', "\n\n"; $specifics = '
"; } - $image = choose_image($filename); + $image = FileManager::choose_image($filename); $sql = "select * from $tbl_lp_item where id=$id_in_path"; //error_log('New LP - Querying lp_item table: '.$sql, 0); @@ -1578,7 +1578,7 @@ function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_win $pathname = explode('/', $myrow['path']); // Making a correct name for the link. $last = count($pathname) - 1; // Making a correct name for the link. $filename = $pathname[$last]; // Making a correct name for the link. - $image = choose_image($filename); + $image = FileManager::choose_image($filename); $ext = explode('.', $filename); $ext = strtolower($ext[sizeof($ext) - 1]); $myrow['path'] = rawurlencode($myrow['path']); @@ -1830,7 +1830,7 @@ function rl_get_resource_name($course_code, $learnpath_id, $id_in_path) { $pathname = explode('/', $myrow['path']); // Making a correct name for the link. $last = count($pathname) - 1; // Making a correct name for the link. $filename = $pathname[$last]; // Making a correct name for the link. - $image = choose_image($filename); + $image = FileManager::choose_image($filename); $ext = explode('.', $filename); $ext = strtolower($ext[sizeof($ext) - 1]); $myrow['path'] = rawurlencode($myrow['path']); diff --git a/main/newscorm/scorm.class.php b/main/newscorm/scorm.class.php index 0d220d819b..7b133e3379 100644 --- a/main/newscorm/scorm.class.php +++ b/main/newscorm/scorm.class.php @@ -795,8 +795,8 @@ class scorm extends learnpath { DocumentManager :: file_send_for_download($zipfilename, true); // Delete the temporary zip file and directory in fileManage.lib.php - my_delete($zipfilename); - my_delete($zipfoldername); + FileManager::my_delete($zipfilename); + FileManager::my_delete($zipfoldername); return true; } diff --git a/main/resourcelinker/resourcelinker.inc.php b/main/resourcelinker/resourcelinker.inc.php index 2154e7ae2f..73fab7fd1e 100644 --- a/main/resourcelinker/resourcelinker.inc.php +++ b/main/resourcelinker/resourcelinker.inc.php @@ -98,7 +98,7 @@ function show_documents($folder) } else { - $image = choose_image($row['path']); + $image = FileManager::choose_image($row['path']); echo ""; } @@ -158,7 +158,7 @@ function show_documents($folder) } else { - $image = choose_image($path); + $image = FileManager::choose_image($path); echo ""; } @@ -309,7 +309,7 @@ function display_addedresource_link($type, $id, $style='') $pathname = explode('/',$myrow['path']); // making a correct name for the link $last = count($pathname) - 1; // making a correct name for the link $filename = $pathname[$last]; // making a correct name for the link - $image = choose_image($filename); + $image = FileManager::choose_image($filename); $ext = explode('.',$filename); $ext = strtolower($ext[sizeof($ext)-1]); $myrow['path'] = rawurlencode($myrow['path']); @@ -821,7 +821,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_ } } if (($builder != 'builder') and ($icon != 'wrap')) { echo ""; } - $image=choose_image($filename); + $image=FileManager::choose_image($filename); $sql="select * from $tbl_learnpath_item where id=$id_in_path"; $result=Database::query($sql); $row=Database::fetch_array($result); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 245a9f19a4..0c470f8975 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -1118,7 +1118,7 @@ function del_dir($id) { require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; $new_dir = $work_data_url.'_DELETED_'.$id; if (api_get_setting('permanently_remove_deleted_files') == 'true'){ - my_delete($work_data_url); + FileManager::my_delete($work_data_url); } else { if (file_exists($work_data_url)) { rename($work_data_url, $new_dir); @@ -1193,7 +1193,7 @@ function update_dir_name($work_data, $new_name, $title) { $new_name = Security::remove_XSS($new_name); $new_name = replace_dangerous_char($new_name); $new_name = disable_dangerous_file($new_name); - my_rename($base_work_dir.'/'.$path, $new_name); + FileManager::my_rename($base_work_dir.'/'.$path, $new_name); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); //update all the files in the other directories according with the next query diff --git a/main/work/work.php b/main/work/work.php index 1bae1c4eda..eee1da2fe2 100644 --- a/main/work/work.php +++ b/main/work/work.php @@ -428,7 +428,7 @@ switch ($action) { $realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl))); $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl); $text_document = $form->addElement('text', 'document', get_lang('Document')); - $defaults['document'] = '' . $realUrl . ''; + $defaults['document'] = '' . $realUrl . ''; $text_document->freeze(); } elseif ($item_id && ($is_allowed_to_edit or $is_author)) { $workUrl = $currentCourseRepositoryWeb . $workUrl; @@ -934,7 +934,7 @@ switch ($action) { //security fix: make sure they can't move files that are not in the document table if ($path = get_work_path($item_id)) { - if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) { + if (FileManager::move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) { //update db update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']); @@ -1075,7 +1075,7 @@ switch ($action) { if ($row['contains_file'] == 1) { if (!empty($work)) { if (api_get_setting('permanently_remove_deleted_files') == 'true') { - my_delete($currentCourseRepositorySys.'/'.$work); + FileManager::my_delete($currentCourseRepositorySys.'/'.$work); Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted')); $file_deleted = true; } else { diff --git a/tests/main/inc/lib/fileDisplay.lib.test.php b/tests/main/inc/lib/fileDisplay.lib.test.php index 28c6b64c5e..abe23284e6 100755 --- a/tests/main/inc/lib/fileDisplay.lib.test.php +++ b/tests/main/inc/lib/fileDisplay.lib.test.php @@ -1,5 +1,4 @@ assertEqual($res,'defaut.gif'); - $this->assertTrue(is_string($res)); - //var_dump($file_name); - } - - public function testFormatFileSize(){ - $file_size = '100'; - $res = format_file_size($file_size); - $this->assertTrue($res); - $this->assertTrue(is_string($res)); - //var_dump($res); - - } - - public function testFormatDate(){ - $date = '11/02/2009'; - $res = format_date($date); - $this->assertTrue($res); - //var_dump($res); - - } - - public function testFormatUrl(){ - $file_path ='/var/www/path/'; - $res = format_url($file_path); - $this->assertTrue($res); - $this->assertTrue(is_string($res)); - //var_dump($res); - - } - - public function testRecentModifiedFileTime(){ - $dir_name = ''; - $$do_recursive =true; - $res = recent_modified_file_time($dir_name, $do_recursive); - $this->assertTrue(is_numeric($res)); - //var_dump($res); - - } - - public function testFolderSize(){ - $dir_name =''; - $res = folder_size($dir_name); - $this->assertFalse($res); - $this->assertTrue(is_numeric($res)); - //var_dump($res); - - - } - -} - - -?> +} \ No newline at end of file diff --git a/tests/main/inc/lib/fileManage.lib.test.php b/tests/main/inc/lib/fileManage.lib.test.php index db2a8d6e7b..c2c5595236 100755 --- a/tests/main/inc/lib/fileManage.lib.test.php +++ b/tests/main/inc/lib/fileManage.lib.test.php @@ -37,14 +37,14 @@ class TestFileManager extends UnitTestCase { public function testUpdatedbInfo(){ $action =''; $oldPath =''; - $res = update_db_info($action, $oldPath, $newPath=""); + $res = FileManager::update_db_info($action, $oldPath, $newPath=""); $this->assertNull($res); //var_dump($res); } public function testCheckNameExist(){ $filePath =''; - $res = check_name_exist($filePath); + $res = FileManager::check_name_exist($filePath); $this->assertFalse($res); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); @@ -53,7 +53,7 @@ class TestFileManager extends UnitTestCase { public function testMyDelete(){ $file=''; - $res = my_delete($file); + $res = FileManager::my_delete($file); $this->assertFalse($res); $this->assertTrue(is_bool($res)); $this->assertTrue($res===false); @@ -62,7 +62,7 @@ class TestFileManager extends UnitTestCase { public function testRemoveDir(){ $dir=''; - $res = removeDir($dir); + $res = FileManager::removeDir($dir); $this->assertTrue(is_bool($res)); $this->assertFalse($res === true); //var_dump($res); @@ -71,7 +71,7 @@ class TestFileManager extends UnitTestCase { public function testMyRename(){ $filePath ='document/'; $newFileName=''; - $res = my_rename($filePath, $newFileName); + $res = FileManager::my_rename($filePath, $newFileName); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); //var_dump($res); @@ -80,7 +80,7 @@ class TestFileManager extends UnitTestCase { public function testMove(){ $source =''; $target =''; - $res = move($source, $target); + $res = FileManager::move($source, $target); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); $this->assertFalse($res); @@ -90,14 +90,14 @@ class TestFileManager extends UnitTestCase { public function testCopyDirTo(){ $origDirPath=api_get_path(SYS_COURSE_PATH).'document/audio'; $destination=api_get_path(SYS_COURSE_PATH).'document/flash/audio'; - $res = copyDirTo($origDirPath, $destination, $move = false); + $res = FileManager::copyDirTo($origDirPath, $destination, $move = false); $this->assertTrue($res===null); $this->assertNull($res); } public function testIndexDir(){ $path=api_get_path(SYS_COURSE_PATH).'document/'; - $res = index_dir($path); + $res = FileManager::index_dir($path); if(!is_null($res)) { $this->assertTrue(is_array($res)); } else { @@ -108,7 +108,7 @@ class TestFileManager extends UnitTestCase { public function testIndexAndSortDir(){ $path=api_get_path(SYS_COURSE_PATH).'document/'; - $res = index_and_sort_dir($path); + $res = FileManager::index_and_sort_dir($path); if(!is_bool($res)) { $this->assertTrue($res); $this->assertTrue(is_array($res)); @@ -116,16 +116,6 @@ class TestFileManager extends UnitTestCase { //var_dump($res); } - public function testFormDirList(){ - $sourceType = ''; - $sourceComponent = ''; - $command = ''; - $baseWorkDir = api_get_path(SYS_COURSE_PATH).'document/'; - $res = form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir); - $this->assertTrue($res); - $this->assertTrue(is_string($res)); - //var_dump($res); - } public function testMkpath(){ $path=api_get_path(SYS_COURSE_PATH).'document/'; diff --git a/tests/main/inc/lib/fileManager.lib.test.php b/tests/main/inc/lib/fileManager.lib.test.php index 95d46866b4..158b004374 100755 --- a/tests/main/inc/lib/fileManager.lib.test.php +++ b/tests/main/inc/lib/fileManager.lib.test.php @@ -44,14 +44,14 @@ class TestFileManager extends UnitTestCase { public function testUpdatedbInfo(){ $action =''; $oldPath =''; - $res = update_db_info($action, $oldPath, $newPath=""); + $res = FileManager::update_db_info($action, $oldPath, $newPath=""); $this->assertTrue(is_null($res)); //var_dump($res); } public function testCheckNameExist(){ $filePath =''; - $res = check_name_exist($filePath); + $res = FileManager::check_name_exist($filePath); $this->assertFalse($res); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); @@ -60,7 +60,7 @@ class TestFileManager extends UnitTestCase { public function testMyDelete(){ $file=''; - $res = my_delete($file); + $res = FileManager::my_delete($file); $this->assertFalse($res); $this->assertTrue(is_bool($res)); $this->assertTrue($res===false); @@ -69,7 +69,7 @@ class TestFileManager extends UnitTestCase { public function testRemoveDir(){ $dir=''; - $res = removeDir($dir); + $res = FileManager::removeDir($dir); $this->assertTrue(is_bool($res)); $this->assertFalse($res === true); //var_dump($res); @@ -78,7 +78,7 @@ class TestFileManager extends UnitTestCase { public function testMyRename(){ $filePath ='documents'; $newFileName=''; - $res = my_rename($filePath, $newFileName); + $res = FileManager::my_rename($filePath, $newFileName); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); //var_dump($res); @@ -87,7 +87,7 @@ class TestFileManager extends UnitTestCase { public function testMove(){ $source =''; $target =''; - $res = move($source, $target); + $res = FileManager::move($source, $target); $this->assertTrue(is_bool($res)); $this->assertTrue($res === false); $this->assertFalse($res); @@ -97,14 +97,14 @@ class TestFileManager extends UnitTestCase { public function testCopyDirTo(){ $origDirPath=''; $destination=''; - $res = copyDirTo($origDirPath, $destination, $move=true); + $res = FileManager::copyDirTo($origDirPath, $destination, $move=true); $this->assertTrue($res===null); $this->assertNull($res); } public function testIndexDir(){ $path='/var/www/path/'; - $res = index_dir($path); + $res = FileManager::index_dir($path); $this->assertFalse(is_array($res)); $this->assertNull($res); //var_dump($res); @@ -112,7 +112,7 @@ class TestFileManager extends UnitTestCase { public function testIndexAndSortDir(){ $path='/var/www/path/'; - $res = index_and_sort_dir($path); + $res = FileManager::index_and_sort_dir($path); $this->assertFalse($res); $this->assertFalse(is_array($res)); $this->assertTrue(is_bool($res)); @@ -120,16 +120,6 @@ class TestFileManager extends UnitTestCase { //var_dump($res); } - public function testFormDirList(){ - $sourceType=''; - $sourceComponent=''; - $command=''; - $baseWorkDir=''; - $res =form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir); - $this->assertTrue($res); - $this->assertTrue(is_string($res)); - //var_dump($res); - } public function testMkpath(){ $path='/var/www/path/';