document_slideshow.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  6. * files (since these are the files that can be viewed in a browser) and creates
  7. * a slideshow with it by allowing to go to the next/previous image.
  8. * You can also have a quick overview (thumbnail view) of all the images in
  9. * that particular folder.
  10. *
  11. * Each slideshow is folder based. Only
  12. * the images of the chosen folder are shown.
  13. *
  14. * This file has two large sections.
  15. * 1. code that belongs in document.php, but to avoid clutter I put the code here
  16. * (not present) 2. the function resize_image that handles the image resizing
  17. *
  18. * @author Patrick Cool, responsible author
  19. * @author Roan Embrechts, minor cleanup
  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. // Resetting the images of the slideshow = destroying the slideshow
  30. if (isset($_GET['action']) && $_GET['action'] == 'exit_slideshow') {
  31. Session::write('image_files_only', null);
  32. unset($image_files_only);
  33. }
  34. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  35. // grabbing the list of all the documents of this folder
  36. //$all_files = $fileList['name'];
  37. $array_to_search = !empty($documentAndFolders) && is_array($documentAndFolders) ? $documentAndFolders : array();
  38. if (count($array_to_search) > 0) {
  39. while (list($key) = each($array_to_search)) {
  40. $all_files[] = basename($array_to_search[$key]['path']);
  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. Session::write('document_slideshow_table_column', $tablename_column);
  63. $image_files_only = sort_files($array_to_search);
  64. Session::write('image_files_only', $image_files_only);
  65. function sort_files($table)
  66. {
  67. $tablename_direction = isset($_GET['tablename_direction']) ? Security::remove_XSS($_GET['tablename_direction']) : 'ASC';
  68. $accepted_extensions = array('.jpg', '.jpeg', '.gif', '.png', '.bmp', '.svg');
  69. $temp = array();
  70. foreach ($table as & $file_array) {
  71. if ($file_array['filetype'] == 'file') {
  72. $slideshow_extension = strrchr($file_array['path'], '.');
  73. $slideshow_extension = strtolower($slideshow_extension);
  74. if (in_array($slideshow_extension, $accepted_extensions)) {
  75. $start_date = isset($file_array['insert_date']) ? $file_array['insert_date'] : null;
  76. $temp[] = array('file', basename($file_array['path']), $file_array['size'], $start_date);
  77. }
  78. }
  79. }
  80. if ($tablename_direction == 'DESC') {
  81. usort($temp, 'rsort_table');
  82. } else {
  83. usort($temp, 'sort_table');
  84. }
  85. $final_array = array();
  86. foreach ($temp as & $file_array) {
  87. $final_array[] = $file_array[1];
  88. }
  89. return $final_array;
  90. }
  91. function sort_table($a, $b)
  92. {
  93. $tablename_column = Session::read('document_slideshow_table_column');
  94. return strnatcmp($a[$tablename_column], $b[$tablename_column]);
  95. }
  96. function rsort_table($a, $b)
  97. {
  98. $tablename_column = Session::read('document_slideshow_table_column');
  99. return strnatcmp($b[$tablename_column], $a[$tablename_column]);
  100. }
  101. Session::erase('document_slideshow_table_column');