|
|
|
@ -1,40 +1,17 @@ |
|
|
|
|
<?php |
|
|
|
|
/* |
|
|
|
|
============================================================================== |
|
|
|
|
Dokeos - elearning and course management software |
|
|
|
|
|
|
|
|
|
Copyright (c) 2004 Dokeos S.A. |
|
|
|
|
Copyright (c) 2003 Ghent University (UGent) |
|
|
|
|
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
|
|
|
|
Copyright (c) various contributors |
|
|
|
|
|
|
|
|
|
For a full list of contributors, see "credits.txt". |
|
|
|
|
The full license can be read in "license.txt". |
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
|
|
|
modify it under the terms of the GNU General Public License |
|
|
|
|
as published by the Free Software Foundation; either version 2 |
|
|
|
|
of the License, or (at your option) any later version. |
|
|
|
|
|
|
|
|
|
See the GNU General Public License for more details. |
|
|
|
|
|
|
|
|
|
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
|
|
|
|
============================================================================== |
|
|
|
|
*/ |
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
/** |
|
|
|
|
============================================================================== |
|
|
|
|
FILE UPLOAD LIBRARY |
|
|
|
|
|
|
|
|
|
* This is the file upload library for Dokeos. |
|
|
|
|
* Include/require it in your code to use its functionality. |
|
|
|
|
* |
|
|
|
|
* @package dokeos.library |
|
|
|
|
* @package chamilo.library |
|
|
|
|
* @todo test and reorganise |
|
|
|
|
============================================================================== |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
============================================================================== |
|
|
|
|
|
|
|
|
|
List of functions |
|
|
|
|
function php2phps ($fileName) |
|
|
|
|
function htaccess2txt($filename) |
|
|
|
@ -68,10 +45,9 @@ function check_for_missing_files($file) |
|
|
|
|
function build_missing_files_form($missing_files,$upload_path,$file_name) |
|
|
|
|
Still experimental: |
|
|
|
|
function api_replace_parameter($upload_path, $buffer, $param_name="src") |
|
|
|
|
============================================================================== |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* change the file name extension from .php to .phps |
|
|
|
@ -88,7 +64,7 @@ function php2phps ($fileName) |
|
|
|
|
return $fileName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Renames .htaccess & .HTACCESS tot htaccess.txt |
|
|
|
@ -103,7 +79,6 @@ function htaccess2txt($filename) |
|
|
|
|
return $filename; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -122,8 +97,6 @@ function disable_dangerous_file($filename) |
|
|
|
|
return $filename; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* this function generates a unique name for a file on a given location |
|
|
|
|
* filenames are changed to name_#.ext |
|
|
|
@ -145,7 +118,6 @@ function unique_name($path,$name) |
|
|
|
|
return $name_no_ext . $unique . $ext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the name without extension, used for the title |
|
|
|
@ -163,8 +135,6 @@ function get_document_title($name) |
|
|
|
|
return $filename; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This function checks if the upload succeeded |
|
|
|
|
* |
|
|
|
@ -196,8 +166,6 @@ function process_uploaded_file($uploaded_file) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* this function does the save-work for the documents. |
|
|
|
|
* it handles the uploaded file and adds the properties to the database |
|
|
|
@ -418,7 +386,7 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Check if there is enough place to add a file on a directory |
|
|
|
@ -450,7 +418,7 @@ function enough_size($fileSize, $dir, $maxDirSpace) |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Check if there is enough place to add a file on a directory |
|
|
|
@ -479,7 +447,7 @@ function enough_space($file_size, $max_dir_space) |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Compute the size already occupied by a directory and is subdirectories |
|
|
|
@ -526,7 +494,7 @@ function dir_total_space($dirPath) |
|
|
|
|
return $sumSize; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Calculate the total size of all documents in a course |
|
|
|
@ -562,7 +530,7 @@ function documents_total_space($to_group_id='0') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Try to add an extension to files without extension |
|
|
|
@ -670,7 +638,7 @@ function add_ext_on_mime($fileName,$fileType) |
|
|
|
|
return $fileName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
@ -856,7 +824,7 @@ function unzip_uploaded_file($uploadedFile, $uploadPath, $baseWorkDir, $maxFille |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Manages all the unzipping process of an uploaded document |
|
|
|
@ -1013,7 +981,7 @@ function unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $ |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* this function is a callback function that is used while extracting a zipfile |
|
|
|
@ -1029,7 +997,7 @@ function clean_up_files_in_zip($p_event, &$p_header) |
|
|
|
|
return $res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* this function cleans up a given path |
|
|
|
@ -1121,7 +1089,7 @@ function filter_extension(&$filename) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds a new document to the database |
|
|
|
@ -1154,13 +1122,13 @@ function add_document($_course,$path,$filetype,$filesize,$title,$comment=NULL, $ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
function get_document_id() moved to document.lib.php |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update an existing document in the database |
|
|
|
@ -1233,7 +1201,7 @@ function item_property_update_on_folder($_course,$path,$user_id) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the directory depth of the file. |
|
|
|
@ -1256,7 +1224,7 @@ function get_levels($filename) |
|
|
|
|
class FileManager |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds file to document table in database |
|
|
|
@ -1306,7 +1274,7 @@ function set_default_settings($upload_path,$filename,$filetype="file") |
|
|
|
|
Database::query($query); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* retrieve the image path list in a html file |
|
|
|
@ -1364,7 +1332,7 @@ function search_img_from_html($htmlFile) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* creates a new directory trying to find a directory name |
|
|
|
@ -1422,7 +1390,7 @@ function create_unexisting_directory($_course,$user_id,$to_group_id,$to_user_id, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Handles uploaded missing images |
|
|
|
@ -1458,9 +1426,9 @@ function move_uploaded_file_collection_into_directory($_course, $uploaded_file_c |
|
|
|
|
return $new_file_list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* Open the old html file and replace the src path into the img tag |
|
|
|
@ -1512,7 +1480,7 @@ function replace_img_path_in_html_file($originalImgPath, $newImgPath, $htmlFile) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a file containing an html redirection to a given url |
|
|
|
@ -1541,7 +1509,7 @@ function create_link_file($filePath, $url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
Open html file $full_file_name; |
|
|
|
@ -1567,7 +1535,7 @@ function api_replace_links_in_html($upload_path, $full_file_name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@deprecated, use api_replace_parameter instead |
|
|
|
@ -1662,7 +1630,7 @@ function api_replace_links_in_string($upload_path, $buffer) |
|
|
|
|
return $buffer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
EXPERIMENTAL - function seems to work, needs more testing |
|
|
|
@ -1789,7 +1757,7 @@ function api_replace_parameter($upload_path, $buffer, $param_name="src") |
|
|
|
|
return $buffer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks the extension of a file, if it's .htm or .html |
|
|
|
@ -1809,7 +1777,7 @@ function check_for_missing_files($file) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This builds a form that asks for the missing images in a html file |
|
|
|
@ -1848,7 +1816,7 @@ function build_missing_files_form($missing_files,$upload_path,$file_name) |
|
|
|
|
return $form; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This recursive function can be used during the upgrade process form older versions of Dokeos |
|
|
|
|