fileDisplay.lib.php 5.2 KB

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