[svn r18131] FS#2867 - FCKEditor: Adaptation of the php-connector for quick uploads to the new scheme of repositories.

skala
Ivan Tcholakov 16 years ago
parent ea8541453a
commit 8938ac632c
  1. 206
      main/inc/lib/fckeditor/editor/filemanager/upload/php/upload.php

@ -17,10 +17,11 @@
* File Authors:
* Frederico Caldeira Knabben (fredck@fckeditor.net)
*/
error_log('enter in upload');
include('../../../../../../global.inc.php');
include_once(api_get_path(INCLUDE_PATH)."lib/fileUpload.lib.php");
$language_file = array('create_course');
include '../../../../../../global.inc.php';
require_once api_get_path(INCLUDE_PATH).'lib/fckeditor/repositories_config.php';
require('config.php') ;
require('util.php') ;
@ -34,6 +35,33 @@ function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg =
exit ;
}
function check_and_create_resource_directory($repository_path, $resource_directory, $resource_directory_name)
{
global $permissions_for_new_directories;
$resource_directory_full_path = substr($repository_path, 0, strlen($repository_path) - 1) . $resource_directory . '/';
if (!is_dir($resource_directory_full_path))
{
if (@mkdir($resource_directory_full_path, $permissions_for_new_directories))
{
// While we are in a course: Registering the newly created folder in the course's database.
if (api_is_in_course())
{
global $_course, $_user;
global $group_properties, $to_group_id;
$group_directory = !empty($group_properties['directory']) ? $group_properties['directory'] : '';
$doc_id = add_document($_course, $group_directory.$resource_directory, 'folder', 0, $resource_directory_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
}
return true;
}
return false;
}
return true;
}
// Check if this uploader has been enabled.
if ( !$Config['Enabled'] )
SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
@ -69,53 +97,94 @@ $sFileUrl = '' ;
// Initializes the counter used to rename the file, if another one with the same name already exists.
$iCounter = 0 ;
$currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH) . $_course["path"]."/";
$currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH) . $_course["path"]."/";
$sType=strtolower($sType);
if(isset($_SESSION["_course"]["sysCode"])){
//It's a teacher, so the uoploaded document will be put in course documents
if(api_is_allowed_to_edit()){
//set the upload path according to the file type
if($sType=="mp3"){
$sServerDir = $currentCourseRepositorySys.'document/audio/';
$sserverWebath=$currentCourseRepositoryWeb.'document/audio/';
$sType="audio";
}
elseif($sType=="flash"){
$sServerDir = $currentCourseRepositorySys.'document/flash/';
$sserverWebath=$currentCourseRepositoryWeb.'document/flash/';
}
elseif($sType=="video"){
$sServerDir = $currentCourseRepositorySys.'document/video/';
$sserverWebath=$currentCourseRepositoryWeb.'document/video/';
}
elseif($sType=="video/flv"){
$sServerDir = $currentCourseRepositorySys.'document/video/flv/';
$sserverWebath=$currentCourseRepositoryWeb.'document/video/flv/';
// Choosing the repository to be used.
if (api_is_in_course())
{
if (!api_is_in_group())
{
// 1. We are inside a course and not in a group.
if (api_is_allowed_to_edit())
{
// 1.1. Teacher
$sServerDir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/';
$sserverWebath = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/';
}
else{
$sServerDir = $currentCourseRepositorySys.'document/';
$sserverWebath=$currentCourseRepositoryWeb.'document/';
else
{
// 1.2. Student
$sServerDir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
$sserverWebath = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
}
}
//It's a student, we get the upload path in parameters
elseif(isset($_REQUEST['uploadPath']) && $_REQUEST['uploadPath']!=""){
$sServerDir = $currentCourseRepositorySys.$_REQUEST['uploadPath'];
$sserverWebath=$currentCourseRepositoryWeb.$_REQUEST['uploadPath'];
else
{
// 2. Inside a course and inside a group.
$sServerDir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
$sserverWebath = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
}
//Default
else{
$sServerDir = $currentCourseRepositorySys.'upload/';
$sserverWebath=$currentCourseRepositoryWeb.'upload/';
}
}
else
{ // not in a course
$sServerDir = api_get_path(SYS_PATH).'main/upload/';
$sserverWebath = api_get_path(WEB_PATH).'main/upload/';
{
if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin')
{
// 3. Platform administration activities.
$sServerDir = $_configuration['root_sys'].'home/default_platform_document/';
$sserverWebath = $_configuration['root_web'].'home/default_platform_document/';
}
else
{
// 4. The user is outside courses.
$sServerDir = $_configuration['root_sys'].'main/upload/users/'.api_get_user_id().'/my_files/';
$sserverWebath = $_configuration['root_web'].'main/upload/users/'.api_get_user_id().'/my_files/';
}
}
// Set the upload path according to the resource type.
if ($sType == 'audio')
{
check_and_create_resource_directory($sServerDir, '/audio', get_lang('Audio'));
$sServerDir = $sServerDir.'audio/';
$sserverWebath = $sserverWebath.'audio/';
$path = "/audio/";
}
elseif ($sType == 'mp3')
{
$sType = 'audio';
check_and_create_resource_directory($sServerDir, '/audio', get_lang('Audio'));
$sServerDir = $sServerDir.'audio/';
$sserverWebath = $sserverWebath.'audio/';
$path = "/audio/";
}
elseif ($sType == 'flash')
{
check_and_create_resource_directory($sServerDir, '/flash', get_lang('Flash'));
$sServerDir = $sServerDir.'flash/';
$sserverWebath = $sserverWebath.'flash/';
$path = "/flash/";
}
elseif ($sType == 'images')
{
check_and_create_resource_directory($sServerDir, '/images', get_lang('Images'));
$sServerDir = $sServerDir.'images/';
$sserverWebath = $sserverWebath.'images/';
$path = "/images/";
}
elseif ($sType == 'video')
{
check_and_create_resource_directory($sServerDir, '/video', get_lang('Video'));
$sServerDir = $sServerDir.'video/';
$sserverWebath = $sserverWebath.'video/';
$path = "/video/";
}
elseif ($sType == 'video/flv')
{
check_and_create_resource_directory($sServerDir, '/video', get_lang('Video'));
check_and_create_resource_directory($sServerDir, '/video/flv', 'flv');
$sServerDir = $sServerDir.'video/flv/';
$sserverWebath = $sserverWebath.'video/flv/';
$path = "/video/flv/";
}
// Try to add an extension to the file if it has'nt one
@ -143,57 +212,24 @@ if ( is_file( $sServerDir.$sFileName ) ){
}
}
if(!is_dir($sServerDir))
{
mkdir($sServerDir);
}
if(!is_dir($sserverWebath))
{
mkdir($sserverWebath);
}
if(!move_uploaded_file( $oFile['tmp_name'], $sServerDir.$sFileName )) $sErrorNumber = '203' ; //check php.ini setting
if (!move_uploaded_file( $oFile['tmp_name'], $sServerDir.$sFileName )) $sErrorNumber = '203' ; // Check php.ini setting.
if ( is_file( $sServerDir.$sFileName ) )
{
$oldumask = umask(0) ;
$perm = api_get_setting('permissions_for_new_files');
$perm = octdec(!empty($perm)?$perm:'0660');
chmod( $sFilePath, $perm ) ;
chmod( $sServerDir.$sFileName, $permissions_for_new_files ) ;
umask( $oldumask ) ;
}
//If we are in a course and if it's a teacher who did the upload, we record the uploaded file in database
if(isset($_SESSION["_course"]["sysCode"]) && api_is_allowed_to_edit())
{
$document_name= strtr($sFileName,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn");
$document_name=preg_replace('/[^\w\._]/', '_', $document_name);
$document_size=$oFile["size"];
include_once(api_get_path(LIBRARY_PATH)."fileUpload.lib.php");
if($sType=="flash"){
$path = "/flash/";
}
if($sType=="audio"){
$path = "/audio/";
}
if($sType=="video"){
$path = "/video/";
}
// If we are in a course we record the uploaded file in database.
if (api_is_in_course())
{
$document_name = $sFileName;
$document_size=$oFile["size"];
$group_directory = !empty($group_properties['directory']) ? $group_properties['directory'] : '';
if($sType=="video/flv"){
$path = "/video/flv/";
$doc_id = add_document($_course, $group_directory.$path.$document_name, 'file', $document_size, $document_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentCreated', $_user['user_id'], $to_group_id);
}
$doc_id = add_document($_course, $path.$document_name, 'file', $document_size, $document_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentCreated', $_user['user_id']);
}
SendResults( $sErrorNumber, $sserverWebath.$sFileName, $sFileName ) ;

Loading…
Cancel
Save