fileDisplay.lib.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * This is the file display library for Dokeos.
  5. * Include/require it in your code to use its functionality.
  6. *
  7. * @todo move this file to DocumentManager
  8. *
  9. * @package chamilo.library
  10. */
  11. /* FILE DISPLAY FUNCTIONS */
  12. /**
  13. * Define the image to display for each file extension.
  14. * This needs an existing image repository to work.
  15. *
  16. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  17. *
  18. * @param string $file_name (string) - Name of a file
  19. *
  20. * @return string The gif image to chose
  21. */
  22. function choose_image($file_name)
  23. {
  24. static $type, $image;
  25. /* TABLES INITIALISATION */
  26. if (!$type || !$image) {
  27. $type['word'] = [
  28. 'doc',
  29. 'dot',
  30. 'rtf',
  31. 'mcw',
  32. 'wps',
  33. 'psw',
  34. 'docm',
  35. 'docx',
  36. 'dotm',
  37. 'dotx',
  38. ];
  39. $type['web'] = [
  40. 'htm',
  41. 'html',
  42. 'htx',
  43. 'xml',
  44. 'xsl',
  45. 'php',
  46. 'xhtml',
  47. ];
  48. $type['image'] = [
  49. 'gif',
  50. 'jpg',
  51. 'png',
  52. 'bmp',
  53. 'jpeg',
  54. 'tif',
  55. 'tiff',
  56. ];
  57. $type['image_vect'] = ['svg', 'svgz'];
  58. $type['audio'] = [
  59. 'wav',
  60. 'mid',
  61. 'mp2',
  62. 'mp3',
  63. 'midi',
  64. 'sib',
  65. 'amr',
  66. 'kar',
  67. 'oga',
  68. 'au',
  69. 'wma',
  70. ];
  71. $type['video'] = [
  72. 'mp4',
  73. 'mov',
  74. 'rm',
  75. 'pls',
  76. 'mpg',
  77. 'mpeg',
  78. 'm2v',
  79. 'm4v',
  80. 'flv',
  81. 'f4v',
  82. 'avi',
  83. 'wmv',
  84. 'asf',
  85. '3gp',
  86. 'ogv',
  87. 'ogg',
  88. 'ogx',
  89. 'webm',
  90. ];
  91. $type['excel'] = [
  92. 'xls',
  93. 'xlt',
  94. 'xls',
  95. 'xlt',
  96. 'pxl',
  97. 'xlsx',
  98. 'xlsm',
  99. 'xlam',
  100. 'xlsb',
  101. 'xltm',
  102. 'xltx',
  103. ];
  104. $type['compressed'] = ['zip', 'tar', 'rar', 'gz'];
  105. $type['code'] = [
  106. 'js',
  107. 'cpp',
  108. 'c',
  109. 'java',
  110. 'phps',
  111. 'jsp',
  112. 'asp',
  113. 'aspx',
  114. 'cfm',
  115. ];
  116. $type['acrobat'] = ['pdf'];
  117. $type['powerpoint'] = [
  118. 'ppt',
  119. 'pps',
  120. 'pptm',
  121. 'pptx',
  122. 'potm',
  123. 'potx',
  124. 'ppam',
  125. 'ppsm',
  126. 'ppsx',
  127. ];
  128. $type['flash'] = ['fla', 'swf'];
  129. $type['text'] = ['txt', 'log'];
  130. $type['oo_writer'] = ['odt', 'ott', 'sxw', 'stw'];
  131. $type['oo_calc'] = ['ods', 'ots', 'sxc', 'stc'];
  132. $type['oo_impress'] = ['odp', 'otp', 'sxi', 'sti'];
  133. $type['oo_draw'] = ['odg', 'otg', 'sxd', 'std'];
  134. $type['epub'] = ['epub'];
  135. $type['java'] = ['class', 'jar'];
  136. $type['freemind'] = ['mm'];
  137. $image['word'] = 'word.png';
  138. $image['web'] = 'file_html.png';
  139. $image['image'] = 'file_image.png';
  140. $image['image_vect'] = 'file_svg.png';
  141. $image['audio'] = 'file_sound.png';
  142. $image['video'] = 'film.png';
  143. $image['excel'] = 'excel.png';
  144. $image['compressed'] = 'file_zip.png';
  145. $image['code'] = 'icons/22/mime_code.png';
  146. $image['acrobat'] = 'file_pdf.png';
  147. $image['powerpoint'] = 'powerpoint.png';
  148. $image['flash'] = 'file_flash.png';
  149. $image['text'] = 'icons/22/mime_text.png';
  150. $image['oo_writer'] = 'file_oo_writer.png';
  151. $image['oo_calc'] = 'file_oo_calc.png';
  152. $image['oo_impress'] = 'file_oo_impress.png';
  153. $image['oo_draw'] = 'file_oo_draw.png';
  154. $image['epub'] = 'file_epub.png';
  155. $image['java'] = 'file_java.png';
  156. $image['freemind'] = 'file_freemind.png';
  157. }
  158. $extension = [];
  159. if (!is_array($file_name)) {
  160. if (preg_match('/\.([[:alnum:]]+)(\?|$)/', $file_name, $extension)) {
  161. $extension[1] = strtolower($extension[1]);
  162. foreach ($type as $generic_type => $extension_list) {
  163. if (in_array($extension[1], $extension_list)) {
  164. return $image[$generic_type];
  165. }
  166. }
  167. }
  168. }
  169. return 'defaut.gif';
  170. }
  171. /**
  172. * Get the icon to display for a folder by its path.
  173. *
  174. * @param string $folderPath
  175. *
  176. * @return string
  177. */
  178. function chooseFolderIcon($folderPath)
  179. {
  180. if ($folderPath == '/shared_folder') {
  181. return 'folder_users.png';
  182. }
  183. if (strstr($folderPath, 'shared_folder_session_')) {
  184. return 'folder_users.png';
  185. }
  186. switch ($folderPath) {
  187. case '/audio':
  188. return 'folder_audio.png';
  189. case '/flash':
  190. return 'folder_flash.png';
  191. case '/images':
  192. return 'folder_images.png';
  193. case '/video':
  194. return 'folder_video.png';
  195. case '/images/gallery':
  196. return 'folder_gallery.png';
  197. case '/chat_files':
  198. return 'folder_chat.png';
  199. case '/learning_path':
  200. return 'folder_learningpath.png';
  201. }
  202. return 'folder_document.png';
  203. }