document_slideshow.inc.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  5. * files (since these are the files that can be viewed in a browser) and creates
  6. * a slideshow with it by allowing to go to the next/previous image.
  7. * You can also have a quick overview (thumbnail view) of all the images in
  8. * that particular folder.
  9. *
  10. * Each slideshow is folder based. Only
  11. * the images of the chosen folder are shown.
  12. *
  13. * This file has two large sections.
  14. * 1. code that belongs in document.php, but to avoid clutter I put the code here
  15. * (not present) 2. the function resize_image that handles the image resizing
  16. *
  17. * @author Patrick Cool, responsible author
  18. * @author Roan Embrechts, minor cleanup
  19. *
  20. * @package chamilo.document
  21. */
  22. /**
  23. * General code that belongs in document.php.
  24. *
  25. * This code should indeed go in documents.php but since document.php is already a really ugly file with
  26. * too much things in one file , I decided to put the code for document.php here and to include this
  27. * file into document.php
  28. */
  29. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  30. // grabbing the list of all the documents of this folder
  31. $array_to_search = !empty($documentAndFolders) && is_array($documentAndFolders) ? $documentAndFolders : [];
  32. if (count($array_to_search) > 0) {
  33. foreach ($array_to_search as $file) {
  34. $all_files[] = basename($file['path']);
  35. }
  36. }
  37. // Always show gallery.
  38. $image_present = 1;
  39. /*
  40. if (isset($all_files) && is_array($all_files) && count($all_files) > 0) {
  41. foreach ($all_files as & $file) {
  42. $slideshow_extension = strrchr($file, '.');
  43. $slideshow_extension = strtolower($slideshow_extension);
  44. if (in_array($slideshow_extension, $accepted_extensions)) {
  45. $image_present = 1;
  46. break;
  47. }
  48. }
  49. }*/
  50. $tablename_column = isset($_GET['tablename_column']) ? Security::remove_XSS($_GET['tablename_column']) : 0;
  51. if ($tablename_column == 0) {
  52. $tablename_column = 1;
  53. } else {
  54. $tablename_column = intval($tablename_column) - 1;
  55. }
  56. $image_files_only = sort_files($array_to_search);
  57. function sort_files($table)
  58. {
  59. $tablename_direction = isset($_GET['tablename_direction']) ? Security::remove_XSS($_GET['tablename_direction']) : 'ASC';
  60. $accepted_extensions = ['.jpg', '.jpeg', '.gif', '.png', '.bmp', '.svg'];
  61. $temp = [];
  62. foreach ($table as &$file_array) {
  63. if ($file_array['filetype'] == 'file') {
  64. $slideshow_extension = strrchr($file_array['path'], '.');
  65. $slideshow_extension = strtolower($slideshow_extension);
  66. if (in_array($slideshow_extension, $accepted_extensions)) {
  67. $start_date = isset($file_array['insert_date']) ? $file_array['insert_date'] : null;
  68. $temp[] = ['file', basename($file_array['path']), $file_array['size'], $start_date];
  69. }
  70. }
  71. }
  72. if ($tablename_direction == 'DESC') {
  73. usort($temp, 'rsort_table');
  74. } else {
  75. usort($temp, 'sort_table');
  76. }
  77. $final_array = [];
  78. foreach ($temp as &$file_array) {
  79. $final_array[] = $file_array[1];
  80. }
  81. return $final_array;
  82. }
  83. function sort_table($a, $b)
  84. {
  85. global $tablename_column;
  86. return strnatcmp($a[$tablename_column], $b[$tablename_column]);
  87. }
  88. function rsort_table($a, $b)
  89. {
  90. global $tablename_column;
  91. return strnatcmp($b[$tablename_column], $a[$tablename_column]);
  92. }