document_slideshow.inc.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @package chamilo.document
  20. */
  21. /**
  22. * General code that belongs in document.php
  23. *
  24. * This code should indeed go in documents.php but since document.php is already a really ugly file with
  25. * too much things in one file , I decided to put the code for document.php here and to include this
  26. * file into document.php
  27. */
  28. // Resetting the images of the slideshow = destroying the slideshow
  29. if (isset($_GET['action']) && $_GET['action'] == 'exit_slideshow') {
  30. $_SESSION['image_files_only'] = null;
  31. unset($image_files_only);
  32. }
  33. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  34. // grabbing the list of all the documents of this folder
  35. //$all_files = $fileList['name'];
  36. $array_to_search = !empty($documentAndFolders) && is_array($documentAndFolders) ? $documentAndFolders : array();
  37. if (count($array_to_search) > 0) {
  38. while (list($key) = each($array_to_search)) {
  39. $all_files[] = basename($array_to_search[$key]['path']);
  40. //echo basename($array_to_search[$key]['path']).'<br />';
  41. }
  42. }
  43. // Always show gallery.
  44. $image_present = 1;
  45. /*
  46. if (isset($all_files) && is_array($all_files) && count($all_files) > 0) {
  47. foreach ($all_files as & $file) {
  48. $slideshow_extension = strrchr($file, '.');
  49. $slideshow_extension = strtolower($slideshow_extension);
  50. if (in_array($slideshow_extension, $accepted_extensions)) {
  51. $image_present = 1;
  52. break;
  53. }
  54. }
  55. }*/
  56. $tablename_column = isset($_GET['tablename_column']) ? Security::remove_XSS($_GET['tablename_column']) : 0;
  57. if ($tablename_column == 0) {
  58. $tablename_column = 1;
  59. } else {
  60. $tablename_column = intval($tablename_column) - 1;
  61. }
  62. $image_files_only = sort_files($array_to_search);
  63. $_SESSION['image_files_only'] = $image_files_only;
  64. function sort_files($table)
  65. {
  66. $tablename_direction = isset($_GET['tablename_direction']) ? Security::remove_XSS($_GET['tablename_direction']) : 'ASC';
  67. $accepted_extensions = array('.jpg', '.jpeg', '.gif', '.png', '.bmp', '.svg');
  68. $temp = array();
  69. foreach ($table as & $file_array) {
  70. if ($file_array['filetype'] == 'file') {
  71. $slideshow_extension = strrchr($file_array['path'], '.');
  72. $slideshow_extension = strtolower($slideshow_extension);
  73. if (in_array($slideshow_extension, $accepted_extensions)) {
  74. $start_date = isset($file_array['insert_date']) ? $file_array['insert_date'] : null;
  75. $temp[] = array('file', basename($file_array['path']), $file_array['size'], $start_date);
  76. }
  77. }
  78. }
  79. if ($tablename_direction == 'DESC') {
  80. usort($temp, 'rsort_table');
  81. } else {
  82. usort($temp, 'sort_table');
  83. }
  84. $final_array = array();
  85. foreach ($temp as & $file_array) {
  86. $final_array[] = $file_array[1];
  87. }
  88. return $final_array;
  89. }
  90. function sort_table($a, $b) {
  91. global $tablename_column;
  92. return strnatcmp($a[$tablename_column], $b[$tablename_column]);
  93. }
  94. function rsort_table($a, $b) {
  95. global $tablename_column;
  96. return strnatcmp($b[$tablename_column], $a[$tablename_column]);
  97. }