Browse Source

Fix elfinder/ckeditor upload

Julio Montoya 9 years ago
parent
commit
600bb2590b

+ 19 - 0
app/AppKernel.php

@@ -147,6 +147,16 @@ class AppKernel extends Kernel
         return $this->getRealRootDir().'app/config/';
     }
 
+    /**
+     * If Chamilo is installed in my.chamilo.net return ''
+     * If Chamilo is installed in my.chamilo.net/chamilo return 'chamilo'
+     * @return string
+     */
+    public function getUrlAppend()
+    {
+        return $this->getContainer()->getParameter('url_append');
+    }
+
     /**
      * @return string
      */
@@ -154,5 +164,14 @@ class AppKernel extends Kernel
     {
         return $this->getRealRootDir().'app/config/configuration.php';
     }
+
+    /**
+     * Check if system is installed
+     * @return bool
+     */
+    public function isInstalled()
+    {
+        return !empty($this->getContainer()->getParameter('installed'));
+    }
 }
 

+ 2 - 0
app/config/parameters.yml.dist

@@ -25,4 +25,6 @@ parameters:
     sylius.cache:
         type: file_system
 
+    url_append: ''
     sonata_media.cdn.host: /uploads/media
+

+ 1 - 1
app/config/sonata/sonata_media.yml

@@ -68,7 +68,7 @@ sonata_media:
     cdn:
         # define the public base url for the uploaded media
         server:
-            path:      %sonata_media.cdn.host%
+            path: %url_append%%sonata_media.cdn.host%
 
     filesystem:
         # define where the uploaded file will be stored

+ 7 - 41
main/inc/lib/api.lib.php

@@ -770,43 +770,14 @@ function api_get_path($path_type, $path = null)
     }
 
     if (!$is_this_function_initialized) {
-        global $_configuration;
-
-        $root_rel = $_configuration['url_append'];
-
-        // Support for the installation process.
-        // Developers might use the function api_get_path() directly or indirectly (this is difficult to be traced), at the moment when
-        // configuration has not been created yet. This is why this function should be upgraded to return correct results in this case.
-
-        if (defined('SYSTEM_INSTALLATION') && SYSTEM_INSTALLATION) {
-            if (($pos = strpos(($requested_page_rel = api_get_self()), 'main/install')) !== false) {
-                $root_rel = substr($requested_page_rel, 0, $pos);
-                // See http://www.mediawiki.org/wiki/Manual:$wgServer
-                $server_protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
-                $server_name =
-                    isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME']
-                    : (isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME']
-                    : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
-                    : (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR']
-                    : 'localhost')));
-                if (isset($_SERVER['SERVER_PORT']) && !strpos($server_name, ':')
-                    && (($server_protocol == 'http'
-                    && $_SERVER['SERVER_PORT'] != 80 ) || ($server_protocol == 'https' && $_SERVER['SERVER_PORT'] != 443 ))) {
-                    $server_name .= ":" . $_SERVER['SERVER_PORT'];
-                }
-                $root_web = $server_protocol.'://'.$server_name.$root_rel;
-                $root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/';
-                $code_folder = 'main/';
-            }
-            // Here we give up, so we don't touch anything.
-        }
+        $root_rel = Container::getUrlAppend();
 
         // Dealing with trailing slashes.
-        $root_web       = api_add_trailing_slash($root_web);
-        $root_sys       = api_add_trailing_slash($root_sys);
-        $root_rel       = api_add_trailing_slash($root_rel);
-        $code_folder    = api_add_trailing_slash($code_folder);
-        $course_folder  = api_add_trailing_slash($course_folder);
+        $root_web = api_add_trailing_slash($root_web);
+        $root_sys = api_add_trailing_slash($root_sys);
+        $root_rel = api_add_trailing_slash($root_rel);
+        $code_folder = api_add_trailing_slash($code_folder);
+        $course_folder = api_add_trailing_slash($course_folder);
 
         // Web server base and system server base.
         $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web); // No trailing slash.
@@ -849,8 +820,6 @@ function api_get_path($path_type, $path = null)
 
         $bundleWebPath = Container::getAsset()->getUrl('bundles/chamilocore/');
         $paths[WEB_IMG_PATH] = $bundleWebPath.'img/';
-
-
         $paths[SYS_IMG_PATH] = $paths[SYS_PATH].$paths[SYS_IMG_PATH];
         $paths[WEB_LIBRARY_PATH]        = $paths[WEB_CODE_PATH].$paths[WEB_LIBRARY_PATH];
         $paths[WEB_LIBRARY_JS_PATH] = $bundleWebPath.'js/';
@@ -870,9 +839,6 @@ function api_get_path($path_type, $path = null)
         $paths[CONFIGURATION_PATH]      = $paths[SYS_PATH].$paths[CONFIGURATION_PATH];
 
         $paths[SYS_COURSE_PATH]         = Container::getCourseDir();
-        /*$paths[SYS_LOG_PATH]            = Container::getLogDir();
-        $paths[SYS_CONFIG_PATH]         = Container::getConfigDir();
-        */
 
         $is_this_function_initialized = true;
     } else {
@@ -1970,7 +1936,7 @@ function api_format_course_array($course_data)
     if (array_key_exists('add_teachers_to_sessions_courses', $course_data)) {
         $_course['add_teachers_to_sessions_courses'] = $course_data['add_teachers_to_sessions_courses'];
     }
-    
+
     if (file_exists(api_get_path(SYS_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png')) {
         $url_image = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png';
     } else {

+ 8 - 6
main/inc/lib/chat.lib.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use ChamiloSession as Session;
+
 /**
  * Class Chat
  *
@@ -272,7 +274,7 @@ class Chat extends Model
 
         return $text;
     }
-    
+
     /**
      * SET Disable Chat
      * @param boolean status to disable chat
@@ -280,9 +282,9 @@ class Chat extends Model
      */
     public static function setDisableChat($status = true)
     {
-        $_SESSION['disable_chat'] = $status;
+        Session::write('disable_chat', $status);
     }
-    
+
     /**
      * Disable Chat - disable the chat
      * @return boolean - return true if setDisableChat status is true
@@ -296,10 +298,10 @@ class Chat extends Model
                 return true;
             }
         }
-         
-         return false;
+
+        return false;
     }
-    
+
     public function is_chat_blocked_by_exercises()
     {
         if (isset($_SESSION['current_exercises'])) {

+ 0 - 311
main/inc/lib/fileDisplay.lib.php

@@ -1,311 +0,0 @@
-<?php
-/* See license terms in /license.txt */
-/**
-*	This is the file display library for Dokeos.
-*	Include/require it in your code to use its functionality.
-*
-*	@package chamilo.library
-*/
-
-/* FILE DISPLAY FUNCTIONS */
-/**
- * Define the image to display for each file extension.
- * This needs an existing image repository to work.
- *
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @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';
-    }
-
-    $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 <peeters@ipm.ucl.ac.be>
- * @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 	int 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.session_id'
-    );
-
-    $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;
-    }
-}

+ 302 - 0
main/inc/lib/fileManage.lib.php

@@ -475,3 +475,305 @@ class FileManager
 		Database::query($query);
 	}
 }
+
+/**
+ * Define the image to display for each file extension.
+ * This needs an existing image repository to work.
+ *
+ * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
+ * @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';
+	}
+
+	$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 <peeters@ipm.ucl.ac.be>
+ * @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 	int 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.session_id'
+	);
+
+	$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;
+	}
+}

+ 0 - 44
main/inc/lib/fileUpload.lib.php

@@ -11,27 +11,6 @@
  *	@todo test and reorganise
  */
 
-/**
- * Changes the file name extension from .php to .phps
- * Useful for securing a site.
- *
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @param  - file_name (string) name of a file
- * @return - the filenam phps'ized
- */
-function php2phps($file_name) {
-    return preg_replace('/\.(php.?|phtml.?)(\.){0,1}.*$/i', '.phps', $file_name);
-}
-
-/**
- * Renames .htaccess & .HTACCESS to htaccess.txt
- *
- * @param string $filename
- * @return string
- */
-function htaccess2txt($filename) {
-    return str_replace(array('.htaccess', '.HTACCESS'), array('htaccess.txt', 'htaccess.txt'), $filename);
-}
 
 /**
  * This function executes our safety precautions
@@ -46,29 +25,6 @@ function disable_dangerous_file($filename) {
     return htaccess2txt(php2phps($filename));
 }
 
-/**
- * This function generates a unique name for a file on a given location
- * file names are changed to name_#.ext
- *
- * @param string $path
- * @param string $name
- *
- * @deprecated
- *
- * @return string new unique name
- */
-function unique_name($path, $name)
-{
-    $ext = substr(strrchr($name, '.'), 0);
-    $name_no_ext = substr($name, 0, strlen($name) - strlen(strstr($name, $ext)));
-    $n = 0;
-    $unique = '';
-    while (file_exists($path . $name_no_ext . $unique . $ext)) {
-        $unique = '_' . ++$n;
-    }
-    return $name_no_ext . $unique . $ext;
-}
-
 /**
  * Returns the name without extension, used for the title
  *

+ 46 - 0
main/inc/lib/text.lib.php

@@ -10,6 +10,52 @@
 
 define('EXERCISE_NUMBER_OF_DECIMALS', 2);
 
+
+/**
+ * This function generates a unique name for a file on a given location
+ * file names are changed to name_#.ext
+ *
+ * @param string $path
+ * @param string $name
+ *
+ * @deprecated
+ *
+ * @return string new unique name
+ */
+function unique_name($path, $name)
+{
+    $ext = substr(strrchr($name, '.'), 0);
+    $name_no_ext = substr($name, 0, strlen($name) - strlen(strstr($name, $ext)));
+    $n = 0;
+    $unique = '';
+    while (file_exists($path . $name_no_ext . $unique . $ext)) {
+        $unique = '_' . ++$n;
+    }
+    return $name_no_ext . $unique . $ext;
+}
+
+/**
+ * Changes the file name extension from .php to .phps
+ * Useful for securing a site.
+ *
+ * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
+ * @param  - file_name (string) name of a file
+ * @return - the filenam phps'ized
+ */
+function php2phps($file_name) {
+    return preg_replace('/\.(php.?|phtml.?)(\.){0,1}.*$/i', '.phps', $file_name);
+}
+
+/**
+ * Renames .htaccess & .HTACCESS to htaccess.txt
+ *
+ * @param string $filename
+ * @return string
+ */
+function htaccess2txt($filename) {
+    return str_replace(array('.htaccess', '.HTACCESS'), array('htaccess.txt', 'htaccess.txt'), $filename);
+}
+
 /**
  * This function strips all html-tags found in the input string and outputs a pure text.
  * Mostly, the function is to be used before language or encoding detection of the input string.

+ 17 - 1
src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php

@@ -165,6 +165,8 @@ class CourseDriver extends Driver implements DriverInterface
     {
         $this->setConnectorFromPlugin();
 
+        $sessionId = api_get_session_id();
+
         if ($this->allow()) {
 
             // upload file by elfinder.
@@ -190,13 +192,27 @@ class CourseDriver extends Driver implements DriverInterface
 
                 // Removing course path
                 $realPath = str_replace($realPathRoot, '/', $realPath);
-                add_document(
+                $documentId = add_document(
                     $this->connector->course,
                     $realPath,
                     'file',
                     intval($result['size']),
                     $result['name']
                 );
+
+                api_item_property_update(
+                    $this->connector->course,
+                    TOOL_DOCUMENT,
+                    $documentId,
+                    'DocumentAdded',
+                    api_get_user_id(),
+                    null,
+                    null,
+                    null,
+                    null,
+                    $sessionId
+                );
+
             }
             //error_log(print_r($this->error(),1));
 

+ 137 - 11
src/Chamilo/CoreBundle/Component/Editor/Driver/Driver.php

@@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Component\Editor\Driver;
 
 use Chamilo\CoreBundle\Component\Editor\Connector;
 use FM\ElFinderPHP\Driver\ElFinderVolumeLocalFileSystem;
+use FM\ElFinderPHP\ElFinder;
 
 /**
  * Class Driver
@@ -19,6 +20,8 @@ class Driver extends ElFinderVolumeLocalFileSystem
     /** @var Connector */
     public $connector;
 
+    protected $encoding = 'utf-8';
+
     /**
      * Gets driver name.
      * @return string
@@ -70,11 +73,11 @@ class Driver extends ElFinderVolumeLocalFileSystem
     public function customRename($hash, $name)
     {
         if (!$this->nameAccepted($name)) {
-            return $this->setError(\elFinder::ERROR_INVALID_NAME, $name);
+            return $this->setError(ElFinder::ERROR_INVALID_NAME, $name);
         }
 
         if (!($file = $this->file($hash))) {
-            return $this->setError(\elFinder::ERROR_FILE_NOT_FOUND);
+            return $this->setError(ElFinder::ERROR_FILE_NOT_FOUND);
         }
 
         if ($name == $file['name']) {
@@ -82,28 +85,151 @@ class Driver extends ElFinderVolumeLocalFileSystem
         }
 
         if (!empty($file['locked'])) {
-            return $this->setError(\elFinder::ERROR_LOCKED, $file['name']);
+            return $this->setError(ElFinder::ERROR_LOCKED, $file['name']);
         }
 
         $path = $this->decode($hash);
-        $dir  = $this->dirnameCE($path);
-        $stat = $this->stat($this->joinPathCE($dir, $name));
+        $dir = $this->_dirname($path);
+        $stat = $this->stat($this->_joinPath($dir, $name));
 
         if ($stat) {
-            return $this->setError(\elFinder::ERROR_EXISTS, $name);
+            return $this->setError(ElFinder::ERROR_EXISTS, $name);
         }
 
         if (!$this->allowCreate($dir, $name, ($file['mime'] === 'directory'))) {
-            return $this->setError(\elFinder::ERROR_PERM_DENIED);
+            return $this->setError(ElFinder::ERROR_PERM_DENIED);
         }
 
         $this->rmTmb($file); // remove old name tmbs, we cannot do this after dir move
 
+        return $this->stat($path);
+
+    }
+
+    /**
+     * Return parent directory path (with convert encording)
+     *
+     * @param  string $path file path
+     * @return string
+     * @author Naoki Sawada
+     **/
+    protected function dirnameCE($path)
+    {
+        return (!$this->encoding) ? $this->_dirname($path) : $this->convEncOut(
+            $this->_dirname($this->convEncIn($path))
+        );
+    }
+
+    protected function joinPathCE($dir, $name)
+    {
+        return (!$this->encoding) ? $this->_joinPath(
+            $dir,
+            $name
+        ) : $this->convEncOut(
+            $this->_joinPath($this->convEncIn($dir), $this->convEncIn($name))
+        );
+    }
+
+    /**
+     * Converts character encoding from UTF-8 to server's one
+     *
+     * @param  mixed $var target string or array var
+     * @param  bool $restoreLocale do retore global locale, default is false
+     * @param  string $unknown replaces character for unknown
+     * @return mixed
+     * @author Naoki Sawada
+     */
+    public function convEncIn($var, $restoreLocale = false, $unknown = '_')
+    {
+        return (!$this->encoding) ? $var : $this->convEnc(
+            $var,
+            'UTF-8',
+            $this->encoding,
+            $this->options['locale'],
+            $restoreLocale,
+            $unknown
+        );
+    }
 
-        if ($path = $this->convEncOut($this->_move($this->convEncIn($path), $this->convEncIn($dir), $this->convEncIn($name)))) {
-            $this->clearcache();
-            return $this->stat($path);
+    /**
+     * Converts character encoding from server's one to UTF-8
+     *
+     * @param  mixed $var target string or array var
+     * @param  bool $restoreLocale do retore global locale, default is true
+     * @param  string $unknown replaces character for unknown
+     * @return mixed
+     * @author Naoki Sawada
+     */
+    public function convEncOut($var, $restoreLocale = true, $unknown = '_')
+    {
+        return (!$this->encoding) ? $var : $this->convEnc(
+            $var,
+            $this->encoding,
+            'UTF-8',
+            $this->options['locale'],
+            $restoreLocale,
+            $unknown
+        );
+    }
+
+    /**
+     * Converts character encoding (base function)
+     *
+     * @param  mixed $var target string or array var
+     * @param  string $from from character encoding
+     * @param  string $to to character encoding
+     * @param  string $locale local locale
+     * @param  string $unknown replaces character for unknown
+     * @return mixed
+     */
+    protected function convEnc(
+        $var,
+        $from,
+        $to,
+        $locale,
+        $restoreLocale,
+        $unknown = '_'
+    ) {
+        if (strtoupper($from) !== strtoupper($to)) {
+            if ($locale) {
+                @setlocale(LC_ALL, $locale);
+            }
+            if (is_array($var)) {
+                $_ret = array();
+                foreach ($var as $_k => $_v) {
+                    $_ret[$_k] = $this->convEnc(
+                        $_v,
+                        $from,
+                        $to,
+                        '',
+                        false,
+                        $unknown = '_'
+                    );
+                }
+                $var = $_ret;
+            } else {
+                $_var = false;
+                if (is_string($var)) {
+                    $_var = $var;
+                    if (false !== ($_var = @iconv(
+                            $from,
+                            $to.'//TRANSLIT',
+                            $_var
+                        ))
+                    ) {
+                        $_var = str_replace('?', $unknown, $_var);
+                    }
+                }
+                if ($_var !== false) {
+                    $var = $_var;
+                }
+            }
+            if ($restoreLocale) {
+                setlocale(LC_ALL, elFinder::$locale);
+            }
         }
-        return false;
+
+        return $var;
     }
+
 }

+ 1 - 0
src/Chamilo/CoreBundle/Composer/ScriptHandler.php

@@ -91,6 +91,7 @@ class ScriptHandler
             __DIR__.'/../../../../main/inc/lib/item_property.class.php',
             __DIR__.'/../../../../main/inc/lib/chamilo.class.php',
             __DIR__.'/../../../../main/inc/lib/events.lib.inc.php',
+            __DIR__.'/../../../../main/inc/lib/fileDisplay.lib.php',
             __DIR__.'/../../../../main/inc/lib/current_user.class.php',
             __DIR__.'/../../../../main/inc/lib/current_course.class.php',
             __DIR__.'/../../../../main/inc/lib/response.class.php',

+ 2 - 1
src/Chamilo/CoreBundle/Controller/FrontController.php

@@ -21,6 +21,7 @@ use Chamilo\CoreBundle\Component\Editor\Finder;
 class FrontController extends Controller
 {
     /**
+     * Get templates (left column when creating a document)
      * @Route("/editor/templates", name="editor_templates")
      * @Method({"GET"})
      */
@@ -53,7 +54,7 @@ class FrontController extends Controller
 
     /**
      * @Route("/editor/connector", name="editor_connector")
-     * @Method({"GET"})
+     * @Method({"GET|POST"})
      */
     public function editorConnector()
     {

+ 0 - 5
src/Chamilo/CoreBundle/Controller/LegacyController.php

@@ -36,11 +36,6 @@ class LegacyController extends ToolBaseController
 
         $rootDir = $this->get('kernel')->getRealRootDir();
 
-        // Legacy require files
-        require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-        require api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
-        require api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
-
         //$_REQUEST = $request->request->all();
         $mainPath = $rootDir.'main/';
         $fileToLoad = $mainPath.$name;

+ 16 - 0
src/Chamilo/CoreBundle/Framework/Container.php

@@ -105,6 +105,22 @@ class Container
         return self::$container->get('kernel')->getRealRootDir();
     }
 
+    /**
+     * @return string
+     */
+    public static function getUrlAppend()
+    {
+        return self::$container->get('kernel')->getUrlAppend();
+    }
+
+    /**
+     * @return string
+     */
+    public static function isInstalled()
+    {
+        return self::$container->get('kernel')->isInstalled();
+    }
+
     /**
      * @return string
      */

+ 0 - 1
tests/test_manager.inc.php

@@ -67,7 +67,6 @@ require_once $maindir.'course_info/download.lib.php';
 
 /**Files inside '/../main/lib/' */
 require_once $libdir.'urlmanager.lib.php';
-require_once $libdir.'fileDisplay.lib.php';
 require_once $libdir.'groupmanager.lib.php';
 require_once $libdir.'usermanager.lib.php';
 require_once $libdir.'social.lib.php';

+ 4 - 0
web/legacy.php

@@ -6,3 +6,7 @@ require_once __DIR__.'/../main/inc/lib/api.lib.php';
 require_once __DIR__.'/../main/inc/lib/database.constants.inc.php';
 require_once __DIR__.'/../main/inc/lib/internationalization.lib.php';
 require_once __DIR__.'/../main/inc/lib/text.lib.php';
+
+require_once __DIR__.'/../main/inc/lib/fileManage.lib.php';
+require_once __DIR__.'/../main/inc/lib/fileUpload.lib.php';
+