123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?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.
- * @todo move this file to DocumentManager
- * @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 string $file_name (string) - Name of a file
- * @return string 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';
- }
- /**
- * Get the icon to display for a folder by its path
- * @param string $folderPath
- * @return string
- */
- function chooseFolderIcon($folderPath)
- {
- if ($folderPath == '/shared_folder') {
- return 'folder_users.gif';
- }
- if (strstr($folderPath, 'shared_folder_session_')) {
- return 'folder_users.gif';
- }
- switch ($folderPath) {
- case '/audio':
- return 'folder_audio.gif';
- case '/flash':
- return 'folder_flash.gif';
- case '/images':
- return 'folder_images.gif';
- case '/video':
- return 'folder_video.gif';
- case '/images/gallery':
- return 'folder_gallery.gif';
- case '/chat_files':
- return 'folder_chat.gif';
- case '/learning_path':
- return 'folder_learningpath.gif';
- }
- return 'folder_document.gif';
- }
- /**
- * Transform a UNIX time stamp in human readable format date.
- *
- * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
- * @param int $date - UNIX time stamp
- * @return string 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 string $file_path (string) - Relative local path of the file on the hard disk
- * @return string 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 total size of a directory.
- *
- * @param string $dir_name (string) - Path of the dir on the hard disk
- * @return int 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 props.ref, size
- FROM $table_itemproperty AS props
- INNER JOIN $table_document AS docs
- ON (docs.id = props.ref AND docs.c_id = props.c_id)
- WHERE
- docs.c_id = $course_id 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;
- }
- }
|